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 ()
45 , syncing_selection (false)
46 , syncing_punch (false)
47 , punch_in_button (_("In"))
48 , punch_out_button (_("Out"))
50 selection_start = new AudioClock ("selection-start", false, "SelectionClockDisplay", false, false, false, false);
51 selection_end = new AudioClock ("selection-end", false, "SelectionClockDisplay", false, false, false, false);
52 selection_length = new AudioClock ("selection-length", false, "SelectionClockDisplay", false, false, true, false);
54 punch_start = new AudioClock ("punch-start", false, "PunchClockDisplay", false, false, false, false);
55 punch_end = new AudioClock ("punch-end", false, "PunchClockDisplay", false, false, false, false);
57 CairoEditableText& ss (selection_start->main_display());
58 ss.set_corner_radius (0);
60 CairoEditableText& se (selection_end->main_display());
61 se.set_corner_radius (0);
63 CairoEditableText& sl (selection_length->main_display());
64 sl.set_corner_radius (0);
66 CairoEditableText& ps (punch_start->main_display());
67 ps.set_corner_radius (0);
69 CairoEditableText& pe (punch_end->main_display());
70 pe.set_corner_radius (0);
72 selection_title.set_text (_("Selection"));
73 punch_title.set_text (_("Punch"));
75 set_homogeneous (false);
80 /* a bit more spacing between the two "sides" */
81 set_col_spacing (1, 10);
85 selection_title.set_name ("TimeInfoSelectionTitle");
86 attach (selection_title, 0, 2, 0, 1);
87 l = manage (new Label);
88 l->set_text (_("Start"));
89 l->set_alignment (1.0, 0.5);
90 l->set_name (X_("TimeInfoSelectionLabel"));
91 attach (*l, 0, 1, 1, 2, FILL);
92 attach (*selection_start, 1, 2, 1, 2);
94 l = manage (new Label);
95 l->set_text (_("End"));
96 l->set_alignment (1.0, 0.5);
97 l->set_name (X_("TimeInfoSelectionLabel"));
98 attach (*l, 0, 1, 2, 3, FILL);
99 attach (*selection_end, 1, 2, 2, 3);
101 l = manage (new Label);
102 l->set_text (_("Length"));
103 l->set_alignment (1.0, 0.5);
104 l->set_name (X_("TimeInfoSelectionLabel"));
105 attach (*l, 0, 1, 3, 4, FILL);
106 attach (*selection_length, 1, 2, 3, 4);
108 punch_title.set_name ("TimeInfoSelectionTitle");
109 attach (punch_title, 2, 4, 0, 1);
110 l = manage (new Label);
111 l->set_alignment (1.0, 0.5);
112 l->set_text (_("In"));
113 l->set_name (X_("TimeInfoPunchLabel"));
114 attach (*l, 2, 3, 1, 2, FILL);
115 attach (*punch_start, 3, 4, 1, 2);
117 l = manage (new Label);
118 l->set_alignment (1.0, 0.5);
119 l->set_text (_("Out"));
120 l->set_name (X_("TimeInfoPunchLabel"));
121 attach (*l, 2, 3, 2, 3, FILL);
122 attach (*punch_end, 3, 4, 2, 3);
124 punch_in_button.set_name ("TimeInfoPunchButton");
125 punch_out_button.set_name ("TimeInfoPunchButton");
126 punch_button_box.set_homogeneous (true);
127 punch_button_box.set_spacing (6);
128 punch_button_box.set_border_width (2);
129 punch_button_box.pack_start (punch_in_button, true, true);
130 punch_button_box.pack_start (punch_out_button, true, true);
132 ActionManager::get_action ("Transport", "TogglePunchIn")->connect_proxy (punch_in_button);
133 ActionManager::get_action ("Transport", "TogglePunchOut")->connect_proxy (punch_out_button);
135 Gtkmm2ext::UI::instance()->set_tip (punch_in_button, _("Start recording at auto-punch start"));
136 Gtkmm2ext::UI::instance()->set_tip (punch_out_button, _("Stop recording at auto-punch end"));
138 attach (punch_button_box, 2, 4, 3, 4, FILL, FILL);
142 selection_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_start));
143 selection_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_end));
144 selection_length->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_length));
146 punch_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_start));
147 punch_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_end));
149 selection_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_start), true);
150 selection_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_end), true);
152 punch_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_start), true);
153 punch_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_end), true);
155 Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
156 Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
158 Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), ui_bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
161 TimeInfoBox::~TimeInfoBox ()
163 delete selection_length;
164 delete selection_end;
165 delete selection_start;
172 TimeInfoBox::track_mouse_mode ()
174 selection_changed ();
178 TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src)
184 if (ev->button == 1) {
185 _session->request_locate (src->current_time ());
193 TimeInfoBox::sync_selection_mode (AudioClock* src)
195 if (!syncing_selection) {
196 syncing_selection = true;
197 selection_start->set_mode (src->mode());
198 selection_end->set_mode (src->mode());
199 selection_length->set_mode (src->mode());
200 syncing_selection = false;
205 TimeInfoBox::sync_punch_mode (AudioClock* src)
207 if (!syncing_punch) {
208 syncing_punch = true;
209 punch_start->set_mode (src->mode());
210 punch_end->set_mode (src->mode());
211 syncing_punch = false;
217 TimeInfoBox::set_session (Session* s)
219 SessionHandlePtr::set_session (s);
221 selection_start->set_session (s);
222 selection_end->set_session (s);
223 selection_length->set_session (s);
225 punch_start->set_session (s);
226 punch_end->set_session (s);
229 Location* punch = s->locations()->auto_punch_location ();
235 punch_changed (punch);
237 _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR,
238 boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context());
243 TimeInfoBox::selection_changed ()
246 Selection& selection (Editor::instance().get_selection());
248 switch (Editor::instance().current_mouse_mode()) {
250 case Editing::MouseObject:
251 if (Editor::instance().internal_editing()) {
252 /* displaying MIDI note selection is tricky */
254 selection_start->set_off (true);
255 selection_end->set_off (true);
256 selection_length->set_off (true);
259 if (selection.regions.empty()) {
260 if (selection.points.empty()) {
261 selection_start->set_off (true);
262 selection_end->set_off (true);
263 selection_length->set_off (true);
267 for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
268 s = min (s, (framepos_t) i->start);
269 e = max (e, (framepos_t) i->end);
271 selection_start->set_off (false);
272 selection_end->set_off (false);
273 selection_length->set_off (false);
274 selection_start->set (s);
275 selection_end->set (e);
276 selection_length->set (e - s + 1);
279 s = selection.regions.start();
280 e = selection.regions.end_frame();
281 selection_start->set_off (false);
282 selection_end->set_off (false);
283 selection_length->set_off (false);
284 selection_start->set (s);
285 selection_end->set (e);
286 selection_length->set (e - s + 1);
291 case Editing::MouseRange:
292 if (selection.time.empty()) {
293 selection_start->set_off (true);
294 selection_end->set_off (true);
295 selection_length->set_off (true);
297 selection_start->set_off (false);
298 selection_end->set_off (false);
299 selection_length->set_off (false);
300 selection_start->set (selection.time.start());
301 selection_end->set (selection.time.end_frame());
302 selection_length->set (selection.time.length());
307 selection_start->set_off (true);
308 selection_end->set_off (true);
309 selection_length->set_off (true);
315 TimeInfoBox::punch_location_changed (Location* loc)
323 TimeInfoBox::watch_punch (Location* punch)
325 punch_connections.drop_connections ();
327 punch->start_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
328 punch->end_changed.connect (punch_connections, MISSING_INVALIDATOR, boost::bind (&TimeInfoBox::punch_changed, this, _1), gui_context());
330 punch_changed (punch);
334 TimeInfoBox::punch_changed (Location* loc)
337 punch_start->set_off (true);
338 punch_end->set_off (true);
342 punch_start->set_off (false);
343 punch_end->set_off (false);
345 punch_start->set (loc->start());
346 punch_end->set (loc->end());
350 TimeInfoBox::on_expose_event (GdkEventExpose* ev)
354 Gtk::Widget* window_parent;
355 Glib::RefPtr<Gdk::Window> win = Gtkmm2ext::window_to_draw_on (*this, &window_parent);
359 Cairo::RefPtr<Cairo::Context> context = win->create_cairo_context();
362 translate_coordinates (*window_parent, ev->area.x, ev->area.y, x, y);
363 context->rectangle (x, y, ev->area.width, ev->area.height);
366 translate_coordinates (*window_parent, 0, 0, x, y);
367 context->set_source_rgba (0.149, 0.149, 0.149, 1.0);
368 Gtkmm2ext::rounded_rectangle (context, x, y, get_allocation().get_width(), get_allocation().get_height(), 5);
373 Table::on_expose_event (ev);