Detect DigiTech devices on startup. If more than one device is found, ask user which one to use.

This commit is contained in:
Tim LaBerge
2012-03-26 16:17:03 +02:00
committed by Tomasz Moń
parent ce296d2698
commit 35e42dc653
4 changed files with 73 additions and 11 deletions

1
TODO
View File

@@ -2,5 +2,4 @@
-handling presets (saving, exporting to xml patches) -handling presets (saving, exporting to xml patches)
-buildsystem (install knob.png to share dir, don't use inline knob pixbuf) -buildsystem (install knob.png to share dir, don't use inline knob pixbuf)
-various fixes to MIDI IN messages handling -various fixes to MIDI IN messages handling
-ask user which device to use if more than one DigiTech device is found
-optimizations -optimizations

27
gdigi.c
View File

@@ -1058,6 +1058,8 @@ static gboolean request_who_am_i(unsigned char *device_id, unsigned char *family
*device_id = data->str[8]; *device_id = data->str[8];
*family_id = data->str[9]; *family_id = data->str[9];
*product_id = data->str[10]; *product_id = data->str[10];
g_message("I am device id %d family %d product id %d.",
*device_id, *family_id, *product_id);
g_string_free(data, TRUE); g_string_free(data, TRUE);
return TRUE; return TRUE;
} }
@@ -1122,18 +1124,14 @@ static gint get_digitech_devices(GList **devices)
{ {
gint card_num = -1; gint card_num = -1;
gint number = 0; gint number = 0;
snd_card_next(&card_num);
while (card_num > -1) { while (!snd_card_next(&card_num) && (card_num > -1)) {
char* name; char* name;
snd_card_get_longname(card_num, &name); snd_card_get_longname(card_num, &name);
gint count = strspn(name,"DigiTech"); if (strspn(name,"DigiTech") > 0) {
if (count > 0)
{
number++; number++;
*devices = g_list_append(*devices, GINT_TO_POINTER(card_num)); *devices = g_list_append(*devices, GINT_TO_POINTER(card_num));
} }
snd_card_next(&card_num);
} }
return number; return number;
@@ -1162,12 +1160,23 @@ int main(int argc, char *argv[]) {
if (device_port == NULL) { if (device_port == NULL) {
/* port not given explicitly in commandline - search for devices */ /* port not given explicitly in commandline - search for devices */
GList *devices = NULL; GList *devices = NULL;
if (get_digitech_devices(&devices) <= 0) { GList *device = NULL;
g_message("Couldn't find DigiTech devices!"); int num_devices = 0;
int chosen_device = 0;
if ((num_devices = get_digitech_devices(&devices)) <= 0) {
g_message("Couldn't find any DigiTech devices!");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (num_devices > 1) {
chosen_device = select_device_dialog(devices);
if (chosen_device < 0) {
show_error_message(NULL, "No device chosen");
exit(EXIT_FAILURE);
}
}
device = g_list_nth(devices, chosen_device);
device_port = g_strdup_printf("hw:%d,0,0", device_port = g_strdup_printf("hw:%d,0,0",
GPOINTER_TO_INT(devices->data)); GPOINTER_TO_INT(device->data));
g_list_free(devices); g_list_free(devices);
g_message("Found device %s", device_port); g_message("Found device %s", device_port);
} else { } else {

53
gui.c
View File

@@ -17,6 +17,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib-object.h> #include <glib-object.h>
#include <string.h> #include <string.h>
#include <alsa/asoundlib.h>
#include "gdigi.h" #include "gdigi.h"
#include "gui.h" #include "gui.h"
#include "effects.h" #include "effects.h"
@@ -1339,3 +1340,55 @@ gboolean unsupported_device_dialog(Device **device)
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
return FALSE; return FALSE;
} }
/**
* \param devices List containing the available Digitech devices.
*
* Displays dialogbox for choosing a device.
*
* \return Index of the selected device or -1 on failure.
**/
gint select_device_dialog (GList *devices)
{
GtkWidget *dialog;
GtkWidget *label;
GtkWidget *combo_box;
GtkWidget *vbox;
GList *device;
dialog = gtk_dialog_new_with_buttons("Select Digitech device",
NULL, GTK_DIALOG_MODAL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
label = gtk_label_new("You have multiple Digitech devices, select one.\n");
gtk_container_add(GTK_CONTAINER(vbox), label);
combo_box = gtk_combo_box_text_new();
device = g_list_first(devices);
do {
char *name;
snd_card_get_longname(GPOINTER_TO_INT(device->data), &name);
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combo_box), NULL, name);
} while ((device = g_list_next(device)));
gtk_container_add(GTK_CONTAINER(vbox), combo_box);
gtk_widget_show_all(vbox);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
gint number = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box));
if (number != -1) {
gtk_widget_destroy(dialog);
return (number);
}
}
gtk_widget_destroy(dialog);
return -1;
}

1
gui.h
View File

@@ -28,5 +28,6 @@ gboolean apply_current_preset_to_gui(gpointer data);
void gui_create(Device *device); void gui_create(Device *device);
void gui_free(); void gui_free();
gboolean unsupported_device_dialog(Device **device); gboolean unsupported_device_dialog(Device **device);
gint select_device_dialog (GList *devices);
#endif /* GDIGI_GUI_H */ #endif /* GDIGI_GUI_H */