From 4392797fa6ae042dabe2de8c7452f02601a9a216 Mon Sep 17 00:00:00 2001 From: Christof Date: Mon, 21 Oct 2024 22:31:22 +0200 Subject: [PATCH] Fixed #355: Creating synth banks with fill didn't work if there were less patches available than required to make a full synth bank. Fixed by just repeating the last entry to make sure the entire bank is full. --- The-Orm/CreateListDialog.cpp | 2 +- The-Orm/CreateListDialog.h | 2 +- The-Orm/PatchView.cpp | 25 +++++++++++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/The-Orm/CreateListDialog.cpp b/The-Orm/CreateListDialog.cpp index 1efaf63f..0201e038 100644 --- a/The-Orm/CreateListDialog.cpp +++ b/The-Orm/CreateListDialog.cpp @@ -213,7 +213,7 @@ void CreateListDialog::notifyResult() else if (static_cast(fillMode_.getValue()) == 2) { fillParameters.fillMode = TListFillMode::Random; } - fillParameters.number = patchNumber_.getValue(); + fillParameters.number = (size_t) (patchNumber_.getValue().operator int()); callback_(list_, fillParameters); } diff --git a/The-Orm/CreateListDialog.h b/The-Orm/CreateListDialog.h index f398c30e..86216306 100644 --- a/The-Orm/CreateListDialog.h +++ b/The-Orm/CreateListDialog.h @@ -22,7 +22,7 @@ class CreateListDialog : public Component, private TextButton::Listener { }; struct TFillParameters { TListFillMode fillMode; - int number; + size_t number; }; typedef std::function result)> TCallback; typedef std::function result, TFillParameters fillParameters)> TCallbackWithFill; diff --git a/The-Orm/PatchView.cpp b/The-Orm/PatchView.cpp index cd888eca..908f5c7a 100644 --- a/The-Orm/PatchView.cpp +++ b/The-Orm/PatchView.cpp @@ -1081,22 +1081,39 @@ void PatchView::fillList(std::shared_ptr list, CreateListD else { auto filter = currentFilter(); auto synthBank = std::dynamic_pointer_cast(list); - int patchesDesired = fillParameters.number; + size_t patchesDesired = fillParameters.number; + size_t minimumPatches = 0; if (synthBank) { // This is a synth bank, restrict the filter to deliver only patches for the synth that the bank is for filter.synths.clear(); filter.synths[synthBank->synth()->getName()] = synthBank->synth(); patchesDesired = synthBank->patchCapacity(); + if (synthBank->bankNumber().bankSize() >= 0) { + minimumPatches = (size_t) synthBank->bankNumber().bankSize(); + } + else { + spdlog::error("Program error: Unknown bank size, can't fill bank with unknown number of patches"); + return; + } } if (fillParameters.fillMode == CreateListDialog::TListFillMode::Top) { - loadPage(0, patchesDesired, filter, [list, finishedCallback](std::vector patches) { + loadPage(0, (int) patchesDesired, filter, [list, finishedCallback, minimumPatches](std::vector patches) { + // Check if we need to extend the patches list to make sure we have enough patches to make a full bank + while (patches.size() < minimumPatches) { + patches.push_back(patches.back()); + } list->setPatches(patches); finishedCallback(); }); } else if (fillParameters.fillMode == CreateListDialog::TListFillMode::Random) { - loadPage(0, -1, filter, [list, patchesDesired, finishedCallback](std::vector patches) { - list->setPatches(getRandomSubset(patches, patchesDesired)); + loadPage(0, -1, filter, [list, patchesDesired, minimumPatches, finishedCallback](std::vector patches) { + // Check if we need to extend the patches list to make sure we have enough patches to make a full bank + auto randomPatches = getRandomSubset(patches, patchesDesired); + while (randomPatches.size() < minimumPatches) { + randomPatches.push_back(randomPatches.back()); + } + list->setPatches(randomPatches); finishedCallback(); }); }