1 /*
2  * Copyright (C) 2002 2003 2004 2005 2010, 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 "samplesizedialog.h"
25 #include "main.h"
26 #include "effectbrowser.h"
27 #include "gettext.h"
28 #include "um.h"
29 
samplesize_apply_proc(Chunk * chunk,StatusBar * bar,gpointer user_data)30 static Chunk *samplesize_apply_proc(Chunk *chunk, StatusBar *bar,
31 				    gpointer user_data)
32 {
33      Dataformat df;
34      SamplesizeDialog *ssd = SAMPLESIZE_DIALOG(user_data);
35      memcpy(&(df),&(chunk->format),sizeof(Dataformat));
36      format_selector_get(ssd->fs,&df);
37      if (dataformat_samples_equal(&df,&(chunk->format))) {
38 	  user_info(_("File already has the selected sample format"));
39 	  return NULL;
40      }
41      if (ssd->gurumode)
42 	  return chunk_clone_df(chunk,&df);
43      else
44 	  return chunk_convert_sampletype(chunk,&df);
45 }
46 
47 
samplesize_apply(EffectDialog * ed)48 static gboolean samplesize_apply(EffectDialog *ed)
49 {
50      gboolean b;
51      b = document_apply_cb(EFFECT_BROWSER(ed->eb)->dl->selected,
52 			   samplesize_apply_proc,FALSE,ed);
53      mainwindow_update_texts();
54      return b;
55 }
56 
samplesize_setup(EffectDialog * ed)57 static void samplesize_setup(EffectDialog *ed)
58 {
59      Dataformat *f = &(EFFECT_BROWSER(ed->eb)->dl->format);
60      format_selector_set(SAMPLESIZE_DIALOG(ed)->fs, f);
61 }
62 
samplesize_dialog_class_init(EffectDialogClass * klass)63 static void samplesize_dialog_class_init(EffectDialogClass *klass)
64 {
65      klass->apply = samplesize_apply;
66      klass->setup = samplesize_setup;
67 }
68 
gurumode_toggle(GtkToggleButton * togglebutton,gpointer user_data)69 static void gurumode_toggle(GtkToggleButton *togglebutton, gpointer user_data)
70 {
71      SamplesizeDialog *ssd = SAMPLESIZE_DIALOG(user_data);
72      ssd->gurumode = gtk_toggle_button_get_active(togglebutton);
73 }
74 
samplesize_dialog_init(SamplesizeDialog * ssd)75 static void samplesize_dialog_init(SamplesizeDialog *ssd)
76 {
77      GtkWidget *b,*c;
78      GtkBox *ia = GTK_BOX(EFFECT_DIALOG(ssd)->input_area);
79 
80      ssd->gurumode = FALSE;
81 
82      ssd->fs = FORMAT_SELECTOR(format_selector_new(FALSE));
83 
84      b = gtk_vbox_new(FALSE,3);
85      gtk_box_pack_start(ia,b,FALSE,FALSE,0);
86      gtk_widget_show(b);
87      c = gtk_label_new ( _("(This changes the sample type of "
88 			 "the entire file, not just the selection)") );
89      gtk_label_set_justify(GTK_LABEL(c),GTK_JUSTIFY_LEFT);
90      gtk_misc_set_alignment(GTK_MISC(c),0,0.5);
91      gtk_label_set_line_wrap(GTK_LABEL(c),TRUE);
92      gtk_box_pack_start(GTK_BOX(b),c,FALSE,FALSE,0);
93      gtk_widget_show(c);
94 
95      c = GTK_WIDGET(ssd->fs);
96      gtk_box_pack_start(GTK_BOX(b),c,FALSE,FALSE,0);
97      gtk_widget_show(c);
98 
99      c=gtk_check_button_new_with_label(_("Don't actually change the data "
100 				       "(for repairing bad files etc)"));
101      gtk_signal_connect(GTK_OBJECT(c),"toggled",GTK_SIGNAL_FUNC(gurumode_toggle),
102 			ssd);
103      gtk_box_pack_start(GTK_BOX(b),c,FALSE,FALSE,0);
104      gtk_widget_show(c);
105 }
106 
samplesize_dialog_get_type(void)107 GtkType samplesize_dialog_get_type(void)
108 {
109      static GtkType id = 0;
110      if (!id) {
111 	  GtkTypeInfo info = {
112 	       "SamplesizeDialog",
113 	       sizeof(SamplesizeDialog),
114 	       sizeof(SamplesizeDialogClass),
115 	       (GtkClassInitFunc) samplesize_dialog_class_init,
116 	       (GtkObjectInitFunc) samplesize_dialog_init
117 	  };
118 	  id = gtk_type_unique(effect_dialog_get_type(),&info);
119      }
120      return id;
121 }
122