Skip to content

Commit

Permalink
lv2export: expose lights as control output ports, always connect cv
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Jun 1, 2022
1 parent 848237c commit becfa5d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 45 deletions.
25 changes: 24 additions & 1 deletion lv2export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++);
Expand All @@ -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;
Expand Down
57 changes: 30 additions & 27 deletions lv2export/includes/rack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
};
Expand All @@ -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 {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 {};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 8 additions & 16 deletions lv2export/lv2plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
};
Expand All @@ -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);
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion plugins/Fundamental
Submodule Fundamental updated 1 files
+2 −0 src/SEQ3.cpp

0 comments on commit becfa5d

Please sign in to comment.