2 Copyright (C) 1999-2003 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include "pbd/error.h"
30 #include "pbd/enumwriter.h"
31 #include "pbd/pthread_utils.h"
32 #include "pbd/memento_command.h"
33 #include "pbd/stacktrace.h"
35 #include "midi++/mmc.h"
36 #include "midi++/port.h"
38 #include "ardour/audioengine.h"
39 #include "ardour/auditioner.h"
40 #include "ardour/butler.h"
41 #include "ardour/click.h"
42 #include "ardour/debug.h"
43 #include "ardour/location.h"
44 #include "ardour/profile.h"
45 #include "ardour/scene_changer.h"
46 #include "ardour/session.h"
47 #include "ardour/slave.h"
48 #include "ardour/operations.h"
53 using namespace ARDOUR;
57 Session::add_post_transport_work (PostTransportWork ptw)
59 PostTransportWork oldval;
60 PostTransportWork newval;
64 oldval = (PostTransportWork) g_atomic_int_get (&_post_transport_work);
65 newval = PostTransportWork (oldval | ptw);
66 if (g_atomic_int_compare_and_exchange (&_post_transport_work, oldval, newval)) {
72 error << "Could not set post transport work! Crazy thread madness, call the programmers" << endmsg;
76 Session::request_input_change_handling ()
78 if (!(_state_of_the_state & (InitialConnecting|Deletion))) {
79 SessionEvent* ev = new SessionEvent (SessionEvent::InputConfigurationChange, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
85 Session::request_sync_source (Slave* new_slave)
87 SessionEvent* ev = new SessionEvent (SessionEvent::SetSyncSource, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
90 seamless = Config->get_seamless_loop ();
92 if (dynamic_cast<Engine_Slave*>(new_slave)) {
93 /* JACK cannot support seamless looping at present */
94 Config->set_seamless_loop (false);
96 /* reset to whatever the value was before we last switched slaves */
97 Config->set_seamless_loop (_was_seamless);
100 /* save value of seamless from before the switch */
101 _was_seamless = seamless;
103 ev->slave = new_slave;
104 DEBUG_TRACE (DEBUG::Slave, "sent request for new slave\n");
109 Session::request_transport_speed (double speed, bool as_default)
111 SessionEvent* ev = new SessionEvent (SessionEvent::SetTransportSpeed, SessionEvent::Add, SessionEvent::Immediate, 0, speed);
112 ev->third_yes_or_no = as_default; // as_default
113 DEBUG_TRACE (DEBUG::Transport, string_compose ("Request transport speed = %1 as default = %2\n", speed, as_default));
117 /** Request a new transport speed, but if the speed parameter is exactly zero then use
118 * a very small +ve value to prevent the transport actually stopping. This method should
119 * be used by callers who are varying transport speed but don't ever want to stop it.
122 Session::request_transport_speed_nonzero (double speed, bool as_default)
128 request_transport_speed (speed, as_default);
132 Session::request_track_speed (Track* tr, double speed)
134 SessionEvent* ev = new SessionEvent (SessionEvent::SetTrackSpeed, SessionEvent::Add, SessionEvent::Immediate, 0, speed);
140 Session::request_stop (bool abort, bool clear_state)
142 SessionEvent* ev = new SessionEvent (SessionEvent::SetTransportSpeed, SessionEvent::Add, SessionEvent::Immediate, audible_frame(), 0.0, abort, clear_state);
143 DEBUG_TRACE (DEBUG::Transport, string_compose ("Request transport stop, audible %3 transport %4 abort = %1, clear state = %2\n", abort, clear_state, audible_frame(), _transport_frame));
148 Session::request_locate (framepos_t target_frame, bool with_roll)
150 SessionEvent *ev = new SessionEvent (with_roll ? SessionEvent::LocateRoll : SessionEvent::Locate, SessionEvent::Add, SessionEvent::Immediate, target_frame, 0, false);
151 DEBUG_TRACE (DEBUG::Transport, string_compose ("Request locate to %1\n", target_frame));
156 Session::force_locate (framepos_t target_frame, bool with_roll)
158 SessionEvent *ev = new SessionEvent (with_roll ? SessionEvent::LocateRoll : SessionEvent::Locate, SessionEvent::Add, SessionEvent::Immediate, target_frame, 0, true);
159 DEBUG_TRACE (DEBUG::Transport, string_compose ("Request forced locate to %1\n", target_frame));
164 Session::request_play_loop (bool yn, bool change_transport_roll)
167 // don't attempt to loop when not using Internal Transport
168 // see also gtk2_ardour/ardour_ui_options.cc parameter_changed()
173 Location *location = _locations->auto_loop_location();
176 if (location == 0 && yn) {
177 error << _("Cannot loop - no loop range defined")
182 if (change_transport_roll) {
183 if (transport_rolling()) {
184 /* start looping at current speed */
185 target_speed = transport_speed ();
187 /* currently stopped */
189 /* start looping at normal speed */
196 /* leave the speed alone */
197 target_speed = transport_speed ();
200 ev = new SessionEvent (SessionEvent::SetLoop, SessionEvent::Add, SessionEvent::Immediate, 0, target_speed, yn);
201 DEBUG_TRACE (DEBUG::Transport, string_compose ("Request set loop = %1, change roll state ? %2\n", yn, change_transport_roll));
205 if (!change_transport_roll) {
206 if (!transport_rolling()) {
207 /* we're not changing transport state, but we do want
208 to set up position for the new loop. Don't
209 do this if we're rolling already.
211 request_locate (location->start(), false);
215 if (!change_transport_roll && Config->get_seamless_loop() && transport_rolling()) {
216 // request an immediate locate to refresh the tracks
217 // after disabling looping
218 request_locate (_transport_frame-1, false);
224 Session::request_play_range (list<AudioRange>* range, bool leave_rolling)
226 SessionEvent* ev = new SessionEvent (SessionEvent::SetPlayAudioRange, SessionEvent::Add, SessionEvent::Immediate, 0, (leave_rolling ? 1.0 : 0.0));
228 ev->audio_range = *range;
230 ev->audio_range.clear ();
232 DEBUG_TRACE (DEBUG::Transport, string_compose ("Request play range, leave rolling ? %1\n", leave_rolling));
237 Session::request_cancel_play_range ()
239 SessionEvent* ev = new SessionEvent (SessionEvent::CancelPlayAudioRange, SessionEvent::Add, SessionEvent::Immediate, 0, 0);
245 Session::realtime_stop (bool abort, bool clear_state)
247 DEBUG_TRACE (DEBUG::Transport, string_compose ("realtime stop @ %1\n", _transport_frame));
248 PostTransportWork todo = PostTransportWork (0);
250 /* assume that when we start, we'll be moving forwards */
252 if (_transport_speed < 0.0f) {
253 todo = (PostTransportWork (todo | PostTransportStop | PostTransportReverse));
254 _default_transport_speed = 1.0;
256 todo = PostTransportWork (todo | PostTransportStop);
261 boost::shared_ptr<RouteList> r = routes.reader ();
263 for (RouteList::iterator i = r->begin (); i != r->end(); ++i) {
264 (*i)->realtime_handle_transport_stopped ();
267 DEBUG_TRACE (DEBUG::Transport, string_compose ("stop complete, auto-return scheduled for return to %1\n", _requested_return_frame));
269 /* the duration change is not guaranteed to have happened, but is likely */
271 todo = PostTransportWork (todo | PostTransportDuration);
274 todo = PostTransportWork (todo | PostTransportAbort);
278 todo = PostTransportWork (todo | PostTransportClearSubstate);
282 add_post_transport_work (todo);
285 _clear_event_type (SessionEvent::StopOnce);
286 _clear_event_type (SessionEvent::RangeStop);
287 _clear_event_type (SessionEvent::RangeLocate);
289 /* if we're going to clear loop state, then force disabling record BUT only if we're not doing latched rec-enable */
290 disable_record (true, (!Config->get_latched_record_enable() && clear_state));
292 if (clear_state && !Config->get_loop_is_mode()) {
296 reset_slave_state ();
298 _transport_speed = 0;
299 _target_transport_speed = 0;
301 g_atomic_int_set (&_playback_load, 100);
302 g_atomic_int_set (&_capture_load, 100);
304 if (config.get_use_video_sync()) {
305 waiting_for_sync_offset = true;
308 transport_sub_state = 0;
312 Session::realtime_locate ()
314 boost::shared_ptr<RouteList> r = routes.reader ();
315 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
316 (*i)->realtime_locate ();
321 Session::butler_transport_work ()
323 /* Note: this function executes in the butler thread context */
327 PostTransportWork ptw;
328 boost::shared_ptr<RouteList> r = routes.reader ();
331 int on_entry = g_atomic_int_get (&_butler->should_do_transport_work);
333 ptw = post_transport_work();
335 DEBUG_TRACE (DEBUG::Transport, string_compose ("Butler transport work, todo = %1 at %2\n", enum_2_string (ptw), (before = g_get_monotonic_time())));
338 if (ptw & PostTransportLocate) {
340 if (get_play_loop() && !Config->get_seamless_loop()) {
342 DEBUG_TRACE (DEBUG::Butler, "flush loop recording fragment to disk\n");
344 /* this locate might be happening while we are
347 * Non-seamless looping will require a locate (below) that
348 * will reset capture buffers and throw away data.
350 * Rather than first find all tracks and see if they
351 * have outstanding data, just do a flush anyway. It
352 * may be cheaper this way anyway, and is certainly
356 bool more_disk_io_to_do = false;
360 more_disk_io_to_do = _butler->flush_tracks_to_disk_after_locate (r, errors);
366 if (more_disk_io_to_do) {
375 if (ptw & PostTransportAdjustPlaybackBuffering) {
376 /* non_realtime_locate() calls Automatable::transport_located()
377 * for every route. This eventually calls
378 * ARDOUR::AutomationList::state () which has a LocaleGuard,
379 * and would switch locales forth/back every time.
382 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
383 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
385 tr->adjust_playback_buffering ();
386 /* and refill those buffers ... */
388 (*i)->non_realtime_locate (_transport_frame);
393 if (ptw & PostTransportAdjustCaptureBuffering) {
394 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
395 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
397 tr->adjust_capture_buffering ();
402 if (ptw & PostTransportCurveRealloc) {
403 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
404 (*i)->curve_reallocate();
408 if (ptw & PostTransportInputChange) {
409 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
410 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
412 tr->non_realtime_input_change ();
417 if (ptw & PostTransportSpeed) {
418 non_realtime_set_speed ();
421 if (ptw & PostTransportReverse) {
424 cumulative_rf_motion = 0;
427 /* don't seek if locate will take care of that in non_realtime_stop() */
429 if (!(ptw & PostTransportLocate)) {
430 LocaleGuard lg; // see note for non_realtime_locate() above
431 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
432 (*i)->non_realtime_locate (_transport_frame);
434 if (on_entry != g_atomic_int_get (&_butler->should_do_transport_work)) {
435 /* new request, stop seeking, and start again */
436 g_atomic_int_dec_and_test (&_butler->should_do_transport_work);
443 if (ptw & PostTransportLocate) {
444 DEBUG_TRACE (DEBUG::Transport, "nonrealtime locate invoked from BTW\n");
445 non_realtime_locate ();
448 if (ptw & PostTransportStop) {
449 non_realtime_stop (ptw & PostTransportAbort, on_entry, finished);
451 g_atomic_int_dec_and_test (&_butler->should_do_transport_work);
456 if (ptw & PostTransportOverWrite) {
457 non_realtime_overwrite (on_entry, finished);
459 g_atomic_int_dec_and_test (&_butler->should_do_transport_work);
464 if (ptw & PostTransportAudition) {
465 non_realtime_set_audition ();
468 g_atomic_int_dec_and_test (&_butler->should_do_transport_work);
470 DEBUG_TRACE (DEBUG::Transport, string_compose (X_("Butler transport work all done after %1 usecs\n"), g_get_monotonic_time() - before));
471 DEBUG_TRACE (DEBUG::Transport, X_(string_compose ("Frame %1\n", _transport_frame)));
475 Session::non_realtime_set_speed ()
477 boost::shared_ptr<RouteList> rl = routes.reader();
478 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
479 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
481 tr->non_realtime_set_speed ();
487 Session::non_realtime_overwrite (int on_entry, bool& finished)
489 boost::shared_ptr<RouteList> rl = routes.reader();
490 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
491 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
492 if (tr && tr->pending_overwrite ()) {
493 tr->overwrite_existing_buffers ();
495 if (on_entry != g_atomic_int_get (&_butler->should_do_transport_work)) {
504 Session::non_realtime_locate ()
506 DEBUG_TRACE (DEBUG::Transport, string_compose ("locate tracks to %1\n", _transport_frame));
508 if (Config->get_loop_is_mode() && get_play_loop()) {
510 Location *loc = _locations->auto_loop_location();
512 if (!loc || (_transport_frame < loc->start() || _transport_frame >= loc->end())) {
513 /* jumped out of loop range: stop tracks from looping,
514 but leave loop (mode) enabled.
516 set_track_loop (false);
518 } else if (loc && Config->get_seamless_loop() &&
519 ((loc->start() <= _transport_frame) ||
520 (loc->end() > _transport_frame) ) ) {
522 /* jumping to start of loop. This might have been done before but it is
523 * idempotent and cheap. Doing it here ensures that when we start playback
524 * outside the loop we still flip tracks into the magic seamless mode
527 set_track_loop (true);
530 set_track_loop (false);
535 /* no more looping .. should have been noticed elsewhere */
540 LocaleGuard lg; // see note for non_realtime_locate() above
541 boost::shared_ptr<RouteList> rl = routes.reader();
542 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
543 (*i)->non_realtime_locate (_transport_frame);
547 _scene_changer->locate (_transport_frame);
549 /* XXX: it would be nice to generate the new clicks here (in the non-RT thread)
550 rather than clearing them so that the RT thread has to spend time constructing
551 them (in Session::click).
556 #ifdef USE_TRACKS_CODE_FEATURES
558 Session::select_playhead_priority_target (framepos_t& jump_to)
562 AutoReturnTarget autoreturn = Config->get_auto_return_target_list ();
568 if (Profile->get_trx() && transport_rolling() ) {
569 // We're playing, so do nothing.
570 // Next stop will put us where we need to be.
574 /* Note that the order of checking each AutoReturnTarget flag defines
575 the priority each flag.
577 Ardour/Mixbus: Last Locate
582 Tracks: Range Selection
588 if (autoreturn & RangeSelectionStart) {
589 if (!_range_selection.empty()) {
590 jump_to = _range_selection.from;
592 if (transport_rolling ()) {
593 /* Range selection no longer exists, but we're playing,
594 so do nothing. Next stop will put us where
602 if (jump_to < 0 && (autoreturn & Loop) && get_play_loop()) {
603 /* don't try to handle loop play when synced to JACK */
605 if (!synced_to_engine()) {
606 Location *location = _locations->auto_loop_location();
609 jump_to = location->start();
611 if (Config->get_seamless_loop()) {
612 /* need to get track buffers reloaded */
613 set_track_loop (true);
619 if (jump_to < 0 && (autoreturn & RegionSelectionStart)) {
620 if (!_object_selection.empty()) {
621 jump_to = _object_selection.from;
625 if (jump_to < 0 && (autoreturn & LastLocate)) {
626 jump_to = _last_roll_location;
634 Session::select_playhead_priority_target (framepos_t& jump_to)
636 if (config.get_external_sync() || !config.get_auto_return()) {
640 jump_to = _last_roll_location;
647 Session::follow_playhead_priority ()
651 if (select_playhead_priority_target (target)) {
652 request_locate (target);
657 Session::non_realtime_stop (bool abort, int on_entry, bool& finished)
663 PostTransportWork ptw = post_transport_work();
668 boost::shared_ptr<RouteList> rl = routes.reader();
669 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
670 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
671 if (tr && tr->get_captured_frames () != 0) {
677 /* stop and locate are merged here because they share a lot of common stuff */
680 now = localtime (&xnow);
683 auditioner->cancel_audition ();
686 cumulative_rf_motion = 0;
690 begin_reversible_command (Operations::capture);
691 _have_captured = true;
694 DEBUG_TRACE (DEBUG::Transport, X_("Butler PTW: DS stop\n"));
696 if (abort && did_record) {
697 /* no reason to save the session file when we remove sources
699 _state_of_the_state = StateOfTheState (_state_of_the_state|InCleanup);
702 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
703 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
705 tr->transport_stopped_wallclock (*now, xnow, abort);
709 if (abort && did_record) {
710 _state_of_the_state = StateOfTheState (_state_of_the_state & ~InCleanup);
713 boost::shared_ptr<RouteList> r = routes.reader ();
715 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
716 if (!(*i)->is_auditioner()) {
717 (*i)->set_pending_declick (0);
722 commit_reversible_command ();
723 /* increase take name */
724 if (config.get_track_name_take () && !config.get_take_name ().empty()) {
725 string newname = config.get_take_name();
726 config.set_take_name(bump_name_number (newname));
730 if (_engine.running()) {
731 PostTransportWork ptw = post_transport_work ();
732 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
733 (*i)->nonrealtime_handle_transport_stopped (abort, (ptw & PostTransportLocate), (!(ptw & PostTransportLocate) || pending_locate_flush));
735 update_latency_compensation ();
738 bool const auto_return_enabled = (!config.get_external_sync() && (Config->get_auto_return_target_list() || abort));
740 if (auto_return_enabled ||
741 (ptw & PostTransportLocate) ||
742 (_requested_return_frame >= 0) ||
743 synced_to_engine()) {
745 if (pending_locate_flush) {
746 flush_all_inserts ();
749 if ((auto_return_enabled || synced_to_engine() || _requested_return_frame >= 0) &&
750 !(ptw & PostTransportLocate)) {
752 /* no explicit locate queued */
754 bool do_locate = false;
756 if (_requested_return_frame >= 0) {
758 /* explicit return request pre-queued in event list. overrides everything else */
760 _transport_frame = _requested_return_frame;
766 if (select_playhead_priority_target (jump_to)) {
768 _transport_frame = jump_to;
773 _transport_frame = _last_roll_location;
778 _requested_return_frame = -1;
781 _engine.transport_locate (_transport_frame);
789 /* do this before seeking, because otherwise the tracks will do the wrong thing in seamless loop mode.
792 if (ptw & PostTransportClearSubstate) {
794 if (!Config->get_loop_is_mode()) {
799 /* this for() block can be put inside the previous if() and has the effect of ... ??? what */
802 LocaleGuard lg; // see note for non_realtime_locate() above
803 DEBUG_TRACE (DEBUG::Transport, X_("Butler PTW: locate\n"));
804 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
805 DEBUG_TRACE (DEBUG::Transport, string_compose ("Butler PTW: locate on %1\n", (*i)->name()));
806 (*i)->non_realtime_locate (_transport_frame);
808 if (on_entry != g_atomic_int_get (&_butler->should_do_transport_work)) {
810 /* we will be back */
818 /* don't bother with this stuff if we're disconnected from the engine,
819 because there will be no process callbacks to deliver stuff from
822 if (_engine.connected() && !_engine.freewheeling()) {
823 // need to queue this in the next RT cycle
824 _send_timecode_update = true;
826 if (!dynamic_cast<MTC_Slave*>(_slave)) {
827 send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdStop));
829 /* This (::non_realtime_stop()) gets called by main
830 process thread, which will lead to confusion
831 when calling AsyncMIDIPort::write().
833 Something must be done. XXX
835 send_mmc_locate (_transport_frame);
839 if ((ptw & PostTransportLocate) && get_record_enabled()) {
840 /* This is scheduled by realtime_stop(), which is also done
841 * when a slave requests /locate/ for an initial sync.
842 * We can't hold up the slave for long with a save() here,
843 * without breaking its initial sync cycle.
845 * save state only if there's no slave or if it's not yet locked.
847 if (!_slave || !_slave->locked()) {
848 DEBUG_TRACE (DEBUG::Transport, X_("Butler PTW: requests save\n"));
849 SaveSessionRequested (_current_snapshot_name);
854 /* always try to get rid of this */
856 remove_pending_capture_state ();
858 /* save the current state of things if appropriate */
860 if (did_record && !saved) {
861 SaveSessionRequested (_current_snapshot_name);
864 if (ptw & PostTransportStop) {
866 if (!Config->get_loop_is_mode()) {
871 PositionChanged (_transport_frame); /* EMIT SIGNAL */
872 DEBUG_TRACE (DEBUG::Transport, string_compose ("send TSC with speed = %1\n", _transport_speed));
873 TransportStateChange (); /* EMIT SIGNAL */
875 /* and start it up again if relevant */
877 if ((ptw & PostTransportLocate) && !config.get_external_sync() && pending_locate_roll) {
878 request_transport_speed (1.0);
881 /* Even if we didn't do a pending locate roll this time, we don't want it hanging
882 around for next time.
884 pending_locate_roll = false;
888 Session::check_declick_out ()
890 bool locate_required = transport_sub_state & PendingLocate;
892 /* this is called after a process() iteration. if PendingDeclickOut was set,
893 it means that we were waiting to declick the output (which has just been
894 done) before maybe doing something else. this is where we do that "something else".
896 note: called from the audio thread.
899 if (transport_sub_state & PendingDeclickOut) {
901 if (locate_required) {
902 start_locate (pending_locate_frame, pending_locate_roll, pending_locate_flush);
903 transport_sub_state &= ~(PendingDeclickOut|PendingLocate);
905 if (!(transport_sub_state & StopPendingCapture)) {
906 stop_transport (pending_abort);
907 transport_sub_state &= ~(PendingDeclickOut|PendingLocate);
911 } else if (transport_sub_state & PendingLoopDeclickOut) {
912 /* Nothing else to do here; we've declicked, and the loop event will be along shortly */
913 transport_sub_state &= ~PendingLoopDeclickOut;
918 Session::unset_play_loop ()
922 clear_events (SessionEvent::AutoLoop);
923 clear_events (SessionEvent::AutoLoopDeclick);
924 set_track_loop (false);
927 if (Config->get_seamless_loop()) {
928 /* likely need to flush track buffers: this will locate us to wherever we are */
929 add_post_transport_work (PostTransportLocate);
930 _butler->schedule_transport_work ();
936 Session::set_track_loop (bool yn)
938 Location* loc = _locations->auto_loop_location ();
944 boost::shared_ptr<RouteList> rl = routes.reader ();
946 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
947 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
948 if (tr && !tr->hidden()) {
949 tr->set_loop (yn ? loc : 0);
955 Session::set_play_loop (bool yn, double speed)
957 /* Called from event-handling context */
961 if (yn == play_loop || (actively_recording() && yn) || (loc = _locations->auto_loop_location()) == 0) {
962 /* nothing to do, or can't change loop status while recording */
966 if (yn && Config->get_seamless_loop() && synced_to_engine()) {
967 warning << string_compose (
968 _("Seamless looping cannot be supported while %1 is using JACK transport.\n"
969 "Recommend changing the configured options"), PROGRAM_NAME)
983 if (Config->get_seamless_loop()) {
984 if (!Config->get_loop_is_mode()) {
985 /* set all tracks to use internal looping */
986 set_track_loop (true);
988 /* we will do this in the locate to the start OR when we hit the end
989 * of the loop for the first time
993 /* set all tracks to NOT use internal looping */
994 set_track_loop (false);
997 /* Put the delick and loop events in into the event list. The declick event will
998 cause a de-clicking fade-out just before the end of the loop, and it will also result
999 in a fade-in when the loop restarts. The AutoLoop event will peform the actual loop.
1004 auto_loop_declick_range (loc, dcp, dcl);
1005 merge_event (new SessionEvent (SessionEvent::AutoLoopDeclick, SessionEvent::Replace, dcp, dcl, 0.0f));
1006 merge_event (new SessionEvent (SessionEvent::AutoLoop, SessionEvent::Replace, loc->end(), loc->start(), 0.0f));
1008 /* if requested to roll, locate to start of loop and
1009 * roll but ONLY if we're not already rolling.
1011 args: positition, roll=true, flush=true, with_loop=false, force buffer refill if seamless looping
1014 if (Config->get_loop_is_mode()) {
1015 /* loop IS a transport mode: if already
1016 rolling, do not locate to loop start.
1018 if (!transport_rolling() && (speed != 0.0)) {
1019 start_locate (loc->start(), true, true, false, true);
1023 start_locate (loc->start(), true, true, false, true);
1033 DEBUG_TRACE (DEBUG::Transport, string_compose ("send TSC2 with speed = %1\n", _transport_speed));
1034 TransportStateChange ();
1037 Session::flush_all_inserts ()
1039 boost::shared_ptr<RouteList> r = routes.reader ();
1041 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
1042 (*i)->flush_processors ();
1047 Session::start_locate (framepos_t target_frame, bool with_roll, bool with_flush, bool for_loop_enabled, bool force)
1049 if (target_frame < 0) {
1050 error << _("Locate called for negative sample position - ignored") << endmsg;
1054 if (synced_to_engine()) {
1059 _slave->speed_and_position (sp, pos);
1061 if (target_frame != pos) {
1063 if (config.get_jack_time_master()) {
1064 /* actually locate now, since otherwise jack_timebase_callback
1065 will use the incorrect _transport_frame and report an old
1066 and incorrect time to Jack transport
1068 locate (target_frame, with_roll, with_flush, for_loop_enabled, force);
1071 /* tell JACK to change transport position, and we will
1072 follow along later in ::follow_slave()
1075 _engine.transport_locate (target_frame);
1077 if (sp != 1.0f && with_roll) {
1078 _engine.transport_start ();
1084 locate (target_frame, with_roll, with_flush, for_loop_enabled, force);
1089 Session::micro_locate (framecnt_t distance)
1091 boost::shared_ptr<RouteList> rl = routes.reader();
1092 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
1093 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
1094 if (tr && !tr->can_internal_playback_seek (distance)) {
1099 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
1100 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
1102 tr->internal_playback_seek (distance);
1106 _transport_frame += distance;
1110 /** @param with_mmc true to send a MMC locate command when the locate is done */
1112 Session::locate (framepos_t target_frame, bool with_roll, bool with_flush, bool for_loop_enabled, bool force, bool with_mmc)
1114 bool need_butler = false;
1116 /* Locates for seamless looping are fairly different from other
1117 * locates. They assume that the diskstream buffers for each track
1118 * already have the correct data in them, and thus there is no need to
1119 * actually tell the tracks to locate. What does need to be done,
1120 * though, is all the housekeeping that is associated with non-linear
1121 * changes in the value of _transport_frame.
1124 DEBUG_TRACE (DEBUG::Transport, string_compose ("rt-locate to %1, roll %2 flush %3 loop-enabled %4 force %5 mmc %6\n",
1125 target_frame, with_roll, with_flush, for_loop_enabled, force, with_mmc));
1127 if (!force && _transport_frame == target_frame && !loop_changing && !for_loop_enabled) {
1129 /* already at the desired position. Not forced to locate,
1130 the loop isn't changing, so unless we're told to
1131 start rolling also, there's nothing to do but
1132 tell the world where we are (again).
1136 set_transport_speed (1.0, 0, false);
1138 loop_changing = false;
1139 Located (); /* EMIT SIGNAL */
1143 if (_transport_speed && !(for_loop_enabled && Config->get_seamless_loop())) {
1144 /* Schedule a declick. We'll be called again when its done.
1145 We only do it this way for ordinary locates, not those
1146 due to **seamless** loops.
1149 if (!(transport_sub_state & PendingDeclickOut)) {
1150 transport_sub_state |= (PendingDeclickOut|PendingLocate);
1151 pending_locate_frame = target_frame;
1152 pending_locate_roll = with_roll;
1153 pending_locate_flush = with_flush;
1158 // Update Timecode time
1159 // [DR] FIXME: find out exactly where this should go below
1160 _transport_frame = target_frame;
1161 _last_roll_or_reversal_location = target_frame;
1162 timecode_time(_transport_frame, transmitting_timecode_time);
1163 outbound_mtc_timecode_frame = _transport_frame;
1164 next_quarter_frame_to_send = 0;
1166 /* do "stopped" stuff if:
1168 * we are rolling AND
1169 * no autoplay in effect AND
1170 * we're not going to keep rolling after the locate AND
1171 * !(playing a loop with JACK sync)
1175 bool transport_was_stopped = !transport_rolling();
1177 if (!transport_was_stopped && (!auto_play_legal || !config.get_auto_play()) && !with_roll && !(synced_to_engine() && play_loop) &&
1178 (!Profile->get_trx() || !(config.get_external_sync() && !synced_to_engine()))) {
1179 realtime_stop (false, true); // XXX paul - check if the 2nd arg is really correct
1180 transport_was_stopped = true;
1182 /* otherwise tell the world that we located */
1186 if (force || !for_loop_enabled || loop_changing) {
1188 PostTransportWork todo = PostTransportLocate;
1190 if (with_roll && transport_was_stopped) {
1191 todo = PostTransportWork (todo | PostTransportRoll);
1194 add_post_transport_work (todo);
1199 /* this is functionally what clear_clicks() does but with a tentative lock */
1201 Glib::Threads::RWLock::WriterLock clickm (click_lock, Glib::Threads::TRY_LOCK);
1203 if (clickm.locked()) {
1205 for (Clicks::iterator i = clicks.begin(); i != clicks.end(); ++i) {
1214 /* switch from input if we're going to roll */
1215 if (Config->get_monitoring_model() == HardwareMonitoring) {
1216 set_track_monitor_input_status (!config.get_auto_input());
1219 /* otherwise we're going to stop, so do the opposite */
1220 if (Config->get_monitoring_model() == HardwareMonitoring) {
1221 set_track_monitor_input_status (true);
1225 /* cancel looped playback if transport pos outside of loop range */
1228 Location* al = _locations->auto_loop_location();
1231 if (_transport_frame < al->start() || _transport_frame >= al->end()) {
1233 // located outside the loop: cancel looping directly, this is called from event handling context
1235 have_looped = false;
1237 if (!Config->get_loop_is_mode()) {
1238 set_play_loop (false, _transport_speed);
1240 if (Config->get_seamless_loop()) {
1241 /* this will make the non_realtime_locate() in the butler
1242 which then causes seek() in tracks actually do the right
1245 set_track_loop (false);
1249 } else if (_transport_frame == al->start()) {
1251 // located to start of loop - this is looping, basically
1255 if (_last_roll_location != al->start()) {
1256 /* didn't start at loop start - playback must have
1257 * started before loop since we've now hit the loop
1260 add_post_transport_work (PostTransportLocate);
1266 boost::shared_ptr<RouteList> rl = routes.reader();
1268 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
1269 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
1271 if (tr && tr->record_enabled ()) {
1272 // tell it we've looped, so it can deal with the record state
1273 tr->transport_looped (_transport_frame);
1278 TransportLooped(); // EMIT SIGNAL
1284 _butler->schedule_transport_work ();
1287 loop_changing = false;
1289 _send_timecode_update = true;
1292 send_mmc_locate (_transport_frame);
1295 _last_roll_location = _last_roll_or_reversal_location = _transport_frame;
1296 Located (); /* EMIT SIGNAL */
1299 /** Set the transport speed.
1300 * Called from the process thread.
1301 * @param speed New speed
1304 Session::set_transport_speed (double speed, framepos_t destination_frame, bool abort, bool clear_state, bool as_default)
1306 DEBUG_TRACE (DEBUG::Transport, string_compose ("@ %5 Set transport speed to %1, abort = %2 clear_state = %3, current = %4 as_default %6\n",
1307 speed, abort, clear_state, _transport_speed, _transport_frame, as_default));
1309 if (_transport_speed == speed) {
1310 if (as_default && speed == 0.0) { // => reset default transport speed. hacky or what?
1311 _default_transport_speed = 1.0;
1316 if (actively_recording() && speed != 1.0 && speed != 0.0) {
1317 /* no varispeed during recording */
1318 DEBUG_TRACE (DEBUG::Transport, string_compose ("No varispeed during recording cur_speed %1, frame %2\n",
1319 _transport_speed, _transport_frame));
1323 _target_transport_speed = fabs(speed);
1325 /* 8.0 max speed is somewhat arbitrary but based on guestimates regarding disk i/o capability
1326 and user needs. We really need CD-style "skip" playback for ffwd and rewind.
1330 speed = min (8.0, speed);
1331 } else if (speed < 0) {
1332 speed = max (-8.0, speed);
1335 if (transport_rolling() && speed == 0.0) {
1337 /* we are rolling and we want to stop */
1339 if (Config->get_monitoring_model() == HardwareMonitoring) {
1340 set_track_monitor_input_status (true);
1343 if (synced_to_engine ()) {
1345 /* do this here because our response to the slave won't
1348 _play_range = false;
1351 _engine.transport_stop ();
1353 bool const auto_return_enabled = (!config.get_external_sync() && (Config->get_auto_return_target_list() || abort));
1355 if (!auto_return_enabled) {
1356 _requested_return_frame = destination_frame;
1359 stop_transport (abort);
1362 } else if (transport_stopped() && speed == 1.0) {
1364 _default_transport_speed = speed;
1366 /* we are stopped and we want to start rolling at speed 1 */
1368 if (Config->get_loop_is_mode() && play_loop) {
1370 Location *location = _locations->auto_loop_location();
1372 if (location != 0) {
1373 if (_transport_frame != location->start()) {
1375 if (Config->get_seamless_loop()) {
1376 /* force tracks to do their thing */
1377 set_track_loop (true);
1380 /* jump to start and then roll from there */
1382 request_locate (location->start(), true);
1388 if (Config->get_monitoring_model() == HardwareMonitoring && config.get_auto_input()) {
1389 set_track_monitor_input_status (false);
1392 if (synced_to_engine()) {
1393 _engine.transport_start ();
1400 /* not zero, not 1.0 ... varispeed */
1402 if ((synced_to_engine()) && speed != 0.0 && speed != 1.0) {
1403 warning << string_compose (
1404 _("Global varispeed cannot be supported while %1 is connected to JACK transport control"),
1410 if (actively_recording()) {
1414 if (speed > 0.0 && _transport_frame == current_end_frame()) {
1418 if (speed < 0.0 && _transport_frame == 0) {
1424 /* if we are reversing relative to the current speed, or relative to the speed
1425 before the last stop, then we have to do extra work.
1428 PostTransportWork todo = PostTransportWork (0);
1430 if ((_transport_speed && speed * _transport_speed < 0.0) || (_last_transport_speed * speed < 0.0) || (_last_transport_speed == 0.0 && speed < 0.0)) {
1431 todo = PostTransportWork (todo | PostTransportReverse);
1432 _last_roll_or_reversal_location = _transport_frame;
1435 _last_transport_speed = _transport_speed;
1436 _transport_speed = speed;
1439 _default_transport_speed = speed;
1442 boost::shared_ptr<RouteList> rl = routes.reader();
1443 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
1444 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
1445 if (tr && tr->realtime_set_speed (tr->speed(), true)) {
1446 todo = PostTransportWork (todo | PostTransportSpeed);
1451 add_post_transport_work (todo);
1452 _butler->schedule_transport_work ();
1455 DEBUG_TRACE (DEBUG::Transport, string_compose ("send TSC3 with speed = %1\n", _transport_speed));
1457 /* throttle signal emissions.
1458 * when slaved [_last]_transport_speed
1459 * usually changes every cycle (tiny amounts due to DLL).
1460 * Emitting a signal every cycle is overkill and unwarranted.
1462 * Using _last_transport_speed is not acceptable,
1463 * since it allows for large changes over a long period
1464 * of time. Hence we introduce a dedicated variable to keep track
1466 * The 0.2% dead-zone is somewhat arbitrary. Main use-case
1467 * for TransportStateChange() here is the ShuttleControl display.
1469 if (fabs (_signalled_varispeed - speed) > .002
1470 // still, signal hard changes to 1.0 and 0.0:
1471 || ( speed == 1.0 && _signalled_varispeed != 1.0)
1472 || ( speed == 0.0 && _signalled_varispeed != 0.0)
1475 TransportStateChange (); /* EMIT SIGNAL */
1476 _signalled_varispeed = speed;
1482 /** Stop the transport. */
1484 Session::stop_transport (bool abort, bool clear_state)
1486 if (_transport_speed == 0.0f) {
1490 DEBUG_TRACE (DEBUG::Transport, string_compose ("stop_transport, declick required? %1\n", get_transport_declick_required()));
1492 if (!get_transport_declick_required()) {
1494 /* stop has not yet been scheduled */
1496 boost::shared_ptr<RouteList> rl = routes.reader();
1497 framepos_t stop_target = audible_frame();
1499 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
1500 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
1502 tr->prepare_to_stop (_transport_frame, stop_target);
1508 if (actively_recording() && /* we are recording */
1509 worst_input_latency() > current_block_size) { /* input latency exceeds block size, so simple 1 cycle delay before stop is not enough */
1511 /* we need to capture the audio that is still somewhere in the pipeline between
1512 wherever it was generated and the process callback. This means that even though
1513 the user (or something else) has asked us to stop, we have to roll
1514 past this point and then reset the playhead/transport location to
1515 the position at which the stop was requested.
1517 we still need playback to "stop" now, however, which is why we schedule
1521 DEBUG_TRACE (DEBUG::Transport, string_compose ("stop transport requested @ %1, scheduled for + %2 = %3, abort = %4\n",
1522 _transport_frame, _worst_input_latency,
1523 _transport_frame + _worst_input_latency,
1526 SessionEvent *ev = new SessionEvent (SessionEvent::StopOnce, SessionEvent::Replace,
1527 _transport_frame + _worst_input_latency,
1532 /* request a declick at the start of the next process cycle() so that playback ceases.
1533 It will remain silent until we actually stop (at the StopOnce event somewhere in
1534 the future). The extra flag (StopPendingCapture) is set to ensure that check_declick_out()
1535 does not stop the transport too early.
1537 new_bits = SubState (PendingDeclickOut|StopPendingCapture);
1541 /* Not recording, schedule a declick in the next process() cycle and then stop at its end */
1543 new_bits = PendingDeclickOut;
1544 DEBUG_TRACE (DEBUG::Transport, string_compose ("stop scheduled for next process cycle @ %1\n", _transport_frame));
1547 /* we'll be called again after the declick */
1548 transport_sub_state = SubState (transport_sub_state|new_bits);
1549 pending_abort = abort;
1555 DEBUG_TRACE (DEBUG::Transport, "time to actually stop\n");
1557 /* declick was scheduled, but we've been called again, which means it is really time to stop
1559 XXX: we should probably split this off into its own method and call it explicitly.
1562 realtime_stop (abort, clear_state);
1563 _butler->schedule_transport_work ();
1567 /** Called from the process thread */
1569 Session::start_transport ()
1571 DEBUG_TRACE (DEBUG::Transport, "start_transport\n");
1573 _last_roll_location = _transport_frame;
1574 _last_roll_or_reversal_location = _transport_frame;
1576 have_looped = false;
1578 /* if record status is Enabled, move it to Recording. if its
1579 already Recording, move it to Disabled.
1582 switch (record_status()) {
1584 if (!config.get_punch_in()) {
1591 disable_record (false);
1599 transport_sub_state |= PendingDeclickIn;
1601 _transport_speed = _default_transport_speed;
1602 _target_transport_speed = _transport_speed;
1604 boost::shared_ptr<RouteList> rl = routes.reader();
1605 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
1606 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
1608 tr->realtime_set_speed (tr->speed(), true);
1612 if (!_engine.freewheeling()) {
1613 Timecode::Time time;
1614 timecode_time_subframes (_transport_frame, time);
1615 if (!dynamic_cast<MTC_Slave*>(_slave)) {
1616 send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdDeferredPlay));
1620 DEBUG_TRACE (DEBUG::Transport, string_compose ("send TSC4 with speed = %1\n", _transport_speed));
1621 TransportStateChange (); /* EMIT SIGNAL */
1624 /** Do any transport work in the audio thread that needs to be done after the
1625 * transport thread is finished. Audio thread, realtime safe.
1628 Session::post_transport ()
1630 PostTransportWork ptw = post_transport_work ();
1632 if (ptw & PostTransportAudition) {
1633 if (auditioner && auditioner->auditioning()) {
1634 process_function = &Session::process_audition;
1636 process_function = &Session::process_with_events;
1640 if (ptw & PostTransportStop) {
1642 transport_sub_state = 0;
1645 if (ptw & PostTransportLocate) {
1647 if (((!config.get_external_sync() && (auto_play_legal && config.get_auto_play())) && !_exporting) || (ptw & PostTransportRoll)) {
1650 transport_sub_state = 0;
1655 /* XXX is this really safe? shouldn't we just be unsetting the bits that we actually
1658 set_post_transport_work (PostTransportWork (0));
1662 Session::reset_rf_scale (framecnt_t motion)
1664 cumulative_rf_motion += motion;
1666 if (cumulative_rf_motion < 4 * _current_frame_rate) {
1668 } else if (cumulative_rf_motion < 8 * _current_frame_rate) {
1670 } else if (cumulative_rf_motion < 16 * _current_frame_rate) {
1682 Session::mtc_status_changed (bool yn)
1684 g_atomic_int_set (&_mtc_active, yn);
1685 MTCSyncStateChanged( yn );
1689 Session::ltc_status_changed (bool yn)
1691 g_atomic_int_set (&_ltc_active, yn);
1692 LTCSyncStateChanged( yn );
1696 Session::use_sync_source (Slave* new_slave)
1698 /* Runs in process() context */
1700 bool non_rt_required = false;
1702 /* XXX this deletion is problematic because we're in RT context */
1707 MTC_Slave* mtc_slave = dynamic_cast<MTC_Slave*>(_slave);
1709 mtc_slave->ActiveChanged.connect_same_thread (mtc_status_connection, boost::bind (&Session::mtc_status_changed, this, _1));
1710 MTCSyncStateChanged(mtc_slave->locked() );
1712 if (g_atomic_int_get (&_mtc_active) ){
1713 g_atomic_int_set (&_mtc_active, 0);
1714 MTCSyncStateChanged( false );
1716 mtc_status_connection.disconnect ();
1719 LTC_Slave* ltc_slave = dynamic_cast<LTC_Slave*> (_slave);
1721 ltc_slave->ActiveChanged.connect_same_thread (ltc_status_connection, boost::bind (&Session::ltc_status_changed, this, _1));
1722 LTCSyncStateChanged (ltc_slave->locked() );
1724 if (g_atomic_int_get (&_ltc_active) ){
1725 g_atomic_int_set (&_ltc_active, 0);
1726 LTCSyncStateChanged( false );
1728 ltc_status_connection.disconnect ();
1731 DEBUG_TRACE (DEBUG::Slave, string_compose ("set new slave to %1\n", _slave));
1733 // need to queue this for next process() cycle
1734 _send_timecode_update = true;
1736 boost::shared_ptr<RouteList> rl = routes.reader();
1737 for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
1738 boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
1739 if (tr && !tr->hidden()) {
1740 if (tr->realtime_set_speed (tr->speed(), true)) {
1741 non_rt_required = true;
1743 tr->set_slaved (_slave != 0);
1747 if (non_rt_required) {
1748 add_post_transport_work (PostTransportSpeed);
1749 _butler->schedule_transport_work ();
1756 Session::drop_sync_source ()
1758 request_sync_source (0);
1762 Session::switch_to_sync_source (SyncSource src)
1766 DEBUG_TRACE (DEBUG::Slave, string_compose ("Setting up sync source %1\n", enum_2_string (src)));
1770 if (_slave && dynamic_cast<MTC_Slave*>(_slave)) {
1775 new_slave = new MTC_Slave (*this, *_midi_ports->mtc_input_port());
1778 catch (failed_constructor& err) {
1784 if (_slave && dynamic_cast<LTC_Slave*>(_slave)) {
1789 new_slave = new LTC_Slave (*this);
1792 catch (failed_constructor& err) {
1799 if (_slave && dynamic_cast<MIDIClock_Slave*>(_slave)) {
1804 new_slave = new MIDIClock_Slave (*this, *_midi_ports->midi_clock_input_port(), 24);
1807 catch (failed_constructor& err) {
1813 if (_slave && dynamic_cast<Engine_Slave*>(_slave)) {
1817 if (config.get_video_pullup() != 0.0f) {
1821 new_slave = new Engine_Slave (*AudioEngine::instance());
1829 request_sync_source (new_slave);
1833 Session::set_track_speed (Track* track, double speed)
1835 if (track->realtime_set_speed (speed, false)) {
1836 add_post_transport_work (PostTransportSpeed);
1837 _butler->schedule_transport_work ();
1843 Session::unset_play_range ()
1845 _play_range = false;
1846 _clear_event_type (SessionEvent::RangeStop);
1847 _clear_event_type (SessionEvent::RangeLocate);
1851 Session::set_play_range (list<AudioRange>& range, bool leave_rolling)
1855 /* Called from event-processing context */
1857 unset_play_range ();
1859 if (range.empty()) {
1860 /* _play_range set to false in unset_play_range()
1862 if (!leave_rolling) {
1863 /* stop transport */
1864 SessionEvent* ev = new SessionEvent (SessionEvent::SetTransportSpeed, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0f, false);
1872 /* cancel loop play */
1875 list<AudioRange>::size_type sz = range.size();
1879 list<AudioRange>::iterator i = range.begin();
1880 list<AudioRange>::iterator next;
1882 while (i != range.end()) {
1887 /* locating/stopping is subject to delays for declicking.
1890 framepos_t requested_frame = i->end;
1892 if (requested_frame > current_block_size) {
1893 requested_frame -= current_block_size;
1895 requested_frame = 0;
1898 if (next == range.end()) {
1899 ev = new SessionEvent (SessionEvent::RangeStop, SessionEvent::Add, requested_frame, 0, 0.0f);
1901 ev = new SessionEvent (SessionEvent::RangeLocate, SessionEvent::Add, requested_frame, (*next).start, 0.0f);
1909 } else if (sz == 1) {
1911 ev = new SessionEvent (SessionEvent::RangeStop, SessionEvent::Add, range.front().end, 0, 0.0f);
1916 /* save range so we can do auto-return etc. */
1918 current_audio_range = range;
1920 /* now start rolling at the right place */
1922 ev = new SessionEvent (SessionEvent::LocateRoll, SessionEvent::Add, SessionEvent::Immediate, range.front().start, 0.0f, false);
1925 DEBUG_TRACE (DEBUG::Transport, string_compose ("send TSC5 with speed = %1\n", _transport_speed));
1926 TransportStateChange ();
1930 Session::request_bounded_roll (framepos_t start, framepos_t end)
1932 AudioRange ar (start, end, 0);
1933 list<AudioRange> lar;
1936 request_play_range (&lar, true);
1940 Session::set_requested_return_frame (framepos_t return_to)
1942 _requested_return_frame = return_to;
1946 Session::request_roll_at_and_return (framepos_t start, framepos_t return_to)
1948 SessionEvent *ev = new SessionEvent (SessionEvent::LocateRollLocate, SessionEvent::Add, SessionEvent::Immediate, return_to, 1.0);
1949 ev->target2_frame = start;
1954 Session::engine_halted ()
1958 /* there will be no more calls to process(), so
1959 we'd better clean up for ourselves, right now.
1961 but first, make sure the butler is out of
1969 realtime_stop (false, true);
1970 non_realtime_stop (false, 0, ignored);
1971 transport_sub_state = 0;
1973 DEBUG_TRACE (DEBUG::Transport, string_compose ("send TSC6 with speed = %1\n", _transport_speed));
1974 TransportStateChange (); /* EMIT SIGNAL */
1979 Session::xrun_recovery ()
1983 Xrun (_transport_frame); /* EMIT SIGNAL */
1985 if (Config->get_stop_recording_on_xrun() && actively_recording()) {
1987 /* it didn't actually halt, but we need
1988 to handle things in the same way.
1996 Session::route_processors_changed (RouteProcessorChange c)
1998 if (ignore_route_processor_changes) {
2002 if (c.type == RouteProcessorChange::MeterPointChange) {
2007 if (c.type == RouteProcessorChange::RealTimeChange) {
2012 update_latency_compensation ();
2019 Session::allow_auto_play (bool yn)
2021 auto_play_legal = yn;
2025 Session::maybe_stop (framepos_t limit)
2027 if ((_transport_speed > 0.0f && _transport_frame >= limit) || (_transport_speed < 0.0f && _transport_frame == 0)) {
2028 if (synced_to_engine () && config.get_jack_time_master ()) {
2029 _engine.transport_stop ();
2030 } else if (!synced_to_engine ()) {
2039 Session::send_mmc_locate (framepos_t t)
2045 if (!_engine.freewheeling()) {
2046 Timecode::Time time;
2047 timecode_time_subframes (t, time);
2048 send_immediate_mmc (MIDI::MachineControlCommand (time));
2052 /** Ask the transport to not send timecode until further notice. The suspension
2053 * will come into effect some finite time after this call, and timecode_transmission_suspended()
2054 * should be checked by the caller to find out when.
2057 Session::request_suspend_timecode_transmission ()
2059 SessionEvent* ev = new SessionEvent (SessionEvent::SetTimecodeTransmission, SessionEvent::Add, SessionEvent::Immediate, 0, 0, false);
2064 Session::request_resume_timecode_transmission ()
2066 SessionEvent* ev = new SessionEvent (SessionEvent::SetTimecodeTransmission, SessionEvent::Add, SessionEvent::Immediate, 0, 0, true);
2071 Session::timecode_transmission_suspended () const
2073 return g_atomic_int_get (&_suspend_timecode_transmission) == 1;