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 (samplepos_t start, samplepos_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 (bool and_roll)
126 session->goto_start (and_roll);
130 BasicUI::goto_zero ()
132 session->request_locate (0);
138 session->goto_end ();
142 BasicUI::add_marker (const std::string& markername)
144 samplepos_t where = session->audible_sample();
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_sample(), session->audible_sample()+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 samplepos_t pos = session->locations()->first_mark_before (session->transport_sample());
298 session->request_locate (pos, session->transport_rolling());
300 session->goto_start ();
305 BasicUI::next_marker ()
307 samplepos_t pos = session->locations()->first_mark_after (session->transport_sample());
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 ();
331 access_action ("Editor/undo");
337 access_action ("Editor/redo");
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_sample ()
381 return session->transport_sample();
385 BasicUI::locate (samplepos_t where, bool roll_after_locate)
387 session->request_locate (where, roll_after_locate);
391 BasicUI::jump_by_seconds (double secs)
393 samplepos_t current = session->transport_sample();
394 double s = (double) current / (double) session->nominal_sample_rate();
400 s = s * session->nominal_sample_rate();
402 session->request_locate ( floor(s) );
406 BasicUI::jump_by_bars (double bars)
408 TempoMap& tmap (session->tempo_map());
409 Timecode::BBT_Time bbt (tmap.bbt_at_sample (session->transport_sample()));
417 any.type = AnyTime::BBT;
420 session->request_locate ( session->convert_to_samples (any) );
424 BasicUI::toggle_monitor_mute ()
426 if (session->monitor_out()) {
427 boost::shared_ptr<MonitorProcessor> mon = session->monitor_out()->monitor_control();
428 if (mon->cut_all ()) {
429 mon->set_cut_all (false);
431 mon->set_cut_all (true);
437 BasicUI::toggle_monitor_dim ()
439 if (session->monitor_out()) {
440 boost::shared_ptr<MonitorProcessor> mon = session->monitor_out()->monitor_control();
441 if (mon->dim_all ()) {
442 mon->set_dim_all (false);
444 mon->set_dim_all (true);
450 BasicUI::toggle_monitor_mono ()
452 if (session->monitor_out()) {
453 boost::shared_ptr<MonitorProcessor> mon = session->monitor_out()->monitor_control();
455 mon->set_mono (false);
457 mon->set_mono (true);
463 BasicUI::midi_panic ()
465 session->midi_panic ();
469 BasicUI::toggle_click ()
471 bool state = !Config->get_clicking();
472 Config->set_clicking (state);
476 BasicUI::toggle_roll ()
478 if (session->transport_rolling()) {
481 transport_play (false);
486 BasicUI::stop_forget ()
488 session->request_stop (true, true);
491 void BasicUI::mark_in () { access_action("Common/start-range-from-playhead"); }
492 void BasicUI::mark_out () { access_action("Common/finish-range-from-playhead"); }
494 void BasicUI::set_punch_range () { access_action("Editor/set-punch-from-edit-range"); }
495 void BasicUI::set_loop_range () { access_action("Editor/set-loop-from-edit-range"); }
496 void BasicUI::set_session_range () { access_action("Editor/set-session-from-edit-range"); }
498 void BasicUI::quick_snapshot_stay () { access_action("Main/QuickSnapshotStay"); }
499 void BasicUI::quick_snapshot_switch () { access_action("Main/QuickSnapshotSwitch"); }
501 void BasicUI::fit_1_track() { access_action("Editor/fit_1_track"); }
502 void BasicUI::fit_2_tracks() { access_action("Editor/fit_2_tracks"); }
503 void BasicUI::fit_4_tracks() { access_action("Editor/fit_4_tracks"); }
504 void BasicUI::fit_8_tracks() { access_action("Editor/fit_8_tracks"); }
505 void BasicUI::fit_16_tracks() { access_action("Editor/fit_16_tracks"); }
506 void BasicUI::fit_32_tracks() { access_action("Editor/fit_32_tracks"); }
507 void BasicUI::fit_all_tracks() { access_action("Editor/fit_all_tracks"); }
509 void BasicUI::zoom_10_ms() { access_action("Editor/zoom_10_ms"); }
510 void BasicUI::zoom_100_ms() { access_action("Editor/zoom_100_ms"); }
511 void BasicUI::zoom_1_sec() { access_action("Editor/zoom_1_sec"); }
512 void BasicUI::zoom_10_sec() { access_action("Editor/zoom_10_sec"); }
513 void BasicUI::zoom_1_min() { access_action("Editor/zoom_1_min"); }
514 void BasicUI::zoom_5_min() { access_action("Editor/zoom_5_min"); }
515 void BasicUI::zoom_10_min() { access_action("Editor/zoom_10_min"); }
516 void BasicUI::zoom_to_session() { access_action("Editor/zoom-to-session"); }
517 void BasicUI::temporal_zoom_in() { access_action("Editor/temporal-zoom-in"); }
518 void BasicUI::temporal_zoom_out() { access_action("Editor/temporal-zoom-out"); }
520 void BasicUI::scroll_up_1_track() { access_action("Editor/step-tracks-up"); }
521 void BasicUI::scroll_dn_1_track() { access_action("Editor/step-tracks-down"); }
522 void BasicUI::scroll_up_1_page() { access_action("Editor/scroll-tracks-up"); }
523 void BasicUI::scroll_dn_1_page() { access_action("Editor/scroll-tracks-down"); }
529 return session->locate_pending();
535 return session->transport_locked ();
539 BasicUI::timecode_frames_per_hour ()
541 return session->timecode_frames_per_hour ();
545 BasicUI::timecode_time (samplepos_t where, Timecode::Time& timecode)
547 session->timecode_time (where, *((Timecode::Time *) &timecode));
551 BasicUI::timecode_to_sample (Timecode::Time& timecode, samplepos_t & sample, bool use_offset, bool use_subframes) const
553 session->timecode_to_sample (*((Timecode::Time*)&timecode), sample, use_offset, use_subframes);
557 BasicUI::sample_to_timecode (samplepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const
559 session->sample_to_timecode (sample, *((Timecode::Time*)&timecode), use_offset, use_subframes);
563 BasicUI::cancel_all_solo ()
566 session->cancel_all_solo ();
570 struct SortLocationsByPosition {
571 bool operator() (Location* a, Location* b) {
572 return a->start() < b->start();
577 BasicUI::goto_nth_marker (int n)
583 const Locations::LocationList& l (session->locations()->list());
584 Locations::LocationList ordered;
587 SortLocationsByPosition cmp;
590 for (Locations::LocationList::iterator i = ordered.begin(); n >= 0 && i != ordered.end(); ++i) {
591 if ((*i)->is_mark() && !(*i)->is_hidden() && !(*i)->is_session_range()) {
593 session->request_locate ((*i)->start(), session->transport_rolling());
602 this stuff is waiting to go in so that all UIs can offer complex solo/mute functionality
605 BasicUI::solo_release (boost::shared_ptr<Route> r)
610 BasicUI::solo_press (boost::shared_ptr<Route> r, bool momentary, bool global, bool exclusive, bool isolate, bool solo_group)
613 _solo_release = new SoloMuteRelease (_route->soloed());
619 _solo_release->routes = _session->get_routes ();
622 if (Config->get_solo_control_is_listen_control()) {
623 _session->set_listen (_session->get_routes(), !_route->listening(), Session::rt_cleanup, true);
625 _session->set_solo (_session->get_routes(), !_route->soloed(), Session::rt_cleanup, true);
628 } else if (exclusive) {
631 _solo_release->exclusive = true;
633 boost::shared_ptr<RouteList> routes = _session->get_routes();
635 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
636 if ((*i)->soloed ()) {
637 _solo_release->routes_on->push_back (*i);
639 _solo_release->routes_off->push_back (*i);
644 if (Config->get_solo_control_is_listen_control()) {
645 /* ??? we need a just_one_listen() method */
647 _session->set_just_one_solo (_route, true);
650 } else if (isolate) {
652 // shift-click: toggle solo isolated status
654 _route->set_solo_isolated (!_route->solo_isolated(), this);
655 delete _solo_release;
658 } else if (solo_group) {
660 /* Primary-button1: solo mix group.
661 NOTE: Primary-button2 is MIDI learn.
664 if (_route->route_group()) {
667 _solo_release->routes = _route->route_group()->route_list();
670 if (Config->get_solo_control_is_listen_control()) {
671 _session->set_listen (_route->route_group()->route_list(), !_route->listening(), Session::rt_cleanup, true);
673 _session->set_solo (_route->route_group()->route_list(), !_route->soloed(), Session::rt_cleanup, true);
679 /* click: solo this route */
681 boost::shared_ptr<RouteList> rl (new RouteList);
682 rl->push_back (route());
685 _solo_release->routes = rl;
688 if (Config->get_solo_control_is_listen_control()) {
689 _session->set_listen (rl, !_route->listening());
691 _session->set_solo (rl, !_route->soloed());