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/session.h"
32 #include "time_info_box.h"
33 #include "audio_clock.h"
39 using namespace ARDOUR;
43 TimeInfoBox::TimeInfoBox ()
46 , syncing_selection (false)
47 , syncing_punch (false)
49 selection_start = new AudioClock ("selection-start", false, "selection", false, false, false, false);
50 selection_end = new AudioClock ("selection-end", false, "selection", false, false, false, false);
51 selection_length = new AudioClock ("selection-length", false, "selection", false, false, true, false);
53 punch_start = new AudioClock ("punch-start", false, "punch", false, false, false, false);
54 punch_end = new AudioClock ("punch-end", false, "punch", false, false, false, false);
56 selection_start->set_draw_background (false);
57 selection_end->set_draw_background (false);
58 selection_length->set_draw_background (false);
59 punch_start->set_draw_background (false);
60 punch_end->set_draw_background (false);
62 selection_title.set_text (_("Selection"));
63 punch_title.set_text (_("Punch"));
65 set_homogeneous (false);
69 pack_start (left, true, true);
70 pack_start (right, true, true);
72 left.set_homogeneous (false);
73 left.set_spacings (0);
74 left.set_border_width (2);
75 left.set_col_spacings (2);
77 right.set_homogeneous (false);
78 right.set_spacings (0);
79 right.set_border_width (2);
80 right.set_col_spacings (2);
84 selection_title.set_name ("TimeInfoSelectionTitle");
85 left.attach (selection_title, 0, 2, 0, 1);
86 l = manage (new Label);
87 l->set_text (_("Start"));
88 l->set_alignment (1.0, 0.5);
89 l->set_name (X_("TimeInfoSelectionLabel"));
90 left.attach (*l, 0, 1, 1, 2, FILL);
91 left.attach (*selection_start, 1, 2, 1, 2);
93 l = manage (new Label);
94 l->set_text (_("End"));
95 l->set_alignment (1.0, 0.5);
96 l->set_name (X_("TimeInfoSelectionLabel"));
97 left.attach (*l, 0, 1, 2, 3, FILL);
98 left.attach (*selection_end, 1, 2, 2, 3);
100 l = manage (new Label);
101 l->set_text (_("Length"));
102 l->set_alignment (1.0, 0.5);
103 l->set_name (X_("TimeInfoSelectionLabel"));
104 left.attach (*l, 0, 1, 3, 4, FILL);
105 left.attach (*selection_length, 1, 2, 3, 4);
107 punch_in_button.set_name ("punch button");
108 punch_out_button.set_name ("punch button");
109 punch_in_button.set_text (_("In"));
110 punch_out_button.set_text (_("Out"));
112 Glib::RefPtr<Action> act = ActionManager::get_action ("Transport", "TogglePunchIn");
113 punch_in_button.set_related_action (act);
114 act = ActionManager::get_action ("Transport", "TogglePunchOut");
115 punch_out_button.set_related_action (act);
117 Gtkmm2ext::UI::instance()->set_tip (punch_in_button, _("Start recording at auto-punch start"));
118 Gtkmm2ext::UI::instance()->set_tip (punch_out_button, _("Stop recording at auto-punch end"));
120 punch_title.set_name ("TimeInfoSelectionTitle");
121 right.attach (punch_title, 2, 4, 0, 1);
122 right.attach (punch_in_button, 2, 3, 1, 2, FILL, SHRINK);
123 right.attach (*punch_start, 3, 4, 1, 2);
124 right.attach (punch_out_button, 2, 3, 2, 3, FILL, SHRINK);
125 right.attach (*punch_end, 3, 4, 2, 3);
129 selection_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_start));
130 selection_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_end));
131 selection_length->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_length));
133 punch_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_start));
134 punch_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_end));
136 selection_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_start), true);
137 selection_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_end), true);
139 punch_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_start), true);
140 punch_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_end), true);
142 Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
143 Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
145 Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), ui_bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
148 TimeInfoBox::~TimeInfoBox ()
150 delete selection_length;
151 delete selection_end;
152 delete selection_start;
159 TimeInfoBox::track_mouse_mode ()
161 selection_changed ();
165 TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src)
171 if (ev->button == 1) {
173 _session->request_locate (src->current_time ());
182 TimeInfoBox::sync_selection_mode (AudioClock* src)
184 if (!syncing_selection) {
185 syncing_selection = true;
186 selection_start->set_mode (src->mode());
187 selection_end->set_mode (src->mode());
188 selection_length->set_mode (src->mode());
189 syncing_selection = false;
194 TimeInfoBox::sync_punch_mode (AudioClock* src)
196 if (!syncing_punch) {
197 syncing_punch = true;
198 punch_start->set_mode (src->mode());
199 punch_end->set_mode (src->mode());
200 syncing_punch = false;
206 TimeInfoBox::set_session (Session* s)
208 SessionHandlePtr::set_session (s);
210 selection_start->set_session (s);
211 selection_end->set_session (s);
212 selection_length->set_session (s);
214 punch_start->set_session (s);
215 punch_end->set_session (s);
218 Location* punch = s->locations()->auto_punch_location ();
224 punch_changed (punch);
226 _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR,
227 boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context());
232 TimeInfoBox::selection_changed ()
235 Selection& selection (Editor::instance().get_selection());
237 switch (Editor::instance().current_mouse_mode()) {
239 case Editing::MouseObject:
240 if (Editor::instance().internal_editing()) {
241 /* displaying MIDI note selection is tricky */
243 selection_start->set_off (true);
244 selection_end->set_off (true);
245 selection_length->set_off (true);
248 if (selection.regions.empty()) {
249 if (selection.points.empty()) {
250 Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
251 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
253 if (tact && tact->get_active() && !selection.time.empty()) {
254 /* show selected range */
255 selection_start->set_off (false);
256 selection_end->set_off (false);
257 selection_length->set_off (false);
258 selection_start->set (selection.time.start());
259 selection_end->set (selection.time.end_frame());
260 selection_length->set (selection.time.length());
262 selection_start->set_off (true);
263 selection_end->set_off (true);
264 selection_length->set_off (true);
269 for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
270 s = min (s, (framepos_t) i->start);
271 e = max (e, (framepos_t) i->end);
273 selection_start->set_off (false);
274 selection_end->set_off (false);
275 selection_length->set_off (false);
276 selection_start->set (s);
277 selection_end->set (e);
278 selection_length->set (e - s + 1);
281 s = selection.regions.start();
282 e = selection.regions.end_frame();
283 selection_start->set_off (false);
284 selection_end->set_off (false);
285 selection_length->set_off (false);
286 selection_start->set (s);
287 selection_end->set (e);
288 selection_length->set (e - s + 1);
293 case Editing::MouseRange:
294 if (selection.time.empty()) {
295 Glib::RefPtr<Action> act = ActionManager::get_action ("MouseMode", "set-mouse-mode-object-range");
296 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
298 if (tact && tact->get_active() && !selection.regions.empty()) {
299 /* show selected regions */
300 s = selection.regions.start();
301 e = selection.regions.end_frame();
302 selection_start->set_off (false);
303 selection_end->set_off (false);
304 selection_length->set_off (false);
305 selection_start->set (s);
306 selection_end->set (e);
307 selection_length->set (e - s + 1);
309 selection_start->set_off (true);
310 selection_end->set_off (true);
311 selection_length->set_off (true);
314 selection_start->set_off (false);
315 selection_end->set_off (false);
316 selection_length->set_off (false);
317 selection_start->set (selection.time.start());
318 selection_end->set (selection.time.end_frame());
319 selection_length->set (selection.time.length());
324 selection_start->set_off (true);
325 selection_end->set_off (true);
326 selection_length->set_off (true);
332 TimeInfoBox::punch_location_changed (Location* loc)
340 TimeInfoBox::watch_punch (Location* punch)
342 punch_connections.drop_connections ();
344 punch->start_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
345 punch->end_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
347 punch_changed (punch);
351 TimeInfoBox::punch_changed (Location* loc)
354 punch_start->set_off (true);
355 punch_end->set_off (true);
359 punch_start->set_off (false);
360 punch_end->set_off (false);
362 punch_start->set (loc->start());
363 punch_end->set (loc->end());