diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index d8201f5..69ddc22 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -256,6 +256,7 @@ void OscirenderAudioProcessorEditor::updateCodeDocument() { if (editingPerspective) { juce::String file = codeDocuments[0]->getAllContent(); audioProcessor.perspectiveEffect->updateCode(file); + audioProcessor.updateLuaValues(); } else { int originalIndex = audioProcessor.getCurrentFileIndex(); int index = audioProcessor.getCurrentFileIndex(); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index eb0751f..84dde63 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -225,6 +225,7 @@ public: juce::String getFileName(int index); std::shared_ptr getFileBlock(int index); void setObjectServerRendering(bool enabled); + void updateLuaValues(); private: std::atomic volume = 1.0; std::atomic threshold = 1.0; @@ -241,7 +242,6 @@ private: AudioWebSocketServer softwareOscilloscopeServer{*this}; ObjectServer objectServer{*this}; - void updateLuaValues(); void updateObjValues(); std::shared_ptr getEffect(juce::String id); BooleanParameter* getBooleanParameter(juce::String id); diff --git a/Source/audio/LuaEffect.cpp b/Source/audio/LuaEffect.cpp index 8213cab..c62691a 100644 --- a/Source/audio/LuaEffect.cpp +++ b/Source/audio/LuaEffect.cpp @@ -10,5 +10,8 @@ Vector2 LuaEffect::apply(int index, Vector2 input, const std::vector& va if (parser != nullptr) { parser->setVariable("slider_" + name.toLowerCase(), values[0]); } + + audioProcessor.perspectiveEffect->setVariable("slider_" + name.toLowerCase(), values[0]); + return input; } diff --git a/Source/audio/PerspectiveEffect.cpp b/Source/audio/PerspectiveEffect.cpp index 1a56a12..3d5243b 100644 --- a/Source/audio/PerspectiveEffect.cpp +++ b/Source/audio/PerspectiveEffect.cpp @@ -93,6 +93,13 @@ void PerspectiveEffect::updateCode(const juce::String& newCode) { parser = std::make_unique(code); } +void PerspectiveEffect::setVariable(juce::String variableName, double value) { + juce::SpinLock::ScopedLockType lock(codeLock); + if (!defaultScript) { + parser->setVariable(variableName, value); + } +} + juce::String PerspectiveEffect::getCode() { juce::SpinLock::ScopedLockType lock(codeLock); return code; diff --git a/Source/audio/PerspectiveEffect.h b/Source/audio/PerspectiveEffect.h index ab2ad3c..2d29a21 100644 --- a/Source/audio/PerspectiveEffect.h +++ b/Source/audio/PerspectiveEffect.h @@ -10,16 +10,20 @@ public: Vector2 apply(int index, Vector2 input, const std::vector& values, double sampleRate) override; void updateCode(const juce::String& newCode); + void setVariable(juce::String variableName, double value); + juce::String getCode(); BooleanParameter* fixedRotateX; BooleanParameter* fixedRotateY; BooleanParameter* fixedRotateZ; + private: const juce::String DEFAULT_SCRIPT = "return { x, y, z }"; juce::String code = DEFAULT_SCRIPT; - juce::SpinLock codeLock; std::unique_ptr parser = std::make_unique(code); + juce::SpinLock codeLock; + bool defaultScript = true; float currentRotateX = 0;