kopia lustrzana https://github.com/jameshball/osci-render
Add trace min and trace max effects
rodzic
6de4e4965d
commit
011fc8bb10
|
@ -43,6 +43,8 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
|
||||||
allEffects.push_back(std::make_shared<Effect>(std::make_unique<DistortEffect>(true), "Vertical shift", "verticalDistort"));
|
allEffects.push_back(std::make_shared<Effect>(std::make_unique<DistortEffect>(true), "Vertical shift", "verticalDistort"));
|
||||||
allEffects.push_back(std::make_shared<Effect>(std::make_unique<DistortEffect>(false), "Horizontal shift", "horizontalDistort"));
|
allEffects.push_back(std::make_shared<Effect>(std::make_unique<DistortEffect>(false), "Horizontal shift", "horizontalDistort"));
|
||||||
allEffects.push_back(std::make_shared<Effect>(std::make_unique<SmoothEffect>(), "Smoothing", "smoothing"));
|
allEffects.push_back(std::make_shared<Effect>(std::make_unique<SmoothEffect>(), "Smoothing", "smoothing"));
|
||||||
|
allEffects.push_back(traceMax);
|
||||||
|
allEffects.push_back(traceMin);
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
addLuaSlider();
|
addLuaSlider();
|
||||||
|
@ -368,7 +370,10 @@ void OscirenderAudioProcessor::updateFrame() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OscirenderAudioProcessor::updateLengthIncrement() {
|
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<float>& buffer, juce::MidiBuffer& midiMessages)
|
void OscirenderAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
|
||||||
|
@ -403,11 +408,13 @@ void OscirenderAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, j
|
||||||
|
|
||||||
for (auto sample = 0; sample < numSamples; ++sample) {
|
for (auto sample = 0; sample < numSamples; ++sample) {
|
||||||
updateLengthIncrement();
|
updateLengthIncrement();
|
||||||
|
|
||||||
|
traceMaxEnabled = false;
|
||||||
|
traceMinEnabled = false;
|
||||||
|
|
||||||
Vector2 channels;
|
Vector2 channels;
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double length = 0.0;
|
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<FileParser> sampleParser;
|
std::shared_ptr<FileParser> sampleParser;
|
||||||
|
@ -423,7 +430,7 @@ void OscirenderAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, j
|
||||||
channels = sampleParser->nextSample();
|
channels = sampleParser->nextSample();
|
||||||
} else if (currentShape < frame.size()) {
|
} else if (currentShape < frame.size()) {
|
||||||
auto& shape = frame[currentShape];
|
auto& shape = frame[currentShape];
|
||||||
length = shape->length();
|
double length = shape->length();
|
||||||
double drawingProgress = length == 0.0 ? 1 : shapeDrawn / length;
|
double drawingProgress = length == 0.0 ? 1 : shapeDrawn / length;
|
||||||
channels = shape->nextVector(drawingProgress);
|
channels = shape->nextVector(drawingProgress);
|
||||||
}
|
}
|
||||||
|
@ -449,31 +456,23 @@ void OscirenderAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, j
|
||||||
} else if (totalNumOutputChannels == 1) {
|
} else if (totalNumOutputChannels == 1) {
|
||||||
channelData[0][sample] = x;
|
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) {
|
if (!renderingSample) {
|
||||||
// hard cap on how many times it can be over the length to
|
incrementShapeDrawing();
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double drawnFrameLength = traceMaxEnabled ? actualTraceMax * frameLength : frameLength;
|
||||||
|
|
||||||
if (!renderingSample && frameDrawn >= frameLength) {
|
if (!renderingSample && frameDrawn >= drawnFrameLength) {
|
||||||
updateFrame();
|
updateFrame();
|
||||||
|
if (traceMinEnabled) {
|
||||||
|
while (frameDrawn < actualTraceMin * frameLength) {
|
||||||
|
incrementShapeDrawing();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,6 +490,29 @@ void OscirenderAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, j
|
||||||
midiMessages.swapWith(processedMidi);
|
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
|
bool OscirenderAudioProcessor::hasEditor() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -201,8 +201,33 @@ private:
|
||||||
double lengthIncrement = 0.0;
|
double lengthIncrement = 0.0;
|
||||||
bool invalidateFrameBuffer = false;
|
bool invalidateFrameBuffer = false;
|
||||||
|
|
||||||
|
std::shared_ptr<Effect> traceMax = std::make_shared<Effect>(
|
||||||
|
[this](int index, Vector2 input, double value, double frequency, double sampleRate) {
|
||||||
|
traceMaxEnabled = true;
|
||||||
|
return input;
|
||||||
|
},
|
||||||
|
"Trace max",
|
||||||
|
"traceMax",
|
||||||
|
1
|
||||||
|
);
|
||||||
|
std::shared_ptr<Effect> traceMin = std::make_shared<Effect>(
|
||||||
|
[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 updateFrame();
|
||||||
void updateLengthIncrement();
|
void updateLengthIncrement();
|
||||||
|
void incrementShapeDrawing();
|
||||||
void openFile(int index);
|
void openFile(int index);
|
||||||
void updateLuaValues();
|
void updateLuaValues();
|
||||||
void updateObjValues();
|
void updateObjValues();
|
||||||
|
|
|
@ -30,9 +30,8 @@ void EffectComponent::componentSetup() {
|
||||||
EffectComponent::~EffectComponent() {}
|
EffectComponent::~EffectComponent() {}
|
||||||
|
|
||||||
void EffectComponent::resized() {
|
void EffectComponent::resized() {
|
||||||
auto sliderRight = getWidth() - 140;
|
auto sliderRight = getWidth() - 160;
|
||||||
auto bounds = getLocalBounds();
|
auto bounds = getLocalBounds();
|
||||||
bounds.removeFromRight(10);
|
|
||||||
auto componentBounds = bounds.removeFromRight(25);
|
auto componentBounds = bounds.removeFromRight(25);
|
||||||
if (component != nullptr) {
|
if (component != nullptr) {
|
||||||
component->setBounds(componentBounds);
|
component->setBounds(componentBounds);
|
||||||
|
|
Ładowanie…
Reference in New Issue