Browse Source

Added method MidiMessage::isMidiNoteBlack()

tags/2021-05-28
jules 11 years ago
parent
commit
c67c180b07
3 changed files with 9 additions and 9 deletions
  1. +5
    -0
      modules/juce_audio_basics/midi/juce_MidiMessage.cpp
  2. +3
    -0
      modules/juce_audio_basics/midi/juce_MidiMessage.h
  3. +1
    -9
      modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp

+ 5
- 0
modules/juce_audio_basics/midi/juce_MidiMessage.cpp View File

@@ -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[] =


+ 3
- 0
modules/juce_audio_basics/midi/juce_MidiMessage.h View File

@@ -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


+ 1
- 9
modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp View File

@@ -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


Loading…
Cancel
Save