diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h index 32d31ac231..1ec1f06af5 100644 --- a/libs/ardour/ardour/route.h +++ b/libs/ardour/ardour/route.h @@ -205,7 +205,7 @@ public: void set_disk_io_point (DiskIOPoint); DiskIOPoint disk_io_point() const { return _disk_io_point; } - void stop_trigger(bool now); + void stop_triggers (bool now); /* Processors */ diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 21fd024669..5d7821cd72 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -486,7 +486,6 @@ public: void reset_transport_speed (TransportRequestSource origin = TRS_UI); void start_transport_from_trigger (); - void stop_transport_from_trigger (); void stop_all_triggers (bool now = true); @@ -1435,7 +1434,6 @@ private: bool _was_seamless; bool _under_nsm_control; unsigned int _xrun_count; - bool transport_started_by_trigger; std::string _missing_file_replacement; diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index 87a5138b12..6601f25a26 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -502,7 +502,8 @@ class LIBARDOUR_API TriggerBox : public Processor DataType data_type() const { return _data_type; } - void request_stop_all (); + void stop_all_immediately (); + void stop_all_quantized (); TriggerPtr currently_playing() const { return _currently_playing; } @@ -644,7 +645,6 @@ class LIBARDOUR_API TriggerBox : public Processor static void init_pool(); static std::atomic active_trigger_boxes; - static PBD::Signal0 StopAllTriggers; }; namespace Properties { diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index e51c687bfd..e165580cad 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -1729,10 +1729,16 @@ Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* } void -Route::stop_trigger (bool now) +Route::stop_triggers (bool now) { if (_triggerbox) { - _triggerbox->request_stop_all(); //ToDo: stop now or at end of quant? + if (now) { + std::cerr << "stop immedaitely\n"; + _triggerbox->stop_all_immediately (); + } else { + std::cerr << "stop quantized\n"; + _triggerbox->stop_all_quantized(); + } } } @@ -3686,6 +3692,8 @@ Route::realtime_handle_transport_stopped () for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) { (*i)->realtime_handle_transport_stopped (); } + + stop_triggers (true); } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 81ec82af3a..aea4582de1 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -215,7 +215,6 @@ Session::Session (AudioEngine &eng, , _writable (false) , _under_nsm_control (false) , _xrun_count (0) - , transport_started_by_trigger (false) , master_wait_end (0) , post_export_sync (false) , post_export_position (0) diff --git a/libs/ardour/session_process.cc b/libs/ardour/session_process.cc index ce2bbcfc0e..f460fd3428 100644 --- a/libs/ardour/session_process.cc +++ b/libs/ardour/session_process.cc @@ -954,11 +954,7 @@ Session::process_event (SessionEvent* ev) break; case SessionEvent::EndRoll: - if (transport_started_by_trigger) { - TriggerBox::start_transport_stop (*this); - } else { - TFSM_STOP (ev->yes_or_no, ev->second_yes_or_no); - } + TFSM_STOP (ev->yes_or_no, ev->second_yes_or_no); break; case SessionEvent::SetTransportMaster: diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index 264e117cff..cf89007693 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -438,7 +438,7 @@ Session::stop_all_triggers (bool now) { boost::shared_ptr rl = routes.reader(); for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) { - (*i)->stop_trigger(now); + (*i)->stop_triggers (now); } } @@ -460,19 +460,10 @@ Session::stop_transport (bool abort, bool clear_state) void Session::start_transport_from_trigger () { - transport_started_by_trigger = true; ENSURE_PROCESS_THREAD; TFSM_ROLL(); } -/** Called from the process thread */ -void -Session::stop_transport_from_trigger () -{ - ENSURE_PROCESS_THREAD; - TFSM_STOP (false, false); -} - /** Called from the process thread */ void Session::start_transport (bool after_loop) diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 47e4d3b76d..64fcf8472a 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -500,7 +500,7 @@ Trigger::maybe_compute_next_transition (samplepos_t start_sample, Temporal::Beat if (q < Temporal::BBT_Offset (0, 0, 0)) { /* negative quantization == do not quantize */ - std::cerr << "negative quant, start right now\n"; + transition_samples = start_sample; transition_beats = start; transition_time = timepos_t (start); @@ -1726,7 +1726,6 @@ std::atomic TriggerBox::_pending_scene (-1); std::atomic TriggerBox::_active_scene (-1); std::atomic TriggerBox::active_trigger_boxes (0); TriggerBoxThread* TriggerBox::worker = 0; -PBD::Signal0 TriggerBox::StopAllTriggers; void TriggerBox::init () @@ -1736,16 +1735,6 @@ TriggerBox::init () init_pool (); } -void -TriggerBox::start_transport_stop (Session& s) -{ - if (active_trigger_boxes.load ()) { - StopAllTriggers(); /* EMIT SIGNAL */ - } else { - s.stop_transport_from_trigger (); - } -} - TriggerBox::TriggerBox (Session& s, DataType dt) : Processor (s, _("TriggerBox"), Temporal::BeatTime) , _data_type (dt) @@ -1775,8 +1764,6 @@ TriggerBox::TriggerBox (Session& s, DataType dt) } Config->ParameterChanged.connect_same_thread (*this, boost::bind (&TriggerBox::parameter_changed, this, _1)); - - StopAllTriggers.connect_same_thread (stop_all_connection, boost::bind (&TriggerBox::request_stop_all, this)); } void @@ -1975,7 +1962,7 @@ TriggerBox::~TriggerBox () } void -TriggerBox::request_stop_all () +TriggerBox::stop_all_immediately () { _requests.stop_all = true; } @@ -2015,6 +2002,8 @@ TriggerBox::set_all_quantization (Temporal::BBT_Offset const& q) void TriggerBox::stop_all () { + /* Stops all triggers as soon as possible */ + /* XXX needs to be done with mutex or via thread-safe queue */ DEBUG_TRACE (DEBUG::Triggers, "stop-all request received\n"); @@ -2028,6 +2017,14 @@ TriggerBox::stop_all () explicit_queue.reset (); } +void +TriggerBox::stop_all_quantized () +{ + for (uint32_t n = 0; n < all_triggers.size(); ++n) { + all_triggers[n]->unbang (); + } +} + void TriggerBox::drop_triggers () { @@ -2323,7 +2320,7 @@ TriggerBox::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp /* transport must be active for triggers */ - if (!_session.transport_state_rolling()) { + if (!_session.transport_state_rolling() && !allstop) { _session.start_transport_from_trigger (); } @@ -2497,10 +2494,6 @@ TriggerBox::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp if (!_currently_playing) { DEBUG_TRACE (DEBUG::Triggers, "nothing currently playing, consider stopping transport\n"); _stop_all = false; - if (active_trigger_boxes.fetch_sub (1) == 1) { - /* last active trigger box */ - _session.stop_transport_from_trigger (); - } } /* audio buffer (channel) count determined by max of input and