2 Copyright (C) 2006 Paul Davis
4 This program is free software; you can redistribute it
5 and/or modify it under the terms of the GNU Lesser
6 General Public License as published by the Free Software
7 Foundation; either version 2 of the License, or (at your
8 option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "pbd/pthread_utils.h"
22 #include "pbd/memento_command.h"
24 #include "ardour/session.h"
25 #include "ardour/location.h"
26 #include "ardour/tempo.h"
27 #include "ardour/utils.h"
29 #include "control_protocol/basic_ui.h"
33 using namespace ARDOUR;
35 PBD::Signal2<void,std::string,std::string> BasicUI::AccessAction;
37 BasicUI::BasicUI (Session& s)
53 BasicUI::register_thread (std::string name)
55 std::string pool_name = name;
56 pool_name += " events";
58 SessionEvent::create_per_thread_pool (pool_name, 64);
62 BasicUI::access_action ( std::string action_path )
64 int split_at = action_path.find( "/" );
65 std::string group = action_path.substr( 0, split_at );
66 std::string item = action_path.substr( split_at + 1 );
68 AccessAction( group, item );
72 BasicUI::loop_toggle ()
78 Location * looploc = session->locations()->auto_loop_location();
84 if (session->get_play_loop()) {
86 /* looping enabled, our job is to disable it */
88 session->request_play_loop (false);
92 /* looping not enabled, our job is to enable it.
94 loop-is-NOT-mode: this action always starts the transport rolling.
95 loop-IS-mode: this action simply sets the loop play mechanism, but
96 does not start transport.
98 if (Config->get_loop_is_mode()) {
99 session->request_play_loop (true, false);
101 session->request_play_loop (true, true);
105 //show the loop markers
106 looploc->set_hidden (false, this);
110 BasicUI::loop_location (framepos_t start, framepos_t end)
113 if ((tll = session->locations()->auto_loop_location()) == 0) {
114 Location* loc = new Location (*session, start, end, _("Loop"), Location::IsAutoLoop);
115 session->locations()->add (loc, true);
116 session->set_auto_loop_location (loc);
118 tll->set_hidden (false, this);
119 tll->set (start, end);
124 BasicUI::goto_start ()
126 session->goto_start ();
130 BasicUI::goto_zero ()
132 session->request_locate (0);
138 session->goto_end ();
142 BasicUI::add_marker (const std::string& markername)
144 framepos_t where = session->audible_frame();
145 Location *location = new Location (*session, where, where, markername, Location::IsMark);
146 session->begin_reversible_command (_("add marker"));
147 XMLNode &before = session->locations()->get_state();
148 session->locations()->add (location, true);
149 XMLNode &after = session->locations()->get_state();
150 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
151 session->commit_reversible_command ();
155 BasicUI::remove_marker_at_playhead ()
159 XMLNode &before = session->locations()->get_state();
160 bool removed = false;
162 //find location(s) at this time
163 Locations::LocationList locs;
164 session->locations()->find_all_between (session->audible_frame(), session->audible_frame()+1, locs, Location::Flags(0));
165 for (Locations::LocationList::iterator i = locs.begin(); i != locs.end(); ++i) {
166 if ((*i)->is_mark()) {
167 session->locations()->remove (*i);
174 session->begin_reversible_command (_("remove marker"));
175 XMLNode &after = session->locations()->get_state();
176 session->add_command(new MementoCommand<Locations>(*(session->locations()), &before, &after));
177 session->commit_reversible_command ();
185 session->request_transport_speed (session->transport_speed() - 1.5);
191 session->request_transport_speed (session->transport_speed() + 1.5);
195 BasicUI::transport_stop ()
197 session->request_transport_speed (0.0);
201 BasicUI::transport_play (bool from_last_start)
207 if (session->is_auditioning()) {
212 if (session->config.get_external_sync()) {
213 switch (Config->get_sync_source()) {
217 /* transport controlled by the master */
223 bool rolling = session->transport_rolling();
225 if (session->get_play_loop()) {
227 /* If loop playback is not a mode, then we should cancel
228 it when this action is requested. If it is a mode
229 we just leave it in place.
232 if (!Config->get_loop_is_mode()) {
233 /* XXX it is not possible to just leave seamless loop and keep
234 playing at present (nov 4th 2009)
236 if (!Config->get_seamless_loop()) {
237 /* stop loop playback and stop rolling */
238 session->request_play_loop (false, true);
239 } else if (rolling) {
240 /* stop loop playback but keep rolling */
241 session->request_play_loop (false, false);
245 } else if (session->get_play_range () ) {
246 /* stop playing a range if we currently are */
247 session->request_play_range (0, true);
251 session->request_transport_speed (1.0f);
256 BasicUI::rec_enable_toggle ()
258 switch (session->record_status()) {
259 case Session::Disabled:
260 if (session->ntracks() == 0) {
261 // string txt = _("Please create 1 or more track\nbefore trying to record.\nCheck the Session menu.");
262 // MessageDialog msg (*editor, txt);
266 session->maybe_enable_record ();
268 case Session::Recording:
269 case Session::Enabled:
270 session->disable_record (false, true);
275 BasicUI::all_tracks_rec_in ()
277 session->set_all_tracks_record_enabled (true);
281 BasicUI::all_tracks_rec_out ()
283 session->set_all_tracks_record_enabled (false);
287 BasicUI::save_state ()
289 session->save_state ("");
293 BasicUI::prev_marker ()
295 framepos_t pos = session->locations()->first_mark_before (session->transport_frame());
298 session->request_locate (pos, session->transport_rolling());
300 session->goto_start ();
305 BasicUI::next_marker ()
307 framepos_t pos = session->locations()->first_mark_after (session->transport_frame());
310 session->request_locate (pos, session->transport_rolling());
317 BasicUI::set_transport_speed (double speed)
319 session->request_transport_speed (speed);
323 BasicUI::get_transport_speed ()
325 return session->transport_speed ();
341 BasicUI::toggle_all_rec_enables ()
343 if (session->get_record_enabled()) {
344 // session->record_disenable_all ();
346 // session->record_enable_all ();
351 BasicUI::toggle_punch_in ()
353 session->config.set_punch_in (!session->config.get_punch_in());
357 BasicUI::toggle_punch_out ()
359 session->config.set_punch_out (!session->config.get_punch_out());
363 BasicUI::get_record_enabled ()
365 return session->get_record_enabled();
369 BasicUI::set_record_enable (bool yn)
372 session->maybe_enable_record ();
374 session->disable_record (false, true);
379 BasicUI::transport_frame ()
381 return session->transport_frame();
385 BasicUI::locate (framepos_t where, bool roll_after_locate)
387 session->request_locate (where, roll_after_locate);
391 BasicUI::jump_by_seconds (double secs)
393 framepos_t current = session->transport_frame();
394 double s = (double) current / (double) session->nominal_frame_rate();
397 if (s < 0) current = 0;
398 s = s * session->nominal_frame_rate();
400 session->request_locate ( floor(s) );
404 BasicUI::jump_by_bars (double bars)
406 TempoMap& tmap (session->tempo_map());
407 Timecode::BBT_Time bbt (tmap.bbt_at_frame (session->transport_frame()));
410 if (bars < 0) bars = 0;
413 any.type = AnyTime::BBT;
416 session->request_locate ( session->convert_to_frames (any) );
419 void BasicUI::mark_in () { access_action("Editor/start-range-from-playhead"); }
420 void BasicUI::mark_out () { access_action("Editor/finish-range-from-playhead"); }
422 void BasicUI::toggle_click () { access_action("Transport/ToggleClick"); }
423 void BasicUI::midi_panic () { access_action("MIDI/panic"); }
424 void BasicUI::toggle_roll () { access_action("Transport/ToggleRoll"); }
425 void BasicUI::stop_forget () { access_action("Transport/ToggleRollForgetCapture"); }
427 void BasicUI::set_punch_range () { access_action("Editor/set-punch-from-edit-range"); }
428 void BasicUI::set_loop_range () { access_action("Editor/set-loop-from-edit-range"); }
429 void BasicUI::set_session_range () { access_action("Editor/set-session-from-edit-range"); }
431 void BasicUI::toggle_monitor_mute () { /*access_action("Editor/toggle_monitor_mute"); */ }
432 void BasicUI::toggle_monitor_dim () { /*access_action("Editor/toggle_monitor_dim"); */ }
433 void BasicUI::toggle_monitor_mono () { /*access_action("Editor/toggle_monitor_mono"); */ }
435 void BasicUI::quick_snapshot_stay () { access_action("Main/QuickSnapshotStay"); }
436 void BasicUI::quick_snapshot_switch () { access_action("Main/QuickSnapshotSwitch"); }
438 void BasicUI::fit_1_track() { access_action("Editor/fit_1_track"); }
439 void BasicUI::fit_2_tracks() { access_action("Editor/fit_2_tracks"); }
440 void BasicUI::fit_4_tracks() { access_action("Editor/fit_4_tracks"); }
441 void BasicUI::fit_8_tracks() { access_action("Editor/fit_8_tracks"); }
442 void BasicUI::fit_16_tracks() { access_action("Editor/fit_16_tracks"); }
443 void BasicUI::fit_32_tracks() { access_action("Editor/fit_32_tracks"); }
444 void BasicUI::fit_all_tracks() { access_action("Editor/fit_all_tracks"); }
446 void BasicUI::zoom_10_ms() { access_action("Editor/zoom_10_ms"); }
447 void BasicUI::zoom_100_ms() { access_action("Editor/zoom_100_ms"); }
448 void BasicUI::zoom_1_sec() { access_action("Editor/zoom_1_sec"); }
449 void BasicUI::zoom_10_sec() { access_action("Editor/zoom_10_sec"); }
450 void BasicUI::zoom_1_min() { access_action("Editor/zoom_1_min"); }
451 void BasicUI::zoom_5_min() { access_action("Editor/zoom_5_min"); }
452 void BasicUI::zoom_10_min() { access_action("Editor/zoom_10_min"); }
453 void BasicUI::zoom_to_session() { access_action("Editor/zoom-to-session"); }
454 void BasicUI::temporal_zoom_in() { access_action("Editor/temporal-zoom-in"); }
455 void BasicUI::temporal_zoom_out() { access_action("Editor/temporal-zoom-out"); }
457 void BasicUI::scroll_up_1_track() { access_action("Editor/step-tracks-up"); }
458 void BasicUI::scroll_dn_1_track() { access_action("Editor/step-tracks-down"); }
459 void BasicUI::scroll_up_1_page() { access_action("Editor/scroll-tracks-up"); }
460 void BasicUI::scroll_dn_1_page() { access_action("Editor/scroll-tracks-down"); }
466 return session->locate_pending();
472 return session->transport_locked ();
476 BasicUI::timecode_frames_per_hour ()
478 return session->timecode_frames_per_hour ();
482 BasicUI::timecode_time (framepos_t where, Timecode::Time& timecode)
484 session->timecode_time (where, *((Timecode::Time *) &timecode));
488 BasicUI::timecode_to_sample (Timecode::Time& timecode, framepos_t & sample, bool use_offset, bool use_subframes) const
490 session->timecode_to_sample (*((Timecode::Time*)&timecode), sample, use_offset, use_subframes);
494 BasicUI::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const
496 session->sample_to_timecode (sample, *((Timecode::Time*)&timecode), use_offset, use_subframes);
500 BasicUI::toggle_selection (PresentationInfo::order_t o, PresentationInfo::Flag flags)
502 boost::shared_ptr<Stripable> s = session->get_remote_nth_stripable (o, flags);
505 s->presentation_info().set_selected (!s->presentation_info().selected());
510 BasicUI::clear_stripable_selection ()
512 session->clear_stripable_selection ();
516 BasicUI::toggle_stripable_selection (boost::shared_ptr<Stripable> s)
518 session->toggle_stripable_selection (s);
522 BasicUI::add_stripable_selection (boost::shared_ptr<Stripable> s)
524 session->add_stripable_selection (s);
528 BasicUI::set_stripable_selection (boost::shared_ptr<Stripable> s)
530 session->set_stripable_selection (s);
535 BasicUI::cancel_all_solo ()
538 session->cancel_all_solo ();
542 struct SortLocationsByPosition {
543 bool operator() (Location* a, Location* b) {
544 return a->start() < b->start();
549 BasicUI::goto_nth_marker (int n)
555 const Locations::LocationList& l (session->locations()->list());
556 Locations::LocationList ordered;
559 SortLocationsByPosition cmp;
562 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
563 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
565 session->request_locate ((*i)->start(), session->transport_rolling());
574 this stuff is waiting to go in so that all UIs can offer complex solo/mute functionality
577 BasicUI::solo_release (boost::shared_ptr<Route> r)
582 BasicUI::solo_press (boost::shared_ptr<Route> r, bool momentary, bool global, bool exclusive, bool isolate, bool solo_group)
585 _solo_release = new SoloMuteRelease (_route->soloed());
591 _solo_release->routes = _session->get_routes ();
594 if (Config->get_solo_control_is_listen_control()) {
595 _session->set_listen (_session->get_routes(), !_route->listening(), Session::rt_cleanup, true);
597 _session->set_solo (_session->get_routes(), !_route->soloed(), Session::rt_cleanup, true);
600 } else if (exclusive) {
603 _solo_release->exclusive = true;
605 boost::shared_ptr<RouteList> routes = _session->get_routes();
607 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
608 if ((*i)->soloed ()) {
609 _solo_release->routes_on->push_back (*i);
611 _solo_release->routes_off->push_back (*i);
616 if (Config->get_solo_control_is_listen_control()) {
617 /* ??? we need a just_one_listen() method */
619 _session->set_just_one_solo (_route, true);
622 } else if (isolate) {
624 // shift-click: toggle solo isolated status
626 _route->set_solo_isolated (!_route->solo_isolated(), this);
627 delete _solo_release;
630 } else if (solo_group) {
632 /* Primary-button1: solo mix group.
633 NOTE: Primary-button2 is MIDI learn.
636 if (_route->route_group()) {
639 _solo_release->routes = _route->route_group()->route_list();
642 if (Config->get_solo_control_is_listen_control()) {
643 _session->set_listen (_route->route_group()->route_list(), !_route->listening(), Session::rt_cleanup, true);
645 _session->set_solo (_route->route_group()->route_list(), !_route->soloed(), Session::rt_cleanup, true);
651 /* click: solo this route */
653 boost::shared_ptr<RouteList> rl (new RouteList);
654 rl->push_back (route());
657 _solo_release->routes = rl;
660 if (Config->get_solo_control_is_listen_control()) {
661 _session->set_listen (rl, !_route->listening());
663 _session->set_solo (rl, !_route->soloed());