Loading...
Searching...
No Matches
score-plugin-faust/Faust/Utils.hpp
1#pragma once
2#include <Process/Dataflow/Port.hpp>
3#include <Process/Dataflow/WidgetInlets.hpp>
4
5#include <ossia/dataflow/graph_node.hpp>
6#include <ossia/dataflow/nodes/faust/faust_utils.hpp>
7#include <ossia/dataflow/port.hpp>
8#include <ossia/network/domain/domain.hpp>
9
10#include <QDebug>
11
12#include <faust/gui/MetaDataUI.h>
13
14#include <string_view>
15
16namespace Faust
17{
18
19template <typename Proc, bool Synth>
20struct UI
21 : ::UI
22 , MetaDataUI
23{
24 Proc& fx;
25
26 UI(Proc& sfx)
27 : fx{sfx}
28 {
29 }
30
31 void openTabBox(const char* label) override { }
32 void openHorizontalBox(const char* label) override { }
33 void openVerticalBox(const char* label) override { }
34 void closeBox() override { }
35 void declare(FAUSTFLOAT* zone, const char* key, const char* val) override
36 {
37 MetaDataUI::declare(zone, key, val);
38 }
39 void
40 addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) override
41 {
42 }
43
44 void addButton(const char* label, FAUSTFLOAT* zone) override
45 {
46 if constexpr(Synth)
47 {
48 using namespace std::literals;
49 if(label == "Panic"sv || label == "gate"sv)
50 return;
51 }
52
53 auto inl = new Process::Button{label, getStrongId(fx.inlets()), &fx};
54 fx.inlets().push_back(inl);
55 }
56
57 void addCheckButton(const char* label, FAUSTFLOAT* zone) override
58 {
59 auto inl = new Process::Toggle{bool(*zone), label, getStrongId(fx.inlets()), &fx};
60 fx.inlets().push_back(inl);
61 }
62
63 void addVerticalSlider(
64 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
65 FAUSTFLOAT max, FAUSTFLOAT step) override
66 {
67 using namespace std::literals;
68 if constexpr(Synth)
69 {
70 if(label == "gain"sv || label == "freq"sv || label == "sustain"sv)
71 return;
72 }
73
74 if(label == "0x00"sv)
75 label = "Control";
76
77 if(isKnob(zone))
78 {
79 auto inl = new Process::FloatKnob{
80 (float)min, (float)max, (float)init, label, getStrongId(fx.inlets()), &fx};
81 fx.inlets().push_back(inl);
82 }
83 else
84 {
85 auto inl = new Process::FloatSlider{
86 (float)min, (float)max, (float)init, label, getStrongId(fx.inlets()), &fx};
87 fx.inlets().push_back(inl);
88 }
89 }
90
91 void addHorizontalSlider(
92 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
93 FAUSTFLOAT max, FAUSTFLOAT step) override
94 {
95 addVerticalSlider(label, zone, init, min, max, step);
96 }
97
98 void addNumEntry(
99 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
100 FAUSTFLOAT max, FAUSTFLOAT step) override
101 {
102 // TODO spinbox ?
103 addVerticalSlider(label, zone, init, min, max, step);
104 }
105
106 void addHorizontalBargraph(
107 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) override
108 {
109 auto inl = new Process::Bargraph{
110 (float)min, (float)max, (float)min, label, getStrongId(fx.outlets()), &fx};
111 fx.outlets().push_back(inl);
112 }
113
114 void addVerticalBargraph(
115 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) override
116 {
117 addHorizontalBargraph(label, zone, min, max);
118 }
119};
120
121template <typename Proc, bool SetInit>
123 : ::UI
124 , MetaDataUI
125{
126 Proc& fx;
127 Process::Inlets& toRemove;
128 Process::Outlets& toRemoveO;
129 std::size_t i = 1;
130 std::size_t o = 1;
131
132 UpdateUI(Proc& sfx, Process::Inlets& toRemove, Process::Outlets& toRemoveO)
133 : fx{sfx}
134 , toRemove{toRemove}
135 , toRemoveO{toRemoveO}
136 {
137 }
138
139 void openTabBox(const char* label) override { }
140 void openHorizontalBox(const char* label) override { }
141 void openVerticalBox(const char* label) override { }
142 void closeBox() override { }
143 void declare(FAUSTFLOAT* zone, const char* key, const char* val) override
144 {
145 MetaDataUI::declare(zone, key, val);
146 }
147 void
148 addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) override
149 {
150 }
151
152 void replace(Process::Inlet*& oldinl, Process::Inlet* newinl)
153 {
154 toRemove.push_back(oldinl);
155 oldinl = newinl;
156 }
157
158 void replace(Process::Outlet*& oldoutl, Process::Outlet* newoutl)
159 {
160 toRemoveO.push_back(oldoutl);
161 oldoutl = newoutl;
162 }
163
164 void addButton(const char* label, FAUSTFLOAT* zone) override
165 {
166 if(i < fx.inlets().size())
167 {
168 if(auto inlet = dynamic_cast<Process::Button*>(fx.inlets()[i]))
169 {
170 inlet->setName(label);
171 }
172 else
173 {
174 auto id = fx.inlets()[i]->id();
175 replace(fx.inlets()[i], new Process::Button{label, id, &fx});
176 }
177 }
178 else
179 {
180 auto inl = new Process::Button{label, getStrongId(fx.inlets()), &fx};
181 fx.inlets().push_back(inl);
182 fx.controlAdded(inl->id());
183 }
184 i++;
185 }
186
187 void addCheckButton(const char* label, FAUSTFLOAT* zone) override
188 {
189 if(i < fx.inlets().size())
190 {
191 if(auto inlet = dynamic_cast<Process::Toggle*>(fx.inlets()[i]))
192 {
193 inlet->setName(label);
194 if constexpr(SetInit)
195 inlet->setValue(bool(*zone));
196 }
197 else
198 {
199 auto id = fx.inlets()[i]->id();
200 replace(fx.inlets()[i], new Process::Toggle{bool(*zone), label, id, &fx});
201 }
202 }
203 else
204 {
205 auto inl = new Process::Toggle{bool(*zone), label, getStrongId(fx.inlets()), &fx};
206 fx.inlets().push_back(inl);
207 fx.controlAdded(inl->id());
208 }
209 i++;
210 }
211
212 void addVerticalSlider(
213 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
214 FAUSTFLOAT max, FAUSTFLOAT step) override
215 {
216 if(i < fx.inlets().size())
217 {
218 if(Process::FloatSlider
219 * slider{dynamic_cast<Process::FloatSlider*>(fx.inlets()[i])})
220 {
221 if(isKnob(zone))
222 {
223 auto id = fx.inlets()[i]->id();
224 auto inl = new Process::FloatKnob{
225 (float)min, (float)max, (float)init, label, getStrongId(fx.inlets()), &fx};
226 replace(fx.inlets()[i], inl);
227 }
228 else
229 {
230 slider->setName(label);
231 slider->setDomain(ossia::make_domain(min, max));
232 if constexpr(SetInit)
233 slider->setValue(init);
234 }
235 }
236 else if(
237 Process::FloatKnob * knob{dynamic_cast<Process::FloatKnob*>(fx.inlets()[i])})
238 {
239 if(isKnob(zone))
240 {
241 knob->setName(label);
242 knob->setDomain(ossia::make_domain(min, max));
243 if constexpr(SetInit)
244 knob->setValue(init);
245 }
246 else
247 {
248 auto id = fx.inlets()[i]->id();
249 auto inl = new Process::FloatSlider{
250 (float)min, (float)max, (float)init, label, getStrongId(fx.inlets()), &fx};
251 replace(fx.inlets()[i], inl);
252 }
253 }
254 else
255 {
256 auto id = fx.inlets()[i]->id();
257 if(isKnob(zone))
258 {
259 auto inl = new Process::FloatKnob{
260 (float)min, (float)max, (float)init, label, getStrongId(fx.inlets()), &fx};
261 replace(fx.inlets()[i], inl);
262 }
263 else
264 {
265 auto inl = new Process::FloatSlider{
266 (float)min, (float)max, (float)init, label, getStrongId(fx.inlets()), &fx};
267 replace(fx.inlets()[i], inl);
268 }
269 }
270 }
271 else
272 {
273 if(isKnob(zone))
274 {
275 auto inl = new Process::FloatKnob{
276 (float)min, (float)max, (float)init, label, getStrongId(fx.inlets()), &fx};
277 fx.inlets().push_back(inl);
278 fx.controlAdded(inl->id());
279 }
280 else
281 {
282 auto inl = new Process::FloatSlider{
283 (float)min, (float)max, (float)init, label, getStrongId(fx.inlets()), &fx};
284 fx.inlets().push_back(inl);
285 fx.controlAdded(inl->id());
286 }
287 }
288
289 i++;
290 }
291
292 void addHorizontalSlider(
293 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
294 FAUSTFLOAT max, FAUSTFLOAT step) override
295 {
296 addVerticalSlider(label, zone, init, min, max, step);
297 }
298
299 void addNumEntry(
300 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
301 FAUSTFLOAT max, FAUSTFLOAT step) override
302 {
303 addVerticalSlider(label, zone, init, min, max, step);
304 }
305
306 void addHorizontalBargraph(
307 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) override
308 {
309 if(o < fx.outlets().size())
310 {
311 if(auto outlet = dynamic_cast<Process::Bargraph*>(fx.outlets()[o]))
312 {
313 outlet->setName(label);
314 outlet->setDomain(ossia::make_domain(min, max));
315 }
316 else
317 {
318 auto id = fx.outlets()[o]->id();
319 auto inl
320 = new Process::Bargraph{(float)min, (float)max, (float)min, label, id, &fx};
321 replace(fx.outlets()[o], inl);
322 }
323 }
324 else
325 {
326 auto inl = new Process::Bargraph{
327 (float)min, (float)max, (float)min, label, getStrongId(fx.outlets()), &fx};
328 fx.outlets().push_back(inl);
329 fx.controlAdded(inl->id());
330 }
331 o++;
332 }
333
334 void addVerticalBargraph(
335 const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) override
336 {
337 addHorizontalBargraph(label, zone, min, max);
338 }
339};
340}
Definition Port.hpp:177
Definition Port.hpp:273
Definition score-plugin-faust/Faust/Utils.hpp:23
Definition score-plugin-faust/Faust/Utils.hpp:125
Definition PortForward.hpp:23
Definition PortForward.hpp:27