From 9de0648075ea31692c0ee874c5d4a16f8fdcba7b Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Tue, 23 Feb 2021 03:03:10 +0100 Subject: [PATCH] Convert the editor to use BitArray --- plugins/editor/CMakeLists.txt | 2 +- plugins/editor/src/editor/Editor.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/editor/CMakeLists.txt b/plugins/editor/CMakeLists.txt index ee8b259d..1c10dab7 100644 --- a/plugins/editor/CMakeLists.txt +++ b/plugins/editor/CMakeLists.txt @@ -69,7 +69,7 @@ else() target_include_directories(sfizz_editor PRIVATE ${sfizz-gio_INCLUDE_DIRS}) target_link_libraries(sfizz_editor PRIVATE ${sfizz-gio_LIBRARIES}) endif() -target_link_libraries(sfizz_editor PRIVATE sfizz::filesystem) +target_link_libraries(sfizz_editor PRIVATE sfizz::bit_array sfizz::filesystem) # layout tool if(NOT CMAKE_CROSSCOMPILING) diff --git a/plugins/editor/src/editor/Editor.cpp b/plugins/editor/src/editor/Editor.cpp index fa0bb186..14987bf1 100644 --- a/plugins/editor/src/editor/Editor.cpp +++ b/plugins/editor/src/editor/Editor.cpp @@ -10,6 +10,7 @@ #include "GUIComponents.h" #include "GUIPiano.h" #include "NativeHelpers.h" +#include "BitArray.h" #include "plugin/MessageUtils.h" #include #include @@ -396,11 +397,10 @@ void Editor::Impl::uiReceiveMessage(const char* path, const char* sig, const sfi // 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; - - for (unsigned cc = 0; cc < 8 * byteSize; ++cc) { - bool used = bitChunks[cc / 8] & (1u << (cc % 8)); + size_t numBits = 8 * args[0].b->size; + ConstBitSpan bits { args[0].b->data, numBits }; + for (unsigned cc = 0; cc < numBits; ++cc) { + bool used = bits.test(cc); updateCCUsed(cc, used); if (used) { char pathBuf[256]; @@ -414,10 +414,10 @@ void Editor::Impl::uiReceiveMessage(const char* path, const char* sig, const sfi } } else if (Messages::matchOSC("/cc/changed", path, indices) && !strcmp(sig, "b")) { - const uint8_t* bitChunks = args[0].b->data; - uint32_t byteSize = args[0].b->size; - for (unsigned cc = 0; cc < 8 * byteSize; ++cc) { - bool changed = bitChunks[cc / 8] & (1u << (cc % 8)); + size_t numBits = 8 * args[0].b->size; + ConstBitSpan bits { args[0].b->data, numBits }; + for (unsigned cc = 0; cc < numBits; ++cc) { + bool changed = bits.test(cc); if (changed) { char pathBuf[256]; sprintf(pathBuf, "/cc%u/value", cc);