Browse Source

WindowsMediaFormat fix. ReferenceCountedArray::indexOfSorted() method.

tags/2021-05-28
jules 13 years ago
parent
commit
11659678d6
4 changed files with 70 additions and 30 deletions
  1. +12
    -1
      modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp
  2. +15
    -24
      modules/juce_core/containers/juce_OwnedArray.h
  3. +38
    -0
      modules/juce_core/containers/juce_ReferenceCountedArray.h
  4. +5
    -5
      modules/juce_gui_basics/application/juce_Application.h

+ 12
- 1
modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp View File

@@ -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<IWMHeaderInfo> wmHeaderInfo;


+ 15
- 24
modules/juce_core/containers/juce_OwnedArray.h View File

@@ -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;
}
//==============================================================================


+ 38
- 0
modules/juce_core/containers/juce_ReferenceCountedArray.h View File

@@ -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 <class ElementComparator>
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.


+ 5
- 5
modules/juce_gui_basics/application/juce_Application.h View File

@@ -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 <CommandID>& commands);
void getAllCommands (Array <CommandID>&);
/** @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


Loading…
Cancel
Save