28 uint16 generateNoteID (
int midiChannel,
int midiNoteNumber)
noexcept
30 jassert (midiChannel > 0 && midiChannel <= 16);
31 jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
33 return uint16 ((midiChannel << 7) + midiNoteNumber);
45 : noteID (generateNoteID (midiChannel_, initialNote_)),
46 midiChannel (uint8 (midiChannel_)),
47 initialNote (uint8 (initialNote_)),
48 noteOnVelocity (noteOnVelocity_),
49 pitchbend (pitchbend_),
51 initialTimbre (timbre_),
70 auto pitchInSemitones = double (initialNote) + totalPitchbendInSemitones;
71 return frequencyOfA * std::pow (2.0, (pitchInSemitones - 69.0) / 12.0);
77 jassert (isValid() && other.isValid());
78 return noteID == other.noteID;
83 jassert (isValid() && other.isValid());
84 return noteID != other.noteID;
94 MPENoteTests() :
UnitTest (
"MPENote class",
"MIDI/MPE") {}
97 void runTest()
override
99 beginTest (
"getFrequencyInHertz");
102 note.initialNote = 60;
103 note.totalPitchbendInSemitones = -0.5;
104 expectEqualsWithinOneCent (note.getFrequencyInHertz(), 254.178);
110 void expectEqualsWithinOneCent (
double frequencyInHertzActual,
111 double frequencyInHertzExpected)
113 double ratio = frequencyInHertzActual / frequencyInHertzExpected;
114 double oneCent = 1.0005946;
115 expect (ratio < oneCent);
116 expect (ratio > 1.0 / oneCent);
120static MPENoteTests MPENoteUnitTests;
This class represents a single value for any of the MPE dimensions of control.
This is a base class for classes that perform a unit test.
This struct represents a playing MPE note.
KeyState
Possible values for the note key state.
@ off
The key is up (off).
uint8 initialNote
The MIDI note number that was sent when the note was triggered.
double getFrequencyInHertz(double frequencyOfA=440.0) const noexcept
Returns the current frequency of the note in Hertz.
MPENote() noexcept
Default constructor.
bool operator!=(const MPENote &other) const noexcept
Returns true if two notes are different notes, determined by their unique ID.
uint8 midiChannel
The MIDI channel which this note uses.
bool isValid() const noexcept
Checks whether the MPE note is valid.
bool operator==(const MPENote &other) const noexcept
Returns true if two notes are the same, determined by their unique ID.