Browse Source

Add new carla_get_custom_data_value to API

tags/v1.9.11
falkTX 6 years ago
parent
commit
9253a2a90c
8 changed files with 93 additions and 16 deletions
  1. +10
    -1
      source/backend/CarlaHost.h
  2. +32
    -0
      source/backend/CarlaStandalone.cpp
  3. +25
    -1
      source/carla_backend.py
  4. +7
    -0
      source/carla_backend_qtweb.py
  5. +3
    -7
      source/carla_host.py
  6. +14
    -0
      source/rest/carla-host.cpp
  7. +1
    -0
      source/rest/rest-server.cpp
  8. +1
    -7
      source/widgets/racklistwidget.py

+ 10
- 1
source/backend/CarlaHost.h View File

@@ -612,13 +612,22 @@ CARLA_EXPORT const ParameterRanges* carla_get_parameter_ranges(uint pluginId, ui
CARLA_EXPORT const MidiProgramData* carla_get_midi_program_data(uint pluginId, uint32_t midiProgramId);

/*!
* Get a plugin's custom data.
* Get a plugin's custom data, using index.
* @param pluginId Plugin
* @param customDataId Custom data index
* @see carla_get_custom_data_count()
*/
CARLA_EXPORT const CustomData* carla_get_custom_data(uint pluginId, uint32_t customDataId);

/*!
* Get a plugin's custom data value, using type and key.
* @param pluginId Plugin
* @param type Custom data type
* @param key Custom data key
* @see carla_get_custom_data_count()
*/
CARLA_EXPORT const char* carla_get_custom_data_value(uint pluginId, const char* type, const char* key);

/*!
* Get a plugin's chunk data.
* @param pluginId Plugin


+ 32
- 0
source/backend/CarlaStandalone.cpp View File

@@ -1364,6 +1364,38 @@ const CustomData* carla_get_custom_data(uint pluginId, uint32_t customDataId)
return &retCustomData;
}

const char* carla_get_custom_data_value(uint pluginId, const char* type, const char* key)
{
CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0', gNullCharPtr);
CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', gNullCharPtr);
CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, gNullCharPtr);

CarlaPlugin* const plugin(gStandalone.engine->getPlugin(pluginId));
CARLA_SAFE_ASSERT_RETURN(plugin != nullptr, gNullCharPtr);

const uint32_t count = plugin->getCustomDataCount();
CARLA_SAFE_ASSERT_RETURN(count != 0, gNullCharPtr);

carla_debug("carla_get_custom_data_value(%i, %s, %s)", pluginId, type, key);

static CarlaString customDataValue;

for (uint32_t i=0; i<count; ++i)
{
const CustomData& pluginCustomData(plugin->getCustomData(i));

if (std::strcmp(pluginCustomData.type, type) != 0)
continue;
if (std::strcmp(pluginCustomData.key, key) != 0)
continue;

customDataValue = pluginCustomData.value;
return customDataValue.buffer();
}

return gNullCharPtr;
}

const char* carla_get_chunk_data(uint pluginId)
{
CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr, gNullCharPtr);


+ 25
- 1
source/carla_backend.py View File

@@ -1572,7 +1572,7 @@ class CarlaHostMeta(object):
def get_midi_program_data(self, pluginId, midiProgramId):
raise NotImplementedError

# Get a plugin's custom data.
# Get a plugin's custom data, using index.
# @param pluginId Plugin
# @param customDataId Custom data index
# @see carla_get_custom_data_count()
@@ -1580,6 +1580,15 @@ class CarlaHostMeta(object):
def get_custom_data(self, pluginId, customDataId):
raise NotImplementedError

# Get a plugin's custom data value, using type and key.
# @param pluginId Plugin
# @param type Custom data type
# @param key Custom data key
# @see carla_get_custom_data_count()
@abstractmethod
def get_custom_data_value(self, pluginId, type_, key):
raise NotImplementedError

# Get a plugin's chunk data.
# @param pluginId Plugin
# @see PLUGIN_OPTION_USE_CHUNKS
@@ -2029,6 +2038,9 @@ class CarlaHostNull(CarlaHostMeta):
def get_custom_data(self, pluginId, customDataId):
return PyCustomData

def get_custom_data_value(self, pluginId, type_, key):
return ""

def get_chunk_data(self, pluginId):
return ""

@@ -2311,6 +2323,9 @@ class CarlaHostDLL(CarlaHostMeta):
self.lib.carla_get_custom_data.argtypes = [c_uint, c_uint32]
self.lib.carla_get_custom_data.restype = POINTER(CustomData)

self.lib.carla_get_custom_data_value.argtypes = [c_uint, c_char_p, c_char_p]
self.lib.carla_get_custom_data_value.restype = c_char_p

self.lib.carla_get_chunk_data.argtypes = [c_uint]
self.lib.carla_get_chunk_data.restype = c_char_p

@@ -2588,6 +2603,9 @@ class CarlaHostDLL(CarlaHostMeta):
def get_custom_data(self, pluginId, customDataId):
return structToDict(self.lib.carla_get_custom_data(pluginId, customDataId).contents)

def get_custom_data_by_key(self, pluginId, type_, key):
return charPtrToString(self.lib.carla_get_custom_data_value(pluginId, type_.encode("utf-8"), key.encode("utf-8")))

def get_chunk_data(self, pluginId):
return charPtrToString(self.lib.carla_get_chunk_data(pluginId))

@@ -2931,6 +2949,12 @@ class CarlaHostPlugin(CarlaHostMeta):
def get_custom_data(self, pluginId, customDataId):
return self.fPluginsInfo[pluginId].customData[customDataId]

def get_custom_data_value(self, pluginId, type_, key):
for customData in self.fPluginsInfo[pluginId].customData:
if customData['type'] == type_ and customData['key'] == key:
return customData['value']
return ""

def get_chunk_data(self, pluginId):
return ""



+ 7
- 0
source/carla_backend_qtweb.py View File

@@ -339,6 +339,13 @@ class CarlaHostQtWeb(CarlaHostQtNull):
'customDataId': customDataId,
}).json()

def get_custom_data_value(self, pluginId, type_, key):
return requests.get("{}/get_custom_data_value".format(self.baseurl), params={
'pluginId': pluginId,
'type_': type_,
'key': key,
}).text

def get_chunk_data(self, pluginId):
return requests.get("{}/get_chunk_data".format(self.baseurl), params={
'pluginId': pluginId,


+ 3
- 7
source/carla_host.py View File

@@ -1948,14 +1948,10 @@ class HostWindow(QMainWindow):
wasCompacted = pitem.isCompacted()
isCompacted = wasCompacted

for i in range(self.host.get_custom_data_count(pluginId)):
cdata = self.host.get_custom_data(pluginId, i)

if cdata['type'] == CUSTOM_DATA_TYPE_PROPERTY and cdata['key'] == "CarlaSkinIsCompacted":
isCompacted = bool(cdata['value'] == "true")
break
else:
check = self.host.get_custom_data_value(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaSkinIsCompacted")
if not check:
return
isCompacted = bool(check == "true")

if wasCompacted == isCompacted:
return


+ 14
- 0
source/rest/carla-host.cpp View File

@@ -697,6 +697,20 @@ void handle_carla_get_custom_data(const std::shared_ptr<Session> session)
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

void handle_carla_get_custom_data_value(const std::shared_ptr<Session> session)
{
const std::shared_ptr<const Request> request = session->get_request();

const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)

const std::string type = request->get_query_parameter("type");
const std::string key = request->get_query_parameter("key");

const char* const buf = carla_get_custom_data_value(pluginId, type.c_str(), key.c_str());
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

void handle_carla_get_chunk_data(const std::shared_ptr<Session> session)
{
const std::shared_ptr<const Request> request = session->get_request();


+ 1
- 0
source/rest/rest-server.cpp View File

@@ -175,6 +175,7 @@ int main(int, const char**)
make_resource(service, "/get_parameter_ranges", handle_carla_get_parameter_ranges);
make_resource(service, "/get_midi_program_data", handle_carla_get_midi_program_data);
make_resource(service, "/get_custom_data", handle_carla_get_custom_data);
make_resource(service, "/get_custom_data_value", handle_carla_get_custom_data_value);
make_resource(service, "/get_chunk_data", handle_carla_get_chunk_data);

make_resource(service, "/get_parameter_count", handle_carla_get_parameter_count);


+ 1
- 7
source/widgets/racklistwidget.py View File

@@ -63,16 +63,10 @@ class RackListItem(QListWidgetItem):
self.fWidget = None

self.fOptions = {
'compact': False,
'compact': bool(self.host.get_custom_data_value(pluginId, CUSTOM_DATA_TYPE_PROPERTY, "CarlaSkinIsCompacted") == "true"),
'useSkins': useSkins
}

for i in range(self.host.get_custom_data_count(pluginId)):
cdata = self.host.get_custom_data(pluginId, i)
if cdata['type'] == CUSTOM_DATA_TYPE_PROPERTY and cdata['key'] == "CarlaSkinIsCompacted":
self.fOptions['compact'] = bool(cdata['value'] == "true")
break

self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
#self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled|Qt.ItemIsDragEnabled)



Loading…
Cancel
Save