diff --git a/source/backend/CarlaStandalone.cpp b/source/backend/CarlaStandalone.cpp index 7c6bf32b2..5f765e525 100644 --- a/source/backend/CarlaStandalone.cpp +++ b/source/backend/CarlaStandalone.cpp @@ -172,6 +172,8 @@ private: lib_t libfftw3f; lib_t libfftw3l; lib_t libfftw3q; + + CARLA_DECLARE_NON_COPY_CLASS(ThreadSafeFFTW) }; static ThreadSafeFFTW sThreadSafeFFTW; @@ -870,7 +872,7 @@ const CarlaTransportInfo* carla_get_transport_info() { retTransInfo.bar = timeInfo.bbt.bar; retTransInfo.beat = timeInfo.bbt.beat; - retTransInfo.tick = timeInfo.bbt.tick; + retTransInfo.tick = static_cast(timeInfo.bbt.tick + 0.5); retTransInfo.bpm = timeInfo.bbt.beatsPerMinute; } diff --git a/source/backend/engine/CarlaEngineBridge.cpp b/source/backend/engine/CarlaEngineBridge.cpp index 3ac6ab9eb..f1b210226 100644 --- a/source/backend/engine/CarlaEngineBridge.cpp +++ b/source/backend/engine/CarlaEngineBridge.cpp @@ -837,8 +837,8 @@ public: if (index >= 0 && plugin != nullptr && plugin->isEnabled()) { char strBuf[STR_MAX]; - plugin->getParameterText(index, strBuf); - const uint32_t strBufLen(std::strlen(strBuf)); + plugin->getParameterText(static_cast(index), strBuf); + const uint32_t strBufLen = static_cast(std::strlen(strBuf)); const CarlaMutexLocker _cml(fShmNonRtServerControl.mutex); diff --git a/source/backend/engine/CarlaEngineData.cpp b/source/backend/engine/CarlaEngineData.cpp index 441da65a2..cd54a9ff8 100644 --- a/source/backend/engine/CarlaEngineData.cpp +++ b/source/backend/engine/CarlaEngineData.cpp @@ -206,7 +206,12 @@ EngineOptions::EngineOptions() noexcept binaryDir(nullptr), resourceDir(nullptr), preventBadBehaviour(false), - frontendWinId(0) {} + frontendWinId(0) +#ifndef CARLA_OS_WIN + , wine() +#endif +{ +} EngineOptions::~EngineOptions() noexcept { diff --git a/source/backend/engine/CarlaEngineGraph.cpp b/source/backend/engine/CarlaEngineGraph.cpp index 5be4dfd36..3c6f4eb0d 100644 --- a/source/backend/engine/CarlaEngineGraph.cpp +++ b/source/backend/engine/CarlaEngineGraph.cpp @@ -861,11 +861,11 @@ void RackGraph::process(CarlaEngine::ProtectedData* const data, const float* inB { carla_zeroFloats(dummyBuf, frames); - for (uint32_t i=2; i(audio.getNumSamples())); - if (const int numChan = audio.getNumChannels()) + if (const uint32_t numChan = audio.getNumChannels()) { - const uint numChanu = static_cast(jmin(numChan, 2)); + const uint32_t numChanu = jmin(numChan, 2U); if (fPlugin->getAudioInCount() == 0) audio.clear(); float* audioBuffers[numChan]; - for (int i=0; i(engine->getBufferSize())); - const double sampleRate(engine->getSampleRate()); + const uint32_t bufferSize(engine->getBufferSize()); + const double sampleRate(engine->getSampleRate()); - graph.setPlayConfigDetails(static_cast(inputs), static_cast(outputs), sampleRate, bufferSize); - graph.prepareToPlay(sampleRate, bufferSize); + graph.setPlayConfigDetails(static_cast(inputs), static_cast(outputs), sampleRate, static_cast(bufferSize)); + graph.prepareToPlay(sampleRate, static_cast(bufferSize)); - audioBuffer.setSize(static_cast(jmax(inputs, outputs)), bufferSize); + audioBuffer.setSize(jmax(inputs, outputs), bufferSize); midiBuffer.ensureSize(kMaxEngineEventInternalCount*2); midiBuffer.clear(); @@ -1423,13 +1423,11 @@ PatchbayGraph::~PatchbayGraph() void PatchbayGraph::setBufferSize(const uint32_t bufferSize) { - const int bufferSizei(static_cast(bufferSize)); - const CarlaRecursiveMutexLocker cml1(graph.getReorderMutex()); graph.releaseResources(); - graph.prepareToPlay(kEngine->getSampleRate(), bufferSizei); - audioBuffer.setSize(audioBuffer.getNumChannels(), bufferSizei); + graph.prepareToPlay(kEngine->getSampleRate(), static_cast(bufferSize)); + audioBuffer.setSize(audioBuffer.getNumChannels(), bufferSize); } void PatchbayGraph::setSampleRate(const double sampleRate) @@ -1698,7 +1696,7 @@ void PatchbayGraph::refresh(const char* const deviceName) char strBuf[STR_MAX+1]; strBuf[STR_MAX] = '\0'; - for (int i=0, count=graph.getNumConnections(); ievents.in != nullptr,); @@ -1853,13 +1851,13 @@ void PatchbayGraph::process(CarlaEngine::ProtectedData* const data, const float* // put carla audio in water buffer { - int i=0; + uint32_t i=0; - for (; i < static_cast(inputs); ++i) + for (; i < inputs; ++i) audioBuffer.copyFrom(i, 0, inBuf[i], frames); // clear remaining channels - for (const int count=audioBuffer.getNumChannels(); i(outputs); ++i) + for (uint32_t i=0; i < outputs; ++i) carla_copyFloats(outBuf[i], audioBuffer.getReadPointer(i), frames); } @@ -1893,7 +1891,8 @@ void PatchbayGraph::run() // InternalGraph EngineInternalGraph::EngineInternalGraph(CarlaEngine* const engine) noexcept - : fIsReady(false), + : fIsRack(false), + fIsReady(false), fRack(nullptr), kEngine(engine) {} @@ -2019,7 +2018,7 @@ void EngineInternalGraph::process(CarlaEngine::ProtectedData* const data, const else { CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,); - fPatchbay->process(data, inBuf, outBuf, static_cast(frames)); + fPatchbay->process(data, inBuf, outBuf, frames); } } diff --git a/source/backend/engine/CarlaEngineGraph.hpp b/source/backend/engine/CarlaEngineGraph.hpp index 4279c3e38..a5c8c13b9 100644 --- a/source/backend/engine/CarlaEngineGraph.hpp +++ b/source/backend/engine/CarlaEngineGraph.hpp @@ -182,7 +182,7 @@ public: const char* const* getConnections(const bool external) const; bool getGroupAndPortIdFromFullName(const bool external, const char* const fullPortName, uint& groupId, uint& portId) const; - void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames); + void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames); private: void run() override; diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index a6732c08e..af7abeaaf 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -1031,7 +1031,7 @@ public: startThread(); callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, opts.processMode, opts.transportMode, - pData->sampleRate, + static_cast(pData->sampleRate), getCurrentDriverName()); return true; } @@ -1825,7 +1825,7 @@ protected: mdataTmp[0] = static_cast(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT)); // copy rest - carla_copy(mdataTmp+1, midiEvent.data+1, size-1); + carla_copy(mdataTmp+1, midiEvent.data+1, size-1U); // done mdataPtr = mdataTmp; diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index c8e9dd760..664ccac42 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -1637,7 +1637,7 @@ protected: uiServerOptions(); uiServerCallback(ENGINE_CALLBACK_ENGINE_STARTED, 0, pData->options.processMode, pData->options.transportMode, - pData->sampleRate, "Plugin"); + static_cast(pData->sampleRate), "Plugin"); fUiServer.writeShowMessage(); @@ -1953,7 +1953,7 @@ public: return 0; case NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE: { CarlaEngineNative* const engine = handlePtr; - return (uintptr_t)(CarlaEngine*)engine; + return (intptr_t)(CarlaEngine*)engine; } } diff --git a/source/backend/engine/CarlaEngineRtAudio.cpp b/source/backend/engine/CarlaEngineRtAudio.cpp index da28bde17..356d84e9d 100644 --- a/source/backend/engine/CarlaEngineRtAudio.cpp +++ b/source/backend/engine/CarlaEngineRtAudio.cpp @@ -334,7 +334,7 @@ public: callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, pData->options.processMode, pData->options.transportMode, - pData->sampleRate, getCurrentDriverName()); + static_cast(pData->sampleRate), getCurrentDriverName()); return true; } @@ -445,7 +445,7 @@ public: { CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false); - char strBuf[STR_MAX+1]; + char strBuf[STR_MAX+1U]; strBuf[STR_MAX] = '\0'; ExternalGraph& extGraph(graph->extGraph); @@ -715,7 +715,7 @@ protected: mdataTmp[0] = static_cast(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT)); // copy rest - carla_copy(mdataTmp+1, midiEvent.data+1, size-1); + carla_copy(mdataTmp+1, midiEvent.data+1, size-1U); // done mdataPtr = mdataTmp; diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index 7501eda8f..861c7634a 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -2834,7 +2834,7 @@ public: break; case LV2_PORT_DESIGNATION_TIME_BAR_BEAT: - if (timeInfo.bbt.valid && (fLastTimeInfo.bbt.tick != timeInfo.bbt.tick || + if (timeInfo.bbt.valid && (carla_isNotEqual(fLastTimeInfo.bbt.tick, timeInfo.bbt.tick) || fLastTimeInfo.bbt.beat != timeInfo.bbt.beat)) { fParamBuffers[k] = static_cast(barBeat); @@ -5082,7 +5082,7 @@ public: fLv2Options.minBufferSize = fNeedsFixedBuffers ? bufferSize : 1; fLv2Options.maxBufferSize = bufferSize; fLv2Options.nominalBufferSize = bufferSize; - fLv2Options.sampleRate = pData->engine->getSampleRate(); + fLv2Options.sampleRate = static_cast(pData->engine->getSampleRate()); fLv2Options.transientWinId = static_cast(pData->engine->getOptions().frontendWinId); uint32_t eventBufferSize = MAX_DEFAULT_BUFFER_SIZE; diff --git a/source/backend/plugin/CarlaPluginNative.cpp b/source/backend/plugin/CarlaPluginNative.cpp index 04977acd4..0f72d0854 100644 --- a/source/backend/plugin/CarlaPluginNative.cpp +++ b/source/backend/plugin/CarlaPluginNative.cpp @@ -841,7 +841,7 @@ public: } catch(...) {} } - fCurMidiProgs[channel] = index; + fCurMidiProgs[channel] = static_cast(index); CarlaPlugin::setMidiProgramRT(index); } diff --git a/source/backend/plugin/CarlaPluginSFZero.cpp b/source/backend/plugin/CarlaPluginSFZero.cpp index 1a6962ddf..8132069c5 100644 --- a/source/backend/plugin/CarlaPluginSFZero.cpp +++ b/source/backend/plugin/CarlaPluginSFZero.cpp @@ -555,7 +555,7 @@ public: // -------------------------------------------------------------------------------------------------------- // Parameter outputs - fNumVoices = fSynth.numVoicesUsed(); + fNumVoices = static_cast(fSynth.numVoicesUsed()); } bool processSingle(AudioSampleBuffer& audioOutBuffer, const uint32_t frames, const uint32_t timeOffset) @@ -581,7 +581,7 @@ public: // -------------------------------------------------------------------------------------------------------- // Run plugin - fSynth.renderVoices(audioOutBuffer, timeOffset, frames); + fSynth.renderVoices(audioOutBuffer, static_cast(timeOffset), static_cast(frames)); #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH // -------------------------------------------------------------------------------------------------------- diff --git a/source/backend/utils/CachedPlugins.cpp b/source/backend/utils/CachedPlugins.cpp index 4d0df0ffd..63b80c6eb 100644 --- a/source/backend/utils/CachedPlugins.cpp +++ b/source/backend/utils/CachedPlugins.cpp @@ -71,7 +71,7 @@ _CarlaCachedPluginInfo::_CarlaCachedPluginInfo() noexcept static Array gSFZs; -void findSFZs(const char* const sfzPaths) +static void findSFZs(const char* const sfzPaths) { CARLA_SAFE_ASSERT_RETURN(sfzPaths != nullptr,); @@ -91,7 +91,7 @@ void findSFZs(const char* const sfzPaths) // ------------------------------------------------------------------------------------------------------------------- -const CarlaCachedPluginInfo* get_cached_plugin_internal(const NativePluginDescriptor& desc) +static const CarlaCachedPluginInfo* get_cached_plugin_internal(const NativePluginDescriptor& desc) { static CarlaCachedPluginInfo info; @@ -125,7 +125,7 @@ const CarlaCachedPluginInfo* get_cached_plugin_internal(const NativePluginDescri return &info; } -const CarlaCachedPluginInfo* get_cached_plugin_lv2(Lv2WorldClass& lv2World, Lilv::Plugin& lilvPlugin) +static const CarlaCachedPluginInfo* get_cached_plugin_lv2(Lv2WorldClass& lv2World, Lilv::Plugin& lilvPlugin) { static CarlaCachedPluginInfo info; @@ -471,7 +471,7 @@ const CarlaCachedPluginInfo* get_cached_plugin_lv2(Lv2WorldClass& lv2World, Lilv return &info; } -const CarlaCachedPluginInfo* get_cached_plugin_sfz(const File file) +static const CarlaCachedPluginInfo* get_cached_plugin_sfz(const File file) { static CarlaCachedPluginInfo info; @@ -524,7 +524,7 @@ uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath) case CB::PLUGIN_SFZ: { findSFZs(pluginPath); - return gSFZs.size(); + return static_cast(gSFZs.size()); } default: @@ -562,7 +562,7 @@ const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype, case CB::PLUGIN_SFZ: { CARLA_SAFE_ASSERT_BREAK(index < static_cast(gSFZs.size())); - return get_cached_plugin_sfz(gSFZs.getUnchecked(index)); + return get_cached_plugin_sfz(gSFZs.getUnchecked(static_cast(index))); } default: diff --git a/source/bridges-plugin/CarlaBridgeSingleLV2.cpp b/source/bridges-plugin/CarlaBridgeSingleLV2.cpp index 7225bcffa..97ac8d5ac 100644 --- a/source/bridges-plugin/CarlaBridgeSingleLV2.cpp +++ b/source/bridges-plugin/CarlaBridgeSingleLV2.cpp @@ -245,7 +245,7 @@ public: mdataTmp[0] = static_cast(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT)); // copy rest - carla_copy(mdataTmp+1, midiEvent.data+1, size-1); + carla_copy(mdataTmp+1, midiEvent.data+1, size-1U); // done mdataPtr = mdataTmp; diff --git a/source/includes/CarlaNativePlugin.h b/source/includes/CarlaNativePlugin.h index a6083d410..b9f9da223 100644 --- a/source/includes/CarlaNativePlugin.h +++ b/source/includes/CarlaNativePlugin.h @@ -21,6 +21,7 @@ #include "CarlaBackend.h" #include "CarlaNative.h" +#ifndef CARLA_HOST_H_INCLUDED /*! * Get the absolute filename of this carla library. */ @@ -30,6 +31,7 @@ CARLA_EXPORT const char* carla_get_library_filename(); * Get the folder where this carla library resides. */ CARLA_EXPORT const char* carla_get_library_folder(); +#endif /*! * Get the native plugin descriptor for the carla-rack plugin. diff --git a/source/modules/dgl/Application.hpp b/source/modules/dgl/Application.hpp index dc630cebe..1b868c792 100644 --- a/source/modules/dgl/Application.hpp +++ b/source/modules/dgl/Application.hpp @@ -62,7 +62,7 @@ public: idle() is called at regular intervals. @note This function is meant for standalones only, *never* call this from plugins. */ - void exec(int idleTime = 10); + void exec(unsigned int idleTime = 10); /** Quit the application. diff --git a/source/modules/dgl/src/Application.cpp b/source/modules/dgl/src/Application.cpp index 114ee8fc3..32d3d1468 100644 --- a/source/modules/dgl/src/Application.cpp +++ b/source/modules/dgl/src/Application.cpp @@ -44,7 +44,7 @@ void Application::idle() } } -void Application::exec(int idleTime) +void Application::exec(unsigned int idleTime) { for (; pData->doLoop;) { diff --git a/source/modules/water/buffers/AudioSampleBuffer.h b/source/modules/water/buffers/AudioSampleBuffer.h index 2f2f42148..4b08fc203 100644 --- a/source/modules/water/buffers/AudioSampleBuffer.h +++ b/source/modules/water/buffers/AudioSampleBuffer.h @@ -44,9 +44,12 @@ public: //============================================================================== /** Creates an empty buffer with 0 channels and 0 length. */ AudioSampleBuffer() noexcept - : numChannels (0), size (0), allocatedBytes (0), - channels (static_cast (preallocatedChannelSpace)), - isClear (false) + : numChannels(0), + size(0), + allocatedBytes(0), + channels(static_cast (preallocatedChannelSpace)), + allocatedData(), + isClear(false) { } @@ -60,17 +63,16 @@ public: when the buffer is deleted. If the memory can't be allocated, this will throw a std::bad_alloc exception. */ - AudioSampleBuffer (int numChannelsToAllocate, - int numSamplesToAllocate, - bool clearData = false) noexcept - : numChannels (numChannelsToAllocate), - size (numSamplesToAllocate), - allocatedBytes (0), - isClear (false) + AudioSampleBuffer (const uint32_t numChannelsToAllocate, + const uint32_t numSamplesToAllocate, + const bool clearData = false) noexcept + : numChannels(numChannelsToAllocate), + size(numSamplesToAllocate), + allocatedBytes(0), + channels(nullptr), + allocatedData(), + isClear(false) { - CARLA_SAFE_ASSERT_RETURN (size >= 0,); - CARLA_SAFE_ASSERT_RETURN (numChannels >= 0,); - allocateData (clearData); } @@ -90,15 +92,16 @@ public: size of the arrays passed in */ AudioSampleBuffer (float* const* dataToReferTo, - int numChannelsToUse, - int numSamples) noexcept - : numChannels (numChannelsToUse), - size (numSamples), - allocatedBytes (0), - isClear (false) + const uint32_t numChannelsToUse, + const uint32_t numSamples) noexcept + : numChannels(numChannelsToUse), + size(numSamples), + allocatedBytes(0), + channels(nullptr), + allocatedData(), + isClear(false) { CARLA_SAFE_ASSERT_RETURN (dataToReferTo != nullptr,); - CARLA_SAFE_ASSERT_RETURN (numChannelsToUse >= 0 && numSamples >= 0,); allocateChannels (dataToReferTo, 0); } @@ -120,16 +123,17 @@ public: size of the arrays passed in */ AudioSampleBuffer (float* const* dataToReferTo, - int numChannelsToUse, - int startSample, - int numSamples) noexcept - : numChannels (numChannelsToUse), - size (numSamples), - allocatedBytes (0), - isClear (false) + const uint32_t numChannelsToUse, + const uint32_t startSample, + const uint32_t numSamples) noexcept + : numChannels(numChannelsToUse), + size(numSamples), + allocatedBytes(0), + channels(nullptr), + allocatedData(), + isClear(false) { CARLA_SAFE_ASSERT_RETURN (dataToReferTo != nullptr,); - CARLA_SAFE_ASSERT_RETURN (numChannelsToUse >= 0 && startSample >= 0 && numSamples >= 0,); allocateChannels (dataToReferTo, startSample); } @@ -141,9 +145,12 @@ public: shared block of data. */ AudioSampleBuffer (const AudioSampleBuffer& other) noexcept - : numChannels (other.numChannels), - size (other.size), - allocatedBytes (other.allocatedBytes) + : numChannels(other.numChannels), + size(other.size), + allocatedBytes(other.allocatedBytes), + channels(nullptr), + allocatedData(), + isClear(false) { if (allocatedBytes == 0) { @@ -159,12 +166,40 @@ public: } else { - for (int i = 0; i < numChannels; ++i) + for (uint32_t i = 0; i < numChannels; ++i) carla_copyFloats (channels[i], other.channels[i], size); } } } + AudioSampleBuffer& operator= (const AudioSampleBuffer& other) noexcept + { + numChannels = other.numChannels; + size = other.size; + allocatedBytes = other.allocatedBytes; + channels = other.channels; + + if (allocatedBytes == 0) + { + allocateChannels (other.channels, 0); + } + else + { + allocateData(); + + if (other.isClear) + { + clear(); + } + else + { + for (uint32_t i = 0; i < numChannels; ++i) + carla_copyFloats (channels[i], other.channels[i], size); + } + } + return *this; + } + /** Destructor. This will free any memory allocated by the buffer. */ @@ -180,7 +215,7 @@ public: allocatedData (static_cast&&> (other.allocatedData)), isClear (other.isClear) { - memcpy (preallocatedChannelSpace, other.preallocatedChannelSpace, sizeof (preallocatedChannelSpace)); + std::memcpy (preallocatedChannelSpace, other.preallocatedChannelSpace, sizeof (preallocatedChannelSpace)); other.numChannels = 0; other.size = 0; other.allocatedBytes = 0; @@ -207,12 +242,12 @@ public: /** Returns the number of channels of audio data that this buffer contains. @see getSampleData */ - int getNumChannels() const noexcept { return numChannels; } + uint32_t getNumChannels() const noexcept { return numChannels; } /** Returns the number of samples allocated in each of the buffer's channels. @see getSampleData */ - int getNumSamples() const noexcept { return size; } + uint32_t getNumSamples() const noexcept { return size; } /** Returns a pointer to an array of read-only samples in one of the buffer's channels. For speed, this doesn't check whether the channel number is out of range, @@ -221,9 +256,10 @@ public: result! Instead, you must call getWritePointer so that the buffer knows you're planning on modifying the data. */ - const float* getReadPointer (int channelNumber) const noexcept + const float* getReadPointer (const uint32_t channelNumber) const noexcept { - CARLA_SAFE_ASSERT_RETURN (isPositiveAndBelow (channelNumber, numChannels), nullptr); + CARLA_SAFE_ASSERT_RETURN (channelNumber < numChannels, nullptr); + return channels [channelNumber]; } @@ -234,10 +270,11 @@ public: result! Instead, you must call getWritePointer so that the buffer knows you're planning on modifying the data. */ - const float* getReadPointer (int channelNumber, int sampleIndex) const noexcept + const float* getReadPointer (const uint32_t channelNumber, const uint32_t sampleIndex) const noexcept { - CARLA_SAFE_ASSERT_RETURN (isPositiveAndBelow (channelNumber, numChannels), nullptr); - CARLA_SAFE_ASSERT_RETURN (isPositiveAndBelow (sampleIndex, size), nullptr); + CARLA_SAFE_ASSERT_RETURN (channelNumber < numChannels, nullptr); + CARLA_SAFE_ASSERT_RETURN (sampleIndex < size, nullptr); + return channels [channelNumber] + sampleIndex; } @@ -247,9 +284,10 @@ public: Note that if you're not planning on writing to the data, you should always use getReadPointer instead. */ - float* getWritePointer (int channelNumber) noexcept + float* getWritePointer (const uint32_t channelNumber) noexcept { - CARLA_SAFE_ASSERT_RETURN (isPositiveAndBelow (channelNumber, numChannels), nullptr); + CARLA_SAFE_ASSERT_RETURN (channelNumber < numChannels, nullptr); + isClear = false; return channels [channelNumber]; } @@ -260,10 +298,11 @@ public: Note that if you're not planning on writing to the data, you should use getReadPointer instead. */ - float* getWritePointer (int channelNumber, int sampleIndex) noexcept + float* getWritePointer (const uint32_t channelNumber, const uint32_t sampleIndex) noexcept { - CARLA_SAFE_ASSERT_RETURN (isPositiveAndBelow (channelNumber, numChannels), nullptr); - CARLA_SAFE_ASSERT_RETURN (isPositiveAndBelow (sampleIndex, size), nullptr); + CARLA_SAFE_ASSERT_RETURN (channelNumber < numChannels, nullptr); + CARLA_SAFE_ASSERT_RETURN (sampleIndex < size, nullptr); + isClear = false; return channels [channelNumber] + sampleIndex; } @@ -287,17 +326,13 @@ public: This can expand the buffer's length, and add or remove channels. */ - bool setSize (int newNumChannels, int newNumSamples) noexcept + bool setSize (const uint32_t newNumChannels, const uint32_t newNumSamples) noexcept { - CARLA_SAFE_ASSERT_RETURN (newNumChannels >= 0, false); - CARLA_SAFE_ASSERT_RETURN (newNumSamples >= 0, false); - if (newNumSamples != size || newNumChannels != numChannels) { - const size_t allocatedSamplesPerChannel = ((size_t) newNumSamples + 3) & ~3u; - const size_t channelListSize = ((sizeof (float*) * (size_t) (newNumChannels + 1)) + 15) & ~15u; - const size_t newTotalBytes = ((size_t) newNumChannels * (size_t) allocatedSamplesPerChannel * sizeof (float)) - + channelListSize + 32; + const uint32_t allocatedSamplesPerChannel = (newNumSamples + 3) & ~3u; + const uint32_t channelListSize = ((sizeof (float*) * (newNumChannels + 1)) + 15) & ~15u; + const size_t newTotalBytes = newNumChannels * allocatedSamplesPerChannel * sizeof(float) + channelListSize + 32u; if (allocatedBytes >= newTotalBytes) { @@ -312,13 +347,13 @@ public: } float* chan = reinterpret_cast (allocatedData + channelListSize); - for (int i = 0; i < newNumChannels; ++i) + for (uint32_t i = 0; i < newNumChannels; ++i) { channels[i] = chan; chan += allocatedSamplesPerChannel; } - channels [newNumChannels] = 0; + channels [newNumChannels] = nullptr; size = newNumSamples; numChannels = newNumChannels; } @@ -331,22 +366,18 @@ public: Returns true if the required memory is available. */ - bool setSizeRT (int newNumSamples) noexcept + bool setSizeRT (const uint32_t newNumSamples) noexcept { - CARLA_SAFE_ASSERT_RETURN (newNumSamples >= 0, false); - CARLA_SAFE_ASSERT_RETURN (numChannels >= 0, false); - if (newNumSamples != size) { - const size_t allocatedSamplesPerChannel = ((size_t) newNumSamples + 3) & ~3u; - const size_t channelListSize = ((sizeof (float*) * (size_t) (numChannels + 1)) + 15) & ~15u; - const size_t newTotalBytes = ((size_t) numChannels * (size_t) allocatedSamplesPerChannel * sizeof (float)) - + channelListSize + 32; + const uint32_t allocatedSamplesPerChannel = (newNumSamples + 3) & ~3u; + const uint32_t channelListSize = ((sizeof (float*) * (numChannels + 1)) + 15) & ~15u; + const size_t newTotalBytes = numChannels * allocatedSamplesPerChannel * sizeof(float) + channelListSize + 32u; CARLA_SAFE_ASSERT_RETURN(allocatedBytes >= newTotalBytes, false); float* chan = reinterpret_cast (allocatedData + channelListSize); - for (int i = 0; i < numChannels; ++i) + for (uint32_t i = 0; i < numChannels; ++i) { channels[i] = chan; chan += allocatedSamplesPerChannel; @@ -377,11 +408,10 @@ public: size of the arrays passed in */ bool setDataToReferTo (float** dataToReferTo, - const int newNumChannels, - const int newNumSamples) noexcept + const uint32_t newNumChannels, + const uint32_t newNumSamples) noexcept { CARLA_SAFE_ASSERT_RETURN(dataToReferTo != nullptr, false); - CARLA_SAFE_ASSERT_INT2_RETURN(newNumChannels >= 0 && newNumSamples >= 0, newNumChannels, newNumSamples, false); if (allocatedBytes != 0) { @@ -401,7 +431,7 @@ public: { if (! isClear) { - for (int i = 0; i < numChannels; ++i) + for (uint32_t i = 0; i < numChannels; ++i) carla_zeroFloats (channels[i], size); isClear = true; @@ -413,17 +443,17 @@ public: For speed, this doesn't check whether the channel and sample number are in-range, so be careful! */ - void clear (int startSample, - int numSamples) noexcept + void clear (const uint32_t startSample, + const uint32_t numSamples) noexcept { - CARLA_SAFE_ASSERT_INT2_RETURN(startSample >= 0 && startSample + numSamples <= size, numSamples, size,); + CARLA_SAFE_ASSERT_UINT2_RETURN(startSample + numSamples <= size, numSamples, size,); if (! isClear) { if (startSample == 0 && numSamples == size) isClear = true; - for (int i = 0; i < numChannels; ++i) + for (uint32_t i = 0; i < numChannels; ++i) carla_zeroFloats (channels[i] + startSample, numSamples); } } @@ -433,12 +463,12 @@ public: For speed, this doesn't check whether the channel and sample number are in-range, so be careful! */ - void clear (int channel, - int startSample, - int numSamples) noexcept + void clear (const uint32_t channel, + const uint32_t startSample, + const uint32_t numSamples) noexcept { - CARLA_SAFE_ASSERT_INT2_RETURN(isPositiveAndBelow(channel, numChannels), channel, numChannels,); - CARLA_SAFE_ASSERT_INT2_RETURN(startSample >= 0 && startSample + numSamples <= size, numSamples, size,); + CARLA_SAFE_ASSERT_UINT2_RETURN(channel < numChannels, channel, numChannels,); + CARLA_SAFE_ASSERT_UINT2_RETURN(startSample + numSamples <= size, numSamples, size,); if (! isClear) carla_zeroFloats (channels [channel] + startSample, numSamples); @@ -466,21 +496,21 @@ public: @see copyFrom */ - void addFrom (int destChannel, - int destStartSample, + void addFrom (const uint32_t destChannel, + const uint32_t destStartSample, const AudioSampleBuffer& source, - int sourceChannel, - int sourceStartSample, - int numSamples, - float gainToApplyToSource = (float) 1) noexcept + const uint32_t sourceChannel, + const uint32_t sourceStartSample, + const uint32_t numSamples, + const float gainToApplyToSource = 1.0f) noexcept { - CARLA_SAFE_ASSERT_INT2_RETURN(&source != this || sourceChannel != destChannel, sourceChannel, destChannel,); - CARLA_SAFE_ASSERT_INT2_RETURN(isPositiveAndBelow(destChannel, numChannels), destChannel, numChannels,); - CARLA_SAFE_ASSERT_INT2_RETURN(isPositiveAndBelow(sourceChannel, source.numChannels), sourceChannel, source.numChannels,); - CARLA_SAFE_ASSERT_INT2_RETURN(destStartSample >= 0 && destStartSample + numSamples <= size, numSamples, size,); - CARLA_SAFE_ASSERT_INT2_RETURN(sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size, numSamples, source.size,); + CARLA_SAFE_ASSERT_UINT2_RETURN(&source != this || sourceChannel != destChannel, sourceChannel, destChannel,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destChannel < numChannels, destChannel, numChannels,); + CARLA_SAFE_ASSERT_UINT2_RETURN(sourceChannel < source.numChannels, sourceChannel, source.numChannels,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destStartSample + numSamples <= size, numSamples, size,); + CARLA_SAFE_ASSERT_UINT2_RETURN(sourceStartSample + numSamples <= source.size, numSamples, source.size,); - if (gainToApplyToSource != 0.0f && numSamples > 0 && ! source.isClear) + if (carla_isNotZero(gainToApplyToSource) && numSamples != 0 && ! source.isClear) { float* const d = channels [destChannel] + destStartSample; const float* const s = source.channels [sourceChannel] + sourceStartSample; @@ -489,14 +519,14 @@ public: { isClear = false; - if (gainToApplyToSource != 1.0f) + if (carla_isNotZero(gainToApplyToSource - 1.0f)) carla_copyWithMultiply (d, s, gainToApplyToSource, numSamples); else carla_copyFloats (d, s, numSamples); } else { - if (gainToApplyToSource != 1.0f) + if (carla_isNotZero(gainToApplyToSource - 1.0f)) carla_addWithMultiply (d, s, gainToApplyToSource, numSamples); else carla_add (d, s, numSamples); @@ -516,17 +546,17 @@ public: @see copyFrom */ - void addFrom (int destChannel, - int destStartSample, + void addFrom (const uint32_t destChannel, + const uint32_t destStartSample, const float* source, - int numSamples, - float gainToApplyToSource = (float) 1) noexcept + const uint32_t numSamples, + float gainToApplyToSource = 1.0f) noexcept { - CARLA_SAFE_ASSERT_INT2_RETURN(isPositiveAndBelow(destChannel, numChannels), destChannel, numChannels,); - CARLA_SAFE_ASSERT_INT2_RETURN(destStartSample >= 0 && destStartSample + numSamples <= size, numSamples, size,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destChannel < numChannels, destChannel, numChannels,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destStartSample + numSamples <= size, numSamples, size,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,); - if (gainToApplyToSource != 0.0f && numSamples > 0) + if (carla_isNotZero(gainToApplyToSource) && numSamples != 0) { float* const d = channels [destChannel] + destStartSample; @@ -534,14 +564,14 @@ public: { isClear = false; - if (gainToApplyToSource != 1.0f) + if (carla_isNotZero(gainToApplyToSource - 1.0f)) carla_copyWithMultiply (d, source, gainToApplyToSource, numSamples); else carla_copyFloats (d, source, numSamples); } else { - if (gainToApplyToSource != 1.0f) + if (carla_isNotZero(gainToApplyToSource - 1.0f)) carla_addWithMultiply (d, source, gainToApplyToSource, numSamples); else carla_add (d, source, numSamples); @@ -560,18 +590,18 @@ public: @see addFrom */ - void copyFrom (int destChannel, - int destStartSample, + void copyFrom (const uint32_t destChannel, + const uint32_t destStartSample, const AudioSampleBuffer& source, - int sourceChannel, - int sourceStartSample, - int numSamples) noexcept + const uint32_t sourceChannel, + const uint32_t sourceStartSample, + const uint32_t numSamples) noexcept { - CARLA_SAFE_ASSERT_INT2_RETURN(&source != this || sourceChannel != destChannel, sourceChannel, destChannel,); - CARLA_SAFE_ASSERT_INT2_RETURN(isPositiveAndBelow(destChannel, numChannels), destChannel, numChannels,); - CARLA_SAFE_ASSERT_INT2_RETURN(isPositiveAndBelow(sourceChannel, source.numChannels), sourceChannel, source.numChannels,); - CARLA_SAFE_ASSERT_INT2_RETURN(destStartSample >= 0 && destStartSample + numSamples <= size, numSamples, size,); - CARLA_SAFE_ASSERT_INT2_RETURN(sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size, numSamples, source.size,); + CARLA_SAFE_ASSERT_UINT2_RETURN(&source != this || sourceChannel != destChannel, sourceChannel, destChannel,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destChannel < numChannels, destChannel, numChannels,); + CARLA_SAFE_ASSERT_UINT2_RETURN(sourceChannel < source.numChannels, sourceChannel, source.numChannels,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destStartSample + numSamples <= size, numSamples, size,); + CARLA_SAFE_ASSERT_UINT2_RETURN(sourceStartSample + numSamples <= source.size, numSamples, source.size,); if (numSamples > 0) { @@ -599,13 +629,13 @@ public: @see addFrom */ - void copyFrom (int destChannel, - int destStartSample, + void copyFrom (const uint32_t destChannel, + const uint32_t destStartSample, const float* source, - int numSamples) noexcept + const uint32_t numSamples) noexcept { - CARLA_SAFE_ASSERT_INT2_RETURN(isPositiveAndBelow(destChannel, numChannels), destChannel, numChannels,); - CARLA_SAFE_ASSERT_INT2_RETURN(destStartSample >= 0 && destStartSample + numSamples <= size, numSamples, size,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destChannel < numChannels, destChannel, numChannels,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destStartSample + numSamples <= size, numSamples, size,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,); if (numSamples > 0) @@ -625,38 +655,35 @@ public: @see addFrom */ - void copyFrom (int destChannel, - int destStartSample, + void copyFrom (const uint32_t destChannel, + const uint32_t destStartSample, const float* source, - int numSamples, + const uint32_t numSamples, float gain) noexcept { - CARLA_SAFE_ASSERT_INT2_RETURN(isPositiveAndBelow(destChannel, numChannels), destChannel, numChannels,); - CARLA_SAFE_ASSERT_INT2_RETURN(destStartSample >= 0 && destStartSample + numSamples <= size, numSamples, size,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destChannel < numChannels, destChannel, numChannels,); + CARLA_SAFE_ASSERT_UINT2_RETURN(destStartSample + numSamples <= size, numSamples, size,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,); if (numSamples > 0) { float* const d = channels [destChannel] + destStartSample; - if (gain != 1.0f) + if (carla_isZero(gain)) { - if (gain == 0) - { - if (! isClear) - carla_zeroFloats (d, numSamples); - } - else - { - isClear = false; - carla_copyWithMultiply (d, source, gain, numSamples); - } + if (! isClear) + carla_zeroFloats (d, numSamples); } - else + else if (carla_isZero(gain - 1.0f)) { isClear = false; carla_copyFloats (d, source, numSamples); } + else + { + isClear = false; + carla_copyWithMultiply (d, source, gain, numSamples); + } } } @@ -669,28 +696,28 @@ public: @see addFrom */ - void copyFromInterleavedSource (int destChannel, + void copyFromInterleavedSource (const uint32_t destChannel, const float* source, - int totalNumSamples) noexcept + const uint32_t totalNumSamples) noexcept { CARLA_SAFE_ASSERT_RETURN(isPositiveAndBelow(destChannel, numChannels),); CARLA_SAFE_ASSERT_RETURN(source != nullptr,); - if (const int numSamples = totalNumSamples / numChannels) + if (const uint32_t numSamples = totalNumSamples / numChannels) { CARLA_SAFE_ASSERT_RETURN(numSamples <= size,); isClear = false; float* d = channels [destChannel]; - for (int i=numSamples; --i >= 0;) + for (uint32_t i=0; i < numSamples; ++i) d[i] = source[i * numChannels + destChannel]; } } private: //============================================================================== - int numChannels, size; + uint32_t numChannels, size; size_t allocatedBytes; float** channels; HeapBlock allocatedData; @@ -699,15 +726,15 @@ private: bool allocateData (bool clearData = false) { - const size_t channelListSize = sizeof (float*) * (size_t) (numChannels + 1); - const size_t nextAllocatedBytes = (size_t) numChannels * (size_t) size * sizeof (float) + channelListSize + 32; + const size_t channelListSize = sizeof (float*) * (numChannels + 1); + const size_t nextAllocatedBytes = numChannels * size * sizeof (float) + channelListSize + 32; CARLA_SAFE_ASSERT_RETURN (allocatedData.allocate (nextAllocatedBytes, clearData), false); allocatedBytes = nextAllocatedBytes; channels = reinterpret_cast (allocatedData.getData()); float* chan = (float*) (allocatedData + channelListSize); - for (int i = 0; i < numChannels; ++i) + for (uint32_t i = 0; i < numChannels; ++i) { channels[i] = chan; chan += size; @@ -718,22 +745,20 @@ private: return true; } - bool allocateChannels (float* const* const dataToReferTo, int offset) + bool allocateChannels (float* const* const dataToReferTo, const uint32_t offset) { - CARLA_SAFE_ASSERT_RETURN (offset >= 0, false); - // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools) - if (numChannels < (int) numElementsInArray (preallocatedChannelSpace)) + if (numChannels < numElementsInArray (preallocatedChannelSpace)) { channels = static_cast (preallocatedChannelSpace); } else { - CARLA_SAFE_ASSERT_RETURN( allocatedData.malloc ((size_t) numChannels + 1, sizeof (float*)), false); + CARLA_SAFE_ASSERT_RETURN( allocatedData.malloc (numChannels + 1, sizeof (float*)), false); channels = reinterpret_cast (allocatedData.getData()); } - for (int i = 0; i < numChannels; ++i) + for (uint32_t i = 0; i < numChannels; ++i) { // you have to pass in the same number of valid pointers as numChannels CARLA_SAFE_ASSERT_CONTINUE (dataToReferTo[i] != nullptr); @@ -745,6 +770,8 @@ private: isClear = false; return true; } + + // CARLA_DECLARE_NON_COPY_CLASS(AudioSampleBuffer) }; } diff --git a/source/modules/water/containers/Array.h b/source/modules/water/containers/Array.h index 66fcd395a..d1c1053d3 100644 --- a/source/modules/water/containers/Array.h +++ b/source/modules/water/containers/Array.h @@ -61,7 +61,9 @@ private: public: //============================================================================== /** Creates an empty array. */ - Array() noexcept : numUsed (0) + Array() noexcept + : data(), + numUsed(0) { } @@ -69,7 +71,8 @@ public: @param other the array to copy */ Array (const Array& other) noexcept - : numUsed (0) + : data(), + numUsed(0) { CARLA_SAFE_ASSERT_RETURN(data.setAllocatedSize (other.numUsed),); numUsed = other.numUsed; @@ -385,7 +388,7 @@ public: */ bool add (ElementType&& newElement) noexcept { - if (! data.ensureAllocatedSize (numUsed + 1)) + if (! data.ensureAllocatedSize (static_cast(numUsed + 1))) return false; new (data.elements + numUsed++) ElementType (static_cast (newElement)); @@ -1099,7 +1102,7 @@ private: void minimiseStorageAfterRemoval() { - if (data.numAllocated > jmax (minimumAllocatedSize, numUsed * 2)) + if (data.numAllocated > static_cast(jmax (minimumAllocatedSize, numUsed * 2))) data.shrinkToNoMoreThan (jmax (numUsed, jmax (minimumAllocatedSize, 64 / (int) sizeof (ElementType)))); } }; diff --git a/source/modules/water/containers/ArrayAllocationBase.h b/source/modules/water/containers/ArrayAllocationBase.h index 7a79bca23..34a5c50e1 100644 --- a/source/modules/water/containers/ArrayAllocationBase.h +++ b/source/modules/water/containers/ArrayAllocationBase.h @@ -71,7 +71,8 @@ public: //============================================================================== /** Creates an empty array. */ ArrayAllocationBase() noexcept - : numAllocated (0) + : elements(), + numAllocated(0) { } @@ -106,7 +107,7 @@ public: #else bool #endif - setAllocatedSize (const int numNewElements) noexcept + setAllocatedSize (const size_t numNewElements) noexcept { if (numAllocated != numNewElements) { @@ -128,7 +129,7 @@ public: #if WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS template - NonTriviallyCopyableBool setAllocatedSize (const int numNewElements) noexcept + NonTriviallyCopyableBool setAllocatedSize (const size_t numNewElements) noexcept { if (numAllocated != numNewElements) { @@ -139,7 +140,7 @@ public: if (! newElements.malloc (numNewElements)) return false; - for (int i = 0; i < numNewElements; ++i) + for (size_t i = 0; i < numNewElements; ++i) { if (i < numAllocated) { @@ -174,10 +175,10 @@ public: @param minNumElements the minimum number of elements that are needed */ - bool ensureAllocatedSize (const int minNumElements) noexcept + bool ensureAllocatedSize (const size_t minNumElements) noexcept { if (minNumElements > numAllocated) - return setAllocatedSize ((minNumElements + minNumElements / 2 + 8) & ~7); + return setAllocatedSize ((minNumElements + minNumElements / 2U + 8U) & ~7U); return true; } @@ -185,7 +186,7 @@ public: /** Minimises the amount of storage allocated so that it's no more than the given number of elements. */ - bool shrinkToNoMoreThan (const int maxNumElements) noexcept + bool shrinkToNoMoreThan (const size_t maxNumElements) noexcept { if (maxNumElements < numAllocated) return setAllocatedSize (maxNumElements); @@ -205,28 +206,28 @@ public: #else void #endif - moveMemory (ElementType* target, const ElementType* source, const int numElements) noexcept + moveMemory (ElementType* target, const ElementType* source, const size_t numElements) noexcept { CARLA_SAFE_ASSERT_RETURN(target != nullptr,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,); CARLA_SAFE_ASSERT_RETURN(target != source,); - CARLA_SAFE_ASSERT_RETURN(numElements > 0,); + CARLA_SAFE_ASSERT_RETURN(numElements != 0,); std::memmove (target, source, ((size_t) numElements) * sizeof (ElementType)); } #if WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS template - NonTriviallyCopyableVoid moveMemory (ElementType* target, const ElementType* source, const int numElements) noexcept + NonTriviallyCopyableVoid moveMemory (ElementType* target, const ElementType* source, const size_t numElements) noexcept { CARLA_SAFE_ASSERT_RETURN(target != nullptr,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,); CARLA_SAFE_ASSERT_RETURN(target != source,); - CARLA_SAFE_ASSERT_RETURN(numElements > 0,); + CARLA_SAFE_ASSERT_RETURN(numElements != 0,); if (target > source) { - for (int i = numElements; --i >= 0;) + for (size_t i = 0; i < numElements; ++i) { moveElement (target, std::move (*source)); ++target; @@ -235,7 +236,7 @@ public: } else { - for (int i = numElements; --i >= 0;) + for (size_t i = 0; i < numElements; ++i) { moveElement (target, std::move (*source)); --target; @@ -253,7 +254,7 @@ public: //============================================================================== HeapBlock elements; - int numAllocated; + size_t numAllocated; private: CARLA_DECLARE_NON_COPY_CLASS (ArrayAllocationBase) diff --git a/source/modules/water/containers/NamedValueSet.h b/source/modules/water/containers/NamedValueSet.h index 9af491056..7d0caa02e 100644 --- a/source/modules/water/containers/NamedValueSet.h +++ b/source/modules/water/containers/NamedValueSet.h @@ -64,8 +64,8 @@ public: //============================================================================== struct NamedValue { - NamedValue() noexcept {} - NamedValue (const Identifier& n, const var& v) : name (n), value (v) {} + NamedValue() noexcept : name(), value() {} + NamedValue (const Identifier& n, const var& v) : name (n), value (v) {} NamedValue (const NamedValue& other) : name (other.name), value (other.value) {} #if WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS diff --git a/source/modules/water/containers/OwnedArray.h b/source/modules/water/containers/OwnedArray.h index d659c4d25..171ec68b8 100644 --- a/source/modules/water/containers/OwnedArray.h +++ b/source/modules/water/containers/OwnedArray.h @@ -117,7 +117,7 @@ public: /** Returns the number of items currently in the array. @see operator[] */ - inline int size() const noexcept + inline size_t size() const noexcept { return numUsed; } @@ -136,11 +136,11 @@ public: @see getUnchecked */ - inline ObjectClass* operator[] (const int index) const noexcept + inline ObjectClass* operator[] (const size_t index) const noexcept { - if (isPositiveAndBelow (index, numUsed)) + if (index < numUsed) { - jassert (data.elements != nullptr); + CARLA_SAFE_ASSERT_RETURN(data.elements != nullptr, nullptr); return data.elements [index]; } @@ -154,7 +154,6 @@ public: */ inline ObjectClass* getUnchecked (const int index) const noexcept { - jassert (isPositiveAndBelow (index, numUsed) && data.elements != nullptr); return data.elements [index]; } @@ -167,7 +166,7 @@ public: { if (numUsed > 0) { - jassert (data.elements != nullptr); + CARLA_SAFE_ASSERT_RETURN(data.elements != nullptr, nullptr); return data.elements [0]; } @@ -183,7 +182,7 @@ public: { if (numUsed > 0) { - jassert (data.elements != nullptr); + CARLA_SAFE_ASSERT_RETURN(data.elements != nullptr, nullptr); return data.elements [numUsed - 1]; } @@ -301,14 +300,16 @@ public: if (indexToInsertAt < 0) return add (newObject); - if (indexToInsertAt > numUsed) - indexToInsertAt = numUsed; + size_t uindexToInsertAt = indexToInsertAt; + + if (uindexToInsertAt > numUsed) + uindexToInsertAt = numUsed; if (! data.ensureAllocatedSize (numUsed + 1)) return nullptr; - ObjectClass** const e = data.elements + indexToInsertAt; - const int numToMove = numUsed - indexToInsertAt; + ObjectClass** const e = data.elements + uindexToInsertAt; + const int numToMove = numUsed - uindexToInsertAt; if (numToMove > 0) std::memmove (e + 1, e, sizeof (ObjectClass*) * (size_t) numToMove); @@ -330,20 +331,20 @@ public: @param numberOfElements how many items are in the array @see insert, add, addSorted, set */ - void insertArray (int indexToInsertAt, + void insertArray (const size_t indexToInsertAt, ObjectClass* const* newObjects, - int numberOfElements) + const size_t numberOfElements) { if (numberOfElements > 0) { data.ensureAllocatedSize (numUsed + numberOfElements); ObjectClass** insertPos = data.elements; - if (isPositiveAndBelow (indexToInsertAt, numUsed)) + if (indexToInsertAt < numUsed) { insertPos += indexToInsertAt; - const size_t numberToMove = (size_t) (numUsed - indexToInsertAt); - memmove (insertPos + numberOfElements, insertPos, numberToMove * sizeof (ObjectClass*)); + const size_t numberToMove = numUsed - indexToInsertAt; + std::memmove (insertPos + numberOfElements, insertPos, numberToMove * sizeof (ObjectClass*)); } else { @@ -352,7 +353,7 @@ public: numUsed += numberOfElements; - while (--numberOfElements >= 0) + for (size_t i=0; i < numberOfElements; ++i) *insertPos++ = *newObjects++; } } @@ -470,15 +471,9 @@ public: */ template void addCopiesOf (const OtherArrayType& arrayToAddFrom, - int startIndex = 0, + size_t startIndex = 0, int numElementsToAdd = -1) { - if (startIndex < 0) - { - jassertfalse; - startIndex = 0; - } - if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size()) numElementsToAdd = arrayToAddFrom.size() - startIndex; @@ -558,24 +553,22 @@ public: @param deleteObject whether to delete the object that is removed @see removeObject, removeRange */ - void remove (int indexToRemove, bool deleteObject = true) + void remove (const size_t indexToRemove, bool deleteObject = true) { ScopedPointer toDelete; + if (indexToRemove < numUsed) { - if (isPositiveAndBelow (indexToRemove, numUsed)) - { - ObjectClass** const e = data.elements + indexToRemove; + ObjectClass** const e = data.elements + indexToRemove; - if (deleteObject) - toDelete = *e; + if (deleteObject) + toDelete = *e; - --numUsed; - const int numToShift = numUsed - indexToRemove; + --numUsed; + const size_t numToShift = numUsed - indexToRemove; - if (numToShift > 0) - memmove (e, e + 1, sizeof (ObjectClass*) * (size_t) numToShift); - } + if (numToShift > 0) + std::memmove (e, e + 1, sizeof (ObjectClass*) * numToShift); } if ((numUsed << 1) < data.numAllocated) @@ -591,19 +584,19 @@ public: @param indexToRemove the index of the element to remove @see remove, removeObject, removeRange */ - ObjectClass* removeAndReturn (int indexToRemove) + ObjectClass* removeAndReturn (const size_t indexToRemove) { ObjectClass* removedItem = nullptr; - if (isPositiveAndBelow (indexToRemove, numUsed)) + if (indexToRemove < numUsed) { ObjectClass** const e = data.elements + indexToRemove; removedItem = *e; --numUsed; - const int numToShift = numUsed - indexToRemove; + const size_t numToShift = numUsed - indexToRemove; if (numToShift > 0) - memmove (e, e + 1, sizeof (ObjectClass*) * (size_t) numToShift); + std::memmove (e, e + 1, sizeof (ObjectClass*) * (size_t) numToShift); if ((numUsed << 1) < data.numAllocated) minimiseStorageOverheads(); @@ -647,10 +640,10 @@ public: @param deleteObjects whether to delete the objects that get removed @see remove, removeObject */ - void removeRange (int startIndex, int numberToRemove, bool deleteObjects = true) + void removeRange (size_t startIndex, const size_t numberToRemove, bool deleteObjects = true) { - const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove); - startIndex = jlimit (0, numUsed, startIndex); + const size_t endIndex = jlimit (0UL, numUsed, startIndex + numberToRemove); + startIndex = jlimit (0UL, numUsed, startIndex); if (endIndex > startIndex) { @@ -663,12 +656,12 @@ public: } } - const int rangeSize = endIndex - startIndex; + const size_t rangeSize = endIndex - startIndex; ObjectClass** e = data.elements + startIndex; - int numToShift = numUsed - endIndex; + size_t numToShift = numUsed - endIndex; numUsed -= rangeSize; - while (--numToShift >= 0) + for (size_t i=0; i < numToShift; ++i) { *e = e [rangeSize]; ++e; @@ -699,11 +692,10 @@ public: If either of the indexes passed in is out-of-range, nothing will happen, otherwise the two objects at these positions will be exchanged. */ - void swap (int index1, - int index2) noexcept + void swap (const size_t index1, + const size_t index2) noexcept { - if (isPositiveAndBelow (index1, numUsed) - && isPositiveAndBelow (index2, numUsed)) + if (index1 < numUsed && index2 < numUsed) { std::swap (data.elements [index1], data.elements [index2]); @@ -723,28 +715,28 @@ public: @param newIndex the index at which you'd like this object to end up. If this is less than zero, it will be moved to the end of the array */ - void move (int currentIndex, int newIndex) noexcept + void move (const size_t currentIndex, const size_t newIndex) noexcept { if (currentIndex != newIndex) { - if (isPositiveAndBelow (currentIndex, numUsed)) + if (currentIndex < numUsed) { - if (! isPositiveAndBelow (newIndex, numUsed)) + if (newIndex >= numUsed) newIndex = numUsed - 1; ObjectClass* const value = data.elements [currentIndex]; if (newIndex > currentIndex) { - memmove (data.elements + currentIndex, - data.elements + currentIndex + 1, - sizeof (ObjectClass*) * (size_t) (newIndex - currentIndex)); + std::memmove (data.elements + currentIndex, + data.elements + currentIndex + 1, + sizeof (ObjectClass*) * (size_t) (newIndex - currentIndex)); } else { - memmove (data.elements + newIndex + 1, - data.elements + newIndex, - sizeof (ObjectClass*) * (size_t) (currentIndex - newIndex)); + std::memmove (data.elements + newIndex + 1, + data.elements + newIndex, + sizeof (ObjectClass*) * (size_t) (currentIndex - newIndex)); } data.elements [newIndex] = value; @@ -826,7 +818,7 @@ public: private: //============================================================================== ArrayAllocationBase data; - int numUsed; + size_t numUsed; void deleteAllObjects() { diff --git a/source/modules/water/containers/ReferenceCountedArray.h b/source/modules/water/containers/ReferenceCountedArray.h index 1ee512df3..efeaa51df 100644 --- a/source/modules/water/containers/ReferenceCountedArray.h +++ b/source/modules/water/containers/ReferenceCountedArray.h @@ -549,9 +549,9 @@ public: const int numberToShift = numUsed - indexToRemove; if (numberToShift > 0) - memmove (e, e + 1, sizeof (ObjectClass*) * (size_t) numberToShift); + std::memmove (e, e + 1, sizeof (ObjectClass*) * (size_t) numberToShift); - if ((numUsed << 1) < data.numAllocated) + if ((numUsed << 1) < static_cast(data.numAllocated)) minimiseStorageOverheads(); } } diff --git a/source/modules/water/files/File.cpp b/source/modules/water/files/File.cpp index 25d2a080a..64f69d473 100644 --- a/source/modules/water/files/File.cpp +++ b/source/modules/water/files/File.cpp @@ -54,6 +54,11 @@ namespace water { +File::File () noexcept + : fullPath () +{ +} + File::File (const String& fullPathName) : fullPath (parseAbsolutePath (fullPathName)) { diff --git a/source/modules/water/files/File.h b/source/modules/water/files/File.h index 496f9818b..5f3180375 100644 --- a/source/modules/water/files/File.h +++ b/source/modules/water/files/File.h @@ -54,7 +54,7 @@ public: You can use its operator= method to point it at a proper file. */ - File() noexcept {} + File() noexcept; /** Creates a file from an absolute path. @@ -760,11 +760,7 @@ public: if (foldersFirst && (firstFile.isDirectory() != secondFile.isDirectory())) return firstFile.isDirectory() ? -1 : 1; - #if NAMES_ARE_CASE_SENSITIVE - return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), true); - #else - return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), false); - #endif + return firstFile.getFullPathName().compareNatural (secondFile.getFullPathName(), File::areFileNamesCaseSensitive()); } bool foldersFirst; diff --git a/source/modules/water/maths/MathsFunctions.h b/source/modules/water/maths/MathsFunctions.h index c09df1562..95b3862dc 100644 --- a/source/modules/water/maths/MathsFunctions.h +++ b/source/modules/water/maths/MathsFunctions.h @@ -170,7 +170,8 @@ Type jlimit (const Type lowerLimit, const Type upperLimit, const Type valueToConstrain) noexcept { - jassert (lowerLimit <= upperLimit); // if these are in the wrong order, results are unpredictable.. + // if these are in the wrong order, results are unpredictable.. + CARLA_SAFE_ASSERT_RETURN(lowerLimit <= upperLimit, lowerLimit); return (valueToConstrain < lowerLimit) ? lowerLimit : ((upperLimit < valueToConstrain) ? upperLimit @@ -185,14 +186,18 @@ Type jlimit (const Type lowerLimit, template bool isPositiveAndBelow (Type valueToTest, Type upperLimit) noexcept { - jassert (Type() <= upperLimit); // makes no sense to call this if the upper limit is itself below zero.. + // makes no sense to call this if the upper limit is itself below zero.. + CARLA_SAFE_ASSERT_RETURN(Type() <= upperLimit, false); + return Type() <= valueToTest && valueToTest < upperLimit; } template <> inline bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noexcept { - jassert (upperLimit >= 0); // makes no sense to call this if the upper limit is itself below zero.. + // makes no sense to call this if the upper limit is itself below zero.. + CARLA_SAFE_ASSERT_RETURN(upperLimit >= 0, false); + return static_cast (valueToTest) < static_cast (upperLimit); } @@ -204,14 +209,18 @@ inline bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noe template bool isPositiveAndNotGreaterThan (Type valueToTest, Type upperLimit) noexcept { - jassert (Type() <= upperLimit); // makes no sense to call this if the upper limit is itself below zero.. + // makes no sense to call this if the upper limit is itself below zero.. + CARLA_SAFE_ASSERT_RETURN(Type() <= upperLimit, false); + return Type() <= valueToTest && valueToTest <= upperLimit; } template <> inline bool isPositiveAndNotGreaterThan (const int valueToTest, const int upperLimit) noexcept { - jassert (upperLimit >= 0); // makes no sense to call this if the upper limit is itself below zero.. + // makes no sense to call this if the upper limit is itself below zero.. + CARLA_SAFE_ASSERT_RETURN(upperLimit >= 0, false); + return static_cast (valueToTest) <= static_cast (upperLimit); } @@ -239,13 +248,13 @@ void ignoreUnused (const Type1&, const Type2&, const Type3&, const Type4&) noexc /** Handy function for getting the number of elements in a simple const C array. E.g. @code - static int myArray[] = { 1, 2, 3 }; + static size_t myArray[] = { 1, 2, 3 }; - int numElements = numElementsInArray (myArray) // returns 3 + size_t numElements = numElementsInArray (myArray) // returns 3 @endcode */ -template -int numElementsInArray (Type (&array)[N]) +template +size_t numElementsInArray (Type (&array)[N]) { ignoreUnused (array); (void) sizeof (0[array]); // This line should cause an error if you pass an object with a user-defined subscript operator diff --git a/source/modules/water/memory/Atomic.h b/source/modules/water/memory/Atomic.h index d2614305d..3602c5e10 100644 --- a/source/modules/water/memory/Atomic.h +++ b/source/modules/water/memory/Atomic.h @@ -32,6 +32,14 @@ namespace water { +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Weffc++" +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Weffc++" +#endif + //============================================================================== /** Simple class to hold a primitive value and perform atomic operations on it. @@ -159,10 +167,12 @@ private: template static inline Dest castTo (Source value) noexcept { union { Dest d; Source s; } u; u.s = value; return u.d; } - static inline Type castFrom32Bit (int32 value) noexcept { return castTo (value); } - static inline Type castFrom64Bit (int64 value) noexcept { return castTo (value); } - static inline int32 castTo32Bit (Type value) noexcept { return castTo (value); } - static inline int64 castTo64Bit (Type value) noexcept { return castTo (value); } + static inline Type castFrom32Bit (int32 value) noexcept { return castTo (value); } + static inline Type castFrom64Bit (int64 value) noexcept { return castTo (value); } + static inline Type castFrom32Bit (uint32 value) noexcept { return castTo (value); } + static inline Type castFrom64Bit (uint64 value) noexcept { return castTo (value); } + static inline int32 castTo32Bit (Type value) noexcept { return castTo (value); } + static inline int64 castTo64Bit (Type value) noexcept { return castTo (value); } Type operator++ (int); // better to just use pre-increment with atomics.. Type operator-- (int); @@ -186,11 +196,32 @@ private: }; //============================================================================== -template -inline Type Atomic::get() const noexcept +template<> +inline int32 Atomic::get() const noexcept +{ + static_jassert (sizeof (int32) == 4); + return castFrom32Bit ((int32) __sync_add_and_fetch (const_cast(&value), 0)); +} + +template<> +inline int64 Atomic::get() const noexcept +{ + static_jassert (sizeof (int64) == 8); + return castFrom64Bit ((int64) __sync_add_and_fetch (const_cast(&value), 0)); +} + +template<> +inline uint32 Atomic::get() const noexcept { - return sizeof (Type) == 4 ? castFrom32Bit ((int32) __sync_add_and_fetch ((volatile int32*) &value, 0)) - : castFrom64Bit ((int64) __sync_add_and_fetch ((volatile int64*) &value, 0)); + static_jassert (sizeof (uint32) == 4); + return castFrom32Bit ((uint32) __sync_add_and_fetch (const_cast(&value), 0)); +} + +template<> +inline uint64 Atomic::get() const noexcept +{ + static_jassert (sizeof (uint64) == 8); + return castFrom64Bit ((uint64) __sync_add_and_fetch (const_cast(&value), 0)); } template @@ -217,14 +248,14 @@ template inline Type Atomic::operator++() noexcept { return sizeof (Type) == 4 ? (Type) __sync_add_and_fetch (&value, (Type) 1) - : (Type) __sync_add_and_fetch ((int64_t*) &value, 1); + : (Type) __sync_add_and_fetch ((volatile int64*) &value, 1); } template inline Type Atomic::operator--() noexcept { return sizeof (Type) == 4 ? (Type) __sync_add_and_fetch (&value, (Type) -1) - : (Type) __sync_add_and_fetch ((int64_t*) &value, -1); + : (Type) __sync_add_and_fetch ((volatile int64*) &value, -1); } template @@ -247,6 +278,12 @@ inline void Atomic::memoryBarrier() noexcept __sync_synchronize(); } +#if defined(__clang__) +# pragma clang diagnostic pop +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +# pragma GCC diagnostic pop +#endif + } #endif // WATER_ATOMIC_H_INCLUDED diff --git a/source/modules/water/memory/HeapBlock.h b/source/modules/water/memory/HeapBlock.h index 105770c21..97fef020b 100644 --- a/source/modules/water/memory/HeapBlock.h +++ b/source/modules/water/memory/HeapBlock.h @@ -253,6 +253,8 @@ public: private: //============================================================================== ElementType* data; + + CARLA_DECLARE_NON_COPY_CLASS(HeapBlock) }; } diff --git a/source/modules/water/memory/ReferenceCountedObject.h b/source/modules/water/memory/ReferenceCountedObject.h index af7f1e037..f0b2f7305 100644 --- a/source/modules/water/memory/ReferenceCountedObject.h +++ b/source/modules/water/memory/ReferenceCountedObject.h @@ -104,7 +104,8 @@ public: protected: //============================================================================== /** Creates the reference-counted object (with an initial ref count of zero). */ - ReferenceCountedObject() {} + ReferenceCountedObject() + : refCount() {} /** Destructor. */ virtual ~ReferenceCountedObject() @@ -123,7 +124,7 @@ protected: private: //============================================================================== - Atomic refCount; + Atomic refCount; CARLA_DECLARE_NON_COPY_CLASS (ReferenceCountedObject) }; diff --git a/source/modules/water/midi/MidiFile.cpp b/source/modules/water/midi/MidiFile.cpp index e87bc120d..aea60fddd 100644 --- a/source/modules/water/midi/MidiFile.cpp +++ b/source/modules/water/midi/MidiFile.cpp @@ -160,7 +160,7 @@ namespace MidiFileHelpers MidiMessageSequence& results, MethodType method) { - for (int i = 0; i < tracks.size(); ++i) + for (size_t i = 0; i < tracks.size(); ++i) { const MidiMessageSequence& track = *tracks.getUnchecked(i); const int numEvents = track.getNumEvents(); @@ -207,12 +207,12 @@ void MidiFile::clear() } //============================================================================== -int MidiFile::getNumTracks() const noexcept +size_t MidiFile::getNumTracks() const noexcept { return tracks.size(); } -const MidiMessageSequence* MidiFile::getTrack (const int index) const noexcept +const MidiMessageSequence* MidiFile::getTrack (const size_t index) const noexcept { return tracks [index]; } @@ -259,7 +259,7 @@ double MidiFile::getLastTimestamp() const { double t = 0.0; - for (int i = tracks.size(); --i >= 0;) + for (size_t i=0; i < tracks.size(); ++i) t = jmax (t, tracks.getUnchecked(i)->getEndTime()); return t; @@ -359,7 +359,7 @@ void MidiFile::convertTimestampTicksToSeconds() if (timeFormat != 0) { - for (int i = 0; i < tracks.size(); ++i) + for (size_t i = 0; i < tracks.size(); ++i) { const MidiMessageSequence& ms = *tracks.getUnchecked(i); @@ -383,7 +383,7 @@ bool MidiFile::writeTo (OutputStream& out, int midiFileType) if (! out.writeShortBigEndian ((short) tracks.size())) return false; if (! out.writeShortBigEndian (timeFormat)) return false; - for (int i = 0; i < tracks.size(); ++i) + for (size_t i = 0; i < tracks.size(); ++i) if (! writeTrack (out, i)) return false; diff --git a/source/modules/water/midi/MidiFile.h b/source/modules/water/midi/MidiFile.h index 89b9377e3..3dd75c8f7 100644 --- a/source/modules/water/midi/MidiFile.h +++ b/source/modules/water/midi/MidiFile.h @@ -64,13 +64,13 @@ public: /** Returns the number of tracks in the file. @see getTrack, addTrack */ - int getNumTracks() const noexcept; + size_t getNumTracks() const noexcept; /** Returns a pointer to one of the tracks in the file. @returns a pointer to the track, or nullptr if the index is out-of-range @see getNumTracks, addTrack */ - const MidiMessageSequence* getTrack (int index) const noexcept; + const MidiMessageSequence* getTrack (size_t index) const noexcept; /** Adds a midi track to the file. This will make its own internal copy of the sequence that is passed-in. diff --git a/source/modules/water/midi/MidiMessage.cpp b/source/modules/water/midi/MidiMessage.cpp index f36604332..a82df144b 100644 --- a/source/modules/water/midi/MidiMessage.cpp +++ b/source/modules/water/midi/MidiMessage.cpp @@ -324,7 +324,7 @@ uint8* MidiMessage::allocateSpace (int bytes) int MidiMessage::getChannel() const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); if ((data[0] & 0xf0) != 0xf0) return (data[0] & 0xf) + 1; @@ -336,7 +336,7 @@ bool MidiMessage::isForChannel (const int channel) const noexcept { jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16 - const uint8* const data = getRawData(); + const uint8* const data = getData(); return ((data[0] & 0xf) == channel - 1) && ((data[0] & 0xf0) != 0xf0); @@ -355,7 +355,7 @@ void MidiMessage::setChannel (const int channel) noexcept bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); return ((data[0] & 0xf0) == 0x90) && (returnTrueForVelocity0 || data[2] != 0); @@ -363,7 +363,7 @@ bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const noexcept bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); return ((data[0] & 0xf0) == 0x80) || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90)); @@ -371,7 +371,7 @@ bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const noex bool MidiMessage::isNoteOnOrOff() const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); const int d = data[0] & 0xf0; return (d == 0x90) || (d == 0x80); @@ -379,7 +379,7 @@ bool MidiMessage::isNoteOnOrOff() const noexcept int MidiMessage::getNoteNumber() const noexcept { - return getRawData()[1]; + return getData()[1]; } void MidiMessage::setNoteNumber (const int newNoteNumber) noexcept @@ -391,7 +391,7 @@ void MidiMessage::setNoteNumber (const int newNoteNumber) noexcept uint8 MidiMessage::getVelocity() const noexcept { if (isNoteOnOrOff()) - return getRawData()[2]; + return getData()[2]; return 0; } @@ -418,13 +418,13 @@ void MidiMessage::multiplyVelocity (const float scaleFactor) noexcept bool MidiMessage::isAftertouch() const noexcept { - return (getRawData()[0] & 0xf0) == 0xa0; + return (getData()[0] & 0xf0) == 0xa0; } int MidiMessage::getAfterTouchValue() const noexcept { jassert (isAftertouch()); - return getRawData()[2]; + return getData()[2]; } MidiMessage MidiMessage::aftertouchChange (const int channel, @@ -442,13 +442,13 @@ MidiMessage MidiMessage::aftertouchChange (const int channel, bool MidiMessage::isChannelPressure() const noexcept { - return (getRawData()[0] & 0xf0) == 0xd0; + return (getData()[0] & 0xf0) == 0xd0; } int MidiMessage::getChannelPressureValue() const noexcept { jassert (isChannelPressure()); - return getRawData()[1]; + return getData()[1]; } MidiMessage MidiMessage::channelPressureChange (const int channel, const int pressure) noexcept @@ -459,25 +459,25 @@ MidiMessage MidiMessage::channelPressureChange (const int channel, const int pre return MidiMessage (MidiHelpers::initialByte (0xd0, channel), pressure & 0x7f); } -bool MidiMessage::isSustainPedalOn() const noexcept { return isControllerOfType (0x40) && getRawData()[2] >= 64; } -bool MidiMessage::isSustainPedalOff() const noexcept { return isControllerOfType (0x40) && getRawData()[2] < 64; } +bool MidiMessage::isSustainPedalOn() const noexcept { return isControllerOfType (0x40) && getData()[2] >= 64; } +bool MidiMessage::isSustainPedalOff() const noexcept { return isControllerOfType (0x40) && getData()[2] < 64; } -bool MidiMessage::isSostenutoPedalOn() const noexcept { return isControllerOfType (0x42) && getRawData()[2] >= 64; } -bool MidiMessage::isSostenutoPedalOff() const noexcept { return isControllerOfType (0x42) && getRawData()[2] < 64; } +bool MidiMessage::isSostenutoPedalOn() const noexcept { return isControllerOfType (0x42) && getData()[2] >= 64; } +bool MidiMessage::isSostenutoPedalOff() const noexcept { return isControllerOfType (0x42) && getData()[2] < 64; } -bool MidiMessage::isSoftPedalOn() const noexcept { return isControllerOfType (0x43) && getRawData()[2] >= 64; } -bool MidiMessage::isSoftPedalOff() const noexcept { return isControllerOfType (0x43) && getRawData()[2] < 64; } +bool MidiMessage::isSoftPedalOn() const noexcept { return isControllerOfType (0x43) && getData()[2] >= 64; } +bool MidiMessage::isSoftPedalOff() const noexcept { return isControllerOfType (0x43) && getData()[2] < 64; } bool MidiMessage::isProgramChange() const noexcept { - return (getRawData()[0] & 0xf0) == 0xc0; + return (getData()[0] & 0xf0) == 0xc0; } int MidiMessage::getProgramChangeNumber() const noexcept { jassert (isProgramChange()); - return getRawData()[1]; + return getData()[1]; } MidiMessage MidiMessage::programChange (const int channel, const int programNumber) noexcept @@ -489,13 +489,13 @@ MidiMessage MidiMessage::programChange (const int channel, const int programNumb bool MidiMessage::isPitchWheel() const noexcept { - return (getRawData()[0] & 0xf0) == 0xe0; + return (getData()[0] & 0xf0) == 0xe0; } int MidiMessage::getPitchWheelValue() const noexcept { jassert (isPitchWheel()); - const uint8* const data = getRawData(); + const uint8* const data = getData(); return data[1] | (data[2] << 7); } @@ -510,25 +510,25 @@ MidiMessage MidiMessage::pitchWheel (const int channel, const int position) noex bool MidiMessage::isController() const noexcept { - return (getRawData()[0] & 0xf0) == 0xb0; + return (getData()[0] & 0xf0) == 0xb0; } bool MidiMessage::isControllerOfType (const int controllerType) const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); return (data[0] & 0xf0) == 0xb0 && data[1] == controllerType; } int MidiMessage::getControllerNumber() const noexcept { jassert (isController()); - return getRawData()[1]; + return getData()[1]; } int MidiMessage::getControllerValue() const noexcept { jassert (isController()); - return getRawData()[2]; + return getData()[2]; } MidiMessage MidiMessage::controllerEvent (const int channel, const int controllerType, const int value) noexcept @@ -583,7 +583,7 @@ MidiMessage MidiMessage::allNotesOff (const int channel) noexcept bool MidiMessage::isAllNotesOff() const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); return (data[0] & 0xf0) == 0xb0 && data[1] == 123; } @@ -594,7 +594,7 @@ MidiMessage MidiMessage::allSoundOff (const int channel) noexcept bool MidiMessage::isAllSoundOff() const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); return (data[0] & 0xf0) == 0xb0 && data[1] == 120; } @@ -618,7 +618,7 @@ MidiMessage MidiMessage::masterVolume (const float volume) //============================================================================== bool MidiMessage::isSysEx() const noexcept { - return *getRawData() == 0xf0; + return *getData() == 0xf0; } MidiMessage MidiMessage::createSysExMessage (const void* sysexData, const int dataSize) @@ -635,7 +635,7 @@ MidiMessage MidiMessage::createSysExMessage (const void* sysexData, const int da const uint8* MidiMessage::getSysExData() const noexcept { - return isSysEx() ? getRawData() + 1 : nullptr; + return isSysEx() ? getData() + 1 : nullptr; } int MidiMessage::getSysExDataSize() const noexcept @@ -644,18 +644,18 @@ int MidiMessage::getSysExDataSize() const noexcept } //============================================================================== -bool MidiMessage::isMetaEvent() const noexcept { return *getRawData() == 0xff; } -bool MidiMessage::isActiveSense() const noexcept { return *getRawData() == 0xfe; } +bool MidiMessage::isMetaEvent() const noexcept { return *getData() == 0xff; } +bool MidiMessage::isActiveSense() const noexcept { return *getData() == 0xfe; } int MidiMessage::getMetaEventType() const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); return *data != 0xff ? -1 : data[1]; } int MidiMessage::getMetaEventLength() const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); if (*data == 0xff) { int n; @@ -670,7 +670,7 @@ const uint8* MidiMessage::getMetaEventData() const noexcept jassert (isMetaEvent()); int n; - const uint8* d = getRawData() + 2; + const uint8* d = getData() + 2; readVariableLengthVal (d, n); return d + n; } @@ -722,14 +722,14 @@ MidiMessage MidiMessage::textMetaEvent (int type, StringRef text) return result; } -bool MidiMessage::isTrackNameEvent() const noexcept { const uint8* data = getRawData(); return (data[1] == 3) && (*data == 0xff); } -bool MidiMessage::isTempoMetaEvent() const noexcept { const uint8* data = getRawData(); return (data[1] == 81) && (*data == 0xff); } -bool MidiMessage::isMidiChannelMetaEvent() const noexcept { const uint8* data = getRawData(); return (data[1] == 0x20) && (*data == 0xff) && (data[2] == 1); } +bool MidiMessage::isTrackNameEvent() const noexcept { const uint8* data = getData(); return (data[1] == 3) && (*data == 0xff); } +bool MidiMessage::isTempoMetaEvent() const noexcept { const uint8* data = getData(); return (data[1] == 81) && (*data == 0xff); } +bool MidiMessage::isMidiChannelMetaEvent() const noexcept { const uint8* data = getData(); return (data[1] == 0x20) && (*data == 0xff) && (data[2] == 1); } int MidiMessage::getMidiChannelMetaEventChannel() const noexcept { jassert (isMidiChannelMetaEvent()); - return getRawData()[3] + 1; + return getData()[3] + 1; } double MidiMessage::getTempoSecondsPerQuarterNote() const noexcept @@ -784,7 +784,7 @@ MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) noexcep bool MidiMessage::isTimeSignatureMetaEvent() const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); return (data[1] == 0x58) && (*data == (uint8) 0xff); } @@ -853,8 +853,8 @@ MidiMessage MidiMessage::endOfTrack() noexcept } //============================================================================== -bool MidiMessage::isSongPositionPointer() const noexcept { return *getRawData() == 0xf2; } -int MidiMessage::getSongPositionPointerMidiBeat() const noexcept { const uint8* data = getRawData(); return data[1] | (data[2] << 7); } +bool MidiMessage::isSongPositionPointer() const noexcept { return *getData() == 0xf2; } +int MidiMessage::getSongPositionPointerMidiBeat() const noexcept { const uint8* data = getData(); return data[1] | (data[2] << 7); } MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) noexcept { @@ -863,21 +863,21 @@ MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) noe (positionInMidiBeats >> 7) & 127); } -bool MidiMessage::isMidiStart() const noexcept { return *getRawData() == 0xfa; } +bool MidiMessage::isMidiStart() const noexcept { return *getData() == 0xfa; } MidiMessage MidiMessage::midiStart() noexcept { return MidiMessage (0xfa); } -bool MidiMessage::isMidiContinue() const noexcept { return *getRawData() == 0xfb; } +bool MidiMessage::isMidiContinue() const noexcept { return *getData() == 0xfb; } MidiMessage MidiMessage::midiContinue() noexcept { return MidiMessage (0xfb); } -bool MidiMessage::isMidiStop() const noexcept { return *getRawData() == 0xfc; } +bool MidiMessage::isMidiStop() const noexcept { return *getData() == 0xfc; } MidiMessage MidiMessage::midiStop() noexcept { return MidiMessage (0xfc); } -bool MidiMessage::isMidiClock() const noexcept { return *getRawData() == 0xf8; } +bool MidiMessage::isMidiClock() const noexcept { return *getData() == 0xf8; } MidiMessage MidiMessage::midiClock() noexcept { return MidiMessage (0xf8); } -bool MidiMessage::isQuarterFrame() const noexcept { return *getRawData() == 0xf1; } -int MidiMessage::getQuarterFrameSequenceNumber() const noexcept { return ((int) getRawData()[1]) >> 4; } -int MidiMessage::getQuarterFrameValue() const noexcept { return ((int) getRawData()[1]) & 0x0f; } +bool MidiMessage::isQuarterFrame() const noexcept { return *getData() == 0xf1; } +int MidiMessage::getQuarterFrameSequenceNumber() const noexcept { return ((int) getData()[1]) >> 4; } +int MidiMessage::getQuarterFrameValue() const noexcept { return ((int) getData()[1]) & 0x0f; } MidiMessage MidiMessage::quarterFrame (const int sequenceNumber, const int value) noexcept { @@ -886,7 +886,7 @@ MidiMessage MidiMessage::quarterFrame (const int sequenceNumber, const int value bool MidiMessage::isFullFrame() const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); return data[0] == 0xf0 && data[1] == 0x7f @@ -900,7 +900,7 @@ void MidiMessage::getFullFrameParameters (int& hours, int& minutes, int& seconds { jassert (isFullFrame()); - const uint8* const data = getRawData(); + const uint8* const data = getData(); timecodeType = (SmpteTimecodeType) (data[5] >> 5); hours = data[5] & 0x1f; minutes = data[6]; @@ -924,7 +924,7 @@ MidiMessage MidiMessage::fullFrame (const int hours, const int minutes, bool MidiMessage::isMidiMachineControlMessage() const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); return data[0] == 0xf0 && data[1] == 0x7f && data[3] == 0x06 @@ -935,7 +935,7 @@ MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand { jassert (isMidiMachineControlMessage()); - return (MidiMachineControlCommand) getRawData()[4]; + return (MidiMachineControlCommand) getData()[4]; } MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command) @@ -948,7 +948,7 @@ MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineCont //============================================================================== bool MidiMessage::isMidiMachineControlGoto (int& hours, int& minutes, int& seconds, int& frames) const noexcept { - const uint8* const data = getRawData(); + const uint8* const data = getData(); if (size >= 12 && data[0] == 0xf0 && data[1] == 0x7f diff --git a/source/modules/water/midi/MidiMessage.h b/source/modules/water/midi/MidiMessage.h index a00b09fbe..07f15c467 100644 --- a/source/modules/water/midi/MidiMessage.h +++ b/source/modules/water/midi/MidiMessage.h @@ -900,8 +900,9 @@ private: double timeStamp; int size; - inline bool isHeapAllocated() const noexcept { return size > (int) sizeof (packedData); } - inline uint8* getData() const noexcept { return isHeapAllocated() ? packedData.allocatedData : (uint8*) packedData.asBytes; } + inline bool isHeapAllocated() const noexcept { return size > (int) sizeof (packedData); } + inline uint8* getData() noexcept { return isHeapAllocated() ? packedData.allocatedData : packedData.asBytes; } + inline const uint8* getData() const noexcept { return isHeapAllocated() ? packedData.allocatedData : packedData.asBytes; } uint8* allocateSpace (int); }; diff --git a/source/modules/water/midi/MidiMessageSequence.cpp b/source/modules/water/midi/MidiMessageSequence.cpp index b7b571450..b01e87f6c 100644 --- a/source/modules/water/midi/MidiMessageSequence.cpp +++ b/source/modules/water/midi/MidiMessageSequence.cpp @@ -142,7 +142,7 @@ MidiMessageSequence::MidiEventHolder* MidiMessageSequence::addEvent (const MidiM void MidiMessageSequence::deleteEvent (const int index, const bool deleteMatchingNoteUp) { - if (isPositiveAndBelow (index, list.size())) + if (isPositiveAndBelow (index, static_cast(list.size()))) { if (deleteMatchingNoteUp) deleteEvent (getIndexOfMatchingKeyUp (index), false); @@ -163,7 +163,7 @@ struct MidiMessageSequenceSorter void MidiMessageSequence::addSequence (const MidiMessageSequence& other, double timeAdjustment) { - for (int i = 0; i < other.list.size(); ++i) + for (int i = 0; i < static_cast(other.list.size()); ++i) { const MidiMessage& m = other.list.getUnchecked(i)->message; @@ -180,7 +180,7 @@ void MidiMessageSequence::addSequence (const MidiMessageSequence& other, double firstAllowableTime, double endOfAllowableDestTimes) { - for (int i = 0; i < other.list.size(); ++i) + for (int i = 0; i < static_cast(other.list.size()); ++i) { const MidiMessage& m = other.list.getUnchecked(i)->message; const double t = m.getTimeStamp() + timeAdjustment; @@ -206,7 +206,7 @@ void MidiMessageSequence::sort() noexcept void MidiMessageSequence::updateMatchedPairs() noexcept { - for (int i = 0; i < list.size(); ++i) + for (int i = 0; i < static_cast(list.size()); ++i) { MidiEventHolder* const meh = list.getUnchecked(i); const MidiMessage& m1 = meh->message; @@ -245,7 +245,7 @@ void MidiMessageSequence::updateMatchedPairs() noexcept void MidiMessageSequence::addTimeToMessages (const double delta) noexcept { - for (int i = list.size(); --i >= 0;) + for (int i = static_cast(list.size()); --i >= 0;) { MidiMessage& mm = list.getUnchecked(i)->message; mm.setTimeStamp (mm.getTimeStamp() + delta); @@ -257,7 +257,7 @@ void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToE MidiMessageSequence& destSequence, const bool alsoIncludeMetaEvents) const { - for (int i = 0; i < list.size(); ++i) + for (int i = 0; i < static_cast(list.size()); ++i) { const MidiMessage& mm = list.getUnchecked(i)->message; @@ -268,7 +268,7 @@ void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToE void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const { - for (int i = 0; i < list.size(); ++i) + for (int i = 0; i < static_cast(list.size()); ++i) { const MidiMessage& mm = list.getUnchecked(i)->message; diff --git a/source/modules/water/processors/AudioProcessorGraph.cpp b/source/modules/water/processors/AudioProcessorGraph.cpp index ba3da7ce6..81e24ed94 100644 --- a/source/modules/water/processors/AudioProcessorGraph.cpp +++ b/source/modules/water/processors/AudioProcessorGraph.cpp @@ -747,7 +747,7 @@ class ConnectionLookupTable public: explicit ConnectionLookupTable (const OwnedArray& connections) { - for (int i = 0; i < connections.size(); ++i) + for (int i = 0; i < static_cast(connections.size()); ++i) { const AudioProcessorGraph::Connection* const c = connections.getUnchecked(i); @@ -1275,10 +1275,10 @@ void AudioProcessorGraph::buildRenderingSequence() audioBuffers->setRenderingBufferSize (numRenderingBuffersNeeded, getBlockSize()); - for (int i = midiBuffers.size(); --i >= 0;) + for (int i = static_cast(midiBuffers.size()); --i >= 0;) midiBuffers.getUnchecked(i)->clear(); - while (midiBuffers.size() < numMidiBuffersNeeded) + while (static_cast(midiBuffers.size()) < numMidiBuffersNeeded) midiBuffers.add (new MidiBuffer()); renderingOps.swapWith (newRenderingOps); @@ -1362,7 +1362,7 @@ void AudioProcessorGraph::processAudio (AudioSampleBuffer& buffer, MidiBuffer& m op->perform (renderingBuffers, midiBuffers, numSamples); } - for (int i = 0; i < buffer.getNumChannels(); ++i) + for (uint32_t i = 0; i < buffer.getNumChannels(); ++i) buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples); midiMessages.clear(); diff --git a/source/modules/water/processors/AudioProcessorGraph.h b/source/modules/water/processors/AudioProcessorGraph.h index 8d1f1337a..a2cdb9f71 100644 --- a/source/modules/water/processors/AudioProcessorGraph.h +++ b/source/modules/water/processors/AudioProcessorGraph.h @@ -190,10 +190,10 @@ public: //============================================================================== /** Returns the number of connections in the graph. */ - int getNumConnections() const { return connections.size(); } + size_t getNumConnections() const { return connections.size(); } /** Returns a pointer to one of the connections in the graph. */ - const Connection* getConnection (int index) const { return connections [index]; } + const Connection* getConnection (size_t index) const { return connections [index]; } /** Searches for a connection between some specified channels. If no such connection is found, this returns nullptr. diff --git a/source/modules/water/synthesisers/Synthesiser.cpp b/source/modules/water/synthesisers/Synthesiser.cpp index 4b3c4c19b..2fc39c79e 100644 --- a/source/modules/water/synthesisers/Synthesiser.cpp +++ b/source/modules/water/synthesisers/Synthesiser.cpp @@ -90,7 +90,7 @@ Synthesiser::Synthesiser() subBlockSubdivisionIsStrict (false), shouldStealNotes (true) { - for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i) + for (size_t i = 0; i < numElementsInArray (lastPitchWheelValues); ++i) lastPitchWheelValues[i] = 0x2000; zerostruct(sustainPedalsDown); @@ -506,7 +506,7 @@ SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay, const bool stealIfNoneAvailable) const { - for (int i = 0; i < voices.size(); ++i) + for (size_t i = 0; i < voices.size(); ++i) { SynthesiserVoice* const voice = voices.getUnchecked (i); @@ -546,7 +546,7 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay, Array usableVoices; usableVoices.ensureStorageAllocated (voices.size()); - for (int i = 0; i < voices.size(); ++i) + for (size_t i = 0; i < voices.size(); ++i) { SynthesiserVoice* const voice = voices.getUnchecked (i); diff --git a/source/modules/water/synthesisers/Synthesiser.h b/source/modules/water/synthesisers/Synthesiser.h index b57a45da6..e6073b302 100644 --- a/source/modules/water/synthesisers/Synthesiser.h +++ b/source/modules/water/synthesisers/Synthesiser.h @@ -311,7 +311,7 @@ public: void clearVoices(); /** Returns the number of voices that have been added. */ - int getNumVoices() const noexcept { return voices.size(); } + size_t getNumVoices() const noexcept { return voices.size(); } /** Returns one of the voices that have been added. */ SynthesiserVoice* getVoice (int index) const; diff --git a/source/modules/water/text/CharPointer_UTF8.h b/source/modules/water/text/CharPointer_UTF8.h index 8eb880f55..e3beae701 100644 --- a/source/modules/water/text/CharPointer_UTF8.h +++ b/source/modules/water/text/CharPointer_UTF8.h @@ -54,13 +54,13 @@ public: { } - inline CharPointer_UTF8 operator= (CharPointer_UTF8 other) noexcept + inline CharPointer_UTF8& operator= (CharPointer_UTF8 other) noexcept { data = other.data; return *this; } - inline CharPointer_UTF8 operator= (const CharType* text) noexcept + inline CharPointer_UTF8& operator= (const CharType* text) noexcept { data = const_cast (text); return *this; @@ -129,7 +129,7 @@ public: { water_uchar bit = 0x40; - while ((n & bit) != 0 && bit > 0x8) + while ((static_cast(n) & bit) != 0 && bit > 0x8) { ++data; bit >>= 1; @@ -140,7 +140,7 @@ public: } /** Moves this pointer back to the previous character in the string. */ - CharPointer_UTF8 operator--() noexcept + CharPointer_UTF8& operator--() noexcept { int count = 0; diff --git a/source/modules/water/water.h b/source/modules/water/water.h index 67bbc4877..31a4f7814 100644 --- a/source/modules/water/water.h +++ b/source/modules/water/water.h @@ -155,7 +155,7 @@ namespace NumberToStringConverters do { - *--t = '0' + (char) (v % 10); + *--t = static_cast('0' + (v % 10)); v /= 10; } while (v > 0); diff --git a/source/native-plugins/Makefile b/source/native-plugins/Makefile index ab05a5fba..3ff5bcd07 100644 --- a/source/native-plugins/Makefile +++ b/source/native-plugins/Makefile @@ -81,6 +81,6 @@ $(OBJDIR)/%.cpp.o: %.cpp # --------------------------------------------------------------------------------------------------------------------- --include $(OBJS_all:%.o=%.d) +-include $(OBJS:%.o=%.d) # --------------------------------------------------------------------------------------------------------------------- diff --git a/source/native-plugins/_all.c b/source/native-plugins/_all.c index 18b83ed5a..dcf4d34c2 100644 --- a/source/native-plugins/_all.c +++ b/source/native-plugins/_all.c @@ -46,6 +46,7 @@ extern void carla_register_native_plugin_bigmeter(void); extern void carla_register_native_plugin_notes(void); #ifdef HAVE_EXTERNAL_PLUGINS +void carla_register_all_native_external_plugins(void); # define CARLA_EXTERNAL_PLUGINS_INCLUDED_DIRECTLY # include "external/_all.c" #endif diff --git a/source/native-plugins/audio-base.hpp b/source/native-plugins/audio-base.hpp index 8ec546392..57f569924 100644 --- a/source/native-plugins/audio-base.hpp +++ b/source/native-plugins/audio-base.hpp @@ -29,20 +29,20 @@ typedef struct adinfo ADInfo; struct AudioFilePool { float* buffer[2]; + uint64_t startFrame; uint32_t sampleRate; - uint32_t startFrame; uint32_t size; #ifdef CARLA_PROPER_CPP11_SUPPORT AudioFilePool() : buffer{nullptr}, - sampleRate(0), startFrame(0), + sampleRate(0), size(0) {} #else AudioFilePool() - : sampleRate(0), - startFrame(0), + : startFrame(0), + sampleRate(0), size(0) { buffer[0] = buffer[1] = nullptr; @@ -103,28 +103,33 @@ struct AudioFilePool { carla_zeroFloats(buffer[0], size); carla_zeroFloats(buffer[1], size); } + + CARLA_DECLARE_NON_COPY_STRUCT(AudioFilePool) }; class AbstractAudioPlayer { public: virtual ~AbstractAudioPlayer() {} - virtual uint32_t getLastFrame() const = 0; + virtual uint64_t getLastFrame() const = 0; }; class AudioFileThread : public CarlaThread { public: - AudioFileThread(AbstractAudioPlayer* const player, const double sampleRate) + AudioFileThread(AbstractAudioPlayer* const player, const uint32_t sampleRate) : CarlaThread("AudioFileThread"), kPlayer(player), fLoopingMode(true), fNeedsRead(false), fQuitNow(true), fFilePtr(nullptr), + fFileNfo(), fMaxPlayerFrame(0), fPollTempData(nullptr), - fPollTempSize(0) + fPollTempSize(0), + fPool(), + fMutex() { CARLA_ASSERT(kPlayer != nullptr); @@ -247,7 +252,7 @@ public: return false; } - fMaxPlayerFrame = fFileNfo.frames/fFileNfo.channels; + fMaxPlayerFrame = static_cast(fFileNfo.frames/fFileNfo.channels); fPollTempSize = pollTempSize; readPoll(); @@ -289,16 +294,18 @@ public: return; } - int64_t lastFrame = kPlayer->getLastFrame(); - int64_t readFrame = lastFrame; - int64_t maxFrame = fFileNfo.frames; + const uint64_t lastFrame = kPlayer->getLastFrame(); + int32_t readFrameCheck; - if (lastFrame >= maxFrame) + if (lastFrame >= static_cast(fFileNfo.frames)) { if (fLoopingMode) { + const uint64_t readFrameCheckLoop = lastFrame % fMaxPlayerFrame; + CARLA_SAFE_ASSERT_RETURN(readFrameCheckLoop < INT32_MAX,); + carla_debug("R: transport out of bounds for loop"); - readFrame %= fMaxPlayerFrame; + readFrameCheck = static_cast(readFrameCheckLoop); } else { @@ -307,6 +314,13 @@ public: return; } } + else + { + CARLA_SAFE_ASSERT_RETURN(lastFrame < INT32_MAX,); + readFrameCheck = static_cast(lastFrame); + } + + const int32_t readFrame = readFrameCheck; // temp data buffer carla_zeroFloats(fPollTempData, fPollTempSize); @@ -326,12 +340,14 @@ public: return; } + const size_t urv = static_cast(rv); + // see if we can read more - if (readFrame + rv >= static_cast(fFileNfo.frames) && static_cast(rv) < fPollTempSize) + if (readFrame + rv >= static_cast(fFileNfo.frames) && urv < fPollTempSize) { carla_debug("R: from start"); ad_seek(fFilePtr, 0); - rv += ad_read(fFilePtr, fPollTempData+rv, fPollTempSize-rv); + rv += ad_read(fFilePtr, fPollTempData+urv, fPollTempSize-urv); } // lock, and put data asap @@ -396,8 +412,8 @@ protected: { while (! fQuitNow) { - const uint32_t lastFrame = kPlayer->getLastFrame(); - const uint32_t loopedFrame = fLoopingMode ? lastFrame % fMaxPlayerFrame : lastFrame; + const uint64_t lastFrame = kPlayer->getLastFrame(); + const uint64_t loopedFrame = fLoopingMode ? lastFrame % fMaxPlayerFrame : lastFrame; if (fNeedsRead || lastFrame < fPool.startFrame || (lastFrame - fPool.startFrame >= fPool.size*3/4 && loopedFrame < fMaxPlayerFrame)) readPoll(); @@ -423,6 +439,8 @@ private: AudioFilePool fPool; CarlaMutex fMutex; + + CARLA_DECLARE_NON_COPY_STRUCT(AudioFileThread) }; #endif // AUDIO_BASE_HPP_INCLUDED diff --git a/source/native-plugins/audio-file.cpp b/source/native-plugins/audio-file.cpp index 7aaaf3957..387ccae57 100644 --- a/source/native-plugins/audio-file.cpp +++ b/source/native-plugins/audio-file.cpp @@ -33,9 +33,10 @@ public: fDoProcess(false), fLastFrame(0), fMaxFrame(0), - fThread(this, getSampleRate()) + fPool(), + fThread(this, static_cast(getSampleRate())) { - fPool.create(getSampleRate()); + fPool.create(static_cast(getSampleRate())); } ~AudioFilePlugin() override @@ -44,7 +45,7 @@ public: fThread.stopNow(); } - uint32_t getLastFrame() const override + uint64_t getLastFrame() const override { return fLastFrame; } @@ -166,19 +167,21 @@ protected: return; } - int64_t poolFrame = (int64_t)timePos->frame - fPool.startFrame; - int64_t poolSize = fPool.size; + const uint32_t poolSize = fPool.size; + int64_t poolFrame = static_cast(timePos->frame - fPool.startFrame); + float* const bufferL = fPool.buffer[0]; + float* const bufferR = fPool.buffer[1]; for (uint32_t i=0; i < frames; ++i, ++poolFrame) { if (poolFrame >= 0 && poolFrame < poolSize) { - out1[i] = fPool.buffer[0][poolFrame]; - out2[i] = fPool.buffer[1][poolFrame]; + out1[i] = bufferL[poolFrame]; + out2[i] = bufferR[poolFrame]; // reset - fPool.buffer[0][poolFrame] = 0.0f; - fPool.buffer[1][poolFrame] = 0.0f; + bufferL[poolFrame] = 0.0f; + bufferR[poolFrame] = 0.0f; } else { @@ -208,7 +211,7 @@ private: bool fLoopMode; bool fDoProcess; - uint32_t fLastFrame; + uint64_t fLastFrame; uint32_t fMaxFrame; AudioFilePool fPool; diff --git a/source/native-plugins/midi-base.hpp b/source/native-plugins/midi-base.hpp index 97faa1395..afc95156b 100644 --- a/source/native-plugins/midi-base.hpp +++ b/source/native-plugins/midi-base.hpp @@ -354,10 +354,13 @@ public: CARLA_SAFE_ASSERT_RETURN(tmpSize > 0,); CARLA_SAFE_ASSERT_RETURN(tmpSize < 24,); - std::strncpy(tmpBuf, dataRead, static_cast(tmpSize)); - tmpBuf[tmpSize] = '\0'; - dataRead += tmpSize+1; - dataPos += tmpSize+1; + { + const size_t uSize = static_cast(tmpSize); + std::strncpy(tmpBuf, dataRead, uSize); + tmpBuf[tmpSize] = '\0'; + dataRead += uSize+1U; + dataPos += uSize+1U; + } const long long time = std::atoll(tmpBuf); CARLA_SAFE_ASSERT_RETURN(time >= 0,); @@ -371,27 +374,31 @@ public: tmpSize = needle - dataRead; CARLA_SAFE_ASSERT_RETURN(tmpSize > 0 && tmpSize < 24,); - std::strncpy(tmpBuf, dataRead, static_cast(tmpSize)); - tmpBuf[tmpSize] = '\0'; - dataRead += tmpSize+1; - dataPos += tmpSize+1; + { + const size_t uSize = static_cast(tmpSize); + std::strncpy(tmpBuf, dataRead, uSize); + tmpBuf[tmpSize] = '\0'; + dataRead += uSize+1U; + dataPos += uSize+1U; + } - const int size = std::atoi(tmpBuf); - CARLA_SAFE_ASSERT_RETURN(size > 0 && size <= MAX_EVENT_DATA_SIZE,); + const int midiDataSize = std::atoi(tmpBuf); + CARLA_SAFE_ASSERT_RETURN(midiDataSize > 0 && midiDataSize <= MAX_EVENT_DATA_SIZE,); - midiEvent.size = static_cast(size); + midiEvent.size = static_cast(midiDataSize); // get events - for (int i=0; i= 4,); tmpSize = i==0 ? 4 : 3; - std::strncpy(tmpBuf, dataRead, static_cast(tmpSize)); + const size_t uSize = static_cast(tmpSize); + std::strncpy(tmpBuf, dataRead, uSize); tmpBuf[tmpSize] = '\0'; - dataRead += tmpSize+1; - dataPos += tmpSize+1; + dataRead += uSize+1U; + dataPos += uSize+1U; long mdata; @@ -409,7 +416,7 @@ public: midiEvent.data[i] = static_cast(mdata); } - for (int i=size; i(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT)); // copy rest - carla_copy(mdataTmp+1, midiEvent.data+1, size-1); + carla_copy(mdataTmp+1, midiEvent.data+1, size-1U); // done mdataPtr = mdataTmp; diff --git a/source/utils/CarlaLv2Utils.hpp b/source/utils/CarlaLv2Utils.hpp index 8c98c1068..39e9fdf4f 100644 --- a/source/utils/CarlaLv2Utils.hpp +++ b/source/utils/CarlaLv2Utils.hpp @@ -557,6 +557,7 @@ public: fWorker(nullptr), fTimeInfo(), fLastPositionData(), + fPorts(), fURIs(), fUI() { diff --git a/source/utils/CarlaPluginUI.cpp b/source/utils/CarlaPluginUI.cpp index 36d26fdb0..43bd34420 100644 --- a/source/utils/CarlaPluginUI.cpp +++ b/source/utils/CarlaPluginUI.cpp @@ -155,7 +155,8 @@ public: carla_zeroStruct(hints); if (XGetNormalHints(fDisplay, childWindow, &hints) && hints.width > 0 && hints.height > 0) - setSize(hints.width, hints.height, false); + setSize(static_cast(hints.width), + static_cast(hints.height), false); } const Atom _xevp = XInternAtom(fDisplay, "_XEventProc", False);