diff --git a/extras/audio plugins/demo/build/AudioUnit/JuceDemoAU.xcodeproj/project.pbxproj b/extras/audio plugins/demo/build/AudioUnit/JuceDemoAU.xcodeproj/project.pbxproj index 53b8035934..7cd1d6a2d4 100644 --- a/extras/audio plugins/demo/build/AudioUnit/JuceDemoAU.xcodeproj/project.pbxproj +++ b/extras/audio plugins/demo/build/AudioUnit/JuceDemoAU.xcodeproj/project.pbxproj @@ -80,7 +80,7 @@ 84CFB0240909684B0053C22C /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; - dstPath = "/Users/jules/Library/Audio/Plug-Ins/Components"; + dstPath = "~/Library/Audio/Plug-Ins/Components"; dstSubfolderSpec = 0; files = ( 84CFB029090968590053C22C /* DemoJuceAudioUnit.component in CopyFiles */, diff --git a/src/juce_appframework/gui/components/buttons/juce_Button.cpp b/src/juce_appframework/gui/components/buttons/juce_Button.cpp index 67d3f98ed1..3700c4a9f7 100644 --- a/src/juce_appframework/gui/components/buttons/juce_Button.cpp +++ b/src/juce_appframework/gui/components/buttons/juce_Button.cpp @@ -230,7 +230,7 @@ Button::ButtonState Button::updateState (const MouseEvent* const e) throw() const bool over = reallyContains (mx, my, true); const bool down = isMouseButtonDownAnywhere(); - if ((down && (over || triggerOnMouseDown)) || isKeyDown) + if ((down && (over || (triggerOnMouseDown && state == buttonDown))) || isKeyDown) state = buttonDown; else if (over) state = buttonOver; diff --git a/src/juce_core/containers/juce_Array.h b/src/juce_core/containers/juce_Array.h index 725450ff88..cccccf826e 100644 --- a/src/juce_core/containers/juce_Array.h +++ b/src/juce_core/containers/juce_Array.h @@ -46,6 +46,10 @@ Note that when holding pointers to objects, the array doesn't take any ownership of the objects - for doing this, see the OwnedArray class or the ReferenceCountedArray class. + If you're using a class or struct as the element type, it must be + capable of being copied or moved with a straightforward memcpy, rather than + needing construction and destruction code. + For holding lists of strings, use the specialised class StringArray. To make all the array's methods thread-safe, pass in "CriticalSection" as the templated @@ -672,7 +676,7 @@ public: @param comparator the comparator to use to compare the elements - see the sort() method for details about the form this object should take - @param elementToLookFor the new element to insert to the array + @param elementToLookFor the element to search for @returns the index of the element, or -1 if it's not found @see addSorted, sort */ diff --git a/src/juce_core/containers/juce_ElementComparator.h b/src/juce_core/containers/juce_ElementComparator.h index 38d4e0ab33..ec35a0363d 100644 --- a/src/juce_core/containers/juce_ElementComparator.h +++ b/src/juce_core/containers/juce_ElementComparator.h @@ -183,6 +183,8 @@ static void sortArray (ElementComparator& comparator, if (--stackIndex < 0) break; + jassert (stackIndex < numElementsInArray (fromStack)); + firstElement = fromStack [stackIndex]; lastElement = toStack [stackIndex]; } diff --git a/src/juce_core/containers/juce_OwnedArray.h b/src/juce_core/containers/juce_OwnedArray.h index 69822978e8..1e74defcb1 100644 --- a/src/juce_core/containers/juce_OwnedArray.h +++ b/src/juce_core/containers/juce_OwnedArray.h @@ -380,7 +380,7 @@ public: @param comparator the comparator to use to compare the elements - see the sort method for details about this object's structure @param newObject the new object to insert to the array - @see add, sort + @see add, sort, indexOfSorted */ template void addSorted (ElementComparator& comparator, @@ -393,6 +393,58 @@ public: lock.exit(); } + /** Finds the index of an object in the array, assuming that the array is sorted. + + This will use a comparator to do a binary-chop to find the index of the given + element, if it exists. If the array isn't sorted, the behaviour of this + method will be unpredictable. + + @param comparator the comparator to use to compare the elements - see the sort() + method for details about the form this object should take + @param objectToLookFor the object to search for + @returns the index of the element, or -1 if it's not found + @see addSorted, sort + */ + template + int indexOfSorted (ElementComparator& comparator, + const ObjectClass* const objectToLookFor) const throw() + { + (void) comparator; // if you pass in an object with a static compareElements() method, this + // avoids getting warning messages about the parameter being unused + lock.enter(); + + int start = 0; + int end = numUsed; + + for (;;) + { + if (start >= end) + { + lock.exit(); + return -1; + } + else if (comparator.compareElements (objectToLookFor, this->elements [start]) == 0) + { + lock.exit(); + return start; + } + else + { + const int halfway = (start + end) >> 1; + + if (halfway == start) + { + lock.exit(); + return -1; + } + else if (comparator.compareElements (objectToLookFor, this->elements [halfway]) >= 0) + start = halfway; + else + end = halfway; + } + } + } + //============================================================================== /** Removes an object from the array. @@ -679,7 +731,7 @@ public: be important in some cases. If it's false, a faster algorithm is used, but equivalent elements may be rearranged. - @see sortArray + @see sortArray, indexOfSorted */ template void sort (ElementComparator& comparator, diff --git a/src/juce_core/containers/juce_SortedSet.h b/src/juce_core/containers/juce_SortedSet.h index dd77b050ae..ccc6c2211a 100644 --- a/src/juce_core/containers/juce_SortedSet.h +++ b/src/juce_core/containers/juce_SortedSet.h @@ -54,6 +54,10 @@ to determine the order), and searching the set for known values is very fast because it uses a binary-chop method. + Note that if you're using a class or struct as the element type, it must be + capable of being copied or moved with a straightforward memcpy, rather than + needing construction and destruction code. + To make all the set's methods thread-safe, pass in "CriticalSection" as the templated TypeOfCriticalSectionToUse parameter, instead of the default DummyCriticalSection.