Skip to content

Commit

Permalink
plugin: allow dropping jsfx into plugin
Browse files Browse the repository at this point in the history
allow drag and drop of a jsfx file into the plugin when no plugin is loaded
  • Loading branch information
JoepVanlier committed Sep 26, 2024
1 parent 0976f30 commit a4da615
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions plugin/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion plugin/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
#include <memory>
class YsfxProcessor;

class YsfxEditor : public juce::AudioProcessorEditor {
class YsfxEditor : public juce::AudioProcessorEditor, public juce::FileDragAndDropTarget {
public:
explicit YsfxEditor(YsfxProcessor &proc);
~YsfxEditor() override;

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();
Expand Down

0 comments on commit a4da615

Please sign in to comment.