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 (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 ("selection-start", false, "selection", false, false, false, false);
57 selection_end = new AudioClock ("selection-end", false, "selection", false, false, false, false);
58 selection_length = new AudioClock ("selection-length", false, "selection", false, false, true, false);
60 selection_title.set_text (_("Selection"));
62 set_homogeneous (false);
66 pack_start (table, false, false);
68 table.set_homogeneous (false);
69 table.set_spacings (0);
70 table.set_border_width (2);
71 table.set_col_spacings (2);
75 selection_title.set_name ("TimeInfoSelectionTitle");
76 if (with_punch_clock) {
77 table.attach (selection_title, 1, 2, 0, 1);
79 l = manage (new Label);
80 l->set_text (_("Start"));
81 l->set_alignment (1.0, 0.5);
82 l->set_name (X_("TimeInfoSelectionLabel"));
83 table.attach (*l, 0, 1, 1, 2, FILL);
84 table.attach (*selection_start, 1, 2, 1, 2);
86 l = manage (new Label);
87 l->set_text (_("End"));
88 l->set_alignment (1.0, 0.5);
89 l->set_name (X_("TimeInfoSelectionLabel"));
90 table.attach (*l, 0, 1, 2, 3, FILL);
91 table.attach (*selection_end, 1, 2, 2, 3);
93 l = manage (new Label);
94 l->set_text (_("Length"));
95 l->set_alignment (1.0, 0.5);
96 l->set_name (X_("TimeInfoSelectionLabel"));
97 table.attach (*l, 0, 1, 3, 4, FILL);
98 table.attach (*selection_length, 1, 2, 3, 4);
100 if (with_punch_clock) {
101 punch_start = new AudioClock ("punch-start", false, "punch", false, false, false, false);
102 punch_end = new AudioClock ("punch-end", false, "punch", false, false, false, false);
103 punch_title.set_text (_("Punch"));
105 punch_title.set_name ("TimeInfoSelectionTitle");
106 table.attach (punch_title, 2, 3, 0, 1);
107 table.attach (*punch_start, 2, 3, 1, 2);
108 table.attach (*punch_end, 2, 3, 2, 3);
113 selection_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_start));
114 selection_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_end));
115 selection_length->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_length));
117 selection_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_start), true);
118 selection_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_end), true);
120 if (with_punch_clock) {
121 punch_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_start));
122 punch_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_end));
124 punch_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_start), true);
125 punch_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_end), true);
128 Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
129 Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
131 Region::RegionPropertyChanged.connect (region_property_connections, invalidator (*this), boost::bind (&TimeInfoBox::region_property_change, this, _1, _2), gui_context());
132 Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), boost::bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
135 TimeInfoBox::~TimeInfoBox ()
137 delete selection_length;
138 delete selection_end;
139 delete selection_start;
146 TimeInfoBox::track_mouse_mode ()
148 selection_changed ();
152 TimeInfoBox::region_property_change (boost::shared_ptr<ARDOUR::Region> /* r */, const PBD::PropertyChange& what_changed)
154 Selection& selection (Editor::instance().get_selection());
156 if (selection.regions.empty()) {
160 PBD::PropertyChange our_interests;
162 our_interests.add (ARDOUR::Properties::position);
163 our_interests.add (ARDOUR::Properties::length);
164 our_interests.add (ARDOUR::Properties::start);
166 if (!what_changed.contains (our_interests)) {
170 /* TODO: check if RegionSelection includes the given region.
171 * This is not straight foward because RegionSelection is done by
172 * RegionView (not Region itself).
175 //selection_changed ();
179 TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src)
185 if (ev->button == 1) {
187 _session->request_locate (src->current_time ());
196 TimeInfoBox::sync_selection_mode (AudioClock* src)
198 if (!syncing_selection) {
199 syncing_selection = true;
200 selection_start->set_mode (src->mode());
201 selection_end->set_mode (src->mode());
202 selection_length->set_mode (src->mode());
203 syncing_selection = false;
208 TimeInfoBox::sync_punch_mode (AudioClock* src)
210 if (!with_punch_clock) {
213 if (!syncing_punch) {
214 syncing_punch = true;
215 punch_start->set_mode (src->mode());
216 punch_end->set_mode (src->mode());
217 syncing_punch = false;
223 TimeInfoBox::set_session (Session* s)
225 SessionHandlePtr::set_session (s);
227 selection_start->set_session (s);
228 selection_end->set_session (s);
229 selection_length->set_session (s);
231 if (!with_punch_clock) {
235 punch_start->set_session (s);
236 punch_end->set_session (s);
239 Location* punch = s->locations()->auto_punch_location ();
245 punch_changed (punch);
247 _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR,
248 boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context());
253 TimeInfoBox::selection_changed ()
256 Selection& selection (Editor::instance().get_selection());
258 switch (Editor::instance().current_mouse_mode()) {
260 case Editing::MouseContent:
261 /* displaying MIDI note selection is tricky */
262 selection_start->set_off (true);
263 selection_end->set_off (true);
264 selection_length->set_off (true);
267 case Editing::MouseObject:
268 if (selection.regions.empty()) {
269 if (selection.points.empty()) {
270 Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
271 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
273 if (tact && tact->get_active() && !selection.time.empty()) {
274 /* show selected range */
275 selection_start->set_off (false);
276 selection_end->set_off (false);
277 selection_length->set_off (false);
278 selection_start->set (selection.time.start());
279 selection_end->set (selection.time.end_frame());
280 selection_length->set (selection.time.length());
282 selection_start->set_off (true);
283 selection_end->set_off (true);
284 selection_length->set_off (true);
289 for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
290 framepos_t const p = (*i)->line().session_position ((*i)->model ());
294 selection_start->set_off (false);
295 selection_end->set_off (false);
296 selection_length->set_off (false);
297 selection_start->set (s);
298 selection_end->set (e);
299 selection_length->set (e - s + 1);
302 s = selection.regions.start();
303 e = selection.regions.end_frame();
304 selection_start->set_off (false);
305 selection_end->set_off (false);
306 selection_length->set_off (false);
307 selection_start->set (s);
308 selection_end->set (e);
309 selection_length->set (e - s + 1);
313 case Editing::MouseRange:
314 if (selection.time.empty()) {
315 Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
316 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
318 if (tact && tact->get_active() && !selection.regions.empty()) {
319 /* show selected regions */
320 s = selection.regions.start();
321 e = selection.regions.end_frame();
322 selection_start->set_off (false);
323 selection_end->set_off (false);
324 selection_length->set_off (false);
325 selection_start->set (s);
326 selection_end->set (e);
327 selection_length->set (e - s + 1);
329 selection_start->set_off (true);
330 selection_end->set_off (true);
331 selection_length->set_off (true);
334 selection_start->set_off (false);
335 selection_end->set_off (false);
336 selection_length->set_off (false);
337 selection_start->set (selection.time.start());
338 selection_end->set (selection.time.end_frame());
339 selection_length->set (selection.time.length());
344 selection_start->set_off (true);
345 selection_end->set_off (true);
346 selection_length->set_off (true);
352 TimeInfoBox::punch_location_changed (Location* loc)
354 if (loc && with_punch_clock) {
360 TimeInfoBox::watch_punch (Location* punch)
362 assert (with_punch_clock);
363 punch_connections.drop_connections ();
365 punch->start_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
366 punch->end_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
368 punch_changed (punch);
372 TimeInfoBox::punch_changed (Location* loc)
374 assert (with_punch_clock);
376 punch_start->set_off (true);
377 punch_end->set_off (true);
381 punch_start->set_off (false);
382 punch_end->set_off (false);
384 punch_start->set (loc->start());
385 punch_end->set (loc->end());