replace use of non-null region as test for "trigger can be used"

This commit is contained in:
Paul Davis 2024-03-10 05:44:31 -06:00
parent 256d3b1d52
commit 5450e80bd4
2 changed files with 39 additions and 26 deletions

View File

@ -315,6 +315,8 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
bool active() const { return _state >= Running; } bool active() const { return _state >= Running; }
State state() const { return _state; } State state() const { return _state; }
virtual bool has_data() const = 0;
void set_region (std::shared_ptr<Region>, bool use_thread = true); void set_region (std::shared_ptr<Region>, bool use_thread = true);
void clear_region (); void clear_region ();
virtual int set_region_in_worker_thread (std::shared_ptr<Region>) = 0; virtual int set_region_in_worker_thread (std::shared_ptr<Region>) = 0;
@ -495,6 +497,9 @@ class LIBARDOUR_API AudioTrigger : public Trigger {
return audio_run<true> (bufs, start_sample, end_sample, start, end, nframes, dest_offset, bpm, quantize_offset); return audio_run<true> (bufs, start_sample, end_sample, start, end, nframes, dest_offset, bpm, quantize_offset);
} }
bool has_data() const { return data.length > 0; }
uint32_t n_channels() const { return data.size(); }
StretchMode stretch_mode() const { return _stretch_mode; } StretchMode stretch_mode() const { return _stretch_mode; }
void set_stretch_mode (StretchMode); void set_stretch_mode (StretchMode);
@ -559,6 +564,7 @@ class LIBARDOUR_API AudioTrigger : public Trigger {
void drop_data (); void drop_data ();
int load_data (std::shared_ptr<AudioRegion>); int load_data (std::shared_ptr<AudioRegion>);
int load_data (BufferSet const &);
void estimate_tempo (); void estimate_tempo ();
void reset_stretcher (); void reset_stretcher ();
void _startup (BufferSet&, pframes_t dest_offset, Temporal::BBT_Offset const &); void _startup (BufferSet&, pframes_t dest_offset, Temporal::BBT_Offset const &);
@ -577,6 +583,8 @@ class LIBARDOUR_API MIDITrigger : public Trigger {
return midi_run<true> (bufs, start_sample, end_sample, start, end, nframes, dest_offset, bpm, quantize_offset); return midi_run<true> (bufs, start_sample, end_sample, start, end, nframes, dest_offset, bpm, quantize_offset);
} }
bool has_data() const { return (bool) model; }
void set_start (timepos_t const &); void set_start (timepos_t const &);
void set_end (timepos_t const &); void set_end (timepos_t const &);
void set_legato_offset (timepos_t const &); void set_legato_offset (timepos_t const &);
@ -645,6 +653,7 @@ class LIBARDOUR_API MIDITrigger : public Trigger {
bool map_change; bool map_change;
int load_data (std::shared_ptr<MidiRegion>); int load_data (std::shared_ptr<MidiRegion>);
int load_data (BufferSet const &);
void compute_and_set_length (); void compute_and_set_length ();
void _startup (BufferSet&, pframes_t dest_offset, Temporal::BBT_Offset const &); void _startup (BufferSet&, pframes_t dest_offset, Temporal::BBT_Offset const &);
}; };

View File

