Skip to content

Commit

Permalink
Cleanup extension/capabilities interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Oct 15, 2023
1 parent 91acf11 commit 782963a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/GainPlugin/GainPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GainPlugin::GainPlugin()
gainDBParameter = dynamic_cast<ModulatableFloatParameter *>(vts.getParameter(gainParamTag));

reaperPluginExtension =
static_cast<const reaper_plugin_info_t *>(extensionGet("cockos.reaper_extension"));
static_cast<const reaper_plugin_info_t *>(getExtension("cockos.reaper_extension"));
jassert(reaperPluginExtension != nullptr || !juce::PluginHostType{}.isReaper());

if (reaperPluginExtension != nullptr)
Expand Down
30 changes: 19 additions & 11 deletions include/clap-juce-extensions/clap-juce-extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
class ClapJuceWrapper;
struct JUCEParameterVariant;

namespace ClapAdapter
{
[[maybe_unused]] static const clap_plugin *clap_create_plugin(const struct clap_plugin_factory *,
const clap_host *, const char *);
}

/** Forward declarations for any JUCE classes we might need. */
namespace juce
{
Expand Down Expand Up @@ -49,11 +55,6 @@ struct clap_properties
// The processing and active clap state
std::atomic<bool> is_clap_active{false}, is_clap_processing{false};

std::function<const void *(const char *)> extensionGet = extensionGetStatic;

// Internal implementation detail.
static std::function<const void *(const char *)> extensionGetStatic;

// Internal implementation detail. Please disregard (and FIXME)
static bool building_clap;
};
Expand Down Expand Up @@ -276,12 +277,14 @@ struct clap_juce_audio_processor_capabilities
return nullptr;
}

// const void * getExtension(const char* name)
// {
// if (extensionGet)
// return extensionGet(name);
// return nullptr;
// }
const void *getExtension(const char *name)
{
if (clapHostStatic != nullptr)
return clapHostStatic->get_extension(clapHostStatic, name);
if (extensionGet)
return extensionGet(name);
return nullptr;
}

private:
friend class ::ClapJuceWrapper;
Expand All @@ -290,6 +293,11 @@ struct clap_juce_audio_processor_capabilities
std::function<void()> noteNamesChangedSignal = nullptr;
std::function<void()> remoteControlsChangedSignal = nullptr;
std::function<void(uint32_t)> suggestRemoteControlsPageSignal = nullptr;
std::function<const void *(const char *)> extensionGet = nullptr;

friend const clap_plugin *ClapAdapter::clap_create_plugin(const struct clap_plugin_factory *,
const clap_host *, const char *);
static const clap_host *clapHostStatic;
};

/*
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/clap-juce-extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace clap_juce_extensions
bool clap_properties::building_clap{false};
uint32_t clap_properties::clap_version_major{0}, clap_properties::clap_version_minor{0},
clap_properties::clap_version_revision{0};
std::function<const void *(const char *)> clap_properties::extensionGetStatic{nullptr};

clap_properties::clap_properties() : is_clap{building_clap} {}

const clap_host* clap_juce_audio_processor_capabilities::clapHostStatic{nullptr};
} // namespace clap_juce_extensions
11 changes: 3 additions & 8 deletions src/wrapper/clap-juce-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,7 @@ class ClapJuceWrapper : public clap::helpers::Plugin<
_host.remoteControlsSuggestPage(pageID);
});
};
}
if (processorAsClapProperties != nullptr)
{
processorAsClapProperties->extensionGet = [this](const char *name) {
processorAsClapExtensions->extensionGet = [this](const char *name) {
return _host.host()->get_extension(_host.host(), name);
};
}
Expand Down Expand Up @@ -2226,12 +2223,10 @@ static const clap_plugin *clap_create_plugin(const struct clap_plugin_factory *,
clap_juce_extensions::clap_properties::clap_version_major = CLAP_VERSION_MAJOR;
clap_juce_extensions::clap_properties::clap_version_minor = CLAP_VERSION_MINOR;
clap_juce_extensions::clap_properties::clap_version_revision = CLAP_VERSION_REVISION;
clap_juce_extensions::clap_properties::extensionGetStatic = [host](const char *name) {
return host->get_extension(host, name);
};
clap_juce_extensions::clap_juce_audio_processor_capabilities::clapHostStatic = host;
auto *const pluginInstance = ::createPluginFilter();
clap_juce_extensions::clap_properties::building_clap = false;
clap_juce_extensions::clap_properties::extensionGetStatic = nullptr;
clap_juce_extensions::clap_juce_audio_processor_capabilities::clapHostStatic = nullptr;
auto *wrapper = new ClapJuceWrapper(host, pluginInstance);
return wrapper->clapPlugin();
}
Expand Down

0 comments on commit 782963a

Please sign in to comment.