Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,38 @@ void LFOModifier::applyToBuffer (const PluginRenderContext& prc)
if (prc.bufferForMidiMessages == nullptr)
return;

if (skipNativeResync_.load (std::memory_order_acquire))
const bool skipResync = skipNativeResync_.load (std::memory_order_acquire);
const bool gateByMidi = gateOnTriggerSource_.load (std::memory_order_acquire)
&& juce::roundToInt (syncTypeParam->getCurrentValue()) == ModifierCommon::note;

if (skipResync && ! gateByMidi)
return;

for (auto& m : *prc.bufferForMidiMessages)
{
if (m.isNoteOn())
modifierTimer->resync (prc.bufferNumSamples / getSampleRate());
{
if (! skipResync)
modifierTimer->resync (prc.bufferNumSamples / getSampleRate());

if (gateByMidi)
{
++heldNotes_;
gated_.store (false, std::memory_order_release);
}
}
else if (gateByMidi && m.isNoteOff (true))
{
heldNotes_ = juce::jmax (0, heldNotes_ - 1);
if (heldNotes_ == 0)
gated_.store (true, std::memory_order_release);
}
else if (gateByMidi && (m.isAllNotesOff() || m.isAllSoundOff()))
{
heldNotes_ = 0;
gated_.store (true, std::memory_order_release);
}
}
}

void LFOModifier::triggerNoteOn (bool forceZeroValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ class LFOModifier : public Modifier,
void setSkipNativeResync (bool skip) { skipNativeResync_.store (skip, std::memory_order_release); }
bool getSkipNativeResync() const { return skipNativeResync_.load (std::memory_order_acquire); }

/** When true and syncType == note, applyToBuffer() drives the gated_ flag
from the MIDI stream: NoteOn ungates and increments a held-note count,
NoteOff (or vel-0 NoteOn) decrements it; gate is re-asserted once the
count returns to zero. AllNotesOff / AllSoundOff force the count to
zero. Lets MIDI-trigger LFOs behave like envelopes — output sits at 0
between notes — without changing the free-run sync mode. */
void setGateOnTriggerSource (bool g)
{
gateOnTriggerSource_.store (g, std::memory_order_release);
if (! g)
gated_.store (false, std::memory_order_release);
}
bool getGateOnTriggerSource() const { return gateOnTriggerSource_.load (std::memory_order_acquire); }

private:
struct LFOModifierTimer;
std::unique_ptr<LFOModifierTimer> modifierTimer;
Expand All @@ -113,6 +127,8 @@ class LFOModifier : public Modifier,
std::atomic<float> currentPhase { 0.0f }, currentValue { 0.0f };
std::atomic<bool> gated_ { false };
std::atomic<bool> skipNativeResync_ { false };
std::atomic<bool> gateOnTriggerSource_ { false };
int heldNotes_ = 0; // audio-thread only; touched from applyToBuffer

void valueTreeChanged() override;
};
Expand Down
Loading