Skip to content

Commit

Permalink
Multiplex list Fill range improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Jul 26, 2023
1 parent 3ccbcbb commit 2963e2d
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Source/Common/Processor/Multiplex/List/MultiplexList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion Source/Common/Processor/Multiplex/List/MultiplexList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
141 changes: 91 additions & 50 deletions Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Module*> modules = ModuleManager::getInstance()->getModuleList();
OwnedArray<ContainerChooserPopupMenu>* choosers = new OwnedArray<ContainerChooserPopupMenu>();
for (auto& m : modules)
{
PopupMenu cp;
int offset = 0;
Array<Module*> modules = ModuleManager::getInstance()->getModuleList();
OwnedArray<ContainerChooserPopupMenu>* choosers = new OwnedArray<ContainerChooserPopupMenu>();
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<WeakReference<Controllable>> 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<WeakReference<Controllable>> 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<WeakReference<Controllable>> 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<WeakReference<Controllable>> cList = cc->getAllControllables();
showRangeMenuAndFillFromControllables(cList);
}
);
}

delete chooser;
}
);
}
break;
}
}

void InputValueListEditor::showRangeMenuAndFillFromControllables(Array<WeakReference<Controllable>> 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);

Expand All @@ -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<int> r = getLocalBounds().reduced(2);
instructions.setBounds(r.removeFromTop(60).reduced(8));

Rectangle<int> 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));
}
Expand All @@ -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());
}
}

Expand Down
11 changes: 9 additions & 2 deletions Source/Common/Processor/Multiplex/List/ui/MultiplexListEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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;
Expand Down Expand Up @@ -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<WeakReference<Controllable>> controllables);
};


0 comments on commit 2963e2d

Please sign in to comment.