diff --git a/source/backend/carla_backend.hpp b/source/backend/carla_backend.hpp index f5bfb9597..674cf0e10 100644 --- a/source/backend/carla_backend.hpp +++ b/source/backend/carla_backend.hpp @@ -546,7 +546,7 @@ enum ProcessMode { * * \see CallbackType and set_callback_function() */ -typedef void (*CallbackFunc)(void* ptr, CallbackType action, unsigned int pluginId, int value1, int value2, double value3, const char* valueStr); +typedef void (*CallbackFunc)(void* ptr, CallbackType action, unsigned int pluginId, int value1, int value2, float value3, const char* valueStr); /*! * Parameter data @@ -599,6 +599,15 @@ struct ParameterRanges { else if (value > max) value = max; } + + float fixValue(const float& value) const + { + if (value < min) + return min; + else if (value > max) + return max; + return value; + } }; /*! diff --git a/source/backend/carla_engine.hpp b/source/backend/carla_engine.hpp index 3d04abe05..66ad5b7f8 100644 --- a/source/backend/carla_engine.hpp +++ b/source/backend/carla_engine.hpp @@ -216,7 +216,6 @@ struct EngineEvent { */ struct EngineOptions { ProcessMode processMode; - bool processHighPrecision; bool forceStereo; bool preferPluginBridges; @@ -254,7 +253,6 @@ struct EngineOptions { EngineOptions() : processMode(PROCESS_MODE_CONTINUOUS_RACK), - processHighPrecision(false), forceStereo(false), preferPluginBridges(false), preferUiBridges(true), @@ -535,7 +533,7 @@ private: * Private data used in CarlaEngine. * No other than CarlaEngine must have direct access to this. */ -struct CarlaEngineProtectedData; +struct CarlaEnginePrivateData; /*! * Carla Engine. @@ -665,13 +663,13 @@ public: * Add new plugin.\n * Returns the id of the plugin, or -1 if the operation failed. */ - bool addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr); + bool addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr); /*! * Add new plugin, using native binary type.\n * Returns the id of the plugin, or -1 if the operation failed. */ - bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra = nullptr) + bool addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra = nullptr) { return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra); } @@ -733,6 +731,11 @@ public: return fOptions; } + ProcessMode getProccessMode() const + { + return fOptions.processMode; + } + /*! * Get current Time information (read-only). */ @@ -763,7 +766,7 @@ public: /*! * TODO. */ - void callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3, const char* const valueStr); + void callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const float value3, const char* const valueStr); /*! * TODO. @@ -846,8 +849,6 @@ protected: EngineOptions fOptions; EngineTimeInfo fTimeInfo; - ScopedPointer const fData; - #ifndef BUILD_BRIDGE // Rack mode data EngineEvent* getRackEventBuffer(const bool isInput); @@ -868,6 +869,11 @@ protected: void processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames); #endif + /*! + * TODO. + */ + void proccessPendingEvents(); + /*! * Report to all plugins about buffer size change. */ @@ -881,6 +887,8 @@ protected: void sampleRateChanged(const double newSampleRate); private: + ScopedPointer const fData; + #ifdef WANT_JACK static CarlaEngine* newJack(); #endif diff --git a/source/backend/carla_plugin.hpp b/source/backend/carla_plugin.hpp index df1475da4..995ea2ef9 100644 --- a/source/backend/carla_plugin.hpp +++ b/source/backend/carla_plugin.hpp @@ -94,7 +94,7 @@ public: * \param engine The engine which this plugin belongs to, must not be null * \param id The 'id' of this plugin, must be between 0 and CarlaEngine::maxPluginNumber() */ - CarlaPlugin(CarlaEngine* const engine, const int id); + CarlaPlugin(CarlaEngine* const engine, const unsigned int id); /*! * This is the destructor of the base plugin class. @@ -124,7 +124,7 @@ public: * * \see setId() */ - unsigned short id() const; + unsigned int id() const; /*! * Get the plugin's hints. @@ -291,12 +291,12 @@ public: /*! * Get the current parameter value of \a parameterId. */ - virtual double getParameterValue(const uint32_t parameterId); + virtual float getParameterValue(const uint32_t parameterId); /*! * Get the scalepoint \a scalePointId value of the parameter \a parameterId. */ - virtual double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId); + virtual float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId); /*! * Get the plugin's label (URI for PLUGIN_LV2). @@ -402,7 +402,7 @@ public: * \param sendOsc Send message change over OSC * \param sendCallback Send message change to registered callback */ - void setDryWet(double value, const bool sendOsc, const bool sendCallback); + void setDryWet(const float value, const bool sendOsc, const bool sendCallback); /*! * Set the plugin's output volume to \a value.\n @@ -411,7 +411,7 @@ public: * \param sendOsc Send message change over OSC * \param sendCallback Send message change to registered callback */ - void setVolume(double value, const bool sendOsc, const bool sendCallback); + void setVolume(const float value, const bool sendOsc, const bool sendCallback); /*! * Set the plugin's output left balance value to \a value.\n @@ -422,7 +422,7 @@ public: * * \note Pure-Stereo plugins only! */ - void setBalanceLeft(double value, const bool sendOsc, const bool sendCallback); + void setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback); /*! * Set the plugin's output right balance value to \a value.\n @@ -433,7 +433,7 @@ public: * * \note Pure-Stereo plugins only! */ - void setBalanceRight(double value, const bool sendOsc, const bool sendCallback); + void setBalanceRight(const float value, const bool sendOsc, const bool sendCallback); /*! * Set the plugin's output panning value to \a value.\n @@ -444,7 +444,7 @@ public: * * \note Force-Stereo plugins only! */ - void setPanning(double value, const bool sendOsc, const bool sendCallback); + void setPanning(const float value, const bool sendOsc, const bool sendCallback); #if 0 //ndef BUILD_BRIDGE /*! @@ -467,7 +467,7 @@ public: * * \see getParameterValue() */ - virtual void setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback); + virtual void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback); /*! * Set a plugin's parameter value, including internal parameters.\n @@ -480,7 +480,7 @@ public: * \see setBalanceLeft() * \see setBalanceRight() */ - void setParameterValueByRIndex(const int32_t rindex, const double value, const bool sendGui, const bool sendOsc, const bool sendCallback); + void setParameterValueByRIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback); /*! * Set parameter's \a parameterId MIDI channel to \a channel.\n @@ -529,7 +529,7 @@ public: * \param sendCallback Send message change to registered callback * \param block Block the audio callback */ - virtual void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block); + virtual void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block); /*! * Change the current MIDI plugin program to \a index. @@ -543,7 +543,7 @@ public: * \param sendCallback Send message change to registered callback * \param block Block the audio callback */ - virtual void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block); + virtual void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block); /*! * This is an overloaded call to setMidiProgram().\n @@ -641,6 +641,7 @@ public: /*! * Send a single midi note to be processed in the next audio callback.\n * A note with 0 velocity means note-off. + * \note Non-RT call */ void sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback); @@ -736,6 +737,7 @@ public: struct Initializer { CarlaEngine* const engine; + const unsigned int id; const char* const filename; const char* const name; const char* const label; diff --git a/source/backend/engine/carla_engine.cpp b/source/backend/engine/carla_engine.cpp index ba37b6664..4ad5c45f1 100644 --- a/source/backend/engine/carla_engine.cpp +++ b/source/backend/engine/carla_engine.cpp @@ -1,18 +1,18 @@ /* * Carla Engine - * Copyright (C) 2012 Filipe Coelho + * Copyright (C) 2012-2013 Filipe Coelho * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * For a full copy of the GNU General Public License see the COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #include "carla_engine_internal.hpp" @@ -40,16 +40,15 @@ CarlaEnginePort::~CarlaEnginePort() // Carla Engine Audio port CarlaEngineAudioPort::CarlaEngineAudioPort(const bool isInput, const ProcessMode processMode) - : CarlaEnginePort(isInput, processMode) + : CarlaEnginePort(isInput, processMode), + fBuffer(nullptr) { qDebug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode)); #ifndef BUILD_BRIDGE if (kProcessMode == PROCESS_MODE_PATCHBAY) fBuffer = new float[PATCHBAY_BUFFER_SIZE]; - else #endif - fBuffer = nullptr; } CarlaEngineAudioPort::~CarlaEngineAudioPort() @@ -62,7 +61,7 @@ CarlaEngineAudioPort::~CarlaEngineAudioPort() CARLA_ASSERT(fBuffer); if (fBuffer) - delete[] (float*)fBuffer; + delete[] fBuffer; } #endif } @@ -70,9 +69,7 @@ CarlaEngineAudioPort::~CarlaEngineAudioPort() void CarlaEngineAudioPort::initBuffer(CarlaEngine* const) { #ifndef BUILD_BRIDGE - if (kProcessMode != PROCESS_MODE_PATCHBAY) - fBuffer = nullptr; - else if (! kIsInput) + if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput) carla_zeroFloat(fBuffer, PATCHBAY_BUFFER_SIZE); #endif } @@ -82,16 +79,15 @@ void CarlaEngineAudioPort::initBuffer(CarlaEngine* const) CarlaEngineEventPort::CarlaEngineEventPort(const bool isInput, const ProcessMode processMode) : CarlaEnginePort(isInput, processMode), - kMaxEventCount(processMode == PROCESS_MODE_CONTINUOUS_RACK ? RACK_EVENT_COUNT : PATCHBAY_EVENT_COUNT) + kMaxEventCount(processMode == PROCESS_MODE_CONTINUOUS_RACK ? RACK_EVENT_COUNT : PATCHBAY_EVENT_COUNT), + fBuffer(nullptr) { qDebug("CarlaEngineEventPort::CarlaEngineEventPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode)); #ifndef BUILD_BRIDGE if (kProcessMode == PROCESS_MODE_PATCHBAY) fBuffer = new EngineEvent[PATCHBAY_EVENT_COUNT]; - else #endif - fBuffer = nullptr; } CarlaEngineEventPort::~CarlaEngineEventPort() @@ -235,14 +231,16 @@ void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t cha CARLA_ASSERT(fBuffer != nullptr); CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); - CARLA_ASSERT(data); + CARLA_ASSERT(data != nullptr); CARLA_ASSERT(size > 0); if (fBuffer == nullptr) return; if (channel >= MAX_MIDI_CHANNELS) return; - if (! (data && size > 0)) + if (data == nullptr) + return; + if (size == 0) return; #ifndef BUILD_BRIDGE @@ -282,13 +280,12 @@ void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t cha CarlaEngineClient::CarlaEngineClient(const EngineType engineType, const ProcessMode processMode) : kEngineType(engineType), - kProcessMode(processMode) + kProcessMode(processMode), + fActive(false), + fLatency(0) { qDebug("CarlaEngineClient::CarlaEngineClient(%s, %s)", EngineType2Str(engineType), ProcessMode2Str(processMode)); CARLA_ASSERT(engineType != kEngineTypeNull); - - fActive = false; - fLatency = 0; } CarlaEngineClient::~CarlaEngineClient() @@ -341,12 +338,11 @@ void CarlaEngineClient::setLatency(const uint32_t samples) // Carla Engine CarlaEngine::CarlaEngine() - : fData(new CarlaEngineProtectedData(this)) + : fBufferSize(0), + fSampleRate(0.0), + fData(new CarlaEnginePrivateData(this)) { qDebug("CarlaEngine::CarlaEngine()"); - - fBufferSize = 0; - fSampleRate = 0.0; } CarlaEngine::~CarlaEngine() @@ -356,6 +352,46 @@ CarlaEngine::~CarlaEngine() //data = nullptr; } +// ----------------------------------------------------------------------- +// Helpers + +void doPluginRemove(CarlaEnginePrivateData* const fData, const bool unlock) +{ + CARLA_ASSERT(fData->curPluginCount > 0); + fData->curPluginCount--; + + const unsigned int id = fData->nextAction.pluginId; + + // reset current plugin + fData->plugins[id].plugin = nullptr; + + CarlaPlugin* plugin; + + // move all plugins 1 spot backwards + for (unsigned int i=id; i < fData->curPluginCount; i++) + { + plugin = fData->plugins[i+1].plugin; + + CARLA_ASSERT(plugin); + + if (plugin == nullptr) + break; + + plugin->setId(i); + + fData->plugins[i].plugin = plugin; + fData->plugins[i].insPeak[0] = 0.0f; + fData->plugins[i].insPeak[1] = 0.0f; + fData->plugins[i].outsPeak[0] = 0.0f; + fData->plugins[i].outsPeak[1] = 0.0f; + } + + fData->nextAction.opcode = EnginePostActionNull; + + if (unlock) + fData->nextAction.mutex.unlock(); +} + // ----------------------------------------------------------------------- // Static values and calls @@ -364,12 +400,14 @@ unsigned int CarlaEngine::getDriverCount() qDebug("CarlaEngine::getDriverCount()"); unsigned int count = 0; + #ifdef WANT_JACK count += 1; #endif #ifdef WANT_RTAUDIO count += getRtAudioApiCount(); #endif + return count; } @@ -470,9 +508,11 @@ bool CarlaEngine::init(const char* const clientName) qDebug("CarlaEngine::init(\"%s\")", clientName); CARLA_ASSERT(fData->plugins == nullptr); + fName = clientName; + fName.toBasic(); + fData->aboutToClose = false; fData->curPluginCount = 0; - fData->maxPluginNumber = 0; switch (fOptions.processMode) { @@ -482,6 +522,9 @@ bool CarlaEngine::init(const char* const clientName) case PROCESS_MODE_PATCHBAY: fData->maxPluginNumber = MAX_PATCHBAY_PLUGINS; break; + case PROCESS_MODE_BRIDGE: + fData->maxPluginNumber = 1; + break; default: fData->maxPluginNumber = MAX_DEFAULT_PLUGINS; break; @@ -494,7 +537,7 @@ bool CarlaEngine::init(const char* const clientName) #ifndef BUILD_BRIDGE fData->oscData = fData->osc.getControlData(); #else - fData->oscData = nullptr; // set in setOscBridgeData() + fData->oscData = nullptr; // set later in setOscBridgeData() #endif #ifndef BUILD_BRIDGE @@ -502,6 +545,7 @@ bool CarlaEngine::init(const char* const clientName) carla_setprocname(clientName); #endif + fData->nextAction.ready(); fData->thread.startNow(); return true; @@ -512,6 +556,7 @@ bool CarlaEngine::close() qDebug("CarlaEngine::close()"); CARLA_ASSERT(fData->plugins != nullptr); + fData->nextAction.ready(); fData->thread.stopNow(); #ifndef BUILD_BRIDGE @@ -539,16 +584,6 @@ bool CarlaEngine::close() // ----------------------------------------------------------------------- // Plugin management -#if 0 -int CarlaEngine::getNewPluginId() const -{ - qDebug("CarlaEngine::getNewPluginId()"); - CARLA_ASSERT(data->maxPluginNumber > 0); - - return data->nextPluginId; -} -#endif - CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const { qDebug("CarlaEngine::getPlugin(%i) [count:%i]", id, fData->curPluginCount); @@ -556,7 +591,7 @@ CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const CARLA_ASSERT(id < fData->curPluginCount); CARLA_ASSERT(fData->plugins != nullptr); - if (id < fData->curPluginCount && fData->plugins) + if (id < fData->curPluginCount && fData->plugins != nullptr) return fData->plugins[id].plugin; return nullptr; @@ -572,7 +607,7 @@ const char* CarlaEngine::getNewUniquePluginName(const char* const name) qDebug("CarlaEngine::getNewUniquePluginName(\"%s\")", name); CARLA_ASSERT(fData->curPluginCount > 0); CARLA_ASSERT(fData->plugins != nullptr); - CARLA_ASSERT(name); + CARLA_ASSERT(name != nullptr); CarlaString sname(name); @@ -584,14 +619,14 @@ const char* CarlaEngine::getNewUniquePluginName(const char* const name) for (unsigned short i=0; i < fData->curPluginCount; i++) { -#if 0 + CARLA_ASSERT(fData->plugins[i].plugin); + // Check if unique name doesn't exist if (const char* const pluginName = fData->plugins[i].plugin->name()) { if (sname != pluginName) continue; } -#endif // Check if string has already been modified { @@ -643,7 +678,7 @@ const char* CarlaEngine::getNewUniquePluginName(const char* const name) return strdup(sname); } -bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra) +bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, const void* const extra) { qDebug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2Str(btype), PluginType2Str(ptype), filename, name, label, extra); CARLA_ASSERT(btype != BINARY_NONE); @@ -651,12 +686,19 @@ bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, cons CARLA_ASSERT(filename); CARLA_ASSERT(label); - //CarlaPlugin::Initializer init = { - // this, - // filename, - // name, - // label - //}; + if (fData->curPluginCount == fData->maxPluginNumber) + { + setLastError("Maximum number of plugins reached"); + return false; + } + + CarlaPlugin::Initializer init = { + this, + fData->curPluginCount, + filename, + name, + label + }; CarlaPlugin* plugin = nullptr; @@ -710,23 +752,24 @@ bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, cons else #endif // BUILD_BRIDGE { -#if 0 switch (ptype) { case PLUGIN_NONE: break; - case PLUGIN_INTERNAL: + #ifndef BUILD_BRIDGE + case PLUGIN_INTERNAL: plugin = CarlaPlugin::newNative(init); -#endif break; +#endif case PLUGIN_LADSPA: #ifdef WANT_LADSPA - plugin = CarlaPlugin::newLADSPA(init, extra); + plugin = CarlaPlugin::newLADSPA(init, (const LADSPA_RDF_Descriptor*)extra); #endif break; +#if 0 case PLUGIN_DSSI: #ifdef WANT_DSSI plugin = CarlaPlugin::newDSSI(init, extra); @@ -762,20 +805,20 @@ bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, cons plugin = CarlaPlugin::newSFZ(init); #endif break; - } +#else + default: + break; #endif + } } if (plugin == nullptr) return false; - //const int id = fData->curPluginCount++; + fData->curPluginCount++; -#if 0 - plugin->setId(id); -#endif + callback(CALLBACK_PLUGIN_ADDED, init.id, 0, 0, 0.0f, nullptr); - //return id; return true; } @@ -788,70 +831,46 @@ bool CarlaEngine::removePlugin(const unsigned int id) if (fData->plugins == nullptr) { - // TODO - warning + setLastError("Critical error: no plugins are currently loaded!"); return false; } - CarlaPlugin* plugin = fData->plugins[id].plugin; + CarlaPlugin* const plugin = fData->plugins[id].plugin; CARLA_ASSERT(plugin); - if (plugin /*&& plugin->id() == id*/) + if (plugin) { -#if 0 CARLA_ASSERT(plugin->id() == id); -#endif fData->thread.stopNow(); - // wait for processing to stop for this plugin - // TODO - - // clear this plugin - fData->plugins[id].plugin = nullptr; - fData->plugins[id].insPeak[0] = 0.0; - fData->plugins[id].insPeak[1] = 0.0; - fData->plugins[id].outsPeak[0] = 0.0; - fData->plugins[id].outsPeak[1] = 0.0; - - // wait for processing to stop for this plugin - // TODO - - //processLock(); - //plugin->setEnabled(false); - //data->carlaPlugins[id] = nullptr; - //data->uniqueNames[id] = nullptr; - //processUnlock(); - - delete plugin; + fData->nextAction.pluginId = id; + fData->nextAction.opcode = EnginePostActionRemovePlugin; -#ifndef BUILD_BRIDGE - osc_send_control_remove_plugin(static_cast(id)); + fData->nextAction.mutex.lock(); - // move all plugins 1 spot backwards - for (unsigned int i=id; i < fData->curPluginCount-1; i++) + if (isRunning()) { - plugin = fData->plugins[i+1].plugin; - - CARLA_ASSERT(plugin); + // block wait for unlock on proccessing side + fData->nextAction.mutex.lock(); + } + else + { + doPluginRemove(fData, false); + } -#if 0 - if (plugin) - plugin->setId(i); +#ifndef BUILD_BRIDGE + if (isOscControlRegistered()) + osc_send_control_remove_plugin(id); #endif - fData->plugins[i].plugin = plugin; - fData->plugins[i].insPeak[0] = 0.0; - fData->plugins[i].insPeak[1] = 0.0; - fData->plugins[i].outsPeak[0] = 0.0; - fData->plugins[i].outsPeak[1] = 0.0; - } + delete plugin; - fData->curPluginCount--; + fData->nextAction.mutex.unlock(); if (isRunning() && ! fData->aboutToClose) fData->thread.startNow(); -#endif return true; } @@ -965,7 +984,7 @@ void CarlaEngine::setOutputPeak(const unsigned short pluginId, const unsigned sh // ----------------------------------------------------------------------- // Callback -void CarlaEngine::callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3, const char* const valueStr) +void CarlaEngine::callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const float value3, const char* const valueStr) { qDebug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr); @@ -1297,6 +1316,18 @@ void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t } #endif +void CarlaEngine::proccessPendingEvents() +{ + switch (fData->nextAction.opcode) + { + case EnginePostActionNull: + break; + case EnginePostActionRemovePlugin: + doPluginRemove(fData, true); + break; + } +} + void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize) { qDebug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize); @@ -1321,7 +1352,7 @@ void CarlaEngine::sampleRateChanged(const double newSampleRate) // Carla Engine OSC stuff #ifdef BUILD_BRIDGE -void CarlaEngine::osc_send_peaks(CarlaPlugin* const plugin) +void CarlaEngine::osc_send_peaks(CarlaPlugin* const /*plugin*/) #else void CarlaEngine::osc_send_peaks(CarlaPlugin* const plugin, const unsigned short& id) #endif diff --git a/source/backend/engine/carla_engine_internal.hpp b/source/backend/engine/carla_engine_internal.hpp index c10c342b5..806c1eab3 100644 --- a/source/backend/engine/carla_engine_internal.hpp +++ b/source/backend/engine/carla_engine_internal.hpp @@ -98,20 +98,13 @@ const char* EngineControlEventType2Str(const EngineControlEventType type) * \note There are both input and output peaks. */ /*static*/ -const unsigned short MAX_PEAKS = 2; +const unsigned short MAX_PEAKS = 2; const uint32_t PATCHBAY_BUFFER_SIZE = 128; const unsigned short PATCHBAY_EVENT_COUNT = 512; const unsigned short RACK_EVENT_COUNT = 1024; #if 0 -enum EnginePostEventType { - EnginePostEventNull, - EnginePostEventDebug, - EnginePostEventAddPlugin, // id, ptr - EnginePostEventRemovePlugin // id -}; - struct EnginePostEvent { EnginePostEventType type; int32_t value1; @@ -124,18 +117,25 @@ struct EnginePostEvent { }; #endif +enum EnginePostAction { + EnginePostActionNull, + EnginePostActionRemovePlugin +}; + struct EnginePluginData { CarlaPlugin* plugin; - double insPeak[MAX_PEAKS]; - double outsPeak[MAX_PEAKS]; + float insPeak[MAX_PEAKS]; + float outsPeak[MAX_PEAKS]; EnginePluginData() : plugin(nullptr), - insPeak{0}, - outsPeak{0} {} + insPeak{ 0.0f }, + outsPeak{ 0.0f } {} }; -struct CarlaEngineProtectedData { +// ------------------------------------------------------------------------------------------------------------------- + +struct CarlaEnginePrivateData { CarlaEngineOsc osc; CarlaEngineThread thread; @@ -154,9 +154,25 @@ struct CarlaEngineProtectedData { unsigned int curPluginCount; // number of plugins loaded (0...max) unsigned int maxPluginNumber; // number of plugins allowed (0, 16, 99 or 999) + struct NextAction { + EnginePostAction opcode; + unsigned int pluginId; + CarlaMutex mutex; + + NextAction() + : opcode(EnginePostActionNull), + pluginId(0) {} + + void ready() + { + mutex.lock(); + mutex.unlock(); + } + } nextAction; + EnginePluginData* plugins; - CarlaEngineProtectedData(CarlaEngine* const engine) + CarlaEnginePrivateData(CarlaEngine* const engine) : osc(engine), thread(engine), oscData(nullptr), @@ -167,9 +183,9 @@ struct CarlaEngineProtectedData { maxPluginNumber(0), plugins(nullptr) {} - CarlaEngineProtectedData() = delete; + CarlaEnginePrivateData() = delete; - CARLA_LEAK_DETECTOR(CarlaEngineProtectedData) + CARLA_LEAK_DETECTOR(CarlaEnginePrivateData) }; CARLA_BACKEND_END_NAMESPACE diff --git a/source/backend/engine/carla_engine_osc.cpp b/source/backend/engine/carla_engine_osc.cpp index d8eba081a..f57bb8ce5 100644 --- a/source/backend/engine/carla_engine_osc.cpp +++ b/source/backend/engine/carla_engine_osc.cpp @@ -528,7 +528,7 @@ int CarlaEngineOsc::handleMsgExiting(CARLA_ENGINE_OSC_HANDLE_ARGS1) qDebug("CarlaEngineOsc::handleMsgExiting()"); // TODO - check for non-UIs (dssi-vst) and set to -1 instead - kEngine->callback(CALLBACK_SHOW_GUI, plugin->id(), 0, 0, 0.0, nullptr); + kEngine->callback(CALLBACK_SHOW_GUI, plugin->id(), 0, 0, 0.0f, nullptr); plugin->freeOscData(); diff --git a/source/backend/engine/carla_engine_thread.cpp b/source/backend/engine/carla_engine_thread.cpp index a2442dbea..65a7b3feb 100644 --- a/source/backend/engine/carla_engine_thread.cpp +++ b/source/backend/engine/carla_engine_thread.cpp @@ -1,18 +1,18 @@ /* * Carla Engine Thread - * Copyright (C) 2012 Filipe Coelho + * Copyright (C) 2012-2013 Filipe Coelho * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * For a full copy of the GNU General Public License see the COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #include "carla_engine.hpp" diff --git a/source/backend/engine/jack.cpp b/source/backend/engine/jack.cpp index d46d37ea6..fdb88084d 100644 --- a/source/backend/engine/jack.cpp +++ b/source/backend/engine/jack.cpp @@ -1,18 +1,18 @@ /* * Carla JACK Engine - * Copyright (C) 2011-2012 Filipe Coelho + * Copyright (C) 2012-2013 Filipe Coelho * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * For a full copy of the GNU General Public License see the COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ #ifdef WANT_JACK @@ -499,7 +499,7 @@ public: #ifndef BUILD_BRIDGE if (fOptions.processMode == PROCESS_MODE_SINGLE_CLIENT || fOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS) #endif - return (unsigned int)jackbridge_client_name_size() - 3; // reserve space for "_2" forced-stereo ports + return static_cast(jackbridge_client_name_size()); return CarlaEngine::maxClientNameSize(); } @@ -509,7 +509,7 @@ public: #ifndef BUILD_BRIDGE if (fOptions.processMode == PROCESS_MODE_SINGLE_CLIENT || fOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS) #endif - return (unsigned int)jackbridge_port_name_size(); + return static_cast(jackbridge_port_name_size()); return CarlaEngine::maxPortNameSize(); } @@ -970,7 +970,7 @@ protected: } m_client = nullptr; - callback(CALLBACK_QUIT, 0, 0, 0, 0.0, nullptr); + callback(CALLBACK_QUIT, 0, 0, 0, 0.0f, nullptr); } // ------------------------------------- diff --git a/source/backend/plugin/carla_plugin.cpp b/source/backend/plugin/carla_plugin.cpp index 7971c6753..046eb1fca 100644 --- a/source/backend/plugin/carla_plugin.cpp +++ b/source/backend/plugin/carla_plugin.cpp @@ -19,7 +19,9 @@ #include "carla_lib_utils.hpp" #include "carla_midi.h" -#include +//#include + +// TODO - save&load options CARLA_BACKEND_START_NAMESPACE @@ -34,41 +36,36 @@ static const CustomData kCustomDataNull; // ------------------------------------------------------------------- // Constructor and destructor -CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const int id) +CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const unsigned int id) : fData(new CarlaPluginProtectedData(engine, id)) { - CARLA_ASSERT(engine); + CARLA_ASSERT(fData != nullptr); + CARLA_ASSERT(engine != nullptr); CARLA_ASSERT(id < engine->currentPluginCount()); qDebug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id); -#if 0 - m_fixedBufferSize = true; - m_processHighPrecision = false; - + if (engine->getProccessMode() == PROCESS_MODE_CONTINUOUS_RACK) { - const CarlaEngineOptions& options(x_engine->getOptions()); + CARLA_ASSERT(id < MAX_RACK_PLUGINS && id < MAX_MIDI_CHANNELS); - m_processHighPrecision = options.processHighPrecision; - - if (options.processMode == PROCESS_MODE_CONTINUOUS_RACK) - m_ctrlInChannel = m_id; + if (id < MAX_RACK_PLUGINS && id < MAX_MIDI_CHANNELS) + fData->ctrlInChannel = id; } -#endif } CarlaPlugin::~CarlaPlugin() { qDebug("CarlaPlugin::~CarlaPlugin()"); -#if 0 // Remove client and ports - if (x_client) + if (fData->client) { - if (x_client->isActive()) - x_client->deactivate(); + if (fData->client->isActive()) + fData->client->deactivate(); removeClientPorts(); - delete x_client; + + delete fData->client; } // Delete data @@ -77,51 +74,17 @@ CarlaPlugin::~CarlaPlugin() // Unload DLL libClose(); - if (m_name) - free((void*)m_name); - - if (m_filename) - free((void*)m_filename); + fData->prog.clear(); + fData->midiprog.clear(); + fData->custom.clear(); - if (prog.count > 0) - { - for (uint32_t i=0; i < prog.count; i++) - { - if (prog.names[i]) - free((void*)prog.names[i]); - } - delete[] prog.names; - } - - if (midiprog.count > 0) - { - for (uint32_t i=0; i < midiprog.count; i++) - { - if (midiprog.data[i].name) - free((void*)midiprog.data[i].name); - } - delete[] midiprog.data; - } - - if (custom.size() > 0) - { - for (size_t i=0; i < custom.size(); i++) - { - if (custom[i].key) - free((void*)custom[i].key); - - if (custom[i].value) - free((void*)custom[i].value); - } - custom.clear(); - } - - if (m_latencyBuffers) +#if 0 + if (fData->latencyBuffers) { - for (uint32_t i=0; i < aIn.count; i++) - delete[] m_latencyBuffers[i]; + for (uint32_t i=0; i < fData->audioIn.count; i++) + delete[] fData->latencyBuffers[i]; - delete[] m_latencyBuffers; + delete[] fData->latencyBuffers; } #endif } @@ -129,7 +92,7 @@ CarlaPlugin::~CarlaPlugin() // ------------------------------------------------------------------- // Information (base) -unsigned short CarlaPlugin::id() const +unsigned int CarlaPlugin::id() const { return fData->id; } @@ -151,12 +114,12 @@ bool CarlaPlugin::enabled() const const char* CarlaPlugin::name() const { - return fData->name; + return (const char*)fData->name; } const char* CarlaPlugin::filename() const { - return fData->filename; + return (const char*)fData->filename; } // ------------------------------------------------------------------- @@ -261,7 +224,7 @@ const CustomData& CarlaPlugin::customData(const size_t index) const int32_t CarlaPlugin::chunkData(void** const dataPtr) { - CARLA_ASSERT(dataPtr); + CARLA_ASSERT(dataPtr != nullptr); return 0; // unused @@ -271,20 +234,20 @@ int32_t CarlaPlugin::chunkData(void** const dataPtr) // ------------------------------------------------------------------- // Information (per-plugin data) -double CarlaPlugin::getParameterValue(const uint32_t parameterId) +float CarlaPlugin::getParameterValue(const uint32_t parameterId) { CARLA_ASSERT(parameterId < parameterCount()); - return 0.0; + return 0.0f; // unused Q_UNUSED(parameterId); } -double CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) +float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) { CARLA_ASSERT(parameterId < parameterCount()); CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId)); - return 0.0; + return 0.0f; // unused Q_UNUSED(parameterId); @@ -308,7 +271,7 @@ void CarlaPlugin::getCopyright(char* const strBuf) void CarlaPlugin::getRealName(char* const strBuf) { - *strBuf = 0;; + *strBuf = 0; } void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) @@ -365,20 +328,22 @@ void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const void CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf) { - CARLA_ASSERT(index < programCount()); + CARLA_ASSERT(index < fData->prog.count); + CARLA_ASSERT(fData->prog.names[index] != nullptr); if (index < fData->prog.count && fData->prog.names[index]) - strncpy(strBuf, fData->prog.names[index], STR_MAX); + std::strncpy(strBuf, fData->prog.names[index], STR_MAX); else *strBuf = 0; } void CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf) { - CARLA_ASSERT(index < midiProgramCount()); + CARLA_ASSERT(index < fData->midiprog.count); + CARLA_ASSERT(fData->midiprog.data[index].name != nullptr); if (index < fData->midiprog.count && fData->midiprog.data[index].name) - strncpy(strBuf, fData->midiprog.data[index].name, STR_MAX); + std::strncpy(strBuf, fData->midiprog.data[index].name, STR_MAX); else *strBuf = 0; } @@ -412,7 +377,7 @@ void CarlaPlugin::setId(const unsigned int id) { fData->id = id; - if (fData->engine->getOptions().processMode == PROCESS_MODE_CONTINUOUS_RACK) + if (fData->engine->getProccessMode() == PROCESS_MODE_CONTINUOUS_RACK) fData->ctrlInChannel = id; } @@ -424,7 +389,8 @@ void CarlaPlugin::setEnabled(const bool yesNo) void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback) { fData->active = active; - double value = active ? 1.0 : 0.0; + + const float value = active ? 1.0f : 0.0f; #ifndef BUILD_BRIDGE if (sendOsc) @@ -441,133 +407,118 @@ void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool se #endif } -void CarlaPlugin::setDryWet(double value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback) { - CARLA_ASSERT(value >= 0.0 && value <= 1.0); + CARLA_ASSERT(value >= 0.0f && value <= 1.0f); - if (value < 0.0) - value = 0.0; - else if (value > 1.0) - value = 1.0; + const float fixedValue = carla_fixValue(0.0f, 1.0f, value); - fData->postProc.dryWet = value; + fData->postProc.dryWet = fixedValue; #ifndef BUILD_BRIDGE if (sendOsc) - fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_DRYWET, value); + fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_DRYWET, fixedValue); #else Q_UNUSED(sendOsc); #endif if (sendCallback) - fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_DRYWET, 0, value, nullptr); + fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_DRYWET, 0, fixedValue, nullptr); #ifndef BUILD_BRIDGE else if (fData->hints & PLUGIN_IS_BRIDGE) - osc_send_control(&fData->osc.data, PARAMETER_DRYWET, value); + osc_send_control(&fData->osc.data, PARAMETER_DRYWET, fixedValue); #endif } -void CarlaPlugin::setVolume(double value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback) { - CARLA_ASSERT(value >= 0.0 && value <= 1.27); + CARLA_ASSERT(value >= 0.0f && value <= 1.27f); - if (value < 0.0) - value = 0.0; - else if (value > 1.27) - value = 1.27; + const float fixedValue = carla_fixValue(0.0f, 1.27f, value); - fData->postProc.volume = value; + fData->postProc.volume = fixedValue; #ifndef BUILD_BRIDGE if (sendOsc) - fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_VOLUME, value); + fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_VOLUME, fixedValue); #else Q_UNUSED(sendOsc); #endif if (sendCallback) - fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_VOLUME, 0, value, nullptr); + fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_VOLUME, 0, fixedValue, nullptr); #ifndef BUILD_BRIDGE else if (fData->hints & PLUGIN_IS_BRIDGE) - osc_send_control(&fData->osc.data, PARAMETER_VOLUME, value); + osc_send_control(&fData->osc.data, PARAMETER_VOLUME, fixedValue); #endif } -void CarlaPlugin::setBalanceLeft(double value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) { - CARLA_ASSERT(value >= -1.0 && value <= 1.0); + CARLA_ASSERT(value >= -1.0f && value <= 1.0f); - if (value < -1.0) - value = -1.0; - else if (value > 1.0) - value = 1.0; + const float fixedValue = carla_fixValue(-1.0f, 1.0f, value); - fData->postProc.balanceLeft = value; + fData->postProc.balanceLeft = fixedValue; #ifndef BUILD_BRIDGE if (sendOsc) - fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_BALANCE_LEFT, value); + fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_BALANCE_LEFT, fixedValue); #else Q_UNUSED(sendOsc); #endif if (sendCallback) - fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_BALANCE_LEFT, 0, value, nullptr); + fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_BALANCE_LEFT, 0, fixedValue, nullptr); #ifndef BUILD_BRIDGE else if (fData->hints & PLUGIN_IS_BRIDGE) - osc_send_control(&fData->osc.data, PARAMETER_BALANCE_LEFT, value); + osc_send_control(&fData->osc.data, PARAMETER_BALANCE_LEFT, fixedValue); #endif } -void CarlaPlugin::setBalanceRight(double value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) { - CARLA_ASSERT(value >= -1.0 && value <= 1.0); + CARLA_ASSERT(value >= -1.0f && value <= 1.0f); - if (value < -1.0) - value = -1.0; - else if (value > 1.0) - value = 1.0; + const float fixedValue = carla_fixValue(-1.0f, 1.0f, value); - fData->postProc.balanceRight = value; + fData->postProc.balanceRight = fixedValue; #ifndef BUILD_BRIDGE if (sendOsc) - fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_BALANCE_RIGHT, value); + fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_BALANCE_RIGHT, fixedValue); #else Q_UNUSED(sendOsc); #endif if (sendCallback) - fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_BALANCE_RIGHT, 0, value, nullptr); + fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_BALANCE_RIGHT, 0, fixedValue, nullptr); #ifndef BUILD_BRIDGE else if (fData->hints & PLUGIN_IS_BRIDGE) - osc_send_control(&fData->osc.data, PARAMETER_BALANCE_RIGHT, value); + osc_send_control(&fData->osc.data, PARAMETER_BALANCE_RIGHT, fixedValue); #endif } -void CarlaPlugin::setPanning(double value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback) { - CARLA_ASSERT(value >= -1.0 && value <= 1.0); + CARLA_ASSERT(value >= -1.0f && value <= 1.0f); - if (value < -1.0) - value = -1.0; - else if (value > 1.0) - value = 1.0; + const float fixedValue = carla_fixValue(-1.0f, 1.0f, value); - fData->postProc.panning = value; + fData->postProc.panning = fixedValue; #ifndef BUILD_BRIDGE if (sendOsc) - fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_PANNING, value); + fData->engine->osc_send_control_set_parameter_value(fData->id, PARAMETER_PANNING, fixedValue); #else Q_UNUSED(sendOsc); #endif if (sendCallback) - fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_PANNING, 0, value, nullptr); + fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, PARAMETER_PANNING, 0, fixedValue, nullptr); #ifndef BUILD_BRIDGE else if (fData->hints & PLUGIN_IS_BRIDGE) - osc_send_control(&fData->osc.data, PARAMETER_PANNING, value); + osc_send_control(&fData->osc.data, PARAMETER_PANNING, fixedValue); #endif } @@ -581,7 +532,7 @@ int CarlaPlugin::setOscBridgeInfo(const PluginBridgeInfoType, const int, const l // ------------------------------------------------------------------- // Set data (plugin-specific stuff) -void CarlaPlugin::setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) { CARLA_ASSERT(parameterId < fData->param.count); @@ -599,10 +550,14 @@ void CarlaPlugin::setParameterValue(const uint32_t parameterId, double value, co fData->engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, fData->id, parameterId, 0, value, nullptr); } -void CarlaPlugin::setParameterValueByRIndex(const int32_t rindex, const double value, const bool sendGui, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setParameterValueByRIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) { CARLA_ASSERT(rindex > PARAMETER_MAX && rindex != PARAMETER_NULL); + if (rindex <= PARAMETER_MAX) + return; + if (rindex == PARAMETER_NULL) + return; if (rindex == PARAMETER_ACTIVE) return setActive(value > 0.0, sendOsc, sendCallback); if (rindex == PARAMETER_DRYWET) @@ -641,7 +596,7 @@ void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t ch #endif if (sendCallback) - fData->engine->callback(CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED, fData->id, parameterId, channel, 0.0, nullptr); + fData->engine->callback(CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED, fData->id, parameterId, channel, 0.0f, nullptr); } void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback) @@ -662,7 +617,7 @@ void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, con #endif if (sendCallback) - fData->engine->callback(CALLBACK_PARAMETER_MIDI_CC_CHANGED, fData->id, parameterId, cc, 0.0, nullptr); + fData->engine->callback(CALLBACK_PARAMETER_MIDI_CC_CHANGED, fData->id, parameterId, cc, 0.0f, nullptr); } void CarlaPlugin::setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) @@ -682,12 +637,10 @@ void CarlaPlugin::setCustomData(const char* const type, const char* const key, c bool saveData = true; -#if 0 - if (strcmp(type, CUSTOM_DATA_STRING) == 0) -#endif + if (std::strcmp(type, CUSTOM_DATA_STRING) == 0) { // Ignore some keys - if (strncmp(key, "OSC:", 4) == 0 || strcmp(key, "guiVisible") == 0) + if (strncmp(key, "OSC:", 4) == 0 || std::strcmp(key, "guiVisible") == 0) saveData = false; //else if (strcmp(key, CARLA_BRIDGE_MSG_SAVE_NOW) == 0 || strcmp(key, CARLA_BRIDGE_MSG_SET_CHUNK) == 0 || strcmp(key, CARLA_BRIDGE_MSG_SET_CUSTOM) == 0) // saveData = false; @@ -719,103 +672,100 @@ void CarlaPlugin::setCustomData(const char* const type, const char* const key, c void CarlaPlugin::setChunkData(const char* const stringData) { - CARLA_ASSERT(stringData); + CARLA_ASSERT(stringData != nullptr); return; // unused Q_UNUSED(stringData); } -void CarlaPlugin::setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block) +void CarlaPlugin::setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool) { - CARLA_ASSERT(index >= -1 && index < (int32_t)fData->prog.count); + CARLA_ASSERT(index >= -1 && index < static_cast(fData->prog.count)); - if (index < -1) - index = -1; - else if (index > (int32_t)fData->prog.count) + if (index > static_cast(fData->prog.count)) return; - fData->prog.current = index; + const int32_t fixedIndex = carla_fixValue(-1, fData->prog.count, index); - if (sendGui && index >= 0) - uiProgramChange(index); + fData->prog.current = fixedIndex; // Change default parameter values - if (index >= 0) + if (fixedIndex >= 0) { + if (sendGui) + uiProgramChange(fixedIndex); + for (uint32_t i=0; i < fData->param.count; i++) { + // FIXME? fData->param.ranges[i].def = getParameterValue(i); fData->param.ranges[i].fixDefault(); -#ifndef BUILD_BRIDGE if (sendOsc) { +#ifndef BUILD_BRIDGE fData->engine->osc_send_control_set_default_value(fData->id, i, fData->param.ranges[i].def); fData->engine->osc_send_control_set_parameter_value(fData->id, i, fData->param.ranges[i].def); - } #endif + } } } #ifndef BUILD_BRIDGE if (sendOsc) - fData->engine->osc_send_control_set_program(fData->id, index); -#else - Q_UNUSED(sendOsc); + fData->engine->osc_send_control_set_program(fData->id, fixedIndex); #endif if (sendCallback) - fData->engine->callback(CALLBACK_PROGRAM_CHANGED, fData->id, index, 0, 0.0, nullptr); - - Q_UNUSED(block); + fData->engine->callback(CALLBACK_PROGRAM_CHANGED, fData->id, fixedIndex, 0, 0.0f, nullptr); } void CarlaPlugin::setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool) { - CARLA_ASSERT(index >= -1 && index < (int32_t)fData->midiprog.count); + CARLA_ASSERT(index >= -1 && index < static_cast(fData->midiprog.count)); - if (index < -1) - index = -1; - else if (index > (int32_t)fData->midiprog.count) + if (index > static_cast(fData->midiprog.count)) return; - fData->midiprog.current = index; + const int32_t fixedIndex = carla_fixValue(-1, fData->midiprog.count, index); - if (sendGui && index >= 0) - uiMidiProgramChange(index); + fData->midiprog.current = fixedIndex; -#ifndef BUILD_BRIDGE - // Change default parameter values (sound banks never change defaults) - if (index >= 0 && type() != PLUGIN_GIG && type() != PLUGIN_SF2 && type() != PLUGIN_SFZ) -#else - if (index >= 0) -#endif + if (fixedIndex >= 0) { - for (uint32_t i=0; i < fData->param.count; i++) + if (sendGui) + uiMidiProgramChange(fixedIndex); + + // Change default parameter values (sound banks never change defaults) +#ifndef BUILD_BRIDGE // FIXME + if (type() != PLUGIN_GIG && type() != PLUGIN_SF2 && type() != PLUGIN_SFZ) +#endif { - fData->param.ranges[i].def = getParameterValue(i); - fData->param.ranges[i].fixDefault(); + for (uint32_t i=0; i < fData->param.count; i++) + { + // FIXME? + fData->param.ranges[i].def = getParameterValue(i); + fData->param.ranges[i].fixDefault(); + if (sendOsc) + { #ifndef BUILD_BRIDGE - if (sendOsc) - { - fData->engine->osc_send_control_set_default_value(fData->id, i, fData->param.ranges[i].def); - fData->engine->osc_send_control_set_parameter_value(fData->id, i, fData->param.ranges[i].def); - } + fData->engine->osc_send_control_set_default_value(fData->id, i, fData->param.ranges[i].def); + fData->engine->osc_send_control_set_parameter_value(fData->id, i, fData->param.ranges[i].def); #endif + } + } } } #ifndef BUILD_BRIDGE if (sendOsc) - fData->engine->osc_send_control_set_midi_program(fData->id, index); -#else - Q_UNUSED(sendOsc); + fData->engine->osc_send_control_set_midi_program(fData->id, fixedIndex); #endif if (sendCallback) - fData->engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, fData->id, index, 0, 0.0, nullptr); + fData->engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, fData->id, fixedIndex, 0, 0.0f, nullptr); } void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block) @@ -843,7 +793,7 @@ void CarlaPlugin::idleGui() if (fData->hints & PLUGIN_USES_SINGLE_THREAD) { // Process postponed events - //postEventsRun(); + postRtEventsRun(); // Update parameter outputs for (uint32_t i=0; i < fData->param.count; i++) @@ -886,6 +836,7 @@ void CarlaPlugin::sampleRateChanged(const double) void CarlaPlugin::recreateLatencyBuffers() { +#if 0 if (fData->latencyBuffers) { for (uint32_t i=0; i < fData->audioIn.count; i++) @@ -903,6 +854,7 @@ void CarlaPlugin::recreateLatencyBuffers() } else fData->latencyBuffers = nullptr; +#endif } // ------------------------------------------------------------------- @@ -910,11 +862,11 @@ void CarlaPlugin::recreateLatencyBuffers() void CarlaPlugin::registerToOscClient() { -#ifndef BUILD_BRIDGE - if (! fData->engine->isOscControlRegistered()) +#ifdef BUILD_BRIDGE + if (! fData->engine->isOscBridgeRegistered()) return; #else - if (! fData->engine->isOscBridgeRegistered()) + if (! fData->engine->isOscControlRegistered()) return; #endif @@ -964,16 +916,19 @@ void CarlaPlugin::registerToOscClient() getParameterName(i, bufName); getParameterUnit(i, bufUnit); + const ParameterData& paramData(fData->param.data[i]); + const ParameterRanges& paramRanges(fData->param.ranges[i]); + #ifdef BUILD_BRIDGE fData->engine->osc_send_bridge_parameter_info(i, bufName, bufUnit); - //fData->engine->osc_send_bridge_parameter_data(i, fData->param.data[i].type, fData->param.data[i].rindex, param.data[i].hints, param.data[i].midiChannel, param.data[i].midiCC); - //fData->engine->osc_send_bridge_parameter_ranges(i, fData->param.ranges[i].def, fData->param.ranges[i].min, param.ranges[i].max, param.ranges[i].step, param.ranges[i].stepSmall, param.ranges[i].stepLarge); + fData->engine->osc_send_bridge_parameter_data(i, paramData.type, paramData.rindex, paramData.hints, paramData.midiChannel, paramData.midiCC); + fData->engine->osc_send_bridge_parameter_ranges(i, paramRanges.def, paramRanges.min, paramRanges.max, paramRanges.step, paramRanges.stepSmall, paramRanges.stepLarge); fData->engine->osc_send_bridge_set_parameter_value(i, getParameterValue(i)); #else - fData->engine->osc_send_control_set_parameter_data(fData->id, i, fData->param.data[i].type, fData->param.data[i].hints, bufName, bufUnit, getParameterValue(i)); - fData->engine->osc_send_control_set_parameter_ranges(fData->id, i, fData->param.ranges[i].min, fData->param.ranges[i].max, fData->param.ranges[i].def, fData->param.ranges[i].step, fData->param.ranges[i].stepSmall, fData->param.ranges[i].stepLarge); - fData->engine->osc_send_control_set_parameter_midi_cc(fData->id, i, fData->param.data[i].midiCC); - fData->engine->osc_send_control_set_parameter_midi_channel(fData->id, i, fData->param.data[i].midiChannel); + fData->engine->osc_send_control_set_parameter_data(fData->id, i, paramData.type, paramData.hints, bufName, bufUnit, getParameterValue(i)); + fData->engine->osc_send_control_set_parameter_ranges(fData->id, i, paramRanges.min, paramRanges.max, paramRanges.def, paramRanges.step, paramRanges.stepSmall, paramRanges.stepLarge); + fData->engine->osc_send_control_set_parameter_midi_cc(fData->id, i, paramData.midiCC); + fData->engine->osc_send_control_set_parameter_midi_channel(fData->id, i, paramData.midiChannel); fData->engine->osc_send_control_set_parameter_value(fData->id, i, getParameterValue(i)); #endif } @@ -1006,14 +961,22 @@ void CarlaPlugin::registerToOscClient() fData->engine->osc_send_bridge_midi_program_count(fData->midiprog.count); for (uint32_t i=0; i < fData->midiprog.count; i++) - fData->engine->osc_send_bridge_midi_program_info(i, fData->midiprog.data[i].bank, fData->midiprog.data[i].program, fData->midiprog.data[i].name); + { + const MidiProgramData& mpData(fData->midiprog.data[i]); + + fData->engine->osc_send_bridge_midi_program_info(i, mpData.bank, mpData.program, mpData.name); + } fData->engine->osc_send_bridge_set_midi_program(fData->midiprog.current); #else fData->engine->osc_send_control_set_midi_program_count(fData->id, fData->midiprog.count); for (uint32_t i=0; i < fData->midiprog.count; i++) - fData->engine->osc_send_control_set_midi_program_data(fData->id, i, fData->midiprog.data[i].bank, fData->midiprog.data[i].program, fData->midiprog.data[i].name); + { + const MidiProgramData& mpData(fData->midiprog.data[i]); + + fData->engine->osc_send_control_set_midi_program_data(fData->id, i, mpData.bank, mpData.program, mpData.name); + } fData->engine->osc_send_control_set_midi_program(fData->id, fData->midiprog.current); #endif @@ -1123,32 +1086,26 @@ bool CarlaPlugin::waitForOscGuiShow() return false; } -#if 0 - // ------------------------------------------------------------------- // MIDI events void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback) { - CARLA_ASSERT(channel < 16); - CARLA_ASSERT(note < 128); - CARLA_ASSERT(velo < 128); + CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); + CARLA_ASSERT(note < MAX_MIDI_NOTE); + CARLA_ASSERT(velo < MAX_MIDI_VALUE); - if (! m_active) + if (! fData->active) return; - engineMidiLock(); - for (unsigned short i=0; i < MAX_MIDI_EVENTS; i++) - { - if (extMidiNotes[i].channel < 0) - { - extMidiNotes[i].channel = channel; - extMidiNotes[i].note = note; - extMidiNotes[i].velo = velo; - break; - } - } - engineMidiUnlock(); + ExternalMidiNote extNote; + extNote.channel = channel; + extNote.note = note; + extNote.velo = velo; + + fData->extNotes.mutex.lock(); + fData->extNotes.append(extNote); + fData->extNotes.mutex.unlock(); if (sendGui) { @@ -1162,56 +1119,49 @@ void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, if (sendOsc) { if (velo > 0) - x_engine->osc_send_control_note_on(m_id, channel, note, velo); + fData->engine->osc_send_control_note_on(fData->id, channel, note, velo); else - x_engine->osc_send_control_note_off(m_id, channel, note); + fData->engine->osc_send_control_note_off(fData->id, channel, note); } #else Q_UNUSED(sendOsc); #endif if (sendCallback) - x_engine->callback(velo ? CALLBACK_NOTE_ON : CALLBACK_NOTE_OFF, m_id, channel, note, velo, nullptr); + fData->engine->callback(velo ? CALLBACK_NOTE_ON : CALLBACK_NOTE_OFF, fData->id, channel, note, velo, nullptr); } void CarlaPlugin::sendMidiAllNotesOff() { - engineMidiLock(); - postEvents.mutex.lock(); + // TODO +#if 0 + fData->extNotes.mutex.lock(); + fData->postRtEvents.mutex.lock(); - unsigned short postPad = 0; + ExternalMidiNote extNote; + extNote.channel = fData->ctrlInChannel; + extNote.note = 0; + extNote.velo = 0; - for (unsigned short i=0; i < MAX_POST_EVENTS; i++) - { - if (postEvents.data[i].type == PluginPostEventNull) - { - postPad = i; - break; - } - } + PluginPostRtEvent postEvent; + postEvent.type = kPluginPostRtEventNoteOff; + postEvent.value1 = fData->ctrlInChannel; + postEvent.value2 = 0; + postEvent.value3 = 0.0; - if (postPad == MAX_POST_EVENTS - 1) + for (unsigned short i=0; i < MAX_MIDI_NOTE; i++) { - qWarning("post-events buffer full, making room for all notes off now"); - postPad -= 128; - } + extNote.note = i; + postEvent.value2 = i; - for (unsigned short i=0; i < 128; i++) - { - extMidiNotes[i].channel = m_ctrlInChannel; - extMidiNotes[i].note = i; - extMidiNotes[i].velo = 0; - - postEvents.data[i + postPad].type = PluginPostEventNoteOff; - postEvents.data[i + postPad].value1 = m_ctrlInChannel; - postEvents.data[i + postPad].value2 = i; - postEvents.data[i + postPad].value3 = 0.0; + fData->extNotes.append(extNote); + fData->postRtEvents.appendNonRT(event); } - postEvents.mutex.unlock(); - engineMidiUnlock(); -} + fData->postRtEvents.mutex.unlock(); + fData->extNotes.mutex.unlock(); #endif +} // ------------------------------------------------------------------- // Post-poned events @@ -1229,8 +1179,8 @@ void CarlaPlugin::postponeRtEvent(const PluginPostRtEventType type, const int32_ void CarlaPlugin::postRtEventsRun() { - int i = 0; - PluginPostRtEvent listData[512]; + unsigned short i = 0; + PluginPostRtEvent listData[MAX_RT_EVENTS]; // Make a safe copy of events while clearing them fData->postRtEvents.mutex.lock(); @@ -1244,7 +1194,7 @@ void CarlaPlugin::postRtEventsRun() fData->postRtEvents.mutex.unlock(); // Handle events now - for (i=0; i < 512; i++) + for (i=0; i < MAX_RT_EVENTS; i++) { const PluginPostRtEvent* const event = &listData[i]; @@ -1264,8 +1214,8 @@ void CarlaPlugin::postRtEventsRun() #ifndef BUILD_BRIDGE // Update OSC control client - if (x_engine->isOscControlRegistered()) - x_engine->osc_send_control_set_parameter_value(fData->id, event->value1, event->value3); + if (fData->engine->isOscControlRegistered()) + fData->engine->osc_send_control_set_parameter_value(fData->id, event->value1, event->value3); #endif // Update Host @@ -1402,85 +1352,28 @@ void CarlaPlugin::removeClientPorts() { qDebug("CarlaPlugin::removeClientPorts() - start"); - for (uint32_t i=0; i < fData->audioIn.count; i++) - { - delete fData->audioIn.ports[i].port; - fData->audioIn.ports[i].port = nullptr; - } - - for (uint32_t i=0; i < fData->audioOut.count; i++) - { - delete fData->audioOut.ports[i].port; - fData->audioOut.ports[i].port = nullptr; - } - - if (fData->event.portIn) - { - delete fData->event.portIn; - fData->event.portIn = nullptr; - } - - if (fData->event.portOut) - { - delete fData->event.portOut; - fData->event.portOut = nullptr; - } + fData->audioIn.freePorts(); + fData->audioOut.freePorts(); + fData->event.freePorts(); qDebug("CarlaPlugin::removeClientPorts() - end"); } void CarlaPlugin::initBuffers() { - for (uint32_t i=0; i < fData->audioIn.count; i++) - { - if (fData->audioIn.ports[i].port) - fData->audioIn.ports[i].port->initBuffer(fData->engine); - } - - for (uint32_t i=0; i < fData->audioOut.count; i++) - { - if (fData->audioOut.ports[i].port) - fData->audioOut.ports[i].port->initBuffer(fData->engine); - } - - if (fData->event.portIn) - fData->event.portIn->initBuffer(fData->engine); - - if (fData->event.portOut) - fData->event.portOut->initBuffer(fData->engine); + fData->audioIn.initBuffers(fData->engine); + fData->audioOut.initBuffers(fData->engine); + fData->event.initBuffers(fData->engine); } void CarlaPlugin::deleteBuffers() { qDebug("CarlaPlugin::deleteBuffers() - start"); - if (fData->audioIn.count > 0) - { - fData->audioIn.free(); - } - - if (fData->audioOut.count > 0) - { - fData->audioOut.free(); - } - - if (fData->param.count > 0) - { - delete[] fData->param.data; - delete[] fData->param.ranges; - } - - fData->audioIn.count = 0; - fData->audioIn.ports = nullptr; - - fData->audioOut.count = 0; - fData->audioOut.ports = nullptr; - - fData->param.count = 0; - fData->param.data = nullptr; - fData->param.ranges = nullptr; - fData->event.portIn = nullptr; - fData->event.portOut = nullptr; + fData->audioIn.clear(); + fData->audioOut.clear(); + fData->param.clear(); + fData->event.clear(); qDebug("CarlaPlugin::deleteBuffers() - end"); } @@ -1511,50 +1404,25 @@ const char* CarlaPlugin::libError(const char* const filename) return lib_error(filename); } -#if 0 -// ------------------------------------------------------------------- -// Locks - -void CarlaPlugin::engineProcessLock() -{ - x_engine->processLock(); -} - -void CarlaPlugin::engineProcessUnlock() -{ - x_engine->processUnlock(); -} - -void CarlaPlugin::engineMidiLock() -{ - x_engine->midiLock(); -} - -void CarlaPlugin::engineMidiUnlock() -{ - x_engine->midiUnlock(); -} - // ------------------------------------------------------------------- // CarlaPluginGUI -CarlaPluginGUI::CarlaPluginGUI(QWidget* const parent, Callback* const callback) - : QMainWindow(parent), - m_callback(callback) +CarlaPluginGUI::CarlaPluginGUI(QWidget* const parent) + : QMainWindow(parent) { - qDebug("CarlaPluginGUI::CarlaPluginGUI(%p, %p", parent, callback); - CARLA_ASSERT(callback); + qDebug("CarlaPluginGUI::CarlaPluginGUI(%p)", parent); + //CARLA_ASSERT(callback); - m_container = new GuiContainer(this); - setCentralWidget(m_container); - adjustSize(); + //m_container = new GuiContainer(this); + //setCentralWidget(m_container); + //adjustSize(); - m_container->setParent(this); - m_container->show(); + //m_container->setParent(this); + //m_container->show(); - m_resizable = true; + //m_resizable = true; - setNewSize(50, 50); + //setNewSize(50, 50); QMainWindow::setVisible(false); } @@ -1562,12 +1430,14 @@ CarlaPluginGUI::CarlaPluginGUI(QWidget* const parent, Callback* const callback) CarlaPluginGUI::~CarlaPluginGUI() { qDebug("CarlaPluginGUI::~CarlaPluginGUI()"); - CARLA_ASSERT(m_container); + //CARLA_ASSERT(m_container); // FIXME, automatically deleted by parent ? - delete m_container; + //delete m_container; } +#if 0 + // ------------------------------------------------------------------- GuiContainer* CarlaPluginGUI::getContainer() const diff --git a/source/backend/plugin/carla_plugin_internal.hpp b/source/backend/plugin/carla_plugin_internal.hpp index 483b56cfd..c715f1403 100644 --- a/source/backend/plugin/carla_plugin_internal.hpp +++ b/source/backend/plugin/carla_plugin_internal.hpp @@ -22,15 +22,14 @@ #include "carla_plugin_thread.hpp" #include "carla_engine.hpp" +#include "carla_osc_utils.hpp" -#ifdef BUILD_BRIDGE -# include "carla_bridge_osc.hpp" -#else -# include "carla_osc_utils.hpp" -#endif +//#include "carla_bridge_osc.hpp" #include "rt_list.hpp" +#include + #define CARLA_DECLARE_NON_COPY_STRUCT(structName) \ structName(const structName&) = delete; @@ -81,15 +80,38 @@ struct PluginAudioData { ports = new PluginAudioPort[count]; } - void free() + void freePorts() + { + for (uint32_t i=0; i < count; i++) + { + if (ports[i].port != nullptr) + { + delete ports[i].port; + ports[i].port = nullptr; + } + } + } + + void clear() { - CARLA_ASSERT(ports != nullptr); + freePorts(); if (ports != nullptr) { delete[] ports; ports = nullptr; } + + count = 0; + } + + void initBuffers(CarlaEngine* const engine) + { + for (uint32_t i=0; i < count; i++) + { + if (ports[i].port != nullptr) + ports[i].port->initBuffer(engine); + } } CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(PluginAudioData) @@ -111,6 +133,35 @@ struct PluginEventData { CARLA_ASSERT(portOut == nullptr); } + void freePorts() + { + if (portIn != nullptr) + { + delete portIn; + portIn = nullptr; + } + + if (portOut != nullptr) + { + delete portOut; + portOut = nullptr; + } + } + + void clear() + { + freePorts(); + } + + void initBuffers(CarlaEngine* const engine) + { + if (portIn != nullptr) + portIn->initBuffer(engine); + + if (portOut != nullptr) + portOut->initBuffer(engine); + } + CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(PluginEventData) }; @@ -144,11 +195,8 @@ struct PluginParameterData { ranges = new ParameterRanges[count]; } - void free() + void clear() { - CARLA_ASSERT(data != nullptr); - CARLA_ASSERT(ranges != nullptr); - if (data != nullptr) { delete[] data; @@ -160,6 +208,8 @@ struct PluginParameterData { delete[] ranges; ranges = nullptr; } + + count = 0; } CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(PluginParameterData) @@ -184,28 +234,39 @@ struct PluginProgramData { CARLA_ASSERT(names == nullptr); } - void createNew(const size_t count) + void createNew(const uint32_t count) { CARLA_ASSERT(names == nullptr); if (names == nullptr) names = new ProgramName[count]; + + for (uint32_t i=0; i < count; i++) + names[i] = nullptr; + + this->count = count; } - void free() + void clear() { - CARLA_ASSERT(names != nullptr); - if (names != nullptr) { + for (uint32_t i=0; i < count; i++) + std::free((void*)names[i]); + delete[] names; names = nullptr; } + + count = 0; + current = -1; } CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(PluginProgramData) }; +// ----------------------------------------------------------------------- + struct PluginMidiProgramData { uint32_t count; int32_t current; @@ -221,27 +282,31 @@ struct PluginMidiProgramData { CARLA_ASSERT(data == nullptr); } - void createNew(const size_t count) + void createNew(const uint32_t count) { CARLA_ASSERT(data == nullptr); if (data == nullptr) data = new MidiProgramData[count]; + + this->count = count; } - void free() + void clear() { - CARLA_ASSERT(data != nullptr); - if (data != nullptr) { delete[] data; data = nullptr; } + + count = 0; + current = -1; } - const MidiProgramData& getCurrent() + const MidiProgramData& getCurrent() const { + CARLA_ASSERT(current >= 0 && current < static_cast(count)); return data[current]; } @@ -282,14 +347,33 @@ struct ExternalMidiNote { // ----------------------------------------------------------------------- +class CarlaPluginGUI : public QMainWindow +{ +public: + CarlaPluginGUI(QWidget* const parent = nullptr); + + ~CarlaPluginGUI(); + +private: + CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginGUI) +}; + +// ----------------------------------------------------------------------- + +const unsigned short MIN_RT_EVENTS = 152; +const unsigned short MAX_RT_EVENTS = 512; + const unsigned int PLUGIN_OPTION2_HAS_MIDI_IN = 0x1; const unsigned int PLUGIN_OPTION2_HAS_MIDI_OUT = 0x2; +// ----------------------------------------------------------------------- + struct CarlaPluginProtectedData { - int id; + unsigned int id; CarlaEngine* const engine; CarlaEngineClient* client; + CarlaPluginGUI* gui; unsigned int hints; unsigned int options; @@ -300,13 +384,16 @@ struct CarlaPluginProtectedData { bool enabled; void* lib; - const char* name; - const char* filename; + CarlaString name; + CarlaString filename; // misc - int8_t ctrlInChannel; + int8_t ctrlInChannel; + +#if 0 uint32_t latency; float** latencyBuffers; +#endif // data PluginAudioData audioIn; @@ -315,7 +402,7 @@ struct CarlaPluginProtectedData { PluginParameterData param; PluginProgramData prog; PluginMidiProgramData midiprog; - NonRtList custom; + NonRtListNew custom; struct ExternalNotes { CarlaMutex mutex; @@ -323,6 +410,12 @@ struct CarlaPluginProtectedData { ExternalNotes() : data(32, 512) {} + + void append(const ExternalMidiNote& note) + { + data.append_sleepy(note); + } + } extNotes; struct PostRtEvents { @@ -331,8 +424,8 @@ struct CarlaPluginProtectedData { RtList dataPendingRT; PostRtEvents() - : data(152, 512), - dataPendingRT(152, 256) {} + : data(MIN_RT_EVENTS, MAX_RT_EVENTS), + dataPendingRT(MIN_RT_EVENTS, MAX_RT_EVENTS) {} void appendRT(const PluginPostRtEvent& event) { @@ -345,21 +438,26 @@ struct CarlaPluginProtectedData { } } + //void appendNonRT(const PluginPostRtEvent& event) + //{ + // data.append_sleepy(event); + //} + } postRtEvents; struct PostProc { - double dryWet; - double volume; - double balanceLeft; - double balanceRight; - double panning; + float dryWet; + float volume; + float balanceLeft; + float balanceRight; + float panning; PostProc() - : dryWet(1.0), - volume(1.0), - balanceLeft(-1.0), - balanceRight(1.0), - panning(0.0) {} + : dryWet(1.0f), + volume(1.0f), + balanceLeft(-1.0f), + balanceRight(1.0f), + panning(0.0f) {} } postProc; struct OSC { @@ -374,6 +472,7 @@ struct CarlaPluginProtectedData { : id(id_), engine(engine_), client(nullptr), + gui(nullptr), hints(0x0), options(0x0), options2(0x0), @@ -381,11 +480,11 @@ struct CarlaPluginProtectedData { activeBefore(false), enabled(false), lib(nullptr), - name(nullptr), - filename(nullptr), - ctrlInChannel(-1), + ctrlInChannel(-1) {} +#if 0 latency(0), latencyBuffers(nullptr) {} +#endif CarlaPluginProtectedData() = delete; diff --git a/source/backend/plugin/ladspa.cpp b/source/backend/plugin/ladspa.cpp index e8d79799d..c779bfecd 100644 --- a/source/backend/plugin/ladspa.cpp +++ b/source/backend/plugin/ladspa.cpp @@ -1,21 +1,21 @@ /* * Carla LADSPA Plugin - * Copyright (C) 2011-2012 Filipe Coelho + * Copyright (C) 2011-2013 Filipe Coelho * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * For a full copy of the GNU General Public License see the COPYING file + * For a full copy of the GNU General Public License see the GPL.txt file */ -#include "carla_plugin.hpp" +#include "carla_plugin_internal.hpp" #ifdef WANT_LADSPA @@ -23,56 +23,46 @@ CARLA_BACKEND_START_NAMESPACE -/*! - * @defgroup CarlaBackendLadspaPlugin Carla Backend LADSPA Plugin - * - * The Carla Backend LADSPA Plugin.\n - * http://www.ladspa.org/ - * @{ - */ - class LadspaPlugin : public CarlaPlugin { public: - LadspaPlugin(CarlaEngine* const engine, const unsigned short id) + LadspaPlugin(CarlaEngine* const engine, const unsigned int id) : CarlaPlugin(engine, id) { qDebug("LadspaPlugin::LadspaPlugin()"); - m_type = PLUGIN_LADSPA; + fHandle = nullptr; + fHandle2 = nullptr; + fDescriptor = nullptr; + fRdfDescriptor = nullptr; - handle = h2 = nullptr; - descriptor = nullptr; - rdf_descriptor = nullptr; - - paramBuffers = nullptr; + fParamBuffers = nullptr; } ~LadspaPlugin() { qDebug("LadspaPlugin::~LadspaPlugin()"); - if (descriptor) + if (fDescriptor) { - if (descriptor->deactivate && m_activeBefore) + if (fDescriptor->deactivate && fData->activeBefore) { - if (handle) - descriptor->deactivate(handle); - if (h2) - descriptor->deactivate(h2); + if (fHandle) + fDescriptor->deactivate(fHandle); + if (fHandle2) + fDescriptor->deactivate(fHandle2); } - if (descriptor->cleanup) + if (fDescriptor->cleanup) { - if (handle) - descriptor->cleanup(handle); - if (h2) - descriptor->cleanup(h2); + if (fHandle) + fDescriptor->cleanup(fHandle); + if (fHandle2) + fDescriptor->cleanup(fHandle2); } } - if (rdf_descriptor) - delete rdf_descriptor; + delete fRdfDescriptor; } // ------------------------------------------------------------------- @@ -80,18 +70,18 @@ public: PluginCategory category() { - if (rdf_descriptor) + if (fRdfDescriptor) { - const LADSPA_Properties category = rdf_descriptor->Type; + const LADSPA_Properties category = fRdfDescriptor->Type; // Specific Types - if (category & (LADSPA_CLASS_DELAY|LADSPA_CLASS_REVERB)) + if (category & (LADSPA_PLUGIN_DELAY|LADSPA_PLUGIN_REVERB)) return PLUGIN_CATEGORY_DELAY; - if (category & (LADSPA_CLASS_PHASER|LADSPA_CLASS_FLANGER|LADSPA_CLASS_CHORUS)) + if (category & (LADSPA_PLUGIN_PHASER|LADSPA_PLUGIN_FLANGER|LADSPA_PLUGIN_CHORUS)) return PLUGIN_CATEGORY_MODULATOR; - if (category & (LADSPA_CLASS_AMPLIFIER)) + if (category & (LADSPA_PLUGIN_AMPLIFIER)) return PLUGIN_CATEGORY_DYNAMICS; - if (category & (LADSPA_CLASS_UTILITY|LADSPA_CLASS_SPECTRAL|LADSPA_CLASS_FREQUENCY_METER)) + if (category & (LADSPA_PLUGIN_UTILITY|LADSPA_PLUGIN_SPECTRAL|LADSPA_PLUGIN_FREQUENCY_METER)) return PLUGIN_CATEGORY_UTILITY; // Pre-set LADSPA Types @@ -113,14 +103,14 @@ public: return PLUGIN_CATEGORY_SYNTH; } - return getPluginCategoryFromName(m_name); + return getPluginCategoryFromName(fData->name); } long uniqueId() { - CARLA_ASSERT(descriptor); + CARLA_ASSERT(fDescriptor); - return descriptor ? descriptor->UniqueID : 0; + return fDescriptor ? fDescriptor->UniqueID : 0; } // ------------------------------------------------------------------- @@ -128,13 +118,13 @@ public: uint32_t parameterScalePointCount(const uint32_t parameterId) { - CARLA_ASSERT(parameterId < param.count); + CARLA_ASSERT(parameterId < fData->param.count); - int32_t rindex = param.data[parameterId].rindex; + int32_t rindex = fData->param.data[parameterId].rindex; - if (rdf_descriptor && rindex < (int32_t)rdf_descriptor->PortCount) + if (fRdfDescriptor && rindex < (int32_t)fRdfDescriptor->PortCount) { - const LADSPA_RDF_Port* const port = &rdf_descriptor->Ports[rindex]; + const LADSPA_RDF_Port* const port = &fRdfDescriptor->Ports[rindex]; if (port) return port->ScalePointCount; @@ -146,23 +136,23 @@ public: // ------------------------------------------------------------------- // Information (per-plugin data) - double getParameterValue(const uint32_t parameterId) + float getParameterValue(const uint32_t parameterId) { - CARLA_ASSERT(parameterId < param.count); + CARLA_ASSERT(parameterId < fData->param.count); - return paramBuffers[parameterId]; + return fParamBuffers[parameterId]; } - double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) + float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) { - CARLA_ASSERT(parameterId < param.count); + CARLA_ASSERT(parameterId < fData->param.count); CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId)); - int32_t rindex = param.data[parameterId].rindex; + int32_t rindex = fData->param.data[parameterId].rindex; - if (rdf_descriptor && rindex < (int32_t)rdf_descriptor->PortCount) + if (fRdfDescriptor && rindex < (int32_t)fRdfDescriptor->PortCount) { - const LADSPA_RDF_Port* const port = &rdf_descriptor->Ports[rindex]; + const LADSPA_RDF_Port* const port = &fRdfDescriptor->Ports[rindex]; if (port && scalePointId < port->ScalePointCount) { @@ -178,70 +168,70 @@ public: void getLabel(char* const strBuf) { - CARLA_ASSERT(descriptor); + CARLA_ASSERT(fDescriptor); - if (descriptor && descriptor->Label) - strncpy(strBuf, descriptor->Label, STR_MAX); + if (fDescriptor && fDescriptor->Label) + strncpy(strBuf, fDescriptor->Label, STR_MAX); else CarlaPlugin::getLabel(strBuf); } void getMaker(char* const strBuf) { - CARLA_ASSERT(descriptor); + CARLA_ASSERT(fDescriptor); - if (rdf_descriptor && rdf_descriptor->Creator) - strncpy(strBuf, rdf_descriptor->Creator, STR_MAX); - else if (descriptor && descriptor->Maker) - strncpy(strBuf, descriptor->Maker, STR_MAX); + if (fRdfDescriptor && fRdfDescriptor->Creator) + strncpy(strBuf, fRdfDescriptor->Creator, STR_MAX); + else if (fDescriptor && fDescriptor->Maker) + strncpy(strBuf, fDescriptor->Maker, STR_MAX); else CarlaPlugin::getMaker(strBuf); } void getCopyright(char* const strBuf) { - CARLA_ASSERT(descriptor); + CARLA_ASSERT(fDescriptor); - if (descriptor && descriptor->Copyright) - strncpy(strBuf, descriptor->Copyright, STR_MAX); + if (fDescriptor && fDescriptor->Copyright) + strncpy(strBuf, fDescriptor->Copyright, STR_MAX); else CarlaPlugin::getCopyright(strBuf); } void getRealName(char* const strBuf) { - CARLA_ASSERT(descriptor); + CARLA_ASSERT(fDescriptor); - if (rdf_descriptor && rdf_descriptor->Title) - strncpy(strBuf, rdf_descriptor->Title, STR_MAX); - else if (descriptor && descriptor->Name) - strncpy(strBuf, descriptor->Name, STR_MAX); + if (fRdfDescriptor && fRdfDescriptor->Title) + strncpy(strBuf, fRdfDescriptor->Title, STR_MAX); + else if (fDescriptor && fDescriptor->Name) + strncpy(strBuf, fDescriptor->Name, STR_MAX); else CarlaPlugin::getRealName(strBuf); } void getParameterName(const uint32_t parameterId, char* const strBuf) { - CARLA_ASSERT(descriptor); - CARLA_ASSERT(parameterId < param.count); + CARLA_ASSERT(fDescriptor); + CARLA_ASSERT(parameterId < fData->param.count); - int32_t rindex = param.data[parameterId].rindex; + int32_t rindex = fData->param.data[parameterId].rindex; - if (descriptor && rindex < (int32_t)descriptor->PortCount) - strncpy(strBuf, descriptor->PortNames[rindex], STR_MAX); + if (fDescriptor && rindex < (int32_t)fDescriptor->PortCount) + strncpy(strBuf, fDescriptor->PortNames[rindex], STR_MAX); else CarlaPlugin::getParameterName(parameterId, strBuf); } void getParameterSymbol(const uint32_t parameterId, char* const strBuf) { - CARLA_ASSERT(parameterId < param.count); + CARLA_ASSERT(parameterId < fData->param.count); - int32_t rindex = param.data[parameterId].rindex; + int32_t rindex = fData->param.data[parameterId].rindex; - if (rdf_descriptor && rindex < (int32_t)rdf_descriptor->PortCount) + if (fRdfDescriptor && rindex < (int32_t)fRdfDescriptor->PortCount) { - const LADSPA_RDF_Port* const port = &rdf_descriptor->Ports[rindex]; + const LADSPA_RDF_Port* const port = &fRdfDescriptor->Ports[rindex]; if (LADSPA_PORT_HAS_LABEL(port->Hints) && port->Label) { @@ -255,13 +245,13 @@ public: void getParameterUnit(const uint32_t parameterId, char* const strBuf) { - CARLA_ASSERT(parameterId < param.count); + CARLA_ASSERT(parameterId < fData->param.count); - int32_t rindex = param.data[parameterId].rindex; + int32_t rindex = fData->param.data[parameterId].rindex; - if (rdf_descriptor && rindex < (int32_t)rdf_descriptor->PortCount) + if (fRdfDescriptor && rindex < (int32_t)fRdfDescriptor->PortCount) { - const LADSPA_RDF_Port* const port = &rdf_descriptor->Ports[rindex]; + const LADSPA_RDF_Port* const port = &fRdfDescriptor->Ports[rindex]; if (LADSPA_PORT_HAS_UNIT(port->Hints)) { @@ -294,14 +284,14 @@ public: void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) { - CARLA_ASSERT(parameterId < param.count); + CARLA_ASSERT(parameterId < fData->param.count); CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId)); - int32_t rindex = param.data[parameterId].rindex; + int32_t rindex = fData->param.data[parameterId].rindex; - if (rdf_descriptor && rindex < (int32_t)rdf_descriptor->PortCount) + if (fRdfDescriptor && rindex < (int32_t)fRdfDescriptor->PortCount) { - const LADSPA_RDF_Port* const port = &rdf_descriptor->Ports[rindex]; + const LADSPA_RDF_Port* const port = &fRdfDescriptor->Ports[rindex]; if (port && scalePointId < port->ScalePointCount) { @@ -321,13 +311,14 @@ public: // ------------------------------------------------------------------- // Set data (plugin-specific stuff) - void setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback) + void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) { - CARLA_ASSERT(parameterId < param.count); + CARLA_ASSERT(parameterId < fData->param.count); - paramBuffers[parameterId] = fixParameterValue(value, param.ranges[parameterId]); + const float fixedValue = fData->param.ranges[parameterId].fixValue(value); + fParamBuffers[parameterId] = fixedValue; - CarlaPlugin::setParameterValue(parameterId, value, sendGui, sendOsc, sendCallback); + CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback); } // ------------------------------------------------------------------- @@ -336,15 +327,15 @@ public: void reload() { qDebug("LadspaPlugin::reload() - start"); - CARLA_ASSERT(descriptor); + CARLA_ASSERT(fDescriptor); - const ProcessMode processMode(x_engine->getOptions().processMode); + const ProcessMode processMode(fData->engine->getOptions().processMode); // Safely disable plugin for reload - const ScopedDisabler m(this); + //const ScopedDisabler m(this); - if (x_client->isActive()) - x_client->deactivate(); + if (fData->client->isActive()) + fData->client->deactivate(); // Remove client ports removeClientPorts(); @@ -355,15 +346,15 @@ public: uint32_t aIns, aOuts, params, j; aIns = aOuts = params = 0; - const double sampleRate = x_engine->getSampleRate(); - const unsigned long portCount = descriptor->PortCount; + const double sampleRate = fData->engine->getSampleRate(); + const unsigned long portCount = fDescriptor->PortCount; bool forcedStereoIn, forcedStereoOut; forcedStereoIn = forcedStereoOut = false; for (unsigned long i=0; i < portCount; i++) { - const LADSPA_PortDescriptor portType = descriptor->PortDescriptors[i]; + const LADSPA_PortDescriptor portType = fDescriptor->PortDescriptors[i]; if (LADSPA_IS_PORT_AUDIO(portType)) { @@ -376,9 +367,9 @@ public: params += 1; } - if (x_engine->getOptions().forceStereo && (aIns == 1 || aOuts == 1) && ! h2) + if (fData->engine->getOptions().forceStereo && (aIns == 1 || aOuts == 1) && ! fHandle2) { - h2 = descriptor->instantiate(descriptor, sampleRate); + fHandle2 = fDescriptor->instantiate(fDescriptor, sampleRate); if (aIns == 1) { @@ -395,34 +386,34 @@ public: if (aIns > 0) { - aIn.ports = new CarlaEngineAudioPort*[aIns]; - aIn.rindexes = new uint32_t[aIns]; + //fData->audioIn.ports = new CarlaEngineAudioPort*[aIns]; + //fData->audioIn.rindexes = new uint32_t[aIns]; } if (aOuts > 0) { - aOut.ports = new CarlaEngineAudioPort*[aOuts]; - aOut.rindexes = new uint32_t[aOuts]; + //fData->audioOut.ports = new CarlaEngineAudioPort*[aOuts]; + //fData->audioOut.rindexes = new uint32_t[aOuts]; } if (params > 0) { - param.data = new ParameterData[params]; - param.ranges = new ParameterRanges[params]; - paramBuffers = new float[params]; + fData->param.data = new ParameterData[params]; + fData->param.ranges = new ParameterRanges[params]; + fParamBuffers = new float[params]; } bool needsCtrlIn = false; bool needsCtrlOut = false; - const int portNameSize = x_engine->maxPortNameSize(); + const int portNameSize = fData->engine->maxPortNameSize(); CarlaString portName; for (unsigned long i=0; i < portCount; i++) { - const LADSPA_PortDescriptor portType = descriptor->PortDescriptors[i]; - const LADSPA_PortRangeHint portHints = descriptor->PortRangeHints[i]; - const bool hasPortRDF = (rdf_descriptor && i < rdf_descriptor->PortCount); + const LADSPA_PortDescriptor portType = fDescriptor->PortDescriptors[i]; + const LADSPA_PortRangeHint portHints = fDescriptor->PortRangeHints[i]; + const bool hasPortRDF = (fRdfDescriptor && i < fRdfDescriptor->PortCount); if (LADSPA_IS_PORT_AUDIO(portType)) { @@ -430,38 +421,38 @@ public: if (processMode == PROCESS_MODE_SINGLE_CLIENT) { - portName = m_name; + portName = fData->name; portName += ":"; } - portName += descriptor->PortNames[i]; + portName += fDescriptor->PortNames[i]; portName.truncate(portNameSize); if (LADSPA_IS_PORT_INPUT(portType)) { - j = aIn.count++; - aIn.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, true); - aIn.rindexes[j] = i; + //j = fData->audioIn.count++; + //aIn.ports[j] = (CarlaEngineAudioPort*)fData->client->addPort(kEnginePortTypeAudio, portName, true); + //aIn.rindexes[j] = i; if (forcedStereoIn) { portName += "_2"; - aIn.ports[1] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, true); - aIn.rindexes[1] = i; + //aIn.ports[1] = (CarlaEngineAudioPort*)fData->client->addPort(kEnginePortTypeAudio, portName, true); + //aIn.rindexes[1] = i; } } else if (LADSPA_IS_PORT_OUTPUT(portType)) { - j = aOut.count++; - aOut.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, false); - aOut.rindexes[j] = i; + //j = aOut.count++; + //aOut.ports[j] = (CarlaEngineAudioPort*)fData->client->addPort(kEnginePortTypeAudio, portName, false); + //aOut.rindexes[j] = i; needsCtrlIn = true; if (forcedStereoOut) { portName += "_2"; - aOut.ports[1] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, false); - aOut.rindexes[1] = i; + //aOut.ports[1] = (CarlaEngineAudioPort*)x_client->addPort(CarlaEnginePortTypeAudio, portName, false); + //aOut.rindexes[1] = i; } } else @@ -469,14 +460,14 @@ public: } else if (LADSPA_IS_PORT_CONTROL(portType)) { - j = param.count++; - param.data[j].index = j; - param.data[j].rindex = i; - param.data[j].hints = 0; - param.data[j].midiChannel = 0; - param.data[j].midiCC = -1; + j = fData->param.count++; + fData->param.data[j].index = j; + fData->param.data[j].rindex = i; + fData->param.data[j].hints = 0; + fData->param.data[j].midiChannel = 0; + fData->param.data[j].midiCC = -1; - double min, max, def, step, stepSmall, stepLarge; + float min, max, def, step, stepSmall, stepLarge; // min value if (LADSPA_IS_HINT_BOUNDED_BELOW(portHints.HintDescriptor)) @@ -502,8 +493,8 @@ public: } // default value - if (hasPortRDF && LADSPA_PORT_HAS_DEFAULT(rdf_descriptor->Ports[i].Hints)) - def = rdf_descriptor->Ports[i].Default; + if (hasPortRDF && LADSPA_PORT_HAS_DEFAULT(fRdfDescriptor->Ports[i].Hints)) + def = fRdfDescriptor->Ports[i].Default; else def = get_default_ladspa_port_value(portHints.HintDescriptor, min, max); @@ -517,7 +508,7 @@ public: min *= sampleRate; max *= sampleRate; def *= sampleRate; - param.data[j].hints |= PARAMETER_USES_SAMPLERATE; + fData->param.data[j].hints |= PARAMETER_USES_SAMPLERATE; } if (LADSPA_IS_HINT_TOGGLED(portHints.HintDescriptor)) @@ -525,14 +516,14 @@ public: step = max - min; stepSmall = step; stepLarge = step; - param.data[j].hints |= PARAMETER_IS_BOOLEAN; + fData->param.data[j].hints |= PARAMETER_IS_BOOLEAN; } else if (LADSPA_IS_HINT_INTEGER(portHints.HintDescriptor)) { step = 1.0; stepSmall = 1.0; stepLarge = 10.0; - param.data[j].hints |= PARAMETER_IS_INTEGER; + fData->param.data[j].hints |= PARAMETER_IS_INTEGER; } else { @@ -544,14 +535,14 @@ public: if (LADSPA_IS_PORT_INPUT(portType)) { - param.data[j].type = PARAMETER_INPUT; - param.data[j].hints |= PARAMETER_IS_ENABLED; - param.data[j].hints |= PARAMETER_IS_AUTOMABLE; + fData->param.data[j].type = PARAMETER_INPUT; + fData->param.data[j].hints |= PARAMETER_IS_ENABLED; + fData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE; needsCtrlIn = true; } else if (LADSPA_IS_PORT_OUTPUT(portType)) { - if (strcmp(descriptor->PortNames[i], "latency") == 0 || strcmp(descriptor->PortNames[i], "_latency") == 0) + if (strcmp(fDescriptor->PortNames[i], "latency") == 0 || strcmp(fDescriptor->PortNames[i], "_latency") == 0) { min = 0.0; max = sampleRate; @@ -560,60 +551,62 @@ public: stepSmall = 1.0; stepLarge = 1.0; - param.data[j].type = PARAMETER_LATENCY; - param.data[j].hints = 0; + fData->param.data[j].type = PARAMETER_LATENCY; + fData->param.data[j].hints = 0; } - else if (strcmp(descriptor->PortNames[i], "_sample-rate") == 0) + else if (strcmp(fDescriptor->PortNames[i], "_sample-rate") == 0) { def = sampleRate; step = 1.0; stepSmall = 1.0; stepLarge = 1.0; - param.data[j].type = PARAMETER_SAMPLE_RATE; - param.data[j].hints = 0; + fData->param.data[j].type = PARAMETER_SAMPLE_RATE; + fData->param.data[j].hints = 0; } else { - param.data[j].type = PARAMETER_OUTPUT; - param.data[j].hints |= PARAMETER_IS_ENABLED; - param.data[j].hints |= PARAMETER_IS_AUTOMABLE; + fData->param.data[j].type = PARAMETER_OUTPUT; + fData->param.data[j].hints |= PARAMETER_IS_ENABLED; + fData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE; needsCtrlOut = true; } } else { - param.data[j].type = PARAMETER_UNKNOWN; + fData->param.data[j].type = PARAMETER_UNKNOWN; qWarning("WARNING - Got a broken Port (Control, but not input or output)"); } // extra parameter hints if (LADSPA_IS_HINT_LOGARITHMIC(portHints.HintDescriptor)) - param.data[j].hints |= PARAMETER_IS_LOGARITHMIC; + fData->param.data[j].hints |= PARAMETER_IS_LOGARITHMIC; // check for scalepoints, require at least 2 to make it useful - if (hasPortRDF && rdf_descriptor->Ports[i].ScalePointCount > 1) - param.data[j].hints |= PARAMETER_USES_SCALEPOINTS; + if (hasPortRDF && fRdfDescriptor->Ports[i].ScalePointCount > 1) + fData->param.data[j].hints |= PARAMETER_USES_SCALEPOINTS; - param.ranges[j].min = min; - param.ranges[j].max = max; - param.ranges[j].def = def; - param.ranges[j].step = step; - param.ranges[j].stepSmall = stepSmall; - param.ranges[j].stepLarge = stepLarge; + fData->param.ranges[j].min = min; + fData->param.ranges[j].max = max; + fData->param.ranges[j].def = def; + fData->param.ranges[j].step = step; + fData->param.ranges[j].stepSmall = stepSmall; + fData->param.ranges[j].stepLarge = stepLarge; // Start parameters in their default values - paramBuffers[j] = def; + fParamBuffers[j] = def; + + fDescriptor->connect_port(fHandle, i, &fParamBuffers[j]); - descriptor->connect_port(handle, i, ¶mBuffers[j]); - if (h2) descriptor->connect_port(h2, i, ¶mBuffers[j]); + if (fHandle2) + fDescriptor->connect_port(fHandle2, i, &fParamBuffers[j]); } else { // Not Audio or Control qCritical("ERROR - Got a broken Port (neither Audio or Control)"); - descriptor->connect_port(handle, i, nullptr); - if (h2) descriptor->connect_port(h2, i, nullptr); + fDescriptor->connect_port(fHandle, i, nullptr); + if (fHandle2) fDescriptor->connect_port(fHandle2, i, nullptr); } } @@ -623,14 +616,14 @@ public: if (processMode == PROCESS_MODE_SINGLE_CLIENT) { - portName = m_name; + portName = fData->name; portName += ":"; } portName += "control-in"; portName.truncate(portNameSize); - param.portCin = (CarlaEngineControlPort*)x_client->addPort(CarlaEnginePortTypeControl, portName, true); + //param.portCin = (CarlaEngineControlPort*)x_client->addPort(CarlaEnginePortTypeControl, portName, true); } if (needsCtrlOut) @@ -639,76 +632,77 @@ public: if (processMode == PROCESS_MODE_SINGLE_CLIENT) { - portName = m_name; + portName = fData->name; portName += ":"; } portName += "control-out"; portName.truncate(portNameSize); - param.portCout = (CarlaEngineControlPort*)x_client->addPort(CarlaEnginePortTypeControl, portName, false); + //param.portCout = (CarlaEngineControlPort*)x_client->addPort(CarlaEnginePortTypeControl, portName, false); } - aIn.count = aIns; - aOut.count = aOuts; - param.count = params; + //aIn.count = aIns; + //aOut.count = aOuts; + //param.count = params; // plugin checks - m_hints &= ~(PLUGIN_IS_SYNTH | PLUGIN_USES_CHUNKS | PLUGIN_CAN_DRYWET | PLUGIN_CAN_VOLUME | PLUGIN_CAN_BALANCE | PLUGIN_CAN_FORCE_STEREO); + fData->hints &= ~(PLUGIN_IS_SYNTH | PLUGIN_USES_CHUNKS | PLUGIN_CAN_DRYWET | PLUGIN_CAN_VOLUME | PLUGIN_CAN_BALANCE | PLUGIN_CAN_FORCE_STEREO); if (aOuts > 0 && (aIns == aOuts || aIns == 1)) - m_hints |= PLUGIN_CAN_DRYWET; + fData->hints |= PLUGIN_CAN_DRYWET; if (aOuts > 0) - m_hints |= PLUGIN_CAN_VOLUME; + fData->hints |= PLUGIN_CAN_VOLUME; if (aOuts >= 2 && aOuts%2 == 0) - m_hints |= PLUGIN_CAN_BALANCE; + fData->hints |= PLUGIN_CAN_BALANCE; if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0)) - m_hints |= PLUGIN_CAN_FORCE_STEREO; + fData->hints |= PLUGIN_CAN_FORCE_STEREO; +#if 0 // check latency - if (m_hints & PLUGIN_CAN_DRYWET) + if (fData->hints & PLUGIN_CAN_DRYWET) { bool hasLatency = false; - m_latency = 0; + fData->latency = 0; - for (uint32_t i=0; i < param.count; i++) + for (uint32_t i=0; i < fData->param.count; i++) { - if (param.data[i].type == PARAMETER_LATENCY) + if (fData->param.data[i].type == PARAMETER_LATENCY) { // pre-run so plugin can update latency control-port float tmpIn[2][aIns]; float tmpOut[2][aOuts]; - for (j=0; j < aIn.count; j++) + for (j=0; j < fData->audioIn.count; j++) { tmpIn[j][0] = 0.0f; tmpIn[j][1] = 0.0f; - if (j == 0 || ! h2) - descriptor->connect_port(handle, aIn.rindexes[j], tmpIn[j]); + //if (j == 0 || ! fHandle2) + // fDescriptor->connect_port(fHandle, fData->audioIn.rindexes[j], tmpIn[j]); } - for (j=0; j < aOut.count; j++) + for (j=0; j < fData->audioOut.count; j++) { tmpOut[j][0] = 0.0f; tmpOut[j][1] = 0.0f; - if (j == 0 || ! h2) - descriptor->connect_port(handle, aOut.rindexes[j], tmpOut[j]); + //if (j == 0 || ! fHandle2) + // fDescriptor->connect_port(fHandle, fData->audioOut.rindexes[j], tmpOut[j]); } - if (descriptor->activate) - descriptor->activate(handle); + if (fDescriptor->activate) + fDescriptor->activate(fHandle); - descriptor->run(handle, 2); + fDescriptor->run(fHandle, 2); - if (descriptor->deactivate) - descriptor->deactivate(handle); + if (fDescriptor->deactivate) + fDescriptor->deactivate(fHandle); - m_latency = rint(paramBuffers[i]); + fData->latency = rint(fParamBuffers[i]); hasLatency = true; break; } @@ -716,12 +710,13 @@ public: if (hasLatency) { - x_client->setLatency(m_latency); + fData->client->setLatency(fData->latency); recreateLatencyBuffers(); } } +#endif - x_client->activate(); + fData->client->activate(); qDebug("LadspaPlugin::reload() - end"); } @@ -741,9 +736,9 @@ public: // -------------------------------------------------------------------------------------------------------- // Input VU - if (aIn.count > 0 && x_engine->getOptions().processMode != PROCESS_MODE_CONTINUOUS_RACK) + if (fData->audioIn.count > 0 && fData->engine->getOptions().processMode != PROCESS_MODE_CONTINUOUS_RACK) { - if (aIn.count == 1) + if (fData->audioIn.count == 1) { for (k=0; k < frames; k++) { @@ -751,7 +746,7 @@ public: aInsPeak[0] = std::abs(inBuffer[0][k]); } } - else if (aIn.count > 1) + else if (fData->audioIn.count > 1) { for (k=0; k < frames; k++) { @@ -769,14 +764,15 @@ public: // -------------------------------------------------------------------------------------------------------- // Parameters Input [Automation] - if (param.portCin && m_active && m_activeBefore) +#if 0 + //if (param.portCin && m_active && m_activeBefore) { - const CarlaEngineControlEvent* cinEvent; - uint32_t time, nEvents = param.portCin->getEventCount(); + const EngineEvent* cinEvent = nullptr; + uint32_t time, nEvents = 0; //param.portCin->getEventCount(); for (i=0; i < nEvents; i++) { - cinEvent = param.portCin->getEvent(i); + //cinEvent = param.portCin->getEvent(i); if (! cinEvent) continue; @@ -789,7 +785,7 @@ public: // Control change switch (cinEvent->type) { - case CarlaEngineNullEvent: + case kEngineControlEventTypeNull: break; case CarlaEngineParameterChangeEvent: @@ -883,16 +879,16 @@ public: case CarlaEngineAllSoundOffEvent: if (cinEvent->channel == m_ctrlInChannel) { - if (descriptor->deactivate) + if (fDescriptor->deactivate) { - descriptor->deactivate(handle); - if (h2) descriptor->deactivate(h2); + descriptor->deactivate(fHandle); + if (fHandle2) descriptor->deactivate(fHandle2); } - if (descriptor->activate) + if (fDescriptor->activate) { - descriptor->activate(handle); - if (h2) descriptor->activate(h2); + descriptor->activate(fHandle); + if (fHandle2) descriptor->activate(fHandle2); } postponeEvent(PluginPostEventParameterChange, PARAMETER_ACTIVE, 0, 0.0); @@ -907,6 +903,7 @@ public: } // End of Parameters Input CARLA_PROCESS_CONTINUE_CHECK; +#endif // -------------------------------------------------------------------------------------------------------- // Special Parameters @@ -926,46 +923,54 @@ public: // -------------------------------------------------------------------------------------------------------- // Plugin processing - if (m_active) + if (fData->active) { - if (! m_activeBefore) + if (! fData->activeBefore) { - if (m_latency > 0) +#if 0 + if (fData->latency > 0) { - for (i=0; i < aIn.count; i++) - memset(m_latencyBuffers[i], 0, sizeof(float)*m_latency); + for (i=0; i < fData->audioIn.count; i++) + memset(fData->latencyBuffers[i], 0, sizeof(float)*fData->latency); } +#endif - if (descriptor->activate) + if (fDescriptor->activate) { - descriptor->activate(handle); - if (h2) descriptor->activate(h2); + fDescriptor->activate(fHandle); + if (fHandle2) fDescriptor->activate(fHandle2); } } +#if 0 for (i=0; i < aIn.count; i++) { - if (i == 0 || ! h2) descriptor->connect_port(handle, aIn.rindexes[i], inBuffer[i]); - else if (i == 1) descriptor->connect_port(h2, aIn.rindexes[i], inBuffer[i]); + if (i == 0 || ! fHandle2) + fDescriptor->connect_port(fHandle, aIn.rindexes[i], inBuffer[i]); + else if (i == 1) + fDescriptor->connect_port(fHandle2, aIn.rindexes[i], inBuffer[i]); } for (i=0; i < aOut.count; i++) { - if (i == 0 || ! h2) descriptor->connect_port(handle, aOut.rindexes[i], outBuffer[i]); - else if (i == 1) descriptor->connect_port(h2, aOut.rindexes[i], outBuffer[i]); + if (i == 0 || ! fHandle2) + fDescriptor->connect_port(handle, aOut.rindexes[i], outBuffer[i]); + else if (i == 1) + fDescriptor->connect_port(fHandle2, aOut.rindexes[i], outBuffer[i]); } +#endif - descriptor->run(handle, frames); - if (h2) descriptor->run(h2, frames); + fDescriptor->run(fHandle, frames); + if (fHandle2) fDescriptor->run(fHandle2, frames); } else { - if (m_activeBefore) + if (fData->activeBefore) { - if (descriptor->deactivate) + if (fDescriptor->deactivate) { - descriptor->deactivate(handle); - if (h2) descriptor->deactivate(h2); + fDescriptor->deactivate(fHandle); + if (fHandle2) fDescriptor->deactivate(fHandle2); } } } @@ -975,11 +980,12 @@ public: // -------------------------------------------------------------------------------------------------------- // Post-processing (dry/wet, volume and balance) - if (m_active) +#if 0 + if (fData->active) { - bool do_drywet = (m_hints & PLUGIN_CAN_DRYWET) > 0 && x_dryWet != 1.0; - bool do_volume = (m_hints & PLUGIN_CAN_VOLUME) > 0 && x_volume != 1.0; - bool do_balance = (m_hints & PLUGIN_CAN_BALANCE) > 0 && (x_balanceLeft != -1.0 || x_balanceRight != 1.0); + bool do_drywet = (fData->hints & PLUGIN_CAN_DRYWET) > 0 && x_dryWet != 1.0; + bool do_volume = (fData->hints & PLUGIN_CAN_VOLUME) > 0 && x_volume != 1.0; + bool do_balance = (fData->hints & PLUGIN_CAN_BALANCE) > 0 && (x_balanceLeft != -1.0 || x_balanceRight != 1.0); double bal_rangeL, bal_rangeR; float bufValue, oldBufLeft[do_balance ? frames : 1]; @@ -992,7 +998,7 @@ public: for (k=0; k < frames; k++) { if (k < m_latency && m_latency < frames) - bufValue = (aIn.count == 1) ? m_latencyBuffers[0][k] : m_latencyBuffers[i][k]; + bufValue = (aIn.count == 1) ? fData->latencyBuffers[0][k] : fData->latencyBuffers[i][k]; else bufValue = (aIn.count == 1) ? inBuffer[0][k-m_latency] : inBuffer[i][k-m_latency]; @@ -1034,7 +1040,7 @@ public: } // Output VU - if (x_engine->getOptions().processMode != PROCESS_MODE_CONTINUOUS_RACK) + if (fData->engine->getOptions().processMode != PROCESS_MODE_CONTINUOUS_RACK) { for (k=0; i < 2 && k < frames; k++) { @@ -1045,10 +1051,10 @@ public: } // Latency, save values for next callback - if (m_latency > 0 && m_latency < frames) + if (fData->latency > 0 && fData->latency < frames) { for (i=0; i < aIn.count; i++) - memcpy(m_latencyBuffers[i], inBuffer[i] + (frames - m_latency), sizeof(float)*m_latency); + memcpy(fData->latencyBuffers[i], inBuffer[i] + (frames - fData->latency), sizeof(float)*fData->latency); } } else @@ -1061,12 +1067,14 @@ public: aOutsPeak[1] = 0.0; } // End of Post-processing +#endif CARLA_PROCESS_CONTINUE_CHECK; // -------------------------------------------------------------------------------------------------------- // Control Output +#if 0 if (param.portCout && m_active) { double value; @@ -1085,18 +1093,19 @@ public: } } } // End of Control Output +#endif CARLA_PROCESS_CONTINUE_CHECK; // -------------------------------------------------------------------------------------------------------- // Peak Values - x_engine->setInputPeak(m_id, 0, aInsPeak[0]); - x_engine->setInputPeak(m_id, 1, aInsPeak[1]); - x_engine->setOutputPeak(m_id, 0, aOutsPeak[0]); - x_engine->setOutputPeak(m_id, 1, aOutsPeak[1]); + //fData->engine->setInputPeak(fData->id, 0, aInsPeak[0]); + //fData->engine->setInputPeak(fData->id, 1, aInsPeak[1]); + //fData->engine->setOutputPeak(fData->id, 0, aOutsPeak[0]); + //fData->engine->setOutputPeak(fData->id, 1, aOutsPeak[1]); - m_activeBefore = m_active; + fData->activeBefore = fData->active; } // ------------------------------------------------------------------- @@ -1106,10 +1115,10 @@ public: { qDebug("LadspaPlugin::deleteBuffers() - start"); - if (param.count > 0) - delete[] paramBuffers; + if (fData->param.count > 0) + delete[] fParamBuffers; - paramBuffers = nullptr; + fParamBuffers = nullptr; CarlaPlugin::deleteBuffers(); @@ -1118,14 +1127,14 @@ public: // ------------------------------------------------------------------- - bool init(const char* const filename, const char* const name, const char* const label, const LADSPA_RDF_Descriptor* const rdf_descriptor_) + bool init(const char* const filename, const char* const name, const char* const label, const LADSPA_RDF_Descriptor* const rdfDescriptor) { // --------------------------------------------------------------- // open DLL if (! libOpen(filename)) { - x_engine->setLastError(libError(filename)); + fData->engine->setLastError(libError(filename)); return false; } @@ -1136,7 +1145,7 @@ public: if (! descFn) { - x_engine->setLastError("Could not find the LASDPA Descriptor in the plugin library"); + fData->engine->setLastError("Could not find the LASDPA Descriptor in the plugin library"); return false; } @@ -1144,52 +1153,52 @@ public: // get descriptor that matches label unsigned long i = 0; - while ((descriptor = descFn(i++))) + while ((fDescriptor = descFn(i++))) { - if (strcmp(descriptor->Label, label) == 0) + if (strcmp(fDescriptor->Label, label) == 0) break; } - if (! descriptor) + if (! fDescriptor) { - x_engine->setLastError("Could not find the requested plugin Label in the plugin library"); + fData->engine->setLastError("Could not find the requested plugin Label in the plugin library"); return false; } // --------------------------------------------------------------- // get info - m_filename = strdup(filename); + fData->filename = strdup(filename); - if (is_ladspa_rdf_descriptor_valid(rdf_descriptor_, descriptor)) - rdf_descriptor = ladspa_rdf_dup(rdf_descriptor_); + if (is_ladspa_rdf_descriptor_valid(rdfDescriptor, fDescriptor)) + fRdfDescriptor = ladspa_rdf_dup(rdfDescriptor); if (name) - m_name = x_engine->getUniquePluginName(name); - else if (rdf_descriptor && rdf_descriptor->Title) - m_name = x_engine->getUniquePluginName(rdf_descriptor->Title); + fData->name = fData->engine->getNewUniquePluginName(name); + else if (fRdfDescriptor && fRdfDescriptor->Title) + fData->name = fData->engine->getNewUniquePluginName(fRdfDescriptor->Title); else - m_name = x_engine->getUniquePluginName(descriptor->Name); + fData->name = fData->engine->getNewUniquePluginName(fDescriptor->Name); // --------------------------------------------------------------- // register client - x_client = x_engine->addClient(this); + fData->client = fData->engine->addClient(this); - if (! x_client->isOk()) + if (! fData->client->isOk()) { - x_engine->setLastError("Failed to register plugin client"); + fData->engine->setLastError("Failed to register plugin client"); return false; } // --------------------------------------------------------------- // initialize plugin - handle = descriptor->instantiate(descriptor, x_engine->getSampleRate()); + fHandle = fDescriptor->instantiate(fDescriptor, fData->engine->getSampleRate()); - if (! handle) + if (! fHandle) { - x_engine->setLastError("Plugin failed to initialize"); + fData->engine->setLastError("Plugin failed to initialize"); return false; } @@ -1197,15 +1206,14 @@ public: } private: - LADSPA_Handle handle, h2; - const LADSPA_Descriptor* descriptor; - const LADSPA_RDF_Descriptor* rdf_descriptor; + LADSPA_Handle fHandle; + LADSPA_Handle fHandle2; + const LADSPA_Descriptor* fDescriptor; + const LADSPA_RDF_Descriptor* fRdfDescriptor; - float* paramBuffers; + float* fParamBuffers; }; -/**@}*/ - CARLA_BACKEND_END_NAMESPACE #else // WANT_LADSPA @@ -1214,22 +1222,14 @@ CARLA_BACKEND_END_NAMESPACE CARLA_BACKEND_START_NAMESPACE -CarlaPlugin* CarlaPlugin::newLADSPA(const initializer& init, const void* const extra) +CarlaPlugin* CarlaPlugin::newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* const rdfDescriptor) { - qDebug("CarlaPlugin::newLADSPA({%p, \"%s\", \"%s\", \"%s\"}, %p)", init.engine, init.filename, init.name, init.label, extra); + qDebug("CarlaPlugin::newLADSPA({%p, \"%s\", \"%s\", \"%s\"}, %p)", init.engine, init.filename, init.name, init.label, rdfDescriptor); #ifdef WANT_LADSPA - short id = init.engine->getNewPluginId(); - - if (id < 0 || id > init.engine->maxPluginNumber()) - { - init.engine->setLastError("Maximum number of plugins reached"); - return nullptr; - } - - LadspaPlugin* const plugin = new LadspaPlugin(init.engine, id); + LadspaPlugin* const plugin = new LadspaPlugin(init.engine, init.id); - if (! plugin->init(init.filename, init.name, init.label, (const LADSPA_RDF_Descriptor*)extra)) + if (! plugin->init(init.filename, init.name, init.label, rdfDescriptor)) { delete plugin; return nullptr; diff --git a/source/bridges/carla_bridge_client.hpp b/source/bridges/carla_bridge_client.hpp index 19fcc3fa8..975aa8509 100644 --- a/source/bridges/carla_bridge_client.hpp +++ b/source/bridges/carla_bridge_client.hpp @@ -59,7 +59,7 @@ public: // --------------------------------------------------------------------- // processing - virtual void setParameter(const int32_t rindex, const double value) = 0; + virtual void setParameter(const int32_t rindex, const float value) = 0; virtual void setProgram(const uint32_t index) = 0; #ifdef BUILD_BRIDGE_PLUGIN virtual void setMidiProgram(const uint32_t index) = 0; diff --git a/source/bridges/carla_bridge_plugin.cpp b/source/bridges/carla_bridge_plugin.cpp index 652f5c219..7a5a45531 100644 --- a/source/bridges/carla_bridge_plugin.cpp +++ b/source/bridges/carla_bridge_plugin.cpp @@ -628,7 +628,7 @@ public: // --------------------------------------------------------------------- // processing - void setParameter(const int32_t rindex, const double value) + void setParameter(const int32_t rindex, const float value) { qDebug("CarlaPluginClient::setParameter(%i, %g)", rindex, value); CARLA_ASSERT(plugin); @@ -799,7 +799,7 @@ public: // --------------------------------------------------------------------- // callback - static void callback(void* const ptr, CarlaBackend::CallbackType const action, const unsigned int, const int value1, const int value2, const double value3, const char* const valueStr) + static void callback(void* ptr, CarlaBackend::CallbackType action, unsigned int, int value1, int value2, float value3, const char* valueStr) { CARLA_ASSERT(ptr); diff --git a/source/bridges/qtcreator/carla-bridge-plugin.pro b/source/bridges/qtcreator/carla-bridge-plugin.pro index f976c834e..bd4ea24be 100644 --- a/source/bridges/qtcreator/carla-bridge-plugin.pro +++ b/source/bridges/qtcreator/carla-bridge-plugin.pro @@ -34,9 +34,10 @@ SOURCES += \ # carla-plugin SOURCES += \ - ../../backend/plugin/carla_plugin.cpp + ../../backend/plugin/carla_plugin.cpp \ + ../../backend/plugin/ladspa.cpp + # ../../backend/plugin/carla_plugin_thread.cpp \ -# ../../backend/plugin/ladspa.cpp \ # ../../backend/plugin/dssi.cpp \ # ../../backend/plugin/lv2.cpp \ # ../../backend/plugin/vst.cpp diff --git a/source/utils/carla_utils.hpp b/source/utils/carla_utils.hpp index 7aadc2c64..f6724dc3b 100644 --- a/source/utils/carla_utils.hpp +++ b/source/utils/carla_utils.hpp @@ -141,6 +141,17 @@ const T& carla_min(const T& v1, const T& v2, const T& min) return ((v1 < min || v2 < min) ? min : (v1 < v2 ? v1 : v2)); } +template +static inline +const T& carla_fixValue(const T& min, const T& max, const T& value) +{ + if (value < min) + return min; + if (value > max) + return max; + return value; +} + template static inline void carla_fill(T* data, const unsigned int size, const T v) diff --git a/source/utils/rt_list.hpp b/source/utils/rt_list.hpp index 486d0b11f..3c0f396a2 100644 --- a/source/utils/rt_list.hpp +++ b/source/utils/rt_list.hpp @@ -29,9 +29,11 @@ extern "C" { // Declare non copyable and prevent heap allocation #define LIST_DECLARATIONS(className) \ className(const className&); \ - className& operator= (const className&); \ - static void* operator new (size_t); \ - static void operator delete (void*); \ + className& operator= (const className&); + +// FIXME +//static void* operator new (size_t); +//static void operator delete (void*); typedef struct list_head k_list_head; @@ -303,7 +305,7 @@ private: rtsafe_memory_pool_deallocate(fMemPool, dataPtr); } - //LIST_DECLARATIONS(RtList) + LIST_DECLARATIONS(RtList) }; template @@ -329,7 +331,7 @@ private: free(dataPtr); } - //LIST_DECLARATIONS(NonRtList) + LIST_DECLARATIONS(NonRtList) }; template @@ -355,7 +357,7 @@ private: delete dataPtr; } - //LIST_DECLARATIONS(NonRtListNew) + LIST_DECLARATIONS(NonRtListNew) }; // -----------------------------------------------------------------------