[PATCH] gmix



The patch adds a menu item and SIGUSR1 handler, both of which make it
rescan for mixer devices. This is my first patch; I hope I didn't do
anything really stupid :-0

Haukur Hreinsson
? diff
Index: gmix.c
===================================================================
RCS file: /cvs/gnome/gnome-media/gmix/gmix.c,v
retrieving revision 1.22
diff -u -r1.22 gmix.c
--- gmix.c	1999/03/02 23:14:02	1.22
+++ gmix.c	1999/03/07 01:49:34
@@ -57,20 +57,24 @@
 static void about_cb (GtkWidget *widget, void *data);
 static void options_cb (GtkWidget *widget, void *data);
 static void quit_cb (GtkWidget *widget, void *data);
+static void rescan_cb (GtkWidget *widget, void *data);
 
 static void get_device_config(void);
 static void put_device_config(void);
 static void get_gui_config(void);
 static void put_gui_config(void);
 void scan_devices(void);
+void rescan_devices(void);
 void free_devices(void);
 void init_devices(void);
 void open_dialog(void);
+void signal_handler(int);
 
 /*
  * Gnome info:
  */
 GtkWidget *app;
+GtkWidget *notebook;
 
 /* Menus */
 static GnomeUIInfo help_menu[] = {
@@ -80,6 +84,7 @@
 };
  
 static GnomeUIInfo program_menu[] = {
+    GNOMEUIINFO_MENU_NEW_ITEM(N_("_Rescan"), N_("Rescans for mixer devices"), rescan_cb, NULL),
     GNOMEUIINFO_MENU_EXIT_ITEM(quit_cb, NULL),
     GNOMEUIINFO_END
 };      
@@ -236,7 +241,8 @@
 
 		if (~mode & M_INITONLY) {
 			get_gui_config();
-
+			
+			signal(SIGUSR1, signal_handler);
 			open_dialog();
 
 			put_gui_config();
@@ -382,11 +388,11 @@
 	return channels;
 }
 
