diff --git a/extras/juce demo/src/demos/AudioDemoLatencyPage.cpp b/extras/juce demo/src/demos/AudioDemoLatencyPage.cpp index da1ad88bab..705dd0d22f 100644 --- a/extras/juce demo/src/demos/AudioDemoLatencyPage.cpp +++ b/extras/juce demo/src/demos/AudioDemoLatencyPage.cpp @@ -204,7 +204,8 @@ private: const float* s = buffer.getSampleData (0, 0); const int spikeDriftAllowed = 5; - Array spikesFound (100); + Array spikesFound; + spikesFound.ensureStorageAllocated (100); double runningAverage = 0; int lastSpike = 0; diff --git a/src/application/juce_ApplicationCommandManager.cpp b/src/application/juce_ApplicationCommandManager.cpp index 8f7a6e25fa..61f0517363 100644 --- a/src/application/juce_ApplicationCommandManager.cpp +++ b/src/application/juce_ApplicationCommandManager.cpp @@ -38,8 +38,7 @@ BEGIN_JUCE_NAMESPACE //============================================================================== ApplicationCommandManager::ApplicationCommandManager() - : listeners (8), - firstTarget (0) + : firstTarget (0) { keyMappings = new KeyPressMappingSet (this); @@ -166,7 +165,7 @@ const StringArray ApplicationCommandManager::getCommandCategories() const throw( const Array ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw() { - Array results (4); + Array results; for (int i = 0; i < commands.size(); ++i) if (commands.getUnchecked(i)->categoryName == categoryName) diff --git a/src/audio/audio_file_formats/juce_AudioFormatManager.cpp b/src/audio/audio_file_formats/juce_AudioFormatManager.cpp index fba221ba00..1dcbc513fa 100644 --- a/src/audio/audio_file_formats/juce_AudioFormatManager.cpp +++ b/src/audio/audio_file_formats/juce_AudioFormatManager.cpp @@ -37,8 +37,7 @@ BEGIN_JUCE_NAMESPACE //============================================================================== AudioFormatManager::AudioFormatManager() - : knownFormats (4), - defaultFormatIndex (0) + : defaultFormatIndex (0) { } diff --git a/src/audio/audio_sources/juce_BufferingAudioSource.cpp b/src/audio/audio_sources/juce_BufferingAudioSource.cpp index 3a3a4dc3f6..d36324c958 100644 --- a/src/audio/audio_sources/juce_BufferingAudioSource.cpp +++ b/src/audio/audio_sources/juce_BufferingAudioSource.cpp @@ -42,8 +42,7 @@ class SharedBufferingAudioSourceThread : public DeletedAtShutdown, { public: SharedBufferingAudioSourceThread() - : Thread ("Audio Buffer"), - sources (8) + : Thread ("Audio Buffer") { } diff --git a/src/audio/devices/juce_AudioDeviceManager.cpp b/src/audio/devices/juce_AudioDeviceManager.cpp index d05a04d660..5b3b4c85f6 100644 --- a/src/audio/devices/juce_AudioDeviceManager.cpp +++ b/src/audio/devices/juce_AudioDeviceManager.cpp @@ -64,9 +64,6 @@ AudioDeviceManager::AudioDeviceManager() inputLevelMeasurementEnabledCount (0), inputLevel (0), tempBuffer (2, 2), - enabledMidiInputs (4), - midiCallbacks (4), - midiCallbackDevices (4), defaultMidiOutput (0), cpuUsageMs (0), timeToCpuScale (0) diff --git a/src/audio/midi/juce_MidiBuffer.cpp b/src/audio/midi/juce_MidiBuffer.cpp index 54254b96e3..3f8c31c968 100644 --- a/src/audio/midi/juce_MidiBuffer.cpp +++ b/src/audio/midi/juce_MidiBuffer.cpp @@ -32,24 +32,20 @@ BEGIN_JUCE_NAMESPACE //============================================================================== MidiBuffer::MidiBuffer() throw() - : data (32), - bytesUsed (0) + : bytesUsed (0) { } MidiBuffer::MidiBuffer (const MidiMessage& message) throw() - : data (32), - bytesUsed (0) + : bytesUsed (0) { addEvent (message, 0); } MidiBuffer::MidiBuffer (const MidiBuffer& other) throw() - : data (32), - bytesUsed (other.bytesUsed) + : bytesUsed (other.bytesUsed), + data (other.data) { - data.ensureAllocatedSize (bytesUsed); - memcpy (data.elements, other.data.elements, bytesUsed); } const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() @@ -57,10 +53,7 @@ const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() if (this != &other) { bytesUsed = other.bytesUsed; - data.ensureAllocatedSize (bytesUsed); - - if (bytesUsed > 0) - memcpy (data.elements, other.data.elements, bytesUsed); + data = other.data; } return *this; @@ -68,8 +61,7 @@ const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() void MidiBuffer::swap (MidiBuffer& other) { - swapVariables (data.elements, other.data.elements); - swapVariables (data.numAllocated, other.data.numAllocated); + data.swapWith (other.data); swapVariables (bytesUsed, other.bytesUsed); } @@ -85,12 +77,12 @@ void MidiBuffer::clear() throw() void MidiBuffer::clear (const int startSample, const int numSamples) throw() { - uint8* const start = findEventAfter (data.elements, startSample - 1); + uint8* const start = findEventAfter (data, startSample - 1); uint8* const end = findEventAfter (start, startSample + numSamples - 1); if (end > start) { - const size_t bytesToMove = (size_t) (bytesUsed - (end - data.elements)); + const size_t bytesToMove = (size_t) (bytesUsed - (end - (uint8*) data.getData())); if (bytesToMove > 0) memmove (start, end, bytesToMove); @@ -144,10 +136,11 @@ void MidiBuffer::addEvent (const uint8* const newData, if (numBytes > 0) { - data.ensureAllocatedSize (bytesUsed + numBytes + 6); + int spaceNeeded = bytesUsed + numBytes + 6; + data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7); - uint8* d = findEventAfter (data.elements, sampleNumber); - const size_t bytesToMove = (size_t) (bytesUsed - (d - data.elements)); + uint8* d = findEventAfter ((uint8*) data.getData(), sampleNumber); + const size_t bytesToMove = (size_t) (bytesUsed - (d - (uint8*) data.getData())); if (bytesToMove > 0) memmove (d + numBytes + 6, @@ -173,13 +166,13 @@ void MidiBuffer::addEvents (const MidiBuffer& otherBuffer, Iterator i (otherBuffer); i.setNextSamplePosition (startSample); - const uint8* data; - int size, position; + const uint8* eventData; + int eventSize, position; - while (i.getNextEvent (data, size, position) + while (i.getNextEvent (eventData, eventSize, position) && (position < startSample + numSamples || numSamples < 0)) { - addEvent (data, size, position + sampleDeltaToAdd); + addEvent (eventData, eventSize, position + sampleDeltaToAdd); } } @@ -191,8 +184,8 @@ bool MidiBuffer::isEmpty() const throw() int MidiBuffer::getNumEvents() const throw() { int n = 0; - const uint8* d = data.elements; - const uint8* const end = data.elements + bytesUsed; + const uint8* d = (uint8*) data.getData(); + const uint8* const end = d + bytesUsed; while (d < end) { @@ -206,7 +199,7 @@ int MidiBuffer::getNumEvents() const throw() int MidiBuffer::getFirstEventTime() const throw() { - return (bytesUsed > 0) ? *(const int*) data.elements : 0; + return (bytesUsed > 0) ? *(const int*) data.getData() : 0; } int MidiBuffer::getLastEventTime() const throw() @@ -214,7 +207,7 @@ int MidiBuffer::getLastEventTime() const throw() if (bytesUsed == 0) return 0; - const uint8* d = data.elements; + const uint8* d = (uint8*) data.getData(); const uint8* const endData = d + bytesUsed; for (;;) @@ -230,7 +223,7 @@ int MidiBuffer::getLastEventTime() const throw() uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw() { - const uint8* const endData = data.elements + bytesUsed; + const uint8* const endData = ((uint8*) data.getData()) + bytesUsed; while (d < endData && *(int*) d <= samplePosition) { @@ -244,7 +237,7 @@ uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const thr //============================================================================== MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw() : buffer (buffer_), - data (buffer_.data.elements) + data ((uint8*) buffer_.data.getData()) { } @@ -255,8 +248,8 @@ MidiBuffer::Iterator::~Iterator() throw() //============================================================================== void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw() { - data = buffer.data.elements; - const uint8* dataEnd = buffer.data.elements + buffer.bytesUsed; + data = buffer.data; + const uint8* dataEnd = ((uint8*) buffer.data.getData()) + buffer.bytesUsed; while (data < dataEnd && *(int*) data < samplePosition) { @@ -269,7 +262,7 @@ bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, int& samplePosition) throw() { - if (data >= buffer.data.elements + buffer.bytesUsed) + if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed) return false; samplePosition = *(int*) data; @@ -285,7 +278,7 @@ bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePosition) throw() { - if (data >= buffer.data.elements + buffer.bytesUsed) + if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed) return false; samplePosition = *(int*) data; diff --git a/src/audio/midi/juce_MidiBuffer.h b/src/audio/midi/juce_MidiBuffer.h index 7e023d9b8b..223dae6a6f 100644 --- a/src/audio/midi/juce_MidiBuffer.h +++ b/src/audio/midi/juce_MidiBuffer.h @@ -26,7 +26,7 @@ #ifndef __JUCE_MIDIBUFFER_JUCEHEADER__ #define __JUCE_MIDIBUFFER_JUCEHEADER__ -#include "../../containers/juce_ArrayAllocationBase.h" +#include "../../containers/juce_MemoryBlock.h" #include "juce_MidiMessage.h" @@ -226,7 +226,7 @@ public: private: friend class MidiBuffer::Iterator; - ArrayAllocationBase data; + MemoryBlock data; int bytesUsed; uint8* findEventAfter (uint8* d, const int samplePosition) const throw(); diff --git a/src/audio/midi/juce_MidiKeyboardState.cpp b/src/audio/midi/juce_MidiKeyboardState.cpp index dc82b437e6..5a244b8aac 100644 --- a/src/audio/midi/juce_MidiKeyboardState.cpp +++ b/src/audio/midi/juce_MidiKeyboardState.cpp @@ -33,7 +33,6 @@ BEGIN_JUCE_NAMESPACE //============================================================================== MidiKeyboardState::MidiKeyboardState() - : listeners (2) { zeromem (noteStates, sizeof (noteStates)); } diff --git a/src/audio/midi/juce_MidiMessageSequence.cpp b/src/audio/midi/juce_MidiMessageSequence.cpp index fb19920572..6885a2ba1c 100644 --- a/src/audio/midi/juce_MidiMessageSequence.cpp +++ b/src/audio/midi/juce_MidiMessageSequence.cpp @@ -298,7 +298,8 @@ void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumbe { bool doneProg = false; bool donePitchWheel = false; - Array doneControllers (32); + Array doneControllers; + doneControllers.ensureStorageAllocated (32); for (int i = list.size(); --i >= 0;) { diff --git a/src/audio/synthesisers/juce_Synthesiser.cpp b/src/audio/synthesisers/juce_Synthesiser.cpp index f0061c7c2d..e7e5bcc127 100644 --- a/src/audio/synthesisers/juce_Synthesiser.cpp +++ b/src/audio/synthesisers/juce_Synthesiser.cpp @@ -72,9 +72,7 @@ void SynthesiserVoice::clearCurrentNote() //============================================================================== Synthesiser::Synthesiser() - : voices (2), - sounds (2), - sampleRate (0), + : sampleRate (0), lastNoteOnCounter (0), shouldStealNotes (true) { diff --git a/src/containers/juce_Array.h b/src/containers/juce_Array.h index b8a2ec1dbf..93c2d59864 100644 --- a/src/containers/juce_Array.h +++ b/src/containers/juce_Array.h @@ -56,15 +56,9 @@ class Array { public: //============================================================================== - /** Creates an empty array. - - @param granularity this is the size of increment by which the internal storage - used by the array will grow. Only change it from the default if you know the - array is going to be very big and needs to be able to grow efficiently. - */ - Array (const int granularity = juceDefaultArrayGranularity) throw() - : data (granularity), - numUsed (0) + /** Creates an empty array. */ + Array() throw() + : numUsed (0) { } @@ -72,7 +66,6 @@ public: @param other the array to copy */ Array (const Array& other) throw() - : data (other.data.granularity) { other.lockArray(); numUsed = other.numUsed; @@ -86,8 +79,7 @@ public: @param values the array to copy from */ Array (const ElementType* values) throw() - : data (juceDefaultArrayGranularity), - numUsed (0) + : numUsed (0) { while (*values != 0) add (*values++); @@ -99,8 +91,7 @@ public: @param numValues the number of values in the array */ Array (const ElementType* values, int numValues) throw() - : data (juceDefaultArrayGranularity), - numUsed (numValues) + : numUsed (numValues) { data.setAllocatedSize (numValues); memcpy (data.elements, values, numValues * sizeof (ElementType)); @@ -121,7 +112,6 @@ public: other.lockArray(); lock.enter(); - data.granularity = other.data.granularity; data.ensureAllocatedSize (other.size()); numUsed = other.numUsed; memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); @@ -977,19 +967,7 @@ public: void minimiseStorageOverheads() throw() { lock.enter(); - - if (numUsed == 0) - { - data.setAllocatedSize (0); - } - else - { - const int newAllocation = data.granularity * (numUsed / data.granularity + 1); - - if (newAllocation < data.numAllocated) - data.setAllocatedSize (newAllocation); - } - + data.shrinkToNoMoreThan (numUsed); lock.exit(); } @@ -1001,7 +979,9 @@ public: */ void ensureStorageAllocated (const int minNumElements) throw() { + lock.enter(); data.ensureAllocatedSize (minNumElements); + lock.exit(); } //============================================================================== diff --git a/src/containers/juce_ArrayAllocationBase.h b/src/containers/juce_ArrayAllocationBase.h index 131cc2ed37..1ed5250b68 100644 --- a/src/containers/juce_ArrayAllocationBase.h +++ b/src/containers/juce_ArrayAllocationBase.h @@ -27,14 +27,6 @@ #define __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__ -//============================================================================== -/** The default size of chunk in which arrays increase their storage. - - Used by ArrayAllocationBase and its subclasses. -*/ -const int juceDefaultArrayGranularity = 8; - - //============================================================================== /** Implements some basic array storage allocation functions. @@ -49,17 +41,11 @@ class ArrayAllocationBase { public: //============================================================================== - /** Creates an empty array. - - @param granularity_ this is the size of increment by which the internal storage - will be increased. - */ - ArrayAllocationBase (const int granularity_) throw() + /** Creates an empty array. */ + ArrayAllocationBase() throw() : elements (0), - numAllocated (0), - granularity (granularity_) + numAllocated (0) { - jassert (granularity > 0); } /** Destructor. */ @@ -114,25 +100,21 @@ public: void ensureAllocatedSize (int minNumElements) throw() { if (minNumElements > numAllocated) - { - // for arrays with small granularity that get big, start - // increasing the size in bigger jumps - if (minNumElements > (granularity << 6)) - { - minNumElements += (minNumElements / granularity); - if (minNumElements > (granularity << 8)) - minNumElements += granularity << 6; - else - minNumElements += granularity << 5; - } + setAllocatedSize ((minNumElements + minNumElements / 2 + 8) & ~7); + } - setAllocatedSize (granularity * (minNumElements / granularity + 1)); - } + /** Minimises the amount of storage allocated so that it's no more than + the given number of elements. + */ + void shrinkToNoMoreThan (int maxNumElements) throw() + { + if (maxNumElements < numAllocated) + setAllocatedSize (maxNumElements); } //============================================================================== ElementType* elements; - int numAllocated, granularity; + int numAllocated; private: ArrayAllocationBase (const ArrayAllocationBase&); diff --git a/src/containers/juce_MemoryBlock.cpp b/src/containers/juce_MemoryBlock.cpp index 5541adf0f6..ef488c3c45 100644 --- a/src/containers/juce_MemoryBlock.cpp +++ b/src/containers/juce_MemoryBlock.cpp @@ -145,6 +145,12 @@ void MemoryBlock::ensureSize (const int minimumSize, setSize (minimumSize, initialiseToZero); } +void MemoryBlock::swapWith (MemoryBlock& other) throw() +{ + swapVariables (size, other.size); + data.swapWith (other.data); +} + //============================================================================== void MemoryBlock::fillWith (const uint8 value) throw() { diff --git a/src/containers/juce_MemoryBlock.h b/src/containers/juce_MemoryBlock.h index e3f63f05e4..8614fe1801 100644 --- a/src/containers/juce_MemoryBlock.h +++ b/src/containers/juce_MemoryBlock.h @@ -151,6 +151,11 @@ public: void append (const void* const data, const int numBytes) throw(); + /** Exchanges the contents of this and another memory block. + No actual copying is required for this, so it's very fast. + */ + void swapWith (MemoryBlock& other) throw(); + //============================================================================== /** Copies data into this MemoryBlock from a memory address. diff --git a/src/containers/juce_OwnedArray.h b/src/containers/juce_OwnedArray.h index 35ea144ff3..1bf749a711 100644 --- a/src/containers/juce_OwnedArray.h +++ b/src/containers/juce_OwnedArray.h @@ -58,15 +58,9 @@ class OwnedArray { public: //============================================================================== - /** Creates an empty array. - - @param granularity this is the size of increment by which the internal storage - used by the array will grow. Only change it from the default if you know the - array is going to be very big and needs to be able to grow efficiently. - */ - OwnedArray (const int granularity = juceDefaultArrayGranularity) throw() - : data (granularity), - numUsed (0) + /** Creates an empty array. */ + OwnedArray() throw() + : numUsed (0) { } @@ -674,19 +668,7 @@ public: void minimiseStorageOverheads() throw() { lock.enter(); - - if (numUsed == 0) - { - data.setAllocatedSize (0); - } - else - { - const int newAllocation = data.granularity * (numUsed / data.granularity + 1); - - if (newAllocation < data.numAllocated) - data.setAllocatedSize (newAllocation); - } - + data.shrinkToNoMoreThan (numUsed); lock.exit(); } @@ -698,7 +680,9 @@ public: */ void ensureStorageAllocated (const int minNumElements) throw() { + lock.enter(); data.ensureAllocatedSize (minNumElements); + lock.exit(); } //============================================================================== diff --git a/src/containers/juce_ReferenceCountedArray.h b/src/containers/juce_ReferenceCountedArray.h index cc0a1bba95..ec153ead10 100644 --- a/src/containers/juce_ReferenceCountedArray.h +++ b/src/containers/juce_ReferenceCountedArray.h @@ -51,22 +51,15 @@ class ReferenceCountedArray public: //============================================================================== /** Creates an empty array. - - @param granularity this is the size of increment by which the internal storage - used by the array will grow. Only change it from the default if you know the - array is going to be very big and needs to be able to grow efficiently. - @see ReferenceCountedObject, Array, OwnedArray */ - ReferenceCountedArray (const int granularity = juceDefaultArrayGranularity) throw() - : data (granularity), - numUsed (0) + ReferenceCountedArray() throw() + : numUsed (0) { } /** Creates a copy of another array */ ReferenceCountedArray (const ReferenceCountedArray& other) throw() - : data (other.data.granularity) { other.lockArray(); numUsed = other.numUsed; @@ -93,7 +86,6 @@ public: clear(); - data.granularity = other.granularity; data.ensureAllocatedSize (other.numUsed); numUsed = other.numUsed; memcpy (data.elements, other.data.elements, numUsed * sizeof (ObjectClass*)); @@ -738,19 +730,7 @@ public: void minimiseStorageOverheads() throw() { lock.enter(); - - if (numUsed == 0) - { - data.setAllocatedSize (0); - } - else - { - const int newAllocation = data.granularity * (numUsed / data.granularity + 1); - - if (newAllocation < data.numAllocated) - data.setAllocatedSize (newAllocation); - } - + data.shrinkToNoMoreThan (numUsed); lock.exit(); } diff --git a/src/containers/juce_SortedSet.h b/src/containers/juce_SortedSet.h index beb39b762c..e15d6bef9c 100644 --- a/src/containers/juce_SortedSet.h +++ b/src/containers/juce_SortedSet.h @@ -62,15 +62,9 @@ class SortedSet { public: //============================================================================== - /** Creates an empty set. - - @param granularity this is the size of increment by which the internal storage - used by the array will grow. Only change it from the default if you know the - array is going to be very big and needs to be able to grow efficiently. - */ - SortedSet (const int granularity = juceDefaultArrayGranularity) throw() - : data (granularity), - numUsed (0) + /** Creates an empty set. */ + SortedSet() throw() + : numUsed (0) { } @@ -78,7 +72,6 @@ public: @param other the set to copy */ SortedSet (const SortedSet& other) throw() - : data (other.data.granularity) { other.lockSet(); numUsed = other.numUsed; @@ -102,7 +95,6 @@ public: other.lockSet(); lock.enter(); - data.granularity = other.data.granularity; data.ensureAllocatedSize (other.size()); numUsed = other.numUsed; memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); @@ -572,19 +564,7 @@ public: void minimiseStorageOverheads() throw() { lock.enter(); - - if (numUsed == 0) - { - data.setAllocatedSize (0); - } - else - { - const int newAllocation = data.granularity * (numUsed / data.granularity + 1); - - if (newAllocation < data.numAllocated) - data.setAllocatedSize (newAllocation); - } - + data.shrinkToNoMoreThan (numUsed); lock.exit(); } diff --git a/src/containers/juce_Value.cpp b/src/containers/juce_Value.cpp index 9c94a18c7c..2884542c75 100644 --- a/src/containers/juce_Value.cpp +++ b/src/containers/juce_Value.cpp @@ -145,6 +145,11 @@ void Value::setValue (const var& newValue) value->setValue (newValue); } +const String Value::toString() const +{ + return value->getValue().toString(); +} + const Value& Value::operator= (const var& newValue) { value->setValue (newValue); diff --git a/src/containers/juce_Value.h b/src/containers/juce_Value.h index dad4b2cf7e..f96c0d1cbb 100644 --- a/src/containers/juce_Value.h +++ b/src/containers/juce_Value.h @@ -76,6 +76,12 @@ public: /** Returns the current value. */ operator const var() const; + /** Returns the value as a string. + + This is alternative to writing things like "myValue.getValue().toString()". + */ + const String toString() const; + /** Sets the current value. You can also use operator= to set the value. diff --git a/src/core/juce_MathsFunctions.h b/src/core/juce_MathsFunctions.h index 67985e443f..5fdb718ddf 100644 --- a/src/core/juce_MathsFunctions.h +++ b/src/core/juce_MathsFunctions.h @@ -193,7 +193,7 @@ inline void swapVariables (Type& variable1, Type& variable2) variable2 = tempVal; } -/** Handy macro 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. @code @@ -202,7 +202,8 @@ inline void swapVariables (Type& variable1, Type& variable2) int numElements = numElementsInArray (myArray) // returns 3 @endcode */ -#define numElementsInArray(a) ((int) (sizeof (a) / sizeof ((a)[0]))) +template +inline int numElementsInArray (Type& array) { return (int) (sizeof (array) / sizeof (array[0])); } //============================================================================== // Some useful maths functions that aren't always present with all compilers and build settings. diff --git a/src/core/juce_Memory.h b/src/core/juce_Memory.h index edcf4202b9..3229feea1b 100644 --- a/src/core/juce_Memory.h +++ b/src/core/juce_Memory.h @@ -200,15 +200,17 @@ //============================================================================== /** Clears a block of memory. */ -#define zeromem(memory, numBytes) memset (memory, 0, numBytes) +inline void zeromem (void* memory, int numBytes) { memset (memory, 0, numBytes); } /** Clears a reference to a local structure. */ -#define zerostruct(structure) memset (&structure, 0, sizeof (structure)) +template +inline void zerostruct (Type& structure) { memset (&structure, 0, sizeof (structure)); } -/** A handy macro that calls delete on a pointer if it's non-zero, and - then sets the pointer to null. +/** A handy function that calls delete on a pointer if it's non-zero, and then sets + the pointer to null. */ -#define deleteAndZero(pointer) { delete (pointer); (pointer) = 0; } +template +inline void deleteAndZero (Type& pointer) { delete pointer; pointer = 0; } diff --git a/src/core/juce_PlatformDefs.h b/src/core/juce_PlatformDefs.h index 97714b8d1e..4e81904171 100644 --- a/src/core/juce_PlatformDefs.h +++ b/src/core/juce_PlatformDefs.h @@ -203,20 +203,12 @@ forcedinline void myfunction (int x) @endcode */ - #ifdef JUCE_DEBUG + #ifndef JUCE_DEBUG #define forcedinline __forceinline #else #define forcedinline inline #endif - /** A platform-independent way of stopping the compiler inlining a function. - - Use the syntax: @code - juce_noinline void myfunction (int x) - @endcode - */ - #define juce_noinline - #else /** A platform-independent way of forcing an inline function. @@ -230,14 +222,6 @@ #define forcedinline inline #endif - /** A platform-independent way of stopping the compiler inlining a function. - - Use the syntax: @code - juce_noinline void myfunction (int x) - @endcode - */ - #define juce_noinline __attribute__((noinline)) - #endif #endif // __JUCE_PLATFORMDEFS_JUCEHEADER__ diff --git a/src/core/juce_SystemStats.cpp b/src/core/juce_SystemStats.cpp index c187a1ea0a..85b51b91b8 100644 --- a/src/core/juce_SystemStats.cpp +++ b/src/core/juce_SystemStats.cpp @@ -60,6 +60,11 @@ void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI() #ifdef JUCE_DEBUG { + char a1[7]; + jassert (numElementsInArray(a1) == 7); + int a2[3]; + jassert (numElementsInArray(a2) == 3); + // Some simple test code to keep an eye on things and make sure these functions // work ok on all platforms. Let me know if any of these assertions fail! int n = 1; diff --git a/src/core/juce_TargetPlatform.h b/src/core/juce_TargetPlatform.h index c802f66a6e..2294a227d8 100644 --- a/src/core/juce_TargetPlatform.h +++ b/src/core/juce_TargetPlatform.h @@ -70,10 +70,10 @@ #ifdef _DEBUG #define JUCE_DEBUG 1 #endif - - #ifdef __MINGW32__ - #define JUCE_MINGW 1 - #endif + + #ifdef __MINGW32__ + #define JUCE_MINGW 1 + #endif /** If defined, this indicates that the processor is little-endian. */ #define JUCE_LITTLE_ENDIAN 1 diff --git a/src/gui/components/buttons/juce_Button.cpp b/src/gui/components/buttons/juce_Button.cpp index 2ee2d9b276..dac4825b15 100644 --- a/src/gui/components/buttons/juce_Button.cpp +++ b/src/gui/components/buttons/juce_Button.cpp @@ -36,10 +36,8 @@ BEGIN_JUCE_NAMESPACE //============================================================================== Button::Button (const String& name) : Component (name), - shortcuts (2), keySource (0), text (name), - buttonListeners (2), buttonPressTime (0), lastTimeCallbackTime (0), commandManagerToUse (0), diff --git a/src/gui/components/controls/juce_Label.cpp b/src/gui/components/controls/juce_Label.cpp index a4e37777f9..4c827396bd 100644 --- a/src/gui/components/controls/juce_Label.cpp +++ b/src/gui/components/controls/juce_Label.cpp @@ -38,7 +38,6 @@ Label::Label (const String& componentName, text (labelText), font (15.0f), justification (Justification::centredLeft), - listeners (2), ownerComponent (0), horizontalBorderSize (3), verticalBorderSize (1), diff --git a/src/gui/components/controls/juce_Slider.cpp b/src/gui/components/controls/juce_Slider.cpp index 494f028e90..fbfe8f1caa 100644 --- a/src/gui/components/controls/juce_Slider.cpp +++ b/src/gui/components/controls/juce_Slider.cpp @@ -91,7 +91,6 @@ private: //============================================================================== Slider::Slider (const String& name) : Component (name), - listeners (2), lastCurrentValue (0), lastValueMin (0), lastValueMax (0), diff --git a/src/gui/components/controls/juce_TableHeaderComponent.cpp b/src/gui/components/controls/juce_TableHeaderComponent.cpp index 9b45cd1f2a..4271d05b03 100644 --- a/src/gui/components/controls/juce_TableHeaderComponent.cpp +++ b/src/gui/components/controls/juce_TableHeaderComponent.cpp @@ -64,8 +64,7 @@ private: //============================================================================== TableHeaderComponent::TableHeaderComponent() - : listeners (2), - columnsChanged (false), + : columnsChanged (false), columnsResized (false), sortChanged (false), menuActive (true), diff --git a/src/gui/components/controls/juce_TextEditor.cpp b/src/gui/components/controls/juce_TextEditor.cpp index 3611d2103d..1c6c95da6e 100644 --- a/src/gui/components/controls/juce_TextEditor.cpp +++ b/src/gui/components/controls/juce_TextEditor.cpp @@ -79,17 +79,17 @@ public: const Colour& colour_, const tchar passwordCharacter) : font (font_), - colour (colour_), - atoms (64) + colour (colour_) { initialiseAtoms (text, passwordCharacter); } UniformTextSection (const UniformTextSection& other) : font (other.font), - colour (other.colour), - atoms (64) + colour (other.colour) { + atoms.ensureStorageAllocated (other.atoms.size()); + for (int i = 0; i < other.atoms.size(); ++i) atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i))); } @@ -141,6 +141,8 @@ public: } } + atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i); + while (i < other.atoms.size()) { atoms.add (other.getAtom(i)); @@ -990,10 +992,8 @@ TextEditor::TextEditor (const String& name, currentFont (14.0f), totalNumChars (0), caretPosition (0), - sections (8), passwordCharacter (passwordCharacter_), - dragType (notDragging), - listeners (2) + dragType (notDragging) { setOpaque (true); diff --git a/src/gui/components/controls/juce_TreeView.cpp b/src/gui/components/controls/juce_TreeView.cpp index af6a32916a..e02547aea3 100644 --- a/src/gui/components/controls/juce_TreeView.cpp +++ b/src/gui/components/controls/juce_TreeView.cpp @@ -1086,7 +1086,6 @@ enum TreeViewOpenness TreeViewItem::TreeViewItem() : ownerView (0), parentItem (0), - subItems (8), y (0), itemHeight (0), totalHeight (0), diff --git a/src/gui/components/filebrowser/juce_DirectoryContentsDisplayComponent.cpp b/src/gui/components/filebrowser/juce_DirectoryContentsDisplayComponent.cpp index 0a9cec8623..c29af793e7 100644 --- a/src/gui/components/filebrowser/juce_DirectoryContentsDisplayComponent.cpp +++ b/src/gui/components/filebrowser/juce_DirectoryContentsDisplayComponent.cpp @@ -33,8 +33,7 @@ BEGIN_JUCE_NAMESPACE //============================================================================== DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow) - : fileList (listToShow), - listeners (2) + : fileList (listToShow) { } diff --git a/src/gui/components/filebrowser/juce_FileBrowserComponent.cpp b/src/gui/components/filebrowser/juce_FileBrowserComponent.cpp index 715772f9c0..a9fa1c0caa 100644 --- a/src/gui/components/filebrowser/juce_FileBrowserComponent.cpp +++ b/src/gui/components/filebrowser/juce_FileBrowserComponent.cpp @@ -44,7 +44,6 @@ FileBrowserComponent::FileBrowserComponent (int flags_, : FileFilter (String::empty), fileFilter (fileFilter_), flags (flags_), - listeners (2), previewComp (previewComp_), thread ("Juce FileBrowser") { diff --git a/src/gui/components/juce_Component.cpp b/src/gui/components/juce_Component.cpp index 0943bf7224..158f60529f 100644 --- a/src/gui/components/juce_Component.cpp +++ b/src/gui/components/juce_Component.cpp @@ -46,8 +46,8 @@ BEGIN_JUCE_NAMESPACE Component* Component::componentUnderMouse = 0; Component* Component::currentlyFocusedComponent = 0; -static Array modalComponentStack (4), modalComponentReturnValueKeys (4); -static Array modalReturnValues (4); +static Array modalComponentStack, modalComponentReturnValueKeys; +static Array modalReturnValues; static const int customCommandMessage = 0x7fff0001; static const int exitModalStateMessage = 0x7fff0002; @@ -108,7 +108,6 @@ Component::Component() throw() : parentComponent_ (0), componentUID (++nextComponentUID), numDeepMouseListeners (0), - childComponentList_ (16), lookAndFeel_ (0), effect_ (0), bufferedImage_ (0), @@ -125,7 +124,6 @@ Component::Component (const String& name) throw() parentComponent_ (0), componentUID (++nextComponentUID), numDeepMouseListeners (0), - childComponentList_ (16), lookAndFeel_ (0), effect_ (0), bufferedImage_ (0), @@ -2163,7 +2161,7 @@ void Component::parentSizeChanged() void Component::addComponentListener (ComponentListener* const newListener) throw() { if (componentListeners_ == 0) - componentListeners_ = new VoidArray (4); + componentListeners_ = new VoidArray(); componentListeners_->addIfNotAlreadyThere (newListener); } @@ -2243,7 +2241,7 @@ void Component::addMouseListener (MouseListener* const newListener, checkMessageManagerIsLocked if (mouseListeners_ == 0) - mouseListeners_ = new VoidArray (4); + mouseListeners_ = new VoidArray(); if (! mouseListeners_->contains (newListener)) { @@ -3509,7 +3507,7 @@ const Rectangle Component::getParentMonitorArea() const throw() void Component::addKeyListener (KeyListener* const newListener) throw() { if (keyListeners_ == 0) - keyListeners_ = new VoidArray (4); + keyListeners_ = new VoidArray(); keyListeners_->addIfNotAlreadyThere (newListener); } diff --git a/src/gui/components/juce_Desktop.cpp b/src/gui/components/juce_Desktop.cpp index 4251e70a89..f85698b4ff 100644 --- a/src/gui/components/juce_Desktop.cpp +++ b/src/gui/components/juce_Desktop.cpp @@ -40,11 +40,7 @@ extern void juce_updateMultiMonitorInfo (Array & monitorCoords, static Desktop* juce_desktopInstance = 0; Desktop::Desktop() throw() - : mouseListeners (2), - desktopComponents (4), - monitorCoordsClipped (2), - monitorCoordsUnclipped (2), - lastMouseX (0), + : lastMouseX (0), lastMouseY (0), kioskModeComponent (0) { diff --git a/src/gui/components/layout/juce_ComponentMovementWatcher.cpp b/src/gui/components/layout/juce_ComponentMovementWatcher.cpp index a9892dae28..c077cbe2ba 100644 --- a/src/gui/components/layout/juce_ComponentMovementWatcher.cpp +++ b/src/gui/components/layout/juce_ComponentMovementWatcher.cpp @@ -34,7 +34,6 @@ BEGIN_JUCE_NAMESPACE ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_) : component (component_), lastPeer (0), - registeredParentComps (4), reentrant (false) { jassert (component != 0); // can't use this with a null pointer.. diff --git a/src/gui/components/layout/juce_ScrollBar.cpp b/src/gui/components/layout/juce_ScrollBar.cpp index c06fcb64b3..bbd3a0480d 100644 --- a/src/gui/components/layout/juce_ScrollBar.cpp +++ b/src/gui/components/layout/juce_ScrollBar.cpp @@ -98,8 +98,7 @@ ScrollBar::ScrollBar (const bool vertical_, isDraggingThumb (false), alwaysVisible (false), upButton (0), - downButton (0), - listeners (2) + downButton (0) { setButtonVisibility (buttonsAreVisible); diff --git a/src/gui/components/menus/juce_PopupMenu.cpp b/src/gui/components/menus/juce_PopupMenu.cpp index d9b8e8f4d7..f754719a35 100644 --- a/src/gui/components/menus/juce_PopupMenu.cpp +++ b/src/gui/components/menus/juce_PopupMenu.cpp @@ -1281,15 +1281,13 @@ private: //============================================================================== PopupMenu::PopupMenu() - : items (8), - lookAndFeel (0), + : lookAndFeel (0), separatorPending (false) { } PopupMenu::PopupMenu (const PopupMenu& other) - : items (8), - lookAndFeel (other.lookAndFeel), + : lookAndFeel (other.lookAndFeel), separatorPending (false) { items.ensureStorageAllocated (other.items.size()); diff --git a/src/gui/components/mouse/juce_MouseCursor.cpp b/src/gui/components/mouse/juce_MouseCursor.cpp index 897ddf0404..2a66ccb2ea 100644 --- a/src/gui/components/mouse/juce_MouseCursor.cpp +++ b/src/gui/components/mouse/juce_MouseCursor.cpp @@ -40,7 +40,7 @@ void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) th //============================================================================== static CriticalSection activeCursorListLock; -static VoidArray activeCursors (2); +static VoidArray activeCursors; //============================================================================== class SharedMouseCursorInternal : public ReferenceCountedObject diff --git a/src/gui/components/special/juce_AudioDeviceSelectorComponent.cpp b/src/gui/components/special/juce_AudioDeviceSelectorComponent.cpp index b246def589..fdadf3e52c 100644 --- a/src/gui/components/special/juce_AudioDeviceSelectorComponent.cpp +++ b/src/gui/components/special/juce_AudioDeviceSelectorComponent.cpp @@ -674,6 +674,7 @@ private: return y; } +public: //============================================================================== class ChannelSelectorListBox : public ListBox, public ListBoxModel @@ -930,6 +931,7 @@ private: const ChannelSelectorListBox& operator= (const ChannelSelectorListBox&); }; +private: ChannelSelectorListBox* inputChanList; ChannelSelectorListBox* outputChanList; diff --git a/src/gui/components/special/juce_MidiKeyboardComponent.cpp b/src/gui/components/special/juce_MidiKeyboardComponent.cpp index 0c2bba990f..2c94aec0d7 100644 --- a/src/gui/components/special/juce_MidiKeyboardComponent.cpp +++ b/src/gui/components/special/juce_MidiKeyboardComponent.cpp @@ -95,8 +95,6 @@ MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_, canScroll (true), mouseDragging (false), useMousePositionForVelocity (true), - keyPresses (4), - keyPressNotes (16), keyMappingOctave (6), octaveNumForMiddleC (3) { diff --git a/src/gui/components/windows/juce_ComponentPeer.cpp b/src/gui/components/windows/juce_ComponentPeer.cpp index efbc22e0c1..77589a7435 100644 --- a/src/gui/components/windows/juce_ComponentPeer.cpp +++ b/src/gui/components/windows/juce_ComponentPeer.cpp @@ -53,7 +53,7 @@ extern bool juce_MouseHasMovedSignificantlySincePressed; static const int fakeMouseMoveMessage = 0x7fff00ff; -static VoidArray heavyweightPeers (4); +static VoidArray heavyweightPeers; //============================================================================== diff --git a/src/gui/components/windows/juce_TopLevelWindow.cpp b/src/gui/components/windows/juce_TopLevelWindow.cpp index 7e1b66a90c..2720c94004 100644 --- a/src/gui/components/windows/juce_TopLevelWindow.cpp +++ b/src/gui/components/windows/juce_TopLevelWindow.cpp @@ -45,8 +45,7 @@ class TopLevelWindowManager : public Timer, public: //============================================================================== TopLevelWindowManager() - : windows (8), - currentActive (0) + : currentActive (0) { } diff --git a/src/gui/graphics/colour/juce_ColourGradient.cpp b/src/gui/graphics/colour/juce_ColourGradient.cpp index eebf6881df..0f081b4dd1 100644 --- a/src/gui/graphics/colour/juce_ColourGradient.cpp +++ b/src/gui/graphics/colour/juce_ColourGradient.cpp @@ -32,7 +32,6 @@ BEGIN_JUCE_NAMESPACE //============================================================================== ColourGradient::ColourGradient() throw() - : colours (4) { #ifdef JUCE_DEBUG x1 = 987654.0f; @@ -50,8 +49,7 @@ ColourGradient::ColourGradient (const Colour& colour1, y1 (y1_), x2 (x2_), y2 (y2_), - isRadial (isRadial_), - colours (4) + isRadial (isRadial_) { colours.add (0); colours.add (colour1.getARGB()); diff --git a/src/gui/graphics/contexts/juce_Graphics.cpp b/src/gui/graphics/contexts/juce_Graphics.cpp index fb162b2795..418cddf4db 100644 --- a/src/gui/graphics/contexts/juce_Graphics.cpp +++ b/src/gui/graphics/contexts/juce_Graphics.cpp @@ -35,20 +35,16 @@ BEGIN_JUCE_NAMESPACE static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality; //============================================================================== -#define MINIMUM_COORD -0x3fffffff -#define MAXIMUM_COORD 0x3fffffff - -#undef ASSERT_COORDS_ARE_SENSIBLE_NUMBERS -#define ASSERT_COORDS_ARE_SENSIBLE_NUMBERS(x, y, w, h) \ - jassert ((int) x >= MINIMUM_COORD \ - && (int) x <= MAXIMUM_COORD \ - && (int) y >= MINIMUM_COORD \ - && (int) y <= MAXIMUM_COORD \ - && (int) w >= MINIMUM_COORD \ - && (int) w <= MAXIMUM_COORD \ - && (int) h >= MINIMUM_COORD \ - && (int) h <= MAXIMUM_COORD); +template +static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h) +{ + const int maxVal = 0x3fffffff; + return (int) x >= -maxVal && (int) x <= maxVal + && (int) y >= -maxVal && (int) y <= maxVal + && (int) w >= -maxVal && (int) w <= maxVal + && (int) h >= -maxVal && (int) h <= maxVal; +} //============================================================================== LowLevelGraphicsContext::LowLevelGraphicsContext() @@ -62,7 +58,7 @@ LowLevelGraphicsContext::~LowLevelGraphicsContext() //============================================================================== Graphics::Graphics (Image& imageToDrawOnto) throw() : context (imageToDrawOnto.createLowLevelContext()), - ownsContext (true), + contextToDelete (context), saveStatePending (false) { resetToDefaultState(); @@ -70,7 +66,6 @@ Graphics::Graphics (Image& imageToDrawOnto) throw() Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw() : context (internalContext), - ownsContext (false), saveStatePending (false) { resetToDefaultState(); @@ -78,8 +73,6 @@ Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw() Graphics::~Graphics() throw() { - if (ownsContext) - delete context; } //============================================================================== @@ -325,7 +318,7 @@ void Graphics::fillRect (int x, int height) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (x, y, width, height); + jassert (areCoordsSensibleNumbers (x, y, width, height)); context->fillRect (Rectangle (x, y, width, height), false); } @@ -341,7 +334,7 @@ void Graphics::fillRect (const float x, const float height) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (x, y, width, height); + jassert (areCoordsSensibleNumbers (x, y, width, height)); Path p; p.addRectangle (x, y, width, height); @@ -397,7 +390,7 @@ void Graphics::drawRect (const int x, const int lineThickness) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (x, y, width, height); + jassert (areCoordsSensibleNumbers (x, y, width, height)); context->fillRect (Rectangle (x, y, width, lineThickness), false); context->fillRect (Rectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2), false); @@ -412,7 +405,7 @@ void Graphics::drawRect (const float x, const float lineThickness) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (x, y, width, height); + jassert (areCoordsSensibleNumbers (x, y, width, height)); Path p; p.addRectangle (x, y, width, lineThickness); @@ -441,7 +434,7 @@ void Graphics::drawBevel (const int x, const bool sharpEdgeOnOutside) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (x, y, width, height); + jassert (areCoordsSensibleNumbers (x, y, width, height)); if (clipRegionIntersects (x, y, width, height)) { @@ -476,7 +469,7 @@ void Graphics::fillEllipse (const float x, const float height) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (x, y, width, height); + jassert (areCoordsSensibleNumbers (x, y, width, height)); Path p; p.addEllipse (x, y, width, height); @@ -490,7 +483,7 @@ void Graphics::drawEllipse (const float x, const float lineThickness) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (x, y, width, height); + jassert (areCoordsSensibleNumbers (x, y, width, height)); Path p; p.addEllipse (x, y, width, height); @@ -504,7 +497,7 @@ void Graphics::fillRoundedRectangle (const float x, const float cornerSize) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (x, y, width, height); + jassert (areCoordsSensibleNumbers (x, y, width, height)); Path p; p.addRoundedRectangle (x, y, width, height, cornerSize); @@ -529,7 +522,7 @@ void Graphics::drawRoundedRectangle (const float x, const float lineThickness) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (x, y, width, height); + jassert (areCoordsSensibleNumbers (x, y, width, height)); Path p; p.addRoundedRectangle (x, y, width, height, cornerSize); @@ -723,7 +716,7 @@ void Graphics::drawImageWithin (const Image* const imageToDraw, const bool fillAlphaChannelWithCurrentBrush) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (destX, destY, destW, destH); + jassert (areCoordsSensibleNumbers (destX, destY, destW, destH)); if (imageToDraw != 0) { @@ -757,8 +750,8 @@ void Graphics::drawImage (const Image* const imageToDraw, const bool fillAlphaChannelWithCurrentBrush) const throw() { // passing in a silly number can cause maths problems in rendering! - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (dx, dy, dw, dh); - ASSERT_COORDS_ARE_SENSIBLE_NUMBERS (sx, sy, sw, sh); + jassert (areCoordsSensibleNumbers (dx, dy, dw, dh)); + jassert (areCoordsSensibleNumbers (sx, sy, sw, sh)); if (context->clipRegionIntersects (Rectangle (dx, dy, dw, dh))) { diff --git a/src/gui/graphics/contexts/juce_Graphics.h b/src/gui/graphics/contexts/juce_Graphics.h index c2736f965a..7fc311aa82 100644 --- a/src/gui/graphics/contexts/juce_Graphics.h +++ b/src/gui/graphics/contexts/juce_Graphics.h @@ -717,7 +717,7 @@ public: private: //============================================================================== LowLevelGraphicsContext* const context; - const bool ownsContext; + ScopedPointer contextToDelete; bool saveStatePending; void saveStateIfPending() throw(); diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp index b1699410b6..d3783a8485 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp @@ -443,10 +443,9 @@ void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im, pixel = Colours::transparentWhite; } - char colourString [16]; - sprintf (colourString, "%x%x%x", pixel.getRed(), pixel.getGreen(), pixel.getBlue()); + const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() }; - out << (const char*) colourString; + out << String::toHexString (pixelValues, 3, 0); charsOnLine += 3; if (charsOnLine > 100) diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp index ecd6f6a530..51134e4ecc 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp @@ -1341,10 +1341,10 @@ private: //============================================================================== LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_) - : image (image_), - stateStack (20) + : image (image_) { - currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(), FillType(), Graphics::mediumResamplingQuality); + currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(), + FillType(), Graphics::mediumResamplingQuality); } LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer() diff --git a/src/gui/graphics/fonts/juce_Font.cpp b/src/gui/graphics/fonts/juce_Font.cpp index 08cbaba1f3..9c943b9537 100644 --- a/src/gui/graphics/fonts/juce_Font.cpp +++ b/src/gui/graphics/fonts/juce_Font.cpp @@ -341,8 +341,7 @@ class TypefaceCache : public DeletedAtShutdown { public: TypefaceCache (int numToCache = 10) throw() - : counter (1), - faces (2) + : counter (1) { while (--numToCache >= 0) faces.add (new CachedFace()); diff --git a/src/gui/graphics/fonts/juce_GlyphArrangement.cpp b/src/gui/graphics/fonts/juce_GlyphArrangement.cpp index 48b59e789e..50cd67390d 100644 --- a/src/gui/graphics/fonts/juce_GlyphArrangement.cpp +++ b/src/gui/graphics/fonts/juce_GlyphArrangement.cpp @@ -109,8 +109,8 @@ void PositionedGlyph::moveBy (const float deltaX, //============================================================================== GlyphArrangement::GlyphArrangement() - : glyphs (128) { + glyphs.ensureStorageAllocated (128); } GlyphArrangement::GlyphArrangement (const GlyphArrangement& other) diff --git a/src/gui/graphics/fonts/juce_TextLayout.cpp b/src/gui/graphics/fonts/juce_TextLayout.cpp index 0c09450250..0370503b46 100644 --- a/src/gui/graphics/fonts/juce_TextLayout.cpp +++ b/src/gui/graphics/fonts/juce_TextLayout.cpp @@ -93,22 +93,21 @@ public: //============================================================================== TextLayout::TextLayout() throw() - : tokens (64), - totalLines (0) + : totalLines (0) { + tokens.ensureStorageAllocated (64); } TextLayout::TextLayout (const String& text, const Font& font) throw() - : tokens (64), - totalLines (0) + : totalLines (0) { + tokens.ensureStorageAllocated (64); appendText (text, font); } TextLayout::TextLayout (const TextLayout& other) throw() - : tokens (64), - totalLines (0) + : totalLines (0) { *this = other; } diff --git a/src/gui/graphics/geometry/juce_Path.cpp b/src/gui/graphics/geometry/juce_Path.cpp index ead5c53ea3..fe4e360350 100644 --- a/src/gui/graphics/geometry/juce_Path.cpp +++ b/src/gui/graphics/geometry/juce_Path.cpp @@ -49,8 +49,7 @@ static const int defaultGranularity = 32; //============================================================================== Path::Path() throw() - : data (defaultGranularity), - numElements (0), + : numElements (0), pathXMin (0), pathXMax (0), pathYMin (0), @@ -64,8 +63,7 @@ Path::~Path() throw() } Path::Path (const Path& other) throw() - : data (defaultGranularity), - numElements (other.numElements), + : numElements (other.numElements), pathXMin (other.pathXMin), pathXMax (other.pathXMax), pathYMin (other.pathYMin), diff --git a/src/gui/graphics/imaging/image_file_formats/juce_JPEGLoader.cpp b/src/gui/graphics/imaging/image_file_formats/juce_JPEGLoader.cpp index 4b53c28cae..29b5ab81f7 100644 --- a/src/gui/graphics/imaging/image_file_formats/juce_JPEGLoader.cpp +++ b/src/gui/graphics/imaging/image_file_formats/juce_JPEGLoader.cpp @@ -32,9 +32,9 @@ namespace jpeglibNamespace { #if JUCE_INCLUDE_JPEGLIB_CODE - #if JUCE_MINGW - typedef unsigned char boolean; - #endif + #if JUCE_MINGW + typedef unsigned char boolean; + #endif extern "C" { #define JPEG_INTERNALS diff --git a/src/gui/graphics/imaging/juce_ImageCache.cpp b/src/gui/graphics/imaging/juce_ImageCache.cpp index d45836a792..76dabf47e5 100644 --- a/src/gui/graphics/imaging/juce_ImageCache.cpp +++ b/src/gui/graphics/imaging/juce_ImageCache.cpp @@ -49,7 +49,6 @@ static int cacheTimeout = 5000; ImageCache::ImageCache() - : images (4) { } diff --git a/src/io/files/juce_File.cpp b/src/io/files/juce_File.cpp index 07aa002b22..9df4cd4fb3 100644 --- a/src/io/files/juce_File.cpp +++ b/src/io/files/juce_File.cpp @@ -985,17 +985,6 @@ bool File::appendText (const String& text, return false; } -bool File::printf (const tchar* pf, ...) const -{ - va_list list; - va_start (list, pf); - - String text; - text.vprintf (pf, list); - - return appendData ((const char*) text, text.length()); -} - bool File::replaceWithText (const String& textToWrite, const bool asUnicode, const bool writeUnicodeHeaderBytes) const diff --git a/src/io/files/juce_File.h b/src/io/files/juce_File.h index d99feb18dc..f380ca7a95 100644 --- a/src/io/files/juce_File.h +++ b/src/io/files/juce_File.h @@ -575,7 +575,7 @@ public: @returns a stream that will write to this file (initially positioned at the end of the file), or 0 if the file can't be opened for some reason - @see createInputStream, printf, appendData, appendText + @see createInputStream, appendData, appendText */ FileOutputStream* createOutputStream (const int bufferSize = 0x8000) const; @@ -602,14 +602,6 @@ public: const String loadFileAsString() const; //============================================================================== - /** Writes text to the end of the file. - - This will try to do a printf to the file. - - @returns false if it can't write to the file for some reason - */ - bool printf (const tchar* format, ...) const; - /** Appends a block of binary data to the end of the file. This will try to write the given buffer to the end of the file. diff --git a/src/native/common/juce_posix_SharedCode.h b/src/native/common/juce_posix_SharedCode.h index f325a6cdc8..371db4b08c 100644 --- a/src/native/common/juce_posix_SharedCode.h +++ b/src/native/common/juce_posix_SharedCode.h @@ -416,12 +416,6 @@ const String juce_getOutputFromCommand (const String& command) } //============================================================================== -#if JUCE_64BIT - #define filedesc ((long long) internal) -#else - #define filedesc ((int) internal) -#endif - InterProcessLock::InterProcessLock (const String& name_) : internal (0), name (name_), @@ -436,7 +430,7 @@ InterProcessLock::InterProcessLock (const String& name_) temp.create(); - internal = (void*) open (temp.getFullPathName().toUTF8(), O_RDWR); + internal = open (temp.getFullPathName().toUTF8(), O_RDWR); } InterProcessLock::~InterProcessLock() @@ -444,7 +438,7 @@ InterProcessLock::~InterProcessLock() while (reentrancyLevel > 0) this->exit(); - close (filedesc); + close (internal); } bool InterProcessLock::enter (const int timeOutMillisecs) @@ -464,7 +458,7 @@ bool InterProcessLock::enter (const int timeOutMillisecs) for (;;) { - const int result = fcntl (filedesc, F_SETLK, &fl); + const int result = fcntl (internal, F_SETLK, &fl); if (result >= 0) { @@ -498,7 +492,7 @@ void InterProcessLock::exit() for (;;) { - const int result = fcntl (filedesc, F_SETLKW, &fl); + const int result = fcntl (internal, F_SETLKW, &fl); if (result >= 0 || errno != EINTR) break; diff --git a/src/native/mac/juce_iphone_Audio.cpp b/src/native/mac/juce_iphone_Audio.cpp index c8c010fd82..2c9d578f5e 100644 --- a/src/native/mac/juce_iphone_Audio.cpp +++ b/src/native/mac/juce_iphone_Audio.cpp @@ -504,7 +504,7 @@ private: { NSString* route = (NSString*) audioRoute; - //printf ("audio route: %s\n", [route cString]); + //DBG ("audio route: " + nsStringToJuce (route)); if ([route hasPrefix: @"Receiver"]) { diff --git a/src/native/mac/juce_mac_Files.mm b/src/native/mac/juce_mac_Files.mm index 925ae45674..3e3b4cb9f6 100644 --- a/src/native/mac/juce_mac_Files.mm +++ b/src/native/mac/juce_mac_Files.mm @@ -406,7 +406,7 @@ void* juce_findFileStart (const String& directory, const String& wildCard, Strin if (e != 0) { - FindFileStruct* ff = new FindFileStruct(); + ScopedPointer ff (new FindFileStruct()); ff->enumerator = [e retain]; ff->parentDir = directory; ff->wildCard = wildCard; @@ -415,10 +415,9 @@ void* juce_findFileStart (const String& directory, const String& wildCard, Strin ff->parentDir += File::separator; if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly)) - return ff; + return ff.release(); [e release]; - delete ff; } return 0; @@ -426,9 +425,8 @@ void* juce_findFileStart (const String& directory, const String& wildCard, Strin void juce_findFileClose (void* handle) { - FindFileStruct* ff = (FindFileStruct*) handle; + ScopedPointer ff ((FindFileStruct*) handle); [ff->enumerator release]; - delete ff; } //============================================================================== diff --git a/src/native/mac/juce_mac_OpenGLComponent.mm b/src/native/mac/juce_mac_OpenGLComponent.mm index 8e979b1fec..4c0c799328 100644 --- a/src/native/mac/juce_mac_OpenGLComponent.mm +++ b/src/native/mac/juce_mac_OpenGLComponent.mm @@ -178,7 +178,7 @@ public: { makeInactive(); [renderContext clearDrawable]; - delete viewHolder; + viewHolder = 0; } bool makeActive() const throw() @@ -250,7 +250,7 @@ public: private: OpenGLPixelFormat pixelFormat; - NSViewComponentInternal* viewHolder; + ScopedPointer viewHolder; //============================================================================== WindowedGLContext (const WindowedGLContext&); diff --git a/src/native/windows/juce_win32_ASIO.cpp b/src/native/windows/juce_win32_ASIO.cpp index 6c5c322883..54c3ffdcb4 100644 --- a/src/native/windows/juce_win32_ASIO.cpp +++ b/src/native/windows/juce_win32_ASIO.cpp @@ -1723,7 +1723,6 @@ class ASIOAudioIODeviceType : public AudioIODeviceType public: ASIOAudioIODeviceType() : AudioIODeviceType (T("ASIO")), - classIds (2), hasScanned (false) { CoInitialize (0); diff --git a/src/native/windows/juce_win32_ActiveXComponent.cpp b/src/native/windows/juce_win32_ActiveXComponent.cpp index 0e313cbe39..f5b450397f 100644 --- a/src/native/windows/juce_win32_ActiveXComponent.cpp +++ b/src/native/windows/juce_win32_ActiveXComponent.cpp @@ -171,7 +171,7 @@ public: HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo) { - frame->AddRef(); + // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak.. *lplpFrame = frame; *lplpDoc = 0; lpFrameInfo->fMDIApp = FALSE; diff --git a/src/native/windows/juce_win32_DirectSound.cpp b/src/native/windows/juce_win32_DirectSound.cpp index 0e4a430062..a3b153174c 100644 --- a/src/native/windows/juce_win32_DirectSound.cpp +++ b/src/native/windows/juce_win32_DirectSound.cpp @@ -960,8 +960,6 @@ public: isStarted (false), outputDeviceIndex (outputDeviceIndex_), inputDeviceIndex (inputDeviceIndex_), - inChans (4), - outChans (4), numInputBuffers (0), numOutputBuffers (0), totalSamplesOut (0), diff --git a/src/native/windows/juce_win32_Messaging.cpp b/src/native/windows/juce_win32_Messaging.cpp index 8af316e2ca..04044cf39d 100644 --- a/src/native/windows/juce_win32_Messaging.cpp +++ b/src/native/windows/juce_win32_Messaging.cpp @@ -32,16 +32,16 @@ static const unsigned int specialId = WM_APP + 0x4400; static const unsigned int broadcastId = WM_APP + 0x4403; static const unsigned int specialCallbackId = WM_APP + 0x4402; - + static const TCHAR* const messageWindowName = _T("JUCEWindow"); HWND juce_messageWindowHandle = 0; extern long improbableWindowNumber; // defined in windowing.cpp - -#ifndef WM_APPCOMMAND - #define WM_APPCOMMAND 0x0319 -#endif + +#ifndef WM_APPCOMMAND + #define WM_APPCOMMAND 0x0319 +#endif //============================================================================== diff --git a/src/native/windows/juce_win32_Midi.cpp b/src/native/windows/juce_win32_Midi.cpp index 6eb4084bd4..52ab8b455f 100644 --- a/src/native/windows/juce_win32_Midi.cpp +++ b/src/native/windows/juce_win32_Midi.cpp @@ -415,7 +415,7 @@ struct MidiOutHandle juce_UseDebuggingNewOperator }; -static VoidArray handles (4); +static Array midiOutputHandles; //============================================================================== const StringArray MidiOutput::getDevices() @@ -485,9 +485,9 @@ MidiOutput* MidiOutput::openDevice (int index) } } - for (i = handles.size(); --i >= 0;) + for (i = midiOutputHandles.size(); --i >= 0;) { - MidiOutHandle* const han = (MidiOutHandle*) handles.getUnchecked(i); + MidiOutHandle* const han = midiOutputHandles.getUnchecked(i); if (han != 0 && han->deviceId == deviceId) { @@ -510,7 +510,7 @@ MidiOutput* MidiOutput::openDevice (int index) han->deviceId = deviceId; han->refCount = 1; han->handle = h; - handles.add (han); + midiOutputHandles.add (han); MidiOutput* const out = new MidiOutput(); out->internal = (void*) han; @@ -533,10 +533,10 @@ MidiOutput::~MidiOutput() { MidiOutHandle* const h = (MidiOutHandle*) internal; - if (handles.contains ((void*) h) && --(h->refCount) == 0) + if (midiOutputHandles.contains (h) && --(h->refCount) == 0) { midiOutClose (h->handle); - handles.removeValue ((void*) h); + midiOutputHandles.removeValue (h); delete h; } } diff --git a/src/native/windows/juce_win32_PlatformUtils.cpp b/src/native/windows/juce_win32_PlatformUtils.cpp index fa0021f9b5..3765a19576 100644 --- a/src/native/windows/juce_win32_PlatformUtils.cpp +++ b/src/native/windows/juce_win32_PlatformUtils.cpp @@ -72,7 +72,7 @@ static HKEY findKeyForPath (String name, const String PlatformUtilities::getRegistryValue (const String& regValuePath, const String& defaultValue) { - String valueName, s; + String valueName, result (defaultValue); HKEY k = findKeyForPath (regValuePath, false, valueName); if (k != 0) @@ -82,14 +82,17 @@ const String PlatformUtilities::getRegistryValue (const String& regValuePath, DWORD type = REG_SZ; if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS) - s = buffer; - else - s = defaultValue; + { + if (type == REG_SZ) + result = buffer; + else if (type == REG_DWORD) + result = String ((int) *(DWORD*) buffer); + } RegCloseKey (k); } - return s; + return result; } void PlatformUtilities::setRegistryValue (const String& regValuePath, diff --git a/src/text/juce_XmlElement.cpp b/src/text/juce_XmlElement.cpp index 65c90012fa..d44f53ec10 100644 --- a/src/text/juce_XmlElement.cpp +++ b/src/text/juce_XmlElement.cpp @@ -715,10 +715,7 @@ void XmlElement::setAttribute (const tchar* const attributeName, void XmlElement::setAttribute (const tchar* const attributeName, const double number) throw() { - tchar buffer [40]; - CharacterFunctions::printf (buffer, numElementsInArray (buffer), T("%.9g"), number); - - setAttribute (attributeName, buffer); + setAttribute (attributeName, String (number)); } void XmlElement::removeAttribute (const tchar* const attributeName) throw() diff --git a/src/threads/juce_InterProcessLock.h b/src/threads/juce_InterProcessLock.h index 4a68e00644..c014d8c332 100644 --- a/src/threads/juce_InterProcessLock.h +++ b/src/threads/juce_InterProcessLock.h @@ -73,7 +73,14 @@ public: private: //============================================================================== + #if JUCE_WINDOWS void* internal; + #elif JUCE_64BIT + long long internal; + #else + int internal; + #endif + String name; int reentrancyLevel; diff --git a/src/threads/juce_Thread.cpp b/src/threads/juce_Thread.cpp index 80a48cacfe..a6fe0029c8 100644 --- a/src/threads/juce_Thread.cpp +++ b/src/threads/juce_Thread.cpp @@ -43,7 +43,7 @@ void juce_CloseThreadHandle (void* handle); #endif //============================================================================== -static VoidArray runningThreads (4); +static VoidArray runningThreads; static CriticalSection runningThreadsLock; //============================================================================== diff --git a/src/utilities/juce_DeletedAtShutdown.cpp b/src/utilities/juce_DeletedAtShutdown.cpp index 32b78a8e46..609bead8f2 100644 --- a/src/utilities/juce_DeletedAtShutdown.cpp +++ b/src/utilities/juce_DeletedAtShutdown.cpp @@ -34,7 +34,7 @@ BEGIN_JUCE_NAMESPACE //============================================================================== -static VoidArray objectsToDelete (16); +static VoidArray objectsToDelete; static CriticalSection lock; //==============================================================================