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