diff --git a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp index e0f0f1da32..96ed33c46a 100644 --- a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp @@ -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) { diff --git a/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp b/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp index 5066548106..2a98be646c 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp +++ b/modules/juce_gui_basics/layout/juce_ComponentBuilder.cpp @@ -33,7 +33,7 @@ namespace ComponentBuilderHelpers return state [ComponentBuilder::idProperty].toString(); } - Component* findComponentWithID (OwnedArray& components, const String& compId) + Component* removeComponentWithID (OwnedArray& 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]); diff --git a/modules/juce_gui_basics/layout/juce_ComponentBuilder.h b/modules/juce_gui_basics/layout/juce_ComponentBuilder.h index 46f4410ed9..7f416720c4 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentBuilder.h +++ b/modules/juce_gui_basics/layout/juce_ComponentBuilder.h @@ -258,6 +258,9 @@ private: WeakReference componentRef; #endif + static const Identifier positionID; + void initialiseRecursively (Component&, const ValueTree&); + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentBuilder); };