Browse Source

More DISTRHO work, fixup some LV2 stuff

tags/1.9.4
falkTX 11 years ago
parent
commit
1fa918b90a
5 changed files with 31 additions and 56 deletions
  1. +0
    -3
      source/modules/carla_native/nekobi/DistrhoPluginNekobi.hpp
  2. +0
    -1
      source/modules/carla_native/nekobi/DistrhoUINekobi.hpp
  3. +25
    -38
      source/modules/distrho/src/DistrhoPluginLV2.cpp
  4. +1
    -1
      source/modules/distrho/src/DistrhoPluginLV2export.cpp
  5. +5
    -13
      source/modules/distrho/src/DistrhoUILV2.cpp

+ 0
- 3
source/modules/carla_native/nekobi/DistrhoPluginNekobi.hpp View File

@@ -48,9 +48,6 @@ public:
DistrhoPluginNekobi(); DistrhoPluginNekobi();
~DistrhoPluginNekobi() override; ~DistrhoPluginNekobi() override;
void d_initStateKey(uint32_t, d_string&) override {}
void d_setState(const char*, const char*) override {}
protected: protected:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Information // Information


+ 0
- 1
source/modules/carla_native/nekobi/DistrhoUINekobi.hpp View File

@@ -65,7 +65,6 @@ protected:
// DSP Callbacks // DSP Callbacks


void d_parameterChanged(uint32_t index, float value) override; void d_parameterChanged(uint32_t index, float value) override;
void d_stateChanged(const char*, const char*) override {}


// ------------------------------------------------------------------- // -------------------------------------------------------------------
// UI Callbacks // UI Callbacks


+ 25
- 38
source/modules/distrho/src/DistrhoPluginLV2.cpp View File

@@ -369,57 +369,44 @@ public:
// ------------------------------------------------------------------- // -------------------------------------------------------------------


#if DISTRHO_PLUGIN_WANT_STATE #if DISTRHO_PLUGIN_WANT_STATE
LV2_State_Status lv2_save(LV2_State_Store_Function store, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* /*features*/)
LV2_State_Status lv2_save(const LV2_State_Store_Function store, const LV2_State_Handle handle, const uint32_t flags)
{ {
flags = LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE;
//flags = LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE;


for (auto it = fStateMap.begin(), end = fStateMap.end(); it != end; ++it) for (auto it = fStateMap.begin(), end = fStateMap.end(); it != end; ++it)
{ {
const d_string& key = it->first; const d_string& key = it->first;
const d_string& value = it->second; const d_string& value = it->second;


store(handle, fUridMap->map(fUridMap->handle, (const char*)key), (const char*)value, value.length(), fURIDs.atomString, flags);
store(handle, fUridMap->map(fUridMap->handle, (const char*)key), (const char*)value, value.length()+1, fURIDs.atomString, flags);
} }


return LV2_STATE_SUCCESS; return LV2_STATE_SUCCESS;
} }


