2 Copyright (C) 2000-2010 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 <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"
31 using namespace Editing;
32 using namespace ARDOUR;
34 InsertRemoveTimeDialog::InsertRemoveTimeDialog (PublicEditor& e, bool remove)
35 : ArdourDialog (remove ? _("Remove Time") : _("Insert Time"))
37 , duration_clock ("insertTimeClock", true, "",
39 false, // follows_playhead
42 true // accept_on_focus_out
44 , position_clock ("insertPosTimeClock", true, "",
46 false, // follows_playhead
49 true // accept_on_focus_out
52 set_session (_editor.session ());
54 get_vbox()->set_border_width (12);
55 get_vbox()->set_spacing (4);
57 Table* table = manage (new Table (2, 3));
58 table->set_spacings (4);
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()->secondary_clock->mode());
65 table->attach (position_clock, 1, 2, 0, 1);
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()->secondary_clock->mode());
72 table->attach (duration_clock, 1, 2, 1, 2);
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_frame(), true, _editor.get_selection().time.start() );
78 duration_clock.set_bbt_reference (_editor.get_selection().time.start());
80 framepos_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);
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);
97 get_vbox()->pack_start (*table);
99 _all_playlists.set_label (_("Apply to all the track's playlists"));
100 get_vbox()->pack_start (_all_playlists);
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);
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);
132 move_markers_toggled ();
136 InsertRemoveTimeDialog::intersected_region_action ()
138 /* only setting this to keep GCC quiet */
139 InsertTimeOption opt = LeaveIntersected;
141 switch (_intersected_combo.get_active_row_number ()) {
143 opt = LeaveIntersected;
146 opt = MoveIntersected;
149 opt = SplitIntersected;
157 InsertRemoveTimeDialog::all_playlists () const
159 return _all_playlists.get_active ();
163 InsertRemoveTimeDialog::move_glued () const
165 return _move_glued.get_active ();
169 InsertRemoveTimeDialog::move_tempos () const
171 return _move_tempos.get_active ();
175 InsertRemoveTimeDialog::move_markers () const
177 return _move_markers.get_active ();
181 InsertRemoveTimeDialog::move_glued_markers () const
183 return _move_glued_markers.get_active ();
187 InsertRemoveTimeDialog::move_locked_markers () const
189 return _move_locked_markers.get_active ();
193 InsertRemoveTimeDialog::position () const
195 return position_clock.current_time();
199 InsertRemoveTimeDialog::distance () const
201 return duration_clock.current_duration ( position_clock.current_time() );
205 InsertRemoveTimeDialog::doit ()
207 if (distance () == 0) {
208 Gtk::MessageDialog msg (*this, _("Invalid or zero duration entered. Please enter a valid duration"));
212 response (RESPONSE_OK);
216 InsertRemoveTimeDialog::move_markers_toggled ()
218 _move_glued_markers.set_sensitive (_move_markers.get_active ());
219 _move_locked_markers.set_sensitive (_move_markers.get_active ());