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