Esempio n. 1
0
void push_message(GString *msg)
{
    MessageID msgid = get_message_id(msg);
    if (((unsigned char)msg->str[0] == 0xF0) &&
            ((unsigned char)msg->str[msg->len-1] == 0xF7)) {
        debug_msg(DEBUG_VERBOSE, "Pushing correct message!");
    } else {
        g_warning("Pushing incorrect message!");
    }

    int x;
    if (debug_flag_is_set(DEBUG_HEX)) {
        for (x = 0; x<msg->len; x++) {
            if (x && (x % HEX_WIDTH) == 0) {
                printf("\n");
            }
            printf("%02x ", (unsigned char)msg->str[x]);
        }
        if (x % HEX_WIDTH) {
            printf("\n");
        }
    }
    debug_msg(DEBUG_VERBOSE, "Received %s", get_message_name(msgid));

    SettingParam *param;
    switch (msgid) {
        case ACK:
            g_string_free(msg, TRUE);
            return;

        case NACK:
            g_warning("Received NACK!");
            g_string_free(msg, TRUE);
            return;

        case RECEIVE_PARAMETER_VALUE:
        {
            unpack_message(msg);
            param = setting_param_new_from_data(&msg->str[8], NULL);
            if (debug_flag_is_set(DEBUG_MSG2HOST)) {
                GString *ipv = format_ipv(param->id,
                                          param->position,
                                          param->value);
                debug_msg(DEBUG_MSG2HOST, "RECEIVE_PARAMETER_VALUE\n%s",
                                          ipv->str);
                g_string_free(ipv, TRUE);
            }

            GDK_THREADS_ENTER();
            apply_setting_param_to_gui(param);
            GDK_THREADS_LEAVE();

            setting_param_free(param);
            g_string_free(msg, TRUE);
            return;
        }

        case RECEIVE_DEVICE_NOTIFICATION:
            unpack_message(msg);
            unsigned char *str = (unsigned char*)msg->str;
            switch (str[8]) {
            case NOTIFY_PRESET_MOVED:
                if (str[11] == PRESETS_EDIT_BUFFER && str[12] == 0) {

                    GDK_THREADS_ENTER();
                    g_timeout_add(0, apply_current_preset_to_gui, NULL);
                    GDK_THREADS_LEAVE();
                    debug_msg(DEBUG_MSG2HOST,
                              "RECEIVE_DEVICE_NOTIFICATION: Loaded preset "
                              "%d from bank %d",
                              str[10], str[9]);
                } else {
                    debug_msg(DEBUG_MSG2HOST,
                              "RECEIVE_DEVICE_NOTIFICATION: %d %d moved to "
                              "%d %d",
                              str[9], str[10],
                              str[11], str[12]);
                }
                break;

            case NOTIFY_MODIFIER_GROUP_CHANGED:
            {
                int i;
                if (debug_flag_is_set(DEBUG_HEX)) {
                    printf("\n");
                    for (i = 0; i < msg->len; i++) {
                        printf(" %02x", (unsigned char) str[i]);
                    }
                    printf("\n");
                }

                debug_msg(DEBUG_MSG2HOST,
                          "NOTIFY_MODIFIER_GROUP_CHANGED: Modifier group "
                          "id %d changed",
                          (str[9] << 8) | (str[10]));

                if (!modifier_linkable_list_request_pending) {
                    send_message(REQUEST_MODIFIER_LINKABLE_LIST, "\x00\x01", 2);
                    modifier_linkable_list_request_pending = TRUE;
                }

                break;
            }
            default:
                g_warning("Received unhandled device notification 0x%x",
                          str[11]);
            }
            g_string_free(msg, TRUE);
            return;
        case RECEIVE_GLOBAL_PARAMETERS:
            unpack_message(msg);
            gint tot, n, x;
            tot = (unsigned char)msg->str[9];
            if (debug_flag_is_set(DEBUG_HEX)) {
                for (n = 0; n < msg->len; n++) {
                    printf("%02x ",(unsigned char) msg->str[n]);
                }
                printf("\n");
            }

            n = 0;
            x = 10;
            do {
                param = setting_param_new_from_data(&msg->str[x], &x);
                debug_msg(DEBUG_MSG2HOST,
                          "RECEIVE_GLOBAL_PARAMETERS ID: %5d "
                          "Position: %2.1d Value: %6.1d: %s",
                          param->id,
                          param->position, param->value, "XXX");

                GDK_THREADS_ENTER();
                apply_setting_param_to_gui(param);
                GDK_THREADS_LEAVE();

                setting_param_free(param);
            } while ( (x < msg->len) && n < tot);

            g_string_free(msg, TRUE);
            return;


        case RECEIVE_MODIFIER_LINKABLE_LIST:

            modifier_linkable_list_request_pending = FALSE;
            unpack_message(msg);
            tot = (unsigned char)msg->str[9];

            if (debug_flag_is_set(DEBUG_HEX)) {
                for (n = 0; n < msg->len; n++) {
                    printf("%02x ",(unsigned char) msg->str[n]);
                }
                printf("\n");
            }


            update_modifier_linkable_list(msg);

            g_string_free(msg, TRUE);

            GDK_THREADS_ENTER();

            create_modifier_group(EXP_POSITION, EXP_ASSIGN1);
            create_modifier_group(LFO1_POSITION, LFO_TYPE);
            create_modifier_group(LFO2_POSITION, LFO_TYPE);

            GDK_THREADS_LEAVE();

            return;


        default:
            g_mutex_lock(message_queue_mutex);
            g_queue_push_tail(message_queue, msg);
            g_cond_signal(message_queue_cond);
            g_mutex_unlock(message_queue_mutex);
            break;
    }
}
Esempio n. 2
0
void push_message(GString *msg)
{
    if (((unsigned char)msg->str[0] == 0xF0) && ((unsigned char)msg->str[msg->len-1] == 0xF7))
        g_message("Pushing correct message!");
    else
        g_warning("Pushing incorrect message!");

    int x;
    for (x = 0; x<msg->len; x++)
        printf("%02x ", (unsigned char)msg->str[x]);
    printf("\n");

    switch (get_message_id(msg)) {
        case ACK:
            g_message("Received ACK");
            g_string_free(msg, TRUE);
            return;

        case NACK:
            g_message("Received NACK");
            g_string_free(msg, TRUE);
            return;

        case RECEIVE_PARAMETER_VALUE:
            unpack_message(msg);
            SettingParam *param = setting_param_new_from_data(&msg->str[8], NULL);
            g_message("Received parameter change ID: %d Position: %d Value: %d", param->id, param->position, param->value);

            GDK_THREADS_ENTER();
            apply_setting_param_to_gui(param);
            GDK_THREADS_LEAVE();

            setting_param_free(param);
            g_string_free(msg, TRUE);
            return;

        case RECEIVE_DEVICE_NOTIFICATION:
            unpack_message(msg);
            unsigned char *str = (unsigned char*)msg->str;
            switch (str[8]) {
                case NOTIFY_PRESET_MOVED:
                    if (str[11] == PRESETS_EDIT_BUFFER && str[12] == 0) {
                        g_message("Loaded preset %d from bank %d", str[10], str[9]);

                        GDK_THREADS_ENTER();
                        g_timeout_add(0, apply_current_preset_to_gui, NULL);
                        GDK_THREADS_LEAVE();
                    } else
                        g_message("%d %d moved to %d %d", str[9], str[10], str[11], str[12]);
                default:
                    g_message("Received unhandled device notification");
            }
            g_string_free(msg, TRUE);
            return;
        default:
            g_mutex_lock(message_queue_mutex);
            g_queue_push_tail(message_queue, msg);
            g_cond_signal(message_queue_cond);
            g_mutex_unlock(message_queue_mutex);
    }
}