Browse Source

lv2export: expose lights as control output ports, always connect cv

Signed-off-by: falkTX <falktx@falktx.com>
tags/22.06
falkTX 2 years ago
parent
commit
becfa5d39d
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 63 additions and 45 deletions
  1. +24
    -1
      lv2export/export.cpp
  2. +30
    -27
      lv2export/includes/rack.hpp
  3. +8
    -16
      lv2export/lv2plugin.cpp
  4. +1
    -1
      plugins/Fundamental

+ 24
- 1
lv2export/export.cpp View File

@@ -92,7 +92,7 @@ void lv2_generate_ttl()

for (int i=0; i<module->getNumParams(); ++i)
{
ParamQuantity* q = module->getParamQuantity(i);
ParamQuantity* const q = module->getParamQuantity(i);
d_stdout(" lv2:port [");
d_stdout(" a lv2:InputPort, lv2:ControlPort ;");
d_stdout(" lv2:index %d ;", index++);
@@ -107,6 +107,29 @@ void lv2_generate_ttl()
// q->unit.c_str()
}

for (int i=0; i<module->getNumLights(); ++i)
{
LightInfo* const li = module->getLightInfo(i);
d_stdout(" lv2:port [");
d_stdout(" a lv2:OutputPort, lv2:ControlPort ;");
d_stdout(" lv2:index %d ;", index++);
d_stdout(" lv2:symbol \"lv2_light_%d\" ;", i + 1);
if (!li->name.empty())
{
d_stdout(" lv2:name \"%s\" ;", li->name.c_str());
if (!li->description.empty())
d_stdout(" lv2:comment \"%s\" ;", li->description.c_str());
}
else
{
d_stdout(" lv2:name \"Light %d\" ;", i + 1);
}
d_stdout(" ] ;");
d_stdout("");
// q->getDescription().c_str()
// q->unit.c_str()
}

d_stdout(" .");

delete module;


+ 30
- 27
lv2export/includes/rack.hpp View File

