Loading...
Searching...
No Matches
MidiToArray.hpp
1#pragma once
2#include <Fx/Types.hpp>
3
4#include <ossia/dataflow/port.hpp>
5
6#include <halp/audio.hpp>
7#include <halp/callback.hpp>
8#include <halp/controls.hpp>
9#include <halp/meta.hpp>
10#include <halp/midi.hpp>
11
12namespace Nodes::MidiToArray
13{
14struct Node
15{
16 halp_meta(name, "MIDI to array")
17 halp_meta(c_name, "MidiToArray")
18 halp_meta(category, "Midi")
19 halp_meta(author, "ossia score")
20 halp_meta(manual_url, "")
21 halp_meta(description, "Converts a MIDI 1 input to a sequence of bytes")
22 halp_meta(uuid, "1311a0fb-3468-4e35-b0ba-c5aaf20efe7a");
23
24 enum midi_mode
25 {
26 MIDI1,
27 UMP
28 };
29
30 struct
31 {
32 ossia_port<"in", ossia::midi_port> port{};
33 halp::enum_t<midi_mode, "Mode"> mode;
34 } inputs;
35 struct
36 {
37 ossia_port<"out", ossia::value_port> port{};
38 } outputs;
39
40 void operator()()
41 {
42 if(inputs.mode == midi_mode::MIDI1)
43 {
44 for(auto& msg : inputs.port.value->messages)
45 {
46 std::vector<ossia::value> vals;
47 vals.reserve(4);
48 for(auto byte : libremidi::midi1_from_ump(msg).bytes)
49 vals.emplace_back((int)byte);
50 outputs.port.value->write_value(std::move(vals), msg.timestamp);
51 }
52 }
53 else
54 {
55 for(auto& msg : inputs.port.value->messages)
56 {
57 std::vector<ossia::value> vals;
58 vals.reserve(4);
59 for(std::size_t i = 0; i < msg.size(); i++)
60 vals.emplace_back((int)msg.data[i]);
61 outputs.port.value->write_value(std::move(vals), msg.timestamp);
62 }
63 }
64 }
65};
66}
Definition MidiToArray.hpp:15
Definition Types.hpp:39