commit 5f852def9906f9cdf8fbb91adbf87c0eb6b2fb77
parent 7097aa33fe0c91c3af61ef2c6a3e9d3aca415a13
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Mon, 20 May 2024 00:07:31 +0200
rework drag & drop system to have a SavePatchDesc as drag source for everything
Diffstat:
8 files changed, 84 insertions(+), 64 deletions(-)
diff --git a/source/jucePluginEditorLib/partbutton.cpp b/source/jucePluginEditorLib/partbutton.cpp
@@ -15,7 +15,7 @@ namespace jucePluginEditorLib
if(!list)
return {};
- const auto patches = patchManager::List::getPatchesFromDragSource(_source);
+ const auto& patches = patchManager::SavePatchDesc::getPatchesFromDragSource(_source);
if (patches.size() != 1)
return {};
@@ -90,7 +90,9 @@ namespace jucePluginEditorLib
template <typename T> void PartButton<T>::mouseDrag(const juce::MouseEvent& _event)
{
- m_editor.startDragging(new patchManager::SavePatchDesc(m_part), this);
+ auto* patchManager = m_editor.getPatchManager();
+ if(patchManager)
+ m_editor.startDragging(new patchManager::SavePatchDesc(*patchManager, m_part), this);
genericUI::Button<T>::mouseDrag(_event);
}
diff --git a/source/jucePluginEditorLib/patchmanager/list.cpp b/source/jucePluginEditorLib/patchmanager/list.cpp
@@ -3,6 +3,7 @@
#include "defaultskin.h"
#include "listitem.h"
#include "patchmanager.h"
+#include "savepatchdesc.h"
#include "search.h"
#include "../pluginEditor.h"
#include "../../juceUiLib/uiObject.h"
@@ -371,18 +372,18 @@ namespace jucePluginEditorLib::patchManager
if (ranges.isEmpty())
return {};
- juce::Array<juce::var> indices;
+ std::map<uint32_t, pluginLib::patchDB::PatchPtr> patches;
for (const auto& range : ranges)
{
for (int i = range.getStart(); i < range.getEnd(); ++i)
{
if(i >= 0 && static_cast<size_t>(i) < getPatches().size())
- indices.add(i);
+ patches.insert({i, getPatches()[i]});
}
}
- return indices;
+ return new SavePatchDesc(m_patchManager, std::move(patches));
}
juce::Component* List::refreshComponentForRow(int rowNumber, bool isRowSelected, Component* existingComponentToUpdate)
@@ -503,30 +504,6 @@ namespace jucePluginEditorLib::patchManager
setContent(m_search);
}
- std::vector<pluginLib::patchDB::PatchPtr> List::getPatchesFromDragSource(const juce::DragAndDropTarget::SourceDetails& _dragSourceDetails)
- {
- const auto* list = dynamic_cast<List*>(_dragSourceDetails.sourceComponent.get());
- if(!list)
- return {};
-
- const auto* arr = _dragSourceDetails.description.getArray();
- if (!arr)
- return {};
-
- std::vector<pluginLib::patchDB::PatchPtr> patches;
-
- for (const auto& var : *arr)
- {
- if (!var.isInt())
- continue;
- const int idx = var;
- if (const auto patch = list->getPatch(idx))
- patches.push_back(patch);
- }
-
- return patches;
- }
-
pluginLib::patchDB::DataSourceNodePtr List::getDataSource() const
{
if(!m_search)
diff --git a/source/jucePluginEditorLib/patchmanager/list.h b/source/jucePluginEditorLib/patchmanager/list.h
@@ -61,8 +61,6 @@ namespace jucePluginEditorLib::patchManager
void processDirty(const pluginLib::patchDB::Dirty& _dirty);
- static std::vector<pluginLib::patchDB::PatchPtr> getPatchesFromDragSource(const juce::DragAndDropTarget::SourceDetails& _dragSourceDetails);
-
pluginLib::patchDB::DataSourceNodePtr getDataSource() const;
static Patch getPatch(const Patches& _patches, const size_t _index)
diff --git a/source/jucePluginEditorLib/patchmanager/listitem.cpp b/source/jucePluginEditorLib/patchmanager/listitem.cpp
@@ -86,27 +86,25 @@ namespace jucePluginEditorLib::patchManager
const auto row = drag == DragType::Above ? m_row : m_row + 1;
- if(const auto* list = dynamic_cast<const List*>(dragSourceDetails.sourceComponent.get()))
- {
- const auto patches = List::getPatchesFromDragSource(dragSourceDetails);
+ const auto patches = SavePatchDesc::getPatchesFromDragSource(dragSourceDetails);
+
+ if(patches.empty())
+ return;
+ const auto* savePatchDesc = SavePatchDesc::fromDragSource(dragSourceDetails);
+ assert(savePatchDesc);
+
+ if(dynamic_cast<const List*>(dragSourceDetails.sourceComponent.get()))
+ {
if(!patches.empty() && pm.movePatchesTo(row, patches))
m_list.refreshContent();
}
- else
+ else if(patches.size() == 1 && savePatchDesc->isPartValid())
{
const auto& source = m_list.getDataSource();
if(!source)
return;
- const auto* savePatchDesc = SavePatchDesc::fromDragSource(dragSourceDetails);
- if(!savePatchDesc)
- return;
-
- const auto patch = pm.requestPatchForPart(savePatchDesc->getPart());
- if(!patch)
- return;
-
if(drag == DragType::Over)
{
repaint();
@@ -117,7 +115,7 @@ namespace jucePluginEditorLib::patchManager
"Replace Patch",
"Do you want to replace the existing patch '" + existingPatch->name + "' with contents of part " + std::to_string(savePatchDesc->getPart()+1) + "?"))
{
- pm.replacePatch(existingPatch, patch);
+ pm.replacePatch(existingPatch, patches.front());
}
}
else
@@ -126,7 +124,8 @@ namespace jucePluginEditorLib::patchManager
pm.getEditor().showDemoRestrictionMessageBox();
#else
const auto part = savePatchDesc->getPart();
- pm.copyPatchesTo(source, {patch}, row, [this, part](const std::vector<pluginLib::patchDB::PatchPtr>& _patches)
+
+ pm.copyPatchesTo(source, patches, row, [this, part](const std::vector<pluginLib::patchDB::PatchPtr>& _patches)
{
juce::MessageManager::callAsync([this, part, _patches]
{
diff --git a/source/jucePluginEditorLib/patchmanager/savepatchdesc.cpp b/source/jucePluginEditorLib/patchmanager/savepatchdesc.cpp
@@ -0,0 +1,35 @@
+#include "savepatchdesc.h"
+
+#include "patchmanager.h"
+
+#include "../../synthLib/sysexToMidi.h"
+
+namespace jucePluginEditorLib::patchManager
+{
+ std::map<uint32_t, pluginLib::patchDB::PatchPtr>& SavePatchDesc::getPatches() const
+ {
+ if(m_patches.empty() && isPartValid())
+ {
+ auto patch = m_patchManager.requestPatchForPart(m_part);
+ if(!patch)
+ return m_patches;
+ m_patches.insert({m_part, patch});
+ }
+ return m_patches;
+ }
+
+ std::vector<pluginLib::patchDB::PatchPtr> SavePatchDesc::getPatchesFromDragSource(const juce::DragAndDropTarget::SourceDetails& _dragSourceDetails)
+ {
+ const auto* savePatchDesc = fromDragSource(_dragSourceDetails);
+
+ if(!savePatchDesc)
+ return {};
+
+ std::vector<pluginLib::patchDB::PatchPtr> patches;
+
+ for (const auto& it : savePatchDesc->getPatches())
+ patches.push_back(it.second);
+
+ return patches;
+ }
+}
diff --git a/source/jucePluginEditorLib/patchmanager/savepatchdesc.h b/source/jucePluginEditorLib/patchmanager/savepatchdesc.h
@@ -1,24 +1,44 @@
#pragma once
#include "juce_core/juce_core.h"
+#include "juce_gui_basics/juce_gui_basics.h"
+
+#include "../../jucePluginLib/patchdb/patchdbtypes.h"
namespace jucePluginEditorLib::patchManager
{
+ class PatchManager;
+
class SavePatchDesc : public juce::ReferenceCountedObject
{
+ static constexpr int InvalidPart = -1;
+
public:
- SavePatchDesc(int _part) : m_part(_part)
+ SavePatchDesc(PatchManager& _pm, const int _part) : m_patchManager(_pm), m_part(_part)
+ {
+ }
+
+ SavePatchDesc(PatchManager& _pm, std::map<uint32_t, pluginLib::patchDB::PatchPtr>&& _patches) : m_patchManager(_pm), m_part(InvalidPart), m_patches(std::move(_patches))
{
}
auto getPart() const { return m_part; }
+ std::map<uint32_t, pluginLib::patchDB::PatchPtr>& getPatches() const;
+
+ bool isPartValid() const { return m_part != InvalidPart; }
+ bool hasPatches() const { return !getPatches().empty(); }
+
static const SavePatchDesc* fromDragSource(const juce::DragAndDropTarget::SourceDetails& _source)
{
return dynamic_cast<const SavePatchDesc*>(_source.description.getObject());
}
+ static std::vector<pluginLib::patchDB::PatchPtr> getPatchesFromDragSource(const juce::DragAndDropTarget::SourceDetails& _dragSourceDetails);
+
private:
+ PatchManager& m_patchManager;
int m_part;
+ mutable std::map<uint32_t, pluginLib::patchDB::PatchPtr> m_patches;
};
}
diff --git a/source/jucePluginEditorLib/patchmanager/treeitem.cpp b/source/jucePluginEditorLib/patchmanager/treeitem.cpp
@@ -136,23 +136,10 @@ namespace jucePluginEditorLib::patchManager
void TreeItem::itemDropped(const juce::DragAndDropTarget::SourceDetails& dragSourceDetails, int insertIndex)
{
- if (dynamic_cast<List*>(dragSourceDetails.sourceComponent.get()))
- {
- const auto patches = List::getPatchesFromDragSource(dragSourceDetails);
+ const auto patches = SavePatchDesc::getPatchesFromDragSource(dragSourceDetails);
- if(!patches.empty())
- patchesDropped(patches);
- }
- else
- {
- const auto* desc = SavePatchDesc::fromDragSource(dragSourceDetails);
-
- if(!desc)
- return;
-
- if(auto patch = getPatchManager().requestPatchForPart(desc->getPart()))
- patchesDropped({patch}, desc);
- }
+ if(!patches.empty())
+ patchesDropped(patches);
}
bool TreeItem::isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& _dragSourceDetails)
diff --git a/source/virusJucePlugin/VirusEditor.cpp b/source/virusJucePlugin/VirusEditor.cpp
@@ -139,10 +139,12 @@ namespace genericVirusUI
onProgramChange(getController().getCurrentPart());
}
};
- m_presetNameMouseListener = new PartMouseListener(pluginLib::MidiPacket::AnyPart, [this](const juce::MouseEvent& _mouseEvent, int )
+
+ m_presetNameMouseListener = new PartMouseListener(pluginLib::MidiPacket::AnyPart, [this](const juce::MouseEvent&, int)
{
- startDragging(new jucePluginEditorLib::patchManager::SavePatchDesc(getController().getCurrentPart()), m_presetName);
+ startDragging(new jucePluginEditorLib::patchManager::SavePatchDesc(*getPatchManager(), getController().getCurrentPart()), m_presetName);
});
+
m_presetName->addMouseListener(m_presetNameMouseListener, false);
auto* menuButton = findComponentT<juce::Button>("Menu", false);