@@ -409,13 +409,13 @@ struct Engine {

struct Light {
float value = 0.f;
void setBrightness(float brightness) {
inline void setBrightness(float brightness) {
value = brightness;
}
float getBrightness() {
inline float getBrightness() {
return value;
}
void setBrightnessSmooth(float brightness, float deltaTime, float lambda = 30.f) {
inline void setBrightnessSmooth(float brightness, float deltaTime, float lambda = 30.f) {
if (brightness < value) {
// Fade out light
value += (brightness - value) * lambda * deltaTime;
@@ -425,10 +425,10 @@ struct Light {
value = brightness;
}
}
void setSmoothBrightness(float brightness, float deltaTime) {
inline void setSmoothBrightness(float brightness, float deltaTime) {
setBrightnessSmooth(brightness, deltaTime);
}
void setBrightnessSmooth(float brightness, int frames = 1) {
inline void setBrightnessSmooth(float brightness, int frames = 1) {
setBrightnessSmooth(brightness, frames / 44100.f);
}
};
@@ -445,8 +445,8 @@ struct LightInfo {

struct Param {
float value = 0.f;
float getValue() { return value; }
void setValue(float value) { this->value = value; }
inline float getValue() { return value; }
inline void setValue(float value) { this->value = value; }
};

struct Port {
@@ -463,39 +463,39 @@ struct Port {
INPUT,
OUTPUT,
};
void setVoltage(float voltage, int channel = 0) { voltages[channel] = voltage; }
float getVoltage(int channel = 0) { return voltages[channel]; }
float getPolyVoltage(int channel) { return isMonophonic() ? getVoltage(0) : getVoltage(channel); }
float getNormalVoltage(float normalVoltage, int channel = 0) {
inline void setVoltage(float voltage, int channel = 0) { voltages[channel] = voltage; }
inline float getVoltage(int channel = 0) { return voltages[channel]; }
inline float getPolyVoltage(int channel) { return isMonophonic() ? getVoltage(0) : getVoltage(channel); }
inline float getNormalVoltage(float normalVoltage, int channel = 0) {
return isConnected() ? getVoltage(channel) : normalVoltage;
}
float getNormalPolyVoltage(float normalVoltage, int channel) {
inline float getNormalPolyVoltage(float normalVoltage, int channel) {
return isConnected() ? getPolyVoltage(channel) : normalVoltage;
}
float* getVoltages(int firstChannel = 0) { return &voltages[firstChannel]; }
void readVoltages(float* v) {
inline float* getVoltages(int firstChannel = 0) { return &voltages[firstChannel]; }
inline void readVoltages(float* v) {
for (int c = 0; c < channels; c++) {
v[c] = voltages[c];
}
}
void writeVoltages(const float* v) {
inline void writeVoltages(const float* v) {
for (int c = 0; c < channels; c++) {
voltages[c] = v[c];
}
}
void clearVoltages() {
inline void clearVoltages() {
for (int c = 0; c < channels; c++) {
voltages[c] = 0.f;
}
}
float getVoltageSum() {
inline float getVoltageSum() {
float sum = 0.f;
for (int c = 0; c < channels; c++) {
sum += voltages[c];
}
return sum;
}
float getVoltageRMS() {
inline float getVoltageRMS() {
if (channels == 0) {
return 0.f;
}
@@ -534,7 +534,7 @@ struct Port {
// void setVoltageSimd(T voltage, int firstChannel) {
// voltage.store(&voltages[firstChannel]);
// }
void setChannels(int channels) {
inline void setChannels(int channels) {
if (this->channels == 0) {
return;
}
@@ -546,11 +546,11 @@ struct Port {
}
this->channels = channels;
}
int getChannels() { return channels; }
bool isConnected() { return channels > 0; }
bool isMonophonic() { return channels == 1; }
bool isPolyphonic() { return channels > 1; }
float normalize(float normalVoltage) { return getNormalVoltage(normalVoltage); }
inline int getChannels() { return channels; }
inline bool isConnected() { return channels > 0; }
inline bool isMonophonic() { return channels == 1; }
inline bool isPolyphonic() { return channels > 1; }
inline float normalize(float normalVoltage) { return getNormalVoltage(normalVoltage); }
};

struct Output : Port {};
@@ -601,9 +601,9 @@ struct ParamQuantity : Quantity {
// float getSmoothValue();
// void setValue(float value) override;
// float getValue() override;
float getMinValue() override { return minValue; }
float getMaxValue() override { return maxValue; }
float getDefaultValue() override { return defaultValue; }
inline float getMinValue() override { return minValue; }
inline float getMaxValue() override { return maxValue; }
inline float getDefaultValue() override { return defaultValue; }
// float getDisplayValue() override;
// void setDisplayValue(float displayValue) override;
// std::string getDisplayValueString() override;
@@ -669,6 +669,9 @@ struct Module {
configOutput(i);
}
lightInfos.resize(numLights);
for (int i = 0; i < numLights; i++) {
configLight(i);
}
}
template <class TParamQuantity = ParamQuantity>
TParamQuantity* configParam(int paramId, float minValue, float maxValue, float defaultValue, std::string name = "", std::string unit = "", float displayBase = 0.f, float displayMultiplier = 1.f, float displayOffset = 0.f) {


+ 8
- 16
lv2export/lv2plugin.cpp View File

@@ -105,13 +105,13 @@ struct PluginLv2 {
// FIXME for CV ports we need to detect if something is connected
for (int i=numInputs; --i >=0;)
{
if (!kCvInputs[i])
module->inputs[i].channels = 1;
// if (!kCvInputs[i])
module->inputs[i].channels = 1;
}
for (int i=numOutputs; --i >=0;)
{
if (!kCvOutputs[i])
module->outputs[i].channels = 1;
// if (!kCvOutputs[i])
module->outputs[i].channels = 1;
}

d_stdout("Loaded " SLUG " :: %i inputs, %i outputs, %i params and %i lights",
@@ -130,12 +130,6 @@ struct PluginLv2 {
ports[port] = dataLocation;
}

void lv2_activate()
{
contextSet(&context);
module->onReset();
}

void lv2_run(const uint32_t sampleCount)
{
if (sampleCount == 0)
@@ -171,6 +165,9 @@ struct PluginLv2 {
++args.frame;
}

for (int i=numLights; --i >=0;)
*static_cast<float*>(ports[numInputs+numOutputs+numParams+i]) = module->lights[i].getBrightness();

frameCount += sampleCount;
}
};
@@ -189,11 +186,6 @@ static void lv2_connect_port(LV2_Handle instance, uint32_t port, void* dataLocat
instancePtr->lv2_connect_port(port, dataLocation);
}

static void lv2_activate(LV2_Handle instance)
{
instancePtr->lv2_activate();
}

static void lv2_run(LV2_Handle instance, uint32_t sampleCount)
{
instancePtr->lv2_run(sampleCount);
@@ -219,7 +211,7 @@ static const LV2_Descriptor sLv2Descriptor = {
"urn:cardinal:" SLUG,
lv2_instantiate,
lv2_connect_port,
lv2_activate,
NULL, // activate
lv2_run,
NULL, // deactivate
lv2_cleanup,


+ 1
- 1
plugins/Fundamental

@@ -1 +1 @@
Subproject commit 5ad6f48a006beedda1465208aab8f9296d39c48a
Subproject commit 224c46f5f1ee2a4137e31054da6edc87b9d6f47d

Loading…
Cancel
Save