1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-11 23:54:18 +00:00

Added a way to store a Font descriptor as a string. Tweaked sample-rate initialisation in the AU hosting wrapper. Gave default constructors to a few components.

This commit is contained in:
Julian Storer 2010-05-12 11:53:28 +01:00
parent 5a9e18d3a5
commit 22e02cf791
13 changed files with 201 additions and 32 deletions

View file

@ -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<Font>& 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:

View file

@ -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();

View file

@ -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);

View file

@ -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

View file

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

View file

@ -49,7 +49,7 @@ public:
@see Button
*/
TextButton (const String& buttonName,
TextButton (const String& buttonName = String::empty,
const String& toolTip = String::empty);
/** Destructor. */

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -338,6 +338,53 @@ void Font::findFonts (Array<Font>& 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

View file

@ -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