#include <JuceHeader.h>
namespace lee {
namespace midi {
class Channel {
public :
Channel() {}
Channel(int n) {
channel = fixChannel(n);
}
Channel(const Channel& other) {
channel = other.channel;
}
Channel(const juce::MidiMessage& midiMessage) {
channel = midiMessage.getChannel();
}
Channel& operator= (const Channel& other) {
channel = other.channel;
return *this;
}
Channel& operator+= (const Channel& other) {
channel = fixChannel(channel + other.channel);
return *this;
}
Channel& operator-= (const Channel& other) {
channel = fixChannel(channel - other.channel);
return *this;
}
Channel& operator++ () {
channel = fixChannel(++channel);
return *this;
}
Channel& operator-- () {
channel = fixChannel(--channel);
return *this;
}
Channel operator+ (const Channel& other) const {
return Channel(fixChannel(channel + other.channel));
}
Channel operator- (const Channel& other) const {
return Channel(fixChannel(channel - other.channel));
}
bool operator> (const Channel& other) const {
if (channel > other.channel) return true;
return false;
}
bool operator< (const Channel& other) const {
if (channel < other.channel) return true;
return false;
}
bool operator== (const Channel& other) const {
if (channel == other.channel) return true;
return false;
}
bool operator>= (const Channel& other) const {
if (channel >= other.channel) return true;
return false;
}
bool operator<= (const Channel& other) const {
if (channel <= other.channel) return true;
return false;
}
int operator() () const {
return channel;
}
friend Channel operator+ (int n, const Channel& other);
friend Channel operator- (int n, const Channel& other);
void setChannel(const Channel& other) {
channel = other.channel;
}
int getChannel() const {
return channel;
}
protected :
int fixChannel(int n) const {
if (n < min) n = max;
else if (n > max) n = min;
return n;
}
private :
int channel {1};
const int min {1};
const int max {16};
};
Channel operator+ (int n, const Channel& other) {
return other + n;
}
Channel operator- (int n, const Channel& other) {
return Channel(n - other.channel);
}
}
}