Tidy up window titles, according to GNOME HIG and as suggested in mantis 2803.
[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/utils.h>
33
34 #include "editor.h"
35 #include "audio_time_axis.h"
36 #include "audio_region_view.h"
37 #include "region_selection.h"
38
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/audio_diskstream.h"
45 #include "ardour/stretch.h"
46 #include "ardour/midi_stretch.h"
47 #include "ardour/pitch.h"
48
49 #ifdef USE_RUBBERBAND
50 #include "rubberband/RubberBandStretcher.h"
51 using namespace RubberBand;
52 #endif
53
54 #include "i18n.h"
55
56 using namespace std;
57 using namespace ARDOUR;
58 using namespace PBD;
59 using namespace sigc;
60 using namespace Gtk;
61 using namespace Gtkmm2ext;
62
63 TimeFXDialog::TimeFXDialog (Editor& e, bool pitch)
64         : ArdourDialog (X_("time fx dialog"))
65         , editor (e)
66         , pitching (pitch)
67         , pitch_octave_adjustment (0.0, -4.0, 4.0, 1, 2.0)
68         , pitch_semitone_adjustment (0.0, -12.0, 12.0, 1.0, 4.0)
69         , pitch_cent_adjustment (0.0, -499.0, 500.0, 5.0, 15.0)
70         , pitch_octave_spinner (pitch_octave_adjustment)
71         , pitch_semitone_spinner (pitch_semitone_adjustment)
72         , pitch_cent_spinner (pitch_cent_adjustment)
73         , quick_button (_("Quick but Ugly"))
74         , antialias_button (_("Skip Anti-aliasing"))
75         , stretch_opts_label (_("Contents:"))
76         , precise_button (_("Strict Linear"))
77         , preserve_formants_button(_("Preserve Formants"))
78 {
79         set_modal (true);
80         set_skip_taskbar_hint (true);
81         set_resizable (false);
82         set_position (Gtk::WIN_POS_MOUSE);
83         set_name (N_("TimeFXDialog"));
84
85         if (pitching) {
86                 set_title (_("Pitch Shift"));
87         } else {
88                 set_title (_("Time Stretch"));
89         }
90
91         cancel_button = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
92
93         VBox* vbox = manage (new VBox);
94         Gtk::Label* l;
95
96         get_vbox()->set_spacing (4);
97
98         vbox->set_spacing (18);
99         vbox->set_border_width (5);
100
101         upper_button_box.set_spacing (6);
102
103         l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
104         l->set_use_markup ();
105
106         upper_button_box.pack_start (*l, false, false);
107
108         if (pitching) {
109                 Table* table = manage (new Table (4, 3, false));
110                 table->set_row_spacings (6);
111                 table->set_col_spacing  (1, 6);
112                 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false )); //Common gnome way for padding
113                 l->set_padding (8, 0);
114                 table->attach (*l, 0, 1, 0, 4, Gtk::FILL, Gtk::FILL, 0, 0);
115
116                 l = manage (new Label (_("Octaves:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
117                 table->attach (*l, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
118                 table->attach (pitch_octave_spinner, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
119
120                 l = manage (new Label (_("Semitones:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
121                 table->attach (*l, 1, 2, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
122                 table->attach (pitch_semitone_spinner, 2, 3, 1, 2, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
123
124                 l = manage (new Label (_("Cents:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
125                 pitch_cent_spinner.set_digits (1);
126                 table->attach (*l, 1, 2, 2, 3, Gtk::FILL, Gtk::EXPAND, 0, 0);
127                 table->attach (pitch_cent_spinner, 2, 3, 2, 3, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
128
129                 table->attach (preserve_formants_button, 1, 3, 3, 4, Gtk::FILL, Gtk::EXPAND, 0, 0);
130
131
132                 add_button (_("Shift"), Gtk::RESPONSE_ACCEPT);
133
134                 upper_button_box.pack_start (*table, false, true);
135         } else {
136                 Table* table = manage (new Table (2, 3, false));
137                 table->set_row_spacings (6);
138                 table->set_col_spacing  (1, 6);
139                 l = manage (new Label ("", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false ));
140                 l->set_padding (8, 0);
141                 table->attach (*l, 0, 1, 0, 2, Gtk::FILL, Gtk::FILL, 0, 0);
142
143 #ifdef USE_RUBBERBAND
144                 vector<string> strings;
145
146                 table->attach (stretch_opts_label, 1, 2, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
147
148                 set_popdown_strings (stretch_opts_selector, editor.rb_opt_strings);
149                 /* set default */
150                 stretch_opts_selector.set_active_text (editor.rb_opt_strings[4]);
151                 table->attach (stretch_opts_selector, 2, 3, 0, 1, Gtk::FILL, Gtk::EXPAND & Gtk::FILL, 0, 0);
152
153                 table->attach (precise_button, 1, 3, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
154
155 #else
156                 quick_button.set_name (N_("TimeFXButton"));
157                 table->attach (quick_button, 1, 3, 0, 1, Gtk::FILL, Gtk::EXPAND, 0, 0);
158
159                 antialias_button.set_name (N_("TimeFXButton"));
160                 table->attach (antialias_button, 1, 3, 1, 2, Gtk::FILL, Gtk::EXPAND, 0, 0);
161
162 #endif
163
164                 add_button (_("Stretch/Shrink"), Gtk::RESPONSE_ACCEPT);
165
166                 upper_button_box.pack_start (*table, false, true);
167         }
168
169         VBox* progress_box = manage (new VBox);
170         progress_box->set_spacing (6);
171
172         l = manage (new Label (_("<b>Progress</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
173         l->set_use_markup ();
174
175         progress_bar.set_name (N_("TimeFXProgress"));
176
177         progress_box->pack_start (*l, false, false);
178         progress_box->pack_start (progress_bar, false, true);
179
180
181         vbox->pack_start (upper_button_box, false, true);
182         vbox->pack_start (*progress_box, false, true);
183
184         get_vbox()->pack_start (*vbox, false, false);
185
186
187         show_all_children ();
188 }
189
190 gint
191 TimeFXDialog::update_progress ()
192 {
193         progress_bar.set_fraction (request.progress);
194         return !request.done;
195 }
196
197 void
198 TimeFXDialog::cancel_in_progress ()
199 {
200         status = -2;
201         request.cancel = true;
202         first_cancel.disconnect();
203 }
204
205 gint
206 TimeFXDialog::delete_in_progress (GdkEventAny*)
207 {
208         status = -2;
209         request.cancel = true;
210         first_delete.disconnect();
211         return TRUE;
212 }
213