From 8a91099c55ac5f7786bcb282e9861e603e1fcf10 Mon Sep 17 00:00:00 2001 From: James Ball Date: Sun, 7 Jan 2024 16:17:20 +0000 Subject: [PATCH] Rename Vector2 to Point --- Source/PluginProcessor.cpp | 4 +- Source/PluginProcessor.h | 20 ++++---- Source/audio/BitCrushEffect.cpp | 4 +- Source/audio/BitCrushEffect.h | 4 +- Source/audio/BooleanParameter.h | 2 +- Source/audio/BulgeEffect.cpp | 4 +- Source/audio/BulgeEffect.h | 4 +- Source/audio/DelayEffect.cpp | 6 +-- Source/audio/DelayEffect.h | 6 +-- Source/audio/DistortEffect.cpp | 2 +- Source/audio/DistortEffect.h | 4 +- Source/audio/Effect.cpp | 4 +- Source/audio/Effect.h | 6 +-- Source/audio/EffectApplication.h | 4 +- Source/audio/EffectParameter.h | 2 +- Source/audio/LuaEffect.cpp | 2 +- Source/audio/LuaEffect.h | 4 +- Source/audio/PerspectiveEffect.cpp | 4 +- Source/audio/PerspectiveEffect.h | 4 +- Source/audio/RotateEffect.cpp | 2 +- Source/audio/RotateEffect.h | 4 +- Source/audio/ShapeVoice.cpp | 2 +- Source/audio/SmoothEffect.cpp | 4 +- Source/audio/SmoothEffect.h | 4 +- Source/audio/VectorCancellingEffect.cpp | 2 +- Source/audio/VectorCancellingEffect.h | 4 +- Source/audio/WobbleEffect.cpp | 4 +- Source/audio/WobbleEffect.h | 4 +- Source/obj/Camera.cpp | 16 +++---- Source/obj/Camera.h | 8 ++-- Source/parser/FileParser.cpp | 6 +-- Source/parser/FileParser.h | 2 +- Source/parser/FrameSource.h | 2 +- Source/shape/CircleArc.cpp | 8 ++-- Source/shape/CircleArc.h | 4 +- Source/shape/CubicBezierCurve.cpp | 4 +- Source/shape/CubicBezierCurve.h | 4 +- Source/shape/Line.cpp | 4 +- Source/shape/Line.h | 4 +- Source/shape/Point.cpp | 62 +++++++++++++++++++++++++ Source/shape/{Vector2.h => Point.h} | 15 +++--- Source/shape/Shape.cpp | 24 +++++----- Source/shape/Shape.h | 6 +-- Source/shape/Vector2.cpp | 59 ----------------------- Source/svg/SvgParser.h | 2 +- Source/txt/TextParser.h | 2 +- osci-render.jucer | 4 +- 47 files changed, 180 insertions(+), 176 deletions(-) create mode 100644 Source/shape/Point.cpp rename Source/shape/{Vector2.h => Point.h} (60%) delete mode 100644 Source/shape/Vector2.cpp diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 7cde0c04..70e48b31 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -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) )); toggleableEffects.push_back(std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { input.x += values[0]; input.y += values[1]; return input; @@ -612,7 +612,7 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer& buffer, ju currentVolume = std::sqrt(squaredVolume); currentVolume = juce::jlimit(0.0, 1.0, currentVolume); - Vector2 channels; + Point channels; if (totalNumOutputChannels >= 2) { channels = {buffer.getSample(0, sample), buffer.getSample(1, sample)}; } else if (totalNumOutputChannels == 1) { diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index a9a262e8..2b0ba185 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -78,7 +78,7 @@ public: std::vector> luaEffects; std::shared_ptr frequencyEffect = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { frequency = values[0]; return input; }, new EffectParameter( @@ -90,7 +90,7 @@ public: ); std::shared_ptr volumeEffect = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { volume = values[0]; return input; }, new EffectParameter( @@ -102,7 +102,7 @@ public: ); std::shared_ptr thresholdEffect = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { threshold = values[0]; return input; }, new EffectParameter( @@ -114,7 +114,7 @@ public: ); std::shared_ptr focalLength = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { if (getCurrentFileIndex() != -1) { auto camera = getCurrentFileParser()->getCamera(); if (camera == nullptr) return input; @@ -133,7 +133,7 @@ public: BooleanParameter* fixedRotateY = new BooleanParameter("Object Fixed Rotate Y", "objFixedRotateY", VERSION_HINT, false); BooleanParameter* fixedRotateZ = new BooleanParameter("Object Fixed Rotate Z", "objFixedRotateZ", VERSION_HINT, false); std::shared_ptr rotateX = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { if (getCurrentFileIndex() != -1) { auto obj = getCurrentFileParser()->getObject(); if (obj == nullptr) return input; @@ -153,7 +153,7 @@ public: ) ); std::shared_ptr rotateY = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { if (getCurrentFileIndex() != -1) { auto obj = getCurrentFileParser()->getObject(); if (obj == nullptr) return input; @@ -173,7 +173,7 @@ public: ) ); std::shared_ptr rotateZ = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { if (getCurrentFileIndex() != -1) { auto obj = getCurrentFileParser()->getObject(); if (obj == nullptr) return input; @@ -193,7 +193,7 @@ public: ) ); std::shared_ptr rotateSpeed = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { if (getCurrentFileIndex() != -1) { auto obj = getCurrentFileParser()->getObject(); if (obj == nullptr) return input; @@ -209,7 +209,7 @@ public: ); std::shared_ptr traceMax = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { return input; }, new EffectParameter( "Trace max", @@ -219,7 +219,7 @@ public: ) ); std::shared_ptr traceMin = std::make_shared( - [this](int index, Vector2 input, const std::vector& values, double sampleRate) { + [this](int index, Point input, const std::vector& values, double sampleRate) { return input; }, new EffectParameter( "Trace min", diff --git a/Source/audio/BitCrushEffect.cpp b/Source/audio/BitCrushEffect.cpp index 3f08ab1a..7724c2aa 100644 --- a/Source/audio/BitCrushEffect.cpp +++ b/Source/audio/BitCrushEffect.cpp @@ -3,7 +3,7 @@ BitCrushEffect::BitCrushEffect() {} // algorithm from https://www.kvraudio.com/forum/viewtopic.php?t=163880 -Vector2 BitCrushEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) { +Point BitCrushEffect::apply(int index, Point input, const std::vector& values, double sampleRate) { double value = values[0]; // change rage of value from 0-1 to 0.0-0.78 double rangedValue = value * 0.78; @@ -12,5 +12,5 @@ Vector2 BitCrushEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; + Point apply(int index, Point input, const std::vector& values, double sampleRate) override; }; diff --git a/Source/audio/BooleanParameter.h b/Source/audio/BooleanParameter.h index b2cd44e3..9bad39a3 100644 --- a/Source/audio/BooleanParameter.h +++ b/Source/audio/BooleanParameter.h @@ -1,5 +1,5 @@ #pragma once -#include "../shape/Vector2.h" +#include "../shape/Point.h" #include class BooleanParameter : public juce::AudioProcessorParameterWithID { diff --git a/Source/audio/BulgeEffect.cpp b/Source/audio/BulgeEffect.cpp index af2e649f..9af13cb0 100644 --- a/Source/audio/BulgeEffect.cpp +++ b/Source/audio/BulgeEffect.cpp @@ -4,7 +4,7 @@ BulgeEffect::BulgeEffect() {} BulgeEffect::~BulgeEffect() {} -Vector2 BulgeEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) { +Point BulgeEffect::apply(int index, Point input, const std::vector& values, double sampleRate) { double value = values[0]; double translatedBulge = -value + 1; @@ -12,5 +12,5 @@ Vector2 BulgeEffect::apply(int index, Vector2 input, const std::vector& double theta = atan2(input.y, input.x); double rn = pow(r, translatedBulge); - return Vector2(rn * cos(theta), rn * sin(theta)); + return Point(rn * cos(theta), rn * sin(theta)); } diff --git a/Source/audio/BulgeEffect.h b/Source/audio/BulgeEffect.h index c9803d0d..2bdd86b0 100644 --- a/Source/audio/BulgeEffect.h +++ b/Source/audio/BulgeEffect.h @@ -1,11 +1,11 @@ #pragma once #include "EffectApplication.h" -#include "../shape/Vector2.h" +#include "../shape/Point.h" class BulgeEffect : public EffectApplication { public: BulgeEffect(); ~BulgeEffect(); - Vector2 apply(int index, Vector2 input, const std::vector&, double sampleRate) override; + Point apply(int index, Point input, const std::vector&, double sampleRate) override; }; \ No newline at end of file diff --git a/Source/audio/DelayEffect.cpp b/Source/audio/DelayEffect.cpp index ea77eb61..c8b34f18 100644 --- a/Source/audio/DelayEffect.cpp +++ b/Source/audio/DelayEffect.cpp @@ -4,7 +4,7 @@ DelayEffect::DelayEffect() {} DelayEffect::~DelayEffect() {} -Vector2 DelayEffect::apply(int index, Vector2 vector, const std::vector& values, double sampleRate) { +Point DelayEffect::apply(int index, Point vector, const std::vector& values, double sampleRate) { double decay = values[0]; double decayLength = values[1]; int delayBufferLength = (int)(sampleRate * decayLength); @@ -22,8 +22,8 @@ Vector2 DelayEffect::apply(int index, Vector2 vector, const std::vector& } } - Vector2 echo = delayBuffer[position]; - vector = Vector2( + Point echo = delayBuffer[position]; + vector = Point( vector.x + echo.x * decay, vector.y + echo.y * decay ); diff --git a/Source/audio/DelayEffect.h b/Source/audio/DelayEffect.h index e8921d45..5c77726e 100644 --- a/Source/audio/DelayEffect.h +++ b/Source/audio/DelayEffect.h @@ -1,17 +1,17 @@ #pragma once #include "EffectApplication.h" -#include "../shape/Vector2.h" +#include "../shape/Point.h" class DelayEffect : public EffectApplication { public: DelayEffect(); ~DelayEffect(); - Vector2 apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; + Point apply(int index, Point input, const std::vector& values, double sampleRate) override; private: const static int MAX_DELAY = 192000 * 10; - std::vector delayBuffer = std::vector(MAX_DELAY); + std::vector delayBuffer = std::vector(MAX_DELAY); int head = 0; int position = 0; int samplesSinceLastDelay = 0; diff --git a/Source/audio/DistortEffect.cpp b/Source/audio/DistortEffect.cpp index 38e48be0..5881e139 100644 --- a/Source/audio/DistortEffect.cpp +++ b/Source/audio/DistortEffect.cpp @@ -4,7 +4,7 @@ DistortEffect::DistortEffect(bool vertical) : vertical(vertical) {} DistortEffect::~DistortEffect() {} -Vector2 DistortEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) { +Point DistortEffect::apply(int index, Point input, const std::vector& values, double sampleRate) { double value = values[0]; int vertical = (int)this->vertical; if (index % 2 == 0) { diff --git a/Source/audio/DistortEffect.h b/Source/audio/DistortEffect.h index f92e6580..edcbd4dd 100644 --- a/Source/audio/DistortEffect.h +++ b/Source/audio/DistortEffect.h @@ -1,13 +1,13 @@ #pragma once #include "EffectApplication.h" -#include "../shape/Vector2.h" +#include "../shape/Point.h" class DistortEffect : public EffectApplication { public: DistortEffect(bool vertical); ~DistortEffect(); - Vector2 apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; + Point apply(int index, Point input, const std::vector& values, double sampleRate) override; private: bool vertical; }; \ No newline at end of file diff --git a/Source/audio/Effect.cpp b/Source/audio/Effect.cpp index d8f7d2b3..e9e1a20b 100644 --- a/Source/audio/Effect.cpp +++ b/Source/audio/Effect.cpp @@ -17,7 +17,7 @@ Effect::Effect(EffectApplicationType application, const std::vector{parameter}) {} -Vector2 Effect::apply(int index, Vector2 input, double volume) { +Point Effect::apply(int index, Point input, double volume) { animateValues(volume); if (application) { return application(index, input, actualValues, sampleRate); @@ -90,7 +90,7 @@ float Effect::nextPhase(EffectParameter* parameter) { } void Effect::apply() { - apply(0, Vector2()); + apply(0, Point()); } double Effect::getValue(int index) { diff --git a/Source/audio/Effect.h b/Source/audio/Effect.h index 0b20b5da..1108961b 100644 --- a/Source/audio/Effect.h +++ b/Source/audio/Effect.h @@ -1,11 +1,11 @@ #pragma once -#include "../shape/Vector2.h" +#include "../shape/Point.h" #include #include "EffectApplication.h" #include "EffectParameter.h" #include "BooleanParameter.h" -typedef std::function& values, double sampleRate)> EffectApplicationType; +typedef std::function& values, double sampleRate)> EffectApplicationType; class Effect { public: @@ -14,7 +14,7 @@ public: Effect(EffectApplicationType application, const std::vector& parameters); 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(); double getValue(int index); diff --git a/Source/audio/EffectApplication.h b/Source/audio/EffectApplication.h index 7573e48b..ac944ca6 100644 --- a/Source/audio/EffectApplication.h +++ b/Source/audio/EffectApplication.h @@ -1,12 +1,12 @@ #pragma once -#include "../shape/Vector2.h" +#include "../shape/Point.h" #include class EffectApplication { public: EffectApplication() {}; - virtual Vector2 apply(int index, Vector2 input, const std::vector& values, double sampleRate) = 0; + virtual Point apply(int index, Point input, const std::vector& values, double sampleRate) = 0; void resetPhase(); double nextPhase(double frequency, double sampleRate); diff --git a/Source/audio/EffectParameter.h b/Source/audio/EffectParameter.h index 88fc2aaa..a84ea326 100644 --- a/Source/audio/EffectParameter.h +++ b/Source/audio/EffectParameter.h @@ -1,5 +1,5 @@ #pragma once -#include "../shape/Vector2.h" +#include "../shape/Point.h" #include #include "BooleanParameter.h" diff --git a/Source/audio/LuaEffect.cpp b/Source/audio/LuaEffect.cpp index c62691a0..af9914c8 100644 --- a/Source/audio/LuaEffect.cpp +++ b/Source/audio/LuaEffect.cpp @@ -1,7 +1,7 @@ #include "LuaEffect.h" #include "../lua/LuaParser.h" -Vector2 LuaEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) { +Point LuaEffect::apply(int index, Point input, const std::vector& values, double sampleRate) { int fileIndex = audioProcessor.getCurrentFileIndex(); if (fileIndex == -1) { return input; diff --git a/Source/audio/LuaEffect.h b/Source/audio/LuaEffect.h index ae5e4808..86bb221d 100644 --- a/Source/audio/LuaEffect.h +++ b/Source/audio/LuaEffect.h @@ -1,6 +1,6 @@ #pragma once #include "EffectApplication.h" -#include "../shape/Vector2.h" +#include "../shape/Point.h" #include "../audio/Effect.h" #include "../PluginProcessor.h" @@ -8,7 +8,7 @@ class LuaEffect : public EffectApplication { public: LuaEffect(juce::String name, OscirenderAudioProcessor& p) : audioProcessor(p), name(name) {}; - Vector2 apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; + Point apply(int index, Point input, const std::vector& values, double sampleRate) override; private: OscirenderAudioProcessor& audioProcessor; juce::String name; diff --git a/Source/audio/PerspectiveEffect.cpp b/Source/audio/PerspectiveEffect.cpp index bc6f1cf0..9673d48c 100644 --- a/Source/audio/PerspectiveEffect.cpp +++ b/Source/audio/PerspectiveEffect.cpp @@ -14,7 +14,7 @@ PerspectiveEffect::~PerspectiveEffect() { parser->close(L); } -Vector2 PerspectiveEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) { +Point PerspectiveEffect::apply(int index, Point input, const std::vector& values, double sampleRate) { auto effectScale = values[0]; auto depth = 1.0 + (values[1] - 0.1) * 3; auto rotateSpeed = linearSpeedToActualSpeed(values[2]); @@ -88,7 +88,7 @@ Vector2 PerspectiveEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; + Point apply(int index, Point input, const std::vector& values, double sampleRate) override; void updateCode(const juce::String& newCode); void setVariable(juce::String variableName, double value); diff --git a/Source/audio/RotateEffect.cpp b/Source/audio/RotateEffect.cpp index 876c1c84..46c25669 100644 --- a/Source/audio/RotateEffect.cpp +++ b/Source/audio/RotateEffect.cpp @@ -4,7 +4,7 @@ RotateEffect::RotateEffect() {} RotateEffect::~RotateEffect() {} -Vector2 RotateEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) { +Point RotateEffect::apply(int index, Point input, const std::vector& values, double sampleRate) { input.rotate(nextPhase(values[0], sampleRate)); return input; } diff --git a/Source/audio/RotateEffect.h b/Source/audio/RotateEffect.h index 282e64e7..3c61109d 100644 --- a/Source/audio/RotateEffect.h +++ b/Source/audio/RotateEffect.h @@ -1,11 +1,11 @@ #pragma once #include "EffectApplication.h" -#include "../shape/Vector2.h" +#include "../shape/Point.h" class RotateEffect : public EffectApplication { public: RotateEffect(); ~RotateEffect(); - Vector2 apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; + Point apply(int index, Point input, const std::vector& values, double sampleRate) override; }; \ No newline at end of file diff --git a/Source/audio/ShapeVoice.cpp b/Source/audio/ShapeVoice.cpp index 680d4f0b..5c37f833 100644 --- a/Source/audio/ShapeVoice.cpp +++ b/Source/audio/ShapeVoice.cpp @@ -89,7 +89,7 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star double proportionalLength = (traceMax - traceMin) * frameLength; lengthIncrement = juce::jmax(proportionalLength / (audioProcessor.currentSampleRate / frequency), MIN_LENGTH_INCREMENT); - Vector2 channels; + Point channels; double x = 0.0; double y = 0.0; diff --git a/Source/audio/SmoothEffect.cpp b/Source/audio/SmoothEffect.cpp index c3ad0006..c369abdd 100644 --- a/Source/audio/SmoothEffect.cpp +++ b/Source/audio/SmoothEffect.cpp @@ -4,7 +4,7 @@ SmoothEffect::SmoothEffect() {} SmoothEffect::~SmoothEffect() {} -Vector2 SmoothEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) { +Point SmoothEffect::apply(int index, Point input, const std::vector& values, double sampleRate) { double weight = values[0]; weight *= 0.95; double strength = 10; @@ -12,5 +12,5 @@ Vector2 SmoothEffect::apply(int index, Vector2 input, const std::vector& // TODO: This doesn't consider the sample rate! leftAvg = weight * leftAvg + (1 - weight) * input.x; rightAvg = weight * rightAvg + (1 - weight) * input.y; - return Vector2(leftAvg, rightAvg); + return Point(leftAvg, rightAvg); } diff --git a/Source/audio/SmoothEffect.h b/Source/audio/SmoothEffect.h index 9992d354..d9dafc7e 100644 --- a/Source/audio/SmoothEffect.h +++ b/Source/audio/SmoothEffect.h @@ -1,13 +1,13 @@ #pragma once #include "EffectApplication.h" -#include "../shape/Vector2.h" +#include "../shape/Point.h" class SmoothEffect : public EffectApplication { public: SmoothEffect(); ~SmoothEffect(); - Vector2 apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; + Point apply(int index, Point input, const std::vector& values, double sampleRate) override; private: double leftAvg = 0; double rightAvg = 0; diff --git a/Source/audio/VectorCancellingEffect.cpp b/Source/audio/VectorCancellingEffect.cpp index 561e80b8..3c2df37d 100644 --- a/Source/audio/VectorCancellingEffect.cpp +++ b/Source/audio/VectorCancellingEffect.cpp @@ -4,7 +4,7 @@ VectorCancellingEffect::VectorCancellingEffect() {} VectorCancellingEffect::~VectorCancellingEffect() {} -Vector2 VectorCancellingEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) { +Point VectorCancellingEffect::apply(int index, Point input, const std::vector& values, double sampleRate) { double value = values[0]; if (value < 0.001) { return input; diff --git a/Source/audio/VectorCancellingEffect.h b/Source/audio/VectorCancellingEffect.h index 6c94161d..38aac064 100644 --- a/Source/audio/VectorCancellingEffect.h +++ b/Source/audio/VectorCancellingEffect.h @@ -1,13 +1,13 @@ #pragma once #include "EffectApplication.h" -#include "../shape/Vector2.h" +#include "../shape/Point.h" class VectorCancellingEffect : public EffectApplication { public: VectorCancellingEffect(); ~VectorCancellingEffect(); - Vector2 apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; + Point apply(int index, Point input, const std::vector& values, double sampleRate) override; private: int lastIndex = 0; double nextInvert = 0; diff --git a/Source/audio/WobbleEffect.cpp b/Source/audio/WobbleEffect.cpp index 938a1264..4a4b41ac 100644 --- a/Source/audio/WobbleEffect.cpp +++ b/Source/audio/WobbleEffect.cpp @@ -4,7 +4,7 @@ WobbleEffect::WobbleEffect(PitchDetector& pitchDetector) : pitchDetector(pitchDe WobbleEffect::~WobbleEffect() {} -Vector2 WobbleEffect::apply(int index, Vector2 input, const std::vector& values, double sampleRate) { +Point WobbleEffect::apply(int index, Point input, const std::vector& values, double sampleRate) { // TODO: this doesn't consider sample rate smoothedFrequency = smoothedFrequency * 0.99995 + pitchDetector.frequency * 0.00005; double theta = nextPhase(smoothedFrequency, sampleRate); @@ -12,5 +12,5 @@ Vector2 WobbleEffect::apply(int index, Vector2 input, const std::vector& double x = input.x + delta; double y = input.y + delta; - return Vector2(x, y); + return Point(x, y); } diff --git a/Source/audio/WobbleEffect.h b/Source/audio/WobbleEffect.h index dd8ba807..2d30ca6a 100644 --- a/Source/audio/WobbleEffect.h +++ b/Source/audio/WobbleEffect.h @@ -1,6 +1,6 @@ #pragma once #include "EffectApplication.h" -#include "../shape/Vector2.h" +#include "../shape/Point.h" #include "PitchDetector.h" class WobbleEffect : public EffectApplication { @@ -8,7 +8,7 @@ public: WobbleEffect(PitchDetector& pitchDetector); ~WobbleEffect(); - Vector2 apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; + Point apply(int index, Point input, const std::vector& values, double sampleRate) override; private: PitchDetector& pitchDetector; diff --git a/Source/obj/Camera.cpp b/Source/obj/Camera.cpp index e60f824e..58cc77b9 100644 --- a/Source/obj/Camera.cpp +++ b/Source/obj/Camera.cpp @@ -27,8 +27,8 @@ std::vector> Camera::draw(WorldObject& object) { edge.z2 = minZ; } - Vector2 start = project(edge.x1, edge.y1, edge.z1); - Vector2 end = project(edge.x2, edge.y2, edge.z2); + Point start = project(edge.x1, edge.y1, edge.z1); + Point end = project(edge.x2, edge.y2, edge.z2); shapes.push_back(std::make_unique(start.x, start.y, end.x, end.y)); } @@ -40,7 +40,7 @@ void Camera::findZPos(WorldObject& object) { y = 0.0; z = 0.0; - std::vector vertices; + std::vector vertices; int stepsMade = 0; while (maxVertexValue(vertices) > VERTEX_VALUE_THRESHOLD && stepsMade < MAX_NUM_STEPS) { @@ -54,10 +54,10 @@ void Camera::setFocalLength(double focalLength) { this->focalLength = focalLength; } -std::vector Camera::sampleVerticesInRender(WorldObject& object) { +std::vector Camera::sampleVerticesInRender(WorldObject& object) { double rotation = 2.0 * std::numbers::pi / SAMPLE_RENDER_SAMPLES; - std::vector vertices; + std::vector vertices; for (int i = 0; i < SAMPLE_RENDER_SAMPLES - 1; i++) { for (size_t j = 0; j < std::min(VERTEX_SAMPLES, object.numVertices); j++) { @@ -72,7 +72,7 @@ std::vector Camera::sampleVerticesInRender(WorldObject& object) { return vertices; } -double Camera::maxVertexValue(std::vector& vertices) { +double Camera::maxVertexValue(std::vector& vertices) { if (vertices.empty()) { return std::numeric_limits::infinity(); } @@ -83,9 +83,9 @@ double Camera::maxVertexValue(std::vector& vertices) { 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 end = y * focalLength / (z - this->z) + this->y; - return Vector2(start, end); + return Point(start, end); } diff --git a/Source/obj/Camera.h b/Source/obj/Camera.h index d953cf90..29e89e2d 100644 --- a/Source/obj/Camera.h +++ b/Source/obj/Camera.h @@ -3,7 +3,7 @@ #include #include "WorldObject.h" #include "../shape/Shape.h" -#include "../shape/Vector2.h" +#include "../shape/Point.h" class Camera { public: @@ -22,7 +22,7 @@ private: std::atomic focalLength; double x, y, z; - std::vector sampleVerticesInRender(WorldObject& object); - double maxVertexValue(std::vector& vertices); - Vector2 project(double x, double y, double z); + std::vector sampleVerticesInRender(WorldObject& object); + double maxVertexValue(std::vector& vertices); + Point project(double x, double y, double z); }; \ No newline at end of file diff --git a/Source/parser/FileParser.cpp b/Source/parser/FileParser.cpp index 87e7f6a4..c023b66c 100644 --- a/Source/parser/FileParser.cpp +++ b/Source/parser/FileParser.cpp @@ -48,15 +48,15 @@ std::vector> FileParser::nextFrame() { 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); if (lua != nullptr) { auto values = lua->run(L, vars, step, phase); if (values.size() < 2) { - return Vector2(); + return Point(); } - return Vector2(values[0], values[1]); + return Point(values[0], values[1]); } } diff --git a/Source/parser/FileParser.h b/Source/parser/FileParser.h index fbb596cf..b557c892 100644 --- a/Source/parser/FileParser.h +++ b/Source/parser/FileParser.h @@ -14,7 +14,7 @@ public: void parse(juce::String fileName, juce::String extension, std::unique_ptr, juce::Font); std::vector> 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); bool isSample(); bool isActive(); diff --git a/Source/parser/FrameSource.h b/Source/parser/FrameSource.h index 02490a4e..fda90b9b 100644 --- a/Source/parser/FrameSource.h +++ b/Source/parser/FrameSource.h @@ -8,7 +8,7 @@ class FrameSource { public: virtual std::vector> nextFrame() = 0; - virtual Vector2 nextSample() = 0; + virtual Point nextSample() = 0; virtual bool isSample() = 0; virtual bool isActive() = 0; virtual void disable() = 0; diff --git a/Source/shape/CircleArc.cpp b/Source/shape/CircleArc.cpp index cb855fcc..8ce9a2a5 100644 --- a/Source/shape/CircleArc.cpp +++ b/Source/shape/CircleArc.cpp @@ -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) {} -Vector2 CircleArc::nextVector(double drawingProgress) { +Point CircleArc::nextVector(double drawingProgress) { // scale between start and end angle in the positive direction double angle = startAngle + endAngle * drawingProgress; - return Vector2( + return Point( x + radiusX * std::cos(angle), y + radiusY * std::sin(angle) ); @@ -58,8 +58,8 @@ double CircleArc::length() { len = 0; // TODO: Replace this, it's stupid. Do a real approximation. int segments = 5; - Vector2 start; - Vector2 end = nextVector(0); + Point start; + Point end = nextVector(0); for (int i = 0; i < segments; i++) { start = end; end = nextVector((i + 1) / (double) segments); diff --git a/Source/shape/CircleArc.h b/Source/shape/CircleArc.h index b2754036..e7266c29 100644 --- a/Source/shape/CircleArc.h +++ b/Source/shape/CircleArc.h @@ -1,13 +1,13 @@ #pragma once #include "Shape.h" -#include "Vector2.h" +#include "Point.h" class CircleArc : public Shape { public: 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 scale(double x, double y) override; void translate(double x, double y) override; diff --git a/Source/shape/CubicBezierCurve.cpp b/Source/shape/CubicBezierCurve.cpp index d0488734..6c08ea27 100644 --- a/Source/shape/CubicBezierCurve.cpp +++ b/Source/shape/CubicBezierCurve.cpp @@ -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) {} -Vector2 CubicBezierCurve::nextVector(double t) { +Point CubicBezierCurve::nextVector(double t) { double pow1 = pow(1 - t, 3); double pow2 = pow(1 - 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 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) { diff --git a/Source/shape/CubicBezierCurve.h b/Source/shape/CubicBezierCurve.h index 56492ab5..ffed5bc9 100644 --- a/Source/shape/CubicBezierCurve.h +++ b/Source/shape/CubicBezierCurve.h @@ -1,13 +1,13 @@ #pragma once #include "Shape.h" -#include "Vector2.h" +#include "Point.h" class CubicBezierCurve : public Shape { public: 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 scale(double x, double y) override; void translate(double x, double y) override; diff --git a/Source/shape/Line.cpp b/Source/shape/Line.cpp index bb05e93c..fffbd1c9 100644 --- a/Source/shape/Line.cpp +++ b/Source/shape/Line.cpp @@ -2,8 +2,8 @@ Line::Line(double x1, double y1, double x2, double y2) : x1(x1), y1(y1), x2(x2), y2(y2) {} -Vector2 Line::nextVector(double drawingProgress) { - return Vector2( +Point Line::nextVector(double drawingProgress) { + return Point( x1 + (x2 - x1) * drawingProgress, y1 + (y2 - y1) * drawingProgress ); diff --git a/Source/shape/Line.h b/Source/shape/Line.h index edc36c5b..d62743ab 100644 --- a/Source/shape/Line.h +++ b/Source/shape/Line.h @@ -1,13 +1,13 @@ #pragma once #include "Shape.h" -#include "Vector2.h" +#include "Point.h" class Line : public Shape { public: 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 scale(double x, double y) override; void translate(double x, double y) override; diff --git a/Source/shape/Point.cpp b/Source/shape/Point.cpp new file mode 100644 index 00000000..3aedf6a6 --- /dev/null +++ b/Source/shape/Point.cpp @@ -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 Point::clone() { + return std::make_unique(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; +} diff --git a/Source/shape/Vector2.h b/Source/shape/Point.h similarity index 60% rename from Source/shape/Vector2.h rename to Source/shape/Point.h index 1f716d67..46d2272d 100644 --- a/Source/shape/Vector2.h +++ b/Source/shape/Point.h @@ -4,13 +4,14 @@ #include #include -class Vector2 : public Shape { +class Point : public Shape { public: - Vector2(double x, double y); - Vector2(double val); - Vector2(); + Point(double x, double y, double z); + Point(double x, double y); + Point(double val); + Point(); - Vector2 nextVector(double drawingProgress) override; + Point nextVector(double drawingProgress) override; void rotate(double theta) override; void scale(double x, double y) override; void translate(double x, double y) override; @@ -21,8 +22,8 @@ public: std::string type() override; // copy assignment operator - Vector2& operator=(const Vector2& other); + Point& operator=(const Point& other); - double x, y; + double x, y, z; }; \ No newline at end of file diff --git a/Source/shape/Shape.cpp b/Source/shape/Shape.cpp index 4154aeea..edb7db33 100644 --- a/Source/shape/Shape.cpp +++ b/Source/shape/Shape.cpp @@ -1,6 +1,6 @@ #include "Shape.h" #include "Line.h" -#include "Vector2.h" +#include "Point.h" double Shape::totalLength(std::vector>& shapes) { double length = 0.0; @@ -30,7 +30,7 @@ void Shape::normalize(std::vector>& shapes) { shape->scale(2.0 / maxDim, -2.0 / maxDim); } - Vector2 max = maxVector(shapes); + Point max = maxVector(shapes); double newHeight = height(shapes); for (auto& shape : shapes) { @@ -42,7 +42,7 @@ double Shape::height(std::vector>& shapes) { double maxY = std::numeric_limits::min(); double minY = std::numeric_limits::max(); - Vector2 vectors[4]; + Point vectors[4]; for (auto& shape : shapes) { for (int i = 0; i < 4; i++) { @@ -62,7 +62,7 @@ double Shape::width(std::vector>& shapes) { double maxX = std::numeric_limits::min(); double minX = std::numeric_limits::max(); - Vector2 vectors[4]; + Point vectors[4]; for (auto& shape : shapes) { for (int i = 0; i < 4; i++) { @@ -78,13 +78,13 @@ double Shape::width(std::vector>& shapes) { return std::abs(maxX - minX); } -Vector2 Shape::maxVector(std::vector>& shapes) { +Point Shape::maxVector(std::vector>& shapes) { double maxX = std::numeric_limits::min(); double maxY = std::numeric_limits::min(); for (auto& shape : shapes) { - Vector2 startVector = shape->nextVector(0); - Vector2 endVector = shape->nextVector(1); + Point startVector = shape->nextVector(0); + Point endVector = shape->nextVector(1); double x = std::max(startVector.x, endVector.x); double y = std::max(startVector.y, endVector.y); @@ -93,22 +93,22 @@ Vector2 Shape::maxVector(std::vector>& shapes) { maxY = std::max(y, maxY); } - return Vector2(maxX, maxY); + return Point(maxX, maxY); } void Shape::removeOutOfBounds(std::vector>& shapes) { std::vector toRemove; for (int i = 0; i < shapes.size(); i++) { - Vector2 start = shapes[i]->nextVector(0); - Vector2 end = shapes[i]->nextVector(1); + Point start = shapes[i]->nextVector(0); + Point end = shapes[i]->nextVector(1); bool keep = false; 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 (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)); - Vector2 newEnd(std::min(std::max(end.x, -1.0), 1.0), std::min(std::max(end.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)); + 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(newStart.x, newStart.y, newEnd.x, newEnd.y); } keep = true; diff --git a/Source/shape/Shape.h b/Source/shape/Shape.h index cc699ac3..775ebd74 100644 --- a/Source/shape/Shape.h +++ b/Source/shape/Shape.h @@ -6,10 +6,10 @@ #include #include -class Vector2; +class Point; class Shape { public: - virtual Vector2 nextVector(double drawingProgress) = 0; + virtual Point nextVector(double drawingProgress) = 0; virtual void rotate(double theta) = 0; virtual void scale(double x, double y) = 0; virtual void translate(double x, double y) = 0; @@ -22,7 +22,7 @@ public: static void normalize(std::vector>&); static double height(std::vector>&); static double width(std::vector>&); - static Vector2 maxVector(std::vector>&); + static Point maxVector(std::vector>&); static void removeOutOfBounds(std::vector>&); const double INVALID_LENGTH = -1.0; diff --git a/Source/shape/Vector2.cpp b/Source/shape/Vector2.cpp deleted file mode 100644 index 62b0f8a3..00000000 --- a/Source/shape/Vector2.cpp +++ /dev/null @@ -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 Vector2::clone() { - return std::make_unique(x, y); -} - -std::string Vector2::type() { - return std::string(); -} - -Vector2& Vector2::operator=(const Vector2& other) { - x = other.x; - y = other.y; - return *this; -} diff --git a/Source/svg/SvgParser.h b/Source/svg/SvgParser.h index f9227344..6baafecb 100644 --- a/Source/svg/SvgParser.h +++ b/Source/svg/SvgParser.h @@ -1,5 +1,5 @@ #pragma once -#include "../shape/Vector2.h" +#include "../shape/Point.h" #include #include "../shape/Shape.h" diff --git a/Source/txt/TextParser.h b/Source/txt/TextParser.h index c4406e6d..2640f690 100644 --- a/Source/txt/TextParser.h +++ b/Source/txt/TextParser.h @@ -1,5 +1,5 @@ #pragma once -#include "../shape/Vector2.h" +#include "../shape/Point.h" #include #include "../shape/Shape.h" diff --git a/osci-render.jucer b/osci-render.jucer index be5b4768..ac6bc3d1 100644 --- a/osci-render.jucer +++ b/osci-render.jucer @@ -444,8 +444,8 @@ file="Source/shape/QuadraticBezierCurve.h"/> - - + +