13
0

provide a better method to decide if a trigger(slot) is occupied

This is necessary with clip recording because for some short time after recording,
a trigger may be playable despite not yet having a region.

libs edition.
This commit is contained in:
Paul Davis 2024-10-02 13:46:52 -06:00
parent e089953e78
commit 1e8b2c521c
7 changed files with 30 additions and 25 deletions

View File

@ -328,7 +328,8 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
void clear_region ();
virtual int set_region_in_worker_thread (std::shared_ptr<Region>) = 0;
virtual int set_region_in_worker_thread_from_capture (std::shared_ptr<Region>) = 0;
std::shared_ptr<Region> region() const { return _region; }
std::shared_ptr<Region> the_region() const { return _region; }
virtual bool playable() const = 0;
uint32_t index() const { return _index; }
@ -509,6 +510,8 @@ class LIBARDOUR_API AudioTrigger : public Trigger {
return audio_run<true> (bufs, start_sample, end_sample, start, end, nframes, dest_offset, bpm, quantize_offset);
}
bool playable() const { return data.length; }
StretchMode stretch_mode() const { return _stretch_mode; }
void set_stretch_mode (StretchMode);
@ -600,6 +603,8 @@ class LIBARDOUR_API MIDITrigger : public Trigger {
MIDITrigger (uint32_t index, TriggerBox&);
~MIDITrigger ();
bool playable() const { return rt_midibuffer.load(); }
void captured (SlotArmInfo&, BufferSet&);
void arm();
void disarm ();

View File

@ -3812,7 +3812,7 @@ TriggerBox::fast_forward (CueEvents const & cues, samplepos_t transport_position
pos = c->time;
cnt = 0;
if (!trig->region()) {
if (!trig->playable()) {
fast_forward_nothing_to_do ();
return;
}
@ -4030,7 +4030,7 @@ TriggerBox::maybe_swap_pending (uint32_t slot)
if (p) {
if (p == Trigger::MagicClearPointerValue) {
if (all_triggers[slot]->region()) {
if (all_triggers[slot]->playable()) {
if (_active_slots) {
_active_slots--;
}
@ -4040,7 +4040,7 @@ TriggerBox::maybe_swap_pending (uint32_t slot)
}
all_triggers[slot]->clear_region ();
} else {
if (!all_triggers[slot]->region()) {
if (!all_triggers[slot]->playable()) {
if (_active_slots == 0) {
empty_changed = true;
}
@ -4129,7 +4129,7 @@ TriggerBox::deep_sources (std::set<std::shared_ptr<Source> >& sources)
Glib::Threads::RWLock::ReaderLock lm (trigger_lock);
for (uint64_t n = 0; n < all_triggers.size(); ++n) {
std::shared_ptr<Region> r (trigger(n)->region ());
std::shared_ptr<Region> r (trigger(n)->the_region ());
if (r) {
r->deep_sources (sources);
}
@ -4142,7 +4142,7 @@ TriggerBox::used_regions (std::set<std::shared_ptr<Region> >& regions)
Glib::Threads::RWLock::ReaderLock lm (trigger_lock);
for (uint64_t n = 0; n < all_triggers.size(); ++n) {
std::shared_ptr<Region> r (trigger(n)->region ());
std::shared_ptr<Region> r (trigger(n)->the_region ());
if (r) {
regions.insert (r);
}
@ -4322,7 +4322,7 @@ void
TriggerBox::bang_trigger_at (Triggers::size_type row, float velocity)
{
TriggerPtr t = trigger(row);
if (t && t->region()) {
if (t && t->playable()) {
t->bang (velocity);
} else {
/* by convention, an empty slot is effectively a STOP button */
@ -4334,7 +4334,7 @@ void
TriggerBox::unbang_trigger_at (Triggers::size_type row)
{
TriggerPtr t = trigger(row);
if (t && t->region()) {
if (t && t->playable()) {
t->unbang();
} else {
/* you shouldn't be able to unbang an empty slot; but if this somehow happens we'll just treat it as a */
@ -4758,7 +4758,7 @@ TriggerBox::run_cycle (BufferSet& bufs, samplepos_t start_sample, samplepos_t en
DEBUG_TRACE (DEBUG::Triggers, string_compose ("tb noticed active scene %1\n", _active_scene));
if (_active_scene < (int32_t) all_triggers.size()) {
if (!all_triggers[_active_scene]->cue_isolated()) {
if (all_triggers[_active_scene]->region()) {
if (all_triggers[_active_scene]->playable()) {
all_triggers[_active_scene]->bang ();
} else {
stop_all_quantized (); //empty slot, this should work as a Stop for the running clips
@ -5095,12 +5095,12 @@ TriggerBox::determine_next_trigger (uint32_t current)
/* 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) {
if (all_triggers[n]->region()) {
if (all_triggers[n]->playable()) {
runnable++;
}
}
if (runnable == 0 || !all_triggers[current]->region()) {
if (runnable == 0 || !all_triggers[current]->playable()) {
return -1;
}
@ -5161,7 +5161,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
break;
}
if (all_triggers[n]->region() && !all_triggers[n]->active()) {
if (all_triggers[n]->playable() && !all_triggers[n]->active()) {
return n;
}
}
@ -5180,7 +5180,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
break;
}
if (all_triggers[n]->region() && !all_triggers[n]->active ()) {
if (all_triggers[n]->playable() && !all_triggers[n]->active ()) {
return n;
}
}
@ -5188,14 +5188,14 @@ TriggerBox::determine_next_trigger (uint32_t current)
case FollowAction::FirstTrigger:
for (n = 0; n < all_triggers.size(); ++n) {
if (all_triggers[n]->region() && !all_triggers[n]->active ()) {
if (all_triggers[n]->playable() && !all_triggers[n]->active ()) {
return n;
}
}
break;
case FollowAction::LastTrigger:
for (int i = all_triggers.size() - 1; i >= 0; --i) {
if (all_triggers[i]->region() && !all_triggers[i]->active ()) {
if (all_triggers[i]->playable() && !all_triggers[i]->active ()) {
return i;
}
}
@ -5203,7 +5203,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
case FollowAction::JumpTrigger:
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]->playable()) {
possible_targets.push_back (n);
}
}
@ -5280,7 +5280,7 @@ TriggerBox::set_state (const XMLNode& node, int version)
all_triggers.push_back (trig);
trig->set_state (**t, version);
}
if (trig->region ()) {
if (trig->playable ()) {
_active_slots++;
}
}

View File

@ -889,7 +889,7 @@ BasicUI::trigger_display_at (int x, int y)
ARDOUR::TriggerPtr current = tb->currently_playing ();
TriggerPtr tp = tb->trigger (_tbank_start_row + y);
if (tp) {
if (!tp->region()) {
if (!tp->playable()) {
disp.state = -1;
} else if (tp == current) {
disp.state = 1;

View File

@ -1049,7 +1049,7 @@ LaunchKey4::trigger_property_change (PropertyChange pc, Trigger* t)
void
LaunchKey4::trigger_pad_light (Pad& pad, std::shared_ptr<Route> r, Trigger* t)
{
if (!r || !t || !t->region()) {
if (!r || !t || !t->playable()) {
unlight_pad (pad.id);
return;
}

View File

@ -1584,7 +1584,7 @@ LaunchPadPro::trigger_property_change (PropertyChange pc, Trigger* t)
MidiByteArray msg;
std::shared_ptr<Route> r = session->get_remote_nth_route (scroll_x_offset + x);
if (!r || !t->region()) {
if (!r || !t->playable()) {
msg.push_back (0x90);
msg.push_back (pid);
msg.push_back (0x0);
@ -1659,7 +1659,7 @@ LaunchPadPro::map_triggerbox (int x)
TriggerPtr t = session->trigger_at (xp, yp);
if (!t || !t->region()) {
if (!t || !t->playable()) {
msg[2] = 0x0;
} else {
msg[2] = palette_index;

View File

@ -1262,7 +1262,7 @@ LaunchPadX::trigger_property_change (PropertyChange pc, Trigger* t)
MidiByteArray msg;
std::shared_ptr<Route> r = session->get_remote_nth_route (scroll_x_offset + x);
if (!r || !t->region()) {
if (!r || !t->playable()) {
msg.push_back (0x90);
msg.push_back (pid);
msg.push_back (0x0);
@ -1337,7 +1337,7 @@ LaunchPadX::map_triggerbox (int x)
TriggerPtr t = session->trigger_at (xp, yp);
if (!t || !t->region()) {
if (!t || !t->playable()) {
msg[2] = 0x0;
} else {
msg[2] = palette_index;

View File

@ -432,7 +432,7 @@ CueLayout::viewport_changed ()
std::shared_ptr<Push2::Pad> pad = _p2.pad_by_xy (n, y);
if (tb && tb->active()) {
TriggerPtr tp = tb->trigger (y);
if (tp && tp->region()) {
if (tp && tp->playable()) {
/* trigger in slot */
pad->set_color (color);
tp->PropertyChanged.connect (_trig_connections[n * 8 + y], invalidator (*this), boost::bind (&CueLayout::trigger_property_change, this, _1, n, y), &_p2);
@ -780,7 +780,7 @@ CueLayout::set_pad_color_from_trigger_state (int col, std::shared_ptr<Push2::Pad
return;
}
if (trig->region()) {
if (trig->playable()) {
if (trig->active()) {