From 70dea828b9e02848f671cd9c153674da51edb5f7 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 4 Apr 2013 10:57:42 +0100 Subject: [PATCH] Misc fixing, needed for pizmidi plugs --- source/backend/plugin/CarlaPluginInternal.hpp | 4 +-- source/backend/plugin/VstPlugin.cpp | 36 +++++++++++++------ source/utils/CarlaString.hpp | 32 ++++++++--------- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/source/backend/plugin/CarlaPluginInternal.hpp b/source/backend/plugin/CarlaPluginInternal.hpp index 1e5eadcfb..4de6fc7a2 100644 --- a/source/backend/plugin/CarlaPluginInternal.hpp +++ b/source/backend/plugin/CarlaPluginInternal.hpp @@ -560,12 +560,12 @@ struct CarlaPluginProtectedData { if (client->isActive()) client->deactivate(); + clearBuffers(); + delete client; client = nullptr; } - clearBuffers(); - for (auto it = custom.begin(); it.valid(); it.next()) { CustomData& cData(*it); diff --git a/source/backend/plugin/VstPlugin.cpp b/source/backend/plugin/VstPlugin.cpp index b5e1a5702..870b6c8b9 100644 --- a/source/backend/plugin/VstPlugin.cpp +++ b/source/backend/plugin/VstPlugin.cpp @@ -1790,24 +1790,41 @@ protected: return 0; if (ptr == nullptr) return 0; -#if 0 - if (! isProcessing) + if (! fIsProcessing) { - carla_stderr2("VstPlugin::handleAudioMasterProcessEvents(%p) - received MIDI out events outside audio thread, ignoring", vstEvents); + carla_stderr2("audioMasterProcessEvents(%p) - received MIDI out events outside audio thread, ignoring", ptr); return 0; } - for (int32_t i=0; i < vstEvents->numEvents && events.numEvents < MAX_MIDI_EVENTS*2; ++i) + if (fMidiEventCount >= MAX_MIDI_EVENTS*2) + return 0; + + + { + const VstEvents* const vstEvents((const VstEvents*)ptr); + + for (int32_t i=0; i < vstEvents->numEvents && i < MAX_MIDI_EVENTS*2; ++i) { - if (! vstEvents->events[i]) + if (vstEvents->events[i] == nullptr) break; const VstMidiEvent* const vstMidiEvent = (const VstMidiEvent*)vstEvents->events[i]; - if (vstMidiEvent->type == kVstMidiType) - memcpy(&midiEvents[events.numEvents++], vstMidiEvent, sizeof(VstMidiEvent)); + if (vstMidiEvent->type != kVstMidiType) + continue; + + // reverse-find first free event, and put it there + for (uint32_t j=(MAX_MIDI_EVENTS*2)-1; j >= fMidiEventCount; --j) + { + if (fMidiEvents[j].type == 0) + { + std::memcpy(&fMidiEvents[j], vstMidiEvent, sizeof(VstMidiEvent)); + break; + } + } } -#endif + } + ret = 1; break; @@ -2210,13 +2227,12 @@ public: // set default options fOptions = 0x0; - fOptions |= PLUGIN_OPTION_FIXED_BUFFER; fOptions |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; if (fEffect->flags & effFlagsProgramChunks) fOptions |= PLUGIN_OPTION_USE_CHUNKS; - //if (mIns > 0) + if (vstPluginCanDo(fEffect, "receiveVstEvents") || vstPluginCanDo(fEffect, "receiveVstMidiEvent") || (fEffect->flags & effFlagsIsSynth) > 0 || (fHints & PLUGIN_WANTS_MIDI_INPUT)) { fOptions |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE; fOptions |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH; diff --git a/source/utils/CarlaString.hpp b/source/utils/CarlaString.hpp index bf2bab74b..79e38dba2 100644 --- a/source/utils/CarlaString.hpp +++ b/source/utils/CarlaString.hpp @@ -50,47 +50,43 @@ public: explicit CarlaString(const int value) { - const size_t strBufSize = static_cast(std::abs(value/10) + 3); - char strBuf[strBufSize]; - std::snprintf(strBuf, strBufSize, "%d", value); + char strBuf[0xff] = { '\0' }; + std::snprintf(strBuf, 0xff, "%d", value); _init(); - _dup(strBuf, strBufSize); + _dup(strBuf); } explicit CarlaString(const unsigned int value, const bool hexadecimal = false) { - const size_t strBufSize = value/10 + 2 + (hexadecimal ? 2 : 0); - char strBuf[strBufSize]; - std::snprintf(strBuf, strBufSize, hexadecimal ? "0x%x" : "%u", value); + char strBuf[0xff] = { '\0' }; + std::snprintf(strBuf, 0xff, hexadecimal ? "0x%x" : "%u", value); _init(); - _dup(strBuf, strBufSize); + _dup(strBuf); } explicit CarlaString(const long int value) { - const size_t strBufSize = static_cast(std::abs(value/10) + 3); - char strBuf[strBufSize]; - std::snprintf(strBuf, strBufSize, "%ld", value); + char strBuf[0xff] = { '\0' }; + std::snprintf(strBuf, 0xff, "%ld", value); _init(); - _dup(strBuf, strBufSize); + _dup(strBuf); } explicit CarlaString(const unsigned long int value, const bool hexadecimal = false) { - const size_t strBufSize = value/10 + 2 + (hexadecimal ? 2 : 0); - char strBuf[strBufSize]; - std::snprintf(strBuf, strBufSize, hexadecimal ? "0x%lx" : "%lu", value); + char strBuf[0xff] = { '\0' }; + std::snprintf(strBuf, 0xff, hexadecimal ? "0x%lx" : "%lu", value); _init(); - _dup(strBuf, strBufSize); + _dup(strBuf); } explicit CarlaString(const float value) { - char strBuf[0xff]; + char strBuf[0xff] = { '\0' }; std::snprintf(strBuf, 0xff, "%f", value); _init(); @@ -99,7 +95,7 @@ public: explicit CarlaString(const double value) { - char strBuf[0xff]; + char strBuf[0xff] = { '\0' }; std::snprintf(strBuf, 0xff, "%g", value); _init();