Browse Source

Start a big cleanup, WIP

tags/v2.1-alpha1-winvst
falkTX 7 years ago
parent
commit
ee0a4e5fdf
48 changed files with 549 additions and 436 deletions
  1. +3
    -1
      source/backend/CarlaStandalone.cpp
  2. +2
    -2
      source/backend/engine/CarlaEngineBridge.cpp
  3. +6
    -1
      source/backend/engine/CarlaEngineData.cpp
  4. +23
    -24
      source/backend/engine/CarlaEngineGraph.cpp
  5. +1
    -1
      source/backend/engine/CarlaEngineGraph.hpp
  6. +2
    -2
      source/backend/engine/CarlaEngineJack.cpp
  7. +2
    -2
      source/backend/engine/CarlaEngineNative.cpp
  8. +3
    -3
      source/backend/engine/CarlaEngineRtAudio.cpp
  9. +2
    -2
      source/backend/plugin/CarlaPluginLV2.cpp
  10. +1
    -1
      source/backend/plugin/CarlaPluginNative.cpp
  11. +2
    -2
      source/backend/plugin/CarlaPluginSFZero.cpp
  12. +6
    -6
      source/backend/utils/CachedPlugins.cpp
  13. +1
    -1
      source/bridges-plugin/CarlaBridgeSingleLV2.cpp
  14. +2
    -0
      source/includes/CarlaNativePlugin.h
  15. +1
    -1
      source/modules/dgl/Application.hpp
  16. +1
    -1
      source/modules/dgl/src/Application.cpp
  17. +173
    -146
      source/modules/water/buffers/AudioSampleBuffer.h
  18. +7
    -4
      source/modules/water/containers/Array.h
  19. +15
    -14
      source/modules/water/containers/ArrayAllocationBase.h
  20. +2
    -2
      source/modules/water/containers/NamedValueSet.h
  21. +51
    -59
      source/modules/water/containers/OwnedArray.h
  22. +2
    -2
      source/modules/water/containers/ReferenceCountedArray.h
  23. +5
    -0
      source/modules/water/files/File.cpp
  24. +2
    -6
      source/modules/water/files/File.h
  25. +18
    -9
      source/modules/water/maths/MathsFunctions.h
  26. +47
    -10
      source/modules/water/memory/Atomic.h
  27. +2
    -0
      source/modules/water/memory/HeapBlock.h
  28. +3
    -2
      source/modules/water/memory/ReferenceCountedObject.h
  29. +6
    -6
      source/modules/water/midi/MidiFile.cpp
  30. +2
    -2
      source/modules/water/midi/MidiFile.h
  31. +53
    -53
      source/modules/water/midi/MidiMessage.cpp
  32. +3
    -2
      source/modules/water/midi/MidiMessage.h
  33. +7
    -7
      source/modules/water/midi/MidiMessageSequence.cpp
  34. +4
    -4
      source/modules/water/processors/AudioProcessorGraph.cpp
  35. +2
    -2
      source/modules/water/processors/AudioProcessorGraph.h
  36. +3
    -3
      source/modules/water/synthesisers/Synthesiser.cpp
  37. +1
    -1
      source/modules/water/synthesisers/Synthesiser.h
  38. +4
    -4
      source/modules/water/text/CharPointer_UTF8.h
  39. +1
    -1
      source/modules/water/water.h
  40. +1
    -1
      source/native-plugins/Makefile
  41. +1
    -0
      source/native-plugins/_all.c
  42. +35
    -17
      source/native-plugins/audio-base.hpp
  43. +13
    -10
      source/native-plugins/audio-file.cpp
  44. +23
    -16
      source/native-plugins/midi-base.hpp
  45. +1
    -1
      source/native-plugins/midi-file.cpp
  46. +1
    -1
      source/utils/CarlaEngineUtils.hpp
  47. +1
    -0
      source/utils/CarlaLv2Utils.hpp
  48. +2
    -1
      source/utils/CarlaPluginUI.cpp

+ 3
- 1
source/backend/CarlaStandalone.cpp View File

@@ -172,6 +172,8 @@ private:
lib_t libfftw3f; lib_t libfftw3f;
lib_t libfftw3l; lib_t libfftw3l;
lib_t libfftw3q; lib_t libfftw3q;

CARLA_DECLARE_NON_COPY_CLASS(ThreadSafeFFTW)
}; };


static ThreadSafeFFTW sThreadSafeFFTW; static ThreadSafeFFTW sThreadSafeFFTW;
@@ -870,7 +872,7 @@ const CarlaTransportInfo* carla_get_transport_info()
{ {
retTransInfo.bar = timeInfo.bbt.bar; retTransInfo.bar = timeInfo.bbt.bar;
retTransInfo.beat = timeInfo.bbt.beat; retTransInfo.beat = timeInfo.bbt.beat;
retTransInfo.tick = timeInfo.bbt.tick;
retTransInfo.tick = static_cast<int32_t>(timeInfo.bbt.tick + 0.5);
retTransInfo.bpm = timeInfo.bbt.beatsPerMinute; retTransInfo.bpm = timeInfo.bbt.beatsPerMinute;
} }




+ 2
- 2
source/backend/engine/CarlaEngineBridge.cpp View File

@@ -837,8 +837,8 @@ public:
if (index >= 0 && plugin != nullptr && plugin->isEnabled()) if (index >= 0 && plugin != nullptr && plugin->isEnabled())
{ {
char strBuf[STR_MAX]; char strBuf[STR_MAX];
plugin->getParameterText(index, strBuf);
const uint32_t strBufLen(std::strlen(strBuf));
plugin->getParameterText(static_cast<uint32_t>(index), strBuf);
const uint32_t strBufLen = static_cast<uint32_t>(std::strlen(strBuf));


const CarlaMutexLocker _cml(fShmNonRtServerControl.mutex); const CarlaMutexLocker _cml(fShmNonRtServerControl.mutex);




+ 6
- 1
source/backend/engine/CarlaEngineData.cpp View File

@@ -206,7 +206,12 @@ EngineOptions::EngineOptions() noexcept
binaryDir(nullptr), binaryDir(nullptr),
resourceDir(nullptr), resourceDir(nullptr),
preventBadBehaviour(false), preventBadBehaviour(false),
frontendWinId(0) {}
frontendWinId(0)
#ifndef CARLA_OS_WIN
, wine()
#endif
{
}


EngineOptions::~EngineOptions() noexcept EngineOptions::~EngineOptions() noexcept
{ {


+ 23
- 24
source/backend/engine/CarlaEngineGraph.cpp View File

@@ -861,11 +861,11 @@ void RackGraph::process(CarlaEngine::ProtectedData* const data, const float* inB
{ {
carla_zeroFloats(dummyBuf, frames); carla_zeroFloats(dummyBuf, frames);


for (uint32_t i=2; i<numInBufs; ++i)
inBuf[i] = dummyBuf;
for (uint32_t j=2; j<numInBufs; ++j)
inBuf[j] = dummyBuf;


for (uint32_t i=2; i<numOutBufs; ++i)
outBuf[i] = dummyBuf;
for (uint32_t j=2; j<numOutBufs; ++j)
outBuf[j] = dummyBuf;
} }


// process // process
@@ -1206,16 +1206,16 @@ public:


const uint32_t numSamples(static_cast<uint32_t>(audio.getNumSamples())); const uint32_t numSamples(static_cast<uint32_t>(audio.getNumSamples()));


if (const int numChan = audio.getNumChannels())
if (const uint32_t numChan = audio.getNumChannels())
{ {
const uint numChanu = static_cast<uint>(jmin(numChan, 2));
const uint32_t numChanu = jmin(numChan, 2U);


if (fPlugin->getAudioInCount() == 0) if (fPlugin->getAudioInCount() == 0)
audio.clear(); audio.clear();


float* audioBuffers[numChan]; float* audioBuffers[numChan];


for (int i=0; i<numChan; ++i)
for (uint32_t i=0; i<numChan; ++i)
audioBuffers[i] = audio.getWritePointer(i); audioBuffers[i] = audio.getWritePointer(i);


float inPeaks[2] = { 0.0f }; float inPeaks[2] = { 0.0f };
@@ -1328,13 +1328,13 @@ PatchbayGraph::PatchbayGraph(CarlaEngine* const engine, const uint32_t ins, cons
extGraph(engine), extGraph(engine),
kEngine(engine) kEngine(engine)
{ {
const int bufferSize(static_cast<int>(engine->getBufferSize()));
const double sampleRate(engine->getSampleRate());
const uint32_t bufferSize(engine->getBufferSize());
const double sampleRate(engine->getSampleRate());


graph.setPlayConfigDetails(static_cast<int>(inputs), static_cast<int>(outputs), sampleRate, bufferSize);
graph.prepareToPlay(sampleRate, bufferSize);
graph.setPlayConfigDetails(static_cast<int>(inputs), static_cast<int>(outputs), sampleRate, static_cast<int>(bufferSize));
graph.prepareToPlay(sampleRate, static_cast<int>(bufferSize));


audioBuffer.setSize(static_cast<int>(jmax(inputs, outputs)), bufferSize);
audioBuffer.setSize(jmax(inputs, outputs), bufferSize);


midiBuffer.ensureSize(kMaxEngineEventInternalCount*2); midiBuffer.ensureSize(kMaxEngineEventInternalCount*2);
midiBuffer.clear(); midiBuffer.clear();
@@ -1423,13 +1423,11 @@ PatchbayGraph::~PatchbayGraph()


void PatchbayGraph::setBufferSize(const uint32_t bufferSize) void PatchbayGraph::setBufferSize(const uint32_t bufferSize)
{ {
const int bufferSizei(static_cast<int>(bufferSize));

const CarlaRecursiveMutexLocker cml1(graph.getReorderMutex()); const CarlaRecursiveMutexLocker cml1(graph.getReorderMutex());


graph.releaseResources(); graph.releaseResources();
graph.prepareToPlay(kEngine->getSampleRate(), bufferSizei);
audioBuffer.setSize(audioBuffer.getNumChannels(), bufferSizei);
graph.prepareToPlay(kEngine->getSampleRate(), static_cast<int>(bufferSize));
audioBuffer.setSize(audioBuffer.getNumChannels(), bufferSize);
} }


void PatchbayGraph::setSampleRate(const double sampleRate) void PatchbayGraph::setSampleRate(const double sampleRate)
@@ -1698,7 +1696,7 @@ void PatchbayGraph::refresh(const char* const deviceName)
char strBuf[STR_MAX+1]; char strBuf[STR_MAX+1];
strBuf[STR_MAX] = '\0'; strBuf[STR_MAX] = '\0';


for (int i=0, count=graph.getNumConnections(); i<count; ++i)
for (size_t i=0, count=graph.getNumConnections(); i<count; ++i)
{ {
const AudioProcessorGraph::Connection* const conn(graph.getConnection(i)); const AudioProcessorGraph::Connection* const conn(graph.getConnection(i));
CARLA_SAFE_ASSERT_CONTINUE(conn != nullptr); CARLA_SAFE_ASSERT_CONTINUE(conn != nullptr);
@@ -1834,7 +1832,7 @@ bool PatchbayGraph::getGroupAndPortIdFromFullName(const bool external, const cha
return false; return false;
} }


void PatchbayGraph::process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames)
void PatchbayGraph::process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames)
{ {
CARLA_SAFE_ASSERT_RETURN(data != nullptr,); CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
CARLA_SAFE_ASSERT_RETURN(data->events.in != nullptr,); CARLA_SAFE_ASSERT_RETURN(data->events.in != nullptr,);
@@ -1853,13 +1851,13 @@ void PatchbayGraph::process(CarlaEngine::ProtectedData* const data, const float*


// put carla audio in water buffer // put carla audio in water buffer
{ {
int i=0;
uint32_t i=0;


for (; i < static_cast<int>(inputs); ++i)
for (; i < inputs; ++i)
audioBuffer.copyFrom(i, 0, inBuf[i], frames); audioBuffer.copyFrom(i, 0, inBuf[i], frames);


// clear remaining channels // clear remaining channels
for (const int count=audioBuffer.getNumChannels(); i<count; ++i)
for (const uint32_t count=audioBuffer.getNumChannels(); i<count; ++i)
audioBuffer.clear(i, 0, frames); audioBuffer.clear(i, 0, frames);
} }


@@ -1868,7 +1866,7 @@ void PatchbayGraph::process(CarlaEngine::ProtectedData* const data, const float*


// put water audio in carla buffer // put water audio in carla buffer
{ {
for (int i=0; i < static_cast<int>(outputs); ++i)
for (uint32_t i=0; i < outputs; ++i)
carla_copyFloats(outBuf[i], audioBuffer.getReadPointer(i), frames); carla_copyFloats(outBuf[i], audioBuffer.getReadPointer(i), frames);
} }


@@ -1893,7 +1891,8 @@ void PatchbayGraph::run()
// InternalGraph // InternalGraph


EngineInternalGraph::EngineInternalGraph(CarlaEngine* const engine) noexcept EngineInternalGraph::EngineInternalGraph(CarlaEngine* const engine) noexcept
: fIsReady(false),
: fIsRack(false),
fIsReady(false),
fRack(nullptr), fRack(nullptr),
kEngine(engine) {} kEngine(engine) {}


@@ -2019,7 +2018,7 @@ void EngineInternalGraph::process(CarlaEngine::ProtectedData* const data, const
else else
{ {
CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,); CARLA_SAFE_ASSERT_RETURN(fPatchbay != nullptr,);
fPatchbay->process(data, inBuf, outBuf, static_cast<int>(frames));
fPatchbay->process(data, inBuf, outBuf, frames);
} }
} }




+ 1
- 1
source/backend/engine/CarlaEngineGraph.hpp View File

@@ -182,7 +182,7 @@ public:
const char* const* getConnections(const bool external) const; const char* const* getConnections(const bool external) const;
bool getGroupAndPortIdFromFullName(const bool external, const char* const fullPortName, uint& groupId, uint& portId) 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: private:
void run() override; void run() override;


+ 2
- 2
source/backend/engine/CarlaEngineJack.cpp View File

@@ -1031,7 +1031,7 @@ public:
startThread(); startThread();
callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, callback(ENGINE_CALLBACK_ENGINE_STARTED, 0,
opts.processMode, opts.transportMode, opts.processMode, opts.transportMode,
pData->sampleRate,
static_cast<float>(pData->sampleRate),
getCurrentDriverName()); getCurrentDriverName());
return true; return true;
} }
@@ -1825,7 +1825,7 @@ protected:
mdataTmp[0] = static_cast<uint8_t>(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT)); mdataTmp[0] = static_cast<uint8_t>(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT));


// copy rest // copy rest
carla_copy<uint8_t>(mdataTmp+1, midiEvent.data+1, size-1);
carla_copy<uint8_t>(mdataTmp+1, midiEvent.data+1, size-1U);


// done // done
mdataPtr = mdataTmp; mdataPtr = mdataTmp;


+ 2
- 2
source/backend/engine/CarlaEngineNative.cpp View File

@@ -1637,7 +1637,7 @@ protected:
uiServerOptions(); uiServerOptions();
uiServerCallback(ENGINE_CALLBACK_ENGINE_STARTED, 0, uiServerCallback(ENGINE_CALLBACK_ENGINE_STARTED, 0,
pData->options.processMode, pData->options.transportMode, pData->options.processMode, pData->options.transportMode,
pData->sampleRate, "Plugin");
static_cast<float>(pData->sampleRate), "Plugin");


fUiServer.writeShowMessage(); fUiServer.writeShowMessage();


@@ -1953,7 +1953,7 @@ public:
return 0; return 0;
case NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE: { case NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE: {
CarlaEngineNative* const engine = handlePtr; CarlaEngineNative* const engine = handlePtr;
return (uintptr_t)(CarlaEngine*)engine;
return (intptr_t)(CarlaEngine*)engine;
} }
} }




+ 3
- 3
source/backend/engine/CarlaEngineRtAudio.cpp View File

@@ -334,7 +334,7 @@ public:


callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, callback(ENGINE_CALLBACK_ENGINE_STARTED, 0,
pData->options.processMode, pData->options.transportMode, pData->options.processMode, pData->options.transportMode,
pData->sampleRate, getCurrentDriverName());
static_cast<float>(pData->sampleRate), getCurrentDriverName());
return true; return true;
} }


@@ -445,7 +445,7 @@ public:
{ {
CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false); CARLA_SAFE_ASSERT_RETURN(graph != nullptr, false);


char strBuf[STR_MAX+1];
char strBuf[STR_MAX+1U];
strBuf[STR_MAX] = '\0'; strBuf[STR_MAX] = '\0';


ExternalGraph& extGraph(graph->extGraph); ExternalGraph& extGraph(graph->extGraph);
@@ -715,7 +715,7 @@ protected:
mdataTmp[0] = static_cast<uint8_t>(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT)); mdataTmp[0] = static_cast<uint8_t>(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT));


