Fix some unused parameter warnings.
[ardour.git] / gtk2_ardour / time_fx_dialog.cc
1 /*
2     Copyright (C) 2000-2009 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "time_fx_dialog.h"
21
22 #include <iostream>
23 #include <cstdlib>
24 #include <cmath>
25
26 #include <string>
27
28 #include "pbd/error.h"
29 #include "pbd/pthread_utils.h"
30 #include "pbd/memento_command.h"
31
32 #include <gtkmm2ext/window_title.h>
33 #include <gtkmm2ext/utils.h>
34
35 #include "editor.h"
36 #include "audio_time_axis.h"
37 #include "audio_region_view.h"
38 #include "region_selection.h"
39
40 #include "ardour/session.h"
41 #include "ardour/region.h"
42 #include "ardour/audioplaylist.h"
43 #include "ardour/audio_track.h"
44 #include "ardour/audioregion.h"
45 #include "ardour/audio_diskstream.h"
46 #include "ardour/stretch.h"
47 #include "ardour/midi_stretch.h"
48 #include "ardour/pitch.h"
49
50 #ifdef USE_RUBBERBAND
51 #include "rubberband/RubberBandStretcher.h"
52 using namespace RubberBand;
53 #endif
54
55 #include "i18n.h"
56
57 using namespace std;
58 using namespace ARDOUR;
59 using namespace PBD;
60 using namespace sigc;
61 using namespace Gtk;
62 using namespace Gtkmm2ext;
63
64 TimeFXDialog::TimeFXDialog (Editor& e, bool pitch)
65         : ArdourDialog (X_("time fx dialog"))
66         , editor (e)
67         , pitching (pitch)
68         , pitch_octave_adjustment (0.0, -4.0, 4.0, 1, 2.0)
69         , pitch_semitone_adjustment (0.0, -12.0, 12.0, 1.0, 4.0)
70         , pitch_cent_adjustment (0.0, -499.0, 500.0, 5.0, 15.0)
71         , pitch_octave_spinner (pitch_octave_adjustment)
72         , pitch_semitone_spinner (pitch_semitone_adjustment)
73         , pitch_cent_spinner (pitch_cent_adjustment)
74         , quick_button (_("Quick but Ugly"))
75         , antialias_button (_("Skip Anti-aliasing"))
76         , stretch_opts_label (_("Contents:"))
77         , precise_button (_("Strict Linear"))
78         , preserve_formants_button(_("Preserve Formants"))
79 {
80         set_modal (true);
81         set_skip_taskbar_hint (true);
82         set_resizable (false);
83         set_position (Gtk::WIN_POS_MOUSE);
84         set_name (N_("TimeFXDialog"));
85
86         WindowTitle title(Glib::get_application_name());
87         if (pitching) {
88                 title += _("Pitch Shift");
89         } else {
90                 title += _("Time Stretch");
91         }
92         set_title(title.get_string());
93
94         cancel_button = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
95
96         VBox* vbox = manage (new VBox);
97         Gtk::Label* l;
98
99         get_vbox()->set_spacing (4);
100
101         vbox->set_spacing (18);
102         vbox->set_border_width (5);
103
104         upper_button_box.set_spacing (6);
105
106         l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
107         l->set_use_markup ();
108
109         upper_button_box.pack_start (*l, false, false);
110
111         if (pitching) {
112                 Table* table = manage (new Table (4, 3, false));
113                 table->set_row_spacings (6);
114                 table->set_col_spacing  (1, 6);
115                 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false )); //Common gnome way for padding
116                 l->set_padding (8, 0);
117                 table->attach (*l, 0, 1, 0, 4, Gtk::FILL, Gtk::FILL, 0, 0);
118
119                 l = manage (new Label (_("Octaves:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
120                 table->attach (*l, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
121                 table->attach (pitch_octave_spinner, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
122
123                 l = manage (new Label (_("Semitones:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
124                 table->attach (*l, 1, 2, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
125                 table->attach (pitch_semitone_spinner, 2, 3, 1, 2, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
126
127                 l = manage (new Label (_("Cents:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
128                 pitch_cent_spinner.set_digits (1);
129                 table->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::EXPAND, 0, 0);
130                 table->attach (pitch_cent_spinner, 2, 3, 2, 3, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
131
132                 table->attach (preserve_formants_button, 1, 3, 3, 4, Gtk::FILL, Gtk::EXPAND, 0, 0);
133
134
135                 add_button (_("Shift"), Gtk::RESPONSE_ACCEPT);
136
137                 upper_button_box.pack_start (*table, false, true);
138         } else {
139                 Table* table = manage (new Table (2, 3, false));
140                 table->set_row_spacings (6);
141                 table->set_col_spacing  (1, 6);
142                 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
143                 l->set_padding (8, 0);
144                 table->attach (*l, 0, 1, 0, 2, Gtk::FILL, Gtk::FILL, 0, 0);
145
146 #ifdef USE_RUBBERBAND
147                 vector<string> strings;
148
149                 table->attach (stretch_opts_label, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
150
151                 set_popdown_strings (stretch_opts_selector, editor.rb_opt_strings);
152                 /* set default */
153                 stretch_opts_selector.set_active_text (editor.rb_opt_strings[4]);
154                 table->attach (stretch_opts_selector, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
155
156                 table->attach (precise_button, 1, 3, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
157
158 #else
159                 quick_button.set_name (N_("TimeFXButton"));
160                 table->attach (quick_button, 1, 3, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
161
162                 antialias_button.set_name (N_("TimeFXButton"));
163                 table->attach (antialias_button, 1, 3, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
164
165 #endif  
166
167                 add_button (_("Stretch/Shrink"), Gtk::RESPONSE_ACCEPT);
168
169                 upper_button_box.pack_start (*table, false, true);
170         }
171
172         VBox* progress_box = manage (new VBox);
173         progress_box->set_spacing (6);
174
175         l = manage (new Label (_("<b>Progress</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
176         l->set_use_markup ();
177
178         progress_bar.set_name (N_("TimeFXProgress"));
179         
180         progress_box->pack_start (*l, false, false);
181         progress_box->pack_start (progress_bar, false, true);
182
183
184         vbox->pack_start (upper_button_box, false, true);
185         vbox->pack_start (*progress_box, false, true);
186
187         get_vbox()->pack_start (*vbox, false, false);
188
189         
190         show_all_children ();
191 }
192
193 gint
194 TimeFXDialog::update_progress ()
195 {
196         progress_bar.set_fraction (request.progress);
197         return !request.done;
198 }
199
200 void
201 TimeFXDialog::cancel_in_progress ()
202 {
203         status = -2;
204         request.cancel = true;
205         first_cancel.disconnect();
206 }
207
208 gint
209 TimeFXDialog::delete_in_progress (GdkEventAny*)
210 {
211         status = -2;
212         request.cancel = true;
213         first_delete.disconnect();
214         return TRUE;
215 }
216