Browse Source

Support lv2 parameters that are both readable and writable

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.3.0-RC1
falkTX 4 years ago
parent
commit
d4fe70694d
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 98 additions and 78 deletions
  1. +59
    -55
      source/backend/plugin/CarlaPluginLV2.cpp
  2. +6
    -6
      source/bridges-ui/CarlaBridgeFormatLV2.cpp
  3. +14
    -10
      source/includes/lv2_rdf.hpp
  4. +19
    -7
      source/utils/CarlaLv2Utils.hpp

+ 59
- 55
source/backend/plugin/CarlaPluginLV2.cpp View File

@@ -1473,19 +1473,19 @@ public:

switch (fRdfDescriptor->Parameters[rparamId].Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_TYPE_BOOL:
lv2_atom_forge_bool(&atomForge, fixedValue > 0.5f);
break;
case LV2_PARAMETER_INT:
case LV2_PARAMETER_TYPE_INT:
lv2_atom_forge_int(&atomForge, static_cast<int32_t>(fixedValue + 0.5f));
break;
case LV2_PARAMETER_LONG:
case LV2_PARAMETER_TYPE_LONG:
lv2_atom_forge_long(&atomForge, static_cast<int64_t>(fixedValue + 0.5f));
break;
case LV2_PARAMETER_FLOAT:
case LV2_PARAMETER_TYPE_FLOAT:
lv2_atom_forge_float(&atomForge, fixedValue);
break;
case LV2_PARAMETER_DOUBLE:
case LV2_PARAMETER_TYPE_DOUBLE:
lv2_atom_forge_double(&atomForge, fixedValue);
break;
default:
@@ -1548,11 +1548,11 @@ public:

switch (rdfParam.Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_INT:
// case LV2_PARAMETER_LONG:
case LV2_PARAMETER_FLOAT:
case LV2_PARAMETER_DOUBLE:
case LV2_PARAMETER_TYPE_BOOL:
case LV2_PARAMETER_TYPE_INT:
// case LV2_PARAMETER_TYPE_LONG:
case LV2_PARAMETER_TYPE_FLOAT:
case LV2_PARAMETER_TYPE_DOUBLE:
for (uint32_t j=0; j < pData->param.count; ++j)
{
if (pData->param.data[j].rindex == rindex)
@@ -1579,16 +1579,16 @@ public:

switch (rdfParam.Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_TYPE_BOOL:
rvalue = *(const int32_t*)valueptr != 0 ? 1.0f : 0.0f;
break;
case LV2_PARAMETER_INT:
case LV2_PARAMETER_TYPE_INT:
rvalue = static_cast<float>(*(const int32_t*)valueptr);
break;
case LV2_PARAMETER_FLOAT:
case LV2_PARAMETER_TYPE_FLOAT:
rvalue = *(const float*)valueptr;
break;
case LV2_PARAMETER_DOUBLE:
case LV2_PARAMETER_TYPE_DOUBLE:
rvalue = static_cast<float>(*(const double*)valueptr);
break;
default:
@@ -2239,13 +2239,13 @@ public:
aIns = aOuts = cvIns = cvOuts = params = 0;
LinkedList<uint> evIns, evOuts;

const uint32_t eventBufferSize(static_cast<uint32_t>(fLv2Options.sequenceSize)+0xff);
const uint32_t eventBufferSize = static_cast<uint32_t>(fLv2Options.sequenceSize) + 0xff;

bool forcedStereoIn, forcedStereoOut;
forcedStereoIn = forcedStereoOut = false;

bool needsCtrlIn, needsCtrlOut;
needsCtrlIn = needsCtrlOut = false;
bool needsCtrlIn, needsCtrlOut, hasPatchParameterOutputs;
needsCtrlIn = needsCtrlOut = hasPatchParameterOutputs = false;

for (uint32_t i=0; i < portCount; ++i)
{
@@ -2294,14 +2294,14 @@ public:
{
switch (fRdfDescriptor->Parameters[i].Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_INT:
// case LV2_PARAMETER_LONG:
case LV2_PARAMETER_FLOAT:
case LV2_PARAMETER_DOUBLE:
case LV2_PARAMETER_TYPE_BOOL:
case LV2_PARAMETER_TYPE_INT:
// case LV2_PARAMETER_TYPE_LONG:
case LV2_PARAMETER_TYPE_FLOAT:
case LV2_PARAMETER_TYPE_DOUBLE:
params += 1;
break;
case LV2_PARAMETER_PATH:
case LV2_PARAMETER_TYPE_PATH:
if (fFilePathURI.isEmpty())
fFilePathURI = fRdfDescriptor->Parameters[i].URI;
break;
@@ -2982,11 +2982,11 @@ public:

switch (rdfParam.Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_INT:
// case LV2_PARAMETER_LONG:
case LV2_PARAMETER_FLOAT:
case LV2_PARAMETER_DOUBLE:
case LV2_PARAMETER_TYPE_BOOL:
case LV2_PARAMETER_TYPE_INT:
// case LV2_PARAMETER_TYPE_LONG:
case LV2_PARAMETER_TYPE_FLOAT:
case LV2_PARAMETER_TYPE_DOUBLE:
break;
default:
continue;
@@ -3039,15 +3039,15 @@ public:

switch (rdfParam.Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_TYPE_BOOL:
step = max - min;
stepSmall = step;
stepLarge = step;
pData->param.data[j].hints |= PARAMETER_IS_BOOLEAN;
break;

case LV2_PARAMETER_INT:
case LV2_PARAMETER_LONG:
case LV2_PARAMETER_TYPE_INT:
case LV2_PARAMETER_TYPE_LONG:
step = 1.0f;
stepSmall = 1.0f;
stepLarge = 10.0f;
@@ -3062,20 +3062,23 @@ public:
break;
}

if (rdfParam.Input)
if (rdfParam.Flags & LV2_PARAMETER_FLAG_INPUT)
{
pData->param.data[j].type = PARAMETER_INPUT;
pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
pData->param.data[j].hints |= PARAMETER_IS_NOT_SAVED;
needsCtrlIn = true;
if (rdfParam.Flags & LV2_PARAMETER_FLAG_OUTPUT)
hasPatchParameterOutputs = true;
}
else
else if (rdfParam.Flags & LV2_PARAMETER_FLAG_OUTPUT)
{
pData->param.data[j].type = PARAMETER_OUTPUT;
pData->param.data[j].hints |= PARAMETER_IS_ENABLED;
pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
needsCtrlOut = true;
hasPatchParameterOutputs = true;
}

pData->param.ranges[j].min = min;
@@ -3134,7 +3137,8 @@ public:
(fUI.type != UI::TYPE_NULL && fEventsIn.count > 0 && (fEventsIn.data[0].type & CARLA_EVENT_DATA_ATOM) != 0))
fAtomBufferEvIn.createBuffer(eventBufferSize);

if (fUI.type != UI::TYPE_NULL && fEventsOut.count > 0 && (fEventsOut.data[0].type & CARLA_EVENT_DATA_ATOM) != 0)
if (hasPatchParameterOutputs ||
(fUI.type != UI::TYPE_NULL && fEventsOut.count > 0 && (fEventsOut.data[0].type & CARLA_EVENT_DATA_ATOM) != 0))
{
fAtomBufferUiOut.createBuffer(std::min(eventBufferSize*32, 1638400U));
fAtomBufferUiOutTmpData = new uint8_t[fAtomBufferUiOut.getSize()];
@@ -4906,19 +4910,19 @@ public:

switch (fRdfDescriptor->Parameters[rindex].Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_TYPE_BOOL:
lv2_atom_forge_bool(&atomForge, value > 0.5f);
break;
case LV2_PARAMETER_INT:
case LV2_PARAMETER_TYPE_INT:
lv2_atom_forge_int(&atomForge, static_cast<int32_t>(value + 0.5f));
break;
case LV2_PARAMETER_LONG:
case LV2_PARAMETER_TYPE_LONG:
lv2_atom_forge_long(&atomForge, static_cast<int64_t>(value + 0.5f));
break;
case LV2_PARAMETER_FLOAT:
case LV2_PARAMETER_TYPE_FLOAT:
lv2_atom_forge_float(&atomForge, value);
break;
case LV2_PARAMETER_DOUBLE:
case LV2_PARAMETER_TYPE_DOUBLE:
lv2_atom_forge_double(&atomForge, value);
break;
default:
@@ -5482,11 +5486,11 @@ public:

switch (rdfParam.Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_INT:
// case LV2_PARAMETER_LONG:
case LV2_PARAMETER_FLOAT:
case LV2_PARAMETER_DOUBLE:
case LV2_PARAMETER_TYPE_BOOL:
case LV2_PARAMETER_TYPE_INT:
// case LV2_PARAMETER_TYPE_LONG:
case LV2_PARAMETER_TYPE_FLOAT:
case LV2_PARAMETER_TYPE_DOUBLE:
break;
default:
continue;
@@ -5524,11 +5528,11 @@ public:

switch (rdfParam.Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_INT:
// case LV2_PARAMETER_LONG:
case LV2_PARAMETER_FLOAT:
case LV2_PARAMETER_DOUBLE:
case LV2_PARAMETER_TYPE_BOOL:
case LV2_PARAMETER_TYPE_INT:
// case LV2_PARAMETER_TYPE_LONG:
case LV2_PARAMETER_TYPE_FLOAT:
case LV2_PARAMETER_TYPE_DOUBLE:
break;
default:
continue;
@@ -6023,7 +6027,7 @@ public:

for (uint32_t i=0; i < fRdfDescriptor->ParameterCount; ++i)
{
if (fRdfDescriptor->Parameters[i].Type != LV2_PARAMETER_PATH)
if (fRdfDescriptor->Parameters[i].Type != LV2_PARAMETER_TYPE_PATH)
continue;
if (std::strcmp(fRdfDescriptor->Parameters[i].URI, uri) != 0)
continue;
@@ -6219,8 +6223,8 @@ public:
switch (type)
{
case kUridAtomBool:
CARLA_SAFE_ASSERT_RETURN(size == sizeof(bool),);
paramValue = (*(const bool*)value) ? 1.0f : 0.0f;
CARLA_SAFE_ASSERT_RETURN(size == sizeof(int32_t),);
paramValue = *(const int32_t*)value != 0 ? 1.0f : 0.0f;
break;
case kUridAtomDouble:
CARLA_SAFE_ASSERT_RETURN(size == sizeof(double),);
@@ -6228,15 +6232,15 @@ public:
break;
case kUridAtomFloat:
CARLA_SAFE_ASSERT_RETURN(size == sizeof(float),);
paramValue = (*(const float*)value);
paramValue = *(const float*)value;
break;
case kUridAtomInt:
CARLA_SAFE_ASSERT_RETURN(size == sizeof(int32_t),);
paramValue = static_cast<float>((*(const int32_t*)value));
paramValue = static_cast<float>(*(const int32_t*)value);
break;
case kUridAtomLong:
CARLA_SAFE_ASSERT_RETURN(size == sizeof(int64_t),);
paramValue = static_cast<float>((*(const int64_t*)value));
paramValue = static_cast<float>(*(const int64_t*)value);
break;
default:
carla_stdout("CarlaPluginLV2::handleLilvSetPortValue(\"%s\", %p, %i, %i:\"%s\") - unknown type",


+ 6
- 6
source/bridges-ui/CarlaBridgeFormatLV2.cpp View File

@@ -680,19 +680,19 @@ public:

switch (fRdfDescriptor->Parameters[parameterId].Type)
{
case LV2_PARAMETER_BOOL:
case LV2_PARAMETER_TYPE_BOOL:
lv2_atom_forge_bool(&atomForge, value > 0.5f);
break;
case LV2_PARAMETER_INT:
case LV2_PARAMETER_TYPE_INT:
lv2_atom_forge_int(&atomForge, static_cast<int32_t>(value + 0.5f));
break;
case LV2_PARAMETER_LONG:
case LV2_PARAMETER_TYPE_LONG:
lv2_atom_forge_long(&atomForge, static_cast<int64_t>(value + 0.5f));
break;
case LV2_PARAMETER_FLOAT:
case LV2_PARAMETER_TYPE_FLOAT:
lv2_atom_forge_float(&atomForge, value);
break;
case LV2_PARAMETER_DOUBLE:
case LV2_PARAMETER_TYPE_DOUBLE:
lv2_atom_forge_double(&atomForge, value);
break;
default:
@@ -949,7 +949,7 @@ public:

for (uint32_t i=0; i < fRdfDescriptor->ParameterCount; ++i)
{
if (fRdfDescriptor->Parameters[i].Type != LV2_PARAMETER_PATH)
if (fRdfDescriptor->Parameters[i].Type != LV2_PARAMETER_TYPE_PATH)
continue;
if (std::strcmp(fRdfDescriptor->Parameters[i].URI, uri) != 0)
continue;


+ 14
- 10
source/includes/lv2_rdf.hpp View File

@@ -31,14 +31,18 @@ typedef const char* LV2_URI;
typedef uint32_t LV2_Property;
#define LV2UI_INVALID_PORT_INDEX ((uint32_t)-1)

// Parameter FLAGS
#define LV2_PARAMETER_FLAG_INPUT 0x1
#define LV2_PARAMETER_FLAG_OUTPUT 0x2

// Parameter Types
#define LV2_PARAMETER_BOOL 1
#define LV2_PARAMETER_INT 2
#define LV2_PARAMETER_LONG 3
#define LV2_PARAMETER_FLOAT 4
#define LV2_PARAMETER_DOUBLE 5
#define LV2_PARAMETER_PATH 6
#define LV2_PARAMETER_STRING 7
#define LV2_PARAMETER_TYPE_BOOL 1
#define LV2_PARAMETER_TYPE_INT 2
#define LV2_PARAMETER_TYPE_LONG 3
#define LV2_PARAMETER_TYPE_FLOAT 4
#define LV2_PARAMETER_TYPE_DOUBLE 5
#define LV2_PARAMETER_TYPE_PATH 6
#define LV2_PARAMETER_TYPE_STRING 7

// Port Midi Map Types
#define LV2_PORT_MIDI_MAP_CC 1
@@ -494,7 +498,7 @@ struct LV2_RDF_PortGroup {
struct LV2_RDF_Parameter {
LV2_URI URI;
LV2_Property Type;
bool Input;
LV2_Property Flags;
const char* Label;
const char* Comment;
const char* GroupURI;
@@ -506,7 +510,7 @@ struct LV2_RDF_Parameter {
LV2_RDF_Parameter() noexcept
: URI(nullptr),
Type(0),
Input(true),
Flags(0x0),
Label(nullptr),
Comment(nullptr),
GroupURI(nullptr),
@@ -542,7 +546,7 @@ struct LV2_RDF_Parameter {
{
URI = other.URI;
Type = other.Type;
Input = other.Input;
Flags = other.Flags;
Label = other.Label;
Comment = other.Comment;
GroupURI = other.GroupURI;


+ 19
- 7
source/utils/CarlaLv2Utils.hpp View File

@@ -250,6 +250,7 @@ public:

Lilv::Node lv2_name;
Lilv::Node lv2_symbol;
Lilv::Node patch_readable;
Lilv::Node patch_writable;
Lilv::Node pg_group;
Lilv::Node preset_preset;
@@ -385,6 +386,7 @@ public:

lv2_name (new_uri(LV2_CORE__name)),
lv2_symbol (new_uri(LV2_CORE__symbol)),
patch_readable (new_uri(LV2_PATCH__readable)),
patch_writable (new_uri(LV2_PATCH__writable)),
pg_group (new_uri(LV2_PORT_GROUPS__group)),
preset_preset (new_uri(LV2_PRESETS__Preset)),
@@ -2351,6 +2353,7 @@ const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool loadPresets)
// Set Plugin Parameters
{
std::map<std::string, LV2_RDF_Parameter> parameters;
Lilv::Nodes patchReadableNodes(lilvPlugin.get_value(lv2World.patch_readable));
Lilv::Nodes patchWritableNodes(lilvPlugin.get_value(lv2World.patch_writable));

if (const uint numParameters = patchWritableNodes.size())
@@ -2375,12 +2378,20 @@ const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool loadPresets)

lilv_node_free(typeNode);
}
else
{
continue;
}

CARLA_SAFE_ASSERT_CONTINUE(patchWritableNode.is_uri());

++numUsed;
LV2_RDF_Parameter rdfParam;
rdfParam.URI = carla_strdup(patchWritableNode.as_uri());
rdfParam.Flags = LV2_PARAMETER_FLAG_INPUT;

if (patchReadableNodes.contains(patchWritableNode))
rdfParam.Flags |= LV2_PARAMETER_FLAG_OUTPUT;

// ----------------------------------------------------------------------------------------------------
// Set Basics
@@ -2391,19 +2402,19 @@ const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool loadPresets)
const char* const rangeURI = lilv_node_as_string(rangeNode);

/**/ if (std::strcmp(rangeURI, LV2_ATOM__Bool) == 0)
rdfParam.Type = LV2_PARAMETER_BOOL;
rdfParam.Type = LV2_PARAMETER_TYPE_BOOL;
else if (std::strcmp(rangeURI, LV2_ATOM__Int) == 0)
rdfParam.Type = LV2_PARAMETER_INT;
rdfParam.Type = LV2_PARAMETER_TYPE_INT;
else if (std::strcmp(rangeURI, LV2_ATOM__Long) == 0)
rdfParam.Type = LV2_PARAMETER_LONG;
rdfParam.Type = LV2_PARAMETER_TYPE_LONG;
else if (std::strcmp(rangeURI, LV2_ATOM__Float) == 0)
rdfParam.Type = LV2_PARAMETER_FLOAT;
rdfParam.Type = LV2_PARAMETER_TYPE_FLOAT;
else if (std::strcmp(rangeURI, LV2_ATOM__Double) == 0)
rdfParam.Type = LV2_PARAMETER_DOUBLE;
rdfParam.Type = LV2_PARAMETER_TYPE_DOUBLE;
else if (std::strcmp(rangeURI, LV2_ATOM__Path) == 0)
rdfParam.Type = LV2_PARAMETER_PATH;
rdfParam.Type = LV2_PARAMETER_TYPE_PATH;
else if (std::strcmp(rangeURI, LV2_ATOM__String) == 0)
rdfParam.Type = LV2_PARAMETER_STRING;
rdfParam.Type = LV2_PARAMETER_TYPE_STRING;
else
carla_stderr("lv2_rdf_new(\"%s\") - got unknown parameter type '%s'", uri, rangeURI);

@@ -2578,6 +2589,7 @@ const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool loadPresets)
}
}

lilv_nodes_free(const_cast<LilvNodes*>(patchReadableNodes.me));
lilv_nodes_free(const_cast<LilvNodes*>(patchWritableNodes.me));
}



Loading…
Cancel
Save