@@ -941,6 +941,11 @@ double MidiMessage::getMidiNoteInHertz (int noteNumber, const double frequencyOf | |||||
return frequencyOfA * pow (2.0, (noteNumber - 69) / 12.0); | return frequencyOfA * pow (2.0, (noteNumber - 69) / 12.0); | ||||
} | } | ||||
bool MidiMessage::isMidiNoteBlack (int noteNumber) noexcept | |||||
{ | |||||
return ((1 << (noteNumber % 12)) & 0x054a) != 0; | |||||
} | |||||
const char* MidiMessage::getGMInstrumentName (const int n) | const char* MidiMessage::getGMInstrumentName (const int n) | ||||
{ | { | ||||
static const char* names[] = | static const char* names[] = | ||||
@@ -889,6 +889,9 @@ public: | |||||
*/ | */ | ||||
static double getMidiNoteInHertz (int noteNumber, const double frequencyOfA = 440.0) noexcept; | static double getMidiNoteInHertz (int noteNumber, const double frequencyOfA = 440.0) noexcept; | ||||
/** Returns true if the given midi note number is a black key. */ | |||||
static bool isMidiNoteBlack (int noteNumber) noexcept; | |||||
/** Returns the standard name of a GM instrument, or nullptr if unknown for this index. | /** Returns the standard name of a GM instrument, or nullptr if unknown for this index. | ||||
@param midiInstrumentNumber the program number 0 to 127 | @param midiInstrumentNumber the program number 0 to 127 | ||||
@@ -211,19 +211,11 @@ void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyW | |||||
5.0f, 6 - blackNoteWidth * 0.3f, | 5.0f, 6 - blackNoteWidth * 0.3f, | ||||
6.0f }; | 6.0f }; | ||||
static const float widths[] = { 1.0f, blackNoteWidth, | |||||
1.0f, blackNoteWidth, | |||||
1.0f, | |||||
1.0f, blackNoteWidth, | |||||
1.0f, blackNoteWidth, | |||||
1.0f, blackNoteWidth, | |||||
1.0f }; | |||||
const int octave = midiNoteNumber / 12; | const int octave = midiNoteNumber / 12; | ||||
const int note = midiNoteNumber % 12; | const int note = midiNoteNumber % 12; | ||||
x = roundToInt (octave * 7.0f * keyWidth_ + notePos [note] * keyWidth_); | x = roundToInt (octave * 7.0f * keyWidth_ + notePos [note] * keyWidth_); | ||||
w = roundToInt (widths [note] * keyWidth_); | |||||
w = roundToInt (MidiMessage::isMidiNoteBlack (note) ? blackNoteWidth * keyWidth_ : keyWidth_); | |||||
} | } | ||||
void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const | void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const | ||||