From bd6073b43920aebff7696a9cf8aadbd984cc518d Mon Sep 17 00:00:00 2001 From: Christoph Hart Date: Wed, 16 Oct 2024 20:36:40 +0200 Subject: [PATCH] - fix #583 - fix #544 --- currentGitHash.txt | 2 +- hi_backend/backend/currentGit.h | 2 +- .../scripting/scriptnode/api/DspNetwork.cpp | 78 ++++++++ .../scripting/scriptnode/api/DspNetwork.h | 12 ++ .../scriptnode/api/StaticNodeWrappers.cpp | 1 + .../scriptnode/ui/DspNetworkComponents.cpp | 188 ++++-------------- .../scripting/scriptnode/ui/NodeComponent.cpp | 3 +- .../scriptnode/ui/NodeContainerComponent.cpp | 10 +- 8 files changed, 135 insertions(+), 161 deletions(-) diff --git a/currentGitHash.txt b/currentGitHash.txt index 634c1482fa..6ea1fd20c2 100644 --- a/currentGitHash.txt +++ b/currentGitHash.txt @@ -1 +1 @@ -66bdd1eb58f13d0b2b742d79533176365f78a784 +4572cb0361e619914f05c8a26845f6310d53fcc8 diff --git a/hi_backend/backend/currentGit.h b/hi_backend/backend/currentGit.h index 7b01464824..dde2ee4abf 100644 --- a/hi_backend/backend/currentGit.h +++ b/hi_backend/backend/currentGit.h @@ -1 +1 @@ -#define PREVIOUS_HISE_COMMIT "66bdd1eb58f13d0b2b742d79533176365f78a784" +#define PREVIOUS_HISE_COMMIT "4572cb0361e619914f05c8a26845f6310d53fcc8" diff --git a/hi_scripting/scripting/scriptnode/api/DspNetwork.cpp b/hi_scripting/scripting/scriptnode/api/DspNetwork.cpp index 6db308cc43..1041a7b5ef 100644 --- a/hi_scripting/scripting/scriptnode/api/DspNetwork.cpp +++ b/hi_scripting/scripting/scriptnode/api/DspNetwork.cpp @@ -2439,6 +2439,84 @@ void HostHelpers::setNumDataObjectsFromValueTree(OpaqueNode& on, const ValueTree } #if USE_BACKEND +ValueTree DuplicateHelpers::findRoot(const ValueTree& v) +{ + auto p = v.getParent(); + + if(!p.isValid()) + return v; + + return findRoot(p); +} + +void DuplicateHelpers::removeOutsideConnections(const Array& newNodes, + const Array& idChanges) +{ + for(auto& ct: newNodes) + { + Array connectionsToRemove; + + valuetree::Helpers::forEach(ct, [&](ValueTree& c) + { + if(c.getType() == PropertyIds::Connection) + { + auto thisTarget = c[PropertyIds::NodeId].toString(); + auto found = false; + + for(const auto& ch: idChanges) + { + found |= ch.newId == thisTarget; + } + + if(!found) + connectionsToRemove.add(c); + } + + return false; + }); + + for(const auto& c: connectionsToRemove) + c.getParent().removeChild(c, nullptr); + } +} + +int DuplicateHelpers::getIndexInRoot(const ValueTree& v) +{ + auto p = findRoot(v); + + int index = 0; + auto iptr = &index; + + valuetree::Helpers::forEach(p, [&iptr, v](ValueTree& c) + { + *iptr = *iptr + 1; + return c == v; + }); + + return index; +} + +int DuplicateHelpers::compareElements(const WeakReference& n1, const WeakReference& n2) +{ + if(n1 == n2) + return 0; + + if(n1 != nullptr && n2 != nullptr) + { + auto i1 = getIndexInRoot(n1->getValueTree()); + auto i2 = getIndexInRoot(n2->getValueTree()); + + if(i1 < i2) + return 1; + if(i1 > i2) + return -1; + } + + jassertfalse; + return 0; +} + + void DspNetworkListeners::DspNetworkGraphRootListener::onChangeStatic(DspNetworkGraphRootListener& l, NodeBase* n) { if(n != nullptr) diff --git a/hi_scripting/scripting/scriptnode/api/DspNetwork.h b/hi_scripting/scripting/scriptnode/api/DspNetwork.h index 9dbde6a996..dbcadff98e 100644 --- a/hi_scripting/scripting/scriptnode/api/DspNetwork.h +++ b/hi_scripting/scripting/scriptnode/api/DspNetwork.h @@ -991,6 +991,18 @@ struct HostHelpers struct DspNetworkGraph; +struct DuplicateHelpers +{ + static ValueTree findRoot(const ValueTree& v); + + static void removeOutsideConnections(const Array& newNodes, const Array& idChanges); + + static int getIndexInRoot(const ValueTree& v); + + // This sorts it reversed so that the index works when duplicating + static int compareElements(const WeakReference& n1, const WeakReference& n2); +}; + struct DspNetworkListeners { struct DspNetworkGraphRootListener diff --git a/hi_scripting/scripting/scriptnode/api/StaticNodeWrappers.cpp b/hi_scripting/scripting/scriptnode/api/StaticNodeWrappers.cpp index 9e020bedb7..041f16e2cc 100644 --- a/hi_scripting/scripting/scriptnode/api/StaticNodeWrappers.cpp +++ b/hi_scripting/scripting/scriptnode/api/StaticNodeWrappers.cpp @@ -802,6 +802,7 @@ TemplateNodeFactory::TemplateNodeFactory(DspNetwork* n) : Array changes; auto newTree = n->cloneValueTreeWithNewIds(v, changes, false); + DuplicateHelpers::removeOutsideConnections({ newTree }, changes ); for(auto& c: changes) n->changeNodeId(newTree, c.oldId, c.newId, nullptr); diff --git a/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.cpp b/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.cpp index a664ad812e..4b695cdbd6 100644 --- a/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.cpp +++ b/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.cpp @@ -1582,12 +1582,28 @@ bool DspNetworkGraph::Actions::swapOrientation(DspNetworkGraph& g) for (auto n : l) { - if (auto sn = dynamic_cast(n.get())) + if(auto sn = dynamic_cast(n.get())) + { sn->isVertical.storeValue(!sn->isVertical.getValue(), sn->getUndoManager()); + + auto dg = &g; + + auto f = [sn, dg]() + { + if(auto b = dg->getComponent(sn)) + { + auto cb = dg->getLocalArea(b, b->getLocalBounds()); + dg->findParentComponentOfClass()->zoomToRectangle(cb); + } + }; + + MessageManager::callAsync(f); + + return true; + } } - g.setTransform({}); - g.findParentComponentOfClass()->centerCanvas(); + return true; } @@ -1712,99 +1728,6 @@ bool DspNetworkGraph::Actions::unfreezeNode(NodeBase::Ptr node) } } - - - - - - - - - - - - -#if 0 - if (auto hc = node->getAsRestorableNode()) - { - // Check if there is already a node that was unfrozen - - for (auto n : node->getRootNetwork()->getListOfUnconnectedNodes()) - { - if (n->getValueTree()[PropertyIds::FreezedId].toString() == node->getId()) - { - auto newTree = n->getValueTree(); - auto oldTree = node->getValueTree(); - auto um = node->getUndoManager(); - - auto f = [oldTree, newTree, um]() - { - auto p = oldTree.getParent(); - - int position = p.indexOf(oldTree); - p.removeChild(oldTree, um); - p.addChild(newTree, position, um); - }; - - MessageManager::callAsync(f); - - auto nw = node->getRootNetwork(); - - auto s = [newTree, nw]() - { - auto newNode = nw->getNodeForValueTree(newTree); - nw->deselectAll(); - nw->addToSelection(newNode, ModifierKeys()); - }; - - MessageManager::callAsync(s); - - return true; - } - } - - auto t = hc->getSnippetText(); - - if (t.isNotEmpty()) - { - auto newTree = ValueTreeConverters::convertBase64ToValueTree(t, true); - newTree = node->getRootNetwork()->cloneValueTreeWithNewIds(newTree); - newTree.setProperty(PropertyIds::FreezedPath, node->getValueTree()[PropertyIds::FactoryPath], nullptr); - newTree.setProperty(PropertyIds::FreezedId, node->getId(), nullptr); - - { - auto oldTree = node->getValueTree(); - auto um = node->getUndoManager(); - - auto newNode = node->getRootNetwork()->createFromValueTree(true, newTree, true); - - auto f = [oldTree, newTree, um]() - { - auto p = oldTree.getParent(); - - int position = p.indexOf(oldTree); - p.removeChild(oldTree, um); - p.addChild(newTree, position, um); - }; - - MessageManager::callAsync(f); - - auto nw = node->getRootNetwork(); - - auto s = [newNode, nw]() - { - nw->deselectAll(); - nw->addToSelection(newNode, ModifierKeys()); - }; - - MessageManager::callAsync(s); - } - } - - return true; - } -#endif - return false; } @@ -2526,59 +2449,12 @@ bool DspNetworkGraph::Actions::showKeyboardPopup(DspNetworkGraph& g, KeyboardPop return true; } -struct DuplicateHelpers -{ - static ValueTree findRoot(const ValueTree& v) - { - auto p = v.getParent(); - - if(!p.isValid()) - return v; - - return findRoot(p); - } - - static int getIndexInRoot(const ValueTree& v) - { - auto p = findRoot(v); - - int index = 0; - auto iptr = &index; - - valuetree::Helpers::forEach(p, [&iptr, v](ValueTree& c) - { - *iptr = *iptr + 1; - return c == v; - }); - - return index; - } - - // This sorts it reversed so that the index works when duplicating - static int compareElements(const WeakReference& n1, const WeakReference& n2) - { - if(n1 == n2) - return 0; - - if(n1 != nullptr && n2 != nullptr) - { - auto i1 = getIndexInRoot(n1->getValueTree()); - auto i2 = getIndexInRoot(n2->getValueTree()); - - if(i1 < i2) - return 1; - if(i1 > i2) - return -1; - } - - jassertfalse; - return 0; - } -}; + bool DspNetworkGraph::Actions::duplicateSelection(DspNetworkGraph& g) { +#if USE_BACKEND int insertIndex = 0; for (auto n : g.network->getSelection()) @@ -2586,9 +2462,7 @@ bool DspNetworkGraph::Actions::duplicateSelection(DspNetworkGraph& g) auto tree = n->getValueTree(); insertIndex = jmax(insertIndex, tree.getParent().indexOf(tree) + 1); } - - - + Array changes; struct TreeData @@ -2599,7 +2473,6 @@ bool DspNetworkGraph::Actions::duplicateSelection(DspNetworkGraph& g) auto sortedSelection = g.network->getSelection(); - DuplicateHelpers h; sortedSelection.sort(h); @@ -2623,14 +2496,25 @@ bool DspNetworkGraph::Actions::duplicateSelection(DspNetworkGraph& g) { g.network->changeNodeId(ct.newTree, c.oldId, c.newId, nullptr); } - + } + + Array newNodes; + + for(auto& ct: clonedTrees) + newNodes.add(ct.newTree); + + h.removeOutsideConnections(newNodes, changes); + + for(auto& ct: clonedTrees) + { g.network->createFromValueTree(true, ct.newTree, true); ct.location.getParent().addChild(ct.newTree, insertIndex, g.network->getUndoManager()); insertIndex = ct.location.getParent().indexOf(ct.newTree); } g.network->runPostInitFunctions(); - + +#endif return true; } @@ -3067,6 +2951,8 @@ void KeyboardPopup::addNodeAndClose(String path) for(auto& c: changes) network->changeNodeId(newTree, c.oldId, c.newId, nullptr); + BACKEND_ONLY(DuplicateHelpers::removeOutsideConnections(newTree, changes)); + newNode = network->createFromValueTree(true, newTree, true); auto as = dynamic_cast(container); diff --git a/hi_scripting/scripting/scriptnode/ui/NodeComponent.cpp b/hi_scripting/scripting/scriptnode/ui/NodeComponent.cpp index 827a2fbb61..df7f5960a8 100644 --- a/hi_scripting/scripting/scriptnode/ui/NodeComponent.cpp +++ b/hi_scripting/scripting/scriptnode/ui/NodeComponent.cpp @@ -574,8 +574,7 @@ void NodeComponent::paintOverChildren(Graphics& g) if (isBeingCopied()) { Path p; - p.loadPathFromData(HiBinaryData::ProcessorEditorHeaderIcons::addIcon, - sizeof(HiBinaryData::ProcessorEditorHeaderIcons::addIcon)); + p.loadPathFromData(HiBinaryData::ProcessorEditorHeaderIcons::addIcon, HiBinaryData::ProcessorEditorHeaderIcons::addIcon_Size); auto b = getLocalBounds().toFloat().withSizeKeepingCentre(32, 32); diff --git a/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.cpp b/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.cpp index 62eed27f3b..0cc21ed7cc 100644 --- a/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.cpp +++ b/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.cpp @@ -281,13 +281,15 @@ void ContainerComponent::insertDraggedNode(NodeComponent* newNode, bool copyNode { auto newTree = newNode->node->getValueTree(); auto container = dynamic_cast(node.get()); - - if (copyNode) { Array changes; auto copy = node->getRootNetwork()->cloneValueTreeWithNewIds(newTree, changes, true); + + + BACKEND_ONLY(DuplicateHelpers::removeOutsideConnections({ copy }, changes)); + node->getRootNetwork()->createFromValueTree(container->isPolyphonic(), copy, true); container->getNodeTree().addChild(copy, insertPosition, node->getUndoManager()); } @@ -1318,10 +1320,6 @@ void MacroPropertyEditor::ConnectionEditor::buttonClicked(Button* b) ValueTree lockedContainer; - - - - valuetree::Helpers::forEachParent(nv, [&](ValueTree& v) { if(v.getType() == PropertyIds::Node)