From 099ee14b018c7be8dc6f3311eb62393ece1055df Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Mon, 12 Apr 2021 15:24:34 +0200 Subject: [PATCH] Use a color pair for key/switch, giving switch priority --- plugins/editor/src/editor/GUIPiano.cpp | 23 +++++------------------ plugins/editor/src/editor/GUIPiano.h | 4 ++-- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/plugins/editor/src/editor/GUIPiano.cpp b/plugins/editor/src/editor/GUIPiano.cpp index 9ea88959..4091ef60 100644 --- a/plugins/editor/src/editor/GUIPiano.cpp +++ b/plugins/editor/src/editor/GUIPiano.cpp @@ -33,7 +33,6 @@ 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; @@ -126,16 +125,16 @@ void SPiano::setKeyValue(unsigned key, float value) invalid(); } -int SPiano::getKeyRole(unsigned key) +SPiano::KeyRole SPiano::getKeyRole(unsigned key) { Impl& impl = *impl_; - int role = 0; + KeyRole role = KeyRole::Unused; if (key < 128) { - if (impl.keyUsed_.test(key)) - role |= KeyRole::Note; if (impl.keyswitchUsed_.test(key)) - role |= KeyRole::Switch; + role = KeyRole::Switch; + else if (impl.keyUsed_.test(key)) + role = KeyRole::Note; } return role; @@ -189,12 +188,6 @@ 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; @@ -235,12 +228,6 @@ 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 9cbccd29..b20a6f88 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 KeyRole : int { + enum class KeyRole : int { Unused = 0, Note = 1 << 0, Switch = 1 << 1, }; - int getKeyRole(unsigned key); + KeyRole getKeyRole(unsigned key); std::function onKeyPressed; std::function onKeyReleased;