From 0cf1d57bc3dab11f773d23a25db0c3d18f6cfe52 Mon Sep 17 00:00:00 2001 From: waker Date: Sun, 28 Nov 2010 17:24:14 +0100 Subject: ported supereq to new api; converted to float; added reentrancy support --- plugins/gtkui/eq.c | 127 +++++++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 57 deletions(-) (limited to 'plugins/gtkui/eq.c') diff --git a/plugins/gtkui/eq.c b/plugins/gtkui/eq.c index a40e1900..c7a82dea 100644 --- a/plugins/gtkui/eq.c +++ b/plugins/gtkui/eq.c @@ -40,79 +40,88 @@ amp_to_db (float amp) { return 20*log10 (amp); } -DB_supereq_dsp_t * -get_supereq_plugin (void) { - DB_dsp_t **plugs = deadbeef->plug_get_dsp_list (); - for (int i = 0; plugs[i]; i++) { - if (plugs[i]->plugin.id && !strcmp (plugs[i]->plugin.id, "supereq")) { - return (DB_supereq_dsp_t *)plugs[i]; +DB_dsp_instance_t * +get_supereq (void) { + DB_dsp_instance_t *dsp = deadbeef->streamer_get_dsp_chain (); + while (dsp) { + if (!strcmp (dsp->plugin->plugin.id, "supereq")) { + return dsp; } + dsp = dsp->next; } + return NULL; } void eq_value_changed (DdbEqualizer *widget) { - DB_supereq_dsp_t *eq = get_supereq_plugin (); - for (int i = 0; i < 18; i++) { - eq->set_band (i, db_to_amp (ddb_equalizer_get_band (widget, i))); + DB_dsp_instance_t *eq = get_supereq (); + if (eq) { + DB_supereq_dsp_t *plugin = (DB_supereq_dsp_t *)eq->plugin; + for (int i = 0; i < 18; i++) { + plugin->set_band (eq, i, db_to_amp (ddb_equalizer_get_band (widget, i))); + } + plugin->set_preamp (eq, db_to_amp (ddb_equalizer_get_preamp (widget))); } - eq->set_preamp (db_to_amp (ddb_equalizer_get_preamp (widget))); } void on_enable_toggled (GtkToggleButton *togglebutton, gpointer user_data) { -#if 0 // !!!! FIXME !!!! - DB_supereq_dsp_t *eq = get_supereq_plugin (); - eq->dsp.enabled = gtk_toggle_button_get_active (togglebutton) ? 1 : 0; -#endif + DB_dsp_instance_t *eq = get_supereq (); + if (eq) { + DB_supereq_dsp_t *plugin = (DB_supereq_dsp_t *)eq->plugin; + plugin->dsp.enable (eq, gtk_toggle_button_get_active (togglebutton) ? 1 : 0); + } } void on_zero_all_clicked (GtkButton *button, gpointer user_data) { -#if 0 // !!!! FIXME !!!! if (eqwin) { - DB_supereq_dsp_t *eq = get_supereq_plugin (); - eq->set_preamp (1); - ddb_equalizer_set_preamp (DDB_EQUALIZER (eqwin), 0); - for (int i = 0; i < 18; i++) { - ddb_equalizer_set_band (DDB_EQUALIZER (eqwin), i, 0); - eq->set_band (i, 1); + DB_dsp_instance_t *eq = get_supereq (); + if (eq) { + DB_supereq_dsp_t *plugin = (DB_supereq_dsp_t *)eq->plugin; + plugin->set_preamp (eq, 1); + ddb_equalizer_set_preamp (DDB_EQUALIZER (eqwin), 0); + for (int i = 0; i < 18; i++) { + ddb_equalizer_set_band (DDB_EQUALIZER (eqwin), i, 0); + plugin->set_band (eq, i, 1); + } + gdk_window_invalidate_rect (eqwin->window, NULL, FALSE); } - gdk_window_invalidate_rect (eqwin->window, NULL, FALSE); } -#endif } void on_zero_preamp_clicked (GtkButton *button, gpointer user_data) { -#if 0 // !!!! FIXME !!!! if (eqwin) { - DB_supereq_dsp_t *eq = get_supereq_plugin (); - eq->set_preamp (1); - ddb_equalizer_set_preamp (DDB_EQUALIZER (eqwin), 0); - gdk_window_invalidate_rect (eqwin->window, NULL, FALSE); + DB_dsp_instance_t *eq = get_supereq (); + if (eq) { + DB_supereq_dsp_t *plugin = (DB_supereq_dsp_t *)eq->plugin; + plugin->set_preamp (eq, 1); + ddb_equalizer_set_preamp (DDB_EQUALIZER (eqwin), 0); + gdk_window_invalidate_rect (eqwin->window, NULL, FALSE); + } } -#endif } void on_zero_bands_clicked (GtkButton *button, gpointer user_data) { -#if 0 // !!!! FIXME !!!! if (eqwin) { - DB_supereq_dsp_t *eq = get_supereq_plugin (); - for (int i = 0; i < 18; i++) { - ddb_equalizer_set_band (DDB_EQUALIZER (eqwin), i, 0); - eq->set_band (i, 1); + DB_dsp_instance_t *eq = get_supereq (); + if (eq) { + DB_supereq_dsp_t *plugin = (DB_supereq_dsp_t *)eq->plugin; + for (int i = 0; i < 18; i++) { + ddb_equalizer_set_band (DDB_EQUALIZER (eqwin), i, 0); + plugin->set_band (eq, i, 1); + } + gdk_window_invalidate_rect (eqwin->window, NULL, FALSE); } - gdk_window_invalidate_rect (eqwin->window, NULL, FALSE); } -#endif } void @@ -138,11 +147,14 @@ on_save_preset_clicked (GtkButton *button, if (fname) { FILE *fp = fopen (fname, "w+b"); if (fp) { - DB_supereq_dsp_t *eq = get_supereq_plugin (); - for (int i = 0; i < 18; i++) { - fprintf (fp, "%f\n", amp_to_db (eq->get_band (i))); + DB_dsp_instance_t *eq = get_supereq (); + if (eq) { + DB_supereq_dsp_t *plugin = (DB_supereq_dsp_t *)eq->plugin; + for (int i = 0; i < 18; i++) { + fprintf (fp, "%f\n", amp_to_db (plugin->get_band (eq, i))); + } + fprintf (fp, "%f\n", amp_to_db (plugin->get_preamp (eq))); } - fprintf (fp, "%f\n", amp_to_db (eq->get_preamp ())); fclose (fp); } g_free (fname); @@ -194,13 +206,14 @@ on_load_preset_clicked (GtkButton *button, fclose (fp); if (i == 19) { // apply and save config - DB_supereq_dsp_t *eq = get_supereq_plugin (); + DB_dsp_instance_t *eq = get_supereq (); if (eq) { - eq->set_preamp (db_to_amp (vals[18])); + DB_supereq_dsp_t *plugin = (DB_supereq_dsp_t *)eq->plugin; + plugin->set_preamp (eq, db_to_amp (vals[18])); ddb_equalizer_set_preamp (DDB_EQUALIZER (eqwin), vals[18]); for (int i = 0; i < 18; i++) { ddb_equalizer_set_band (DDB_EQUALIZER (eqwin), i, vals[i]); - eq->set_band (i, db_to_amp (vals[i])); + plugin->set_band (eq, i, db_to_amp (vals[i])); } gdk_window_invalidate_rect (eqwin->window, NULL, FALSE); deadbeef->conf_save (); @@ -257,13 +270,14 @@ on_import_fb2k_preset_clicked (GtkButton *button, fclose (fp); if (i == 18) { // apply and save config - DB_supereq_dsp_t *eq = get_supereq_plugin (); + DB_dsp_instance_t *eq = get_supereq (); if (eq) { - eq->set_preamp (1); + DB_supereq_dsp_t *plugin = (DB_supereq_dsp_t *)eq->plugin; + plugin->set_preamp (eq, 1); ddb_equalizer_set_preamp (DDB_EQUALIZER (eqwin), 0); for (int i = 0; i < 18; i++) { ddb_equalizer_set_band (DDB_EQUALIZER (eqwin), i, vals[i]); - eq->set_band (i, db_to_amp (vals[i])); + plugin->set_band (eq, i, db_to_amp (vals[i])); } gdk_window_invalidate_rect (eqwin->window, NULL, FALSE); deadbeef->conf_save (); @@ -281,10 +295,6 @@ on_import_fb2k_preset_clicked (GtkButton *button, void eq_window_show (void) { - DB_supereq_dsp_t *eq = get_supereq_plugin (); - if (!eq) { - return; - } if (!eqcont) { eqcont = gtk_vbox_new (FALSE, 8); GtkWidget *parent= lookup_widget (mainwin, "plugins_bottom_vbox"); @@ -300,7 +310,8 @@ eq_window_show (void) { eqenablebtn = button = gtk_check_button_new_with_label (_("Enable")); gtk_widget_show (button); gtk_box_pack_start (GTK_BOX (buttons), button, FALSE, FALSE, 0); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (eqenablebtn), deadbeef->conf_get_int ("supereq.enable", 0)); + DB_dsp_instance_t *eq = get_supereq (); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (eqenablebtn), eq ? eq->enabled : 0); g_signal_connect ((gpointer) button, "toggled", G_CALLBACK (on_enable_toggled), NULL); @@ -351,12 +362,14 @@ eq_window_show (void) { g_signal_connect (eqwin, "on_changed", G_CALLBACK (eq_value_changed), 0); gtk_widget_set_size_request (eqwin, -1, 200); - - ddb_equalizer_set_preamp (DDB_EQUALIZER (eqwin), amp_to_db (eq->get_preamp ())); - for (int i = 0; i < 18; i++) { - if (eq) { - float val = eq->get_band (i); - ddb_equalizer_set_band (DDB_EQUALIZER (eqwin), i, amp_to_db (val)); + if (eq) { + DB_supereq_dsp_t *plugin = (DB_supereq_dsp_t *)eq->plugin; + ddb_equalizer_set_preamp (DDB_EQUALIZER (eqwin), amp_to_db (plugin->get_preamp (eq))); + for (int i = 0; i < 18; i++) { + if (eq) { + float val = plugin->get_band (eq, i); + ddb_equalizer_set_band (DDB_EQUALIZER (eqwin), i, amp_to_db (val)); + } } } -- cgit v1.2.3