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"
28 #include "control_protocol/basic_ui.h"
32 using namespace ARDOUR;
34 PBD::Signal2<void,std::string,std::string> BasicUI::AccessAction;
36 BasicUI::BasicUI (Session& s)
52 BasicUI::register_thread (std::string name)
54 std::string pool_name = name;
55 pool_name += " events";
57 SessionEvent::create_per_thread_pool (pool_name, 64);
61 BasicUI::access_action ( std::string action_path )
63 int split_at = action_path.find( "/" );
64 std::string group = action_path.substr( 0, split_at );
65 std::string item = action_path.substr( split_at + 1 );
67 AccessAction( group, item );
71 BasicUI::loop_toggle ()
77 Location * looploc = session->locations()->auto_loop_location();
83 if (session->get_play_loop()) {
85 /* looping enabled, our job is to disable it */
87 session->request_play_loop (false);
91 /* looping not enabled, our job is to enable it.
93 loop-is-NOT-mode: this action always starts the transport rolling.
94 loop-IS-mode: this action simply sets the loop play mechanism, but
95 does not start transport.
97 if (Config->get_loop_is_mode()) {
98 session->request_play_loop (true, false);
100 session->request_play_loop (true, true);
104 //show the loop markers
105 looploc->set_hidden (false, this);
109 BasicUI::loop_location (framepos_t start, framepos_t end)
112 if ((tll = session->locations()->auto_loop_location()) == 0) {
113 Location* loc = new Location (*session, start, end, _("Loop"), Location::IsAutoLoop);
114 session->locations()->add (loc, true);
115 session->set_auto_loop_location (loc);
117 tll->set_hidden (false, this);
118 tll->set (start, end);
123 BasicUI::goto_start ()
125 session->goto_start ();
129 BasicUI::goto_zero ()
131 session->request_locate (0);
137 session->goto_end ();
141 BasicUI::add_marker (const std::string& markername)
143 framepos_t where = session->audible_frame();
144 Location *location = new Location (*session, where, where, markername, Location::IsMark);
145 session->begin_reversible_command (_("add marker"));
146 XMLNode &before = session->locations()->get_state();
147 session->locations()->add (location, true);
148 XMLNode &after = session->locations()->get_state();
149 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
150 session->commit_reversible_command ();
154 BasicUI::remove_marker_at_playhead ()
158 XMLNode &before = session->locations()->get_state();
159 bool removed = false;
161 //find location(s) at this time
162 Locations::LocationList locs;
163 session->locations()->find_all_between (session->audible_frame(), session->audible_frame()+1, locs, Location::Flags(0));
164 for (Locations::LocationList::iterator i = locs.begin(); i != locs.end(); ++i) {
165 if ((*i)->is_mark()) {
166 session->locations()->remove (*i);
173 session->begin_reversible_command (_("remove marker"));
174 XMLNode &after = session->locations()->get_state();
175 session->add_command(new MementoCommand<Locations>(*(session->locations()), &before, &after));
176 session->commit_reversible_command ();
184 session->request_transport_speed (session->transport_speed() - 1.5);
190 session->request_transport_speed (session->transport_speed() + 1.5);
194 BasicUI::transport_stop ()
196 session->request_transport_speed (0.0);
200 BasicUI::transport_play (bool from_last_start)
206 if (session->is_auditioning()) {
211 if (session->config.get_external_sync()) {
212 switch (Config->get_sync_source()) {
216 /* transport controlled by the master */
222 bool rolling = session->transport_rolling();
224 if (session->get_play_loop()) {
226 /* If loop playback is not a mode, then we should cancel
227 it when this action is requested. If it is a mode
228 we just leave it in place.
231 if (!Config->get_loop_is_mode()) {
232 /* XXX it is not possible to just leave seamless loop and keep
233 playing at present (nov 4th 2009)
235 if (!Config->get_seamless_loop()) {
236 /* stop loop playback and stop rolling */
237 session->request_play_loop (false, true);
238 } else if (rolling) {
239 /* stop loop playback but keep rolling */
240 session->request_play_loop (false, false);
244 } else if (session->get_play_range () ) {
245 /* stop playing a range if we currently are */
246 session->request_play_range (0, true);
250 session->request_transport_speed (1.0f);
255 BasicUI::rec_enable_toggle ()
257 switch (session->record_status()) {
258 case Session::Disabled:
259 if (session->ntracks() == 0) {
260 // string txt = _("Please create 1 or more track\nbefore trying to record.\nCheck the Session menu.");
261 // MessageDialog msg (*editor, txt);
265 session->maybe_enable_record ();
267 case Session::Recording:
268 case Session::Enabled:
269 session->disable_record (false, true);
274 BasicUI::all_tracks_rec_in ()
276 session->set_all_tracks_record_enabled (true);
280 BasicUI::all_tracks_rec_out ()
282 session->set_all_tracks_record_enabled (false);
286 BasicUI::save_state ()
288 session->save_state ("");
292 BasicUI::prev_marker ()
294 framepos_t pos = session->locations()->first_mark_before (session->transport_frame());
297 session->request_locate (pos, session->transport_rolling());
299 session->goto_start ();
304 BasicUI::next_marker ()
306 framepos_t pos = session->locations()->first_mark_after (session->transport_frame());
309 session->request_locate (pos, session->transport_rolling());
316 BasicUI::set_transport_speed (double speed)
318 session->request_transport_speed (speed);
322 BasicUI::get_transport_speed ()
324 return session->transport_speed ();
340 BasicUI::toggle_all_rec_enables ()
342 if (session->get_record_enabled()) {
343 // session->record_disenable_all ();
345 // session->record_enable_all ();
350 BasicUI::toggle_punch_in ()
352 session->config.set_punch_in (!session->config.get_punch_in());
356 BasicUI::toggle_punch_out ()
358 session->config.set_punch_out (!session->config.get_punch_out());
362 BasicUI::get_record_enabled ()
364 return session->get_record_enabled();
368 BasicUI::set_record_enable (bool yn)
371 session->maybe_enable_record ();
373 session->disable_record (false, true);
378 BasicUI::transport_frame ()
380 return session->transport_frame();
384 BasicUI::locate (framepos_t where, bool roll_after_locate)
386 session->request_locate (where, roll_after_locate);
390 BasicUI::jump_by_seconds (double secs)
392 framepos_t current = session->transport_frame();
393 double s = (double) current / (double) session->nominal_frame_rate();
396 if (s < 0) current = 0;
397 s = s * session->nominal_frame_rate();
399 session->request_locate ( floor(s) );
403 BasicUI::jump_by_bars (double bars)
405 TempoMap& tmap (session->tempo_map());
406 Timecode::BBT_Time bbt (tmap.bbt_at_frame (session->transport_frame()));
409 if (bars < 0) bars = 0;
412 any.type = AnyTime::BBT;
415 session->request_locate ( session->convert_to_frames (any) );
418 void BasicUI::mark_in () { access_action("Editor/start-range-from-playhead"); }
419 void BasicUI::mark_out () { access_action("Editor/finish-range-from-playhead"); }
421 void BasicUI::toggle_click () { access_action("Transport/ToggleClick"); }
422 void BasicUI::midi_panic () { access_action("MIDI/panic"); }
423 void BasicUI::toggle_roll () { access_action("Transport/ToggleRoll"); }
424 void BasicUI::stop_forget () { access_action("Transport/ToggleRollForgetCapture"); }
426 void BasicUI::set_punch_range () { access_action("Editor/set-punch-from-edit-range"); }
427 void BasicUI::set_loop_range () { access_action("Editor/set-loop-from-edit-range"); }
428 void BasicUI::set_session_range () { access_action("Editor/set-session-from-edit-range"); }
430 void BasicUI::toggle_monitor_mute () { /*access_action("Editor/toggle_monitor_mute"); */ }
431 void BasicUI::toggle_monitor_dim () { /*access_action("Editor/toggle_monitor_dim"); */ }
432 void BasicUI::toggle_monitor_mono () { /*access_action("Editor/toggle_monitor_mono"); */ }
434 void BasicUI::quick_snapshot_stay () { access_action("Main/QuickSnapshotStay"); }
435 void BasicUI::quick_snapshot_switch () { access_action("Main/QuickSnapshotSwitch"); }
437 void BasicUI::fit_1_track() { access_action("Editor/fit_1_track"); }
438 void BasicUI::fit_2_tracks() { access_action("Editor/fit_2_tracks"); }
439 void BasicUI::fit_4_tracks() { access_action("Editor/fit_4_tracks"); }
440 void BasicUI::fit_8_tracks() { access_action("Editor/fit_8_tracks"); }
441 void BasicUI::fit_16_tracks() { access_action("Editor/fit_16_tracks"); }
442 void BasicUI::fit_32_tracks() { access_action("Editor/fit_32_tracks"); }
443 void BasicUI::fit_all_tracks() { access_action("Editor/fit_all_tracks"); }
445 void BasicUI::zoom_10_ms() { access_action("Editor/zoom_10_ms"); }
446 void BasicUI::zoom_100_ms() { access_action("Editor/zoom_100_ms"); }
447 void BasicUI::zoom_1_sec() { access_action("Editor/zoom_1_sec"); }
448 void BasicUI::zoom_10_sec() { access_action("Editor/zoom_10_sec"); }
449 void BasicUI::zoom_1_min() { access_action("Editor/zoom_1_min"); }
450 void BasicUI::zoom_5_min() { access_action("Editor/zoom_5_min"); }
451 void BasicUI::zoom_10_min() { access_action("Editor/zoom_10_min"); }
452 void BasicUI::zoom_to_session() { access_action("Editor/zoom-to-session"); }
453 void BasicUI::temporal_zoom_in() { access_action("Editor/temporal-zoom-in"); }
454 void BasicUI::temporal_zoom_out() { access_action("Editor/temporal-zoom-out"); }
456 void BasicUI::scroll_up_1_track() { access_action("Editor/step-tracks-up"); }
457 void BasicUI::scroll_dn_1_track() { access_action("Editor/step-tracks-down"); }
458 void BasicUI::scroll_up_1_page() { access_action("Editor/scroll-tracks-up"); }
459 void BasicUI::scroll_dn_1_page() { access_action("Editor/scroll-tracks-down"); }
465 return session->locate_pending();
471 return session->transport_locked ();
475 BasicUI::timecode_frames_per_hour ()
477 return session->timecode_frames_per_hour ();
481 BasicUI::timecode_time (framepos_t where, Timecode::Time& timecode)
483 session->timecode_time (where, *((Timecode::Time *) &timecode));
487 BasicUI::timecode_to_sample (Timecode::Time& timecode, framepos_t & sample, bool use_offset, bool use_subframes) const
489 session->timecode_to_sample (*((Timecode::Time*)&timecode), sample, use_offset, use_subframes);
493 BasicUI::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const
495 session->sample_to_timecode (sample, *((Timecode::Time*)&timecode), use_offset, use_subframes);
499 this stuff is waiting to go in so that all UIs can offer complex solo/mute functionality
502 BasicUI::solo_release (boost::shared_ptr<Route> r)
507 BasicUI::solo_press (boost::shared_ptr<Route> r, bool momentary, bool global, bool exclusive, bool isolate, bool solo_group)
510 _solo_release = new SoloMuteRelease (_route->soloed());
516 _solo_release->routes = _session->get_routes ();
519 if (Config->get_solo_control_is_listen_control()) {
520 _session->set_listen (_session->get_routes(), !_route->listening(), Session::rt_cleanup, true);
522 _session->set_solo (_session->get_routes(), !_route->soloed(), Session::rt_cleanup, true);
525 } else if (exclusive) {
528 _solo_release->exclusive = true;
530 boost::shared_ptr<RouteList> routes = _session->get_routes();
532 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
533 if ((*i)->soloed ()) {
534 _solo_release->routes_on->push_back (*i);
536 _solo_release->routes_off->push_back (*i);
541 if (Config->get_solo_control_is_listen_control()) {
542 /* ??? we need a just_one_listen() method */
544 _session->set_just_one_solo (_route, true);
547 } else if (isolate) {
549 // shift-click: toggle solo isolated status
551 _route->set_solo_isolated (!_route->solo_isolated(), this);
552 delete _solo_release;
555 } else if (solo_group) {
557 /* Primary-button1: solo mix group.
558 NOTE: Primary-button2 is MIDI learn.
561 if (_route->route_group()) {
564 _solo_release->routes = _route->route_group()->route_list();
567 if (Config->get_solo_control_is_listen_control()) {
568 _session->set_listen (_route->route_group()->route_list(), !_route->listening(), Session::rt_cleanup, true);
570 _session->set_solo (_route->route_group()->route_list(), !_route->soloed(), Session::rt_cleanup, true);
576 /* click: solo this route */
578 boost::shared_ptr<RouteList> rl (new RouteList);
579 rl->push_back (route());
582 _solo_release->routes = rl;
585 if (Config->get_solo_control_is_listen_control()) {
586 _session->set_listen (rl, !_route->listening());
588 _session->set_solo (rl, !_route->soloed());