From e2ef26e91c37508b6976de0577febc282afbd7eb Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Thu, 6 Jan 2011 15:32:11 +0000 Subject: [PATCH] Added an alertwindow font setting to the lookandfeel class. Made sure the ComponentListener::componentChildrenChanged is called when component z-order changes. Fix for CoreMidi output timestamps. --- .../jucer_ProjectInformationComponent.cpp | 10 +- .../Source/GraphEditorPanel.cpp | 3 + juce_amalgamated.cpp | 99 ++++++++++--------- juce_amalgamated.h | 11 ++- .../juce_ResamplingAudioSource.cpp | 23 +++-- src/core/juce_StandardHeader.h | 2 +- src/gui/components/juce_Component.cpp | 61 ++++++------ src/gui/components/juce_Component.h | 3 +- .../lookandfeel/juce_LookAndFeel.cpp | 5 + .../components/lookandfeel/juce_LookAndFeel.h | 1 + .../components/windows/juce_AlertWindow.cpp | 2 +- .../drawables/juce_DrawableComposite.h | 3 +- src/io/files/juce_File.h | 2 +- src/native/mac/juce_mac_CoreMidi.cpp | 4 +- 14 files changed, 124 insertions(+), 105 deletions(-) diff --git a/extras/Jucer (experimental)/Source/Project/jucer_ProjectInformationComponent.cpp b/extras/Jucer (experimental)/Source/Project/jucer_ProjectInformationComponent.cpp index 02fc828b7e..fa285bac6b 100644 --- a/extras/Jucer (experimental)/Source/Project/jucer_ProjectInformationComponent.cpp +++ b/extras/Jucer (experimental)/Source/Project/jucer_ProjectInformationComponent.cpp @@ -362,22 +362,22 @@ JUCER_COMPONENT_METADATA_START constructorParams="Project& project_" memberInitialisers="project (project_)"> + position="8, 0, this.left + parent.right - 16, this.top + parent.bottom - 36"/> + position="8, parent.bottom - 30, this.left + 192, this.top + 22"/> + textColour="" backgroundColourOn="" textColourOn="" position="608, parent.bottom - 30, this.left + 208, this.top + 22"/> - + diff --git a/extras/audio plugin host/Source/GraphEditorPanel.cpp b/extras/audio plugin host/Source/GraphEditorPanel.cpp index 8e46d06c3a..4dfff03fa7 100644 --- a/extras/audio plugin host/Source/GraphEditorPanel.cpp +++ b/extras/audio plugin host/Source/GraphEditorPanel.cpp @@ -1026,6 +1026,7 @@ GraphDocumentComponent::GraphDocumentComponent (AudioDeviceManager* deviceManage addAndMakeVisible (statusBar = new TooltipBar()); deviceManager->addAudioCallback (&graphPlayer); + deviceManager->addMidiInputCallback (String::empty, &graphPlayer.getMidiMessageCollector()); graphPanel->updateComponents(); } @@ -1033,6 +1034,8 @@ GraphDocumentComponent::GraphDocumentComponent (AudioDeviceManager* deviceManage GraphDocumentComponent::~GraphDocumentComponent() { deviceManager->removeAudioCallback (&graphPlayer); + deviceManager->removeMidiInputCallback (String::empty, &graphPlayer.getMidiMessageCollector()); + deleteAllChildren(); graphPlayer.setProcessor (0); diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 38d992b73b..d3f93ab9ce 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -24896,15 +24896,20 @@ void ResamplingAudioSource::releaseResources() void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info) { - const ScopedLock sl (ratioLock); + float localRatio; - if (lastRatio != ratio) { - createLowPass (ratio); - lastRatio = ratio; + const ScopedLock sl (ratioLock); + localRatio = ratio; } - const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2; + if (lastRatio != localRatio) + { + createLowPass (localRatio); + lastRatio = localRatio; + } + + const int sampsNeeded = roundToInt (info.numSamples * localRatio) + 2; int bufferSize = buffer.getNumSamples(); @@ -24934,7 +24939,7 @@ void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& inf input->getNextAudioBlock (readInfo); - if (ratio > 1.0001) + if (localRatio > 1.0001) { // for down-sampling, pre-apply the filter.. @@ -24961,7 +24966,7 @@ void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& inf for (int channel = 0; channel < channelsToProcess; ++channel) *destBuffers[channel]++ = srcBuffers[channel][bufferPos] * invAlpha + srcBuffers[channel][nextPos] * alpha; - subSampleOffset += ratio; + subSampleOffset += localRatio; jassert (sampsInBuffer > 0); @@ -24977,13 +24982,13 @@ void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& inf } } - if (ratio < 0.9999) + if (localRatio < 0.9999) { // for up-sampling, apply the filter after transposing.. for (int i = channelsToProcess; --i >= 0;) applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]); } - else if (ratio <= 1.0001) + else if (localRatio <= 1.0001) { // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities for (int i = channelsToProcess; --i >= 0;) @@ -40241,6 +40246,21 @@ void Component::setBufferedToImage (const bool shouldBeBuffered) } } +void Component::moveChildInternal (const int sourceIndex, const int destIndex) +{ + if (sourceIndex != destIndex) + { + Component* const c = childComponentList.getUnchecked (sourceIndex); + jassert (c != 0); + c->repaintParent(); + + childComponentList.move (sourceIndex, destIndex); + + sendFakeMouseMove(); + internalChildrenChanged(); + } +} + void Component::toFront (const bool setAsForeground) { // if component methods are being called from threads other than the message @@ -40261,7 +40281,7 @@ void Component::toFront (const bool setAsForeground) } else if (parentComponent != 0) { - Array& childList = parentComponent->childComponentList; + const Array& childList = parentComponent->childComponentList; if (childList.getLast() != this) { @@ -40279,13 +40299,7 @@ void Component::toFront (const bool setAsForeground) --insertIndex; } - if (index != insertIndex) - { - childList.move (index, insertIndex); - sendFakeMouseMove(); - - repaintParent(); - } + parentComponent->moveChildInternal (index, insertIndex); } } @@ -40306,8 +40320,7 @@ void Component::toBehind (Component* const other) if (parentComponent != 0) { - Array& childList = parentComponent->childComponentList; - + const Array& childList = parentComponent->childComponentList; const int index = childList.indexOf (this); if (index >= 0 && childList [index + 1] != other) @@ -40319,10 +40332,7 @@ void Component::toBehind (Component* const other) if (index < otherIndex) --otherIndex; - childList.move (index, otherIndex); - - sendFakeMouseMove(); - repaintParent(); + parentComponent->moveChildInternal (index, otherIndex); } } } @@ -40345,35 +40355,27 @@ void Component::toBehind (Component* const other) void Component::toBack() { - Array& childList = parentComponent->childComponentList; - if (isOnDesktop()) { jassertfalse; //xxx need to add this to native window } - else if (parentComponent != 0 && childList.getFirst() != this) + else if (parentComponent != 0) { - const int index = childList.indexOf (this); + const Array& childList = parentComponent->childComponentList; - if (index > 0) + if (childList.getFirst() != this) { - int insertIndex = 0; + const int index = childList.indexOf (this); - if (flags.alwaysOnTopFlag) + if (index > 0) { - while (insertIndex < childList.size() - && ! childList.getUnchecked (insertIndex)->isAlwaysOnTop()) - { - ++insertIndex; - } - } + int insertIndex = 0; - if (index != insertIndex) - { - childList.move (index, insertIndex); + if (flags.alwaysOnTopFlag) + while (insertIndex < childList.size() && ! childList.getUnchecked (insertIndex)->isAlwaysOnTop()) + ++insertIndex; - sendFakeMouseMove(); - repaintParent(); + parentComponent->moveChildInternal (index, insertIndex); } } } @@ -65444,6 +65446,11 @@ int LookAndFeel::getAlertWindowButtonHeight() return 28; } +const Font LookAndFeel::getAlertWindowMessageFont() +{ + return Font (15.0f); +} + const Font LookAndFeel::getAlertWindowFont() { return Font (12.0f); @@ -76484,7 +76491,7 @@ void AlertWindow::setMessage (const String& message) { text = newMessage; - font.setHeight (15.0f); + font = getLookAndFeel().getAlertWindowMessageFont(); Font titleFont (font.getHeight() * 1.1f, Font::bold); textLayout.setText (getName() + "\n\n", titleFont); @@ -270305,7 +270312,7 @@ void MidiOutput::sendMessageNow (const MidiMessage& message) for (int i = 0; i < numPackets; ++i) { - p->timeStamp = 0; + p->timeStamp = AudioGetCurrentHostTime(); p->length = jmin (maxPacketSize, bytesLeft); memcpy (p->data, message.getRawData() + pos, p->length); pos += p->length; @@ -270319,7 +270326,7 @@ void MidiOutput::sendMessageNow (const MidiMessage& message) { MIDIPacketList packets; packets.numPackets = 1; - packets.packet[0].timeStamp = 0; + packets.packet[0].timeStamp = AudioGetCurrentHostTime(); packets.packet[0].length = message.getRawDataSize(); *(int*) (packets.packet[0].data) = *(const int*) message.getRawData(); @@ -278808,7 +278815,7 @@ void MidiOutput::sendMessageNow (const MidiMessage& message) for (int i = 0; i < numPackets; ++i) { - p->timeStamp = 0; + p->timeStamp = AudioGetCurrentHostTime(); p->length = jmin (maxPacketSize, bytesLeft); memcpy (p->data, message.getRawData() + pos, p->length); pos += p->length; @@ -278822,7 +278829,7 @@ void MidiOutput::sendMessageNow (const MidiMessage& message) { MIDIPacketList packets; packets.numPackets = 1; - packets.packet[0].timeStamp = 0; + packets.packet[0].timeStamp = AudioGetCurrentHostTime(); packets.packet[0].length = message.getRawDataSize(); *(int*) (packets.packet[0].data) = *(const int*) message.getRawData(); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index fa781d80c4..75ab9379b8 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -73,7 +73,7 @@ namespace JuceDummyNamespace {} */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 53 -#define JUCE_BUILDNUMBER 7 +#define JUCE_BUILDNUMBER 8 /** Current Juce version number. @@ -9459,7 +9459,7 @@ public: the file first and then re-writing it, it creates a new temporary file, writes the data to that, and then moves the new file to replace the existing file. This means that if the power gets pulled out or something crashes, - you're a lot less likely to end up with an empty file.. + you're a lot less likely to end up with a corrupted or unfinished file.. Returns true if the operation succeeds, or false if it fails. @@ -29038,7 +29038,8 @@ private: void internalModifierKeysChanged(); void internalChildrenChanged(); void internalHierarchyChanged(); - Component* removeChildComponent (const int index, bool sendParentEvents, bool sendChildEvents); + Component* removeChildComponent (int index, bool sendParentEvents, bool sendChildEvents); + void moveChildInternal (int sourceIndex, int destIndex); void paintComponentAndChildren (Graphics& g); void paintComponent (Graphics& g); void paintWithinParentContext (Graphics& g); @@ -56179,6 +56180,7 @@ public: virtual int getAlertWindowButtonHeight(); + virtual const Font getAlertWindowMessageFont(); virtual const Font getAlertWindowFont(); /** Draws a progress bar. @@ -61769,8 +61771,7 @@ protected: @see Drawable */ -class JUCE_API DrawableComposite : public Drawable//, -// public Expression::EvaluationContext +class JUCE_API DrawableComposite : public Drawable { public: diff --git a/src/audio/audio_sources/juce_ResamplingAudioSource.cpp b/src/audio/audio_sources/juce_ResamplingAudioSource.cpp index b92e835cab..30b0c614b4 100644 --- a/src/audio/audio_sources/juce_ResamplingAudioSource.cpp +++ b/src/audio/audio_sources/juce_ResamplingAudioSource.cpp @@ -88,15 +88,20 @@ void ResamplingAudioSource::releaseResources() void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info) { - const ScopedLock sl (ratioLock); + float localRatio; - if (lastRatio != ratio) { - createLowPass (ratio); - lastRatio = ratio; + const ScopedLock sl (ratioLock); + localRatio = ratio; } - const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2; + if (lastRatio != localRatio) + { + createLowPass (localRatio); + lastRatio = localRatio; + } + + const int sampsNeeded = roundToInt (info.numSamples * localRatio) + 2; int bufferSize = buffer.getNumSamples(); @@ -126,7 +131,7 @@ void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& inf input->getNextAudioBlock (readInfo); - if (ratio > 1.0001) + if (localRatio > 1.0001) { // for down-sampling, pre-apply the filter.. @@ -153,7 +158,7 @@ void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& inf for (int channel = 0; channel < channelsToProcess; ++channel) *destBuffers[channel]++ = srcBuffers[channel][bufferPos] * invAlpha + srcBuffers[channel][nextPos] * alpha; - subSampleOffset += ratio; + subSampleOffset += localRatio; jassert (sampsInBuffer > 0); @@ -169,13 +174,13 @@ void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& inf } } - if (ratio < 0.9999) + if (localRatio < 0.9999) { // for up-sampling, apply the filter after transposing.. for (int i = channelsToProcess; --i >= 0;) applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]); } - else if (ratio <= 1.0001) + else if (localRatio <= 1.0001) { // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities for (int i = channelsToProcess; --i >= 0;) diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index 88c3c93b05..bf67e61de9 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -33,7 +33,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 53 -#define JUCE_BUILDNUMBER 7 +#define JUCE_BUILDNUMBER 8 /** Current Juce version number. diff --git a/src/gui/components/juce_Component.cpp b/src/gui/components/juce_Component.cpp index 72492c4cb9..893eb2ba7b 100644 --- a/src/gui/components/juce_Component.cpp +++ b/src/gui/components/juce_Component.cpp @@ -732,6 +732,21 @@ void Component::setBufferedToImage (const bool shouldBeBuffered) } //============================================================================== +void Component::moveChildInternal (const int sourceIndex, const int destIndex) +{ + if (sourceIndex != destIndex) + { + Component* const c = childComponentList.getUnchecked (sourceIndex); + jassert (c != 0); + c->repaintParent(); + + childComponentList.move (sourceIndex, destIndex); + + sendFakeMouseMove(); + internalChildrenChanged(); + } +} + void Component::toFront (const bool setAsForeground) { // if component methods are being called from threads other than the message @@ -752,7 +767,7 @@ void Component::toFront (const bool setAsForeground) } else if (parentComponent != 0) { - Array& childList = parentComponent->childComponentList; + const Array& childList = parentComponent->childComponentList; if (childList.getLast() != this) { @@ -770,13 +785,7 @@ void Component::toFront (const bool setAsForeground) --insertIndex; } - if (index != insertIndex) - { - childList.move (index, insertIndex); - sendFakeMouseMove(); - - repaintParent(); - } + parentComponent->moveChildInternal (index, insertIndex); } } @@ -797,8 +806,7 @@ void Component::toBehind (Component* const other) if (parentComponent != 0) { - Array& childList = parentComponent->childComponentList; - + const Array& childList = parentComponent->childComponentList; const int index = childList.indexOf (this); if (index >= 0 && childList [index + 1] != other) @@ -810,10 +818,7 @@ void Component::toBehind (Component* const other) if (index < otherIndex) --otherIndex; - childList.move (index, otherIndex); - - sendFakeMouseMove(); - repaintParent(); + parentComponent->moveChildInternal (index, otherIndex); } } } @@ -836,35 +841,27 @@ void Component::toBehind (Component* const other) void Component::toBack() { - Array& childList = parentComponent->childComponentList; - if (isOnDesktop()) { jassertfalse; //xxx need to add this to native window } - else if (parentComponent != 0 && childList.getFirst() != this) + else if (parentComponent != 0) { - const int index = childList.indexOf (this); + const Array& childList = parentComponent->childComponentList; - if (index > 0) + if (childList.getFirst() != this) { - int insertIndex = 0; + const int index = childList.indexOf (this); - if (flags.alwaysOnTopFlag) + if (index > 0) { - while (insertIndex < childList.size() - && ! childList.getUnchecked (insertIndex)->isAlwaysOnTop()) - { - ++insertIndex; - } - } + int insertIndex = 0; - if (index != insertIndex) - { - childList.move (index, insertIndex); + if (flags.alwaysOnTopFlag) + while (insertIndex < childList.size() && ! childList.getUnchecked (insertIndex)->isAlwaysOnTop()) + ++insertIndex; - sendFakeMouseMove(); - repaintParent(); + parentComponent->moveChildInternal (index, insertIndex); } } } diff --git a/src/gui/components/juce_Component.h b/src/gui/components/juce_Component.h index e763f4f2ab..aaee81f8d3 100644 --- a/src/gui/components/juce_Component.h +++ b/src/gui/components/juce_Component.h @@ -2239,7 +2239,8 @@ private: void internalModifierKeysChanged(); void internalChildrenChanged(); void internalHierarchyChanged(); - Component* removeChildComponent (const int index, bool sendParentEvents, bool sendChildEvents); + Component* removeChildComponent (int index, bool sendParentEvents, bool sendChildEvents); + void moveChildInternal (int sourceIndex, int destIndex); void paintComponentAndChildren (Graphics& g); void paintComponent (Graphics& g); void paintWithinParentContext (Graphics& g); diff --git a/src/gui/components/lookandfeel/juce_LookAndFeel.cpp b/src/gui/components/lookandfeel/juce_LookAndFeel.cpp index e22868cbff..cb5eef50d0 100644 --- a/src/gui/components/lookandfeel/juce_LookAndFeel.cpp +++ b/src/gui/components/lookandfeel/juce_LookAndFeel.cpp @@ -685,6 +685,11 @@ int LookAndFeel::getAlertWindowButtonHeight() return 28; } +const Font LookAndFeel::getAlertWindowMessageFont() +{ + return Font (15.0f); +} + const Font LookAndFeel::getAlertWindowFont() { return Font (12.0f); diff --git a/src/gui/components/lookandfeel/juce_LookAndFeel.h b/src/gui/components/lookandfeel/juce_LookAndFeel.h index 9b8abb5d97..627c61a25a 100644 --- a/src/gui/components/lookandfeel/juce_LookAndFeel.h +++ b/src/gui/components/lookandfeel/juce_LookAndFeel.h @@ -199,6 +199,7 @@ public: virtual int getAlertWindowButtonHeight(); + virtual const Font getAlertWindowMessageFont(); virtual const Font getAlertWindowFont(); /** Draws a progress bar. diff --git a/src/gui/components/windows/juce_AlertWindow.cpp b/src/gui/components/windows/juce_AlertWindow.cpp index a8661fe9f7..635b5c2b11 100644 --- a/src/gui/components/windows/juce_AlertWindow.cpp +++ b/src/gui/components/windows/juce_AlertWindow.cpp @@ -125,7 +125,7 @@ void AlertWindow::setMessage (const String& message) { text = newMessage; - font.setHeight (15.0f); + font = getLookAndFeel().getAlertWindowMessageFont(); Font titleFont (font.getHeight() * 1.1f, Font::bold); textLayout.setText (getName() + "\n\n", titleFont); diff --git a/src/gui/graphics/drawables/juce_DrawableComposite.h b/src/gui/graphics/drawables/juce_DrawableComposite.h index 899204cfae..8421c33090 100644 --- a/src/gui/graphics/drawables/juce_DrawableComposite.h +++ b/src/gui/graphics/drawables/juce_DrawableComposite.h @@ -38,8 +38,7 @@ @see Drawable */ -class JUCE_API DrawableComposite : public Drawable//, -// public Expression::EvaluationContext +class JUCE_API DrawableComposite : public Drawable { public: //============================================================================== diff --git a/src/io/files/juce_File.h b/src/io/files/juce_File.h index fc750cbf2b..6665195f87 100644 --- a/src/io/files/juce_File.h +++ b/src/io/files/juce_File.h @@ -624,7 +624,7 @@ public: the file first and then re-writing it, it creates a new temporary file, writes the data to that, and then moves the new file to replace the existing file. This means that if the power gets pulled out or something crashes, - you're a lot less likely to end up with an empty file.. + you're a lot less likely to end up with a corrupted or unfinished file.. Returns true if the operation succeeds, or false if it fails. diff --git a/src/native/mac/juce_mac_CoreMidi.cpp b/src/native/mac/juce_mac_CoreMidi.cpp index e46107b1d4..fc156b4f17 100644 --- a/src/native/mac/juce_mac_CoreMidi.cpp +++ b/src/native/mac/juce_mac_CoreMidi.cpp @@ -399,7 +399,7 @@ void MidiOutput::sendMessageNow (const MidiMessage& message) for (int i = 0; i < numPackets; ++i) { - p->timeStamp = 0; + p->timeStamp = AudioGetCurrentHostTime(); p->length = jmin (maxPacketSize, bytesLeft); memcpy (p->data, message.getRawData() + pos, p->length); pos += p->length; @@ -413,7 +413,7 @@ void MidiOutput::sendMessageNow (const MidiMessage& message) { MIDIPacketList packets; packets.numPackets = 1; - packets.packet[0].timeStamp = 0; + packets.packet[0].timeStamp = AudioGetCurrentHostTime(); packets.packet[0].length = message.getRawDataSize(); *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();