Browse Source

StringArray fix + additional unit tests. AudioFormatManager tweak for iOS. Minor clean-ups.

tags/2021-05-28
jules 14 years ago
parent
commit
07b73e4071
14 changed files with 91 additions and 101 deletions
  1. +1
    -1
      extras/JuceDemo/Source/demos/OpenGLDemo.cpp
  2. +21
    -34
      modules/juce_audio_formats/format/juce_AudioFormatManager.cpp
  3. +3
    -5
      modules/juce_core/containers/juce_LinkedListPointer.h
  4. +17
    -2
      modules/juce_core/text/juce_String.cpp
  5. +14
    -13
      modules/juce_core/text/juce_StringArray.cpp
  6. +8
    -9
      modules/juce_core/xml/juce_XmlElement.cpp
  7. +6
    -11
      modules/juce_events/broadcasters/juce_AsyncUpdater.cpp
  8. +3
    -4
      modules/juce_events/broadcasters/juce_AsyncUpdater.h
  9. +4
    -4
      modules/juce_events/broadcasters/juce_ListenerList.h
  10. +3
    -3
      modules/juce_graphics/colour/juce_Colour.cpp
  11. +5
    -7
      modules/juce_graphics/colour/juce_FillType.cpp
  12. +2
    -2
      modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.h
  13. +3
    -5
      modules/juce_gui_basics/menus/juce_PopupMenu.cpp
  14. +1
    -1
      modules/juce_gui_basics/widgets/juce_ComboBox.h

+ 1
- 1
extras/JuceDemo/Source/demos/OpenGLDemo.cpp View File

