@@ -176,8 +176,6 @@ namespace MarkChunk | |||||
for (int i = 0; i < numCues; ++i) | for (int i = 0; i < numCues; ++i) | ||||
{ | { | ||||
const String prefixCue ("Cue" + String (i)); | const String prefixCue ("Cue" + String (i)); | ||||
const String prefixLabel ("CueLabel" + String (i)); | |||||
const int identifier = idOffset + values.getValue (prefixCue + "Identifier", "1").getIntValue(); | const int identifier = idOffset + values.getValue (prefixCue + "Identifier", "1").getIntValue(); | ||||
#if JUCE_DEBUG | #if JUCE_DEBUG | ||||
@@ -186,8 +184,7 @@ namespace MarkChunk | |||||
#endif | #endif | ||||
const int offset = values.getValue (prefixCue + "Offset", "0").getIntValue(); | const int offset = values.getValue (prefixCue + "Offset", "0").getIntValue(); | ||||
String label (prefixLabel); | |||||
String label ("CueLabel" + String (i)); | |||||
for (int labelIndex = 0; labelIndex < numCueLabels; ++labelIndex) | for (int labelIndex = 0; labelIndex < numCueLabels; ++labelIndex) | ||||
{ | { | ||||
@@ -250,18 +250,18 @@ class OggWriter : public AudioFormatWriter | |||||
public: | public: | ||||
//============================================================================== | //============================================================================== | ||||
OggWriter (OutputStream* const out, | OggWriter (OutputStream* const out, | ||||
const double sampleRate, | |||||
const int numChannels, | |||||
const int bitsPerSample, | |||||
const double sampleRate_, | |||||
const int numChannels_, | |||||
const int bitsPerSample_, | |||||
const int qualityIndex) | const int qualityIndex) | ||||
: AudioFormatWriter (out, TRANS (oggFormatName), sampleRate, numChannels, bitsPerSample), | |||||
: AudioFormatWriter (out, TRANS (oggFormatName), sampleRate_, numChannels_, bitsPerSample_), | |||||
ok (false) | ok (false) | ||||
{ | { | ||||
using namespace OggVorbisNamespace; | using namespace OggVorbisNamespace; | ||||
vorbis_info_init (&vi); | vorbis_info_init (&vi); | ||||
if (vorbis_encode_init_vbr (&vi, numChannels, (int) sampleRate, | |||||
if (vorbis_encode_init_vbr (&vi, numChannels_, (int) sampleRate_, | |||||
jlimit (0.0f, 1.0f, qualityIndex * 0.1f)) == 0) | jlimit (0.0f, 1.0f, qualityIndex * 0.1f)) == 0) | ||||
{ | { | ||||
vorbis_comment_init (&vc); | vorbis_comment_init (&vc); | ||||
@@ -78,12 +78,12 @@ void ReverbAudioSource::setParameters (const Reverb::Parameters& newParams) | |||||
reverb.setParameters (newParams); | reverb.setParameters (newParams); | ||||
} | } | ||||
void ReverbAudioSource::setBypassed (bool isBypassed) noexcept | |||||
void ReverbAudioSource::setBypassed (bool b) noexcept | |||||
{ | { | ||||
if (bypass != isBypassed) | |||||
if (bypass != b) | |||||
{ | { | ||||
const ScopedLock sl (lock); | const ScopedLock sl (lock); | ||||
bypass = isBypassed; | |||||
bypass = b; | |||||
reverb.reset(); | reverb.reset(); | ||||
} | } | ||||
} | } | ||||
@@ -775,11 +775,11 @@ void AudioDeviceManager::addMidiInputCallback (const String& name, | |||||
} | } | ||||
} | } | ||||
void AudioDeviceManager::removeMidiInputCallback (const String& name, MidiInputCallback* callback) | |||||
void AudioDeviceManager::removeMidiInputCallback (const String& name, MidiInputCallback* callbackToRemove) | |||||
{ | { | ||||
for (int i = midiCallbacks.size(); --i >= 0;) | for (int i = midiCallbacks.size(); --i >= 0;) | ||||
{ | { | ||||
if (midiCallbackDevices[i] == name && midiCallbacks.getUnchecked(i) == callback) | |||||
if (midiCallbackDevices[i] == name && midiCallbacks.getUnchecked(i) == callbackToRemove) | |||||
{ | { | ||||
const ScopedLock sl (midiCallbackLock); | const ScopedLock sl (midiCallbackLock); | ||||
midiCallbacks.remove (i); | midiCallbacks.remove (i); | ||||
@@ -235,9 +235,9 @@ void Synthesiser::noteOn (const int midiChannel, | |||||
{ | { | ||||
// If hitting a note that's still ringing, stop it first (it could be | // If hitting a note that's still ringing, stop it first (it could be | ||||
// still playing because of the sustain or sostenuto pedal). | // still playing because of the sustain or sostenuto pedal). | ||||
for (int i = voices.size(); --i >= 0;) | |||||
for (int j = voices.size(); --j >= 0;) | |||||
{ | { | ||||
SynthesiserVoice* const voice = voices.getUnchecked (i); | |||||
SynthesiserVoice* const voice = voices.getUnchecked (j); | |||||
if (voice->getCurrentlyPlayingNote() == midiNoteNumber | if (voice->getCurrentlyPlayingNote() == midiNoteNumber | ||||
&& voice->isPlayingChannel (midiChannel)) | && voice->isPlayingChannel (midiChannel)) | ||||
@@ -315,9 +315,9 @@ public: | |||||
{ | { | ||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
const ElementType* e = data.elements.getData(); | const ElementType* e = data.elements.getData(); | ||||
const ElementType* const end = e + numUsed; | |||||
const ElementType* const end_ = e + numUsed; | |||||
for (; e != end; ++e) | |||||
for (; e != end_; ++e) | |||||
if (elementToLookFor == *e) | if (elementToLookFor == *e) | ||||
return static_cast <int> (e - data.elements.getData()); | return static_cast <int> (e - data.elements.getData()); | ||||
@@ -333,9 +333,9 @@ public: | |||||
{ | { | ||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
const ElementType* e = data.elements.getData(); | const ElementType* e = data.elements.getData(); | ||||
const ElementType* const end = e + numUsed; | |||||
const ElementType* const end_ = e + numUsed; | |||||
for (; e != end; ++e) | |||||
for (; e != end_; ++e) | |||||
if (elementToLookFor == *e) | if (elementToLookFor == *e) | ||||
return true; | return true; | ||||
@@ -668,11 +668,11 @@ public: | |||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
int start = 0; | int start = 0; | ||||
int end = numUsed; | |||||
int end_ = numUsed; | |||||
for (;;) | for (;;) | ||||
{ | { | ||||
if (start >= end) | |||||
if (start >= end_) | |||||
{ | { | ||||
return -1; | return -1; | ||||
} | } | ||||
@@ -682,14 +682,14 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
const int halfway = (start + end) >> 1; | |||||
const int halfway = (start + end_) >> 1; | |||||
if (halfway == start) | if (halfway == start) | ||||
return -1; | return -1; | ||||
else if (comparator.compareElements (elementToLookFor, data.elements [halfway]) >= 0) | else if (comparator.compareElements (elementToLookFor, data.elements [halfway]) >= 0) | ||||
start = halfway; | start = halfway; | ||||
else | else | ||||
end = halfway; | |||||
end_ = halfway; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -108,7 +108,7 @@ public: | |||||
will be the "upperLimit" parameter that is passed to your generateHash() function. The number | will be the "upperLimit" parameter that is passed to your generateHash() function. The number | ||||
of hash slots will grow automatically if necessary, or it can be remapped manually using remapTable(). | of hash slots will grow automatically if necessary, or it can be remapped manually using remapTable(). | ||||
*/ | */ | ||||
HashMap (const int numberOfSlots = defaultHashTableSize) | |||||
explicit HashMap (const int numberOfSlots = defaultHashTableSize) | |||||
: totalNumItems (0) | : totalNumItems (0) | ||||
{ | { | ||||
slots.insertMultiple (0, nullptr, numberOfSlots); | slots.insertMultiple (0, nullptr, numberOfSlots); | ||||
@@ -185,9 +185,9 @@ public: | |||||
{ | { | ||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
ObjectClass* const* e = data.elements.getData(); | ObjectClass* const* e = data.elements.getData(); | ||||
ObjectClass* const* const end = e + numUsed; | |||||
ObjectClass* const* const end_ = e + numUsed; | |||||
for (; e != end; ++e) | |||||
for (; e != end_; ++e) | |||||
if (objectToLookFor == *e) | if (objectToLookFor == *e) | ||||
return static_cast <int> (e - data.elements.getData()); | return static_cast <int> (e - data.elements.getData()); | ||||
@@ -203,9 +203,9 @@ public: | |||||
{ | { | ||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
ObjectClass* const* e = data.elements.getData(); | ObjectClass* const* e = data.elements.getData(); | ||||
ObjectClass* const* const end = e + numUsed; | |||||
ObjectClass* const* const end_ = e + numUsed; | |||||
for (; e != end; ++e) | |||||
for (; e != end_; ++e) | |||||
if (objectToLookFor == *e) | if (objectToLookFor == *e) | ||||
return true; | return true; | ||||
@@ -463,11 +463,11 @@ public: | |||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
int start = 0; | int start = 0; | ||||
int end = numUsed; | |||||
int end_ = numUsed; | |||||
for (;;) | for (;;) | ||||
{ | { | ||||
if (start >= end) | |||||
if (start >= end_) | |||||
{ | { | ||||
return -1; | return -1; | ||||
} | } | ||||
@@ -477,14 +477,14 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
const int halfway = (start + end) >> 1; | |||||
const int halfway = (start + end_) >> 1; | |||||
if (halfway == start) | if (halfway == start) | ||||
return -1; | return -1; | ||||
else if (comparator.compareElements (objectToLookFor, data.elements [halfway]) >= 0) | else if (comparator.compareElements (objectToLookFor, data.elements [halfway]) >= 0) | ||||
start = halfway; | start = halfway; | ||||
else | else | ||||
end = halfway; | |||||
end_ = halfway; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -198,9 +198,9 @@ public: | |||||
{ | { | ||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
ObjectClass** e = data.elements.getData(); | ObjectClass** e = data.elements.getData(); | ||||
ObjectClass** const end = e + numUsed; | |||||
ObjectClass** const end_ = e + numUsed; | |||||
while (e != end) | |||||
while (e != end_) | |||||
{ | { | ||||
if (objectToLookFor == *e) | if (objectToLookFor == *e) | ||||
return static_cast <int> (e - data.elements.getData()); | return static_cast <int> (e - data.elements.getData()); | ||||
@@ -220,9 +220,9 @@ public: | |||||
{ | { | ||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
ObjectClass** e = data.elements.getData(); | ObjectClass** e = data.elements.getData(); | ||||
ObjectClass** const end = e + numUsed; | |||||
ObjectClass** const end_ = e + numUsed; | |||||
while (e != end) | |||||
while (e != end_) | |||||
{ | { | ||||
if (objectToLookFor == *e) | if (objectToLookFor == *e) | ||||
return true; | return true; | ||||
@@ -529,12 +529,12 @@ public: | |||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
const int start = jlimit (0, numUsed, startIndex); | const int start = jlimit (0, numUsed, startIndex); | ||||
const int end = jlimit (0, numUsed, startIndex + numberToRemove); | |||||
const int end_ = jlimit (0, numUsed, startIndex + numberToRemove); | |||||
if (end > start) | |||||
if (end_ > start) | |||||
{ | { | ||||
int i; | int i; | ||||
for (i = start; i < end; ++i) | |||||
for (i = start; i < end_; ++i) | |||||
{ | { | ||||
if (data.elements[i] != nullptr) | if (data.elements[i] != nullptr) | ||||
{ | { | ||||
@@ -543,9 +543,9 @@ public: | |||||
} | } | ||||
} | } | ||||
const int rangeSize = end - start; | |||||
const int rangeSize = end_ - start; | |||||
ObjectClass** e = data.elements + start; | ObjectClass** e = data.elements + start; | ||||
i = numUsed - end; | |||||
i = numUsed - end_; | |||||
numUsed -= rangeSize; | numUsed -= rangeSize; | ||||
while (--i >= 0) | while (--i >= 0) | ||||
@@ -270,11 +270,11 @@ public: | |||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
int start = 0; | int start = 0; | ||||
int end = numUsed; | |||||
int end_ = numUsed; | |||||
for (;;) | for (;;) | ||||
{ | { | ||||
if (start >= end) | |||||
if (start >= end_) | |||||
{ | { | ||||
return -1; | return -1; | ||||
} | } | ||||
@@ -284,12 +284,12 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
const int halfway = (start + end) >> 1; | |||||
const int halfway = (start + end_) >> 1; | |||||
if (halfway == start) | if (halfway == start) | ||||
return -1; | return -1; | ||||
else if (elementToLookFor < data.elements [halfway]) | else if (elementToLookFor < data.elements [halfway]) | ||||
end = halfway; | |||||
end_ = halfway; | |||||
else | else | ||||
start = halfway; | start = halfway; | ||||
} | } | ||||
@@ -306,11 +306,11 @@ public: | |||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
int start = 0; | int start = 0; | ||||
int end = numUsed; | |||||
int end_ = numUsed; | |||||
for (;;) | for (;;) | ||||
{ | { | ||||
if (start >= end) | |||||
if (start >= end_) | |||||
{ | { | ||||
return false; | return false; | ||||
} | } | ||||
@@ -320,12 +320,12 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
const int halfway = (start + end) >> 1; | |||||
const int halfway = (start + end_) >> 1; | |||||
if (halfway == start) | if (halfway == start) | ||||
return false; | return false; | ||||
else if (elementToLookFor < data.elements [halfway]) | else if (elementToLookFor < data.elements [halfway]) | ||||
end = halfway; | |||||
end_ = halfway; | |||||
else | else | ||||
start = halfway; | start = halfway; | ||||
} | } | ||||
@@ -343,13 +343,13 @@ public: | |||||
const ScopedLockType lock (getLock()); | const ScopedLockType lock (getLock()); | ||||
int start = 0; | int start = 0; | ||||
int end = numUsed; | |||||
int end_ = numUsed; | |||||
for (;;) | for (;;) | ||||
{ | { | ||||
if (start >= end) | |||||
if (start >= end_) | |||||
{ | { | ||||
jassert (start <= end); | |||||
jassert (start <= end_); | |||||
insertInternal (start, newElement); | insertInternal (start, newElement); | ||||
break; | break; | ||||
} | } | ||||
@@ -359,7 +359,7 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
const int halfway = (start + end) >> 1; | |||||
const int halfway = (start + end_) >> 1; | |||||
if (halfway == start) | if (halfway == start) | ||||
{ | { | ||||
@@ -371,7 +371,7 @@ public: | |||||
break; | break; | ||||
} | } | ||||
else if (newElement < data.elements [halfway]) | else if (newElement < data.elements [halfway]) | ||||
end = halfway; | |||||
end_ = halfway; | |||||
else | else | ||||
start = halfway; | start = halfway; | ||||
} | } | ||||
@@ -565,9 +565,9 @@ Array<var>* var::convertToArray() | |||||
return array; | return array; | ||||
} | } | ||||
void var::append (const var& value) | |||||
void var::append (const var& n) | |||||
{ | { | ||||
convertToArray()->add (value); | |||||
convertToArray()->add (n); | |||||
} | } | ||||
void var::remove (const int index) | void var::remove (const int index) | ||||
@@ -578,9 +578,9 @@ void var::remove (const int index) | |||||
array->remove (index); | array->remove (index); | ||||
} | } | ||||
void var::insert (const int index, const var& value) | |||||
void var::insert (const int index, const var& n) | |||||
{ | { | ||||
convertToArray()->insert (index, value); | |||||
convertToArray()->insert (index, n); | |||||
} | } | ||||
void var::resize (const int numArrayElementsWanted) | void var::resize (const int numArrayElementsWanted) | ||||
@@ -588,10 +588,10 @@ void var::resize (const int numArrayElementsWanted) | |||||
convertToArray()->resize (numArrayElementsWanted); | convertToArray()->resize (numArrayElementsWanted); | ||||
} | } | ||||
int var::indexOf (const var& value) const | |||||
int var::indexOf (const var& n) const | |||||
{ | { | ||||
const Array<var>* const array = getArray(); | const Array<var>* const array = getArray(); | ||||
return array != nullptr ? array->indexOf (value) : -1; | |||||
return array != nullptr ? array->indexOf (n) : -1; | |||||
} | } | ||||
//============================================================================== | //============================================================================== | ||||
@@ -44,7 +44,10 @@ | |||||
any kind of ReferenceCountedObject. The var class is intended to act like | any kind of ReferenceCountedObject. The var class is intended to act like | ||||
the kind of values used in dynamic scripting languages. | the kind of values used in dynamic scripting languages. | ||||
@see DynamicObject | |||||
You can save/load var objects either in a small, proprietary binary format | |||||
using writeToStream()/readFromStream(), or as JSON by using the JSON class. | |||||
@see JSON, DynamicObject | |||||
*/ | */ | ||||
class JUCE_API var | class JUCE_API var | ||||
{ | { | ||||
@@ -208,12 +211,14 @@ public: | |||||
//============================================================================== | //============================================================================== | ||||
/** Writes a binary representation of this value to a stream. | /** Writes a binary representation of this value to a stream. | ||||
The data can be read back later using readFromStream(). | The data can be read back later using readFromStream(). | ||||
@see JSON | |||||
*/ | */ | ||||
void writeToStream (OutputStream& output) const; | void writeToStream (OutputStream& output) const; | ||||
/** Reads back a stored binary representation of a value. | /** Reads back a stored binary representation of a value. | ||||
The data in the stream must have been written using writeToStream(), or this | The data in the stream must have been written using writeToStream(), or this | ||||
will have unpredictable results. | will have unpredictable results. | ||||
@see JSON | |||||
*/ | */ | ||||
static var readFromStream (InputStream& input); | static var readFromStream (InputStream& input); | ||||
@@ -65,7 +65,7 @@ public: | |||||
void run() | void run() | ||||
{ | { | ||||
uint32 lastTime = Time::getMillisecondCounter(); | uint32 lastTime = Time::getMillisecondCounter(); | ||||
Message::Ptr message (new Message()); | |||||
Message::Ptr messageToSend (new Message()); | |||||
while (! threadShouldExit()) | while (! threadShouldExit()) | ||||
{ | { | ||||
@@ -92,7 +92,7 @@ public: | |||||
*/ | */ | ||||
if (callbackNeeded.compareAndSetBool (1, 0)) | if (callbackNeeded.compareAndSetBool (1, 0)) | ||||
{ | { | ||||
postMessage (message); | |||||
postMessage (messageToSend); | |||||
/* Sometimes our message can get discarded by the OS (e.g. when running as an RTAS | /* Sometimes our message can get discarded by the OS (e.g. when running as an RTAS | ||||
when the app has a modal loop), so this is how long to wait before assuming the | when the app has a modal loop), so this is how long to wait before assuming the | ||||
@@ -77,15 +77,15 @@ void ShapeButton::setShape (const Path& newShape, | |||||
if (resizeNowToFitThisShape) | if (resizeNowToFitThisShape) | ||||
{ | { | ||||
Rectangle<float> bounds (shape.getBounds()); | |||||
Rectangle<float> newBounds (shape.getBounds()); | |||||
if (hasShadow) | if (hasShadow) | ||||
bounds.expand (4.0f, 4.0f); | |||||
newBounds.expand (4.0f, 4.0f); | |||||
shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY())); | |||||
shape.applyTransform (AffineTransform::translation (-newBounds.getX(), -newBounds.getY())); | |||||
setSize (1 + (int) (bounds.getWidth() + outlineWidth), | |||||
1 + (int) (bounds.getHeight() + outlineWidth)); | |||||
setSize (1 + (int) (newBounds.getWidth() + outlineWidth), | |||||
1 + (int) (newBounds.getHeight() + outlineWidth)); | |||||
} | } | ||||
} | } | ||||
@@ -31,8 +31,8 @@ BEGIN_JUCE_NAMESPACE | |||||
//============================================================================== | //============================================================================== | ||||
ImageComponent::ImageComponent (const String& componentName) | |||||
: Component (componentName), | |||||
ImageComponent::ImageComponent (const String& name) | |||||
: Component (name), | |||||
placement (RectanglePlacement::centred) | placement (RectanglePlacement::centred) | ||||
{ | { | ||||
} | } | ||||
@@ -34,9 +34,9 @@ BEGIN_JUCE_NAMESPACE | |||||
//============================================================================== | //============================================================================== | ||||
Label::Label (const String& componentName, | |||||
Label::Label (const String& name, | |||||
const String& labelText) | const String& labelText) | ||||
: Component (componentName), | |||||
: Component (name), | |||||
textValue (labelText), | textValue (labelText), | ||||
lastTextValue (labelText), | lastTextValue (labelText), | ||||
font (15.0f), | font (15.0f), | ||||
@@ -1715,9 +1715,9 @@ void TextEditor::drawContent (Graphics& g) | |||||
} | } | ||||
} | } | ||||
for (int i = underlinedSections.size(); --i >= 0;) | |||||
for (int j = underlinedSections.size(); --j >= 0;) | |||||
{ | { | ||||
const Range<int>& underlinedSection = underlinedSections.getReference (i); | |||||
const Range<int>& underlinedSection = underlinedSections.getReference (j); | |||||
Iterator i2 (sections, wordWrapWidth, passwordCharacter); | Iterator i2 (sections, wordWrapWidth, passwordCharacter); | ||||
@@ -459,8 +459,8 @@ private: | |||||
//============================================================================== | //============================================================================== | ||||
TreeView::TreeView (const String& componentName) | |||||
: Component (componentName), | |||||
TreeView::TreeView (const String& name) | |||||
: Component (name), | |||||
rootItem (nullptr), | rootItem (nullptr), | ||||
indentSize (24), | indentSize (24), | ||||
defaultOpenness (false), | defaultOpenness (false), | ||||
@@ -200,7 +200,7 @@ void ModalComponentManager::handleAsyncUpdate() | |||||
if (! item->isActive) | if (! item->isActive) | ||||
{ | { | ||||
ScopedPointer<ModalItem> item (stack.removeAndReturn (i)); | |||||
ScopedPointer<ModalItem> deleter (stack.removeAndReturn (i)); | |||||
for (int j = item->callbacks.size(); --j >= 0;) | for (int j = item->callbacks.size(); --j >= 0;) | ||||
item->callbacks.getUnchecked(j)->modalStateFinished (item->returnValue); | item->callbacks.getUnchecked(j)->modalStateFinished (item->returnValue); | ||||
@@ -385,7 +385,7 @@ public: | |||||
void changeListenerCallback (ChangeBroadcaster*) | void changeListenerCallback (ChangeBroadcaster*) | ||||
{ | { | ||||
const OpennessRestorer openness (*this); | |||||
const OpennessRestorer opennessRestorer (*this); | |||||
clearSubItems(); | clearSubItems(); | ||||
const StringArray categories (owner.getMappings().getCommandManager()->getCommandCategories()); | const StringArray categories (owner.getMappings().getCommandManager()->getCommandCategories()); | ||||
@@ -32,9 +32,9 @@ BEGIN_JUCE_NAMESPACE | |||||
//============================================================================== | //============================================================================== | ||||
GroupComponent::GroupComponent (const String& componentName, | |||||
GroupComponent::GroupComponent (const String& name, | |||||
const String& labelText) | const String& labelText) | ||||
: Component (componentName), | |||||
: Component (name), | |||||
text (labelText), | text (labelText), | ||||
justification (Justification::left) | justification (Justification::left) | ||||
{ | { | ||||
@@ -150,11 +150,11 @@ void ResizableBorderComponent::mouseDrag (const MouseEvent& e) | |||||
return; | return; | ||||
} | } | ||||
const Rectangle<int> bounds (mouseZone.resizeRectangleBy (originalBounds, e.getOffsetFromDragStart())); | |||||
const Rectangle<int> newBounds (mouseZone.resizeRectangleBy (originalBounds, e.getOffsetFromDragStart())); | |||||
if (constrainer != nullptr) | if (constrainer != nullptr) | ||||
{ | { | ||||
constrainer->setBoundsForComponent (component, bounds, | |||||
constrainer->setBoundsForComponent (component, newBounds, | |||||
mouseZone.isDraggingTopEdge(), | mouseZone.isDraggingTopEdge(), | ||||
mouseZone.isDraggingLeftEdge(), | mouseZone.isDraggingLeftEdge(), | ||||
mouseZone.isDraggingBottomEdge(), | mouseZone.isDraggingBottomEdge(), | ||||
@@ -162,12 +162,12 @@ void ResizableBorderComponent::mouseDrag (const MouseEvent& e) | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
Component::Positioner* const positioner = component->getPositioner(); | |||||
Component::Positioner* const pos = component->getPositioner(); | |||||
if (positioner != nullptr) | |||||
positioner->applyNewBounds (bounds); | |||||
if (pos != nullptr) | |||||
pos->applyNewBounds (newBounds); | |||||
else | else | ||||
component->setBounds (bounds); | |||||
component->setBounds (newBounds); | |||||
} | } | ||||
} | } | ||||
@@ -87,10 +87,10 @@ void ResizableCornerComponent::mouseDrag (const MouseEvent& e) | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
Component::Positioner* const positioner = component->getPositioner(); | |||||
Component::Positioner* const pos = component->getPositioner(); | |||||
if (positioner != nullptr) | |||||
positioner->applyNewBounds (r); | |||||
if (pos != nullptr) | |||||
pos->applyNewBounds (r); | |||||
else | else | ||||
component->setBounds (r); | component->setBounds (r); | ||||
} | } | ||||
@@ -82,20 +82,20 @@ void ResizableEdgeComponent::mouseDrag (const MouseEvent& e) | |||||
return; | return; | ||||
} | } | ||||
Rectangle<int> bounds (originalBounds); | |||||
Rectangle<int> newBounds (originalBounds); | |||||
switch (edge) | switch (edge) | ||||
{ | { | ||||
case leftEdge: bounds.setLeft (jmin (bounds.getRight(), bounds.getX() + e.getDistanceFromDragStartX())); break; | |||||
case rightEdge: bounds.setWidth (jmax (0, bounds.getWidth() + e.getDistanceFromDragStartX())); break; | |||||
case topEdge: bounds.setTop (jmin (bounds.getBottom(), bounds.getY() + e.getDistanceFromDragStartY())); break; | |||||
case bottomEdge: bounds.setHeight (jmax (0, bounds.getHeight() + e.getDistanceFromDragStartY())); break; | |||||
case leftEdge: newBounds.setLeft (jmin (newBounds.getRight(), newBounds.getX() + e.getDistanceFromDragStartX())); break; | |||||
case rightEdge: newBounds.setWidth (jmax (0, newBounds.getWidth() + e.getDistanceFromDragStartX())); break; | |||||
case topEdge: newBounds.setTop (jmin (newBounds.getBottom(), newBounds.getY() + e.getDistanceFromDragStartY())); break; | |||||
case bottomEdge: newBounds.setHeight (jmax (0, newBounds.getHeight() + e.getDistanceFromDragStartY())); break; | |||||
default: jassertfalse; break; | default: jassertfalse; break; | ||||
} | } | ||||
if (constrainer != nullptr) | if (constrainer != nullptr) | ||||
{ | { | ||||
constrainer->setBoundsForComponent (component, bounds, | |||||
constrainer->setBoundsForComponent (component, newBounds, | |||||
edge == topEdge, | edge == topEdge, | ||||
edge == leftEdge, | edge == leftEdge, | ||||
edge == bottomEdge, | edge == bottomEdge, | ||||
@@ -103,12 +103,12 @@ void ResizableEdgeComponent::mouseDrag (const MouseEvent& e) | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
Component::Positioner* const positioner = component->getPositioner(); | |||||
Component::Positioner* const pos = component->getPositioner(); | |||||
if (positioner != nullptr) | |||||
positioner->applyNewBounds (bounds); | |||||
if (pos != nullptr) | |||||
pos->applyNewBounds (newBounds); | |||||
else | else | ||||
component->setBounds (bounds); | |||||
component->setBounds (newBounds); | |||||
} | } | ||||
} | } | ||||
@@ -32,8 +32,8 @@ BEGIN_JUCE_NAMESPACE | |||||
//============================================================================== | //============================================================================== | ||||
Viewport::Viewport (const String& componentName) | |||||
: Component (componentName), | |||||
Viewport::Viewport (const String& name) | |||||
: Component (name), | |||||
scrollBarThickness (0), | scrollBarThickness (0), | ||||
singleStepX (16), | singleStepX (16), | ||||
singleStepY (16), | singleStepY (16), | ||||
@@ -220,10 +220,10 @@ void RelativeCoordinatePositionerBase::componentChildrenChanged (Component& chan | |||||
apply(); | apply(); | ||||
} | } | ||||
void RelativeCoordinatePositionerBase::componentBeingDeleted (Component& component) | |||||
void RelativeCoordinatePositionerBase::componentBeingDeleted (Component& comp) | |||||
{ | { | ||||
jassert (sourceComponents.contains (&component)); | |||||
sourceComponents.removeValue (&component); | |||||
jassert (sourceComponents.contains (&comp)); | |||||
sourceComponents.removeValue (&comp); | |||||
registeredOk = false; | registeredOk = false; | ||||
} | } | ||||
@@ -147,8 +147,8 @@ const Rectangle<float> RelativeRectangle::resolve (const Expression::Scope* scop | |||||
{ | { | ||||
if (scope == nullptr) | if (scope == nullptr) | ||||
{ | { | ||||
RelativeRectangleLocalScope scope (*this); | |||||
return resolve (&scope); | |||||
RelativeRectangleLocalScope defaultScope (*this); | |||||
return resolve (&defaultScope); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -36,17 +36,17 @@ BEGIN_JUCE_NAMESPACE | |||||
//============================================================================== | //============================================================================== | ||||
CallOutBox::CallOutBox (Component& contentComponent, | CallOutBox::CallOutBox (Component& contentComponent, | ||||
Component& componentToPointTo, | Component& componentToPointTo, | ||||
Component* const parentComponent) | |||||
Component* const parent) | |||||
: borderSpace (20), arrowSize (16.0f), content (contentComponent) | : borderSpace (20), arrowSize (16.0f), content (contentComponent) | ||||
{ | { | ||||
addAndMakeVisible (&content); | addAndMakeVisible (&content); | ||||
if (parentComponent != nullptr) | |||||
if (parent != nullptr) | |||||
{ | { | ||||
parentComponent->addChildComponent (this); | |||||
parent->addChildComponent (this); | |||||
updatePosition (parentComponent->getLocalArea (&componentToPointTo, componentToPointTo.getLocalBounds()), | |||||
parentComponent->getLocalBounds()); | |||||
updatePosition (parent->getLocalArea (&componentToPointTo, componentToPointTo.getLocalBounds()), | |||||
parent->getLocalBounds()); | |||||
setVisible (true); | setVisible (true); | ||||
} | } | ||||
@@ -155,12 +155,12 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R | |||||
targetArea = newAreaToPointTo; | targetArea = newAreaToPointTo; | ||||
availableArea = newAreaToFitIn; | availableArea = newAreaToFitIn; | ||||
Rectangle<int> bounds (0, 0, | |||||
content.getWidth() + borderSpace * 2, | |||||
content.getHeight() + borderSpace * 2); | |||||
Rectangle<int> newBounds (0, 0, | |||||
content.getWidth() + borderSpace * 2, | |||||
content.getHeight() + borderSpace * 2); | |||||
const int hw = bounds.getWidth() / 2; | |||||
const int hh = bounds.getHeight() / 2; | |||||
const int hw = newBounds.getWidth() / 2; | |||||
const int hh = newBounds.getHeight() / 2; | |||||
const float hwReduced = (float) (hw - borderSpace * 3); | const float hwReduced = (float) (hw - borderSpace * 3); | ||||
const float hhReduced = (float) (hh - borderSpace * 3); | const float hhReduced = (float) (hh - borderSpace * 3); | ||||
const float arrowIndent = borderSpace - arrowSize; | const float arrowIndent = borderSpace - arrowSize; | ||||
@@ -195,12 +195,12 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R | |||||
nearest = distanceFromCentre; | nearest = distanceFromCentre; | ||||
targetPoint = targets[i]; | targetPoint = targets[i]; | ||||
bounds.setPosition ((int) (centre.getX() - hw), | |||||
(int) (centre.getY() - hh)); | |||||
newBounds.setPosition ((int) (centre.getX() - hw), | |||||
(int) (centre.getY() - hh)); | |||||
} | } | ||||
} | } | ||||
setBounds (bounds); | |||||
setBounds (newBounds); | |||||
} | } | ||||
void CallOutBox::refreshPath() | void CallOutBox::refreshPath() | ||||
@@ -65,18 +65,18 @@ class TempDialogWindow : public DialogWindow | |||||
{ | { | ||||
public: | public: | ||||
TempDialogWindow (const String& title, | TempDialogWindow (const String& title, | ||||
Component* contentComponent, | |||||
Component* contentComponent_, | |||||
Component* componentToCentreAround, | Component* componentToCentreAround, | ||||
const Colour& colour, | const Colour& colour, | ||||
const bool escapeKeyTriggersCloseButton, | |||||
const bool escapeKeyTriggersCloseButton_, | |||||
const bool shouldBeResizable, | const bool shouldBeResizable, | ||||
const bool useBottomRightCornerResizer) | const bool useBottomRightCornerResizer) | ||||
: DialogWindow (title, colour, escapeKeyTriggersCloseButton, true) | |||||
: DialogWindow (title, colour, escapeKeyTriggersCloseButton_, true) | |||||
{ | { | ||||
if (! JUCEApplication::isStandaloneApp()) | if (! JUCEApplication::isStandaloneApp()) | ||||
setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level | setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level | ||||
setContentNonOwned (contentComponent, true); | |||||
setContentNonOwned (contentComponent_, true); | |||||
centreAroundComponent (componentToCentreAround, getWidth(), getHeight()); | centreAroundComponent (componentToCentreAround, getWidth(), getHeight()); | ||||
setResizable (shouldBeResizable, useBottomRightCornerResizer); | setResizable (shouldBeResizable, useBottomRightCornerResizer); | ||||
} | } | ||||
@@ -83,13 +83,13 @@ ResizableWindow::~ResizableWindow() | |||||
jassert (getNumChildComponents() == 0); | jassert (getNumChildComponents() == 0); | ||||
} | } | ||||
void ResizableWindow::initialise (const bool addToDesktop) | |||||
void ResizableWindow::initialise (const bool shouldAddToDesktop) | |||||
{ | { | ||||
defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16); | defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16); | ||||
lastNonFullScreenPos.setBounds (50, 50, 256, 256); | lastNonFullScreenPos.setBounds (50, 50, 256, 256); | ||||
if (addToDesktop) | |||||
if (shouldAddToDesktop) | |||||
Component::addToDesktop (ResizableWindow::getDesktopWindowStyleFlags()); | Component::addToDesktop (ResizableWindow::getDesktopWindowStyleFlags()); | ||||
} | } | ||||
@@ -349,12 +349,12 @@ void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer | |||||
} | } | ||||
} | } | ||||
void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds) | |||||
void ResizableWindow::setBoundsConstrained (const Rectangle<int>& newBounds) | |||||
{ | { | ||||
if (constrainer != nullptr) | if (constrainer != nullptr) | ||||
constrainer->setBoundsForComponent (this, bounds, false, false, false, false); | |||||
constrainer->setBoundsForComponent (this, newBounds, false, false, false, false); | |||||
else | else | ||||
setBounds (bounds); | |||||
setBounds (newBounds); | |||||
} | } | ||||
//============================================================================== | //============================================================================== | ||||
@@ -37,7 +37,7 @@ BEGIN_JUCE_NAMESPACE | |||||
//============================================================================== | //============================================================================== | ||||
TooltipWindow::TooltipWindow (Component* const parentComponent, | |||||
TooltipWindow::TooltipWindow (Component* const parent_, | |||||
const int millisecondsBeforeTipAppears_) | const int millisecondsBeforeTipAppears_) | ||||
: Component ("tooltip"), | : Component ("tooltip"), | ||||
millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_), | millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_), | ||||
@@ -52,8 +52,8 @@ TooltipWindow::TooltipWindow (Component* const parentComponent, | |||||
setAlwaysOnTop (true); | setAlwaysOnTop (true); | ||||
setOpaque (true); | setOpaque (true); | ||||
if (parentComponent != nullptr) | |||||
parentComponent->addChildComponent (this); | |||||
if (parent_ != nullptr) | |||||
parent_->addChildComponent (this); | |||||
} | } | ||||
TooltipWindow::~TooltipWindow() | TooltipWindow::~TooltipWindow() | ||||
@@ -146,11 +146,11 @@ void DrawableComposite::resetContentAreaAndBoundingBoxToFitChildren() | |||||
resetBoundingBoxToContentArea(); | resetBoundingBoxToContentArea(); | ||||
} | } | ||||
bool DrawableComposite::registerCoordinates (RelativeCoordinatePositionerBase& positioner) | |||||
bool DrawableComposite::registerCoordinates (RelativeCoordinatePositionerBase& pos) | |||||
{ | { | ||||
bool ok = positioner.addPoint (bounds.topLeft); | |||||
ok = positioner.addPoint (bounds.topRight) && ok; | |||||
return positioner.addPoint (bounds.bottomLeft) && ok; | |||||
bool ok = pos.addPoint (bounds.topLeft); | |||||
ok = pos.addPoint (bounds.topRight) && ok; | |||||
return pos.addPoint (bounds.bottomLeft) && ok; | |||||
} | } | ||||
void DrawableComposite::recalculateCoordinates (Expression::Scope* scope) | void DrawableComposite::recalculateCoordinates (Expression::Scope* scope) | ||||
@@ -98,11 +98,11 @@ void DrawableImage::setBoundingBox (const RelativeParallelogram& newBounds) | |||||
} | } | ||||
//============================================================================== | //============================================================================== | ||||
bool DrawableImage::registerCoordinates (RelativeCoordinatePositionerBase& positioner) | |||||
bool DrawableImage::registerCoordinates (RelativeCoordinatePositionerBase& pos) | |||||
{ | { | ||||
bool ok = positioner.addPoint (bounds.topLeft); | |||||
ok = positioner.addPoint (bounds.topRight) && ok; | |||||
return positioner.addPoint (bounds.bottomLeft) && ok; | |||||
bool ok = pos.addPoint (bounds.topLeft); | |||||
ok = pos.addPoint (bounds.topRight) && ok; | |||||
return pos.addPoint (bounds.bottomLeft) && ok; | |||||
} | } | ||||
void DrawableImage::recalculateCoordinates (Expression::Scope* scope) | void DrawableImage::recalculateCoordinates (Expression::Scope* scope) | ||||
@@ -210,16 +210,15 @@ void DrawablePath::ValueTreeWrapper::writeTo (RelativePointPath& relativePath) c | |||||
for (int j = 0; j < numCps; ++j) | for (int j = 0; j < numCps; ++j) | ||||
points[j] = e.getControlPoint (j); | points[j] = e.getControlPoint (j); | ||||
const Identifier type (e.getType()); | |||||
RelativePointPath::ElementBase* newElement = 0; | RelativePointPath::ElementBase* newElement = 0; | ||||
if (type == Element::startSubPathElement) newElement = new RelativePointPath::StartSubPath (points[0]); | |||||
else if (type == Element::closeSubPathElement) newElement = new RelativePointPath::CloseSubPath(); | |||||
else if (type == Element::lineToElement) newElement = new RelativePointPath::LineTo (points[0]); | |||||
else if (type == Element::quadraticToElement) newElement = new RelativePointPath::QuadraticTo (points[0], points[1]); | |||||
else if (type == Element::cubicToElement) newElement = new RelativePointPath::CubicTo (points[0], points[1], points[2]); | |||||
else jassertfalse; | |||||
const Identifier t (e.getType()); | |||||
if (t == Element::startSubPathElement) newElement = new RelativePointPath::StartSubPath (points[0]); | |||||
else if (t == Element::closeSubPathElement) newElement = new RelativePointPath::CloseSubPath(); | |||||
else if (t == Element::lineToElement) newElement = new RelativePointPath::LineTo (points[0]); | |||||
else if (t == Element::quadraticToElement) newElement = new RelativePointPath::QuadraticTo (points[0], points[1]); | |||||
else if (t == Element::cubicToElement) newElement = new RelativePointPath::CubicTo (points[0], points[1], points[2]); | |||||
else jassertfalse; | |||||
relativePath.addElement (newElement); | relativePath.addElement (newElement); | ||||
} | } | ||||
@@ -87,12 +87,12 @@ void DrawableRectangle::rebuildPath() | |||||
} | } | ||||
} | } | ||||
bool DrawableRectangle::registerCoordinates (RelativeCoordinatePositionerBase& positioner) | |||||
bool DrawableRectangle::registerCoordinates (RelativeCoordinatePositionerBase& pos) | |||||
{ | { | ||||
bool ok = positioner.addPoint (bounds.topLeft); | |||||
ok = positioner.addPoint (bounds.topRight) && ok; | |||||
ok = positioner.addPoint (bounds.bottomLeft) && ok; | |||||
return positioner.addPoint (cornerSize) && ok; | |||||
bool ok = pos.addPoint (bounds.topLeft); | |||||
ok = pos.addPoint (bounds.topRight) && ok; | |||||
ok = pos.addPoint (bounds.bottomLeft) && ok; | |||||
return pos.addPoint (cornerSize) && ok; | |||||
} | } | ||||
void DrawableRectangle::recalculateCoordinates (Expression::Scope* scope) | void DrawableRectangle::recalculateCoordinates (Expression::Scope* scope) | ||||
@@ -101,17 +101,17 @@ void DrawableShape::setStrokeFill (const FillType& newFill) | |||||
} | } | ||||
void DrawableShape::setFillInternal (RelativeFillType& fill, const RelativeFillType& newFill, | void DrawableShape::setFillInternal (RelativeFillType& fill, const RelativeFillType& newFill, | ||||
ScopedPointer<RelativeCoordinatePositionerBase>& positioner) | |||||
ScopedPointer<RelativeCoordinatePositionerBase>& pos) | |||||
{ | { | ||||
if (fill != newFill) | if (fill != newFill) | ||||
{ | { | ||||
fill = newFill; | fill = newFill; | ||||
positioner = nullptr; | |||||
pos = nullptr; | |||||
if (fill.isDynamic()) | if (fill.isDynamic()) | ||||
{ | { | ||||
positioner = new RelativePositioner (*this, fill, true); | |||||
positioner->apply(); | |||||
pos = new RelativePositioner (*this, fill, true); | |||||
pos->apply(); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -130,12 +130,12 @@ void DrawableText::refreshBounds() | |||||
} | } | ||||
} | } | ||||
bool DrawableText::registerCoordinates (RelativeCoordinatePositionerBase& positioner) | |||||
bool DrawableText::registerCoordinates (RelativeCoordinatePositionerBase& pos) | |||||
{ | { | ||||
bool ok = positioner.addPoint (bounds.topLeft); | |||||
ok = positioner.addPoint (bounds.topRight) && ok; | |||||
ok = positioner.addPoint (bounds.bottomLeft) && ok; | |||||
return positioner.addPoint (fontSizeControlPoint) && ok; | |||||
bool ok = pos.addPoint (bounds.topLeft); | |||||
ok = pos.addPoint (bounds.topRight) && ok; | |||||
ok = pos.addPoint (bounds.bottomLeft) && ok; | |||||
return pos.addPoint (fontSizeControlPoint) && ok; | |||||
} | } | ||||
void DrawableText::recalculateCoordinates (Expression::Scope* scope) | void DrawableText::recalculateCoordinates (Expression::Scope* scope) | ||||
@@ -315,9 +315,9 @@ private: | |||||
return code; | return code; | ||||
} | } | ||||
int getCode (const int codeSize_, const bool initialise) | |||||
int getCode (const int codeSize_, const bool shouldInitialise) | |||||
{ | { | ||||
if (initialise) | |||||
if (shouldInitialise) | |||||
{ | { | ||||
currentBit = 0; | currentBit = 0; | ||||
lastBit = 0; | lastBit = 0; | ||||
@@ -1056,9 +1056,9 @@ Expression Expression::withRenamedSymbol (const Expression::Symbol& oldSymbol, c | |||||
return e; | return e; | ||||
} | } | ||||
bool Expression::referencesSymbol (const Expression::Symbol& symbol, const Scope& scope) const | |||||
bool Expression::referencesSymbol (const Expression::Symbol& symbolToCheck, const Scope& scope) const | |||||
{ | { | ||||
Helpers::SymbolCheckVisitor visitor (symbol); | |||||
Helpers::SymbolCheckVisitor visitor (symbolToCheck); | |||||
try | try | ||||
{ | { | ||||
@@ -51,9 +51,9 @@ public: | |||||
unitsToHeightScaleFactor (0.0f) | unitsToHeightScaleFactor (0.0f) | ||||
{ | { | ||||
JUCE_AUTORELEASEPOOL | JUCE_AUTORELEASEPOOL | ||||
CFStringRef name = PlatformUtilities::juceStringToCFString (font.getTypefaceName()); | |||||
ctFontRef = CTFontCreateWithName (name, 1024, nullptr); | |||||
CFRelease (name); | |||||
CFStringRef cfName = PlatformUtilities::juceStringToCFString (font.getTypefaceName()); | |||||
ctFontRef = CTFontCreateWithName (cfName, 1024, nullptr); | |||||
CFRelease (cfName); | |||||
if (ctFontRef != nullptr) | if (ctFontRef != nullptr) | ||||
{ | { | ||||
@@ -61,7 +61,7 @@ public: | |||||
if (font.isItalic()) | if (font.isItalic()) | ||||
{ | { | ||||
CTFontRef newFont = CTFontCreateCopyWithSymbolicTraits (ctFontRef, 0.0, nullptr, | |||||
CTFontRef newFont = CTFontCreateCopyWithSymbolicTraits (ctFontRef, 0.0f, nullptr, | |||||
kCTFontItalicTrait, kCTFontItalicTrait); | kCTFontItalicTrait, kCTFontItalicTrait); | ||||
if (newFont != nullptr) | if (newFont != nullptr) | ||||
@@ -77,7 +77,7 @@ public: | |||||
if (font.isBold()) | if (font.isBold()) | ||||
{ | { | ||||
CTFontRef newFont = CTFontCreateCopyWithSymbolicTraits (ctFontRef, 0.0, nullptr, | |||||
CTFontRef newFont = CTFontCreateCopyWithSymbolicTraits (ctFontRef, 0.0f, nullptr, | |||||
kCTFontBoldTrait, kCTFontBoldTrait); | kCTFontBoldTrait, kCTFontBoldTrait); | ||||
if (newFont != nullptr) | if (newFont != nullptr) | ||||
{ | { | ||||
@@ -156,6 +156,7 @@ private: | |||||
{ | { | ||||
DynamicObject* const resultObject = new DynamicObject(); | DynamicObject* const resultObject = new DynamicObject(); | ||||
result = resultObject; | result = resultObject; | ||||
NamedValueSet& resultProperties = resultObject->getProperties(); | |||||
for (;;) | for (;;) | ||||
{ | { | ||||
@@ -185,17 +186,17 @@ private: | |||||
t = t.findEndOfWhitespace(); | t = t.findEndOfWhitespace(); | ||||
oldT = t; | oldT = t; | ||||
const juce_wchar c = t.getAndAdvance(); | |||||
if (c != ':') | |||||
const juce_wchar c2 = t.getAndAdvance(); | |||||
if (c2 != ':') | |||||
return createFail ("Expected ':', but found", &oldT); | return createFail ("Expected ':', but found", &oldT); | ||||
var propertyValue; | |||||
Result r (parseAny (t, propertyValue)); | |||||
resultProperties.set (propertyName, var::null); | |||||
var* propertyValue = resultProperties.getVarPointer (propertyName); | |||||
if (r.failed()) | |||||
return r; | |||||
Result r2 (parseAny (t, *propertyValue)); | |||||
resultObject->setProperty (propertyName, propertyValue); | |||||
if (r2.failed()) | |||||
return r2; | |||||
t = t.findEndOfWhitespace(); | t = t.findEndOfWhitespace(); | ||||
oldT = t; | oldT = t; | ||||
@@ -528,5 +529,123 @@ void JSON::writeToStream (OutputStream& output, const var& data, const bool allO | |||||
JSONFormatter::write (output, data, 0, allOnOneLine); | JSONFormatter::write (output, data, 0, allOnOneLine); | ||||
} | } | ||||
//============================================================================== | |||||
//============================================================================== | |||||
#if JUCE_UNIT_TESTS | |||||
#include "../utilities/juce_UnitTest.h" | |||||
#include "../maths/juce_Random.h" | |||||
class JSONTests : public UnitTest | |||||
{ | |||||
public: | |||||
JSONTests() : UnitTest ("JSON") {} | |||||
static String createRandomWideCharString (Random& r) | |||||
{ | |||||
juce_wchar buffer[40] = { 0 }; | |||||
for (int i = 0; i < numElementsInArray (buffer) - 1; ++i) | |||||
{ | |||||
if (r.nextBool()) | |||||
{ | |||||
do | |||||
{ | |||||
buffer[i] = (juce_wchar) (1 + r.nextInt (0x10ffff - 1)); | |||||
} | |||||
while (! CharPointer_UTF16::canRepresent (buffer[i])); | |||||
} | |||||
else | |||||
buffer[i] = (juce_wchar) (1 + r.nextInt (0xff)); | |||||
} | |||||
return CharPointer_UTF32 (buffer); | |||||
} | |||||
static String createRandomIdentifier (Random& r) | |||||
{ | |||||
char buffer[30] = { 0 }; | |||||
for (int i = 0; i < numElementsInArray (buffer) - 1; ++i) | |||||
{ | |||||
static const char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-:"; | |||||
buffer[i] = chars [r.nextInt (sizeof (chars) - 1)]; | |||||
} | |||||
return CharPointer_ASCII (buffer); | |||||
} | |||||
static var createRandomVar (Random& r, int depth) | |||||
{ | |||||
switch (r.nextInt (depth > 3 ? 6 : 8)) | |||||
{ | |||||
case 0: return var::null; | |||||
case 1: return r.nextInt(); | |||||
case 2: return r.nextInt64(); | |||||
case 3: return r.nextBool(); | |||||
case 4: return r.nextDouble(); | |||||
case 5: return createRandomWideCharString (r); | |||||
case 6: | |||||
{ | |||||
var v (createRandomVar (r, depth + 1)); | |||||
for (int i = 1 + r.nextInt (30); --i >= 0;) | |||||
v.append (createRandomVar (r, depth + 1)); | |||||
return v; | |||||
} | |||||
case 7: | |||||
{ | |||||
DynamicObject* o = new DynamicObject(); | |||||
for (int i = r.nextInt (30); --i >= 0;) | |||||
o->setProperty (createRandomIdentifier (r), createRandomVar (r, depth + 1)); | |||||
return o; | |||||
} | |||||
default: | |||||
return var::null; | |||||
} | |||||
} | |||||
void runTest() | |||||
{ | |||||
beginTest ("JSON"); | |||||
Random r; | |||||
r.setSeedRandomly(); | |||||
expect (JSON::parse (String::empty) == var::null); | |||||
expect (JSON::parse ("{}").isObject()); | |||||
expect (JSON::parse ("[]").isArray()); | |||||
expect (JSON::parse ("1234").isInt()); | |||||
expect (JSON::parse ("12345678901234").isInt64()); | |||||
expect (JSON::parse ("1.123e3").isDouble()); | |||||
expect (JSON::parse ("-1234").isInt()); | |||||
expect (JSON::parse ("-12345678901234").isInt64()); | |||||
expect (JSON::parse ("-1.123e3").isDouble()); | |||||
for (int i = 100; --i >= 0;) | |||||
{ | |||||
var v; | |||||
if (i > 0) | |||||
v = createRandomVar (r, 0); | |||||
const bool oneLine = r.nextBool(); | |||||
String asString (JSON::toString (v, oneLine)); | |||||
var parsed = JSON::parse (asString); | |||||
String parsedString (JSON::toString (parsed, oneLine)); | |||||
expect (asString.isNotEmpty() && parsedString == asString); | |||||
} | |||||
} | |||||
}; | |||||
static JSONTests JSONUnitTests; | |||||
#endif | |||||
END_JUCE_NAMESPACE | END_JUCE_NAMESPACE |