From bf9ec425bb1b066aa9a2fe14ff88c5608eac25c8 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Mon, 22 Feb 2021 19:57:50 +0100 Subject: [PATCH] Send key ranges to editor --- plugins/editor/src/editor/Editor.cpp | 14 ++++++++++---- src/sfizz/Synth.cpp | 10 ++++++++++ src/sfizz/SynthMessaging.cpp | 8 ++++++++ src/sfizz/SynthPrivate.h | 1 + 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/plugins/editor/src/editor/Editor.cpp b/plugins/editor/src/editor/Editor.cpp index f56b7f0a..fa0bb186 100644 --- a/plugins/editor/src/editor/Editor.cpp +++ b/plugins/editor/src/editor/Editor.cpp @@ -219,7 +219,8 @@ void Editor::open(CFrame& frame) impl.frame_ = &frame; frame.addView(impl.mainView_.get()); - // request the whole CC information + // request the whole Key and CC information + impl.sendQueuedOSC("/key/slots", "", nullptr); impl.sendQueuedOSC("/cc/slots", "", nullptr); } @@ -244,7 +245,8 @@ void Editor::Impl::uiReceiveValue(EditId id, const EditValue& v) currentSfzFile_ = value; updateSfzFileLabel(value); - // request the whole CC information + // request the whole Key and CC information + sendQueuedOSC("/key/slots", "", nullptr); sendQueuedOSC("/cc/slots", "", nullptr); } break; @@ -390,7 +392,10 @@ void Editor::Impl::uiReceiveMessage(const char* path, const char* sig, const sfi { unsigned indices[8]; - if (Messages::matchOSC("/cc/slots", path, indices) && !strcmp(sig, "b")) { + if (Messages::matchOSC("/key/slots", path, indices) && !strcmp(sig, "b")) { + // TODO(jpc) key ranges + } + else if (Messages::matchOSC("/cc/slots", path, indices) && !strcmp(sig, "b")) { const uint8_t* bitChunks = args[0].b->data; uint32_t byteSize = args[0].b->size; @@ -962,7 +967,8 @@ void Editor::Impl::changeSfzFile(const std::string& filePath) currentSfzFile_ = filePath; updateSfzFileLabel(filePath); - // request the whole CC information + // request the whole Key and CC information + sendQueuedOSC("/key/slots", "", nullptr); sendQueuedOSC("/cc/slots", "", nullptr); } diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index c43302b7..c2f73319 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -249,6 +249,7 @@ void Synth::Impl::clear() currentUsedCCs_.clear(); changedCCsThisCycle_.clear(); keyLabels_.clear(); + keySlots_.clear(); keyswitchLabels_.clear(); globalOpcodes_.clear(); masterOpcodes_.clear(); @@ -735,6 +736,15 @@ void Synth::Impl::finalizeSfzLoad() // cache the set of used CCs for future access currentUsedCCs_ = collectAllUsedCCs(); + + // cache the set of keys assigned + for (const RegionPtr& regionPtr : regions_) { + Range keyRange = regionPtr->keyRange; + unsigned loKey = keyRange.getStart(); + unsigned hiKey = keyRange.getEnd(); + for (unsigned key = loKey; key <= hiKey; ++key) + keySlots_.set(key); + } } bool Synth::loadScalaFile(const fs::path& path) diff --git a/src/sfizz/SynthMessaging.cpp b/src/sfizz/SynthMessaging.cpp index 123fac10..f8672cca 100644 --- a/src/sfizz/SynthMessaging.cpp +++ b/src/sfizz/SynthMessaging.cpp @@ -38,6 +38,14 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co //---------------------------------------------------------------------- + MATCH("/key/slots", "") { + const BitArray<128>& keys = impl.keySlots_; + sfizz_blob_t blob { keys.data(), static_cast(keys.byte_size()) }; + client.receive<'b'>(delay, path, &blob); + } break; + + //---------------------------------------------------------------------- + MATCH("/cc/slots", "") { const BitArray& ccs = impl.currentUsedCCs_; sfizz_blob_t blob { ccs.data(), static_cast(ccs.byte_size()) }; diff --git a/src/sfizz/SynthPrivate.h b/src/sfizz/SynthPrivate.h index 08c3fcca..e0d3124a 100644 --- a/src/sfizz/SynthPrivate.h +++ b/src/sfizz/SynthPrivate.h @@ -216,6 +216,7 @@ struct Synth::Impl final: public Parser::Listener { std::vector ccLabels_; std::map ccLabelsMap_; std::vector keyLabels_; + BitArray<128> keySlots_; std::vector keyswitchLabels_; // Set as sw_default if present in the file