Files
serumalt/Source/Engine.h
T
biggy e4cea300db chore: land janitor round 1 and graft integration
Round 1 findings and fixes, all previously uncommitted:
- FXProcessor per-slot DSP history repair (HEAD does not compile without it)
- SynthVoice::getModulationValue, editor control-lock guard
- ExactCompare.h naming the deliberate exact float comparisons
- KnobLookAndFeel replacing the never-installed SerumLookAndFeel
- 55 first-party compiler warnings to 0
- AGENT.md renamed to AGENTS.md across Source/
- graft repository context graph and its hooks
- JANITOR_TASKS.md and UI_UX_AUDIT.md records
2026-10-06 08:50:45 +02:00

87 lines
2.8 KiB
C++

#pragma once
#include <JuceHeader.h>
#include <string_view>
#include <unordered_map>
#include "Params.h"
#include "Wavetable.h"
#include "SynthVoice.h"
#include "LFO.h"
#include "FXProcessor.h"
#include "ModulationMatrix.h"
#include "MacroControls.h"
namespace serum
{
// ===========================================================================
// The synthesis engine: a fixed pool of voices, four global LFOs, a wavetable
// library and the FX rack. Owns all per-block DSP and MIDI handling.
// ===========================================================================
class Engine
{
public:
Engine();
void prepare (double sampleRate, int blockSize, juce::AudioProcessorValueTreeState& apvts);
void reset();
// Ask for the DSP state to be cleared before the next block is rendered.
// Safe to call from the message thread while controlLock is held: the audio
// thread performs the reset in captureControls, so the DSP objects are only
// ever touched by the audio thread.
void requestReset() noexcept;
void processBlock (juce::AudioBuffer<float>& buffer,
juce::MidiBuffer& midi,
juce::AudioProcessorValueTreeState& apvts,
juce::AudioPlayHead* playhead);
// MIDI
void noteOn (int noteNumber, float velocity01);
void noteOff (int noteNumber);
void allNotesOff();
// Control-state accessors: hold getControlLock() while reading or editing.
const juce::CriticalSection& getControlLock() const { return controlLock; }
ModulationMatrix& getMatrix() { return matrix; }
MacroControls& getMacros() { return macros; }
const std::array<LFO, kNumLfos>& getLfos() const { return controlLfos; }
const WavetableLibrary& getWavetables() const { return wavetables; }
void setLfoShapeData (int index, const std::vector<float>& data, int steps);
private:
std::array<SynthVoice, kNumVoices> voices;
std::array<LFO, kNumLfos> lfos, controlLfos;
WavetableLibrary wavetables;
FXProcessor fx;
ModulationMatrix matrix, audioMatrix;
MacroControls macros, audioMacros;
juce::CriticalSection controlLock;
bool resetRequested = false; // guarded by controlLock
struct ParameterValue
{
std::atomic<float>* source;
float value;
};
std::unordered_map<std::string_view, ParameterValue> parameterValues;
double sr = 44100.0;
int blockSize = 512;
double bpm = 120.0;
float pitchBend = 0.0f;
float modWheel = 0.0f;
juce::uint64 noteCounter = 0;
juce::AudioBuffer<float> mixBuffer;
SynthVoice* findFreeVoice();
SynthVoice* stealVoice();
void captureControls();
float v (const char* id) const;
int vic (const char* id, int maxValue) const;
void readOscParams (const paramIds::Oscillator& ids, OscParams& out) const;
};
} // namespace serum