triggerbox: remove Playout as a possible state and use a separate bool

A trigger can be in a playout state when we decide to change its
state to WaitingToStop (e.g. due to a cue marker). This design
leaves the playout condition "in effect" despite the state changing.
This commit is contained in:
Paul Davis 2022-02-18 12:49:15 -07:00
parent fbbe74a530
commit 4b7c0448e4
2 changed files with 26 additions and 35 deletions

View file

@ -102,10 +102,6 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
* have transitioned to Stopped. * have transitioned to Stopped.
*/ */
Stopping, Stopping,
/* a Trigger in this state has played all of its data and is
* now silent-filling until we reach the "true end" of the trigger
*/
Playout,
}; };
enum LaunchStyle { enum LaunchStyle {
@ -379,6 +375,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
TriggerBox& _box; TriggerBox& _box;
UIRequests _requests; UIRequests _requests;
State _state; State _state;
bool _playout;
std::atomic<int> _bang; std::atomic<int> _bang;
std::atomic<int> _unbang; std::atomic<int> _unbang;
uint32_t _index; uint32_t _index;

View file

@ -172,6 +172,7 @@ Trigger::Trigger (uint32_t n, TriggerBox& b)
, final_processed_sample (0) , final_processed_sample (0)
, _box (b) , _box (b)
, _state (Stopped) , _state (Stopped)
, _playout (false)
, _bang (0) , _bang (0)
, _unbang (0) , _unbang (0)
, _index (n) , _index (n)
@ -608,6 +609,7 @@ void
Trigger::retrigger () Trigger::retrigger ()
{ {
process_index = 0; process_index = 0;
_playout = false;
} }
void void
@ -628,6 +630,7 @@ void
Trigger::_startup (BufferSet& bufs, pframes_t dest_offset, Temporal::BBT_Offset const & start_quantization) Trigger::_startup (BufferSet& bufs, pframes_t dest_offset, Temporal::BBT_Offset const & start_quantization)
{ {
_state = WaitingToStart; _state = WaitingToStart;
_playout = false;
_loop_cnt = 0; _loop_cnt = 0;
_velocity_gain = _pending_velocity_gain; _velocity_gain = _pending_velocity_gain;
_explicitly_stopped = false; _explicitly_stopped = false;
@ -649,6 +652,7 @@ void
Trigger::shutdown (BufferSet& bufs, pframes_t dest_offset) Trigger::shutdown (BufferSet& bufs, pframes_t dest_offset)
{ {
_state = Stopped; _state = Stopped;
_playout = false;
_cue_launched = false; _cue_launched = false;
_pending_velocity_gain = _velocity_gain = 1.0; _pending_velocity_gain = _velocity_gain = 1.0;
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 shuts down\n", name())); DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 shuts down\n", name()));
@ -724,7 +728,6 @@ Trigger::process_state_requests (BufferSet& bufs, pframes_t dest_offset)
switch (_state) { switch (_state) {
case Running: case Running:
case Playout:
switch (launch_style()) { switch (launch_style()) {
case OneShot: case OneShot:
/* do nothing, just let it keep playing */ /* do nothing, just let it keep playing */
@ -769,7 +772,6 @@ Trigger::process_state_requests (BufferSet& bufs, pframes_t dest_offset)
switch (_state) { switch (_state) {
case Running: case Running:
case Playout:
begin_stop (true); begin_stop (true);
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 unbanged, now in WaitingToStop\n", index())); DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 unbanged, now in WaitingToStop\n", index()));
break; break;
@ -859,7 +861,7 @@ Trigger::compute_next_transition (samplepos_t start_sample, Temporal::Beats cons
/* In these states, we are not waiting for a transition */ /* In these states, we are not waiting for a transition */
if (_state == Stopped || _state == Running || _state == Stopping || _state == Playout) { if (_state == Stopped || _state == Running || _state == Stopping) {
/* no transition */ /* no transition */
return 0; return 0;
} }
@ -908,7 +910,7 @@ Trigger::maybe_compute_next_transition (samplepos_t start_sample, Temporal::Beat
/* In these states, we are not waiting for a transition */ /* In these states, we are not waiting for a transition */
if (_state == Running || _state == Stopping || _state == Playout) { if ((_state == Running) || (_state == Stopping)) {
/* will cover everything */ /* will cover everything */
return; return;
} }
@ -1680,7 +1682,6 @@ AudioTrigger::audio_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t
/* did everything we could do */ /* did everything we could do */
return nframes; return nframes;
case Running: case Running:
case Playout:
case WaitingToStop: case WaitingToStop:
case Stopping: case Stopping:
/* stuff to do */ /* stuff to do */
@ -1709,7 +1710,7 @@ AudioTrigger::audio_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t
/* tell the stretcher what we are doing for this ::run() call */ /* tell the stretcher what we are doing for this ::run() call */
if (do_stretch && _state != Playout) { if (do_stretch && !_playout) {
const double stretch = _segment_tempo / bpm; const double stretch = _segment_tempo / bpm;
_stretcher->setTimeRatio (stretch); _stretcher->setTimeRatio (stretch);
@ -1755,7 +1756,7 @@ AudioTrigger::audio_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t
} }
} }
while (nframes && (_state != Playout)) { while (nframes && !_playout) {
pframes_t to_stretcher; pframes_t to_stretcher;
pframes_t from_stretcher; pframes_t from_stretcher;
@ -1835,7 +1836,7 @@ AudioTrigger::audio_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t
if (process_index < final_processed_sample) { if (process_index < final_processed_sample) {
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 reached (EX) end, entering playout mode to cover %2 .. %3\n", index(), process_index, final_processed_sample)); DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 reached (EX) end, entering playout mode to cover %2 .. %3\n", index(), process_index, final_processed_sample));
_state = Playout; _playout = true;
} else { } else {
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 reached (EX) end, now stopped, retrieved %2, avail %3 pi %4 vs fs %5\n", index(), retrieved, avail, process_index, final_processed_sample)); DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 reached (EX) end, now stopped, retrieved %2, avail %3 pi %4 vs fs %5\n", index(), retrieved, avail, process_index, final_processed_sample));
_state = Stopped; _state = Stopped;
@ -1896,20 +1897,19 @@ AudioTrigger::audio_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t
if (process_index < final_processed_sample) { if (process_index < final_processed_sample) {
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 reached end, entering playout mode to cover %2 .. %3\n", index(), process_index, final_processed_sample)); DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 reached end, entering playout mode to cover %2 .. %3\n", index(), process_index, final_processed_sample));
_state = Playout; _playout = true;
} else { } else {
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 reached end, now stopped, retrieved %2, avail %3\n", index(), retrieved, avail));
_state = Stopped; _state = Stopped;
_loop_cnt++; _loop_cnt++;
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 reached end, now stopped, retrieved %2, avail %3 LC now %4\n", index(), retrieved, avail, _loop_cnt));
} }
break; break;
} }
} }
pframes_t covered_frames = orig_nframes - nframes; pframes_t covered_frames = orig_nframes - nframes;
if (_state == Playout) { if (_playout) {
if (nframes != orig_nframes) { if (nframes != orig_nframes) {
/* we've already taken dest_offset into account, it plays no /* we've already taken dest_offset into account, it plays no
@ -2401,7 +2401,6 @@ MIDITrigger::midi_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t en
case WaitingToStart: case WaitingToStart:
return nframes; return nframes;
case Running: case Running:
case Playout:
case WaitingToStop: case WaitingToStop:
case Stopping: case Stopping:
break; break;
@ -2409,7 +2408,7 @@ MIDITrigger::midi_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t en
Temporal::Beats last_event_timeline_beats; Temporal::Beats last_event_timeline_beats;
while (iter != model->end() && _state != Playout) { while (iter != model->end() && !_playout) {
MidiEvent const & event (*iter); MidiEvent const & event (*iter);
@ -2497,24 +2496,19 @@ MIDITrigger::midi_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t en
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 entering playout because ... leb %2 <= fb %3\n", index(), last_event_timeline_beats, final_beat)); DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 entering playout because ... leb %2 <= fb %3\n", index(), last_event_timeline_beats, final_beat));
if (_state != Playout) { _playout = true;
_state = Playout;
} if (final_beat > end_beats) {
/* not finished with playout yet, all frames covered */
if (_state == Playout) { nframes = 0;
if (final_beat > end_beats) { DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 not done with playout, all frames covered\n", index()));
/* not finished with playout yet, all frames covered */ } else {
nframes = 0; /* finishing up playout */
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 not done with playout, all frames covered\n", index())); samplepos_t final_processed_sample = tmap->sample_at (timepos_t (final_beat));
} else { nframes = orig_nframes - (final_processed_sample - start_sample);
/* finishing up playout */ _loop_cnt++;
samplepos_t final_processed_sample = tmap->sample_at (timepos_t (final_beat)); _state = Stopped;
nframes = orig_nframes - (final_processed_sample - start_sample); DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 playout done, nf = %2 fb %3 fs %4 %5 LC %6\n", index(), nframes, final_beat, final_processed_sample, start_sample, _loop_cnt));
_loop_cnt++;
_state = Stopped;
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 playout done, nf = %2 fb %3 fs %4 %5\n", index(), nframes, final_beat, final_processed_sample, start_sample));
}
} }
} else { } else {