aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-07-20 23:00:38 +0200
committerHarald Eilertsen <haraldei@anduin.net>2020-07-20 23:00:38 +0200
commit8bd321abb4470fd050db9b46a1230dbc5e1b612e (patch)
tree2e6892aafb1a0a8c756d8f4ff715aa552944c760
parentd94ee6218b6e3f65554c133d9e09044b99f86396 (diff)
downloadairwindows-lv2-port-8bd321abb4470fd050db9b46a1230dbc5e1b612e.tar.gz
airwindows-lv2-port-8bd321abb4470fd050db9b46a1230dbc5e1b612e.tar.bz2
airwindows-lv2-port-8bd321abb4470fd050db9b46a1230dbc5e1b612e.zip
LV2: Refactor in, out and params to base class.
Base class is now a template taking number of params, inputs and outputs as template args. The last two defaults to 2 (stereo pair), but number of params have to be given. Now if only we could find a smart template for generating the run function too...
-rw-r--r--plugins/LV2/include/lv2plugin.h24
-rw-r--r--plugins/LV2/src/ADClip7/ADClip7.cpp63
-rw-r--r--plugins/LV2/src/ADClip7/ADClip7.h13
-rw-r--r--plugins/LV2/src/ADT/ADT.cpp77
-rw-r--r--plugins/LV2/src/ADT/ADT.h13
-rw-r--r--plugins/LV2/src/Acceleration/Acceleration.cpp49
-rw-r--r--plugins/LV2/src/Acceleration/Acceleration.h9
-rw-r--r--plugins/LV2/src/Air/Air.cpp77
-rw-r--r--plugins/LV2/src/Air/Air.h13
9 files changed, 48 insertions, 290 deletions
diff --git a/plugins/LV2/include/lv2plugin.h b/plugins/LV2/include/lv2plugin.h
index f8ae4da..46464a3 100644
--- a/plugins/LV2/include/lv2plugin.h
+++ b/plugins/LV2/include/lv2plugin.h
@@ -1,6 +1,10 @@
+#include <cstddef>
+#include <iostream>
+
// Required typa alias for VTS processing funcs.
using VstInt32 = int32_t;
+template<size_t nparams, size_t ninputs = 2, size_t noutputs = 2>
class LV2Plugin
{
public:
@@ -8,11 +12,31 @@ public:
: rate(frame_rate)
{}
+ void connect_port(uint32_t port, void * data)
+ {
+ if (port < nparams) {
+ params[port] = static_cast<const float *>(data);
+ }
+ else if (port < nparams + ninputs) {
+ in[port - nparams] = static_cast<const float *>(data);
+ }
+ else if (port < nparams + ninputs + noutputs) {
+ out[port - nparams - ninputs] = static_cast<float *>(data);
+ }
+ else {
+ std::cerr << "Invalid port " << port << ": ignoring." << std::endl;
+ }
+ }
+
double getSampleRate() const
{
return rate;
}
+ const float * params[nparams];
+ const float * in[ninputs];
+ float * out[noutputs];
+
private:
double rate;
};
diff --git a/plugins/LV2/src/ADClip7/ADClip7.cpp b/plugins/LV2/src/ADClip7/ADClip7.cpp
index 11c8c27..e568a30 100644
--- a/plugins/LV2/src/ADClip7/ADClip7.cpp
+++ b/plugins/LV2/src/ADClip7/ADClip7.cpp
@@ -3,21 +3,6 @@
#include <iostream>
#include <lv2wrapper.h>
-namespace {
-
-enum class PortIndex : uint32_t {
- BOOST,
- SOFTEN,
- ENHANCE,
- MODE,
- IN_L,
- IN_R,
- OUT_L,
- OUT_R,
-};
-
-} // anon namespace
-
ADClip7::ADClip7(double rate)
: LV2Plugin(rate)
, refclipL(0.99)
@@ -25,52 +10,12 @@ ADClip7::ADClip7(double rate)
{
}
-void ADClip7::connect_port(uint32_t port, void * data)
-{
- switch (static_cast<PortIndex>(port)) {
- case PortIndex::BOOST:
- boost = static_cast<const float *>(data);
- break;
-
- case PortIndex::SOFTEN:
- soften = static_cast<const float *>(data);
- break;
-
- case PortIndex::ENHANCE:
- enhance = static_cast<const float *>(data);
- break;
-
- case PortIndex::MODE:
- mode = static_cast<const float *>(data);
- break;
-
- case PortIndex::IN_L:
- in[0] = static_cast<const float *>(data);
- break;
-
- case PortIndex::IN_R:
- in[1] = static_cast<const float *>(data);
- break;
-
- case PortIndex::OUT_L:
- out[0] = static_cast<float *>(data);
- break;
-
- case PortIndex::OUT_R:
- out[1] = static_cast<float *>(data);
- break;
-
- default:
- std::cerr << "Invalid port " << port << ": ignoring." << std::endl;
- }
-}
-
void ADClip7::run(uint32_t num_samples)
{
- A = *boost;
- B = *soften;
- C = *enhance;
- D = *mode;
+ A = *params[0];
+ B = *params[1];
+ C = *params[2];
+ D = *params[3];
processReplacing(const_cast<float **>(in), out, num_samples);
}
diff --git a/plugins/LV2/src/ADClip7/ADClip7.h b/plugins/LV2/src/ADClip7/ADClip7.h
index e3d8474..a92ebfd 100644
--- a/plugins/LV2/src/ADClip7/ADClip7.h
+++ b/plugins/LV2/src/ADClip7/ADClip7.h
@@ -4,11 +4,10 @@
#include <cstdint>
#include <lv2plugin.h>
-class ADClip7 : protected LV2Plugin {
+class ADClip7 : public LV2Plugin<4> {
public:
ADClip7(double rate);
- void connect_port(uint32_t port, void * data);
void run(uint32_t num_samples);
static constexpr const char * URI = "https://www.airwindows.com/adclip-7";
@@ -21,16 +20,6 @@ private:
void processReplacing(float **in, float **out, VstInt32 samples);
void processDoubleReplacing(double **in, double **out, VstInt32 samples);
- // Pointers to control ports
- const float * boost;
- const float * soften;
- const float * enhance;
- const float * mode;
-
- // Pointer to audio buffers
- const float * in[2];
- float * out[2];
-
// Temp values used by the processing code
float A;
float B;
diff --git a/plugins/LV2/src/ADT/ADT.cpp b/plugins/LV2/src/ADT/ADT.cpp
index 66423b2..5f5e6e0 100644
--- a/plugins/LV2/src/ADT/ADT.cpp
+++ b/plugins/LV2/src/ADT/ADT.cpp
@@ -2,84 +2,19 @@
#include <iostream>
#include <lv2wrapper.h>
-namespace {
-
-enum class PortIndex : uint32_t {
- HEADRM,
- A_DELAY,
- A_LEVEL,
- B_DELAY,
- B_LEVEL,
- OUTPUT,
- IN_L,
- IN_R,
- OUT_L,
- OUT_R,
-};
-
-} // anon namespace
-
ADT::ADT(double rate)
: LV2Plugin(rate)
{
}
-void ADT::connect_port(uint32_t port, void * data)
-{
- switch (static_cast<PortIndex>(port)) {
- case PortIndex::HEADRM:
- headroom = static_cast<const float *>(data);
- break;
-
- case PortIndex::A_DELAY:
- a_delay = static_cast<const float *>(data);
- break;
-
- case PortIndex::A_LEVEL:
- a_level = static_cast<const float *>(data);
- break;
-
- case PortIndex::B_DELAY:
- b_delay = static_cast<const float *>(data);
- break;
-
- case PortIndex::B_LEVEL:
- b_level = static_cast<const float *>(data);
- break;
-
- case PortIndex::OUTPUT:
- out_level = static_cast<const float *>(data);
- break;
-
- case PortIndex::IN_L:
- in[0] = static_cast<const float *>(data);
- break;
-
- case PortIndex::IN_R:
- in[1] = static_cast<const float *>(data);
- break;
-
- case PortIndex::OUT_L:
- out[0] = static_cast<float *>(data);
- break;
-
- case PortIndex::OUT_R:
- out[1] = static_cast<float *>(data);
- break;
-
- default:
- std::cerr << "Invalid port " << port << ": ignoring." << std::endl;
- }
-}
-
void ADT::run(uint32_t num_samples)
{
- A = *headroom;
- B = *a_delay;
- C = *a_level;
- D = *b_delay;
- E = *b_level;
- F = *out_level;
+ A = *params[0];
+ B = *params[1];
+ C = *params[2];
+ D = *params[3];
+ E = *params[4];
+ F = *params[5];
processReplacing(const_cast<float **>(in), out, num_samples);
}
diff --git a/plugins/LV2/src/ADT/ADT.h b/plugins/LV2/src/ADT/ADT.h
index e76ae87..fb6aab4 100644
--- a/plugins/LV2/src/ADT/ADT.h
+++ b/plugins/LV2/src/ADT/ADT.h
@@ -4,11 +4,10 @@
#include <cstdint>
#include <lv2plugin.h>
-class ADT : protected LV2Plugin {
+class ADT : public LV2Plugin<6> {
public:
ADT(double rate);
- void connect_port(uint32_t port, void * data);
void run(uint32_t num_samples);
static constexpr const char * URI = "https://www.airwindows.com/adt";
@@ -21,16 +20,6 @@ private:
void processReplacing(float **in, float **out, VstInt32 samples);
void processDoubleReplacing(double **in, double **out, VstInt32 samples);
- const float * headroom;
- const float * a_delay;
- const float * a_level;
- const float * b_delay;
- const float * b_level;
- const float * out_level;
-
- const float * in[2];
- float * out[2];
-
/*
* Members needed by the processing functions.
*/
diff --git a/plugins/LV2/src/Acceleration/Acceleration.cpp b/plugins/LV2/src/Acceleration/Acceleration.cpp
index 840d0f3..3499537 100644
--- a/plugins/LV2/src/Acceleration/Acceleration.cpp
+++ b/plugins/LV2/src/Acceleration/Acceleration.cpp
@@ -2,60 +2,17 @@
#include <iostream>
#include <lv2wrapper.h>
-namespace {
-
-enum class PortIndex : uint32_t {
- LIMIT,
- DRYWET,
- IN_L,
- IN_R,
- OUT_L,
- OUT_R,
-};
-
-} // anon namespace
-
Acceleration::Acceleration(double rate)
: LV2Plugin(rate)
{
}
-void Acceleration::connect_port(uint32_t port, void * data)
-{
- switch (static_cast<PortIndex>(port)) {
- case PortIndex::LIMIT:
- limit = (const float *) data;
- break;
-
- case PortIndex::DRYWET:
- drywet = (const float *) data;
- break;
-
- case PortIndex::IN_L:
- in[0] = (const float *) data;
- break;
-
- case PortIndex::IN_R:
- in[1] = (const float *) data;
- break;
-
- case PortIndex::OUT_L:
- out[0] = (float *) data;
- break;
-
- case PortIndex::OUT_R:
- out[1] = (float *) data;
- break;
-
- default:
- std::cerr << "Invalid port " << port << ": ignoring." << std::endl;
- }
-}
void Acceleration::run(uint32_t num_samples)
{
- A = *limit;
- B = *drywet;
+ A = *params[0];
+ B = *params[1];
+
processReplacing(const_cast<float **>(in), out, num_samples);
}
diff --git a/plugins/LV2/src/Acceleration/Acceleration.h b/plugins/LV2/src/Acceleration/Acceleration.h
index 0971045..a038a12 100644
--- a/plugins/LV2/src/Acceleration/Acceleration.h
+++ b/plugins/LV2/src/Acceleration/Acceleration.h
@@ -1,14 +1,14 @@
#ifndef __Acceleration_H
#define __Acceleration_H
+#include <cstddef>
#include <cstdint>
#include <lv2plugin.h>
-class Acceleration : protected LV2Plugin {
+class Acceleration : public LV2Plugin<2> {
public:
Acceleration(double rate);
- void connect_port(uint32_t port, void * data);
void run(uint32_t num_samples);
static constexpr const char * URI = "https://www.airwindows.com/acceleration";
@@ -21,11 +21,6 @@ private:
void processReplacing(float **in, float **out, VstInt32 samples);
void processDoubleReplacing(double **in, double **out, VstInt32 samples);
- const float * limit;
- const float * drywet;
- const float * in[2];
- float * out[2];
-
// Temp values used by the processing code
double A; // Value of limit when processing called
double B; // Value of dry/wet when processing called
diff --git a/plugins/LV2/src/Air/Air.cpp b/plugins/LV2/src/Air/Air.cpp
index 0783317..9a9e1e3 100644
--- a/plugins/LV2/src/Air/Air.cpp
+++ b/plugins/LV2/src/Air/Air.cpp
@@ -2,84 +2,19 @@
#include <iostream>
#include <lv2wrapper.h>
-namespace {
-
-enum class PortIndex : uint32_t {
- TAP22,
- TAP15,
- TAP11,
- FILTERS_Q,
- OUTPUT,
- DRY_WET,
- IN_L,
- IN_R,
- OUT_L,
- OUT_R,
-};
-
-} // anon namespace
-
Air::Air(double rate)
: LV2Plugin(rate)
{
}
-void Air::connect_port(uint32_t port, void * data)
-{
- switch (static_cast<PortIndex>(port)) {
- case PortIndex::TAP22:
- tap22 = static_cast<const float *>(data);
- break;
-
- case PortIndex::TAP15:
- tap15 = static_cast<const float *>(data);
- break;
-
- case PortIndex::TAP11:
- tap11 = static_cast<const float *>(data);
- break;
-
- case PortIndex::FILTERS_Q:
- filters_q = static_cast<const float *>(data);
- break;
-
- case PortIndex::OUTPUT:
- out_level = static_cast<const float *>(data);
- break;
-
- case PortIndex::DRY_WET:
- dry_wet = static_cast<const float *>(data);
- break;
-
- case PortIndex::IN_L:
- in[0] = static_cast<const float *>(data);
- break;
-
- case PortIndex::IN_R:
- in[1] = static_cast<const float *>(data);
- break;
-
- case PortIndex::OUT_L:
- out[0] = static_cast<float *>(data);
- break;
-
- case PortIndex::OUT_R:
- out[1] = static_cast<float *>(data);
- break;
-
- default:
- std::cerr << "Invalid port " << port << ": ignoring." << std::endl;
- }
-}
-
void Air::run(uint32_t num_samples)
{
- A = *tap22;
- B = *tap15;
- C = *tap11;
- D = *filters_q;
- E = *out_level;
- F = *dry_wet;
+ A = *params[0];
+ B = *params[1];
+ C = *params[2];
+ D = *params[3];
+ E = *params[4];
+ F = *params[5];
processReplacing(const_cast<float **>(in), out, num_samples);
}
diff --git a/plugins/LV2/src/Air/Air.h b/plugins/LV2/src/Air/Air.h
index 580650a..2ff3877 100644
--- a/plugins/LV2/src/Air/Air.h
+++ b/plugins/LV2/src/Air/Air.h
@@ -4,11 +4,10 @@
#include <cstdint>
#include <lv2plugin.h>
-class Air : protected LV2Plugin {
+class Air : public LV2Plugin<6> {
public:
Air(double rate);
- void connect_port(uint32_t port, void * data);
void run(uint32_t num_samples);
static constexpr const char * URI = "https://www.airwindows.com/air";
@@ -21,16 +20,6 @@ private:
void processReplacing(float **in, float **out, VstInt32 samples);
void processDoubleReplacing(double **in, double **out, VstInt32 samples);
- const float * tap22;
- const float * tap15;
- const float * tap11;
- const float * filters_q;
- const float * out_level;
- const float * dry_wet;
-
- const float * in[2];
- float * out[2];
-
/*
* Members needed by the processing functions.
*/