From 2cded52eef141ca59b5b5b35d7ecff7cc07df0da Mon Sep 17 00:00:00 2001 From: Armin Date: Mon, 20 Jul 2026 12:33:36 +0200 Subject: [PATCH] Fix track signal indicator sometimes not showing for short samples Use a latch pattern for trackActive: the audio thread sets it true whenever a voice is active, and the UI timer atomically reads and clears it via exchange(false). This eliminates the race where the flag was cleared at the start of every processBlock, causing the 30Hz timer to miss brief activations from short samples. --- Source/PluginEditor.cpp | 2 +- Source/PluginProcessor.cpp | 3 --- Source/PluginProcessor.h | 3 ++- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index d62c57f..6b56093 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -433,7 +433,7 @@ void TrommelkisteEditor::timerCallback() const double now = juce::Time::getMillisecondCounterHiRes() / 1000.0; for (int i = 0; i < NUM_TRACKS; ++i) { - if (proc.trackActive[i]) + if (proc.trackActive[i].exchange(false)) trackActivatedTime[i] = now; } repaint(); diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index e681902..2347c98 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -57,9 +57,6 @@ void TrommelkisteProcessor::processBlock(juce::AudioBuffer& buffer, juce: const int numSamples = buffer.getNumSamples(); buffer.clear(); - for (int i = 0; i < NUM_TRACKS; ++i) - trackActive[i] = false; - // Shuffle: add ghost notes (bar-quantized) const float globalShuffleAmt = apvts.getRawParameterValue("global_shuffleAmount")->load(); const float globalGroove = apvts.getRawParameterValue("global_groove")->load(); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 1cfaba5..6abc340 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -2,6 +2,7 @@ #include #include #include +#include #include static constexpr int NUM_TRACKS = 10; @@ -50,7 +51,7 @@ public: }; Track tracks[NUM_TRACKS]; - bool trackActive[NUM_TRACKS] = {}; + std::atomic trackActive[NUM_TRACKS] = {}; juce::AudioProcessorValueTreeState apvts; // Sample library