1 /*
2 * Copyright (C) 2015-2016 Colin Fletcher <colin.m.fletcher@googlemail.com>
3 * Copyright (C) 2016-2018 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2016 Ben Loftis <ben@harrisonconsoles.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include <gtkmm/table.h>
22 #include <gtkmm/comboboxtext.h>
23 #include <gtkmm/stock.h>
24 #include <gtkmm/alignment.h>
25 #include "insert_remove_time_dialog.h"
26 #include "audio_clock.h"
27 #include "ardour_ui.h"
28 #include "main_clock.h"
29 #include "pbd/i18n.h"
30
31 using namespace Gtk;
32 using namespace Editing;
33 using namespace ARDOUR;
34
InsertRemoveTimeDialog(PublicEditor & e,bool remove)35 InsertRemoveTimeDialog::InsertRemoveTimeDialog (PublicEditor& e, bool remove)
36 : ArdourDialog (remove ? _("Remove Time") : _("Insert Time"))
37 , _editor (e)
38 , duration_clock ("insertTimeClock", true, "",
39 true, // editable
40 false, // follows_playhead
41 true, // duration
42 false, // with_info
43 true // accept_on_focus_out
44 )
45 , position_clock ("insertPosTimeClock", true, "",
46 true, // editable
47 false, // follows_playhead
48 false, // duration
49 false, // with_info
50 true // accept_on_focus_out
51 )
52 {
53 set_session (_editor.session ());
54
55 get_vbox()->set_border_width (12);
56 get_vbox()->set_spacing (4);
57
58 Table* table = manage (new Table (2, 3));
59 table->set_spacings (4);
60
61 Label* time_label = manage (new Label (remove ? _("Remove Time starting at:") : _("Insert Time starting at:")));
62 time_label->set_alignment (1, 0.5);
63 table->attach (*time_label, 0, 1, 0, 1, FILL | EXPAND);
64 position_clock.set_session (_session);
65 position_clock.set_mode (ARDOUR_UI::instance()->primary_clock->mode());
66 table->attach (position_clock, 1, 2, 0, 1);
67
68 time_label = manage (new Label (remove ? _("Time to remove:") : _("Time to insert:")));
69 time_label->set_alignment (1, 0.5);
70 table->attach (*time_label, 0, 1, 1, 2, FILL | EXPAND);
71 duration_clock.set_session (_session);
72 duration_clock.set_mode (ARDOUR_UI::instance()->primary_clock->mode());
73 table->attach (duration_clock, 1, 2, 1, 2);
74
75 //if a Range is selected, assume the user wants to insert/remove the length of the range
76 if ( _editor.get_selection().time.length() != 0 ) {
77 position_clock.set ( _editor.get_selection().time.start(), true );
78 duration_clock.set ( _editor.get_selection().time.end_sample(), true, _editor.get_selection().time.start() );
79 duration_clock.set_bbt_reference (_editor.get_selection().time.start());
80 } else {
81 samplepos_t const pos = _editor.get_preferred_edit_position (EDIT_IGNORE_MOUSE);
82 position_clock.set ( pos, true );
83 duration_clock.set_bbt_reference (pos);
84 duration_clock.set (0);
85 }
86
87 if (!remove) {
88 Label* intersected_label = manage (new Label (_("Intersected regions should:")));
89 intersected_label->set_alignment (1, 0.5);
90 table->attach (*intersected_label, 0, 1, 2, 3, FILL | EXPAND);
91 _intersected_combo.append_text (_("stay in position"));
92 _intersected_combo.append_text (_("move"));
93 _intersected_combo.append_text (_("be split"));
94 _intersected_combo.set_active (0);
95 table->attach (_intersected_combo, 1, 2, 2, 3);
96 }
97
98 get_vbox()->pack_start (*table);
99
100 _all_playlists.set_label (_("Apply to all playlists of the selected track(s)"));
101 get_vbox()->pack_start (_all_playlists);
102
103 _move_glued.set_label (_("Move glued-to-musical-time regions (MIDI regions)"));
104 _move_glued.set_active();
105 get_vbox()->pack_start (_move_glued);
106 _move_markers.set_label (_("Move markers"));
107 get_vbox()->pack_start (_move_markers);
108 _move_markers.signal_toggled().connect (sigc::mem_fun (*this, &InsertRemoveTimeDialog::move_markers_toggled));
109 _move_glued_markers.set_label (_("Move glued-to-musical-time markers"));
110 _move_glued_markers.set_active();
111 Alignment* indent = manage (new Alignment);
112 indent->set_padding (0, 0, 12, 0);
113 indent->add (_move_glued_markers);
114 get_vbox()->pack_start (*indent);
115 _move_locked_markers.set_label (_("Move locked markers"));
116 indent = manage (new Alignment);
117 indent->set_padding (0, 0, 12, 0);
118 indent->add (_move_locked_markers);
119 get_vbox()->pack_start (*indent);
120 tempo_label.set_markup (_("Move tempo and meter changes\n<i>(may cause oddities in the tempo map)</i>"));
121 HBox* tempo_box = manage (new HBox);
122 tempo_box->set_spacing (6);
123 tempo_box->pack_start (_move_tempos, false, false);
124 tempo_box->pack_start (tempo_label, false, false);
125 get_vbox()->pack_start (*tempo_box);
126
127 add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
128 Gtk::Button *btn = manage (new Gtk::Button (remove ? _("Remove time") : _("Insert time")));
129 btn->signal_clicked().connect (sigc::mem_fun(*this, &InsertRemoveTimeDialog::doit));
130 get_action_area()->pack_start (*btn);
131 show_all ();
132
133 move_markers_toggled ();
134 }
135
136 InsertTimeOption
intersected_region_action()137 InsertRemoveTimeDialog::intersected_region_action ()
138 {
139 /* only setting this to keep GCC quiet */
140 InsertTimeOption opt = LeaveIntersected;
141
142 switch (_intersected_combo.get_active_row_number ()) {
143 case 0:
144 opt = LeaveIntersected;
145 break;
146 case 1:
147 opt = MoveIntersected;
148 break;
149 case 2:
150 opt = SplitIntersected;
151 break;
152 }
153
154 return opt;
155 }
156
157 bool
all_playlists() const158 InsertRemoveTimeDialog::all_playlists () const
159 {
160 return _all_playlists.get_active ();
161 }
162
163 bool
move_glued() const164 InsertRemoveTimeDialog::move_glued () const
165 {
166 return _move_glued.get_active ();
167 }
168
169 bool
move_tempos() const170 InsertRemoveTimeDialog::move_tempos () const
171 {
172 return _move_tempos.get_active ();
173 }
174
175 bool
move_markers() const176 InsertRemoveTimeDialog::move_markers () const
177 {
178 return _move_markers.get_active ();
179 }
180
181 bool
move_glued_markers() const182 InsertRemoveTimeDialog::move_glued_markers () const
183 {
184 return _move_glued_markers.get_active ();
185 }
186
187 bool
move_locked_markers() const188 InsertRemoveTimeDialog::move_locked_markers () const
189 {
190 return _move_locked_markers.get_active ();
191 }
192
193 samplepos_t
position() const194 InsertRemoveTimeDialog::position () const
195 {
196 return position_clock.current_time();
197 }
198
199 samplepos_t
distance() const200 InsertRemoveTimeDialog::distance () const
201 {
202 return duration_clock.current_duration ( position_clock.current_time() );
203 }
204
205 void
doit()206 InsertRemoveTimeDialog::doit ()
207 {
208 if (distance () == 0) {
209 Gtk::MessageDialog msg (*this, _("Invalid or zero duration entered. Please enter a valid duration"));
210 msg.run ();
211 return;
212 }
213 response (RESPONSE_OK);
214 }
215
216 void
move_markers_toggled()217 InsertRemoveTimeDialog::move_markers_toggled ()
218 {
219 _move_glued_markers.set_sensitive (_move_markers.get_active ());
220 _move_locked_markers.set_sensitive (_move_markers.get_active ());
221 }
222