Files
viseq/src/datatypes.h
T

302 lines
8.5 KiB
C++
Raw Normal View History

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
#define VS_COLOR_BLACK (Color){20, 20, 20, 255}
2024-10-27 00:40:57 +02:00
#define VS_COLOR_DARKGREY (Color){46, 46, 46, 255}
#define VS_COLOR_LIGHTGREY (Color){100, 100, 100, 255}
#define VS_COLOR_WHITE (Color){214, 214, 214, 255}
#define VS_COLOR_YELLOW (Color){229, 181, 103, 255}
#define VS_COLOR_GREEN (Color){180, 210, 115, 255}
#define VS_COLOR_ORANGE (Color){232, 125, 62, 255}
#define VS_COLOR_PURPLE (Color){158, 134, 200, 255}
#define VS_COLOR_PINK (Color){176, 82, 121, 255}
#define VS_COLOR_BLUE (Color){108, 153, 187, 255}
#define VS_COLOR_RED (Color){195, 83, 85, 255}
#define VS_COLOR_BROWN (Color){84, 75, 61, 255}
#define VS_COLOR_SUN (Color){214, 170, 21, 255}
#include "nlohmann/json.hpp"
using json = nlohmann::json;
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
2024-11-01 14:08:27 +01:00
#define RANGE_FILTER(L) std::ranges::views::filter(L)
2024-11-03 03:48:49 +01:00
namespace VISEQ::GRAPH::NODES {
enum Distribution {GEOMETRIC, ROUNDROBIN, RANDOM};
}
2024-10-30 14:55:24 +01:00
2024-11-03 03:48:49 +01:00
namespace VISEQ::GRAPH{
enum GraphItemType {NODE, EDGE, CONNECTOR, CANVAS, HANDLE, VS_BUTTON};
2024-11-07 00:56:33 +01:00
enum NodeType {OSCNODE, MIDINODE, CONFIGNODE};
enum EdgeType {MIDIEDGE, CONFIGEDGE};
2024-11-03 03:48:49 +01:00
}
2024-10-30 14:55:24 +01:00
2024-10-20 01:17:18 +02:00
2024-11-03 03:48:49 +01:00
namespace VISEQ::MIDI{
2024-11-07 00:56:33 +01:00
struct MidiNote{
int channel = 0;
int note = 0;
int velocity = 0;
int gate = 0; // gate time in milliseconds
2024-11-07 00:56:33 +01:00
};
struct MidiCC{
int channel = 0;
int control = 0;
int value = 0;
};
struct MidiPC{
int channel = 0;
int program = 0;
int value = 0;
};
struct MidiPitchBend{
int channel = 0;
int value = 0;
};
struct MidiAftertouch{
int channel = 0;
int value = 0;
};
struct MidiPolyPressure{
int channel = 0;
int note = 0;
int value = 0;
};
2024-11-03 03:48:49 +01:00
struct MidiOutPort{
libremidi::output_port port;
int number;
bool enabled;
};
2024-10-20 01:17:18 +02:00
2024-11-03 03:48:49 +01:00
struct MidiOut{
libremidi::midi_out out;
int number;
};
2024-10-20 01:17:18 +02:00
inline std::ostream& operator<<(std::ostream& os, const MidiNote note){
os << "note: " << note.note << " channel: " << note.channel << " velocity: " << note.velocity << " gate: " << note.gate;
return os;
}
inline MidiNote operator+(const MidiNote left, const MidiNote right){
MidiNote added;
added.note = left.note + right.note;
added.channel = left.channel + right.channel;
added.gate = left.gate + right.gate;
added.velocity = left.velocity + right.velocity;
return added;
}
inline MidiCC operator+(const MidiCC left, const MidiCC right){
MidiCC added;
added.channel = left.channel + right.channel;
added.control = left.control + right.control;
added.value = left.value+ right.value;
return added;
}
inline MidiPC operator+(const MidiPC left, const MidiPC right){
MidiPC added;
added.channel = left.channel + right.channel;
added.program = left.program + right.program;
added.value = left.value+ right.value;
return added;
}
inline MidiPitchBend operator+(const MidiPitchBend left, const MidiPitchBend right){
MidiPitchBend added;
added.channel = left.channel + right.channel;
added.value = left.value+ right.value;
return added;
}
inline MidiAftertouch operator+(const MidiAftertouch left, const MidiAftertouch right){
MidiAftertouch added;
added.channel = left.channel + right.channel;
added.value = left.value+ right.value;
return added;
}
inline MidiPolyPressure operator+(const MidiPolyPressure left, const MidiPolyPressure right){
MidiPolyPressure added;
added.channel = left.channel + right.channel;
added.note = left.note + right.note;
added.value = left.value+ right.value;
return added;
}
inline MidiNote operator-(const MidiNote left, const MidiNote right){
MidiNote added;
added.note = left.note - right.note;
added.channel = left.channel - right.channel;
added.gate = left.gate - right.gate;
added.velocity = left.velocity - right.velocity;
return added;
}
inline MidiCC operator-(const MidiCC left, const MidiCC right){
MidiCC added;
added.channel = left.channel - right.channel;
added.control = left.control - right.control;
added.value = left.value- right.value;
return added;
}
inline MidiPC operator-(const MidiPC left, const MidiPC right){
MidiPC added;
added.channel = left.channel - right.channel;
added.program = left.program - right.program;
added.value = left.value- right.value;
return added;
}
inline MidiPitchBend operator-(const MidiPitchBend left, const MidiPitchBend right){
MidiPitchBend added;
added.channel = left.channel - right.channel;
added.value = left.value- right.value;
return added;
}
inline MidiAftertouch operator-(const MidiAftertouch left, const MidiAftertouch right){
MidiAftertouch added;
added.channel = left.channel - right.channel;
added.value = left.value- right.value;
return added;
}
inline MidiPolyPressure operator-(const MidiPolyPressure left, const MidiPolyPressure right){
MidiPolyPressure added;
added.channel = left.channel - right.channel;
added.note = left.note - right.note;
added.value = left.value- right.value;
return added;
}
// COMPOUND
inline MidiNote& operator+=(MidiNote& left, const MidiNote& right){
left.note += right.note;
left.channel += right.channel;
left.gate += right.gate;
left.velocity += right.velocity;
return left;
}
inline MidiCC& operator+=(MidiCC& left, const MidiCC right){
left.channel += right.channel;
left.control += right.control;
left.value += right.value;
return left;
}
inline MidiPC& operator+=(MidiPC& left, const MidiPC right){
left.channel += right.channel;
left.program += right.program;
left.value += right.value;
return left;
}
inline MidiPitchBend& operator+=(MidiPitchBend& left, const MidiPitchBend right){
left.channel += right.channel;
left.value += right.value;
return left;
}
inline MidiAftertouch& operator+=(MidiAftertouch& left, const MidiAftertouch right){
left.channel += right.channel;
left.value += right.value;
return left;
}
inline MidiPolyPressure& operator+=(MidiPolyPressure& left, const MidiPolyPressure right){
left.channel += right.channel;
left.note += right.note;
left.value += right.value;
return left;
}
inline MidiNote& operator-=(MidiNote& left, const MidiNote& right){
left.note -= right.note;
left.channel -= right.channel;
left.gate -= right.gate;
left.velocity -= right.velocity;
return left;
}
inline MidiCC& operator-=(MidiCC& left, const MidiCC right){
left.channel -= right.channel;
left.control -= right.control;
left.value -= right.value;
return left;
}
inline MidiPC& operator-=(MidiPC& left, const MidiPC right){
left.channel -= right.channel;
left.program -= right.program;
left.value -= right.value;
return left;
}
inline MidiPitchBend& operator-=(MidiPitchBend& left, const MidiPitchBend right){
left.channel -= right.channel;
left.value -= right.value;
return left;
}
inline MidiAftertouch& operator-=(MidiAftertouch& left, const MidiAftertouch right){
left.channel -= right.channel;
left.value -= right.value;
return left;
}
inline MidiPolyPressure& operator-=(MidiPolyPressure& left, const MidiPolyPressure right){
left.channel -= right.channel;
left.note -= right.note;
left.value -= right.value;
return left;
}
/*Vec2D<T> operator*(const Vec2D<T> left, T scalar){*/
/* return Vec2D<T>(left.x * scalar, left.y * scalar);*/
/*};*/
2024-11-03 03:48:49 +01:00
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MidiOut, number)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MidiOutPort, number, enabled)
2024-10-30 14:55:24 +01:00
inline std::vector<std::string> Fractions = {"1/32","1/16","3/32","1/8","5/32","3/16","7/32","1/4","9/32","5/16","11/32","3/8","13/32","7/16","15/32","1/2","17/32","9/16","19/32","5/8","21/32","11/16","23/32","3/4","25/32","13/16","27/32","7/8","29/32","15/16","31/32","1/1"};
2024-11-03 03:48:49 +01:00
2024-10-20 23:42:38 +02:00
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"
};
}