diff --git a/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp index 47db879ec9..6843aeb43a 100644 --- a/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp @@ -140,7 +140,7 @@ public: if (wmCreateSyncReader != nullptr) { - CoInitialize (0); + checkCoInitialiseCalled(); HRESULT hr = wmCreateSyncReader (nullptr, WMT_RIGHT_PLAYBACK, wmSyncReader.resetAndGetPointerAddress()); @@ -173,6 +173,8 @@ public: if (sampleRate <= 0) return false; + checkCoInitialiseCalled(); + if (startSampleInFile != currentPosition) { currentPosition = startSampleInFile; @@ -252,6 +254,15 @@ private: MemoryBlock buffer; int bufferStart, bufferEnd; + void checkCoInitialiseCalled() + { + APTTYPE dummy1; + APTTYPEQUALIFIER dummy2; + + if (CoGetApartmentType (&dummy1, &dummy2) == CO_E_NOTINITIALIZED) + CoInitialize (0); + } + void scanFileForDetails() { ComSmartPtr wmHeaderInfo; diff --git a/modules/juce_core/containers/juce_OwnedArray.h b/modules/juce_core/containers/juce_OwnedArray.h index b5a0345d5c..e45bc7de31 100644 --- a/modules/juce_core/containers/juce_OwnedArray.h +++ b/modules/juce_core/containers/juce_OwnedArray.h @@ -475,35 +475,26 @@ public: int indexOfSorted (ElementComparator& comparator, const ObjectClass* const objectToLookFor) const noexcept { - (void) comparator; // if you pass in an object with a static compareElements() method, this - // avoids getting warning messages about the parameter being unused + (void) comparator; const ScopedLockType lock (getLock()); + int s = 0, e = numUsed; - int start = 0; - int end_ = numUsed; - - for (;;) + while (s < e) { - if (start >= end_) - { - return -1; - } - else if (comparator.compareElements (objectToLookFor, data.elements [start]) == 0) - { - return start; - } - else - { - const int halfway = (start + end_) >> 1; + if (comparator.compareElements (objectToLookFor, data.elements [s]) == 0) + return s; - if (halfway == start) - return -1; - else if (comparator.compareElements (objectToLookFor, data.elements [halfway]) >= 0) - start = halfway; - else - end_ = halfway; - } + const int halfway = (s + e) / 2; + if (halfway == s) + break; + + if (comparator.compareElements (objectToLookFor, data.elements [halfway]) >= 0) + s = halfway; + else + e = halfway; } + + return -1; } //============================================================================== diff --git a/modules/juce_core/containers/juce_ReferenceCountedArray.h b/modules/juce_core/containers/juce_ReferenceCountedArray.h index 95ace6643f..80e04cd463 100644 --- a/modules/juce_core/containers/juce_ReferenceCountedArray.h +++ b/modules/juce_core/containers/juce_ReferenceCountedArray.h @@ -471,6 +471,44 @@ public: insert (index, newObject); // no match, so insert the new one } + /** 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 noexcept + { + (void) comparator; + const ScopedLockType lock (getLock()); + int s = 0, e = numUsed; + + while (s < e) + { + if (comparator.compareElements (objectToLookFor, data.elements [s]) == 0) + return s; + + const int halfway = (s + e) / 2; + if (halfway == s) + break; + + if (comparator.compareElements (objectToLookFor, data.elements [halfway]) >= 0) + s = halfway; + else + e = halfway; + } + + return -1; + } + //============================================================================== /** Removes an object from the array. diff --git a/modules/juce_gui_basics/application/juce_Application.h b/modules/juce_gui_basics/application/juce_Application.h index e9ba4641e8..26165848ed 100644 --- a/modules/juce_gui_basics/application/juce_Application.h +++ b/modules/juce_gui_basics/application/juce_Application.h @@ -209,24 +209,24 @@ public: /** Returns true if this executable is running as an app (as opposed to being a plugin or other kind of shared library. */ - static inline bool isStandaloneApp() noexcept { return createInstance != 0; } + static inline bool isStandaloneApp() noexcept { return createInstance != nullptr; } //============================================================================== /** @internal */ ApplicationCommandTarget* getNextCommandTarget(); /** @internal */ - void getCommandInfo (CommandID commandID, ApplicationCommandInfo& result); + void getCommandInfo (CommandID, ApplicationCommandInfo&); /** @internal */ - void getAllCommands (Array & commands); + void getAllCommands (Array &); /** @internal */ - bool perform (const InvocationInfo& info); + bool perform (const InvocationInfo&); //============================================================================== #ifndef DOXYGEN // The following methods are internal calls - not for public use. static int main (const String& commandLine); static int main (int argc, const char* argv[]); - static void sendUnhandledException (const std::exception* e, const char* sourceFile, int lineNumber); + static void sendUnhandledException (const std::exception*, const char* sourceFile, int lineNumber); bool initialiseApp (const String& commandLine); int shutdownApp(); #endif