Browse Source

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.

tags/2021-05-28
Julian Storer 15 years ago
parent
commit
22e02cf791
13 changed files with 201 additions and 32 deletions
  1. +76
    -6
      juce_amalgamated.cpp
  2. +24
    -10
      juce_amalgamated.h
  3. +23
    -6
      src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm
  4. +7
    -0
      src/containers/juce_ValueTree.cpp
  5. +4
    -2
      src/containers/juce_ValueTree.h
  6. +1
    -1
      src/gui/components/buttons/juce_TextButton.h
  7. +1
    -1
      src/gui/components/buttons/juce_ToggleButton.h
  8. +1
    -1
      src/gui/components/controls/juce_ComboBox.h
  9. +2
    -2
      src/gui/components/controls/juce_Label.h
  10. +1
    -1
      src/gui/components/controls/juce_Slider.h
  11. +2
    -2
      src/gui/components/layout/juce_GroupComponent.h
  12. +47
    -0
      src/gui/graphics/fonts/juce_Font.cpp
  13. +12
    -0
      src/gui/graphics/fonts/juce_Font.h

+ 76
- 6
juce_amalgamated.cpp View File

@@ -16629,6 +16629,12 @@ ValueTree ValueTree::readFromStream (InputStream& input)
return v; 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_JUCE_NAMESPACE
/*** End of inlined file: juce_ValueTree.cpp ***/ /*** End of inlined file: juce_ValueTree.cpp ***/


@@ -30392,6 +30398,27 @@ void AudioUnitPluginInstance::initialise()
void AudioUnitPluginInstance::prepareToPlay (double sampleRate_, void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
int samplesPerBlockExpected) 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(); initialise();


if (initialised) if (initialised)
@@ -30423,16 +30450,12 @@ void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
stream.mBitsPerChannel = 32; stream.mBitsPerChannel = 32;
stream.mChannelsPerFrame = numIns; stream.mChannelsPerFrame = numIns;


OSStatus err = AudioUnitSetProperty (audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
OSStatus err = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
0, &stream, sizeof (stream)); 0, &stream, sizeof (stream));


stream.mChannelsPerFrame = numOuts; stream.mChannelsPerFrame = numOuts;


err = AudioUnitSetProperty (audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
err = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output,
0, &stream, sizeof (stream)); 0, &stream, sizeof (stream));


outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1); 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)); 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 class TypefaceCache : public DeletedAtShutdown
{ {
public: public:


+ 24
- 10
juce_amalgamated.h View File

@@ -13086,10 +13086,12 @@ public:
*/ */
void writeToStream (OutputStream& output); 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); 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. /** Listener class for events that happen to a ValueTree.


To get events from a ValueTree, make your class implement this interface, and use 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(); 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 juce_UseDebuggingNewOperator


private: private:
@@ -35113,8 +35127,8 @@ public:
@param componentName the name to give the component @param componentName the name to give the component
@param labelText the text to show in the label @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. */ /** Destructor. */
~Label(); ~Label();
@@ -35430,7 +35444,7 @@ public:


@param componentName the name to set for the component (see Component::setName()) @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. */ /** Destructor. */
~ComboBox(); ~ComboBox();
@@ -39198,7 +39212,7 @@ public:


@see Button @see Button
*/ */
TextButton (const String& buttonName,
TextButton (const String& buttonName = String::empty,
const String& toolTip = String::empty); const String& toolTip = String::empty);


/** Destructor. */ /** Destructor. */
@@ -42267,7 +42281,7 @@ public:
initially set to this string, but these can be changed later initially set to this string, but these can be changed later
using the setName() and setButtonText() methods) using the setName() and setButtonText() methods)
*/ */
ToggleButton (const String& buttonText);
explicit ToggleButton (const String& buttonText = String::empty);


/** Destructor. */ /** Destructor. */
~ToggleButton(); ~ToggleButton();
@@ -44162,7 +44176,7 @@ public:
When created, you'll need to set up the slider's style and range with setSliderStyle(), When created, you'll need to set up the slider's style and range with setSliderStyle(),
setRange(), etc. setRange(), etc.
*/ */
explicit Slider (const String& componentName);
explicit Slider (const String& componentName = String::empty);


