diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index e7d3c23..699867e 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -43,6 +43,8 @@ OscirenderAudioProcessor::OscirenderAudioProcessor() allEffects.push_back(std::make_shared(std::make_unique(true), "Vertical shift", "verticalDistort")); allEffects.push_back(std::make_shared(std::make_unique(false), "Horizontal shift", "horizontalDistort")); allEffects.push_back(std::make_shared(std::make_unique(), "Smoothing", "smoothing")); + allEffects.push_back(traceMax); + allEffects.push_back(traceMin); for (int i = 0; i < 5; i++) { addLuaSlider(); @@ -368,7 +370,10 @@ void OscirenderAudioProcessor::updateFrame() { } void OscirenderAudioProcessor::updateLengthIncrement() { - lengthIncrement = std::max(frameLength / (currentSampleRate / frequency), MIN_LENGTH_INCREMENT); + double traceMaxValue = traceMaxEnabled ? actualTraceMax : 1.0; + double traceMinValue = traceMinEnabled ? actualTraceMin : 0.0; + double proportionalLength = (traceMaxValue - traceMinValue) * frameLength; + lengthIncrement = std::max(proportionalLength / (currentSampleRate / frequency), MIN_LENGTH_INCREMENT); } void OscirenderAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages) @@ -403,11 +408,13 @@ void OscirenderAudioProcessor::processBlock (juce::AudioBuffer& buffer, j for (auto sample = 0; sample < numSamples; ++sample) { updateLengthIncrement(); + + traceMaxEnabled = false; + traceMinEnabled = false; Vector2 channels; double x = 0.0; double y = 0.0; - double length = 0.0; std::shared_ptr sampleParser; @@ -423,7 +430,7 @@ void OscirenderAudioProcessor::processBlock (juce::AudioBuffer& buffer, j channels = sampleParser->nextSample(); } else if (currentShape < frame.size()) { auto& shape = frame[currentShape]; - length = shape->length(); + double length = shape->length(); double drawingProgress = length == 0.0 ? 1 : shapeDrawn / length; channels = shape->nextVector(drawingProgress); } @@ -449,31 +456,23 @@ void OscirenderAudioProcessor::processBlock (juce::AudioBuffer& buffer, j } else if (totalNumOutputChannels == 1) { channelData[0][sample] = x; } + + actualTraceMax = std::max(actualTraceMin + MIN_TRACE, std::min(traceMax->getValue(), 1.0)); + actualTraceMin = std::max(MIN_TRACE, std::min(traceMin->getValue(), actualTraceMax - MIN_TRACE)); if (!renderingSample) { - // hard cap on how many times it can be over the length to - // prevent audio stuttering - frameDrawn += std::min(lengthIncrement, 20 * length); - shapeDrawn += std::min(lengthIncrement, 20 * length); - - // Need to skip all shapes that the lengthIncrement draws over. - // This is especially an issue when there are lots of small lines being - // drawn. - while (shapeDrawn > length) { - shapeDrawn -= length; - currentShape++; - if (currentShape >= frame.size()) { - currentShape = 0; - break; - } - // POTENTIAL TODO: Think of a way to make this more efficient when iterating - // this loop many times - length = frame[currentShape]->len; - } + incrementShapeDrawing(); } + + double drawnFrameLength = traceMaxEnabled ? actualTraceMax * frameLength : frameLength; - if (!renderingSample && frameDrawn >= frameLength) { + if (!renderingSample && frameDrawn >= drawnFrameLength) { updateFrame(); + if (traceMinEnabled) { + while (frameDrawn < actualTraceMin * frameLength) { + incrementShapeDrawing(); + } + } } } @@ -491,6 +490,29 @@ void OscirenderAudioProcessor::processBlock (juce::AudioBuffer& buffer, j midiMessages.swapWith(processedMidi); } +void OscirenderAudioProcessor::incrementShapeDrawing() { + double length = currentShape < frame.size() ? frame[currentShape]->len : 0.0; + // hard cap on how many times it can be over the length to + // prevent audio stuttering + frameDrawn += std::min(lengthIncrement, 20 * length); + shapeDrawn += std::min(lengthIncrement, 20 * length); + + // Need to skip all shapes that the lengthIncrement draws over. + // This is especially an issue when there are lots of small lines being + // drawn. + while (shapeDrawn > length) { + shapeDrawn -= length; + currentShape++; + if (currentShape >= frame.size()) { + currentShape = 0; + break; + } + // POTENTIAL TODO: Think of a way to make this more efficient when iterating + // this loop many times + length = frame[currentShape]->len; + } +} + //============================================================================== bool OscirenderAudioProcessor::hasEditor() const { diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index f3a889d..23fae77 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -201,8 +201,33 @@ private: double lengthIncrement = 0.0; bool invalidateFrameBuffer = false; + std::shared_ptr traceMax = std::make_shared( + [this](int index, Vector2 input, double value, double frequency, double sampleRate) { + traceMaxEnabled = true; + return input; + }, + "Trace max", + "traceMax", + 1 + ); + std::shared_ptr traceMin = std::make_shared( + [this](int index, Vector2 input, double value, double frequency, double sampleRate) { + traceMinEnabled = true; + return input; + }, + "Trace min", + "traceMin", + 0 + ); + const double MIN_TRACE = 0.005; + double actualTraceMax = traceMax->getValue(); + double actualTraceMin = traceMin->getValue(); + bool traceMaxEnabled = false; + bool traceMinEnabled = false; + void updateFrame(); void updateLengthIncrement(); + void incrementShapeDrawing(); void openFile(int index); void updateLuaValues(); void updateObjValues(); diff --git a/Source/components/EffectComponent.cpp b/Source/components/EffectComponent.cpp index 9c7455a..a9b7519 100644 --- a/Source/components/EffectComponent.cpp +++ b/Source/components/EffectComponent.cpp @@ -30,9 +30,8 @@ void EffectComponent::componentSetup() { EffectComponent::~EffectComponent() {} void EffectComponent::resized() { - auto sliderRight = getWidth() - 140; + auto sliderRight = getWidth() - 160; auto bounds = getLocalBounds(); - bounds.removeFromRight(10); auto componentBounds = bounds.removeFromRight(25); if (component != nullptr) { component->setBounds(componentBounds);