Split TimeFXDialog from Editor.
[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_position (Gtk::WIN_POS_MOUSE);
82         set_name (N_("TimeFXDialog"));
83
84         WindowTitle title(Glib::get_application_name());
85         if (pitching) {
86                 title += _("Pitch Shift");
87         } else {
88                 title += _("Time Stretch");
89         }
90         set_title(title.get_string());
91
92         cancel_button = add_button (_("Cancel"), Gtk::RESPONSE_CANCEL);
93
94         get_vbox()->set_spacing (5);
95         get_vbox()->set_border_width (12);
96
97         if (pitching) {
98
99                 upper_button_box.set_spacing (5);
100                 upper_button_box.set_border_width (5);
101                 
102                 Gtk::Label* l;
103
104                 l = manage (new Label (_("Octaves")));
105                 upper_button_box.pack_start (*l, false, false);
106                 upper_button_box.pack_start (pitch_octave_spinner, false, false);
107
108                 l = manage (new Label (_("Semitones (12TET)")));
109                 upper_button_box.pack_start (*l, false, false);
110                 upper_button_box.pack_start (pitch_semitone_spinner, false, false);
111
112                 l = manage (new Label (_("Cents")));
113                 upper_button_box.pack_start (*l, false, false);
114                 upper_button_box.pack_start (pitch_cent_spinner, false, false);
115
116                 pitch_cent_spinner.set_digits (1);
117
118                 upper_button_box.pack_start (preserve_formants_button, false, false);
119
120
121                 add_button (_("Shift"), Gtk::RESPONSE_ACCEPT);
122
123                 get_vbox()->pack_start (upper_button_box, false, false);
124
125         } else {
126
127 #ifdef USE_RUBBERBAND
128                 opts_box.set_spacing (5);
129                 opts_box.set_border_width (5);
130                 vector<string> strings;
131
132                 set_popdown_strings (stretch_opts_selector, editor.rb_opt_strings);
133                 /* set default */
134                 stretch_opts_selector.set_active_text (editor.rb_opt_strings[4]);
135
136                 opts_box.pack_start (precise_button, false, false);
137                 opts_box.pack_start (stretch_opts_label, false, false);
138                 opts_box.pack_start (stretch_opts_selector, false, false);
139
140                 get_vbox()->pack_start (opts_box, false, false);
141
142 #else
143                 upper_button_box.set_homogeneous (true);
144                 upper_button_box.set_spacing (5);
145                 upper_button_box.set_border_width (5);
146
147                 upper_button_box.pack_start (quick_button, true, true);
148                 upper_button_box.pack_start (antialias_button, true, true);
149
150                 quick_button.set_name (N_("TimeFXButton"));
151                 antialias_button.set_name (N_("TimeFXButton"));
152
153                 get_vbox()->pack_start (upper_button_box, false, false);
154
155 #endif  
156                 add_button (_("Stretch/Shrink"), Gtk::RESPONSE_ACCEPT);
157         }
158
159         get_vbox()->pack_start (progress_bar);
160
161         progress_bar.set_name (N_("TimeFXProgress"));
162
163         show_all_children ();
164 }
165
166 gint
167 TimeFXDialog::update_progress ()
168 {
169         progress_bar.set_fraction (request.progress);
170         return !request.done;
171 }
172
173 void
174 TimeFXDialog::cancel_in_progress ()
175 {
176         status = -2;
177         request.cancel = true;
178         first_cancel.disconnect();
179 }
180
181 gint
182 TimeFXDialog::delete_in_progress (GdkEventAny* ev)
183 {
184         status = -2;
185         request.cancel = true;
186         first_delete.disconnect();
187         return TRUE;
188 }
189