From 2eb4e97810c528fa60c0986c2ccb5a386b5d001f Mon Sep 17 00:00:00 2001 From: Ahmed Toulan Date: Mon, 5 Sep 2011 20:45:35 +0200 Subject: [PATCH] detect DigiTech devices on startup --- Makefile | 1 + TODO | 2 +- gdigi.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- gdigi.desktop | 1 + 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4960607..f46dd6a 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ distclean : clean install: gdigi install gdigi $(DESTDIR)/usr/bin + install gdigi.desktop $(DESTDIR)/usr/share/applications/ NODEP_TARGETS := clean distclean depinc := 1 diff --git a/TODO b/TODO index 3d3fc4c..6a1e154 100644 --- a/TODO +++ b/TODO @@ -2,5 +2,5 @@ -handling presets (saving, exporting to xml patches) -buildsystem (install knob.png to share dir, don't use inline knob pixbuf) -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 diff --git a/gdigi.c b/gdigi.c index e14fb2d..5a46939 100644 --- a/gdigi.c +++ b/gdigi.c @@ -29,7 +29,7 @@ static unsigned char product_id = 0x7F; static snd_rawmidi_t *output = 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 GMutex *message_queue_mutex = NULL; @@ -1110,6 +1110,35 @@ static GOptionEntry options[] = { #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[]) { GError *error = NULL; GOptionContext *context; @@ -1130,6 +1159,21 @@ int main(int argc, char *argv[]) { 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); if (open_device() == TRUE) { diff --git a/gdigi.desktop b/gdigi.desktop index 293f3f5..804407a 100644 --- a/gdigi.desktop +++ b/gdigi.desktop @@ -3,4 +3,5 @@ Version=1.0 Type=Application Name=gdigi Exec=gdigi +Categories=GNOME;Audio;AudioVideo;