-void scan_devices(void)
+void rescan_devices(void)
 {
 	int cnt;
 	device_info *new_device;
-	cnt=0; devices=NULL;
+	cnt=g_list_length(devices);
 	do {
 		new_device=open_device(cnt++);
 		if (new_device) {
@@ -397,6 +403,12 @@
 	num_mixers=cnt-1;
 }
 
+void scan_devices(void)
+{
+	devices=NULL;
+	rescan_devices();
+}
+
 void free_one_device(gpointer a, gpointer b)
 {
 	device_info *info = (device_info *)a;
@@ -552,13 +564,89 @@
 	return hbox;
 }
 
-void open_dialog(void)
+void add_device_page(device_info *di, GtkWidget *notebook)
 {
-	GtkWidget *table, *notebook, *spixmap;
-	GList *d, *c;
+	GtkWidget *table, *spixmap;
+	GList *c;
 	
 	int i,j;
 
+	i=j=0;
+		
+	/*
+	 * count channels for table size;
+	 */	
+	for (c=di->channels; c; c=c->next) {
+		i++;
+	}
+	
+	for (c=di->channels; c; c=c->next) {
+		j+=2;
+	}
+
+	table=gtk_table_new(i*2, 7, FALSE);
+	gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
+		table, 
+		gtk_label_new(di->info.name));
+	gtk_table_set_row_spacings (GTK_TABLE (table), 0);
+	gtk_table_set_col_spacings (GTK_TABLE (table), 0);
+	gtk_container_border_width (GTK_CONTAINER (table), 0);
+	gtk_widget_show (table);
+		for (c=di->channels;c;c=c->next) {
+		GtkWidget *label, *mixer, *separator;
+		channel_info *ci;
+		ci=c->data;
+		if (ci->pixmap)
+		 {
+		  spixmap = gnome_stock_pixmap_widget (app, ci->pixmap);
+                         gtk_table_attach (GTK_TABLE (table), spixmap, i, i+1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+		  gtk_widget_show (spixmap);
+		 }
+		label=gtk_label_new(ci->title);
+		gtk_misc_set_alignment (GTK_MISC(label), 0.1, 0.5);
+		gtk_table_attach (GTK_TABLE (table), label, i, i+1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+		gtk_widget_show(label);
+			mixer=make_slider_mixer(ci);
+		gtk_table_attach (GTK_TABLE (table), mixer, i, i+1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+		gtk_widget_show (mixer);
+			if (ci->device->stereodevs & (1<<ci->channel)) {
+			/* lock-button, only useful for stereo */
+			ci->lock = gtk_check_button_new_with_label(_("Lock"));
+			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ci->lock), (ci->device->lock_bitmask & (1<<ci->channel))!=0);
+			gtk_signal_connect (GTK_OBJECT (ci->lock), "toggled", (GtkSignalFunc) lock_cb, (gpointer)ci);
+			gtk_table_attach (GTK_TABLE (table), ci->lock, i, i+1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+			gtk_widget_show (ci->lock);
+		}
+#if 0
+/*
+ * record-sources are disabled for now...
+ */
+		if (ci->device->recmask & (1<<ci->channel)) {
+			ci->rec = gtk_check_button_new_with_label (_("Rec."));
+			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ci->rec), (ci->device->record_bitmask & (1<<ci->channel))!=0);
+			gtk_signal_connect (GTK_OBJECT (ci->rec), "toggled", (GtkSignalFunc) rec_cb, (gpointer)ci);
+			gtk_table_attach (GTK_TABLE (table), ci->rec, i, i+1, 6, 7, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+			gtk_widget_show (ci->rec);
+		}
+#endif	
+		ci->mute=gtk_check_button_new_with_label(_("Mute"));
+		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ci->mute), (ci->device->mute_bitmask & (1<<ci->channel))!=0);
+		gtk_signal_connect (GTK_OBJECT (ci->mute), "toggled", (GtkSignalFunc) mute_cb, (gpointer)ci);
+		gtk_table_attach (GTK_TABLE (table), ci->mute, i, i+1, 6, 7, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+		gtk_widget_show (ci->mute);
+			separator = gtk_vseparator_new ();
+		gtk_table_attach (GTK_TABLE (table), separator, i+1, i+2, 1, 7, GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+		gtk_widget_show (separator);
+		i+=2; 
+	}
+}
+
+void open_dialog(void)
+{
+	GList *d, *c;
+	
+	int i=0;
+	
 	app = gnome_app_new ("gmix", _("GMIX 3.0") );
 	gtk_widget_realize (app);
 	gtk_signal_connect (GTK_OBJECT (app), "delete_event",
@@ -571,92 +659,16 @@
 	gnome_app_create_menus(GNOME_APP(app), main_menu);
 
 	/*
-	 * count channels for table size;
-	 */
-	i=0;
-	for (d=devices; d; d=d->next) {
-		for (c=((device_info *)d->data)->channels; c; c=c->next) {
-			i++;
-		}
-	}
-
-	/*
 	 * Build table with sliders
 	 */	
 	notebook = gtk_notebook_new();
 	gtk_widget_show(notebook);
 	gnome_app_set_contents(GNOME_APP (app), notebook);
 
-	i=0;
 	for (d=devices; d; d=d->next) {
-		device_info *di;
-		di=d->data;
-		j=0;
-		for (c=((device_info *)d->data)->channels;c;c=c->next) {
-			j+=2;
-		}
-
-		table=gtk_table_new(i*2, 7, FALSE);
-		gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
-			table, 
-			gtk_label_new(di->info.name));
-		gtk_table_set_row_spacings (GTK_TABLE (table), 0);
-		gtk_table_set_col_spacings (GTK_TABLE (table), 0);
-		gtk_container_border_width (GTK_CONTAINER (table), 0);
-		gtk_widget_show (table);
-
-		for (c=((device_info *)d->data)->channels;c;c=c->next) {
-			GtkWidget *label, *mixer, *separator;
-			channel_info *ci;
-			ci=c->data;
-			if (ci->pixmap)
-			 {
-			  spixmap = gnome_stock_pixmap_widget (app, ci->pixmap);
-                          gtk_table_attach (GTK_TABLE (table), spixmap, i, i+1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
-			  gtk_widget_show (spixmap);
-			 }
-			label=gtk_label_new(ci->title);
-			gtk_misc_set_alignment (GTK_MISC(label), 0.1, 0.5);
-			gtk_table_attach (GTK_TABLE (table), label, i, i+1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
-			gtk_widget_show(label);
-
-			mixer=make_slider_mixer(ci);
-			gtk_table_attach (GTK_TABLE (table), mixer, i, i+1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
-			gtk_widget_show (mixer);
-
-			if (ci->device->stereodevs & (1<<ci->channel)) {
-				/* lock-button, only useful for stereo */
-				ci->lock = gtk_check_button_new_with_label(_("Lock"));
-				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ci->lock), (ci->device->lock_bitmask & (1<<ci->channel))!=0);
-				gtk_signal_connect (GTK_OBJECT (ci->lock), "toggled", (GtkSignalFunc) lock_cb, (gpointer)ci);
-				gtk_table_attach (GTK_TABLE (table), ci->lock, i, i+1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
-				gtk_widget_show (ci->lock);
-			}
-#if 0
-	/*
-	 * record-sources are disabled for now...
-	 */
-			if (ci->device->recmask & (1<<ci->channel)) {
-				ci->rec = gtk_check_button_new_with_label (_("Rec."));
-				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ci->rec), (ci->device->record_bitmask & (1<<ci->channel))!=0);
-				gtk_signal_connect (GTK_OBJECT (ci->rec), "toggled", (GtkSignalFunc) rec_cb, (gpointer)ci);
-				gtk_table_attach (GTK_TABLE (table), ci->rec, i, i+1, 6, 7, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
-				gtk_widget_show (ci->rec);
-			}
-#endif	
-			ci->mute=gtk_check_button_new_with_label(_("Mute"));
-			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ci->mute), (ci->device->mute_bitmask & (1<<ci->channel))!=0);
-			gtk_signal_connect (GTK_OBJECT (ci->mute), "toggled", (GtkSignalFunc) mute_cb, (gpointer)ci);
-			gtk_table_attach (GTK_TABLE (table), ci->mute, i, i+1, 6, 7, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
-			gtk_widget_show (ci->mute);
-
-			separator = gtk_vseparator_new ();
-			gtk_table_attach (GTK_TABLE (table), separator, i+1, i+2, 1, 7, GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
-			gtk_widget_show (separator);
-			i+=2; 
-		}
-	}
-
+		add_device_page((device_info *)d->data, notebook);
+	};
+	  
 	gtk_widget_show(app);
 
 	/*
@@ -800,4 +812,20 @@
 		_("This is a mixer for OSS sound-devices."),
 		NULL);
 	gtk_widget_show (about);
+}
+
+void rescan_cb (GtkWidget *widget, void *data)
+{
+        int i=g_list_length(devices);
+	rescan_devices();
+	for (;i<g_list_length(devices);i++) {
+	     add_device_page((device_info *)(g_list_nth(devices, i)->data), notebook);
+	};
+}
+
+void signal_handler(int sig_num) {
+        switch (sig_num) {
+	case SIGUSR1:
+	  rescan_cb(NULL, NULL);
+	};
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]