Mercurial > audlegacy-plugins
changeset 1189:af5bd4592100 trunk
Added cdaudio-ng.h; added a configure dialog
author | zither@litestep.network |
---|---|
date | Wed, 20 Jun 2007 22:27:48 +0300 |
parents | 22a470857579 |
children | ed2d7787779e |
files | src/cdaudio-ng/Makefile src/cdaudio-ng/cdaudio-ng.c src/cdaudio-ng/cdaudio-ng.h src/cdaudio-ng/configure.c src/cdaudio-ng/configure.h |
diffstat | 5 files changed, 317 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cdaudio-ng/Makefile Mon Jun 18 21:53:26 2007 +0900 +++ b/src/cdaudio-ng/Makefile Wed Jun 20 22:27:48 2007 +0300 @@ -6,7 +6,7 @@ LIBADD = $(GTK_LIBS) $(GLIB_LIBS) $(PANGO_LIBS) $(CDIO_LIBS) LIBDIR = $(plugindir)/$(INPUT_PLUGIN_DIR) -SOURCES = cdaudio-ng.c +SOURCES = cdaudio-ng.c configure.c OBJECTS = ${SOURCES:.c=.o}
--- a/src/cdaudio-ng/cdaudio-ng.c Mon Jun 18 21:53:26 2007 +0900 +++ b/src/cdaudio-ng/cdaudio-ng.c Wed Jun 20 22:27:48 2007 +0300 @@ -1,13 +1,14 @@ /* todo: - - move stuff into cdaudio-ng.h - vis_pcm...?! - limit cd read speed - cddb - - dialogs + - fileinfo dialog + - about dialog - remove //'s & todo's - additional comments + - surpress debug output */ #include <string.h> @@ -32,31 +33,8 @@ #include <audacious/util.h> #include <audacious/output.h> -#define DEF_STRING_LEN 256 -#define CDDA_DEFAULT "cdda://default" -#define CDDA_DAE_FRAMES 8 - - -typedef struct { - - char performer[DEF_STRING_LEN]; - char name[DEF_STRING_LEN]; - char genre[DEF_STRING_LEN]; - lsn_t startlsn; - lsn_t endlsn; - -} trackinfo_t; - -typedef struct { - - lsn_t startlsn; - lsn_t endlsn; - lsn_t currlsn; - lsn_t seektime; /* in miliseconds */ - InputPlayback *pplayback; - GThread *thread; - -} dae_params_t; +#include "cdaudio-ng.h" +#include "configure.h" static int firsttrackno = -1; @@ -65,11 +43,14 @@ static trackinfo_t *trackinfo = NULL; static char album_name[DEF_STRING_LEN]; static gboolean use_dae = TRUE; +static gboolean use_cdtext = TRUE; +static gboolean use_cddb = TRUE; +static char device[DEF_STRING_LEN]; +static int limitspeed = 1; static gboolean is_paused = FALSE; static int playing_track = -1; static dae_params_t *pdae_params = NULL; - static void cdaudio_init(); static void cdaudio_about(); static void cdaudio_configure(); @@ -92,6 +73,7 @@ static int find_trackno_from_filename(char *filename); static void cleanup_on_error(); + /* static int calculate_digit_sum(int n); static unsigned long calculate_cddb_discid(); @@ -140,6 +122,29 @@ cleanup_on_error(); return; } + + ConfigDb *db = bmp_cfg_db_open(); + gchar *string = NULL; + + if (!bmp_cfg_db_get_bool(db, "CDDA", "use_dae", &use_dae)) + use_dae = TRUE; + if (!bmp_cfg_db_get_int(db, "CDDA", "limitspeed", &limitspeed)) + limitspeed = 1; + if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cdtext", &use_cdtext)) + use_cdtext = TRUE; + if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cddb", &use_cddb)) + use_cddb = TRUE; + if (!bmp_cfg_db_get_string(db, "CDDA", "device", &string)) + strcpy(device, ""); + else + strcpy(device, string); + + bmp_cfg_db_close(db); + + printf("cdaudio-ng: configuration: use_dae = %d, limitspeed = %d, use_cdtext = %d, use_cddb = %d, device = \"%s\"\n", use_dae, limitspeed, use_cdtext, use_cddb, device); + + configure_set_variables(&use_dae, &limitspeed, &use_cdtext, &use_cddb, device); + configure_create_gui(); } void cdaudio_about() @@ -150,6 +155,8 @@ void cdaudio_configure() { printf("cdaudio-ng: cdaudio_configure()\n"); + + configure_show_gui(); } gint cdaudio_is_our_file(gchar *filename) @@ -195,23 +202,27 @@ return NULL; } - /* find the first available, audio capable, cd drive */ - char **ppcd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false); - if (ppcd_drives != NULL) { /* we have at least one audio capable cd drive */ - pcdio = cdio_open(*ppcd_drives, DRIVER_UNKNOWN); - if (pcdio == NULL) { - fprintf(stderr, "cdaudio-ng: failed to open cd\n"); + /* find an available, audio capable, cd drive */ + if (device != NULL && strlen(device) > 0) + pcdio = cdio_open(device, DRIVER_UNKNOWN); + else { + char **ppcd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false); + if (ppcd_drives != NULL) { /* we have at least one audio capable cd drive */ + pcdio = cdio_open(*ppcd_drives, DRIVER_UNKNOWN); + if (pcdio == NULL) { + fprintf(stderr, "cdaudio-ng: failed to open cd\n"); + cleanup_on_error(); + return NULL; + } + } + else { + fprintf(stderr, "cdaudio-ng: unable find or access a cdda capable drive\n"); cleanup_on_error(); return NULL; } + printf("cdaudio-ng: found cd drive \"%s\" with audio capable media\n", *ppcd_drives); + cdio_free_device_list(ppcd_drives); } - else { - fprintf(stderr, "cdaudio-ng: unable find or access a cdda capable drive\n"); - cleanup_on_error(); - return NULL; - } - printf("cdaudio-ng: found cd drive \"%s\" with audio capable media\n", *ppcd_drives); - cdio_free_device_list(ppcd_drives); /* get track information */ cdrom_drive_t *pcdrom_drive = cdio_cddap_identify_cdio(pcdio, 1, NULL); // todo : check return / NULL @@ -232,7 +243,9 @@ int trackno; for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { list = g_list_append(list, g_strdup_printf("track%02u.cda", trackno)); - cdtext_t *pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, trackno); + cdtext_t *pcdtext = NULL; + if (use_cdtext) + pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, trackno); if (pcdtext != NULL) { strcpy(trackinfo[trackno].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : ""); @@ -245,6 +258,8 @@ strcpy(trackinfo[trackno].genre, ""); } + // todo: implement cddb + if (strlen(trackinfo[trackno].name) == 0) sprintf(trackinfo[trackno].name, "CD Audio Track %02u", trackno); @@ -502,6 +517,16 @@ trackinfo = NULL; } playing_track = -1; + + // todo: destroy the gui + + ConfigDb *db = bmp_cfg_db_open(); + bmp_cfg_db_set_bool(db, "CDDA", "use_dae", use_dae); + bmp_cfg_db_set_int(db, "CDDA", "limitspeed", limitspeed); + bmp_cfg_db_set_bool(db, "CDDA", "use_cdtext", use_cdtext); + bmp_cfg_db_set_bool(db, "CDDA", "use_cddb", use_cddb); + bmp_cfg_db_set_string(db, "CDDA", "device", device); + bmp_cfg_db_close(db); } void cdaudio_get_song_info(gchar *filename, gchar **title, gint *length)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cdaudio-ng/cdaudio-ng.h Wed Jun 20 22:27:48 2007 +0300 @@ -0,0 +1,33 @@ + +#ifndef CDAUDIO_NG_H +#define CDAUDIO_NG_H + + +#define DEF_STRING_LEN 256 +#define CDDA_DEFAULT "cdda://default" +#define CDDA_DAE_FRAMES 8 + + +typedef struct { + + char performer[DEF_STRING_LEN]; + char name[DEF_STRING_LEN]; + char genre[DEF_STRING_LEN]; + lsn_t startlsn; + lsn_t endlsn; + +} trackinfo_t; + +typedef struct { + + lsn_t startlsn; + lsn_t endlsn; + lsn_t currlsn; + lsn_t seektime; /* in miliseconds */ + InputPlayback *pplayback; + GThread *thread; + +} dae_params_t; + + +#endif // CDAUDIO_NG_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cdaudio-ng/configure.c Wed Jun 20 22:27:48 2007 +0300 @@ -0,0 +1,206 @@ + +#include <stdio.h> +#include <string.h> +#include <gtk/gtk.h> + +#include "configure.h" + + +static GtkWidget *configwindow; +static GtkWidget *okbutton; +static GtkWidget *cancelbutton; +static GtkWidget *maintable; +static GtkWidget *daeframe; +static GtkWidget *titleinfoframe; +static GtkWidget *miscframe; +static GtkWidget *daetable; +static GtkWidget *titleinfotable; +static GtkWidget *misctable; +static GtkWidget *usedaecheckbutton; +static GtkWidget *limitcheckbutton; +static GtkWidget *usecdtextcheckbutton; +static GtkWidget *usecddbcheckbutton; +static GtkWidget *usedevicecheckbutton; +static GtkWidget *buttonbox; +static GtkWidget *limitspinbutton; +static GtkWidget *deviceentry; + +static gboolean *usedae; +static int *limitspeed; +static gboolean *usecdtext; +static gboolean *usecddb; +static char *device; + +static gboolean delete_window(GtkWidget *widget, GdkEvent *event, gpointer data); +static void button_clicked(GtkWidget *widget, gpointer data); +static void checkbutton_toggled(GtkWidget *widget, gpointer data); +static void values_to_gui(); +static void gui_to_values(); + + +void configure_set_variables(gboolean *_usedae, int *_limitspeed, gboolean *_usecdtext, gboolean *_usecddb, char *_device) +{ + usedae = _usedae; + limitspeed = _limitspeed; + usecdtext = _usecdtext; + usecddb = _usecddb; + device = _device; +} + +void configure_create_gui() +{ + configwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(configwindow), "CD Audio Plugin Configuration"); + gtk_window_set_resizable(GTK_WINDOW(configwindow), FALSE); + gtk_window_set_position(GTK_WINDOW(configwindow), GTK_WIN_POS_CENTER_ALWAYS); + gtk_container_set_border_width(GTK_CONTAINER(configwindow), 10); + g_signal_connect(G_OBJECT(configwindow), "delete_event", G_CALLBACK(delete_window), NULL); + + maintable = gtk_table_new(4, 2, TRUE); + gtk_container_add(GTK_CONTAINER(configwindow), maintable); + + + daeframe = gtk_frame_new("Digital audio extraction"); + gtk_table_attach_defaults(GTK_TABLE(maintable), daeframe, 0, 2, 0, 1); + daetable = gtk_table_new(2, 2, TRUE); + gtk_container_add(GTK_CONTAINER(daeframe), daetable); + + titleinfoframe = gtk_frame_new("Title information"); + gtk_table_attach_defaults(GTK_TABLE(maintable), titleinfoframe, 0, 2, 1, 2); + titleinfotable = gtk_table_new(2, 2, TRUE); + gtk_container_add(GTK_CONTAINER(titleinfoframe), titleinfotable); + + miscframe = gtk_frame_new("Misc"); + gtk_table_attach_defaults(GTK_TABLE(maintable), miscframe, 0, 2, 2, 3); + misctable = gtk_table_new(2, 2, TRUE); + gtk_container_add(GTK_CONTAINER(miscframe), misctable); + + + usedaecheckbutton = gtk_check_button_new_with_label("Use digital audio extraction"); + g_signal_connect(G_OBJECT(usedaecheckbutton), "toggled", G_CALLBACK(checkbutton_toggled), NULL); + gtk_table_attach_defaults(GTK_TABLE(daetable), usedaecheckbutton, 0, 2, 0, 1); + + limitcheckbutton = gtk_check_button_new_with_label("Limit read speed to: "); + g_signal_connect(G_OBJECT(limitcheckbutton), "toggled", G_CALLBACK(checkbutton_toggled), NULL); + gtk_table_attach_defaults(GTK_TABLE(daetable), limitcheckbutton, 0, 1, 1, 2); + + limitspinbutton = gtk_spin_button_new_with_range(1.0, 24.0, 1.0); + gtk_table_attach_defaults(GTK_TABLE(daetable), limitspinbutton, 1, 2, 1, 2); + + usecdtextcheckbutton = gtk_check_button_new_with_label("Use cd-text if available"); + g_signal_connect(G_OBJECT(usecdtextcheckbutton), "toggled", G_CALLBACK(checkbutton_toggled), NULL); + gtk_table_attach_defaults(GTK_TABLE(titleinfotable), usecdtextcheckbutton, 0, 2, 0, 1); + + usecddbcheckbutton = gtk_check_button_new_with_label("Use CDDB if available"); + g_signal_connect(G_OBJECT(usecddbcheckbutton), "toggled", G_CALLBACK(checkbutton_toggled), NULL); + gtk_table_attach_defaults(GTK_TABLE(titleinfotable), usecddbcheckbutton, 0, 2, 1, 2); + + usedevicecheckbutton = gtk_check_button_new_with_label("Override default device: "); + g_signal_connect(G_OBJECT(usedevicecheckbutton), "toggled", G_CALLBACK(checkbutton_toggled), NULL); + gtk_table_attach_defaults(GTK_TABLE(misctable), usedevicecheckbutton, 0, 1, 0, 1); + + deviceentry = gtk_entry_new(); + gtk_table_attach_defaults(GTK_TABLE(misctable), deviceentry, 1, 2, 0, 1); + + + buttonbox = gtk_hbutton_box_new(); + gtk_hbutton_box_set_layout_default(GTK_BUTTONBOX_END); + gtk_hbutton_box_set_spacing_default(10); + gtk_table_attach_defaults(GTK_TABLE(maintable), buttonbox, 0, 2, 3, 4); + + okbutton = gtk_button_new_with_label("Ok"); + g_signal_connect(G_OBJECT(okbutton), "clicked", G_CALLBACK(button_clicked), NULL); + gtk_container_add(GTK_CONTAINER(buttonbox), okbutton); + + cancelbutton = gtk_button_new_with_label("Cancel"); + g_signal_connect(G_OBJECT(cancelbutton), "clicked", G_CALLBACK(button_clicked), NULL); + gtk_container_add(GTK_CONTAINER(buttonbox), cancelbutton); + + + gtk_widget_show(usedaecheckbutton); + gtk_widget_show(limitcheckbutton); + gtk_widget_show(limitspinbutton); + gtk_widget_show(usecdtextcheckbutton); + gtk_widget_show(usecddbcheckbutton); + gtk_widget_show(usedevicecheckbutton); + gtk_widget_show(deviceentry); + + gtk_widget_show(daetable); + gtk_widget_show(daeframe); + gtk_widget_show(titleinfotable); + gtk_widget_show(titleinfoframe); + gtk_widget_show(misctable); + gtk_widget_show(miscframe); + + gtk_widget_show(buttonbox); + gtk_widget_show(okbutton); + gtk_widget_show(cancelbutton); + + gtk_widget_show(maintable); +} + +void configure_show_gui() +{ + values_to_gui(); + gtk_widget_show(configwindow); +} + +gboolean delete_window(GtkWidget *widget, GdkEvent *event, gpointer data) +{ + gtk_widget_hide(configwindow); + return TRUE; +} + +void button_clicked(GtkWidget *widget, gpointer data) +{ + gtk_widget_hide(configwindow); + if (widget == okbutton) + gui_to_values(); +} + + +void checkbutton_toggled(GtkWidget *widget, gpointer data) +{ + gtk_widget_set_sensitive(limitcheckbutton, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usedaecheckbutton))); + + gtk_widget_set_sensitive( + limitspinbutton, + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(limitcheckbutton)) && + GTK_WIDGET_IS_SENSITIVE(limitcheckbutton)); + + gtk_widget_set_sensitive(deviceentry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usedevicecheckbutton))); +} + +void values_to_gui() +{ + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usedaecheckbutton), *usedae); + + gtk_widget_set_sensitive(limitcheckbutton, *usedae); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(limitcheckbutton), *limitspeed > 0); + + gtk_widget_set_sensitive(limitspinbutton, *usedae && *limitspeed > 0); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(limitspinbutton), *limitspeed); + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usecdtextcheckbutton), *usecdtext); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usecddbcheckbutton), *usecddb); + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usedevicecheckbutton), strlen(device) > 0); + + gtk_widget_set_sensitive(deviceentry, strlen(device) > 0); + gtk_entry_set_text(GTK_ENTRY(deviceentry), device); +} + +void gui_to_values() +{ + *usedae = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usedaecheckbutton)); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(limitcheckbutton))) + *limitspeed = gtk_spin_button_get_value(GTK_SPIN_BUTTON(limitspinbutton)); + else + *limitspeed = 0; + *usecdtext = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usecdtextcheckbutton)); + *usecddb = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usecddbcheckbutton)); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usedevicecheckbutton))) + strcpy(device, gtk_entry_get_text(GTK_ENTRY(deviceentry))); + else + strcpy(device, ""); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cdaudio-ng/configure.h Wed Jun 20 22:27:48 2007 +0300 @@ -0,0 +1,10 @@ + +#ifndef CONFIGURE_H +#define CONFIGURE_H + +void configure_set_variables(gboolean *usedae, int *limitspeed, gboolean *usecdtext, gboolean *usecddb, char *device); +void configure_create_gui(); +void configure_show_gui(); + + +#endif // CONFIGURE_H