diff --git a/distrho/DistrhoPlugin.hpp b/distrho/DistrhoPlugin.hpp index e0b7ccb1..741efe75 100644 --- a/distrho/DistrhoPlugin.hpp +++ b/distrho/DistrhoPlugin.hpp @@ -837,6 +837,18 @@ public: */ double getSampleRate() const noexcept; + /** + Get the absolute filename of the plugin binary. + Under certain systems or plugin formats the binary will be inside the plugin bundle. + */ + const char* getBinaryFilename() const noexcept; + + /** + Get the bundle path where the plugin resides. + Can return null if the plugin is not available in a bundle (if it is a single binary). + */ + const char* getBundlePath() const noexcept; + #if DISTRHO_PLUGIN_WANT_TIMEPOS /** Get the current host transport time position.@n diff --git a/distrho/DistrhoPluginUtils.hpp b/distrho/DistrhoPluginUtils.hpp index 47eb0e66..cb27effa 100644 --- a/distrho/DistrhoPluginUtils.hpp +++ b/distrho/DistrhoPluginUtils.hpp @@ -22,6 +22,19 @@ START_NAMESPACE_DISTRHO // ----------------------------------------------------------------------------------------------------------- +// misc functions + +/** + Get a string representation of the current plugin format we are building against.@n + This can be "JACK/Standalone", "LADSPA", "DSSI", "LV2", "VST2" or "VST3".@n + This string is purely informational and must not be used to tweak plugin behaviour. + + @note DO NOT CHANGE PLUGIN BEHAVIOUR BASED ON PLUGIN FORMAT. +*/ +const char* getPluginFormatName() noexcept; + +// ----------------------------------------------------------------------------------------------------------- +// Plugin helper classes /** Handy class to help keep audio buffer in sync with incoming MIDI events. diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp index 8dda7fae..95e1d832 100644 --- a/distrho/DistrhoUI.hpp +++ b/distrho/DistrhoUI.hpp @@ -131,6 +131,19 @@ public: */ double getSampleRate() const noexcept; + /** + Get the absolute filename of the UI binary.@n + Under certain systems or plugin formats the binary will be inside the plugin bundle.@n + Also, in some formats or setups, this file might not be the same as the DSP/plugin side (because of DSP/UI separation). + */ + const char* getBinaryFilename() const noexcept; + + /** + Get the bundle path where the UI resides.@n + Can return null if the UI is not available in a bundle (if it is a single binary). + */ + const char* getBundlePath() const noexcept; + /** editParameter. diff --git a/distrho/src/DistrhoPlugin.cpp b/distrho/src/DistrhoPlugin.cpp index 693c4913..cd504412 100644 --- a/distrho/src/DistrhoPlugin.cpp +++ b/distrho/src/DistrhoPlugin.cpp @@ -100,6 +100,16 @@ double Plugin::getSampleRate() const noexcept return pData->sampleRate; } +const char* Plugin::getBinaryFilename() const noexcept +{ + return pData->binaryFilename; +} + +const char* Plugin::getBundlePath() const noexcept +{ + return pData->bundlePath; +} + #if DISTRHO_PLUGIN_WANT_TIMEPOS const TimePosition& Plugin::getTimePosition() const noexcept { diff --git a/distrho/src/DistrhoPluginInternal.hpp b/distrho/src/DistrhoPluginInternal.hpp index 753d3e08..c6ebde30 100644 --- a/distrho/src/DistrhoPluginInternal.hpp +++ b/distrho/src/DistrhoPluginInternal.hpp @@ -122,6 +122,8 @@ struct Plugin::PrivateData { uint32_t bufferSize; double sampleRate; + char* binaryFilename; + char* bundlePath; bool canRequestParameterValueChanges; PrivateData() noexcept @@ -151,6 +153,8 @@ struct Plugin::PrivateData { requestParameterValueChangeCallbackFunc(nullptr), bufferSize(d_lastBufferSize), sampleRate(d_lastSampleRate), + binaryFilename(nullptr), + bundlePath(nullptr), canRequestParameterValueChanges(d_lastCanRequestParameterValueChanges) { DISTRHO_SAFE_ASSERT(bufferSize != 0); @@ -225,6 +229,18 @@ struct Plugin::PrivateData { stateDefValues = nullptr; } #endif + + if (binaryFilename != nullptr) + { + std::free(binaryFilename); + binaryFilename = nullptr; + } + + if (bundlePath != nullptr) + { + std::free(bundlePath); + bundlePath = nullptr; + } } #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp index 64802841..920a8725 100644 --- a/distrho/src/DistrhoUI.cpp +++ b/distrho/src/DistrhoUI.cpp @@ -217,6 +217,16 @@ double UI::getSampleRate() const noexcept return uiData->sampleRate; } +const char* UI::getBinaryFilename() const noexcept +{ + return uiData->binaryFilename; +} + +const char* UI::getBundlePath() const noexcept +{ + return uiData->bundlePath; +} + void UI::editParameter(uint32_t index, bool started) { uiData->editParamCallback(index + uiData->parameterOffset, started); diff --git a/distrho/src/DistrhoUIPrivateData.hpp b/distrho/src/DistrhoUIPrivateData.hpp index 1371b9d2..9e479a5c 100644 --- a/distrho/src/DistrhoUIPrivateData.hpp +++ b/distrho/src/DistrhoUIPrivateData.hpp @@ -308,6 +308,8 @@ struct UI::PrivateData { #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI && !defined(DGL_FILE_BROWSER_DISABLED) char* uiStateFileKeyRequest; #endif + char* binaryFilename; + char* bundlePath; // Callbacks void* callbacksPtr; @@ -331,6 +333,8 @@ struct UI::PrivateData { #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI && !defined(DGL_FILE_BROWSER_DISABLED) uiStateFileKeyRequest(nullptr), #endif + binaryFilename(nullptr), + bundlePath(nullptr), callbacksPtr(nullptr), editParamCallbackFunc(nullptr), setParamCallbackFunc(nullptr), @@ -370,6 +374,8 @@ struct UI::PrivateData { #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI && !defined(DGL_FILE_BROWSER_DISABLED) std::free(uiStateFileKeyRequest); #endif + std::free(binaryFilename); + std::free(bundlePath); } void editParamCallback(const uint32_t rindex, const bool started) diff --git a/distrho/src/DistrhoUtils.cpp b/distrho/src/DistrhoUtils.cpp new file mode 100644 index 00000000..d743fd51 --- /dev/null +++ b/distrho/src/DistrhoUtils.cpp @@ -0,0 +1,47 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2021 Filipe Coelho + * + * 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 + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +START_NAMESPACE_DISTRHO + +#ifdef DISTRHO_PLUGIN_TARGET_JACK +#endif + +// ----------------------------------------------------------------------- + +const char* getPluginFormatName() noexcept +{ +#if defined(DISTRHO_PLUGIN_TARGET_CARLA) + return "Carla"; +#elif defined(DISTRHO_PLUGIN_TARGET_JACK) + return "JACK/Standalone"; +#elif defined(DISTRHO_PLUGIN_TARGET_LADSPA) + return "LADSPA"; +#elif defined(DISTRHO_PLUGIN_TARGET_DSSI) + return "DSSI"; +#elif defined(DISTRHO_PLUGIN_TARGET_LV2) + return "LV2"; +#elif defined(DISTRHO_PLUGIN_TARGET_VST2) + return "VST2"; +#elif defined(DISTRHO_PLUGIN_TARGET_VST3) + return "VST3"; +#else + return "Unknown"; +#endif +} + +// ----------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO