lv2export: expose lights as control output ports, always connect cv
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
848237c9c5
commit
becfa5d39d
4 changed files with 63 additions and 45 deletions
|
@ -92,7 +92,7 @@ void lv2_generate_ttl()
|
||||||
|
|
||||||
for (int i=0; i<module->getNumParams(); ++i)
|
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(" lv2:port [");
|
||||||
d_stdout(" a lv2:InputPort, lv2:ControlPort ;");
|
d_stdout(" a lv2:InputPort, lv2:ControlPort ;");
|
||||||
d_stdout(" lv2:index %d ;", index++);
|
d_stdout(" lv2:index %d ;", index++);
|
||||||
|
@ -107,6 +107,29 @@ void lv2_generate_ttl()
|
||||||
// q->unit.c_str()
|
// 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(" .");
|
d_stdout(" .");
|
||||||
|
|
||||||
delete module;
|
delete module;
|
||||||
|
|
|
@ -409,13 +409,13 @@ struct Engine {
|
||||||
|
|
||||||
struct Light {
|
struct Light {
|
||||||
float value = 0.f;
|
float value = 0.f;
|
||||||
void setBrightness(float brightness) {
|
inline void setBrightness(float brightness) {
|
||||||
value = brightness;
|
value = brightness;
|
||||||
}
|
}
|
||||||
float getBrightness() {
|
inline float getBrightness() {
|
||||||
return value;
|
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) {
|
if (brightness < value) {
|
||||||
// Fade out light
|
// Fade out light
|
||||||
value += (brightness - value) * lambda * deltaTime;
|
value += (brightness - value) * lambda * deltaTime;
|
||||||
|
@ -425,10 +425,10 @@ struct Light {
|
||||||
value = brightness;
|
value = brightness;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setSmoothBrightness(float brightness, float deltaTime) {
|
inline void setSmoothBrightness(float brightness, float deltaTime) {
|
||||||
setBrightnessSmooth(brightness, deltaTime);
|
setBrightnessSmooth(brightness, deltaTime);
|
||||||
}
|
}
|
||||||
void setBrightnessSmooth(float brightness, int frames = 1) {
|
inline void setBrightnessSmooth(float brightness, int frames = 1) {
|
||||||
setBrightnessSmooth(brightness, frames / 44100.f);
|
setBrightnessSmooth(brightness, frames / 44100.f);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -445,8 +445,8 @@ struct LightInfo {
|
||||||
|
|
||||||
struct Param {
|
struct Param {
|
||||||
float value = 0.f;
|
float value = 0.f;
|
||||||
float getValue() { return value; }
|
inline float getValue() { return value; }
|
||||||
void setValue(float value) { this->value = value; }
|
inline void setValue(float value) { this->value = value; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Port {
|
struct Port {
|
||||||
|
@ -463,39 +463,39 @@ struct Port {
|
||||||
INPUT,
|
INPUT,
|
||||||
OUTPUT,
|
OUTPUT,
|
||||||
};
|
};
|
||||||
void setVoltage(float voltage, int channel = 0) { voltages[channel] = voltage; }
|
inline void setVoltage(float voltage, int channel = 0) { voltages[channel] = voltage; }
|
||||||
float getVoltage(int channel = 0) { return voltages[channel]; }
|
inline float getVoltage(int channel = 0) { return voltages[channel]; }
|
||||||
float getPolyVoltage(int channel) { return isMonophonic() ? getVoltage(0) : getVoltage(channel); }
|
inline float getPolyVoltage(int channel) { return isMonophonic() ? getVoltage(0) : getVoltage(channel); }
|
||||||
float getNormalVoltage(float normalVoltage, int channel = 0) {
|
inline float getNormalVoltage(float normalVoltage, int channel = 0) {
|
||||||
return isConnected() ? getVoltage(channel) : normalVoltage;
|
return isConnected() ? getVoltage(channel) : normalVoltage;
|
||||||
}
|
}
|
||||||
float getNormalPolyVoltage(float normalVoltage, int channel) {
|
inline float getNormalPolyVoltage(float normalVoltage, int channel) {
|
||||||
return isConnected() ? getPolyVoltage(channel) : normalVoltage;
|
return isConnected() ? getPolyVoltage(channel) : normalVoltage;
|
||||||
}
|
}
|
||||||
float* getVoltages(int firstChannel = 0) { return &voltages[firstChannel]; }
|
inline float* getVoltages(int firstChannel = 0) { return &voltages[firstChannel]; }
|
||||||
void readVoltages(float* v) {
|
inline void readVoltages(float* v) {
|
||||||
for (int c = 0; c < channels; c++) {
|
for (int c = 0; c < channels; c++) {
|
||||||
v[c] = voltages[c];
|
v[c] = voltages[c];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void writeVoltages(const float* v) {
|
inline void writeVoltages(const float* v) {
|
||||||
for (int c = 0; c < channels; c++) {
|
for (int c = 0; c < channels; c++) {
|
||||||
voltages[c] = v[c];
|
voltages[c] = v[c];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void clearVoltages() {
|
inline void clearVoltages() {
|
||||||
for (int c = 0; c < channels; c++) {
|
for (int c = 0; c < channels; c++) {
|
||||||
voltages[c] = 0.f;
|
voltages[c] = 0.f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float getVoltageSum() {
|
inline float getVoltageSum() {
|
||||||
float sum = 0.f;
|
float sum = 0.f;
|
||||||
for (int c = 0; c < channels; c++) {
|
for (int c = 0; c < channels; c++) {
|
||||||
sum += voltages[c];
|
sum += voltages[c];
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
float getVoltageRMS() {
|
inline float getVoltageRMS() {
|
||||||
if (channels == 0) {
|
if (channels == 0) {
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
|
@ -534,7 +534,7 @@ struct Port {
|
||||||
// void setVoltageSimd(T voltage, int firstChannel) {
|
// void setVoltageSimd(T voltage, int firstChannel) {
|
||||||
// voltage.store(&voltages[firstChannel]);
|
// voltage.store(&voltages[firstChannel]);
|
||||||
// }
|
// }
|
||||||
void setChannels(int channels) {
|
inline void setChannels(int channels) {
|
||||||
if (this->channels == 0) {
|
if (this->channels == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -546,11 +546,11 @@ struct Port {
|
||||||
}
|
}
|
||||||
this->channels = channels;
|
this->channels = channels;
|
||||||
}
|
}
|
||||||
int getChannels() { return channels; }
|
inline int getChannels() { return channels; }
|
||||||
bool isConnected() { return channels > 0; }
|
inline bool isConnected() { return channels > 0; }
|
||||||
bool isMonophonic() { return channels == 1; }
|
inline bool isMonophonic() { return channels == 1; }
|
||||||
bool isPolyphonic() { return channels > 1; }
|
inline bool isPolyphonic() { return channels > 1; }
|
||||||
float normalize(float normalVoltage) { return getNormalVoltage(normalVoltage); }
|
inline float normalize(float normalVoltage) { return getNormalVoltage(normalVoltage); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Output : Port {};
|
struct Output : Port {};
|
||||||
|
@ -601,9 +601,9 @@ struct ParamQuantity : Quantity {
|
||||||
// float getSmoothValue();
|
// float getSmoothValue();
|
||||||
// void setValue(float value) override;
|
// void setValue(float value) override;
|
||||||
// float getValue() override;
|
// float getValue() override;
|
||||||
float getMinValue() override { return minValue; }
|
inline float getMinValue() override { return minValue; }
|
||||||
float getMaxValue() override { return maxValue; }
|
inline float getMaxValue() override { return maxValue; }
|
||||||
float getDefaultValue() override { return defaultValue; }
|
inline float getDefaultValue() override { return defaultValue; }
|
||||||
// float getDisplayValue() override;
|
// float getDisplayValue() override;
|
||||||
// void setDisplayValue(float displayValue) override;
|
// void setDisplayValue(float displayValue) override;
|
||||||
// std::string getDisplayValueString() override;
|
// std::string getDisplayValueString() override;
|
||||||
|
@ -669,6 +669,9 @@ struct Module {
|
||||||
configOutput(i);
|
configOutput(i);
|
||||||
}
|
}
|
||||||
lightInfos.resize(numLights);
|
lightInfos.resize(numLights);
|
||||||
|
for (int i = 0; i < numLights; i++) {
|
||||||
|
configLight(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <class TParamQuantity = ParamQuantity>
|
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) {
|
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) {
|
||||||
|
|
|
@ -105,12 +105,12 @@ struct PluginLv2 {
|
||||||
// FIXME for CV ports we need to detect if something is connected
|
// FIXME for CV ports we need to detect if something is connected
|
||||||
for (int i=numInputs; --i >=0;)
|
for (int i=numInputs; --i >=0;)
|
||||||
{
|
{
|
||||||
if (!kCvInputs[i])
|
// if (!kCvInputs[i])
|
||||||
module->inputs[i].channels = 1;
|
module->inputs[i].channels = 1;
|
||||||
}
|
}
|
||||||
for (int i=numOutputs; --i >=0;)
|
for (int i=numOutputs; --i >=0;)
|
||||||
{
|
{
|
||||||
if (!kCvOutputs[i])
|
// if (!kCvOutputs[i])
|
||||||
module->outputs[i].channels = 1;
|
module->outputs[i].channels = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,12 +130,6 @@ struct PluginLv2 {
|
||||||
ports[port] = dataLocation;
|
ports[port] = dataLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lv2_activate()
|
|
||||||
{
|
|
||||||
contextSet(&context);
|
|
||||||
module->onReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void lv2_run(const uint32_t sampleCount)
|
void lv2_run(const uint32_t sampleCount)
|
||||||
{
|
{
|
||||||
if (sampleCount == 0)
|
if (sampleCount == 0)
|
||||||
|
@ -171,6 +165,9 @@ struct PluginLv2 {
|
||||||
++args.frame;
|
++args.frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i=numLights; --i >=0;)
|
||||||
|
*static_cast<float*>(ports[numInputs+numOutputs+numParams+i]) = module->lights[i].getBrightness();
|
||||||
|
|
||||||
frameCount += sampleCount;
|
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);
|
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)
|
static void lv2_run(LV2_Handle instance, uint32_t sampleCount)
|
||||||
{
|
{
|
||||||
instancePtr->lv2_run(sampleCount);
|
instancePtr->lv2_run(sampleCount);
|
||||||
|
@ -219,7 +211,7 @@ static const LV2_Descriptor sLv2Descriptor = {
|
||||||
"urn:cardinal:" SLUG,
|
"urn:cardinal:" SLUG,
|
||||||
lv2_instantiate,
|
lv2_instantiate,
|
||||||
lv2_connect_port,
|
lv2_connect_port,
|
||||||
lv2_activate,
|
NULL, // activate
|
||||||
lv2_run,
|
lv2_run,
|
||||||
NULL, // deactivate
|
NULL, // deactivate
|
||||||
lv2_cleanup,
|
lv2_cleanup,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5ad6f48a006beedda1465208aab8f9296d39c48a
|
Subproject commit 224c46f5f1ee2a4137e31054da6edc87b9d6f47d
|
Loading…
Add table
Add a link
Reference in a new issue