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::save_state ()
217 session->save_state ("");
221 BasicUI::prev_marker ()
223 framepos_t pos = session->locations()->first_mark_before (session->transport_frame());
226 session->request_locate (pos, session->transport_rolling());
228 session->goto_start ();
233 BasicUI::next_marker ()
235 framepos_t pos = session->locations()->first_mark_after (session->transport_frame());
238 session->request_locate (pos, session->transport_rolling());
245 BasicUI::set_transport_speed (double speed)
247 session->request_transport_speed (speed);
251 BasicUI::get_transport_speed ()
253 return session->transport_speed ();
269 BasicUI::toggle_all_rec_enables ()
271 if (session->get_record_enabled()) {
272 // session->record_disenable_all ();
274 // session->record_enable_all ();
279 BasicUI::toggle_punch_in ()
281 session->config.set_punch_in (!session->config.get_punch_in());
285 BasicUI::toggle_punch_out ()
287 session->config.set_punch_out (!session->config.get_punch_out());
291 BasicUI::get_record_enabled ()
293 return session->get_record_enabled();
297 BasicUI::set_record_enable (bool yn)
300 session->maybe_enable_record ();
302 session->disable_record (false, true);
307 BasicUI::transport_frame ()
309 return session->transport_frame();
313 BasicUI::locate (framepos_t where, bool roll_after_locate)
315 session->request_locate (where, roll_after_locate);
319 BasicUI::jump_by_seconds (double secs)
321 framepos_t current = session->transport_frame();
322 double s = (double) current / (double) session->nominal_frame_rate();
325 if (s < 0) current = 0;
326 s = s * session->nominal_frame_rate();
328 session->request_locate ( floor(s) );
332 BasicUI::jump_by_bars (double bars)
334 Timecode::BBT_Time bbt;
335 TempoMap& tmap (session->tempo_map());
336 tmap.bbt_time (session->transport_frame(), bbt);
339 if (bars < 0) bars = 0;
342 any.type = AnyTime::BBT;
345 session->request_locate ( session->convert_to_frames (any) );
348 void BasicUI::mark_in () { access_action("Editor/start-range"); }
349 void BasicUI::mark_out () { access_action("Editor/finish-range"); }
351 void BasicUI::toggle_click () { access_action("Transport/ToggleClick"); }
352 void BasicUI::midi_panic () { access_action("MIDI/panic"); }
353 void BasicUI::toggle_roll () { access_action("Transport/ToggleRoll"); }
354 void BasicUI::stop_forget () { access_action("Transport/ToggleRollForgetCapture"); }
356 void BasicUI::set_punch_range () { access_action("Editor/set-punch-from-edit-range"); }
357 void BasicUI::set_loop_range () { access_action("Editor/set-loop-from-edit-range"); }
358 void BasicUI::set_session_range () { access_action("Editor/set-session-from-edit-range"); }
360 void BasicUI::toggle_monitor_mute () { /*access_action("Editor/toggle_monitor_mute"); */ }
361 void BasicUI::toggle_monitor_dim () { /*access_action("Editor/toggle_monitor_dim"); */ }
362 void BasicUI::toggle_monitor_mono () { /*access_action("Editor/toggle_monitor_mono"); */ }
364 void BasicUI::quick_snapshot_stay () { access_action("Main/QuickSnapshotStay"); }
365 void BasicUI::quick_snapshot_switch () { access_action("Main/QuickSnapshotSwitch"); }
367 void BasicUI::fit_1_track() { access_action("Editor/fit_1_track"); }
368 void BasicUI::fit_2_tracks() { access_action("Editor/fit_2_tracks"); }
369 void BasicUI::fit_4_tracks() { access_action("Editor/fit_4_tracks"); }
370 void BasicUI::fit_8_tracks() { access_action("Editor/fit_8_tracks"); }
371 void BasicUI::fit_16_tracks() { access_action("Editor/fit_16_tracks"); }
372 void BasicUI::fit_32_tracks() { access_action("Editor/fit_32_tracks"); }
373 void BasicUI::fit_all_tracks() { access_action("Editor/fit_all_tracks"); }
375 void BasicUI::zoom_10_ms() { access_action("Editor/zoom_10_ms"); }
376 void BasicUI::zoom_100_ms() { access_action("Editor/zoom_100_ms"); }
377 void BasicUI::zoom_1_sec() { access_action("Editor/zoom_1_sec"); }
378 void BasicUI::zoom_10_sec() { access_action("Editor/zoom_10_sec"); }
379 void BasicUI::zoom_1_min() { access_action("Editor/zoom_1_min"); }
380 void BasicUI::zoom_5_min() { access_action("Editor/zoom_5_min"); }
381 void BasicUI::zoom_10_min() { access_action("Editor/zoom_10_min"); }
382 void BasicUI::zoom_to_session() { access_action("Editor/zooom-to-session"); }
384 void BasicUI::scroll_up_1_track() { access_action("Editor/scroll_up_1_track"); }
385 void BasicUI::scroll_dn_1_track() { access_action("Editor/scroll_dn_1_track"); }
391 return session->locate_pending();
397 return session->transport_locked ();
401 BasicUI::timecode_frames_per_hour ()
403 return session->timecode_frames_per_hour ();
407 BasicUI::timecode_time (framepos_t where, Timecode::Time& timecode)
409 session->timecode_time (where, *((Timecode::Time *) &timecode));
413 BasicUI::timecode_to_sample (Timecode::Time& timecode, framepos_t & sample, bool use_offset, bool use_subframes) const
415 session->timecode_to_sample (*((Timecode::Time*)&timecode), sample, use_offset, use_subframes);
419 BasicUI::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const
421 session->sample_to_timecode (sample, *((Timecode::Time*)&timecode), use_offset, use_subframes);
425 this stuff is waiting to go in so that all UIs can offer complex solo/mute functionality
428 BasicUI::solo_release (boost::shared_ptr<Route> r)
433 BasicUI::solo_press (boost::shared_ptr<Route> r, bool momentary, bool global, bool exclusive, bool isolate, bool solo_group)
436 _solo_release = new SoloMuteRelease (_route->soloed());
442 _solo_release->routes = _session->get_routes ();
445 if (Config->get_solo_control_is_listen_control()) {
446 _session->set_listen (_session->get_routes(), !_route->listening(), Session::rt_cleanup, true);
448 _session->set_solo (_session->get_routes(), !_route->soloed(), Session::rt_cleanup, true);
451 } else if (exclusive) {
454 _solo_release->exclusive = true;
456 boost::shared_ptr<RouteList> routes = _session->get_routes();
458 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
459 if ((*i)->soloed ()) {
460 _solo_release->routes_on->push_back (*i);
462 _solo_release->routes_off->push_back (*i);
467 if (Config->get_solo_control_is_listen_control()) {
468 /* ??? we need a just_one_listen() method */
470 _session->set_just_one_solo (_route, true);
473 } else if (isolate) {
475 // shift-click: toggle solo isolated status
477 _route->set_solo_isolated (!_route->solo_isolated(), this);
478 delete _solo_release;
481 } else if (solo_group) {
483 /* Primary-button1: solo mix group.
484 NOTE: Primary-button2 is MIDI learn.
487 if (_route->route_group()) {
490 _solo_release->routes = _route->route_group()->route_list();
493 if (Config->get_solo_control_is_listen_control()) {
494 _session->set_listen (_route->route_group()->route_list(), !_route->listening(), Session::rt_cleanup, true);
496 _session->set_solo (_route->route_group()->route_list(), !_route->soloed(), Session::rt_cleanup, true);
502 /* click: solo this route */
504 boost::shared_ptr<RouteList> rl (new RouteList);
505 rl->push_back (route());
508 _solo_release->routes = rl;
511 if (Config->get_solo_control_is_listen_control()) {
512 _session->set_listen (rl, !_route->listening());
514 _session->set_solo (rl, !_route->soloed());