fix up file renaming code a little bit
[ArdourMidi.git] / gtk2_ardour / time_fx_dialog.cc
blobd1650430b24b6a7dd39071601e44e23c070098f7
1 /*
2 Copyright (C) 2000-2009 Paul Davis
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.
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.
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.
20 #include "time_fx_dialog.h"
22 #include <iostream>
23 #include <cstdlib>
24 #include <cmath>
26 #include <string>
28 #include "pbd/error.h"
29 #include "pbd/pthread_utils.h"
30 #include "pbd/memento_command.h"
32 #include <gtkmm2ext/utils.h>
34 #include "editor.h"
35 #include "audio_time_axis.h"
36 #include "audio_region_view.h"
37 #include "region_selection.h"
39 #include "ardour/session.h"
40 #include "ardour/region.h"
41 #include "ardour/audioplaylist.h"
42 #include "ardour/audio_track.h"
43 #include "ardour/audioregion.h"
44 #include "ardour/stretch.h"
45 #include "ardour/midi_stretch.h"
46 #include "ardour/pitch.h"
48 #ifdef USE_RUBBERBAND
49 #include "rubberband/RubberBandStretcher.h"
50 using namespace RubberBand;
51 #endif
53 #include "i18n.h"
55 using namespace std;
56 using namespace ARDOUR;
57 using namespace PBD;
58 using namespace Gtk;
59 using namespace Gtkmm2ext;
61 TimeFXDialog::TimeFXDialog (Editor& e, bool pitch)
62 : ArdourDialog (X_("time fx dialog"))
63 , editor (e)
64 , pitching (pitch)
65 , pitch_octave_adjustment (0.0, -4.0, 4.0, 1, 2.0)
66 , pitch_semitone_adjustment (0.0, -12.0, 12.0, 1.0, 4.0)
67 , pitch_cent_adjustment (0.0, -499.0, 500.0, 5.0, 15.0)
68 , pitch_octave_spinner (pitch_octave_adjustment)
69 , pitch_semitone_spinner (pitch_semitone_adjustment)
70 , pitch_cent_spinner (pitch_cent_adjustment)
71 , quick_button (_("Quick but Ugly"))
72 , antialias_button (_("Skip Anti-aliasing"))
73 , stretch_opts_label (_("Contents:"))
74 , precise_button (_("Strict Linear"))
75 , preserve_formants_button(_("Preserve Formants"))
77 set_modal (true);
78 set_skip_taskbar_hint (true);
79 set_resizable (false);
80 set_position (Gtk::WIN_POS_MOUSE);
81 set_name (N_("TimeFXDialog"));
83 if (pitching) {
84 set_title (_("Pitch Shift"));
85 } else {
86 set_title (_("Time Stretch"));
89 cancel_button = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
91 VBox* vbox = manage (new VBox);
92 Gtk::Label* l;
94 get_vbox()->set_spacing (4);
96 vbox->set_spacing (18);
97 vbox->set_border_width (5);
99 upper_button_box.set_spacing (6);
101 l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
102 l->set_use_markup ();
104 upper_button_box.pack_start (*l, false, false);
106 if (pitching) {
107 Table* table = manage (new Table (4, 3, false));
108 table->set_row_spacings (6);
109 table->set_col_spacing (1, 6);
110 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false )); //Common gnome way for padding
111 l->set_padding (8, 0);
112 table->attach (*l, 0, 1, 0, 4, Gtk::FILL, Gtk::FILL, 0, 0);
114 l = manage (new Label (_("Octaves:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
115 table->attach (*l, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
116 table->attach (pitch_octave_spinner, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
118 l = manage (new Label (_("Semitones:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
119 table->attach (*l, 1, 2, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
120 table->attach (pitch_semitone_spinner, 2, 3, 1, 2, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
122 l = manage (new Label (_("Cents:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
123 pitch_cent_spinner.set_digits (1);
124 table->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::EXPAND, 0, 0);
125 table->attach (pitch_cent_spinner, 2, 3, 2, 3, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
127 table->attach (preserve_formants_button, 1, 3, 3, 4, Gtk::FILL, Gtk::EXPAND, 0, 0);
130 add_button (_("Shift"), Gtk::RESPONSE_ACCEPT);
132 upper_button_box.pack_start (*table, false, true);
133 } else {
134 Table* table = manage (new Table (2, 3, false));
135 table->set_row_spacings (6);
136 table->set_col_spacing (1, 6);
137 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
138 l->set_padding (8, 0);
139 table->attach (*l, 0, 1, 0, 2, Gtk::FILL, Gtk::FILL, 0, 0);
141 #ifdef USE_RUBBERBAND
142 vector<string> strings;
144 table->attach (stretch_opts_label, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
146 set_popdown_strings (stretch_opts_selector, editor.rb_opt_strings);
147 /* set default */
148 stretch_opts_selector.set_active_text (editor.rb_opt_strings[4]);
149 table->attach (stretch_opts_selector, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
151 table->attach (precise_button, 1, 3, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
153 #else
154 quick_button.set_name (N_("TimeFXButton"));
155 table->attach (quick_button, 1, 3, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
157 antialias_button.set_name (N_("TimeFXButton"));
158 table->attach (antialias_button, 1, 3, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
160 #endif
162 add_button (_("Stretch/Shrink"), Gtk::RESPONSE_ACCEPT);
164 upper_button_box.pack_start (*table, false, true);
167 VBox* progress_box = manage (new VBox);
168 progress_box->set_spacing (6);
170 l = manage (new Label (_("<b>Progress</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
171 l->set_use_markup ();
173 progress_bar.set_name (N_("TimeFXProgress"));
175 progress_box->pack_start (*l, false, false);
176 progress_box->pack_start (progress_bar, false, true);
179 vbox->pack_start (upper_button_box, false, true);
180 vbox->pack_start (*progress_box, false, true);
182 get_vbox()->pack_start (*vbox, false, false);
185 show_all_children ();
188 gint
189 TimeFXDialog::update_progress ()
191 progress_bar.set_fraction (request.progress);
192 return !request.done;
195 void
196 TimeFXDialog::cancel_in_progress ()
198 status = -2;
199 request.cancel = true;
200 first_cancel.disconnect();
203 gint
204 TimeFXDialog::delete_in_progress (GdkEventAny*)
206 status = -2;
207 request.cancel = true;
208 first_delete.disconnect();
209 return TRUE;