Skip to content

Commit

Permalink
Implement full state for AU
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Feb 24, 2024
1 parent eaf4bab commit 3aa6958
Show file tree
Hide file tree
Showing 9 changed files with 675 additions and 298 deletions.
676 changes: 502 additions & 174 deletions distrho/src/DistrhoPluginAU.cpp

Large diffs are not rendered by default.

28 changes: 8 additions & 20 deletions distrho/src/DistrhoPluginCLAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ class ClapUI : public DGL_NAMESPACE::IdleCallback
// Set state
for (StringMap::const_iterator cit=fStateMap.begin(), cite=fStateMap.end(); cit != cite; ++cit)
{
const String& key = cit->first;
const String& value = cit->second;
const String& key(cit->first);
const String& value(cit->second);

// TODO skip DSP only states

Expand Down Expand Up @@ -1433,7 +1433,7 @@ class PluginCLAP : ClapEventQueue
// Update current state
for (StringMap::const_iterator cit=fStateMap.begin(), cite=fStateMap.end(); cit != cite; ++cit)
{
const String& key = cit->first;
const String& key(cit->first);
fStateMap[key] = fPlugin.getStateValue(key);
}
#endif
Expand All @@ -1457,8 +1457,8 @@ class PluginCLAP : ClapEventQueue

for (StringMap::const_iterator cit=fStateMap.begin(), cite=fStateMap.end(); cit != cite; ++cit)
{
const String& key = cit->first;
const String& value = cit->second;
const String& key(cit->first);
const String& value(cit->second);

// join key and value
String tmpStr;
Expand Down Expand Up @@ -1764,23 +1764,11 @@ class PluginCLAP : ClapEventQueue
{
fPlugin.setState(key, value);

// check if we want to save this key
if (! fPlugin.wantStateKey(key))
return;

// check if key already exists
for (StringMap::iterator it=fStateMap.begin(), ite=fStateMap.end(); it != ite; ++it)
if (fPlugin.wantStateKey(key))
{
const String& dkey(it->first);

if (dkey == key)
{
it->second = value;
return;
}
const String dkey(key);
fStateMap[dkey] = value;
}

d_stderr("Failed to find plugin state with key \"%s\"", key);
}
#endif

Expand Down
6 changes: 4 additions & 2 deletions distrho/src/DistrhoPluginInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ class PluginExporter
fPlugin->setParameterValue(index, value);
}

/*
bool getParameterIndexForSymbol(const char* const symbol, uint32_t& index)
{
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr, false);
Expand All @@ -771,6 +772,7 @@ class PluginExporter
return false;
}
*/

uint32_t getPortGroupCount() const noexcept
{
Expand Down Expand Up @@ -884,15 +886,15 @@ class PluginExporter
}
#endif

# if DISTRHO_PLUGIN_WANT_FULL_STATE
#if DISTRHO_PLUGIN_WANT_FULL_STATE
String getStateValue(const char* const key) const
{
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr, sFallbackString);
DISTRHO_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0', sFallbackString);

return fPlugin->getState(key);
}
# endif
#endif

void setState(const char* const key, const char* const value)
{
Expand Down
32 changes: 10 additions & 22 deletions distrho/src/DistrhoPluginLV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,38 +1353,26 @@ class PluginLv2

// save this key if necessary
if (fPlugin.wantStateKey(key))
updateInternalState(key, newValue, false);
{
const String dkey(key);
fStateMap[dkey] = newValue;
}
}

bool updateState(const char* const key, const char* const newValue)
{
fPlugin.setState(key, newValue);
return updateInternalState(key, newValue, true);
}

bool updateInternalState(const char* const key, const char* const newValue, const bool sendToUI)
{
// key must already exist
for (StringToStringMap::iterator it=fStateMap.begin(), ite=fStateMap.end(); it != ite; ++it)
for (uint32_t i=0, count=fPlugin.getStateCount(); i < count; ++i)
{
const String& dkey(it->first);

if (dkey == key)
if (fPlugin.getStateKey(i) == key)
{
it->second = newValue;
const String dkey(key);
fStateMap[dkey] = newValue;

if (sendToUI)
{
for (uint32_t i=0, count=fPlugin.getStateCount(); i < count; ++i)
{
if (fPlugin.getStateKey(i) == key)
{
if ((fPlugin.getStateHints(i) & kStateIsOnlyForDSP) == 0x0)
fNeededUiSends[i] = true;
break;
}
}
}
if ((fPlugin.getStateHints(i) & kStateIsOnlyForDSP) == 0x0)
fNeededUiSends[i] = true;

return true;
}
Expand Down
17 changes: 3 additions & 14 deletions distrho/src/DistrhoPluginVST2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,22 +1286,11 @@ class PluginVst : public ParameterAndNotesHelper
fPlugin.setState(key, value);

// check if we want to save this key
if (! fPlugin.wantStateKey(key))
return;

// check if key already exists
for (StringMap::iterator it=fStateMap.begin(), ite=fStateMap.end(); it != ite; ++it)
if (fPlugin.wantStateKey(key))
{
const String& dkey(it->first);

if (dkey == key)
{
it->second = value;
return;
}
const String dkey(key);
fStateMap[dkey] = value;
}

d_stderr("Failed to find plugin state with key \"%s\"", key);
}
#endif
};
Expand Down
28 changes: 8 additions & 20 deletions distrho/src/DistrhoPluginVST3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ class PluginVst3
// Update current state
for (StringMap::const_iterator cit=fStateMap.begin(), cite=fStateMap.end(); cit != cite; ++cit)
{
const String& key = cit->first;
const String& key(cit->first);
fStateMap[key] = fPlugin.getStateValue(key);
}
#endif
Expand All @@ -1204,8 +1204,8 @@ class PluginVst3

for (StringMap::const_iterator cit=fStateMap.begin(), cite=fStateMap.end(); cit != cite; ++cit)
{
const String& key = cit->first;
const String& value = cit->second;
const String& key(cit->first);
const String& value(cit->second);

// join key and value
String tmpStr;
Expand Down Expand Up @@ -2194,7 +2194,7 @@ class PluginVst3
// Update current state from plugin side
for (StringMap::const_iterator cit=fStateMap.begin(), cite=fStateMap.end(); cit != cite; ++cit)
{
const String& key = cit->first;
const String& key(cit->first);
fStateMap[key] = fPlugin.getStateValue(key);
}
#endif
Expand All @@ -2203,8 +2203,8 @@ class PluginVst3
// Set state
for (StringMap::const_iterator cit=fStateMap.begin(), cite=fStateMap.end(); cit != cite; ++cit)
{
const String& key = cit->first;
const String& value = cit->second;
const String& key(cit->first);
const String& value(cit->second);

sendStateSetToUI(key, value);
}
Expand Down Expand Up @@ -2399,20 +2399,8 @@ class PluginVst3
// save this key as needed
if (fPlugin.wantStateKey(key))
{
for (StringMap::iterator it=fStateMap.begin(), ite=fStateMap.end(); it != ite; ++it)
{
const String& dkey(it->first);

if (dkey == key)
{
it->second = value;
std::free(key16);
std::free(value16);
return V3_OK;
}
}

d_stderr("Failed to find plugin state with key \"%s\"", key);
const String dkey(key);
fStateMap[dkey] = value;
}

std::free(key16);
Expand Down
Loading

0 comments on commit 3aa6958

Please sign in to comment.