Loading...
Searching...
No Matches
Smooth_v2.hpp
1#pragma once
2#include <Fx/NoiseFilter.hpp>
3#include <Fx/Types.hpp>
4
5#include <ossia/dataflow/value_port.hpp>
6
7#include <halp/controls.hpp>
8#include <halp/meta.hpp>
9namespace Nodes::Smooth::v2
10{
12{
13 halp_meta(name, "Smooth")
14 halp_meta(c_name, "ValueFilter")
15 halp_meta(category, "Control/Mappings")
16 halp_meta(author, "ossia score")
17 halp_meta(manual_url, "https://ossia.io/score-docs/processes/smooth.html#smooth")
18 halp_meta(description, "Filter noisy value stream")
19 halp_meta(uuid, "bf603921-5a48-4aa5-9bc1-48a762be6467")
20
21 struct
22 {
23 // FIXME all incorrect when token_request smaller than tick
24 halp::val_port<"in", std::optional<ossia::value>> port{};
25 halp::enum_t<dno::type, "Type"> type;
26 halp::knob_f32<"Amount", halp::range{0., 1., 0.1}> amount;
27 halp::log_hslider_f32<"Freq (1e/LP)", halp::range{0.001, 300., 120.}> freq;
28 halp::log_hslider_f32<"Cutoff (1e/LP)", halp::range{0.001, 10., 1.}> cutoff;
29 halp::hslider_f32<"Beta (1e only)", halp::range{0.001, 10., 1.}> beta;
30 halp::toggle<"Continuous", halp::toggle_setup{}> continuous;
31 } inputs;
32 struct
33 {
34 value_out port{};
35 } outputs;
36 void operator()()
37 {
38 if(auto& v = this->inputs.port.value)
39 {
40 auto filtered = this->filter(
41 *v, inputs.type, inputs.amount, inputs.freq, inputs.cutoff, inputs.beta);
42 outputs.port(std::move(filtered)); // TODO fix accuracy of timestamp
43 this->last = *v;
44 }
45 else
46 {
47 // FIXME this is slightly imprecise as the filters expect regular input
48 // and if we have split ticks that's not what happens
49 if(inputs.continuous && this->last.valid())
50 {
51 auto filtered = this->filter(
52 this->last, inputs.type, inputs.amount, inputs.freq, inputs.cutoff,
53 inputs.beta);
54 outputs.port(std::move(filtered));
55 }
56 }
57 }
58
59#if FX_UI
60 static void item(
61 Process::Enum& type, Process::FloatKnob& amount, Process::LogFloatSlider& freq,
62 Process::LogFloatSlider& cutoff, Process::FloatSlider& beta, Process::Toggle& cont,
63 const Process::ProcessModel& process, QGraphicsItem& parent, QObject& context,
64 const Process::Context& doc)
65 {
66 using namespace Process;
67 const Process::PortFactoryList& portFactory
69 const auto tMarg = 5;
70 const auto cMarg = 15;
71 const auto h = 125;
72 const auto w = 220;
73
74 auto c0_bg = new score::BackgroundItem{&parent};
75 c0_bg->setRect({0., 0., w, h});
76
77 auto type_item = makeControl(
78 tuplet::get<0>(Metadata::controls), type, parent, context, doc, portFactory);
79 type_item.root.setPos(70, 0);
80 type_item.control.rows = 4;
81 type_item.control.columns = 1;
82 type_item.control.setRect(QRectF{0, 0, 60, 105});
83
84 auto amount_item = makeControl(
85 tuplet::get<1>(Metadata::controls), amount, parent, context, doc, portFactory);
86 amount_item.root.setPos(tMarg, 30);
87 amount_item.control.setPos(0, cMarg);
88
89 auto freq_item = makeControl(
90 tuplet::get<2>(Metadata::controls), freq, parent, context, doc, portFactory);
91 freq_item.root.setPos(140, 0);
92 freq_item.control.setPos(0, cMarg);
93
94 auto cutoff_item = makeControl(
95 tuplet::get<3>(Metadata::controls), cutoff, parent, context, doc, portFactory);
96 cutoff_item.root.setPos(140, 40);
97 cutoff_item.control.setPos(0, cMarg);
98
99 auto beta_item = makeControl(
100 tuplet::get<4>(Metadata::controls), beta, parent, context, doc, portFactory);
101 beta_item.root.setPos(140, 80);
102 beta_item.control.setPos(0, cMarg);
103
104 auto cont_item = makeControl(
105 tuplet::get<5>(Metadata::controls), cont, parent, context, doc, portFactory);
106 cont_item.root.setPos(tMarg, 0);
107 //cont_item.control.setPos(10, cMarg);
108 }
109#endif
110};
111}
Definition NoiseFilter.hpp:128
Definition PortFactory.hpp:74
The Process class.
Definition score-lib-process/Process/Process.hpp:61
Definition RectItem.hpp:96
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
Definition Smooth_v2.hpp:12
Definition ProcessContext.hpp:12
const T & interfaces() const
Access to a specific interface list.
Definition ApplicationContext.hpp:67