// copy rest // copy rest
carla_copy<uint8_t>(mdataTmp+1, midiEvent.data+1, size-1);
carla_copy<uint8_t>(mdataTmp+1, midiEvent.data+1, size-1U);


// done // done
mdataPtr = mdataTmp; mdataPtr = mdataTmp;


+ 2
- 2
source/backend/plugin/CarlaPluginLV2.cpp View File

@@ -2834,7 +2834,7 @@ public:
break; break;


case LV2_PORT_DESIGNATION_TIME_BAR_BEAT: 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)) fLastTimeInfo.bbt.beat != timeInfo.bbt.beat))
{ {
fParamBuffers[k] = static_cast<float>(barBeat); fParamBuffers[k] = static_cast<float>(barBeat);
@@ -5082,7 +5082,7 @@ public:
fLv2Options.minBufferSize = fNeedsFixedBuffers ? bufferSize : 1; fLv2Options.minBufferSize = fNeedsFixedBuffers ? bufferSize : 1;
fLv2Options.maxBufferSize = bufferSize; fLv2Options.maxBufferSize = bufferSize;
fLv2Options.nominalBufferSize = bufferSize; fLv2Options.nominalBufferSize = bufferSize;
fLv2Options.sampleRate = pData->engine->getSampleRate();
fLv2Options.sampleRate = static_cast<float>(pData->engine->getSampleRate());
fLv2Options.transientWinId = static_cast<int64_t>(pData->engine->getOptions().frontendWinId); fLv2Options.transientWinId = static_cast<int64_t>(pData->engine->getOptions().frontendWinId);


uint32_t eventBufferSize = MAX_DEFAULT_BUFFER_SIZE; uint32_t eventBufferSize = MAX_DEFAULT_BUFFER_SIZE;


+ 1
- 1
source/backend/plugin/CarlaPluginNative.cpp View File

@@ -841,7 +841,7 @@ public:
} catch(...) {} } catch(...) {}
} }


fCurMidiProgs[channel] = index;
fCurMidiProgs[channel] = static_cast<int32_t>(index);


CarlaPlugin::setMidiProgramRT(index); CarlaPlugin::setMidiProgramRT(index);
} }


+ 2
- 2
source/backend/plugin/CarlaPluginSFZero.cpp View File

@@ -555,7 +555,7 @@ public:
// -------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------
// Parameter outputs // Parameter outputs


fNumVoices = fSynth.numVoicesUsed();
fNumVoices = static_cast<float>(fSynth.numVoicesUsed());
} }


bool processSingle(AudioSampleBuffer& audioOutBuffer, const uint32_t frames, const uint32_t timeOffset) bool processSingle(AudioSampleBuffer& audioOutBuffer, const uint32_t frames, const uint32_t timeOffset)
@@ -581,7 +581,7 @@ public:
// -------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------
// Run plugin // Run plugin


fSynth.renderVoices(audioOutBuffer, timeOffset, frames);
fSynth.renderVoices(audioOutBuffer, static_cast<int>(timeOffset), static_cast<int>(frames));


#ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
// -------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------


+ 6
- 6
source/backend/utils/CachedPlugins.cpp View File

@@ -71,7 +71,7 @@ _CarlaCachedPluginInfo::_CarlaCachedPluginInfo() noexcept


static Array<File> gSFZs; static Array<File> gSFZs;


void findSFZs(const char* const sfzPaths)
static void findSFZs(const char* const sfzPaths)
{ {
CARLA_SAFE_ASSERT_RETURN(sfzPaths != nullptr,); 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; static CarlaCachedPluginInfo info;


@@ -125,7 +125,7 @@ const CarlaCachedPluginInfo* get_cached_plugin_internal(const NativePluginDescri
return &info; 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; static CarlaCachedPluginInfo info;


@@ -471,7 +471,7 @@ const CarlaCachedPluginInfo* get_cached_plugin_lv2(Lv2WorldClass& lv2World, Lilv
return &info; return &info;
} }


const CarlaCachedPluginInfo* get_cached_plugin_sfz(const File file)
static const CarlaCachedPluginInfo* get_cached_plugin_sfz(const File file)
{ {
static CarlaCachedPluginInfo info; static CarlaCachedPluginInfo info;


@@ -524,7 +524,7 @@ uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath)


case CB::PLUGIN_SFZ: { case CB::PLUGIN_SFZ: {
findSFZs(pluginPath); findSFZs(pluginPath);
return gSFZs.size();
return static_cast<uint>(gSFZs.size());
} }


default: default:
@@ -562,7 +562,7 @@ const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype,


case CB::PLUGIN_SFZ: { case CB::PLUGIN_SFZ: {
CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gSFZs.size())); CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gSFZs.size()));
return get_cached_plugin_sfz(gSFZs.getUnchecked(index));
return get_cached_plugin_sfz(gSFZs.getUnchecked(static_cast<int>(index)));
} }


default: default:


+ 1
- 1
source/bridges-plugin/CarlaBridgeSingleLV2.cpp View File

@@ -245,7 +245,7 @@ public:
mdataTmp[0] = static_cast<uint8_t>(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT)); mdataTmp[0] = static_cast<uint8_t>(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT));


// copy rest // copy rest
carla_copy<uint8_t>(mdataTmp+1, midiEvent.data+1, size-1);
carla_copy<uint8_t>(mdataTmp+1, midiEvent.data+1, size-1U);


// done // done
mdataPtr = mdataTmp; mdataPtr = mdataTmp;


+ 2
- 0
source/includes/CarlaNativePlugin.h View File

@@ -21,6 +21,7 @@
#include "CarlaBackend.h" #include "CarlaBackend.h"
#include "CarlaNative.h" #include "CarlaNative.h"


#ifndef CARLA_HOST_H_INCLUDED
/*! /*!
* Get the absolute filename of this carla library. * 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. * Get the folder where this carla library resides.
*/ */
CARLA_EXPORT const char* carla_get_library_folder(); CARLA_EXPORT const char* carla_get_library_folder();
#endif


