From 50d3ccaaf0382d5c6306392640f7c2ec25a7bd31 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Wed, 24 Mar 2021 12:46:59 +0100 Subject: [PATCH] Display overlap of key range and switches on VK --- plugins/editor/src/editor/GUIPiano.cpp | 31 ++++++++++++++++++-------- plugins/editor/src/editor/GUIPiano.h | 10 ++++----- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/plugins/editor/src/editor/GUIPiano.cpp b/plugins/editor/src/editor/GUIPiano.cpp index a2614a06..68f1636c 100644 --- a/plugins/editor/src/editor/GUIPiano.cpp +++ b/plugins/editor/src/editor/GUIPiano.cpp @@ -33,6 +33,7 @@ struct SPiano::Impl { float keyUsedHue_ = 0.55; float keySwitchHue_ = 0.0; + float keyUsedAndSwitchHue_ = 0.85; float whiteKeyChroma_ = 0.9; float blackKeyChroma_ = 0.75; float whiteKeyLuma_ = 0.9; @@ -125,19 +126,19 @@ void SPiano::setKeyValue(unsigned key, float value) invalid(); } -SPiano::KeyRole SPiano::getKeyRole(unsigned key) +int SPiano::getKeyRole(unsigned key) { Impl& impl = *impl_; + int role = 0; - if (key >= 128) - return KeyRole::Unused; + if (key < 128) { + if (impl.keyUsed_.test(key)) + role |= KeyRole::Note; + if (impl.keyswitchUsed_.test(key)) + role |= KeyRole::Switch; + } - if (impl.keyUsed_.test(key)) - return KeyRole::Note; - if (impl.keyswitchUsed_.test(key)) - return KeyRole::Switch; - - return KeyRole::Unused; + return role; } void SPiano::draw(CDrawContext* dc) @@ -170,6 +171,12 @@ void SPiano::draw(CDrawContext* dc) goto whiteKeyDefault; hcy.h = impl.keyUsedHue_; break; + case KeyRole::Note|KeyRole::Switch: + if (!allKeysUsed) { + hcy.h = impl.keyUsedAndSwitchHue_; + break; + } + // fall through case KeyRole::Switch: hcy.h = impl.keySwitchHue_; break; @@ -210,6 +217,12 @@ void SPiano::draw(CDrawContext* dc) goto blackKeyDefault; hcy.h = impl.keyUsedHue_; break; + case KeyRole::Note|KeyRole::Switch: + if (!allKeysUsed) { + hcy.h = impl.keyUsedAndSwitchHue_; + break; + } + // fall through case KeyRole::Switch: hcy.h = impl.keySwitchHue_; break; diff --git a/plugins/editor/src/editor/GUIPiano.h b/plugins/editor/src/editor/GUIPiano.h index d7e57fae..4bb662dc 100644 --- a/plugins/editor/src/editor/GUIPiano.h +++ b/plugins/editor/src/editor/GUIPiano.h @@ -29,13 +29,13 @@ public: void setKeyswitchUsed(unsigned key, bool used); void setKeyValue(unsigned key, float value); - enum class KeyRole { - Unused, - Note, - Switch, + enum KeyRole : int { + Unused = 0, + Note = 1 << 0, + Switch = 1 << 1, }; - KeyRole getKeyRole(unsigned key); + int getKeyRole(unsigned key); std::function onKeyPressed; std::function onKeyReleased;