From 3b6d54acdc477aa2e3bda7e8b975e8abf109bac9 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 18 Mar 2014 16:07:25 +0000 Subject: [PATCH] More work --- source/backend/CarlaEngine.hpp | 16 +- source/backend/engine/CarlaEngine.cpp | 164 +++++++-------- source/backend/engine/CarlaEngineInternal.cpp | 194 ++++++++---------- source/backend/engine/CarlaEngineInternal.hpp | 21 +- source/backend/engine/CarlaEngineJack.cpp | 76 ++++--- source/backend/engine/CarlaEngineJuce.cpp | 2 - source/backend/engine/CarlaEngineRtAudio.cpp | 100 +++++---- source/modules/jackbridge/JackBridge.hpp | 2 + source/modules/jackbridge/JackBridge1.cpp | 13 +- 9 files changed, 305 insertions(+), 283 deletions(-) diff --git a/source/backend/CarlaEngine.hpp b/source/backend/CarlaEngine.hpp index a64e0628b..7548fd4da 100644 --- a/source/backend/CarlaEngine.hpp +++ b/source/backend/CarlaEngine.hpp @@ -584,7 +584,7 @@ public: * Add a new port of type \a portType. * \note This function does nothing in rack processing mode since ports are static there (2 audio + 1 event for both input and output). */ - virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput) noexcept; + virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput); #ifndef DOXYGEN protected: @@ -623,7 +623,7 @@ public: * The decontructor. * The engine must have been closed before this happens. */ - virtual ~CarlaEngine(); + virtual ~CarlaEngine() noexcept; // ------------------------------------------------------------------- // Static calls @@ -1069,7 +1069,7 @@ protected: // ------------------------------------------------------------------- -private: +public: /*! * Native audio APIs. */ @@ -1094,6 +1094,7 @@ private: // JACK static CarlaEngine* newJack(); +#ifndef BUILD_BRIDGE // RtAudio static CarlaEngine* newRtAudio(const AudioApi api); static uint getRtAudioApiCount(); @@ -1107,15 +1108,15 @@ private: static const char* getJuceApiName(const uint index); static const char* const* getJuceApiDeviceNames(const uint index); static const EngineDriverDeviceInfo* getJuceDeviceInfo(const uint index, const char* const deviceName); - -#ifdef BUILD_BRIDGE -public: +#else // Bridge - static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName, const char* const timeBaseName); + static CarlaEngine* newBridge(const char* const audioBaseName, const char* const controlBaseName, const char* const timeBaseName); +#endif // ------------------------------------------------------------------- // Bridge/Controller OSC stuff +#ifdef BUILD_BRIDGE void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept; void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept; void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept; @@ -1140,7 +1141,6 @@ public: void oscSend_bridge_set_peaks() const noexcept; void oscSend_bridge_pong() const noexcept; #else -public: void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept; void oscSend_control_add_plugin_end(const uint pluginId) const noexcept; void oscSend_control_remove_plugin(const uint pluginId) const noexcept; diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 22f69ce62..af719e52f 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -30,9 +30,10 @@ #include "CarlaBackendUtils.hpp" #include "CarlaEngineUtils.hpp" #include "CarlaMathUtils.hpp" +#include "CarlaMIDI.h" #include "CarlaStateUtils.hpp" -#include "CarlaMIDI.h" +#include "jackbridge/JackBridge.hpp" #include #include @@ -438,9 +439,6 @@ bool CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t CARLA_SAFE_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(param)); } - // FIXME? should not fix range if midi-program - const float fixedValue(carla_fixValue(0.0f, 1.0f, value)); - for (uint32_t i=0; i < kMaxEngineEventInternalCount; ++i) { EngineEvent& event(fBuffer[i]); @@ -454,7 +452,7 @@ bool CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t event.ctrl.type = type; event.ctrl.param = param; - event.ctrl.value = fixedValue; + event.ctrl.value = carla_fixValue(0.0f, 1.0f, value); return true; } @@ -569,30 +567,22 @@ void CarlaEngineClient::setLatency(const uint32_t samples) noexcept fLatency = samples; } -CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput) noexcept +CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput) { CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr); carla_debug("CarlaEngineClient::addPort(%i:%s, \"%s\", %s)", portType, EnginePortType2Str(portType), name, bool2str(isInput)); - CarlaEnginePort* ret = nullptr; - - try { - switch (portType) - { - case kEnginePortTypeNull: - break; - case kEnginePortTypeAudio: - ret = new CarlaEngineAudioPort(fEngine, isInput); - case kEnginePortTypeCV: - ret = new CarlaEngineCVPort(fEngine, isInput); - case kEnginePortTypeEvent: - ret = new CarlaEngineEventPort(fEngine, isInput); - } + switch (portType) + { + case kEnginePortTypeNull: + break; + case kEnginePortTypeAudio: + return new CarlaEngineAudioPort(fEngine, isInput); + case kEnginePortTypeCV: + return new CarlaEngineCVPort(fEngine, isInput); + case kEnginePortTypeEvent: + return new CarlaEngineEventPort(fEngine, isInput); } - CARLA_SAFE_EXCEPTION_RETURN("new CarlaEnginePort", nullptr); - - if (ret != nullptr) - return ret; carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput)); return nullptr; @@ -607,7 +597,7 @@ CarlaEngine::CarlaEngine() carla_debug("CarlaEngine::CarlaEngine()"); } -CarlaEngine::~CarlaEngine() +CarlaEngine::~CarlaEngine() noexcept { carla_debug("CarlaEngine::~CarlaEngine()"); @@ -617,11 +607,14 @@ CarlaEngine::~CarlaEngine() // ----------------------------------------------------------------------- // Static calls -unsigned int CarlaEngine::getDriverCount() +uint CarlaEngine::getDriverCount() { carla_debug("CarlaEngine::getDriverCount()"); - unsigned int count = 1; // JACK + uint count = 0; + + if (jackbridge_is_ok()) + count += 1; #ifndef BUILD_BRIDGE count += getRtAudioApiCount(); @@ -633,24 +626,24 @@ unsigned int CarlaEngine::getDriverCount() return count; } -const char* CarlaEngine::getDriverName(const unsigned int index) +const char* CarlaEngine::getDriverName(const uint index2) { - carla_debug("CarlaEngine::getDriverName(%i)", index); + carla_debug("CarlaEngine::getDriverName(%i)", index2); + + uint index(index2); - if (index == 0) + if (jackbridge_is_ok() && index-- == 0) return "JACK"; #ifndef BUILD_BRIDGE - const unsigned int rtAudioIndex(index-1); + if (index < getRtAudioApiCount()) + return getRtAudioApiName(index); - if (rtAudioIndex < getRtAudioApiCount()) - return getRtAudioApiName(rtAudioIndex); + index -= getRtAudioApiCount(); # ifdef HAVE_JUCE - const unsigned int juceIndex(index-rtAudioIndex-1); - - if (juceIndex < getJuceApiCount()) - return getJuceApiName(juceIndex); + if (index < getJuceApiCount()) + return getJuceApiName(index); # endif #endif @@ -658,27 +651,27 @@ const char* CarlaEngine::getDriverName(const unsigned int index) return nullptr; } -const char* const* CarlaEngine::getDriverDeviceNames(const unsigned int index) +const char* const* CarlaEngine::getDriverDeviceNames(const uint index2) { - carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index); + carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index2); + + uint index(index2); - if (index == 0) // JACK + if (jackbridge_is_ok() && index-- == 0) { static const char* ret[3] = { "Auto-Connect OFF", "Auto-Connect ON", nullptr }; return ret; } #ifndef BUILD_BRIDGE - const unsigned int rtAudioIndex(index-1); + if (index < getRtAudioApiCount()) + return getRtAudioApiDeviceNames(index); - if (rtAudioIndex < getRtAudioApiCount()) - return getRtAudioApiDeviceNames(rtAudioIndex); + index -= getRtAudioApiCount(); # ifdef HAVE_JUCE - const unsigned int juceIndex(index-rtAudioIndex-1); - - if (juceIndex < getJuceApiCount()) - return getJuceApiDeviceNames(juceIndex); + if (index < getJuceApiCount()) + return getJuceApiDeviceNames(index); # endif #endif @@ -686,11 +679,13 @@ const char* const* CarlaEngine::getDriverDeviceNames(const unsigned int index) return nullptr; } -const EngineDriverDeviceInfo* CarlaEngine::getDriverDeviceInfo(const unsigned int index, const char* const deviceName) +const EngineDriverDeviceInfo* CarlaEngine::getDriverDeviceInfo(const uint index2, const char* const deviceName) { - carla_debug("CarlaEngine::getDriverDeviceInfo(%i, \"%s\")", index, deviceName); + carla_debug("CarlaEngine::getDriverDeviceInfo(%i, \"%s\")", index2, deviceName); + + uint index(index2); - if (index == 0) // JACK + if (jackbridge_is_ok() && index-- == 0) { static uint32_t bufSizes[11] = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 0 }; static EngineDriverDeviceInfo devInfo; @@ -701,16 +696,14 @@ const EngineDriverDeviceInfo* CarlaEngine::getDriverDeviceInfo(const unsigned in } #ifndef BUILD_BRIDGE - const unsigned int rtAudioIndex(index-1); + if (index < getRtAudioApiCount()) + return getRtAudioDeviceInfo(index, deviceName); - if (rtAudioIndex < getRtAudioApiCount()) - return getRtAudioDeviceInfo(rtAudioIndex, deviceName); + index -= getRtAudioApiCount(); # ifdef HAVE_JUCE - const unsigned int juceIndex(index-rtAudioIndex-1); - - if (juceIndex < getJuceApiCount()) - return getJuceDeviceInfo(juceIndex, deviceName); + if (index < getJuceApiCount()) + return getJuceDeviceInfo(index, deviceName); # endif #endif @@ -789,22 +782,22 @@ CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName) // ----------------------------------------------------------------------- // Maximum values -unsigned int CarlaEngine::getMaxClientNameSize() const noexcept +uint CarlaEngine::getMaxClientNameSize() const noexcept { return STR_MAX/2; } -unsigned int CarlaEngine::getMaxPortNameSize() const noexcept +uint CarlaEngine::getMaxPortNameSize() const noexcept { return STR_MAX; } -unsigned int CarlaEngine::getCurrentPluginCount() const noexcept +uint CarlaEngine::getCurrentPluginCount() const noexcept { return pData->curPluginCount; } -unsigned int CarlaEngine::getMaxPluginNumber() const noexcept +uint CarlaEngine::getMaxPluginNumber() const noexcept { return pData->maxPluginNumber; } @@ -924,17 +917,8 @@ bool CarlaEngine::close() pData->plugins = nullptr; } - if (pData->events.in != nullptr) - { - delete[] pData->events.in; - pData->events.in = nullptr; - } - - if (pData->events.out != nullptr) - { - delete[] pData->events.out; - pData->events.out = nullptr; - } + pData->events.clear(); + pData->audio.clear(); pData->name.clear(); @@ -949,7 +933,7 @@ void CarlaEngine::idle() CARLA_SAFE_ASSERT_RETURN(pData->nextPluginId == pData->maxPluginNumber,); // TESTING, remove later CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr,); // this one too maybe - for (unsigned int i=0; i < pData->curPluginCount; ++i) + for (uint i=0; i < pData->curPluginCount; ++i) { CarlaPlugin* const plugin(pData->plugins[i].plugin); @@ -978,7 +962,7 @@ bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, cons CARLA_SAFE_ASSERT_RETURN_ERR((filename != nullptr && filename[0] != '\0') || (label != nullptr && label[0] != '\0'), "Invalid plugin params (err #3)"); carla_debug("CarlaEngine::addPlugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p)", btype, BinaryType2Str(btype), ptype, PluginType2Str(ptype), filename, name, label, uniqueId, extra); - unsigned int id; + uint id; CarlaPlugin* oldPlugin = nullptr; if (pData->nextPluginId < pData->curPluginCount) @@ -1229,7 +1213,7 @@ bool CarlaEngine::addPlugin(const PluginType ptype, const char* const filename, return addPlugin(BINARY_NATIVE, ptype, filename, name, label, uniqueId, extra); } -bool CarlaEngine::removePlugin(const unsigned int id) +bool CarlaEngine::removePlugin(const uint id) { CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #14)"); CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #15)"); @@ -1278,7 +1262,7 @@ bool CarlaEngine::removeAllPlugins() callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr); - for (unsigned int i=0; i < pData->maxPluginNumber; ++i) + for (uint i=0; i < pData->maxPluginNumber; ++i) { EnginePluginData& pluginData(pData->plugins[i]); @@ -1302,7 +1286,7 @@ bool CarlaEngine::removeAllPlugins() return true; } -const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName) +const char* CarlaEngine::renamePlugin(const uint id, const char* const newName) { CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #21)"); CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #22)"); @@ -1326,7 +1310,7 @@ const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const n return nullptr; } -bool CarlaEngine::clonePlugin(const unsigned int id) +bool CarlaEngine::clonePlugin(const uint id) { CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #25)"); CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #26)"); @@ -1343,7 +1327,7 @@ bool CarlaEngine::clonePlugin(const unsigned int id) carla_zeroChar(label, STR_MAX+1); plugin->getLabel(label); - const unsigned int pluginCountBefore(pData->curPluginCount); + const uint pluginCountBefore(pData->curPluginCount); if (! addPlugin(plugin->getBinaryType(), plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getUniqueId(), plugin->getExtraStuff())) return false; @@ -1356,7 +1340,7 @@ bool CarlaEngine::clonePlugin(const unsigned int id) return true; } -bool CarlaEngine::replacePlugin(const unsigned int id) +bool CarlaEngine::replacePlugin(const uint id) { CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #29)"); CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #30)"); @@ -1382,7 +1366,7 @@ bool CarlaEngine::replacePlugin(const unsigned int id) return true; } -bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB) +bool CarlaEngine::switchPlugins(const uint idA, const uint idB) { CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #33)"); CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount >= 2, "Invalid engine internal data (err #34)"); @@ -1416,7 +1400,7 @@ bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB) return true; } -CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const +CarlaPlugin* CarlaEngine::getPlugin(const uint id) const { CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #38)"); CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #39)"); @@ -1426,7 +1410,7 @@ CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const return pData->plugins[id].plugin; } -CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const noexcept +CarlaPlugin* CarlaEngine::getPluginUnchecked(const uint id) const noexcept { return pData->plugins[id].plugin; } @@ -1454,7 +1438,7 @@ const char* CarlaEngine::getUniquePluginName(const char* const name) const sname.truncate(maxNameSize); sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names - for (unsigned short i=0; i < pData->curPluginCount; ++i) + for (uint i=0; i < pData->curPluginCount; ++i) { CARLA_SAFE_ASSERT_BREAK(pData->plugins[i].plugin != nullptr); @@ -1836,7 +1820,7 @@ bool CarlaEngine::saveProject(const char* const filename) // ----------------------------------------------------------------------- // Information (base) -unsigned int CarlaEngine::getHints() const noexcept +uint CarlaEngine::getHints() const noexcept { return pData->hints; } @@ -1874,14 +1858,14 @@ const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept // ----------------------------------------------------------------------- // Information (peaks) -float CarlaEngine::getInputPeak(const unsigned int pluginId, const bool isLeft) const noexcept +float CarlaEngine::getInputPeak(const uint pluginId, const bool isLeft) const noexcept { CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f); return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1]; } -float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) const noexcept +float CarlaEngine::getOutputPeak(const uint pluginId, const bool isLeft) const noexcept { CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f); @@ -1891,7 +1875,7 @@ float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) // ----------------------------------------------------------------------- // Callback -void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept +void CarlaEngine::callback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept { carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr); @@ -2186,7 +2170,7 @@ EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexc return isInput ? pData->events.in : pData->events.out; } -void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) noexcept +void CarlaEngine::registerEnginePlugin(const uint id, CarlaPlugin* const plugin) noexcept { CARLA_SAFE_ASSERT_RETURN(id == pData->curPluginCount,); carla_debug("CarlaEngine::registerEnginePlugin(%i, %p)", id, plugin); @@ -2254,7 +2238,7 @@ void CarlaEngine::runPendingRtEvents() noexcept } } -void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept +void CarlaEngine::setPluginPeaks(const uint pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept { EnginePluginData& pluginData(pData->plugins[pluginId]); diff --git a/source/backend/engine/CarlaEngineInternal.cpp b/source/backend/engine/CarlaEngineInternal.cpp index 41f07fc60..5d1eb06af 100644 --- a/source/backend/engine/CarlaEngineInternal.cpp +++ b/source/backend/engine/CarlaEngineInternal.cpp @@ -172,59 +172,59 @@ bool RackGraph::disconnect(CarlaEngine* const engine, const uint connectionId) n if (connection.id == connectionId) { -#if 0 - const int otherPort((connection.portOut >= 0) ? connection.portOut : connection.portIn); - const int carlaPort((otherPort == connection.portOut) ? connection.portIn : connection.portOut); + int carlaPort, otherPort; - if (otherPort >= RACK_PATCHBAY_GROUP_MIDI_OUT*1000) + if (connection.groupA == RACK_PATCHBAY_GROUP_CARLA) { - CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_MIDI_IN, false); - - const int portId(otherPort-RACK_PATCHBAY_GROUP_MIDI_OUT*1000); - disconnectRackMidiInPort(portId); + carlaPort = connection.portA; + otherPort = connection.portB; } - else if (otherPort >= RACK_PATCHBAY_GROUP_MIDI_IN*1000) + else { - CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_MIDI_OUT, false); + CARLA_SAFE_ASSERT_RETURN(connection.groupB == RACK_PATCHBAY_GROUP_CARLA, false); - const int portId(otherPort-RACK_PATCHBAY_GROUP_MIDI_IN*1000); - disconnectRackMidiOutPort(portId); + carlaPort = connection.portB; + otherPort = connection.portA; } - else if (otherPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000) - { - CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT2, false); - - const int portId(otherPort-RACK_PATCHBAY_GROUP_AUDIO_OUT*1000); + switch (carlaPort) + { + case RACK_PATCHBAY_CARLA_PORT_AUDIO_IN1: connectLock.enter(); + connectedIn1.removeAll(otherPort); + connectLock.leave(); + break; - if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1) - connectedOut1.removeAll(portId); - else - connectedOut2.removeAll(portId); - + case RACK_PATCHBAY_CARLA_PORT_AUDIO_IN2: + connectLock.enter(); + connectedIn2.removeAll(otherPort); connectLock.leave(); - } - else if (otherPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000) - { - CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN2, false); + break; - const int portId(otherPort-RACK_PATCHBAY_GROUP_AUDIO_IN*1000); + case RACK_PATCHBAY_CARLA_PORT_AUDIO_OUT1: + connectLock.enter(); + connectedOut1.removeAll(otherPort); + connectLock.leave(); + break; + case RACK_PATCHBAY_CARLA_PORT_AUDIO_OUT2: connectLock.enter(); + connectedOut2.removeAll(otherPort); + connectLock.leave(); + break; - if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1) - connectedIn1.removeAll(portId); - else - connectedIn2.removeAll(portId); + case RACK_PATCHBAY_CARLA_PORT_MIDI_IN: + engine->disconnectRackMidiInPort(otherPort); + break; - connectLock.leave(); - } - else - { - CARLA_SAFE_ASSERT_RETURN(false, false); + case RACK_PATCHBAY_CARLA_PORT_MIDI_OUT: + engine->disconnectRackMidiOutPort(otherPort); + break; + + default: + engine->setLastError("Invalid connection"); + return false; } -#endif engine->callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED, connection.id, 0, 0, 0.0f, nullptr); @@ -237,76 +237,63 @@ bool RackGraph::disconnect(CarlaEngine* const engine, const uint connectionId) n return false; } -void RackGraph::refresh(CarlaEngine* const engine, const LinkedList& /*midiIns*/, const LinkedList& /*midiOuts*/) noexcept +void RackGraph::refresh(CarlaEngine* const engine, const char* const deviceName, const LinkedList& /*midiIns*/, const LinkedList& /*midiOuts*/) noexcept { CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); -#if 0 - CARLA_SAFE_ASSERT_RETURN(pData->audio.isReady, false); - - fUsedMidiIns.clear(); - fUsedMidiOuts.clear(); - - pData->audio.initPatchbay(); - - if (! pData->audio.isRack) - { - // not implemented yet - return false; - } + lastConnectionId = 0; + usedConnections.clear(); char strBuf[STR_MAX+1]; strBuf[STR_MAX] = '\0'; - AbstractEngineBuffer* const rack(pData->audio.buffer); - // Main { - callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_CARLA, PATCHBAY_ICON_CARLA, -1, 0.0f, getName()); - - callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_AUDIO_IN1, PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT, 0.0f, "audio-in1"); - callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_AUDIO_IN2, PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT, 0.0f, "audio-in2"); - callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_AUDIO_OUT1, PATCHBAY_PORT_TYPE_AUDIO, 0.0f, "audio-out1"); - callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_AUDIO_OUT2, PATCHBAY_PORT_TYPE_AUDIO, 0.0f, "audio-out2"); - callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_MIDI_IN, PATCHBAY_PORT_TYPE_MIDI|PATCHBAY_PORT_IS_INPUT, 0.0f, "midi-in"); - callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_MIDI_OUT, PATCHBAY_PORT_TYPE_MIDI, 0.0f, "midi-out"); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_CARLA, PATCHBAY_ICON_CARLA, -1, 0.0f, engine->getName()); + + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_AUDIO_IN1, PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT, 0.0f, "audio-in1"); + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_AUDIO_IN2, PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT, 0.0f, "audio-in2"); + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_AUDIO_OUT1, PATCHBAY_PORT_TYPE_AUDIO, 0.0f, "audio-out1"); + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_AUDIO_OUT2, PATCHBAY_PORT_TYPE_AUDIO, 0.0f, "audio-out2"); + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_MIDI_IN, PATCHBAY_PORT_TYPE_MIDI|PATCHBAY_PORT_IS_INPUT, 0.0f, "midi-in"); + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_CARLA, RACK_PATCHBAY_CARLA_PORT_MIDI_OUT, PATCHBAY_PORT_TYPE_MIDI, 0.0f, "midi-out"); } // Audio In { - if (fDeviceName.isNotEmpty()) - std::snprintf(strBuf, STR_MAX, "Capture (%s)", fDeviceName.buffer()); + if (deviceName != nullptr) + std::snprintf(strBuf, STR_MAX, "Capture (%s)", deviceName); else std::strncpy(strBuf, "Capture", STR_MAX); - callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_AUDIO, PATCHBAY_ICON_HARDWARE, -1, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_AUDIO, PATCHBAY_ICON_HARDWARE, -1, 0.0f, strBuf); for (uint i=0; i < pData->audio.inCount; ++i) { std::snprintf(strBuf, STR_MAX, "capture_%i", i+1); - callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_AUDIO, static_cast(i), PATCHBAY_PORT_TYPE_AUDIO, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_AUDIO, static_cast(i), PATCHBAY_PORT_TYPE_AUDIO, 0.0f, strBuf); } } // Audio Out { - if (fDeviceName.isNotEmpty()) - std::snprintf(strBuf, STR_MAX, "Playback (%s)", fDeviceName.buffer()); + if (deviceName != nullptr) + std::snprintf(strBuf, STR_MAX, "Playback (%s)", deviceName); else std::strncpy(strBuf, "Playback", STR_MAX); - callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_AUDIO, PATCHBAY_ICON_HARDWARE, -1, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_AUDIO, PATCHBAY_ICON_HARDWARE, -1, 0.0f, strBuf); for (uint i=0; i < pData->audio.outCount; ++i) { std::snprintf(strBuf, STR_MAX, "playback_%i", i+1); - callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_AUDIO, static_cast(i), PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_AUDIO, static_cast(i), PATCHBAY_PORT_TYPE_AUDIO|PATCHBAY_PORT_IS_INPUT, 0.0f, strBuf); } } // MIDI In { - callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_MIDI, PATCHBAY_ICON_HARDWARE, -1, 0.0f, "Readable MIDI ports"); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_MIDI, PATCHBAY_ICON_HARDWARE, -1, 0.0f, "Readable MIDI ports"); for (uint i=0, count=fDummyMidiIn.getPortCount(); i < count; ++i) { @@ -316,13 +303,13 @@ void RackGraph::refresh(CarlaEngine* const engine, const LinkedListcallback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_MIDI, portNameToId.portId, PATCHBAY_PORT_TYPE_MIDI, 0.0f, portNameToId.name); } } // MIDI Out { - callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_MIDI, PATCHBAY_ICON_HARDWARE, -1, 0.0f, "Writable MIDI ports"); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_MIDI, PATCHBAY_ICON_HARDWARE, -1, 0.0f, "Writable MIDI ports"); for (uint i=0, count=fDummyMidiOut.getPortCount(); i < count; ++i) { @@ -332,107 +319,107 @@ void RackGraph::refresh(CarlaEngine* const engine, const LinkedListcallback(ENGINE_CALLBACK_PATCHBAY_PORT_ADDED, RACK_PATCHBAY_GROUP_MIDI, portNameToId.portId, PATCHBAY_PORT_TYPE_MIDI|PATCHBAY_PORT_IS_INPUT, 0.0f, portNameToId.name); } } // Connections - rack->connectLock.enter(); + connectLock.enter(); - for (LinkedList::Itenerator it = rack->connectedIn1.begin(); it.valid(); it.next()) + for (LinkedList::Itenerator it = connectedIn1.begin(); it.valid(); it.next()) { const int& port(it.getValue()); CARLA_SAFE_ASSERT_CONTINUE(port >= 0 && port < static_cast(pData->audio.inCount)); ConnectionToId connectionToId; - connectionToId.id = rack->lastConnectionId; + connectionToId.id = lastConnectionId; connectionToId.groupOut = RACK_PATCHBAY_GROUP_AUDIO; connectionToId.portOut = port; connectionToId.groupIn = RACK_PATCHBAY_GROUP_CARLA; connectionToId.portIn = RACK_PATCHBAY_CARLA_PORT_AUDIO_IN1; std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupOut, connectionToId.portOut, connectionToId.groupIn, connectionToId.portIn); - callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, 0, 0, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, lastConnectionId, 0, 0, 0.0f, strBuf); - rack->usedConnections.append(connectionToId); - ++rack->lastConnectionId; + usedConnections.append(connectionToId); + ++lastConnectionId; } - for (LinkedList::Itenerator it = rack->connectedIn2.begin(); it.valid(); it.next()) + for (LinkedList::Itenerator it = connectedIn2.begin(); it.valid(); it.next()) { const int& port(it.getValue()); CARLA_SAFE_ASSERT_CONTINUE(port >= 0 && port < static_cast(pData->audio.inCount)); ConnectionToId connectionToId; - connectionToId.id = rack->lastConnectionId; + connectionToId.id = lastConnectionId; connectionToId.groupOut = RACK_PATCHBAY_GROUP_AUDIO; connectionToId.portOut = port; connectionToId.groupIn = RACK_PATCHBAY_GROUP_CARLA; connectionToId.portIn = RACK_PATCHBAY_CARLA_PORT_AUDIO_IN2; std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupOut, connectionToId.portOut, connectionToId.groupIn, connectionToId.portIn); - callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, 0, 0, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, lastConnectionId, 0, 0, 0.0f, strBuf); - rack->usedConnections.append(connectionToId); - ++rack->lastConnectionId; + usedConnections.append(connectionToId); + ++lastConnectionId; } - for (LinkedList::Itenerator it = rack->connectedOut1.begin(); it.valid(); it.next()) + for (LinkedList::Itenerator it = connectedOut1.begin(); it.valid(); it.next()) { const int& port(it.getValue()); CARLA_SAFE_ASSERT_CONTINUE(port >= 0 && port < static_cast(pData->audio.outCount)); ConnectionToId connectionToId; - connectionToId.id = rack->lastConnectionId; + connectionToId.id = lastConnectionId; connectionToId.groupOut = RACK_PATCHBAY_GROUP_CARLA; connectionToId.portOut = RACK_PATCHBAY_CARLA_PORT_AUDIO_OUT1; connectionToId.groupIn = RACK_PATCHBAY_GROUP_AUDIO; connectionToId.portIn = port; std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupOut, connectionToId.portOut, connectionToId.groupIn, connectionToId.portIn); - callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, 0, 0, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, lastConnectionId, 0, 0, 0.0f, strBuf); - rack->usedConnections.append(connectionToId); - ++rack->lastConnectionId; + usedConnections.append(connectionToId); + ++lastConnectionId; } - for (LinkedList::Itenerator it = rack->connectedOut2.begin(); it.valid(); it.next()) + for (LinkedList::Itenerator it = connectedOut2.begin(); it.valid(); it.next()) { const int& port(it.getValue()); CARLA_SAFE_ASSERT_CONTINUE(port >= 0 && port < static_cast(pData->audio.outCount)); ConnectionToId connectionToId; - connectionToId.id = rack->lastConnectionId; + connectionToId.id = lastConnectionId; connectionToId.groupOut = RACK_PATCHBAY_GROUP_CARLA; connectionToId.portOut = RACK_PATCHBAY_CARLA_PORT_AUDIO_OUT2; connectionToId.groupIn = RACK_PATCHBAY_GROUP_AUDIO; connectionToId.portIn = port; std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupOut, connectionToId.portOut, connectionToId.groupIn, connectionToId.portIn); - callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, 0, 0, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, lastConnectionId, 0, 0, 0.0f, strBuf); - rack->usedConnections.append(connectionToId); - ++rack->lastConnectionId; + usedConnections.append(connectionToId); + ++lastConnectionId; } - pData->audio.rack->connectLock.leave(); + connectLock.leave(); for (LinkedList::Itenerator it=fMidiIns.begin(); it.valid(); it.next()) { const MidiPort& midiPort(it.getValue()); ConnectionToId connectionToId; - connectionToId.id = rack->lastConnectionId; + connectionToId.id = lastConnectionId; connectionToId.groupOut = RACK_PATCHBAY_GROUP_MIDI; connectionToId.portOut = midiPort.portId; connectionToId.groupIn = RACK_PATCHBAY_GROUP_CARLA; connectionToId.portIn = RACK_PATCHBAY_CARLA_PORT_MIDI_IN; std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupOut, connectionToId.portOut, connectionToId.groupIn, connectionToId.portIn); - callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, 0, 0, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, lastConnectionId, 0, 0, 0.0f, strBuf); - rack->usedConnections.append(connectionToId); - ++rack->lastConnectionId; + usedConnections.append(connectionToId); + ++lastConnectionId; } for (LinkedList::Itenerator it=fMidiOuts.begin(); it.valid(); it.next()) @@ -440,18 +427,19 @@ void RackGraph::refresh(CarlaEngine* const engine, const LinkedListlastConnectionId; + connectionToId.id = lastConnectionId; connectionToId.groupOut = RACK_PATCHBAY_GROUP_CARLA; connectionToId.portOut = RACK_PATCHBAY_CARLA_PORT_MIDI_OUT; connectionToId.groupIn = RACK_PATCHBAY_GROUP_MIDI; connectionToId.portIn = midiPort.portId; std::snprintf(strBuf, STR_MAX, "%i:%i:%i:%i", connectionToId.groupOut, connectionToId.portOut, connectionToId.groupIn, connectionToId.portIn); - callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, 0, 0, 0.0f, strBuf); + engine->callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, lastConnectionId, 0, 0, 0.0f, strBuf); - rack->usedConnections.append(connectionToId); - ++rack->lastConnectionId; + usedConnections.append(connectionToId); + ++lastConnectionId; } +#if 0 #endif } diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index 5537e6799..770ee2459 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -280,6 +280,21 @@ struct EngineInternalEvents { CARLA_SAFE_ASSERT(out == nullptr); } + void clear() noexcept + { + if (in != nullptr) + { + delete[] in; + in = nullptr; + } + + if (out != nullptr) + { + delete[] out; + out = nullptr; + } + } + CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalEvents) }; @@ -432,11 +447,13 @@ struct CarlaEngineProtectedData { EnginePluginData* plugins; -//#ifndef BUILD_BRIDGE +#ifndef BUILD_BRIDGE EngineInternalAudio audio; -//#endif +#endif EngineInternalEvents events; +#ifndef BUILD_BRIDGE EngineInternalGraph graph; +#endif EngineInternalTime time; EngineNextAction nextAction; diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index 178594783..61d4deba9 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -457,60 +457,56 @@ public: } #endif - CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput) noexcept override + CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput) override { - carla_debug("CarlaEngineJackClient::addPort(%s, \"%s\", %s)", EnginePortType2Str(portType), name, bool2str(isInput)); + carla_debug("CarlaEngineJackClient::addPort(%i:%s, \"%s\", %s)", portType, EnginePortType2Str(portType), name, bool2str(isInput)); jack_port_t* port = nullptr; // Create JACK port first, if needed if (fUseClient && fClient != nullptr) { - try { - switch (portType) - { - case kEnginePortTypeNull: - break; - case kEnginePortTypeAudio: - port = jackbridge_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); - break; - case kEnginePortTypeCV: - port = jackbridge_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); - break; - case kEnginePortTypeEvent: - port = jackbridge_port_register(fClient, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); - break; - } - } - CARLA_SAFE_EXCEPTION_RETURN("JackClient addPort", nullptr) - } - - // Create Engine port - try { switch (portType) { case kEnginePortTypeNull: break; - case kEnginePortTypeAudio: { - CarlaEngineJackAudioPort* const enginePort(new CarlaEngineJackAudioPort(fEngine, isInput, fClient, port)); - fAudioPorts.append(enginePort); - return enginePort; - } - case kEnginePortTypeCV: { - CarlaEngineJackCVPort* const enginePort(new CarlaEngineJackCVPort(fEngine, isInput, fClient, port)); - fCVPorts.append(enginePort); - return enginePort; - } - case kEnginePortTypeEvent: { - CarlaEngineJackEventPort* const enginePort(new CarlaEngineJackEventPort(fEngine, isInput, fClient, port)); - fEventPorts.append(enginePort); - return enginePort; - } + case kEnginePortTypeAudio: + port = jackbridge_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); + break; + case kEnginePortTypeCV: + port = jackbridge_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); + break; + case kEnginePortTypeEvent: + port = jackbridge_port_register(fClient, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); + break; } + + CARLA_SAFE_ASSERT_RETURN(port != nullptr, nullptr); + } + + // Create Engine port + switch (portType) + { + case kEnginePortTypeNull: + break; + case kEnginePortTypeAudio: { + CarlaEngineJackAudioPort* const enginePort(new CarlaEngineJackAudioPort(fEngine, isInput, fClient, port)); + fAudioPorts.append(enginePort); + return enginePort; + } + case kEnginePortTypeCV: { + CarlaEngineJackCVPort* const enginePort(new CarlaEngineJackCVPort(fEngine, isInput, fClient, port)); + fCVPorts.append(enginePort); + return enginePort; + } + case kEnginePortTypeEvent: { + CarlaEngineJackEventPort* const enginePort(new CarlaEngineJackEventPort(fEngine, isInput, fClient, port)); + fEventPorts.append(enginePort); + return enginePort; + } } - CARLA_SAFE_EXCEPTION_RETURN("JackClient new Port", nullptr) - carla_stderr("CarlaEngineJackClient::addPort(%s, \"%s\", %s) - invalid type", EnginePortType2Str(portType), name, bool2str(isInput)); + carla_stderr("CarlaEngineJackClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput)); return nullptr; } diff --git a/source/backend/engine/CarlaEngineJuce.cpp b/source/backend/engine/CarlaEngineJuce.cpp index b1353cfe3..fc67f1d0b 100644 --- a/source/backend/engine/CarlaEngineJuce.cpp +++ b/source/backend/engine/CarlaEngineJuce.cpp @@ -184,8 +184,6 @@ public: fDevice = nullptr; } - pData->audio.clear(); - return !hasError; } diff --git a/source/backend/engine/CarlaEngineRtAudio.cpp b/source/backend/engine/CarlaEngineRtAudio.cpp index 2fc02ab73..e0d812868 100644 --- a/source/backend/engine/CarlaEngineRtAudio.cpp +++ b/source/backend/engine/CarlaEngineRtAudio.cpp @@ -62,7 +62,7 @@ static void initRtApis() } } -static const char* getRtAudioApiName(const RtAudio::Api api) +static const char* getRtAudioApiName(const RtAudio::Api api) noexcept { switch (api) { @@ -98,7 +98,7 @@ static const char* getRtAudioApiName(const RtAudio::Api api) return nullptr; } -static RtMidi::Api getMatchedAudioMidiAPi(const RtAudio::Api rtApi) +static RtMidi::Api getMatchedAudioMidiAPi(const RtAudio::Api rtApi) noexcept { switch (rtApi) { @@ -138,16 +138,14 @@ static RtMidi::Api getMatchedAudioMidiAPi(const RtAudio::Api rtApi) // ------------------------------------------------------------------------------------------------------------------- // Cleanup -static struct RtAudioCleanup { +static const struct RtAudioCleanup { RtAudioCleanup() {} - ~RtAudioCleanup() - { + ~RtAudioCleanup() { if (gRetNames != nullptr) { delete[] gRetNames; gRetNames = nullptr; } - gRtAudioApis.clear(); } } sRtAudioCleanup; @@ -202,7 +200,7 @@ public: RtAudio::StreamParameters iParams, oParams; bool deviceSet = false; - const unsigned int devCount(fAudio.getDeviceCount()); + const uint devCount(fAudio.getDeviceCount()); if (devCount == 0) { @@ -212,13 +210,13 @@ public: if (pData->options.audioDevice != nullptr && pData->options.audioDevice[0] != '\0') { - for (unsigned int i=0; i < devCount; ++i) + for (uint i=0; i < devCount; ++i) { RtAudio::DeviceInfo devInfo(fAudio.getDeviceInfo(i)); if (devInfo.probed && devInfo.outputChannels > 0 && devInfo.name == pData->options.audioDevice) { - deviceSet = true; + deviceSet = true; fDeviceName = devInfo.name.c_str(); iParams.deviceId = i; oParams.deviceId = i; @@ -255,13 +253,12 @@ public: fLastEventTime = 0; - unsigned int bufferFrames = pData->options.audioBufferSize; + uint bufferFrames = pData->options.audioBufferSize; try { fAudio.openStream(&oParams, &iParams, RTAUDIO_FLOAT32, pData->options.audioSampleRate, &bufferFrames, carla_rtaudio_process_callback, this, &rtOptions); } - catch (const RtError& e) - { + catch (const RtError& e) { setLastError(e.what()); return false; } @@ -278,16 +275,30 @@ public: { fAudioBufIn = new float*[pData->audio.inCount]; + // set as null first for (uint i=0; i < pData->audio.inCount; ++i) + fAudioBufIn[i] = nullptr; + + for (uint i=0; i < pData->audio.inCount; ++i) + { fAudioBufIn[i] = new float[pData->bufferSize]; + FLOAT_CLEAR(fAudioBufIn[i], pData->bufferSize); + } } if (pData->audio.outCount > 0) { fAudioBufOut = new float*[pData->audio.outCount]; + // set as null first for (uint i=0; i < pData->audio.outCount; ++i) + fAudioBufOut[i] = nullptr; + + for (uint i=0; i < pData->audio.outCount; ++i) + { fAudioBufOut[i] = new float[pData->bufferSize]; + FLOAT_CLEAR(fAudioBufOut[i], pData->bufferSize); + } } pData->audio.create(pData->bufferSize); @@ -340,7 +351,13 @@ public: if (fAudioBufIn != nullptr) { for (uint i=0; i < pData->audio.inCount; ++i) - delete[] fAudioBufIn[i]; + { + if (fAudioBufIn[i] != nullptr) + { + delete[] fAudioBufIn[i]; + fAudioBufIn[i] = nullptr; + } + } delete[] fAudioBufIn; fAudioBufIn = nullptr; @@ -349,16 +366,18 @@ public: if (fAudioBufOut != nullptr) { for (uint i=0; i < pData->audio.outCount; ++i) - delete[] fAudioBufOut[i]; + { + if (fAudioBufOut[i] != nullptr) + { + delete[] fAudioBufOut[i]; + fAudioBufOut[i] = nullptr; + } + } delete[] fAudioBufOut; fAudioBufOut = nullptr; } - pData->audio.clear(); - - fDeviceName.clear(); - for (LinkedList::Itenerator it = fMidiIns.begin(); it.valid(); it.next()) { MidiPort& port(it.getValue()); @@ -376,6 +395,8 @@ public: delete midiOutPort; } + fDeviceName.clear(); + fMidiIns.clear(); fMidiOuts.clear(); @@ -410,13 +431,18 @@ public: bool patchbayRefresh() override { + CARLA_SAFE_ASSERT_RETURN(pData->audio.isReady, false); + + fUsedMidiIns.clear(); + fUsedMidiOuts.clear(); + return true; } // ------------------------------------------------------------------- protected: - void handleAudioProcessCallback(void* outputBuffer, void* inputBuffer, unsigned int nframes, double streamTime, RtAudioStreamStatus status) + void handleAudioProcessCallback(void* outputBuffer, void* inputBuffer, uint nframes, double streamTime, RtAudioStreamStatus status) { // get buffers from RtAudio float* const insPtr = (float*)inputBuffer; @@ -432,7 +458,7 @@ protected: // initialize rtaudio input if (fIsAudioInterleaved) { - for (unsigned int i=0, j=0, count=nframes*pData->audio.inCount; i < count; ++i) + for (uint i=0, j=0, count=nframes*pData->audio.inCount; i < count; ++i) { fAudioBufIn[i/pData->audio.inCount][j] = insPtr[i]; @@ -442,12 +468,12 @@ protected: } else { - for (unsigned int i=0; i < pData->audio.inCount; ++i) + for (uint i=0; i < pData->audio.inCount; ++i) FLOAT_COPY(fAudioBufIn[i], insPtr+(nframes*i), nframes); } // initialize rtaudio output - for (unsigned int i=0; i < pData->audio.outCount; ++i) + for (uint i=0; i < pData->audio.outCount; ++i) FLOAT_CLEAR(fAudioBufOut[i], nframes); // initialize input events @@ -495,7 +521,7 @@ protected: // output audio if (fIsAudioInterleaved) { - for (unsigned int i=0, j=0; i < nframes*pData->audio.outCount; ++i) + for (uint i=0, j=0; i < nframes*pData->audio.outCount; ++i) { outsPtr[i] = fAudioBufOut[i/pData->audio.outCount][j]; @@ -505,7 +531,7 @@ protected: } else { - for (unsigned int i=0; i < pData->audio.outCount; ++i) + for (uint i=0; i < pData->audio.outCount; ++i) FLOAT_COPY(outsPtr+(nframes*i), fAudioBufOut[i], nframes); } @@ -523,7 +549,7 @@ protected: (void)status; } - void handleMidiCallback(double timeStamp, std::vector* const message) + void handleMidiCallback(double timeStamp, std::vector* const message) { if (! pData->audio.isReady) return; @@ -781,13 +807,13 @@ private: #define handlePtr ((CarlaEngineRtAudio*)userData) - static int carla_rtaudio_process_callback(void* outputBuffer, void* inputBuffer, unsigned int nframes, double streamTime, RtAudioStreamStatus status, void* userData) + static int carla_rtaudio_process_callback(void* outputBuffer, void* inputBuffer, uint nframes, double streamTime, RtAudioStreamStatus status, void* userData) { handlePtr->handleAudioProcessCallback(outputBuffer, inputBuffer, nframes, streamTime, status); return 0; } - static void carla_rtmidi_callback(double timeStamp, std::vector* message, void* userData) + static void carla_rtmidi_callback(double timeStamp, std::vector* message, void* userData) { handlePtr->handleMidiCallback(timeStamp, message); } @@ -799,7 +825,7 @@ private: // ----------------------------------------- -CarlaEngine* CarlaEngine::newRtAudio(AudioApi api) +CarlaEngine* CarlaEngine::newRtAudio(const AudioApi api) { initRtApis(); @@ -836,14 +862,14 @@ CarlaEngine* CarlaEngine::newRtAudio(AudioApi api) return new CarlaEngineRtAudio(rtApi); } -unsigned int CarlaEngine::getRtAudioApiCount() +uint CarlaEngine::getRtAudioApiCount() { initRtApis(); - return static_cast(gRtAudioApis.size()); + return static_cast(gRtAudioApis.size()); } -const char* CarlaEngine::getRtAudioApiName(const unsigned int index) +const char* CarlaEngine::getRtAudioApiName(const uint index) { initRtApis(); @@ -853,7 +879,7 @@ const char* CarlaEngine::getRtAudioApiName(const unsigned int index) return CarlaBackend::getRtAudioApiName(gRtAudioApis[index]); } -const char* const* CarlaEngine::getRtAudioApiDeviceNames(const unsigned int index) +const char* const* CarlaEngine::getRtAudioApiDeviceNames(const uint index) { initRtApis(); @@ -864,14 +890,14 @@ const char* const* CarlaEngine::getRtAudioApiDeviceNames(const unsigned int inde RtAudio rtAudio(api); - const unsigned int devCount(rtAudio.getDeviceCount()); + const uint devCount(rtAudio.getDeviceCount()); if (devCount == 0) return nullptr; LinkedList devNames; - for (unsigned int i=0; i < devCount; ++i) + for (uint i=0; i < devCount; ++i) { RtAudio::DeviceInfo devInfo(rtAudio.getDeviceInfo(i)); @@ -899,7 +925,7 @@ const char* const* CarlaEngine::getRtAudioApiDeviceNames(const unsigned int inde return gRetNames; } -const EngineDriverDeviceInfo* CarlaEngine::getRtAudioDeviceInfo(const unsigned int index, const char* const deviceName) +const EngineDriverDeviceInfo* CarlaEngine::getRtAudioDeviceInfo(const uint index, const char* const deviceName) { initRtApis(); @@ -910,12 +936,12 @@ const EngineDriverDeviceInfo* CarlaEngine::getRtAudioDeviceInfo(const unsigned i RtAudio rtAudio(api); - const unsigned int devCount(rtAudio.getDeviceCount()); + const uint devCount(rtAudio.getDeviceCount()); if (devCount == 0) return nullptr; - unsigned int i; + uint i; RtAudio::DeviceInfo rtAudioDevInfo; for (i=0; i < devCount; ++i) diff --git a/source/modules/jackbridge/JackBridge.hpp b/source/modules/jackbridge/JackBridge.hpp index 142b973b1..a27dfd77e 100644 --- a/source/modules/jackbridge/JackBridge.hpp +++ b/source/modules/jackbridge/JackBridge.hpp @@ -263,6 +263,8 @@ typedef void (*JackPropertyChangeCallback)(jack_uuid_t subject, const char* key, #endif // ! JACKBRIDGE_DIRECT +bool jackbridge_is_ok() noexcept; + CARLA_EXPORT void jackbridge_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr); CARLA_EXPORT const char* jackbridge_get_version_string(); diff --git a/source/modules/jackbridge/JackBridge1.cpp b/source/modules/jackbridge/JackBridge1.cpp index ea0d97abb..799d720b9 100644 --- a/source/modules/jackbridge/JackBridge1.cpp +++ b/source/modules/jackbridge/JackBridge1.cpp @@ -484,12 +484,23 @@ struct JackBridge { } }; -static JackBridge bridge; +static const JackBridge bridge; #endif // ! JACKBRIDGE_DIRECT // ----------------------------------------------------------------------------- +bool jackbridge_is_ok() noexcept +{ +#if defined(JACKBRIDGE_DUMMY) || defined(JACKBRIDGE_DIRECT) + return true; +#else + return (bridge.lib != nullptr); +#endif +} + +// ----------------------------------------------------------------------------- + void jackbridge_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr) { #if defined(JACKBRIDGE_DUMMY)