commit d247f6bb629a37a0c7219d64c0e771661a5db7f7
parent 63f3923b8553e8e1831cefb0ee18d590dcaa1df8
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Mon, 20 May 2024 11:43:08 +0200
support import of external files with patches onto part button via drag & drop, this also closes the circle so that we can D&D parts from one instance to another instance
Diffstat:
4 files changed, 75 insertions(+), 1 deletion(-)
diff --git a/source/jucePluginEditorLib/partbutton.cpp b/source/jucePluginEditorLib/partbutton.cpp
@@ -1,10 +1,13 @@
#include "partbutton.h"
#include "pluginEditor.h"
+#include "pluginProcessor.h"
#include "patchmanager/list.h"
#include "patchmanager/patchmanager.h"
#include "patchmanager/savepatchdesc.h"
+#include "../synthLib/os.h"
+
namespace jucePluginEditorLib
{
namespace
@@ -35,6 +38,44 @@ namespace jucePluginEditorLib
return patch.first != nullptr;
}
+ template <typename T> bool PartButton<T>::isInterestedInFileDrag(const juce::StringArray& _files)
+ {
+ if(_files.size() != 1)
+ return false;
+ return true;
+ }
+
+ template <typename T> void PartButton<T>::fileDragEnter(const juce::StringArray& files, int x, int y)
+ {
+ if(isInterestedInFileDrag(files))
+ setIsDragTarget(true);
+ FileDragAndDropTarget::fileDragEnter(files, x, y);
+ }
+
+ template <typename T> void PartButton<T>::fileDragExit(const juce::StringArray& files)
+ {
+ FileDragAndDropTarget::fileDragExit(files);
+ setIsDragTarget(false);
+ }
+
+ template <typename T> void PartButton<T>::filesDropped(const juce::StringArray& _files, int, int)
+ {
+ setIsDragTarget(false);
+
+ auto* pm = m_editor.getPatchManager();
+ if(!pm)
+ return;
+
+ if(!pm->activatePatch(_files.begin()->toStdString(), getPart()))
+ {
+ juce::NativeMessageBox::showMessageBoxAsync(juce::MessageBoxIconType::WarningIcon,
+ m_editor.getProcessor().getProperties().name,
+ "Failed to load patch. Make sure that the format is supported and that the file only contains one patch.\n"
+ "\n"
+ "Drag files with multiple patches onto the Patch Manager instead to import them", nullptr, juce::ModalCallbackFunction::create([](int){}));
+ }
+ }
+
template <typename T> void PartButton<T>::itemDragEnter(const SourceDetails& dragSourceDetails)
{
if(isInterestedInDragSource(dragSourceDetails))
diff --git a/source/jucePluginEditorLib/partbutton.h b/source/jucePluginEditorLib/partbutton.h
@@ -14,7 +14,7 @@ namespace jucePluginEditorLib
class Editor;
template<typename T>
- class PartButton : public genericUI::Button<T>, public juce::DragAndDropTarget
+ class PartButton : public genericUI::Button<T>, public juce::DragAndDropTarget, public juce::FileDragAndDropTarget
{
public:
template<class... TArgs>
@@ -38,6 +38,12 @@ namespace jucePluginEditorLib
void itemDragExit(const SourceDetails& _dragSourceDetails) override;
void itemDropped(const SourceDetails& _dragSourceDetails) override;
+ bool isInterestedInFileDrag (const juce::StringArray& _files) override;
+
+ void fileDragEnter(const juce::StringArray& files, int x, int y) override;
+ void fileDragExit(const juce::StringArray& files) override;
+ void filesDropped(const juce::StringArray& _files, int x, int y) override;
+
void paint(juce::Graphics& g) override;
void mouseDrag(const juce::MouseEvent& _event) override;
diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.cpp b/source/jucePluginEditorLib/patchmanager/patchmanager.cpp
@@ -588,6 +588,31 @@ namespace jucePluginEditorLib::patchManager
return m_editor.getTemplate(_name);
}
+ bool PatchManager::activatePatch(const std::string& _filename, const uint32_t _part)
+ {
+ if(_part >= m_state.getPartCount())
+ return false;
+
+ pluginLib::patchDB::DataList results;
+ loadFile(results, _filename);
+
+ if(results.empty())
+ return false;
+
+ auto result = results.front();
+ const auto patch = initializePatch(std::move(result));
+ if(!patch)
+ return false;
+
+ if(!activatePatch(patch, _part))
+ return false;
+
+ if(getCurrentPart() == _part)
+ m_list->setSelectedPatches(std::set<pluginLib::patchDB::PatchKey>{});
+
+ return true;
+ }
+
void PatchManager::onLoadFinished()
{
DB::onLoadFinished();
diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.h b/source/jucePluginEditorLib/patchmanager/patchmanager.h
@@ -96,6 +96,8 @@ namespace jucePluginEditorLib::patchManager
virtual bool activatePatch(const pluginLib::patchDB::PatchPtr& _patch) = 0;
virtual bool activatePatch(const pluginLib::patchDB::PatchPtr& _patch, uint32_t _part) = 0;
+ virtual bool activatePatch(const std::string& _filename, uint32_t _part);
+
void onLoadFinished() override;
void setPerInstanceConfig(const std::vector<uint8_t>& _data);