Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pure-binary grease pencil line art files #248

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Reaper project used to create the above demo: [square_spiral.rpp](projects/squar
- Render text
- Scriptable visuals and audio effects using Lua
- Blender integration
- 3D animation via Grease Pencil Line Art
- Saving animations to disk
- Software oscilloscope
- Applying image effects
- Bit Crush
Expand Down
50 changes: 28 additions & 22 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,24 +658,25 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
auto* channelData = buffer.getArrayOfWritePointers();


for (int sample = 0; sample < buffer.getNumSamples(); ++sample) {
for (int sample = 0; sample < buffer.getNumSamples(); ++sample) {

// Update frame animation
if (animateFrames->getValue()) {
if (animationSyncBPM->getValue()) {
animationTime = playTimeBeats;
} else {
}
else {
animationTime = playTimeSeconds;
}

juce::SpinLock::ScopedLockType lock1(parsersLock);
juce::SpinLock::ScopedLockType lock2(effectsLock);
if (currentFile >= 0 && sounds[currentFile]->parser->isAnimatable) {
int animFrame = (int)(animationTime * animationRate->getValueUnnormalised() + animationOffset->getValueUnnormalised());
auto lineArt = sounds[currentFile]->parser->getLineArt();
auto binLineArt = sounds[currentFile]->parser->getBinaryLineArt();
auto img = sounds[currentFile]->parser->getImg();
if (lineArt != nullptr) {
lineArt->setFrame(animFrame);
if (binLineArt != nullptr) {
binLineArt->setFrame(animFrame);
} else if (img != nullptr) {
img->setFrame(animFrame);
}
Expand All @@ -687,7 +688,8 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
if (totalNumInputChannels >= 2) {
left = inputBuffer.getSample(0, sample);
right = inputBuffer.getSample(1, sample);
} else if (totalNumInputChannels == 1) {
}
else if (totalNumInputChannels == 1) {
left = inputBuffer.getSample(0, sample);
right = inputBuffer.getSample(0, sample);
}
Expand All @@ -702,27 +704,31 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
currentVolume = juce::jlimit(0.0, 1.0, currentVolume);

Point channels = { outputBuffer3d.getSample(0, sample), outputBuffer3d.getSample(1, sample), outputBuffer3d.getSample(2, sample) };
Point exIn = { left, right };

{
juce::SpinLock::ScopedLockType lock1(parsersLock);
juce::SpinLock::ScopedLockType lock2(effectsLock);
if (volume > EPSILON) {
for (auto& effect : toggleableEffects) {
if (effect->enabled->getValue()) {
channels = effect->apply(sample, channels, currentVolume);
}
juce::SpinLock::ScopedLockType lock1(parsersLock);
juce::SpinLock::ScopedLockType lock2(effectsLock);
if (volume > EPSILON) {
for (auto& effect : toggleableEffects) {
if (effect->enabled->getValue()) {
effect->extInput(exIn);
channels = effect->apply(sample, channels, currentVolume);
}
}
for (auto& effect : permanentEffects) {
channels = effect->apply(sample, channels, currentVolume);
}
auto lua = currentFile >= 0 ? sounds[currentFile]->parser->getLua() : nullptr;
if (lua != nullptr || custom->enabled->getBoolValue()) {
for (auto& effect : luaEffects) {
effect->apply(sample, channels, currentVolume);
}
}
for (auto& effect : permanentEffects) {
effect->extInput(exIn);
channels = effect->apply(sample, channels, currentVolume);
}
// looks like nothing is done from here
auto lua = currentFile >= 0 ? sounds[currentFile]->parser->getLua() : nullptr;
if (lua != nullptr || custom->enabled->getBoolValue()) {
for (auto& effect : luaEffects) {
effect->extInput(exIn);
effect->apply(sample, channels, currentVolume);
}
}
// to here. can I delete it?

double x = channels.x;
double y = channels.y;
Expand Down
15 changes: 8 additions & 7 deletions Source/audio/CustomEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ Point CustomEffect::apply(int index, Point input, const std::vector<std::atomic<
std::copy(std::begin(luaValues), std::end(luaValues), std::begin(vars.sliders));

auto result = parser->run(L, vars);
if (result.size() >= 2) {
x = result[0];
y = result[1];
if (result.size() >= 3) {
z = result[2];
}
}
int rs = result.size();

if (rs < 1) return input;

x = result[0];
y = (rs > 1) ? result[1] : y;
z = (rs > 2) ? result[2] : z;

} else {
parser->resetErrors();
}
Expand Down
5 changes: 5 additions & 0 deletions Source/audio/CustomEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class CustomEffect : public EffectApplication {

Point apply(int index, Point input, const std::vector<std::atomic<double>>& values, double sampleRate) override;
void updateCode(const juce::String& newCode);
void extInput(Point newInput) {
vars.ext_x = newInput.x;
vars.ext_y = newInput.y;
return;
}

juce::String getCode();

Expand Down
6 changes: 3 additions & 3 deletions Source/audio/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Effect::Effect(EffectParameter* parameter) : Effect([](int index, Point input, c

Point Effect::apply(int index, Point input, double volume) {
animateValues(volume);
if (application) {
return application(index, input, actualValues, sampleRate);
} else if (effectApplication != nullptr) {
if (effectApplication != nullptr) {
return effectApplication->apply(index, input, actualValues, sampleRate);
} else if (application) {
return application(index, input, actualValues, sampleRate);
}
return input;
}
Expand Down
5 changes: 5 additions & 0 deletions Source/audio/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "BooleanParameter.h"

typedef std::function<Point(int index, Point input, const std::vector<std::atomic<double>>& values, double sampleRate)> EffectApplicationType;
typedef std::function<void(Point newInput)> ExtInputType;

class Effect {
public:
Expand All @@ -17,6 +18,10 @@ class Effect {
Effect(EffectParameter* parameter);

Point apply(int index, Point input, double volume = 0.0);
void extInput(Point newInput) {
effectApplication->extInput(newInput);
return;
}

void apply();
double getValue(int index);
Expand Down
1 change: 1 addition & 0 deletions Source/audio/EffectApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class EffectApplication {
EffectApplication() {};

virtual Point apply(int index, Point input, const std::vector<std::atomic<double>>& values, double sampleRate) = 0;
void extInput(Point newInput) { return; }

void resetPhase();
double nextPhase(double frequency, double sampleRate);
Expand Down
10 changes: 9 additions & 1 deletion Source/audio/ShapeVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ void ShapeVoice::updateSound(juce::SynthesiserSound* sound) {
}
}

void ShapeVoice::extInput(juce::AudioSampleBuffer& inputBuffer)
{
exIn = inputBuffer;
}

void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int startSample, int numSamples) {
juce::ScopedNoDenormals noDenormals;

Expand Down Expand Up @@ -111,7 +116,10 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star
vars.sampleRate = audioProcessor.currentSampleRate;
vars.frequency = actualFrequency;
std::copy(std::begin(audioProcessor.luaValues), std::end(audioProcessor.luaValues), std::begin(vars.sliders));

if (exIn.getNumChannels() > 1 && exIn.getNumSamples() >= startSample + numSamples) {
vars.ext_x = exIn.getSample(0, sample);
vars.ext_y = exIn.getSample(1, sample);
}
channels = parser->nextSample(L, vars);
} else if (currentShape < frame.size()) {
auto& shape = frame[currentShape];
Expand Down
4 changes: 4 additions & 0 deletions Source/audio/ShapeVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ShapeVoice : public juce::SynthesiserVoice {
void pitchWheelMoved(int newPitchWheelValue) override;
void controllerMoved(int controllerNumber, int newControllerValue) override;

void extInput(juce::AudioSampleBuffer& inputBuffer);


void incrementShapeDrawing();
double getFrequency();
Expand Down Expand Up @@ -51,5 +53,7 @@ class ShapeVoice : public juce::SynthesiserVoice {
double endTime = 99999999;
bool waitingForRelease = false;

juce::AudioSampleBuffer exIn;

void noteStopped();
};
Loading