2024-10-25 16:41:37 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "raygui/raygui.h"
|
|
|
|
|
#include "raygui/dark/style_dark.h"
|
|
|
|
|
|
|
|
|
|
#include "datatypes.h"
|
|
|
|
|
|
|
|
|
|
#include "connection-manager.h"
|
|
|
|
|
#include "node-manager.h"
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
#include "signal-manager.h"
|
|
|
|
|
#include <ranges>
|
|
|
|
|
|
|
|
|
|
class AppUI{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
AppUI(AppSettings *settings, NodeManager *nm, ConnectionManager *cm, SignalManager *sm) : settings(settings), nm(nm), sm(sm), cm(cm) {}
|
|
|
|
|
|
|
|
|
|
AppSettings *settings;
|
|
|
|
|
NodeManager *nm;
|
|
|
|
|
SignalManager *sm;
|
|
|
|
|
ConnectionManager *cm;
|
|
|
|
|
|
|
|
|
|
void init(){
|
|
|
|
|
GuiLoadStyleDark();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drawSideBar(){
|
|
|
|
|
|
2024-10-28 02:07:47 +01:00
|
|
|
GuiPanel((Rectangle){-1,-30,280,(float)settings->height + 31}, "");
|
2024-10-25 16:41:37 +02:00
|
|
|
{
|
2024-10-28 02:07:47 +01:00
|
|
|
const int s_controls = 20;
|
|
|
|
|
//GuiSetStyle(BUTTON, STATE_FOCUSED, 0xFF0000FF);
|
|
|
|
|
if(GuiButton((Rectangle){20, (float)s_controls, 80, 30}, "PLAY")) sm->play ? sm->pause() : sm->start();
|
|
|
|
|
if(GuiButton((Rectangle){120, (float)s_controls, 60, 30}, "STOP")) sm->stop();
|
|
|
|
|
if(GuiButton((Rectangle){200, (float)s_controls, 60, 30}, "RESET")) sm->reset();
|
2024-10-25 16:41:37 +02:00
|
|
|
|
|
|
|
|
const int s_bpm = s_controls + 35;
|
|
|
|
|
GuiLabel((Rectangle){20, (float)s_bpm, 120, 20}, "TIMING");
|
|
|
|
|
GuiLabel((Rectangle){200, (float)s_bpm, 40, 20}, std::format("{}",settings->bpm).c_str());
|
|
|
|
|
float _bpm = (float)settings->bpm;
|
|
|
|
|
GuiSlider((Rectangle){20, (float)s_bpm + 25, 240, 20}, "", "", &_bpm, 1, 300);
|
|
|
|
|
settings->bpm = _bpm;
|
|
|
|
|
|
|
|
|
|
int s_midi = s_bpm + 55;
|
|
|
|
|
GuiLabel((Rectangle){20, (float)s_midi, 240, 20}, "MIDI OUT");
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(auto& mo : sm->midi.midi_out_ports){
|
|
|
|
|
GuiCheckBox((Rectangle){20, (float)s_midi + 25 + i*20.0f, 20, 20}, mo.port.port_name.c_str(), &mo.enabled);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(GuiButton((Rectangle){20, (float)s_midi + 45 + i*20.0f, 240, 20}, "ENABLE FOR ALL")) {
|
|
|
|
|
for(auto &midis : sm->midi.midi_out_ports){
|
|
|
|
|
if(midis.enabled){
|
|
|
|
|
for(auto &n : nm->nodes){
|
2024-10-26 02:14:41 +02:00
|
|
|
n.second.setMidiPort(midis.number, true);
|
2024-10-25 16:41:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int s_signal = s_midi + 90 + i*20;
|
|
|
|
|
GuiLabel((Rectangle){20, (float)s_signal, 240, 20}, "SIGNALS");
|
|
|
|
|
if(GuiButton((Rectangle){20, (float)s_signal + 35, 240, 20}, "ADD RANDOM SIGNAL")){
|
2024-10-26 02:14:41 +02:00
|
|
|
int ni = nm->getRandomNode();
|
|
|
|
|
sm->addSignalAtNode(ni);
|
2024-10-25 16:41:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int signal_configs = 0;
|
|
|
|
|
for(auto &s : sm->signals){
|
|
|
|
|
if(GuiButton((Rectangle){20,(float)s_signal+70 + signal_configs*20, 20, 20},"X")) sm->removeSignal(signal_configs);
|
|
|
|
|
DrawCircle(55, s_signal+80 + signal_configs*20, 6.0F, s.color);
|
|
|
|
|
float s_multiplier = round(s.multiplier*10.0f)/10.0f;
|
|
|
|
|
float signal_bpm = settings->bpm * s.multiplier;
|
2024-10-26 02:25:46 +02:00
|
|
|
GuiSlider((Rectangle){70, (float)s_signal+70 + signal_configs*20, 160, 20}, "", std::format("{:.1f}",signal_bpm).c_str(), &s_multiplier, 0.1, 10);
|
2024-10-25 16:41:37 +02:00
|
|
|
s.multiplier = s_multiplier;
|
|
|
|
|
s.speed = settings->speed;
|
|
|
|
|
signal_configs++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int s_nodes = s_signal + 60 + signal_configs*20;
|
|
|
|
|
GuiLabel((Rectangle){20, (float)s_nodes + 30, 240, 20}, "NODES");
|
|
|
|
|
if(GuiButton((Rectangle){20, (float)s_nodes + 60, 240, 20}, "ADD RANDOM NODE")){
|
2024-10-26 02:14:41 +02:00
|
|
|
nm->addNode(200.0f, 200.0f);
|
2024-10-25 16:41:37 +02:00
|
|
|
}
|
2024-10-28 02:07:47 +01:00
|
|
|
DrawText(std::format("{}", nm->nodes.size()).c_str(), 20, settings->height - 70, 15, VS_COLOR_WHITE);
|
2024-10-25 16:41:37 +02:00
|
|
|
DrawFPS(20, settings->height - 30);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drawPerNodeConfig(Camera2D *camera){
|
2024-10-26 02:14:41 +02:00
|
|
|
for(auto& n : nm->nodes | std::ranges::views::values | std::views::filter([](Node n){ return n.config; })){
|
2024-10-25 16:41:37 +02:00
|
|
|
Vector2 np = GetWorldToScreen2D((Vector2){n.position.x, n.position.y}, *camera);
|
|
|
|
|
|
|
|
|
|
n.config = !GuiWindowBox((Rectangle){np.x + 10, np.y + 10, 240, 440}, "config");
|
|
|
|
|
|
|
|
|
|
int option = n.mode;
|
|
|
|
|
GuiToggleGroup((Rectangle){ np.x + 20, np.y + 40, 110, 20 }, "Round Robin;Random", &option);
|
|
|
|
|
n.mode = (Distribution)option;
|
|
|
|
|
|
|
|
|
|
GuiLabel((Rectangle){np.x + 20, np.y + 65, 220, 20}, "SIGNALS");
|
|
|
|
|
if(GuiButton((Rectangle){np.x + 20, np.y + 90, 220, 20}, "ADD SIGNAL")){
|
2024-10-26 02:14:41 +02:00
|
|
|
sm->addSignalAtNode(n.id);
|
2024-10-25 16:41:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int y_midi = 120;
|
|
|
|
|
GuiLabel((Rectangle){np.x + 20, np.y + y_midi, 220, 20}, "MIDI OUT");
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(auto& mo : n.midi_outs){
|
|
|
|
|
GuiCheckBox((Rectangle){np.x + 20, np.y + y_midi + 20 + i*20.0f, 20, 20}, mo.second.name.c_str(), &mo.second.enabled);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int y_channel = y_midi + 30 + i*20;
|
|
|
|
|
GuiLabel((Rectangle){np.x + 20, np.y + y_channel, 220, 20}, "CHANNEL");
|
|
|
|
|
GuiToggleGroup((Rectangle){np.x + 20, np.y + y_channel + 30, 25, 20}, "1;2;3;4;5;6;7;8\n9;10;11;12;13;14;15;16", &n.midi_channel);
|
|
|
|
|
|
|
|
|
|
GuiLabel((Rectangle){np.x + 20, np.y + y_channel + 90, 100, 20}, "NOTE");
|
|
|
|
|
float v = n.midi_note;
|
|
|
|
|
GuiLabel((Rectangle){np.x + 210, np.y + y_channel + 90, 20, 20}, sm->midi.midiNotes[(int)round(v)].c_str());
|
|
|
|
|
GuiLabel((Rectangle){np.x + 160, np.y + y_channel + 90, 40, 20}, std::format("{}",n.midi_note).c_str());
|
|
|
|
|
GuiSlider((Rectangle){np.x + 20, np.y + y_channel + 120, 220, 20}, "", "", &v, 0, 127);
|
|
|
|
|
n.midi_note = round(v);
|
|
|
|
|
|
|
|
|
|
GuiLabel((Rectangle){np.x + 20, np.y + y_channel + 150, 100, 20}, "VELOCITY");
|
|
|
|
|
v = n.midi_velocity;
|
|
|
|
|
GuiLabel((Rectangle){np.x + 210, np.y + y_channel + 150, 20, 20}, std::format("{}",n.midi_velocity).c_str());
|
|
|
|
|
GuiSlider((Rectangle){np.x + 20, np.y + y_channel + 180, 220, 20}, "", "", &v, 0, 127);
|
|
|
|
|
n.midi_velocity = round(v);
|
|
|
|
|
|
|
|
|
|
GuiLabel((Rectangle){np.x + 20, np.y + y_channel + 210, 100, 20}, "GATE");
|
|
|
|
|
v = n.midi_gate;
|
|
|
|
|
GuiLabel((Rectangle){np.x + 210, np.y + y_channel + 210, 20, 20}, std::format("{}",(float)n.midi_gate/1000.0f).c_str());
|
2024-10-27 00:40:57 +02:00
|
|
|
GuiSlider((Rectangle){np.x + 20, np.y + y_channel + 240, 220, 20}, "", "", &v, 0, 30000);
|
2024-10-25 16:41:37 +02:00
|
|
|
n.midi_gate = round(v);
|
|
|
|
|
|
|
|
|
|
//if(GuiValueBox((Rectangle){n.position.x + 100, n.position.y + y_channel + 40, 140, 20}, "VELOCITY", &n.midi_velocity, 0, 127, n.gui_midi_velocity_edit)) n.gui_midi_velocity_edit = !n.gui_midi_velocity_edit;
|
|
|
|
|
//if(GuiValueBox((Rectangle){n.position.x + 100, n.position.y + y_channel + 60, 140, 20}, "GATE", &n.midi_gate, 0, 5000, n.gui_midi_gate_edit)) n.gui_midi_gate_edit = !n.gui_midi_gate_edit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void draw(Vec2D<float> *mouse_pos, Camera2D *camera){
|
|
|
|
|
drawSideBar();
|
|
|
|
|
drawPerNodeConfig(camera);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|