/*! /*!
* Get the native plugin descriptor for the carla-rack plugin. * Get the native plugin descriptor for the carla-rack plugin.


+ 1
- 1
source/modules/dgl/Application.hpp View File

@@ -62,7 +62,7 @@ public:
idle() is called at regular intervals. idle() is called at regular intervals.
@note This function is meant for standalones only, *never* call this from plugins. @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. Quit the application.


+ 1
- 1
source/modules/dgl/src/Application.cpp View File

@@ -44,7 +44,7 @@ void Application::idle()
} }
} }


void Application::exec(int idleTime)
void Application::exec(unsigned int idleTime)
{ {
for (; pData->doLoop;) for (; pData->doLoop;)
{ {


+ 173
- 146
source/modules/water/buffers/AudioSampleBuffer.h View File

@@ -44,9 +44,12 @@ public:
//============================================================================== //==============================================================================
/** Creates an empty buffer with 0 channels and 0 length. */ /** Creates an empty buffer with 0 channels and 0 length. */
AudioSampleBuffer() noexcept AudioSampleBuffer() noexcept
: numChannels (0), size (0), allocatedBytes (0),
channels (static_cast<float**> (preallocatedChannelSpace)),
isClear (false)
: numChannels(0),
size(0),
allocatedBytes(0),
channels(static_cast<float**> (preallocatedChannelSpace)),
allocatedData(),
isClear(false)
{ {
} }
@@ -60,17 +63,16 @@ public:
when the buffer is deleted. If the memory can't be allocated, this will when the buffer is deleted. If the memory can't be allocated, this will
throw a std::bad_alloc exception. 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); allocateData (clearData);
} }
@@ -90,15 +92,16 @@ public:
size of the arrays passed in size of the arrays passed in
*/ */
AudioSampleBuffer (float* const* dataToReferTo, 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 (dataToReferTo != nullptr,);
CARLA_SAFE_ASSERT_RETURN (numChannelsToUse >= 0 && numSamples >= 0,);
allocateChannels (dataToReferTo, 0); allocateChannels (dataToReferTo, 0);
} }
@@ -120,16 +123,17 @@ public:
size of the arrays passed in size of the arrays passed in
*/ */
AudioSampleBuffer (float* const* dataToReferTo, 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 (dataToReferTo != nullptr,);
CARLA_SAFE_ASSERT_RETURN (numChannelsToUse >= 0 && startSample >= 0 && numSamples >= 0,);
allocateChannels (dataToReferTo, startSample); allocateChannels (dataToReferTo, startSample);
} }
@@ -141,9 +145,12 @@ public:
shared block of data. shared block of data.
*/ */
AudioSampleBuffer (const AudioSampleBuffer& other) noexcept 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) if (allocatedBytes == 0)
{ {
@@ -159,12 +166,40 @@ public:
} }
else else
{ {
for (int i = 0; i < numChannels; ++i)
for (uint32_t i = 0; i < numChannels; ++i)
carla_copyFloats (channels[i], other.channels[i], size); 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. /** Destructor.
This will free any memory allocated by the buffer. This will free any memory allocated by the buffer.
*/ */
@@ -180,7 +215,7 @@ public:
allocatedData (static_cast<HeapBlock<char>&&> (other.allocatedData)), allocatedData (static_cast<HeapBlock<char>&&> (other.allocatedData)),
isClear (other.isClear) isClear (other.isClear)
{ {
memcpy (preallocatedChannelSpace, other.preallocatedChannelSpace, sizeof (preallocatedChannelSpace));
std::memcpy (preallocatedChannelSpace, other.preallocatedChannelSpace, sizeof (preallocatedChannelSpace));
other.numChannels = 0; other.numChannels = 0;
other.size = 0; other.size = 0;
other.allocatedBytes = 0; other.allocatedBytes = 0;
@@ -207,12 +242,12 @@ public:
/** Returns the number of channels of audio data that this buffer contains. /** Returns the number of channels of audio data that this buffer contains.
@see getSampleData @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. /** Returns the number of samples allocated in each of the buffer's channels.
@see getSampleData @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. /** 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, 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 result! Instead, you must call getWritePointer so that the buffer knows you're
planning on modifying the data. 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]; return channels [channelNumber];
} }
@@ -234,10 +270,11 @@ public:
result! Instead, you must call getWritePointer so that the buffer knows you're result! Instead, you must call getWritePointer so that the buffer knows you're
planning on modifying the data. 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; return channels [channelNumber] + sampleIndex;
} }
@@ -247,9 +284,10 @@ public:
Note that if you're not planning on writing to the data, you should always Note that if you're not planning on writing to the data, you should always
use getReadPointer instead. 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; isClear = false;
return channels [channelNumber]; return channels [channelNumber];
} }
@@ -260,10 +298,11 @@ public:
Note that if you're not planning on writing to the data, you should Note that if you're not planning on writing to the data, you should
use getReadPointer instead. 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; isClear = false;
return channels [channelNumber] + sampleIndex; return channels [channelNumber] + sampleIndex;
} }
@@ -287,17 +326,13 @@ public:
This can expand the buffer's length, and add or remove channels. 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) 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) if (allocatedBytes >= newTotalBytes)
{ {
@@ -312,13 +347,13 @@ public:
} }
float* chan = reinterpret_cast<float*> (allocatedData + channelListSize); float* chan = reinterpret_cast<float*> (allocatedData + channelListSize);
for (int i = 0; i < newNumChannels; ++i)
for (uint32_t i = 0; i < newNumChannels; ++i)
{ {
channels[i] = chan; channels[i] = chan;
chan += allocatedSamplesPerChannel; chan += allocatedSamplesPerChannel;
} }
channels [newNumChannels] = 0;
channels [newNumChannels] = nullptr;
size = newNumSamples; size = newNumSamples;
numChannels = newNumChannels; numChannels = newNumChannels;
} }
@@ -331,22 +366,18 @@ public:
Returns true if the required memory is available. 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) 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); CARLA_SAFE_ASSERT_RETURN(allocatedBytes >= newTotalBytes, false);
float* chan = reinterpret_cast<float*> (allocatedData + channelListSize); float* chan = reinterpret_cast<float*> (allocatedData + channelListSize);
for (int i = 0; i < numChannels; ++i)
for (uint32_t i = 0; i < numChannels; ++i)
{ {
channels[i] = chan; channels[i] = chan;
chan += allocatedSamplesPerChannel; chan += allocatedSamplesPerChannel;
@@ -377,11 +408,10 @@ public:
size of the arrays passed in size of the arrays passed in
*/ */
bool setDataToReferTo (float** dataToReferTo, 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_RETURN(dataToReferTo != nullptr, false);
CARLA_SAFE_ASSERT_INT2_RETURN(newNumChannels >= 0 && newNumSamples >= 0, newNumChannels, newNumSamples, false);
if (allocatedBytes != 0) if (allocatedBytes != 0)
{ {
@@ -401,7 +431,7 @@ public:
{ {
if (! isClear) if (! isClear)
{ {
for (int i = 0; i < numChannels; ++i)
for (uint32_t i = 0; i < numChannels; ++i)
carla_zeroFloats (channels[i], size); carla_zeroFloats (channels[i], size);
isClear = true; isClear = true;
@@ -413,17 +443,17 @@ public:
For speed, this doesn't check whether the channel and sample number For speed, this doesn't check whether the channel and sample number
are in-range, so be careful! 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 (! isClear)
{ {
if (startSample == 0 && numSamples == size) if (startSample == 0 && numSamples == size)
isClear = true; isClear = true;
for (int i = 0; i < numChannels; ++i)
for (uint32_t i = 0; i < numChannels; ++i)
carla_zeroFloats (channels[i] + startSample, numSamples); carla_zeroFloats (channels[i] + startSample, numSamples);
} }
} }
@@ -433,12 +463,12 @@ public:
For speed, this doesn't check whether the channel and sample number For speed, this doesn't check whether the channel and sample number
are in-range, so be careful! 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) if (! isClear)
carla_zeroFloats (channels [channel] + startSample, numSamples); carla_zeroFloats (channels [channel] + startSample, numSamples);
@@ -466,21 +496,21 @@ public:
@see copyFrom @see copyFrom
*/ */
void addFrom (int destChannel,
int destStartSample,
void addFrom (const uint32_t destChannel,
const uint32_t destStartSample,
const AudioSampleBuffer& source, 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; float* const d = channels [destChannel] + destStartSample;
const float* const s = source.channels [sourceChannel] + sourceStartSample; const float* const s = source.channels [sourceChannel] + sourceStartSample;
@@ -489,14 +519,14 @@ public:
{ {
isClear = false; isClear = false;
if (gainToApplyToSource != 1.0f)
if (carla_isNotZero(gainToApplyToSource - 1.0f))
carla_copyWithMultiply (d, s, gainToApplyToSource, numSamples); carla_copyWithMultiply (d, s, gainToApplyToSource, numSamples);
else else
carla_copyFloats (d, s, numSamples); carla_copyFloats (d, s, numSamples);
} }
else else
{ {
if (gainToApplyToSource != 1.0f)
if (carla_isNotZero(gainToApplyToSource - 1.0f))
carla_addWithMultiply (d, s, gainToApplyToSource, numSamples); carla_addWithMultiply (d, s, gainToApplyToSource, numSamples);
else else
carla_add (d, s, numSamples); carla_add (d, s, numSamples);
@@ -516,17 +546,17 @@ public:
@see copyFrom @see copyFrom
*/ */
void addFrom (int destChannel,
int destStartSample,
void addFrom (const uint32_t destChannel,
const uint32_t destStartSample,
const float* source, 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,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,);
if (gainToApplyToSource != 0.0f && numSamples > 0)
if (carla_isNotZero(gainToApplyToSource) && numSamples != 0)
{ {
float* const d = channels [destChannel] + destStartSample; float* const d = channels [destChannel] + destStartSample;
@@ -534,14 +564,14 @@ public:
{ {
isClear = false; isClear = false;
if (gainToApplyToSource != 1.0f)
if (carla_isNotZero(gainToApplyToSource - 1.0f))
carla_copyWithMultiply (d, source, gainToApplyToSource, numSamples); carla_copyWithMultiply (d, source, gainToApplyToSource, numSamples);
else else
carla_copyFloats (d, source, numSamples); carla_copyFloats (d, source, numSamples);
} }
else else
{ {
if (gainToApplyToSource != 1.0f)
if (carla_isNotZero(gainToApplyToSource - 1.0f))
carla_addWithMultiply (d, source, gainToApplyToSource, numSamples); carla_addWithMultiply (d, source, gainToApplyToSource, numSamples);
else else
carla_add (d, source, numSamples); carla_add (d, source, numSamples);
@@ -560,18 +590,18 @@ public:
@see addFrom @see addFrom
*/ */
void copyFrom (int destChannel,
int destStartSample,
void copyFrom (const uint32_t destChannel,
const uint32_t destStartSample,
const AudioSampleBuffer& source, 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) if (numSamples > 0)
{ {
@@ -599,13 +629,13 @@ public:
@see addFrom @see addFrom
*/ */
void copyFrom (int destChannel,
int destStartSample,
void copyFrom (const uint32_t destChannel,
const uint32_t destStartSample,
const float* source, 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,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,);
if (numSamples > 0) if (numSamples > 0)
@@ -625,38 +655,35 @@ public:
@see addFrom @see addFrom
*/ */
void copyFrom (int destChannel,
int destStartSample,
void copyFrom (const uint32_t destChannel,
const uint32_t destStartSample,
const float* source, const float* source,
int numSamples,
const uint32_t numSamples,
float gain) noexcept 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,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,);
if (numSamples > 0) if (numSamples > 0)
{ {
float* const d = channels [destChannel] + destStartSample; 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; isClear = false;
carla_copyFloats (d, source, numSamples); carla_copyFloats (d, source, numSamples);
} }
else
{
isClear = false;
carla_copyWithMultiply (d, source, gain, numSamples);
}
} }
} }
@@ -669,28 +696,28 @@ public:
@see addFrom @see addFrom
*/ */
void copyFromInterleavedSource (int destChannel,
void copyFromInterleavedSource (const uint32_t destChannel,
const float* source, const float* source,
int totalNumSamples) noexcept
const uint32_t totalNumSamples) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(isPositiveAndBelow(destChannel, numChannels),); CARLA_SAFE_ASSERT_RETURN(isPositiveAndBelow(destChannel, numChannels),);
CARLA_SAFE_ASSERT_RETURN(source != nullptr,); 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,); CARLA_SAFE_ASSERT_RETURN(numSamples <= size,);
isClear = false; isClear = false;
float* d = channels [destChannel]; float* d = channels [destChannel];
for (int i=numSamples; --i >= 0;)
for (uint32_t i=0; i < numSamples; ++i)
d[i] = source[i * numChannels + destChannel]; d[i] = source[i * numChannels + destChannel];
} }
} }
private: private:
//============================================================================== //==============================================================================
int numChannels, size;
uint32_t numChannels, size;
size_t allocatedBytes; size_t allocatedBytes;
float** channels; float** channels;
HeapBlock<char> allocatedData; HeapBlock<char> allocatedData;
@@ -699,15 +726,15 @@ private:
bool allocateData (bool clearData = false) 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); CARLA_SAFE_ASSERT_RETURN (allocatedData.allocate (nextAllocatedBytes, clearData), false);
allocatedBytes = nextAllocatedBytes; allocatedBytes = nextAllocatedBytes;
channels = reinterpret_cast<float**> (allocatedData.getData()); channels = reinterpret_cast<float**> (allocatedData.getData());
float* chan = (float*) (allocatedData + channelListSize); float* chan = (float*) (allocatedData + channelListSize);
for (int i = 0; i < numChannels; ++i)
for (uint32_t i = 0; i < numChannels; ++i)
{ {
channels[i] = chan; channels[i] = chan;
chan += size; chan += size;
@@ -718,22 +745,20 @@ private:
return true; 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) // (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<float**> (preallocatedChannelSpace); channels = static_cast<float**> (preallocatedChannelSpace);
} }
else 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<float**> (allocatedData.getData()); channels = reinterpret_cast<float**> (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 // you have to pass in the same number of valid pointers as numChannels
CARLA_SAFE_ASSERT_CONTINUE (dataToReferTo[i] != nullptr); CARLA_SAFE_ASSERT_CONTINUE (dataToReferTo[i] != nullptr);
@@ -745,6 +770,8 @@ private:
isClear = false; isClear = false;
return true; return true;
} }
// CARLA_DECLARE_NON_COPY_CLASS(AudioSampleBuffer)
}; };
} }


+ 7
- 4
source/modules/water/containers/Array.h View File

@@ -61,7 +61,9 @@ private:
public: public:
//============================================================================== //==============================================================================
/** Creates an empty array. */ /** Creates an empty array. */
Array() noexcept : numUsed (0)
Array() noexcept
: data(),
numUsed(0)
{ {
} }
@@ -69,7 +71,8 @@ public:
@param other the array to copy @param other the array to copy
*/ */
Array (const Array<ElementType>& other) noexcept Array (const Array<ElementType>& other) noexcept
: numUsed (0)
: data(),
numUsed(0)
{ {
CARLA_SAFE_ASSERT_RETURN(data.setAllocatedSize (other.numUsed),); CARLA_SAFE_ASSERT_RETURN(data.setAllocatedSize (other.numUsed),);
numUsed = other.numUsed; numUsed = other.numUsed;
@@ -385,7 +388,7 @@ public:
*/ */
bool add (ElementType&& newElement) noexcept bool add (ElementType&& newElement) noexcept
{ {
if (! data.ensureAllocatedSize (numUsed + 1))
if (! data.ensureAllocatedSize (static_cast<size_t>(numUsed + 1)))
return false; return false;
new (data.elements + numUsed++) ElementType (static_cast<ElementType&&> (newElement)); new (data.elements + numUsed++) ElementType (static_cast<ElementType&&> (newElement));
@@ -1099,7 +1102,7 @@ private:
void minimiseStorageAfterRemoval() void minimiseStorageAfterRemoval()
{ {
if (data.numAllocated > jmax (minimumAllocatedSize, numUsed * 2))
if (data.numAllocated > static_cast<size_t>(jmax (minimumAllocatedSize, numUsed * 2)))
data.shrinkToNoMoreThan (jmax (numUsed, jmax (minimumAllocatedSize, 64 / (int) sizeof (ElementType)))); data.shrinkToNoMoreThan (jmax (numUsed, jmax (minimumAllocatedSize, 64 / (int) sizeof (ElementType))));
} }
}; };


+ 15
- 14
source/modules/water/containers/ArrayAllocationBase.h View File

@@ -71,7 +71,8 @@ public:
//============================================================================== //==============================================================================
/** Creates an empty array. */ /** Creates an empty array. */
ArrayAllocationBase() noexcept ArrayAllocationBase() noexcept
: numAllocated (0)
: elements(),
numAllocated(0)
{ {
} }
@@ -106,7 +107,7 @@ public:
#else #else
bool bool
#endif #endif
setAllocatedSize (const int numNewElements) noexcept
setAllocatedSize (const size_t numNewElements) noexcept
{ {
if (numAllocated != numNewElements) if (numAllocated != numNewElements)
{ {
@@ -128,7 +129,7 @@ public:
#if WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS #if WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS
template <typename T = ElementType> template <typename T = ElementType>
NonTriviallyCopyableBool<T> setAllocatedSize (const int numNewElements) noexcept
NonTriviallyCopyableBool<T> setAllocatedSize (const size_t numNewElements) noexcept
{ {
if (numAllocated != numNewElements) if (numAllocated != numNewElements)
{ {
@@ -139,7 +140,7 @@ public:
if (! newElements.malloc (numNewElements)) if (! newElements.malloc (numNewElements))
return false; return false;
for (int i = 0; i < numNewElements; ++i)
for (size_t i = 0; i < numNewElements; ++i)
{ {
if (i < numAllocated) if (i < numAllocated)
{ {
@@ -174,10 +175,10 @@ public:
@param minNumElements the minimum number of elements that are needed @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) if (minNumElements > numAllocated)
return setAllocatedSize ((minNumElements + minNumElements / 2 + 8) & ~7);
return setAllocatedSize ((minNumElements + minNumElements / 2U + 8U) & ~7U);
return true; return true;
} }
@@ -185,7 +186,7 @@ public:
/** Minimises the amount of storage allocated so that it's no more than /** Minimises the amount of storage allocated so that it's no more than
the given number of elements. the given number of elements.
*/ */
bool shrinkToNoMoreThan (const int maxNumElements) noexcept
bool shrinkToNoMoreThan (const size_t maxNumElements) noexcept
{ {
if (maxNumElements < numAllocated) if (maxNumElements < numAllocated)
return setAllocatedSize (maxNumElements); return setAllocatedSize (maxNumElements);
@@ -205,28 +206,28 @@ public:
#else #else
void void
#endif #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(target != nullptr,);
CARLA_SAFE_ASSERT_RETURN(source != nullptr,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,);
CARLA_SAFE_ASSERT_RETURN(target != source,); 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)); std::memmove (target, source, ((size_t) numElements) * sizeof (ElementType));
} }
#if WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS #if WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS
template <typename T = ElementType> template <typename T = ElementType>
NonTriviallyCopyableVoid<T> moveMemory (ElementType* target, const ElementType* source, const int numElements) noexcept
NonTriviallyCopyableVoid<T> moveMemory (ElementType* target, const ElementType* source, const size_t numElements) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(target != nullptr,); CARLA_SAFE_ASSERT_RETURN(target != nullptr,);
CARLA_SAFE_ASSERT_RETURN(source != nullptr,); CARLA_SAFE_ASSERT_RETURN(source != nullptr,);
CARLA_SAFE_ASSERT_RETURN(target != source,); CARLA_SAFE_ASSERT_RETURN(target != source,);
CARLA_SAFE_ASSERT_RETURN(numElements > 0,);
CARLA_SAFE_ASSERT_RETURN(numElements != 0,);
if (target > source) if (target > source)
{ {
for (int i = numElements; --i >= 0;)
for (size_t i = 0; i < numElements; ++i)
{ {
moveElement (target, std::move (*source)); moveElement (target, std::move (*source));
++target; ++target;
@@ -235,7 +236,7 @@ public:
} }
else else
{ {
for (int i = numElements; --i >= 0;)
for (size_t i = 0; i < numElements; ++i)
{ {
moveElement (target, std::move (*source)); moveElement (target, std::move (*source));
--target; --target;
@@ -253,7 +254,7 @@ public:
//============================================================================== //==============================================================================
HeapBlock<ElementType> elements; HeapBlock<ElementType> elements;
int numAllocated;
size_t numAllocated;
private: private:
CARLA_DECLARE_NON_COPY_CLASS (ArrayAllocationBase) CARLA_DECLARE_NON_COPY_CLASS (ArrayAllocationBase)


+ 2
- 2
source/modules/water/containers/NamedValueSet.h View File

@@ -64,8 +64,8 @@ public:
//============================================================================== //==============================================================================
struct NamedValue 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) {} NamedValue (const NamedValue& other) : name (other.name), value (other.value) {}
#if WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS #if WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS


+ 51
- 59
source/modules/water/containers/OwnedArray.h View File

@@ -117,7 +117,7 @@ public:
/** Returns the number of items currently in the array. /** Returns the number of items currently in the array.
@see operator[] @see operator[]
*/ */
inline int size() const noexcept
inline size_t size() const noexcept
{ {
return numUsed; return numUsed;
} }
@@ -136,11 +136,11 @@ public:
@see getUnchecked @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]; return data.elements [index];
} }
@@ -154,7 +154,6 @@ public:
*/ */
inline ObjectClass* getUnchecked (const int index) const noexcept inline ObjectClass* getUnchecked (const int index) const noexcept
{ {
jassert (isPositiveAndBelow (index, numUsed) && data.elements != nullptr);
return data.elements [index]; return data.elements [index];
} }
@@ -167,7 +166,7 @@ public:
{ {
if (numUsed > 0) if (numUsed > 0)
{ {
jassert (data.elements != nullptr);
CARLA_SAFE_ASSERT_RETURN(data.elements != nullptr, nullptr);
return data.elements [0]; return data.elements [0];
} }
@@ -183,7 +182,7 @@ public:
{ {
if (numUsed > 0) if (numUsed > 0)
{ {
jassert (data.elements != nullptr);
CARLA_SAFE_ASSERT_RETURN(data.elements != nullptr, nullptr);
return data.elements [numUsed - 1]; return data.elements [numUsed - 1];
} }
@@ -301,14 +300,16 @@ public:
if (indexToInsertAt < 0) if (indexToInsertAt < 0)
return add (newObject); return add (newObject);
if (indexToInsertAt > numUsed)
indexToInsertAt = numUsed;
size_t uindexToInsertAt = indexToInsertAt;
if (uindexToInsertAt > numUsed)
uindexToInsertAt = numUsed;
if (! data.ensureAllocatedSize (numUsed + 1)) if (! data.ensureAllocatedSize (numUsed + 1))
return nullptr; 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) if (numToMove > 0)
std::memmove (e + 1, e, sizeof (ObjectClass*) * (size_t) numToMove); std::memmove (e + 1, e, sizeof (ObjectClass*) * (size_t) numToMove);
@@ -330,20 +331,20 @@ public:
@param numberOfElements how many items are in the array @param numberOfElements how many items are in the array
@see insert, add, addSorted, set @see insert, add, addSorted, set
*/ */
void insertArray (int indexToInsertAt,
void insertArray (const size_t indexToInsertAt,
ObjectClass* const* newObjects, ObjectClass* const* newObjects,
int numberOfElements)
const size_t numberOfElements)
{ {
if (numberOfElements > 0) if (numberOfElements > 0)
{ {
data.ensureAllocatedSize (numUsed + numberOfElements); data.ensureAllocatedSize (numUsed + numberOfElements);
ObjectClass** insertPos = data.elements; ObjectClass** insertPos = data.elements;
if (isPositiveAndBelow (indexToInsertAt, numUsed))
if (indexToInsertAt < numUsed)
{ {
insertPos += indexToInsertAt; 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 else
{ {
@@ -352,7 +353,7 @@ public:
numUsed += numberOfElements; numUsed += numberOfElements;
while (--numberOfElements >= 0)
for (size_t i=0; i < numberOfElements; ++i)
*insertPos++ = *newObjects++; *insertPos++ = *newObjects++;
} }
} }
@@ -470,15 +471,9 @@ public:
*/ */
template <class OtherArrayType> template <class OtherArrayType>
void addCopiesOf (const OtherArrayType& arrayToAddFrom, void addCopiesOf (const OtherArrayType& arrayToAddFrom,
int startIndex = 0,
size_t startIndex = 0,
int numElementsToAdd = -1) int numElementsToAdd = -1)
{ {
if (startIndex < 0)
{
jassertfalse;
startIndex = 0;
}
if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size()) if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size())
numElementsToAdd = arrayToAddFrom.size() - startIndex; numElementsToAdd = arrayToAddFrom.size() - startIndex;
@@ -558,24 +553,22 @@ public:
@param deleteObject whether to delete the object that is removed @param deleteObject whether to delete the object that is removed
@see removeObject, removeRange @see removeObject, removeRange
*/ */
void remove (int indexToRemove, bool deleteObject = true)
void remove (const size_t indexToRemove, bool deleteObject = true)
{ {
ScopedPointer<ObjectClass> toDelete; ScopedPointer<ObjectClass> 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) if ((numUsed << 1) < data.numAllocated)
@@ -591,19 +584,19 @@ public:
@param indexToRemove the index of the element to remove @param indexToRemove the index of the element to remove
@see remove, removeObject, removeRange @see remove, removeObject, removeRange
*/ */
ObjectClass* removeAndReturn (int indexToRemove)
ObjectClass* removeAndReturn (const size_t indexToRemove)
{ {
ObjectClass* removedItem = nullptr; ObjectClass* removedItem = nullptr;
if (isPositiveAndBelow (indexToRemove, numUsed))
if (indexToRemove < numUsed)
{ {
ObjectClass** const e = data.elements + indexToRemove; ObjectClass** const e = data.elements + indexToRemove;
removedItem = *e; removedItem = *e;
--numUsed; --numUsed;
const int numToShift = numUsed - indexToRemove;
const size_t numToShift = numUsed - indexToRemove;
if (numToShift > 0) 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) if ((numUsed << 1) < data.numAllocated)
minimiseStorageOverheads(); minimiseStorageOverheads();
@@ -647,10 +640,10 @@ public:
@param deleteObjects whether to delete the objects that get removed @param deleteObjects whether to delete the objects that get removed
@see remove, removeObject @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) if (endIndex > startIndex)
{ {
@@ -663,12 +656,12 @@ public:
} }
} }
const int rangeSize = endIndex - startIndex;
const size_t rangeSize = endIndex - startIndex;
ObjectClass** e = data.elements + startIndex; ObjectClass** e = data.elements + startIndex;
int numToShift = numUsed - endIndex;
size_t numToShift = numUsed - endIndex;
numUsed -= rangeSize; numUsed -= rangeSize;
while (--numToShift >= 0)
for (size_t i=0; i < numToShift; ++i)
{ {
*e = e [rangeSize]; *e = e [rangeSize];
++e; ++e;
@@ -699,11 +692,10 @@ public:
If either of the indexes passed in is out-of-range, nothing will happen, If either of the indexes passed in is out-of-range, nothing will happen,
otherwise the two objects at these positions will be exchanged. 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], std::swap (data.elements [index1],
data.elements [index2]); data.elements [index2]);
@@ -723,28 +715,28 @@ public:
@param newIndex the index at which you'd like this object to end up. If this @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 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 (currentIndex != newIndex)
{ {
if (isPositiveAndBelow (currentIndex, numUsed))
if (currentIndex < numUsed)
{ {
if (! isPositiveAndBelow (newIndex, numUsed))
if (newIndex >= numUsed)
newIndex = numUsed - 1; newIndex = numUsed - 1;
ObjectClass* const value = data.elements [currentIndex]; ObjectClass* const value = data.elements [currentIndex];
if (newIndex > 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 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; data.elements [newIndex] = value;
@@ -826,7 +818,7 @@ public:
private: private:
//============================================================================== //==============================================================================
ArrayAllocationBase <ObjectClass*> data; ArrayAllocationBase <ObjectClass*> data;
int numUsed;
size_t numUsed;
void deleteAllObjects() void deleteAllObjects()
{ {


+ 2
- 2
source/modules/water/containers/ReferenceCountedArray.h View File

@@ -549,9 +549,9 @@ public:
const int numberToShift = numUsed - indexToRemove; const int numberToShift = numUsed - indexToRemove;
if (numberToShift > 0) 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<int>(data.numAllocated))
minimiseStorageOverheads(); minimiseStorageOverheads();
} }
} }


+ 5
- 0
source/modules/water/files/File.cpp View File

@@ -54,6 +54,11 @@
namespace water { namespace water {
File::File () noexcept
: fullPath ()
{
}
File::File (const String& fullPathName) File::File (const String& fullPathName)
: fullPath (parseAbsolutePath (fullPathName)) : fullPath (parseAbsolutePath (fullPathName))
{ {


+ 2
- 6
source/modules/water/files/File.h View File

@@ -54,7 +54,7 @@ public:
You can use its operator= method to point it at a proper file. You can use its operator= method to point it at a proper file.
*/ */
File() noexcept {}
File() noexcept;
/** Creates a file from an absolute path. /** Creates a file from an absolute path.
@@ -760,11 +760,7 @@ public:
if (foldersFirst && (firstFile.isDirectory() != secondFile.isDirectory())) if (foldersFirst && (firstFile.isDirectory() != secondFile.isDirectory()))
return firstFile.isDirectory() ? -1 : 1; 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; bool foldersFirst;


+ 18
- 9
source/modules/water/maths/MathsFunctions.h View File

@@ -170,7 +170,8 @@ Type jlimit (const Type lowerLimit,
const Type upperLimit, const Type upperLimit,
const Type valueToConstrain) noexcept 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 return (valueToConstrain < lowerLimit) ? lowerLimit
: ((upperLimit < valueToConstrain) ? upperLimit : ((upperLimit < valueToConstrain) ? upperLimit
@@ -185,14 +186,18 @@ Type jlimit (const Type lowerLimit,
template <typename Type> template <typename Type>
bool isPositiveAndBelow (Type valueToTest, Type upperLimit) noexcept 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; return Type() <= valueToTest && valueToTest < upperLimit;
} }
template <> template <>
inline bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noexcept 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<unsigned int> (valueToTest) < static_cast<unsigned int> (upperLimit); return static_cast<unsigned int> (valueToTest) < static_cast<unsigned int> (upperLimit);
} }
@@ -204,14 +209,18 @@ inline bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noe
template <typename Type> template <typename Type>
bool isPositiveAndNotGreaterThan (Type valueToTest, Type upperLimit) noexcept 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; return Type() <= valueToTest && valueToTest <= upperLimit;
} }
template <> template <>
inline bool isPositiveAndNotGreaterThan (const int valueToTest, const int upperLimit) noexcept 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<unsigned int> (valueToTest) <= static_cast<unsigned int> (upperLimit); return static_cast<unsigned int> (valueToTest) <= static_cast<unsigned int> (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. /** Handy function for getting the number of elements in a simple const C array.
E.g. E.g.
@code @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 @endcode
*/ */
template <typename Type, int N>
int numElementsInArray (Type (&array)[N])
template <typename Type, size_t N>
size_t numElementsInArray (Type (&array)[N])
{ {
ignoreUnused (array); ignoreUnused (array);
(void) sizeof (0[array]); // This line should cause an error if you pass an object with a user-defined subscript operator (void) sizeof (0[array]); // This line should cause an error if you pass an object with a user-defined subscript operator


+ 47
- 10
source/modules/water/memory/Atomic.h View File

@@ -32,6 +32,14 @@
namespace water { 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. Simple class to hold a primitive value and perform atomic operations on it.
@@ -159,10 +167,12 @@ private:
template <typename Dest, typename Source> template <typename Dest, typename Source>
static inline Dest castTo (Source value) noexcept { union { Dest d; Source s; } u; u.s = value; return u.d; } 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 <Type, int32> (value); }
static inline Type castFrom64Bit (int64 value) noexcept { return castTo <Type, int64> (value); }
static inline int32 castTo32Bit (Type value) noexcept { return castTo <int32, Type> (value); }
static inline int64 castTo64Bit (Type value) noexcept { return castTo <int64, Type> (value); }
static inline Type castFrom32Bit (int32 value) noexcept { return castTo <Type, int32> (value); }
static inline Type castFrom64Bit (int64 value) noexcept { return castTo <Type, int64> (value); }
static inline Type castFrom32Bit (uint32 value) noexcept { return castTo <Type, uint32> (value); }
static inline Type castFrom64Bit (uint64 value) noexcept { return castTo <Type, uint64> (value); }
static inline int32 castTo32Bit (Type value) noexcept { return castTo <int32, Type> (value); }
static inline int64 castTo64Bit (Type value) noexcept { return castTo <int64, Type> (value); }
Type operator++ (int); // better to just use pre-increment with atomics.. Type operator++ (int); // better to just use pre-increment with atomics..
Type operator-- (int); Type operator-- (int);
@@ -186,11 +196,32 @@ private:
}; };
//============================================================================== //==============================================================================
template <typename Type>
inline Type Atomic<Type>::get() const noexcept
template<>
inline int32 Atomic<int32>::get() const noexcept
{
static_jassert (sizeof (int32) == 4);
return castFrom32Bit ((int32) __sync_add_and_fetch (const_cast<volatile int32*>(&value), 0));
}
template<>
inline int64 Atomic<int64>::get() const noexcept
{
static_jassert (sizeof (int64) == 8);
return castFrom64Bit ((int64) __sync_add_and_fetch (const_cast<volatile int64*>(&value), 0));
}
template<>
inline uint32 Atomic<uint32>::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<volatile uint32*>(&value), 0));
}
template<>
inline uint64 Atomic<uint64>::get() const noexcept
{
static_jassert (sizeof (uint64) == 8);
return castFrom64Bit ((uint64) __sync_add_and_fetch (const_cast<volatile uint64*>(&value), 0));
} }
template <typename Type> template <typename Type>
@@ -217,14 +248,14 @@ template <typename Type>
inline Type Atomic<Type>::operator++() noexcept inline Type Atomic<Type>::operator++() noexcept
{ {
return sizeof (Type) == 4 ? (Type) __sync_add_and_fetch (&value, (Type) 1) 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 <typename Type> template <typename Type>
inline Type Atomic<Type>::operator--() noexcept inline Type Atomic<Type>::operator--() noexcept
{ {
return sizeof (Type) == 4 ? (Type) __sync_add_and_fetch (&value, (Type) -1) 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 <typename Type> template <typename Type>
@@ -247,6 +278,12 @@ inline void Atomic<Type>::memoryBarrier() noexcept
__sync_synchronize(); __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 #endif // WATER_ATOMIC_H_INCLUDED

+ 2
- 0
source/modules/water/memory/HeapBlock.h View File

@@ -253,6 +253,8 @@ public:
private: private:
//============================================================================== //==============================================================================
ElementType* data; ElementType* data;
CARLA_DECLARE_NON_COPY_CLASS(HeapBlock)
}; };
} }


+ 3
- 2
source/modules/water/memory/ReferenceCountedObject.h View File

@@ -104,7 +104,8 @@ public:
protected: protected:
//============================================================================== //==============================================================================
/** Creates the reference-counted object (with an initial ref count of zero). */ /** Creates the reference-counted object (with an initial ref count of zero). */
ReferenceCountedObject() {}
ReferenceCountedObject()
: refCount() {}
/** Destructor. */ /** Destructor. */
virtual ~ReferenceCountedObject() virtual ~ReferenceCountedObject()
@@ -123,7 +124,7 @@ protected:
private: private:
//============================================================================== //==============================================================================
Atomic <int> refCount;
Atomic<int> refCount;
CARLA_DECLARE_NON_COPY_CLASS (ReferenceCountedObject) CARLA_DECLARE_NON_COPY_CLASS (ReferenceCountedObject)
}; };


+ 6
- 6
source/modules/water/midi/MidiFile.cpp View File

@@ -160,7 +160,7 @@ namespace MidiFileHelpers
MidiMessageSequence& results, MidiMessageSequence& results,
MethodType method) 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 MidiMessageSequence& track = *tracks.getUnchecked(i);
const int numEvents = track.getNumEvents(); 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(); 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]; return tracks [index];
} }
@@ -259,7 +259,7 @@ double MidiFile::getLastTimestamp() const
{ {
double t = 0.0; 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()); t = jmax (t, tracks.getUnchecked(i)->getEndTime());
return t; return t;
@@ -359,7 +359,7 @@ void MidiFile::convertTimestampTicksToSeconds()
if (timeFormat != 0) 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); 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 ((short) tracks.size())) return false;
if (! out.writeShortBigEndian (timeFormat)) 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)) if (! writeTrack (out, i))
return false; return false;


+ 2
- 2
source/modules/water/midi/MidiFile.h View File

@@ -64,13 +64,13 @@ public:
/** Returns the number of tracks in the file. /** Returns the number of tracks in the file.
@see getTrack, addTrack @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 one of the tracks in the file.
@returns a pointer to the track, or nullptr if the index is out-of-range @returns a pointer to the track, or nullptr if the index is out-of-range
@see getNumTracks, addTrack @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. /** Adds a midi track to the file.
This will make its own internal copy of the sequence that is passed-in. This will make its own internal copy of the sequence that is passed-in.


+ 53
- 53
source/modules/water/midi/MidiMessage.cpp View File

@@ -324,7 +324,7 @@ uint8* MidiMessage::allocateSpace (int bytes)
int MidiMessage::getChannel() const noexcept int MidiMessage::getChannel() const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
if ((data[0] & 0xf0) != 0xf0) if ((data[0] & 0xf0) != 0xf0)
return (data[0] & 0xf) + 1; 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 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) return ((data[0] & 0xf) == channel - 1)
&& ((data[0] & 0xf0) != 0xf0); && ((data[0] & 0xf0) != 0xf0);
@@ -355,7 +355,7 @@ void MidiMessage::setChannel (const int channel) noexcept
bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const noexcept bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
return ((data[0] & 0xf0) == 0x90) return ((data[0] & 0xf0) == 0x90)
&& (returnTrueForVelocity0 || data[2] != 0); && (returnTrueForVelocity0 || data[2] != 0);
@@ -363,7 +363,7 @@ bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const noexcept
bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) 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) return ((data[0] & 0xf0) == 0x80)
|| (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90)); || (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 bool MidiMessage::isNoteOnOrOff() const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
const int d = data[0] & 0xf0; const int d = data[0] & 0xf0;
return (d == 0x90) || (d == 0x80); return (d == 0x90) || (d == 0x80);
@@ -379,7 +379,7 @@ bool MidiMessage::isNoteOnOrOff() const noexcept
int MidiMessage::getNoteNumber() const noexcept int MidiMessage::getNoteNumber() const noexcept
{ {
return getRawData()[1];
return getData()[1];
} }
void MidiMessage::setNoteNumber (const int newNoteNumber) noexcept void MidiMessage::setNoteNumber (const int newNoteNumber) noexcept
@@ -391,7 +391,7 @@ void MidiMessage::setNoteNumber (const int newNoteNumber) noexcept
uint8 MidiMessage::getVelocity() const noexcept uint8 MidiMessage::getVelocity() const noexcept
{ {
if (isNoteOnOrOff()) if (isNoteOnOrOff())
return getRawData()[2];
return getData()[2];
return 0; return 0;
} }
@@ -418,13 +418,13 @@ void MidiMessage::multiplyVelocity (const float scaleFactor) noexcept
bool MidiMessage::isAftertouch() const noexcept bool MidiMessage::isAftertouch() const noexcept
{ {
return (getRawData()[0] & 0xf0) == 0xa0;
return (getData()[0] & 0xf0) == 0xa0;
} }
int MidiMessage::getAfterTouchValue() const noexcept int MidiMessage::getAfterTouchValue() const noexcept
{ {
jassert (isAftertouch()); jassert (isAftertouch());
return getRawData()[2];
return getData()[2];
} }
MidiMessage MidiMessage::aftertouchChange (const int channel, MidiMessage MidiMessage::aftertouchChange (const int channel,
@@ -442,13 +442,13 @@ MidiMessage MidiMessage::aftertouchChange (const int channel,
bool MidiMessage::isChannelPressure() const noexcept bool MidiMessage::isChannelPressure() const noexcept
{ {
return (getRawData()[0] & 0xf0) == 0xd0;
return (getData()[0] & 0xf0) == 0xd0;
} }
int MidiMessage::getChannelPressureValue() const noexcept int MidiMessage::getChannelPressureValue() const noexcept
{ {
jassert (isChannelPressure()); jassert (isChannelPressure());
return getRawData()[1];
return getData()[1];
} }
MidiMessage MidiMessage::channelPressureChange (const int channel, const int pressure) noexcept 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); 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 bool MidiMessage::isProgramChange() const noexcept
{ {
return (getRawData()[0] & 0xf0) == 0xc0;
return (getData()[0] & 0xf0) == 0xc0;
} }
int MidiMessage::getProgramChangeNumber() const noexcept int MidiMessage::getProgramChangeNumber() const noexcept
{ {
jassert (isProgramChange()); jassert (isProgramChange());
return getRawData()[1];
return getData()[1];
} }
MidiMessage MidiMessage::programChange (const int channel, const int programNumber) noexcept 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 bool MidiMessage::isPitchWheel() const noexcept
{ {
return (getRawData()[0] & 0xf0) == 0xe0;
return (getData()[0] & 0xf0) == 0xe0;
} }
int MidiMessage::getPitchWheelValue() const noexcept int MidiMessage::getPitchWheelValue() const noexcept
{ {
jassert (isPitchWheel()); jassert (isPitchWheel());
const uint8* const data = getRawData();
const uint8* const data = getData();
return data[1] | (data[2] << 7); 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 bool MidiMessage::isController() const noexcept
{ {
return (getRawData()[0] & 0xf0) == 0xb0;
return (getData()[0] & 0xf0) == 0xb0;
} }
bool MidiMessage::isControllerOfType (const int controllerType) const noexcept 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; return (data[0] & 0xf0) == 0xb0 && data[1] == controllerType;
} }
int MidiMessage::getControllerNumber() const noexcept int MidiMessage::getControllerNumber() const noexcept
{ {
jassert (isController()); jassert (isController());
return getRawData()[1];
return getData()[1];
} }
int MidiMessage::getControllerValue() const noexcept int MidiMessage::getControllerValue() const noexcept
{ {
jassert (isController()); jassert (isController());
return getRawData()[2];
return getData()[2];
} }
MidiMessage MidiMessage::controllerEvent (const int channel, const int controllerType, const int value) noexcept 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 bool MidiMessage::isAllNotesOff() const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
return (data[0] & 0xf0) == 0xb0 && data[1] == 123; return (data[0] & 0xf0) == 0xb0 && data[1] == 123;
} }
@@ -594,7 +594,7 @@ MidiMessage MidiMessage::allSoundOff (const int channel) noexcept
bool MidiMessage::isAllSoundOff() const noexcept bool MidiMessage::isAllSoundOff() const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
return (data[0] & 0xf0) == 0xb0 && data[1] == 120; return (data[0] & 0xf0) == 0xb0 && data[1] == 120;
} }
@@ -618,7 +618,7 @@ MidiMessage MidiMessage::masterVolume (const float volume)
//============================================================================== //==============================================================================
bool MidiMessage::isSysEx() const noexcept bool MidiMessage::isSysEx() const noexcept
{ {
return *getRawData() == 0xf0;
return *getData() == 0xf0;
} }
MidiMessage MidiMessage::createSysExMessage (const void* sysexData, const int dataSize) 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 const uint8* MidiMessage::getSysExData() const noexcept
{ {
return isSysEx() ? getRawData() + 1 : nullptr;
return isSysEx() ? getData() + 1 : nullptr;
} }
int MidiMessage::getSysExDataSize() const noexcept 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 int MidiMessage::getMetaEventType() const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
return *data != 0xff ? -1 : data[1]; return *data != 0xff ? -1 : data[1];
} }
int MidiMessage::getMetaEventLength() const noexcept int MidiMessage::getMetaEventLength() const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
if (*data == 0xff) if (*data == 0xff)
{ {
int n; int n;
@@ -670,7 +670,7 @@ const uint8* MidiMessage::getMetaEventData() const noexcept
jassert (isMetaEvent()); jassert (isMetaEvent());
int n; int n;
const uint8* d = getRawData() + 2;
const uint8* d = getData() + 2;
readVariableLengthVal (d, n); readVariableLengthVal (d, n);
return d + n; return d + n;
} }
@@ -722,14 +722,14 @@ MidiMessage MidiMessage::textMetaEvent (int type, StringRef text)
return result; 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 int MidiMessage::getMidiChannelMetaEventChannel() const noexcept
{ {
jassert (isMidiChannelMetaEvent()); jassert (isMidiChannelMetaEvent());
return getRawData()[3] + 1;
return getData()[3] + 1;
} }
double MidiMessage::getTempoSecondsPerQuarterNote() const noexcept double MidiMessage::getTempoSecondsPerQuarterNote() const noexcept
@@ -784,7 +784,7 @@ MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) noexcep
bool MidiMessage::isTimeSignatureMetaEvent() const noexcept bool MidiMessage::isTimeSignatureMetaEvent() const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
return (data[1] == 0x58) && (*data == (uint8) 0xff); 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 MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) noexcept
{ {
@@ -863,21 +863,21 @@ MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) noe
(positionInMidiBeats >> 7) & 127); (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); } 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); } 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); } 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); } 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 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 bool MidiMessage::isFullFrame() const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
return data[0] == 0xf0 return data[0] == 0xf0
&& data[1] == 0x7f && data[1] == 0x7f
@@ -900,7 +900,7 @@ void MidiMessage::getFullFrameParameters (int& hours, int& minutes, int& seconds
{ {
jassert (isFullFrame()); jassert (isFullFrame());
const uint8* const data = getRawData();
const uint8* const data = getData();
timecodeType = (SmpteTimecodeType) (data[5] >> 5); timecodeType = (SmpteTimecodeType) (data[5] >> 5);
hours = data[5] & 0x1f; hours = data[5] & 0x1f;
minutes = data[6]; minutes = data[6];
@@ -924,7 +924,7 @@ MidiMessage MidiMessage::fullFrame (const int hours, const int minutes,
bool MidiMessage::isMidiMachineControlMessage() const noexcept bool MidiMessage::isMidiMachineControlMessage() const noexcept
{ {
const uint8* const data = getRawData();
const uint8* const data = getData();
return data[0] == 0xf0 return data[0] == 0xf0
&& data[1] == 0x7f && data[1] == 0x7f
&& data[3] == 0x06 && data[3] == 0x06
@@ -935,7 +935,7 @@ MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand
{ {
jassert (isMidiMachineControlMessage()); jassert (isMidiMachineControlMessage());
return (MidiMachineControlCommand) getRawData()[4];
return (MidiMachineControlCommand) getData()[4];
} }
MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command) 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 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 if (size >= 12
&& data[0] == 0xf0 && data[0] == 0xf0
&& data[1] == 0x7f && data[1] == 0x7f


+ 3
- 2
source/modules/water/midi/MidiMessage.h View File

@@ -900,8 +900,9 @@ private:
double timeStamp; double timeStamp;
int size; 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); uint8* allocateSpace (int);
}; };


+ 7
- 7
source/modules/water/midi/MidiMessageSequence.cpp View File

@@ -142,7 +142,7 @@ MidiMessageSequence::MidiEventHolder* MidiMessageSequence::addEvent (const MidiM
void MidiMessageSequence::deleteEvent (const int index, void MidiMessageSequence::deleteEvent (const int index,
const bool deleteMatchingNoteUp) const bool deleteMatchingNoteUp)
{ {
if (isPositiveAndBelow (index, list.size()))
if (isPositiveAndBelow (index, static_cast<int>(list.size())))
{ {
if (deleteMatchingNoteUp) if (deleteMatchingNoteUp)
deleteEvent (getIndexOfMatchingKeyUp (index), false); deleteEvent (getIndexOfMatchingKeyUp (index), false);
@@ -163,7 +163,7 @@ struct MidiMessageSequenceSorter
void MidiMessageSequence::addSequence (const MidiMessageSequence& other, double timeAdjustment) void MidiMessageSequence::addSequence (const MidiMessageSequence& other, double timeAdjustment)
{ {
for (int i = 0; i < other.list.size(); ++i)
for (int i = 0; i < static_cast<int>(other.list.size()); ++i)
{ {
const MidiMessage& m = other.list.getUnchecked(i)->message; const MidiMessage& m = other.list.getUnchecked(i)->message;
@@ -180,7 +180,7 @@ void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
double firstAllowableTime, double firstAllowableTime,
double endOfAllowableDestTimes) double endOfAllowableDestTimes)
{ {
for (int i = 0; i < other.list.size(); ++i)
for (int i = 0; i < static_cast<int>(other.list.size()); ++i)
{ {
const MidiMessage& m = other.list.getUnchecked(i)->message; const MidiMessage& m = other.list.getUnchecked(i)->message;
const double t = m.getTimeStamp() + timeAdjustment; const double t = m.getTimeStamp() + timeAdjustment;
@@ -206,7 +206,7 @@ void MidiMessageSequence::sort() noexcept
void MidiMessageSequence::updateMatchedPairs() noexcept void MidiMessageSequence::updateMatchedPairs() noexcept
{ {
for (int i = 0; i < list.size(); ++i)
for (int i = 0; i < static_cast<int>(list.size()); ++i)
{ {
MidiEventHolder* const meh = list.getUnchecked(i); MidiEventHolder* const meh = list.getUnchecked(i);
const MidiMessage& m1 = meh->message; const MidiMessage& m1 = meh->message;
@@ -245,7 +245,7 @@ void MidiMessageSequence::updateMatchedPairs() noexcept
void MidiMessageSequence::addTimeToMessages (const double delta) noexcept void MidiMessageSequence::addTimeToMessages (const double delta) noexcept
{ {
for (int i = list.size(); --i >= 0;)
for (int i = static_cast<int>(list.size()); --i >= 0;)
{ {
MidiMessage& mm = list.getUnchecked(i)->message; MidiMessage& mm = list.getUnchecked(i)->message;
mm.setTimeStamp (mm.getTimeStamp() + delta); mm.setTimeStamp (mm.getTimeStamp() + delta);
@@ -257,7 +257,7 @@ void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToE
MidiMessageSequence& destSequence, MidiMessageSequence& destSequence,
const bool alsoIncludeMetaEvents) const const bool alsoIncludeMetaEvents) const
{ {
for (int i = 0; i < list.size(); ++i)
for (int i = 0; i < static_cast<int>(list.size()); ++i)
{ {
const MidiMessage& mm = list.getUnchecked(i)->message; const MidiMessage& mm = list.getUnchecked(i)->message;
@@ -268,7 +268,7 @@ void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToE
void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
{ {
for (int i = 0; i < list.size(); ++i)
for (int i = 0; i < static_cast<int>(list.size()); ++i)
{ {
const MidiMessage& mm = list.getUnchecked(i)->message; const MidiMessage& mm = list.getUnchecked(i)->message;


+ 4
- 4
source/modules/water/processors/AudioProcessorGraph.cpp View File

@@ -747,7 +747,7 @@ class ConnectionLookupTable
public: public:
explicit ConnectionLookupTable (const OwnedArray<AudioProcessorGraph::Connection>& connections) explicit ConnectionLookupTable (const OwnedArray<AudioProcessorGraph::Connection>& connections)
{ {
for (int i = 0; i < connections.size(); ++i)
for (int i = 0; i < static_cast<int>(connections.size()); ++i)
{ {
const AudioProcessorGraph::Connection* const c = connections.getUnchecked(i); const AudioProcessorGraph::Connection* const c = connections.getUnchecked(i);
@@ -1275,10 +1275,10 @@ void AudioProcessorGraph::buildRenderingSequence()
audioBuffers->setRenderingBufferSize (numRenderingBuffersNeeded, getBlockSize()); audioBuffers->setRenderingBufferSize (numRenderingBuffersNeeded, getBlockSize());
for (int i = midiBuffers.size(); --i >= 0;)
for (int i = static_cast<int>(midiBuffers.size()); --i >= 0;)
midiBuffers.getUnchecked(i)->clear(); midiBuffers.getUnchecked(i)->clear();
while (midiBuffers.size() < numMidiBuffersNeeded)
while (static_cast<int>(midiBuffers.size()) < numMidiBuffersNeeded)
midiBuffers.add (new MidiBuffer()); midiBuffers.add (new MidiBuffer());
renderingOps.swapWith (newRenderingOps); renderingOps.swapWith (newRenderingOps);
@@ -1362,7 +1362,7 @@ void AudioProcessorGraph::processAudio (AudioSampleBuffer& buffer, MidiBuffer& m
op->perform (renderingBuffers, midiBuffers, numSamples); 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); buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
midiMessages.clear(); midiMessages.clear();


+ 2
- 2
source/modules/water/processors/AudioProcessorGraph.h View File

@@ -190,10 +190,10 @@ public:
//============================================================================== //==============================================================================
/** Returns the number of connections in the graph. */ /** 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. */ /** 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. /** Searches for a connection between some specified channels.
If no such connection is found, this returns nullptr. If no such connection is found, this returns nullptr.


+ 3
- 3
source/modules/water/synthesisers/Synthesiser.cpp View File

@@ -90,7 +90,7 @@ Synthesiser::Synthesiser()
subBlockSubdivisionIsStrict (false), subBlockSubdivisionIsStrict (false),
shouldStealNotes (true) shouldStealNotes (true)
{ {
for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
for (size_t i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
lastPitchWheelValues[i] = 0x2000; lastPitchWheelValues[i] = 0x2000;
zerostruct(sustainPedalsDown); zerostruct(sustainPedalsDown);
@@ -506,7 +506,7 @@ SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
const bool stealIfNoneAvailable) const 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); SynthesiserVoice* const voice = voices.getUnchecked (i);
@@ -546,7 +546,7 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay,
Array<SynthesiserVoice*> usableVoices; Array<SynthesiserVoice*> usableVoices;
usableVoices.ensureStorageAllocated (voices.size()); 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); SynthesiserVoice* const voice = voices.getUnchecked (i);


+ 1
- 1
source/modules/water/synthesisers/Synthesiser.h View File

@@ -311,7 +311,7 @@ public:
void clearVoices(); void clearVoices();
/** Returns the number of voices that have been added. */ /** 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. */ /** Returns one of the voices that have been added. */
SynthesiserVoice* getVoice (int index) const; SynthesiserVoice* getVoice (int index) const;


+ 4
- 4
source/modules/water/text/CharPointer_UTF8.h View File

@@ -54,13 +54,13 @@ public:
{ {
} }
inline CharPointer_UTF8 operator= (CharPointer_UTF8 other) noexcept
inline CharPointer_UTF8& operator= (CharPointer_UTF8 other) noexcept
{ {
data = other.data; data = other.data;
return *this; return *this;
} }
inline CharPointer_UTF8 operator= (const CharType* text) noexcept
inline CharPointer_UTF8& operator= (const CharType* text) noexcept
{ {
data = const_cast<CharType*> (text); data = const_cast<CharType*> (text);
return *this; return *this;
@@ -129,7 +129,7 @@ public:
{ {
water_uchar bit = 0x40; water_uchar bit = 0x40;
while ((n & bit) != 0 && bit > 0x8)
while ((static_cast<unsigned char>(n) & bit) != 0 && bit > 0x8)
{ {
++data; ++data;
bit >>= 1; bit >>= 1;
@@ -140,7 +140,7 @@ public:
} }
/** Moves this pointer back to the previous character in the string. */ /** Moves this pointer back to the previous character in the string. */
CharPointer_UTF8 operator--() noexcept
CharPointer_UTF8& operator--() noexcept
{ {
int count = 0; int count = 0;


+ 1
- 1
source/modules/water/water.h View File

@@ -155,7 +155,7 @@ namespace NumberToStringConverters
do do
{ {
*--t = '0' + (char) (v % 10);
*--t = static_cast<char>('0' + (v % 10));
v /= 10; v /= 10;
} while (v > 0); } while (v > 0);


+ 1
- 1
source/native-plugins/Makefile View File

@@ -81,6 +81,6 @@ $(OBJDIR)/%.cpp.o: %.cpp


# --------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------


-include $(OBJS_all:%.o=%.d)
-include $(OBJS:%.o=%.d)


# --------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------

+ 1
- 0
source/native-plugins/_all.c View File

@@ -46,6 +46,7 @@ extern void carla_register_native_plugin_bigmeter(void);
extern void carla_register_native_plugin_notes(void); extern void carla_register_native_plugin_notes(void);


#ifdef HAVE_EXTERNAL_PLUGINS #ifdef HAVE_EXTERNAL_PLUGINS
void carla_register_all_native_external_plugins(void);
# define CARLA_EXTERNAL_PLUGINS_INCLUDED_DIRECTLY # define CARLA_EXTERNAL_PLUGINS_INCLUDED_DIRECTLY
# include "external/_all.c" # include "external/_all.c"
#endif #endif


+ 35
- 17
source/native-plugins/audio-base.hpp View File

@@ -29,20 +29,20 @@ typedef struct adinfo ADInfo;


struct AudioFilePool { struct AudioFilePool {
float* buffer[2]; float* buffer[2];
uint64_t startFrame;
uint32_t sampleRate; uint32_t sampleRate;
uint32_t startFrame;
uint32_t size; uint32_t size;


#ifdef CARLA_PROPER_CPP11_SUPPORT #ifdef CARLA_PROPER_CPP11_SUPPORT
AudioFilePool() AudioFilePool()
: buffer{nullptr}, : buffer{nullptr},
sampleRate(0),
startFrame(0), startFrame(0),
sampleRate(0),
size(0) {} size(0) {}
#else #else
AudioFilePool() AudioFilePool()
: sampleRate(0),
startFrame(0),
: startFrame(0),
sampleRate(0),
size(0) size(0)
{ {
buffer[0] = buffer[1] = nullptr; buffer[0] = buffer[1] = nullptr;
@@ -103,28 +103,33 @@ struct AudioFilePool {
carla_zeroFloats(buffer[0], size); carla_zeroFloats(buffer[0], size);
carla_zeroFloats(buffer[1], size); carla_zeroFloats(buffer[1], size);
} }

CARLA_DECLARE_NON_COPY_STRUCT(AudioFilePool)
}; };


class AbstractAudioPlayer class AbstractAudioPlayer
{ {
public: public:
virtual ~AbstractAudioPlayer() {} virtual ~AbstractAudioPlayer() {}
virtual uint32_t getLastFrame() const = 0;
virtual uint64_t getLastFrame() const = 0;
}; };


class AudioFileThread : public CarlaThread class AudioFileThread : public CarlaThread
{ {
public: public:
AudioFileThread(AbstractAudioPlayer* const player, const double sampleRate)
AudioFileThread(AbstractAudioPlayer* const player, const uint32_t sampleRate)
: CarlaThread("AudioFileThread"), : CarlaThread("AudioFileThread"),
kPlayer(player), kPlayer(player),
fLoopingMode(true), fLoopingMode(true),
fNeedsRead(false), fNeedsRead(false),
fQuitNow(true), fQuitNow(true),
fFilePtr(nullptr), fFilePtr(nullptr),
fFileNfo(),
fMaxPlayerFrame(0), fMaxPlayerFrame(0),
fPollTempData(nullptr), fPollTempData(nullptr),
fPollTempSize(0)
fPollTempSize(0),
fPool(),
fMutex()
{ {
CARLA_ASSERT(kPlayer != nullptr); CARLA_ASSERT(kPlayer != nullptr);


@@ -247,7 +252,7 @@ public:
return false; return false;
} }


fMaxPlayerFrame = fFileNfo.frames/fFileNfo.channels;
fMaxPlayerFrame = static_cast<uint32_t>(fFileNfo.frames/fFileNfo.channels);
fPollTempSize = pollTempSize; fPollTempSize = pollTempSize;


readPoll(); readPoll();
@@ -289,16 +294,18 @@ public:
return; 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<uint64_t>(fFileNfo.frames))
{ {
if (fLoopingMode) if (fLoopingMode)
{ {
const uint64_t readFrameCheckLoop = lastFrame % fMaxPlayerFrame;
CARLA_SAFE_ASSERT_RETURN(readFrameCheckLoop < INT32_MAX,);

carla_debug("R: transport out of bounds for loop"); carla_debug("R: transport out of bounds for loop");
readFrame %= fMaxPlayerFrame;
readFrameCheck = static_cast<int32_t>(readFrameCheckLoop);
} }
else else
{ {
@@ -307,6 +314,13 @@ public:
return; return;
} }
} }
else
{
CARLA_SAFE_ASSERT_RETURN(lastFrame < INT32_MAX,);
readFrameCheck = static_cast<int32_t>(lastFrame);
}

const int32_t readFrame = readFrameCheck;


// temp data buffer // temp data buffer
carla_zeroFloats(fPollTempData, fPollTempSize); carla_zeroFloats(fPollTempData, fPollTempSize);
@@ -326,12 +340,14 @@ public:
return; return;
} }


const size_t urv = static_cast<size_t>(rv);

// see if we can read more // see if we can read more
if (readFrame + rv >= static_cast<ssize_t>(fFileNfo.frames) && static_cast<size_t>(rv) < fPollTempSize)
if (readFrame + rv >= static_cast<ssize_t>(fFileNfo.frames) && urv < fPollTempSize)
{ {
carla_debug("R: from start"); carla_debug("R: from start");
ad_seek(fFilePtr, 0); 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 // lock, and put data asap
@@ -396,8 +412,8 @@ protected:
{ {
while (! fQuitNow) 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)) if (fNeedsRead || lastFrame < fPool.startFrame || (lastFrame - fPool.startFrame >= fPool.size*3/4 && loopedFrame < fMaxPlayerFrame))
readPoll(); readPoll();
@@ -423,6 +439,8 @@ private:


AudioFilePool fPool; AudioFilePool fPool;
CarlaMutex fMutex; CarlaMutex fMutex;

CARLA_DECLARE_NON_COPY_STRUCT(AudioFileThread)
}; };


#endif // AUDIO_BASE_HPP_INCLUDED #endif // AUDIO_BASE_HPP_INCLUDED

+ 13
- 10
source/native-plugins/audio-file.cpp View File

@@ -33,9 +33,10 @@ public:
fDoProcess(false), fDoProcess(false),
fLastFrame(0), fLastFrame(0),
fMaxFrame(0), fMaxFrame(0),
fThread(this, getSampleRate())
fPool(),
fThread(this, static_cast<uint32_t>(getSampleRate()))
{ {
fPool.create(getSampleRate());
fPool.create(static_cast<uint32_t>(getSampleRate()));
} }


~AudioFilePlugin() override ~AudioFilePlugin() override
@@ -44,7 +45,7 @@ public:
fThread.stopNow(); fThread.stopNow();
} }


uint32_t getLastFrame() const override
uint64_t getLastFrame() const override
{ {
return fLastFrame; return fLastFrame;
} }
@@ -166,19 +167,21 @@ protected:
return; 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<uint32_t>(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) for (uint32_t i=0; i < frames; ++i, ++poolFrame)
{ {
if (poolFrame >= 0 && poolFrame < poolSize) 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 // reset
fPool.buffer[0][poolFrame] = 0.0f;
fPool.buffer[1][poolFrame] = 0.0f;
bufferL[poolFrame] = 0.0f;
bufferR[poolFrame] = 0.0f;
} }
else else
{ {
@@ -208,7 +211,7 @@ private:
bool fLoopMode; bool fLoopMode;
bool fDoProcess; bool fDoProcess;


uint32_t fLastFrame;
uint64_t fLastFrame;
uint32_t fMaxFrame; uint32_t fMaxFrame;


AudioFilePool fPool; AudioFilePool fPool;


+ 23
- 16
source/native-plugins/midi-base.hpp View File

@@ -354,10 +354,13 @@ public:
CARLA_SAFE_ASSERT_RETURN(tmpSize > 0,); CARLA_SAFE_ASSERT_RETURN(tmpSize > 0,);
CARLA_SAFE_ASSERT_RETURN(tmpSize < 24,); CARLA_SAFE_ASSERT_RETURN(tmpSize < 24,);


std::strncpy(tmpBuf, dataRead, static_cast<size_t>(tmpSize));
tmpBuf[tmpSize] = '\0';
dataRead += tmpSize+1;
dataPos += tmpSize+1;
{
const size_t uSize = static_cast<size_t>(tmpSize);
std::strncpy(tmpBuf, dataRead, uSize);
tmpBuf[tmpSize] = '\0';
dataRead += uSize+1U;
dataPos += uSize+1U;
}


const long long time = std::atoll(tmpBuf); const long long time = std::atoll(tmpBuf);
CARLA_SAFE_ASSERT_RETURN(time >= 0,); CARLA_SAFE_ASSERT_RETURN(time >= 0,);
@@ -371,27 +374,31 @@ public:
tmpSize = needle - dataRead; tmpSize = needle - dataRead;
CARLA_SAFE_ASSERT_RETURN(tmpSize > 0 && tmpSize < 24,); CARLA_SAFE_ASSERT_RETURN(tmpSize > 0 && tmpSize < 24,);


std::strncpy(tmpBuf, dataRead, static_cast<size_t>(tmpSize));
tmpBuf[tmpSize] = '\0';
dataRead += tmpSize+1;
dataPos += tmpSize+1;
{
const size_t uSize = static_cast<size_t>(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<uint8_t>(size);
midiEvent.size = static_cast<uint8_t>(midiDataSize);


// get events // get events
for (int i=0; i<size; ++i)
for (int i=0; i<midiDataSize; ++i)
{ {
CARLA_SAFE_ASSERT_RETURN(dataRead-data >= 4,); CARLA_SAFE_ASSERT_RETURN(dataRead-data >= 4,);


tmpSize = i==0 ? 4 : 3; tmpSize = i==0 ? 4 : 3;


std::strncpy(tmpBuf, dataRead, static_cast<size_t>(tmpSize));
const size_t uSize = static_cast<size_t>(tmpSize);
std::strncpy(tmpBuf, dataRead, uSize);
tmpBuf[tmpSize] = '\0'; tmpBuf[tmpSize] = '\0';
dataRead += tmpSize+1;
dataPos += tmpSize+1;
dataRead += uSize+1U;
dataPos += uSize+1U;


long mdata; long mdata;


@@ -409,7 +416,7 @@ public:
midiEvent.data[i] = static_cast<uint8_t>(mdata); midiEvent.data[i] = static_cast<uint8_t>(mdata);
} }


for (int i=size; i<MAX_EVENT_DATA_SIZE; ++i)
for (int i=midiDataSize; i<MAX_EVENT_DATA_SIZE; ++i)
midiEvent.data[i] = 0; midiEvent.data[i] = 0;


RawMidiEvent* const event(new RawMidiEvent()); RawMidiEvent* const event(new RawMidiEvent());


+ 1
- 1
source/native-plugins/midi-file.cpp View File

@@ -160,7 +160,7 @@ private:


const double sampleRate(getSampleRate()); const double sampleRate(getSampleRate());


for (int i=0, numTracks = midiFile.getNumTracks(); i<numTracks; ++i)
for (size_t i=0, numTracks = midiFile.getNumTracks(); i<numTracks; ++i)
{ {
const MidiMessageSequence* const track(midiFile.getTrack(i)); const MidiMessageSequence* const track(midiFile.getTrack(i));
CARLA_SAFE_ASSERT_CONTINUE(track != nullptr); CARLA_SAFE_ASSERT_CONTINUE(track != nullptr);


+ 1
- 1
source/utils/CarlaEngineUtils.hpp View File

@@ -189,7 +189,7 @@ void fillWaterMidiBufferFromEngineEvents(water::MidiBuffer& midiBuffer, const En
mdataTmp[0] = static_cast<uint8_t>(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT)); mdataTmp[0] = static_cast<uint8_t>(midiEvent.data[0] | (engineEvent.channel & MIDI_CHANNEL_BIT));


// copy rest // copy rest
carla_copy<uint8_t>(mdataTmp+1, midiEvent.data+1, size-1);
carla_copy<uint8_t>(mdataTmp+1, midiEvent.data+1, size-1U);


// done // done
mdataPtr = mdataTmp; mdataPtr = mdataTmp;


+ 1
- 0
source/utils/CarlaLv2Utils.hpp View File

@@ -557,6 +557,7 @@ public:
fWorker(nullptr), fWorker(nullptr),
fTimeInfo(), fTimeInfo(),
fLastPositionData(), fLastPositionData(),
fPorts(),
fURIs(), fURIs(),
fUI() fUI()
{ {


+ 2
- 1
source/utils/CarlaPluginUI.cpp View File

@@ -155,7 +155,8 @@ public:
carla_zeroStruct(hints); carla_zeroStruct(hints);


if (XGetNormalHints(fDisplay, childWindow, &hints) && hints.width > 0 && hints.height > 0) if (XGetNormalHints(fDisplay, childWindow, &hints) && hints.width > 0 && hints.height > 0)
setSize(hints.width, hints.height, false);
setSize(static_cast<uint>(hints.width),
static_cast<uint>(hints.height), false);
} }


const Atom _xevp = XInternAtom(fDisplay, "_XEventProc", False); const Atom _xevp = XInternAtom(fDisplay, "_XEventProc", False);


Loading…
Cancel
Save