2023-07-21 16:42:29 +00:00
|
|
|
#pragma once
|
|
|
|
#include "EffectApplication.h"
|
2024-01-07 16:17:20 +00:00
|
|
|
#include "../shape/Point.h"
|
2023-07-21 16:42:29 +00:00
|
|
|
#include "../audio/Effect.h"
|
|
|
|
#include "../lua/LuaParser.h"
|
|
|
|
|
|
|
|
class PerspectiveEffect : public EffectApplication {
|
|
|
|
public:
|
2023-12-20 23:30:20 +00:00
|
|
|
PerspectiveEffect(int versionHint, std::function<void(int, juce::String, juce::String)> errorCallback);
|
|
|
|
~PerspectiveEffect();
|
2023-07-21 16:42:29 +00:00
|
|
|
|
2023-12-20 18:43:03 +00:00
|
|
|
// arbitrary UUID
|
|
|
|
static const juce::String FILE_NAME;
|
|
|
|
|
2024-01-07 16:17:20 +00:00
|
|
|
Point apply(int index, Point input, const std::vector<double>& values, double sampleRate) override;
|
2023-07-22 21:00:59 +00:00
|
|
|
void updateCode(const juce::String& newCode);
|
2023-10-19 11:20:24 +00:00
|
|
|
void setVariable(juce::String variableName, double value);
|
|
|
|
|
2023-07-22 21:00:59 +00:00
|
|
|
juce::String getCode();
|
2023-07-22 14:07:11 +00:00
|
|
|
|
2023-09-01 18:52:36 +00:00
|
|
|
BooleanParameter* fixedRotateX;
|
|
|
|
BooleanParameter* fixedRotateY;
|
|
|
|
BooleanParameter* fixedRotateZ;
|
2023-10-19 11:20:24 +00:00
|
|
|
|
2023-07-21 16:42:29 +00:00
|
|
|
private:
|
|
|
|
const juce::String DEFAULT_SCRIPT = "return { x, y, z }";
|
2023-07-22 21:00:59 +00:00
|
|
|
juce::String code = DEFAULT_SCRIPT;
|
2023-12-20 17:47:58 +00:00
|
|
|
std::function<void(int, juce::String, juce::String)> errorCallback;
|
2023-12-20 23:30:20 +00:00
|
|
|
std::unique_ptr<LuaParser> parser = std::make_unique<LuaParser>(FILE_NAME, code, errorCallback);
|
2023-10-19 11:20:24 +00:00
|
|
|
juce::SpinLock codeLock;
|
|
|
|
|
2023-07-22 14:07:11 +00:00
|
|
|
bool defaultScript = true;
|
2023-07-21 16:42:29 +00:00
|
|
|
|
|
|
|
float currentRotateX = 0;
|
|
|
|
float currentRotateY = 0;
|
|
|
|
float currentRotateZ = 0;
|
2023-12-20 23:30:20 +00:00
|
|
|
|
|
|
|
lua_State *L = nullptr;
|
2023-09-01 18:52:36 +00:00
|
|
|
|
|
|
|
int versionHint;
|
2023-07-21 16:42:29 +00:00
|
|
|
|
2023-12-20 23:30:20 +00:00
|
|
|
long step = 1;
|
|
|
|
double phase = 0;
|
|
|
|
|
2023-09-09 10:22:14 +00:00
|
|
|
double linearSpeedToActualSpeed(double rotateSpeed) {
|
2023-09-09 12:47:02 +00:00
|
|
|
double actualSpeed = (std::exp(3 * juce::jmin(10.0, std::abs(rotateSpeed))) - 1) / 50000;
|
2023-09-09 10:22:14 +00:00
|
|
|
if (rotateSpeed < 0) {
|
|
|
|
actualSpeed *= -1;
|
|
|
|
}
|
|
|
|
return actualSpeed;
|
|
|
|
}
|
2023-09-01 18:52:36 +00:00
|
|
|
};
|