#pragma once
#include <JuceHeader.h>
namespace lee {
namespace midi {
class NoteNumber {
public :
NoteNumber() {}
NoteNumber(int n) {
noteNumber = fixNoteNumber(n);
}
NoteNumber(const NoteNumber& other) {
noteNumber = other.noteNumber;
}
NoteNumber(const juce::MidiMessage& midiMessage) {
if (midiMessage.isNoteOnOrOff()) noteNumber = midiMessage.getNoteNumber();
}
NoteNumber& operator= (const NoteNumber& other) {
noteNumber = other.noteNumber;
return *this;
}
NoteNumber& operator+= (const NoteNumber& other) {
noteNumber = fixNoteNumber(noteNumber + other.noteNumber);
return *this;
}
NoteNumber& operator-= (const NoteNumber& other) {
noteNumber = fixNoteNumber(noteNumber - other.noteNumber);
return *this;
}
NoteNumber& operator++ () {
noteNumber = fixNoteNumber(++noteNumber);
return *this;
}
NoteNumber& operator-- () {
noteNumber = fixNoteNumber(++noteNumber);
return *this;
}
NoteNumber operator+ (const NoteNumber& other) const {
return NoteNumber(fixNoteNumber(noteNumber + other.noteNumber));
}
NoteNumber operator- (const NoteNumber& other) const {
return NoteNumber(fixNoteNumber(noteNumber - other.noteNumber));
}
bool operator> (const NoteNumber& other) const {
if (noteNumber > other.noteNumber) return true;
return false;
}
bool operator< (const NoteNumber& other) const {
if (noteNumber < other.noteNumber) return true;
return false;
}
bool operator== (const NoteNumber& other) const {
if (noteNumber == other.noteNumber) return true;
return false;
}
bool operator>= (const NoteNumber& other) const {
if (noteNumber >= other.noteNumber) return true;
return false;
}
bool operator<= (const NoteNumber& other) const {
if (noteNumber <= other.noteNumber) return true;
return false;
}
int operator() () {
return noteNumber;
}
friend NoteNumber operator+ (int n, const NoteNumber& other);
friend NoteNumber operator- (int n, const NoteNumber& other);
void setNoteNumber(const NoteNumber& other) {
noteNumber = other.noteNumber;
}
int getNoteNumber() const {
return noteNumber;
}
protected :
int fixNoteNumber(int n) const {
if (n < min) n = min;
else if (n > max) n = max;
return n;
}
private :
int noteNumber {64};
const int min {0};
const int max {127};
};
NoteNumber operator+ (int n, const NoteNumber& other) {
return other + n;
}
NoteNumber operator- (int n, const NoteNumber& other) {
return NoteNumber(n - other.noteNumber);
}
}
}