diff --git a/The-Orm/BCR2000_Component.cpp b/The-Orm/BCR2000_Component.cpp index 69741278..9e03010a 100644 --- a/The-Orm/BCR2000_Component.cpp +++ b/The-Orm/BCR2000_Component.cpp @@ -21,6 +21,8 @@ #include "SendsProgramChangeCapability.h" #include "CreateInitPatchDataCapability.h" +#include "MidiCoroutine.h" + #include "MidiHelpers.h" #include @@ -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 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()); + } } } } diff --git a/The-Orm/PatchView.cpp b/The-Orm/PatchView.cpp index 6ffa27ce..4859ee9e 100644 --- a/The-Orm/PatchView.cpp +++ b/The-Orm/PatchView.cpp @@ -552,31 +552,30 @@ void PatchView::retrieveEditBuffer() auto activeSynth = UIModel::instance()->currentSynth_.smartSynth(); auto midiLocation = midikraft::Capability::hasCapability(activeSynth); if (activeSynth && midiLocation) { - librarian_.downloadEditBuffer(midikraft::MidiController::instance()->getMidiOutput(midiLocation->midiOutput()), - activeSynth, - nullptr, - [this](std::vector 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>( + librarian_.downloadEditBuffer(midikraft::MidiController::instance()->getMidiOutput(midiLocation->midiOutput()), activeSynth, nullptr), + [this](std::vector 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(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(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); + }); }); - }); } }