detect DigiTech devices on startup

This commit is contained in:
Ahmed Toulan
2011-09-05 20:45:35 +02:00
parent 907a3d0ed9
commit 2eb4e97810
4 changed files with 48 additions and 2 deletions

View File

@@ -32,6 +32,7 @@ distclean : clean
install: gdigi install: gdigi
install gdigi $(DESTDIR)/usr/bin install gdigi $(DESTDIR)/usr/bin
install gdigi.desktop $(DESTDIR)/usr/share/applications/
NODEP_TARGETS := clean distclean NODEP_TARGETS := clean distclean
depinc := 1 depinc := 1

2
TODO
View File

@@ -2,5 +2,5 @@
-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
-guess device port when user doesn't explicitly provide it (don't use hardcoded "hw:1,0,0") -ask user which device to use if more than one DigiTech device is found
-optimizations -optimizations

46
gdigi.c
View File

@@ -29,7 +29,7 @@ static unsigned char product_id = 0x7F;
static snd_rawmidi_t *output = NULL; static snd_rawmidi_t *output = NULL;
static snd_rawmidi_t *input = NULL; static snd_rawmidi_t *input = NULL;
static char *device_port = "hw:1,0,0"; static char *device_port = NULL;
static GQueue *message_queue = NULL; static GQueue *message_queue = NULL;
static GMutex *message_queue_mutex = NULL; static GMutex *message_queue_mutex = NULL;
@@ -1110,6 +1110,35 @@ static GOptionEntry options[] = {
#endif /* DOXYGEN_SHOULD_SKIP_THIS */ #endif /* DOXYGEN_SHOULD_SKIP_THIS */
/**
* \param[out] devices GList containing numbers (packed into pointers)
* of connected DigiTech devices
*
* Checks available soundcards for DigiTech devices.
*
* \return the number of connected DigiTech devices.
**/
static gint get_digitech_devices(GList **devices)
{
gint card_num = -1;
gint number = 0;
snd_card_next(&card_num);
while (card_num > -1) {
char* name;
snd_card_get_longname(card_num, &name);
gint count = strspn(name,"DigiTech");
if (count > 0)
{
number++;
*devices = g_list_append(*devices, GINT_TO_POINTER(card_num));
}
snd_card_next(&card_num);
}
return number;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
GError *error = NULL; GError *error = NULL;
GOptionContext *context; GOptionContext *context;
@@ -1130,6 +1159,21 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (device_port == NULL) {
/* port not given explicitly in commandline - search for devices */
GList *devices = NULL;
if (get_digitech_devices(&devices) <= 0) {
g_message("Couldn't find DigiTech devices!");
exit(EXIT_FAILURE);
}
device_port = g_strdup_printf("hw:%d,0,0",
GPOINTER_TO_INT(devices->data));
g_list_free(devices);
g_message("Found device %s", device_port);
} else {
g_message("Using device %s", device_port);
}
g_option_context_free(context); g_option_context_free(context);
if (open_device() == TRUE) { if (open_device() == TRUE) {

View File

@@ -3,4 +3,5 @@ Version=1.0
Type=Application Type=Application
Name=gdigi Name=gdigi
Exec=gdigi Exec=gdigi
Categories=GNOME;Audio;AudioVideo;