From 8d601c64d53f3fa7c7f1ea31bd041e8544d9f464 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sat, 7 Nov 2009 16:14:06 +0100 Subject: apply gui settings without restarting player --- callbacks.c | 83 ++++++++++++-- callbacks.h | 24 ++++ conf.c | 13 --- deadbeef.glade | 339 ++++++++++++++++++++++++++++++++++++++++++++++----------- deadbeef.h | 2 + interface.c | 172 +++++++++++++++++++++-------- main.c | 5 + palsa.c | 70 ++++++++++-- palsa.h | 6 + streamer.c | 24 +++- streamer.h | 3 + 11 files changed, 600 insertions(+), 141 deletions(-) diff --git a/callbacks.c b/callbacks.c index 3a0858e9..95801fda 100644 --- a/callbacks.c +++ b/callbacks.c @@ -1357,6 +1357,27 @@ on_add_audio_cd_activate (GtkMenuItem *menuitem, static GtkWidget *prefwin; +static char alsa_device_names[100][64]; +static int num_alsa_devices; + +static void +gtk_enum_sound_callback (const char *name, const char *desc, void *userdata) { + if (num_alsa_devices >= 100) { + fprintf (stderr, "wtf!! more than 100 alsa devices??\n"); + return; + } + GtkComboBox *combobox = GTK_COMBO_BOX (userdata); + gtk_combo_box_append_text (combobox, desc); + + if (!strcmp (conf_get_str ("alsa_soundcard", "default"), name)) { + gtk_combo_box_set_active (combobox, num_alsa_devices); + } + + strncpy (alsa_device_names[num_alsa_devices], name, 63); + alsa_device_names[num_alsa_devices][63] = 0; + num_alsa_devices++; +} + void on_preferences_activate (GtkMenuItem *menuitem, gpointer user_data) @@ -1365,19 +1386,18 @@ on_preferences_activate (GtkMenuItem *menuitem, gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (mainwin)); // alsa_soundcard - // FIXME: get list of soundcards from alsa + const char *s = conf_get_str ("alsa_soundcard", "default"); GtkComboBox *combobox = GTK_COMBO_BOX (lookup_widget (w, "pref_soundcard")); - if (strcasecmp (s, "default")) { - gtk_combo_box_append_text (combobox, s); - gtk_combo_box_set_active (combobox, 1); - } - else { + gtk_combo_box_append_text (combobox, "Default Audio Device"); + if (!strcmp (s, "default")) { gtk_combo_box_set_active (combobox, 0); } + num_alsa_devices = 1; + strcpy (alsa_device_names[0], "default"); + palsa_enum_soundcards (gtk_enum_sound_callback, combobox); // alsa resampling -// gtk_entry_set_text (GTK_ENTRY (lookup_widget (w, "pref_samplerate")), conf_get_str ("samplerate", "48000")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "pref_alsa_resampling")), conf_get_int ("alsa.resample", 0)); // src_quality @@ -1417,17 +1437,20 @@ void on_pref_soundcard_changed (GtkComboBox *combobox, gpointer user_data) { - char *text = gtk_combo_box_get_active_text (combobox); - conf_set_str ("alsa_soundcard", text ? text : "default"); + int active = gtk_combo_box_get_active (combobox); + if (active >= 0 && active < num_alsa_devices) { + conf_set_str ("alsa_soundcard", alsa_device_names[active]); + messagepump_push (M_CONFIGCHANGED, 0, 0, 0); + } } - void on_pref_alsa_resampling_clicked (GtkButton *button, gpointer user_data) { int active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); conf_set_int ("alsa.resample", active); + messagepump_push (M_CONFIGCHANGED, 0, 0, 0); } @@ -1437,6 +1460,7 @@ on_pref_src_quality_changed (GtkComboBox *combobox, { int active = gtk_combo_box_get_active (combobox); conf_set_int ("src_quality", active == -1 ? 2 : active); + messagepump_push (M_CONFIGCHANGED, 0, 0, 0); } @@ -1446,6 +1470,7 @@ on_pref_replaygain_mode_changed (GtkComboBox *combobox, { int active = gtk_combo_box_get_active (combobox); conf_set_int ("replaygain_mode", active == -1 ? 0 : active); + messagepump_push (M_CONFIGCHANGED, 0, 0, 0); } void @@ -1454,6 +1479,7 @@ on_pref_replaygain_scale_clicked (GtkButton *button, { int active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); conf_set_int ("replaygain_scale", active); + messagepump_push (M_CONFIGCHANGED, 0, 0, 0); } @@ -1463,6 +1489,7 @@ on_pref_close_send_to_tray_clicked (GtkButton *button, { int active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); conf_set_int ("close_send_to_tray", active); + messagepump_push (M_CONFIGCHANGED, 0, 0, 0); } @@ -1564,3 +1591,39 @@ on_remove_column_activate (GtkMenuItem *menuitem, } + +void +on_pref_alsa_freewhenstopped_clicked (GtkButton *button, + gpointer user_data) +{ + int active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); + conf_set_int ("alsa.freeonstop", active); +} + + + + + +void +on_pref_network_proxyaddress_changed (GtkEditable *editable, + gpointer user_data) +{ + +} + + +void +on_pref_network_enableproxy_clicked (GtkButton *button, + gpointer user_data) +{ + +} + + +void +on_pref_network_proxyport_changed (GtkEditable *editable, + gpointer user_data) +{ + +} + diff --git a/callbacks.h b/callbacks.h index 0f00fe82..e557823f 100644 --- a/callbacks.h +++ b/callbacks.h @@ -634,3 +634,27 @@ on_remove_column_activate (GtkMenuItem *menuitem, void on_pref_alsa_resampling_clicked (GtkButton *button, gpointer user_data); + +void +on_pref_alsa_freewhenstopped_clicked (GtkButton *button, + gpointer user_data); + +void +on_pref_soundcard_editing_done (GtkCellEditable *celleditable, + gpointer user_data); + +void +on_pref_soundcard_changed (GtkComboBox *combobox, + gpointer user_data); + +void +on_pref_network_proxyaddress_changed (GtkEditable *editable, + gpointer user_data); + +void +on_pref_network_enableproxy_clicked (GtkButton *button, + gpointer user_data); + +void +on_pref_network_proxyport_changed (GtkEditable *editable, + gpointer user_data); diff --git a/conf.c b/conf.c index 2a374193..378309b3 100644 --- a/conf.c +++ b/conf.c @@ -67,19 +67,6 @@ conf_load (void) { *p = 0; // new items are appended, to preserve order conf_set_str (str, value); -#if 0 - DB_conf_item_t *it = malloc (sizeof (DB_conf_item_t)); - memset (it, 0, sizeof (DB_conf_item_t)); - it->key = strdup (str); - it->value = strdup (value); - if (!tail) { - conf_items = it; - } - else { - tail->next = it; - } - tail = it; -#endif } fclose (fp); changed = 0; diff --git a/deadbeef.glade b/deadbeef.glade index d24847ac..4dcb1009 100644 --- a/deadbeef.glade +++ b/deadbeef.glade @@ -1327,7 +1327,7 @@ 3 True - 5 + 6 2 False 0 @@ -1336,7 +1336,7 @@ True - Soundcard + Output device False False GTK_JUSTIFY_LEFT @@ -1361,28 +1361,10 @@ - - - True - default - False - True - True - - - - 1 - 2 - 0 - 1 - fill - - - True - Enable alsa (software) resampling + Software ALSA resampling False False GTK_JUSTIFY_LEFT @@ -1410,7 +1392,7 @@ True - SRC quality + SRC quality (libsamplerate) False False GTK_JUSTIFY_LEFT @@ -1466,7 +1448,7 @@ True - Apply replaygain peak scale + Replaygain peak scale False False GTK_JUSTIFY_LEFT @@ -1491,6 +1473,56 @@ + + + True + Release ALSA while stopped + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 5 + 6 + fill + + + + + + + True + True + + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 1 + 2 + 1 + 2 + + + + True @@ -1509,11 +1541,48 @@ 2 4 5 - expand + + + True + True + + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 1 + 2 + 5 + 6 + + + + + + + True + False + True + + + + 1 + 2 + 0 + 1 + fill + + + True @@ -1531,7 +1600,6 @@ linear 2 2 3 - fill fill @@ -1551,13 +1619,79 @@ Album 2 3 4 - fill fill + + + False + True + + + + + + True + Sound + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + + + + + 3 + True + 1 + 2 + False + 0 + 3 - + + True + Close minimizes to tray + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + True True @@ -1567,14 +1701,13 @@ Album False False True - + 1 2 - 1 - 2 - expand + 0 + 1 @@ -1586,9 +1719,9 @@ Album - + True - Sound + GUI False False GTK_JUSTIFY_LEFT @@ -1609,19 +1742,19 @@ Album - + 3 True - 1 + 3 2 False 0 3 - + True - Close minimizes to tray + Enable proxy server False False GTK_JUSTIFY_LEFT @@ -1647,7 +1780,57 @@ Album - + + True + Proxy server address + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + True + True + True + 0 + + True + + False + + + + 1 + 2 + 1 + 2 + + + + + + True True @@ -1657,14 +1840,64 @@ Album False False True - + 1 2 0 1 - expand + fill + + + + + + + True + Proxy server port + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + True + True + True + 0 + + True + + False + + + + 1 + 2 + 2 + 3 @@ -1676,9 +1909,9 @@ Album - + True - GUI + Network False False GTK_JUSTIFY_LEFT @@ -1738,7 +1971,7 @@ Album 400 True - 5 + 4 2 False 0 @@ -1939,26 +2172,6 @@ Album - - - - True - True - Configure - True - GTK_RELIEF_NORMAL - True - - - - 1 - 2 - 4 - 5 - - - - True diff --git a/deadbeef.h b/deadbeef.h index 51f512dc..20fccd5d 100644 --- a/deadbeef.h +++ b/deadbeef.h @@ -115,6 +115,7 @@ enum { DB_EV_SONGSTARTED = 2, // triggers when song started playing (for scrobblers and such) DB_EV_SONGFINISHED = 3, // triggers when song finished playing (for scrobblers and such) DB_EV_TRACKDELETED = 4, // triggers when track is to be deleted from playlist + DB_EV_CONFIGCHANGED = 5, // configuration option changed DB_EV_MAX }; @@ -149,6 +150,7 @@ enum { M_PLAYLISTREFRESH, M_REINIT_SOUND, M_TRACKCHANGED, // p1=tracknumber + M_CONFIGCHANGED, // no arguments }; // typecasting macros diff --git a/interface.c b/interface.c index 53597b89..849c4c2a 100644 --- a/interface.c +++ b/interface.c @@ -1145,20 +1145,30 @@ create_prefwin (void) GtkWidget *notebook2; GtkWidget *table3; GtkWidget *label4; - GtkWidget *pref_soundcard; GtkWidget *label5; GtkWidget *label6; GtkWidget *label8; GtkWidget *label9; + GtkWidget *label15; + GtkWidget *pref_alsa_resampling; GtkWidget *pref_replaygain_scale; + GtkWidget *pref_alsa_freewhenstopped; + GtkWidget *pref_soundcard; GtkWidget *pref_src_quality; GtkWidget *pref_replaygain_mode; - GtkWidget *pref_alsa_resampling; GtkWidget *Sound; GtkWidget *table4; GtkWidget *label7; GtkWidget *pref_close_send_to_tray; GtkWidget *label2; + GtkWidget *table6; + GtkWidget *label17; + GtkWidget *label18; + GtkWidget *pref_network_proxyaddress; + GtkWidget *pref_network_enableproxy; + GtkWidget *label19; + GtkWidget *pref_network_proxyport; + GtkWidget *label16; GtkWidget *hpaned1; GtkWidget *scrolledwindow2; GtkWidget *pref_pluginlist; @@ -1171,7 +1181,6 @@ create_prefwin (void) GtkWidget *pref_plugin_author; GtkWidget *pref_plugin_email; GtkWidget *pref_plugin_website; - GtkWidget *pref_plugin_configure; GtkWidget *label3; prefwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); @@ -1183,34 +1192,27 @@ create_prefwin (void) gtk_widget_show (notebook2); gtk_container_add (GTK_CONTAINER (prefwin), notebook2); - table3 = gtk_table_new (5, 2, FALSE); + table3 = gtk_table_new (6, 2, FALSE); gtk_widget_show (table3); gtk_container_add (GTK_CONTAINER (notebook2), table3); gtk_container_set_border_width (GTK_CONTAINER (table3), 3); gtk_table_set_col_spacings (GTK_TABLE (table3), 3); - label4 = gtk_label_new ("Soundcard"); + label4 = gtk_label_new ("Output device"); gtk_widget_show (label4); gtk_table_attach (GTK_TABLE (table3), label4, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5); - pref_soundcard = gtk_combo_box_entry_new_text (); - gtk_widget_show (pref_soundcard); - gtk_table_attach (GTK_TABLE (table3), pref_soundcard, 1, 2, 0, 1, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 0, 0); - gtk_combo_box_append_text (GTK_COMBO_BOX (pref_soundcard), "default"); - - label5 = gtk_label_new ("Enable alsa (software) resampling"); + label5 = gtk_label_new ("Software ALSA resampling"); gtk_widget_show (label5); gtk_table_attach (GTK_TABLE (table3), label5, 0, 1, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label5), 0, 0.5); - label6 = gtk_label_new ("SRC quality"); + label6 = gtk_label_new ("SRC quality (libsamplerate)"); gtk_widget_show (label6); gtk_table_attach (GTK_TABLE (table3), label6, 0, 1, 2, 3, (GtkAttachOptions) (GTK_FILL), @@ -1224,23 +1226,48 @@ create_prefwin (void) (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label8), 0, 0.5); - label9 = gtk_label_new ("Apply replaygain peak scale"); + label9 = gtk_label_new ("Replaygain peak scale"); gtk_widget_show (label9); gtk_table_attach (GTK_TABLE (table3), label9, 0, 1, 4, 5, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label9), 0, 0.5); + label15 = gtk_label_new ("Release ALSA while stopped"); + gtk_widget_show (label15); + gtk_table_attach (GTK_TABLE (table3), label15, 0, 1, 5, 6, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label15), 0, 0.5); + + pref_alsa_resampling = gtk_check_button_new_with_mnemonic (""); + gtk_widget_show (pref_alsa_resampling); + gtk_table_attach (GTK_TABLE (table3), pref_alsa_resampling, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + pref_replaygain_scale = gtk_check_button_new_with_mnemonic (""); gtk_widget_show (pref_replaygain_scale); gtk_table_attach (GTK_TABLE (table3), pref_replaygain_scale, 1, 2, 4, 5, - (GtkAttachOptions) (GTK_EXPAND), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); + pref_alsa_freewhenstopped = gtk_check_button_new_with_mnemonic (""); + gtk_widget_show (pref_alsa_freewhenstopped); + gtk_table_attach (GTK_TABLE (table3), pref_alsa_freewhenstopped, 1, 2, 5, 6, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + pref_soundcard = gtk_combo_box_new_text (); + gtk_widget_show (pref_soundcard); + gtk_table_attach (GTK_TABLE (table3), pref_soundcard, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 0, 0); + pref_src_quality = gtk_combo_box_new_text (); gtk_widget_show (pref_src_quality); gtk_table_attach (GTK_TABLE (table3), pref_src_quality, 1, 2, 2, 3, - (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); gtk_combo_box_append_text (GTK_COMBO_BOX (pref_src_quality), "sinc_best_quality"); gtk_combo_box_append_text (GTK_COMBO_BOX (pref_src_quality), "sinc_medium_quality"); @@ -1251,18 +1278,12 @@ create_prefwin (void) pref_replaygain_mode = gtk_combo_box_new_text (); gtk_widget_show (pref_replaygain_mode); gtk_table_attach (GTK_TABLE (table3), pref_replaygain_mode, 1, 2, 3, 4, - (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); gtk_combo_box_append_text (GTK_COMBO_BOX (pref_replaygain_mode), "Disable"); gtk_combo_box_append_text (GTK_COMBO_BOX (pref_replaygain_mode), "Track"); gtk_combo_box_append_text (GTK_COMBO_BOX (pref_replaygain_mode), "Album"); - pref_alsa_resampling = gtk_check_button_new_with_mnemonic (""); - gtk_widget_show (pref_alsa_resampling); - gtk_table_attach (GTK_TABLE (table3), pref_alsa_resampling, 1, 2, 1, 2, - (GtkAttachOptions) (GTK_EXPAND), - (GtkAttachOptions) (0), 0, 0); - Sound = gtk_label_new ("Sound"); gtk_widget_show (Sound); gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 0), Sound); @@ -1283,13 +1304,64 @@ create_prefwin (void) pref_close_send_to_tray = gtk_check_button_new_with_mnemonic (""); gtk_widget_show (pref_close_send_to_tray); gtk_table_attach (GTK_TABLE (table4), pref_close_send_to_tray, 1, 2, 0, 1, - (GtkAttachOptions) (GTK_EXPAND), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); label2 = gtk_label_new ("GUI"); gtk_widget_show (label2); gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 1), label2); + table6 = gtk_table_new (3, 2, FALSE); + gtk_widget_show (table6); + gtk_container_add (GTK_CONTAINER (notebook2), table6); + gtk_container_set_border_width (GTK_CONTAINER (table6), 3); + gtk_table_set_col_spacings (GTK_TABLE (table6), 3); + + label17 = gtk_label_new ("Enable proxy server"); + gtk_widget_show (label17); + gtk_table_attach (GTK_TABLE (table6), label17, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label17), 0, 0.5); + + label18 = gtk_label_new ("Proxy server address"); + gtk_widget_show (label18); + gtk_table_attach (GTK_TABLE (table6), label18, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label18), 0, 0.5); + + pref_network_proxyaddress = gtk_entry_new (); + gtk_widget_show (pref_network_proxyaddress); + gtk_table_attach (GTK_TABLE (table6), pref_network_proxyaddress, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_entry_set_invisible_char (GTK_ENTRY (pref_network_proxyaddress), 8226); + + pref_network_enableproxy = gtk_check_button_new_with_mnemonic (""); + gtk_widget_show (pref_network_enableproxy); + gtk_table_attach (GTK_TABLE (table6), pref_network_enableproxy, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + + label19 = gtk_label_new ("Proxy server port"); + gtk_widget_show (label19); + gtk_table_attach (GTK_TABLE (table6), label19, 0, 1, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label19), 0, 0.5); + + pref_network_proxyport = gtk_entry_new (); + gtk_widget_show (pref_network_proxyport); + gtk_table_attach (GTK_TABLE (table6), pref_network_proxyport, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_entry_set_invisible_char (GTK_ENTRY (pref_network_proxyport), 8226); + + label16 = gtk_label_new ("Network"); + gtk_widget_show (label16); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 2), label16); + hpaned1 = gtk_hpaned_new (); gtk_widget_show (hpaned1); gtk_container_add (GTK_CONTAINER (notebook2), hpaned1); @@ -1305,7 +1377,7 @@ create_prefwin (void) gtk_widget_show (pref_pluginlist); gtk_container_add (GTK_CONTAINER (scrolledwindow2), pref_pluginlist); - table5 = gtk_table_new (5, 2, FALSE); + table5 = gtk_table_new (4, 2, FALSE); gtk_widget_show (table5); gtk_paned_pack2 (GTK_PANED (hpaned1), table5, TRUE, TRUE); gtk_widget_set_size_request (table5, 400, -1); @@ -1370,60 +1442,73 @@ create_prefwin (void) gtk_editable_set_editable (GTK_EDITABLE (pref_plugin_website), FALSE); gtk_entry_set_invisible_char (GTK_ENTRY (pref_plugin_website), 9679); - pref_plugin_configure = gtk_button_new_with_mnemonic ("Configure"); - gtk_widget_show (pref_plugin_configure); - gtk_table_attach (GTK_TABLE (table5), pref_plugin_configure, 1, 2, 4, 5, - (GtkAttachOptions) (0), - (GtkAttachOptions) (0), 0, 0); - label3 = gtk_label_new ("Plugins"); gtk_widget_show (label3); - gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 2), label3); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook2), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook2), 3), label3); - g_signal_connect ((gpointer) pref_soundcard, "changed", - G_CALLBACK (on_pref_soundcard_changed), + g_signal_connect ((gpointer) pref_alsa_resampling, "clicked", + G_CALLBACK (on_pref_alsa_resampling_clicked), NULL); g_signal_connect ((gpointer) pref_replaygain_scale, "clicked", G_CALLBACK (on_pref_replaygain_scale_clicked), NULL); + g_signal_connect ((gpointer) pref_alsa_freewhenstopped, "clicked", + G_CALLBACK (on_pref_alsa_freewhenstopped_clicked), + NULL); + g_signal_connect ((gpointer) pref_soundcard, "changed", + G_CALLBACK (on_pref_soundcard_changed), + NULL); g_signal_connect ((gpointer) pref_src_quality, "changed", G_CALLBACK (on_pref_src_quality_changed), NULL); g_signal_connect ((gpointer) pref_replaygain_mode, "changed", G_CALLBACK (on_pref_replaygain_mode_changed), NULL); - g_signal_connect ((gpointer) pref_alsa_resampling, "clicked", - G_CALLBACK (on_pref_alsa_resampling_clicked), - NULL); g_signal_connect ((gpointer) pref_close_send_to_tray, "clicked", G_CALLBACK (on_pref_close_send_to_tray_clicked), NULL); + g_signal_connect ((gpointer) pref_network_proxyaddress, "changed", + G_CALLBACK (on_pref_network_proxyaddress_changed), + NULL); + g_signal_connect ((gpointer) pref_network_enableproxy, "clicked", + G_CALLBACK (on_pref_network_enableproxy_clicked), + NULL); + g_signal_connect ((gpointer) pref_network_proxyport, "changed", + G_CALLBACK (on_pref_network_proxyport_changed), + NULL); g_signal_connect ((gpointer) pref_pluginlist, "cursor_changed", G_CALLBACK (on_pref_pluginlist_cursor_changed), NULL); - g_signal_connect ((gpointer) pref_plugin_configure, "clicked", - G_CALLBACK (on_pref_plugin_configure_activate), - NULL); /* Store pointers to all widgets, for use by lookup_widget(). */ GLADE_HOOKUP_OBJECT_NO_REF (prefwin, prefwin, "prefwin"); GLADE_HOOKUP_OBJECT (prefwin, notebook2, "notebook2"); GLADE_HOOKUP_OBJECT (prefwin, table3, "table3"); GLADE_HOOKUP_OBJECT (prefwin, label4, "label4"); - GLADE_HOOKUP_OBJECT (prefwin, pref_soundcard, "pref_soundcard"); GLADE_HOOKUP_OBJECT (prefwin, label5, "label5"); GLADE_HOOKUP_OBJECT (prefwin, label6, "label6"); GLADE_HOOKUP_OBJECT (prefwin, label8, "label8"); GLADE_HOOKUP_OBJECT (prefwin, label9, "label9"); + GLADE_HOOKUP_OBJECT (prefwin, label15, "label15"); + GLADE_HOOKUP_OBJECT (prefwin, pref_alsa_resampling, "pref_alsa_resampling"); GLADE_HOOKUP_OBJECT (prefwin, pref_replaygain_scale, "pref_replaygain_scale"); + GLADE_HOOKUP_OBJECT (prefwin, pref_alsa_freewhenstopped, "pref_alsa_freewhenstopped"); + GLADE_HOOKUP_OBJECT (prefwin, pref_soundcard, "pref_soundcard"); GLADE_HOOKUP_OBJECT (prefwin, pref_src_quality, "pref_src_quality"); GLADE_HOOKUP_OBJECT (prefwin, pref_replaygain_mode, "pref_replaygain_mode"); - GLADE_HOOKUP_OBJECT (prefwin, pref_alsa_resampling, "pref_alsa_resampling"); GLADE_HOOKUP_OBJECT (prefwin, Sound, "Sound"); GLADE_HOOKUP_OBJECT (prefwin, table4, "table4"); GLADE_HOOKUP_OBJECT (prefwin, label7, "label7"); GLADE_HOOKUP_OBJECT (prefwin, pref_close_send_to_tray, "pref_close_send_to_tray"); GLADE_HOOKUP_OBJECT (prefwin, label2, "label2"); + GLADE_HOOKUP_OBJECT (prefwin, table6, "table6"); + GLADE_HOOKUP_OBJECT (prefwin, label17, "label17"); + GLADE_HOOKUP_OBJECT (prefwin, label18, "label18"); + GLADE_HOOKUP_OBJECT (prefwin, pref_network_proxyaddress, "pref_network_proxyaddress"); + GLADE_HOOKUP_OBJECT (prefwin, pref_network_enableproxy, "pref_network_enableproxy"); + GLADE_HOOKUP_OBJECT (prefwin, label19, "label19"); + GLADE_HOOKUP_OBJECT (prefwin, pref_network_proxyport, "pref_network_proxyport"); + GLADE_HOOKUP_OBJECT (prefwin, label16, "label16"); GLADE_HOOKUP_OBJECT (prefwin, hpaned1, "hpaned1"); GLADE_HOOKUP_OBJECT (prefwin, scrolledwindow2, "scrolledwindow2"); GLADE_HOOKUP_OBJECT (prefwin, pref_pluginlist, "pref_pluginlist"); @@ -1436,7 +1521,6 @@ create_prefwin (void) GLADE_HOOKUP_OBJECT (prefwin, pref_plugin_author, "pref_plugin_author"); GLADE_HOOKUP_OBJECT (prefwin, pref_plugin_email, "pref_plugin_email"); GLADE_HOOKUP_OBJECT (prefwin, pref_plugin_website, "pref_plugin_website"); - GLADE_HOOKUP_OBJECT (prefwin, pref_plugin_configure, "pref_plugin_configure"); GLADE_HOOKUP_OBJECT (prefwin, label3, "label3"); return prefwin; diff --git a/main.c b/main.c index 65d5d0d9..13967195 100644 --- a/main.c +++ b/main.c @@ -474,6 +474,11 @@ player_thread (uintptr_t ctx) { search_refresh (); GDK_THREADS_LEAVE(); break; + case M_CONFIGCHANGED: + palsa_configchanged (); + streamer_configchanged (); + plug_trigger_event (DB_EV_CONFIGCHANGED, 0); + break; } } usleep(50000); diff --git a/palsa.c b/palsa.c index f7061359..80ec577b 100644 --- a/palsa.c +++ b/palsa.c @@ -42,6 +42,9 @@ static int state; // 0 = stopped, 1 = playing, 2 = pause static uintptr_t mutex; static intptr_t alsa_tid; +static int conf_alsa_resample = 0; +static char conf_alsa_soundcard[100] = "default"; + static void palsa_callback (char *stream, int len); @@ -51,7 +54,7 @@ palsa_thread (uintptr_t context); static int palsa_set_hw_params (int samplerate) { snd_pcm_hw_params_t *hw_params = NULL; - int alsa_resample = conf_get_int ("alsa.resample", 0); +// int alsa_resample = conf_get_int ("alsa.resample", 0); int err = 0; if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) { @@ -85,12 +88,12 @@ palsa_set_hw_params (int samplerate) { } snd_pcm_hw_params_get_format (hw_params, &fmt); - printf ("chosen sample format: %04Xh\n", (int)fmt); + trace ("chosen sample format: %04Xh\n", (int)fmt); int val = samplerate; int ret = 0; - if ((err = snd_pcm_hw_params_set_rate_resample (audio, hw_params, alsa_resample)) < 0) { + if ((err = snd_pcm_hw_params_set_rate_resample (audio, hw_params, conf_alsa_resample)) < 0) { trace ("cannot setup resampling (%s)\n", snd_strerror (err)); goto error; @@ -102,7 +105,7 @@ palsa_set_hw_params (int samplerate) { goto error; } alsa_rate = val; - printf ("chosen samplerate: %d Hz\n", alsa_rate); + trace ("chosen samplerate: %d Hz\n", alsa_rate); if ((err = snd_pcm_hw_params_set_channels (audio, hw_params, 2)) < 0) { trace ("cannot set channel count (%s)\n", @@ -112,7 +115,7 @@ palsa_set_hw_params (int samplerate) { int nchan; snd_pcm_hw_params_get_channels (hw_params, &nchan); - printf ("alsa channels: %d\n", nchan); + trace ("alsa channels: %d\n", nchan); unsigned int buffer_time = 500000; int dir; @@ -144,9 +147,16 @@ error: int palsa_init (void) { int err; + + // get and cache conf variables + strcpy (conf_alsa_soundcard, conf_get_str ("alsa_soundcard", "default")); + conf_alsa_resample = conf_get_int ("alsa.resample", 0); + trace ("alsa_soundcard: %s\n", conf_alsa_soundcard); + trace ("alsa.resample: %d\n", conf_alsa_resample); + snd_pcm_sw_params_t *sw_params = NULL; state = 0; - const char *conf_alsa_soundcard = conf_get_str ("alsa_soundcard", "default"); + //const char *conf_alsa_soundcard = conf_get_str ("alsa_soundcard", "default"); if ((err = snd_pcm_open (&audio, conf_alsa_soundcard, SND_PCM_STREAM_PLAYBACK, 0))) { trace ("could not open audio device (%s)\n", snd_strerror (err)); @@ -226,6 +236,9 @@ open_error: int palsa_change_rate (int rate) { + if (!audio) { + return 0; + } if (rate == alsa_rate) { trace ("palsa_change_rate: same rate (%d), ignored\n", rate); return rate; @@ -262,6 +275,9 @@ palsa_free (void) { static void palsa_hw_pause (int pause) { + if (!audio) { + return; + } if (state == 0) { return; } @@ -306,8 +322,7 @@ palsa_stop (void) { return 0; } state = 0; - int freeonstop = conf_get_int ("alsa.freeonstop", 0); - if (freeonstop) { + if (conf_get_int ("alsa.freeonstop", 0)) { palsa_free (); } else { @@ -466,3 +481,42 @@ palsa_callback (char *stream, int len) { memset (stream + bytesread, 0, len-bytesread); } } + +void +palsa_configchanged (void) { + int alsa_resample = conf_get_int ("alsa.resample", 0); + const char *alsa_soundcard = conf_get_str ("alsa_soundcard", "default"); + if (alsa_resample != conf_alsa_resample + || strcmp (alsa_soundcard, conf_alsa_soundcard)) { + messagepump_push (M_REINIT_SOUND, 0, 0, 0); + } +} + +// derived from alsa-utils/aplay.c +void +palsa_enum_soundcards (void (*callback)(const char *name, const char *desc, void *), void *userdata) { + void **hints, **n; + char *name, *descr, *descr1, *io; + const char *filter = "Output"; + if (snd_device_name_hint(-1, "pcm", &hints) < 0) + return; + n = hints; + while (*n != NULL) { + name = snd_device_name_get_hint(*n, "NAME"); + descr = snd_device_name_get_hint(*n, "DESC"); + io = snd_device_name_get_hint(*n, "IOID"); + if (io == NULL || !strcmp(io, filter)) { + if (name && descr && callback) { + callback (name, descr, userdata); + } + } + if (name != NULL) + free(name); + if (descr != NULL) + free(descr); + if (io != NULL) + free(io); + n++; + } + snd_device_name_free_hint(hints); +} diff --git a/palsa.h b/palsa.h index 292a1d4f..2896702a 100644 --- a/palsa.h +++ b/palsa.h @@ -48,5 +48,11 @@ palsa_unpause (void); int palsa_get_rate (void); +void +palsa_configchanged (void); + +void +palsa_enum_soundcards (void (*callback)(const char *name, const char *desc, void*), void *userdata); + #endif // __PALSA_H diff --git a/streamer.c b/streamer.c index b4dd2d21..2d7cd377 100644 --- a/streamer.c +++ b/streamer.c @@ -40,6 +40,7 @@ #define trace(fmt,...) static intptr_t streamer_tid; +static int src_quality; static SRC_STATE *src; static SRC_DATA srcdata; static int codecleft; @@ -422,9 +423,8 @@ streamer_thread (uintptr_t ctx) { int streamer_init (void) { mutex = mutex_create (); -// src = src_new (SRC_SINC_BEST_QUALITY, 2, NULL); -// src = src_new (SRC_LINEAR, 2, NULL); - src = src_new (conf_get_int ("src_quality", 2), 2, NULL); + src_quality = conf_get_int ("src_quality", 2); + src = src_new (src_quality, 2, NULL); conf_replaygain_mode = conf_get_int ("replaygain_mode", 0); conf_replaygain_scale = conf_get_int ("replaygain_scale", 1); if (!src) { @@ -831,3 +831,21 @@ streamer_is_buffering (void) { return 0; } } + +void +streamer_configchanged (void) { + conf_replaygain_mode = conf_get_int ("replaygain_mode", 0); + conf_replaygain_scale = conf_get_int ("replaygain_scale", 1); + int q = conf_get_int ("src_quality", 2); + if (q != src_quality && q >= SRC_SINC_BEST_QUALITY && q <= SRC_LINEAR) { + fprintf (stderr, "changing src_quality from %d to %d\n", src_quality, q); + src_quality = q; + streamer_lock (); + if (src) { + src_delete (src); + src = NULL; + } + src = src_new (src_quality, 2, NULL); + streamer_unlock (); + } +} diff --git a/streamer.h b/streamer.h index 5284380a..9544c755 100644 --- a/streamer.h +++ b/streamer.h @@ -75,4 +75,7 @@ streamer_song_removed_notify (playItem_t *it); playItem_t * streamer_get_streaming_track (void); +void +streamer_configchanged (void); + #endif // __STREAMER_H -- cgit v1.2.3