Allow the modulations to be notified of release

This commit is contained in:
Jean Pierre Cimalando 2020-08-21 14:49:36 +02:00
parent a71c1eb0f3
commit 0481862b10
4 changed files with 28 additions and 0 deletions

View file

@ -174,6 +174,8 @@ void sfz::Voice::release(int delay) noexcept
} else {
egEnvelope.startRelease(delay);
}
resources.modMatrix.releaseVoice(id, region->getId(), delay);
}
void sfz::Voice::off(int delay) noexcept

View file

@ -40,6 +40,15 @@ public:
*/
virtual void init(const ModKey& sourceKey, NumericId<Voice> voiceId, unsigned delay) = 0;
/**
* @brief Send the generator a release notification.
*
* @param sourceKey identifier of the source to release
* @param voiceId the particular voice to initialize, if per-voice
* @param delay the frame time when it happens
*/
virtual void release(const ModKey& sourceKey, NumericId<Voice> voiceId, unsigned delay) { (void)sourceKey; (void)voiceId; (void)delay; }
/**
* @brief Generate a cycle of the modulator
*

View file

@ -211,6 +211,17 @@ void ModMatrix::initVoice(NumericId<Voice> voiceId, NumericId<Region> regionId,
}
}
void ModMatrix::releaseVoice(NumericId<Voice> voiceId, NumericId<Region> regionId, unsigned delay)
{
Impl& impl = *impl_;
for (Impl::Source &source : impl.sources_) {
const int flags = source.key.flags();
if ((flags & kModIsPerVoice) && source.key.region() == regionId)
source.gen->release(source.key, voiceId, delay);
}
}
void ModMatrix::beginCycle(unsigned numFrames)
{
Impl& impl = *impl_;

View file

@ -108,6 +108,12 @@ public:
*/
void initVoice(NumericId<Voice> voiceId, NumericId<Region> regionId, unsigned delay);
/**
* @brief Release modulation source for a given voice.
* This must be called when a voice enters released state.
*/
void releaseVoice(NumericId<Voice> voiceId, NumericId<Region> regionId, unsigned delay);
/**
* @brief Start modulation processing for the entire cycle.
* This clears all the buffers.