From 2963e2d24c69496e68c7617653c1c4ab848ef72b Mon Sep 17 00:00:00 2001 From: Ben Kuper Date: Wed, 26 Jul 2023 17:06:02 +0200 Subject: [PATCH] Multiplex list Fill range improvements --- .../Multiplex/List/MultiplexList.cpp | 4 +- .../Processor/Multiplex/List/MultiplexList.h | 2 +- .../Multiplex/List/ui/MultiplexListEditor.cpp | 141 +++++++++++------- .../Multiplex/List/ui/MultiplexListEditor.h | 11 +- 4 files changed, 103 insertions(+), 55 deletions(-) diff --git a/Source/Common/Processor/Multiplex/List/MultiplexList.cpp b/Source/Common/Processor/Multiplex/List/MultiplexList.cpp index 3ce4ba396..2487f53f8 100644 --- a/Source/Common/Processor/Multiplex/List/MultiplexList.cpp +++ b/Source/Common/Processor/Multiplex/List/MultiplexList.cpp @@ -50,9 +50,9 @@ void BaseMultiplexList::updateControllablesSetup() } } -void BaseMultiplexList::fillFromExpression(const String& s) +void BaseMultiplexList::fillFromExpression(const String& s, int start, int end) { - for (int i = 0; i < listSize; i++) + for (int i = jmax(start - 1, 0); i < end; i++) { String exp = s.replace("{index}", String(i + 1)).replace("{index0}", String(i)); diff --git a/Source/Common/Processor/Multiplex/List/MultiplexList.h b/Source/Common/Processor/Multiplex/List/MultiplexList.h index 764fe0365..f6fa88730 100644 --- a/Source/Common/Processor/Multiplex/List/MultiplexList.h +++ b/Source/Common/Processor/Multiplex/List/MultiplexList.h @@ -31,7 +31,7 @@ class BaseMultiplexList : virtual void updateControllablesSetup(); - void fillFromExpression(const String& s); + void fillFromExpression(const String& s, int start, int end); virtual Controllable* createListControllable(); diff --git a/Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.cpp b/Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.cpp index 7a466f4c9..7c33d5197 100644 --- a/Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.cpp +++ b/Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.cpp @@ -242,79 +242,114 @@ void InputValueListEditor::handleFillMenuResult(int result) { case 3: - case 4: { ControllableContainer* cc = nullptr; - if (result == 2) + PopupMenu cp; + int offset = 0; + Array modules = ModuleManager::getInstance()->getModuleList(); + OwnedArray* choosers = new OwnedArray(); + for (auto& m : modules) { - PopupMenu cp; - int offset = 0; - Array modules = ModuleManager::getInstance()->getModuleList(); - OwnedArray* choosers = new OwnedArray(); - for (auto& m : modules) - { - ContainerChooserPopupMenu* chooser = new ContainerChooserPopupMenu(&m->valuesCC, offset, -1, nullptr, StringArray(), StringArray(), true); - choosers->add(chooser); - cp.addSubMenu(m->niceName, *chooser); - offset += 100000; - } + ContainerChooserPopupMenu* chooser = new ContainerChooserPopupMenu(&m->valuesCC, offset, -1, nullptr, StringArray(), StringArray(), true); + choosers->add(chooser); + cp.addSubMenu(m->niceName, *chooser); + offset += 100000; + } - cp.showMenuAsync(PopupMenu::Options(), [this, choosers](int ccResult) + cp.showMenuAsync(PopupMenu::Options(), [this, choosers](int ccResult) + { + if (ccResult > 0) { - if (ccResult > 0) - { - int chooserIndex = (int)floor(ccResult / 100000.0f); - ControllableContainer* cc = (*choosers)[chooserIndex]->getContainerForResult(ccResult); - Array> cList = cc->getAllControllables(); - for (int i = 0; i < baseList->listSize && i < cList.size(); i++) - { - ((TargetParameter*)baseList->list[i])->setValueFromTarget(cList[i]); - } - } - - delete choosers; + int chooserIndex = (int)floor(ccResult / 100000.0f); + ControllableContainer* cc = (*choosers)[chooserIndex]->getContainerForResult(ccResult); + Array> cList = cc->getAllControllables(); + showRangeMenuAndFillFromControllables(cList); } - ); - - if (cc != nullptr) - { + delete choosers; } - } - else + ); + + if (cc != nullptr) { - ContainerChooserPopupMenu* chooser = new ContainerChooserPopupMenu(Engine::mainEngine, 0, -1, nullptr, StringArray(), StringArray(), true); - chooser->showAndGetContainer([this, chooser](ControllableContainer* cc) - { - if (cc != nullptr) - { - Array> cList = cc->getAllControllables(); - for (int i = 0; i < baseList->listSize && i < cList.size(); i++) - { - ((TargetParameter*)baseList->list[i])->setValueFromTarget(cList[i]); - } - } - delete chooser; + } + } + break; + case 4: + { + ContainerChooserPopupMenu* chooser = new ContainerChooserPopupMenu(Engine::mainEngine, 0, -1, nullptr, StringArray(), StringArray(), true); + chooser->showAndGetContainer([this, chooser](ControllableContainer* cc) + { + if (cc != nullptr) + { + Array> cList = cc->getAllControllables(); + showRangeMenuAndFillFromControllables(cList); } - ); - } + + delete chooser; + } + ); } break; } } +void InputValueListEditor::showRangeMenuAndFillFromControllables(Array> cList) +{ + AlertWindow* nameWindow = new AlertWindow("Set the assignation range", "Set the start and end index to use to assign", AlertWindow::AlertIconType::NoIcon, this); + + + nameWindow->addTextEditor("cOffset", "Source Offset"); + nameWindow->addTextEditor("start", "Start Index"); + nameWindow->addTextEditor("end", "End Index"); + + nameWindow->addButton("OK", 1, KeyPress(KeyPress::returnKey)); + nameWindow->addButton("Cancel", 0, KeyPress(KeyPress::escapeKey)); + + nameWindow->enterModalState(true, ModalCallbackFunction::create([this, cList, nameWindow](int result) + { + if (result) + { + String cOffsetS = nameWindow->getTextEditorContents("cOffset"); + String startS = nameWindow->getTextEditorContents("start"); + String endS = nameWindow->getTextEditorContents("start"); + int cOffset = cOffsetS.isNotEmpty() ? cOffsetS.getIntValue() : 0; + int start = startS.isNotEmpty() ? jlimit(1, baseList->listSize, startS.getIntValue()) : 1; + int end = endS.isNotEmpty() ? jlimit(start, baseList->listSize, endS.getIntValue()) : baseList->listSize; + + + for (int i = start - 1; i < end && i < cList.size(); i++) + { + int cIndex = i - (start-1) + cOffset; + if (cIndex >= cList.size()) break; + + ((TargetParameter*)baseList->list[i])->setValueFromTarget(cList[cIndex]); + } + } + }), + true + ); +} + BaseMultiplexListEditor::ExpressionComponentWindow::ExpressionComponentWindow(BaseMultiplexList* list) : list(list), - assignBT("Assign") + assignBT("Assign"), + startIndex("Start", "Index at which to start the expression evaluation", 1, 1, list->listSize), + endIndex("End", "Index at which to stop the expression evaluation (inclusive)", list->listSize, 1, list->listSize), + startUI(&startIndex), + endUI(&endIndex) { - instructions.setText("This expression will be used to fill each item in this list. You can use wildcards {index} and {index0} to replace with index of the item that is processed.", dontSendNotification); + instructions.setText("This expression will be used to fill each item in this list. You can use wildcards {index} and {index0} to replace with index of the item that is processed. You can also modify the start and end index for narrowing down the evaluation.", dontSendNotification); addAndMakeVisible(&instructions); addAndMakeVisible(&editor); addAndMakeVisible(&assignBT); + addAndMakeVisible(&startUI); + addAndMakeVisible(&endUI); + assignBT.addListener(this); //addAndMakeVisible(&closeBT); @@ -323,13 +358,19 @@ BaseMultiplexListEditor::ExpressionComponentWindow::ExpressionComponentWindow(Ba editor.setColour(editor.textColourId, TEXT_COLOR); editor.setMultiLine(true); - setSize(600, 300); + setSize(600, 330); } void BaseMultiplexListEditor::ExpressionComponentWindow::resized() { Rectangle r = getLocalBounds().reduced(2); instructions.setBounds(r.removeFromTop(60).reduced(8)); + + Rectangle ir = r.removeFromTop(30).reduced(8); + startUI.setBounds(ir.removeFromLeft(100)); + ir.removeFromLeft(16); + endUI.setBounds(ir.removeFromLeft(100)); + editor.setBounds(r.removeFromTop(100)); assignBT.setBounds(r.removeFromTop(40).reduced(2)); } @@ -338,7 +379,7 @@ void BaseMultiplexListEditor::ExpressionComponentWindow::buttonClicked(Button* b { if (b == &assignBT) { - list->fillFromExpression(editor.getText()); + list->fillFromExpression(editor.getText(), startIndex.intValue(), endIndex.intValue()); } } diff --git a/Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.h b/Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.h index 561ac7ee7..44f27e78a 100644 --- a/Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.h +++ b/Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.h @@ -24,7 +24,7 @@ class BaseMultiplexListEditor : void buttonClicked(Button* b) override; - virtual void addItemsToFillMenu(PopupMenu &p) {} + virtual void addItemsToFillMenu(PopupMenu& p) {} virtual void handleFillMenuResult(int result) {} class ExpressionComponentWindow : @@ -42,6 +42,11 @@ class BaseMultiplexListEditor : TextButton assignBT; TextButton closeBT; + IntParameter startIndex; + IntParameter endIndex; + IntStepperUI startUI; + IntStepperUI endUI; + void resized() override; void buttonClicked(Button* b) override; @@ -141,8 +146,10 @@ class InputValueListEditor : InputValueMultiplexList* list; - void addItemsToFillMenu(PopupMenu &p) override; + void addItemsToFillMenu(PopupMenu& p) override; void handleFillMenuResult(int result) override; + + void showRangeMenuAndFillFromControllables(Array> controllables); };