From 192b3b3ce3d1f9b49dc8abb87f79cdf40e7a0e15 Mon Sep 17 00:00:00 2001 From: waker Date: Sun, 12 Dec 2010 18:27:36 +0100 Subject: added support for writing converted output directly to WAV file --- plugins/gtkui/callbacks.h | 12 +++++ plugins/gtkui/converter.c | 116 ++++++++++++++++++++++++++++++------------- plugins/gtkui/deadbeef.glade | 91 +++++++++++++++++++++++++++------ plugins/gtkui/interface.c | 35 ++++++++++++- 4 files changed, 204 insertions(+), 50 deletions(-) (limited to 'plugins') diff --git a/plugins/gtkui/callbacks.h b/plugins/gtkui/callbacks.h index 6f31d798..0853eaab 100644 --- a/plugins/gtkui/callbacks.h +++ b/plugins/gtkui/callbacks.h @@ -1077,3 +1077,15 @@ on_converter_dsp_preset_changed (GtkComboBox *combobox, void on_dsp_preset_plugin_configure_clicked (GtkButton *button, gpointer user_data); + +void +on_dsp_preset_plugin_up_clicked (GtkButton *button, + gpointer user_data); + +void +on_dsp_preset_plugin_down_clicked (GtkButton *button, + gpointer user_data); + +void +on_converter_output_format_changed (GtkComboBox *combobox, + gpointer user_data); diff --git a/plugins/gtkui/converter.c b/plugins/gtkui/converter.c index 47fd4ed8..291c9973 100644 --- a/plugins/gtkui/converter.c +++ b/plugins/gtkui/converter.c @@ -70,28 +70,40 @@ ddb_encoder_preset_load (const char *fname) { ddb_encoder_preset_t *p = ddb_encoder_preset_alloc (); char str[1024]; + char item[20]; - if (1 != fscanf (fp, "title %1024[^\n]\n", str)) { - goto error; - } - p->title = strdup (str); - - if (1 != fscanf (fp, "fname %1024[^\n]\n", str)) { - goto error; - } - p->fname = strdup (str); + while (fgets (str, sizeof (str), fp)) { + // chomp + char *cr = str + strlen (str) - 1; + while (*cr == '\n') { + cr--; + } + cr++; + *cr = 0; - if (1 != fscanf (fp, "encoder %1024[^\n]\n", str)) { - goto error; - } - p->encoder = strdup (str); + char *sp = strchr (str, ' '); + if (!sp) { + continue; + } - if (1 != fscanf (fp, "method %d\n", &p->method)) { - goto error; - } + *sp = 0; + char *item = sp + 1; - if (1 != fscanf (fp, "formats %X\n", &p->formats)) { - goto error; + if (!strcmp (str, "title")) { + p->title = strdup (item); + } + else if (!strcmp (str, "fname")) { + p->fname = strdup (item); + } + else if (!strcmp (str, "encoder")) { + p->encoder = strdup (item); + } + else if (!strcmp (str, "method")) { + p->method = atoi (item); + } + else if (!strcmp (str, "formats")) { + sscanf (item, "%X", &p->formats); + } } err = 0; @@ -415,12 +427,6 @@ load_dsp_presets (void) { free (namelist[i]); } free (namelist); - - // prepend empty preset - ddb_dsp_preset_t *p = ddb_dsp_preset_alloc (); - p->title = strdup ("Pass through"); - p->next = dsp_presets; - dsp_presets = p; return 0; } @@ -447,8 +453,12 @@ converter_show (void) { // fill dsp presets combo = GTK_COMBO_BOX (lookup_widget (converter, "dsp_preset")); mdl = GTK_LIST_STORE (gtk_combo_box_get_model (combo)); + GtkTreeIter iter; + gtk_list_store_append (mdl, &iter); + gtk_list_store_set (mdl, &iter, 0, "Pass through", -1); fill_presets (mdl, (ddb_preset_t *)dsp_presets); - gtk_combo_box_set_active (combo, deadbeef->conf_get_int ("converter.dsp_preset", 0)); + + gtk_combo_box_set_active (combo, deadbeef->conf_get_int ("converter.dsp_preset", -1) + 1); // fill channel maps combo = GTK_COMBO_BOX (lookup_widget (converter, "channelmap")); @@ -477,7 +487,7 @@ on_converter_dsp_preset_changed (GtkComboBox *combobox, { GtkComboBox *combo = GTK_COMBO_BOX (lookup_widget (converter, "dsp_preset")); int act = gtk_combo_box_get_active (combo); - deadbeef->conf_set_int ("converter.dsp_preset", act); + deadbeef->conf_set_int ("converter.dsp_preset", act-1); } void @@ -556,7 +566,7 @@ on_converter_ok_clicked (GtkButton *button, return; } combo = GTK_COMBO_BOX (lookup_widget (converter, "dsp_preset")); - int dsp_idx = gtk_combo_box_get_active (combo); + int dsp_idx = gtk_combo_box_get_active (combo) - 1; combo = GTK_COMBO_BOX (lookup_widget (converter, "output_format")); int selected_format = gtk_combo_box_get_active (combo); @@ -586,7 +596,7 @@ on_converter_ok_clicked (GtkButton *button, deadbeef->pl_unlock (); ddb_dsp_preset_t *dsp_preset = NULL; - if (dsp_idx > 0) { + if (dsp_idx >= 0) { dsp_preset = dsp_presets; while (dsp_preset && dsp_idx--) { dsp_preset = dsp_preset->next; @@ -615,7 +625,18 @@ on_converter_ok_clicked (GtkButton *button, FILE *enc_pipe = NULL; FILE *temp_file = NULL; - if (p->method == DDB_ENCODER_METHOD_FILE) { + if (!p->encoder[0]) { + // write to wave file + temp_file = fopen (out, "w+b"); + if (!temp_file) { + fprintf (stderr, "converter: failed to open output wave file %s\n", out); + if (fileinfo) { + dec->free (fileinfo); + } + continue; + } + } + else if (p->method == DDB_ENCODER_METHOD_FILE) { const char *temp_file_name = "/tmp/deadbeef-converter.wav"; // FIXME temp_file = fopen (temp_file_name, "w+b"); if (!temp_file) { @@ -751,7 +772,7 @@ on_converter_ok_clicked (GtkButton *button, fclose (temp_file); } - if (p->method == DDB_ENCODER_METHOD_FILE) { + if (p->encoder[0] && p->method == DDB_ENCODER_METHOD_FILE) { enc_pipe = popen (enc, "w"); } @@ -1277,6 +1298,22 @@ on_dsp_preset_plugin_configure_clicked (GtkButton *button, gtk_widget_destroy (dlg); } +void +on_dsp_preset_plugin_up_clicked (GtkButton *button, + gpointer user_data) +{ + +} + + +void +on_dsp_preset_plugin_down_clicked (GtkButton *button, + gpointer user_data) +{ + +} + + int edit_dsp_preset (const char *title, GtkWidget *toplevel, int overwrite) { int r = GTK_RESPONSE_CANCEL; @@ -1531,15 +1568,26 @@ on_edit_dsp_presets_clicked (GtkButton *button, GtkListStore *mdl = gtk_list_store_new (1, G_TYPE_STRING); gtk_tree_view_set_model (GTK_TREE_VIEW (list), GTK_TREE_MODEL (mdl)); fill_presets (mdl, (ddb_preset_t *)dsp_presets); - int curr = deadbeef->conf_get_int ("converter.dsp_preset", 0); - GtkTreePath *path = gtk_tree_path_new_from_indices (curr, -1); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (list), path, col, FALSE); - gtk_tree_path_free (path); + int curr = deadbeef->conf_get_int ("converter.dsp_preset", -1); + if (curr >= 0) { + GtkTreePath *path = gtk_tree_path_new_from_indices (curr, -1); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (list), path, col, FALSE); + gtk_tree_path_free (path); + } gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); } +void +on_converter_output_format_changed (GtkComboBox *combobox, + gpointer user_data) +{ + int idx = gtk_combo_box_get_active (combobox); + deadbeef->conf_set_int ("converter.output_format", idx); +} + + void on_edit_channel_maps_clicked (GtkButton *button, gpointer user_data) diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index 8f672008..1420b1bf 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -6634,6 +6634,7 @@ SOCKS5_HOSTNAME 32 bit float False True + 0 @@ -7608,27 +7609,87 @@ Descending - + True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - GTK_CORNER_TOP_LEFT + False + 8 - - 196 + True True - False - False - False - True - False - False - False + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + 196 + True + True + False + False + False + True + False + False + False + + + + 0 + True + True + + + + + + True + False + 8 + + + + True + True + gtk-go-up + True + GTK_RELIEF_NORMAL + True + + + + 0 + False + False + + + + + + True + True + gtk-go-down + True + GTK_RELIEF_NORMAL + True + + + + 0 + False + False + + + + + 0 + False + False + diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index b38eed2f..1a7519ff 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -3451,6 +3451,9 @@ create_converterdlg (void) g_signal_connect ((gpointer) edit_channel_maps, "clicked", G_CALLBACK (on_edit_channel_maps_clicked), NULL); + g_signal_connect ((gpointer) output_format, "changed", + G_CALLBACK (on_converter_output_format_changed), + NULL); g_signal_connect ((gpointer) converter_cancel, "clicked", G_CALLBACK (on_converter_cancel_clicked), NULL); @@ -3844,8 +3847,12 @@ create_dsppreset_editor (void) GtkWidget *add; GtkWidget *remove; GtkWidget *configure; + GtkWidget *hbox98; GtkWidget *scrolledwindow7; GtkWidget *plugins; + GtkWidget *vbox34; + GtkWidget *up; + GtkWidget *down; GtkWidget *dialog_action_area8; GtkWidget *cancelbutton6; GtkWidget *okbutton6; @@ -3899,9 +3906,13 @@ create_dsppreset_editor (void) gtk_widget_show (configure); gtk_box_pack_start (GTK_BOX (hbox82), configure, TRUE, TRUE, 0); + hbox98 = gtk_hbox_new (FALSE, 8); + gtk_widget_show (hbox98); + gtk_box_pack_start (GTK_BOX (vbox29), hbox98, TRUE, TRUE, 0); + scrolledwindow7 = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolledwindow7); - gtk_box_pack_start (GTK_BOX (vbox29), scrolledwindow7, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox98), scrolledwindow7, TRUE, TRUE, 0); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow7), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow7), GTK_SHADOW_IN); @@ -3911,6 +3922,18 @@ create_dsppreset_editor (void) gtk_widget_set_size_request (plugins, 196, -1); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (plugins), FALSE); + vbox34 = gtk_vbox_new (FALSE, 8); + gtk_widget_show (vbox34); + gtk_box_pack_start (GTK_BOX (hbox98), vbox34, FALSE, FALSE, 0); + + up = gtk_button_new_from_stock ("gtk-go-up"); + gtk_widget_show (up); + gtk_box_pack_start (GTK_BOX (vbox34), up, FALSE, FALSE, 0); + + down = gtk_button_new_from_stock ("gtk-go-down"); + gtk_widget_show (down); + gtk_box_pack_start (GTK_BOX (vbox34), down, FALSE, FALSE, 0); + dialog_action_area8 = GTK_DIALOG (dsppreset_editor)->action_area; gtk_widget_show (dialog_action_area8); gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area8), GTK_BUTTONBOX_END); @@ -3934,6 +3957,12 @@ create_dsppreset_editor (void) g_signal_connect ((gpointer) configure, "clicked", G_CALLBACK (on_dsp_preset_plugin_configure_clicked), NULL); + g_signal_connect ((gpointer) up, "clicked", + G_CALLBACK (on_dsp_preset_plugin_up_clicked), + NULL); + g_signal_connect ((gpointer) down, "clicked", + G_CALLBACK (on_dsp_preset_plugin_down_clicked), + NULL); /* Store pointers to all widgets, for use by lookup_widget(). */ GLADE_HOOKUP_OBJECT_NO_REF (dsppreset_editor, dsppreset_editor, "dsppreset_editor"); @@ -3947,8 +3976,12 @@ create_dsppreset_editor (void) GLADE_HOOKUP_OBJECT (dsppreset_editor, add, "add"); GLADE_HOOKUP_OBJECT (dsppreset_editor, remove, "remove"); GLADE_HOOKUP_OBJECT (dsppreset_editor, configure, "configure"); + GLADE_HOOKUP_OBJECT (dsppreset_editor, hbox98, "hbox98"); GLADE_HOOKUP_OBJECT (dsppreset_editor, scrolledwindow7, "scrolledwindow7"); GLADE_HOOKUP_OBJECT (dsppreset_editor, plugins, "plugins"); + GLADE_HOOKUP_OBJECT (dsppreset_editor, vbox34, "vbox34"); + GLADE_HOOKUP_OBJECT (dsppreset_editor, up, "up"); + GLADE_HOOKUP_OBJECT (dsppreset_editor, down, "down"); GLADE_HOOKUP_OBJECT_NO_REF (dsppreset_editor, dialog_action_area8, "dialog_action_area8"); GLADE_HOOKUP_OBJECT (dsppreset_editor, cancelbutton6, "cancelbutton6"); GLADE_HOOKUP_OBJECT (dsppreset_editor, okbutton6, "okbutton6"); -- cgit v1.2.3