2 * Copyright (C) 2011-2017 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
4 * Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
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.
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.
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.
22 #include "pbd/compose.h"
24 #include "gtkmm2ext/gui_thread.h"
25 #include "gtkmm2ext/utils.h"
26 #include "gtkmm2ext/actions.h"
28 #include "ardour/location.h"
29 #include "ardour/profile.h"
30 #include "ardour/session.h"
32 #include "audio_clock.h"
33 #include "automation_line.h"
34 #include "control_point.h"
36 #include "region_view.h"
37 #include "time_info_box.h"
42 using namespace ARDOUR;
46 TimeInfoBox::TimeInfoBox (std::string state_node_name, bool with_punch)
50 , syncing_selection (false)
51 , syncing_punch (false)
52 , with_punch_clock (with_punch)
54 set_name (X_("TimeInfoBox"));
56 selection_start = new AudioClock (
57 string_compose ("%1-selection-start", state_node_name),
58 false, "selection", false, false, false, false);
59 selection_end = new AudioClock (
60 string_compose ("%1-selection-end", state_node_name),
61 false, "selection", false, false, false, false);
62 selection_length = new AudioClock (
63 string_compose ("%1-selection-length", state_node_name),
64 false, "selection", false, false, true, false);
66 selection_title.set_text (_("Selection"));
68 set_homogeneous (false);
72 pack_start (table, false, false);
74 table.set_homogeneous (false);
75 table.set_spacings (0);
76 table.set_border_width (2);
77 table.set_col_spacings (2);
81 selection_title.set_name ("TimeInfoSelectionTitle");
82 if (with_punch_clock) {
83 table.attach (selection_title, 1, 2, 0, 1);
85 l = manage (new Label);
86 l->set_text (_("Start"));
87 l->set_alignment (1.0, 0.5);
88 l->set_name (X_("TimeInfoSelectionLabel"));
89 table.attach (*l, 0, 1, 1, 2, FILL);
90 table.attach (*selection_start, 1, 2, 1, 2);
92 l = manage (new Label);
93 l->set_text (_("End"));
94 l->set_alignment (1.0, 0.5);
95 l->set_name (X_("TimeInfoSelectionLabel"));
96 table.attach (*l, 0, 1, 2, 3, FILL);
97 table.attach (*selection_end, 1, 2, 2, 3);
99 l = manage (new Label);
100 l->set_text (_("Length"));
101 l->set_alignment (1.0, 0.5);
102 l->set_name (X_("TimeInfoSelectionLabel"));
103 table.attach (*l, 0, 1, 3, 4, FILL);
104 table.attach (*selection_length, 1, 2, 3, 4);
106 if (with_punch_clock) {
107 punch_start = new AudioClock (
108 string_compose ("%1-punch-start", state_node_name),
109 false, "punch", false, false, false, false);
110 punch_end = new AudioClock (
111 string_compose ("%1-punch-end", state_node_name),
112 false, "punch", false, false, false, false);
113 punch_title.set_text (_("Punch"));
115 punch_title.set_name ("TimeInfoSelectionTitle");
116 table.attach (punch_title, 2, 3, 0, 1);
117 table.attach (*punch_start, 2, 3, 1, 2);
118 table.attach (*punch_end, 2, 3, 2, 3);
123 selection_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_start));
124 selection_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_end));
125 selection_length->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_length));
127 selection_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_start), true);
128 selection_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_end), true);
130 if (with_punch_clock) {
131 punch_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_start));
132 punch_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_end));
134 punch_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_start), true);
135 punch_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_end), true);
138 Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
139 Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
141 Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), boost::bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
144 TimeInfoBox::~TimeInfoBox ()
146 delete selection_length;
147 delete selection_end;
148 delete selection_start;
155 TimeInfoBox::track_mouse_mode ()
157 selection_changed ();
161 TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src)
167 if (ev->button == 1) {
169 _session->request_locate (src->current_time ());
178 TimeInfoBox::sync_selection_mode (AudioClock* src)
180 if (!syncing_selection) {
181 syncing_selection = true;
182 selection_start->set_mode (src->mode());
183 selection_end->set_mode (src->mode());
184 selection_length->set_mode (src->mode());
185 syncing_selection = false;
190 TimeInfoBox::sync_punch_mode (AudioClock* src)
192 if (!with_punch_clock) {
195 if (!syncing_punch) {
196 syncing_punch = true;
197 punch_start->set_mode (src->mode());
198 punch_end->set_mode (src->mode());
199 syncing_punch = false;
205 TimeInfoBox::set_session (Session* s)
207 SessionHandlePtr::set_session (s);
209 selection_start->set_session (s);
210 selection_end->set_session (s);
211 selection_length->set_session (s);
213 if (!with_punch_clock) {
217 punch_start->set_session (s);
218 punch_end->set_session (s);
221 Location* punch = s->locations()->auto_punch_location ();
227 punch_changed (punch);
229 _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR,
230 boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context());
235 TimeInfoBox::region_selection_changed ()
238 Selection& selection (Editor::instance().get_selection());
239 s = selection.regions.start();
240 e = selection.regions.end_sample();
241 selection_start->set_off (false);
242 selection_end->set_off (false);
243 selection_length->set_off (false);
244 selection_start->set (s);
245 selection_end->set (e);
246 selection_length->set (e, false, s);
250 TimeInfoBox::selection_changed ()
253 Selection& selection (Editor::instance().get_selection());
255 region_property_connections.drop_connections();
257 switch (Editor::instance().current_mouse_mode()) {
259 case Editing::MouseContent:
260 /* displaying MIDI note selection is tricky */
261 selection_start->set_off (true);
262 selection_end->set_off (true);
263 selection_length->set_off (true);
266 case Editing::MouseObject:
267 if (selection.regions.empty()) {
268 if (selection.points.empty()) {
269 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("MouseMode", "set-mouse-mode-object-range");
270 if (tact->get_active() && !selection.time.empty()) {
271 /* show selected range */
272 selection_start->set_off (false);
273 selection_end->set_off (false);
274 selection_length->set_off (false);
275 selection_start->set (selection.time.start());
276 selection_end->set (selection.time.end_sample());
277 selection_length->set (selection.time.end_sample(), false, selection.time.start());
279 selection_start->set_off (true);
280 selection_end->set_off (true);
281 selection_length->set_off (true);
286 for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
287 samplepos_t const p = (*i)->line().session_position ((*i)->model ());
291 selection_start->set_off (false);
292 selection_end->set_off (false);
293 selection_length->set_off (false);
294 selection_start->set (s);
295 selection_end->set (e);
296 selection_length->set (e, false, s);
299 /* this is more efficient than tracking changes per region in large selections */
300 std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists;
301 for (RegionSelection::iterator s = selection.regions.begin(); s != selection.regions.end(); ++s) {
302 boost::shared_ptr<Playlist> pl = (*s)->region()->playlist();
304 playlists.insert (pl);
307 for (std::set<boost::shared_ptr<ARDOUR::Playlist> >::iterator ps = playlists.begin(); ps != playlists.end(); ++ps) {
308 (*ps)->ContentsChanged.connect (region_property_connections, invalidator (*this),
309 boost::bind (&TimeInfoBox::region_selection_changed, this), gui_context());
311 region_selection_changed ();
315 case Editing::MouseRange:
316 if (selection.time.empty()) {
317 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("MouseMode", "set-mouse-mode-object-range");
319 if (tact->get_active() && !selection.regions.empty()) {
320 /* show selected regions */
321 s = selection.regions.start();
322 e = selection.regions.end_sample();
323 selection_start->set_off (false);
324 selection_end->set_off (false);
325 selection_length->set_off (false);
326 selection_start->set (s);
327 selection_end->set (e);
328 selection_length->set (e, false, s);
330 selection_start->set_off (true);
331 selection_end->set_off (true);
332 selection_length->set_off (true);
335 selection_start->set_off (false);
336 selection_end->set_off (false);
337 selection_length->set_off (false);
338 selection_start->set (selection.time.start());
339 selection_end->set (selection.time.end_sample());
340 selection_length->set (selection.time.end_sample(), false, selection.time.start());
345 selection_start->set_off (true);
346 selection_end->set_off (true);
347 selection_length->set_off (true);
353 TimeInfoBox::punch_location_changed (Location* loc)
355 if (loc && with_punch_clock) {
361 TimeInfoBox::watch_punch (Location* punch)
363 assert (with_punch_clock);
364 punch_connections.drop_connections ();
366 punch->start_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
367 punch->end_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
369 punch_changed (punch);
373 TimeInfoBox::punch_changed (Location* loc)
375 assert (with_punch_clock);
377 punch_start->set_off (true);
378 punch_end->set_off (true);
382 punch_start->set_off (false);
383 punch_end->set_off (false);
385 punch_start->set (loc->start());
386 punch_end->set (loc->end());