Browse Source

Optimize data saving for bridges; Keep last loaded state

tags/1.9.6
falkTX 10 years ago
parent
commit
9965e8275a
4 changed files with 36 additions and 12 deletions
  1. +2
    -2
      source/backend/CarlaPlugin.hpp
  2. +10
    -2
      source/backend/engine/CarlaEngine.cpp
  3. +4
    -2
      source/backend/plugin/CarlaPlugin.cpp
  4. +20
    -6
      source/backend/plugin/CarlaPluginBridge.cpp

+ 2
- 2
source/backend/CarlaPlugin.hpp View File

@@ -388,11 +388,11 @@ public:

/*!
* Get the plugin's save state.
* The plugin will automatically call prepareForSave() as needed.
* The plugin will automatically call prepareForSave() if requested.
*
* @see loadStateSave()
*/
const CarlaStateSave& getStateSave();
const CarlaStateSave& getStateSave(const bool callPrepareForSave = true);

/*!
* Get the plugin's save state.


+ 10
- 2
source/backend/engine/CarlaEngine.cpp View File

@@ -1519,6 +1519,15 @@ void CarlaEngine::setPluginPeaks(const uint pluginId, float const inPeaks[2], fl

void CarlaEngine::saveProjectInternal(juce::MemoryOutputStream& outStream) const
{
// send initial prepareForSave first, giving time for bridges to act
for (uint i=0; i < pData->curPluginCount; ++i)
{
CarlaPlugin* const plugin(pData->plugins[i].plugin);

if (plugin != nullptr && plugin->isEnabled())
plugin->prepareForSave();
}

outStream << "<?xml version='1.0' encoding='UTF-8'?>\n";
outStream << "<!DOCTYPE CARLA-PROJECT>\n";
outStream << "<CARLA-PROJECT VERSION='2.0'>\n";
@@ -1528,7 +1537,6 @@ void CarlaEngine::saveProjectInternal(juce::MemoryOutputStream& outStream) const

MemoryOutputStream outSettings(1024);


// save appropriate engine settings
outSettings << " <EngineSettings>\n";

@@ -1578,7 +1586,7 @@ void CarlaEngine::saveProjectInternal(juce::MemoryOutputStream& outStream) const
outPlugin << " <!-- " << xmlSafeString(strBuf, true) << " -->\n";

outPlugin << " <Plugin>\n";
outPlugin << plugin->getStateSave().toString();
outPlugin << plugin->getStateSave(false).toString();
outPlugin << " </Plugin>\n";
outStream << outPlugin;
}


+ 4
- 2
source/backend/plugin/CarlaPlugin.cpp View File

@@ -476,10 +476,12 @@ void CarlaPlugin::randomizeParameters() noexcept
}
}

const CarlaStateSave& CarlaPlugin::getStateSave()
const CarlaStateSave& CarlaPlugin::getStateSave(const bool callPrepareForSave)
{
if (callPrepareForSave)
prepareForSave();

pData->stateSave.clear();
prepareForSave();

const PluginType pluginType(getType());



+ 20
- 6
source/backend/plugin/CarlaPluginBridge.cpp View File

@@ -739,7 +739,7 @@ public:
fPluginType(ptype),
fInitiated(false),
fInitError(false),
fSaved(false),
fSaved(true),
fTimedOut(false),
fTimedError(false),
fLastPongCounter(-1),
@@ -841,10 +841,15 @@ public:
// -------------------------------------------------------------------
// Information (current data)

// TODO - missing getCustomData

std::size_t getChunkData(void** const dataPtr) noexcept override
{
CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS, 0);
CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0);

waitForSaved();

CARLA_SAFE_ASSERT_RETURN(fInfo.chunk.size() > 0, 0);

*dataPtr = fInfo.chunk.data();
@@ -910,7 +915,7 @@ public:
// -------------------------------------------------------------------
// Set data (state)

void prepareForSave() override
void prepareForSave() noexcept override
{
fSaved = false;

@@ -920,8 +925,14 @@ public:
fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientPrepareForSave);
fShmNonRtClientControl.commitWrite();
}
}

carla_stdout("CarlaPluginBridge::prepareForSave() - sent, now waiting...");
void waitForSaved()
{
if (fSaved)
return;

carla_stdout("CarlaPluginBridge::waitForSaved() - now waiting...");

for (int i=0; i < 300; ++i)
{
@@ -930,13 +941,12 @@ public:
carla_msleep(20);
pData->engine->callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
pData->engine->idle();
idle();
}

if (! fSaved)
carla_stderr("CarlaPluginBridge::prepareForSave() - Timeout while requesting save state");
carla_stderr("CarlaPluginBridge::waitForSaved() - Timeout while requesting save state");
else
carla_stdout("CarlaPluginBridge::prepareForSave() - success!");
carla_stdout("CarlaPluginBridge::waitForSaved() - success!");
}

// -------------------------------------------------------------------
@@ -1118,6 +1128,10 @@ public:
fShmNonRtClientControl.writeCustomData(filePath.toRawUTF8(), ulength);
fShmNonRtClientControl.commitWrite();
}

// save data internally as well
fInfo.chunk.resize(dataSize);
std::memcpy(fInfo.chunk.data(), data, dataSize);
}

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


Loading…
Cancel
Save