mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added method MidiMessage::isMidiNoteBlack()
This commit is contained in:
parent
e22e536626
commit
c67c180b07
3 changed files with 9 additions and 9 deletions
|
|
@ -941,6 +941,11 @@ double MidiMessage::getMidiNoteInHertz (int noteNumber, const double frequencyOf
|
|||
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)
|
||||
{
|
||||
static const char* names[] =
|
||||
|
|
|
|||
|
|
@ -889,6 +889,9 @@ public:
|
|||
*/
|
||||
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.
|
||||
|
||||
@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,
|
||||
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 note = midiNoteNumber % 12;
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue