changeset 1303:2a7c9e0b9c0f

Added configure options for cddb
author zither@litestep.network
date Fri, 20 Jul 2007 03:29:42 +0300
parents 1d3b02d1842b
children f34112ab9101
files src/cdaudio-ng/cdaudio-ng.c src/cdaudio-ng/configure.c src/cdaudio-ng/configure.h
diffstat 3 files changed, 73 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/src/cdaudio-ng/cdaudio-ng.c	Thu Jul 19 23:43:00 2007 +0200
+++ b/src/cdaudio-ng/cdaudio-ng.c	Fri Jul 20 03:29:42 2007 +0300
@@ -1,13 +1,8 @@
 
 /*
 	todo: 
-		- vis_pcm...?!
 		- fileinfo dialog
 		- about dialog
-		- remove //'s & todo's
-		- additional comments
-		- stop playback when configure
-		- configuration for cddb (server, port)
 */
 
 #include <string.h>
@@ -30,6 +25,7 @@
 #include <audacious/i18n.h>
 #include <audacious/configdb.h>
 #include <audacious/plugin.h>
+//#include <audacious/playback.h>	// todo: this should be available soon (by 1.4)
 #include <audacious/util.h>
 #include <audacious/output.h>
 
@@ -51,6 +47,8 @@
 static int				playing_track = -1;
 static dae_params_t		*pdae_params = NULL;
 static gboolean			debug = FALSE;
+static char				cddb_server[DEF_STRING_LEN];
+static int				cddb_port;
 
 static void				cdaudio_init();
 static void				cdaudio_about();
@@ -74,17 +72,13 @@
 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();
-
-
 
 static InputPlugin inputplugin = {
 	NULL,
 	NULL,
 	"CD Audio Plugin NG",
 	cdaudio_init,
-	cdaudio_about,
+	NULL /*cdaudio_about*/,	// todo: implement an about dialog
 	cdaudio_configure,
 	cdaudio_is_our_file,
 	cdaudio_scan_dir,
@@ -102,7 +96,7 @@
 	NULL,
 	NULL,
 	cdaudio_get_song_info,
-	cdaudio_file_info_box,
+	NULL /*cdaudio_file_info_box*/,	// todo: implement a file info dialog
 	NULL,
 	cdaudio_get_song_tuple
 };
@@ -136,6 +130,12 @@
 		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", "cddbserver", &string))
+		strcpy(cddb_server, "");
+	else
+		strcpy(cddb_server, string);
+	if (!bmp_cfg_db_get_int(db, "CDDA", "cddbport", &cddb_port))
+		cddb_port = 1;
 	if (!bmp_cfg_db_get_string(db, "CDDA", "device", &string))
 		strcpy(device, "");
 	else
@@ -146,9 +146,9 @@
 	bmp_cfg_db_close(db);
 
 	if (debug)
-		printf("cdaudio-ng: configuration: use_dae = %d, limitspeed = %d, use_cdtext = %d, use_cddb = %d, device = \"%s\", debug = %d\n", use_dae, limitspeed, use_cdtext, use_cddb, device, debug);
+		printf("cdaudio-ng: configuration: use_dae = %d, limitspeed = %d, use_cdtext = %d, use_cddb = %d, cddbserver = \"%s\", cddbport = %d, device = \"%s\", debug = %d\n", use_dae, limitspeed, use_cdtext, use_cddb, cddb_server, cddb_port, device, debug);
 
-	configure_set_variables(&use_dae, &limitspeed, &use_cdtext, &use_cddb, device, &debug);
+	configure_set_variables(&use_dae, &limitspeed, &use_cdtext, &use_cddb, device, &debug, cddb_server, &cddb_port);
 	configure_create_gui();
 }
 
@@ -163,6 +163,10 @@
 	if (debug)
 		printf("cdaudio-ng: cdaudio_configure()\n");
 
+		/* if playback is started, we stop it */
+	if (playing_track != -1)
+		playback_stop();
+
 	configure_show_gui();
 }
 
@@ -270,9 +274,17 @@
 	trackinfo = (trackinfo_t *) malloc(sizeof(trackinfo_t) * (lasttrackno + 1));
 	int trackno;
 
