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)
48 , punch_in_button (_("In"))
49 , punch_out_button (_("Out"))
51 selection_start = new AudioClock ("selection-start", false, "SelectionClockDisplay", false, false, false, false);
52 selection_end = new AudioClock ("selection-end", false, "SelectionClockDisplay", false, false, false, false);
53 selection_length = new AudioClock ("selection-length", false, "SelectionClockDisplay", false, false, true, false);
55 punch_start = new AudioClock ("punch-start", false, "PunchClockDisplay", false, false, false, false);
56 punch_end = new AudioClock ("punch-end", false, "PunchClockDisplay", false, false, false, false);
58 CairoEditableText& ss (selection_start->main_display());
59 ss.set_corner_radius (0);
61 CairoEditableText& se (selection_end->main_display());
62 se.set_corner_radius (0);
64 CairoEditableText& sl (selection_length->main_display());
65 sl.set_corner_radius (0);
67 CairoEditableText& ps (punch_start->main_display());
68 ps.set_corner_radius (0);
70 CairoEditableText& pe (punch_end->main_display());
71 pe.set_corner_radius (0);
73 selection_title.set_text (_("Selection"));
74 punch_title.set_text (_("Punch"));
76 set_homogeneous (false);
80 pack_start (left, true, true);
81 pack_start (right, true, true);
83 left.set_homogeneous (false);
84 left.set_spacings (0);
85 left.set_border_width (2);
86 left.set_col_spacings (2);
88 right.set_homogeneous (false);
89 right.set_spacings (0);
90 right.set_border_width (2);
91 right.set_col_spacings (2);
96 selection_title.set_name ("TimeInfoSelectionTitle");
97 left.attach (selection_title, 0, 2, 0, 1);
98 l = manage (new Label);
99 l->set_text (_("Start"));
100 l->set_alignment (1.0, 0.5);
101 l->set_name (X_("TimeInfoSelectionLabel"));
102 left.attach (*l, 0, 1, 1, 2, FILL);
103 left.attach (*selection_start, 1, 2, 1, 2);
105 l = manage (new Label);
106 l->set_text (_("End"));
107 l->set_alignment (1.0, 0.5);
108 l->set_name (X_("TimeInfoSelectionLabel"));
109 left.attach (*l, 0, 1, 2, 3, FILL);
110 left.attach (*selection_end, 1, 2, 2, 3);
112 l = manage (new Label);
113 l->set_text (_("Length"));
114 l->set_alignment (1.0, 0.5);
115 l->set_name (X_("TimeInfoSelectionLabel"));
116 left.attach (*l, 0, 1, 3, 4, FILL);
117 left.attach (*selection_length, 1, 2, 3, 4);
119 punch_title.set_name ("TimeInfoSelectionTitle");
120 right.attach (punch_title, 2, 4, 0, 1);
121 l = manage (new Label);
122 l->set_alignment (1.0, 0.5);
123 l->set_text (_("In"));
124 l->set_name (X_("TimeInfoPunchLabel"));
125 right.attach (*l, 2, 3, 1, 2, FILL);
126 right.attach (*punch_start, 3, 4, 1, 2);
128 l = manage (new Label);
129 l->set_alignment (1.0, 0.5);
130 l->set_text (_("Out"));
131 l->set_name (X_("TimeInfoPunchLabel"));
132 right.attach (*l, 2, 3, 2, 3, FILL);
133 right.attach (*punch_end, 3, 4, 2, 3);
135 punch_in_button.set_name ("TimeInfoPunchButton");
136 punch_out_button.set_name ("TimeInfoPunchButton");
137 punch_button_box.set_homogeneous (true);
138 punch_button_box.set_spacing (6);
139 punch_button_box.set_border_width (2);
140 punch_button_box.pack_start (punch_in_button, true, true);
141 punch_button_box.pack_start (punch_out_button, true, true);
143 ActionManager::get_action ("Transport", "TogglePunchIn")->connect_proxy (punch_in_button);
144 ActionManager::get_action ("Transport", "TogglePunchOut")->connect_proxy (punch_out_button);
146 Gtkmm2ext::UI::instance()->set_tip (punch_in_button, _("Start recording at auto-punch start"));
147 Gtkmm2ext::UI::instance()->set_tip (punch_out_button, _("Stop recording at auto-punch end"));
149 right.attach (punch_button_box, 2, 4, 3, 4, FILL, FILL);
153 selection_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_start));
154 selection_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_end));
155 selection_length->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_length));
157 punch_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_start));
158 punch_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_end));
160 selection_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_start), true);
161 selection_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_end), true);
163 punch_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_start), true);
164 punch_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_end), true);
166 Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
167 Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
169 Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), ui_bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
172 TimeInfoBox::~TimeInfoBox ()
174 delete selection_length;
175 delete selection_end;
176 delete selection_start;
183 TimeInfoBox::track_mouse_mode ()
185 selection_changed ();
189 TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src)
195 if (ev->button == 1) {
196 _session->request_locate (src->current_time ());
204 TimeInfoBox::sync_selection_mode (AudioClock* src)
206 if (!syncing_selection) {
207 syncing_selection = true;
208 selection_start->set_mode (src->mode());
209 selection_end->set_mode (src->mode());
210 selection_length->set_mode (src->mode());
211 syncing_selection = false;
216 TimeInfoBox::sync_punch_mode (AudioClock* src)
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 punch_start->set_session (s);
237 punch_end->set_session (s);
240 Location* punch = s->locations()->auto_punch_location ();
246 punch_changed (punch);
248 _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR,
249 boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context());
254 TimeInfoBox::selection_changed ()
257 Selection& selection (Editor::instance().get_selection());
259 switch (Editor::instance().current_mouse_mode()) {
261 case Editing::MouseObject:
262 if (Editor::instance().internal_editing()) {
263 /* displaying MIDI note selection is tricky */
265 selection_start->set_off (true);
266 selection_end->set_off (true);
267 selection_length->set_off (true);
270 if (selection.regions.empty()) {
271 if (selection.points.empty()) {
272 selection_start->set_off (true);
273 selection_end->set_off (true);
274 selection_length->set_off (true);
278 for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
279 s = min (s, (framepos_t) i->start);
280 e = max (e, (framepos_t) i->end);
282 selection_start->set_off (false);
283 selection_end->set_off (false);
284 selection_length->set_off (false);
285 selection_start->set (s);
286 selection_end->set (e);
287 selection_length->set (e - s + 1);
290 s = selection.regions.start();
291 e = selection.regions.end_frame();
292 selection_start->set_off (false);
293 selection_end->set_off (false);
294 selection_length->set_off (false);
295 selection_start->set (s);
296 selection_end->set (e);
297 selection_length->set (e - s + 1);
302 case Editing::MouseRange:
303 if (selection.time.empty()) {
304 selection_start->set_off (true);
305 selection_end->set_off (true);
306 selection_length->set_off (true);
308 selection_start->set_off (false);
309 selection_end->set_off (false);
310 selection_length->set_off (false);
311 selection_start->set (selection.time.start());
312 selection_end->set (selection.time.end_frame());
313 selection_length->set (selection.time.length());
318 selection_start->set_off (true);
319 selection_end->set_off (true);
320 selection_length->set_off (true);
326 TimeInfoBox::punch_location_changed (Location* loc)
334 TimeInfoBox::watch_punch (Location* punch)
336 punch_connections.drop_connections ();
338 punch->start_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
339 punch->end_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
341 punch_changed (punch);
345 TimeInfoBox::punch_changed (Location* loc)
348 punch_start->set_off (true);
349 punch_end->set_off (true);
353 punch_start->set_off (false);
354 punch_end->set_off (false);
356 punch_start->set (loc->start());
357 punch_end->set (loc->end());
361 TimeInfoBox::on_expose_event (GdkEventExpose* ev)
365 Gtk::Widget* window_parent;
366 Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (*this, &window_parent);
370 Cairo::RefPtr<Cairo::Context> context = win->create_cairo_context();
373 translate_coordinates (*window_parent, ev->area.x, ev->area.y, x, y);
374 context->rectangle (x, y, ev->area.width, ev->area.height);
377 translate_coordinates (*window_parent, 0, 0, x, y);
378 context->set_source_rgba (0.149, 0.149, 0.149, 1.0);
379 Gtkmm2ext::rounded_rectangle (context, x, y, get_allocation().get_width(), get_allocation().get_height(), 5);
384 HBox::on_expose_event (ev);