Use a color pair for key/switch, giving switch priority

This commit is contained in:
Jean Pierre Cimalando 2021-04-12 15:24:34 +02:00
parent c29f2bd27e
commit 099ee14b01
2 changed files with 7 additions and 20 deletions

View file

@ -33,7 +33,6 @@ struct SPiano::Impl {
float keyUsedHue_ = 0.55; float keyUsedHue_ = 0.55;
float keySwitchHue_ = 0.0; float keySwitchHue_ = 0.0;
float keyUsedAndSwitchHue_ = 0.85;
float whiteKeyChroma_ = 0.9; float whiteKeyChroma_ = 0.9;
float blackKeyChroma_ = 0.75; float blackKeyChroma_ = 0.75;
float whiteKeyLuma_ = 0.9; float whiteKeyLuma_ = 0.9;
@ -126,16 +125,16 @@ void SPiano::setKeyValue(unsigned key, float value)
invalid(); invalid();
} }
int SPiano::getKeyRole(unsigned key) SPiano::KeyRole SPiano::getKeyRole(unsigned key)
{ {
Impl& impl = *impl_; Impl& impl = *impl_;
int role = 0; KeyRole role = KeyRole::Unused;
if (key < 128) { if (key < 128) {
if (impl.keyUsed_.test(key))
role |= KeyRole::Note;
if (impl.keyswitchUsed_.test(key)) if (impl.keyswitchUsed_.test(key))
role |= KeyRole::Switch; role = KeyRole::Switch;
else if (impl.keyUsed_.test(key))
role = KeyRole::Note;
} }
return role; return role;
@ -189,12 +188,6 @@ void SPiano::draw(CDrawContext* dc)
goto whiteKeyDefault; goto whiteKeyDefault;
hcy.h = impl.keyUsedHue_; hcy.h = impl.keyUsedHue_;
break; break;
case KeyRole::Note|KeyRole::Switch:
if (!allKeysUsed) {
hcy.h = impl.keyUsedAndSwitchHue_;
break;
}
// fall through
case KeyRole::Switch: case KeyRole::Switch:
hcy.h = impl.keySwitchHue_; hcy.h = impl.keySwitchHue_;
break; break;
@ -235,12 +228,6 @@ void SPiano::draw(CDrawContext* dc)
goto blackKeyDefault; goto blackKeyDefault;
hcy.h = impl.keyUsedHue_; hcy.h = impl.keyUsedHue_;
break; break;
case KeyRole::Note|KeyRole::Switch:
if (!allKeysUsed) {
hcy.h = impl.keyUsedAndSwitchHue_;
break;
}
// fall through
case KeyRole::Switch: case KeyRole::Switch:
hcy.h = impl.keySwitchHue_; hcy.h = impl.keySwitchHue_;
break; break;

View file

@ -29,13 +29,13 @@ public:
void setKeyswitchUsed(unsigned key, bool used); void setKeyswitchUsed(unsigned key, bool used);
void setKeyValue(unsigned key, float value); void setKeyValue(unsigned key, float value);
enum KeyRole : int { enum class KeyRole : int {
Unused = 0, Unused = 0,
Note = 1 << 0, Note = 1 << 0,
Switch = 1 << 1, Switch = 1 << 1,
}; };
int getKeyRole(unsigned key); KeyRole getKeyRole(unsigned key);
std::function<void(unsigned, float)> onKeyPressed; std::function<void(unsigned, float)> onKeyPressed;
std::function<void(unsigned, float)> onKeyReleased; std::function<void(unsigned, float)> onKeyReleased;