From 4572cb0361e619914f05c8a26845f6310d53fcc8 Mon Sep 17 00:00:00 2001 From: Christoph Hart Date: Wed, 16 Oct 2024 13:17:28 +0200 Subject: [PATCH] - fix #584 - make goto button in connection list work with locked containers --- currentGitHash.txt | 2 +- hi_backend/backend/currentGit.h | 2 +- .../scriptnode/ui/DspNetworkComponents.cpp | 10 ++- .../scriptnode/ui/DspNetworkComponents.h | 2 +- .../scriptnode/ui/NodeContainerComponent.cpp | 68 +++++++++++++++++-- .../scriptnode/ui/NodeContainerComponent.h | 35 +++++++--- 6 files changed, 99 insertions(+), 20 deletions(-) diff --git a/currentGitHash.txt b/currentGitHash.txt index c894d54eb9..634c1482fa 100644 --- a/currentGitHash.txt +++ b/currentGitHash.txt @@ -1 +1 @@ -f6a6c7169429983f39eb61d125468dd060fb2ed8 +66bdd1eb58f13d0b2b742d79533176365f78a784 diff --git a/hi_backend/backend/currentGit.h b/hi_backend/backend/currentGit.h index a8214482a1..7b01464824 100644 --- a/hi_backend/backend/currentGit.h +++ b/hi_backend/backend/currentGit.h @@ -1 +1 @@ -#define PREVIOUS_HISE_COMMIT "f6a6c7169429983f39eb61d125468dd060fb2ed8" +#define PREVIOUS_HISE_COMMIT "66bdd1eb58f13d0b2b742d79533176365f78a784" diff --git a/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.cpp b/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.cpp index 3b4312832f..a664ad812e 100644 --- a/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.cpp +++ b/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.cpp @@ -566,7 +566,7 @@ struct RootUndoAction: public UndoableAction WeakReference prev, current; }; -void DspNetworkGraph::setCurrentRootNode(NodeBase* newRoot, bool useUndo) +void DspNetworkGraph::setCurrentRootNode(NodeBase* newRoot, bool useUndo, bool allowAnimation) { if(newRoot == network->getRootNode()) newRoot = nullptr; @@ -611,7 +611,8 @@ void DspNetworkGraph::setCurrentRootNode(NodeBase* newRoot, bool useUndo) auto zoomFactor = zoomIn ? 1.008f : JUCE_LIVE_CONSTANT_OFF(0.993f); - parent->makeSwapSnapshot(zoomFactor); + if(allowAnimation) + parent->makeSwapSnapshot(zoomFactor); auto g = this; @@ -626,7 +627,10 @@ void DspNetworkGraph::setCurrentRootNode(NodeBase* newRoot, bool useUndo) g->grabKeyboardFocus(); }; - Timer::callAfterDelay(JUCE_LIVE_CONSTANT_OFF(350), f); + if(allowAnimation) + Timer::callAfterDelay(JUCE_LIVE_CONSTANT_OFF(350), f); + else + f(); } } diff --git a/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.h b/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.h index d63153af33..85b8250636 100644 --- a/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.h +++ b/hi_scripting/scripting/scriptnode/ui/DspNetworkComponents.h @@ -767,7 +767,7 @@ class DspNetworkGraph : public ComponentWithMiddleMouseDrag, UndoManager rootUndoManager; - void setCurrentRootNode(NodeBase* newRoot, bool useUndo=true); + void setCurrentRootNode(NodeBase* newRoot, bool useUndo=true, bool allowAnimation=true); NodeBase* getCurrentRootNode() const { return currentRootNode != nullptr ? currentRootNode.get() : network->getRootNode(); } diff --git a/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.cpp b/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.cpp index 754b5b5e4c..62eed27f3b 100644 --- a/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.cpp +++ b/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.cpp @@ -1295,21 +1295,79 @@ void MacroPropertyEditor::ConnectionEditor::buttonClicked(Button* b) } else if (b == &gotoButton) { - if (auto targetNode = node->getRootNetwork()->getNodeWithId(data[PropertyIds::NodeId].toString())) + auto nodeToShow = node.get(); + + if(showSource) + { + nodeToShow = node->getRootNetwork()->getNodeForValueTree(valuetree::Helpers::findParentWithType(data, PropertyIds::Node)); + } + else + { + auto nodeId = data[PropertyIds::NodeId].toString(); + nodeToShow = node->getRootNetwork()->getNodeWithId(nodeId); + } + + if (nodeToShow != nullptr) { auto sp = findParentComponentOfClass(); - auto gotoNode = [sp, targetNode]() + auto gotoNode = [sp, nodeToShow]() { + auto nv = nodeToShow->getValueTree(); + auto um = nodeToShow->getUndoManager(); + + ValueTree lockedContainer; + + + + + + valuetree::Helpers::forEachParent(nv, [&](ValueTree& v) + { + if(v.getType() == PropertyIds::Node) + { + v.setProperty(PropertyIds::Folded, false, um); + + if(v[PropertyIds::Locked]) + { + lockedContainer = v; + return true; + } + + } + + return false; + }); + sp->setCurrentModalWindow(nullptr, {}); - if (auto nc = sp->getContent()->getComponent(targetNode)) + auto currentRootTree = sp->getContent()->getCurrentRootNode()->getValueTree(); + + if(!lockedContainer.isValid() && !nodeToShow->getValueTree().isAChildOf(currentRootTree)) + { + lockedContainer = nodeToShow->getValueTree(); + + if(lockedContainer.getParent().getType() == PropertyIds::Nodes) + lockedContainer = lockedContainer.getParent().getParent(); + } + + if(lockedContainer.isValid()) + { + if(auto newRoot = nodeToShow->getRootNetwork()->getNodeForValueTree(lockedContainer, false)) + { + sp->getContent()->setCurrentRootNode(newRoot, true, false); + } + } + + + + if (auto nc = sp->getContent()->getComponent(nodeToShow)) { nc->grabKeyboardFocus(); } - targetNode->getRootNetwork()->deselectAll(); - targetNode->getRootNetwork()->addToSelection(targetNode, ModifierKeys()); + nodeToShow->getRootNetwork()->deselectAll(); + nodeToShow->getRootNetwork()->addToSelection(nodeToShow, ModifierKeys()); }; MessageManager::callAsync(gotoNode); diff --git a/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.h b/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.h index 97beef694a..49da320241 100644 --- a/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.h +++ b/hi_scripting/scripting/scriptnode/ui/NodeContainerComponent.h @@ -289,15 +289,24 @@ struct MacroPropertyEditor : public Component, addAndMakeVisible(connectionViewport); connectionViewport.setViewedComponent(&connectionContent, false); + if(parameter != nullptr) + { + if(parameter->data[PropertyIds::Automated]) + { + connectionArray.addIfNotAlreadyThere(parameter->getConnectionSourceTree(false)); + } + else + { + addAndMakeVisible(connectionButton); + connectionButton.setLookAndFeel(&blaf); + connectionButton.addListener(this); + } + } + int height = jmin(700, connectionArray.isEmpty() ? 10 : (100 + (connectionArray.size() * 110))); - if (!containerMode) - { + if(connectionButton.isVisible()) height += 32; - addAndMakeVisible(connectionButton); - connectionButton.setLookAndFeel(&blaf); - connectionButton.addListener(this); - } setSize(parameterProperties.getWidth() + connectionViewport.getScrollBarThickness(), parameterProperties.getHeight() + height); @@ -331,7 +340,7 @@ struct MacroPropertyEditor : public Component, auto b = getLocalBounds(); b.removeFromTop(y); - if(!containerMode) + if(connectionButton.isVisible()) connectionButton.setBounds(b.removeFromBottom(32)); connectionViewport.setBounds(b); @@ -340,7 +349,7 @@ struct MacroPropertyEditor : public Component, resizer.setBounds(getLocalBounds().removeFromRight(s).removeFromBottom(s)); } - static String getPathFromNode(bool showSource, ValueTree& data) + static String getPathFromNode(bool showSource, const ValueTree& data) { String text; @@ -396,7 +405,15 @@ struct MacroPropertyEditor : public Component, continue; } - auto newEditor = new ConnectionEditor(node, c, !containerMode); + auto isSource = true; + + if(parameter != nullptr && c.isAChildOf(parameter->data)) + isSource = false; + + if(parameter == nullptr) + isSource = false; + + auto newEditor = new ConnectionEditor(node, c, isSource); connectionContent.addAndMakeVisible(newEditor); connectionEditors.add(newEditor); }