From ba85fd13a42b55c6653db593dc9583542b33461f Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 17 Jul 2014 09:45:16 +0100 Subject: [PATCH] Fix engine build with strict flags; Put some common code in utils --- source/backend/engine/CarlaEngine.cpp | 1 - source/backend/engine/CarlaEngineGraph.cpp | 229 ++++++------------- source/backend/engine/CarlaEngineGraph.hpp | 6 +- source/backend/engine/CarlaEngineJack.cpp | 42 ++-- source/backend/engine/CarlaEngineJuce.cpp | 8 +- source/backend/engine/CarlaEngineNative.cpp | 4 +- source/backend/engine/CarlaEngineRtAudio.cpp | 2 +- source/utils/CarlaEngineUtils.hpp | 82 +++++++ 8 files changed, 176 insertions(+), 198 deletions(-) diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index e90ba7c8a..4a57c3040 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -21,7 +21,6 @@ * - implement oscSend_control_switch_plugins() * - proper find&load plugins * - something about the peaks? - * - patchbayDisconnect should return false sometimes */ #include "CarlaEngineInternal.hpp" diff --git a/source/backend/engine/CarlaEngineGraph.cpp b/source/backend/engine/CarlaEngineGraph.cpp index d814e162c..ca8e47d1c 100644 --- a/source/backend/engine/CarlaEngineGraph.cpp +++ b/source/backend/engine/CarlaEngineGraph.cpp @@ -142,6 +142,8 @@ RackGraph::~RackGraph() noexcept void RackGraph::setBufferSize(const uint32_t bufferSize) noexcept { + const int bufferSizei(static_cast(bufferSize)); + if (audio.inBuf[0] != nullptr) { delete[] audio.inBuf[0]; audio.inBuf[0] = nullptr; } if (audio.inBuf[1] != nullptr) { delete[] audio.inBuf[1]; audio.inBuf[1] = nullptr; } if (audio.inBufTmp[0] != nullptr) { delete[] audio.inBufTmp[0]; audio.inBufTmp[0] = nullptr; } @@ -175,15 +177,15 @@ void RackGraph::setBufferSize(const uint32_t bufferSize) noexcept return; } - FloatVectorOperations::clear(audio.inBufTmp[0], bufferSize); - FloatVectorOperations::clear(audio.inBufTmp[1], bufferSize); + FloatVectorOperations::clear(audio.inBufTmp[0], bufferSizei); + FloatVectorOperations::clear(audio.inBufTmp[1], bufferSizei); if (inputs > 0 || outputs > 0) { - FloatVectorOperations::clear(audio.inBuf[0], bufferSize); - FloatVectorOperations::clear(audio.inBuf[1], bufferSize); - FloatVectorOperations::clear(audio.outBuf[0], bufferSize); - FloatVectorOperations::clear(audio.outBuf[1], bufferSize); + FloatVectorOperations::clear(audio.inBuf[0], bufferSizei); + FloatVectorOperations::clear(audio.inBuf[1], bufferSizei); + FloatVectorOperations::clear(audio.outBuf[0], bufferSizei); + FloatVectorOperations::clear(audio.outBuf[1], bufferSizei); } } @@ -524,18 +526,20 @@ void RackGraph::process(CarlaEngine::ProtectedData* const data, const float* inB CARLA_SAFE_ASSERT_RETURN(data->events.in != nullptr,); CARLA_SAFE_ASSERT_RETURN(data->events.out != nullptr,); + const int iframes(static_cast(frames)); + // safe copy float inBuf0[frames]; float inBuf1[frames]; float* inBuf[2] = { inBuf0, inBuf1 }; // initialize audio inputs - FloatVectorOperations::copy(inBuf0, inBufReal[0], frames); - FloatVectorOperations::copy(inBuf1, inBufReal[1], frames); + FloatVectorOperations::copy(inBuf0, inBufReal[0], iframes); + FloatVectorOperations::copy(inBuf1, inBufReal[1], iframes); // initialize audio outputs (zero) - FloatVectorOperations::clear(outBuf[0], frames); - FloatVectorOperations::clear(outBuf[1], frames); + FloatVectorOperations::clear(outBuf[0], iframes); + FloatVectorOperations::clear(outBuf[1], iframes); // initialize event outputs (zero) carla_zeroStruct(data->events.out, kMaxEngineEventInternalCount); @@ -556,12 +560,12 @@ void RackGraph::process(CarlaEngine::ProtectedData* const data, const float* inB if (processed) { // initialize audio inputs (from previous outputs) - FloatVectorOperations::copy(inBuf0, outBuf[0], frames); - FloatVectorOperations::copy(inBuf1, outBuf[1], frames); + FloatVectorOperations::copy(inBuf0, outBuf[0], iframes); + FloatVectorOperations::copy(inBuf1, outBuf[1], iframes); // initialize audio outputs (zero) - FloatVectorOperations::clear(outBuf[0], frames); - FloatVectorOperations::clear(outBuf[1], frames); + FloatVectorOperations::clear(outBuf[0], iframes); + FloatVectorOperations::clear(outBuf[1], iframes); // if plugin has no midi out, add previous events if (oldMidiOutCount == 0 && data->events.in[0].type != kEngineEventTypeNull) @@ -593,8 +597,8 @@ void RackGraph::process(CarlaEngine::ProtectedData* const data, const float* inB // if plugin has no audio inputs, add input buffer if (oldAudioInCount == 0) { - FloatVectorOperations::add(outBuf[0], inBuf0, frames); - FloatVectorOperations::add(outBuf[1], inBuf1, frames); + FloatVectorOperations::add(outBuf[0], inBuf0, iframes); + FloatVectorOperations::add(outBuf[1], inBuf1, iframes); } // set peaks @@ -605,10 +609,10 @@ void RackGraph::process(CarlaEngine::ProtectedData* const data, const float* inB if (oldAudioInCount > 0) { - range = FloatVectorOperations::findMinAndMax(inBuf0, static_cast(frames)); + range = FloatVectorOperations::findMinAndMax(inBuf0, iframes); pluginData.insPeak[0] = carla_max(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f); - range = FloatVectorOperations::findMinAndMax(inBuf1, static_cast(frames)); + range = FloatVectorOperations::findMinAndMax(inBuf1, iframes); pluginData.insPeak[1] = carla_max(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f); } else @@ -619,10 +623,10 @@ void RackGraph::process(CarlaEngine::ProtectedData* const data, const float* inB if (plugin->getAudioOutCount() > 0) { - range = FloatVectorOperations::findMinAndMax(outBuf[0], static_cast(frames)); + range = FloatVectorOperations::findMinAndMax(outBuf[0], iframes); pluginData.outsPeak[0] = carla_max(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f); - range = FloatVectorOperations::findMinAndMax(outBuf[1], static_cast(frames)); + range = FloatVectorOperations::findMinAndMax(outBuf[1], iframes); pluginData.outsPeak[1] = carla_max(std::abs(range.getStart()), std::abs(range.getEnd()), 1.0f); } else @@ -640,6 +644,8 @@ void RackGraph::processHelper(CarlaEngine::ProtectedData* const data, const floa { CARLA_SAFE_ASSERT_RETURN(audio.outBuf[1] != nullptr,); + const int iframes(static_cast(frames)); + const CarlaRecursiveMutexLocker _cml(audio.mutex); if (inBuf != nullptr && inputs > 0) @@ -654,17 +660,17 @@ void RackGraph::processHelper(CarlaEngine::ProtectedData* const data, const floa if (noConnections) { - FloatVectorOperations::copy(audio.inBuf[0], inBuf[port], frames); + FloatVectorOperations::copy(audio.inBuf[0], inBuf[port], iframes); noConnections = false; } else { - FloatVectorOperations::add(audio.inBuf[0], inBuf[port], frames); + FloatVectorOperations::add(audio.inBuf[0], inBuf[port], iframes); } } if (noConnections) - FloatVectorOperations::clear(audio.inBuf[0], frames); + FloatVectorOperations::clear(audio.inBuf[0], iframes); noConnections = true; @@ -675,26 +681,26 @@ void RackGraph::processHelper(CarlaEngine::ProtectedData* const data, const floa if (noConnections) { - FloatVectorOperations::copy(audio.inBuf[1], inBuf[port], frames); + FloatVectorOperations::copy(audio.inBuf[1], inBuf[port], iframes); noConnections = false; } else { - FloatVectorOperations::add(audio.inBuf[1], inBuf[port], frames); + FloatVectorOperations::add(audio.inBuf[1], inBuf[port], iframes); } } if (noConnections) - FloatVectorOperations::clear(audio.inBuf[1], frames); + FloatVectorOperations::clear(audio.inBuf[1], iframes); } else { - FloatVectorOperations::clear(audio.inBuf[0], frames); - FloatVectorOperations::clear(audio.inBuf[1], frames); + FloatVectorOperations::clear(audio.inBuf[0], iframes); + FloatVectorOperations::clear(audio.inBuf[1], iframes); } - FloatVectorOperations::clear(audio.outBuf[0], frames); - FloatVectorOperations::clear(audio.outBuf[1], frames); + FloatVectorOperations::clear(audio.outBuf[0], iframes); + FloatVectorOperations::clear(audio.outBuf[1], iframes); // process process(data, const_cast(audio.inBuf), audio.outBuf, frames); @@ -707,7 +713,7 @@ void RackGraph::processHelper(CarlaEngine::ProtectedData* const data, const floa const uint& port(it.getValue()); CARLA_SAFE_ASSERT_CONTINUE(port < outputs); - FloatVectorOperations::add(outBuf[port], audio.outBuf[0], frames); + FloatVectorOperations::add(outBuf[port], audio.outBuf[0], iframes); } } @@ -718,7 +724,7 @@ void RackGraph::processHelper(CarlaEngine::ProtectedData* const data, const floa const uint& port(it.getValue()); CARLA_SAFE_ASSERT_CONTINUE(port < outputs); - FloatVectorOperations::add(outBuf[port], audio.outBuf[1], frames); + FloatVectorOperations::add(outBuf[port], audio.outBuf[1], iframes); } } } @@ -775,8 +781,8 @@ public: d.uid = d.name.hashCode(); d.isInstrument = (fPlugin->getHints() & PLUGIN_IS_SYNTH); - d.numInputChannels = fPlugin->getAudioInCount(); - d.numOutputChannels = fPlugin->getAudioOutCount(); + d.numInputChannels = static_cast(fPlugin->getAudioInCount()); + d.numOutputChannels = static_cast(fPlugin->getAudioOutCount()); //d.hasSharedContainer = true; } @@ -791,31 +797,15 @@ public: { if (CarlaEngineEventPort* const port = fPlugin->getDefaultEventInPort()) { - EngineEvent* const buffer(port->fBuffer); - CARLA_SAFE_ASSERT_RETURN(buffer != nullptr,); - - carla_zeroStruct(buffer, kMaxEngineEventInternalCount); - - const uint8_t* midiData; - int numBytes; - int sampleNumber; - ushort engineEventIndex = 0; - - for (MidiBuffer::Iterator outBufferIterator(midi); outBufferIterator.getNextEvent(midiData, numBytes, sampleNumber);) - { - if (numBytes <= 0 || numBytes >= MAX_MIDI_VALUE) - continue; + EngineEvent* const engineEvents(port->fBuffer); + CARLA_SAFE_ASSERT_RETURN(engineEvents != nullptr,); - EngineEvent& engineEvent(buffer[engineEventIndex++]); - - engineEvent.time = sampleNumber; - engineEvent.fillFromMidiData(static_cast(numBytes), midiData); - - if (engineEventIndex >= kMaxEngineEventInternalCount) - break; - } + carla_zeroStruct(engineEvents, kMaxEngineEventInternalCount); + fillEngineEventsFromJuceMidiBuffer(engineEvents, midi); } + const uint32_t bufferSize(static_cast(audio.getNumSamples())); + if (const int numChan = audio.getNumChannels()) { float* audioBuffers[numChan]; @@ -823,56 +813,21 @@ public: for (int i=0; iprocess(audioBuffers, audioBuffers, audio.getNumSamples()); + fPlugin->process(audioBuffers, audioBuffers, bufferSize); } else { - fPlugin->process(nullptr, nullptr, audio.getNumSamples()); + fPlugin->process(nullptr, nullptr, bufferSize); } midi.clear(); if (CarlaEngineEventPort* const port = fPlugin->getDefaultEventOutPort()) { - EngineEvent* const buffer(port->fBuffer); - CARLA_SAFE_ASSERT_RETURN(buffer != nullptr,); - - uint8_t size = 0; - uint8_t mdata[3] = { 0, 0, 0 }; - const uint8_t* mdataPtr = mdata; - - for (ushort i=0; i < kMaxEngineEventInternalCount; ++i) - { - const EngineEvent& engineEvent(buffer[i]); - - if (engineEvent.type == kEngineEventTypeNull) - break; - - else if (engineEvent.type == kEngineEventTypeControl) - { - const EngineControlEvent& ctrlEvent(engineEvent.ctrl); - ctrlEvent.convertToMidiData(engineEvent.channel, size, mdata); - mdataPtr = mdata; - } - else if (engineEvent.type == kEngineEventTypeMidi) - { - const EngineMidiEvent& midiEvent(engineEvent.midi); - - size = midiEvent.size; + const EngineEvent* const engineEvents(port->fBuffer); + CARLA_SAFE_ASSERT_RETURN(engineEvents != nullptr,); - if (size > EngineMidiEvent::kDataSize && midiEvent.dataExt != nullptr) - mdataPtr = midiEvent.dataExt; - else - mdataPtr = midiEvent.data; - } - else - { - continue; - } - - if (size > 0) - midi.addEvent(mdataPtr, size, engineEvent.time); - } + fillJuceMidiBufferFromEngineEvents(midi, engineEvents); } } @@ -882,7 +837,9 @@ public: const String getInputChannelName(int) const override { return String(); } const String getOutputChannelName(int) const override { return String(); } const String getParameterName(int) override { return String(); } + String getParameterName(int, int) override { return String(); } const String getParameterText(int) override { return String(); } + String getParameterText(int, int) override { return String(); } const String getProgramName(int) override { return String(); } double getTailLengthSeconds() const override { return 0.0; } @@ -920,13 +877,13 @@ private: static const int kMidiInputNodeId = MAX_PATCHBAY_PLUGINS*3+1; static const int kMidiOutputNodeId = MAX_PATCHBAY_PLUGINS*3+2; -PatchbayGraph::PatchbayGraph(const uint32_t bufferSize, const double sampleRate, const uint32_t ins, const uint32_t outs) - : inputs(ins), - outputs(outs) +PatchbayGraph::PatchbayGraph(const int bufferSize, const double sampleRate, const uint32_t ins, const uint32_t outs) + : inputs(static_cast(ins)), + outputs(static_cast(outs)) { graph.setPlayConfigDetails(inputs, outputs, sampleRate, bufferSize); graph.prepareToPlay(sampleRate, bufferSize); - audioBuffer.setSize(jmax(ins, outs), bufferSize); + audioBuffer.setSize(jmax(inputs, outputs), bufferSize); midiBuffer.ensureSize(kMaxEngineEventInternalCount*2); midiBuffer.clear(); @@ -960,7 +917,7 @@ PatchbayGraph::~PatchbayGraph() audioBuffer.clear(); } -void PatchbayGraph::setBufferSize(const uint32_t bufferSize) +void PatchbayGraph::setBufferSize(const int bufferSize) { graph.releaseResources(); graph.prepareToPlay(graph.getSampleRate(), bufferSize); @@ -1049,57 +1006,19 @@ bool PatchbayGraph::getPortIdFromFullName(const char* const /*fillPortName*/, ui } #endif -void PatchbayGraph::process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames) +void PatchbayGraph::process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames) { CARLA_SAFE_ASSERT_RETURN(data != nullptr,); CARLA_SAFE_ASSERT_RETURN(data->events.in != nullptr,); CARLA_SAFE_ASSERT_RETURN(data->events.out != nullptr,); + CARLA_SAFE_ASSERT_RETURN(frames > 0,); // put events in juce buffer { - uint8_t size = 0; - uint8_t mdata[3] = { 0, 0, 0 }; - const uint8_t* mdataPtr = mdata; - midiBuffer.clear(); - - for (ushort i=0; i < kMaxEngineEventInternalCount; ++i) - { - const EngineEvent& engineEvent(data->events.in[i]); - - if (engineEvent.type == kEngineEventTypeNull) - break; - - else if (engineEvent.type == kEngineEventTypeControl) - { - const EngineControlEvent& ctrlEvent(engineEvent.ctrl); - ctrlEvent.convertToMidiData(engineEvent.channel, size, mdata); - mdataPtr = mdata; - } - else if (engineEvent.type == kEngineEventTypeMidi) - { - const EngineMidiEvent& midiEvent(engineEvent.midi); - - size = midiEvent.size; - - if (size > EngineMidiEvent::kDataSize && midiEvent.dataExt != nullptr) - mdataPtr = midiEvent.dataExt; - else - mdataPtr = midiEvent.data; - } - else - { - continue; - } - - if (size > 0) - midiBuffer.addEvent(mdataPtr, size, engineEvent.time); - } + fillJuceMidiBufferFromEngineEvents(midiBuffer, data->events.in); } - // initialize event outputs (zero) - carla_zeroStruct(data->events.out, kMaxEngineEventInternalCount); - // put carla audio in juce buffer { int i=0; @@ -1122,24 +1041,8 @@ void PatchbayGraph::process(CarlaEngine::ProtectedData* const data, const float* // put juce events in carla buffer { - const uint8_t* midiData; - int numBytes; - int sampleNumber; - ushort engineEventIndex = 0; - - for (MidiBuffer::Iterator outBufferIterator(midiBuffer); outBufferIterator.getNextEvent(midiData, numBytes, sampleNumber);) - { - if (numBytes <= 0 || numBytes >= MAX_MIDI_VALUE) - continue; - - EngineEvent& engineEvent(data->events.out[engineEventIndex++]); - - engineEvent.time = sampleNumber; - engineEvent.fillFromMidiData(static_cast(numBytes), midiData); - - if (engineEventIndex >= kMaxEngineEventInternalCount) - break; - } + carla_zeroStruct(data->events.out, kMaxEngineEventInternalCount); + fillEngineEventsFromJuceMidiBuffer(data->events.out, midiBuffer); } } @@ -1171,7 +1074,7 @@ void EngineInternalGraph::create(const bool isRack, const double sampleRate, con else { CARLA_SAFE_ASSERT_RETURN(fPatchbay == nullptr,); - fPatchbay = new PatchbayGraph(sampleRate, bufferSize, inputs, outputs); + fPatchbay = new PatchbayGraph(static_cast(bufferSize), sampleRate, inputs, outputs); } fIsReady = true; @@ -1213,7 +1116,7 @@ void EngineInternalGraph::setBufferSize(const uint32_t bufferSize) else { CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,); - fPatchbay->setBufferSize(bufferSize); + fPatchbay->setBufferSize(static_cast(bufferSize)); } } @@ -1277,7 +1180,7 @@ void EngineInternalGraph::process(CarlaEngine::ProtectedData* const data, const else { CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,); - fPatchbay->process(data, inBuf, outBuf, frames); + fPatchbay->process(data, inBuf, outBuf, static_cast(frames)); } } diff --git a/source/backend/engine/CarlaEngineGraph.hpp b/source/backend/engine/CarlaEngineGraph.hpp index 33828050a..b1db830a9 100644 --- a/source/backend/engine/CarlaEngineGraph.hpp +++ b/source/backend/engine/CarlaEngineGraph.hpp @@ -113,10 +113,10 @@ struct PatchbayGraph { const int outputs; //CharStringListPtr retCon; - PatchbayGraph(const uint32_t bufferSize, const double sampleRate, const uint32_t inputs, const uint32_t outputs); + PatchbayGraph(const int bufferSize, const double sampleRate, const uint32_t inputs, const uint32_t outputs); ~PatchbayGraph(); - void setBufferSize(const uint32_t bufferSize); + void setBufferSize(const int bufferSize); void setSampleRate(const double sampleRate); void setOffline(const bool offline); @@ -131,7 +131,7 @@ struct PatchbayGraph { //const char* const* getConnections() const noexcept; //bool getPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept; - void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames); + void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames); }; // ----------------------------------------------------------------------- diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index 21d83a9cb..7deb282e0 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -109,7 +109,7 @@ public: try { jackbridge_port_unregister(fJackClient, fJackPort); - } catch(...) {} + } CARLA_SAFE_EXCEPTION("Audio port unregister"); fJackClient = nullptr; fJackPort = nullptr; @@ -151,7 +151,7 @@ public: } else { - FloatVectorOperations::clear(fBuffer, bufferSize); + FloatVectorOperations::clear(fBuffer, static_cast(bufferSize)); } } @@ -253,7 +253,7 @@ public: try { jackbridge_port_unregister(fJackClient, fJackPort); - } catch(...) {} + } CARLA_SAFE_EXCEPTION("CV port unregister"); fJackClient = nullptr; fJackPort = nullptr; @@ -279,7 +279,7 @@ public: } if (! fIsInput) - FloatVectorOperations::clear(fBuffer, bufferSize); + FloatVectorOperations::clear(fBuffer, static_cast(bufferSize)); } void invalidate() noexcept @@ -339,7 +339,7 @@ public: { try { jackbridge_port_unregister(fJackClient, fJackPort); - } catch(...) {} + } CARLA_SAFE_EXCEPTION("Event port unregister"); fJackClient = nullptr; fJackPort = nullptr; @@ -374,13 +374,9 @@ public: CARLA_SAFE_ASSERT_RETURN(fIsInput, 0); CARLA_SAFE_ASSERT_RETURN(fJackBuffer != nullptr, 0); - uint32_t count = 0; - try { - count = jackbridge_midi_get_event_count(fJackBuffer); - } catch(...) {} - - return count; + return jackbridge_midi_get_event_count(fJackBuffer); + } CARLA_SAFE_EXCEPTION_RETURN("jack_midi_get_event_count", 0); } const EngineEvent& getEvent(const uint32_t index) const noexcept override @@ -402,12 +398,12 @@ public: try { test = jackbridge_midi_event_get(&jackEvent, fJackBuffer, index); - } catch(...) {} + } CARLA_SAFE_EXCEPTION_RETURN("jack_midi_event_get", kFallbackJackEngineEvent); if (! test) return kFallbackJackEngineEvent; - CARLA_SAFE_ASSERT_RETURN(jackEvent.size <= 0xFF /* uint8_t max */, kFallbackJackEngineEvent); + CARLA_SAFE_ASSERT_RETURN(jackEvent.size < UINT8_MAX, kFallbackJackEngineEvent); fRetEvent.time = jackEvent.time; fRetEvent.fillFromMidiData(static_cast(jackEvent.size), jackEvent.buffer); @@ -440,13 +436,9 @@ public: if (size == 0) return false; - bool ret = false; - try { - ret = jackbridge_midi_event_write(fJackBuffer, time, data, size); - } catch(...) {} - - return ret; + return jackbridge_midi_event_write(fJackBuffer, time, data, size); + } CARLA_SAFE_EXCEPTION_RETURN("jack_midi_event_write", false); } bool writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data) noexcept override @@ -467,13 +459,9 @@ public: for (uint8_t i=1; i < size; ++i) jdata[i] = data[i]; - bool ret = false; - try { - ret = jackbridge_midi_event_write(fJackBuffer, time, jdata, size); - } catch(...) {} - - return ret; + return jackbridge_midi_event_write(fJackBuffer, time, jdata, size); + } CARLA_SAFE_EXCEPTION_RETURN("jack_midi_event_write", false); } void invalidate() noexcept @@ -1434,8 +1422,8 @@ protected: float* const audioOut2 = (float*)jackbridge_port_get_buffer(fRackPorts[kRackPortAudioOut2], nframes); void* const eventOut = jackbridge_port_get_buffer(fRackPorts[kRackPortEventOut], nframes); - FloatVectorOperations::copy(audioOut1, audioIn1, nframes); - FloatVectorOperations::copy(audioOut2, audioIn2, nframes); + FloatVectorOperations::copy(audioOut1, audioIn1, static_cast(nframes)); + FloatVectorOperations::copy(audioOut2, audioIn2, static_cast(nframes)); jackbridge_midi_clear_buffer(eventOut); } diff --git a/source/backend/engine/CarlaEngineJuce.cpp b/source/backend/engine/CarlaEngineJuce.cpp index f23dc0d73..4b379fd20 100644 --- a/source/backend/engine/CarlaEngineJuce.cpp +++ b/source/backend/engine/CarlaEngineJuce.cpp @@ -142,6 +142,12 @@ public: StringArray inputNames(fDevice->getInputChannelNames()); StringArray outputNames(fDevice->getOutputChannelNames()); + if (inputNames.size() < 0 || outputNames.size() <= 0) + { + setLastError("Selected device does not have any outputs"); + return false; + } + BigInteger inputChannels; inputChannels.setRange(0, inputNames.size(), true); @@ -160,7 +166,7 @@ public: pData->bufferSize = static_cast(fDevice->getCurrentBufferSizeSamples()); pData->sampleRate = fDevice->getCurrentSampleRate(); - pData->graph.create(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK, pData->sampleRate, pData->bufferSize, inputNames.size(), outputNames.size()); + pData->graph.create(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK, pData->sampleRate, pData->bufferSize, static_cast(inputNames.size()), static_cast(outputNames.size())); fDevice->start(this); diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index 06aa36596..a411bc910 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -1074,8 +1074,8 @@ protected: { if (pData->curPluginCount == 0 && ! fIsPatchbay) { - FloatVectorOperations::copy(outBuffer[0], inBuffer[0], frames); - FloatVectorOperations::copy(outBuffer[1], inBuffer[1], frames); + FloatVectorOperations::copy(outBuffer[0], inBuffer[0], static_cast(frames)); + FloatVectorOperations::copy(outBuffer[1], inBuffer[1], static_cast(frames)); return runPendingRtEvents();; } diff --git a/source/backend/engine/CarlaEngineRtAudio.cpp b/source/backend/engine/CarlaEngineRtAudio.cpp index b7a51ace8..d90be8809 100644 --- a/source/backend/engine/CarlaEngineRtAudio.cpp +++ b/source/backend/engine/CarlaEngineRtAudio.cpp @@ -611,7 +611,7 @@ protected: for (uint i=0; i < fAudioOutCount; ++i) outBuf[i] = outsPtr+(nframes*i); - FloatVectorOperations::clear(outsPtr, nframes*fAudioOutCount); + FloatVectorOperations::clear(outsPtr, static_cast(nframes*fAudioOutCount)); // initialize events carla_zeroStruct(pData->events.in, kMaxEngineEventInternalCount); diff --git a/source/utils/CarlaEngineUtils.hpp b/source/utils/CarlaEngineUtils.hpp index 646ac4928..79d51da50 100644 --- a/source/utils/CarlaEngineUtils.hpp +++ b/source/utils/CarlaEngineUtils.hpp @@ -21,6 +21,8 @@ #include "CarlaEngine.hpp" #include "CarlaUtils.hpp" +#include "juce_audio_basics.h" + CARLA_BACKEND_START_NAMESPACE // ----------------------------------------------------------------------- @@ -114,6 +116,86 @@ const char* EngineControlEventType2Str(const EngineControlEventType type) noexce // ----------------------------------------------------------------------- +static inline +void fillEngineEventsFromJuceMidiBuffer(EngineEvent engineEvents[kMaxEngineEventInternalCount], const juce::MidiBuffer& midiBuffer) +{ + const uint8_t* midiData; + int numBytes; + int sampleNumber; + ushort engineEventIndex = 0; + + for (ushort i=0; i < kMaxEngineEventInternalCount; ++i) + { + const EngineEvent& engineEvent(engineEvents[i]); + + if (engineEvent.type != kEngineEventTypeNull) + continue; + + engineEventIndex = i; + break; + } + + for (juce::MidiBuffer::Iterator midiBufferIterator(midiBuffer); midiBufferIterator.getNextEvent(midiData, numBytes, sampleNumber) && engineEventIndex < kMaxEngineEventInternalCount;) + { + CARLA_SAFE_ASSERT_CONTINUE(numBytes > 0); + CARLA_SAFE_ASSERT_CONTINUE(sampleNumber >= 0); + + if (numBytes > UINT8_MAX) + continue; + + EngineEvent& engineEvent(engineEvents[engineEventIndex++]); + + engineEvent.time = static_cast(sampleNumber); + engineEvent.fillFromMidiData(static_cast(numBytes), midiData); + } +} + +// ----------------------------------------------------------------------- + +static inline +void fillJuceMidiBufferFromEngineEvents(juce::MidiBuffer& midiBuffer, const EngineEvent engineEvents[kMaxEngineEventInternalCount]) +{ + uint8_t size = 0; + uint8_t mdata[3] = { 0, 0, 0 }; + const uint8_t* mdataPtr = mdata; + + for (ushort i=0; i < kMaxEngineEventInternalCount; ++i) + { + const EngineEvent& engineEvent(engineEvents[i]); + + if (engineEvent.type == kEngineEventTypeNull) + break; + + else if (engineEvent.type == kEngineEventTypeControl) + { + const EngineControlEvent& ctrlEvent(engineEvent.ctrl); + + ctrlEvent.convertToMidiData(engineEvent.channel, size, mdata); + mdataPtr = mdata; + } + else if (engineEvent.type == kEngineEventTypeMidi) + { + const EngineMidiEvent& midiEvent(engineEvent.midi); + + size = midiEvent.size; + + if (size > EngineMidiEvent::kDataSize && midiEvent.dataExt != nullptr) + mdataPtr = midiEvent.dataExt; + else + mdataPtr = midiEvent.data; + } + else + { + continue; + } + + if (size > 0) + midiBuffer.addEvent(mdataPtr, static_cast(size), static_cast(engineEvent.time)); + } +} + +// ----------------------------------------------------------------------- + CARLA_BACKEND_END_NAMESPACE #endif // CARLA_ENGINE_UTILS_HPP_INCLUDED