Skip to content

Commit

Permalink
Initial work for host-visible state
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Feb 1, 2022
1 parent e9f41ad commit 7e6e3cc
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 88 deletions.
37 changes: 32 additions & 5 deletions distrho/DistrhoPlugin.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2022 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
Expand Down Expand Up @@ -135,6 +135,29 @@ static const uint32_t kParameterIsTrigger = 0x20 | kParameterIsBoolean;

/** @} */

/* ------------------------------------------------------------------------------------------------------------
* State Hints */

/**
@defgroup StateHints State Hints
Various state hints.
@see Plugin::getStateHints
@{
*/

/**
State is available for the host to see and change.
*/
static const uint32_t kStateIsHostVisible = 0x01;

/**
State is a filename path.
*/
static const uint32_t kStateIsFilenamePath = 0x02 | kStateIsHostVisible;

/** @} */

/* ------------------------------------------------------------------------------------------------------------
* Base Plugin structs */

Expand Down Expand Up @@ -993,13 +1016,17 @@ class Plugin
Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
*/
virtual void initState(uint32_t index, String& stateKey, String& defaultStateValue);
#endif

#if DISTRHO_PLUGIN_WANT_STATEFILES
/**
TODO API under construction
TODO API under construction, should likely be put in a new State struct with key, name defValue and hints
Returns StateHints mask.
*/
virtual bool isStateFile(uint32_t index) = 0;
virtual uint32_t getStateHints(uint32_t index);
#endif

#if DISTRHO_PLUGIN_WANT_STATEFILES
DISTRHO_DEPRECATED_BY("getStateHints")
virtual bool isStateFile(uint32_t index) { return false; }
#endif

/* --------------------------------------------------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion distrho/src/DistrhoPlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2022 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
Expand Down Expand Up @@ -200,6 +200,16 @@ String Plugin::getState(const char*) const { return String(); }
#endif

#if DISTRHO_PLUGIN_WANT_STATE
uint32_t Plugin::getStateHints(const uint32_t index)
{
#if DISTRHO_PLUGIN_WANT_STATEFILES
if isStateFile(index)
return kStateIsFilenamePath;
#endif

return 0x0;
}

void Plugin::setState(const char*, const char*) {}
#endif

Expand Down
16 changes: 7 additions & 9 deletions distrho/src/DistrhoPluginInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,13 @@ class PluginExporter
return fData->stateCount;
}

uint32_t getStateHints(const uint32_t index) const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->stateCount, 0x0);

return fPlugin->getStateHints(index);
}

const String& getStateKey(const uint32_t index) const noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->stateCount, sFallbackString);
Expand All @@ -741,15 +748,6 @@ class PluginExporter
return fData->stateDefValues[index];
}

# if DISTRHO_PLUGIN_WANT_STATEFILES
bool isStateFile(const uint32_t index) const
{
DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr && index < fData->stateCount, false);

return fPlugin->isStateFile(index);
}
# endif

# if DISTRHO_PLUGIN_WANT_FULL_STATE
String getState(const char* key) const
{
Expand Down

0 comments on commit 7e6e3cc

Please sign in to comment.