@@ -172,7 +172,7 @@ private:
for (int i = 10; --i >= 0;)
{
Path pp;
pp.addStar (Point<float> (r.nextInt (w), r.nextInt (h)), r.nextInt (8) + 3, 10, 20, 0);
pp.addStar (Point<float> (r.nextFloat() * w, r.nextFloat() * h, r.nextFloat() * 8 + 3, 10.0f, 20.0f, 0.0f);
g.setColour (Colours::pink.withAlpha (0.4f));
g.fillPath (pp);
}


+ 21
- 34
modules/juce_audio_formats/format/juce_AudioFormatManager.cpp View File

@@ -42,7 +42,7 @@ void AudioFormatManager::registerFormat (AudioFormat* newFormat, const bool make
if (newFormat != nullptr)
{
#if JUCE_DEBUG
#if JUCE_DEBUG
for (int i = getNumKnownFormats(); --i >= 0;)
{
if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
@@ -50,7 +50,7 @@ void AudioFormatManager::registerFormat (AudioFormat* newFormat, const bool make
jassertfalse; // trying to add the same format twice!
}
}
#endif
#endif
if (makeThisTheDefaultFormat)
defaultFormatIndex = getNumKnownFormats();
@@ -61,22 +61,20 @@ void AudioFormatManager::registerFormat (AudioFormat* newFormat, const bool make
void AudioFormatManager::registerBasicFormats()
{
#if JUCE_MAC
registerFormat (new AiffAudioFormat(), true);
registerFormat (new WavAudioFormat(), false);
registerFormat (new CoreAudioFormat(), false);
#else
registerFormat (new WavAudioFormat(), true);
registerFormat (new AiffAudioFormat(), false);
#endif
#if JUCE_USE_FLAC
#if JUCE_MAC || JUCE_IOS
registerFormat (new CoreAudioFormat(), false);
#endif
#if JUCE_USE_FLAC
registerFormat (new FlacAudioFormat(), false);
#endif
#endif
#if JUCE_USE_OGGVORBIS
#if JUCE_USE_OGGVORBIS
registerFormat (new OggVorbisAudioFormat(), false);
#endif
#endif
}
void AudioFormatManager::clearFormats()
@@ -102,12 +100,11 @@ AudioFormat* AudioFormatManager::getDefaultFormat() const
AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
{
String e (fileExtension);
if (! e.startsWithChar ('.'))
e = "." + e;
if (! fileExtension.startsWithChar ('.'))
return findFormatForFileExtension ("." + fileExtension);
for (int i = 0; i < getNumKnownFormats(); ++i)
if (getKnownFormat(i)->getFileExtensions().contains (e, true))
if (getKnownFormat(i)->getFileExtensions().contains (fileExtension, true))
return getKnownFormat(i);
return nullptr;
@@ -115,30 +112,20 @@ AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileE
String AudioFormatManager::getWildcardForAllFormats() const
{
StringArray allExtensions;
StringArray extensions;
int i;
for (i = 0; i < getNumKnownFormats(); ++i)
allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
allExtensions.trim();
allExtensions.removeEmptyStrings();
extensions.addArray (getKnownFormat(i)->getFileExtensions());
String s;
for (i = 0; i < allExtensions.size(); ++i)
{
s << '*';
if (! allExtensions[i].startsWithChar ('.'))
s << '.';
extensions.trim();
extensions.removeEmptyStrings();
s << allExtensions[i];
if (i < allExtensions.size() - 1)
s << ';';
}
for (i = 0; i < extensions.size(); ++i)
extensions.set (i, (extensions[i].startsWithChar ('.') ? "*" : "*.") + extensions[i]);
return s;
extensions.removeDuplicates (true);
return extensions.joinIntoString (";");
}
//==============================================================================


+ 3
- 5
modules/juce_core/containers/juce_LinkedListPointer.h View File

@@ -87,12 +87,10 @@ public:
LinkedListPointer& operator= (LinkedListPointer&& other) noexcept
{
if (this != &other)
{
item = other.item;
other.item = nullptr;
}
jassert (this != &other); // hopefully the compiler should make this situation impossible!
item = other.item;
other.item = nullptr;
return *this;
}
#endif


+ 17
- 2
modules/juce_core/text/juce_String.cpp View File

@@ -2382,8 +2382,8 @@ public:
beginTest ("StringArray");
StringArray s;
for (int i = 5; --i >= 0;)
s.add (String (i));
s.addTokens ("4,3,2,1,0", ";,", "x");
expectEquals (s.size(), 5);
expectEquals (s.joinIntoString ("-"), String ("4-3-2-1-0"));
s.remove (2);
@@ -2391,6 +2391,21 @@ public:
expectEquals (s.joinIntoString (String::empty), String ("4310"));
s.clear();
expectEquals (s.joinIntoString ("x"), String::empty);
StringArray toks;
toks.addTokens ("x,,", ";,", "");
expectEquals (toks.size(), 3);
expectEquals (toks.joinIntoString ("-"), String ("x--"));
toks.clear();
toks.addTokens (",x,", ";,", "");
expectEquals (toks.size(), 3);
expectEquals (toks.joinIntoString ("-"), String ("-x-"));
toks.clear();
toks.addTokens ("x,'y,z',", ";,", "'");
expectEquals (toks.size(), 3);
expectEquals (toks.joinIntoString ("-"), String ("x-'y,z'-"));
}
}
};


+ 14
- 13
modules/juce_core/text/juce_StringArray.cpp View File

@@ -279,15 +279,13 @@ void StringArray::trim()
}
//==============================================================================
class InternalStringArrayComparator_CaseSensitive
struct InternalStringArrayComparator_CaseSensitive
{
public:
static int compareElements (String& first, String& second) { return first.compare (second); }
};
class InternalStringArrayComparator_CaseInsensitive
struct InternalStringArrayComparator_CaseInsensitive
{
public:
static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
};
@@ -363,18 +361,21 @@ int StringArray::addTokens (const String& text, const String& breakCharacters, c
int num = 0;
String::CharPointerType t (text.getCharPointer());
while (! t.isEmpty())
if (! t.isEmpty())
{
String::CharPointerType tokenEnd (CharacterFunctions::findEndOfToken (t,
breakCharacters.getCharPointer(),
quoteCharacters.getCharPointer()));
add (String (t, tokenEnd));
++num;
for (;;)
{
String::CharPointerType tokenEnd (CharacterFunctions::findEndOfToken (t,
breakCharacters.getCharPointer(),
quoteCharacters.getCharPointer()));
add (String (t, tokenEnd));
++num;
if (tokenEnd.isEmpty())
break;
if (tokenEnd.isEmpty())
break;
t = ++tokenEnd;
t = ++tokenEnd;
}
}
return num;


+ 8
- 9
modules/juce_core/xml/juce_XmlElement.cpp View File

@@ -95,16 +95,15 @@ XmlElement::XmlElement (XmlElement&& other) noexcept
XmlElement& XmlElement::operator= (XmlElement&& other) noexcept
{
if (this != &other)
{
removeAllAttributes();
deleteAllChildElements();
jassert (this != &other); // hopefully the compiler should make this situation impossible!
nextListItem = static_cast <LinkedListPointer <XmlElement>&&> (other.nextListItem);
firstChildElement = static_cast <LinkedListPointer <XmlElement>&&> (other.firstChildElement);
attributes = static_cast <LinkedListPointer <XmlAttributeNode>&&> (other.attributes);
tagName = static_cast <String&&> (other.tagName);
}
removeAllAttributes();
deleteAllChildElements();
nextListItem = static_cast <LinkedListPointer <XmlElement>&&> (other.nextListItem);
firstChildElement = static_cast <LinkedListPointer <XmlElement>&&> (other.firstChildElement);
attributes = static_cast <LinkedListPointer <XmlAttributeNode>&&> (other.attributes);
tagName = static_cast <String&&> (other.tagName);
return *this;
}


+ 6
- 11
modules/juce_events/broadcasters/juce_AsyncUpdater.cpp View File

@@ -26,7 +26,7 @@
BEGIN_JUCE_NAMESPACE
//==============================================================================
class AsyncUpdaterMessage : public CallbackMessage
class AsyncUpdater::AsyncUpdaterMessage : public CallbackMessage
{
public:
AsyncUpdaterMessage (AsyncUpdater& owner_)
@@ -52,11 +52,6 @@ AsyncUpdater::AsyncUpdater()
message = new AsyncUpdaterMessage (*this);
}
inline Atomic<int>& AsyncUpdater::getDeliveryFlag() const noexcept
{
return static_cast <AsyncUpdaterMessage*> (message.getObject())->shouldDeliver;
}
AsyncUpdater::~AsyncUpdater()
{
// You're deleting this object with a background thread while there's an update
@@ -65,18 +60,18 @@ AsyncUpdater::~AsyncUpdater()
// deleting this object, or find some other way to avoid such a race condition.
jassert ((! isUpdatePending()) || MessageManager::getInstance()->currentThreadHasLockedMessageManager());
getDeliveryFlag().set (0);
message->shouldDeliver.set (0);
}
void AsyncUpdater::triggerAsyncUpdate()
{
if (getDeliveryFlag().compareAndSetBool (1, 0))
if (message->shouldDeliver.compareAndSetBool (1, 0))
message->post();
}
void AsyncUpdater::cancelPendingUpdate() noexcept
{
getDeliveryFlag().set (0);
message->shouldDeliver.set (0);
}
void AsyncUpdater::handleUpdateNowIfNeeded()
@@ -84,13 +79,13 @@ void AsyncUpdater::handleUpdateNowIfNeeded()
// This can only be called by the event thread.
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
if (getDeliveryFlag().exchange (0) != 0)
if (message->shouldDeliver.exchange (0) != 0)
handleAsyncUpdate();
}
bool AsyncUpdater::isUpdatePending() const noexcept
{
return getDeliveryFlag().value != 0;
return message->shouldDeliver.value != 0;
}


+ 3
- 4
modules/juce_events/broadcasters/juce_AsyncUpdater.h View File

@@ -26,8 +26,6 @@
#ifndef __JUCE_ASYNCUPDATER_JUCEHEADER__
#define __JUCE_ASYNCUPDATER_JUCEHEADER__
#include "../messages/juce_CallbackMessage.h"
//==============================================================================
/**
@@ -102,8 +100,9 @@ public:
private:
//==============================================================================
ReferenceCountedObjectPtr<CallbackMessage> message;
Atomic<int>& getDeliveryFlag() const noexcept;
class AsyncUpdaterMessage;
friend class ReferenceCountedObjectPtr<AsyncUpdaterMessage>;
ReferenceCountedObjectPtr<AsyncUpdaterMessage> message;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AsyncUpdater);
};


+ 4
- 4
modules/juce_events/broadcasters/juce_ListenerList.h View File

@@ -281,14 +281,14 @@ public:
{
public:
//==============================================================================
Iterator (const ListType& list_)
Iterator (const ListType& list_) noexcept
: list (list_), index (list_.size())
{}
~Iterator() {}
~Iterator() noexcept {}
//==============================================================================
bool next()
bool next() noexcept
{
if (index <= 0)
return false;
@@ -302,7 +302,7 @@ public:
return index >= 0;
}
bool next (const BailOutCheckerType& bailOutChecker)
bool next (const BailOutCheckerType& bailOutChecker) noexcept
{
return (! bailOutChecker.shouldBailOut()) && next();
}


+ 3
- 3
modules/juce_graphics/colour/juce_Colour.cpp View File

@@ -97,7 +97,7 @@ struct HSB
return Colour (hue, saturation, brightness, original.getAlpha());
}
static PixelARGB convertHSBtoRGB (float h, float s, float v, const uint8 alpha) noexcept
static PixelARGB toRGB (float h, float s, float v, const uint8 alpha) noexcept
{
v = jlimit (0.0f, 255.0f, v * 255.0f);
const uint8 intV = (uint8) roundToInt (v);
@@ -178,7 +178,7 @@ Colour Colour::fromRGBAFloat (const uint8 red, const uint8 green, const uint8 bl
}
Colour::Colour (const float hue, const float saturation, const float brightness, const float alpha) noexcept
: argb (HSB::convertHSBtoRGB (hue, saturation, brightness, ColourHelpers::floatToUInt8 (alpha)))
: argb (HSB::toRGB (hue, saturation, brightness, ColourHelpers::floatToUInt8 (alpha)))
{
}
@@ -188,7 +188,7 @@ Colour Colour::fromHSV (const float hue, const float saturation, const float bri
}
Colour::Colour (const float hue, const float saturation, const float brightness, const uint8 alpha) noexcept
: argb (HSB::convertHSBtoRGB (hue, saturation, brightness, alpha))
: argb (HSB::toRGB (hue, saturation, brightness, alpha))
{
}


+ 5
- 7
modules/juce_graphics/colour/juce_FillType.cpp View File

@@ -78,14 +78,12 @@ FillType::FillType (FillType&& other) noexcept
FillType& FillType::operator= (FillType&& other) noexcept
{
if (this != &other)
{
colour = other.colour;
gradient = other.gradient.release();
image = static_cast <Image&&> (other.image);
transform = other.transform;
}
jassert (this != &other); // hopefully the compiler should make this situation impossible!
colour = other.colour;
gradient = other.gradient.release();
image = static_cast <Image&&> (other.image);
transform = other.transform;
return *this;
}
#endif


+ 2
- 2
modules/juce_gui_basics/filebrowser/juce_FileBrowserComponent.h View File

@@ -79,11 +79,11 @@ public:
or saveMode, and canSelectFiles and/or canSelectDirectories.
@param initialFileOrDirectory The file or directory that should be selected when the component begins.
If this is File::nonexistent, a default directory will be chosen.
@param fileFilter an optional filter to use to determine which files are shown.
@param fileFilter an optional filter to use to determine which files are shown.
If this is nullptr then all files are displayed. Note that a pointer
is kept internally to this object, so make sure that it is not deleted
before the FileBrowserComponent object is deleted.
@param previewComp an optional preview component that will be used to show previews of
@param previewComp an optional preview component that will be used to show previews of
files that the user selects
*/
FileBrowserComponent (int flags,


+ 3
- 5
modules/juce_gui_basics/menus/juce_PopupMenu.cpp View File

@@ -1169,12 +1169,10 @@ PopupMenu::PopupMenu (PopupMenu&& other) noexcept
PopupMenu& PopupMenu::operator= (PopupMenu&& other) noexcept
{
if (this != &other)
{
items.swapWithArray (other.items);
lookAndFeel = other.lookAndFeel;
}
jassert (this != &other); // hopefully the compiler should make this situation impossible!
items.swapWithArray (other.items);
lookAndFeel = other.lookAndFeel;
return *this;
}
#endif


+ 1
- 1
modules/juce_gui_basics/widgets/juce_ComboBox.h View File

@@ -108,7 +108,7 @@ public:
The item ID of each item will be its index in the StringArray + firstItemIdOffset.
*/
void addItemList (const StringArray& items, int firstItemIdOffset);
/** Adds a separator line to the drop-down list.
This is like adding a separator to a popup menu. See PopupMenu::addSeparator().


Loading…
Cancel
Save