propertly apply xml patch

This commit is contained in:
Tomasz Moń
2009-03-03 21:57:47 +01:00
parent 8e445bb408
commit 904a30bb38
2 changed files with 89 additions and 11 deletions

48
gdigi.c
View File

@@ -173,7 +173,41 @@ static void clear_midi_in_buffer()
} while (str != NULL);
}
static void send_message(gint procedure, gchar *data, gint len)
GString *pack_data(gchar *data, gint len)
{
GString *packed;
gint i;
gint new_len;
u_char status;
gint offset;
gint status_byte;
new_len = len + (len/7);
packed = g_string_sized_new(new_len);
status = 0;
offset = -1;
status_byte = 0;
for (i=0; i<len; i++) {
if ((i % 7) == 0) {
packed->str[status_byte] = status;
status = 0;
status_byte = packed->len;
g_string_append_c(packed, '\0');
}
g_string_append_c(packed, (data[i] & 0x7F));
status |= (data[i] & 0x80) >> ((i%7) + 1);
}
packed->str[status_byte] = status;
return packed;
}
/*
data - unpacked data to send
len - data length
*/
void send_message(gint procedure, gchar *data, gint len)
{
GString *msg = g_string_new_len("\xF0" /* SysEx status byte */
"\x00\x00\x10", /* Manufacturer ID */
@@ -184,8 +218,11 @@ static void send_message(gint procedure, gchar *data, gint len)
device_id, family_id, product_id,
procedure);
if (len > 0)
g_string_append_len(msg, data, len);
if (len > 0) {
GString *tmp = pack_data(data, len);
g_string_append_len(msg, tmp->str, tmp->len);
g_string_free(tmp, TRUE);
}
g_string_append_printf(msg, "%c\xF7",
calc_checksum(&msg->str[1], msg->len - 1));
@@ -444,7 +481,6 @@ static void unpack_message(GString *msg)
i = 8;
do {
printf("status byte [%d] 0x%02x\n", offset-1, msg->str[offset-1]);
status = (u_char)msg->str[offset-1];
for (x=0; x<7; x++) {
if ((u_char)msg->str[offset+x] == 0xF7) {
@@ -453,8 +489,6 @@ static void unpack_message(GString *msg)
}
msg->str[i] = (((status << (x+1)) & 0x80) | (u_char)msg->str[x+offset]);
printf("merging byte [%d] with byte [%d] MSB is %d\n",
i, x+offset, (((status << (x+1)) & 0x80) >> 7));
i++;
}
offset += 8;
@@ -468,7 +502,7 @@ GString *get_current_preset()
/* clear MIDI IN buffer */
clear_midi_in_buffer();
send_message(REQUEST_PRESET, "\x00\x04\x00", 3);
send_message(REQUEST_PRESET, "\x04\x00", 3);
/* read reply */
data = read_data();

52
gui.c
View File

@@ -473,19 +473,63 @@ static void action_open_preset_cb(GtkAction *action)
gtk_widget_hide(dialog);
GString *msg = g_string_sized_new(500);
GList *iter = preset->params;
gint len = g_list_length(iter);
g_string_append_printf(msg, "%c%c",
((len & 0xFF00) >> 8),
(len & 0xFF));
while (iter) {
SettingParam *param = iter->data;
iter = iter->next;
/* sending those is likely to freeze/reboot device */
if ((param->id == 8704) || (param->id == 8705))
continue;
g_string_append_printf(msg, "%c%c%c",
((param->id & 0xFF00) >> 8),
(param->id & 0xFF),
param->position);
set_option(param->id, param->position, param->value);
/* check how many bytes long the value is */
gint temp = param->value;
gint n = 0;
do {
n++;
temp = temp >> 8;
} while (temp);
if (n == 1) {
if (param->value & 0x80)
n = 2;
else
g_string_append_printf(msg, "%c", param->value);
}
if (n > 1) {
gint x;
g_string_append_printf(msg, "%c", (n | 0x80));
for (x=0; x<n; x++) {
g_string_append_printf(msg, "%c",
((param->value >> (8*(n-x-1))) & 0xFF));
}
}
};
GString *start = g_string_new(NULL);
g_string_append_printf(start,
"%c%c%s%c%c%c",
PRESETS_EDIT_BUFFER, 0,
preset->name, 0 /* NULL terminated string */,
0 /* modified */, 2 /* messages to follow */);
send_message(RECEIVE_PRESET_START, start->str, start->len);
send_message(RECEIVE_PRESET_PARAMETERS, msg->str, msg->len);
send_message(RECEIVE_PRESET_END, NULL, 0);
show_store_preset_window(window, preset->name);
g_string_free(start, TRUE);
g_string_free(msg, TRUE);
preset_free(preset);
loaded = TRUE;
}