From a4da61531f90a581557dfde1119896c267774a06 Mon Sep 17 00:00:00 2001 From: Joep Vanlier Date: Thu, 26 Sep 2024 00:10:12 +0200 Subject: [PATCH] plugin: allow dropping jsfx into plugin allow drag and drop of a jsfx file into the plugin when no plugin is loaded --- plugin/editor.cpp | 30 ++++++++++++++++++++++++++++++ plugin/editor.h | 4 +++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugin/editor.cpp b/plugin/editor.cpp index b909bec..cd08706 100644 --- a/plugin/editor.cpp +++ b/plugin/editor.cpp @@ -231,6 +231,36 @@ YsfxEditor::~YsfxEditor() } } +//------------------------------------------------------------------------------ +bool YsfxEditor::isInterestedInFileDrag(const juce::StringArray &files) +{ + (void)files; + + YsfxInfo::Ptr info = m_impl->m_info; + ysfx_t *fx = info->effect.get(); + + return !ysfx_is_compiled(fx); +} + +void YsfxEditor::filesDropped(const juce::StringArray &files, int x, int y) +{ + (void)x; + (void)y; + + // We only allow jsfx drops if no JSFX was loaded. + YsfxInfo::Ptr info = m_impl->m_info; + ysfx_t *fx = info->effect.get(); + + if (!ysfx_is_compiled(fx)) { + if (files.size() == 1) { + juce::File file{files[0]}; + if (file.existsAsFile()) { + m_impl->loadFile(files[0]); + } + } + } +} + void YsfxEditor::resized() { m_impl->relayoutUILater(); diff --git a/plugin/editor.h b/plugin/editor.h index ed8119e..5de698f 100644 --- a/plugin/editor.h +++ b/plugin/editor.h @@ -20,7 +20,7 @@ #include class YsfxProcessor; -class YsfxEditor : public juce::AudioProcessorEditor { +class YsfxEditor : public juce::AudioProcessorEditor, public juce::FileDragAndDropTarget { public: explicit YsfxEditor(YsfxProcessor &proc); ~YsfxEditor() override; @@ -28,6 +28,8 @@ class YsfxEditor : public juce::AudioProcessorEditor { protected: void resized() override; void paint (juce::Graphics& g) override; + bool isInterestedInFileDrag(const juce::StringArray &files) override; + void filesDropped(const juce::StringArray &files, int x, int y) override; private: void readTheme();