From f5815166356e85a5fe244f6024c2e401f04b10fa Mon Sep 17 00:00:00 2001 From: FergusL Date: Fri, 21 Jun 2024 07:53:52 +0200 Subject: [PATCH 1/4] [WIP] VST3: Fix incorrect MIDI input values for CC and Note On/Off (#453) * Add debug prints to MidiThrough example * Fix CC and Note On/Off calculation Given the current normalized input, mutliply by 127 would give wrong result for some input values, dividing by 0.0078125, which is 1.0/128, fixes this * Use std::round * Use DPF functions for rounding * Remove debug prints in MidiThrough example This reverts commit 82767715a16b715d44ceed3ccd97402696a0e8de. --- distrho/src/DistrhoPluginVST3.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp index a68b12d5..a9b99416 100644 --- a/distrho/src/DistrhoPluginVST3.cpp +++ b/distrho/src/DistrhoPluginVST3.cpp @@ -359,14 +359,14 @@ class PluginVst3 midiEvent.size = 3; midiEvent.data[0] = 0x90 | (eventStorage.noteOn.channel & 0xf); midiEvent.data[1] = eventStorage.noteOn.pitch; - midiEvent.data[2] = std::max(0, std::min(127, (int)(eventStorage.noteOn.velocity * 127))); + midiEvent.data[2] = std::max(0, std::min(127, d_roundToIntPositive(eventStorage.noteOn.velocity * 127))); midiEvent.data[3] = 0; break; case NoteOff: midiEvent.size = 3; midiEvent.data[0] = 0x80 | (eventStorage.noteOff.channel & 0xf); midiEvent.data[1] = eventStorage.noteOff.pitch; - midiEvent.data[2] = std::max(0, std::min(127, (int)(eventStorage.noteOff.velocity * 127))); + midiEvent.data[2] = std::max(0, std::min(127, d_roundToIntPositive(eventStorage.noteOff.velocity * 127))); midiEvent.data[3] = 0; break; /* TODO @@ -377,7 +377,7 @@ class PluginVst3 midiEvent.size = 3; midiEvent.data[0] = 0xA0 | (eventStorage.polyPressure.channel & 0xf); midiEvent.data[1] = eventStorage.polyPressure.pitch; - midiEvent.data[2] = std::max(0, std::min(127, (int)(eventStorage.polyPressure.pressure * 127))); + midiEvent.data[2] = std::max(0, std::min(127, d_roundToIntPositive(eventStorage.polyPressure.pressure * 127))); midiEvent.data[3] = 0; break; case CC_Normal: @@ -469,7 +469,7 @@ class PluginVst3 { case 128: eventStorage.type = CC_ChannelPressure; - eventStorage.midi[1] = std::max(0, std::min(127, (int)(normalized * 127))); + eventStorage.midi[1] = std::max(0, std::min(127, d_roundToIntPositive(normalized * 127))); eventStorage.midi[2] = 0; break; case 129: @@ -480,7 +480,7 @@ class PluginVst3 default: eventStorage.type = CC_Normal; eventStorage.midi[1] = cc; - eventStorage.midi[2] = std::max(0, std::min(127, (int)(normalized * 127))); + eventStorage.midi[2] = std::max(0, std::min(127, d_roundToIntPositive(normalized * 127))); break; } From bbdcbf14625497c391e883c74b8bbb2db16412dc Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 6 Sep 2025 11:12:29 +0200 Subject: [PATCH 2/4] Fix regression in pugl x11 initial position Signed-off-by: falkTX --- dgl/src/pugl-upstream | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dgl/src/pugl-upstream b/dgl/src/pugl-upstream index 93c3d70f..86185d8d 160000 --- a/dgl/src/pugl-upstream +++ b/dgl/src/pugl-upstream @@ -1 +1 @@ -Subproject commit 93c3d70fe15eba1ece029ca8b86eb0c953a40a6d +Subproject commit 86185d8d7b2c1ef0d72179af8e7a1930ecb16e4f From 33e750e4cf185af09be105187ccede3446bddc63 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 6 Sep 2025 11:37:10 +0200 Subject: [PATCH 3/4] Cleanup String class, fix some compiler warnings --- distrho/extra/String.hpp | 107 ++++++++++++-------------- distrho/src/DistrhoPluginVST2.cpp | 4 +- distrho/src/jackbridge/JackBridge.cpp | 3 + 3 files changed, 56 insertions(+), 58 deletions(-) diff --git a/distrho/extra/String.hpp b/distrho/extra/String.hpp index b7fda927..015ff49e 100644 --- a/distrho/extra/String.hpp +++ b/distrho/extra/String.hpp @@ -269,7 +269,7 @@ public: /* * Get length of the string. */ - std::size_t length() const noexcept + size_t length() const noexcept { return fBufferLen; } @@ -295,7 +295,7 @@ public: */ bool contains(const char c) const noexcept { - for (std::size_t i=0; i(ret); + return static_cast(ret); } if (found != nullptr) @@ -460,7 +460,7 @@ public: * Find the last occurrence of character 'c' in the string. * Returns "length()" if the character is not found. */ - std::size_t rfind(const char c, bool* const found = nullptr) const noexcept + size_t rfind(const char c, bool* const found = nullptr) const noexcept { if (fBufferLen == 0 || c == '\0') { @@ -469,7 +469,7 @@ public: return fBufferLen; } - for (std::size_t i=fBufferLen; i > 0; --i) + for (size_t i=fBufferLen; i > 0; --i) { if (fBuffer[i-1] == c) { @@ -488,7 +488,7 @@ public: * Find the last occurrence of string 'strBuf' in the string. * Returns "length()" if the string is not found. */ - std::size_t rfind(const char* const strBuf, bool* const found = nullptr) const noexcept + size_t rfind(const char* const strBuf, bool* const found = nullptr) const noexcept { if (found != nullptr) *found = false; @@ -496,12 +496,12 @@ public: if (fBufferLen == 0 || strBuf == nullptr || strBuf[0] == '\0') return fBufferLen; - const std::size_t strBufLen(std::strlen(strBuf)); + const size_t strBufLen(std::strlen(strBuf)); - std::size_t ret = fBufferLen; + size_t ret = fBufferLen; const char* tmpBuf = fBuffer; - for (std::size_t i=0; i < fBufferLen; ++i) + for (size_t i=0; i < fBufferLen; ++i) { if (std::strstr(tmpBuf+1, strBuf) == nullptr && std::strncmp(tmpBuf, strBuf, strBufLen) == 0) { @@ -532,7 +532,7 @@ public: { DISTRHO_SAFE_ASSERT_RETURN(before != '\0' /* && after != '\0' */, *this); - for (std::size_t i=0; i < fBufferLen; ++i) + for (size_t i=0; i < fBufferLen; ++i) { if (fBuffer[i] == before) fBuffer[i] = after; @@ -551,7 +551,7 @@ public: if (fBufferLen == 0) return *this; - for (std::size_t i=0; i < fBufferLen; ++i) + for (size_t i=0; i < fBufferLen; ++i) { if (fBuffer[i] == c) { @@ -567,7 +567,7 @@ public: /* * Truncate the string to size 'n'. */ - String& truncate(const std::size_t n) noexcept + String& truncate(const size_t n) noexcept { if (n >= fBufferLen) return *this; @@ -583,7 +583,7 @@ public: */ String& toBasic() noexcept { - for (std::size_t i=0; i < fBufferLen; ++i) + for (size_t i=0; i < fBufferLen; ++i) { if (fBuffer[i] >= '0' && fBuffer[i] <= '9') continue; @@ -607,7 +607,7 @@ public: { static constexpr const char kCharDiff = 'a' - 'A'; - for (std::size_t i=0; i < fBufferLen; ++i) + for (size_t i=0; i < fBufferLen; ++i) { if (fBuffer[i] >= 'A' && fBuffer[i] <= 'Z') fBuffer[i] = static_cast(fBuffer[i] + kCharDiff); @@ -623,7 +623,7 @@ public: { static constexpr const char kCharDiff = 'a' - 'A'; - for (std::size_t i=0; i < fBufferLen; ++i) + for (size_t i=0; i < fBufferLen; ++i) { if (fBuffer[i] >= 'a' && fBuffer[i] <= 'z') fBuffer[i] = static_cast(fBuffer[i] - kCharDiff); @@ -688,31 +688,28 @@ public: // base64 stuff, based on http://www.adp-gmbh.ch/cpp/common/base64.html // Copyright (C) 2004-2008 René Nyffenegger - static String asBase64(const void* const data, const std::size_t dataSize) + static String asBase64(const void* const data, const size_t dataSize) { static constexpr const char* const kBase64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; - #ifndef _MSC_VER - const std::size_t kTmpBufSize = std::min(d_nextPowerOf2(static_cast(dataSize/3)), 65536U); - #else - constexpr std::size_t kTmpBufSize = 65536U; - #endif + const size_t strBufSize = std::min(d_nextPowerOf2(static_cast(dataSize/3)), 65536U); + char* strBuf = static_cast(std::malloc(strBufSize)); + DISTRHO_SAFE_ASSERT_RETURN(strBuf != nullptr, String()); - const uchar* bytesToEncode((const uchar*)data); + strBuf[strBufSize] = '\0'; + size_t strBufIndex = 0; + + const uchar* bytesToEncode = static_cast(data); uint i=0, j=0; uint charArray3[3], charArray4[4]; - char strBuf[kTmpBufSize + 1]; - strBuf[kTmpBufSize] = '\0'; - std::size_t strBufIndex = 0; - String ret; - for (std::size_t s=0; s> 6); charArray4[3] = charArray3[2] & 0x3f; - for (i=0; i<4; ++i) + for (i = 0; i < 4; ++i) strBuf[strBufIndex++] = kBase64Chars[charArray4[i]]; - if (strBufIndex >= kTmpBufSize-7) + if (strBufIndex >= strBufSize - 7) { strBuf[strBufIndex] = '\0'; strBufIndex = 0; @@ -739,7 +736,7 @@ public: if (i != 0) { - for (j=i; j<3; ++j) + for (j = i; j < 3; ++j) charArray3[j] = '\0'; charArray4[0] = (charArray3[0] & 0xfc) >> 2; @@ -747,7 +744,7 @@ public: charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6); charArray4[3] = charArray3[2] & 0x3f; - for (j=0; j<4 && i<3 && j(std::malloc(newBufSize + 1)); DISTRHO_SAFE_ASSERT_RETURN(newBuf != nullptr, String()); @@ -1080,7 +1075,7 @@ public: private: char* fBuffer; // the actual string buffer - std::size_t fBufferLen; // string length + size_t fBufferLen; // string length bool fBufferAlloc; // wherever the buffer is allocated, not using _null() /* @@ -1101,7 +1096,7 @@ private: * - Allocates string only if 'strBuf' is not null and new string contents are different * - If 'strBuf' is null, 'size' must be 0 */ - void _dup(const char* const strBuf, const std::size_t size = 0) noexcept + void _dup(const char* const strBuf, const size_t size = 0) noexcept { if (strBuf != nullptr) { @@ -1158,9 +1153,9 @@ String operator+(const String& strBefore, const char* const strBufAfter) noexcep if (strBefore.isEmpty()) return String(strBufAfter); - const std::size_t strBeforeLen = strBefore.length(); - const std::size_t strBufAfterLen = std::strlen(strBufAfter); - const std::size_t newBufSize = strBeforeLen + strBufAfterLen; + const size_t strBeforeLen = strBefore.length(); + const size_t strBufAfterLen = std::strlen(strBufAfter); + const size_t newBufSize = strBeforeLen + strBufAfterLen; char* const newBuf = static_cast(malloc(newBufSize + 1)); DISTRHO_SAFE_ASSERT_RETURN(newBuf != nullptr, String()); @@ -1178,9 +1173,9 @@ String operator+(const char* const strBufBefore, const String& strAfter) noexcep if (strBufBefore == nullptr || strBufBefore[0] == '\0') return strAfter; - const std::size_t strBufBeforeLen = std::strlen(strBufBefore); - const std::size_t strAfterLen = strAfter.length(); - const std::size_t newBufSize = strBufBeforeLen + strAfterLen; + const size_t strBufBeforeLen = std::strlen(strBufBefore); + const size_t strAfterLen = strAfter.length(); + const size_t newBufSize = strBufBeforeLen + strAfterLen; char* const newBuf = static_cast(malloc(newBufSize + 1)); DISTRHO_SAFE_ASSERT_RETURN(newBuf != nullptr, String()); diff --git a/distrho/src/DistrhoPluginVST2.cpp b/distrho/src/DistrhoPluginVST2.cpp index 686341a8..a45f927b 100644 --- a/distrho/src/DistrhoPluginVST2.cpp +++ b/distrho/src/DistrhoPluginVST2.cpp @@ -398,8 +398,8 @@ public: { parameterValues = new float[parameterCount]; - for (uint32_t i=0; i < parameterCount; ++i) - parameterValues[i] = NAN; + for (uint32_t i = 0; i < parameterCount; ++i) + parameterValues[i] = fPlugin.getParameterDefault(i); } #if DISTRHO_PLUGIN_WANT_MIDI_INPUT diff --git a/distrho/src/jackbridge/JackBridge.cpp b/distrho/src/jackbridge/JackBridge.cpp index 7c5633d0..c4c44b54 100644 --- a/distrho/src/jackbridge/JackBridge.cpp +++ b/distrho/src/jackbridge/JackBridge.cpp @@ -68,6 +68,9 @@ typedef void* lib_t; # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdeprecated-declarations" # pragma clang diagnostic ignored "-Wunused-but-set-variable" +# if __clang_major__ >= 17 +# pragma clang diagnostic ignored "-Wvla-cxx-extension" +# endif # endif # include "RtAudioBridge.hpp" # ifdef RTAUDIO_API_TYPE From 536ab7d84b452602558ea106a4b2e1df75eaf591 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 6 Sep 2025 13:08:45 +0200 Subject: [PATCH 4/4] Update copyright year Signed-off-by: falkTX --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 652264ae..c8f3a8bc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (C) 2012-2024 Filipe Coelho +Copyright (C) 2012-2025 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