diff --git a/source/Makefile.mk b/source/Makefile.mk index a9e2bf4b7..8ed9a19c1 100644 --- a/source/Makefile.mk +++ b/source/Makefile.mk @@ -54,6 +54,7 @@ BUILD_CXX_FLAGS += -DVESTIGE_HEADER HAVE_JACK = $(shell pkg-config --exists jack && echo true) HAVE_OPENGL = $(shell pkg-config --exists gl && echo true) +HAVE_QT5 = $(shell pkg-config --atleast-version=5.0 QtCore && echo true) HAVE_AF_DEPS = $(shell pkg-config --exists libavcodec libavformat sndfile && echo true) HAVE_ZYN_DEPS = $(shell pkg-config --exists fftw3 mxml zlib && echo true) diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 20148aefb..cbd90867b 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -1033,6 +1033,10 @@ bool CarlaEngine::loadProject(const char* const filename) if (node.toElement().tagName() == "Plugin") { const SaveState& saveState = getSaveStateDictFromXML(node); + CARLA_ASSERT(saveState.type != nullptr); + + if (saveState.type == nullptr) + continue; const void* extraStuff = nullptr; diff --git a/source/backend/plugin/BridgePlugin.cpp b/source/backend/plugin/BridgePlugin.cpp index 2205db15a..671a9ec40 100644 --- a/source/backend/plugin/BridgePlugin.cpp +++ b/source/backend/plugin/BridgePlugin.cpp @@ -914,6 +914,26 @@ public: bool init(const char* const filename, const char* const name, const char* const label, const char* const bridgeBinary) { + // --------------------------------------------------------------- + // first checks + + if (kData->engine == nullptr) + { + return false; + } + + if (kData->client != nullptr) + { + kData->engine->setLastError("Plugin client is already registered"); + return false; + } + + if (filename == nullptr) + { + kData->engine->setLastError("null filename"); + return false; + } + m_filename = strdup(filename); if (name) diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index a66abe762..4101443b9 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -655,7 +655,7 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) QVector paramSymbols; - if (std::strcmp(saveState.type, "LADSPA") == 0 || std::strcmp(saveState.type, "LV2") == 0) + if (type() == PLUGIN_LADSPA || type() == PLUGIN_LV2) { for (uint32_t i=0; i < kData->param.count; i++) { @@ -680,7 +680,7 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) int32_t index = -1; - if (std::strcmp(saveState.type, "LADSPA") == 0) + if (type() == PLUGIN_LADSPA) { // Try to set by symbol, otherwise use index if (stateParameter->symbol != nullptr && *stateParameter->symbol != 0) @@ -699,7 +699,7 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) else index = stateParameter->index; } - else if (std::strcmp(saveState.type, "LV2") == 0) + else if (type() == PLUGIN_LV2) { // Symbol only if (stateParameter->symbol != nullptr && *stateParameter->symbol != 0) @@ -1178,6 +1178,13 @@ void CarlaPlugin::setCustomData(const char* const type, const char* const key, c CARLA_ASSERT(cData.key != nullptr); CARLA_ASSERT(cData.value != nullptr); + if (cData.type == nullptr) + return; + if (cData.key == nullptr) + return; + if (cData.value == nullptr) + return; + if (std::strcmp(cData.key, key) == 0) { if (cData.value != nullptr) @@ -1926,6 +1933,15 @@ CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) { carla_debug("CarlaPlugin::ScopedDisabler(%p)", plugin); CARLA_ASSERT(plugin != nullptr); + CARLA_ASSERT(plugin->kData != nullptr); + CARLA_ASSERT(plugin->kData->client != nullptr); + + if (plugin == nullptr) + return; + if (plugin->kData == nullptr) + return; + if (plugin->kData->client == nullptr) + return; plugin->kData->masterMutex.lock(); @@ -1939,6 +1955,16 @@ CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) CarlaPlugin::ScopedDisabler::~ScopedDisabler() { carla_debug("CarlaPlugin::~ScopedDisabler()"); + CARLA_ASSERT(kPlugin != nullptr); + CARLA_ASSERT(kPlugin->kData != nullptr); + CARLA_ASSERT(kPlugin->kData->client != nullptr); + + if (kPlugin == nullptr) + return; + if (kPlugin->kData == nullptr) + return; + if (kPlugin->kData->client == nullptr) + return; kPlugin->fEnabled = true; kPlugin->kData->client->activate(); @@ -1955,13 +1981,19 @@ CarlaPlugin::ScopedProcessLocker::ScopedProcessLocker(CarlaPlugin* const plugin, carla_debug("CarlaPlugin::ScopedProcessLocker(%p, %s)", plugin, bool2str(block)); CARLA_ASSERT(plugin != nullptr); - if (block) + if (plugin != nullptr && block) plugin->kData->singleMutex.lock(); } CarlaPlugin::ScopedProcessLocker::~ScopedProcessLocker() { carla_debug("CarlaPlugin::~ScopedProcessLocker()"); + CARLA_ASSERT(kPlugin != nullptr && kPlugin->kData != nullptr); + + if (kPlugin == nullptr) + return; + if (kPlugin->kData == nullptr) + return; if (kBlock) { @@ -2005,6 +2037,14 @@ void CarlaPluginGUI::idle() void CarlaPluginGUI::resizeLater(int width, int height) { + CARLA_ASSERT_INT(width > 0, width); + CARLA_ASSERT_INT(height > 0, height); + + if (width <= 0) + return; + if (height <= 0) + return; + fNextWidth = width; fNextHeight = height; } @@ -2047,6 +2087,9 @@ void CarlaPluginGUI::closeEvent(QCloseEvent* const event) carla_debug("CarlaPluginGUI::closeEvent(%p)", event); CARLA_ASSERT(event != nullptr); + if (event == nullptr) + return; + if (! event->spontaneous()) { event->ignore(); diff --git a/source/backend/plugin/DssiPlugin.cpp b/source/backend/plugin/DssiPlugin.cpp index 43796d1fc..a7bac7618 100644 --- a/source/backend/plugin/DssiPlugin.cpp +++ b/source/backend/plugin/DssiPlugin.cpp @@ -370,8 +370,18 @@ public: carla_debug("DssiPlugin::reload() - start"); CARLA_ASSERT(kData->engine != nullptr); CARLA_ASSERT(fDescriptor != nullptr); + CARLA_ASSERT(fDssiDescriptor != nullptr); CARLA_ASSERT(fHandle != nullptr); + if (kData->engine == nullptr) + return; + if (fDescriptor == nullptr) + return; + if (fDssiDescriptor == nullptr) + return; + if (fHandle == nullptr) + return; + const ProcessMode processMode(kData->engine->getProccessMode()); // Safely disable plugin for reload @@ -1065,8 +1075,9 @@ public: { if (processSingle(inBuffer, outBuffer, time - timeOffset, timeOffset, midiEventCount)) { - midiEventCount = 0; + startTime = 0; timeOffset = time; + midiEventCount = 0; if (kData->midiprog.current >= 0 && kData->midiprog.count > 0) nextBankId = kData->midiprog.data[kData->midiprog.current].bank; @@ -1434,6 +1445,24 @@ public: bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset, const unsigned long midiEventCount) { + CARLA_ASSERT(frames > 0); + + if (frames == 0) + return false; + + if (kData->audioIn.count > 0) + { + CARLA_ASSERT(inBuffer != nullptr); + if (inBuffer == nullptr) + return false; + } + if (kData->audioOut.count > 0) + { + CARLA_ASSERT(outBuffer != nullptr); + if (outBuffer == nullptr) + return false; + } + uint32_t i, k; // -------------------------------------------------------------------------------------------------------- @@ -1748,6 +1777,32 @@ public: CARLA_ASSERT(filename != nullptr); CARLA_ASSERT(label != nullptr); + // --------------------------------------------------------------- + // first checks + + if (kData->engine == nullptr) + { + return false; + } + + if (kData->client != nullptr) + { + kData->engine->setLastError("Plugin client is already registered"); + return false; + } + + if (filename == nullptr) + { + kData->engine->setLastError("null filename"); + return false; + } + + if (label == nullptr) + { + kData->engine->setLastError("null label"); + return false; + } + // --------------------------------------------------------------- // open DLL diff --git a/source/backend/plugin/FluidSynthPlugin.cpp b/source/backend/plugin/FluidSynthPlugin.cpp index 9ba7ce180..798d6421d 100644 --- a/source/backend/plugin/FluidSynthPlugin.cpp +++ b/source/backend/plugin/FluidSynthPlugin.cpp @@ -392,6 +392,11 @@ public: CARLA_ASSERT(kData->engine != nullptr); CARLA_ASSERT(fSynth != nullptr); + if (kData->engine == nullptr) + return; + if (fSynth == nullptr) + return; + const ProcessMode processMode(kData->engine->getProccessMode()); // Safely disable plugin for reload @@ -957,6 +962,7 @@ public: { if (processSingle(outBuffer, time - timeOffset, timeOffset)) { + startTime = 0; timeOffset = time; if (kData->midiprog.current >= 0 && kData->midiprog.count > 0 && kData->ctrlChannel >= 0 && kData->ctrlChannel < 16) @@ -1233,6 +1239,14 @@ public: bool processSingle(float** const outBuffer, const uint32_t frames, const uint32_t timeOffset) { + CARLA_ASSERT(outBuffer != nullptr); + CARLA_ASSERT(frames > 0); + + if (outBuffer == nullptr) + return false; + if (frames == 0) + return false; + uint32_t i, k; // -------------------------------------------------------------------------------------------------------- @@ -1373,6 +1387,38 @@ public: CARLA_ASSERT(filename != nullptr); CARLA_ASSERT(label != nullptr); + // --------------------------------------------------------------- + // first checks + + if (kData->engine == nullptr) + { + return false; + } + + if (kData->client != nullptr) + { + kData->engine->setLastError("Plugin client is already registered"); + return false; + } + + if (fSynth == nullptr) + { + kData->engine->setLastError("null synth"); + return false; + } + + if (filename == nullptr) + { + kData->engine->setLastError("null filename"); + return false; + } + + if (label == nullptr) + { + kData->engine->setLastError("null label"); + return false; + } + // --------------------------------------------------------------- // open soundfont diff --git a/source/backend/plugin/LadspaPlugin.cpp b/source/backend/plugin/LadspaPlugin.cpp index f081e9490..e8730d753 100644 --- a/source/backend/plugin/LadspaPlugin.cpp +++ b/source/backend/plugin/LadspaPlugin.cpp @@ -368,6 +368,13 @@ public: CARLA_ASSERT(fDescriptor != nullptr); CARLA_ASSERT(fHandle != nullptr); + if (kData->engine == nullptr) + return; + if (fDescriptor == nullptr) + return; + if (fHandle == nullptr) + return; + const ProcessMode processMode(kData->engine->getProccessMode()); // Safely disable plugin for reload @@ -1078,6 +1085,24 @@ public: bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset) { + CARLA_ASSERT(frames > 0); + + if (frames == 0) + return false; + + if (kData->audioIn.count > 0) + { + CARLA_ASSERT(inBuffer != nullptr); + if (inBuffer == nullptr) + return false; + } + if (kData->audioOut.count > 0) + { + CARLA_ASSERT(outBuffer != nullptr); + if (outBuffer == nullptr) + return false; + } + uint32_t i, k; // -------------------------------------------------------------------------------------------------------- @@ -1305,6 +1330,32 @@ public: CARLA_ASSERT(filename != nullptr); CARLA_ASSERT(label != nullptr); + // --------------------------------------------------------------- + // first checks + + if (kData->engine == nullptr) + { + return false; + } + + if (kData->client != nullptr) + { + kData->engine->setLastError("Plugin client is already registered"); + return false; + } + + if (filename == nullptr) + { + kData->engine->setLastError("null filename"); + return false; + } + + if (label == nullptr) + { + kData->engine->setLastError("null label"); + return false; + } + // --------------------------------------------------------------- // open DLL diff --git a/source/backend/plugin/LinuxSamplerPlugin.cpp b/source/backend/plugin/LinuxSamplerPlugin.cpp index d1724ee28..133ea8c51 100644 --- a/source/backend/plugin/LinuxSamplerPlugin.cpp +++ b/source/backend/plugin/LinuxSamplerPlugin.cpp @@ -301,6 +301,11 @@ public: CARLA_ASSERT(kData->engine != nullptr); CARLA_ASSERT(fInstrument != nullptr); + if (kData->engine == nullptr) + return; + if (fInstrument == nullptr) + return; + const ProcessMode processMode(kData->engine->getProccessMode()); // Safely disable plugin for reload @@ -544,6 +549,7 @@ public: { if (processSingle(outBuffer, time - timeOffset, timeOffset)) { + startTime = 0; timeOffset = time; if (kData->midiprog.current >= 0 && kData->midiprog.count > 0) @@ -803,6 +809,14 @@ public: bool processSingle(float** const outBuffer, const uint32_t frames, const uint32_t timeOffset) { + CARLA_ASSERT(outBuffer != nullptr); + CARLA_ASSERT(frames > 0); + + if (outBuffer == nullptr) + return false; + if (frames == 0) + return false; + uint32_t i, k; // -------------------------------------------------------------------------------------------------------- @@ -893,6 +907,32 @@ public: CARLA_ASSERT(filename != nullptr); CARLA_ASSERT(label != nullptr); + // --------------------------------------------------------------- + // first checks + + if (kData->engine == nullptr) + { + return false; + } + + if (kData->client != nullptr) + { + kData->engine->setLastError("Plugin client is already registered"); + return false; + } + + if (filename == nullptr) + { + kData->engine->setLastError("null filename"); + return false; + } + + if (label == nullptr) + { + kData->engine->setLastError("null label"); + return false; + } + // --------------------------------------------------------------- // Check if file exists { diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index 3e7d57578..da995b892 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -3937,6 +3937,26 @@ public: bool init(const char* const bundle, const char* const name, const char* const URI) { + // --------------------------------------------------------------- + // first checks + + if (kData->engine == nullptr) + { + return false; + } + + if (kData->client != nullptr) + { + kData->engine->setLastError("Plugin client is already registered"); + return false; + } + + if (filename == nullptr) + { + kData->engine->setLastError("null filename"); + return false; + } + // --------------------------------------------------------------- // get plugin from lv2_rdf (lilv) diff --git a/source/backend/plugin/NativePlugin.cpp b/source/backend/plugin/NativePlugin.cpp index 8bf7f3efa..0b8f59bd8 100644 --- a/source/backend/plugin/NativePlugin.cpp +++ b/source/backend/plugin/NativePlugin.cpp @@ -266,6 +266,9 @@ public: { CARLA_ASSERT(fDescriptor != nullptr); + if (fDescriptor == nullptr) + return 0x0; + unsigned int options = 0x0; if (fDescriptor->name != nullptr) @@ -619,6 +622,13 @@ public: CARLA_ASSERT(fDescriptor != nullptr); CARLA_ASSERT(fHandle != nullptr); + if (kData->engine == nullptr) + return; + if (fDescriptor == nullptr) + return; + if (fHandle == nullptr) + return; + const ProcessMode processMode(kData->engine->getProccessMode()); // Safely disable plugin for reload @@ -1237,14 +1247,15 @@ public: { if (processSingle(inBuffer, outBuffer, time - timeOffset, timeOffset)) { + startTime = 0; + timeOffset = time; + nextBankId = 0; + if (fMidiEventCount > 0) { //carla_zeroMem(fMidiEvents, sizeof(::MidiEvent)*fMidiEventCount); fMidiEventCount = 0; } - - nextBankId = 0; - timeOffset = time; } else startTime += timeOffset; @@ -1555,6 +1566,24 @@ public: bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset) { + CARLA_ASSERT(frames > 0); + + if (frames == 0) + return false; + + if (kData->audioIn.count > 0) + { + CARLA_ASSERT(inBuffer != nullptr); + if (inBuffer == nullptr) + return false; + } + if (kData->audioOut.count > 0) + { + CARLA_ASSERT(outBuffer != nullptr); + if (outBuffer == nullptr) + return false; + } + uint32_t i, k; // -------------------------------------------------------------------------------------------------------- @@ -1930,7 +1959,27 @@ public: { CARLA_ASSERT(kData->engine != nullptr); CARLA_ASSERT(kData->client == nullptr); - CARLA_ASSERT(label); + CARLA_ASSERT(label != nullptr); + + // --------------------------------------------------------------- + // first checks + + if (kData->engine == nullptr) + { + return false; + } + + if (kData->client != nullptr) + { + kData->engine->setLastError("Plugin client is already registered"); + return false; + } + + if (label == nullptr) + { + kData->engine->setLastError("null label"); + return false; + } // --------------------------------------------------------------- // get descriptor that matches label diff --git a/source/backend/plugin/VstPlugin.cpp b/source/backend/plugin/VstPlugin.cpp index 213085641..a6d72c81b 100644 --- a/source/backend/plugin/VstPlugin.cpp +++ b/source/backend/plugin/VstPlugin.cpp @@ -168,6 +168,9 @@ public: { CARLA_ASSERT(fEffect != nullptr); + if (fEffect == nullptr) + return 0x0; + unsigned int options = 0x0; options |= PLUGIN_OPTION_FIXED_BUFFER; @@ -286,7 +289,9 @@ public: CARLA_ASSERT(parameterId < kData->param.count); const float fixedValue = kData->param.fixValue(parameterId, value); - fEffect->setParameter(fEffect, parameterId, fixedValue); + + if (fEffect != nullptr) + fEffect->setParameter(fEffect, parameterId, fixedValue); CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback); } @@ -431,6 +436,11 @@ public: CARLA_ASSERT(kData->engine != nullptr); CARLA_ASSERT(fEffect != nullptr); + if (kData->engine == nullptr) + return; + if (fEffect == nullptr) + return; + const ProcessMode processMode(kData->engine->getProccessMode()); // Safely disable plugin for reload @@ -1085,13 +1095,14 @@ public: { if (processSingle(inBuffer, outBuffer, time - timeOffset, timeOffset)) { + startTime = 0; + timeOffset = time; + if (fMidiEventCount > 0) { //carla_zeroMem(fMidiEvents, sizeof(::MidiEvent)*fMidiEventCount); fMidiEventCount = 0; } - - timeOffset = time; } else startTime += timeOffset; @@ -1367,6 +1378,24 @@ public: bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset) { + CARLA_ASSERT(frames > 0); + + if (frames == 0) + return false; + + if (kData->audioIn.count > 0) + { + CARLA_ASSERT(inBuffer != nullptr); + if (inBuffer == nullptr) + return false; + } + if (kData->audioOut.count > 0) + { + CARLA_ASSERT(outBuffer != nullptr); + if (outBuffer == nullptr) + return false; + } + uint32_t i, k; // -------------------------------------------------------------------------------------------------------- @@ -2017,6 +2046,26 @@ public: CARLA_ASSERT(kData->client == nullptr); CARLA_ASSERT(filename != nullptr); + // --------------------------------------------------------------- + // first checks + + if (kData->engine == nullptr) + { + return false; + } + + if (kData->client != nullptr) + { + kData->engine->setLastError("Plugin client is already registered"); + return false; + } + + if (filename == nullptr) + { + kData->engine->setLastError("null filename"); + return false; + } + // --------------------------------------------------------------- // open DLL diff --git a/source/bridges/Makefile b/source/bridges/Makefile index 287c056d5..2133e08ff 100644 --- a/source/bridges/Makefile +++ b/source/bridges/Makefile @@ -30,16 +30,13 @@ LINK_FLAGS += $(shell pkg-config --libs liblo QtCore) # Plugin bridges BUILD_PLUGIN_FLAGS = $(BUILD_CXX_FLAGS) -BUILD_PLUGIN_FLAGS += -DBUILD_BRIDGE_PLUGIN -DBRIDGE_PLUGIN -DWANT_JACK +BUILD_PLUGIN_FLAGS += -DBUILD_BRIDGE_PLUGIN -DBRIDGE_PLUGIN +BUILD_PLUGIN_FLAGS += -DWANT_LADSPA -DWANT_DSSI -DWANT_LV2 -DWANT_VST -DWANT_JACK BUILD_PLUGIN_FLAGS += -I../backend/engine -I../backend/plugin -I../libs -BUILD_PLUGIN_FLAGS += $(shell pkg-config --cflags QtGui QtXml) +BUILD_PLUGIN_FLAGS += $(QT_UI_FLAGS) $(shell pkg-config --cflags QtXml) LINK_PLUGIN_FLAGS = $(LINK_FLAGS) -LINK_PLUGIN_FLAGS += $(shell pkg-config --libs QtGui QtXml) -lpthread - -ifeq ($(CARLA_PLUGIN_SUPPORT),true) -BUILD_PLUGIN_FLAGS += -DWANT_LADSPA -DWANT_DSSI -DWANT_LV2 -DWANT_VST -endif +LINK_PLUGIN_FLAGS += $(QT_UI_FLAGS) $(shell pkg-config --libs QtXml) -lpthread # -------------------------------------------------------------- # Plugin bridges (POSIX) @@ -65,11 +62,13 @@ NATIVE_LINK_FLAGS = $(POSIX_LINK_FLAGS) ifeq ($(HAVE_FLUIDSYNTH),true) NATIVE_BUILD_FLAGS += -DWANT_FLUIDSYNTH +NATIVE_BUILD_FLAGS += $(shell pkg-config --cflags fluidsynth) NATIVE_LINK_FLAGS += $(shell pkg-config --libs fluidsynth) endif ifeq ($(HAVE_LINUXSAMPLER),true) NATIVE_BUILD_FLAGS += -DWANT_LINUXSAMPLER +NATIVE_BUILD_FLAGS += $(shell pkg-config --cflags linuxsampler) NATIVE_LINK_FLAGS += $(shell pkg-config --libs linuxsampler) endif @@ -503,5 +502,6 @@ clean: rm -f $(OBJS_POSIX64) rm -f $(OBJS_WIN32) rm -f $(OBJS_WIN64) - rm -f carla-bridge-lv2-gtk2 carla-bridge-lv2-gtk3 carla-bridge-lv2-qt4 carla-bridge-lv2-qt5 carla-bridge-lv2-x11 carla-bridge-vst-x11 + rm -f carla-bridge-lv2-gtk2 carla-bridge-lv2-gtk3 carla-bridge-lv2-qt4 carla-bridge-lv2-qt5 carla-bridge-lv2-x11 + rm -f carla-bridge-vst-x11 rm -f carla-bridge-native carla-bridge-posix32 carla-bridge-posix64