+	trackinfo[0].startlsn = cdio_get_track_lsn(pcdrom_drive->p_cdio, trackno);
+	trackinfo[0].endlsn = cdio_get_track_last_lsn(pcdrom_drive->p_cdio, CDIO_CDROM_LEADOUT_TRACK);
+	strcpy(trackinfo[0].performer, "");
+	strcpy(trackinfo[0].name, "");
+	strcpy(trackinfo[0].genre, "");
 	for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) {
 		trackinfo[trackno].startlsn = cdio_get_track_lsn(pcdrom_drive->p_cdio, trackno);
 		trackinfo[trackno].endlsn = cdio_get_track_last_lsn(pcdrom_drive->p_cdio, trackno);
+		strcpy(trackinfo[trackno].performer, "");
+		strcpy(trackinfo[trackno].name, "");
+		strcpy(trackinfo[trackno].genre, "");
 
 		if (trackinfo[trackno].startlsn == CDIO_INVALID_LSN || trackinfo[trackno].endlsn == CDIO_INVALID_LSN) {
 			fprintf(stderr, "cdaudio-ng: failed to retrieve stard/end lsn for track %d\n", trackno);
@@ -294,7 +306,8 @@
 			if (debug)
 				printf("cdaudio-ng: getting cddb info\n");
 
-			// todo: change the default cddb settings
+			cddb_set_server_name(pcddb_conn, cddb_server);
+			cddb_set_server_port(pcddb_conn, cddb_port);
 
 			pcddb_disc = cddb_disc_new();
 			for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) {
@@ -491,9 +504,10 @@
 void cdaudio_stop(InputPlayback *pinputplayback)
 {
 	if (debug)
-		printf("cdaudio-ng: cdaudio_stop(\"%s\")\n", pinputplayback->filename);
+		printf("cdaudio-ng: cdaudio_stop(\"%s\")\n", pinputplayback != NULL ? pinputplayback->filename : "N/A");
 
-	pinputplayback->playing = FALSE;
+	if (pinputplayback != NULL)
+		pinputplayback->playing = FALSE;
 	playing_track = -1;
 	is_paused = FALSE;
 
@@ -666,6 +680,8 @@
 	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", "cddbserver", cddb_server);
+	bmp_cfg_db_set_int(db, "CDDA", "cddbport", cddb_port);
 	bmp_cfg_db_set_string(db, "CDDA", "device", device);
 	bmp_cfg_db_set_bool(db, "CDDA", "debug", debug);
 	bmp_cfg_db_close(db);
@@ -726,41 +742,6 @@
 
 	/* auxiliar functions */
 
-
-static int calculate_digit_sum(int n)
-{
-	int ret = 0;
-
-	while (1) {
-		ret += n % 10;
-		n    = n / 10;
-		if (n == 0)
-			return ret;
-	}
-}
-
-
-
-static unsigned long calculate_cddb_discid()
-{
-	int trackno, t, n = 0;
-	msf_t startmsf;
-	msf_t msf;
-	
-	for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) {
-		cdio_get_track_msf(pcdio, trackno, &msf);
-		n += calculate_digit_sum(cdio_audio_get_msf_seconds(&msf));
-	}
-	
-	cdio_get_track_msf(pcdio, 1, &startmsf);
-	cdio_get_track_msf(pcdio, CDIO_CDROM_LEADOUT_TRACK, &msf);
-	
-	t = cdio_audio_get_msf_seconds(&msf) - cdio_audio_get_msf_seconds(&startmsf);
-	
-	return ((n % 0xFF) << 24 | t << 8 | (lasttrackno - firsttrackno + 1));
-}
-
-
 void *dae_playing_thread_core(dae_params_t *pdae_params)
 {
 	unsigned char *buffer = (unsigned char *) malloc(CDDA_DAE_FRAMES * CDIO_CD_FRAMESIZE_RAW);
--- a/src/cdaudio-ng/configure.c	Thu Jul 19 23:43:00 2007 +0200
+++ b/src/cdaudio-ng/configure.c	Fri Jul 20 03:29:42 2007 +0300
@@ -1,5 +1,6 @@
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <gtk/gtk.h>
 
@@ -20,6 +21,10 @@
 static GtkWidget		*limitcheckbutton;
 static GtkWidget		*usecdtextcheckbutton;
 static GtkWidget		*usecddbcheckbutton;
+static GtkWidget		*cddbserverlabel;
+static GtkWidget		*cddbportlabel;
+static GtkWidget		*cddbserverentry;
+static GtkWidget		*cddbportentry;
 static GtkWidget		*usedevicecheckbutton;
 static GtkWidget		*buttonbox;
 static GtkWidget		*limitspinbutton;
@@ -32,6 +37,8 @@
 static gboolean			*usecddb;
 static char				*device;
 static gboolean			*debug;
+static char				*cddbserver;
+static int				*cddbport;
 
 static gboolean			delete_window(GtkWidget *widget, GdkEvent *event, gpointer data);
 static void				button_clicked(GtkWidget *widget, gpointer data);
@@ -40,7 +47,7 @@
 static void				gui_to_values();
 
 
-void configure_set_variables(gboolean *_usedae, int *_limitspeed, gboolean *_usecdtext, gboolean *_usecddb, char *_device, gboolean *_debug)
+void configure_set_variables(gboolean *_usedae, int *_limitspeed, gboolean *_usecdtext, gboolean *_usecddb, char *_device, gboolean *_debug, char *_cddbserver, int *_cddbport)
 {
 	usedae = _usedae;
 	limitspeed = _limitspeed;
@@ -48,6 +55,8 @@
 	usecddb = _usecddb;
 	device = _device;
 	debug = _debug;
+	cddbserver = _cddbserver;
+	cddbport = _cddbport;
 }
 
 void configure_create_gui()
@@ -60,6 +69,7 @@
 	g_signal_connect(G_OBJECT(configwindow), "delete_event", G_CALLBACK(delete_window), NULL);
 
 	maintable = gtk_table_new(4, 2, TRUE);
+	gtk_table_set_homogeneous(GTK_TABLE(maintable), FALSE);
 	gtk_container_add(GTK_CONTAINER(configwindow), maintable);
 
 	daeframe = gtk_frame_new("Digital audio extraction");
@@ -96,6 +106,19 @@
 	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);
+	
+	cddbserverlabel = gtk_label_new("Server: ");
+	gtk_table_attach_defaults(GTK_TABLE(titleinfotable), cddbserverlabel, 0, 1, 2, 3);
+	
+	cddbportlabel = gtk_label_new("Port: ");
+	gtk_table_attach_defaults(GTK_TABLE(titleinfotable), cddbportlabel, 0, 1, 3, 4);
+	
+	cddbserverentry = gtk_entry_new();
+	gtk_table_attach_defaults(GTK_TABLE(titleinfotable), cddbserverentry, 1, 2, 2, 3);
+	
+	cddbportentry = gtk_entry_new();
+	gtk_table_attach_defaults(GTK_TABLE(titleinfotable), cddbportentry, 1, 2, 3, 4);
+
 
 	usedevicecheckbutton = gtk_check_button_new_with_label("Override default device: ");
 	g_signal_connect(G_OBJECT(usedevicecheckbutton), "toggled", G_CALLBACK(checkbutton_toggled), NULL);
@@ -128,6 +151,10 @@
 	gtk_widget_show(limitspinbutton);
 	gtk_widget_show(usecdtextcheckbutton);
 	gtk_widget_show(usecddbcheckbutton);
+	gtk_widget_show(cddbserverentry);
+	gtk_widget_show(cddbportentry);
+	gtk_widget_show(cddbserverlabel);
+	gtk_widget_show(cddbportlabel);
 	gtk_widget_show(usedevicecheckbutton);
 	gtk_widget_show(deviceentry);
 	gtk_widget_show(debugcheckbutton);
@@ -175,6 +202,9 @@
 		gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(limitcheckbutton)) && 
 		GTK_WIDGET_IS_SENSITIVE(limitcheckbutton));
 
