2 Copyright (C) 2011 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.
21 #include "pbd/compose.h"
23 #include "gtkmm2ext/gui_thread.h"
24 #include "gtkmm2ext/utils.h"
25 #include "gtkmm2ext/actions.h"
27 #include "ardour/location.h"
28 #include "ardour/profile.h"
29 #include "ardour/session.h"
31 #include "time_info_box.h"
32 #include "audio_clock.h"
34 #include "control_point.h"
35 #include "automation_line.h"
40 using namespace ARDOUR;
44 TimeInfoBox::TimeInfoBox (std::string state_node_name, bool with_punch)
48 , syncing_selection (false)
49 , syncing_punch (false)
50 , with_punch_clock (with_punch)
52 set_name (X_("TimeInfoBox"));
54 selection_start = new AudioClock (
55 string_compose ("%1-selection-start", state_node_name),
56 false, "selection", false, false, false, false);
57 selection_end = new AudioClock (
58 string_compose ("%1-selection-end", state_node_name),
59 false, "selection", false, false, false, false);
60 selection_length = new AudioClock (
61 string_compose ("%1-selection-length", state_node_name),
62 false, "selection", false, false, true, false);
64 selection_title.set_text (_("Selection"));
66 set_homogeneous (false);
70 pack_start (table, false, false);
72 table.set_homogeneous (false);
73 table.set_spacings (0);
74 table.set_border_width (2);
75 table.set_col_spacings (2);
79 selection_title.set_name ("TimeInfoSelectionTitle");
80 if (with_punch_clock) {
81 table.attach (selection_title, 1, 2, 0, 1);
83 l = manage (new Label);
84 l->set_text (_("Start"));
85 l->set_alignment (1.0, 0.5);
86 l->set_name (X_("TimeInfoSelectionLabel"));
87 table.attach (*l, 0, 1, 1, 2, FILL);
88 table.attach (*selection_start, 1, 2, 1, 2);
90 l = manage (new Label);
91 l->set_text (_("End"));
92 l->set_alignment (1.0, 0.5);
93 l->set_name (X_("TimeInfoSelectionLabel"));
94 table.attach (*l, 0, 1, 2, 3, FILL);
95 table.attach (*selection_end, 1, 2, 2, 3);
97 l = manage (new Label);
98 l->set_text (_("Length"));
99 l->set_alignment (1.0, 0.5);
100 l->set_name (X_("TimeInfoSelectionLabel"));
101 table.attach (*l, 0, 1, 3, 4, FILL);
102 table.attach (*selection_length, 1, 2, 3, 4);
104 if (with_punch_clock) {
105 punch_start = new AudioClock (
106 string_compose ("%1-punch-start", state_node_name),
107 false, "punch", false, false, false, false);
108 punch_end = new AudioClock (
109 string_compose ("%1-punch-end", state_node_name),
110 false, "punch", false, false, false, false);
111 punch_title.set_text (_("Punch"));
113 punch_title.set_name ("TimeInfoSelectionTitle");
114 table.attach (punch_title, 2, 3, 0, 1);
115 table.attach (*punch_start, 2, 3, 1, 2);
116 table.attach (*punch_end, 2, 3, 2, 3);
121 selection_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_start));
122 selection_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_end));
123 selection_length->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_length));
125 selection_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_start), true);
126 selection_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_end), true);
128 if (with_punch_clock) {
129 punch_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_start));
130 punch_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_end));
132 punch_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_start), true);
133 punch_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_end), true);
136 Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
137 Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
139 Region::RegionPropertyChanged.connect (region_property_connections, invalidator (*this), boost::bind (&TimeInfoBox::region_property_change, this, _1, _2), gui_context());
140 Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), boost::bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
143 TimeInfoBox::~TimeInfoBox ()
145 delete selection_length;
146 delete selection_end;
147 delete selection_start;
154 TimeInfoBox::track_mouse_mode ()
156 selection_changed ();
160 TimeInfoBox::region_property_change (boost::shared_ptr<ARDOUR::Region> r, const PBD::PropertyChange& what_changed)
162 Selection& selection (Editor::instance().get_selection());
164 if (selection.regions.empty()) {
168 PBD::PropertyChange our_interests;
170 our_interests.add (ARDOUR::Properties::position);
171 our_interests.add (ARDOUR::Properties::length);
172 our_interests.add (ARDOUR::Properties::start);
174 if (!what_changed.contains (our_interests)) {
178 if (selection.regions.contains (r)) {
179 selection_changed ();
184 TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src)
190 if (ev->button == 1) {
192 _session->request_locate (src->current_time ());
201 TimeInfoBox::sync_selection_mode (AudioClock* src)
203 if (!syncing_selection) {
204 syncing_selection = true;
205 selection_start->set_mode (src->mode());
206 selection_end->set_mode (src->mode());
207 selection_length->set_mode (src->mode());
208 syncing_selection = false;
213 TimeInfoBox::sync_punch_mode (AudioClock* src)
215 if (!with_punch_clock) {
218 if (!syncing_punch) {
219 syncing_punch = true;
220 punch_start->set_mode (src->mode());
221 punch_end->set_mode (src->mode());
222 syncing_punch = false;
228 TimeInfoBox::set_session (Session* s)
230 SessionHandlePtr::set_session (s);
232 selection_start->set_session (s);
233 selection_end->set_session (s);
234 selection_length->set_session (s);
236 if (!with_punch_clock) {
240 punch_start->set_session (s);
241 punch_end->set_session (s);
244 Location* punch = s->locations()->auto_punch_location ();
250 punch_changed (punch);
252 _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR,
253 boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context());
258 TimeInfoBox::selection_changed ()
261 Selection& selection (Editor::instance().get_selection());
263 switch (Editor::instance().current_mouse_mode()) {
265 case Editing::MouseContent:
266 /* displaying MIDI note selection is tricky */
267 selection_start->set_off (true);
268 selection_end->set_off (true);
269 selection_length->set_off (true);
272 case Editing::MouseObject:
273 if (selection.regions.empty()) {
274 if (selection.points.empty()) {
275 Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
276 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
278 if (tact && tact->get_active() && !selection.time.empty()) {
279 /* show selected range */
280 selection_start->set_off (false);
281 selection_end->set_off (false);
282 selection_length->set_off (false);
283 selection_start->set (selection.time.start());
284 selection_end->set (selection.time.end_frame());
285 selection_length->set (selection.time.length());
287 selection_start->set_off (true);
288 selection_end->set_off (true);
289 selection_length->set_off (true);
294 for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
295 framepos_t const p = (*i)->line().session_position ((*i)->model ());
299 selection_start->set_off (false);
300 selection_end->set_off (false);
301 selection_length->set_off (false);
302 selection_start->set (s);
303 selection_end->set (e);
304 selection_length->set (e - s + 1);
307 s = selection.regions.start();
308 e = selection.regions.end_frame();
309 selection_start->set_off (false);
310 selection_end->set_off (false);
311 selection_length->set_off (false);
312 selection_start->set (s);
313 selection_end->set (e);
314 selection_length->set (e - s + 1);
318 case Editing::MouseRange:
319 if (selection.time.empty()) {
320 Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
321 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
323 if (tact && tact->get_active() && !selection.regions.empty()) {
324 /* show selected regions */
325 s = selection.regions.start();
326 e = selection.regions.end_frame();
327 selection_start->set_off (false);
328 selection_end->set_off (false);
329 selection_length->set_off (false);
330 selection_start->set (s);
331 selection_end->set (e);
332 selection_length->set (e - s + 1);
334 selection_start->set_off (true);
335 selection_end->set_off (true);
336 selection_length->set_off (true);
339 selection_start->set_off (false);
340 selection_end->set_off (false);
341 selection_length->set_off (false);
342 selection_start->set (selection.time.start());
343 selection_end->set (selection.time.end_frame());
344 selection_length->set (selection.time.length());
349 selection_start->set_off (true);
350 selection_end->set_off (true);
351 selection_length->set_off (true);
357 TimeInfoBox::punch_location_changed (Location* loc)
359 if (loc && with_punch_clock) {
365 TimeInfoBox::watch_punch (Location* punch)
367 assert (with_punch_clock);
368 punch_connections.drop_connections ();
370 punch->start_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
371 punch->end_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
373 punch_changed (punch);
377 TimeInfoBox::punch_changed (Location* loc)
379 assert (with_punch_clock);
381 punch_start->set_off (true);
382 punch_end->set_off (true);
386 punch_start->set_off (false);
387 punch_end->set_off (false);
389 punch_start->set (loc->start());
390 punch_end->set (loc->end());