in between working states, switchting to multi midi out per node
This commit is contained in:
+40
-24
@@ -6,6 +6,7 @@
|
||||
#include "raylib.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
@@ -15,55 +16,70 @@ struct NoteTimer{
|
||||
int channel;
|
||||
int note;
|
||||
int velocity;
|
||||
int start;
|
||||
int length;
|
||||
float start;
|
||||
int gate;
|
||||
bool erase = false;
|
||||
};
|
||||
|
||||
struct MidiOutPort{
|
||||
libremidi::output_port port;
|
||||
int number;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
struct MidiOut{
|
||||
libremidi::midi_out out;
|
||||
|
||||
};
|
||||
|
||||
class Midi {
|
||||
|
||||
public:
|
||||
Midi() {
|
||||
|
||||
for(const libremidi::input_port& port : obs.get_input_ports()){
|
||||
midi_in_ports.push_back(port);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for(const libremidi::output_port& port : obs.get_output_ports()){
|
||||
midi_out_ports.push_back(port);
|
||||
midi_out_ports.push_back({port, i, false});
|
||||
i++;
|
||||
}
|
||||
std::cout << midi_out_ports.size() << std::endl;
|
||||
}
|
||||
|
||||
libremidi::observer obs;
|
||||
|
||||
std::vector<std::shared_ptr<libremidi::midi_out>> midi_outs;
|
||||
std::map<int, std::shared_ptr<libremidi::midi_out>> midi_outs;
|
||||
std::vector<libremidi::input_port> midi_in_ports;
|
||||
std::vector<libremidi::output_port> midi_out_ports;
|
||||
std::vector<MidiOutPort> midi_out_ports;
|
||||
|
||||
std::vector<NoteTimer> notes;
|
||||
|
||||
float timer;
|
||||
|
||||
void open_midi_out(int midi_n){
|
||||
std::cout << midi_n << std::endl;
|
||||
|
||||
auto out = std::make_shared<libremidi::midi_out>();
|
||||
out->open_port(midi_out_ports[midi_n]);
|
||||
midi_outs.push_back(out);
|
||||
|
||||
void open_midi_out(MidiOutPort *out_port){
|
||||
if(!midi_outs.contains(out_port->number)){
|
||||
auto out = std::make_shared<libremidi::midi_out>();
|
||||
out->open_port(out_port->port);
|
||||
midi_outs[out_port->number] = out;
|
||||
}
|
||||
}
|
||||
|
||||
void note(int midi_out, int channel, int note, int velocity, int length){
|
||||
midi_outs[midi_out]->send_message(libremidi::channel_events::note_on(channel, note, velocity));
|
||||
notes.emplace_back(midi_out, channel, note, velocity, GetTime(), length);
|
||||
void note(int midi_out, int channel, int note, int velocity, int gate){
|
||||
if(!midi_outs.empty()){
|
||||
midi_outs[midi_out]->send_message(libremidi::channel_events::note_on(channel, note, velocity));
|
||||
notes.emplace_back(midi_out, channel, note, velocity, GetTime(), gate);
|
||||
}
|
||||
}
|
||||
|
||||
void update(){
|
||||
float time = GetTime();
|
||||
for( auto it = notes.begin(); it != notes.end(); ++it){
|
||||
if(time - it->start > ((float)it->length / 1000.0f)){
|
||||
for(auto it = notes.begin(); it != notes.end(); ++it){
|
||||
if(time - it->start >= (float)it->gate / 1000.0f){
|
||||
midi_outs[it->midi_out]->send_message(libremidi::channel_events::note_off(it->channel, it->note, it->velocity));
|
||||
notes.erase(it);
|
||||
it->erase = true;
|
||||
}
|
||||
}
|
||||
std::erase_if(notes, [](const auto& item){return item.erase;});
|
||||
for(auto& p : midi_out_ports){
|
||||
if(p.enabled) {
|
||||
open_midi_out(&p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user