2024-10-09 02:01:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-10-22 18:36:18 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
|
#endif
|
|
|
|
|
|
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-22 01:55:31 +02:00
|
|
|
// State
|
|
|
|
|
|
|
|
|
|
enum States {IDLE, CONFIG};
|
|
|
|
|
|
|
|
|
|
struct AppState{
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
int grid;
|
|
|
|
|
int bpm;
|
|
|
|
|
int fps;
|
|
|
|
|
float speed = 16.0f;
|
|
|
|
|
int gui_selected_midi_out;
|
|
|
|
|
States state;
|
|
|
|
|
};
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-20 23:42:38 +02:00
|
|
|
namespace MIDI{
|
|
|
|
|
inline std::vector<std::string> Notes = {
|
|
|
|
|
"C-1", "C#-1", "D-1", "D#-1", "E-1", "F-1", "F#-1", "G-1",
|
|
|
|
|
"G#-1", "A-1", "A#-1", "B-1", "C0", "C#0", "D0", "D#0",
|
|
|
|
|
"E0", "F0", "F#0", "G0", "G#0", "A0", "A#0", "B0",
|
|
|
|
|
"C1", "C#1", "D1", "D#1", "E1", "F1", "F#1", "G1",
|
|
|
|
|
"G#1", "A1", "A#1", "B1", "C2", "C#2", "D2", "D#2",
|
|
|
|
|
"E2", "F2", "F#2", "G2", "G#2", "A2", "A#2", "B2",
|
|
|
|
|
"C3", "C#3", "D3", "D#3", "E3", "F3", "F#3", "G3",
|
|
|
|
|
"G#3", "A3", "A#3", "B3", "C4", "C#4", "D4", "D#4",
|
|
|
|
|
"E4", "F4", "F#4", "G4", "G#4", "A4", "A#4", "B4",
|
|
|
|
|
"C5", "C#5", "D5", "D#5", "E5", "F5", "F#5", "G5",
|
|
|
|
|
"G#5", "A5", "A#5", "B5", "C6", "C#6", "D6", "D#6",
|
|
|
|
|
"E6", "F6", "F#6", "G6", "G#6", "A6", "A#6", "B6",
|
|
|
|
|
"C7", "C#7", "D7", "D#7", "E7", "F7", "F#7", "G7",
|
|
|
|
|
"G#7", "A7", "A#7", "B7", "C8", "C#8", "D8", "D#8",
|
|
|
|
|
"E8", "F8", "F#8", "G8", "G#8", "A8", "A#8", "B8",
|
|
|
|
|
"C9", "C#9", "D9", "D#9", "E9", "F9", "F#9", "G9",
|
|
|
|
|
"G#9", "A9", "A#9", "B9", "C10"
|
|
|
|
|
};
|
|
|
|
|
}
|