Skip to content

Commit

Permalink
[coroutines] Using the second generation MidiCoroutines. Does this fe…
Browse files Browse the repository at this point in the history
…el better?
  • Loading branch information
christofmuc committed Jan 8, 2023
1 parent db56668 commit 6a8ad88
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
13 changes: 6 additions & 7 deletions The-Orm/BCR2000_Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "SendsProgramChangeCapability.h"
#include "CreateInitPatchDataCapability.h"

#include "MidiCoroutine.h"

#include "MidiHelpers.h"

#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -364,13 +366,10 @@ void BCR2000_Component::UpdateSynthListener::listenForMidiMessages(MidiInput* so
if (programChangeCap) {
programChangeCap->gotProgramChange(MidiProgramNumber::fromZeroBase(message.getProgramChangeNumber()));
if (location) {
papa_->librarian_.downloadEditBuffer(midikraft::MidiController::instance()->getMidiOutput(location->midiOutput()),
UIModel::currentSynthOfPatchSmart(), nullptr, [this](std::vector<midikraft::PatchHolder> patch) {
if (patch.size() > 0 && patch[0].patch()) {
updateAllKnobsFromPatch(patch[0].patch());
}
});

auto patch = midikraft::awaitMidiCoroutine(papa_->librarian_.downloadEditBuffer(midikraft::MidiController::instance()->getMidiOutput(location->midiOutput()), UIModel::currentSynthOfPatchSmart(), nullptr));
if (patch.size() > 0 && patch[0].patch()) {
updateAllKnobsFromPatch(patch[0].patch());
}
}
}
}
Expand Down
41 changes: 20 additions & 21 deletions The-Orm/PatchView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,31 +552,30 @@ void PatchView::retrieveEditBuffer()
auto activeSynth = UIModel::instance()->currentSynth_.smartSynth();
auto midiLocation = midikraft::Capability::hasCapability<midikraft::MidiLocationCapability>(activeSynth);
if (activeSynth && midiLocation) {
librarian_.downloadEditBuffer(midikraft::MidiController::instance()->getMidiOutput(midiLocation->midiOutput()),
activeSynth,
nullptr,
[this](std::vector<midikraft::PatchHolder> patchesLoaded) {
// There should only be one edit buffer, just check that this is true here
jassert(patchesLoaded.size() == 1);

if (patchesLoaded.size() == 1) {
spdlog::info("Current edit buffer from synth is patch '{}'", patchesLoaded[0].name());
}
midikraft::runMidiCoroutineWithCallback < std::vector<midikraft::PatchHolder>>(
librarian_.downloadEditBuffer(midikraft::MidiController::instance()->getMidiOutput(midiLocation->midiOutput()), activeSynth, nullptr),
[this](std::vector<midikraft::PatchHolder> const& patchesLoaded) {
// There should only be one edit buffer, just check that this is true here
jassert(patchesLoaded.size() == 1);

if (patchesLoaded.size() == 1) {
spdlog::info("Current edit buffer from synth is patch '{}'", patchesLoaded[0].name());
}

patchesLoaded = autoCategorize(patchesLoaded);
auto categorizedPatches = autoCategorize(patchesLoaded);

// Set a specific "EditBufferImport" source for those patches retrieved directly from the edit buffer
auto now = Time::getCurrentTime();
auto editBufferSource = std::make_shared<midikraft::FromSynthSource>(now);
for (auto &p : patchesLoaded) {
p.setSourceInfo(editBufferSource);
}
// Set a specific "EditBufferImport" source for those patches retrieved directly from the edit buffer
auto now = Time::getCurrentTime();
auto editBufferSource = std::make_shared<midikraft::FromSynthSource>(now);
for (auto& p : categorizedPatches) {
p.setSourceInfo(editBufferSource);
}

// Off to the UI thread (because we will update the UI)
MessageManager::callAsync([this, patchesLoaded]() {
mergeNewPatches(patchesLoaded);
// Off to the UI thread (because we will update the UI)
MessageManager::callAsync([this, categorizedPatches]() {
mergeNewPatches(categorizedPatches);
});
});
});
}
}

Expand Down

0 comments on commit 6a8ad88

Please sign in to comment.