kopia lustrzana https://github.com/jameshball/osci-render
Rename Vector2 to Point
rodzic
9376b5d715
commit
8a91099c55
|
@ -59,7 +59,7 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
|
||||||
new EffectParameter("Distort Y", "Distorts the image in the vertical direction by jittering the audio sample being drawn.", "distortY", VERSION_HINT, 0.0, 0.0, 1.0)
|
new EffectParameter("Distort Y", "Distorts the image in the vertical direction by jittering the audio sample being drawn.", "distortY", VERSION_HINT, 0.0, 0.0, 1.0)
|
||||||
));
|
));
|
||||||
toggleableEffects.push_back(std::make_shared<Effect>(
|
toggleableEffects.push_back(std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
input.x += values[0];
|
input.x += values[0];
|
||||||
input.y += values[1];
|
input.y += values[1];
|
||||||
return input;
|
return input;
|
||||||
|
@ -612,7 +612,7 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
|
||||||
currentVolume = std::sqrt(squaredVolume);
|
currentVolume = std::sqrt(squaredVolume);
|
||||||
currentVolume = juce::jlimit(0.0, 1.0, currentVolume);
|
currentVolume = juce::jlimit(0.0, 1.0, currentVolume);
|
||||||
|
|
||||||
Vector2 channels;
|
Point channels;
|
||||||
if (totalNumOutputChannels >= 2) {
|
if (totalNumOutputChannels >= 2) {
|
||||||
channels = {buffer.getSample(0, sample), buffer.getSample(1, sample)};
|
channels = {buffer.getSample(0, sample), buffer.getSample(1, sample)};
|
||||||
} else if (totalNumOutputChannels == 1) {
|
} else if (totalNumOutputChannels == 1) {
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
std::vector<std::shared_ptr<Effect>> luaEffects;
|
std::vector<std::shared_ptr<Effect>> luaEffects;
|
||||||
|
|
||||||
std::shared_ptr<Effect> frequencyEffect = std::make_shared<Effect>(
|
std::shared_ptr<Effect> frequencyEffect = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
frequency = values[0];
|
frequency = values[0];
|
||||||
return input;
|
return input;
|
||||||
}, new EffectParameter(
|
}, new EffectParameter(
|
||||||
|
@ -90,7 +90,7 @@ public:
|
||||||
);
|
);
|
||||||
|
|
||||||
std::shared_ptr<Effect> volumeEffect = std::make_shared<Effect>(
|
std::shared_ptr<Effect> volumeEffect = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
volume = values[0];
|
volume = values[0];
|
||||||
return input;
|
return input;
|
||||||
}, new EffectParameter(
|
}, new EffectParameter(
|
||||||
|
@ -102,7 +102,7 @@ public:
|
||||||
);
|
);
|
||||||
|
|
||||||
std::shared_ptr<Effect> thresholdEffect = std::make_shared<Effect>(
|
std::shared_ptr<Effect> thresholdEffect = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
threshold = values[0];
|
threshold = values[0];
|
||||||
return input;
|
return input;
|
||||||
}, new EffectParameter(
|
}, new EffectParameter(
|
||||||
|
@ -114,7 +114,7 @@ public:
|
||||||
);
|
);
|
||||||
|
|
||||||
std::shared_ptr<Effect> focalLength = std::make_shared<Effect>(
|
std::shared_ptr<Effect> focalLength = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
if (getCurrentFileIndex() != -1) {
|
if (getCurrentFileIndex() != -1) {
|
||||||
auto camera = getCurrentFileParser()->getCamera();
|
auto camera = getCurrentFileParser()->getCamera();
|
||||||
if (camera == nullptr) return input;
|
if (camera == nullptr) return input;
|
||||||
|
@ -133,7 +133,7 @@ public:
|
||||||
BooleanParameter* fixedRotateY = new BooleanParameter("Object Fixed Rotate Y", "objFixedRotateY", VERSION_HINT, false);
|
BooleanParameter* fixedRotateY = new BooleanParameter("Object Fixed Rotate Y", "objFixedRotateY", VERSION_HINT, false);
|
||||||
BooleanParameter* fixedRotateZ = new BooleanParameter("Object Fixed Rotate Z", "objFixedRotateZ", VERSION_HINT, false);
|
BooleanParameter* fixedRotateZ = new BooleanParameter("Object Fixed Rotate Z", "objFixedRotateZ", VERSION_HINT, false);
|
||||||
std::shared_ptr<Effect> rotateX = std::make_shared<Effect>(
|
std::shared_ptr<Effect> rotateX = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
if (getCurrentFileIndex() != -1) {
|
if (getCurrentFileIndex() != -1) {
|
||||||
auto obj = getCurrentFileParser()->getObject();
|
auto obj = getCurrentFileParser()->getObject();
|
||||||
if (obj == nullptr) return input;
|
if (obj == nullptr) return input;
|
||||||
|
@ -153,7 +153,7 @@ public:
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> rotateY = std::make_shared<Effect>(
|
std::shared_ptr<Effect> rotateY = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
if (getCurrentFileIndex() != -1) {
|
if (getCurrentFileIndex() != -1) {
|
||||||
auto obj = getCurrentFileParser()->getObject();
|
auto obj = getCurrentFileParser()->getObject();
|
||||||
if (obj == nullptr) return input;
|
if (obj == nullptr) return input;
|
||||||
|
@ -173,7 +173,7 @@ public:
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> rotateZ = std::make_shared<Effect>(
|
std::shared_ptr<Effect> rotateZ = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
if (getCurrentFileIndex() != -1) {
|
if (getCurrentFileIndex() != -1) {
|
||||||
auto obj = getCurrentFileParser()->getObject();
|
auto obj = getCurrentFileParser()->getObject();
|
||||||
if (obj == nullptr) return input;
|
if (obj == nullptr) return input;
|
||||||
|
@ -193,7 +193,7 @@ public:
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> rotateSpeed = std::make_shared<Effect>(
|
std::shared_ptr<Effect> rotateSpeed = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
if (getCurrentFileIndex() != -1) {
|
if (getCurrentFileIndex() != -1) {
|
||||||
auto obj = getCurrentFileParser()->getObject();
|
auto obj = getCurrentFileParser()->getObject();
|
||||||
if (obj == nullptr) return input;
|
if (obj == nullptr) return input;
|
||||||
|
@ -209,7 +209,7 @@ public:
|
||||||
);
|
);
|
||||||
|
|
||||||
std::shared_ptr<Effect> traceMax = std::make_shared<Effect>(
|
std::shared_ptr<Effect> traceMax = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
return input;
|
return input;
|
||||||
}, new EffectParameter(
|
}, new EffectParameter(
|
||||||
"Trace max",
|
"Trace max",
|
||||||
|
@ -219,7 +219,7 @@ public:
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
std::shared_ptr<Effect> traceMin = std::make_shared<Effect>(
|
std::shared_ptr<Effect> traceMin = std::make_shared<Effect>(
|
||||||
[this](int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
return input;
|
return input;
|
||||||
}, new EffectParameter(
|
}, new EffectParameter(
|
||||||
"Trace min",
|
"Trace min",
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
BitCrushEffect::BitCrushEffect() {}
|
BitCrushEffect::BitCrushEffect() {}
|
||||||
|
|
||||||
// algorithm from https://www.kvraudio.com/forum/viewtopic.php?t=163880
|
// algorithm from https://www.kvraudio.com/forum/viewtopic.php?t=163880
|
||||||
Vector2 BitCrushEffect::apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
Point BitCrushEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
double value = values[0];
|
double value = values[0];
|
||||||
// change rage of value from 0-1 to 0.0-0.78
|
// change rage of value from 0-1 to 0.0-0.78
|
||||||
double rangedValue = value * 0.78;
|
double rangedValue = value * 0.78;
|
||||||
|
@ -12,5 +12,5 @@ Vector2 BitCrushEffect::apply(int index, Vector2 input, const std::vector<double
|
||||||
double x = powf(2.0f, crush);
|
double x = powf(2.0f, crush);
|
||||||
double quant = 0.5 * x;
|
double quant = 0.5 * x;
|
||||||
double dequant = 1.0f / quant;
|
double dequant = 1.0f / quant;
|
||||||
return Vector2(dequant * (int)(input.x * quant), dequant * (int)(input.y * quant));
|
return Point(dequant * (int)(input.x * quant), dequant * (int)(input.y * quant));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
|
|
||||||
class BitCrushEffect : public EffectApplication {
|
class BitCrushEffect : public EffectApplication {
|
||||||
public:
|
public:
|
||||||
BitCrushEffect();
|
BitCrushEffect();
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
|
|
||||||
class BooleanParameter : public juce::AudioProcessorParameterWithID {
|
class BooleanParameter : public juce::AudioProcessorParameterWithID {
|
||||||
|
|
|
@ -4,7 +4,7 @@ BulgeEffect::BulgeEffect() {}
|
||||||
|
|
||||||
BulgeEffect::~BulgeEffect() {}
|
BulgeEffect::~BulgeEffect() {}
|
||||||
|
|
||||||
Vector2 BulgeEffect::apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
Point BulgeEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
double value = values[0];
|
double value = values[0];
|
||||||
double translatedBulge = -value + 1;
|
double translatedBulge = -value + 1;
|
||||||
|
|
||||||
|
@ -12,5 +12,5 @@ Vector2 BulgeEffect::apply(int index, Vector2 input, const std::vector<double>&
|
||||||
double theta = atan2(input.y, input.x);
|
double theta = atan2(input.y, input.x);
|
||||||
double rn = pow(r, translatedBulge);
|
double rn = pow(r, translatedBulge);
|
||||||
|
|
||||||
return Vector2(rn * cos(theta), rn * sin(theta));
|
return Point(rn * cos(theta), rn * sin(theta));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
|
|
||||||
class BulgeEffect : public EffectApplication {
|
class BulgeEffect : public EffectApplication {
|
||||||
public:
|
public:
|
||||||
BulgeEffect();
|
BulgeEffect();
|
||||||
~BulgeEffect();
|
~BulgeEffect();
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>&, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>&, double sampleRate) override;
|
||||||
};
|
};
|
|
@ -4,7 +4,7 @@ DelayEffect::DelayEffect() {}
|
||||||
|
|
||||||
DelayEffect::~DelayEffect() {}
|
DelayEffect::~DelayEffect() {}
|
||||||
|
|
||||||
Vector2 DelayEffect::apply(int index, Vector2 vector, const std::vector<double>& values, double sampleRate) {
|
Point DelayEffect::apply(int index, Point vector, const std::vector<double>& values, double sampleRate) {
|
||||||
double decay = values[0];
|
double decay = values[0];
|
||||||
double decayLength = values[1];
|
double decayLength = values[1];
|
||||||
int delayBufferLength = (int)(sampleRate * decayLength);
|
int delayBufferLength = (int)(sampleRate * decayLength);
|
||||||
|
@ -22,8 +22,8 @@ Vector2 DelayEffect::apply(int index, Vector2 vector, const std::vector<double>&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 echo = delayBuffer[position];
|
Point echo = delayBuffer[position];
|
||||||
vector = Vector2(
|
vector = Point(
|
||||||
vector.x + echo.x * decay,
|
vector.x + echo.x * decay,
|
||||||
vector.y + echo.y * decay
|
vector.y + echo.y * decay
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
|
|
||||||
class DelayEffect : public EffectApplication {
|
class DelayEffect : public EffectApplication {
|
||||||
public:
|
public:
|
||||||
DelayEffect();
|
DelayEffect();
|
||||||
~DelayEffect();
|
~DelayEffect();
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const static int MAX_DELAY = 192000 * 10;
|
const static int MAX_DELAY = 192000 * 10;
|
||||||
std::vector<Vector2> delayBuffer = std::vector<Vector2>(MAX_DELAY);
|
std::vector<Point> delayBuffer = std::vector<Point>(MAX_DELAY);
|
||||||
int head = 0;
|
int head = 0;
|
||||||
int position = 0;
|
int position = 0;
|
||||||
int samplesSinceLastDelay = 0;
|
int samplesSinceLastDelay = 0;
|
||||||
|
|
|
@ -4,7 +4,7 @@ DistortEffect::DistortEffect(bool vertical) : vertical(vertical) {}
|
||||||
|
|
||||||
DistortEffect::~DistortEffect() {}
|
DistortEffect::~DistortEffect() {}
|
||||||
|
|
||||||
Vector2 DistortEffect::apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
Point DistortEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
double value = values[0];
|
double value = values[0];
|
||||||
int vertical = (int)this->vertical;
|
int vertical = (int)this->vertical;
|
||||||
if (index % 2 == 0) {
|
if (index % 2 == 0) {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
|
|
||||||
class DistortEffect : public EffectApplication {
|
class DistortEffect : public EffectApplication {
|
||||||
public:
|
public:
|
||||||
DistortEffect(bool vertical);
|
DistortEffect(bool vertical);
|
||||||
~DistortEffect();
|
~DistortEffect();
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
||||||
private:
|
private:
|
||||||
bool vertical;
|
bool vertical;
|
||||||
};
|
};
|
|
@ -17,7 +17,7 @@ Effect::Effect(EffectApplicationType application, const std::vector<EffectParame
|
||||||
|
|
||||||
Effect::Effect(EffectApplicationType application, EffectParameter* parameter) : Effect(application, std::vector<EffectParameter*>{parameter}) {}
|
Effect::Effect(EffectApplicationType application, EffectParameter* parameter) : Effect(application, std::vector<EffectParameter*>{parameter}) {}
|
||||||
|
|
||||||
Vector2 Effect::apply(int index, Vector2 input, double volume) {
|
Point Effect::apply(int index, Point input, double volume) {
|
||||||
animateValues(volume);
|
animateValues(volume);
|
||||||
if (application) {
|
if (application) {
|
||||||
return application(index, input, actualValues, sampleRate);
|
return application(index, input, actualValues, sampleRate);
|
||||||
|
@ -90,7 +90,7 @@ float Effect::nextPhase(EffectParameter* parameter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Effect::apply() {
|
void Effect::apply() {
|
||||||
apply(0, Vector2());
|
apply(0, Point());
|
||||||
}
|
}
|
||||||
|
|
||||||
double Effect::getValue(int index) {
|
double Effect::getValue(int index) {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "EffectParameter.h"
|
#include "EffectParameter.h"
|
||||||
#include "BooleanParameter.h"
|
#include "BooleanParameter.h"
|
||||||
|
|
||||||
typedef std::function<Vector2(int index, Vector2 input, const std::vector<double>& values, double sampleRate)> EffectApplicationType;
|
typedef std::function<Point(int index, Point input, const std::vector<double>& values, double sampleRate)> EffectApplicationType;
|
||||||
|
|
||||||
class Effect {
|
class Effect {
|
||||||
public:
|
public:
|
||||||
|
@ -14,7 +14,7 @@ public:
|
||||||
Effect(EffectApplicationType application, const std::vector<EffectParameter*>& parameters);
|
Effect(EffectApplicationType application, const std::vector<EffectParameter*>& parameters);
|
||||||
Effect(EffectApplicationType application, EffectParameter* parameter);
|
Effect(EffectApplicationType application, EffectParameter* parameter);
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, double volume = 0.0);
|
Point apply(int index, Point input, double volume = 0.0);
|
||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
double getValue(int index);
|
double getValue(int index);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
|
|
||||||
class EffectApplication {
|
class EffectApplication {
|
||||||
public:
|
public:
|
||||||
EffectApplication() {};
|
EffectApplication() {};
|
||||||
|
|
||||||
virtual Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) = 0;
|
virtual Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) = 0;
|
||||||
|
|
||||||
void resetPhase();
|
void resetPhase();
|
||||||
double nextPhase(double frequency, double sampleRate);
|
double nextPhase(double frequency, double sampleRate);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
#include "BooleanParameter.h"
|
#include "BooleanParameter.h"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "LuaEffect.h"
|
#include "LuaEffect.h"
|
||||||
#include "../lua/LuaParser.h"
|
#include "../lua/LuaParser.h"
|
||||||
|
|
||||||
Vector2 LuaEffect::apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
Point LuaEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
int fileIndex = audioProcessor.getCurrentFileIndex();
|
int fileIndex = audioProcessor.getCurrentFileIndex();
|
||||||
if (fileIndex == -1) {
|
if (fileIndex == -1) {
|
||||||
return input;
|
return input;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
#include "../audio/Effect.h"
|
#include "../audio/Effect.h"
|
||||||
#include "../PluginProcessor.h"
|
#include "../PluginProcessor.h"
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ class LuaEffect : public EffectApplication {
|
||||||
public:
|
public:
|
||||||
LuaEffect(juce::String name, OscirenderAudioProcessor& p) : audioProcessor(p), name(name) {};
|
LuaEffect(juce::String name, OscirenderAudioProcessor& p) : audioProcessor(p), name(name) {};
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
||||||
private:
|
private:
|
||||||
OscirenderAudioProcessor& audioProcessor;
|
OscirenderAudioProcessor& audioProcessor;
|
||||||
juce::String name;
|
juce::String name;
|
||||||
|
|
|
@ -14,7 +14,7 @@ PerspectiveEffect::~PerspectiveEffect() {
|
||||||
parser->close(L);
|
parser->close(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 PerspectiveEffect::apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
Point PerspectiveEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
auto effectScale = values[0];
|
auto effectScale = values[0];
|
||||||
auto depth = 1.0 + (values[1] - 0.1) * 3;
|
auto depth = 1.0 + (values[1] - 0.1) * 3;
|
||||||
auto rotateSpeed = linearSpeedToActualSpeed(values[2]);
|
auto rotateSpeed = linearSpeedToActualSpeed(values[2]);
|
||||||
|
@ -88,7 +88,7 @@ Vector2 PerspectiveEffect::apply(int index, Vector2 input, const std::vector<dou
|
||||||
|
|
||||||
// perspective projection
|
// perspective projection
|
||||||
auto focalLength = 1.0;
|
auto focalLength = 1.0;
|
||||||
return Vector2(
|
return Point(
|
||||||
(1 - effectScale) * input.x + effectScale * (x3 * focalLength / (z3 - depth)),
|
(1 - effectScale) * input.x + effectScale * (x3 * focalLength / (z3 - depth)),
|
||||||
(1 - effectScale) * input.y + effectScale * (y3 * focalLength / (z3 - depth))
|
(1 - effectScale) * input.y + effectScale * (y3 * focalLength / (z3 - depth))
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
#include "../audio/Effect.h"
|
#include "../audio/Effect.h"
|
||||||
#include "../lua/LuaParser.h"
|
#include "../lua/LuaParser.h"
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ public:
|
||||||
// arbitrary UUID
|
// arbitrary UUID
|
||||||
static const juce::String FILE_NAME;
|
static const juce::String FILE_NAME;
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
||||||
void updateCode(const juce::String& newCode);
|
void updateCode(const juce::String& newCode);
|
||||||
void setVariable(juce::String variableName, double value);
|
void setVariable(juce::String variableName, double value);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ RotateEffect::RotateEffect() {}
|
||||||
|
|
||||||
RotateEffect::~RotateEffect() {}
|
RotateEffect::~RotateEffect() {}
|
||||||
|
|
||||||
Vector2 RotateEffect::apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
Point RotateEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
input.rotate(nextPhase(values[0], sampleRate));
|
input.rotate(nextPhase(values[0], sampleRate));
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
|
|
||||||
class RotateEffect : public EffectApplication {
|
class RotateEffect : public EffectApplication {
|
||||||
public:
|
public:
|
||||||
RotateEffect();
|
RotateEffect();
|
||||||
~RotateEffect();
|
~RotateEffect();
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
||||||
};
|
};
|
|
@ -89,7 +89,7 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star
|
||||||
double proportionalLength = (traceMax - traceMin) * frameLength;
|
double proportionalLength = (traceMax - traceMin) * frameLength;
|
||||||
lengthIncrement = juce::jmax(proportionalLength / (audioProcessor.currentSampleRate / frequency), MIN_LENGTH_INCREMENT);
|
lengthIncrement = juce::jmax(proportionalLength / (audioProcessor.currentSampleRate / frequency), MIN_LENGTH_INCREMENT);
|
||||||
|
|
||||||
Vector2 channels;
|
Point channels;
|
||||||
double x = 0.0;
|
double x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ SmoothEffect::SmoothEffect() {}
|
||||||
|
|
||||||
SmoothEffect::~SmoothEffect() {}
|
SmoothEffect::~SmoothEffect() {}
|
||||||
|
|
||||||
Vector2 SmoothEffect::apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
Point SmoothEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
double weight = values[0];
|
double weight = values[0];
|
||||||
weight *= 0.95;
|
weight *= 0.95;
|
||||||
double strength = 10;
|
double strength = 10;
|
||||||
|
@ -12,5 +12,5 @@ Vector2 SmoothEffect::apply(int index, Vector2 input, const std::vector<double>&
|
||||||
// TODO: This doesn't consider the sample rate!
|
// TODO: This doesn't consider the sample rate!
|
||||||
leftAvg = weight * leftAvg + (1 - weight) * input.x;
|
leftAvg = weight * leftAvg + (1 - weight) * input.x;
|
||||||
rightAvg = weight * rightAvg + (1 - weight) * input.y;
|
rightAvg = weight * rightAvg + (1 - weight) * input.y;
|
||||||
return Vector2(leftAvg, rightAvg);
|
return Point(leftAvg, rightAvg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
|
|
||||||
class SmoothEffect : public EffectApplication {
|
class SmoothEffect : public EffectApplication {
|
||||||
public:
|
public:
|
||||||
SmoothEffect();
|
SmoothEffect();
|
||||||
~SmoothEffect();
|
~SmoothEffect();
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
||||||
private:
|
private:
|
||||||
double leftAvg = 0;
|
double leftAvg = 0;
|
||||||
double rightAvg = 0;
|
double rightAvg = 0;
|
||||||
|
|
|
@ -4,7 +4,7 @@ VectorCancellingEffect::VectorCancellingEffect() {}
|
||||||
|
|
||||||
VectorCancellingEffect::~VectorCancellingEffect() {}
|
VectorCancellingEffect::~VectorCancellingEffect() {}
|
||||||
|
|
||||||
Vector2 VectorCancellingEffect::apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
Point VectorCancellingEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
double value = values[0];
|
double value = values[0];
|
||||||
if (value < 0.001) {
|
if (value < 0.001) {
|
||||||
return input;
|
return input;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
|
|
||||||
class VectorCancellingEffect : public EffectApplication {
|
class VectorCancellingEffect : public EffectApplication {
|
||||||
public:
|
public:
|
||||||
VectorCancellingEffect();
|
VectorCancellingEffect();
|
||||||
~VectorCancellingEffect();
|
~VectorCancellingEffect();
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
||||||
private:
|
private:
|
||||||
int lastIndex = 0;
|
int lastIndex = 0;
|
||||||
double nextInvert = 0;
|
double nextInvert = 0;
|
||||||
|
|
|
@ -4,7 +4,7 @@ WobbleEffect::WobbleEffect(PitchDetector& pitchDetector) : pitchDetector(pitchDe
|
||||||
|
|
||||||
WobbleEffect::~WobbleEffect() {}
|
WobbleEffect::~WobbleEffect() {}
|
||||||
|
|
||||||
Vector2 WobbleEffect::apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) {
|
Point WobbleEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
|
||||||
// TODO: this doesn't consider sample rate
|
// TODO: this doesn't consider sample rate
|
||||||
smoothedFrequency = smoothedFrequency * 0.99995 + pitchDetector.frequency * 0.00005;
|
smoothedFrequency = smoothedFrequency * 0.99995 + pitchDetector.frequency * 0.00005;
|
||||||
double theta = nextPhase(smoothedFrequency, sampleRate);
|
double theta = nextPhase(smoothedFrequency, sampleRate);
|
||||||
|
@ -12,5 +12,5 @@ Vector2 WobbleEffect::apply(int index, Vector2 input, const std::vector<double>&
|
||||||
double x = input.x + delta;
|
double x = input.x + delta;
|
||||||
double y = input.y + delta;
|
double y = input.y + delta;
|
||||||
|
|
||||||
return Vector2(x, y);
|
return Point(x, y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "EffectApplication.h"
|
#include "EffectApplication.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
#include "PitchDetector.h"
|
#include "PitchDetector.h"
|
||||||
|
|
||||||
class WobbleEffect : public EffectApplication {
|
class WobbleEffect : public EffectApplication {
|
||||||
|
@ -8,7 +8,7 @@ public:
|
||||||
WobbleEffect(PitchDetector& pitchDetector);
|
WobbleEffect(PitchDetector& pitchDetector);
|
||||||
~WobbleEffect();
|
~WobbleEffect();
|
||||||
|
|
||||||
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PitchDetector& pitchDetector;
|
PitchDetector& pitchDetector;
|
||||||
|
|
|
@ -27,8 +27,8 @@ std::vector<std::unique_ptr<Shape>> Camera::draw(WorldObject& object) {
|
||||||
edge.z2 = minZ;
|
edge.z2 = minZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 start = project(edge.x1, edge.y1, edge.z1);
|
Point start = project(edge.x1, edge.y1, edge.z1);
|
||||||
Vector2 end = project(edge.x2, edge.y2, edge.z2);
|
Point end = project(edge.x2, edge.y2, edge.z2);
|
||||||
|
|
||||||
shapes.push_back(std::make_unique<Line>(start.x, start.y, end.x, end.y));
|
shapes.push_back(std::make_unique<Line>(start.x, start.y, end.x, end.y));
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ void Camera::findZPos(WorldObject& object) {
|
||||||
y = 0.0;
|
y = 0.0;
|
||||||
z = 0.0;
|
z = 0.0;
|
||||||
|
|
||||||
std::vector<Vector2> vertices;
|
std::vector<Point> vertices;
|
||||||
|
|
||||||
int stepsMade = 0;
|
int stepsMade = 0;
|
||||||
while (maxVertexValue(vertices) > VERTEX_VALUE_THRESHOLD && stepsMade < MAX_NUM_STEPS) {
|
while (maxVertexValue(vertices) > VERTEX_VALUE_THRESHOLD && stepsMade < MAX_NUM_STEPS) {
|
||||||
|
@ -54,10 +54,10 @@ void Camera::setFocalLength(double focalLength) {
|
||||||
this->focalLength = focalLength;
|
this->focalLength = focalLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Vector2> Camera::sampleVerticesInRender(WorldObject& object) {
|
std::vector<Point> Camera::sampleVerticesInRender(WorldObject& object) {
|
||||||
double rotation = 2.0 * std::numbers::pi / SAMPLE_RENDER_SAMPLES;
|
double rotation = 2.0 * std::numbers::pi / SAMPLE_RENDER_SAMPLES;
|
||||||
|
|
||||||
std::vector<Vector2> vertices;
|
std::vector<Point> vertices;
|
||||||
|
|
||||||
for (int i = 0; i < SAMPLE_RENDER_SAMPLES - 1; i++) {
|
for (int i = 0; i < SAMPLE_RENDER_SAMPLES - 1; i++) {
|
||||||
for (size_t j = 0; j < std::min(VERTEX_SAMPLES, object.numVertices); j++) {
|
for (size_t j = 0; j < std::min(VERTEX_SAMPLES, object.numVertices); j++) {
|
||||||
|
@ -72,7 +72,7 @@ std::vector<Vector2> Camera::sampleVerticesInRender(WorldObject& object) {
|
||||||
return vertices;
|
return vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Camera::maxVertexValue(std::vector<Vector2>& vertices) {
|
double Camera::maxVertexValue(std::vector<Point>& vertices) {
|
||||||
if (vertices.empty()) {
|
if (vertices.empty()) {
|
||||||
return std::numeric_limits<double>::infinity();
|
return std::numeric_limits<double>::infinity();
|
||||||
}
|
}
|
||||||
|
@ -83,9 +83,9 @@ double Camera::maxVertexValue(std::vector<Vector2>& vertices) {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Camera::project(double x, double y, double z) {
|
Point Camera::project(double x, double y, double z) {
|
||||||
double start = x * focalLength / (z - this->z) + this->x;
|
double start = x * focalLength / (z - this->z) + this->x;
|
||||||
double end = y * focalLength / (z - this->z) + this->y;
|
double end = y * focalLength / (z - this->z) + this->y;
|
||||||
|
|
||||||
return Vector2(start, end);
|
return Point(start, end);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "WorldObject.h"
|
#include "WorldObject.h"
|
||||||
#include "../shape/Shape.h"
|
#include "../shape/Shape.h"
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
|
|
||||||
class Camera {
|
class Camera {
|
||||||
public:
|
public:
|
||||||
|
@ -22,7 +22,7 @@ private:
|
||||||
std::atomic<double> focalLength;
|
std::atomic<double> focalLength;
|
||||||
double x, y, z;
|
double x, y, z;
|
||||||
|
|
||||||
std::vector<Vector2> sampleVerticesInRender(WorldObject& object);
|
std::vector<Point> sampleVerticesInRender(WorldObject& object);
|
||||||
double maxVertexValue(std::vector<Vector2>& vertices);
|
double maxVertexValue(std::vector<Point>& vertices);
|
||||||
Vector2 project(double x, double y, double z);
|
Point project(double x, double y, double z);
|
||||||
};
|
};
|
|
@ -48,15 +48,15 @@ std::vector<std::unique_ptr<Shape>> FileParser::nextFrame() {
|
||||||
return tempShapes;
|
return tempShapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 FileParser::nextSample(lua_State*& L, const LuaVariables vars, long& step, double& phase) {
|
Point FileParser::nextSample(lua_State*& L, const LuaVariables vars, long& step, double& phase) {
|
||||||
juce::SpinLock::ScopedLockType scope(lock);
|
juce::SpinLock::ScopedLockType scope(lock);
|
||||||
|
|
||||||
if (lua != nullptr) {
|
if (lua != nullptr) {
|
||||||
auto values = lua->run(L, vars, step, phase);
|
auto values = lua->run(L, vars, step, phase);
|
||||||
if (values.size() < 2) {
|
if (values.size() < 2) {
|
||||||
return Vector2();
|
return Point();
|
||||||
}
|
}
|
||||||
return Vector2(values[0], values[1]);
|
return Point(values[0], values[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ public:
|
||||||
|
|
||||||
void parse(juce::String fileName, juce::String extension, std::unique_ptr<juce::InputStream>, juce::Font);
|
void parse(juce::String fileName, juce::String extension, std::unique_ptr<juce::InputStream>, juce::Font);
|
||||||
std::vector<std::unique_ptr<Shape>> nextFrame();
|
std::vector<std::unique_ptr<Shape>> nextFrame();
|
||||||
Vector2 nextSample(lua_State*& L, const LuaVariables vars, long& step, double& phase);
|
Point nextSample(lua_State*& L, const LuaVariables vars, long& step, double& phase);
|
||||||
void closeLua(lua_State*& L);
|
void closeLua(lua_State*& L);
|
||||||
bool isSample();
|
bool isSample();
|
||||||
bool isActive();
|
bool isActive();
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
class FrameSource {
|
class FrameSource {
|
||||||
public:
|
public:
|
||||||
virtual std::vector<std::unique_ptr<Shape>> nextFrame() = 0;
|
virtual std::vector<std::unique_ptr<Shape>> nextFrame() = 0;
|
||||||
virtual Vector2 nextSample() = 0;
|
virtual Point nextSample() = 0;
|
||||||
virtual bool isSample() = 0;
|
virtual bool isSample() = 0;
|
||||||
virtual bool isActive() = 0;
|
virtual bool isActive() = 0;
|
||||||
virtual void disable() = 0;
|
virtual void disable() = 0;
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
CircleArc::CircleArc(double x, double y, double radiusX, double radiusY, double startAngle, double endAngle) : x(x), y(y), radiusX(radiusX), radiusY(radiusY), startAngle(startAngle), endAngle(endAngle) {}
|
CircleArc::CircleArc(double x, double y, double radiusX, double radiusY, double startAngle, double endAngle) : x(x), y(y), radiusX(radiusX), radiusY(radiusY), startAngle(startAngle), endAngle(endAngle) {}
|
||||||
|
|
||||||
Vector2 CircleArc::nextVector(double drawingProgress) {
|
Point CircleArc::nextVector(double drawingProgress) {
|
||||||
// scale between start and end angle in the positive direction
|
// scale between start and end angle in the positive direction
|
||||||
double angle = startAngle + endAngle * drawingProgress;
|
double angle = startAngle + endAngle * drawingProgress;
|
||||||
return Vector2(
|
return Point(
|
||||||
x + radiusX * std::cos(angle),
|
x + radiusX * std::cos(angle),
|
||||||
y + radiusY * std::sin(angle)
|
y + radiusY * std::sin(angle)
|
||||||
);
|
);
|
||||||
|
@ -58,8 +58,8 @@ double CircleArc::length() {
|
||||||
len = 0;
|
len = 0;
|
||||||
// TODO: Replace this, it's stupid. Do a real approximation.
|
// TODO: Replace this, it's stupid. Do a real approximation.
|
||||||
int segments = 5;
|
int segments = 5;
|
||||||
Vector2 start;
|
Point start;
|
||||||
Vector2 end = nextVector(0);
|
Point end = nextVector(0);
|
||||||
for (int i = 0; i < segments; i++) {
|
for (int i = 0; i < segments; i++) {
|
||||||
start = end;
|
start = end;
|
||||||
end = nextVector((i + 1) / (double) segments);
|
end = nextVector((i + 1) / (double) segments);
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Shape.h"
|
#include "Shape.h"
|
||||||
#include "Vector2.h"
|
#include "Point.h"
|
||||||
|
|
||||||
class CircleArc : public Shape {
|
class CircleArc : public Shape {
|
||||||
public:
|
public:
|
||||||
CircleArc(double x, double y, double radiusX, double radiusY, double startAngle, double endAngle);
|
CircleArc(double x, double y, double radiusX, double radiusY, double startAngle, double endAngle);
|
||||||
|
|
||||||
Vector2 nextVector(double drawingProgress) override;
|
Point nextVector(double drawingProgress) override;
|
||||||
void rotate(double theta) override;
|
void rotate(double theta) override;
|
||||||
void scale(double x, double y) override;
|
void scale(double x, double y) override;
|
||||||
void translate(double x, double y) override;
|
void translate(double x, double y) override;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
CubicBezierCurve::CubicBezierCurve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) : x1(x1), y1(y1), x2(x2), y2(y2), x3(x3), y3(y3), x4(x4), y4(y4) {}
|
CubicBezierCurve::CubicBezierCurve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) : x1(x1), y1(y1), x2(x2), y2(y2), x3(x3), y3(y3), x4(x4), y4(y4) {}
|
||||||
|
|
||||||
Vector2 CubicBezierCurve::nextVector(double t) {
|
Point CubicBezierCurve::nextVector(double t) {
|
||||||
double pow1 = pow(1 - t, 3);
|
double pow1 = pow(1 - t, 3);
|
||||||
double pow2 = pow(1 - t, 2);
|
double pow2 = pow(1 - t, 2);
|
||||||
double pow3 = pow(t, 2);
|
double pow3 = pow(t, 2);
|
||||||
|
@ -11,7 +11,7 @@ Vector2 CubicBezierCurve::nextVector(double t) {
|
||||||
double x = pow1 * x1 + 3 * pow2 * t * x2 + 3 * (1 - t) * pow3 * x3 + pow4 * x4;
|
double x = pow1 * x1 + 3 * pow2 * t * x2 + 3 * (1 - t) * pow3 * x3 + pow4 * x4;
|
||||||
double y = pow1 * y1 + 3 * pow2 * t * y2 + 3 * (1 - t) * pow3 * y3 + pow4 * y4;
|
double y = pow1 * y1 + 3 * pow2 * t * y2 + 3 * (1 - t) * pow3 * y3 + pow4 * y4;
|
||||||
|
|
||||||
return Vector2(x, y);
|
return Point(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CubicBezierCurve::rotate(double theta) {
|
void CubicBezierCurve::rotate(double theta) {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Shape.h"
|
#include "Shape.h"
|
||||||
#include "Vector2.h"
|
#include "Point.h"
|
||||||
|
|
||||||
class CubicBezierCurve : public Shape {
|
class CubicBezierCurve : public Shape {
|
||||||
public:
|
public:
|
||||||
CubicBezierCurve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
|
CubicBezierCurve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
|
||||||
|
|
||||||
Vector2 nextVector(double drawingProgress) override;
|
Point nextVector(double drawingProgress) override;
|
||||||
void rotate(double theta) override;
|
void rotate(double theta) override;
|
||||||
void scale(double x, double y) override;
|
void scale(double x, double y) override;
|
||||||
void translate(double x, double y) override;
|
void translate(double x, double y) override;
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
Line::Line(double x1, double y1, double x2, double y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
|
Line::Line(double x1, double y1, double x2, double y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
|
||||||
|
|
||||||
Vector2 Line::nextVector(double drawingProgress) {
|
Point Line::nextVector(double drawingProgress) {
|
||||||
return Vector2(
|
return Point(
|
||||||
x1 + (x2 - x1) * drawingProgress,
|
x1 + (x2 - x1) * drawingProgress,
|
||||||
y1 + (y2 - y1) * drawingProgress
|
y1 + (y2 - y1) * drawingProgress
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Shape.h"
|
#include "Shape.h"
|
||||||
#include "Vector2.h"
|
#include "Point.h"
|
||||||
|
|
||||||
class Line : public Shape {
|
class Line : public Shape {
|
||||||
public:
|
public:
|
||||||
Line(double x1, double y1, double x2, double y2);
|
Line(double x1, double y1, double x2, double y2);
|
||||||
|
|
||||||
Vector2 nextVector(double drawingProgress) override;
|
Point nextVector(double drawingProgress) override;
|
||||||
void rotate(double theta) override;
|
void rotate(double theta) override;
|
||||||
void scale(double x, double y) override;
|
void scale(double x, double y) override;
|
||||||
void translate(double x, double y) override;
|
void translate(double x, double y) override;
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
#include "Point.h"
|
||||||
|
|
||||||
|
Point::Point() : x(0), y(0), z(0) {}
|
||||||
|
|
||||||
|
Point::Point(double val) : x(val), y(val), z(0) {}
|
||||||
|
|
||||||
|
Point::Point(double x, double y) : x(x), y(y), z(0) {}
|
||||||
|
|
||||||
|
Point::Point(double x, double y, double z) : x(x), y(y), z(z) {}
|
||||||
|
|
||||||
|
Point Point::nextVector(double drawingProgress){
|
||||||
|
return Point(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Point::rotate(double theta) {
|
||||||
|
double cosTheta = std::cos(theta);
|
||||||
|
double sinTheta = std::sin(theta);
|
||||||
|
|
||||||
|
double newX = x * cosTheta - y * sinTheta;
|
||||||
|
double newY = x * sinTheta + y * cosTheta;
|
||||||
|
|
||||||
|
x = newX;
|
||||||
|
y = newY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Point::scale(double x, double y) {
|
||||||
|
this->x *= x;
|
||||||
|
this->y *= y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Point::translate(double x, double y) {
|
||||||
|
this->x += x;
|
||||||
|
this->y += y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Point::reflectRelativeToVector(double x, double y) {
|
||||||
|
this->x += 2.0 * (x - this->x);
|
||||||
|
this->y += 2.0 * (y - this->y);
|
||||||
|
}
|
||||||
|
|
||||||
|
double Point::length() {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Point::magnitude() {
|
||||||
|
return sqrt(x * x + y * y + z * z);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Shape> Point::clone() {
|
||||||
|
return std::make_unique<Point>(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Point::type() {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
Point& Point::operator=(const Point& other) {
|
||||||
|
x = other.x;
|
||||||
|
y = other.y;
|
||||||
|
z = other.z;
|
||||||
|
return *this;
|
||||||
|
}
|
|
@ -4,13 +4,14 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Vector2 : public Shape {
|
class Point : public Shape {
|
||||||
public:
|
public:
|
||||||
Vector2(double x, double y);
|
Point(double x, double y, double z);
|
||||||
Vector2(double val);
|
Point(double x, double y);
|
||||||
Vector2();
|
Point(double val);
|
||||||
|
Point();
|
||||||
|
|
||||||
Vector2 nextVector(double drawingProgress) override;
|
Point nextVector(double drawingProgress) override;
|
||||||
void rotate(double theta) override;
|
void rotate(double theta) override;
|
||||||
void scale(double x, double y) override;
|
void scale(double x, double y) override;
|
||||||
void translate(double x, double y) override;
|
void translate(double x, double y) override;
|
||||||
|
@ -21,8 +22,8 @@ public:
|
||||||
std::string type() override;
|
std::string type() override;
|
||||||
|
|
||||||
// copy assignment operator
|
// copy assignment operator
|
||||||
Vector2& operator=(const Vector2& other);
|
Point& operator=(const Point& other);
|
||||||
|
|
||||||
double x, y;
|
double x, y, z;
|
||||||
|
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
#include "Shape.h"
|
#include "Shape.h"
|
||||||
#include "Line.h"
|
#include "Line.h"
|
||||||
#include "Vector2.h"
|
#include "Point.h"
|
||||||
|
|
||||||
double Shape::totalLength(std::vector<std::unique_ptr<Shape>>& shapes) {
|
double Shape::totalLength(std::vector<std::unique_ptr<Shape>>& shapes) {
|
||||||
double length = 0.0;
|
double length = 0.0;
|
||||||
|
@ -30,7 +30,7 @@ void Shape::normalize(std::vector<std::unique_ptr<Shape>>& shapes) {
|
||||||
shape->scale(2.0 / maxDim, -2.0 / maxDim);
|
shape->scale(2.0 / maxDim, -2.0 / maxDim);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 max = maxVector(shapes);
|
Point max = maxVector(shapes);
|
||||||
double newHeight = height(shapes);
|
double newHeight = height(shapes);
|
||||||
|
|
||||||
for (auto& shape : shapes) {
|
for (auto& shape : shapes) {
|
||||||
|
@ -42,7 +42,7 @@ double Shape::height(std::vector<std::unique_ptr<Shape>>& shapes) {
|
||||||
double maxY = std::numeric_limits<double>::min();
|
double maxY = std::numeric_limits<double>::min();
|
||||||
double minY = std::numeric_limits<double>::max();
|
double minY = std::numeric_limits<double>::max();
|
||||||
|
|
||||||
Vector2 vectors[4];
|
Point vectors[4];
|
||||||
|
|
||||||
for (auto& shape : shapes) {
|
for (auto& shape : shapes) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
|
@ -62,7 +62,7 @@ double Shape::width(std::vector<std::unique_ptr<Shape>>& shapes) {
|
||||||
double maxX = std::numeric_limits<double>::min();
|
double maxX = std::numeric_limits<double>::min();
|
||||||
double minX = std::numeric_limits<double>::max();
|
double minX = std::numeric_limits<double>::max();
|
||||||
|
|
||||||
Vector2 vectors[4];
|
Point vectors[4];
|
||||||
|
|
||||||
for (auto& shape : shapes) {
|
for (auto& shape : shapes) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
|
@ -78,13 +78,13 @@ double Shape::width(std::vector<std::unique_ptr<Shape>>& shapes) {
|
||||||
return std::abs(maxX - minX);
|
return std::abs(maxX - minX);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Shape::maxVector(std::vector<std::unique_ptr<Shape>>& shapes) {
|
Point Shape::maxVector(std::vector<std::unique_ptr<Shape>>& shapes) {
|
||||||
double maxX = std::numeric_limits<double>::min();
|
double maxX = std::numeric_limits<double>::min();
|
||||||
double maxY = std::numeric_limits<double>::min();
|
double maxY = std::numeric_limits<double>::min();
|
||||||
|
|
||||||
for (auto& shape : shapes) {
|
for (auto& shape : shapes) {
|
||||||
Vector2 startVector = shape->nextVector(0);
|
Point startVector = shape->nextVector(0);
|
||||||
Vector2 endVector = shape->nextVector(1);
|
Point endVector = shape->nextVector(1);
|
||||||
|
|
||||||
double x = std::max(startVector.x, endVector.x);
|
double x = std::max(startVector.x, endVector.x);
|
||||||
double y = std::max(startVector.y, endVector.y);
|
double y = std::max(startVector.y, endVector.y);
|
||||||
|
@ -93,22 +93,22 @@ Vector2 Shape::maxVector(std::vector<std::unique_ptr<Shape>>& shapes) {
|
||||||
maxY = std::max(y, maxY);
|
maxY = std::max(y, maxY);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Vector2(maxX, maxY);
|
return Point(maxX, maxY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shape::removeOutOfBounds(std::vector<std::unique_ptr<Shape>>& shapes) {
|
void Shape::removeOutOfBounds(std::vector<std::unique_ptr<Shape>>& shapes) {
|
||||||
std::vector<int> toRemove;
|
std::vector<int> toRemove;
|
||||||
|
|
||||||
for (int i = 0; i < shapes.size(); i++) {
|
for (int i = 0; i < shapes.size(); i++) {
|
||||||
Vector2 start = shapes[i]->nextVector(0);
|
Point start = shapes[i]->nextVector(0);
|
||||||
Vector2 end = shapes[i]->nextVector(1);
|
Point end = shapes[i]->nextVector(1);
|
||||||
bool keep = false;
|
bool keep = false;
|
||||||
|
|
||||||
if ((start.x < 1 && start.x > -1) || (start.y < 1 && start.y > -1)) {
|
if ((start.x < 1 && start.x > -1) || (start.y < 1 && start.y > -1)) {
|
||||||
if ((end.x < 1 && end.x > -1) || (end.y < 1 && end.y > -1)) {
|
if ((end.x < 1 && end.x > -1) || (end.y < 1 && end.y > -1)) {
|
||||||
if (shapes[i]->type() == "Line") {
|
if (shapes[i]->type() == "Line") {
|
||||||
Vector2 newStart(std::min(std::max(start.x, -1.0), 1.0), std::min(std::max(start.y, -1.0), 1.0));
|
Point newStart(std::min(std::max(start.x, -1.0), 1.0), std::min(std::max(start.y, -1.0), 1.0));
|
||||||
Vector2 newEnd(std::min(std::max(end.x, -1.0), 1.0), std::min(std::max(end.y, -1.0), 1.0));
|
Point newEnd(std::min(std::max(end.x, -1.0), 1.0), std::min(std::max(end.y, -1.0), 1.0));
|
||||||
shapes[i] = std::make_unique<Line>(newStart.x, newStart.y, newEnd.x, newEnd.y);
|
shapes[i] = std::make_unique<Line>(newStart.x, newStart.y, newEnd.x, newEnd.y);
|
||||||
}
|
}
|
||||||
keep = true;
|
keep = true;
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Vector2;
|
class Point;
|
||||||
class Shape {
|
class Shape {
|
||||||
public:
|
public:
|
||||||
virtual Vector2 nextVector(double drawingProgress) = 0;
|
virtual Point nextVector(double drawingProgress) = 0;
|
||||||
virtual void rotate(double theta) = 0;
|
virtual void rotate(double theta) = 0;
|
||||||
virtual void scale(double x, double y) = 0;
|
virtual void scale(double x, double y) = 0;
|
||||||
virtual void translate(double x, double y) = 0;
|
virtual void translate(double x, double y) = 0;
|
||||||
|
@ -22,7 +22,7 @@ public:
|
||||||
static void normalize(std::vector<std::unique_ptr<Shape>>&);
|
static void normalize(std::vector<std::unique_ptr<Shape>>&);
|
||||||
static double height(std::vector<std::unique_ptr<Shape>>&);
|
static double height(std::vector<std::unique_ptr<Shape>>&);
|
||||||
static double width(std::vector<std::unique_ptr<Shape>>&);
|
static double width(std::vector<std::unique_ptr<Shape>>&);
|
||||||
static Vector2 maxVector(std::vector<std::unique_ptr<Shape>>&);
|
static Point maxVector(std::vector<std::unique_ptr<Shape>>&);
|
||||||
static void removeOutOfBounds(std::vector<std::unique_ptr<Shape>>&);
|
static void removeOutOfBounds(std::vector<std::unique_ptr<Shape>>&);
|
||||||
|
|
||||||
const double INVALID_LENGTH = -1.0;
|
const double INVALID_LENGTH = -1.0;
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
#include "Vector2.h"
|
|
||||||
|
|
||||||
Vector2::Vector2() : x(0), y(0) {}
|
|
||||||
|
|
||||||
Vector2::Vector2(double val) : x(val), y(val) {}
|
|
||||||
|
|
||||||
Vector2::Vector2(double x, double y) : x(x), y(y) {}
|
|
||||||
|
|
||||||
Vector2 Vector2::nextVector(double drawingProgress){
|
|
||||||
return Vector2(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vector2::rotate(double theta) {
|
|
||||||
double cosTheta = std::cos(theta);
|
|
||||||
double sinTheta = std::sin(theta);
|
|
||||||
|
|
||||||
double newX = x * cosTheta - y * sinTheta;
|
|
||||||
double newY = x * sinTheta + y * cosTheta;
|
|
||||||
|
|
||||||
x = newX;
|
|
||||||
y = newY;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vector2::scale(double x, double y) {
|
|
||||||
this->x *= x;
|
|
||||||
this->y *= y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vector2::translate(double x, double y) {
|
|
||||||
this->x += x;
|
|
||||||
this->y += y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vector2::reflectRelativeToVector(double x, double y) {
|
|
||||||
this->x += 2.0 * (x - this->x);
|
|
||||||
this->y += 2.0 * (y - this->y);
|
|
||||||
}
|
|
||||||
|
|
||||||
double Vector2::length() {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Vector2::magnitude() {
|
|
||||||
return sqrt(x * x + y * y);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Shape> Vector2::clone() {
|
|
||||||
return std::make_unique<Vector2>(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Vector2::type() {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2& Vector2::operator=(const Vector2& other) {
|
|
||||||
x = other.x;
|
|
||||||
y = other.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
#include "../shape/Shape.h"
|
#include "../shape/Shape.h"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../shape/Vector2.h"
|
#include "../shape/Point.h"
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
#include "../shape/Shape.h"
|
#include "../shape/Shape.h"
|
||||||
|
|
||||||
|
|
|
@ -444,8 +444,8 @@
|
||||||
file="Source/shape/QuadraticBezierCurve.h"/>
|
file="Source/shape/QuadraticBezierCurve.h"/>
|
||||||
<FILE id="W19EPg" name="Line.cpp" compile="1" resource="0" file="Source/shape/Line.cpp"/>
|
<FILE id="W19EPg" name="Line.cpp" compile="1" resource="0" file="Source/shape/Line.cpp"/>
|
||||||
<FILE id="i1A2s1" name="Line.h" compile="0" resource="0" file="Source/shape/Line.h"/>
|
<FILE id="i1A2s1" name="Line.h" compile="0" resource="0" file="Source/shape/Line.h"/>
|
||||||
<FILE id="nUpro8" name="Vector2.cpp" compile="1" resource="0" file="Source/shape/Vector2.cpp"/>
|
<FILE id="nUpro8" name="Point.cpp" compile="1" resource="0" file="Source/shape/Point.cpp"/>
|
||||||
<FILE id="X6A0jk" name="Vector2.h" compile="0" resource="0" file="Source/shape/Vector2.h"/>
|
<FILE id="X6A0jk" name="Point.h" compile="0" resource="0" file="Source/shape/Point.h"/>
|
||||||
<FILE id="NmptSY" name="Shape.h" compile="0" resource="0" file="Source/shape/Shape.h"/>
|
<FILE id="NmptSY" name="Shape.h" compile="0" resource="0" file="Source/shape/Shape.h"/>
|
||||||
</GROUP>
|
</GROUP>
|
||||||
<GROUP id="{56A27063-1FE7-31C3-8263-98389240A8CB}" name="svg">
|
<GROUP id="{56A27063-1FE7-31C3-8263-98389240A8CB}" name="svg">
|
||||||
|
|
Ładowanie…
Reference in New Issue