/** Destructor. */ /** Destructor. */
~Slider(); ~Slider();
@@ -50002,8 +50016,8 @@ public:
@param componentName the name to give the component @param componentName the name to give the component
@param labelText the text to show at the top of the outline @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. */ /** Destructor. */
~GroupComponent(); ~GroupComponent();


+ 23
- 6
src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm View File

@@ -552,6 +552,27 @@ void AudioUnitPluginInstance::initialise()
void AudioUnitPluginInstance::prepareToPlay (double sampleRate_, void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
int samplesPerBlockExpected) 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(); initialise();
if (initialised) if (initialised)
@@ -583,16 +604,12 @@ void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
stream.mBitsPerChannel = 32; stream.mBitsPerChannel = 32;
stream.mChannelsPerFrame = numIns; stream.mChannelsPerFrame = numIns;
OSStatus err = AudioUnitSetProperty (audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
OSStatus err = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
0, &stream, sizeof (stream)); 0, &stream, sizeof (stream));
stream.mChannelsPerFrame = numOuts; stream.mChannelsPerFrame = numOuts;
err = AudioUnitSetProperty (audioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
err = AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output,
0, &stream, sizeof (stream)); 0, &stream, sizeof (stream));
outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1); outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);


+ 7
- 0
src/containers/juce_ValueTree.cpp View File

@@ -28,6 +28,7 @@
BEGIN_JUCE_NAMESPACE BEGIN_JUCE_NAMESPACE
#include "juce_ValueTree.h" #include "juce_ValueTree.h"
#include "../io/streams/juce_MemoryInputStream.h"
//============================================================================== //==============================================================================
@@ -860,4 +861,10 @@ ValueTree ValueTree::readFromStream (InputStream& input)
return v; 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_JUCE_NAMESPACE

+ 4
- 2
src/containers/juce_ValueTree.h View File

@@ -310,10 +310,12 @@ public:
*/ */
void writeToStream (OutputStream& output); 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); 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. /** Listener class for events that happen to a ValueTree.


+ 1
- 1
src/gui/components/buttons/juce_TextButton.h View File

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


+ 1
- 1
src/gui/components/buttons/juce_ToggleButton.h View File

@@ -48,7 +48,7 @@ public:
initially set to this string, but these can be changed later initially set to this string, but these can be changed later
using the setName() and setButtonText() methods) using the setName() and setButtonText() methods)
*/ */
ToggleButton (const String& buttonText);
explicit ToggleButton (const String& buttonText = String::empty);
/** Destructor. */ /** Destructor. */
~ToggleButton(); ~ToggleButton();


+ 1
- 1
src/gui/components/controls/juce_ComboBox.h View File

@@ -84,7 +84,7 @@ public:
@param componentName the name to set for the component (see Component::setName()) @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. */ /** Destructor. */
~ComboBox(); ~ComboBox();


+ 2
- 2
src/gui/components/controls/juce_Label.h View File

@@ -71,8 +71,8 @@ public:
@param componentName the name to give the component @param componentName the name to give the component
@param labelText the text to show in the label @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. */ /** Destructor. */
~Label(); ~Label();


+ 1
- 1
src/gui/components/controls/juce_Slider.h View File

@@ -68,7 +68,7 @@ public:
When created, you'll need to set up the slider's style and range with setSliderStyle(), When created, you'll need to set up the slider's style and range with setSliderStyle(),
setRange(), etc. setRange(), etc.
*/ */
explicit Slider (const String& componentName);
explicit Slider (const String& componentName = String::empty);
/** Destructor. */ /** Destructor. */
~Slider(); ~Slider();


+ 2
- 2
src/gui/components/layout/juce_GroupComponent.h View File

@@ -44,8 +44,8 @@ public:
@param componentName the name to give the component @param componentName the name to give the component
@param labelText the text to show at the top of the outline @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. */ /** Destructor. */
~GroupComponent(); ~GroupComponent();


+ 47
- 0
src/gui/graphics/fonts/juce_Font.cpp View File

@@ -338,6 +338,53 @@ void Font::findFonts (Array<Font>& destArray) throw()
destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain)); 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 class TypefaceCache : public DeletedAtShutdown


+ 12
- 0
src/gui/graphics/fonts/juce_Font.h View File

@@ -344,6 +344,18 @@ public:
*/ */
static void setFallbackFontName (const String& name) throw(); 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 juce_UseDebuggingNewOperator


Loading…
Cancel
Save