remove a bunch of code that will no longer be used
[ardour.git] / libs / surfaces / control_protocol / basic_ui.cc
1 /*
2     Copyright (C) 2006 Paul Davis
3
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.
9
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.
14
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.
18
19 */
20
21 #include "pbd/pthread_utils.h"
22 #include "pbd/memento_command.h"
23
24 #include "ardour/session.h"
25 #include "ardour/location.h"
26 #include "ardour/tempo.h"
27
28 #include "control_protocol/basic_ui.h"
29
30 #include "i18n.h"
31
32 using namespace ARDOUR;
33
34 PBD::Signal2<void,std::string,std::string> BasicUI::AccessAction;
35
36 BasicUI::BasicUI (Session& s)
37         : session (&s)
38 {
39 }
40
41 BasicUI::BasicUI ()
42         : session (0)
43 {
44 }
45
46 BasicUI::~BasicUI ()
47 {
48
49 }
50
51 void
52 BasicUI::register_thread (std::string name)
53 {
54         std::string pool_name = name;
55         pool_name += " events";
56
57         SessionEvent::create_per_thread_pool (pool_name, 64);
58 }
59
60 void
61 BasicUI::access_action ( std::string action_path )
62 {
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 );
66
67         AccessAction( group, item );
68 }
69
70 void
71 BasicUI::loop_toggle ()
72 {
73         if (!session) {
74                 return;
75         }
76
77         Location * looploc = session->locations()->auto_loop_location();
78
79         if (!looploc) {
80                 return;
81         }
82
83         if (session->get_play_loop()) {
84
85                 /* looping enabled, our job is to disable it */
86
87                 session->request_play_loop (false);
88
89         } else {
90
91                 /* looping not enabled, our job is to enable it.
92
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.
96                 */
97                 if (Config->get_loop_is_mode()) {
98                         session->request_play_loop (true, false);
99                 } else {
100                         session->request_play_loop (true, true);
101                 }
102         }
103
104         //show the loop markers
105         looploc->set_hidden (false, this);
106 }
107
108 void
109 BasicUI::loop_location (framepos_t start, framepos_t end)
110 {
111         Location* tll;
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);
116         } else {
117                 tll->set_hidden (false, this);
118                 tll->set (start, end);
119         }
120 }
121
122 void
123 BasicUI::goto_start ()
124 {
125         session->goto_start ();
126 }
127
128 void
129 BasicUI::goto_zero ()
130 {
131         session->request_locate (0);
132 }
133
134 void
135 BasicUI::goto_end ()
136 {
137         session->goto_end ();
138 }
139
140 void
141 BasicUI::add_marker (const std::string& markername)
142 {
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 ();
151 }
152
153 void
154 BasicUI::remove_marker_at_playhead ()
155 {
156         if (session) {
157                 //set up for undo
158                 XMLNode &before = session->locations()->get_state();
159                 bool removed = false;
160
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);
167                                 removed = true;
168                         }
169                 }
170
171                 //store undo
172                 if (removed) {
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 ();
177                 }
178         }
179 }
180
181 void
182 BasicUI::rewind ()
183 {
184         session->request_transport_speed (session->transport_speed() - 1.5);
185 }
186
187 void
188 BasicUI::ffwd ()
189 {
190         session->request_transport_speed (session->transport_speed() + 1.5);
191 }
192
193 void
194 BasicUI::transport_stop ()
195 {
196         session->request_transport_speed (0.0);
197 }
198
199 void
200 BasicUI::transport_play (bool from_last_start)
201 {
202         if (!session) {
203                 return;
204         }
205
206         if (session->is_auditioning()) {
207                 return;
208         }
209
210 #if 0
211         if (session->config.get_external_sync()) {
212                 switch (Config->get_sync_source()) {
213                 case Engine:
214                         break;
215                 default:
216                         /* transport controlled by the master */
217                         return;
218                 }
219         }
220 #endif
221
222         bool rolling = session->transport_rolling();
223
224         if (session->get_play_loop()) {
225
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.
229                 */
230
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)
234                         */
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);
241                         }
242                 }
243
244         } else if (session->get_play_range () ) {
245                 /* stop playing a range if we currently are */
246                 session->request_play_range (0, true);
247         }
248
249         if (!rolling) {
250                 session->request_transport_speed (1.0f);
251         }
252 }
253
254 void
255 BasicUI::rec_enable_toggle ()
256 {
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);
262                         // msg.run ();
263                         return;
264                 }
265                 session->maybe_enable_record ();
266                 break;
267         case Session::Recording:
268         case Session::Enabled:
269                 session->disable_record (false, true);
270         }
271 }
272
273 void
274 BasicUI::all_tracks_rec_in ()
275 {
276         session->set_all_tracks_record_enabled (true);
277 }
278
279 void
280 BasicUI::all_tracks_rec_out ()
281 {
282         session->set_all_tracks_record_enabled (false);
283 }
284
285 void
286 BasicUI::save_state ()
287 {
288         session->save_state ("");
289 }
290
291 void
292 BasicUI::prev_marker ()
293 {
294         framepos_t pos = session->locations()->first_mark_before (session->transport_frame());
295
296         if (pos >= 0) {
297                 session->request_locate (pos, session->transport_rolling());
298         } else {
299                 session->goto_start ();
300         }
301 }
302
303 void
304 BasicUI::next_marker ()
305 {
306         framepos_t pos = session->locations()->first_mark_after (session->transport_frame());
307
308         if (pos >= 0) {
309                 session->request_locate (pos, session->transport_rolling());
310         } else {
311                 session->goto_end();
312         }
313 }
314
315 void
316 BasicUI::set_transport_speed (double speed)
317 {
318         session->request_transport_speed (speed);
319 }
320
321 double
322 BasicUI::get_transport_speed ()
323 {
324         return session->transport_speed ();
325 }
326
327 void
328 BasicUI::undo ()
329 {
330         session->undo (1);
331 }
332
333 void
334 BasicUI::redo ()
335 {
336         session->redo (1);
337 }
338
339 void
340 BasicUI::toggle_all_rec_enables ()
341 {
342         if (session->get_record_enabled()) {
343                 // session->record_disenable_all ();
344         } else {
345                 // session->record_enable_all ();
346         }
347 }
348
349 void
350 BasicUI::toggle_punch_in ()
351 {
352         session->config.set_punch_in (!session->config.get_punch_in());
353 }
354
355 void
356 BasicUI::toggle_punch_out ()
357 {
358         session->config.set_punch_out (!session->config.get_punch_out());
359 }
360
361 bool
362 BasicUI::get_record_enabled ()
363 {
364         return session->get_record_enabled();
365 }
366
367 void
368 BasicUI::set_record_enable (bool yn)
369 {
370         if (yn) {
371                 session->maybe_enable_record ();
372         } else {
373                 session->disable_record (false, true);
374         }
375 }
376
377 framepos_t
378 BasicUI::transport_frame ()
379 {
380         return session->transport_frame();
381 }
382
383 void
384 BasicUI::locate (framepos_t where, bool roll_after_locate)
385 {
386         session->request_locate (where, roll_after_locate);
387 }
388
389 void
390 BasicUI::jump_by_seconds (double secs)
391 {
392         framepos_t current = session->transport_frame();
393         double s = (double) current / (double) session->nominal_frame_rate();
394
395         s+= secs;
396         if (s < 0) current = 0;
397         s = s * session->nominal_frame_rate();
398
399         session->request_locate ( floor(s) );
400 }
401
402 void
403 BasicUI::jump_by_bars (double bars)
404 {
405         TempoMap& tmap (session->tempo_map());
406         Timecode::BBT_Time bbt (tmap.bbt_at_frame (session->transport_frame()));
407
408         bars += bbt.bars;
409         if (bars < 0) bars = 0;
410
411         AnyTime any;
412         any.type = AnyTime::BBT;
413         any.bbt.bars = bars;
414
415         session->request_locate ( session->convert_to_frames (any) );
416 }
417
418 void BasicUI::mark_in () { access_action("Editor/start-range-from-playhead"); }
419 void BasicUI::mark_out () { access_action("Editor/finish-range-from-playhead"); }
420
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"); }
425
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"); }
429
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");  */ }
433
434 void BasicUI::quick_snapshot_stay () { access_action("Main/QuickSnapshotStay"); }
435 void BasicUI::quick_snapshot_switch () { access_action("Main/QuickSnapshotSwitch"); }
436
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"); }
444
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"); }
455
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"); }
460
461
462 bool
463 BasicUI::locating ()
464 {
465         return session->locate_pending();
466 }
467
468 bool
469 BasicUI::locked ()
470 {
471         return session->transport_locked ();
472 }
473
474 ARDOUR::framecnt_t
475 BasicUI::timecode_frames_per_hour ()
476 {
477         return session->timecode_frames_per_hour ();
478 }
479
480 void
481 BasicUI::timecode_time (framepos_t where, Timecode::Time& timecode)
482 {
483         session->timecode_time (where, *((Timecode::Time *) &timecode));
484 }
485
486 void
487 BasicUI::timecode_to_sample (Timecode::Time& timecode, framepos_t & sample, bool use_offset, bool use_subframes) const
488 {
489         session->timecode_to_sample (*((Timecode::Time*)&timecode), sample, use_offset, use_subframes);
490 }
491
492 void
493 BasicUI::sample_to_timecode (framepos_t sample, Timecode::Time& timecode, bool use_offset, bool use_subframes) const
494 {
495         session->sample_to_timecode (sample, *((Timecode::Time*)&timecode), use_offset, use_subframes);
496 }
497
498 #if 0
499 this stuff is waiting to go in so that all UIs can offer complex solo/mute functionality
500
501 void
502 BasicUI::solo_release (boost::shared_ptr<Route> r)
503 {
504 }
505
506 void
507 BasicUI::solo_press (boost::shared_ptr<Route> r, bool momentary, bool global, bool exclusive, bool isolate, bool solo_group)
508 {
509         if (momentary) {
510                 _solo_release = new SoloMuteRelease (_route->soloed());
511         }
512
513         if (global) {
514
515                 if (_solo_release) {
516                         _solo_release->routes = _session->get_routes ();
517                 }
518
519                 if (Config->get_solo_control_is_listen_control()) {
520                         _session->set_listen (_session->get_routes(), !_route->listening(),  Session::rt_cleanup, true);
521                 } else {
522                         _session->set_solo (_session->get_routes(), !_route->soloed(),  Session::rt_cleanup, true);
523                 }
524
525         } else if (exclusive) {
526
527                 if (_solo_release) {
528                         _solo_release->exclusive = true;
529
530                         boost::shared_ptr<RouteList> routes = _session->get_routes();
531
532                         for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
533                                 if ((*i)->soloed ()) {
534                                         _solo_release->routes_on->push_back (*i);
535                                 } else {
536                                         _solo_release->routes_off->push_back (*i);
537                                 }
538                         }
539                 }
540
541                 if (Config->get_solo_control_is_listen_control()) {
542                         /* ??? we need a just_one_listen() method */
543                 } else {
544                         _session->set_just_one_solo (_route, true);
545                 }
546
547         } else if (isolate) {
548
549                 // shift-click: toggle solo isolated status
550
551                 _route->set_solo_isolated (!_route->solo_isolated(), this);
552                 delete _solo_release;
553                 _solo_release = 0;
554
555         } else if (solo_group) {
556
557                 /* Primary-button1: solo mix group.
558                    NOTE: Primary-button2 is MIDI learn.
559                 */
560
561                 if (_route->route_group()) {
562
563                         if (_solo_release) {
564                                 _solo_release->routes = _route->route_group()->route_list();
565                         }
566
567                         if (Config->get_solo_control_is_listen_control()) {
568                                 _session->set_listen (_route->route_group()->route_list(), !_route->listening(),  Session::rt_cleanup, true);
569                         } else {
570                                 _session->set_solo (_route->route_group()->route_list(), !_route->soloed(),  Session::rt_cleanup, true);
571                         }
572                 }
573
574         } else {
575
576                 /* click: solo this route */
577
578                 boost::shared_ptr<RouteList> rl (new RouteList);
579                 rl->push_back (route());
580
581                 if (_solo_release) {
582                         _solo_release->routes = rl;
583                 }
584
585                 if (Config->get_solo_control_is_listen_control()) {
586                         _session->set_listen (rl, !_route->listening());
587                 } else {
588                         _session->set_solo (rl, !_route->soloed());
589                 }
590         }
591 }
592 #endif