OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
midi_parameter.hpp
1#pragma once
2#include <ossia/network/base/parameter.hpp>
3#include <ossia/network/domain/domain.hpp>
4#include <ossia/protocols/midi/detail/channel.hpp>
5
6namespace ossia::net
7{
8class protocol_base;
9}
10namespace ossia::net::midi
11{
12class midi_protocol;
13struct address_info
14{
15 enum class Type : midi_size_t
16 {
17 NoteOn, // /12/note/on 64 127 -> C3 at 127 velocity
18 NoteOn_N, // /12/note/on/64 127 -> C3 at 127 velocity
19 NoteOff, // /12/note/off 64 127
20 NoteOff_N, // /12/note/off/64 127
21 CC, // /12/CC 64 123
22 CC_N, // /12/CC/64 123,
23 PC, // /12/PC 32
24 PC_N, // /12/PC/32 Impulse
25 PB, // /12/PB -8192 -> 8191
26 Any
27 };
28
29 ossia::val_type matchingType()
30 {
31 switch(type)
32 {
33 case Type::NoteOn:
34 case Type::NoteOff:
35 case Type::CC:
36 case Type::Any:
38 case Type::NoteOn_N:
39 case Type::NoteOff_N:
40 case Type::CC_N:
41 case Type::PC:
42 case Type::PB:
44 case Type::PC_N:
46 }
47 return {};
48 }
49
50 static const std::string* num_table_init() noexcept
51 {
52 static std::string num_table[257];
53 for(int i = 0; i < 257; i++)
54 {
55 num_table[i] = std::to_string(i);
56 }
57 return num_table;
58 }
59 static const std::string* num_table() noexcept
60 {
61 static auto ptr = num_table_init();
62 return ptr;
63 }
64
65 std::string address()
66 {
67 auto nums = num_table();
68 switch(type)
69 {
70 case Type::NoteOn:
71 return "/" + nums[channel] + "/note/on";
72 case Type::NoteOff:
73 return "/" + nums[channel] + "/note/off";
74 case Type::CC:
75 return "/" + nums[channel] + "/CC";
76 case Type::NoteOn_N:
77 return "/" + nums[channel] + "/note/on/" + nums[note];
78 case Type::NoteOff_N:
79 return "/" + nums[channel] + "/note/off/" + nums[note];
80 case Type::CC_N:
81 return "/" + nums[channel] + "/CC/" + nums[note];
82 case Type::PC:
83 return "/" + nums[channel] + "/PC";
84 case Type::PC_N:
85 return "/" + nums[channel] + "/PC/" + nums[note];
86 case Type::PB:
87 return "/" + nums[channel] + "/PB";
88 case Type::Any:
89 return "/";
90 }
91 return {};
92 }
93
94 ossia::value defaultValue(int32_t val)
95 {
96 switch(type)
97 {
98 case Type::NoteOn:
99 case Type::NoteOff:
100 case Type::CC:
101 return value{std::vector<ossia::value>{int32_t{val}, int32_t{val}}};
102 case Type::Any:
103 return value{std::vector<ossia::value>{}};
104 case Type::NoteOn_N:
105 case Type::NoteOff_N:
106 case Type::CC_N:
107 case Type::PC:
108 case Type::PB:
109 return int32_t{val};
110 case Type::PC_N:
111 return ossia::impulse{};
112 }
113 return {};
114 }
115
116 ossia::domain defaultDomain()
117 {
118 if(type != Type::PB && type != Type::Any)
119 return ossia::make_domain(defaultValue(0), defaultValue(127));
120 return ossia::make_domain(0, 16384);
121 }
122
123 address_info(Type t)
124 : type{t}
125 {
126 }
127
128 address_info(Type t, midi_size_t n)
129 : type{t}
130 , note{n}
131 {
132 }
133
134 address_info(midi_size_t chan, Type t, midi_size_t n)
135 : channel{chan}
136 , type{t}
137 , note{n}
138 {
139 }
140 midi_size_t channel{};
141 Type type{};
142 midi_size_t note{};
143};
144
145class midi_parameter : public ossia::net::parameter_base
146{
147public:
148 midi_parameter(address_info info, ossia::net::node_base& parent);
149 ossia::net::protocol_base& get_protocol() const noexcept override
150 {
151 return m_protocol;
152 }
153
154 const address_info& info() const;
155
156 void pull_value() final override;
157 parameter_base& push_value(const ossia::value& val) final override;
158 parameter_base& push_value(ossia::value&& val) final override;
159 parameter_base& push_value() final override;
160 const ossia::value& getValue() const;
161
162 ossia::value value() const final override;
163 ossia::value set_value(const ossia::value& v) final override;
164 ossia::value set_value(ossia::value&& v) final override;
165
166 ossia::val_type get_value_type() const noexcept final override;
167 parameter_base& set_value_type(ossia::val_type) final override;
168
169 ossia::access_mode get_access() const noexcept final override;
170 parameter_base& set_access(ossia::access_mode) final override;
171
172 const ossia::domain& get_domain() const noexcept final override;
173 parameter_base& set_domain(const ossia::domain&) final override;
174
175 ossia::bounding_mode get_bounding() const noexcept final override;
176 parameter_base& set_bounding(ossia::bounding_mode) final override;
177
178 void on_first_callback_added() final override;
179 void on_removing_last_callback() final override;
180
181 void value_callback(const ossia::value& val);
182
183protected:
184 address_info m_info;
185 ossia::net::protocol_base& m_protocol;
186 ossia::domain m_domain;
187
188 ossia::val_type m_type = ossia::val_type::INT;
189 ossia::value m_value;
190};
191}
The node_base class.
Definition node.hpp:48
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
The protocol_base class.
Definition protocol.hpp:40
The value class.
Definition value.hpp:173
Definition git_info.h:7
val_type
Enum to represent the types that a value can take.
Definition parameter_properties.hpp:16
@ IMPULSE
array<float, 4>
@ LIST
std::string
bounding_mode
Address behaviors at crossing domain boundaries.
Definition parameter_properties.hpp:56
access_mode
Address behaviors at crossing domain boundaries time.
Definition parameter_properties.hpp:46
domain A domain of values
Definition domain_base.hpp:23