commit bb4d1ea9d5e0232e3e6a348a8df6d1b529c77a24
parent 74d4f9751cd5c1b1950d4e6a1cb32ce9601a378f
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Mon, 20 May 2024 14:33:01 +0200
support dragging external files onto patch manager to add data sources or to import patches to user bank
Diffstat:
5 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/source/jucePluginEditorLib/patchmanager/datasourcetreeitem.cpp b/source/jucePluginEditorLib/patchmanager/datasourcetreeitem.cpp
@@ -69,9 +69,12 @@ namespace jucePluginEditorLib::patchManager
return m_dataSource->type == pluginLib::patchDB::SourceType::LocalStorage;
}
- bool DatasourceTreeItem::isInterestedInPatchList(const List* _list, const juce::Array<juce::var>& _indices)
+ bool DatasourceTreeItem::isInterestedInFileDrag(const juce::StringArray& files)
{
- return m_dataSource->type == pluginLib::patchDB::SourceType::LocalStorage;
+ if(m_dataSource->type == pluginLib::patchDB::SourceType::LocalStorage)
+ return true;
+
+ return TreeItem::isInterestedInFileDrag(files);
}
void DatasourceTreeItem::patchesDropped(const std::vector<pluginLib::patchDB::PatchPtr>& _patches, const SavePatchDesc* _savePatchDesc/* = nullptr*/)
diff --git a/source/jucePluginEditorLib/patchmanager/grouptreeitem.cpp b/source/jucePluginEditorLib/patchmanager/grouptreeitem.cpp
@@ -5,6 +5,8 @@
#include "search.h"
#include "tagtreeitem.h"
+#include "../../synthLib/os.h"
+
namespace jucePluginEditorLib::patchManager
{
class DatasourceTreeItem;
@@ -312,6 +314,72 @@ namespace jucePluginEditorLib::patchManager
TagTreeItem::modifyTags(getPatchManager(), tagType, tag, _patches);
}
+ bool GroupTreeItem::isInterestedInFileDrag(const juce::StringArray& _files)
+ {
+ if(_files.isEmpty())
+ return TreeItem::isInterestedInFileDrag(_files);
+
+ switch (m_type)
+ {
+ case GroupType::DataSources:
+ {
+ // do not allow to add data sources from temporary directory
+ const auto tempDir = juce::File::getSpecialLocation(juce::File::tempDirectory).getFullPathName().toStdString();
+ for (const auto& file : _files)
+ {
+ if(file.toStdString().find(tempDir) == 0)
+ return false;
+ }
+ return true;
+ }
+ case GroupType::LocalStorage:
+ return true;
+ default:
+ return TreeItem::isInterestedInFileDrag(_files);
+ }
+ }
+
+ void GroupTreeItem::filesDropped(const juce::StringArray& _files, const int _insertIndex)
+ {
+ if(m_type == GroupType::DataSources)
+ {
+ for (const auto& file : _files)
+ {
+ pluginLib::patchDB::DataSource ds;
+ ds.name = file.toStdString();
+ ds.type = pluginLib::patchDB::SourceType::File;
+ ds.origin = pluginLib::patchDB::DataSourceOrigin::Manual;
+
+ getPatchManager().addDataSource(ds);
+ }
+ }
+ else if(m_type == GroupType::LocalStorage)
+ {
+ for (const auto& file : _files)
+ {
+ auto patches = getPatchManager().loadPatchesFromFiles(std::vector<std::string>{file.toStdString()});
+
+ if(patches.empty())
+ continue;
+
+ pluginLib::patchDB::DataSource ds;
+ ds.name = synthLib::getFilenameWithoutPath(file.toStdString());
+ ds.type = pluginLib::patchDB::SourceType::LocalStorage;
+ ds.origin = pluginLib::patchDB::DataSourceOrigin::Manual;
+
+ getPatchManager().addDataSource(ds, [this, patches](const bool _success, const std::shared_ptr<pluginLib::patchDB::DataSourceNode>& _ds)
+ {
+ if(_success)
+ getPatchManager().copyPatchesToLocalStorage(_ds, patches, -1);
+ });
+ }
+ }
+ else
+ {
+ TreeItem::filesDropped(_files, _insertIndex);
+ }
+ }
+
DatasourceTreeItem* GroupTreeItem::createItemForDataSource(const pluginLib::patchDB::DataSourceNodePtr& _dataSource)
{
const auto it = m_itemsByDataSource.find(_dataSource);
diff --git a/source/jucePluginEditorLib/patchmanager/grouptreeitem.h b/source/jucePluginEditorLib/patchmanager/grouptreeitem.h
@@ -47,6 +47,8 @@ namespace jucePluginEditorLib::patchManager
bool isInterestedInPatchList(const List* _list, const std::vector<pluginLib::patchDB::PatchPtr>& _patches) override;
void patchesDropped(const std::vector<pluginLib::patchDB::PatchPtr>& _patches, const SavePatchDesc* _savePatchDesc) override;
+ bool isInterestedInFileDrag(const juce::StringArray& _files) override;
+ void filesDropped(const juce::StringArray& _files, int _insertIndex) override;
private:
DatasourceTreeItem* createItemForDataSource(const pluginLib::patchDB::DataSourceNodePtr& _dataSource);
TagTreeItem* createSubItem(const std::string& _tag);
diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.h b/source/jucePluginEditorLib/patchmanager/patchmanager.h
@@ -98,6 +98,9 @@ namespace jucePluginEditorLib::patchManager
virtual bool activatePatch(const std::string& _filename, uint32_t _part);
+ std::vector<pluginLib::patchDB::PatchPtr> loadPatchesFromFiles(const juce::StringArray& _files);
+ std::vector<pluginLib::patchDB::PatchPtr> loadPatchesFromFiles(const std::vector<std::string>& _files);
+
void onLoadFinished() override;
void setPerInstanceConfig(const std::vector<uint8_t>& _data);
diff --git a/source/jucePluginEditorLib/patchmanager/treeitem.cpp b/source/jucePluginEditorLib/patchmanager/treeitem.cpp
@@ -220,6 +220,21 @@ namespace jucePluginEditorLib::patchManager
TreeViewItem::paintItem(_g, _width, _height);
}
+ bool TreeItem::isInterestedInFileDrag(const juce::StringArray& _files)
+ {
+ return TreeViewItem::isInterestedInFileDrag(_files);
+ }
+
+ void TreeItem::filesDropped(const juce::StringArray& _files, const int _insertIndex)
+ {
+ const auto patches = m_patchManager.loadPatchesFromFiles(_files);
+
+ if(!patches.empty())
+ patchesDropped(patches);
+ else
+ TreeViewItem::filesDropped(_files, _insertIndex);
+ }
+
int TreeItem::compareElements(const TreeViewItem* _a, const TreeViewItem* _b)
{
const auto* a = dynamic_cast<const TreeItem*>(_a);