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/cairocell.h"
24 #include "gtkmm2ext/gui_thread.h"
25 #include "gtkmm2ext/utils.h"
26 #include "gtkmm2ext/stateful_button.h"
27 #include "gtkmm2ext/actions.h"
29 #include "ardour/location.h"
30 #include "ardour/profile.h"
31 #include "ardour/session.h"
33 #include "time_info_box.h"
34 #include "audio_clock.h"
36 #include "control_point.h"
37 #include "automation_line.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 Region::RegionPropertyChanged.connect (region_property_connections, invalidator (*this), boost::bind (&TimeInfoBox::region_property_change, this, _1, _2), gui_context());
142 Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), boost::bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
145 TimeInfoBox::~TimeInfoBox ()
147 delete selection_length;
148 delete selection_end;
149 delete selection_start;
156 TimeInfoBox::track_mouse_mode ()
158 selection_changed ();
162 TimeInfoBox::region_property_change (boost::shared_ptr<ARDOUR::Region> r, const PBD::PropertyChange& what_changed)
164 Selection& selection (Editor::instance().get_selection());
166 if (selection.regions.empty()) {
170 PBD::PropertyChange our_interests;
172 our_interests.add (ARDOUR::Properties::position);
173 our_interests.add (ARDOUR::Properties::length);
174 our_interests.add (ARDOUR::Properties::start);
176 if (!what_changed.contains (our_interests)) {
180 if (selection.regions.contains (r)) {
181 selection_changed ();
186 TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src)
192 if (ev->button == 1) {
194 _session->request_locate (src->current_time ());
203 TimeInfoBox::sync_selection_mode (AudioClock* src)
205 if (!syncing_selection) {
206 syncing_selection = true;
207 selection_start->set_mode (src->mode());
208 selection_end->set_mode (src->mode());
209 selection_length->set_mode (src->mode());
210 syncing_selection = false;
215 TimeInfoBox::sync_punch_mode (AudioClock* src)
217 if (!with_punch_clock) {
220 if (!syncing_punch) {
221 syncing_punch = true;
222 punch_start->set_mode (src->mode());
223 punch_end->set_mode (src->mode());
224 syncing_punch = false;
230 TimeInfoBox::set_session (Session* s)
232 SessionHandlePtr::set_session (s);
234 selection_start->set_session (s);
235 selection_end->set_session (s);
236 selection_length->set_session (s);
238 if (!with_punch_clock) {
242 punch_start->set_session (s);
243 punch_end->set_session (s);
246 Location* punch = s->locations()->auto_punch_location ();
252 punch_changed (punch);
254 _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR,
255 boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context());
260 TimeInfoBox::selection_changed ()
263 Selection& selection (Editor::instance().get_selection());
265 switch (Editor::instance().current_mouse_mode()) {
267 case Editing::MouseContent:
268 /* displaying MIDI note selection is tricky */
269 selection_start->set_off (true);
270 selection_end->set_off (true);
271 selection_length->set_off (true);
274 case Editing::MouseObject:
275 if (selection.regions.empty()) {
276 if (selection.points.empty()) {
277 Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
278 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
280 if (tact && tact->get_active() && !selection.time.empty()) {
281 /* show selected range */
282 selection_start->set_off (false);
283 selection_end->set_off (false);
284 selection_length->set_off (false);
285 selection_start->set (selection.time.start());
286 selection_end->set (selection.time.end_frame());
287 selection_length->set (selection.time.length());
289 selection_start->set_off (true);
290 selection_end->set_off (true);
291 selection_length->set_off (true);
296 for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
297 framepos_t const p = (*i)->line().session_position ((*i)->model ());
301 selection_start->set_off (false);
302 selection_end->set_off (false);
303 selection_length->set_off (false);
304 selection_start->set (s);
305 selection_end->set (e);
306 selection_length->set (e - s + 1);
309 s = selection.regions.start();
310 e = selection.regions.end_frame();
311 selection_start->set_off (false);
312 selection_end->set_off (false);
313 selection_length->set_off (false);
314 selection_start->set (s);
315 selection_end->set (e);
316 selection_length->set (e - s + 1);
320 case Editing::MouseRange:
321 if (selection.time.empty()) {
322 Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
323 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
325 if (tact && tact->get_active() && !selection.regions.empty()) {
326 /* show selected regions */
327 s = selection.regions.start();
328 e = selection.regions.end_frame();
329 selection_start->set_off (false);
330 selection_end->set_off (false);
331 selection_length->set_off (false);
332 selection_start->set (s);
333 selection_end->set (e);
334 selection_length->set (e - s + 1);
336 selection_start->set_off (true);
337 selection_end->set_off (true);
338 selection_length->set_off (true);
341 selection_start->set_off (false);
342 selection_end->set_off (false);
343 selection_length->set_off (false);
344 selection_start->set (selection.time.start());
345 selection_end->set (selection.time.end_frame());
346 selection_length->set (selection.time.length());
351 selection_start->set_off (true);
352 selection_end->set_off (true);
353 selection_length->set_off (true);
359 TimeInfoBox::punch_location_changed (Location* loc)
361 if (loc && with_punch_clock) {
367 TimeInfoBox::watch_punch (Location* punch)
369 assert (with_punch_clock);
370 punch_connections.drop_connections ();
372 punch->start_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
373 punch->end_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
375 punch_changed (punch);
379 TimeInfoBox::punch_changed (Location* loc)
381 assert (with_punch_clock);
383 punch_start->set_off (true);
384 punch_end->set_off (true);
388 punch_start->set_off (false);
389 punch_end->set_off (false);
391 punch_start->set (loc->start());
392 punch_end->set (loc->end());