Skip to content

Commit

Permalink
Implement LV2 ControlInputPort change request feature
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Oct 11, 2023
1 parent 3a7d78c commit 98e0a5d
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
37 changes: 37 additions & 0 deletions source/backend/plugin/CarlaPluginLV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ enum CarlaLv2Features {
kFeatureIdWorker,
kFeatureIdInlineDisplay,
kFeatureIdMidnam,
kFeatureIdCtrlInPortChangeReq,
kFeatureCountPlugin,
// UI features
kFeatureIdUiDataAccess = kFeatureCountPlugin,
Expand Down Expand Up @@ -835,6 +836,9 @@ class CarlaPluginLV2 : public CarlaPlugin,
if (fFeatures[kFeatureIdMidnam] != nullptr && fFeatures[kFeatureIdMidnam]->data != nullptr)
delete (LV2_Midnam*)fFeatures[kFeatureIdMidnam]->data;

if (fFeatures[kFeatureIdCtrlInPortChangeReq] != nullptr && fFeatures[kFeatureIdCtrlInPortChangeReq]->data != nullptr)
delete (LV2_ControlInputPort_Change_Request*)fFeatures[kFeatureIdCtrlInPortChangeReq]->data;

for (uint32_t i=0; i < kFeatureCountAll; ++i)
{
if (fFeatures[i] != nullptr)
Expand Down Expand Up @@ -6150,6 +6154,20 @@ class CarlaPluginLV2 : public CarlaPlugin,

// -------------------------------------------------------------------

LV2_ControlInputPort_Change_Status handleCtrlInPortChangeReq(const uint32_t index, const float value)
{
CARLA_SAFE_ASSERT_RETURN(index < fRdfDescriptor->PortCount, LV2_CONTROL_INPUT_PORT_CHANGE_ERR_INVALID_INDEX);
CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr, LV2_CONTROL_INPUT_PORT_CHANGE_ERR_UNKNOWN);

const float fixedValue = pData->param.getFixedValue(index, value);
fParamBuffers[index] = fixedValue;

CarlaPlugin::setParameterValueRT(index, fixedValue, 0, true);
return LV2_CONTROL_INPUT_PORT_CHANGE_SUCCESS;
}

// -------------------------------------------------------------------

void handleExternalUIClosed()
{
CARLA_SAFE_ASSERT_RETURN(fUI.type == UI::TYPE_EXTERNAL,);
Expand Down Expand Up @@ -6791,6 +6809,10 @@ class CarlaPluginLV2 : public CarlaPlugin,
midnam->handle = this;
midnam->update = carla_lv2_midnam_update;

LV2_ControlInputPort_Change_Request* const portChangeReq = new LV2_ControlInputPort_Change_Request;
portChangeReq->handle = this;
portChangeReq->request_change = carla_lv2_ctrl_in_port_change_req;

// ---------------------------------------------------------------
// initialize features (part 2)

Expand Down Expand Up @@ -6868,6 +6890,9 @@ class CarlaPluginLV2 : public CarlaPlugin,
fFeatures[kFeatureIdMidnam]->URI = LV2_MIDNAM__update;
fFeatures[kFeatureIdMidnam]->data = midnam;

fFeatures[kFeatureIdCtrlInPortChangeReq]->URI = LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_URI;
fFeatures[kFeatureIdCtrlInPortChangeReq]->data = portChangeReq;

// ---------------------------------------------------------------
// initialize features (part 3)

Expand Down Expand Up @@ -8176,6 +8201,18 @@ class CarlaPluginLV2 : public CarlaPlugin,
((CarlaPluginLV2*)handle)->handleMidnamUpdate();
}

// -------------------------------------------------------------------
// ControlInputPort change request Feature

static LV2_ControlInputPort_Change_Status carla_lv2_ctrl_in_port_change_req(
LV2_ControlInputPort_Change_Request_Handle handle, uint32_t index, float value)
{
CARLA_SAFE_ASSERT_RETURN(handle != nullptr, LV2_CONTROL_INPUT_PORT_CHANGE_ERR_UNKNOWN);
carla_stdout("carla_lv2_ctrl_in_port_change_req(%p, %u, %f)", handle, index, value);

return ((CarlaPluginLV2*)handle)->handleCtrlInPortChangeReq(index, value);
}

// -------------------------------------------------------------------
// External UI Feature

Expand Down
84 changes: 84 additions & 0 deletions source/includes/lv2/control-input-port-change-request.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
LV2 ControlInputPort change request extension
Copyright 2020 Filipe Coelho <falktx@falktx.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

/**
@file control-input-port-change-request.h
C header for the LV2 ControlInputPort change request extension <http://kx.studio/ns/lv2ext/control-input-port-change-request>.
*/

#ifndef LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_H
#define LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_H

#include "lv2.h"

#define LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_URI "http://kx.studio/ns/lv2ext/control-input-port-change-request"
#define LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_PREFIX LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_URI "#"

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif

/** A status code for LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_URI functions. */
typedef enum {
LV2_CONTROL_INPUT_PORT_CHANGE_SUCCESS = 0, /**< Completed successfully. */
LV2_CONTROL_INPUT_PORT_CHANGE_ERR_UNKNOWN = 1, /**< Unknown error. */
LV2_CONTROL_INPUT_PORT_CHANGE_ERR_INVALID_INDEX = 2 /**< Failed due to invalid port index. */
} LV2_ControlInputPort_Change_Status;

/**
* Opaque handle for LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_URI feature.
*/
typedef void* LV2_ControlInputPort_Change_Request_Handle;

/**
* On instantiation, host must supply LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_URI feature.
* LV2_Feature::data must be pointer to LV2_ControlInputPort_Change_Request.
*/
typedef struct _LV2_ControlInputPort_Change_Request {
/**
* Opaque host data.
*/
LV2_ControlInputPort_Change_Request_Handle handle;

/**
* request_change()
*
* Ask the host to change a plugin's control input port value.
* Parameter handle MUST be the 'handle' member of this struct.
* Parameter index is port index to change.
* Parameter value is the requested value to change the control port input to.
*
* Returns status of the request.
* The host may decline this request, if e.g. it is currently automating this port.
*
* The plugin MUST call this function during run().
*/
LV2_ControlInputPort_Change_Status (*request_change)(LV2_ControlInputPort_Change_Request_Handle handle,
uint32_t index,
float value);

} LV2_ControlInputPort_Change_Request;

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_H */
4 changes: 4 additions & 0 deletions source/utils/CarlaLv2Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
#include "lv2/lv2_programs.h"
#include "lv2/lv2_rtmempool.h"

#include "lv2/control-input-port-change-request.h"

#include "lilv/lilvmm.hpp"
#include "sratom/sratom.h"
#include "lilv/config/lilv_config.h"
Expand Down Expand Up @@ -3184,6 +3186,8 @@ bool is_lv2_feature_supported(const LV2_URI uri) noexcept
return true;
if (std::strcmp(uri, LV2_BUF_SIZE__powerOf2BlockLength) == 0)
return true;
if (std::strcmp(uri, LV2_CONTROL_INPUT_PORT_CHANGE_REQUEST_URI) == 0)
return true;
if (std::strcmp(uri, LV2_CORE__hardRTCapable) == 0)
return true;
if (std::strcmp(uri, LV2_CORE__inPlaceBroken) == 0)
Expand Down

0 comments on commit 98e0a5d

Please sign in to comment.