Skip to content

Commit

Permalink
Fixed #355: Creating synth banks with fill didn't work if there were …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
christofmuc committed Oct 21, 2024
1 parent f76edd1 commit 4392797
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion The-Orm/CreateListDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void CreateListDialog::notifyResult()
else if (static_cast<int>(fillMode_.getValue()) == 2) {
fillParameters.fillMode = TListFillMode::Random;
}
fillParameters.number = patchNumber_.getValue();
fillParameters.number = (size_t) (patchNumber_.getValue().operator int());
callback_(list_, fillParameters);
}

Expand Down
2 changes: 1 addition & 1 deletion The-Orm/CreateListDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CreateListDialog : public Component, private TextButton::Listener {
};
struct TFillParameters {
TListFillMode fillMode;
int number;
size_t number;
};
typedef std::function<void(std::shared_ptr<midikraft::PatchList> result)> TCallback;
typedef std::function<void(std::shared_ptr<midikraft::PatchList> result, TFillParameters fillParameters)> TCallbackWithFill;
Expand Down
25 changes: 21 additions & 4 deletions The-Orm/PatchView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,22 +1081,39 @@ void PatchView::fillList(std::shared_ptr<midikraft::PatchList> list, CreateListD
else {
auto filter = currentFilter();
auto synthBank = std::dynamic_pointer_cast<midikraft::SynthBank>(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<midikraft::PatchHolder> patches) {
loadPage(0, (int) patchesDesired, filter, [list, finishedCallback, minimumPatches](std::vector<midikraft::PatchHolder> 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<midikraft::PatchHolder> patches) {
list->setPatches(getRandomSubset(patches, patchesDesired));
loadPage(0, -1, filter, [list, patchesDesired, minimumPatches, finishedCallback](std::vector<midikraft::PatchHolder> 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();
});
}
Expand Down

0 comments on commit 4392797

Please sign in to comment.