triggerbox: keep track of, and make available, "empty" status for a triggerbox.

Includes PBD::Signal that notifies when a TriggerBox's empty status changes
This commit is contained in:
Paul Davis 2022-01-31 22:40:05 -07:00
parent b55ef8543d
commit 8e4fdb071b
2 changed files with 30 additions and 0 deletions

View File

@ -590,6 +590,9 @@ class LIBARDOUR_API TriggerBox : public Processor
bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
bool configure_io (ChanCount in, ChanCount out);
bool empty() const { return _active_slots == 0; }
PBD::Signal0<void> EmptyStatusChanged;
int32_t order() const { return _order; }
void set_order(int32_t n);
@ -690,6 +693,7 @@ class LIBARDOUR_API TriggerBox : public Processor
Requests _requests;
bool _stop_all;
int32_t _active_scene;
int32_t _active_slots;
boost::shared_ptr<SideChain> _sidechain;

View File

@ -2124,6 +2124,7 @@ TriggerBox::TriggerBox (Session& s, DataType dt)
, _currently_playing (0)
, _stop_all (false)
, _active_scene (-1)
, _active_slots (0)
, requests (1024)
{
set_display_to_user (false);
@ -2220,14 +2221,29 @@ TriggerBox::maybe_swap_pending (uint32_t slot)
*/
Trigger* p = 0;
bool empty_changed = false;
p = all_triggers[slot]->swap_pending (p);
if (p) {
if (p == Trigger::MagicClearPointerValue) {
if (all_triggers[slot]->region()) {
if (_active_slots) {
_active_slots--;
}
if (_active_slots == 0) {
empty_changed = true;
}
}
all_triggers[slot]->clear_region ();
} else {
if (!all_triggers[slot]->region()) {
if (_active_slots == 0) {
empty_changed = true;
}
_active_slots++;
}
/* Note use of a custom delete function. We cannot
delete the old trigger from the RT context where the
trigger swap will happen, so we will ask the trigger
@ -2237,6 +2253,10 @@ TriggerBox::maybe_swap_pending (uint32_t slot)
TriggerSwapped (slot); /* EMIT SIGNAL */
}
}
if (empty_changed) {
EmptyStatusChanged (); /* EMIT SIGNAL */
}
}
void
@ -3157,6 +3177,7 @@ TriggerBox::set_state (const XMLNode& node, int version)
all_triggers.push_back (trig);
trig->set_state (**t, version);
}
_active_slots++;
}
}
@ -3172,6 +3193,11 @@ TriggerBox::set_state (const XMLNode& node, int version)
}
}
/* Since _active_slots may have changed, we could consider sending
* EmptyStatusChanged, but for now we don't consider ::set_state() to
* be used except at session load.
*/
return 0;
}