From 9d232cb2dde76b48c8f516eeb02d8e3e46265583 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 22 Oct 2025 16:57:48 +0000 Subject: [PATCH] Upload files to "Source" --- Source/GraphComponent.h | 217 +++++++++++++--------------- Source/NeuralSharedParams.h | 280 +++++++++++++++++++----------------- 2 files changed, 248 insertions(+), 249 deletions(-) diff --git a/Source/GraphComponent.h b/Source/GraphComponent.h index 9a40128..1fa963e 100644 --- a/Source/GraphComponent.h +++ b/Source/GraphComponent.h @@ -1,118 +1,99 @@ -/* - ============================================================================== - - GraphComponent.h - Created: 4 Jul 2025 11:43:57pm - Author: timot - - ============================================================================== -*/ - -#pragma once - -#include "AudioBufferQueue.h" - -//============================================================================== -template -class GraphComponent : public juce::Component, - private juce::Timer -{ -public: - //============================================================================== - GraphComponent(SampleType min, SampleType max, int numPoints): func(func), min(min), max(max), numPoints(numPoints) - { - x.resize(numPoints); - y.resize(numPoints); - setFramesPerSecond(30); - } - - //============================================================================== - void setFramesPerSecond(int framesPerSecond) - { - jassert(framesPerSecond > 0 && framesPerSecond < 1000); - startTimerHz(framesPerSecond); - } - - //============================================================================== - void setFunction(const std::function& func) { - this->func = func; - } - - //============================================================================== - void paint(juce::Graphics& g) override - { - g.fillAll(juce::Colours::black); - g.setColour(juce::Colours::white); - - auto area = getLocalBounds(); - - if (hasData && area.isFinite()) { - auto h = (SampleType)area.getHeight(); - auto w = (SampleType)area.getWidth(); - - for (size_t i = 1; i < numPoints; ++i) { - auto px_prev = ((x[i - 1] - min) / (max - min)) * w; - auto py_prev = h - ((y[i - 1] - minY) / (maxY - minY)) * h; - - auto px_next = ((x[i] - min) / (max - min)) * w; - auto py_next = h - ((y[i] - minY) / (maxY - minY)) * h; - - juce::Line line(juce::Point(px_prev, py_prev), juce::Point(px_next, py_next)); - - g.drawLine(line); - } - } - } - - //============================================================================== - void resized() override {} - -private: - //============================================================================== - std::vector x, y; - SampleType minY, maxY; - SampleType min, max; - int numPoints; - std::function func; - bool hasData = false; - - //============================================================================== - void timerCallback() override - { - float step = (max - min) / (SampleType)(numPoints - 1); - - for (int i = 0; i < numPoints; i++) { - x[i] = min + step * (SampleType)i; - y[i] = func(x[i]); - } - - auto p = minmax_element(y.begin(), y.end()); - - minY = *p.first; maxY = *p.second; - - hasData = true; - repaint(); - } - - //============================================================================== - /*static void plot(const SampleType* data, - size_t numSamples, - juce::Graphics& g, - juce::Rectangle rect, - SampleType scaler = SampleType(1), - SampleType offset = SampleType(0)) - { - auto w = rect.getWidth(); - auto h = rect.getHeight(); - auto right = rect.getRight(); - - auto center = rect.getBottom() - offset; - auto gain = h * scaler; - - for (size_t i = 1; i < numSamples; ++i) - g.drawLine({ juce::jmap(SampleType(i - 1), SampleType(0), SampleType(numSamples - 1), SampleType(right - w), SampleType(right)), - center - gain * data[i - 1], - juce::jmap(SampleType(i), SampleType(0), SampleType(numSamples - 1), SampleType(right - w), SampleType(right)), - center - gain * data[i] }); - }*/ -}; \ No newline at end of file +/* + ============================================================================== + + GraphComponent.h + Created: 4 Jul 2025 11:43:57pm + Author: timot + + ============================================================================== +*/ + +#pragma once + +#include // for std::minmax_element +#include "AudioBufferQueue.h" + +//============================================================================== +template +class GraphComponent : public juce::Component, + private juce::Timer +{ +public: + //============================================================================== + GraphComponent(SampleType minIn, SampleType maxIn, int numPointsIn) + : min(minIn), max(maxIn), numPoints(numPointsIn) + { + x.resize(numPoints); + y.resize(numPoints); + setFramesPerSecond(30); + // func will be set via setFunction before paint; provide a safe default + func = [](SampleType) noexcept { return SampleType(); }; + } + + //============================================================================== + void setFramesPerSecond(int framesPerSecond) + { + jassert(framesPerSecond > 0 && framesPerSecond < 1000); + startTimerHz(framesPerSecond); + } + + //============================================================================== + void setFunction(const std::function& f) { func = f; } + + //============================================================================== + void paint(juce::Graphics& g) override + { + g.fillAll(juce::Colours::black); + g.setColour(juce::Colours::white); + + auto area = getLocalBounds(); + + if (hasData && area.isFinite()) + { + auto h = (SampleType)area.getHeight(); + auto w = (SampleType)area.getWidth(); + + for (size_t i = 1; i < (size_t)numPoints; ++i) + { + auto px_prev = ((x[i - 1] - min) / (max - min)) * w; + auto py_prev = h - ((y[i - 1] - minY) / (maxY - minY)) * h; + + auto px_next = ((x[i] - min) / (max - min)) * w; + auto py_next = h - ((y[i] - minY) / (maxY - minY)) * h; + + g.drawLine({ px_prev, py_prev, px_next, py_next }); + } + } + } + + //============================================================================== + void resized() override {} + +private: + //============================================================================== + std::vector x, y; + SampleType minY{ SampleType() }, maxY{ SampleType(1) }; + SampleType min{}, max{}; + int numPoints{}; + std::function func; + bool hasData = false; + + //============================================================================== + void timerCallback() override + { + const SampleType step = (max - min) / (SampleType)(numPoints - 1); + + for (int i = 0; i < numPoints; i++) + { + x[(size_t)i] = min + step * (SampleType)i; + y[(size_t)i] = func(x[(size_t)i]); + } + + auto p = std::minmax_element(y.begin(), y.end()); + minY = *p.first; + maxY = *p.second; + + hasData = true; + repaint(); + } +}; diff --git a/Source/NeuralSharedParams.h b/Source/NeuralSharedParams.h index 3527cb9..451c844 100644 --- a/Source/NeuralSharedParams.h +++ b/Source/NeuralSharedParams.h @@ -1,131 +1,149 @@ -/* - ============================================================================== - - NeuralSharedParams.h - Created: 21 Jun 2025 7:53:02am - Author: timot - - ============================================================================== -*/ - -#pragma once - -#include - -struct SliderDetail { - std::string label; - - float min, max, interval, defValue; -}; - -typedef std::unordered_map ParamMap; - -// Each SliderDetail: { label, min, max, step, defaultValue } -const std::unordered_map PARAM_SETTINGS = { - - { "chorus", { - { "rate", { "Rate", 0.0f, 1.0f, 0.1f, 0.1f } }, // Modulation speed - { "depth", { "Depth", 0.0f, 1.0f, 0.1f, 0.1f } }, // Modulation amount - { "centre", { "Centre", 0.0f, 1.0f, 0.1f, 0.1f } }, // Center delay - { "feedback", { "Feedback", 0.0f, 1.0f, 0.1f, 0.1f } }, // Feedback amount - { "mix", { "Mix", 0.0f, 1.0f, 0.1f, 0.1f } } // Dry/wet blend - }}, - - { "delay", { - { "delay", { "Delay", 0.0f, 1.0f, 0.1f, 0.1f } } // Delay time - }}, - - { "reverb", { - { "roomSize", { "Room Size", 0.0f, 1.0f, 0.1f, 0.1f } }, // Size of reverb space - { "damping", { "Damping", 0.0f, 1.0f, 0.1f, 0.1f } }, // High-frequency attenuation - { "wetLevel", { "Wet Level", 0.0f, 1.0f, 0.1f, 0.1f } }, // Reverb amount - { "dryLevel", { "Dry Level", 0.0f, 1.0f, 0.1f, 0.1f } }, // Dry signal amount - { "width", { "Width", 0.0f, 1.0f, 0.1f, 0.1f } }, // Stereo width - { "freezeMode", { "Freeze Mode", 0.0f, 1.0f, 0.1f, 0.1f } } // Infinite decay toggle - }}, - - { "adsr", { - { "attack", { "Attack", 0.0f, 1.0f, 0.1f, 0.1f } }, // Attack time - { "decay", { "Decay", 0.0f, 1.0f, 0.1f, 0.1f } }, // Decay time - { "sustain", { "Sustain", 0.0f, 1.0f, 0.1f, 0.1f } }, // Sustain level - { "release", { "Release", 0.0f, 1.0f, 0.1f, 0.1f } } // Release time - }}, - - { "flanger", { - { "rate", { "Rate", 0.1f, 5.0f, 0.1f, 0.1f } }, // LFO speed - { "depth", { "Depth", 0.1f, 10.0f, 0.1f, 0.1f } }, // Mod depth in ms - { "feedback", { "Feedback", 0.0f, 1.0f, 0.1f, 0.1f } }, // Feedback amount - { "dryMix", { "Dry/Wet", 0.0f, 1.0f, 0.1f, 0.1f } }, // Mix control - { "phase", { "Phase", 0.0f, 1.0f, 0.1f, 0.1f } }, // LFO phase offset (for stereo) - { "delay", { "Delay", 0.0f, 3.0f, 0.1f, 0.1f } } // Base delay offset - }}, - - { "filter", { - { "cutoff", { "Cutoff", 0.2f, 20000.0f, 1.0f, 1000.0f } }, // Frequency cutoff - { "resonance", { "Resonance", 0.1f, 10.0f, 0.1f, 0.2f } }, // Resonance/Q factor - { "type", { "L/H/B", 0.0f, 2.0f, 1.0f, 0.0f } }, // 0 = LPF, 1 = HPF, 2 = BPF - { "drive", { "Drive", 0.0f, 1.0f, 0.01f, 0.0f } }, // Pre-gain into filter - { "mod", { "Mod", -1.0f, 1.0f, 0.1f, 0.0f } }, // Modulation amount - { "key", { "Key", 0.0f, 1.0f, 0.1f, 0.0f } } // Key tracking - }}, - - { "distortion", { - { "drive", { "Drive", 0.0f, 30.0f, 0.1f, 10.0f } }, // Input gain before shaping - { "mix", { "Mix", 0.0f, 1.0f, 0.01f, 0.5f } }, // Wet/dry blend - { "bias", { "Bias", -1.0f, 1.0f, 0.01f, 0.0f } }, // DC offset - { "tone", { "Tone", 100.0f, 8000.0f, 10.0f, 3000.0f } }, // LPF after distortion - { "shape", { "Shape", 0.0f, 2.0f, 1.0f, 0.0f } } // 0=tanh, 1=hard clip, 2=atan - }} - -}; - -struct NeuralSharedParams -{ - std::atomic waveform{ -1 }; - - std::atomic* adsrAttack; - std::atomic* adsrDecay; - std::atomic* adsrSustain; - std::atomic* adsrRelease; - - std::atomic* delayTime; - - std::atomic* chorusRate; - std::atomic* chorusDepth; - std::atomic* chorusCentre; - std::atomic* chorusFeedback; - std::atomic* chorusMix; - - std::atomic* reverbRoomSize; - std::atomic* reverbDamping; - std::atomic* reverbWetLevel; - std::atomic* reverbDryLevel; - std::atomic* reverbWidth; - std::atomic* reverbFreezeMode; - - std::atomic* flangerRate; - std::atomic* flangerDepth; - std::atomic* flangerFeedback; - std::atomic* flangerDryMix; - std::atomic* flangerPhase; - std::atomic* flangerDelay; - - std::atomic* filterCutoff; - std::atomic* filterResonance; - std::atomic* filterType; - std::atomic* filterDrive; - std::atomic* filterMod; - std::atomic* filterKey; - - std::atomic* distortionDrive; - std::atomic* distortionMix; - std::atomic* distortionBias; - std::atomic* distortionTone; - std::atomic* distortionShape; - - std::atomic* lowGainDbls; - std::atomic* midGainDbls; - std::atomic* highGainDbls; - - std::atomic* masterDbls; -}; \ No newline at end of file +#pragma once + +#include +#include +#include + +struct SliderDetail { + std::string label; + float min, max, interval, defValue; +}; + +using ParamMap = std::unordered_map; + +// Each SliderDetail: { label, min, max, step, defaultValue } +const std::unordered_map PARAM_SETTINGS = { + { "chorus", { + { "rate", { "Rate", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "depth", { "Depth", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "centre", { "Centre", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "feedback", { "Feedback", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "mix", { "Mix", 0.0f, 1.0f, 0.1f, 0.1f } } + }}, + { "delay", { + { "delay", { "Delay", 0.0f, 1.0f, 0.1f, 0.1f } } + }}, + { "reverb", { + { "roomSize", { "Room Size", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "damping", { "Damping", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "wetLevel", { "Wet Level", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "dryLevel", { "Dry Level", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "width", { "Width", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "freezeMode", { "Freeze Mode", 0.0f, 1.0f, 0.1f, 0.1f } } + }}, + { "adsr", { + { "attack", { "Attack", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "decay", { "Decay", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "sustain", { "Sustain", 0.0f, 1.0f, 0.1f, 0.1f } }, + { "release", { "Release", 0.0f, 1.0f, 0.1f, 0.1f } } + }}, + // Filter envelope group (short key: "fenv") + { "fenv", { + { "attack", { "Attack", 0.0f, 2.0f, 0.001f, 0.01f } }, + { "decay", { "Decay", 0.0f, 2.0f, 0.001f, 0.10f } }, + { "sustain", { "Sustain", 0.0f, 1.0f, 0.001f, 0.80f } }, + { "release", { "Release", 0.0f, 4.0f, 0.001f, 0.40f } }, + { "amount", { "Amount", -1.0f, 1.0f, 0.001f, 0.50f } } + }}, + { "flanger", { + { "rate", { "Rate", 0.1f, 5.0f, 0.1f, 0.1f } }, + { "depth", { "Depth", 0.1f, 10.0f, 0.1f, 0.1f } }, // ms + { "feedback", { "Feedback", 0.0f, 0.95f, 0.01f, 0.1f } }, + { "dryMix", { "Dry/Wet", 0.0f, 1.0f, 0.01f, 0.0f } }, + { "phase", { "Phase", 0.0f, 1.0f, 0.1f, 0.0f } }, + { "delay", { "Delay", 0.0f, 3.0f, 0.1f, 0.25f } } // ms base + }}, + { "filter", { + { "cutoff", { "Cutoff", 20.0f, 20000.0f, 1.0f, 1000.0f } }, + { "resonance", { "Resonance", 0.1f, 10.0f, 0.1f, 0.7f } }, + { "type", { "L/H/B", 0.0f, 2.0f, 1.0f, 0.0f } }, + { "drive", { "Drive", 0.0f, 1.0f, 0.01f, 0.0f } }, + { "mod", { "Mod", -1.0f, 1.0f, 0.1f, 0.0f } }, + { "key", { "Key", 0.0f, 1.0f, 0.1f, 0.0f } } + }}, + { "distortion", { + { "drive", { "Drive", 0.0f, 30.0f, 0.1f, 10.0f } }, + { "mix", { "Mix", 0.0f, 1.0f, 0.01f, 0.0f } }, + { "bias", { "Bias", -1.0f, 1.0f, 0.01f, 0.0f } }, + { "tone", { "Tone", 100.0f, 8000.0f, 10.0f, 3000.0f } }, + { "shape", { "Shape", 0.0f, 2.0f, 1.0f, 0.0f } } + }} +}; + +struct NeuralSharedParams +{ + std::atomic waveform{ -1 }; + + // Amp ADSR + std::atomic* adsrAttack{}; + std::atomic* adsrDecay{}; + std::atomic* adsrSustain{}; + std::atomic* adsrRelease{}; + + // Delay + std::atomic* delayTime{}; + + // Chorus + std::atomic* chorusRate{}; + std::atomic* chorusDepth{}; + std::atomic* chorusCentre{}; + std::atomic* chorusFeedback{}; + std::atomic* chorusMix{}; + + // Reverb + std::atomic* reverbRoomSize{}; + std::atomic* reverbDamping{}; + std::atomic* reverbWetLevel{}; + std::atomic* reverbDryLevel{}; + std::atomic* reverbWidth{}; + std::atomic* reverbFreezeMode{}; + + // Flanger + std::atomic* flangerRate{}; + std::atomic* flangerDepth{}; + std::atomic* flangerFeedback{}; + std::atomic* flangerDryMix{}; + std::atomic* flangerPhase{}; + std::atomic* flangerDelay{}; + + // Filter (base) + std::atomic* filterCutoff{}; + std::atomic* filterResonance{}; + std::atomic* filterType{}; + std::atomic* filterDrive{}; + std::atomic* filterMod{}; + std::atomic* filterKey{}; + + // Filter Env (polyphonic) + std::atomic* fenvAttack{}; + std::atomic* fenvDecay{}; + std::atomic* fenvSustain{}; + std::atomic* fenvRelease{}; + std::atomic* fenvAmount{}; // +/- octaves + + // Distortion + std::atomic* distortionDrive{}; + std::atomic* distortionMix{}; + std::atomic* distortionBias{}; + std::atomic* distortionTone{}; + std::atomic* distortionShape{}; + + // Per-panel bypass (AudioParameterBool, exposed as float 0/1 via getRawParameterValue) + std::atomic* chorusOn{}; + std::atomic* delayOn{}; + std::atomic* reverbOn{}; + std::atomic* flangerOn{}; + std::atomic* distortionOn{}; + std::atomic* filterOn{}; + std::atomic* eqOn{}; + + // ==== Wavetable controls ==== + std::atomic* wtOn{}; // 0/1 (AudioParameterBool appears as float raw value) + std::atomic* wtMorph{}; // 0..15 (continuous frame index) + + // EQ + Master + std::atomic* lowGainDbls{}; + std::atomic* midGainDbls{}; + std::atomic* highGainDbls{}; + std::atomic* masterDbls{}; +};