From 225ddaa979736cb3d2d7d070a37ae37d4af7670a Mon Sep 17 00:00:00 2001 From: James H Ball Date: Sun, 19 Jan 2025 18:35:46 +0000 Subject: [PATCH] Merge trace parameters into one effect --- Source/PluginProcessor.cpp | 4 ++-- Source/PluginProcessor.h | 30 +++++++++++++++--------------- Source/audio/ShapeVoice.cpp | 29 ++++++++++++++--------------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 69db9cb6..54a20b96 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -121,8 +121,8 @@ OscirenderAudioProcessor::OscirenderAudioProcessor() : CommonAudioProcessor(Buse } )); toggleableEffects.push_back(custom); - toggleableEffects.push_back(traceLength); - toggleableEffects.push_back(traceStart); + toggleableEffects.push_back(trace); + trace->getParameter("traceLength")->lfo->setUnnormalisedValueNotifyingHost((int) LfoType::Sawtooth); for (int i = 0; i < toggleableEffects.size(); i++) { auto effect = toggleableEffects[i]; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 3c239f90..f5f658fa 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -72,21 +72,21 @@ public: ) ); - std::shared_ptr traceLength = std::make_shared( - new EffectParameter( - "Trace Length", - "Defines how much of the frame is drawn per cycle. This has the effect of 'tracing' out the image from a single dot when animated. By default, we draw the whole frame, corresponding to a value of 1.0.", - "traceLength", - VERSION_HINT, 1.0, 0.0, 1.0, 0.001, 0.001 - ) - ); - std::shared_ptr traceStart = std::make_shared( - new EffectParameter( - "Trace Start", - "Defines how far into the frame the drawing is started at. This has the effect of 'tracing' out the image from a single dot when animated. By default, we start drawing from the beginning of the frame, so this value is 0.0.", - "traceStart", - VERSION_HINT, 0.0, 0.0, 1.0, 0.001, 0.001 - ) + std::shared_ptr trace = std::make_shared( + std::vector{ + new EffectParameter( + "Trace Start", + "Defines how far into the frame the drawing is started at. This has the effect of 'tracing' out the image from a single dot when animated. By default, we start drawing from the beginning of the frame, so this value is 0.0.", + "traceStart", + VERSION_HINT, 0.0, 0.0, 1.0, 0.001, 0.001 + ), + new EffectParameter( + "Trace Length", + "Defines how much of the frame is drawn per cycle. This has the effect of 'tracing' out the image from a single dot when animated. By default, we draw the whole frame, corresponding to a value of 1.0.", + "traceLength", + VERSION_HINT, 1.0, 0.0, 1.0, 0.001, 0.001 + ), + } ); std::shared_ptr delayEffect = std::make_shared(); diff --git a/Source/audio/ShapeVoice.cpp b/Source/audio/ShapeVoice.cpp index 2d4223a1..083d796c 100644 --- a/Source/audio/ShapeVoice.cpp +++ b/Source/audio/ShapeVoice.cpp @@ -2,8 +2,8 @@ #include "../PluginProcessor.h" ShapeVoice::ShapeVoice(OscirenderAudioProcessor& p) : audioProcessor(p) { - actualTraceStart = audioProcessor.traceStart->getValue(); - actualTraceLength = audioProcessor.traceLength->getValue(); + actualTraceStart = audioProcessor.trace->getValue(0); + actualTraceLength = audioProcessor.trace->getValue(1); } bool ShapeVoice::canPlaySound(juce::SynthesiserSound* sound) { @@ -86,12 +86,11 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star } for (auto sample = startSample; sample < startSample + numSamples; ++sample) { - bool traceStartEnabled = audioProcessor.traceStart->enabled->getBoolValue(); - bool traceLengthEnabled = audioProcessor.traceLength->enabled->getBoolValue(); + bool traceEnabled = audioProcessor.trace->enabled->getBoolValue(); // update length increment - double traceLen = traceLengthEnabled ? actualTraceLength : 1.0; - double traceMin = traceStartEnabled ? actualTraceStart : 0.0; + double traceLen = traceEnabled ? actualTraceLength : 1.0; + double traceMin = traceEnabled ? actualTraceStart : 0.0; double proportionalLength = std::max(0.001, traceLen) * frameLength; lengthIncrement = juce::jmax(proportionalLength / (audioProcessor.currentSampleRate / actualFrequency), MIN_LENGTH_INCREMENT); @@ -147,11 +146,11 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star outputBuffer.addSample(0, sample, x * gain); } - double traceStartValue = audioProcessor.traceStart->getActualValue(); - double traceLengthValue = audioProcessor.traceLength->getActualValue(); - traceLengthValue = traceLengthEnabled ? traceLengthValue : 1.0; - traceStartValue = traceStartEnabled ? traceStartValue : 0.0; - actualTraceLength = std::max(0.001, traceLengthValue); + double traceStartValue = audioProcessor.trace->getActualValue(0); + double traceLengthValue = audioProcessor.trace->getActualValue(1); + traceLengthValue = traceEnabled ? traceLengthValue : 1.0; + traceStartValue = traceEnabled ? traceStartValue : 0.0; + actualTraceLength = std::max(0.01, traceLengthValue); actualTraceStart = traceStartValue; if (actualTraceStart < 0) { actualTraceStart = 0; @@ -163,7 +162,7 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star double drawnFrameLength = frameLength; bool willLoopOver = false; - if (traceLengthEnabled || traceStartEnabled) { + if (traceEnabled) { drawnFrameLength *= actualTraceLength + actualTraceStart; } @@ -172,8 +171,8 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star frameLength = sound.load()->updateFrame(frame); } frameDrawn -= drawnFrameLength; - if (traceLengthEnabled || traceStartEnabled) { - shapeDrawn = frameDrawn; + if (traceEnabled) { + shapeDrawn = juce::jlimit(0.0, frame[currentShape]->len, frameDrawn); } currentShape = 0; @@ -182,7 +181,7 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star // and shapeDrawn directly. frameDrawn is simply actualTraceStart * frameLength // but shapeDrawn is the amount of the current shape that has been drawn so // we need to iterate over all the shapes to calculate it. - if (traceStartEnabled) { + if (traceEnabled) { while (frameDrawn < actualTraceStart * frameLength) { incrementShapeDrawing(); }