Files
serumalt/Source/PluginProcessor.h
T
biggy 3be1e42242 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.
2026-09-09 14:33:30 +02:00

71 lines
2.4 KiB
C++

#pragma once
#include <JuceHeader.h>
#include <atomic>
#include "Params.h"
#include "Engine.h"
namespace serum
{
// ===========================================================================
// SerumAlt — a wavetable synthesiser (VST3 / AU). Hosts the APVTS, the audio
// engine, preset management and the RAVE toggle.
// ===========================================================================
class SerumAltAudioProcessor : public juce::AudioProcessor
{
public:
SerumAltAudioProcessor();
~SerumAltAudioProcessor() override;
// --- AudioProcessor ---
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
void processBlock (juce::AudioBuffer<float>&, juce::MidiBuffer&) override;
juce::AudioProcessorEditor* createEditor() override;
bool hasEditor() const override { return true; }
const juce::String getName() const override { return "SerumAlt"; }
bool acceptsMidi() const override { return true; }
bool producesMidi() const override { return false; }
bool isMidiEffect() const override { return false; }
double getTailLengthSeconds() const override { return 2.0; }
int getNumPrograms() override;
int getCurrentProgram() override;
void setCurrentProgram (int index) override;
const juce::String getProgramName (int index) override;
void changeProgramName (int index, const juce::String& newName) override;
void getStateInformation (juce::MemoryBlock& destData) override;
void setStateInformation (const void* data, int sizeInBytes) override;
// --- SerumAlt ---
void setRaveEnabled (bool enabled);
bool isRaveEnabled() const;
int getUiScaleIndex() const;
void setUiScaleIndex (int index);
float getUiScale() const;
void loadFactoryPreset (int index);
int getNumFactoryPresets() const;
// Public control state (hold the engine control lock for matrix/macros/LFOs).
juce::AudioProcessorValueTreeState parameters;
Engine engine;
static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout();
private:
std::atomic<int> currentProgram { 0 };
void restoreLfoShapesFromState (const juce::ValueTree& state);
void saveLfoShapesToState (juce::ValueTree& state) const;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SerumAltAudioProcessor)
};
} // namespace serum