+	gtk_widget_set_sensitive(cddbserverentry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usecddbcheckbutton)));
+	gtk_widget_set_sensitive(cddbportentry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usecddbcheckbutton)));
+
 	gtk_widget_set_sensitive(deviceentry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usedevicecheckbutton)));
 }
 
@@ -191,6 +221,13 @@
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usecdtextcheckbutton), *usecdtext);
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usecddbcheckbutton), *usecddb);
 
+	char portstr[10];
+	sprintf(portstr, "%d", *cddbport);
+	gtk_entry_set_text(GTK_ENTRY(cddbserverentry), cddbserver);
+	gtk_entry_set_text(GTK_ENTRY(cddbportentry), portstr);
+	gtk_widget_set_sensitive(cddbserverentry, *usecddb);
+	gtk_widget_set_sensitive(cddbportentry, *usecddb);
+
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(usedevicecheckbutton), strlen(device) > 0);
 
 	gtk_widget_set_sensitive(deviceentry, strlen(device) > 0);
@@ -208,6 +245,8 @@
 		*limitspeed = 0;
 	*usecdtext = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usecdtextcheckbutton));
 	*usecddb = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usecddbcheckbutton));
+	strcpy(cddbserver, gtk_entry_get_text(GTK_ENTRY(cddbserverentry)));
+	*cddbport = strtol(gtk_entry_get_text(GTK_ENTRY(cddbportentry)), NULL, 10);
 	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(usedevicecheckbutton)))
 		strcpy(device, gtk_entry_get_text(GTK_ENTRY(deviceentry)));
 	else
--- a/src/cdaudio-ng/configure.h	Thu Jul 19 23:43:00 2007 +0200
+++ b/src/cdaudio-ng/configure.h	Fri Jul 20 03:29:42 2007 +0300
@@ -2,7 +2,7 @@
 #ifndef CONFIGURE_H
 #define CONFIGURE_H
 
-void				configure_set_variables(gboolean *usedae, int *limitspeed, gboolean *usecdtext, gboolean *usecddb, char *device, gboolean *debug);
+void				configure_set_variables(gboolean *usedae, int *limitspeed, gboolean *usecdtext, gboolean *usecddb, char *device, gboolean *debug, char *cddbserver, int *cddbport);
 void				configure_create_gui();
 void				configure_show_gui();