@ -562,7 +562,7 @@ Trigger::set_ui (void* p)
void void
Trigger::bang (float velocity) Trigger::bang (float velocity)
{ {
if (!_region) { if (!has_data()) {
return; return;
} }
_pending_velocity_gain = velocity; _pending_velocity_gain = velocity;
@ -573,7 +573,7 @@ Trigger::bang (float velocity)
void void
Trigger::unbang () Trigger::unbang ()
{ {
if (!_region) { if (!has_data()) {
return; return;
} }
_unbang.fetch_add (1); _unbang.fetch_add (1);
@ -1285,7 +1285,7 @@ AudioTrigger::set_stretch_mode (Trigger::StretchMode sm)
void void
AudioTrigger::set_segment_tempo (double t) AudioTrigger::set_segment_tempo (double t)
{ {
if (!_region) { if (data.length <= 0) {
_segment_tempo = 0; _segment_tempo = 0;
return; return;
} }
@ -1772,12 +1772,11 @@ AudioTrigger::setup_stretcher ()
using namespace RubberBand; using namespace RubberBand;
using namespace Temporal; using namespace Temporal;
if (!_region) { if (!has_data()) {
return; return;
} }
std::shared_ptr<AudioRegion> ar (std::dynamic_pointer_cast<AudioRegion> (_region)); const uint32_t nchans = std::min (_box.input_streams().n_audio(), n_channels());
const uint32_t nchans = std::min (_box.input_streams().n_audio(), ar->n_channels());
//map our internal enum to a rubberband option //map our internal enum to a rubberband option
RubberBandStretcher::Option ro = RubberBandStretcher::Option (0); RubberBandStretcher::Option ro = RubberBandStretcher::Option (0);
@ -1802,6 +1801,13 @@ AudioTrigger::drop_data ()
delete [] d; delete [] d;
} }
data.clear (); data.clear ();
data.length = 0;
}
int
AudioTrigger::load_data (BufferSet const & bufs)
{
return 0;
} }
int int
@ -1809,8 +1815,8 @@ AudioTrigger::load_data (std::shared_ptr<AudioRegion> ar)
{ {
const uint32_t nchans = ar->n_channels(); const uint32_t nchans = ar->n_channels();
data.length = ar->length_samples();
drop_data (); drop_data ();
data.length = ar->length_samples();
try { try {
for (uint32_t n = 0; n < nchans; ++n) { for (uint32_t n = 0; n < nchans; ++n) {
@ -1849,9 +1855,8 @@ AudioTrigger::audio_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t
Temporal::Beats const & start, Temporal::Beats const & end, Temporal::Beats const & start, Temporal::Beats const & end,
pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t& quantize_offset) pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t& quantize_offset)
{ {
std::shared_ptr<AudioRegion> ar = std::dynamic_pointer_cast<AudioRegion>(_region);
/* We do not modify the I/O of our parent route, so we process only min (bufs.n_audio(),region.channels()) */ /* We do not modify the I/O of our parent route, so we process only min (bufs.n_audio(),region.channels()) */
const uint32_t nchans = (in_process_context ? std::min (bufs.count().n_audio(), ar->n_channels()) : ar->n_channels()); const uint32_t nchans = (in_process_context ? std::min (bufs.count().n_audio(), n_channels()) : n_channels());
int avail = 0; int avail = 0;
BufferSet* scratch; BufferSet* scratch;
std::unique_ptr<BufferSet> scratchp; std::unique_ptr<BufferSet> scratchp;
@ -3262,7 +3267,7 @@ TriggerBox::fast_forward (CueEvents const & cues, samplepos_t transport_position
pos = c->time; pos = c->time;
cnt = 0; cnt = 0;
if (!trig->region()) { if (!trig->has_data()) {
fast_forward_nothing_to_do (); fast_forward_nothing_to_do ();
return; return;
} }
@ -3480,7 +3485,7 @@ TriggerBox::maybe_swap_pending (uint32_t slot)
if (p) { if (p) {
if (p == Trigger::MagicClearPointerValue) { if (p == Trigger::MagicClearPointerValue) {
if (all_triggers[slot]->region()) { if (all_triggers[slot]->has_data()) {
if (_active_slots) { if (_active_slots) {
_active_slots--; _active_slots--;
} }
@ -3490,7 +3495,7 @@ TriggerBox::maybe_swap_pending (uint32_t slot)
} }
all_triggers[slot]->clear_region (); all_triggers[slot]->clear_region ();
} else { } else {
if (!all_triggers[slot]->region()) { if (!all_triggers[slot]->has_data()) {
if (_active_slots == 0) { if (_active_slots == 0) {
empty_changed = true; empty_changed = true;
} }
@ -3772,7 +3777,7 @@ void
TriggerBox::bang_trigger_at (Triggers::size_type row, float velocity) TriggerBox::bang_trigger_at (Triggers::size_type row, float velocity)
{ {
TriggerPtr t = trigger(row); TriggerPtr t = trigger(row);
if (t && t->region()) { if (t && t->has_data()) {
t->bang (velocity); t->bang (velocity);
} else { } else {
/* by convention, an empty slot is effectively a STOP button */ /* by convention, an empty slot is effectively a STOP button */
@ -3784,7 +3789,7 @@ void
TriggerBox::unbang_trigger_at (Triggers::size_type row) TriggerBox::unbang_trigger_at (Triggers::size_type row)
{ {
TriggerPtr t = trigger(row); TriggerPtr t = trigger(row);
if (t && t->region()) { if (t && t->has_data()) {
t->unbang(); t->unbang();
} else { } else {
/* you shouldn't be able to unbang an empty slot; but if this somehow happens we'll just treat it as a */ /* you shouldn't be able to unbang an empty slot; but if this somehow happens we'll just treat it as a */
@ -4174,7 +4179,7 @@ TriggerBox::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
DEBUG_TRACE (DEBUG::Triggers, string_compose ("tb noticed active scene %1\n", _active_scene)); DEBUG_TRACE (DEBUG::Triggers, string_compose ("tb noticed active scene %1\n", _active_scene));
if (_active_scene < (int32_t) all_triggers.size()) { if (_active_scene < (int32_t) all_triggers.size()) {
if (!all_triggers[_active_scene]->cue_isolated()) { if (!all_triggers[_active_scene]->cue_isolated()) {
if (all_triggers[_active_scene]->region()) { if (all_triggers[_active_scene]->has_data()) {
all_triggers[_active_scene]->bang (); all_triggers[_active_scene]->bang ();
} else { } else {
stop_all_quantized (); //empty slot, this should work as a Stop for the running clips stop_all_quantized (); //empty slot, this should work as a Stop for the running clips
@ -4428,10 +4433,9 @@ TriggerBox::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
pframes_t frames_covered; pframes_t frames_covered;
std::shared_ptr<AudioTrigger> att = std::dynamic_pointer_cast<AudioTrigger> (_currently_playing);
std::shared_ptr<AudioRegion> ar = std::dynamic_pointer_cast<AudioRegion> (_currently_playing->region()); if (att) {
if (ar) { max_chans = std::max (att->n_channels(), max_chans);
max_chans = std::max (ar->n_channels(), max_chans);
} }
/* Quantize offset will generally be zero, but if non-zero, it /* Quantize offset will generally be zero, but if non-zero, it
@ -4506,12 +4510,12 @@ TriggerBox::determine_next_trigger (uint32_t current)
/* count number of triggers that can actually be run (i.e. they have a region) */ /* count number of triggers that can actually be run (i.e. they have a region) */
for (uint32_t n = 0; n < all_triggers.size(); ++n) { for (uint32_t n = 0; n < all_triggers.size(); ++n) {
if (all_triggers[n]->region()) { if (all_triggers[n]->has_data()) {
runnable++; runnable++;
} }
} }
if (runnable == 0 || !all_triggers[current]->region()) { if (runnable == 0 || !all_triggers[current]->has_data()) {
return -1; return -1;
} }
@ -4572,7 +4576,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
break; break;
} }
if (all_triggers[n]->region() && !all_triggers[n]->active()) { if (all_triggers[n]->has_data() && !all_triggers[n]->active()) {
return n; return n;
} }
} }
@ -4591,7 +4595,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
break; break;
} }
if (all_triggers[n]->region() && !all_triggers[n]->active ()) { if (all_triggers[n]->has_data() && !all_triggers[n]->active ()) {
return n; return n;
} }
} }
@ -4599,14 +4603,14 @@ TriggerBox::determine_next_trigger (uint32_t current)
case FollowAction::FirstTrigger: case FollowAction::FirstTrigger:
for (n = 0; n < all_triggers.size(); ++n) { for (n = 0; n < all_triggers.size(); ++n) {
if (all_triggers[n]->region() && !all_triggers[n]->active ()) { if (all_triggers[n]->has_data() && !all_triggers[n]->active ()) {
return n; return n;
} }
} }
break; break;
case FollowAction::LastTrigger: case FollowAction::LastTrigger:
for (int i = all_triggers.size() - 1; i >= 0; --i) { for (int i = all_triggers.size() - 1; i >= 0; --i) {
if (all_triggers[i]->region() && !all_triggers[i]->active ()) { if (all_triggers[i]->has_data() && !all_triggers[i]->active ()) {
return i; return i;
} }
} }
@ -4614,7 +4618,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
case FollowAction::JumpTrigger: case FollowAction::JumpTrigger:
for (std::size_t n = 0; n < TriggerBox::default_triggers_per_box; ++n) { for (std::size_t n = 0; n < TriggerBox::default_triggers_per_box; ++n) {
if (fa.targets.test (n) && all_triggers[n]->region()) { if (fa.targets.test (n) && all_triggers[n]->has_data()) {
possible_targets.push_back (n); possible_targets.push_back (n);
} }
} }