refactor(engine): add thread-safe control capture and sub-block MIDI

Introduce a CriticalSection controlLock separating control-thread
state (matrix, macros, controlLfos) from audio-thread snapshots
(audioMatrix, audioMacros, lfos). captureControls() copies under
lock at the start of each processBlock; the audio thread never
touches control state directly. Cache parameter values in an
unordered_map keyed by string_view to avoid per-sample APVTS lookups.

Prebuild wavetables in the constructor instead of lazy allocation.
Resize mixBuffer only in prepare(), not per block. Render MIDI
events at their sample positions using sub-block rendering with
renderUntil(), so notes start at the correct sub-sample offset.

Make RaveController non-destructive: replace APVTS mutation with a
static apply() that boosts the RenderContext and FX slots for the
current block only. Remove the snapshot/restore machinery.

Make currentProgram atomic. Validate state I/O: check XML tag,
clamp program index, sanitize LFO shape data, and use
beginChangeGesture/endChangeGesture for RAVE toggle. Reset
parameters to defaults before loading preset values.
This commit is contained in:
2026-09-09 14:33:30 +02:00
parent cd26beca42
commit 3be1e42242
6 changed files with 408 additions and 336 deletions
+4 -5
View File
@@ -1,16 +1,16 @@
#pragma once
#include <JuceHeader.h>
#include <atomic>
#include "Params.h"
#include "Engine.h"
#include "RAVEButton.h"
namespace serum
{
// ===========================================================================
// SerumAlt — a wavetable synthesiser (VST3 / AU). Hosts the APVTS, the audio
// engine, preset management and the RAVE controller.
// engine, preset management and the RAVE toggle.
// ===========================================================================
class SerumAltAudioProcessor : public juce::AudioProcessor
{
@@ -52,15 +52,14 @@ public:
void loadFactoryPreset (int index);
int getNumFactoryPresets() const;
// Public DSP state (read/write from the GUI thread).
// Public control state (hold the engine control lock for matrix/macros/LFOs).
juce::AudioProcessorValueTreeState parameters;
Engine engine;
RaveController rave;
static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout();
private:
int currentProgram = 0;
std::atomic<int> currentProgram { 0 };
void restoreLfoShapesFromState (const juce::ValueTree& state);
void saveLfoShapesToState (juce::ValueTree& state) const;