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/gui_thread.h"
24 #include "gtkmm2ext/utils.h"
25 #include "gtkmm2ext/actions.h"
27 #include "ardour/location.h"
28 #include "ardour/profile.h"
29 #include "ardour/session.h"
31 #include "audio_clock.h"
32 #include "automation_line.h"
33 #include "control_point.h"
35 #include "region_view.h"
36 #include "time_info_box.h"
41 using namespace ARDOUR;
45 TimeInfoBox::TimeInfoBox (std::string state_node_name, bool with_punch)
49 , syncing_selection (false)
50 , syncing_punch (false)
51 , with_punch_clock (with_punch)
53 set_name (X_("TimeInfoBox"));
55 selection_start = new AudioClock (
56 string_compose ("%1-selection-start", state_node_name),
57 false, "selection", false, false, false, false);
58 selection_end = new AudioClock (
59 string_compose ("%1-selection-end", state_node_name),
60 false, "selection", false, false, false, false);
61 selection_length = new AudioClock (
62 string_compose ("%1-selection-length", state_node_name),
63 false, "selection", false, false, true, false);
65 selection_title.set_text (_("Selection"));
67 set_homogeneous (false);
71 pack_start (table, false, false);
73 table.set_homogeneous (false);
74 table.set_spacings (0);
75 table.set_border_width (2);
76 table.set_col_spacings (2);
80 selection_title.set_name ("TimeInfoSelectionTitle");
81 if (with_punch_clock) {
82 table.attach (selection_title, 1, 2, 0, 1);
84 l = manage (new Label);
85 l->set_text (_("Start"));
86 l->set_alignment (1.0, 0.5);
87 l->set_name (X_("TimeInfoSelectionLabel"));
88 table.attach (*l, 0, 1, 1, 2, FILL);
89 table.attach (*selection_start, 1, 2, 1, 2);
91 l = manage (new Label);
92 l->set_text (_("End"));
93 l->set_alignment (1.0, 0.5);
94 l->set_name (X_("TimeInfoSelectionLabel"));
95 table.attach (*l, 0, 1, 2, 3, FILL);
96 table.attach (*selection_end, 1, 2, 2, 3);
98 l = manage (new Label);
99 l->set_text (_("Length"));
100 l->set_alignment (1.0, 0.5);
101 l->set_name (X_("TimeInfoSelectionLabel"));
102 table.attach (*l, 0, 1, 3, 4, FILL);
103 table.attach (*selection_length, 1, 2, 3, 4);
105 if (with_punch_clock) {
106 punch_start = new AudioClock (
107 string_compose ("%1-punch-start", state_node_name),
108 false, "punch", false, false, false, false);
109 punch_end = new AudioClock (
110 string_compose ("%1-punch-end", state_node_name),
111 false, "punch", false, false, false, false);
112 punch_title.set_text (_("Punch"));
114 punch_title.set_name ("TimeInfoSelectionTitle");
115 table.attach (punch_title, 2, 3, 0, 1);
116 table.attach (*punch_start, 2, 3, 1, 2);
117 table.attach (*punch_end, 2, 3, 2, 3);
122 selection_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_start));
123 selection_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_end));
124 selection_length->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_selection_mode), selection_length));
126 selection_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_start), true);
127 selection_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), selection_end), true);
129 if (with_punch_clock) {
130 punch_start->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_start));
131 punch_end->mode_changed.connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::sync_punch_mode), punch_end));
133 punch_start->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_start), true);
134 punch_end->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &TimeInfoBox::clock_button_release_event), punch_end), true);
137 Editor::instance().get_selection().TimeChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
138 Editor::instance().get_selection().RegionsChanged.connect (sigc::mem_fun (*this, &TimeInfoBox::selection_changed));
140 Editor::instance().MouseModeChanged.connect (editor_connections, invalidator(*this), boost::bind (&TimeInfoBox::track_mouse_mode, this), gui_context());
143 TimeInfoBox::~TimeInfoBox ()
145 delete selection_length;
146 delete selection_end;
147 delete selection_start;
154 TimeInfoBox::track_mouse_mode ()
156 selection_changed ();
160 TimeInfoBox::clock_button_release_event (GdkEventButton* ev, AudioClock* src)
166 if (ev->button == 1) {
168 _session->request_locate (src->current_time ());
177 TimeInfoBox::sync_selection_mode (AudioClock* src)
179 if (!syncing_selection) {
180 syncing_selection = true;
181 selection_start->set_mode (src->mode());
182 selection_end->set_mode (src->mode());
183 selection_length->set_mode (src->mode());
184 syncing_selection = false;
189 TimeInfoBox::sync_punch_mode (AudioClock* src)
191 if (!with_punch_clock) {
194 if (!syncing_punch) {
195 syncing_punch = true;
196 punch_start->set_mode (src->mode());
197 punch_end->set_mode (src->mode());
198 syncing_punch = false;
204 TimeInfoBox::set_session (Session* s)
206 SessionHandlePtr::set_session (s);
208 selection_start->set_session (s);
209 selection_end->set_session (s);
210 selection_length->set_session (s);
212 if (!with_punch_clock) {
216 punch_start->set_session (s);
217 punch_end->set_session (s);
220 Location* punch = s->locations()->auto_punch_location ();
226 punch_changed (punch);
228 _session->auto_punch_location_changed.connect (_session_connections, MISSING_INVALIDATOR,
229 boost::bind (&TimeInfoBox::punch_location_changed, this, _1), gui_context());
234 TimeInfoBox::region_selection_changed ()
237 Selection& selection (Editor::instance().get_selection());
238 s = selection.regions.start();
239 e = selection.regions.end_sample();
240 selection_start->set_off (false);
241 selection_end->set_off (false);
242 selection_length->set_off (false);
243 selection_start->set (s);
244 selection_end->set (e);
245 selection_length->set (e, false, s);
249 TimeInfoBox::selection_changed ()
252 Selection& selection (Editor::instance().get_selection());
254 region_property_connections.drop_connections();
256 switch (Editor::instance().current_mouse_mode()) {
258 case Editing::MouseContent:
259 /* displaying MIDI note selection is tricky */
260 selection_start->set_off (true);
261 selection_end->set_off (true);
262 selection_length->set_off (true);
265 case Editing::MouseObject:
266 if (selection.regions.empty()) {
267 if (selection.points.empty()) {
268 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("MouseMode", "set-mouse-mode-object-range");
269 if (tact->get_active() && !selection.time.empty()) {
270 /* show selected range */
271 selection_start->set_off (false);
272 selection_end->set_off (false);
273 selection_length->set_off (false);
274 selection_start->set (selection.time.start());
275 selection_end->set (selection.time.end_sample());
276 selection_length->set (selection.time.end_sample(), false, selection.time.start());
278 selection_start->set_off (true);
279 selection_end->set_off (true);
280 selection_length->set_off (true);
285 for (PointSelection::iterator i = selection.points.begin(); i != selection.points.end(); ++i) {
286 samplepos_t const p = (*i)->line().session_position ((*i)->model ());
290 selection_start->set_off (false);
291 selection_end->set_off (false);
292 selection_length->set_off (false);
293 selection_start->set (s);
294 selection_end->set (e);
295 selection_length->set (e, false, s);
298 /* this is more efficient than tracking changes per region in large selections */
299 std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists;
300 for (RegionSelection::iterator s = selection.regions.begin(); s != selection.regions.end(); ++s) {
301 boost::shared_ptr<Playlist> pl = (*s)->region()->playlist();
303 playlists.insert (pl);
306 for (std::set<boost::shared_ptr<ARDOUR::Playlist> >::iterator ps = playlists.begin(); ps != playlists.end(); ++ps) {
307 (*ps)->ContentsChanged.connect (region_property_connections, invalidator (*this),
308 boost::bind (&TimeInfoBox::region_selection_changed, this), gui_context());
310 region_selection_changed ();
314 case Editing::MouseRange:
315 if (selection.time.empty()) {
316 Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ("MouseMode", "set-mouse-mode-object-range");
318 if (tact->get_active() && !selection.regions.empty()) {
319 /* show selected regions */
320 s = selection.regions.start();
321 e = selection.regions.end_sample();
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, false, s);
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_sample());
339 selection_length->set (selection.time.end_sample(), false, selection.time.start());
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());