-
Notifications
You must be signed in to change notification settings - Fork 26
/
SimplePatchGrid.cpp
53 lines (43 loc) · 1.48 KB
/
SimplePatchGrid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Copyright (c) 2023 Christof Ruch. All rights reserved.
Dual licensed: Distributed under Affero GPL license by default, an MIT license is available for purchase
*/
#include "SimplePatchGrid.h"
#include "PatchView.h"
#include "Data.h"
#include "UIModel.h"
#include <spdlog/spdlog.h>
SimplePatchGrid::SimplePatchGrid(PatchView* patchView) : patchView_(patchView)
{
grid_ = std::make_unique<PatchButtonPanel>([this](midikraft::PatchHolder& patch) { patchSelectedHandler(patch); }, "secondWindow");
addAndMakeVisible(*grid_);
// Setup the Grid so it always shows the same list as our main patch view
grid_->setPatchLoader([this](int skip, int limit, std::function<void(std::vector< midikraft::PatchHolder>)> callback) {
patchView_->loadPage(skip, limit, patchView_->currentFilter(), callback);
});
Data::ensureEphemeralPropertyExists(EPROPERTY_LIBRARY_PATCH_LIST, {});
listeners_.addListener(Data::getEphemeralPropertyAsValue(EPROPERTY_LIBRARY_PATCH_LIST), [this](juce::Value& newValue) {
ignoreUnused(newValue);
reload();
});
listeners_.triggerAll();
}
void SimplePatchGrid::resized()
{
auto bounds = getLocalBounds();
grid_->setBounds(bounds);
}
void SimplePatchGrid::reload()
{
grid_->setTotalCount(patchView_->getTotalCount());
grid_->refresh(true);
}
void SimplePatchGrid::patchSelectedHandler(midikraft::PatchHolder& patch)
{
spdlog::info("Patch {} selected", patch.name());
patchView_->selectPatch(patch, true);
if (onPatchSelected)
{
onPatchSelected(patch);
}
}