diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index ebeecfec2e..2eed3301fd 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -16629,6 +16629,12 @@ ValueTree ValueTree::readFromStream (InputStream& input) return v; } +ValueTree ValueTree::readFromData (const void* const data, const size_t numBytes) +{ + MemoryInputStream in (data, numBytes, false); + return readFromStream (in); +} + END_JUCE_NAMESPACE /*** End of inlined file: juce_ValueTree.cpp ***/ @@ -30392,6 +30398,27 @@ void AudioUnitPluginInstance::initialise() void AudioUnitPluginInstance::prepareToPlay (double sampleRate_, int samplesPerBlockExpected) { + if (audioUnit != 0) + { + Float64 sampleRateIn = 0, sampleRateOut = 0; + UInt32 sampleRateSize = sizeof (sampleRateIn); + AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Input, 0, &sampleRateIn, &sampleRateSize); + AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Output, 0, &sampleRateOut, &sampleRateSize); + + if (sampleRateIn != sampleRate_ || sampleRateOut != sampleRate_) + { + if (initialised) + { + AudioUnitUninitialize (audioUnit); + initialised = false; + } + + Float64 sr = sampleRate_; + AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Input, 0, &sr, sizeof (Float64)); + AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Output, 0, &sr, sizeof (Float64)); + } + } + initialise(); if (initialised) @@ -30423,16 +30450,12 @@ void AudioUnitPluginInstance::prepareToPlay (double sampleRate_, stream.mBitsPerChannel = 32; stream.mChannelsPerFrame = numIns; - OSStatus err = AudioUnitSetProperty (audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, + OSStatus err = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &stream, sizeof (stream)); stream.mChannelsPerFrame = numOuts; - err = AudioUnitSetProperty (audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Output, + err = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &stream, sizeof (stream)); outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1); @@ -86184,6 +86207,53 @@ void Font::findFonts (Array& destArray) throw() destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain)); } +const String Font::toString() const +{ + String s (getTypefaceName()); + + if (s == getDefaultSansSerifFontName()) + s = String::empty; + else + s += "; "; + + s += String (getHeight(), 1); + + if (isBold()) + s += " bold"; + + if (isItalic()) + s += " italic"; + + return s; +} + +const Font Font::fromString (const String& fontDescription) +{ + String name; + + const int separator = fontDescription.indexOfChar (';'); + + if (separator > 0) + name = fontDescription.substring (0, separator).trim(); + + if (name.isEmpty()) + name = getDefaultSansSerifFontName(); + + String sizeAndStyle (fontDescription.substring (separator + 1)); + + float height = sizeAndStyle.getFloatValue(); + if (height <= 0) + height = 10.0f; + + int flags = Font::plain; + if (sizeAndStyle.containsIgnoreCase ("bold")) + flags |= Font::bold; + if (sizeAndStyle.containsIgnoreCase ("italic")) + flags |= Font::italic; + + return Font (name, height, flags); +} + class TypefaceCache : public DeletedAtShutdown { public: diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 764c98ad63..28d40dee54 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -13086,10 +13086,12 @@ public: */ void writeToStream (OutputStream& output); - /** Reloads a tree from a stream that was written with writeToStream(). - */ + /** Reloads a tree from a stream that was written with writeToStream(). */ static ValueTree readFromStream (InputStream& input); + /** Reloads a tree from a data block that was written with writeToStream(). */ + static ValueTree readFromData (const void* data, size_t numBytes); + /** Listener class for events that happen to a ValueTree. To get events from a ValueTree, make your class implement this interface, and use @@ -21782,6 +21784,18 @@ public: */ static void setFallbackFontName (const String& name) throw(); + /** Creates a string to describe this font. + The string will contain information to describe the font's typeface, size, and + style. To recreate the font from this string, use fromString(). + */ + const String toString() const; + + /** Recreates a font from its stringified encoding. + This method takes a string that was created by toString(), and recreates the + original font. + */ + static const Font fromString (const String& fontDescription); + juce_UseDebuggingNewOperator private: @@ -35113,8 +35127,8 @@ public: @param componentName the name to give the component @param labelText the text to show in the label */ - Label (const String& componentName, - const String& labelText); + Label (const String& componentName = String::empty, + const String& labelText = String::empty); /** Destructor. */ ~Label(); @@ -35430,7 +35444,7 @@ public: @param componentName the name to set for the component (see Component::setName()) */ - explicit ComboBox (const String& componentName); + explicit ComboBox (const String& componentName = String::empty); /** Destructor. */ ~ComboBox(); @@ -39198,7 +39212,7 @@ public: @see Button */ - TextButton (const String& buttonName, + TextButton (const String& buttonName = String::empty, const String& toolTip = String::empty); /** Destructor. */ @@ -42267,7 +42281,7 @@ public: initially set to this string, but these can be changed later using the setName() and setButtonText() methods) */ - ToggleButton (const String& buttonText); + explicit ToggleButton (const String& buttonText = String::empty); /** Destructor. */ ~ToggleButton(); @@ -44162,7 +44176,7 @@ public: When created, you'll need to set up the slider's style and range with setSliderStyle(), setRange(), etc. */ - explicit Slider (const String& componentName); + explicit Slider (const String& componentName = String::empty); /** Destructor. */ ~Slider(); @@ -50002,8 +50016,8 @@ public: @param componentName the name to give the component @param labelText the text to show at the top of the outline */ - GroupComponent (const String& componentName, - const String& labelText); + GroupComponent (const String& componentName = String::empty, + const String& labelText = String::empty); /** Destructor. */ ~GroupComponent(); diff --git a/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm b/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm index f7a6120777..a261293379 100644 --- a/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm +++ b/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm @@ -552,6 +552,27 @@ void AudioUnitPluginInstance::initialise() void AudioUnitPluginInstance::prepareToPlay (double sampleRate_, int samplesPerBlockExpected) { + if (audioUnit != 0) + { + Float64 sampleRateIn = 0, sampleRateOut = 0; + UInt32 sampleRateSize = sizeof (sampleRateIn); + AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Input, 0, &sampleRateIn, &sampleRateSize); + AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Output, 0, &sampleRateOut, &sampleRateSize); + + if (sampleRateIn != sampleRate_ || sampleRateOut != sampleRate_) + { + if (initialised) + { + AudioUnitUninitialize (audioUnit); + initialised = false; + } + + Float64 sr = sampleRate_; + AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Input, 0, &sr, sizeof (Float64)); + AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Output, 0, &sr, sizeof (Float64)); + } + } + initialise(); if (initialised) @@ -583,16 +604,12 @@ void AudioUnitPluginInstance::prepareToPlay (double sampleRate_, stream.mBitsPerChannel = 32; stream.mChannelsPerFrame = numIns; - OSStatus err = AudioUnitSetProperty (audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, + OSStatus err = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &stream, sizeof (stream)); stream.mChannelsPerFrame = numOuts; - err = AudioUnitSetProperty (audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Output, + err = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &stream, sizeof (stream)); outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1); diff --git a/src/containers/juce_ValueTree.cpp b/src/containers/juce_ValueTree.cpp index f98b5333ff..a96c27717c 100644 --- a/src/containers/juce_ValueTree.cpp +++ b/src/containers/juce_ValueTree.cpp @@ -28,6 +28,7 @@ BEGIN_JUCE_NAMESPACE #include "juce_ValueTree.h" +#include "../io/streams/juce_MemoryInputStream.h" //============================================================================== @@ -860,4 +861,10 @@ ValueTree ValueTree::readFromStream (InputStream& input) return v; } +ValueTree ValueTree::readFromData (const void* const data, const size_t numBytes) +{ + MemoryInputStream in (data, numBytes, false); + return readFromStream (in); +} + END_JUCE_NAMESPACE diff --git a/src/containers/juce_ValueTree.h b/src/containers/juce_ValueTree.h index 18cc502640..9bf0a688f9 100644 --- a/src/containers/juce_ValueTree.h +++ b/src/containers/juce_ValueTree.h @@ -310,10 +310,12 @@ public: */ void writeToStream (OutputStream& output); - /** Reloads a tree from a stream that was written with writeToStream(). - */ + /** Reloads a tree from a stream that was written with writeToStream(). */ static ValueTree readFromStream (InputStream& input); + /** Reloads a tree from a data block that was written with writeToStream(). */ + static ValueTree readFromData (const void* data, size_t numBytes); + //============================================================================== /** Listener class for events that happen to a ValueTree. diff --git a/src/gui/components/buttons/juce_TextButton.h b/src/gui/components/buttons/juce_TextButton.h index 00a92934b2..7c133fff56 100644 --- a/src/gui/components/buttons/juce_TextButton.h +++ b/src/gui/components/buttons/juce_TextButton.h @@ -49,7 +49,7 @@ public: @see Button */ - TextButton (const String& buttonName, + TextButton (const String& buttonName = String::empty, const String& toolTip = String::empty); /** Destructor. */ diff --git a/src/gui/components/buttons/juce_ToggleButton.h b/src/gui/components/buttons/juce_ToggleButton.h index 8fd93862b9..399d6c71af 100644 --- a/src/gui/components/buttons/juce_ToggleButton.h +++ b/src/gui/components/buttons/juce_ToggleButton.h @@ -48,7 +48,7 @@ public: initially set to this string, but these can be changed later using the setName() and setButtonText() methods) */ - ToggleButton (const String& buttonText); + explicit ToggleButton (const String& buttonText = String::empty); /** Destructor. */ ~ToggleButton(); diff --git a/src/gui/components/controls/juce_ComboBox.h b/src/gui/components/controls/juce_ComboBox.h index 2ddecabfe5..4841f252b4 100644 --- a/src/gui/components/controls/juce_ComboBox.h +++ b/src/gui/components/controls/juce_ComboBox.h @@ -84,7 +84,7 @@ public: @param componentName the name to set for the component (see Component::setName()) */ - explicit ComboBox (const String& componentName); + explicit ComboBox (const String& componentName = String::empty); /** Destructor. */ ~ComboBox(); diff --git a/src/gui/components/controls/juce_Label.h b/src/gui/components/controls/juce_Label.h index 497de6dd82..d3ca9b1606 100644 --- a/src/gui/components/controls/juce_Label.h +++ b/src/gui/components/controls/juce_Label.h @@ -71,8 +71,8 @@ public: @param componentName the name to give the component @param labelText the text to show in the label */ - Label (const String& componentName, - const String& labelText); + Label (const String& componentName = String::empty, + const String& labelText = String::empty); /** Destructor. */ ~Label(); diff --git a/src/gui/components/controls/juce_Slider.h b/src/gui/components/controls/juce_Slider.h index 0f37757d48..13847982e8 100644 --- a/src/gui/components/controls/juce_Slider.h +++ b/src/gui/components/controls/juce_Slider.h @@ -68,7 +68,7 @@ public: When created, you'll need to set up the slider's style and range with setSliderStyle(), setRange(), etc. */ - explicit Slider (const String& componentName); + explicit Slider (const String& componentName = String::empty); /** Destructor. */ ~Slider(); diff --git a/src/gui/components/layout/juce_GroupComponent.h b/src/gui/components/layout/juce_GroupComponent.h index 0e414efa66..f1aceccfc6 100644 --- a/src/gui/components/layout/juce_GroupComponent.h +++ b/src/gui/components/layout/juce_GroupComponent.h @@ -44,8 +44,8 @@ public: @param componentName the name to give the component @param labelText the text to show at the top of the outline */ - GroupComponent (const String& componentName, - const String& labelText); + GroupComponent (const String& componentName = String::empty, + const String& labelText = String::empty); /** Destructor. */ ~GroupComponent(); diff --git a/src/gui/graphics/fonts/juce_Font.cpp b/src/gui/graphics/fonts/juce_Font.cpp index 606f98eccd..d6db35c1ed 100644 --- a/src/gui/graphics/fonts/juce_Font.cpp +++ b/src/gui/graphics/fonts/juce_Font.cpp @@ -338,6 +338,53 @@ void Font::findFonts (Array& destArray) throw() destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain)); } +//============================================================================== +const String Font::toString() const +{ + String s (getTypefaceName()); + + if (s == getDefaultSansSerifFontName()) + s = String::empty; + else + s += "; "; + + s += String (getHeight(), 1); + + if (isBold()) + s += " bold"; + + if (isItalic()) + s += " italic"; + + return s; +} + +const Font Font::fromString (const String& fontDescription) +{ + String name; + + const int separator = fontDescription.indexOfChar (';'); + + if (separator > 0) + name = fontDescription.substring (0, separator).trim(); + + if (name.isEmpty()) + name = getDefaultSansSerifFontName(); + + String sizeAndStyle (fontDescription.substring (separator + 1)); + + float height = sizeAndStyle.getFloatValue(); + if (height <= 0) + height = 10.0f; + + int flags = Font::plain; + if (sizeAndStyle.containsIgnoreCase ("bold")) + flags |= Font::bold; + if (sizeAndStyle.containsIgnoreCase ("italic")) + flags |= Font::italic; + + return Font (name, height, flags); +} //============================================================================== class TypefaceCache : public DeletedAtShutdown diff --git a/src/gui/graphics/fonts/juce_Font.h b/src/gui/graphics/fonts/juce_Font.h index 75a4be35fb..bafe7787e4 100644 --- a/src/gui/graphics/fonts/juce_Font.h +++ b/src/gui/graphics/fonts/juce_Font.h @@ -344,6 +344,18 @@ public: */ static void setFallbackFontName (const String& name) throw(); + //============================================================================== + /** Creates a string to describe this font. + The string will contain information to describe the font's typeface, size, and + style. To recreate the font from this string, use fromString(). + */ + const String toString() const; + + /** Recreates a font from its stringified encoding. + This method takes a string that was created by toString(), and recreates the + original font. + */ + static const Font fromString (const String& fontDescription); //============================================================================== juce_UseDebuggingNewOperator