56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
#include "signal.h"
|
|
|
|
#include <raylib.h>
|
|
#include "node.h"
|
|
|
|
namespace VISEQ::SIGNAL {
|
|
void Signal::reset(){
|
|
toStart();
|
|
}
|
|
|
|
void Signal::toStart(){
|
|
position = start.lock()->position;
|
|
}
|
|
|
|
void Signal::update(double t_delta){
|
|
// 120px / 16th = 1920px / whole note
|
|
// whole note = 2s at 120bpm
|
|
// 960px / s
|
|
if(run) position += direction.norm() * speed * multiplier * (float)t_delta / 1000000.0f;
|
|
}
|
|
|
|
void Signal::draw(Vec2Df mouse, Camera2D cam) {
|
|
DrawCircle(position.x, position.y, radius, color);
|
|
}
|
|
|
|
void to_json(json& j, const Signal& S){
|
|
std::map<std::string, int> fc = {{"r",S.color.r},{"g",S.color.g},{"b",S.color.b},{"a",S.color.a}};
|
|
j = json{{"color",fc},{"position", S.position},{"radius",S.radius},{"start",S.start.lock()->id},{"next",S.next.lock()->id},{"last",S.last.lock()->id},{"speed",S.speed},{"midi_note_offset",S.midi_note_offset},{"midi_cc_offset",S.midi_cc_offset},{"multiplier",S.multiplier}};
|
|
}
|
|
|
|
void from_json(const json& j, Signal& S){
|
|
|
|
Color c;
|
|
c.r = j.at("color")["r"].get<int>();
|
|
c.g = j.at("color")["g"].get<int>();
|
|
c.b = j.at("color")["b"].get<int>();
|
|
c.a = j.at("color")["a"].get<int>();
|
|
|
|
j.at("position").get_to<Vec2Df>(S.position);
|
|
j.at("speed").get_to<float>(S.speed);
|
|
j.at("radius").get_to<float>(S.radius);
|
|
j.at("midi_note_offset").get_to(S.midi_note_offset);
|
|
j.at("midi_cc_offset").get_to(S.midi_cc_offset);
|
|
|
|
S.color = c;
|
|
}
|
|
|
|
void to_json(json& j, const std::shared_ptr<Signal>& S){
|
|
j = *S;
|
|
}
|
|
|
|
void from_json(const json& j, std::shared_ptr<Signal>& S){
|
|
S.reset(new Signal(j.get<Signal>()));
|
|
}
|
|
}
|