LV2_State_Status lv2_restore(LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* /*features*/)
LV2_State_Status lv2_restore(const LV2_State_Retrieve_Function retrieve, const LV2_State_Handle handle)
{ {
size_t size = 0;
uint32_t type = 0;
size_t size = 0;
uint32_t type = 0;
uint32_t flags = LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE;


flags = LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE;

d_stderr2("lv2_restore called");

//for (uint32_t i=0, count=fPlugin.getStateCount(); i < count; ++i)
for (uint32_t i=0, count=fPlugin.getStateCount(); i < count; ++i)
{ {
//const d_string& key = fPlugin.getStateKey(i);
const d_string key("yKey1");
const d_string& key = fPlugin.getStateKey(i);


const void* data = retrieve(handle, fUridMap->map(fUridMap->handle, (const char*)key), &size, &type, &flags); const void* data = retrieve(handle, fUridMap->map(fUridMap->handle, (const char*)key), &size, &type, &flags);


if (size == 0 || data == nullptr)
{
d_stderr2("lv2_restore err 1");
return LV2_STATE_SUCCESS;//continue;
}
if (size == 0)
continue;
if (data == nullptr)
continue;
if (type != fURIDs.atomString) if (type != fURIDs.atomString)
{
d_stderr2("lv2_restore err 2");
return LV2_STATE_SUCCESS;//continue;
}
continue;


const char* const value((const char*)data); const char* const value((const char*)data);


if (std::strlen(value) != size) if (std::strlen(value) != size)
{
d_stderr2("lv2_restore err 3");
return LV2_STATE_SUCCESS;//continue;
}

d_stderr2("Got request of state restore, key: \"%s\", value: \"%s\"", (const char*)key, (const char*)value);
continue;


setState(key, value); setState(key, value);
} }
@@ -431,7 +418,7 @@ public:


LV2_Worker_Status lv2_work(const void* const data) LV2_Worker_Status lv2_work(const void* const data)
{ {
const char* const stateKey((const char*)data + 1);
const char* const stateKey((const char*)data);
const char* const stateValue(stateKey+std::strlen(stateKey)+1); const char* const stateValue(stateKey+std::strlen(stateKey)+1);


setState(stateKey, stateValue); setState(stateKey, stateValue);
@@ -496,16 +483,16 @@ private:
#if DISTRHO_PLUGIN_WANT_STATE #if DISTRHO_PLUGIN_WANT_STATE
StringMap fStateMap; StringMap fStateMap;


void setState(const char* const newKey, const char* const newValue)
void setState(const char* const key, const char* const newValue)
{ {
fPlugin.setState(newKey, newValue);
fPlugin.setState(key, newValue);


// check if key already exists // check if key already exists
for (auto it = fStateMap.begin(), end = fStateMap.end(); it != end; ++it) for (auto it = fStateMap.begin(), end = fStateMap.end(); it != end; ++it)
{ {
const d_string& key = it->first;
const d_string& d_key = it->first;


if (key == newKey)
if (d_key == key)
{ {
it->second = newValue; it->second = newValue;
return; return;
@@ -513,7 +500,7 @@ private:
} }


// add a new one then // add a new one then
d_string d_key(newKey);
d_string d_key(key);
fStateMap[d_key] = newValue; fStateMap[d_key] = newValue;
} }
#endif #endif
@@ -653,14 +640,14 @@ static void lv2_select_program(LV2_Handle instance, uint32_t bank, uint32_t prog
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


#if DISTRHO_PLUGIN_WANT_STATE #if DISTRHO_PLUGIN_WANT_STATE
static LV2_State_Status lv2_save(LV2_Handle instance, LV2_State_Store_Function store, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* features)
static LV2_State_Status lv2_save(LV2_Handle instance, LV2_State_Store_Function store, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const*)
{ {
return instancePtr->lv2_save(store, handle, flags, features);
return instancePtr->lv2_save(store, handle, flags);
} }


static LV2_State_Status lv2_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* features)
static LV2_State_Status lv2_restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t, const LV2_Feature* const*)
{ {
return instancePtr->lv2_restore(retrieve, handle, flags, features);
return instancePtr->lv2_restore(retrieve, handle);
} }


LV2_Worker_Status lv2_work(LV2_Handle instance, LV2_Worker_Respond_Function, LV2_Worker_Respond_Handle, uint32_t, const void* data) LV2_Worker_Status lv2_work(LV2_Handle instance, LV2_Worker_Respond_Function, LV2_Worker_Respond_Handle, uint32_t, const void* data)


+ 1
- 1
source/modules/distrho/src/DistrhoPluginLV2export.cpp View File

@@ -136,7 +136,7 @@ void lv2_generate_ttl(const char* const basename)
pluginString += "\n"; pluginString += "\n";


// extensionData // extensionData
pluginString += " lv2:extensionData <" LV2_OPTIONS__interface "> ";
pluginString += " lv2:extensionData <" LV2_STATE__interface "> ";
#if DISTRHO_PLUGIN_WANT_STATE #if DISTRHO_PLUGIN_WANT_STATE
pluginString += ",\n <" LV2_OPTIONS__interface "> "; pluginString += ",\n <" LV2_OPTIONS__interface "> ";
pluginString += ",\n <" LV2_WORKER__interface "> "; pluginString += ",\n <" LV2_WORKER__interface "> ";


+ 5
- 13
source/modules/distrho/src/DistrhoUILV2.cpp View File

@@ -111,21 +111,13 @@ protected:


// join key and value // join key and value
std::string tmpStr; std::string tmpStr;
tmpStr += key;
tmpStr += "\xff";
tmpStr += value;
tmpStr += std::string(key);
tmpStr += std::string("\0", 1);
tmpStr += std::string(value);


// get size
// get msg size
const size_t msgSize(tmpStr.size()+1); const size_t msgSize(tmpStr.size()+1);


// convert into char[]
char msg[msgSize];
std::memcpy(msg, tmpStr.c_str(), msgSize-1);

// set proper null chars
msg[std::strlen(key)] = '\0';
msg[msgSize] = '\0';

// reserve atom space // reserve atom space
const size_t atomSize(lv2_atom_pad_size(sizeof(LV2_Atom) + msgSize)); const size_t atomSize(lv2_atom_pad_size(sizeof(LV2_Atom) + msgSize));
char atomBuf[atomSize]; char atomBuf[atomSize];
@@ -137,7 +129,7 @@ protected:
atom->type = fUridMap->map(fUridMap->handle, "urn:distrho:keyValueState"); atom->type = fUridMap->map(fUridMap->handle, "urn:distrho:keyValueState");


// set atom data // set atom data
std::memcpy(atomBuf + sizeof(LV2_Atom), msg, msgSize);
std::memcpy(atomBuf + sizeof(LV2_Atom), tmpStr.data(), msgSize-1);


// send to DSP side // send to DSP side
fWriteFunction(fController, eventInPortIndex, atomSize, fUridMap->map(fUridMap->handle, LV2_ATOM__eventTransfer), atom); fWriteFunction(fController, eventInPortIndex, atomSize, fUridMap->map(fUridMap->handle, LV2_ATOM__eventTransfer), atom);


Loading…
Cancel
Save