diff --git a/build/macosx/Juce.xcodeproj/project.pbxproj b/build/macosx/Juce.xcodeproj/project.pbxproj index de5aa041c0..50edc3cf77 100644 --- a/build/macosx/Juce.xcodeproj/project.pbxproj +++ b/build/macosx/Juce.xcodeproj/project.pbxproj @@ -650,6 +650,8 @@ 84AB91FF10A078190048FC39 /* juce_CPlusPlusCodeTokeniser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84AB91F910A078190048FC39 /* juce_CPlusPlusCodeTokeniser.cpp */; }; 84AB920010A078190048FC39 /* juce_CPlusPlusCodeTokeniser.h in Headers */ = {isa = PBXBuildFile; fileRef = 84AB91FA10A078190048FC39 /* juce_CPlusPlusCodeTokeniser.h */; }; 84AB927210A082E30048FC39 /* juce_CodeTokeniser.h in Headers */ = {isa = PBXBuildFile; fileRef = 84AB927110A082E30048FC39 /* juce_CodeTokeniser.h */; }; + 84B2053E10D535EC008B4A79 /* juce_ValueTree.h in Headers */ = {isa = PBXBuildFile; fileRef = 843D4A3A10D3C54500624BA6 /* juce_ValueTree.h */; }; + 84B2053F10D535EC008B4A79 /* juce_ValueTree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 843D4A3910D3C54500624BA6 /* juce_ValueTree.cpp */; }; 84D0F00C109B1546007F73A3 /* juce_mac_CoreGraphicsContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84D0F00B109B1546007F73A3 /* juce_mac_CoreGraphicsContext.mm */; }; 84F1E6E710403605006A1807 /* juce_Application.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84F1E6DC10403605006A1807 /* juce_Application.cpp */; }; 84F1E6E810403605006A1807 /* juce_Application.h in Headers */ = {isa = PBXBuildFile; fileRef = 84F1E6DD10403605006A1807 /* juce_Application.h */; }; @@ -3203,6 +3205,7 @@ 844BB95B10C5578800DF5536 /* juce_TargetPlatform.h in Headers */, 844BB95D10C5579B00DF5536 /* juce_FillType.h in Headers */, 844BB95F10C557A800DF5536 /* juce_Config.h in Headers */, + 84B2053E10D535EC008B4A79 /* juce_ValueTree.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3873,6 +3876,7 @@ 840F1DA610AD674F002A03A6 /* juce_CPlusPlusCodeTokeniser.cpp in Sources */, 844BB95C10C5579A00DF5536 /* juce_FillType.cpp in Sources */, 844BB95E10C557A600DF5536 /* juce_mac_CoreGraphicsContext.mm in Sources */, + 84B2053F10D535EC008B4A79 /* juce_ValueTree.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -4212,7 +4216,6 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1)"; ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1 = "ppc i386"; GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; - MACOSX_DEPLOYMENT_TARGET_ppc = 10.3; SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk; STRIP_STYLE = "non-global"; }; @@ -4258,7 +4261,10 @@ ); GCC_SYMBOLS_PRIVATE_EXTERN = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_MISSING_PARENTHESES = YES; + GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_UNUSED_VALUE = YES; GCC_WARN_UNUSED_VARIABLE = YES; PRODUCT_NAME = juce; RUN_CLANG_STATIC_ANALYZER = YES; diff --git a/build/win32/vc8/JUCE.vcproj b/build/win32/vc8/JUCE.vcproj index 598a6fd521..33145ff9b7 100644 --- a/build/win32/vc8/JUCE.vcproj +++ b/build/win32/vc8/JUCE.vcproj @@ -1121,6 +1121,14 @@ RelativePath="..\..\..\src\containers\juce_SparseSet.h" > + + + + diff --git a/extras/audio plugins/demo/src/DemoJuceFilter.cpp b/extras/audio plugins/demo/src/DemoJuceFilter.cpp index 6ae59b8062..9aea6df9a0 100644 --- a/extras/audio plugins/demo/src/DemoJuceFilter.cpp +++ b/extras/audio plugins/demo/src/DemoJuceFilter.cpp @@ -115,12 +115,12 @@ const String DemoJuceFilter::getOutputChannelName (const int channelIndex) const bool DemoJuceFilter::isInputChannelStereoPair (int index) const { - return false; + return true; } bool DemoJuceFilter::isOutputChannelStereoPair (int index) const { - return false; + return true; } bool DemoJuceFilter::acceptsMidi() const diff --git a/extras/juce demo/src/demos/RenderingTestComponent.cpp b/extras/juce demo/src/demos/RenderingTestComponent.cpp index 14b1736798..50e60a281e 100644 --- a/extras/juce demo/src/demos/RenderingTestComponent.cpp +++ b/extras/juce demo/src/demos/RenderingTestComponent.cpp @@ -558,7 +558,7 @@ RenderingTestComponent::RenderingTestComponent () setSize (600, 400); //[Constructor] You can add your own custom stuff here.. - testTypeComboBox->setSelectedId (1); + testTypeComboBox->setSelectedId (2); sizeSlider->setValue (1.0, false); opacitySlider->setValue (1.0, false); highQualityToggle->setToggleState (true, false); diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 83263a7775..45eb8cbf23 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -1566,21 +1566,51 @@ void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI() #endif #ifdef JUCE_DEBUG - // Some simple test code to keep an eye on things and make sure these functions - // work ok on all platforms. Let me know if any of these assertions fail! - int n = 1; - atomicIncrement (n); - jassert (atomicIncrementAndReturn (n) == 3); - atomicDecrement (n); - jassert (atomicDecrementAndReturn (n) == 1); + { + // Some simple test code to keep an eye on things and make sure these functions + // work ok on all platforms. Let me know if any of these assertions fail! + int n = 1; + atomicIncrement (n); + jassert (atomicIncrementAndReturn (n) == 3); + atomicDecrement (n); + jassert (atomicDecrementAndReturn (n) == 1); - jassert (swapByteOrder ((uint32) 0x11223344) == 0x44332211); + jassert (swapByteOrder ((uint32) 0x11223344) == 0x44332211); - // quick test to make sure the run-time lib doesn't crash on freeing a null-pointer. - SystemStats* nullPointer = 0; - juce_free (nullPointer); - delete[] nullPointer; - delete nullPointer; + // quick test to make sure the run-time lib doesn't crash on freeing a null-pointer. + SystemStats* nullPointer = 0; + juce_free (nullPointer); + delete[] nullPointer; + delete nullPointer; + + // Some quick stream tests.. + int randomInt = Random::getSystemRandom().nextInt(); + int64 randomInt64 = Random::getSystemRandom().nextInt64(); + double randomDouble = Random::getSystemRandom().nextDouble(); + String randomString; + for (int i = 50; --i >= 0;) + randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff); + + MemoryOutputStream mo; + mo.writeInt (randomInt); + mo.writeIntBigEndian (randomInt); + mo.writeCompressedInt (randomInt); + mo.writeString (randomString); + mo.writeInt64 (randomInt64); + mo.writeInt64BigEndian (randomInt64); + mo.writeDouble (randomDouble); + mo.writeDoubleBigEndian (randomDouble); + + MemoryInputStream mi (mo.getData(), mo.getDataSize(), false); + jassert (mi.readInt() == randomInt); + jassert (mi.readIntBigEndian() == randomInt); + jassert (mi.readCompressedInt() == randomInt); + jassert (mi.readString() == randomString); + jassert (mi.readInt64() == randomInt64); + jassert (mi.readInt64BigEndian() == randomInt64); + jassert (mi.readDouble() == randomDouble); + jassert (mi.readDoubleBigEndian() == randomDouble); + } #endif // Now the real initialisation.. @@ -3869,6 +3899,11 @@ var::operator bool() const throw() return false; } +var::operator float() const throw() +{ + return (float) operator double(); +} + var::operator double() const throw() { switch (type) @@ -3882,7 +3917,7 @@ var::operator double() const throw() default: jassertfalse; break; } - return 0; + return 0.0; } const String var::toString() const throw() @@ -3942,7 +3977,7 @@ void var::writeToStream (OutputStream& output) const throw() case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break; case stringType: { - const int len = value.stringValue->copyToUTF8 (0, -1); + const int len = value.stringValue->copyToUTF8 (0); output.writeCompressedInt (len + 1); output.writeByte (5); uint8* const temp = (uint8*) juce_malloc (len); @@ -4049,12 +4084,14 @@ var::identifier::identifier (const String& name_) throw() : name (name_), hashCode (name_.hashCode()) { + jassert (name_.isNotEmpty()); } var::identifier::identifier (const char* const name_) throw() : name (name_), hashCode (name.hashCode()) { + jassert (name.isNotEmpty()); } var::identifier::~identifier() throw() @@ -4798,7 +4835,7 @@ static inline void II (uint32& a, const uint32 b, const uint32 c, const uint32 d a = rotateLeft (a, s) + b; } -void MD5::ProcessContext::transform (const uint8* const buffer) +void MD5::ProcessContext::transform (const uint8* const bufferToTransform) { uint32 a = state[0]; uint32 b = state[1]; @@ -4806,7 +4843,7 @@ void MD5::ProcessContext::transform (const uint8* const buffer) uint32 d = state[3]; uint32 x[16]; - decode (x, buffer, 64); + decode (x, bufferToTransform, 64); FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ @@ -5333,6 +5370,8 @@ int InputStream::readCompressedInt() if (read (&num, numBytes) != numBytes) return 0; + num = (int) swapIfBigEndian ((uint32) num); + if (negative) num = -num; } @@ -5346,7 +5385,7 @@ int64 InputStream::readInt64() char temp [8]; if (read (temp, 8) == 8) - return (int64) swapIfBigEndian (*(uint64*)temp); + return (int64) swapIfBigEndian (*(uint64*) temp); else return 0; } @@ -5356,7 +5395,7 @@ int64 InputStream::readInt64BigEndian() char temp [8]; if (read (temp, 8) == 8) - return (int64) swapIfLittleEndian (*(uint64*)temp); + return (int64) swapIfLittleEndian (*(uint64*) temp); else return 0; } @@ -5391,76 +5430,51 @@ double InputStream::readDoubleBigEndian() const String InputStream::readString() { - const int tempBufferSize = 256; - uint8 temp [tempBufferSize]; + MemoryBlock buffer (256); + uint8* data = (uint8*) buffer.getData(); int i = 0; - while ((temp [i++] = readByte()) != 0) + while ((data[i] = readByte()) != 0) { - if (i == tempBufferSize) + if (++i >= buffer.getSize()) { - // too big for our quick buffer, so read it in blocks.. - String result (String::fromUTF8 (temp, i)); - i = 0; - - for (;;) - { - if ((temp [i++] = readByte()) == 0) - { - result += String::fromUTF8 (temp, i - 1); - break; - } - else if (i == tempBufferSize) - { - result += String::fromUTF8 (temp, i); - i = 0; - } - } - - return result; + buffer.setSize (buffer.getSize() + 512); + data = (uint8*) buffer.getData(); } } - return String::fromUTF8 (temp, i - 1); + return String::fromUTF8 (data, i); } const String InputStream::readNextLine() { - String s; - const int maxChars = 256; - tchar buffer [maxChars]; - int charsInBuffer = 0; + MemoryBlock buffer (256); + uint8* data = (uint8*) buffer.getData(); + int i = 0; - while (! isExhausted()) + while ((data[i] = readByte()) != 0) { - const uint8 c = readByte(); - const int64 lastPos = getPosition(); - - if (c == '\n') - { + if (data[i] == '\n') break; - } - else if (c == '\r') + + if (data[i] == '\r') { + const int64 lastPos = getPosition(); + if (readByte() != '\n') setPosition (lastPos); break; } - buffer [charsInBuffer++] = c; - - if (charsInBuffer == maxChars) + if (++i >= buffer.getSize()) { - s.append (buffer, maxChars); - charsInBuffer = 0; + buffer.setSize (buffer.getSize() + 512); + data = (uint8*) buffer.getData(); } } - if (charsInBuffer > 0) - s.append (buffer, charsInBuffer); - - return s; + return String::fromUTF8 (data, i); } int InputStream::readIntoMemoryBlock (MemoryBlock& block, @@ -5633,6 +5647,7 @@ void OutputStream::writeCompressedInt (int value) numSigBytes |= 0x80; writeByte ((char) numSigBytes); + un = swapIfBigEndian (un); write (&un, numSigBytes); } @@ -6597,26 +6612,24 @@ int File::findChildFiles (OwnedArray& results, const String path (juce_addTrailingSeparator (fullPath)); String filename; - bool isDirectory, isHidden; + bool itemIsDirectory, itemIsHidden; - void* const handle = juce_findFileStart (path, - wildCardPattern, - filename, - &isDirectory, &isHidden, + void* const handle = juce_findFileStart (path, wildCardPattern, filename, + &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0); if (handle != 0) { do { - if (fileTypeMatches (whatToLookFor, isDirectory, isHidden) + if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden) && ! filename.containsOnly (T("."))) { results.add (new File (path + filename, 0)); ++total; } - } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0)); + } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0)); juce_findFileClose (handle); } @@ -6657,25 +6670,23 @@ int File::getNumberOfChildFiles (const int whatToLookFor, if (isDirectory()) { String filename; - bool isDirectory, isHidden; + bool itemIsDirectory, itemIsHidden; - void* const handle = juce_findFileStart (fullPath, - wildCardPattern, - filename, - &isDirectory, &isHidden, + void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename, + &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0); if (handle != 0) { do { - if (fileTypeMatches (whatToLookFor, isDirectory, isHidden) + if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden) && ! filename.containsOnly (T("."))) { ++count; } - } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0)); + } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0)); juce_findFileClose (handle); } @@ -6696,22 +6707,22 @@ bool File::containsSubDirectories() const throw() if (isDirectory()) { String filename; - bool isDirectory, isHidden; + bool itemIsDirectory, itemIsHidden; void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath), T("*"), filename, - &isDirectory, &isHidden, 0, 0, 0, 0); + &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0); if (handle != 0) { do { - if (isDirectory) + if (itemIsDirectory) { result = true; break; } - } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0)); + } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0)); juce_findFileClose (handle); } @@ -12733,13 +12744,13 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t while (--numExtraValues >= 0 && i < bufferSizeBytes) { - const uint8 c = buffer[i]; + const uint8 nextByte = buffer[i]; - if ((c & 0xc0) != 0x80) + if ((nextByte & 0xc0) != 0x80) break; n <<= 6; - n |= (c & 0x3f); + n |= (nextByte & 0x3f); ++i; } @@ -12771,34 +12782,34 @@ StringArray::StringArray (const StringArray& other) throw() addArray (other); } -StringArray::StringArray (const juce_wchar** const strings, +StringArray::StringArray (const juce_wchar** const initialStrings, const int numberOfStrings) throw() { for (int i = 0; i < numberOfStrings; ++i) - add (strings [i]); + add (initialStrings [i]); } -StringArray::StringArray (const char** const strings, +StringArray::StringArray (const char** const initialStrings, const int numberOfStrings) throw() { for (int i = 0; i < numberOfStrings; ++i) - add (strings [i]); + add (initialStrings [i]); } -StringArray::StringArray (const juce_wchar** const strings) throw() +StringArray::StringArray (const juce_wchar** const initialStrings) throw() { int i = 0; - while (strings[i] != 0) - add (strings [i++]); + while (initialStrings[i] != 0) + add (initialStrings [i++]); } -StringArray::StringArray (const char** const strings) throw() +StringArray::StringArray (const char** const initialStrings) throw() { int i = 0; - while (strings[i] != 0) - add (strings [i++]); + while (initialStrings[i] != 0) + add (initialStrings [i++]); } const StringArray& StringArray::operator= (const StringArray& other) throw() @@ -13687,12 +13698,12 @@ void XmlDocument::readQuotedString (String& result) throw() while (! outOfData) { - const tchar character = readNextChar(); + const tchar c = readNextChar(); - if (character == quote) + if (c == quote) break; - if (character == T('&')) + if (c == T('&')) { --input; readEntity (result); @@ -13805,9 +13816,9 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw { skipNextWhiteSpace(); - const tchar c = *input; + const tchar nextChar = *input; - if (c == T('"') || c == T('\'')) + if (nextChar == T('"') || nextChar == T('\'')) { XmlElement::XmlAttributeNode* const newAtt = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen), @@ -13998,13 +14009,13 @@ void XmlDocument::readChildElements (XmlElement* parent) throw() for (;;) { - const tchar c = *input; + const tchar nextChar = *input; - if (c == T('<') || c == T('&')) + if (nextChar == T('<') || nextChar == T('&')) { break; } - else if (c == 0) + else if (nextChar == 0) { setLastError ("unmatched tags", false); outOfData = true; @@ -14653,58 +14664,62 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, } } -const String XmlElement::createDocument (const String& dtd, +const String XmlElement::createDocument (const String& dtdToUse, const bool allOnOneLine, const bool includeXmlHeader, - const tchar* const encoding, + const tchar* const encodingType, const int lineWrapLength) const throw() { - String doc; - doc.preallocateStorage (1024); - - if (includeXmlHeader) - { - doc << " "; - else - doc += "\"?>\n\n"; - } - - if (dtd.isNotEmpty()) - { - if (allOnOneLine) - doc << dtd << " "; - else - doc << dtd << "\r\n"; - } - MemoryOutputStream mem (2048, 4096); - writeElementAsText (mem, allOnOneLine ? -1 : 0, lineWrapLength); + writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength); - return doc + String (mem.getData(), - mem.getDataSize()); + return String (mem.getData(), mem.getDataSize()); } -bool XmlElement::writeToFile (const File& f, - const String& dtd, - const tchar* const encoding, +void XmlElement::writeToStream (OutputStream& output, + const String& dtdToUse, + const bool allOnOneLine, + const bool includeXmlHeader, + const tchar* const encodingType, + const int lineWrapLength) const throw() +{ + if (includeXmlHeader) + { + output << " "; + else + output << "\"?>\r\n\r\n"; + } + + if (dtdToUse.isNotEmpty()) + { + output << dtdToUse; + + if (allOnOneLine) + output << " "; + else + output << "\r\n"; + } + + writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength); +} + +bool XmlElement::writeToFile (const File& file, + const String& dtdToUse, + const tchar* const encodingType, const int lineWrapLength) const throw() { - if (f.hasWriteAccess()) + if (file.hasWriteAccess()) { - const File tempFile (f.getNonexistentSibling()); + const File tempFile (file.getNonexistentSibling()); FileOutputStream* const out = tempFile.createOutputStream(); if (out != 0) { - *out << "\r\n\r\n" - << dtd << "\r\n"; - - writeElementAsText (*out, 0, lineWrapLength); + writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength); delete out; if (! tempFile.exists()) @@ -14713,7 +14728,7 @@ bool XmlElement::writeToFile (const File& f, int i; for (i = 5; --i >= 0;) { - if (tempFile.moveFileTo (f)) + if (tempFile.moveFileTo (file)) return true; Thread::sleep (100); @@ -15763,7 +15778,7 @@ void Thread::stopThread (const int timeOutMilliseconds) throw() threadHandle_ = 0; threadId_ = 0; - const ScopedLock sl (runningThreadsLock); + const ScopedLock sl2 (runningThreadsLock); runningThreads.removeValue (this); } } @@ -15982,7 +15997,7 @@ void ThreadPool::addJob (ThreadPoolJob* const job) while (--n >= 0 && ! startedOne) { - for (int i = numThreads; --i >= 0;) + for (i = numThreads; --i >= 0;) { if (! threads[i]->isThreadRunning()) { @@ -16282,8 +16297,8 @@ void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client) { const ScopedUnlock ul (listLock); // unlock first to get the order right.. - const ScopedLock sl1 (callbackLock); - const ScopedLock sl2 (listLock); + const ScopedLock sl2 (callbackLock); + const ScopedLock sl3 (listLock); clients.removeValue (client); } @@ -16298,10 +16313,10 @@ int TimeSliceThread::getNumClients() const throw() return clients.size(); } -TimeSliceClient* TimeSliceThread::getClient (const int index) const throw() +TimeSliceClient* TimeSliceThread::getClient (const int i) const throw() { const ScopedLock sl (listLock); - return clients [index]; + return clients [i]; } void TimeSliceThread::run() @@ -16316,7 +16331,7 @@ void TimeSliceThread::run() const ScopedLock sl (callbackLock); { - const ScopedLock sl (listLock); + const ScopedLock sl2 (listLock); if (clients.size() > 0) { @@ -16370,26 +16385,26 @@ BEGIN_JUCE_NAMESPACE class ValueTreeSetPropertyAction : public UndoableAction { public: - ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& id_, + ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_, const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_) throw() - : target (target_), id (id_), newValue (newValue_), + : target (target_), name (name_), newValue (newValue_), isAddingNewProperty (isAddingNewProperty_), isDeletingProperty (isDeletingProperty_) { if (! isAddingNewProperty) - oldValue = target_->getProperty (id_); + oldValue = target_->getProperty (name_); } ~ValueTreeSetPropertyAction() {} bool perform() { - jassert (! (isAddingNewProperty && target->hasProperty (id))); + jassert (! (isAddingNewProperty && target->hasProperty (name))); if (isDeletingProperty) - target->removeProperty (id, 0); + target->removeProperty (name, 0); else - target->setProperty (id, newValue, 0); + target->setProperty (name, newValue, 0); return true; } @@ -16397,9 +16412,9 @@ public: bool undo() { if (isAddingNewProperty) - target->removeProperty (id, 0); + target->removeProperty (name, 0); else - target->setProperty (id, oldValue, 0); + target->setProperty (name, oldValue, 0); return true; } @@ -16411,7 +16426,7 @@ public: private: const ValueTree::SharedObjectPtr target; - const var::identifier id; + const var::identifier name; const var newValue; var oldValue; const bool isAddingNewProperty, isDeletingProperty; @@ -16480,7 +16495,7 @@ ValueTree::SharedObject::SharedObject (const SharedObject& other) throw() for (i = 0; i < other.properties.size(); ++i) { const Property* const p = other.properties.getUnchecked(i); - properties.add (new Property (p->id, p->value)); + properties.add (new Property (p->name, p->value)); } for (i = 0; i < other.children.size(); ++i) @@ -16500,8 +16515,8 @@ ValueTree::SharedObject::~SharedObject() throw() } } -ValueTree::SharedObject::Property::Property (const var::identifier& id_, const var& value_) throw() - : id (id_), value (value_) +ValueTree::SharedObject::Property::Property (const var::identifier& name_, const var& value_) throw() + : name (name_), value (value_) { } @@ -16513,7 +16528,7 @@ void ValueTree::SharedObject::sendPropertyChangeMessage() { ValueTree::Listener* const l = listeners[i]; if (l != 0) - l->ValueTreePropertyChanged (v); + l->valueTreePropertyChanged (v); } } @@ -16525,7 +16540,7 @@ void ValueTree::SharedObject::sendChildChangeMessage() { ValueTree::Listener* const l = listeners[i]; if (l != 0) - l->ValueTreeChildrenChanged (v); + l->valueTreeChildrenChanged (v); } } @@ -16534,7 +16549,6 @@ void ValueTree::SharedObject::sendParentChangeMessage() for (int j = children.size(); --j >= 0;) { SharedObject* const t = children[j]; - if (t != 0) t->sendParentChangeMessage(); } @@ -16543,7 +16557,7 @@ void ValueTree::SharedObject::sendParentChangeMessage() { ValueTree::Listener* const l = listeners[i]; if (l != 0) - l->ValueTreeParentChanged(); + l->valueTreeParentChanged(); } } @@ -16552,7 +16566,7 @@ const var ValueTree::SharedObject::getProperty (const var::identifier& name) con for (int i = properties.size(); --i >= 0;) { const Property* const p = properties.getUnchecked(i); - if (p->id == name) + if (p->name == name) return p->value; } @@ -16565,7 +16579,7 @@ void ValueTree::SharedObject::setProperty (const var::identifier& name, const va { Property* const p = properties.getUnchecked(i); - if (p->id == name) + if (p->name == name) { if (p->value != newValue) { @@ -16598,7 +16612,7 @@ void ValueTree::SharedObject::setProperty (const var::identifier& name, const va bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const throw() { for (int i = properties.size(); --i >= 0;) - if (properties.getUnchecked(i)->id == name) + if (properties.getUnchecked(i)->name == name) return true; return false; @@ -16610,7 +16624,7 @@ void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoM { Property* const p = properties.getUnchecked(i); - if (p->id == name) + if (p->name == name) { if (undoManager == 0) { @@ -16637,17 +16651,26 @@ void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManage else { for (int i = properties.size(); --i >= 0;) - undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getUnchecked(i)->id, var(), false, true)); + undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getUnchecked(i)->name, var(), false, true)); } } -ValueTree ValueTree::SharedObject::getChildWithName (const String& type) const throw() +ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const throw() { for (int i = 0; i < children.size(); ++i) - if (children.getUnchecked(i)->type == type) + if (children.getUnchecked(i)->type == typeToMatch) return (SharedObject*) children.getUnchecked(i); - return 0; + return (SharedObject*) 0; +} + +ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const throw() +{ + for (int i = 0; i < children.size(); ++i) + if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue) + return (SharedObject*) children.getUnchecked(i); + + return (SharedObject*) 0; } bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const throw() @@ -16797,7 +16820,9 @@ const var ValueTree::getProperty (const var::identifier& name) const throw() void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager) throw() { - if (object != 0) + jassert (name.name.isNotEmpty()); + + if (object != 0 && name.name.isNotEmpty()) object->setProperty (name, newValue, undoManager); } @@ -16826,7 +16851,7 @@ int ValueTree::getNumProperties() const throw() const var::identifier ValueTree::getPropertyName (int index) const throw() { const SharedObject::Property* const p = (object == 0) ? 0 : object->properties [index]; - return p != 0 ? p->id : var::identifier (String::empty); + return p != 0 ? p->name : var::identifier (String::empty); } int ValueTree::getNumChildren() const throw() @@ -16844,6 +16869,11 @@ ValueTree ValueTree::getChildWithName (const String& type) const throw() return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0); } +ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const throw() +{ + return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0); +} + bool ValueTree::isAChildOf (const ValueTree& possibleParent) const throw() { return object != 0 && object->isAChildOf (possibleParent.object); @@ -16898,7 +16928,7 @@ XmlElement* ValueTree::SharedObject::createXml() const throw() jassert (! p->value.isObject()); // DynamicObjects can't be stored as XML! - xml->setAttribute (p->id.name, p->value.toString()); + xml->setAttribute (p->name.name, p->value.toString()); } for (i = 0; i < children.size(); ++i) @@ -16929,6 +16959,62 @@ ValueTree ValueTree::fromXml (const XmlElement& xml) throw() return v; } +void ValueTree::writeToStream (OutputStream& output) throw() +{ + output.writeString (getType()); + + const int numProps = getNumProperties(); + output.writeCompressedInt (numProps); + + int i; + for (i = 0; i < numProps; ++i) + { + const var::identifier name (getPropertyName(i)); + output.writeString (name.name); + getProperty(name).writeToStream (output); + } + + const int numChildren = getNumChildren(); + output.writeCompressedInt (numChildren); + + for (i = 0; i < numChildren; ++i) + getChild (i).writeToStream (output); +} + +ValueTree ValueTree::readFromStream (InputStream& input) throw() +{ + String type (input.readString()); + + if (type.isEmpty()) + return ValueTree ((SharedObject*) 0); + + ValueTree v (type); + + const int numProps = input.readCompressedInt(); + + if (numProps < 0) + { + jassertfalse // trying to read corrupted data! + return v; + } + + int i; + for (i = 0; i < numProps; ++i) + { + const String name (input.readString()); + jassert (name.isNotEmpty()); + const var value (var::readFromStream (input)); + v.setProperty (name, value, 0); + } + + const int numChildren = input.readCompressedInt(); + + for (i = 0; i < numChildren; ++i) + v.addChild (readFromStream (input), -1, 0); + + return v; +} + END_JUCE_NAMESPACE /********* End of inlined file: juce_ValueTree.cpp *********/ @@ -18567,17 +18653,17 @@ int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo, if (filesToAvoid != 0) { - const File** files = filesToAvoid; + const File** avoid = filesToAvoid; - while (*files != 0) + while (*avoid != 0) { - if (f == **files) + if (f == **avoid) { needsAvoiding = true; break; } - ++files; + ++avoid; } } @@ -19750,7 +19836,7 @@ void AudioCDReader::refreshTrackLengths() if (r != 0) { - sample += r->lengthInSamples; + sample += (int) r->lengthInSamples; delete r; } } @@ -19987,7 +20073,7 @@ void AudioFormatReader::readMaxLevels (int64 startSampleInFile, if (usesFloatingPointData) { - float lmin = 1.0e6; + float lmin = 1.0e6f; float lmax = -lmin; float rmin = lmin; float rmax = lmax; @@ -20814,6 +20900,8 @@ void AudioThumbnail::clear() void AudioThumbnail::loadFrom (InputStream& input) { + const ScopedLock sl (readerLock); + data.setSize (0); input.readIntoMemoryBlock (data); @@ -20840,14 +20928,14 @@ void AudioThumbnail::saveTo (OutputStream& output) const swapEndiannessIfNeeded (d); } -bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& reader) +bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader) { AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData(); - d->totalSamples = reader.lengthInSamples; - d->numChannels = jmin (2, reader.numChannels); + d->totalSamples = fileReader.lengthInSamples; + d->numChannels = jmin (2, fileReader.numChannels); d->numFinishedSamples = 0; - d->sampleRate = roundDoubleToInt (reader.sampleRate); + d->sampleRate = roundDoubleToInt (fileReader.sampleRate); d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1; data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2); @@ -20858,7 +20946,7 @@ bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& reader) return d->totalSamples > 0; } -bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& reader) +bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader) { AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData(); @@ -20866,7 +20954,7 @@ bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& reader) { const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples); - generateSection (reader, + generateSection (fileReader, d->numFinishedSamples, numToDo); @@ -20896,7 +20984,7 @@ double AudioThumbnail::getTotalLength() const throw() return 0.0; } -void AudioThumbnail::generateSection (AudioFormatReader& reader, +void AudioThumbnail::generateSection (AudioFormatReader& fileReader, int64 startSample, int numSamples) { @@ -20916,12 +21004,12 @@ void AudioThumbnail::generateSection (AudioFormatReader& reader, float lowestLeft, highestLeft, lowestRight, highestRight; - reader.readMaxLevels (sourceStart, - sourceEnd - sourceStart, - lowestLeft, - highestLeft, - lowestRight, - highestRight); + fileReader.readMaxLevels (sourceStart, + sourceEnd - sourceStart, + lowestLeft, + highestLeft, + lowestRight, + highestRight); int n = i * 2; @@ -21042,7 +21130,7 @@ void AudioThumbnail::refillCache (const int numSamples, { for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum) { - char* const data = getChannelData (channelNum); + char* const channelData = getChannelData (channelNum); char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2; const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample; @@ -21055,7 +21143,7 @@ void AudioThumbnail::refillCache (const int numSamples, { const int nextSample = roundDoubleToInt ((startTime + timePerPixel) * timeToThumbSampleFactor); - if (sample >= 0 && data != 0) + if (sample >= 0 && channelData != 0) { char mx = -128; char mn = 127; @@ -21066,8 +21154,8 @@ void AudioThumbnail::refillCache (const int numSamples, break; const int n = sample << 1; - const char sampMin = data [n]; - const char sampMax = data [n + 1]; + const char sampMin = channelData [n]; + const char sampMax = channelData [n + 1]; if (sampMin < mn) mn = sampMin; @@ -22164,13 +22252,13 @@ class WavAudioFormatWriter : public AudioFormatWriter public: WavAudioFormatWriter (OutputStream* const out, - const double sampleRate, + const double sampleRate_, const unsigned int numChannels_, const int bits, const StringPairArray& metadataValues) : AudioFormatWriter (out, wavFormatName, - sampleRate, + sampleRate_, numChannels_, bits), lengthInSamples (0), @@ -23861,10 +23949,10 @@ void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& inf jassert (sampsInBuffer >= 0); } -void ResamplingAudioSource::createLowPass (const double ratio) +void ResamplingAudioSource::createLowPass (const double frequencyRatio) { - const double proportionalRate = (ratio > 1.0) ? 0.5 / ratio - : 0.5 * ratio; + const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio + : 0.5 * frequencyRatio; const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate)); const double nSquared = n * n; @@ -26762,9 +26850,9 @@ uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const thr return d; } -MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer) throw() - : buffer (buffer), - data (buffer.elements) +MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw() + : buffer (buffer_), + data (buffer_.elements) { } @@ -36396,8 +36484,8 @@ private: }; }; -GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner) - : AudioProcessorEditor (owner) +GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_) + : AudioProcessorEditor (owner_) { setOpaque (true); @@ -36405,16 +36493,16 @@ GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const Array params; - const int numParams = owner->getNumParameters(); + const int numParams = owner_->getNumParameters(); int totalHeight = 0; for (int i = 0; i < numParams; ++i) { - String name (owner->getParameterName (i)); + String name (owner_->getParameterName (i)); if (name.trim().isEmpty()) name = "Unnamed"; - ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner, i); + ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i); params.add (pc); totalHeight += pc->getPreferredHeight(); } @@ -39943,7 +40031,7 @@ int Component::runModalLoop() return returnValue; } -void Component::enterModalState (const bool takeKeyboardFocus) +void Component::enterModalState (const bool takeKeyboardFocus_) { // if component methods are being called from threads other than the message // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe. @@ -39962,7 +40050,7 @@ void Component::enterModalState (const bool takeKeyboardFocus) flags.currentlyModalFlag = true; setVisible (true); - if (takeKeyboardFocus) + if (takeKeyboardFocus_) grabKeyboardFocus(); } } @@ -41691,9 +41779,9 @@ bool Component::getWantsKeyboardFocus() const throw() return flags.wantsFocusFlag && ! flags.isDisabledFlag; } -void Component::setFocusContainer (const bool isFocusContainer) throw() +void Component::setFocusContainer (const bool shouldBeFocusContainer) throw() { - flags.isFocusContainerFlag = isFocusContainer; + flags.isFocusContainerFlag = shouldBeFocusContainer; } bool Component::isFocusContainer() const throw() @@ -43795,11 +43883,11 @@ END_JUCE_NAMESPACE BEGIN_JUCE_NAMESPACE -ShapeButton::ShapeButton (const String& text, +ShapeButton::ShapeButton (const String& text_, const Colour& normalColour_, const Colour& overColour_, const Colour& downColour_) - : Button (text), + : Button (text_), normalColour (normalColour_), overColour (overColour_), downColour (downColour_), @@ -44243,11 +44331,11 @@ CodeDocument::Position::Position (const CodeDocument* const ownerDocument, } CodeDocument::Position::Position (const CodeDocument* const ownerDocument, - const int characterPos) throw() + const int characterPos_) throw() : owner (const_cast (ownerDocument)), positionMaintained (false) { - setPosition (characterPos); + setPosition (characterPos_); } CodeDocument::Position::Position (const Position& other) throw() @@ -46777,12 +46865,12 @@ void ComboBox::addSectionHeading (const String& headingName) throw() } void ComboBox::setItemEnabled (const int itemId, - const bool isEnabled) throw() + const bool shouldBeEnabled) throw() { ItemInfo* const item = getItemForId (itemId); if (item != 0) - item->isEnabled = isEnabled; + item->isEnabled = shouldBeEnabled; } void ComboBox::changeItemText (const int itemId, @@ -54100,8 +54188,8 @@ const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_"); class ToolbarSpacerComp : public ToolbarItemComponent { public: - ToolbarSpacerComp (const int itemId, const float fixedSize_, const bool drawBar_) - : ToolbarItemComponent (itemId, String::empty, false), + ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_) + : ToolbarItemComponent (itemId_, String::empty, false), fixedSize (fixedSize_), drawBar (drawBar_) { @@ -56800,27 +56888,27 @@ TreeViewItem* TreeViewItem::getItemOnRow (int index) throw() return 0; } -TreeViewItem* TreeViewItem::findItemRecursively (int y) throw() +TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw() { - if (((unsigned int) y) < (unsigned int) totalHeight) + if (((unsigned int) targetY) < (unsigned int) totalHeight) { const int h = itemHeight; - if (y < h) + if (targetY < h) return this; if (isOpen()) { - y -= h; + targetY -= h; for (int i = 0; i < subItems.size(); ++i) { TreeViewItem* const ti = subItems.getUnchecked(i); - if (y < ti->totalHeight) - return ti->findItemRecursively (y); + if (targetY < ti->totalHeight) + return ti->findItemRecursively (targetY); - y -= ti->totalHeight; + targetY -= ti->totalHeight; } } } @@ -58686,7 +58774,7 @@ FileSearchPathListComponent::FileSearchPathListComponent() { Path arrowPath; - arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0, 40.0f, 100.0f, 50.0f); + arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f); DrawablePath arrowImage; arrowImage.setFill (Colours::black.withAlpha (0.4f)); arrowImage.setPath (arrowPath); @@ -59245,9 +59333,9 @@ BEGIN_JUCE_NAMESPACE WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns, const String& directoryWildcardPatterns, - const String& description) - : FileFilter (description.isEmpty() ? fileWildcardPatterns - : (description + T(" (") + fileWildcardPatterns + T(")"))) + const String& description_) + : FileFilter (description_.isEmpty() ? fileWildcardPatterns + : (description_ + T(" (") + fileWildcardPatterns + T(")"))) { parse (fileWildcardPatterns, fileWildcards); parse (directoryWildcardPatterns, directoryWildcards); @@ -64743,8 +64831,8 @@ void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar, Image im (Image::ARGB, width, height, true); { - Graphics g (im); - drawGlassLozenge (g, 1.0f, 1.0f, + Graphics g2 (im); + drawGlassLozenge (g2, 1.0f, 1.0f, (float) (width - 2), (float) (height - 2), foreground, @@ -66676,7 +66764,7 @@ Button* LookAndFeel::createFileBrowserGoUpButton() DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground); Path arrowPath; - arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0, 40.0f, 100.0f, 50.0f); + arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f); DrawablePath arrowImage; arrowImage.setFill (Colours::black.withAlpha (0.4f)); @@ -69091,12 +69179,12 @@ private: do { ++numColumns; - totalW = workOutBestSize (numColumns, maxMenuW); + totalW = workOutBestSize (maxMenuW); if (totalW > maxMenuW) { numColumns = jmax (1, numColumns - 1); - totalW = workOutBestSize (numColumns, maxMenuW); // to update col widths + totalW = workOutBestSize (maxMenuW); // to update col widths break; } else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH) @@ -69114,7 +69202,7 @@ private: height = actualH + borderSize * 2; } - int workOutBestSize (const int numColumns, const int maxMenuW) + int workOutBestSize (const int maxMenuW) { int totalW = 0; contentHeight = 0; @@ -72915,10 +73003,10 @@ void BubbleComponent::setPosition (Component* componentToPointTo) setPosition (Rectangle (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight())); } -void BubbleComponent::setPosition (const int arrowTipX, - const int arrowTipY) +void BubbleComponent::setPosition (const int arrowTipX_, + const int arrowTipY_) { - setPosition (Rectangle (arrowTipX, arrowTipY, 1, 1)); + setPosition (Rectangle (arrowTipX_, arrowTipY_, 1, 1)); } void BubbleComponent::setPosition (const Rectangle& rectangleToPointTo) @@ -73141,9 +73229,9 @@ public: { } - const String getTextFromValue (double currentValue) + const String getTextFromValue (double value) { - return String::formatted (T("%02X"), (int)currentValue); + return String::formatted (T("%02X"), (int) value); } double getValueFromText (const String& text) @@ -75350,13 +75438,13 @@ void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse) } } -void OpenGLComponent::shareWith (OpenGLContext* context) +void OpenGLComponent::shareWith (OpenGLContext* c) { - if (contextToShareListsWith != context) + if (contextToShareListsWith != c) { const ScopedLock sl (contextLock); deleteContext(); - contextToShareListsWith = context; + contextToShareListsWith = c; } } @@ -80282,8 +80370,8 @@ FillType::FillType (const Colour& colour_) throw() { } -FillType::FillType (const ColourGradient& gradient) throw() - : colour (0xff000000), gradient (new ColourGradient (gradient)), image (0) +FillType::FillType (const ColourGradient& gradient_) throw() + : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0) { } @@ -81520,7 +81608,7 @@ void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const Affin // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the // time-being, this just fills it with the average colour.. - writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5)); + writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f)); out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n"; out << "grestore\n"; @@ -81815,7 +81903,7 @@ public: if (! transform.isIdentity()) { const Line l (x2, y2, x1, y1); - const Point p3 = l.getPointAlongLine (0.0, 100.0f); + const Point p3 = l.getPointAlongLine (0.0f, 100.0f); float x3 = p3.getX(); float y3 = p3.getY(); @@ -81891,9 +81979,9 @@ public: gy1 (gradient.y1) { jassert (numEntries_ >= 0); - const float dx = gradient.x1 - gradient.x2; - const float dy = gradient.y1 - gradient.y2; - maxDist = dx * dx + dy * dy; + const float gdx = gradient.x1 - gradient.x2; + const float gdy = gradient.y1 - gradient.y2; + maxDist = gdx * gdx + gdy * gdy; invScale = numEntries / sqrt (maxDist); jassert (roundDoubleToInt (sqrt (maxDist) * invScale) <= numEntries); } @@ -81968,8 +82056,8 @@ class GradientEdgeTableRenderer : public GradientType { public: GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform, - const PixelARGB* const lookupTable, const int numEntries) throw() - : GradientType (gradient, transform, lookupTable, numEntries - 1), + const PixelARGB* const lookupTable_, const int numEntries_) throw() + : GradientType (gradient, transform, lookupTable_, numEntries_ - 1), destData (destData_) { } @@ -82091,8 +82179,8 @@ public: void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw() { jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width); - SrcPixelType* sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y - yOffset); - uint8* mask = (uint8*) (sourceLineStart + x - xOffset); + SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset); + uint8* mask = (uint8*) (s + x - xOffset); if (sizeof (SrcPixelType) == sizeof (PixelARGB)) mask += PixelARGB::indexA; @@ -83471,62 +83559,24 @@ Drawable* Drawable::createFromImageFile (const File& file) return d; } -Drawable* Drawable::readFromBinaryStream (InputStream& input) +Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw() { - char header[8]; - if (input.read (header, sizeof (header)) != sizeof (header)) - return 0; + Drawable* d = DrawablePath::createFromValueTree (tree); - DrawableComposite* result = 0; - - if (memcmp (header, "JuceDrw1", sizeof (header)) == 0) + if (d == 0) { - result = new DrawableComposite(); + d = DrawableComposite::createFromValueTree (tree); - if (! result->readBinary (input)) - deleteAndZero (result); + if (d == 0) + { + d = DrawableImage::createFromValueTree (tree); + + if (d == 0) + d = DrawableText::createFromValueTree (tree); + } } - return result; -} - -bool Drawable::writeToBinaryStream (OutputStream& output) const -{ - output.write ("JuceDrw1", 8); - return writeBinary (output); -} - -Drawable* Drawable::readFromXml (const XmlElement& xml) -{ - DrawableComposite* result = 0; - - if (xml.hasTagName (T("JuceDrawable"))) - { - result = new DrawableComposite(); - - if (! result->readXml (xml)) - deleteAndZero (result); - } - - return result; -} - -XmlElement* Drawable::createXml() const -{ - if (dynamic_cast (this) == 0) - { - DrawableComposite tempDC; - tempDC.insertDrawable (const_cast (this)); - XmlElement* result = tempDC.createXml(); - tempDC.removeDrawable (0, false); - return result; - } - else - { - XmlElement* e = new XmlElement (T("JuceDrawable")); - writeXml (*e); - return e; - } + return d; } END_JUCE_NAMESPACE @@ -83685,183 +83735,18 @@ Drawable* DrawableComposite::createCopy() const return dc; } -const char juce_drawableCompositeTransformFlag = 't'; -const char juce_drawableCompositeBinaryType = 'C'; -const char juce_drawablePathBinaryType = 'P'; -const char juce_drawableImageBinaryType = 'I'; -const char juce_drawableTextBinaryType = 'T'; - -bool DrawableComposite::readBinary (InputStream& input) +ValueTree DrawableComposite::createValueTree() const throw() { - AffineTransform transform; + ValueTree v (T("Group")); - while (! input.isExhausted()) - { - const int n = input.readByte(); + if (getName().isNotEmpty()) + v.setProperty ("id", getName(), 0); - if (n == 0) - break; - - if (n == juce_drawableCompositeTransformFlag) - { - float f[6]; - for (int i = 0; i < 6; ++i) - f[i] = input.readFloat(); - - transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]); - } - else - { - Drawable* d = 0; - - switch (n) - { - case juce_drawableCompositeBinaryType: d = new DrawableComposite(); break; - case juce_drawablePathBinaryType: d = new DrawablePath(); break; - case juce_drawableImageBinaryType: d = new DrawableImage(); break; - case juce_drawableTextBinaryType: d = new DrawableText(); break; - default: jassertfalse; return false; - } - - d->setName (input.readString()); - - if (! d->readBinary (input)) - { - delete d; - return false; - } - - insertDrawable (d, transform); - transform = AffineTransform::identity; - } - } - - return true; -} - -bool DrawableComposite::writeBinary (OutputStream& output) const -{ for (int i = 0; i < drawables.size(); ++i) { - AffineTransform* transform = transforms.getUnchecked(i); - - if (transform != 0) - { - output.writeByte (juce_drawableCompositeTransformFlag); - output.writeFloat (transform->mat00); - output.writeFloat (transform->mat01); - output.writeFloat (transform->mat02); - output.writeFloat (transform->mat10); - output.writeFloat (transform->mat11); - output.writeFloat (transform->mat12); - } - Drawable* const d = drawables.getUnchecked(i); - char typeFlag; - - if (dynamic_cast (d) != 0) - typeFlag = juce_drawableCompositeBinaryType; - else if (dynamic_cast (d) != 0) - typeFlag = juce_drawablePathBinaryType; - else if (dynamic_cast (d) != 0) - typeFlag = juce_drawableImageBinaryType; - else if (dynamic_cast (d) != 0) - typeFlag = juce_drawableTextBinaryType; - else - { - jassertfalse; - continue; - } - - output.writeByte (typeFlag); - output.writeString (d->getName()); - d->writeBinary (output); - } - - output.writeByte (0); - return true; -} - -const tchar* juce_drawableCompositeXmlTag = T("Group"); -const tchar* juce_drawablePathXmlTag = T("Path"); -const tchar* juce_drawableImageXmlTag = T("Image"); -const tchar* juce_drawableTextXmlTag = T("Text"); - -bool DrawableComposite::readXml (const XmlElement& xml) -{ - forEachXmlChildElement (xml, e) - { - Drawable* d = 0; - - if (e->hasTagName (juce_drawableCompositeXmlTag)) - d = new DrawableComposite(); - else if (e->hasTagName (juce_drawablePathXmlTag)) - d = new DrawablePath(); - else if (e->hasTagName (juce_drawableImageXmlTag)) - d = new DrawableImage(); - else if (e->hasTagName (juce_drawableTextXmlTag)) - d = new DrawableText(); - else - { - jassertfalse; - return false; - } - - d->setName (e->getStringAttribute (T("id"))); - - if (! d->readXml (*e)) - { - jassertfalse; - delete d; - return false; - } - - AffineTransform transform; - const String transformAtt (e->getStringAttribute (T("transform"))); - - if (transformAtt.isNotEmpty()) - { - StringArray tokens; - tokens.addTokens (transformAtt.trim(), false); - tokens.removeEmptyStrings (true); - - if (tokens.size() == 6) - { - float f[6]; - for (int i = 0; i < 6; ++i) - f[i] = (float) tokens[i].getDoubleValue(); - - transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]); - } - } - - insertDrawable (d, transform); - } - - return true; -} - -void DrawableComposite::writeXml (XmlElement& xml) const -{ - for (int i = 0; i < drawables.size(); ++i) - { - XmlElement* e = 0; - Drawable* const d = drawables.getUnchecked(i); - - if (dynamic_cast (d) != 0) - e = new XmlElement (juce_drawableCompositeXmlTag); - else if (dynamic_cast (d) != 0) - e = new XmlElement (juce_drawablePathXmlTag); - else if (dynamic_cast (d) != 0) - e = new XmlElement (juce_drawableImageXmlTag); - else if (dynamic_cast (d) != 0) - e = new XmlElement (juce_drawableTextXmlTag); - else - { - jassertfalse; - continue; - } + ValueTree child (d->createValueTree()); AffineTransform* transform = transforms.getUnchecked(i); @@ -83871,16 +83756,54 @@ void DrawableComposite::writeXml (XmlElement& xml) const t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " " << transform->mat10 << " " << transform->mat11 << " " << transform->mat12; - e->setAttribute (T("transform"), t); + child.setProperty ("transform", t, 0); } - if (d->getName().isNotEmpty()) - e->setAttribute (T("id"), d->getName()); - - d->writeXml (*e); - - xml.addChildElement (e); + v.addChild (child, -1, 0); } + + return v; +} + +DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw() +{ + if (! tree.hasType ("Group")) + return 0; + + DrawableComposite* dc = new DrawableComposite(); + dc->setName (tree ["id"]); + + for (int i = 0; i < tree.getNumChildren(); ++i) + { + ValueTree childTree (tree.getChild (i)); + Drawable* d = Drawable::createFromValueTree (childTree); + + if (d != 0) + { + AffineTransform transform; + const String transformAtt (childTree ["transform"].toString()); + + if (transformAtt.isNotEmpty()) + { + StringArray tokens; + tokens.addTokens (transformAtt.trim(), false); + tokens.removeEmptyStrings (true); + + if (tokens.size() == 6) + { + float f[6]; + for (int j = 0; j < 6; ++j) + f[j] = (float) tokens[j].getDoubleValue(); + + transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]); + } + } + + dc->insertDrawable (d, transform); + } + } + + return dc; } END_JUCE_NAMESPACE @@ -84008,71 +83931,18 @@ Drawable* DrawableImage::createCopy() const return di; } -bool DrawableImage::readBinary (InputStream& input) +ValueTree DrawableImage::createValueTree() const throw() { - opacity = input.readFloat(); - overlayColour = Colour (input.readInt()); + ValueTree v (T("Image")); - const int dataLen = input.readInt(); + if (getName().isNotEmpty()) + v.setProperty ("id", getName(), 0); - if (dataLen > 0) - { - MemoryBlock imageData; - input.readIntoMemoryBlock (imageData, dataLen); - - Image* im = ImageFileFormat::loadFrom (imageData.getData(), imageData.getSize()); - if (im == 0) - return false; - - setImage (im, true); - } - - return true; -} - -bool DrawableImage::writeBinary (OutputStream& output) const -{ - MemoryOutputStream imageData; - - if (image != 0) - { - PNGImageFormat pngFormat; - if (! pngFormat.writeImageToStream (*image, imageData)) - return false; - } - - output.writeFloat (opacity); - output.writeInt (overlayColour.getARGB()); - output.writeInt (imageData.getDataSize()); - output.write (imageData.getData(), imageData.getDataSize()); - return true; -} - -bool DrawableImage::readXml (const XmlElement& xml) -{ - opacity = (float) xml.getDoubleAttribute (T("opacity"), 1.0); - overlayColour = Colour (xml.getStringAttribute (T("overlay"), T("0")).getHexValue32()); - - MemoryBlock imageData; - if (imageData.fromBase64Encoding (xml.getAllSubText())) - { - Image* const im = ImageFileFormat::loadFrom (imageData.getData(), imageData.getSize()); - if (im == 0) - return false; - - setImage (im, true); - } - - return true; -} - -void DrawableImage::writeXml (XmlElement& xml) const -{ if (opacity < 1.0f) - xml.setAttribute (T("opacity"), (double) opacity); + v.setProperty ("opacity", (double) opacity, 0); if (! overlayColour.isTransparent()) - xml.setAttribute (T("overlay"), String::toHexString ((int) overlayColour.getARGB())); + v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0); if (image != 0) { @@ -84085,9 +83955,35 @@ void DrawableImage::writeXml (XmlElement& xml) const for (int i = (base64.length() & ~127); i >= 0; i -= 128) base64 = base64.substring (0, i) + "\n" + base64.substring (i); - xml.addTextElement (base64); + v.setProperty ("data", base64, 0); } } + + return v; +} + +DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw() +{ + if (! tree.hasType ("Image")) + return 0; + + DrawableImage* di = new DrawableImage(); + + di->setName (tree ["id"]); + di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f; + di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32()); + + MemoryBlock imageData; + if (imageData.fromBase64Encoding (tree ["data"])) + { + Image* const im = ImageFileFormat::loadFrom (imageData.getData(), imageData.getSize()); + if (im == 0) + return false; + + di->setImage (im, true); + } + + return di; } END_JUCE_NAMESPACE @@ -84137,13 +84033,15 @@ void DrawablePath::setStrokeThickness (const float newThickness) throw() void DrawablePath::render (const Drawable::RenderingContext& context) const { - FillType f (mainFill); - if (f.isGradient()) - f.gradient->multiplyOpacity (context.opacity); + { + FillType f (mainFill); + if (f.isGradient()) + f.gradient->multiplyOpacity (context.opacity); - f.transform = f.transform.followedBy (context.transform); - context.g.setFillType (f); - context.g.fillPath (path, context.transform); + f.transform = f.transform.followedBy (context.transform); + context.g.setFillType (f); + context.g.fillPath (path, context.transform); + } if (strokeType.getStrokeThickness() > 0.0f) { @@ -84189,226 +84087,120 @@ Drawable* DrawablePath::createCopy() const return dp; } -static const FillType readColourFromBinary (InputStream& input) +static const FillType readFillTypeFromTree (const ValueTree& v) { - switch (input.readByte()) + const String type (v["type"].toString()); + + if (type.equalsIgnoreCase (T("solid"))) { - case 1: - return FillType (Colour ((uint32) input.readInt())); + const String colour (v ["colour"].toString()); + return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000 + : (uint32) colour.getHexValue32())); + } + else if (type.equalsIgnoreCase ("gradient")) + { + ColourGradient g; + g.x1 = v["x1"]; + g.y1 = v["y1"]; + g.x2 = v["x2"]; + g.y2 = v["y2"]; + g.isRadial = v["radial"]; - case 2: - { - ColourGradient g; - g.x1 = input.readFloat(); - g.y1 = input.readFloat(); - g.x2 = input.readFloat(); - g.y2 = input.readFloat(); - g.isRadial = input.readByte() != 0; + StringArray colours; + colours.addTokens (v["colours"].toString(), false); - const int numColours = input.readCompressedInt(); - for (int i = 0; i < numColours; ++i) - { - double proportion = (double) input.readFloat(); - const Colour col ((uint32) input.readInt()); - g.addColour (proportion, col); - } + for (int i = 0; i < colours.size() / 2; ++i) + g.addColour (colours[i * 2].getDoubleValue(), + Colour ((uint32) colours[i * 2 + 1].getHexValue32())); - return FillType (g); - } - - default: - break; + return FillType (g); } + jassertfalse return FillType(); } -static void writeColourToBinary (OutputStream& output, const FillType& fillType) +static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType) { - if (fillType.isColour()) - { - output.writeByte (1); - output.writeInt ((int) fillType.colour.getARGB()); - } - else if (fillType.isGradient()) - { - output.writeByte (2); - - output.writeFloat (fillType.gradient->x1); - output.writeFloat (fillType.gradient->y1); - output.writeFloat (fillType.gradient->x2); - output.writeFloat (fillType.gradient->y2); - output.writeByte (fillType.gradient->isRadial ? 1 : 0); - - output.writeCompressedInt (fillType.gradient->getNumColours()); - - for (int i = 0; i < fillType.gradient->getNumColours(); ++i) - { - output.writeFloat ((float) fillType.gradient->getColourPosition (i)); - output.writeInt ((int) fillType.gradient->getColour (i).getARGB()); - } - } - else - { - jassertfalse // xxx - } - -} - -static const FillType readColourFromXml (const XmlElement* xml) -{ - if (xml != 0) - { - const String type (xml->getStringAttribute (T("type"))); - - if (type.equalsIgnoreCase (T("solid"))) - { - return FillType (Colour ((uint32) xml->getStringAttribute (T("colour"), T("ff000000")).getHexValue32())); - } - else if (type.equalsIgnoreCase (T("gradient"))) - { - ColourGradient g; - g.x1 = (float) xml->getDoubleAttribute (T("x1")); - g.y1 = (float) xml->getDoubleAttribute (T("y1")); - g.x2 = (float) xml->getDoubleAttribute (T("x2")); - g.y2 = (float) xml->getDoubleAttribute (T("y2")); - g.isRadial = xml->getBoolAttribute (T("radial"), false); - - StringArray colours; - colours.addTokens (xml->getStringAttribute (T("colours")), false); - - for (int i = 0; i < colours.size() / 2; ++i) - g.addColour (colours[i * 2].getDoubleValue(), - Colour ((uint32) colours[i * 2 + 1].getHexValue32())); - - return FillType (g); - } - else - { - jassertfalse - } - } - - return FillType(); -} - -static XmlElement* writeColourToXml (const String& tagName, const FillType& fillType) -{ - XmlElement* const xml = new XmlElement (tagName); + ValueTree v (tagName); if (fillType.isColour()) { - xml->setAttribute (T("type"), T("solid")); - xml->setAttribute (T("colour"), String::toHexString ((int) fillType.colour.getARGB())); + v.setProperty ("type", T("solid"), 0); + v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0); } else if (fillType.isGradient()) { - xml->setAttribute (T("type"), T("gradient")); - - xml->setAttribute (T("x1"), fillType.gradient->x1); - xml->setAttribute (T("y1"), fillType.gradient->y1); - xml->setAttribute (T("x2"), fillType.gradient->x2); - xml->setAttribute (T("y2"), fillType.gradient->y2); - xml->setAttribute (T("radial"), fillType.gradient->isRadial); + v.setProperty ("type", T("gradient"), 0); + v.setProperty ("x1", fillType.gradient->x1, 0); + v.setProperty ("y1", fillType.gradient->y1, 0); + v.setProperty ("x2", fillType.gradient->x2, 0); + v.setProperty ("y2", fillType.gradient->y2, 0); + v.setProperty ("radial", fillType.gradient->isRadial, 0); String s; for (int i = 0; i < fillType.gradient->getNumColours(); ++i) s << " " << fillType.gradient->getColourPosition (i) << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB()); - xml->setAttribute (T("colours"), s.trimStart()); + v.setProperty ("colours", s.trimStart(), 0); } else { jassertfalse //xxx } - return xml; + return v; } -bool DrawablePath::readBinary (InputStream& input) +ValueTree DrawablePath::createValueTree() const throw() { - mainFill = readColourFromBinary (input); - strokeFill = readColourFromBinary (input); + ValueTree v (T("Path")); - const float strokeThickness = input.readFloat(); - const int jointStyle = input.readByte(); - const int endStyle = input.readByte(); + v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0); + v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0); - strokeType = PathStrokeType (strokeThickness, - jointStyle == 1 ? PathStrokeType::curved - : (jointStyle == 2 ? PathStrokeType::beveled - : PathStrokeType::mitered), - endStyle == 1 ? PathStrokeType::square - : (endStyle == 2 ? PathStrokeType::rounded - : PathStrokeType::butt)); + if (getName().isNotEmpty()) + v.setProperty ("id", getName(), 0); - const int pathSize = input.readInt(); - MemoryBlock pathData; - input.readIntoMemoryBlock (pathData, pathSize); + v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0); + v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered + ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0); + v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt + ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0); + v.setProperty ("path", path.toString(), 0); - if (pathData.getSize() != pathSize) - return false; - - path.clear(); - path.loadPathFromData ((const uint8*) pathData.getData(), pathSize); - updateOutline(); - return true; + return v; } -bool DrawablePath::writeBinary (OutputStream& output) const +DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw() { - writeColourToBinary (output, mainFill); - writeColourToBinary (output, strokeFill); + if (! tree.hasType ("Path")) + return 0; - output.writeFloat (strokeType.getStrokeThickness()); - output.writeByte (strokeType.getJointStyle() == PathStrokeType::mitered ? 0 - : (strokeType.getJointStyle() == PathStrokeType::curved ? 1 : 2)); - output.writeByte (strokeType.getEndStyle() == PathStrokeType::butt ? 0 - : (strokeType.getEndStyle() == PathStrokeType::square ? 1 : 2)); + DrawablePath* p = new DrawablePath(); - MemoryOutputStream out; - path.writePathToStream (out); - output.writeInt (out.getDataSize()); - output.write (out.getData(), out.getDataSize()); - return true; -} + p->setName (tree ["id"]); + p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill"))); + p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke"))); -bool DrawablePath::readXml (const XmlElement& xml) -{ - mainFill = readColourFromXml (xml.getChildByName (T("fill"))); - strokeFill = readColourFromXml (xml.getChildByName (T("stroke"))); + const String jointStyle (tree ["jointStyle"].toString()); + const String endStyle (tree ["capStyle"].toString()); - const String jointStyle (xml.getStringAttribute (T("jointStyle"), String::empty)); - const String endStyle (xml.getStringAttribute (T("capStyle"), String::empty)); - strokeType = PathStrokeType ((float) xml.getDoubleAttribute (T("strokeWidth"), 0.0), - jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved - : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled - : PathStrokeType::mitered), - endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square - : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded - : PathStrokeType::butt)); + p->strokeType + = PathStrokeType (tree ["strokeWidth"], + jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved + : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled + : PathStrokeType::mitered), + endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square + : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded + : PathStrokeType::butt)); - path.clear(); - path.restoreFromString (xml.getAllSubText()); - updateOutline(); - return true; -} + p->path.clear(); + p->path.restoreFromString (tree ["path"]); + p->updateOutline(); -void DrawablePath::writeXml (XmlElement& xml) const -{ - xml.addChildElement (writeColourToXml (T("fill"), mainFill)); - xml.addChildElement (writeColourToXml (T("stroke"), strokeFill)); - - xml.setAttribute (T("strokeWidth"), (double) strokeType.getStrokeThickness()); - xml.setAttribute (T("jointStyle"), - strokeType.getJointStyle() == PathStrokeType::mitered ? T("miter") - : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel"))); - xml.setAttribute (T("capStyle"), - strokeType.getEndStyle() == PathStrokeType::butt ? T("butt") - : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round"))); - - xml.addTextElement (path.toString()); + return p; } END_JUCE_NAMESPACE @@ -84471,27 +84263,29 @@ Drawable* DrawableText::createCopy() const return dt; } -bool DrawableText::readBinary (InputStream& input) +ValueTree DrawableText::createValueTree() const throw() { - jassertfalse; //xxx TODO - return false; + ValueTree v (T("Text")); + + if (getName().isNotEmpty()) + v.setProperty ("id", getName(), 0); + + jassertfalse // xxx not finished! + return v; } -bool DrawableText::writeBinary (OutputStream& output) const +DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw() { - jassertfalse; //xxx TODO - return false; -} + if (! tree.hasType ("Text")) + return 0; -bool DrawableText::readXml (const XmlElement& xml) -{ - jassertfalse; //xxx TODO - return false; -} + DrawableText* dt = new DrawableText(); -void DrawableText::writeXml (XmlElement& xml) const -{ - jassertfalse; //xxx TODO + dt->setName (tree ["id"]); + + jassertfalse // xxx not finished! + + return dt; } END_JUCE_NAMESPACE @@ -84507,7 +84301,7 @@ public: SVGState (const XmlElement* const topLevel) : topLevelXml (topLevel), - x (0), y (0), + elementX (0), elementY (0), width (512), height (512), viewBoxW (0), viewBoxH (0) { @@ -84531,8 +84325,8 @@ public: if (xml.hasAttribute (T("transform"))) newState.addTransform (xml); - newState.x = getCoordLength (xml.getStringAttribute (T("x"), String (newState.x)), viewBoxW); - newState.y = getCoordLength (xml.getStringAttribute (T("y"), String (newState.y)), viewBoxH); + newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW); + newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH); newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW); newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH); @@ -84603,7 +84397,7 @@ public: private: const XmlElement* const topLevelXml; - float x, y, width, height, viewBoxW, viewBoxH; + float elementX, elementY, width, height, viewBoxW, viewBoxH; AffineTransform transform; String cssStyleText; @@ -85059,9 +84853,9 @@ private: } Drawable* parseShape (const XmlElement& xml, Path& path, - const bool parseTransform = true) const + const bool shouldParseTransform = true) const { - if (parseTransform && xml.hasAttribute (T("transform"))) + if (shouldParseTransform && xml.hasAttribute (T("transform"))) { SVGState newState (*this); newState.addTransform (xml); @@ -85194,8 +84988,8 @@ private: float width = viewBoxW; float height = viewBoxH; - float dx = 0.0; - float dy = 0.0; + float dx = 0.0f; + float dy = 0.0f; const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse")); @@ -87013,7 +86807,7 @@ void GlyphArrangement::spreadOutLine (const int start, const int num, const floa for (int i = 0; i < num; ++i) { - glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0); + glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f); if (glyphs.getUnchecked (start + i)->isWhitespace()) deltaX += extraPaddingBetweenWords; @@ -87751,7 +87545,7 @@ float CustomTypeface::getStringWidth (const String& text) return x; } -void CustomTypeface::getGlyphPositions (const String& text, Array & glyphs, Array& xOffsets) +void CustomTypeface::getGlyphPositions (const String& text, Array & resultGlyphs, Array& xOffsets) { xOffsets.add (0); float x = 0; @@ -87765,7 +87559,7 @@ void CustomTypeface::getGlyphPositions (const String& text, Array & glyphs, if (glyph != 0) { x += glyph->getHorizontalSpacing (*t); - glyphs.add ((int) glyph->character); + resultGlyphs.add ((int) glyph->character); xOffsets.add (x); } } @@ -88789,6 +88583,21 @@ void Path::addRectangle (const float x, const float y, ensureAllocatedSize (numElements + 13); + if (numElements == 0) + { + pathXMin = x1; + pathXMax = x2; + pathYMin = y1; + pathYMax = y2; + } + else + { + pathXMin = jmin (pathXMin, x1); + pathXMax = jmax (pathXMax, x2); + pathYMin = jmin (pathYMin, y1); + pathYMax = jmax (pathYMax, y2); + } + elements [numElements++] = moveMarker; elements [numElements++] = x1; elements [numElements++] = y2; @@ -88802,11 +88611,6 @@ void Path::addRectangle (const float x, const float y, elements [numElements++] = x2; elements [numElements++] = y2; elements [numElements++] = closeSubPathMarker; - - pathXMin = jmin (pathXMin, x1); - pathXMax = jmax (pathXMax, x2); - pathYMin = jmin (pathYMin, y1); - pathYMax = jmax (pathYMax, y2); } void Path::addRectangle (const Rectangle& rectangle) throw() @@ -93481,7 +93285,7 @@ int GIFLoader::processExtension (const int type, int& transparent) return n; } -int GIFLoader::getCode (const int codeSize, const bool initialise) +int GIFLoader::getCode (const int codeSize_, const bool initialise) { if (initialise) { @@ -93491,7 +93295,7 @@ int GIFLoader::getCode (const int codeSize, const bool initialise) return 0; } - if ((currentBit + codeSize) >= lastBit) + if ((currentBit + codeSize_) >= lastBit) { if (finished) return -1; @@ -93512,13 +93316,13 @@ int GIFLoader::getCode (const int codeSize, const bool initialise) int result = 0; int i = currentBit; - for (int j = 0; j < codeSize; ++j) + for (int j = 0; j < codeSize_; ++j) { result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j; ++i; } - currentBit += codeSize; + currentBit += codeSize_; return result; } @@ -126009,12 +125813,12 @@ public: bool ok; FlacWriter (OutputStream* const out, - const double sampleRate, - const int numChannels, + const double sampleRate_, + const int numChannels_, const int bitsPerSample_) : AudioFormatWriter (out, flacFormatName, - sampleRate, - numChannels, + sampleRate_, + numChannels_, bitsPerSample_) { using namespace FlacNamespace; @@ -126060,14 +125864,14 @@ public: if (bitsToShift > 0) { - const int numChannels = (samplesToWrite[1] == 0) ? 1 : 2; - temp.setSize (sizeof (int) * numSamples * numChannels); + const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2; + temp.setSize (sizeof (int) * numSamples * numChannelsToWrite); buf[0] = (int*) temp.getData(); buf[1] = buf[0] + numSamples; buf[2] = 0; - for (int i = numChannels; --i >= 0;) + for (int i = numChannelsToWrite; --i >= 0;) { if (samplesToWrite[i] != 0) { @@ -126120,12 +125924,12 @@ public: packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4); memcpy (buffer + 18, info.md5sum, 16); - const bool ok = output->setPosition (4); - (void) ok; + const bool seekOk = output->setPosition (4); + (void) seekOk; // if this fails, you've given it an output stream that can't seek! It needs // to be able to seek back to write the header - jassert (ok); + jassert (seekOk); output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH); output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH); @@ -259734,7 +259538,7 @@ int SystemStats::getMemorySizeInMegabytes() throw() size_t memSize = sizeof (mem); int mib[] = { CTL_HW, HW_MEMSIZE }; sysctl (mib, 2, &mem, &memSize, 0, 0); - return mem / (1024 * 1024); + return (int) (mem / (1024 * 1024)); } bool SystemStats::hasMMX() throw() @@ -259795,7 +259599,7 @@ int SystemStats::getCpuSpeedInMegaherz() throw() if (speedSize == 4) speedHz >>= 32; #endif - return speedHz / 1000000; + return (int) (speedHz / 1000000); } int SystemStats::getNumCpus() throw() @@ -262090,7 +261894,7 @@ public: if (needsItalicTransform) { - pathTransform = pathTransform.sheared (-0.15, 0); + pathTransform = pathTransform.sheared (-0.15f, 0.0f); renderingTransform.c = 0.15f; } @@ -262510,11 +262314,11 @@ class CoreGraphicsImage : public Image { public: - CoreGraphicsImage (const PixelFormat format, - const int imageWidth, - const int imageHeight, + CoreGraphicsImage (const PixelFormat format_, + const int imageWidth_, + const int imageHeight_, const bool clearImage) - : Image (format, imageWidth, imageHeight, clearImage) + : Image (format_, imageWidth_, imageHeight_, clearImage) { CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB(); @@ -262921,20 +262725,20 @@ public: state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(), state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha()); - CGPoint line[] = { { x1 + 0.5f, flipHeight - (y1 + 0.5f) }, - { x2 + 0.5f, flipHeight - (y2 + 0.5f) } }; + CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) }, + { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } }; CGContextStrokeLineSegments (context, line, 1); } void drawVerticalLine (const int x, double top, double bottom) { - CGContextFillRect (context, CGRectMake (x, flipHeight - bottom, 1.0f, bottom - top)); + CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top))); } void drawHorizontalLine (const int y, double left, double right) { - CGContextFillRect (context, CGRectMake (left, flipHeight - (y + 1.0f), right - left, 1.0f)); + CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f)); } void setFont (const Font& newFont) @@ -266556,7 +266360,7 @@ public: if (needsItalicTransform) { - pathTransform = pathTransform.sheared (-0.15, 0); + pathTransform = pathTransform.sheared (-0.15f, 0.0f); renderingTransform.c = 0.15f; } @@ -266978,11 +266782,11 @@ class CoreGraphicsImage : public Image { public: - CoreGraphicsImage (const PixelFormat format, - const int imageWidth, - const int imageHeight, + CoreGraphicsImage (const PixelFormat format_, + const int imageWidth_, + const int imageHeight_, const bool clearImage) - : Image (format, imageWidth, imageHeight, clearImage) + : Image (format_, imageWidth_, imageHeight_, clearImage) { CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB(); @@ -267389,20 +267193,20 @@ public: state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(), state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha()); - CGPoint line[] = { { x1 + 0.5f, flipHeight - (y1 + 0.5f) }, - { x2 + 0.5f, flipHeight - (y2 + 0.5f) } }; + CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) }, + { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } }; CGContextStrokeLineSegments (context, line, 1); } void drawVerticalLine (const int x, double top, double bottom) { - CGContextFillRect (context, CGRectMake (x, flipHeight - bottom, 1.0f, bottom - top)); + CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top))); } void drawHorizontalLine (const int y, double left, double right) { - CGContextFillRect (context, CGRectMake (left, flipHeight - (y + 1.0f), right - left, 1.0f)); + CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f)); } void setFont (const Font& newFont) @@ -268289,10 +268093,10 @@ static int getModifierForButtonNumber (const int num) throw() : (num == 2 ? ModifierKeys::middleButtonModifier : 0)); } -NSViewComponentPeer::NSViewComponentPeer (Component* const component, +NSViewComponentPeer::NSViewComponentPeer (Component* const component_, const int windowStyleFlags, NSView* viewToAttachTo) - : ComponentPeer (component, windowStyleFlags), + : ComponentPeer (component_, windowStyleFlags), window (0), view (0), isSharedWindow (viewToAttachTo != 0), @@ -270750,13 +270554,13 @@ static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile) } bool QuickTimeMovieComponent::loadMovie (const File& movieFile_, - const bool isControllerVisible) + const bool isControllerVisible_) { - return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible); + return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_); } bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream, - const bool controllerVisible) + const bool controllerVisible_) { closeMovie(); @@ -270773,14 +270577,14 @@ bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream, [theMovie retain]; QTMovieView* view = (QTMovieView*) getView(); [view setMovie: theMovie]; - [view setControllerVisible: controllerVisible]; + [view setControllerVisible: controllerVisible_]; setLooping (looping); return movie != nil; } bool QuickTimeMovieComponent::loadMovie (const URL& movieURL, - const bool isControllerVisible) + const bool isControllerVisible_) { // unfortunately, QTMovie objects can only be created on the main thread.. jassert (MessageManager::getInstance()->isThisTheMessageThread()); @@ -271775,7 +271579,7 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor) while (! quitMessagePosted) { - const ScopedAutoReleasePool pool; + const ScopedAutoReleasePool pool2; CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true); @@ -272817,7 +272621,7 @@ public: // Sometimes the two linked devices seem to get their callbacks in // parallel, so we need to lock both devices to stop the input data being // changed while inside our callback.. - const ScopedLock sl (inputDevice->callbackLock); + const ScopedLock sl2 (inputDevice->callbackLock); callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers, inputDevice->numInputChans, diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 146a6bb8d9..a82ad1d35f 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -2842,7 +2842,7 @@ protected: } /** Destructor. */ - ~ArrayAllocationBase() throw() + virtual ~ArrayAllocationBase() { delete[] elements; } @@ -3336,8 +3336,8 @@ public: @see ArrayAllocationBase */ - OwnedArray (const int granularity = juceDefaultArrayGranularity) throw() - : ArrayAllocationBase (granularity), + OwnedArray (const int granularity_ = juceDefaultArrayGranularity) throw() + : ArrayAllocationBase (granularity_), numUsed (0) { } @@ -4612,8 +4612,8 @@ public: @see ArrayAllocationBase */ - Array (const int granularity = juceDefaultArrayGranularity) throw() - : ArrayAllocationBase (granularity), + Array (const int granularity_ = juceDefaultArrayGranularity) throw() + : ArrayAllocationBase (granularity_), numUsed (0) { } @@ -7295,6 +7295,9 @@ public: private: void* pool; + + ScopedAutoReleasePool (const ScopedAutoReleasePool&); + const ScopedAutoReleasePool& operator= (const ScopedAutoReleasePool&); }; #endif @@ -7377,6 +7380,9 @@ private: int remoteId; bool open (const bool openInExclusiveMode) throw(); + + AppleRemoteDevice (const AppleRemoteDevice&); + const AppleRemoteDevice& operator= (const AppleRemoteDevice&); }; #endif @@ -8940,18 +8946,17 @@ public: */ virtual int readCompressedInt(); - /** Reads a string from the stream, up to the next linefeed or carriage return. + /** Reads a UTF8 string from the stream, up to the next linefeed or carriage return. - The stream is treated as 8-bit characters encoded with the system's default encoding, - and this will read up to the next "\n" or "\r\n" or end-of-stream. + This will read up to the next "\n" or "\r\n" or end-of-stream. - After this call, the stream's position will be left pointing to the character + After this call, the stream's position will be left pointing to the next character following the line-feed, but the linefeeds aren't included in the string that is returned. */ virtual const String readNextLine(); - /** Reads a zero-terminated string from the stream. + /** Reads a zero-terminated UTF8 string from the stream. This will read characters from the stream until it hits a zero character or end-of-stream. @@ -9168,6 +9173,8 @@ public: text-file! It's intended for storing a string for later retrieval by InputStream::readString. + It writes the string to the stream as UTF8, with a null character terminating it. + For appending text to a file, instead use writeText, printf, or operator<< @see InputStream::readString, writeText, printf, operator<< @@ -9276,6 +9283,7 @@ public: operator int() const throw(); operator bool() const throw(); + operator float() const throw(); operator double() const throw(); operator const String() const throw(); const String toString() const throw(); @@ -9751,7 +9759,7 @@ public: @param lineWrapLength the line length that will be used before items get placed on a new line. This isn't an absolute maximum length, it just determines how lists of attributes get broken up - @see writeToFile + @see writeToStream, writeToFile */ const String createDocument (const String& dtdToUse, const bool allOnOneLine = false, @@ -9759,6 +9767,27 @@ public: const tchar* const encodingType = JUCE_T("UTF-8"), const int lineWrapLength = 60) const throw(); + /** Writes the document to a stream as UTF-8. + + @param dtdToUse the DTD to add to the document + @param allOnOneLine if true, this means that the document will not contain any + linefeeds, so it'll be smaller but not very easy to read. + @param includeXmlHeader whether to add the " (granularity), + ReferenceCountedArray (const int granularity_ = juceDefaultArrayGranularity) throw() + : ArrayAllocationBase (granularity_), numUsed (0) { } @@ -11259,8 +11291,8 @@ public: @see ArrayAllocationBase */ - SortedSet (const int granularity = juceDefaultArrayGranularity) throw() - : ArrayAllocationBase (granularity), + SortedSet (const int granularity_ = juceDefaultArrayGranularity) throw() + : ArrayAllocationBase (granularity_), numUsed (0) { } @@ -12871,6 +12903,16 @@ public: */ ValueTree getChildWithName (const String& type) const throw(); + /** Looks for the first child node that has the speficied property value. + + This will scan the child nodes in order, until it finds one that has property that matches + the specified value. + + If no such node is found, it'll return an invalid node. (See isValid() to find out + whether a node is valid). + */ + ValueTree getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const throw(); + /** Adds a child to this node. Make sure that the child is removed from any former parent node before calling this, or @@ -12928,6 +12970,19 @@ public: */ static ValueTree fromXml (const XmlElement& xml) throw(); + /** Stores this tree (and all its children) in a binary format. + + Once written, the data can be read back with readFromStream(). + + It's much faster to load/save your tree in binary form than as XML, but + obviously isn't human-readable. + */ + void writeToStream (OutputStream& output) throw(); + + /** Reloads a tree from a stream that was written with writeToStream(). + */ + static ValueTree readFromStream (InputStream& input) throw(); + /** Listener class for events that happen to a ValueTree. To get events from a ValueTree, make your class implement this interface, and use @@ -12940,13 +12995,13 @@ public: virtual ~Listener() {} /** This method is called when one or more of the properties of this node have changed. */ - virtual void ValueTreePropertyChanged (ValueTree& tree) = 0; + virtual void valueTreePropertyChanged (ValueTree& tree) = 0; /** This method is called when one or more of the children of this node have been added or removed. */ - virtual void ValueTreeChildrenChanged (ValueTree& tree) = 0; + virtual void valueTreeChildrenChanged (ValueTree& tree) = 0; /** This method is called when this node has been added or removed from a parent node. */ - virtual void ValueTreeParentChanged() = 0; + virtual void valueTreeParentChanged() = 0; }; /** Adds a listener to receive callbacks when this node is changed. */ @@ -12970,9 +13025,9 @@ private: struct Property { - Property (const var::identifier& id, const var& value) throw(); + Property (const var::identifier& name, const var& value) throw(); - var::identifier id; + var::identifier name; var value; }; @@ -12992,6 +13047,7 @@ private: void removeAllProperties (UndoManager* const undoManager) throw(); bool isAChildOf (const SharedObject* const possibleParent) const throw(); ValueTree getChildWithName (const String& type) const throw(); + ValueTree getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const throw(); void addChild (SharedObject* child, int index, UndoManager* const undoManager) throw(); void removeChild (const int childIndex, UndoManager* const undoManager) throw(); void removeAllChildren (UndoManager* const undoManager) throw(); @@ -13141,6 +13197,9 @@ private: void* fileHandle; int64 currentPosition, totalSize; bool needToSeek; + + FileInputStream (const FileInputStream&); + const FileInputStream& operator= (const FileInputStream&); }; #endif // __JUCE_FILEINPUTSTREAM_JUCEHEADER__ @@ -16990,12 +17049,6 @@ public: virtual void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); - -private: - // XXX Deprecated! The parameters for this method have changed to accommodate horizonatal scroll-wheels. - // This line is here to cause a syntax error if you're trying to use the old-style definition, so - // if that happens, update your code to use the new one above. - virtual int mouseWheelMove (const MouseEvent&, float) { return 0; } }; #endif // __JUCE_MOUSELISTENER_JUCEHEADER__ @@ -17339,11 +17392,6 @@ public: @see KeyPress, Component::keyStateChanged */ virtual bool keyStateChanged (const bool isKeyDown, Component* originatingComponent); - -private: - // (dummy method to cause a deliberate compile error - if you hit this, you need to update your - // subclass to use the new parameters to keyStateChanged) - virtual void keyStateChanged (Component*) {}; }; #endif // __JUCE_KEYLISTENER_JUCEHEADER__ @@ -23404,7 +23452,7 @@ public: @see isFocusContainer, createFocusTraverser, moveKeyboardFocusToSibling */ - void setFocusContainer (const bool isFocusContainer) throw(); + void setFocusContainer (const bool shouldBeFocusContainer) throw(); /** Returns true if this component has been marked as a focus container. @@ -24833,6 +24881,9 @@ private: friend class CommandTargetMessageInvoker; bool tryToInvoke (const InvocationInfo& info, const bool async); + + ApplicationCommandTarget (const ApplicationCommandTarget&); + const ApplicationCommandTarget& operator= (const ApplicationCommandTarget&); }; #endif // __JUCE_APPLICATIONCOMMANDTARGET_JUCEHEADER__ @@ -25120,6 +25171,9 @@ private: bool stillInitialising; InterProcessLock* appLock; + JUCEApplication (const JUCEApplication&); + const JUCEApplication& operator= (const JUCEApplication&); + public: /** @internal */ bool initialiseApp (String& commandLine); @@ -34993,7 +35047,7 @@ public: current selection - it just stops the user choosing that item from the list. */ void setItemEnabled (const int itemId, - const bool isEnabled) throw(); + const bool shouldBeEnabled) throw(); /** Changes the text for an existing item. */ @@ -39353,6 +39407,9 @@ private: void* sharedEvents; void init (Thread* const thread, ThreadPoolJob* const job) throw(); + + MessageManagerLock (const MessageManagerLock&); + const MessageManagerLock& operator= (const MessageManagerLock&); }; #endif // __JUCE_MESSAGEMANAGER_JUCEHEADER__ @@ -40111,6 +40168,10 @@ public: uint8* data; int lineStride, pixelStride, width, height; + + private: + BitmapData (const BitmapData&); + const BitmapData& operator= (const BitmapData&); }; /** Copies some pixel values to a rectangle of the image. @@ -41528,30 +41589,16 @@ public: */ static Drawable* createFromSVG (const XmlElement& svgDocument); - /** + /** Tries to create a Drawable from a previously-saved ValueTree. + The ValueTree must have been created by the createValueTree() method. */ - static Drawable* readFromBinaryStream (InputStream& input); + static Drawable* createFromValueTree (const ValueTree& tree) throw(); - /** + /** Creates a ValueTree to represent this Drawable. + The VarTree that is returned can be turned back into a Drawable with + createFromValueTree(). */ - bool writeToBinaryStream (OutputStream& output) const; - - /** - */ - static Drawable* readFromXml (const XmlElement& xml); - - /** - */ - XmlElement* createXml() const; - - /** @internal */ - virtual bool readBinary (InputStream& input) = 0; - /** @internal */ - virtual bool writeBinary (OutputStream& output) const = 0; - /** @internal */ - virtual bool readXml (const XmlElement& xml) = 0; - /** @internal */ - virtual void writeXml (XmlElement& xml) const = 0; + virtual ValueTree createValueTree() const throw() = 0; juce_UseDebuggingNewOperator @@ -41679,13 +41726,9 @@ public: /** @internal */ Drawable* createCopy() const; /** @internal */ - bool readBinary (InputStream& input); + ValueTree createValueTree() const throw(); /** @internal */ - bool writeBinary (OutputStream& output) const; - /** @internal */ - bool readXml (const XmlElement& xml); - /** @internal */ - void writeXml (XmlElement& xml) const; + static DrawableComposite* createFromValueTree (const ValueTree& tree) throw(); juce_UseDebuggingNewOperator @@ -41782,13 +41825,9 @@ public: /** @internal */ Drawable* createCopy() const; /** @internal */ - bool readBinary (InputStream& input); + ValueTree createValueTree() const throw(); /** @internal */ - bool writeBinary (OutputStream& output) const; - /** @internal */ - bool readXml (const XmlElement& xml); - /** @internal */ - void writeXml (XmlElement& xml) const; + static DrawableImage* createFromValueTree (const ValueTree& tree) throw(); juce_UseDebuggingNewOperator @@ -41856,13 +41895,9 @@ public: /** @internal */ Drawable* createCopy() const; /** @internal */ - bool readBinary (InputStream& input); + ValueTree createValueTree() const throw(); /** @internal */ - bool writeBinary (OutputStream& output) const; - /** @internal */ - bool readXml (const XmlElement& xml); - /** @internal */ - void writeXml (XmlElement& xml) const; + static DrawableText* createFromValueTree (const ValueTree& tree) throw(); juce_UseDebuggingNewOperator @@ -41957,13 +41992,9 @@ public: /** @internal */ Drawable* createCopy() const; /** @internal */ - bool readBinary (InputStream& input); + ValueTree createValueTree() const throw(); /** @internal */ - bool writeBinary (OutputStream& output) const; - /** @internal */ - bool readXml (const XmlElement& xml); - /** @internal */ - void writeXml (XmlElement& xml) const; + static DrawablePath* createFromValueTree (const ValueTree& tree) throw(); juce_UseDebuggingNewOperator diff --git a/src/application/juce_Application.h b/src/application/juce_Application.h index db113d5d28..82ac873d03 100644 --- a/src/application/juce_Application.h +++ b/src/application/juce_Application.h @@ -291,6 +291,9 @@ private: bool stillInitialising; InterProcessLock* appLock; + JUCEApplication (const JUCEApplication&); + const JUCEApplication& operator= (const JUCEApplication&); + public: /** @internal */ bool initialiseApp (String& commandLine); diff --git a/src/application/juce_ApplicationCommandTarget.h b/src/application/juce_ApplicationCommandTarget.h index b168e29944..fbcf837dde 100644 --- a/src/application/juce_ApplicationCommandTarget.h +++ b/src/application/juce_ApplicationCommandTarget.h @@ -258,6 +258,9 @@ private: friend class CommandTargetMessageInvoker; bool tryToInvoke (const InvocationInfo& info, const bool async); + + ApplicationCommandTarget (const ApplicationCommandTarget&); + const ApplicationCommandTarget& operator= (const ApplicationCommandTarget&); }; diff --git a/src/audio/audio_file_formats/juce_AudioCDReader.cpp b/src/audio/audio_file_formats/juce_AudioCDReader.cpp index d79a8b5451..defa0e21ee 100644 --- a/src/audio/audio_file_formats/juce_AudioCDReader.cpp +++ b/src/audio/audio_file_formats/juce_AudioCDReader.cpp @@ -133,7 +133,7 @@ void AudioCDReader::refreshTrackLengths() if (r != 0) { - sample += r->lengthInSamples; + sample += (int) r->lengthInSamples; delete r; } } diff --git a/src/audio/audio_file_formats/juce_AudioFormat.cpp b/src/audio/audio_file_formats/juce_AudioFormat.cpp index 4ce8f7df8a..3611310627 100644 --- a/src/audio/audio_file_formats/juce_AudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_AudioFormat.cpp @@ -153,7 +153,7 @@ void AudioFormatReader::readMaxLevels (int64 startSampleInFile, if (usesFloatingPointData) { - float lmin = 1.0e6; + float lmin = 1.0e6f; float lmax = -lmin; float rmin = lmin; float rmax = lmax; diff --git a/src/audio/audio_file_formats/juce_AudioThumbnail.cpp b/src/audio/audio_file_formats/juce_AudioThumbnail.cpp index 1c6ba6720d..16b516d874 100644 --- a/src/audio/audio_file_formats/juce_AudioThumbnail.cpp +++ b/src/audio/audio_file_formats/juce_AudioThumbnail.cpp @@ -197,6 +197,8 @@ void AudioThumbnail::clear() void AudioThumbnail::loadFrom (InputStream& input) { + const ScopedLock sl (readerLock); + data.setSize (0); input.readIntoMemoryBlock (data); @@ -223,14 +225,14 @@ void AudioThumbnail::saveTo (OutputStream& output) const swapEndiannessIfNeeded (d); } -bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& reader) +bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader) { AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData(); - d->totalSamples = reader.lengthInSamples; - d->numChannels = jmin (2, reader.numChannels); + d->totalSamples = fileReader.lengthInSamples; + d->numChannels = jmin (2, fileReader.numChannels); d->numFinishedSamples = 0; - d->sampleRate = roundDoubleToInt (reader.sampleRate); + d->sampleRate = roundDoubleToInt (fileReader.sampleRate); d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1; data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2); @@ -241,7 +243,7 @@ bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& reader) return d->totalSamples > 0; } -bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& reader) +bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader) { AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData(); @@ -249,7 +251,7 @@ bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& reader) { const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples); - generateSection (reader, + generateSection (fileReader, d->numFinishedSamples, numToDo); @@ -279,7 +281,7 @@ double AudioThumbnail::getTotalLength() const throw() return 0.0; } -void AudioThumbnail::generateSection (AudioFormatReader& reader, +void AudioThumbnail::generateSection (AudioFormatReader& fileReader, int64 startSample, int numSamples) { @@ -299,12 +301,12 @@ void AudioThumbnail::generateSection (AudioFormatReader& reader, float lowestLeft, highestLeft, lowestRight, highestRight; - reader.readMaxLevels (sourceStart, - sourceEnd - sourceStart, - lowestLeft, - highestLeft, - lowestRight, - highestRight); + fileReader.readMaxLevels (sourceStart, + sourceEnd - sourceStart, + lowestLeft, + highestLeft, + lowestRight, + highestRight); int n = i * 2; @@ -425,7 +427,7 @@ void AudioThumbnail::refillCache (const int numSamples, { for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum) { - char* const data = getChannelData (channelNum); + char* const channelData = getChannelData (channelNum); char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2; const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample; @@ -438,7 +440,7 @@ void AudioThumbnail::refillCache (const int numSamples, { const int nextSample = roundDoubleToInt ((startTime + timePerPixel) * timeToThumbSampleFactor); - if (sample >= 0 && data != 0) + if (sample >= 0 && channelData != 0) { char mx = -128; char mn = 127; @@ -449,8 +451,8 @@ void AudioThumbnail::refillCache (const int numSamples, break; const int n = sample << 1; - const char sampMin = data [n]; - const char sampMax = data [n + 1]; + const char sampMin = channelData [n]; + const char sampMax = channelData [n + 1]; if (sampMin < mn) mn = sampMin; diff --git a/src/audio/audio_file_formats/juce_FlacAudioFormat.cpp b/src/audio/audio_file_formats/juce_FlacAudioFormat.cpp index f80aa01a46..f9cbdf893c 100644 --- a/src/audio/audio_file_formats/juce_FlacAudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_FlacAudioFormat.cpp @@ -314,12 +314,12 @@ public: //============================================================================== FlacWriter (OutputStream* const out, - const double sampleRate, - const int numChannels, + const double sampleRate_, + const int numChannels_, const int bitsPerSample_) : AudioFormatWriter (out, flacFormatName, - sampleRate, - numChannels, + sampleRate_, + numChannels_, bitsPerSample_) { using namespace FlacNamespace; @@ -366,14 +366,14 @@ public: if (bitsToShift > 0) { - const int numChannels = (samplesToWrite[1] == 0) ? 1 : 2; - temp.setSize (sizeof (int) * numSamples * numChannels); + const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2; + temp.setSize (sizeof (int) * numSamples * numChannelsToWrite); buf[0] = (int*) temp.getData(); buf[1] = buf[0] + numSamples; buf[2] = 0; - for (int i = numChannels; --i >= 0;) + for (int i = numChannelsToWrite; --i >= 0;) { if (samplesToWrite[i] != 0) { @@ -426,12 +426,12 @@ public: packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4); memcpy (buffer + 18, info.md5sum, 16); - const bool ok = output->setPosition (4); - (void) ok; + const bool seekOk = output->setPosition (4); + (void) seekOk; // if this fails, you've given it an output stream that can't seek! It needs // to be able to seek back to write the header - jassert (ok); + jassert (seekOk); output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH); output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH); diff --git a/src/audio/audio_file_formats/juce_WavAudioFormat.cpp b/src/audio/audio_file_formats/juce_WavAudioFormat.cpp index c0c6c08ea2..a1cd5306aa 100644 --- a/src/audio/audio_file_formats/juce_WavAudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_WavAudioFormat.cpp @@ -578,13 +578,13 @@ class WavAudioFormatWriter : public AudioFormatWriter public: //============================================================================== WavAudioFormatWriter (OutputStream* const out, - const double sampleRate, + const double sampleRate_, const unsigned int numChannels_, const int bits, const StringPairArray& metadataValues) : AudioFormatWriter (out, wavFormatName, - sampleRate, + sampleRate_, numChannels_, bits), lengthInSamples (0), diff --git a/src/audio/audio_sources/juce_ResamplingAudioSource.cpp b/src/audio/audio_sources/juce_ResamplingAudioSource.cpp index 6b6bc186fc..ef07317b38 100644 --- a/src/audio/audio_sources/juce_ResamplingAudioSource.cpp +++ b/src/audio/audio_sources/juce_ResamplingAudioSource.cpp @@ -198,10 +198,10 @@ void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& inf jassert (sampsInBuffer >= 0); } -void ResamplingAudioSource::createLowPass (const double ratio) +void ResamplingAudioSource::createLowPass (const double frequencyRatio) { - const double proportionalRate = (ratio > 1.0) ? 0.5 / ratio - : 0.5 * ratio; + const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio + : 0.5 * frequencyRatio; const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate)); const double nSquared = n * n; diff --git a/src/audio/midi/juce_MidiBuffer.cpp b/src/audio/midi/juce_MidiBuffer.cpp index c748d5a9e6..ddc8fc4631 100644 --- a/src/audio/midi/juce_MidiBuffer.cpp +++ b/src/audio/midi/juce_MidiBuffer.cpp @@ -242,9 +242,9 @@ uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const thr } //============================================================================== -MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer) throw() - : buffer (buffer), - data (buffer.elements) +MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw() + : buffer (buffer_), + data (buffer_.elements) { } diff --git a/src/audio/processors/juce_GenericAudioProcessorEditor.cpp b/src/audio/processors/juce_GenericAudioProcessorEditor.cpp index 30fda54282..3bc5230918 100644 --- a/src/audio/processors/juce_GenericAudioProcessorEditor.cpp +++ b/src/audio/processors/juce_GenericAudioProcessorEditor.cpp @@ -124,8 +124,8 @@ private: //============================================================================== -GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner) - : AudioProcessorEditor (owner) +GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_) + : AudioProcessorEditor (owner_) { setOpaque (true); @@ -133,16 +133,16 @@ GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const Array params; - const int numParams = owner->getNumParameters(); + const int numParams = owner_->getNumParameters(); int totalHeight = 0; for (int i = 0; i < numParams; ++i) { - String name (owner->getParameterName (i)); + String name (owner_->getParameterName (i)); if (name.trim().isEmpty()) name = "Unnamed"; - ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner, i); + ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i); params.add (pc); totalHeight += pc->getPreferredHeight(); } diff --git a/src/containers/juce_Array.h b/src/containers/juce_Array.h index 838415b9ca..048bb047a0 100644 --- a/src/containers/juce_Array.h +++ b/src/containers/juce_Array.h @@ -64,8 +64,8 @@ public: @see ArrayAllocationBase */ - Array (const int granularity = juceDefaultArrayGranularity) throw() - : ArrayAllocationBase (granularity), + Array (const int granularity_ = juceDefaultArrayGranularity) throw() + : ArrayAllocationBase (granularity_), numUsed (0) { } diff --git a/src/containers/juce_ArrayAllocationBase.h b/src/containers/juce_ArrayAllocationBase.h index a9f83e06b2..456b5412e3 100644 --- a/src/containers/juce_ArrayAllocationBase.h +++ b/src/containers/juce_ArrayAllocationBase.h @@ -63,7 +63,7 @@ protected: } /** Destructor. */ - ~ArrayAllocationBase() throw() + virtual ~ArrayAllocationBase() { delete[] elements; } diff --git a/src/containers/juce_OwnedArray.h b/src/containers/juce_OwnedArray.h index 5624290aae..439f27afbc 100644 --- a/src/containers/juce_OwnedArray.h +++ b/src/containers/juce_OwnedArray.h @@ -65,8 +65,8 @@ public: @see ArrayAllocationBase */ - OwnedArray (const int granularity = juceDefaultArrayGranularity) throw() - : ArrayAllocationBase (granularity), + OwnedArray (const int granularity_ = juceDefaultArrayGranularity) throw() + : ArrayAllocationBase (granularity_), numUsed (0) { } diff --git a/src/containers/juce_ReferenceCountedArray.h b/src/containers/juce_ReferenceCountedArray.h index f69f5b2034..f3ccdba89b 100644 --- a/src/containers/juce_ReferenceCountedArray.h +++ b/src/containers/juce_ReferenceCountedArray.h @@ -58,8 +58,8 @@ public: @see ReferenceCountedObject, ArrayAllocationBase, Array, OwnedArray */ - ReferenceCountedArray (const int granularity = juceDefaultArrayGranularity) throw() - : ArrayAllocationBase (granularity), + ReferenceCountedArray (const int granularity_ = juceDefaultArrayGranularity) throw() + : ArrayAllocationBase (granularity_), numUsed (0) { } diff --git a/src/containers/juce_SortedSet.h b/src/containers/juce_SortedSet.h index c790e15178..a14749a4c2 100644 --- a/src/containers/juce_SortedSet.h +++ b/src/containers/juce_SortedSet.h @@ -70,8 +70,8 @@ public: @see ArrayAllocationBase */ - SortedSet (const int granularity = juceDefaultArrayGranularity) throw() - : ArrayAllocationBase (granularity), + SortedSet (const int granularity_ = juceDefaultArrayGranularity) throw() + : ArrayAllocationBase (granularity_), numUsed (0) { } diff --git a/src/containers/juce_ValueTree.cpp b/src/containers/juce_ValueTree.cpp index c51da8f2be..1161948531 100644 --- a/src/containers/juce_ValueTree.cpp +++ b/src/containers/juce_ValueTree.cpp @@ -34,26 +34,26 @@ BEGIN_JUCE_NAMESPACE class ValueTreeSetPropertyAction : public UndoableAction { public: - ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& id_, + ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_, const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_) throw() - : target (target_), id (id_), newValue (newValue_), + : target (target_), name (name_), newValue (newValue_), isAddingNewProperty (isAddingNewProperty_), isDeletingProperty (isDeletingProperty_) { if (! isAddingNewProperty) - oldValue = target_->getProperty (id_); + oldValue = target_->getProperty (name_); } ~ValueTreeSetPropertyAction() {} bool perform() { - jassert (! (isAddingNewProperty && target->hasProperty (id))); + jassert (! (isAddingNewProperty && target->hasProperty (name))); if (isDeletingProperty) - target->removeProperty (id, 0); + target->removeProperty (name, 0); else - target->setProperty (id, newValue, 0); + target->setProperty (name, newValue, 0); return true; } @@ -61,9 +61,9 @@ public: bool undo() { if (isAddingNewProperty) - target->removeProperty (id, 0); + target->removeProperty (name, 0); else - target->setProperty (id, oldValue, 0); + target->setProperty (name, oldValue, 0); return true; } @@ -75,7 +75,7 @@ public: private: const ValueTree::SharedObjectPtr target; - const var::identifier id; + const var::identifier name; const var newValue; var oldValue; const bool isAddingNewProperty, isDeletingProperty; @@ -147,7 +147,7 @@ ValueTree::SharedObject::SharedObject (const SharedObject& other) throw() for (i = 0; i < other.properties.size(); ++i) { const Property* const p = other.properties.getUnchecked(i); - properties.add (new Property (p->id, p->value)); + properties.add (new Property (p->name, p->value)); } for (i = 0; i < other.children.size(); ++i) @@ -167,8 +167,8 @@ ValueTree::SharedObject::~SharedObject() throw() } } -ValueTree::SharedObject::Property::Property (const var::identifier& id_, const var& value_) throw() - : id (id_), value (value_) +ValueTree::SharedObject::Property::Property (const var::identifier& name_, const var& value_) throw() + : name (name_), value (value_) { } @@ -181,7 +181,7 @@ void ValueTree::SharedObject::sendPropertyChangeMessage() { ValueTree::Listener* const l = listeners[i]; if (l != 0) - l->ValueTreePropertyChanged (v); + l->valueTreePropertyChanged (v); } } @@ -193,7 +193,7 @@ void ValueTree::SharedObject::sendChildChangeMessage() { ValueTree::Listener* const l = listeners[i]; if (l != 0) - l->ValueTreeChildrenChanged (v); + l->valueTreeChildrenChanged (v); } } @@ -202,7 +202,6 @@ void ValueTree::SharedObject::sendParentChangeMessage() for (int j = children.size(); --j >= 0;) { SharedObject* const t = children[j]; - if (t != 0) t->sendParentChangeMessage(); } @@ -211,7 +210,7 @@ void ValueTree::SharedObject::sendParentChangeMessage() { ValueTree::Listener* const l = listeners[i]; if (l != 0) - l->ValueTreeParentChanged(); + l->valueTreeParentChanged(); } } @@ -221,7 +220,7 @@ const var ValueTree::SharedObject::getProperty (const var::identifier& name) con for (int i = properties.size(); --i >= 0;) { const Property* const p = properties.getUnchecked(i); - if (p->id == name) + if (p->name == name) return p->value; } @@ -234,7 +233,7 @@ void ValueTree::SharedObject::setProperty (const var::identifier& name, const va { Property* const p = properties.getUnchecked(i); - if (p->id == name) + if (p->name == name) { if (p->value != newValue) { @@ -267,7 +266,7 @@ void ValueTree::SharedObject::setProperty (const var::identifier& name, const va bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const throw() { for (int i = properties.size(); --i >= 0;) - if (properties.getUnchecked(i)->id == name) + if (properties.getUnchecked(i)->name == name) return true; return false; @@ -279,7 +278,7 @@ void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoM { Property* const p = properties.getUnchecked(i); - if (p->id == name) + if (p->name == name) { if (undoManager == 0) { @@ -306,17 +305,26 @@ void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManage else { for (int i = properties.size(); --i >= 0;) - undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getUnchecked(i)->id, var(), false, true)); + undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getUnchecked(i)->name, var(), false, true)); } } -ValueTree ValueTree::SharedObject::getChildWithName (const String& type) const throw() +ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const throw() { for (int i = 0; i < children.size(); ++i) - if (children.getUnchecked(i)->type == type) + if (children.getUnchecked(i)->type == typeToMatch) return (SharedObject*) children.getUnchecked(i); - return 0; + return (SharedObject*) 0; +} + +ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const throw() +{ + for (int i = 0; i < children.size(); ++i) + if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue) + return (SharedObject*) children.getUnchecked(i); + + return (SharedObject*) 0; } bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const throw() @@ -468,7 +476,9 @@ const var ValueTree::getProperty (const var::identifier& name) const throw() void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager) throw() { - if (object != 0) + jassert (name.name.isNotEmpty()); + + if (object != 0 && name.name.isNotEmpty()) object->setProperty (name, newValue, undoManager); } @@ -497,7 +507,7 @@ int ValueTree::getNumProperties() const throw() const var::identifier ValueTree::getPropertyName (int index) const throw() { const SharedObject::Property* const p = (object == 0) ? 0 : object->properties [index]; - return p != 0 ? p->id : var::identifier (String::empty); + return p != 0 ? p->name : var::identifier (String::empty); } //============================================================================== @@ -516,6 +526,11 @@ ValueTree ValueTree::getChildWithName (const String& type) const throw() return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0); } +ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const throw() +{ + return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0); +} + bool ValueTree::isAChildOf (const ValueTree& possibleParent) const throw() { return object != 0 && object->isAChildOf (possibleParent.object); @@ -572,7 +587,7 @@ XmlElement* ValueTree::SharedObject::createXml() const throw() jassert (! p->value.isObject()); // DynamicObjects can't be stored as XML! - xml->setAttribute (p->id.name, p->value.toString()); + xml->setAttribute (p->name.name, p->value.toString()); } for (i = 0; i < children.size(); ++i) @@ -603,4 +618,61 @@ ValueTree ValueTree::fromXml (const XmlElement& xml) throw() return v; } +//============================================================================== +void ValueTree::writeToStream (OutputStream& output) throw() +{ + output.writeString (getType()); + + const int numProps = getNumProperties(); + output.writeCompressedInt (numProps); + + int i; + for (i = 0; i < numProps; ++i) + { + const var::identifier name (getPropertyName(i)); + output.writeString (name.name); + getProperty(name).writeToStream (output); + } + + const int numChildren = getNumChildren(); + output.writeCompressedInt (numChildren); + + for (i = 0; i < numChildren; ++i) + getChild (i).writeToStream (output); +} + +ValueTree ValueTree::readFromStream (InputStream& input) throw() +{ + String type (input.readString()); + + if (type.isEmpty()) + return ValueTree ((SharedObject*) 0); + + ValueTree v (type); + + const int numProps = input.readCompressedInt(); + + if (numProps < 0) + { + jassertfalse // trying to read corrupted data! + return v; + } + + int i; + for (i = 0; i < numProps; ++i) + { + const String name (input.readString()); + jassert (name.isNotEmpty()); + const var value (var::readFromStream (input)); + v.setProperty (name, value, 0); + } + + const int numChildren = input.readCompressedInt(); + + for (i = 0; i < numChildren; ++i) + v.addChild (readFromStream (input), -1, 0); + + return v; +} + END_JUCE_NAMESPACE diff --git a/src/containers/juce_ValueTree.h b/src/containers/juce_ValueTree.h index 49f5b139a1..3b4e89aca8 100644 --- a/src/containers/juce_ValueTree.h +++ b/src/containers/juce_ValueTree.h @@ -183,6 +183,16 @@ public: */ ValueTree getChildWithName (const String& type) const throw(); + /** Looks for the first child node that has the speficied property value. + + This will scan the child nodes in order, until it finds one that has property that matches + the specified value. + + If no such node is found, it'll return an invalid node. (See isValid() to find out + whether a node is valid). + */ + ValueTree getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const throw(); + /** Adds a child to this node. Make sure that the child is removed from any former parent node before calling this, or @@ -241,6 +251,20 @@ public: */ static ValueTree fromXml (const XmlElement& xml) throw(); + //============================================================================== + /** Stores this tree (and all its children) in a binary format. + + Once written, the data can be read back with readFromStream(). + + It's much faster to load/save your tree in binary form than as XML, but + obviously isn't human-readable. + */ + void writeToStream (OutputStream& output) throw(); + + /** Reloads a tree from a stream that was written with writeToStream(). + */ + static ValueTree readFromStream (InputStream& input) throw(); + //============================================================================== /** Listener class for events that happen to a ValueTree. @@ -254,13 +278,13 @@ public: virtual ~Listener() {} /** This method is called when one or more of the properties of this node have changed. */ - virtual void ValueTreePropertyChanged (ValueTree& tree) = 0; + virtual void valueTreePropertyChanged (ValueTree& tree) = 0; /** This method is called when one or more of the children of this node have been added or removed. */ - virtual void ValueTreeChildrenChanged (ValueTree& tree) = 0; + virtual void valueTreeChildrenChanged (ValueTree& tree) = 0; /** This method is called when this node has been added or removed from a parent node. */ - virtual void ValueTreeParentChanged() = 0; + virtual void valueTreeParentChanged() = 0; }; /** Adds a listener to receive callbacks when this node is changed. */ @@ -285,9 +309,9 @@ private: struct Property { - Property (const var::identifier& id, const var& value) throw(); + Property (const var::identifier& name, const var& value) throw(); - var::identifier id; + var::identifier name; var value; }; @@ -307,6 +331,7 @@ private: void removeAllProperties (UndoManager* const undoManager) throw(); bool isAChildOf (const SharedObject* const possibleParent) const throw(); ValueTree getChildWithName (const String& type) const throw(); + ValueTree getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const throw(); void addChild (SharedObject* child, int index, UndoManager* const undoManager) throw(); void removeChild (const int childIndex, UndoManager* const undoManager) throw(); void removeAllChildren (UndoManager* const undoManager) throw(); diff --git a/src/containers/juce_Variant.cpp b/src/containers/juce_Variant.cpp index 11ffb7ada6..b0cd527ffe 100644 --- a/src/containers/juce_Variant.cpp +++ b/src/containers/juce_Variant.cpp @@ -237,6 +237,11 @@ var::operator bool() const throw() return false; } +var::operator float() const throw() +{ + return (float) operator double(); +} + var::operator double() const throw() { switch (type) @@ -250,7 +255,7 @@ var::operator double() const throw() default: jassertfalse; break; } - return 0; + return 0.0; } const String var::toString() const throw() @@ -310,7 +315,7 @@ void var::writeToStream (OutputStream& output) const throw() case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break; case stringType: { - const int len = value.stringValue->copyToUTF8 (0, -1); + const int len = value.stringValue->copyToUTF8 (0); output.writeCompressedInt (len + 1); output.writeByte (5); uint8* const temp = (uint8*) juce_malloc (len); @@ -419,12 +424,14 @@ var::identifier::identifier (const String& name_) throw() : name (name_), hashCode (name_.hashCode()) { + jassert (name_.isNotEmpty()); } var::identifier::identifier (const char* const name_) throw() : name (name_), hashCode (name.hashCode()) { + jassert (name.isNotEmpty()); } var::identifier::~identifier() throw() diff --git a/src/containers/juce_Variant.h b/src/containers/juce_Variant.h index f1a72c40b9..f004938d63 100644 --- a/src/containers/juce_Variant.h +++ b/src/containers/juce_Variant.h @@ -80,6 +80,7 @@ public: operator int() const throw(); operator bool() const throw(); + operator float() const throw(); operator double() const throw(); operator const String() const throw(); const String toString() const throw(); diff --git a/src/core/juce_PlatformUtilities.h b/src/core/juce_PlatformUtilities.h index 58a957ba71..77fa32af20 100644 --- a/src/core/juce_PlatformUtilities.h +++ b/src/core/juce_PlatformUtilities.h @@ -210,6 +210,9 @@ public: private: void* pool; + + ScopedAutoReleasePool (const ScopedAutoReleasePool&); + const ScopedAutoReleasePool& operator= (const ScopedAutoReleasePool&); }; #endif @@ -297,6 +300,9 @@ private: int remoteId; bool open (const bool openInExclusiveMode) throw(); + + AppleRemoteDevice (const AppleRemoteDevice&); + const AppleRemoteDevice& operator= (const AppleRemoteDevice&); }; #endif diff --git a/src/core/juce_SystemStats.cpp b/src/core/juce_SystemStats.cpp index d57898064a..b91703a358 100644 --- a/src/core/juce_SystemStats.cpp +++ b/src/core/juce_SystemStats.cpp @@ -35,6 +35,8 @@ BEGIN_JUCE_NAMESPACE #include "../threads/juce_Thread.h" #include "../text/juce_LocalisedStrings.h" #include "juce_PlatformUtilities.h" +#include "../io/streams/juce_MemoryOutputStream.h" +#include "../io/streams/juce_MemoryInputStream.h" void juce_initialiseStrings(); @@ -57,21 +59,51 @@ void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI() #endif #ifdef JUCE_DEBUG - // Some simple test code to keep an eye on things and make sure these functions - // work ok on all platforms. Let me know if any of these assertions fail! - int n = 1; - atomicIncrement (n); - jassert (atomicIncrementAndReturn (n) == 3); - atomicDecrement (n); - jassert (atomicDecrementAndReturn (n) == 1); + { + // Some simple test code to keep an eye on things and make sure these functions + // work ok on all platforms. Let me know if any of these assertions fail! + int n = 1; + atomicIncrement (n); + jassert (atomicIncrementAndReturn (n) == 3); + atomicDecrement (n); + jassert (atomicDecrementAndReturn (n) == 1); - jassert (swapByteOrder ((uint32) 0x11223344) == 0x44332211); + jassert (swapByteOrder ((uint32) 0x11223344) == 0x44332211); - // quick test to make sure the run-time lib doesn't crash on freeing a null-pointer. - SystemStats* nullPointer = 0; - juce_free (nullPointer); - delete[] nullPointer; - delete nullPointer; + // quick test to make sure the run-time lib doesn't crash on freeing a null-pointer. + SystemStats* nullPointer = 0; + juce_free (nullPointer); + delete[] nullPointer; + delete nullPointer; + + // Some quick stream tests.. + int randomInt = Random::getSystemRandom().nextInt(); + int64 randomInt64 = Random::getSystemRandom().nextInt64(); + double randomDouble = Random::getSystemRandom().nextDouble(); + String randomString; + for (int i = 50; --i >= 0;) + randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff); + + MemoryOutputStream mo; + mo.writeInt (randomInt); + mo.writeIntBigEndian (randomInt); + mo.writeCompressedInt (randomInt); + mo.writeString (randomString); + mo.writeInt64 (randomInt64); + mo.writeInt64BigEndian (randomInt64); + mo.writeDouble (randomDouble); + mo.writeDoubleBigEndian (randomDouble); + + MemoryInputStream mi (mo.getData(), mo.getDataSize(), false); + jassert (mi.readInt() == randomInt); + jassert (mi.readIntBigEndian() == randomInt); + jassert (mi.readCompressedInt() == randomInt); + jassert (mi.readString() == randomString); + jassert (mi.readInt64() == randomInt64); + jassert (mi.readInt64BigEndian() == randomInt64); + jassert (mi.readDouble() == randomDouble); + jassert (mi.readDoubleBigEndian() == randomDouble); + } #endif // Now the real initialisation.. diff --git a/src/cryptography/juce_MD5.cpp b/src/cryptography/juce_MD5.cpp index 03974529a2..1948f38c04 100644 --- a/src/cryptography/juce_MD5.cpp +++ b/src/cryptography/juce_MD5.cpp @@ -271,7 +271,7 @@ static inline void II (uint32& a, const uint32 b, const uint32 c, const uint32 d a = rotateLeft (a, s) + b; } -void MD5::ProcessContext::transform (const uint8* const buffer) +void MD5::ProcessContext::transform (const uint8* const bufferToTransform) { uint32 a = state[0]; uint32 b = state[1]; @@ -279,7 +279,7 @@ void MD5::ProcessContext::transform (const uint8* const buffer) uint32 d = state[3]; uint32 x[16]; - decode (x, buffer, 64); + decode (x, bufferToTransform, 64); FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ diff --git a/src/events/juce_MessageManager.h b/src/events/juce_MessageManager.h index 813348dc92..01db907f77 100644 --- a/src/events/juce_MessageManager.h +++ b/src/events/juce_MessageManager.h @@ -308,6 +308,9 @@ private: void* sharedEvents; void init (Thread* const thread, ThreadPoolJob* const job) throw(); + + MessageManagerLock (const MessageManagerLock&); + const MessageManagerLock& operator= (const MessageManagerLock&); }; diff --git a/src/gui/components/buttons/juce_ShapeButton.cpp b/src/gui/components/buttons/juce_ShapeButton.cpp index a3c6a10de3..a384af57bb 100644 --- a/src/gui/components/buttons/juce_ShapeButton.cpp +++ b/src/gui/components/buttons/juce_ShapeButton.cpp @@ -31,11 +31,11 @@ BEGIN_JUCE_NAMESPACE //============================================================================== -ShapeButton::ShapeButton (const String& text, +ShapeButton::ShapeButton (const String& text_, const Colour& normalColour_, const Colour& overColour_, const Colour& downColour_) - : Button (text), + : Button (text_), normalColour (normalColour_), overColour (overColour_), downColour (downColour_), diff --git a/src/gui/components/code_editor/juce_CodeDocument.cpp b/src/gui/components/code_editor/juce_CodeDocument.cpp index 2e58e75efe..65c81b9383 100644 --- a/src/gui/components/code_editor/juce_CodeDocument.cpp +++ b/src/gui/components/code_editor/juce_CodeDocument.cpp @@ -227,11 +227,11 @@ CodeDocument::Position::Position (const CodeDocument* const ownerDocument, } CodeDocument::Position::Position (const CodeDocument* const ownerDocument, - const int characterPos) throw() + const int characterPos_) throw() : owner (const_cast (ownerDocument)), positionMaintained (false) { - setPosition (characterPos); + setPosition (characterPos_); } CodeDocument::Position::Position (const Position& other) throw() diff --git a/src/gui/components/controls/juce_ComboBox.cpp b/src/gui/components/controls/juce_ComboBox.cpp index 0a02ecac00..de7741843c 100644 --- a/src/gui/components/controls/juce_ComboBox.cpp +++ b/src/gui/components/controls/juce_ComboBox.cpp @@ -156,12 +156,12 @@ void ComboBox::addSectionHeading (const String& headingName) throw() } void ComboBox::setItemEnabled (const int itemId, - const bool isEnabled) throw() + const bool shouldBeEnabled) throw() { ItemInfo* const item = getItemForId (itemId); if (item != 0) - item->isEnabled = isEnabled; + item->isEnabled = shouldBeEnabled; } void ComboBox::changeItemText (const int itemId, diff --git a/src/gui/components/controls/juce_ComboBox.h b/src/gui/components/controls/juce_ComboBox.h index 78a1fe7e5f..c9ec4b342b 100644 --- a/src/gui/components/controls/juce_ComboBox.h +++ b/src/gui/components/controls/juce_ComboBox.h @@ -149,7 +149,7 @@ public: current selection - it just stops the user choosing that item from the list. */ void setItemEnabled (const int itemId, - const bool isEnabled) throw(); + const bool shouldBeEnabled) throw(); /** Changes the text for an existing item. */ diff --git a/src/gui/components/controls/juce_Toolbar.cpp b/src/gui/components/controls/juce_Toolbar.cpp index 574121d0bc..b954057172 100644 --- a/src/gui/components/controls/juce_Toolbar.cpp +++ b/src/gui/components/controls/juce_Toolbar.cpp @@ -46,8 +46,8 @@ const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_"); class ToolbarSpacerComp : public ToolbarItemComponent { public: - ToolbarSpacerComp (const int itemId, const float fixedSize_, const bool drawBar_) - : ToolbarItemComponent (itemId, String::empty, false), + ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_) + : ToolbarItemComponent (itemId_, String::empty, false), fixedSize (fixedSize_), drawBar (drawBar_) { diff --git a/src/gui/components/controls/juce_TreeView.cpp b/src/gui/components/controls/juce_TreeView.cpp index 875eaaac4c..91d2a40a2e 100644 --- a/src/gui/components/controls/juce_TreeView.cpp +++ b/src/gui/components/controls/juce_TreeView.cpp @@ -1563,27 +1563,27 @@ TreeViewItem* TreeViewItem::getItemOnRow (int index) throw() return 0; } -TreeViewItem* TreeViewItem::findItemRecursively (int y) throw() +TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw() { - if (((unsigned int) y) < (unsigned int) totalHeight) + if (((unsigned int) targetY) < (unsigned int) totalHeight) { const int h = itemHeight; - if (y < h) + if (targetY < h) return this; if (isOpen()) { - y -= h; + targetY -= h; for (int i = 0; i < subItems.size(); ++i) { TreeViewItem* const ti = subItems.getUnchecked(i); - if (y < ti->totalHeight) - return ti->findItemRecursively (y); + if (targetY < ti->totalHeight) + return ti->findItemRecursively (targetY); - y -= ti->totalHeight; + targetY -= ti->totalHeight; } } } diff --git a/src/gui/components/filebrowser/juce_FileSearchPathListComponent.cpp b/src/gui/components/filebrowser/juce_FileSearchPathListComponent.cpp index 948a4ad334..d7fcba53b7 100644 --- a/src/gui/components/filebrowser/juce_FileSearchPathListComponent.cpp +++ b/src/gui/components/filebrowser/juce_FileSearchPathListComponent.cpp @@ -60,7 +60,7 @@ FileSearchPathListComponent::FileSearchPathListComponent() { Path arrowPath; - arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0, 40.0f, 100.0f, 50.0f); + arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f); DrawablePath arrowImage; arrowImage.setFill (Colours::black.withAlpha (0.4f)); arrowImage.setPath (arrowPath); diff --git a/src/gui/components/filebrowser/juce_WildcardFileFilter.cpp b/src/gui/components/filebrowser/juce_WildcardFileFilter.cpp index 4f195ccf75..fd492cbe8e 100644 --- a/src/gui/components/filebrowser/juce_WildcardFileFilter.cpp +++ b/src/gui/components/filebrowser/juce_WildcardFileFilter.cpp @@ -33,9 +33,9 @@ BEGIN_JUCE_NAMESPACE //============================================================================== WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns, const String& directoryWildcardPatterns, - const String& description) - : FileFilter (description.isEmpty() ? fileWildcardPatterns - : (description + T(" (") + fileWildcardPatterns + T(")"))) + const String& description_) + : FileFilter (description_.isEmpty() ? fileWildcardPatterns + : (description_ + T(" (") + fileWildcardPatterns + T(")"))) { parse (fileWildcardPatterns, fileWildcards); parse (directoryWildcardPatterns, directoryWildcards); diff --git a/src/gui/components/juce_Component.cpp b/src/gui/components/juce_Component.cpp index e8b9136431..706e7ee08f 100644 --- a/src/gui/components/juce_Component.cpp +++ b/src/gui/components/juce_Component.cpp @@ -1464,7 +1464,7 @@ int Component::runModalLoop() return returnValue; } -void Component::enterModalState (const bool takeKeyboardFocus) +void Component::enterModalState (const bool takeKeyboardFocus_) { // if component methods are being called from threads other than the message // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe. @@ -1483,7 +1483,7 @@ void Component::enterModalState (const bool takeKeyboardFocus) flags.currentlyModalFlag = true; setVisible (true); - if (takeKeyboardFocus) + if (takeKeyboardFocus_) grabKeyboardFocus(); } } @@ -3235,9 +3235,9 @@ bool Component::getWantsKeyboardFocus() const throw() return flags.wantsFocusFlag && ! flags.isDisabledFlag; } -void Component::setFocusContainer (const bool isFocusContainer) throw() +void Component::setFocusContainer (const bool shouldBeFocusContainer) throw() { - flags.isFocusContainerFlag = isFocusContainer; + flags.isFocusContainerFlag = shouldBeFocusContainer; } bool Component::isFocusContainer() const throw() diff --git a/src/gui/components/juce_Component.h b/src/gui/components/juce_Component.h index 1ce2ff68e0..2aa1f71efb 100644 --- a/src/gui/components/juce_Component.h +++ b/src/gui/components/juce_Component.h @@ -1116,7 +1116,7 @@ public: @see isFocusContainer, createFocusTraverser, moveKeyboardFocusToSibling */ - void setFocusContainer (const bool isFocusContainer) throw(); + void setFocusContainer (const bool shouldBeFocusContainer) throw(); /** Returns true if this component has been marked as a focus container. diff --git a/src/gui/components/keyboard/juce_KeyListener.h b/src/gui/components/keyboard/juce_KeyListener.h index 83972a6081..0ddfddcb2a 100644 --- a/src/gui/components/keyboard/juce_KeyListener.h +++ b/src/gui/components/keyboard/juce_KeyListener.h @@ -74,11 +74,6 @@ public: @see KeyPress, Component::keyStateChanged */ virtual bool keyStateChanged (const bool isKeyDown, Component* originatingComponent); - -private: - // (dummy method to cause a deliberate compile error - if you hit this, you need to update your - // subclass to use the new parameters to keyStateChanged) - virtual void keyStateChanged (Component*) {}; }; diff --git a/src/gui/components/lookandfeel/juce_LookAndFeel.cpp b/src/gui/components/lookandfeel/juce_LookAndFeel.cpp index b0e3cd12c1..520c513240 100644 --- a/src/gui/components/lookandfeel/juce_LookAndFeel.cpp +++ b/src/gui/components/lookandfeel/juce_LookAndFeel.cpp @@ -649,8 +649,8 @@ void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar, Image im (Image::ARGB, width, height, true); { - Graphics g (im); - drawGlassLozenge (g, 1.0f, 1.0f, + Graphics g2 (im); + drawGlassLozenge (g2, 1.0f, 1.0f, (float) (width - 2), (float) (height - 2), foreground, @@ -2612,7 +2612,7 @@ Button* LookAndFeel::createFileBrowserGoUpButton() DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground); Path arrowPath; - arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0, 40.0f, 100.0f, 50.0f); + arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f); DrawablePath arrowImage; arrowImage.setFill (Colours::black.withAlpha (0.4f)); diff --git a/src/gui/components/menus/juce_PopupMenu.cpp b/src/gui/components/menus/juce_PopupMenu.cpp index 17ff40a039..f8bcadd237 100644 --- a/src/gui/components/menus/juce_PopupMenu.cpp +++ b/src/gui/components/menus/juce_PopupMenu.cpp @@ -928,12 +928,12 @@ private: do { ++numColumns; - totalW = workOutBestSize (numColumns, maxMenuW); + totalW = workOutBestSize (maxMenuW); if (totalW > maxMenuW) { numColumns = jmax (1, numColumns - 1); - totalW = workOutBestSize (numColumns, maxMenuW); // to update col widths + totalW = workOutBestSize (maxMenuW); // to update col widths break; } else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH) @@ -951,7 +951,7 @@ private: height = actualH + borderSize * 2; } - int workOutBestSize (const int numColumns, const int maxMenuW) + int workOutBestSize (const int maxMenuW) { int totalW = 0; contentHeight = 0; diff --git a/src/gui/components/mouse/juce_MouseListener.h b/src/gui/components/mouse/juce_MouseListener.h index 2f3c7afa72..6cfb8e7821 100644 --- a/src/gui/components/mouse/juce_MouseListener.h +++ b/src/gui/components/mouse/juce_MouseListener.h @@ -161,13 +161,6 @@ public: virtual void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); - - -private: - // XXX Deprecated! The parameters for this method have changed to accommodate horizonatal scroll-wheels. - // This line is here to cause a syntax error if you're trying to use the old-style definition, so - // if that happens, update your code to use the new one above. - virtual int mouseWheelMove (const MouseEvent&, float) { return 0; } }; diff --git a/src/gui/components/special/juce_BubbleComponent.cpp b/src/gui/components/special/juce_BubbleComponent.cpp index 81d40d01bf..8d881b87ef 100644 --- a/src/gui/components/special/juce_BubbleComponent.cpp +++ b/src/gui/components/special/juce_BubbleComponent.cpp @@ -109,10 +109,10 @@ void BubbleComponent::setPosition (Component* componentToPointTo) setPosition (Rectangle (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight())); } -void BubbleComponent::setPosition (const int arrowTipX, - const int arrowTipY) +void BubbleComponent::setPosition (const int arrowTipX_, + const int arrowTipY_) { - setPosition (Rectangle (arrowTipX, arrowTipY, 1, 1)); + setPosition (Rectangle (arrowTipX_, arrowTipY_, 1, 1)); } //============================================================================== diff --git a/src/gui/components/special/juce_ColourSelector.cpp b/src/gui/components/special/juce_ColourSelector.cpp index 70a5042c4f..bed62e180c 100644 --- a/src/gui/components/special/juce_ColourSelector.cpp +++ b/src/gui/components/special/juce_ColourSelector.cpp @@ -49,9 +49,9 @@ public: { } - const String getTextFromValue (double currentValue) + const String getTextFromValue (double value) { - return String::formatted (T("%02X"), (int)currentValue); + return String::formatted (T("%02X"), (int) value); } double getValueFromText (const String& text) diff --git a/src/gui/components/special/juce_OpenGLComponent.cpp b/src/gui/components/special/juce_OpenGLComponent.cpp index 8370301f92..42f123338f 100644 --- a/src/gui/components/special/juce_OpenGLComponent.cpp +++ b/src/gui/components/special/juce_OpenGLComponent.cpp @@ -199,13 +199,13 @@ void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse) } } -void OpenGLComponent::shareWith (OpenGLContext* context) +void OpenGLComponent::shareWith (OpenGLContext* c) { - if (contextToShareListsWith != context) + if (contextToShareListsWith != c) { const ScopedLock sl (contextLock); deleteContext(); - contextToShareListsWith = context; + contextToShareListsWith = c; } } diff --git a/src/gui/graphics/contexts/juce_FillType.cpp b/src/gui/graphics/contexts/juce_FillType.cpp index dbbd457146..c4267bf978 100644 --- a/src/gui/graphics/contexts/juce_FillType.cpp +++ b/src/gui/graphics/contexts/juce_FillType.cpp @@ -42,8 +42,8 @@ FillType::FillType (const Colour& colour_) throw() { } -FillType::FillType (const ColourGradient& gradient) throw() - : colour (0xff000000), gradient (new ColourGradient (gradient)), image (0) +FillType::FillType (const ColourGradient& gradient_) throw() + : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0) { } diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp index 05066bc80f..b1699410b6 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp @@ -394,7 +394,7 @@ void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const Affin // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the // time-being, this just fills it with the average colour.. - writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5)); + writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f)); out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n"; out << "grestore\n"; diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp index ca9ee47afd..483a0ad0d2 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp @@ -184,7 +184,7 @@ public: if (! transform.isIdentity()) { const Line l (x2, y2, x1, y1); - const Point p3 = l.getPointAlongLine (0.0, 100.0f); + const Point p3 = l.getPointAlongLine (0.0f, 100.0f); float x3 = p3.getX(); float y3 = p3.getY(); @@ -261,9 +261,9 @@ public: gy1 (gradient.y1) { jassert (numEntries_ >= 0); - const float dx = gradient.x1 - gradient.x2; - const float dy = gradient.y1 - gradient.y2; - maxDist = dx * dx + dy * dy; + const float gdx = gradient.x1 - gradient.x2; + const float gdy = gradient.y1 - gradient.y2; + maxDist = gdx * gdx + gdy * gdy; invScale = numEntries / sqrt (maxDist); jassert (roundDoubleToInt (sqrt (maxDist) * invScale) <= numEntries); } @@ -340,8 +340,8 @@ class GradientEdgeTableRenderer : public GradientType { public: GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform, - const PixelARGB* const lookupTable, const int numEntries) throw() - : GradientType (gradient, transform, lookupTable, numEntries - 1), + const PixelARGB* const lookupTable_, const int numEntries_) throw() + : GradientType (gradient, transform, lookupTable_, numEntries_ - 1), destData (destData_) { } @@ -465,8 +465,8 @@ public: void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw() { jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width); - SrcPixelType* sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y - yOffset); - uint8* mask = (uint8*) (sourceLineStart + x - xOffset); + SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset); + uint8* mask = (uint8*) (s + x - xOffset); if (sizeof (SrcPixelType) == sizeof (PixelARGB)) mask += PixelARGB::indexA; diff --git a/src/gui/graphics/drawables/juce_Drawable.cpp b/src/gui/graphics/drawables/juce_Drawable.cpp index c95d838351..3abcf13eb0 100644 --- a/src/gui/graphics/drawables/juce_Drawable.cpp +++ b/src/gui/graphics/drawables/juce_Drawable.cpp @@ -29,7 +29,9 @@ BEGIN_JUCE_NAMESPACE #include "juce_Drawable.h" #include "juce_DrawableComposite.h" +#include "juce_DrawablePath.h" #include "juce_DrawableImage.h" +#include "juce_DrawableText.h" #include "../imaging/juce_ImageFileFormat.h" #include "../../../text/juce_XmlDocument.h" #include "../../../io/files/juce_FileInputStream.h" @@ -143,62 +145,24 @@ Drawable* Drawable::createFromImageFile (const File& file) } //============================================================================== -Drawable* Drawable::readFromBinaryStream (InputStream& input) +Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw() { - char header[8]; - if (input.read (header, sizeof (header)) != sizeof (header)) - return 0; + Drawable* d = DrawablePath::createFromValueTree (tree); - DrawableComposite* result = 0; - - if (memcmp (header, "JuceDrw1", sizeof (header)) == 0) + if (d == 0) { - result = new DrawableComposite(); + d = DrawableComposite::createFromValueTree (tree); - if (! result->readBinary (input)) - deleteAndZero (result); + if (d == 0) + { + d = DrawableImage::createFromValueTree (tree); + + if (d == 0) + d = DrawableText::createFromValueTree (tree); + } } - return result; -} - -bool Drawable::writeToBinaryStream (OutputStream& output) const -{ - output.write ("JuceDrw1", 8); - return writeBinary (output); -} - -Drawable* Drawable::readFromXml (const XmlElement& xml) -{ - DrawableComposite* result = 0; - - if (xml.hasTagName (T("JuceDrawable"))) - { - result = new DrawableComposite(); - - if (! result->readXml (xml)) - deleteAndZero (result); - } - - return result; -} - -XmlElement* Drawable::createXml() const -{ - if (dynamic_cast (this) == 0) - { - DrawableComposite tempDC; - tempDC.insertDrawable (const_cast (this)); - XmlElement* result = tempDC.createXml(); - tempDC.removeDrawable (0, false); - return result; - } - else - { - XmlElement* e = new XmlElement (T("JuceDrawable")); - writeXml (*e); - return e; - } + return d; } diff --git a/src/gui/graphics/drawables/juce_Drawable.h b/src/gui/graphics/drawables/juce_Drawable.h index 27bfe9964d..ec283e0629 100644 --- a/src/gui/graphics/drawables/juce_Drawable.h +++ b/src/gui/graphics/drawables/juce_Drawable.h @@ -28,6 +28,7 @@ #include "../contexts/juce_Graphics.h" #include "../../../text/juce_XmlElement.h" +#include "../../../containers/juce_ValueTree.h" //============================================================================== @@ -180,31 +181,16 @@ public: static Drawable* createFromSVG (const XmlElement& svgDocument); //============================================================================== - /** + /** Tries to create a Drawable from a previously-saved ValueTree. + The ValueTree must have been created by the createValueTree() method. */ - static Drawable* readFromBinaryStream (InputStream& input); + static Drawable* createFromValueTree (const ValueTree& tree) throw(); - /** + /** Creates a ValueTree to represent this Drawable. + The VarTree that is returned can be turned back into a Drawable with + createFromValueTree(). */ - bool writeToBinaryStream (OutputStream& output) const; - - /** - */ - static Drawable* readFromXml (const XmlElement& xml); - - /** - */ - XmlElement* createXml() const; - - //============================================================================== - /** @internal */ - virtual bool readBinary (InputStream& input) = 0; - /** @internal */ - virtual bool writeBinary (OutputStream& output) const = 0; - /** @internal */ - virtual bool readXml (const XmlElement& xml) = 0; - /** @internal */ - virtual void writeXml (XmlElement& xml) const = 0; + virtual ValueTree createValueTree() const throw() = 0; //============================================================================== juce_UseDebuggingNewOperator diff --git a/src/gui/graphics/drawables/juce_DrawableComposite.cpp b/src/gui/graphics/drawables/juce_DrawableComposite.cpp index 1d513f3d87..4a96771c8e 100644 --- a/src/gui/graphics/drawables/juce_DrawableComposite.cpp +++ b/src/gui/graphics/drawables/juce_DrawableComposite.cpp @@ -187,184 +187,18 @@ Drawable* DrawableComposite::createCopy() const } //============================================================================== -const char juce_drawableCompositeTransformFlag = 't'; -const char juce_drawableCompositeBinaryType = 'C'; -const char juce_drawablePathBinaryType = 'P'; -const char juce_drawableImageBinaryType = 'I'; -const char juce_drawableTextBinaryType = 'T'; - -bool DrawableComposite::readBinary (InputStream& input) +ValueTree DrawableComposite::createValueTree() const throw() { - AffineTransform transform; + ValueTree v (T("Group")); - while (! input.isExhausted()) - { - const int n = input.readByte(); + if (getName().isNotEmpty()) + v.setProperty ("id", getName(), 0); - if (n == 0) - break; - - if (n == juce_drawableCompositeTransformFlag) - { - float f[6]; - for (int i = 0; i < 6; ++i) - f[i] = input.readFloat(); - - transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]); - } - else - { - Drawable* d = 0; - - switch (n) - { - case juce_drawableCompositeBinaryType: d = new DrawableComposite(); break; - case juce_drawablePathBinaryType: d = new DrawablePath(); break; - case juce_drawableImageBinaryType: d = new DrawableImage(); break; - case juce_drawableTextBinaryType: d = new DrawableText(); break; - default: jassertfalse; return false; - } - - d->setName (input.readString()); - - if (! d->readBinary (input)) - { - delete d; - return false; - } - - insertDrawable (d, transform); - transform = AffineTransform::identity; - } - } - - return true; -} - -bool DrawableComposite::writeBinary (OutputStream& output) const -{ for (int i = 0; i < drawables.size(); ++i) { - AffineTransform* transform = transforms.getUnchecked(i); - - if (transform != 0) - { - output.writeByte (juce_drawableCompositeTransformFlag); - output.writeFloat (transform->mat00); - output.writeFloat (transform->mat01); - output.writeFloat (transform->mat02); - output.writeFloat (transform->mat10); - output.writeFloat (transform->mat11); - output.writeFloat (transform->mat12); - } - Drawable* const d = drawables.getUnchecked(i); - char typeFlag; - - if (dynamic_cast (d) != 0) - typeFlag = juce_drawableCompositeBinaryType; - else if (dynamic_cast (d) != 0) - typeFlag = juce_drawablePathBinaryType; - else if (dynamic_cast (d) != 0) - typeFlag = juce_drawableImageBinaryType; - else if (dynamic_cast (d) != 0) - typeFlag = juce_drawableTextBinaryType; - else - { - jassertfalse; - continue; - } - - output.writeByte (typeFlag); - output.writeString (d->getName()); - d->writeBinary (output); - } - - output.writeByte (0); - return true; -} - -//============================================================================== -const tchar* juce_drawableCompositeXmlTag = T("Group"); -const tchar* juce_drawablePathXmlTag = T("Path"); -const tchar* juce_drawableImageXmlTag = T("Image"); -const tchar* juce_drawableTextXmlTag = T("Text"); - -bool DrawableComposite::readXml (const XmlElement& xml) -{ - forEachXmlChildElement (xml, e) - { - Drawable* d = 0; - - if (e->hasTagName (juce_drawableCompositeXmlTag)) - d = new DrawableComposite(); - else if (e->hasTagName (juce_drawablePathXmlTag)) - d = new DrawablePath(); - else if (e->hasTagName (juce_drawableImageXmlTag)) - d = new DrawableImage(); - else if (e->hasTagName (juce_drawableTextXmlTag)) - d = new DrawableText(); - else - { - jassertfalse; - return false; - } - - d->setName (e->getStringAttribute (T("id"))); - - if (! d->readXml (*e)) - { - jassertfalse; - delete d; - return false; - } - - AffineTransform transform; - const String transformAtt (e->getStringAttribute (T("transform"))); - - if (transformAtt.isNotEmpty()) - { - StringArray tokens; - tokens.addTokens (transformAtt.trim(), false); - tokens.removeEmptyStrings (true); - - if (tokens.size() == 6) - { - float f[6]; - for (int i = 0; i < 6; ++i) - f[i] = (float) tokens[i].getDoubleValue(); - - transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]); - } - } - - insertDrawable (d, transform); - } - - return true; -} - -void DrawableComposite::writeXml (XmlElement& xml) const -{ - for (int i = 0; i < drawables.size(); ++i) - { - XmlElement* e = 0; - Drawable* const d = drawables.getUnchecked(i); - - if (dynamic_cast (d) != 0) - e = new XmlElement (juce_drawableCompositeXmlTag); - else if (dynamic_cast (d) != 0) - e = new XmlElement (juce_drawablePathXmlTag); - else if (dynamic_cast (d) != 0) - e = new XmlElement (juce_drawableImageXmlTag); - else if (dynamic_cast (d) != 0) - e = new XmlElement (juce_drawableTextXmlTag); - else - { - jassertfalse; - continue; - } + ValueTree child (d->createValueTree()); AffineTransform* transform = transforms.getUnchecked(i); @@ -374,16 +208,55 @@ void DrawableComposite::writeXml (XmlElement& xml) const t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " " << transform->mat10 << " " << transform->mat11 << " " << transform->mat12; - e->setAttribute (T("transform"), t); + child.setProperty ("transform", t, 0); } - if (d->getName().isNotEmpty()) - e->setAttribute (T("id"), d->getName()); - - d->writeXml (*e); - - xml.addChildElement (e); + v.addChild (child, -1, 0); } + + return v; } +DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw() +{ + if (! tree.hasType ("Group")) + return 0; + + DrawableComposite* dc = new DrawableComposite(); + dc->setName (tree ["id"]); + + for (int i = 0; i < tree.getNumChildren(); ++i) + { + ValueTree childTree (tree.getChild (i)); + Drawable* d = Drawable::createFromValueTree (childTree); + + if (d != 0) + { + AffineTransform transform; + const String transformAtt (childTree ["transform"].toString()); + + if (transformAtt.isNotEmpty()) + { + StringArray tokens; + tokens.addTokens (transformAtt.trim(), false); + tokens.removeEmptyStrings (true); + + if (tokens.size() == 6) + { + float f[6]; + for (int j = 0; j < 6; ++j) + f[j] = (float) tokens[j].getDoubleValue(); + + transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]); + } + } + + dc->insertDrawable (d, transform); + } + } + + return dc; +} + + END_JUCE_NAMESPACE diff --git a/src/gui/graphics/drawables/juce_DrawableComposite.h b/src/gui/graphics/drawables/juce_DrawableComposite.h index 4d00f5f771..6cc4c42058 100644 --- a/src/gui/graphics/drawables/juce_DrawableComposite.h +++ b/src/gui/graphics/drawables/juce_DrawableComposite.h @@ -140,13 +140,9 @@ public: /** @internal */ Drawable* createCopy() const; /** @internal */ - bool readBinary (InputStream& input); + ValueTree createValueTree() const throw(); /** @internal */ - bool writeBinary (OutputStream& output) const; - /** @internal */ - bool readXml (const XmlElement& xml); - /** @internal */ - void writeXml (XmlElement& xml) const; + static DrawableComposite* createFromValueTree (const ValueTree& tree) throw(); //============================================================================== juce_UseDebuggingNewOperator diff --git a/src/gui/graphics/drawables/juce_DrawableImage.cpp b/src/gui/graphics/drawables/juce_DrawableImage.cpp index 55457b7871..3ae7992b40 100644 --- a/src/gui/graphics/drawables/juce_DrawableImage.cpp +++ b/src/gui/graphics/drawables/juce_DrawableImage.cpp @@ -155,71 +155,18 @@ Drawable* DrawableImage::createCopy() const } //============================================================================== -bool DrawableImage::readBinary (InputStream& input) +ValueTree DrawableImage::createValueTree() const throw() { - opacity = input.readFloat(); - overlayColour = Colour (input.readInt()); + ValueTree v (T("Image")); - const int dataLen = input.readInt(); + if (getName().isNotEmpty()) + v.setProperty ("id", getName(), 0); - if (dataLen > 0) - { - MemoryBlock imageData; - input.readIntoMemoryBlock (imageData, dataLen); - - Image* im = ImageFileFormat::loadFrom (imageData.getData(), imageData.getSize()); - if (im == 0) - return false; - - setImage (im, true); - } - - return true; -} - -bool DrawableImage::writeBinary (OutputStream& output) const -{ - MemoryOutputStream imageData; - - if (image != 0) - { - PNGImageFormat pngFormat; - if (! pngFormat.writeImageToStream (*image, imageData)) - return false; - } - - output.writeFloat (opacity); - output.writeInt (overlayColour.getARGB()); - output.writeInt (imageData.getDataSize()); - output.write (imageData.getData(), imageData.getDataSize()); - return true; -} - -bool DrawableImage::readXml (const XmlElement& xml) -{ - opacity = (float) xml.getDoubleAttribute (T("opacity"), 1.0); - overlayColour = Colour (xml.getStringAttribute (T("overlay"), T("0")).getHexValue32()); - - MemoryBlock imageData; - if (imageData.fromBase64Encoding (xml.getAllSubText())) - { - Image* const im = ImageFileFormat::loadFrom (imageData.getData(), imageData.getSize()); - if (im == 0) - return false; - - setImage (im, true); - } - - return true; -} - -void DrawableImage::writeXml (XmlElement& xml) const -{ if (opacity < 1.0f) - xml.setAttribute (T("opacity"), (double) opacity); + v.setProperty ("opacity", (double) opacity, 0); if (! overlayColour.isTransparent()) - xml.setAttribute (T("overlay"), String::toHexString ((int) overlayColour.getARGB())); + v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0); if (image != 0) { @@ -232,9 +179,36 @@ void DrawableImage::writeXml (XmlElement& xml) const for (int i = (base64.length() & ~127); i >= 0; i -= 128) base64 = base64.substring (0, i) + "\n" + base64.substring (i); - xml.addTextElement (base64); + v.setProperty ("data", base64, 0); } } + + return v; } +DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw() +{ + if (! tree.hasType ("Image")) + return 0; + + DrawableImage* di = new DrawableImage(); + + di->setName (tree ["id"]); + di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f; + di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32()); + + MemoryBlock imageData; + if (imageData.fromBase64Encoding (tree ["data"])) + { + Image* const im = ImageFileFormat::loadFrom (imageData.getData(), imageData.getSize()); + if (im == 0) + return false; + + di->setImage (im, true); + } + + return di; +} + + END_JUCE_NAMESPACE diff --git a/src/gui/graphics/drawables/juce_DrawableImage.h b/src/gui/graphics/drawables/juce_DrawableImage.h index 5bd48d83f3..09decedd51 100644 --- a/src/gui/graphics/drawables/juce_DrawableImage.h +++ b/src/gui/graphics/drawables/juce_DrawableImage.h @@ -108,13 +108,9 @@ public: /** @internal */ Drawable* createCopy() const; /** @internal */ - bool readBinary (InputStream& input); + ValueTree createValueTree() const throw(); /** @internal */ - bool writeBinary (OutputStream& output) const; - /** @internal */ - bool readXml (const XmlElement& xml); - /** @internal */ - void writeXml (XmlElement& xml) const; + static DrawableImage* createFromValueTree (const ValueTree& tree) throw(); //============================================================================== juce_UseDebuggingNewOperator diff --git a/src/gui/graphics/drawables/juce_DrawablePath.cpp b/src/gui/graphics/drawables/juce_DrawablePath.cpp index 7d567bf4d8..11e2c0e3ae 100644 --- a/src/gui/graphics/drawables/juce_DrawablePath.cpp +++ b/src/gui/graphics/drawables/juce_DrawablePath.cpp @@ -74,13 +74,15 @@ void DrawablePath::setStrokeThickness (const float newThickness) throw() //============================================================================== void DrawablePath::render (const Drawable::RenderingContext& context) const { - FillType f (mainFill); - if (f.isGradient()) - f.gradient->multiplyOpacity (context.opacity); + { + FillType f (mainFill); + if (f.isGradient()) + f.gradient->multiplyOpacity (context.opacity); - f.transform = f.transform.followedBy (context.transform); - context.g.setFillType (f); - context.g.fillPath (path, context.transform); + f.transform = f.transform.followedBy (context.transform); + context.g.setFillType (f); + context.g.fillPath (path, context.transform); + } if (strokeType.getStrokeThickness() > 0.0f) { @@ -127,226 +129,120 @@ Drawable* DrawablePath::createCopy() const } //============================================================================== -static const FillType readColourFromBinary (InputStream& input) +static const FillType readFillTypeFromTree (const ValueTree& v) { - switch (input.readByte()) + const String type (v["type"].toString()); + + if (type.equalsIgnoreCase (T("solid"))) { - case 1: - return FillType (Colour ((uint32) input.readInt())); + const String colour (v ["colour"].toString()); + return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000 + : (uint32) colour.getHexValue32())); + } + else if (type.equalsIgnoreCase ("gradient")) + { + ColourGradient g; + g.x1 = v["x1"]; + g.y1 = v["y1"]; + g.x2 = v["x2"]; + g.y2 = v["y2"]; + g.isRadial = v["radial"]; - case 2: - { - ColourGradient g; - g.x1 = input.readFloat(); - g.y1 = input.readFloat(); - g.x2 = input.readFloat(); - g.y2 = input.readFloat(); - g.isRadial = input.readByte() != 0; + StringArray colours; + colours.addTokens (v["colours"].toString(), false); - const int numColours = input.readCompressedInt(); - for (int i = 0; i < numColours; ++i) - { - double proportion = (double) input.readFloat(); - const Colour col ((uint32) input.readInt()); - g.addColour (proportion, col); - } + for (int i = 0; i < colours.size() / 2; ++i) + g.addColour (colours[i * 2].getDoubleValue(), + Colour ((uint32) colours[i * 2 + 1].getHexValue32())); - return FillType (g); - } - - default: - break; + return FillType (g); } + jassertfalse return FillType(); } -static void writeColourToBinary (OutputStream& output, const FillType& fillType) +static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType) { - if (fillType.isColour()) - { - output.writeByte (1); - output.writeInt ((int) fillType.colour.getARGB()); - } - else if (fillType.isGradient()) - { - output.writeByte (2); - - output.writeFloat (fillType.gradient->x1); - output.writeFloat (fillType.gradient->y1); - output.writeFloat (fillType.gradient->x2); - output.writeFloat (fillType.gradient->y2); - output.writeByte (fillType.gradient->isRadial ? 1 : 0); - - output.writeCompressedInt (fillType.gradient->getNumColours()); - - for (int i = 0; i < fillType.gradient->getNumColours(); ++i) - { - output.writeFloat ((float) fillType.gradient->getColourPosition (i)); - output.writeInt ((int) fillType.gradient->getColour (i).getARGB()); - } - } - else - { - jassertfalse // xxx - } - -} - -static const FillType readColourFromXml (const XmlElement* xml) -{ - if (xml != 0) - { - const String type (xml->getStringAttribute (T("type"))); - - if (type.equalsIgnoreCase (T("solid"))) - { - return FillType (Colour ((uint32) xml->getStringAttribute (T("colour"), T("ff000000")).getHexValue32())); - } - else if (type.equalsIgnoreCase (T("gradient"))) - { - ColourGradient g; - g.x1 = (float) xml->getDoubleAttribute (T("x1")); - g.y1 = (float) xml->getDoubleAttribute (T("y1")); - g.x2 = (float) xml->getDoubleAttribute (T("x2")); - g.y2 = (float) xml->getDoubleAttribute (T("y2")); - g.isRadial = xml->getBoolAttribute (T("radial"), false); - - StringArray colours; - colours.addTokens (xml->getStringAttribute (T("colours")), false); - - for (int i = 0; i < colours.size() / 2; ++i) - g.addColour (colours[i * 2].getDoubleValue(), - Colour ((uint32) colours[i * 2 + 1].getHexValue32())); - - return FillType (g); - } - else - { - jassertfalse - } - } - - return FillType(); -} - -static XmlElement* writeColourToXml (const String& tagName, const FillType& fillType) -{ - XmlElement* const xml = new XmlElement (tagName); + ValueTree v (tagName); if (fillType.isColour()) { - xml->setAttribute (T("type"), T("solid")); - xml->setAttribute (T("colour"), String::toHexString ((int) fillType.colour.getARGB())); + v.setProperty ("type", T("solid"), 0); + v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0); } else if (fillType.isGradient()) { - xml->setAttribute (T("type"), T("gradient")); - - xml->setAttribute (T("x1"), fillType.gradient->x1); - xml->setAttribute (T("y1"), fillType.gradient->y1); - xml->setAttribute (T("x2"), fillType.gradient->x2); - xml->setAttribute (T("y2"), fillType.gradient->y2); - xml->setAttribute (T("radial"), fillType.gradient->isRadial); + v.setProperty ("type", T("gradient"), 0); + v.setProperty ("x1", fillType.gradient->x1, 0); + v.setProperty ("y1", fillType.gradient->y1, 0); + v.setProperty ("x2", fillType.gradient->x2, 0); + v.setProperty ("y2", fillType.gradient->y2, 0); + v.setProperty ("radial", fillType.gradient->isRadial, 0); String s; for (int i = 0; i < fillType.gradient->getNumColours(); ++i) s << " " << fillType.gradient->getColourPosition (i) << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB()); - xml->setAttribute (T("colours"), s.trimStart()); + v.setProperty ("colours", s.trimStart(), 0); } else { jassertfalse //xxx } - return xml; + return v; } -bool DrawablePath::readBinary (InputStream& input) +ValueTree DrawablePath::createValueTree() const throw() { - mainFill = readColourFromBinary (input); - strokeFill = readColourFromBinary (input); + ValueTree v (T("Path")); - const float strokeThickness = input.readFloat(); - const int jointStyle = input.readByte(); - const int endStyle = input.readByte(); + v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0); + v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0); - strokeType = PathStrokeType (strokeThickness, - jointStyle == 1 ? PathStrokeType::curved - : (jointStyle == 2 ? PathStrokeType::beveled - : PathStrokeType::mitered), - endStyle == 1 ? PathStrokeType::square - : (endStyle == 2 ? PathStrokeType::rounded - : PathStrokeType::butt)); + if (getName().isNotEmpty()) + v.setProperty ("id", getName(), 0); - const int pathSize = input.readInt(); - MemoryBlock pathData; - input.readIntoMemoryBlock (pathData, pathSize); + v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0); + v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered + ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0); + v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt + ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0); + v.setProperty ("path", path.toString(), 0); - if (pathData.getSize() != pathSize) - return false; - - path.clear(); - path.loadPathFromData ((const uint8*) pathData.getData(), pathSize); - updateOutline(); - return true; + return v; } -bool DrawablePath::writeBinary (OutputStream& output) const +DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw() { - writeColourToBinary (output, mainFill); - writeColourToBinary (output, strokeFill); + if (! tree.hasType ("Path")) + return 0; - output.writeFloat (strokeType.getStrokeThickness()); - output.writeByte (strokeType.getJointStyle() == PathStrokeType::mitered ? 0 - : (strokeType.getJointStyle() == PathStrokeType::curved ? 1 : 2)); - output.writeByte (strokeType.getEndStyle() == PathStrokeType::butt ? 0 - : (strokeType.getEndStyle() == PathStrokeType::square ? 1 : 2)); + DrawablePath* p = new DrawablePath(); - MemoryOutputStream out; - path.writePathToStream (out); - output.writeInt (out.getDataSize()); - output.write (out.getData(), out.getDataSize()); - return true; -} + p->setName (tree ["id"]); + p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill"))); + p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke"))); -bool DrawablePath::readXml (const XmlElement& xml) -{ - mainFill = readColourFromXml (xml.getChildByName (T("fill"))); - strokeFill = readColourFromXml (xml.getChildByName (T("stroke"))); + const String jointStyle (tree ["jointStyle"].toString()); + const String endStyle (tree ["capStyle"].toString()); - const String jointStyle (xml.getStringAttribute (T("jointStyle"), String::empty)); - const String endStyle (xml.getStringAttribute (T("capStyle"), String::empty)); - strokeType = PathStrokeType ((float) xml.getDoubleAttribute (T("strokeWidth"), 0.0), - jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved - : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled - : PathStrokeType::mitered), - endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square - : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded - : PathStrokeType::butt)); + p->strokeType + = PathStrokeType (tree ["strokeWidth"], + jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved + : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled + : PathStrokeType::mitered), + endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square + : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded + : PathStrokeType::butt)); - path.clear(); - path.restoreFromString (xml.getAllSubText()); - updateOutline(); - return true; -} + p->path.clear(); + p->path.restoreFromString (tree ["path"]); + p->updateOutline(); -void DrawablePath::writeXml (XmlElement& xml) const -{ - xml.addChildElement (writeColourToXml (T("fill"), mainFill)); - xml.addChildElement (writeColourToXml (T("stroke"), strokeFill)); - - xml.setAttribute (T("strokeWidth"), (double) strokeType.getStrokeThickness()); - xml.setAttribute (T("jointStyle"), - strokeType.getJointStyle() == PathStrokeType::mitered ? T("miter") - : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel"))); - xml.setAttribute (T("capStyle"), - strokeType.getEndStyle() == PathStrokeType::butt ? T("butt") - : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round"))); - - xml.addTextElement (path.toString()); + return p; } diff --git a/src/gui/graphics/drawables/juce_DrawablePath.h b/src/gui/graphics/drawables/juce_DrawablePath.h index b3276129d0..ba1bbacd0c 100644 --- a/src/gui/graphics/drawables/juce_DrawablePath.h +++ b/src/gui/graphics/drawables/juce_DrawablePath.h @@ -107,13 +107,9 @@ public: /** @internal */ Drawable* createCopy() const; /** @internal */ - bool readBinary (InputStream& input); + ValueTree createValueTree() const throw(); /** @internal */ - bool writeBinary (OutputStream& output) const; - /** @internal */ - bool readXml (const XmlElement& xml); - /** @internal */ - void writeXml (XmlElement& xml) const; + static DrawablePath* createFromValueTree (const ValueTree& tree) throw(); //============================================================================== juce_UseDebuggingNewOperator diff --git a/src/gui/graphics/drawables/juce_DrawableText.cpp b/src/gui/graphics/drawables/juce_DrawableText.cpp index 4071857174..beb50aba40 100644 --- a/src/gui/graphics/drawables/juce_DrawableText.cpp +++ b/src/gui/graphics/drawables/juce_DrawableText.cpp @@ -88,27 +88,29 @@ Drawable* DrawableText::createCopy() const } //============================================================================== -bool DrawableText::readBinary (InputStream& input) +ValueTree DrawableText::createValueTree() const throw() { - jassertfalse; //xxx TODO - return false; + ValueTree v (T("Text")); + + if (getName().isNotEmpty()) + v.setProperty ("id", getName(), 0); + + jassertfalse // xxx not finished! + return v; } -bool DrawableText::writeBinary (OutputStream& output) const +DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw() { - jassertfalse; //xxx TODO - return false; -} + if (! tree.hasType ("Text")) + return 0; -bool DrawableText::readXml (const XmlElement& xml) -{ - jassertfalse; //xxx TODO - return false; -} + DrawableText* dt = new DrawableText(); -void DrawableText::writeXml (XmlElement& xml) const -{ - jassertfalse; //xxx TODO + dt->setName (tree ["id"]); + + jassertfalse // xxx not finished! + + return dt; } diff --git a/src/gui/graphics/drawables/juce_DrawableText.h b/src/gui/graphics/drawables/juce_DrawableText.h index 207cdd6e34..c8e3585a10 100644 --- a/src/gui/graphics/drawables/juce_DrawableText.h +++ b/src/gui/graphics/drawables/juce_DrawableText.h @@ -78,13 +78,9 @@ public: /** @internal */ Drawable* createCopy() const; /** @internal */ - bool readBinary (InputStream& input); + ValueTree createValueTree() const throw(); /** @internal */ - bool writeBinary (OutputStream& output) const; - /** @internal */ - bool readXml (const XmlElement& xml); - /** @internal */ - void writeXml (XmlElement& xml) const; + static DrawableText* createFromValueTree (const ValueTree& tree) throw(); //============================================================================== juce_UseDebuggingNewOperator diff --git a/src/gui/graphics/drawables/juce_SVGParser.cpp b/src/gui/graphics/drawables/juce_SVGParser.cpp index 3b43bb3b56..93a543f4fd 100644 --- a/src/gui/graphics/drawables/juce_SVGParser.cpp +++ b/src/gui/graphics/drawables/juce_SVGParser.cpp @@ -39,7 +39,7 @@ public: //============================================================================== SVGState (const XmlElement* const topLevel) : topLevelXml (topLevel), - x (0), y (0), + elementX (0), elementY (0), width (512), height (512), viewBoxW (0), viewBoxH (0) { @@ -64,8 +64,8 @@ public: if (xml.hasAttribute (T("transform"))) newState.addTransform (xml); - newState.x = getCoordLength (xml.getStringAttribute (T("x"), String (newState.x)), viewBoxW); - newState.y = getCoordLength (xml.getStringAttribute (T("y"), String (newState.y)), viewBoxH); + newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW); + newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH); newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW); newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH); @@ -136,7 +136,7 @@ public: private: //============================================================================== const XmlElement* const topLevelXml; - float x, y, width, height, viewBoxW, viewBoxH; + float elementX, elementY, width, height, viewBoxW, viewBoxH; AffineTransform transform; String cssStyleText; @@ -595,9 +595,9 @@ private: //============================================================================== Drawable* parseShape (const XmlElement& xml, Path& path, - const bool parseTransform = true) const + const bool shouldParseTransform = true) const { - if (parseTransform && xml.hasAttribute (T("transform"))) + if (shouldParseTransform && xml.hasAttribute (T("transform"))) { SVGState newState (*this); newState.addTransform (xml); @@ -730,8 +730,8 @@ private: float width = viewBoxW; float height = viewBoxH; - float dx = 0.0; - float dy = 0.0; + float dx = 0.0f; + float dy = 0.0f; const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse")); diff --git a/src/gui/graphics/fonts/juce_GlyphArrangement.cpp b/src/gui/graphics/fonts/juce_GlyphArrangement.cpp index c26df75011..0d65f5d310 100644 --- a/src/gui/graphics/fonts/juce_GlyphArrangement.cpp +++ b/src/gui/graphics/fonts/juce_GlyphArrangement.cpp @@ -752,7 +752,7 @@ void GlyphArrangement::spreadOutLine (const int start, const int num, const floa for (int i = 0; i < num; ++i) { - glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0); + glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f); if (glyphs.getUnchecked (start + i)->isWhitespace()) deltaX += extraPaddingBetweenWords; diff --git a/src/gui/graphics/fonts/juce_Typeface.cpp b/src/gui/graphics/fonts/juce_Typeface.cpp index 486f9af685..280952bd83 100644 --- a/src/gui/graphics/fonts/juce_Typeface.cpp +++ b/src/gui/graphics/fonts/juce_Typeface.cpp @@ -339,7 +339,7 @@ float CustomTypeface::getStringWidth (const String& text) return x; } -void CustomTypeface::getGlyphPositions (const String& text, Array & glyphs, Array& xOffsets) +void CustomTypeface::getGlyphPositions (const String& text, Array & resultGlyphs, Array& xOffsets) { xOffsets.add (0); float x = 0; @@ -353,7 +353,7 @@ void CustomTypeface::getGlyphPositions (const String& text, Array & glyphs, if (glyph != 0) { x += glyph->getHorizontalSpacing (*t); - glyphs.add ((int) glyph->character); + resultGlyphs.add ((int) glyph->character); xOffsets.add (x); } } diff --git a/src/gui/graphics/geometry/juce_Path.cpp b/src/gui/graphics/geometry/juce_Path.cpp index 1db31080db..31a3c49054 100644 --- a/src/gui/graphics/geometry/juce_Path.cpp +++ b/src/gui/graphics/geometry/juce_Path.cpp @@ -333,6 +333,21 @@ void Path::addRectangle (const float x, const float y, ensureAllocatedSize (numElements + 13); + if (numElements == 0) + { + pathXMin = x1; + pathXMax = x2; + pathYMin = y1; + pathYMax = y2; + } + else + { + pathXMin = jmin (pathXMin, x1); + pathXMax = jmax (pathXMax, x2); + pathYMin = jmin (pathYMin, y1); + pathYMax = jmax (pathYMax, y2); + } + elements [numElements++] = moveMarker; elements [numElements++] = x1; elements [numElements++] = y2; @@ -346,11 +361,6 @@ void Path::addRectangle (const float x, const float y, elements [numElements++] = x2; elements [numElements++] = y2; elements [numElements++] = closeSubPathMarker; - - pathXMin = jmin (pathXMin, x1); - pathXMax = jmax (pathXMax, x2); - pathYMin = jmin (pathYMin, y1); - pathYMax = jmax (pathYMax, y2); } void Path::addRectangle (const Rectangle& rectangle) throw() diff --git a/src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp b/src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp index 2bdb4f2b06..01da3ac431 100644 --- a/src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp +++ b/src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp @@ -194,7 +194,7 @@ int GIFLoader::processExtension (const int type, int& transparent) return n; } -int GIFLoader::getCode (const int codeSize, const bool initialise) +int GIFLoader::getCode (const int codeSize_, const bool initialise) { if (initialise) { @@ -204,7 +204,7 @@ int GIFLoader::getCode (const int codeSize, const bool initialise) return 0; } - if ((currentBit + codeSize) >= lastBit) + if ((currentBit + codeSize_) >= lastBit) { if (finished) return -1; @@ -225,13 +225,13 @@ int GIFLoader::getCode (const int codeSize, const bool initialise) int result = 0; int i = currentBit; - for (int j = 0; j < codeSize; ++j) + for (int j = 0; j < codeSize_; ++j) { result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j; ++i; } - currentBit += codeSize; + currentBit += codeSize_; return result; } diff --git a/src/gui/graphics/imaging/juce_Image.h b/src/gui/graphics/imaging/juce_Image.h index 492a37546f..48ff1c94ed 100644 --- a/src/gui/graphics/imaging/juce_Image.h +++ b/src/gui/graphics/imaging/juce_Image.h @@ -241,6 +241,10 @@ public: uint8* data; int lineStride, pixelStride, width, height; + + private: + BitmapData (const BitmapData&); + const BitmapData& operator= (const BitmapData&); }; /** Copies some pixel values to a rectangle of the image. diff --git a/src/io/files/juce_File.cpp b/src/io/files/juce_File.cpp index 4dc428a995..478670a430 100644 --- a/src/io/files/juce_File.cpp +++ b/src/io/files/juce_File.cpp @@ -663,26 +663,24 @@ int File::findChildFiles (OwnedArray& results, const String path (juce_addTrailingSeparator (fullPath)); String filename; - bool isDirectory, isHidden; + bool itemIsDirectory, itemIsHidden; - void* const handle = juce_findFileStart (path, - wildCardPattern, - filename, - &isDirectory, &isHidden, + void* const handle = juce_findFileStart (path, wildCardPattern, filename, + &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0); if (handle != 0) { do { - if (fileTypeMatches (whatToLookFor, isDirectory, isHidden) + if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden) && ! filename.containsOnly (T("."))) { results.add (new File (path + filename, 0)); ++total; } - } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0)); + } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0)); juce_findFileClose (handle); } @@ -723,25 +721,23 @@ int File::getNumberOfChildFiles (const int whatToLookFor, if (isDirectory()) { String filename; - bool isDirectory, isHidden; + bool itemIsDirectory, itemIsHidden; - void* const handle = juce_findFileStart (fullPath, - wildCardPattern, - filename, - &isDirectory, &isHidden, + void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename, + &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0); if (handle != 0) { do { - if (fileTypeMatches (whatToLookFor, isDirectory, isHidden) + if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden) && ! filename.containsOnly (T("."))) { ++count; } - } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0)); + } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0)); juce_findFileClose (handle); } @@ -762,22 +758,22 @@ bool File::containsSubDirectories() const throw() if (isDirectory()) { String filename; - bool isDirectory, isHidden; + bool itemIsDirectory, itemIsHidden; void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath), T("*"), filename, - &isDirectory, &isHidden, 0, 0, 0, 0); + &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0); if (handle != 0) { do { - if (isDirectory) + if (itemIsDirectory) { result = true; break; } - } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0)); + } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0)); juce_findFileClose (handle); } diff --git a/src/io/files/juce_FileInputStream.h b/src/io/files/juce_FileInputStream.h index 334d1a44ed..e1e28ff1e7 100644 --- a/src/io/files/juce_FileInputStream.h +++ b/src/io/files/juce_FileInputStream.h @@ -69,6 +69,9 @@ private: void* fileHandle; int64 currentPosition, totalSize; bool needToSeek; + + FileInputStream (const FileInputStream&); + const FileInputStream& operator= (const FileInputStream&); }; #endif // __JUCE_FILEINPUTSTREAM_JUCEHEADER__ diff --git a/src/io/streams/juce_InputStream.cpp b/src/io/streams/juce_InputStream.cpp index af8d84f79c..2012937f28 100644 --- a/src/io/streams/juce_InputStream.cpp +++ b/src/io/streams/juce_InputStream.cpp @@ -99,6 +99,8 @@ int InputStream::readCompressedInt() if (read (&num, numBytes) != numBytes) return 0; + num = (int) swapIfBigEndian ((uint32) num); + if (negative) num = -num; } @@ -112,7 +114,7 @@ int64 InputStream::readInt64() char temp [8]; if (read (temp, 8) == 8) - return (int64) swapIfBigEndian (*(uint64*)temp); + return (int64) swapIfBigEndian (*(uint64*) temp); else return 0; } @@ -122,7 +124,7 @@ int64 InputStream::readInt64BigEndian() char temp [8]; if (read (temp, 8) == 8) - return (int64) swapIfLittleEndian (*(uint64*)temp); + return (int64) swapIfLittleEndian (*(uint64*) temp); else return 0; } @@ -157,76 +159,51 @@ double InputStream::readDoubleBigEndian() const String InputStream::readString() { - const int tempBufferSize = 256; - uint8 temp [tempBufferSize]; + MemoryBlock buffer (256); + uint8* data = (uint8*) buffer.getData(); int i = 0; - while ((temp [i++] = readByte()) != 0) + while ((data[i] = readByte()) != 0) { - if (i == tempBufferSize) + if (++i >= buffer.getSize()) { - // too big for our quick buffer, so read it in blocks.. - String result (String::fromUTF8 (temp, i)); - i = 0; - - for (;;) - { - if ((temp [i++] = readByte()) == 0) - { - result += String::fromUTF8 (temp, i - 1); - break; - } - else if (i == tempBufferSize) - { - result += String::fromUTF8 (temp, i); - i = 0; - } - } - - return result; + buffer.setSize (buffer.getSize() + 512); + data = (uint8*) buffer.getData(); } } - return String::fromUTF8 (temp, i - 1); + return String::fromUTF8 (data, i); } const String InputStream::readNextLine() { - String s; - const int maxChars = 256; - tchar buffer [maxChars]; - int charsInBuffer = 0; + MemoryBlock buffer (256); + uint8* data = (uint8*) buffer.getData(); + int i = 0; - while (! isExhausted()) + while ((data[i] = readByte()) != 0) { - const uint8 c = readByte(); - const int64 lastPos = getPosition(); - - if (c == '\n') - { + if (data[i] == '\n') break; - } - else if (c == '\r') + + if (data[i] == '\r') { + const int64 lastPos = getPosition(); + if (readByte() != '\n') setPosition (lastPos); break; } - buffer [charsInBuffer++] = c; - - if (charsInBuffer == maxChars) + if (++i >= buffer.getSize()) { - s.append (buffer, maxChars); - charsInBuffer = 0; + buffer.setSize (buffer.getSize() + 512); + data = (uint8*) buffer.getData(); } } - if (charsInBuffer > 0) - s.append (buffer, charsInBuffer); - - return s; + return String::fromUTF8 (data, i); } int InputStream::readIntoMemoryBlock (MemoryBlock& block, diff --git a/src/io/streams/juce_InputStream.h b/src/io/streams/juce_InputStream.h index 5796619e4c..d0fc4da1d3 100644 --- a/src/io/streams/juce_InputStream.h +++ b/src/io/streams/juce_InputStream.h @@ -211,18 +211,17 @@ public: virtual int readCompressedInt(); //============================================================================== - /** Reads a string from the stream, up to the next linefeed or carriage return. + /** Reads a UTF8 string from the stream, up to the next linefeed or carriage return. - The stream is treated as 8-bit characters encoded with the system's default encoding, - and this will read up to the next "\n" or "\r\n" or end-of-stream. + This will read up to the next "\n" or "\r\n" or end-of-stream. - After this call, the stream's position will be left pointing to the character + After this call, the stream's position will be left pointing to the next character following the line-feed, but the linefeeds aren't included in the string that is returned. */ virtual const String readNextLine(); - /** Reads a zero-terminated string from the stream. + /** Reads a zero-terminated UTF8 string from the stream. This will read characters from the stream until it hits a zero character or end-of-stream. diff --git a/src/io/streams/juce_OutputStream.cpp b/src/io/streams/juce_OutputStream.cpp index f638f31b60..22c522ba76 100644 --- a/src/io/streams/juce_OutputStream.cpp +++ b/src/io/streams/juce_OutputStream.cpp @@ -124,6 +124,7 @@ void OutputStream::writeCompressedInt (int value) numSigBytes |= 0x80; writeByte ((char) numSigBytes); + un = swapIfBigEndian (un); write (&un, numSigBytes); } diff --git a/src/io/streams/juce_OutputStream.h b/src/io/streams/juce_OutputStream.h index bbbfb06468..5b170032cd 100644 --- a/src/io/streams/juce_OutputStream.h +++ b/src/io/streams/juce_OutputStream.h @@ -186,6 +186,8 @@ public: text-file! It's intended for storing a string for later retrieval by InputStream::readString. + It writes the string to the stream as UTF8, with a null character terminating it. + For appending text to a file, instead use writeText, printf, or operator<< @see InputStream::readString, writeText, printf, operator<< diff --git a/src/native/mac/juce_mac_CoreAudio.cpp b/src/native/mac/juce_mac_CoreAudio.cpp index 17a7342b32..8c05590627 100644 --- a/src/native/mac/juce_mac_CoreAudio.cpp +++ b/src/native/mac/juce_mac_CoreAudio.cpp @@ -676,7 +676,7 @@ public: // Sometimes the two linked devices seem to get their callbacks in // parallel, so we need to lock both devices to stop the input data being // changed while inside our callback.. - const ScopedLock sl (inputDevice->callbackLock); + const ScopedLock sl2 (inputDevice->callbackLock); callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers, inputDevice->numInputChans, diff --git a/src/native/mac/juce_mac_CoreGraphicsContext.mm b/src/native/mac/juce_mac_CoreGraphicsContext.mm index 45a6f90615..aa75d91870 100644 --- a/src/native/mac/juce_mac_CoreGraphicsContext.mm +++ b/src/native/mac/juce_mac_CoreGraphicsContext.mm @@ -32,11 +32,11 @@ class CoreGraphicsImage : public Image { public: //============================================================================== - CoreGraphicsImage (const PixelFormat format, - const int imageWidth, - const int imageHeight, + CoreGraphicsImage (const PixelFormat format_, + const int imageWidth_, + const int imageHeight_, const bool clearImage) - : Image (format, imageWidth, imageHeight, clearImage) + : Image (format_, imageWidth_, imageHeight_, clearImage) { CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB(); @@ -451,20 +451,20 @@ public: state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(), state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha()); - CGPoint line[] = { { x1 + 0.5f, flipHeight - (y1 + 0.5f) }, - { x2 + 0.5f, flipHeight - (y2 + 0.5f) } }; + CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) }, + { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } }; CGContextStrokeLineSegments (context, line, 1); } void drawVerticalLine (const int x, double top, double bottom) { - CGContextFillRect (context, CGRectMake (x, flipHeight - bottom, 1.0f, bottom - top)); + CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top))); } void drawHorizontalLine (const int y, double left, double right) { - CGContextFillRect (context, CGRectMake (left, flipHeight - (y + 1.0f), right - left, 1.0f)); + CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f)); } void setFont (const Font& newFont) diff --git a/src/native/mac/juce_mac_Fonts.mm b/src/native/mac/juce_mac_Fonts.mm index 16a3899056..8ea68db726 100644 --- a/src/native/mac/juce_mac_Fonts.mm +++ b/src/native/mac/juce_mac_Fonts.mm @@ -128,7 +128,7 @@ public: if (needsItalicTransform) { - pathTransform = pathTransform.sheared (-0.15, 0); + pathTransform = pathTransform.sheared (-0.15f, 0.0f); renderingTransform.c = 0.15f; } diff --git a/src/native/mac/juce_mac_MessageManager.mm b/src/native/mac/juce_mac_MessageManager.mm index de090ec3d5..9792a61e37 100644 --- a/src/native/mac/juce_mac_MessageManager.mm +++ b/src/native/mac/juce_mac_MessageManager.mm @@ -414,7 +414,7 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor) while (! quitMessagePosted) { - const ScopedAutoReleasePool pool; + const ScopedAutoReleasePool pool2; CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true); diff --git a/src/native/mac/juce_mac_NSViewComponentPeer.mm b/src/native/mac/juce_mac_NSViewComponentPeer.mm index 126fff45f1..976d0f9bde 100644 --- a/src/native/mac/juce_mac_NSViewComponentPeer.mm +++ b/src/native/mac/juce_mac_NSViewComponentPeer.mm @@ -658,10 +658,10 @@ static int getModifierForButtonNumber (const int num) throw() } //============================================================================== -NSViewComponentPeer::NSViewComponentPeer (Component* const component, +NSViewComponentPeer::NSViewComponentPeer (Component* const component_, const int windowStyleFlags, NSView* viewToAttachTo) - : ComponentPeer (component, windowStyleFlags), + : ComponentPeer (component_, windowStyleFlags), window (0), view (0), isSharedWindow (viewToAttachTo != 0), diff --git a/src/native/mac/juce_mac_QuickTimeMovieComponent.mm b/src/native/mac/juce_mac_QuickTimeMovieComponent.mm index 9c45774881..3b4a963d81 100644 --- a/src/native/mac/juce_mac_QuickTimeMovieComponent.mm +++ b/src/native/mac/juce_mac_QuickTimeMovieComponent.mm @@ -90,13 +90,13 @@ static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile) } bool QuickTimeMovieComponent::loadMovie (const File& movieFile_, - const bool isControllerVisible) + const bool isControllerVisible_) { - return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible); + return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_); } bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream, - const bool controllerVisible) + const bool controllerVisible_) { closeMovie(); @@ -113,14 +113,14 @@ bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream, [theMovie retain]; QTMovieView* view = (QTMovieView*) getView(); [view setMovie: theMovie]; - [view setControllerVisible: controllerVisible]; + [view setControllerVisible: controllerVisible_]; setLooping (looping); return movie != nil; } bool QuickTimeMovieComponent::loadMovie (const URL& movieURL, - const bool isControllerVisible) + const bool isControllerVisible_) { // unfortunately, QTMovie objects can only be created on the main thread.. jassert (MessageManager::getInstance()->isThisTheMessageThread()); diff --git a/src/native/mac/juce_mac_SystemStats.mm b/src/native/mac/juce_mac_SystemStats.mm index b7264fff39..4eed48a1e5 100644 --- a/src/native/mac/juce_mac_SystemStats.mm +++ b/src/native/mac/juce_mac_SystemStats.mm @@ -145,7 +145,7 @@ int SystemStats::getMemorySizeInMegabytes() throw() size_t memSize = sizeof (mem); int mib[] = { CTL_HW, HW_MEMSIZE }; sysctl (mib, 2, &mem, &memSize, 0, 0); - return mem / (1024 * 1024); + return (int) (mem / (1024 * 1024)); } bool SystemStats::hasMMX() throw() @@ -206,7 +206,7 @@ int SystemStats::getCpuSpeedInMegaherz() throw() if (speedSize == 4) speedHz >>= 32; #endif - return speedHz / 1000000; + return (int) (speedHz / 1000000); } int SystemStats::getNumCpus() throw() diff --git a/src/text/juce_String.cpp b/src/text/juce_String.cpp index ffc65fb7a1..a41b8cf453 100644 --- a/src/text/juce_String.cpp +++ b/src/text/juce_String.cpp @@ -2254,13 +2254,13 @@ const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) t while (--numExtraValues >= 0 && i < bufferSizeBytes) { - const uint8 c = buffer[i]; + const uint8 nextByte = buffer[i]; - if ((c & 0xc0) != 0x80) + if ((nextByte & 0xc0) != 0x80) break; n <<= 6; - n |= (c & 0x3f); + n |= (nextByte & 0x3f); ++i; } diff --git a/src/text/juce_StringArray.cpp b/src/text/juce_StringArray.cpp index 1935bf2124..b6d4810066 100644 --- a/src/text/juce_StringArray.cpp +++ b/src/text/juce_StringArray.cpp @@ -41,34 +41,34 @@ StringArray::StringArray (const StringArray& other) throw() addArray (other); } -StringArray::StringArray (const juce_wchar** const strings, +StringArray::StringArray (const juce_wchar** const initialStrings, const int numberOfStrings) throw() { for (int i = 0; i < numberOfStrings; ++i) - add (strings [i]); + add (initialStrings [i]); } -StringArray::StringArray (const char** const strings, +StringArray::StringArray (const char** const initialStrings, const int numberOfStrings) throw() { for (int i = 0; i < numberOfStrings; ++i) - add (strings [i]); + add (initialStrings [i]); } -StringArray::StringArray (const juce_wchar** const strings) throw() +StringArray::StringArray (const juce_wchar** const initialStrings) throw() { int i = 0; - while (strings[i] != 0) - add (strings [i++]); + while (initialStrings[i] != 0) + add (initialStrings [i++]); } -StringArray::StringArray (const char** const strings) throw() +StringArray::StringArray (const char** const initialStrings) throw() { int i = 0; - while (strings[i] != 0) - add (strings [i++]); + while (initialStrings[i] != 0) + add (initialStrings [i++]); } const StringArray& StringArray::operator= (const StringArray& other) throw() diff --git a/src/text/juce_XmlDocument.cpp b/src/text/juce_XmlDocument.cpp index e8877fa475..7f2d1e080e 100644 --- a/src/text/juce_XmlDocument.cpp +++ b/src/text/juce_XmlDocument.cpp @@ -294,12 +294,12 @@ void XmlDocument::readQuotedString (String& result) throw() while (! outOfData) { - const tchar character = readNextChar(); + const tchar c = readNextChar(); - if (character == quote) + if (c == quote) break; - if (character == T('&')) + if (c == T('&')) { --input; readEntity (result); @@ -412,9 +412,9 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw { skipNextWhiteSpace(); - const tchar c = *input; + const tchar nextChar = *input; - if (c == T('"') || c == T('\'')) + if (nextChar == T('"') || nextChar == T('\'')) { XmlElement::XmlAttributeNode* const newAtt = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen), @@ -605,13 +605,13 @@ void XmlDocument::readChildElements (XmlElement* parent) throw() for (;;) { - const tchar c = *input; + const tchar nextChar = *input; - if (c == T('<') || c == T('&')) + if (nextChar == T('<') || nextChar == T('&')) { break; } - else if (c == 0) + else if (nextChar == 0) { setLastError ("unmatched tags", false); outOfData = true; diff --git a/src/text/juce_XmlElement.cpp b/src/text/juce_XmlElement.cpp index 09d4972a07..7456d737d6 100644 --- a/src/text/juce_XmlElement.cpp +++ b/src/text/juce_XmlElement.cpp @@ -379,58 +379,62 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, } } -const String XmlElement::createDocument (const String& dtd, +const String XmlElement::createDocument (const String& dtdToUse, const bool allOnOneLine, const bool includeXmlHeader, - const tchar* const encoding, + const tchar* const encodingType, const int lineWrapLength) const throw() { - String doc; - doc.preallocateStorage (1024); - - if (includeXmlHeader) - { - doc << " "; - else - doc += "\"?>\n\n"; - } - - if (dtd.isNotEmpty()) - { - if (allOnOneLine) - doc << dtd << " "; - else - doc << dtd << "\r\n"; - } - MemoryOutputStream mem (2048, 4096); - writeElementAsText (mem, allOnOneLine ? -1 : 0, lineWrapLength); + writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength); - return doc + String (mem.getData(), - mem.getDataSize()); + return String (mem.getData(), mem.getDataSize()); } -bool XmlElement::writeToFile (const File& f, - const String& dtd, - const tchar* const encoding, +void XmlElement::writeToStream (OutputStream& output, + const String& dtdToUse, + const bool allOnOneLine, + const bool includeXmlHeader, + const tchar* const encodingType, + const int lineWrapLength) const throw() +{ + if (includeXmlHeader) + { + output << " "; + else + output << "\"?>\r\n\r\n"; + } + + if (dtdToUse.isNotEmpty()) + { + output << dtdToUse; + + if (allOnOneLine) + output << " "; + else + output << "\r\n"; + } + + writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength); +} + +bool XmlElement::writeToFile (const File& file, + const String& dtdToUse, + const tchar* const encodingType, const int lineWrapLength) const throw() { - if (f.hasWriteAccess()) + if (file.hasWriteAccess()) { - const File tempFile (f.getNonexistentSibling()); + const File tempFile (file.getNonexistentSibling()); FileOutputStream* const out = tempFile.createOutputStream(); if (out != 0) { - *out << "\r\n\r\n" - << dtd << "\r\n"; - - writeElementAsText (*out, 0, lineWrapLength); + writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength); delete out; if (! tempFile.exists()) @@ -439,7 +443,7 @@ bool XmlElement::writeToFile (const File& f, int i; for (i = 5; --i >= 0;) { - if (tempFile.moveFileTo (f)) + if (tempFile.moveFileTo (file)) return true; Thread::sleep (100); diff --git a/src/text/juce_XmlElement.h b/src/text/juce_XmlElement.h index 11b302aa95..f113f0b38e 100644 --- a/src/text/juce_XmlElement.h +++ b/src/text/juce_XmlElement.h @@ -187,7 +187,7 @@ public: @param lineWrapLength the line length that will be used before items get placed on a new line. This isn't an absolute maximum length, it just determines how lists of attributes get broken up - @see writeToFile + @see writeToStream, writeToFile */ const String createDocument (const String& dtdToUse, const bool allOnOneLine = false, @@ -195,6 +195,27 @@ public: const tchar* const encodingType = JUCE_T("UTF-8"), const int lineWrapLength = 60) const throw(); + /** Writes the document to a stream as UTF-8. + + @param dtdToUse the DTD to add to the document + @param allOnOneLine if true, this means that the document will not contain any + linefeeds, so it'll be smaller but not very easy to read. + @param includeXmlHeader whether to add the "= 0 && ! startedOne) { - for (int i = numThreads; --i >= 0;) + for (i = numThreads; --i >= 0;) { if (! threads[i]->isThreadRunning()) { diff --git a/src/threads/juce_TimeSliceThread.cpp b/src/threads/juce_TimeSliceThread.cpp index 4a310a5815..6668115340 100644 --- a/src/threads/juce_TimeSliceThread.cpp +++ b/src/threads/juce_TimeSliceThread.cpp @@ -66,8 +66,8 @@ void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client) { const ScopedUnlock ul (listLock); // unlock first to get the order right.. - const ScopedLock sl1 (callbackLock); - const ScopedLock sl2 (listLock); + const ScopedLock sl2 (callbackLock); + const ScopedLock sl3 (listLock); clients.removeValue (client); } @@ -82,10 +82,10 @@ int TimeSliceThread::getNumClients() const throw() return clients.size(); } -TimeSliceClient* TimeSliceThread::getClient (const int index) const throw() +TimeSliceClient* TimeSliceThread::getClient (const int i) const throw() { const ScopedLock sl (listLock); - return clients [index]; + return clients [i]; } //============================================================================== @@ -101,7 +101,7 @@ void TimeSliceThread::run() const ScopedLock sl (callbackLock); { - const ScopedLock sl (listLock); + const ScopedLock sl2 (listLock); if (clients.size() > 0) { diff --git a/src/utilities/juce_RecentlyOpenedFilesList.cpp b/src/utilities/juce_RecentlyOpenedFilesList.cpp index 577cc8181a..af18717692 100644 --- a/src/utilities/juce_RecentlyOpenedFilesList.cpp +++ b/src/utilities/juce_RecentlyOpenedFilesList.cpp @@ -100,17 +100,17 @@ int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo, if (filesToAvoid != 0) { - const File** files = filesToAvoid; + const File** avoid = filesToAvoid; - while (*files != 0) + while (*avoid != 0) { - if (f == **files) + if (f == **avoid) { needsAvoiding = true; break; } - ++files; + ++avoid; } }