replace ::cast_dynamic() with relevant ActionManager::get_*_action() calls
[ardour.git] / gtk2_ardour / insert_remove_time_dialog.cc
1 /*
2     Copyright (C) 2000-2010 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 <gtkmm/table.h>
21 #include <gtkmm/comboboxtext.h>
22 #include <gtkmm/stock.h>
23 #include <gtkmm/alignment.h>
24 #include "insert_remove_time_dialog.h"
25 #include "audio_clock.h"
26 #include "ardour_ui.h"
27 #include "main_clock.h"
28 #include "pbd/i18n.h"
29
30 using namespace Gtk;
31 using namespace Editing;
32 using namespace ARDOUR;
33
34 InsertRemoveTimeDialog::InsertRemoveTimeDialog (PublicEditor& e, bool remove)
35         : ArdourDialog (remove ? _("Remove Time") : _("Insert Time"))
36         , _editor (e)
37         , duration_clock ("insertTimeClock", true, "",
38                         true,   // editable
39                         false,  // follows_playhead
40                         true,   // duration
41                         false,  // with_info
42                         true    // accept_on_focus_out
43                 )
44         , position_clock ("insertPosTimeClock", true, "",
45                         true,   // editable
46                         false,  // follows_playhead
47                         false,   // duration
48                         false,  // with_info
49                         true    // accept_on_focus_out
50                 )
51 {
52         set_session (_editor.session ());
53
54         get_vbox()->set_border_width (12);
55         get_vbox()->set_spacing (4);
56
57         Table* table = manage (new Table (2, 3));
58         table->set_spacings (4);
59
60         Label* time_label = manage (new Label (remove ? _("Remove Time starting at:") : _("Insert Time starting at:")));
61         time_label->set_alignment (1, 0.5);
62         table->attach (*time_label, 0, 1, 0, 1, FILL | EXPAND);
63         position_clock.set_session (_session);
64         position_clock.set_mode (ARDOUR_UI::instance()->primary_clock->mode());
65         table->attach (position_clock, 1, 2, 0, 1);
66
67         time_label = manage (new Label (remove ? _("Time to remove:") : _("Time to insert:")));
68         time_label->set_alignment (1, 0.5);
69         table->attach (*time_label, 0, 1, 1, 2, FILL | EXPAND);
70         duration_clock.set_session (_session);
71         duration_clock.set_mode (ARDOUR_UI::instance()->primary_clock->mode());
72         table->attach (duration_clock, 1, 2, 1, 2);
73
74         //if a Range is selected, assume the user wants to insert/remove the length of the range
75         if ( _editor.get_selection().time.length() != 0 ) {
76                 position_clock.set ( _editor.get_selection().time.start(), true );
77                 duration_clock.set ( _editor.get_selection().time.end_sample(), true,  _editor.get_selection().time.start() );
78                 duration_clock.set_bbt_reference (_editor.get_selection().time.start());
79         } else {
80                 samplepos_t const pos = _editor.get_preferred_edit_position (EDIT_IGNORE_MOUSE);
81                 position_clock.set ( pos, true );
82                 duration_clock.set_bbt_reference (pos);
83                 duration_clock.set (0);
84         }
85         
86         if (!remove) {
87                 Label* intersected_label = manage (new Label (_("Intersected regions should:")));
88                 intersected_label->set_alignment (1, 0.5);
89                 table->attach (*intersected_label, 0, 1, 2, 3, FILL | EXPAND);
90                 _intersected_combo.append_text (_("stay in position"));
91                 _intersected_combo.append_text (_("move"));
92                 _intersected_combo.append_text (_("be split"));
93                 _intersected_combo.set_active (0);
94                 table->attach (_intersected_combo, 1, 2, 2, 3);
95         }
96
97         get_vbox()->pack_start (*table);
98
99         _all_playlists.set_label (_("Apply to all the track's playlists"));
100         get_vbox()->pack_start (_all_playlists);
101
102         _move_glued.set_label (_("Move glued-to-musical-time regions (MIDI regions)"));
103         _move_glued.set_active();
104         get_vbox()->pack_start (_move_glued);
105         _move_markers.set_label (_("Move markers"));
106         get_vbox()->pack_start (_move_markers);
107         _move_markers.signal_toggled().connect (sigc::mem_fun (*this, &InsertRemoveTimeDialog::move_markers_toggled));
108         _move_glued_markers.set_label (_("Move glued-to-musical-time markers"));
109         _move_glued_markers.set_active();
110         Alignment* indent = manage (new Alignment);
111         indent->set_padding (0, 0, 12, 0);
112         indent->add (_move_glued_markers);
113         get_vbox()->pack_start (*indent);
114         _move_locked_markers.set_label (_("Move locked markers"));
115         indent = manage (new Alignment);
116         indent->set_padding (0, 0, 12, 0);
117         indent->add (_move_locked_markers);
118         get_vbox()->pack_start (*indent);
119         tempo_label.set_markup (_("Move tempo and meter changes\n<i>(may cause oddities in the tempo map)</i>"));
120         HBox* tempo_box = manage (new HBox);
121         tempo_box->set_spacing (6);
122         tempo_box->pack_start (_move_tempos, false, false);
123         tempo_box->pack_start (tempo_label, false, false);
124         get_vbox()->pack_start (*tempo_box);
125
126         add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
127         Gtk::Button *btn = manage (new Gtk::Button (remove ? _("Remove time") : _("Insert time")));
128         btn->signal_clicked().connect (sigc::mem_fun(*this, &InsertRemoveTimeDialog::doit));
129         get_action_area()->pack_start (*btn);
130         show_all ();
131
132         move_markers_toggled ();
133 }
134
135 InsertTimeOption
136 InsertRemoveTimeDialog::intersected_region_action ()
137 {
138         /* only setting this to keep GCC quiet */
139         InsertTimeOption opt = LeaveIntersected;
140
141         switch (_intersected_combo.get_active_row_number ()) {
142         case 0:
143                 opt = LeaveIntersected;
144                 break;
145         case 1:
146                 opt = MoveIntersected;
147                 break;
148         case 2:
149                 opt = SplitIntersected;
150                 break;
151         }
152
153         return opt;
154 }
155
156 bool
157 InsertRemoveTimeDialog::all_playlists () const
158 {
159         return _all_playlists.get_active ();
160 }
161
162 bool
163 InsertRemoveTimeDialog::move_glued () const
164 {
165         return _move_glued.get_active ();
166 }
167
168 bool
169 InsertRemoveTimeDialog::move_tempos () const
170 {
171         return _move_tempos.get_active ();
172 }
173
174 bool
175 InsertRemoveTimeDialog::move_markers () const
176 {
177         return _move_markers.get_active ();
178 }
179
180 bool
181 InsertRemoveTimeDialog::move_glued_markers () const
182 {
183         return _move_glued_markers.get_active ();
184 }
185
186 bool
187 InsertRemoveTimeDialog::move_locked_markers () const
188 {
189         return _move_locked_markers.get_active ();
190 }
191
192 samplepos_t
193 InsertRemoveTimeDialog::position () const
194 {
195         return position_clock.current_time();
196 }
197
198 samplepos_t
199 InsertRemoveTimeDialog::distance () const
200 {
201         return duration_clock.current_duration ( position_clock.current_time() );
202 }
203
204 void
205 InsertRemoveTimeDialog::doit ()
206 {
207         if (distance () == 0) {
208                 Gtk::MessageDialog msg (*this, _("Invalid or zero duration entered. Please enter a valid duration"));
209                 msg.run ();
210                 return;
211         }
212         response (RESPONSE_OK);
213 }
214
215 void
216 InsertRemoveTimeDialog::move_markers_toggled ()
217 {
218         _move_glued_markers.set_sensitive (_move_markers.get_active ());
219         _move_locked_markers.set_sensitive (_move_markers.get_active ());
220 }