2024-10-09 02:01:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-10-09 09:39:40 +02:00
|
|
|
#include <cmath>
|
2024-10-09 02:01:23 +02:00
|
|
|
#include <math.h>
|
2024-10-20 01:17:18 +02:00
|
|
|
#include "libremidi/libremidi.hpp"
|
2024-10-16 02:26:02 +02:00
|
|
|
|
|
|
|
|
enum Distribution {ROUNDROBIN, RANDOM};
|
|
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
// 2D Vectors
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
class Vec2D{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
Vec2D() {};
|
|
|
|
|
Vec2D(T x, T y) : x(x), y(y) {}
|
|
|
|
|
T x = 0;
|
|
|
|
|
T y = 0;
|
|
|
|
|
T dist(Vec2D* v) { return sqrt(pow((v->x - x), 2) + pow((v->y - y), 2));};
|
2024-10-10 09:54:54 +02:00
|
|
|
|
|
|
|
|
T length() { return (T)sqrt(pow(x, 2) + pow(y, 2));};
|
2024-10-09 09:39:40 +02:00
|
|
|
|
|
|
|
|
T angle(Vec2D &v){
|
|
|
|
|
T angle = atan2(v.y, v.x) - atan2(y,x);
|
|
|
|
|
if(angle > M_PI) angle -= M_PI_2;
|
|
|
|
|
if(angle < -M_PI) angle += M_PI_2;
|
|
|
|
|
return angle;
|
|
|
|
|
//return acos(dot(v));
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-10 02:59:27 +02:00
|
|
|
T angleDeg(Vec2D &v){
|
|
|
|
|
|
|
|
|
|
return angle(v) * 180 / M_PI;
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-09 09:39:40 +02:00
|
|
|
T dot(Vec2D &v){
|
|
|
|
|
return (x*v.x) + (y*v.y);
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-19 17:41:31 +02:00
|
|
|
Vec2D orth(Vec2D &v){
|
|
|
|
|
return Vec2D(-v.y, v.x);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Vec2D orth(){
|
|
|
|
|
return Vec2D(-y, x);
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-10 09:54:54 +02:00
|
|
|
Vec2D norm() { return *this / length();};
|
2024-10-19 17:41:31 +02:00
|
|
|
|
2024-10-09 02:01:23 +02:00
|
|
|
|
|
|
|
|
Vec2D& operator=(const Vec2D& vec){
|
|
|
|
|
if (this == &vec){
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
x = vec.x;
|
|
|
|
|
y = vec.y;
|
|
|
|
|
return *this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Vec2D& operator+=(const Vec2D& vec){
|
|
|
|
|
this->x += vec.x;
|
|
|
|
|
this->y += vec.y;
|
|
|
|
|
return *this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Vec2D& operator-=(const Vec2D& vec){
|
|
|
|
|
this->x -= vec.x;
|
|
|
|
|
this->y -= vec.y;
|
|
|
|
|
return *this;
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-10 09:54:54 +02:00
|
|
|
Vec2D& operator*=(const Vec2D& vec){
|
2024-10-09 02:01:23 +02:00
|
|
|
this->x *= vec.x;
|
|
|
|
|
this->y *= vec.y;
|
|
|
|
|
return *this;
|
|
|
|
|
};
|
2024-10-10 09:54:54 +02:00
|
|
|
|
|
|
|
|
Vec2D& operator/=(const Vec2D& vec){
|
|
|
|
|
this->x /= vec.x;
|
|
|
|
|
this->y /= vec.y;
|
|
|
|
|
return *this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Vec2D& operator*=(T scalar){
|
2024-10-09 02:01:23 +02:00
|
|
|
this->x *= scalar;
|
|
|
|
|
this->y *= scalar;
|
|
|
|
|
return *this;
|
|
|
|
|
};
|
2024-10-10 09:54:54 +02:00
|
|
|
|
|
|
|
|
Vec2D& operator/=(T scalar){
|
|
|
|
|
this->x /= scalar;
|
|
|
|
|
this->y /= scalar;
|
|
|
|
|
return *this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
Vec2D<T> operator+(const Vec2D<T>& left, const Vec2D<T>& right){
|
|
|
|
|
return Vec2D<T>(left.x + right.x, left.y + right.y);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
Vec2D<T> operator-(const Vec2D<T>& left, const Vec2D<T>& right){
|
|
|
|
|
return Vec2D<T>(left.x - right.x, left.y - right.y);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
Vec2D<T> operator*(const Vec2D<T>& left, const Vec2D<T>& right){
|
|
|
|
|
return Vec2D<T>(left.x * right.x, left.y * right.y);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
Vec2D<T> operator/(const Vec2D<T>& left, const Vec2D<T>& right){
|
|
|
|
|
return Vec2D<T>(left.x / right.x, left.y / right.y);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
Vec2D<T> operator/(const Vec2D<T>& left, T scalar){
|
|
|
|
|
return Vec2D<T>(left.x / scalar, left.y / scalar);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
Vec2D<T> operator*(const Vec2D<T>& left, T scalar){
|
|
|
|
|
return Vec2D<T>(left.x * scalar, left.y * scalar);
|
2024-10-09 02:01:23 +02:00
|
|
|
};
|
|
|
|
|
|
2024-10-20 01:17:18 +02:00
|
|
|
|
|
|
|
|
// MIDI
|
|
|
|
|
|
|
|
|
|
struct MidiOutPort{
|
|
|
|
|
libremidi::output_port port;
|
|
|
|
|
int number;
|
|
|
|
|
bool enabled;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct MidiOut{
|
|
|
|
|
libremidi::midi_out out;
|
|
|
|
|
int number;
|
|
|
|
|
};
|
|
|
|
|
|