81 lines
1.8 KiB
C++
81 lines
1.8 KiB
C++
#include "ringmod.h"
|
|
|
|
using Xybrid::Effects::RingMod;
|
|
using namespace Xybrid::Data;
|
|
|
|
#include "util/strings.h"
|
|
|
|
#include "nodelib/basics.h"
|
|
using namespace Xybrid::NodeLib;
|
|
|
|
#include "data/audioframe.h"
|
|
#include "data/porttypes.h"
|
|
|
|
#include "config/pluginregistry.h"
|
|
using namespace Xybrid::Config;
|
|
|
|
#include "audio/audioengine.h"
|
|
using namespace Xybrid::Audio;
|
|
|
|
#include "ui/patchboard/nodeobject.h"
|
|
#include "ui/gadgets/layoutgadget.h"
|
|
#include "ui/gadgets/togglegadget.h"
|
|
#include "ui/gadgets/knobgadget.h"
|
|
using namespace Xybrid::UI;
|
|
|
|
#include <cmath>
|
|
|
|
#include <QCborMap>
|
|
|
|
RegisterPlugin(RingMod, {
|
|
i->id = "fx:ringmod";
|
|
i->displayName = "Ring Mod";
|
|
i->category = "Effect";
|
|
})
|
|
|
|
RingMod::RingMod() { }
|
|
|
|
void RingMod::init() {
|
|
addPort(Port::Input, Port::Audio, 0)->name = "carrier";
|
|
addPort(Port::Input, Port::Audio, 1)->name = "modulator";
|
|
|
|
addPort(Port::Output, Port::Audio, 0);
|
|
}
|
|
|
|
void RingMod::reset() {
|
|
//
|
|
}
|
|
|
|
void RingMod::process() {
|
|
auto c = std::static_pointer_cast<AudioPort>(port(Port::Input, Port::Audio, 0));
|
|
auto m = std::static_pointer_cast<AudioPort>(port(Port::Input, Port::Audio, 1));
|
|
auto out = std::static_pointer_cast<AudioPort>(port(Port::Output, Port::Audio, 0));
|
|
c->pull();
|
|
m->pull();
|
|
out->pull();
|
|
|
|
auto ts = audioEngine->curTickSize();
|
|
for (size_t f = 0; f < ts; f++) {
|
|
AudioFrame fc = (*c)[f];
|
|
AudioFrame fm = (*m)[f];
|
|
|
|
(*out)[f] = (fc*fm * mix) + (fc * (1.0-mix));
|
|
}
|
|
}
|
|
|
|
void RingMod::saveData(QCborMap& m) const {
|
|
m[qs("mix")] = mix;
|
|
}
|
|
|
|
void RingMod::loadData(const QCborMap& m) {
|
|
mix = m.value("mix").toDouble(mix);
|
|
}
|
|
|
|
void RingMod::onGadgetCreated() {
|
|
if (!obj) return;
|
|
auto l = new LayoutGadget(obj);
|
|
|
|
//l->setMetrics(12);
|
|
KnobGadget::autoPercent(l, mix)->setLabel(qs("Mix"))->setDefault(1.0);
|
|
}
|