diff --git a/FEATURES.md b/FEATURES.md index 275d2e7e..83cbe0eb 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -27,6 +27,7 @@ If the limitation is within DPF, a link is provided to a description below on th | UI host-resize | Yes | No | Yes | Yes | No | Yes | Yes | No | UI host-resize | | UI remote control | No | No | Yes | Yes | No | Yes | No | Yes | UI remote control | | UI send midi note | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes | UI send midi note | +| Extra version info | N/A | N/A | N/A | Yes | No | Yes | N/A | N/A | Extra version info | For things that could be unclear: diff --git a/distrho/DistrhoDetails.hpp b/distrho/DistrhoDetails.hpp index f72608f7..cabf8705 100644 --- a/distrho/DistrhoDetails.hpp +++ b/distrho/DistrhoDetails.hpp @@ -1051,6 +1051,91 @@ struct TimePosition { } }; +/** + The build version number is not available. + */ +static constexpr const uint32_t kDistrhoNoBuildVersion = (uint32_t)-1; + +/** + Version information. + + @see DISTRHO_PLUGIN_WANT_EXTRA_VERSION + */ +struct VersionInfo { + /** + Major version number. + */ + uint32_t major; + + /** + Minor version number. + */ + uint32_t minor; + + /** + Micro version number. + */ + uint32_t micro; + + /** + Build version number. @n + + This should be set to kDistrhoNoBuildVersion if the build number is not available. + */ + uint32_t build; + + /** + Default constructor for a null version. + */ + VersionInfo() noexcept + : major(0), + minor(0), + micro(0), + build(kDistrhoNoBuildVersion) {} + + /** + Constructor using custom values. + */ + VersionInfo(uint32_t maj, uint32_t min, uint32_t mic, uint32_t bld = kDistrhoNoBuildVersion) noexcept + : major(maj), + minor(min), + micro(mic), + build(bld) {} + + /** + Constructor using uint32_t version number. + */ + VersionInfo(uint32_t ver) noexcept + : major((ver >> 16) & 0xFF), + minor((ver >> 8) & 0xFF), + micro((ver) & 0xFF), + build(kDistrhoNoBuildVersion) {} + + /** + Convert to uint32_t version number. + */ + uint32_t toUint32() const noexcept + { + uint32_t ver = 0; + if (major > 0xFFFF) + ver |= 0xFFFF0000; + else + ver |= (major << 16); + + if (minor > 0xFF) + ver |= 0xFF00; + else + ver |= (minor << 8); + + if (micro > 0xFF) + ver |= 0xFF; + else + ver |= micro; + + return ver; + } +}; + /** @} */ // -------------------------------------------------------------------------------------------------------------------- diff --git a/distrho/DistrhoInfo.hpp b/distrho/DistrhoInfo.hpp index 7df2003d..4fa9b932 100644 --- a/distrho/DistrhoInfo.hpp +++ b/distrho/DistrhoInfo.hpp @@ -547,6 +547,14 @@ START_NAMESPACE_DISTRHO */ #define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0 +/** + Enable extra version information. + + @see Plugin::getVersion() + @see VersionInfo + */ +#define DISTRHO_PLUGIN_WANT_EXTRA_VERSION 0 + /** Whether the plugin introduces latency during audio or midi processing. @see Plugin::setLatency(uint32_t) diff --git a/distrho/DistrhoPlugin.hpp b/distrho/DistrhoPlugin.hpp index 8570f9e9..f784163c 100644 --- a/distrho/DistrhoPlugin.hpp +++ b/distrho/DistrhoPlugin.hpp @@ -249,11 +249,19 @@ protected: virtual const char* getLicense() const = 0; #endif +#if DISTRHO_PLUGIN_WANT_EXTRA_VERSION + /** + Get the plugin version. + @see VersionInfo + */ + virtual VersionInfo getVersion() const = 0; +#else /** Get the plugin version, in hexadecimal. @see d_version() */ virtual uint32_t getVersion() const = 0; +#endif /** Get the plugin unique Id.@n diff --git a/distrho/DistrhoPluginInfo.h.template b/distrho/DistrhoPluginInfo.h.template index 127b627e..f4075179 100644 --- a/distrho/DistrhoPluginInfo.h.template +++ b/distrho/DistrhoPluginInfo.h.template @@ -75,6 +75,13 @@ */ // #define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0 +/** + Enable extra version information. + + @see VersionInfo + */ +// #define DISTRHO_PLUGIN_WANT_EXTRA_VERSION 0 + /** Whether the plugin introduces latency during audio or midi processing. @see Plugin::setLatency(uint32_t) diff --git a/distrho/src/DistrhoPluginChecks.h b/distrho/src/DistrhoPluginChecks.h index fb05181b..7253714f 100644 --- a/distrho/src/DistrhoPluginChecks.h +++ b/distrho/src/DistrhoPluginChecks.h @@ -61,6 +61,10 @@ # define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0 #endif +#ifndef DISTRHO_PLUGIN_WANT_EXTRA_VERSION +# define DISTRHO_PLUGIN_WANT_EXTRA_VERSION 0 +#endif + #ifndef DISTRHO_PLUGIN_WANT_LATENCY # define DISTRHO_PLUGIN_WANT_LATENCY 0 #endif diff --git a/distrho/src/DistrhoPluginInternal.hpp b/distrho/src/DistrhoPluginInternal.hpp index e42fe867..b6ec5176 100644 --- a/distrho/src/DistrhoPluginInternal.hpp +++ b/distrho/src/DistrhoPluginInternal.hpp @@ -525,12 +525,21 @@ public: return fPlugin->getLicense(); } +#if DISTRHO_PLUGIN_WANT_EXTRA_VERSION + VersionInfo getVersion() const noexcept + { + DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr, VersionInfo()); + + return fPlugin->getVersion(); + } +#else uint32_t getVersion() const noexcept { DISTRHO_SAFE_ASSERT_RETURN(fPlugin != nullptr, 0); return fPlugin->getVersion(); } +#endif long getUniqueId() const noexcept { diff --git a/distrho/src/DistrhoPluginLV2export.cpp b/distrho/src/DistrhoPluginLV2export.cpp index ba3cb196..b2c24f75 100644 --- a/distrho/src/DistrhoPluginLV2export.cpp +++ b/distrho/src/DistrhoPluginLV2export.cpp @@ -1176,11 +1176,19 @@ void lv2_generate_ttl(const char* const basename) } { + #if DISTRHO_PLUGIN_WANT_EXTRA_VERSION + const VersionInfo version(plugin.getVersion()); + + const uint32_t majorVersion = version.major; + /* */ uint32_t minorVersion = version.minor; + const uint32_t microVersion = version.micro; + #else const uint32_t version(plugin.getVersion()); const uint32_t majorVersion = (version & 0xFF0000) >> 16; /* */ uint32_t minorVersion = (version & 0x00FF00) >> 8; const uint32_t microVersion = (version & 0x0000FF) >> 0; + #endif // NOTE: LV2 ignores 'major' version and says 0 for minor is pre-release/unstable. if (majorVersion > 0) diff --git a/distrho/src/DistrhoPluginVST2.cpp b/distrho/src/DistrhoPluginVST2.cpp index 686341a8..43c9c51b 100644 --- a/distrho/src/DistrhoPluginVST2.cpp +++ b/distrho/src/DistrhoPluginVST2.cpp @@ -36,6 +36,10 @@ #include "xaymar-vst2/vst.h" +#if DISTRHO_PLUGIN_WANT_EXTRA_VERSION +# warning "VST2 does not support version number higher than 0xFF nor the build version" +#endif + START_NAMESPACE_DISTRHO // -------------------------------------------------------------------------------------------------------------------- @@ -1530,7 +1534,11 @@ static intptr_t VST_FUNCTION_INTERFACE vst_dispatcherCallback(vst_effect* const return 0; case VST_EFFECT_OPCODE_VENDOR_VERSION: + #if DISTRHO_PLUGIN_WANT_EXTRA_VERSION + return sPlugin->getVersion().toUint32(); + #else return sPlugin->getVersion(); + #endif case VST_EFFECT_OPCODE_VST_VERSION: return VST_VERSION_2_4_0_0; @@ -1651,7 +1659,11 @@ const vst_effect* VSTPluginMain(const vst_host_callback audioMaster) effect->magic_number = 0x56737450; #endif effect->unique_id = sPlugin->getUniqueId(); + #if DISTRHO_PLUGIN_WANT_EXTRA_VERSION + effect->version = sPlugin->getVersion().toUint32(); + #else effect->version = sPlugin->getVersion(); + #endif // VST doesn't support parameter outputs. we can fake them, but it is a hack. Disabled by default. #ifdef DPF_VST_SHOW_PARAMETER_OUTPUTS diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp index 3e8d2f1e..dc0688df 100644 --- a/distrho/src/DistrhoPluginVST3.cpp +++ b/distrho/src/DistrhoPluginVST3.cpp @@ -4590,13 +4590,30 @@ static const char* getPluginVersion() if (version.isEmpty()) { + char versionBuf[64]; + #if DISTRHO_PLUGIN_WANT_EXTRA_VERSION + const VersionInfo versionInfo = sPlugin->getVersion(); + + if (versionInfo.build != kDistrhoNoBuildVersion) { + std::snprintf(versionBuf, sizeof(versionBuf)-1, "%d.%d.%d.%d", + versionInfo.major, + versionInfo.minor, + versionInfo.micro, + versionInfo.build); + } else { + std::snprintf(versionBuf, sizeof(versionBuf)-1, "%d.%d.%d", + versionInfo.major, + versionInfo.minor, + versionInfo.micro); + } + #else const uint32_t versionNum = sPlugin->getVersion(); - char versionBuf[64]; std::snprintf(versionBuf, sizeof(versionBuf)-1, "%d.%d.%d", (versionNum >> 16) & 0xff, (versionNum >> 8) & 0xff, (versionNum >> 0) & 0xff); + #endif versionBuf[sizeof(versionBuf)-1] = '\0'; version = versionBuf; } diff --git a/dpf.doxygen b/dpf.doxygen index 01ae0f1d..7d7cd1de 100644 --- a/dpf.doxygen +++ b/dpf.doxygen @@ -255,6 +255,7 @@ PREDEFINED = DOXYGEN \ DISTRHO_PLUGIN_IS_RT_SAFE=1 \ DISTRHO_PLUGIN_IS_SYNTH=1 \ DISTRHO_PLUGIN_WANT_DIRECT_ACCESS=1 \ + DISTRHO_PLUGIN_WANT_EXTRA_VERSION=1 \ DISTRHO_PLUGIN_WANT_LATENCY=1 \ DISTRHO_PLUGIN_WANT_MIDI_INPUT=1 \ DISTRHO_PLUGIN_WANT_MIDI_OUTPUT=1 \