From 176e08047e328e2c0fbd257dfb1225b88964f989 Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Wed, 3 Feb 2016 18:53:05 -0800 Subject: [PATCH] Rewrite Piano::isBlackKey for clarity --- src/core/Piano.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/core/Piano.cpp b/src/core/Piano.cpp index d08121b66..88e1f115a 100644 --- a/src/core/Piano.cpp +++ b/src/core/Piano.cpp @@ -44,6 +44,19 @@ #include "Note.h" +/*! The black / white order of keys as they appear on the keyboard. + */ +static const Piano::KeyTypes KEY_ORDER[] = +{ +// C CIS D DIS + Piano::WhiteKey, Piano::BlackKey, Piano::WhiteKey, Piano::BlackKey, +// E F FIS G + Piano::WhiteKey, Piano::WhiteKey, Piano::BlackKey, Piano::WhiteKey, +// GIS A AIS B + Piano::BlackKey, Piano::WhiteKey, Piano::BlackKey, Piano::WhiteKey +} ; + + /*! \brief Create a new keyboard display * * \param _it the InstrumentTrack window to attach to @@ -131,17 +144,7 @@ bool Piano::isBlackKey( int key ) { int keyCode = key % KeysPerOctave; - switch (keyCode) - { - case 1: - case 3: - case 6: - case 8: - case 10: - return true; - } - - return false; + return KEY_ORDER[keyCode] == Piano::BlackKey; }