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 ()
73 if (session->get_play_loop()) {
74 session->request_play_loop (false);
76 session->request_play_loop (true);
77 if (!session->transport_rolling()) {
78 session->request_transport_speed (1.0);
84 BasicUI::loop_location (framepos_t start, framepos_t end)
87 if ((tll = session->locations()->auto_loop_location()) == 0) {
88 Location* loc = new Location (*session, start, end, _("Loop"), Location::IsAutoLoop);
89 session->locations()->add (loc, true);
90 session->set_auto_loop_location (loc);
92 tll->set_hidden (false, this);
93 tll->set (start, end);
98 BasicUI::goto_start ()
100 session->goto_start ();
104 BasicUI::goto_zero ()
106 session->request_locate (0);
112 session->goto_end ();
116 BasicUI::add_marker (const std::string& markername)
118 framepos_t where = session->audible_frame();
119 Location *location = new Location (*session, where, where, markername, Location::IsMark);
120 session->begin_reversible_command (_("add marker"));
121 XMLNode &before = session->locations()->get_state();
122 session->locations()->add (location, true);
123 XMLNode &after = session->locations()->get_state();
124 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
125 session->commit_reversible_command ();
129 BasicUI::remove_marker_at_playhead ()
133 XMLNode &before = session->locations()->get_state();
134 bool removed = false;
136 //find location(s) at this time
137 Locations::LocationList locs;
138 session->locations()->find_all_between (session->audible_frame(), session->audible_frame()+1, locs, Location::Flags(0));
139 for (Locations::LocationList::iterator i = locs.begin(); i != locs.end(); ++i) {
140 if ((*i)->is_mark()) {
141 session->locations()->remove (*i);
148 session->begin_reversible_command (_("remove marker"));
149 XMLNode &after = session->locations()->get_state();
150 session->add_command(new MementoCommand<Locations>(*(session->locations()), &before, &after));
151 session->commit_reversible_command ();
159 session->request_transport_speed (session->transport_speed() - 1.5);
165 session->request_transport_speed (session->transport_speed() + 1.5);
169 BasicUI::transport_stop ()
171 session->request_transport_speed (0.0);
175 BasicUI::transport_play (bool from_last_start)
177 bool rolling = session->transport_rolling ();
179 if (session->get_play_loop()) {
180 session->request_play_loop (false);
183 if (session->get_play_range ()) {
184 session->request_play_range (0);
187 if (from_last_start && rolling) {
188 session->request_locate (session->last_transport_start(), true);
192 session->request_transport_speed (1.0f);
196 BasicUI::rec_enable_toggle ()
198 switch (session->record_status()) {
199 case Session::Disabled:
200 if (session->ntracks() == 0) {
201 // string txt = _("Please create 1 or more track\nbefore trying to record.\nCheck the Session menu.");
202 // MessageDialog msg (*editor, txt);
206 session->maybe_enable_record ();
208 case Session::Recording:
209 case Session::Enabled:
210 session->disable_record (true);
215 BasicUI::all_tracks_rec_in ()
217 session->set_all_tracks_record_enabled (true);
221 BasicUI::all_tracks_rec_out ()
223 session->set_all_tracks_record_enabled (false);
227 BasicUI::save_state ()
229 session->save_state ("");
233 BasicUI::prev_marker ()
235 framepos_t pos = session->locations()->first_mark_before (session->transport_frame());
238 session->request_locate (pos, session->transport_rolling());
240 session->goto_start ();
245 BasicUI::next_marker ()
247 framepos_t pos = session->locations()->first_mark_after (session->transport_frame());
250 session->request_locate (pos, session->transport_rolling());
257 BasicUI::set_transport_speed (double speed)
259 session->request_transport_speed (speed);
263 BasicUI::get_transport_speed ()
265 return session->transport_speed ();
281 BasicUI::toggle_all_rec_enables ()
283 if (session->get_record_enabled()) {
284 // session->record_disenable_all ();
286 // session->record_enable_all ();
291 BasicUI::toggle_punch_in ()
293 session->config.set_punch_in (!session->config.get_punch_in());
297 BasicUI::toggle_punch_out ()
299 session->config.set_punch_out (!session->config.get_punch_out());
303 BasicUI::get_record_enabled ()
305 return session->get_record_enabled();
309 BasicUI::set_record_enable (bool yn)
312 session->maybe_enable_record ();
314 session->disable_record (false, true);
319 BasicUI::transport_frame ()
321 return session->transport_frame();
325 BasicUI::locate (framepos_t where, bool roll_after_locate)
327 session->request_locate (where, roll_after_locate);
331 BasicUI::jump_by_seconds (double secs)
333 framepos_t current = session->transport_frame();
334 double s = (double) current / (double) session->nominal_frame_rate();
337 if (s < 0) current = 0;
338 s = s * session->nominal_frame_rate();
340 session->request_locate ( floor(s) );
344 BasicUI::jump_by_bars (double bars)
346 Timecode::BBT_Time bbt;
347 TempoMap& tmap (session->tempo_map());
348 tmap.bbt_time (session->transport_frame(), bbt);
351 if (bars < 0) bars = 0;
354 any.type = AnyTime::BBT;
357 session->request_locate ( session->convert_to_frames (any) );
360 void BasicUI::mark_in () { access_action("Editor/start-range"); }
361 void BasicUI::mark_out () { access_action("Editor/finish-range"); }
363 void BasicUI::toggle_click () { access_action("Transport/ToggleClick"); }
364 void BasicUI::midi_panic () { access_action("MIDI/panic"); }
365 void BasicUI::toggle_roll () { access_action("Transport/ToggleRoll"); }
366 void BasicUI::stop_forget () { access_action("Transport/ToggleRollForgetCapture"); }
368 void BasicUI::set_punch_range () { access_action("Editor/set-punch-from-edit-range"); }
369 void BasicUI::set_loop_range () { access_action("Editor/set-loop-from-edit-range"); }
370 void BasicUI::set_session_range () { access_action("Editor/set-session-from-edit-range"); }
372 void BasicUI::toggle_monitor_mute () { /*access_action("Editor/toggle_monitor_mute"); */ }
373 void BasicUI::toggle_monitor_dim () { /*access_action("Editor/toggle_monitor_dim"); */ }
374 void BasicUI::toggle_monitor_mono () { /*access_action("Editor/toggle_monitor_mono"); */ }
376 void BasicUI::quick_snapshot_stay () { access_action("Main/QuickSnapshotStay"); }
377 void BasicUI::quick_snapshot_switch () { access_action("Main/QuickSnapshotSwitch"); }
379 void BasicUI::fit_1_track() { access_action("Editor/fit_1_track"); }
380 void BasicUI::fit_2_tracks() { access_action("Editor/fit_2_tracks"); }
381 void BasicUI::fit_4_tracks() { access_action("Editor/fit_4_tracks"); }
382 void BasicUI::fit_8_tracks() { access_action("Editor/fit_8_tracks"); }
383 void BasicUI::fit_16_tracks() { access_action("Editor/fit_16_tracks"); }
384 void BasicUI::fit_32_tracks() { access_action("Editor/fit_32_tracks"); }
385 void BasicUI::fit_all_tracks() { access_action("Editor/fit_all_tracks"); }
387 void BasicUI::zoom_10_ms() { access_action("Editor/zoom_10_ms"); }
388 void BasicUI::zoom_100_ms() { access_action("Editor/zoom_100_ms"); }
389 void BasicUI::zoom_1_sec() { access_action("Editor/zoom_1_sec"); }
390 void BasicUI::zoom_10_sec() { access_action("Editor/zoom_10_sec"); }
391 void BasicUI::zoom_1_min() { access_action("Editor/zoom_1_min"); }
392 void BasicUI::zoom_5_min() { access_action("Editor/zoom_5_min"); }
393 void BasicUI::zoom_10_min() { access_action("Editor/zoom_10_min"); }
394 void BasicUI::zoom_to_session() { access_action("Editor/zoom-to-session"); }
395 void BasicUI::temporal_zoom_in() { access_action("Editor/temporal-zoom-in"); }
396 void BasicUI::temporal_zoom_out() { access_action("Editor/temporal-zoom-out"); }
398 void BasicUI::scroll_up_1_track() { access_action("Editor/step-tracks-up"); }
399 void BasicUI::scroll_dn_1_track() { access_action("Editor/step-tracks-down"); }
400 void BasicUI::scroll_up_1_page() { access_action("Editor/scroll-tracks-up"); }
401 void BasicUI::scroll_dn_1_page() { access_action("Editor/scroll-tracks-down"); }
407 return session->locate_pending();
413 return session->transport_locked ();
417 BasicUI::timecode_frames_per_hour ()
419 return session->timecode_frames_per_hour ();
423 BasicUI::timecode_time (framepos_t where, Timecode::Time& timecode)
425 session->timecode_time (where, *((Timecode::Time *) &timecode));
429 BasicUI::timecode_to_sample (Timecode::Time& timecode, framepos_t & sample, bool use_offset, bool use_subframes) const
431 session->timecode_to_sample (*((Timecode::Time*)&timecode), sample, use_offset, use_subframes);
435 BasicUI::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const
437 session->sample_to_timecode (sample, *((Timecode::Time*)&timecode), use_offset, use_subframes);
441 this stuff is waiting to go in so that all UIs can offer complex solo/mute functionality
444 BasicUI::solo_release (boost::shared_ptr<Route> r)
449 BasicUI::solo_press (boost::shared_ptr<Route> r, bool momentary, bool global, bool exclusive, bool isolate, bool solo_group)
452 _solo_release = new SoloMuteRelease (_route->soloed());
458 _solo_release->routes = _session->get_routes ();
461 if (Config->get_solo_control_is_listen_control()) {
462 _session->set_listen (_session->get_routes(), !_route->listening(), Session::rt_cleanup, true);
464 _session->set_solo (_session->get_routes(), !_route->soloed(), Session::rt_cleanup, true);
467 } else if (exclusive) {
470 _solo_release->exclusive = true;
472 boost::shared_ptr<RouteList> routes = _session->get_routes();
474 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
475 if ((*i)->soloed ()) {
476 _solo_release->routes_on->push_back (*i);
478 _solo_release->routes_off->push_back (*i);
483 if (Config->get_solo_control_is_listen_control()) {
484 /* ??? we need a just_one_listen() method */
486 _session->set_just_one_solo (_route, true);
489 } else if (isolate) {
491 // shift-click: toggle solo isolated status
493 _route->set_solo_isolated (!_route->solo_isolated(), this);
494 delete _solo_release;
497 } else if (solo_group) {
499 /* Primary-button1: solo mix group.
500 NOTE: Primary-button2 is MIDI learn.
503 if (_route->route_group()) {
506 _solo_release->routes = _route->route_group()->route_list();
509 if (Config->get_solo_control_is_listen_control()) {
510 _session->set_listen (_route->route_group()->route_list(), !_route->listening(), Session::rt_cleanup, true);
512 _session->set_solo (_route->route_group()->route_list(), !_route->soloed(), Session::rt_cleanup, true);
518 /* click: solo this route */
520 boost::shared_ptr<RouteList> rl (new RouteList);
521 rl->push_back (route());
524 _solo_release->routes = rl;
527 if (Config->get_solo_control_is_listen_control()) {
528 _session->set_listen (rl, !_route->listening());
530 _session->set_solo (rl, !_route->soloed());