11#include <promeki/config.h>
12#if PROMEKI_ENABLE_MUSIC
16PROMEKI_NAMESPACE_BEGIN
39 enum Value : uint8_t {
246 GMP_ScratchPush = 29,
247 GMP_ScratchPull = 30,
249 GMP_SquareClick = 32,
250 GMP_MetronomeClick = 33,
251 GMP_MetronomeBell = 34,
252 GMP_AcousticBassDrum = 35,
255 GMP_AcousticSnare = 38,
257 GMP_ElectricSnare = 40,
258 GMP_LowFloorTom = 41,
259 GMP_ClosedHiHat = 42,
260 GMP_HighFloorTom = 43,
266 GMP_CrashCymbal1 = 49,
268 GMP_RideCymbal1 = 51,
269 GMP_ChineseCymbal = 52,
272 GMP_SplashCymbal = 55,
274 GMP_CrashCymbal2 = 57,
276 GMP_RideCymbal2 = 59,
279 GMP_MuteHiConga = 62,
280 GMP_OpenHiConga = 63,
282 GMP_HighTimbale = 65,
288 GMP_ShortWhistle = 71,
289 GMP_LongWhistle = 72,
293 GMP_HiWoodBlock = 76,
294 GMP_LowWoodBlock = 77,
297 GMP_MuteTriangle = 80,
298 GMP_OpenTriangle = 81,
310 MidiNote() : _value(Invalid) {}
313 MidiNote(Value v) : _value(v) {}
319 MidiNote(uint8_t v) : _value(v > 127 ? Invalid : static_cast<Value>(v)) {}
322 bool isValid()
const {
return _value != Invalid; }
325 Value value()
const {
return _value; }
328 uint8_t rawValue()
const {
return static_cast<uint8_t
>(_value); }
331 operator uint8_t()
const {
return static_cast<uint8_t
>(_value); }
336 const char *pitchClassName()
const;
339 const char *pitchClassNameFlat()
const;
345 int pitchClass()
const;
354 double frequency(
double a4Hz = 440.0)
const;
359 static const char *pitchClassName(
int midiNote);
362 static const char *pitchClassNameFlat(
int midiNote);
365 static int octave(
int midiNote);
368 static int pitchClass(
int midiNote);
371 static String nameFromMidiNote(
int midiNote);
378 static MidiNote fromName(
const String &name);
385 static double frequencyFromMidiNote(
double midiNote,
double a4Hz = 440.0);
392 static double midiNoteFromFrequency(
double frequencyHz,
double a4Hz = 440.0);
396 bool operator==(
const MidiNote &other)
const {
return _value == other._value; }
397 bool operator!=(
const MidiNote &other)
const {
return _value != other._value; }
398 bool operator<(
const MidiNote &other)
const {
return _value < other._value; }
399 bool operator<=(
const MidiNote &other)
const {
return _value <= other._value; }
400 bool operator>(
const MidiNote &other)
const {
return _value > other._value; }
401 bool operator>=(
const MidiNote &other)
const {
return _value >= other._value; }