1 /*
2  * Copyright (C) 2002 2003 2004, Magnus Hjorth
3  *
4  * This file is part of mhWaveEdit.
5  *
6  * mhWaveEdit is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * mhWaveEdit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mhWaveEdit; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 
22 #include <config.h>
23 
24 #include <math.h>
25 #include <gtk/gtk.h>
26 #include "mainwindow.h"
27 #include "sampleratedialog.h"
28 #include "chunk.h"
29 #include "float_box.h"
30 #include "soxdialog.h"
31 #include "pipedialog.h"
32 #include "um.h"
33 #include "inifile.h"
34 #include "effectbrowser.h"
35 #include "rateconv.h"
36 #include "gettext.h"
37 
set_method(Combo * cbo,gpointer user_data)38 static void set_method(Combo *cbo, gpointer user_data)
39 {
40      SamplerateDialog *s = SAMPLERATE_DIALOG(user_data);
41      s->method = combo_selected_index(cbo);
42 }
43 
apply_proc(Chunk * chunk,StatusBar * bar,gpointer user_data)44 static Chunk *apply_proc(Chunk *chunk, StatusBar *bar, gpointer user_data)
45 {
46      SamplerateDialog *s = SAMPLERATE_DIALOG(user_data);
47      return chunk_convert_samplerate(chunk,s->rate->val,
48 				     rateconv_driver_id(FALSE,s->method),
49 				     dither_editing, bar);
50 }
51 
apply(EffectDialog * ed)52 static gboolean apply(EffectDialog *ed)
53 {
54      gboolean b;
55      Document *d = EFFECT_BROWSER(ed->eb)->dl->selected;
56      SamplerateDialog *s = SAMPLERATE_DIALOG(ed);
57      if (intbox_check(s->rate) || s->rate->val==0) return TRUE;
58 
59      inifile_set_guint32("srate_method",s->method);
60      b = document_apply_cb(d,apply_proc,FALSE,ed);
61      mainwindow_update_texts();
62      return b;
63 }
64 
samplerate_dialog_setup(EffectDialog * ed)65 static void samplerate_dialog_setup(EffectDialog *ed)
66 {
67      intbox_set(SAMPLERATE_DIALOG(ed)->rate,
68 		EFFECT_BROWSER(ed->eb)->dl->format.samplerate);
69 }
70 
samplerate_dialog_class_init(EffectDialogClass * klass)71 static void samplerate_dialog_class_init(EffectDialogClass *klass)
72 {
73      klass->apply = apply;
74      klass->setup = samplerate_dialog_setup;
75 }
76 
samplerate_dialog_init(SamplerateDialog * v)77 static void samplerate_dialog_init(SamplerateDialog *v)
78 {
79      EffectDialog *ed = EFFECT_DIALOG(v);
80      GtkWidget *a,*b,*c;
81      GtkRequisition req;
82      GList *l = NULL;
83      int i,j;
84 
85      a = gtk_vbox_new ( FALSE, 3 );
86      gtk_box_pack_start (GTK_BOX(ed->input_area),a,FALSE,FALSE,0);
87      b = gtk_label_new ( _("(This changes the sample rate of \n"
88 			 "the entire file, not just the selection)") );
89      gtk_box_pack_start ( GTK_BOX(a),b,FALSE,FALSE,0 );
90      b = gtk_hbox_new ( FALSE, 3 );
91      gtk_box_pack_start (GTK_BOX(a),b,FALSE,FALSE,0);
92      c = gtk_label_new ( _("New samplerate: ") );
93      gtk_box_pack_start (GTK_BOX(b),c,FALSE,FALSE,0);
94      c = intbox_new(0);
95      v->rate = INTBOX(c);
96      gtk_box_pack_start(GTK_BOX(b),c,FALSE,FALSE,0);
97      b = gtk_hbox_new( FALSE, 3 );
98      gtk_box_pack_start(GTK_BOX(a),b,FALSE,FALSE,0);
99      c = gtk_label_new(_("Method: "));
100      gtk_box_pack_start(GTK_BOX(b),c,FALSE,FALSE,0);
101 
102      c = combo_new();
103      gtk_box_pack_start(GTK_BOX(b),c,FALSE,FALSE,0);
104      gtk_widget_size_request(c,&req);
105 #ifdef COMBO_OLDSCHOOL
106      gtk_widget_set_usize(c,req.width*3/2,req.height);
107 #endif
108      i = rateconv_driver_count(FALSE);
109      for (j=0; j<i; j++)
110 	  l = g_list_append(l,(gpointer)rateconv_driver_name(FALSE,j));
111      v->method = inifile_get_guint32("srate_method",0);
112      if (v->method >= g_list_length(l)) v->method = 0;
113      combo_set_items(COMBO(c),l,v->method);
114      g_list_free(l);
115 
116      gtk_signal_connect(GTK_OBJECT(c),"selection_changed",
117 			GTK_SIGNAL_FUNC(set_method),v);
118 
119      gtk_widget_show_all(a);
120 }
121 
samplerate_dialog_get_type(void)122 GtkType samplerate_dialog_get_type(void)
123 {
124      static GtkType id = 0;
125      if (!id) {
126 	  GtkTypeInfo info = {
127 	       "SamplerateDialog",
128 	       sizeof(SamplerateDialog),
129 	       sizeof(SamplerateDialogClass),
130 	       (GtkClassInitFunc) samplerate_dialog_class_init,
131 	       (GtkObjectInitFunc) samplerate_dialog_init
132 	  };
133 	  id = gtk_type_unique(effect_dialog_get_type(),&info);
134      }
135      return id;
136 }
137