Browse Source

More workarounds for loading dodgy WAV files. Internal ComponentBuilder work.

tags/2021-05-28
jules 13 years ago
parent
commit
e8d58c7ff6
3 changed files with 47 additions and 26 deletions
  1. +13
    -3
      modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp
  2. +31
    -23
      modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp
  3. +3
    -0
      modules/juce_gui_basics/layout/juce_ComponentBuilder.h

+ 13
- 3
modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp View File

@@ -518,9 +518,19 @@ public:
const unsigned short format = (unsigned short) input->readShort();
numChannels = (unsigned int) input->readShort();
sampleRate = input->readInt();
input->skipNextBytes (4); // (skip bytes per second)
bytesPerFrame = (unsigned int) input->readShort();
bitsPerSample = (unsigned int) (8 * bytesPerFrame / numChannels);
const int bytesPerSec = input->readInt();
input->skipNextBytes (2);
bitsPerSample = (unsigned int) (int) input->readShort();
if (bitsPerSample > 64)
{
bytesPerFrame = bytesPerSec / (int) sampleRate;
bitsPerSample = 8 * bytesPerFrame / numChannels;
}
else
{
bytesPerFrame = numChannels * bitsPerSample / 8;
}
if (format == 3)
{


+ 31
- 23
modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp View File

@@ -33,7 +33,7 @@ namespace ComponentBuilderHelpers
return state [ComponentBuilder::idProperty].toString();
}
Component* findComponentWithID (OwnedArray<Component>& components, const String& compId)
Component* removeComponentWithID (OwnedArray<Component>& components, const String& compId)
{
jassert (compId.isNotEmpty());
@@ -157,6 +157,7 @@ namespace ComponentBuilderHelpers
//=============================================================================
const Identifier ComponentBuilder::idProperty ("id");
const Identifier ComponentBuilder::positionID ("position");
ComponentBuilder::ComponentBuilder()
: imageProvider (nullptr)
@@ -331,7 +332,7 @@ void ComponentBuilder::updateChildComponents (Component& parent, const ValueTree
for (i = 0; i < newNumChildren; ++i)
{
const ValueTree childState (children.getChild (i));
Component* c = findComponentWithID (existingComponents, getStateId (childState));
Component* c = removeComponentWithID (existingComponents, getStateId (childState));
if (c == nullptr)
{
@@ -365,44 +366,49 @@ static void updateMarkers (MarkerList* const list, const ValueTree& state)
MarkerList::ValueTreeWrapper (state).applyTo (*list);
}
void ComponentBuilder::initialiseFromValueTree (Component& comp,
const ValueTree& state,
ImageProvider* const imageProvider)
void ComponentBuilder::initialiseRecursively (Component& comp, const ValueTree& state)
{
using namespace ComponentBuilderHelpers;
ComponentBuilder builder;
builder.setImageProvider (imageProvider);
builder.registerStandardComponentTypes();
refreshBasicComponentProperties (comp, state);
updateMarkers (comp.getMarkers (true), state.getChildWithName ("MARKERS_X"));
updateMarkers (comp.getMarkers (false), state.getChildWithName ("MARKERS_Y"));
const ValueTree childList (state.getChildWithName ("COMPONENTS"));
builder.updateChildComponents (comp, childList);
for (int i = 0; i < childList.getNumChildren(); ++i)
if (childList.isValid())
{
const ValueTree state (childList.getChild(i));
Component* const c = findComponentWithID (comp, getStateId (state));
updateChildComponents (comp, childList);
if (c != nullptr)
for (int i = 0; i < childList.getNumChildren(); ++i)
{
ComponentBuilder::TypeHandler* const type = builder.getHandlerForState (state);
const ValueTree childState (childList.getChild(i));
Component* const c = ComponentBuilderHelpers::findComponentWithID (comp, ComponentBuilderHelpers::getStateId (childState));
if (type != nullptr)
type->updateComponentFromState (c, state);
else
refreshBasicComponentProperties (*c, state);
if (c != nullptr)
{
ComponentBuilder::TypeHandler* const type = getHandlerForState (childState);
if (type != nullptr)
type->updateComponentFromState (c, childState);
else
initialiseRecursively (*c, childState);
}
}
}
}
void ComponentBuilder::initialiseFromValueTree (Component& comp,
const ValueTree& state,
ImageProvider* const imageProvider)
{
ComponentBuilder builder;
builder.setImageProvider (imageProvider);
builder.registerStandardComponentTypes();
builder.initialiseRecursively (comp, state);
}
RelativeRectangle ComponentBuilder::getComponentBounds (const ValueTree& state)
{
static const Identifier positionID ("position");
try
{
return RelativeRectangle (state [positionID].toString());
@@ -420,7 +426,9 @@ void ComponentBuilder::refreshBasicComponentProperties (Component& comp, const V
static const Identifier nameID ("name");
comp.setName (state [nameID].toString());
getComponentBounds (state).applyToComponent (comp);
if (state.hasProperty (positionID))
getComponentBounds (state).applyToComponent (comp);
comp.setExplicitFocusOrder (state [focusOrderID]);
const var tip (state [tooltipID]);


+ 3
- 0
modules/juce_gui_basics/layout/juce_ComponentBuilder.h View File

@@ -258,6 +258,9 @@ private:
WeakReference<Component> componentRef;
#endif
static const Identifier positionID;
void initialiseRecursively (Component&, const ValueTree&);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentBuilder);
};


Loading…
Cancel
Save