From 369a7d979da3fc73c8d6179942b50b88fcfb1e3b Mon Sep 17 00:00:00 2001 From: zetaPRIME Date: Fri, 25 Mar 2022 02:25:14 -0400 Subject: [PATCH] switch cutoff to a Param --- xybrid/nodelib/param.h | 14 +++----------- xybrid/nodes/effect/svf.cpp | 14 +++++++++++--- xybrid/nodes/effect/svf.h | 5 ++++- xybrid/ui/gadgets/knobgadget.h | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/xybrid/nodelib/param.h b/xybrid/nodelib/param.h index b0205ce..381626e 100644 --- a/xybrid/nodelib/param.h +++ b/xybrid/nodelib/param.h @@ -70,27 +70,19 @@ namespace Xybrid::NodeLib { return Reader(this, r); } - inline QString saveName() { + inline QString saveName() const { return name.toLower().remove(' '); } - inline void save(QCborMap& m, QString id = { }) { + inline void save(QCborMap& m, QString id = { }) const { if (id.isEmpty()) id = saveName(); m[id] = value; } - inline void load(QCborMap& m, QString id = { }) { + inline void load(const QCborMap& m, QString id = { }) { if (id.isEmpty()) id = saveName(); value = m.value(id).toDouble(value); vt = std::numeric_limits::quiet_NaN(); } - - // - give it a Reader abstraction (grab from a "startTick" thing, call its next() function for tracking and values) - // - functions to automatically save/load from QCborMap - // binding a knobgadget automatically populates range+defaults(+label) - // - figure out how to do range stuff - // - "signed" extents only if min == -max - - // meta info for parameter ports? }; } diff --git a/xybrid/nodes/effect/svf.cpp b/xybrid/nodes/effect/svf.cpp index dee3a10..eae38fb 100644 --- a/xybrid/nodes/effect/svf.cpp +++ b/xybrid/nodes/effect/svf.cpp @@ -52,6 +52,10 @@ SVF::SVF() { } void SVF::init() { addPort(Port::Input, Port::Audio, 0); addPort(Port::Output, Port::Audio, 0); + + //addPort(Port::Input, Port::Parameter, 0); + //auto p = Param("Cutoff", 0.0, 16000.0, 0.0); + cutoff.makePort(this); } void SVF::reset() { @@ -69,12 +73,13 @@ void SVF::process() { out->pull(); auto r = filter.scaledResonance(resonance); + auto c = cutoff.start(); size_t ts = audioEngine->curTickSize(); for (size_t f = 0; f < ts; f++) { AudioFrame inp = (*in)[f]; - filter.process(inp, cutoff, r); + filter.process(inp, c.next(), r); switch (mode) { case Low: @@ -96,13 +101,16 @@ void SVF::process() { } void SVF::saveData(QCborMap& m) const { - m[qs("cutoff")] = cutoff; + //m[qs("cutoff")] = cutoff; + cutoff.save(m); m[qs("resonance")] = resonance; m[qs("mode")] = mode; } void SVF::loadData(const QCborMap& m) { - cutoff = m.value("cutoff").toDouble(m.value("frequency").toDouble(cutoff)); + cutoff.load(m, "frequency"); + cutoff.load(m); + //cutoff = m.value("cutoff").toDouble(m.value("frequency").toDouble(cutoff)); resonance = m.value("resonance").toDouble(resonance); mode = static_cast(m.value("mode").toInteger(mode)); } diff --git a/xybrid/nodes/effect/svf.h b/xybrid/nodes/effect/svf.h index 02059eb..cd67c6f 100644 --- a/xybrid/nodes/effect/svf.h +++ b/xybrid/nodes/effect/svf.h @@ -18,12 +18,15 @@ #include "data/audioframe.h" #include "nodelib/svfilter.h" +#include "nodelib/param.h" namespace Xybrid::Effects { class SVF : public Data::Node { NodeLib::SVFilter filter; - double cutoff = 6440.0; + //double cutoff = 6440.0; + NodeLib::Param cutoff = {"Cutoff", 0, 16000, 0}; + double resonance = 0.0; public: diff --git a/xybrid/ui/gadgets/knobgadget.h b/xybrid/ui/gadgets/knobgadget.h index 78d422e..534d6e1 100644 --- a/xybrid/ui/gadgets/knobgadget.h +++ b/xybrid/ui/gadgets/knobgadget.h @@ -1,6 +1,7 @@ #pragma once #include "ui/gadgets/gadget.h" +#include "nodelib/param.h" #include #include @@ -86,6 +87,24 @@ namespace Xybrid::UI { update(); return this; } + KnobGadget* bind(NodeLib::Param& par) { + auto p = ∥ + fGet = [p] { return p->value; }; + fSet = [p](double d) { + p->value = d; + p->vt = std::numeric_limits::quiet_NaN(); + }; + + // binding to one of these populates metadata + min = p->min; + max = p->max; + defaultVal = p->def; + label->setText(p->name); + + dirty = true; + update(); + return this; + } static QString textPercent(double); static QString textOffset(double);