add create_backup_file()
This commit is contained in:
@@ -483,7 +483,7 @@ static EffectValues values_1_to_10_step_0p1 = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static EffectValues values_rp_mix = {
|
static EffectValues values_rp_mix = {
|
||||||
/** \todo make this display properly (USB 0, USB 1, USB 2 ... USB 49, USB RP, RP 49, RP 48 ... RP 1, RP 0) */
|
/** \todo make this display properly (USB 0, USB 1, USB 2 ... USB 49, USB RP, RP 49, RP 48 ... RP 1, RP 0) */
|
||||||
0.0, 100.0, NULL,
|
0.0, 100.0, NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
138
gdigi.c
138
gdigi.c
@@ -159,20 +159,27 @@ static void unpack_message(GString *msg)
|
|||||||
do {
|
do {
|
||||||
offset += 8;
|
offset += 8;
|
||||||
status = str[offset-1];
|
status = str[offset-1];
|
||||||
for (x=0; x<7; x++) {
|
for (x=0; x<7 && !stop; x++) {
|
||||||
if (offset+x >= msg->len) {
|
if (offset+x >= msg->len) {
|
||||||
|
i++;
|
||||||
stop = TRUE;
|
stop = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (str[offset+x] == 0xF7) {
|
if (str[offset+x] == 0xF7) {
|
||||||
|
if (x == 0) {
|
||||||
|
str[i] = status;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
str[i] = 0xF7;
|
str[i] = 0xF7;
|
||||||
|
i++;
|
||||||
stop = TRUE;
|
stop = TRUE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
str[i] = (((status << (x+1)) & 0x80) | str[x+offset]);
|
str[i] = (((status << (x+1)) & 0x80) | str[x+offset]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
} while (!stop && (offset+x < msg->len));
|
} while (!stop);
|
||||||
|
|
||||||
g_string_truncate(msg, i);
|
g_string_truncate(msg, i);
|
||||||
}
|
}
|
||||||
@@ -653,11 +660,13 @@ GStrv query_preset_names(gchar bank)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries current edit buffer.
|
* Reads multiple messages and puts them into GList.
|
||||||
*
|
*
|
||||||
* \return GList with preset SysEx messages, which must be freed using preset_list_free.
|
* \param id MessageID starting message sequence
|
||||||
|
*
|
||||||
|
* \return GList with SysEx messages, which must be freed using message_list_free.
|
||||||
**/
|
**/
|
||||||
GList *get_current_preset()
|
GList *get_message_list(MessageID id)
|
||||||
{
|
{
|
||||||
GString *data = NULL;
|
GString *data = NULL;
|
||||||
GList *list = NULL;
|
GList *list = NULL;
|
||||||
@@ -665,15 +674,13 @@ GList *get_current_preset()
|
|||||||
gboolean found = FALSE;
|
gboolean found = FALSE;
|
||||||
gboolean done = FALSE;
|
gboolean done = FALSE;
|
||||||
|
|
||||||
send_message(REQUEST_PRESET, "\x04\x00", 2);
|
|
||||||
|
|
||||||
g_mutex_lock(message_queue_mutex);
|
g_mutex_lock(message_queue_mutex);
|
||||||
do {
|
do {
|
||||||
len = g_queue_get_length(message_queue);
|
len = g_queue_get_length(message_queue);
|
||||||
|
|
||||||
for (x = 0; x<len && (found == FALSE); x++) {
|
for (x = 0; x<len && (found == FALSE); x++) {
|
||||||
data = g_queue_peek_nth(message_queue, x);
|
data = g_queue_peek_nth(message_queue, x);
|
||||||
if (get_message_id(data) == RECEIVE_PRESET_START) {
|
if (get_message_id(data) == id) {
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
g_queue_pop_nth(message_queue, x);
|
g_queue_pop_nth(message_queue, x);
|
||||||
unpack_message(data);
|
unpack_message(data);
|
||||||
@@ -686,11 +693,23 @@ GList *get_current_preset()
|
|||||||
int i;
|
int i;
|
||||||
int amt;
|
int amt;
|
||||||
|
|
||||||
for (i = 10; (i < data->len) && data->str[i]; i++);
|
switch (id) {
|
||||||
|
case RECEIVE_PRESET_START:
|
||||||
amt = (unsigned char)data->str[i+2];
|
for (i = 10; (i < data->len) && data->str[i]; i++);
|
||||||
|
amt = (unsigned char)data->str[i+2];
|
||||||
|
break;
|
||||||
|
case RECEIVE_BULK_DUMP_START:
|
||||||
|
amt = ((unsigned char)data->str[8] << 8) | (unsigned char)data->str[9];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_error("get_message_list() doesn't support followning id: %d", id);
|
||||||
|
g_string_free(data, TRUE);
|
||||||
|
g_list_free(list);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
while (amt) {
|
while (amt) {
|
||||||
|
g_message("%d messages left", amt);
|
||||||
data = g_queue_pop_nth(message_queue, x);
|
data = g_queue_pop_nth(message_queue, x);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
g_cond_wait(message_queue_cond, message_queue_mutex);
|
g_cond_wait(message_queue_cond, message_queue_mutex);
|
||||||
@@ -703,7 +722,7 @@ GList *get_current_preset()
|
|||||||
|
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
} else {
|
} else {
|
||||||
/* Receive Preset Start not found in message queue */
|
/* id not found in message queue */
|
||||||
g_cond_wait(message_queue_cond, message_queue_mutex);
|
g_cond_wait(message_queue_cond, message_queue_mutex);
|
||||||
}
|
}
|
||||||
} while (done == FALSE);
|
} while (done == FALSE);
|
||||||
@@ -712,7 +731,12 @@ GList *get_current_preset()
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void preset_list_free(GList *list)
|
/**
|
||||||
|
* \param list list to be freed
|
||||||
|
*
|
||||||
|
* Frees all memory used by message list.
|
||||||
|
**/
|
||||||
|
void message_list_free(GList *list)
|
||||||
{
|
{
|
||||||
g_return_if_fail(list != NULL);
|
g_return_if_fail(list != NULL);
|
||||||
|
|
||||||
@@ -720,6 +744,94 @@ void preset_list_free(GList *list)
|
|||||||
g_list_free(list);
|
g_list_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries current edit buffer.
|
||||||
|
*
|
||||||
|
* \return GList with preset SysEx messages, which must be freed using message_list_free.
|
||||||
|
**/
|
||||||
|
GList *get_current_preset()
|
||||||
|
{
|
||||||
|
send_message(REQUEST_PRESET, "\x04\x00", 2);
|
||||||
|
return get_message_list(RECEIVE_PRESET_START);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates backup file.
|
||||||
|
*
|
||||||
|
* \param file backup file handle
|
||||||
|
* \param error a GError
|
||||||
|
*
|
||||||
|
* \return FALSE on success, TRUE on error.
|
||||||
|
**/
|
||||||
|
static gboolean create_backup_file(GFile *file, GError **error)
|
||||||
|
{
|
||||||
|
GFileOutputStream *output = NULL;
|
||||||
|
GList *list = NULL, *iter = NULL;
|
||||||
|
const gchar header[] = {'\x01', '\x00'};
|
||||||
|
gsize written;
|
||||||
|
gboolean val;
|
||||||
|
|
||||||
|
*error = NULL;
|
||||||
|
output = g_file_create(file, G_FILE_CREATE_NONE, NULL, error);
|
||||||
|
if (output == NULL)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
*error = NULL;
|
||||||
|
val = g_output_stream_write_all(G_OUTPUT_STREAM(output), header,
|
||||||
|
sizeof(header), &written, NULL, error);
|
||||||
|
if (val == FALSE) {
|
||||||
|
g_object_unref(output);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
send_message(REQUEST_BULK_DUMP, "\x00", 1);
|
||||||
|
list = get_message_list(RECEIVE_BULK_DUMP_START);
|
||||||
|
|
||||||
|
for (iter = list; iter; iter = g_list_next(iter)) {
|
||||||
|
GString *str;
|
||||||
|
guchar id; /* message id */
|
||||||
|
guint32 len; /* message length */
|
||||||
|
|
||||||
|
str = (GString*) iter->data;
|
||||||
|
|
||||||
|
id = get_message_id(str);
|
||||||
|
*error = NULL;
|
||||||
|
val = g_output_stream_write_all(G_OUTPUT_STREAM(output), &id,
|
||||||
|
sizeof(id), &written, NULL, error);
|
||||||
|
if (val == FALSE) {
|
||||||
|
message_list_free(list);
|
||||||
|
g_object_unref(output);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = GUINT32_TO_LE(str->len - 10);
|
||||||
|
*error = NULL;
|
||||||
|
val = g_output_stream_write_all(G_OUTPUT_STREAM(output), &len,
|
||||||
|
sizeof(len), &written, NULL, error);
|
||||||
|
if (val == FALSE) {
|
||||||
|
message_list_free(list);
|
||||||
|
g_object_unref(output);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*error = NULL;
|
||||||
|
val = g_output_stream_write_all(G_OUTPUT_STREAM(output), &str->str[8],
|
||||||
|
str->len - 10, &written, NULL, error);
|
||||||
|
if (val == FALSE) {
|
||||||
|
message_list_free(list);
|
||||||
|
g_object_unref(output);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message_list_free(list);
|
||||||
|
|
||||||
|
*error = NULL;
|
||||||
|
val = g_output_stream_close(G_OUTPUT_STREAM(output), NULL, error);
|
||||||
|
g_object_unref(output);
|
||||||
|
return !val;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \param device_id Variable to hold device ID
|
* \param device_id Variable to hold device ID
|
||||||
* \param family_id Variable to hold family ID
|
* \param family_id Variable to hold family ID
|
||||||
|
|||||||
2
gdigi.h
2
gdigi.h
@@ -894,7 +894,7 @@ void switch_preset(guint bank, guint x);
|
|||||||
void store_preset_name(int x, const gchar *name);
|
void store_preset_name(int x, const gchar *name);
|
||||||
void set_preset_level(int level);
|
void set_preset_level(int level);
|
||||||
GStrv query_preset_names(gchar bank);
|
GStrv query_preset_names(gchar bank);
|
||||||
|
void message_list_free(GList *list);
|
||||||
GList *get_current_preset();
|
GList *get_current_preset();
|
||||||
void preset_list_free(GList *list);
|
|
||||||
|
|
||||||
#endif /* GDIGI_H */
|
#endif /* GDIGI_H */
|
||||||
|
|||||||
2
gui.c
2
gui.c
@@ -213,7 +213,7 @@ static void apply_current_preset()
|
|||||||
{
|
{
|
||||||
GList *list = get_current_preset();
|
GList *list = get_current_preset();
|
||||||
Preset *preset = create_preset_from_data(list);
|
Preset *preset = create_preset_from_data(list);
|
||||||
preset_list_free(list);
|
message_list_free(list);
|
||||||
apply_preset_to_gui(preset);
|
apply_preset_to_gui(preset);
|
||||||
preset_free(preset);
|
preset_free(preset);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user