json serialization beginnings, but still much to do
This commit is contained in:
+33
-136
@@ -18,10 +18,14 @@
|
||||
#define VS_COLOR_BROWN (Color){84, 75, 61, 255}
|
||||
#define VS_COLOR_SUN (Color){214, 170, 21, 255}
|
||||
|
||||
#include "vmath.h"
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
using json = nlohmann::json;
|
||||
|
||||
#include <cmath>
|
||||
#include <math.h>
|
||||
#include "libremidi/libremidi.hpp"
|
||||
#include "raylib.h"
|
||||
|
||||
enum Distribution {GEOMETRIC, ROUNDROBIN, RANDOM};
|
||||
|
||||
@@ -45,146 +49,36 @@ typedef std::vector<SPTR_Node> VEC_SPTR_Node;
|
||||
typedef std::vector<SPTR_Edge> VEC_SPTR_Edge;
|
||||
typedef std::vector<SPTR_Signal> VEC_SPTR_Signal;
|
||||
|
||||
using Vec2Df = VMath::Vec2D<float>;
|
||||
|
||||
// 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));};
|
||||
T dist(Vec2D v) { return sqrt(pow((v.x - x), 2) + pow((v.y - y), 2));};
|
||||
|
||||
T length() { return (T)sqrt(pow(x, 2) + pow(y, 2));};
|
||||
|
||||
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));
|
||||
};
|
||||
|
||||
T angleDeg(Vec2D v){
|
||||
return angle(v) * 180 / M_PI;
|
||||
};
|
||||
|
||||
T dot(Vec2D &v){
|
||||
return (x*v.x) + (y*v.y);
|
||||
};
|
||||
|
||||
T dot(Vec2D v){
|
||||
return (x*v.x) + (y*v.y);
|
||||
};
|
||||
|
||||
operator Vector2() const {
|
||||
return (Vector2){x,y};
|
||||
}
|
||||
|
||||
Vec2D orth(Vec2D &v){
|
||||
return Vec2D(-v.y, v.x);
|
||||
};
|
||||
|
||||
Vec2D orth(){
|
||||
return Vec2D(-y, x);
|
||||
};
|
||||
|
||||
Vec2D norm() { return *this / length();};
|
||||
|
||||
Vec2D center(Vec2D v){
|
||||
return Vec2D<T>{x,y} - (Vec2D<T>{x,y} - v)*0.5f;
|
||||
}
|
||||
|
||||
Vec2D& operator=(const Vec2D& vec){
|
||||
if (this == &vec){
|
||||
return *this;
|
||||
namespace nlohmann {
|
||||
template <typename T>
|
||||
struct adl_serializer<std::shared_ptr<T>> {
|
||||
static void to_json(json& j, const std::shared_ptr<T>& opt){
|
||||
if (opt)
|
||||
{
|
||||
j = *opt;
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
Vec2D& operator*=(T scalar){
|
||||
this->x *= scalar;
|
||||
this->y *= scalar;
|
||||
return *this;
|
||||
};
|
||||
|
||||
Vec2D& operator/=(T scalar){
|
||||
this->x /= scalar;
|
||||
this->y /= scalar;
|
||||
return *this;
|
||||
};
|
||||
|
||||
};
|
||||
else
|
||||
{
|
||||
j = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Vec2D<T> cartesianToPolar(T x, T y) {
|
||||
return Vec2D<T>{sqrt(x * x + y * y), atan(y / x)}; // r,theta
|
||||
static void from_json(const json& j, std::shared_ptr<T>& opt){
|
||||
if (j.is_null())
|
||||
{
|
||||
opt = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
opt.reset(new T(j.get<T>()));
|
||||
//opt = j.get<T>();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Vec2D<T> polarToCartesian(T r, T q) {
|
||||
return Vec2D<T>{r * cos(q), r * sin(q)};
|
||||
}
|
||||
|
||||
// App Settings
|
||||
struct AppSettings{
|
||||
@@ -217,6 +111,9 @@ struct MidiOut{
|
||||
int number;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MidiOut, number)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MidiOutPort, number, enabled)
|
||||
|
||||
namespace MIDI{
|
||||
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"};
|
||||
inline std::vector<std::string> Notes = {
|
||||
|
||||
Reference in New Issue
Block a user