From 03b54862c5cfaa1e1eec2a8f3189c6ab8d7e4ed9 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Wed, 9 Dec 2009 15:44:27 +0000 Subject: [PATCH] Fixed a type in AudioSampleBuffer::copyFrom. Added a LookAndFeel::getMouseCursorFor method. Added a parameter to MidiMessage::isNoteOff --- juce_amalgamated.cpp | 39 ++++++++++++------- juce_amalgamated.h | 10 ++++- src/audio/dsp/juce_AudioSampleBuffer.cpp | 13 +++++-- src/audio/midi/juce_MidiMessage.cpp | 4 +- src/audio/midi/juce_MidiMessage.h | 5 ++- src/gui/components/juce_Component.cpp | 2 +- .../lookandfeel/juce_LookAndFeel.cpp | 6 +++ .../components/lookandfeel/juce_LookAndFeel.h | 6 +++ src/gui/components/mouse/juce_MouseCursor.cpp | 16 ++++---- 9 files changed, 67 insertions(+), 34 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index e0189e4653..6fc1c39390 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -25436,14 +25436,21 @@ void AudioSampleBuffer::copyFrom (const int destChannel, jassert (destStartSample >= 0 && destStartSample + numSamples <= size); jassert (source != 0); - if (numSamples > 0 && gain != 0) + if (numSamples > 0) { float* d = channels [destChannel] + destStartSample; if (gain != 1.0f) { - while (--numSamples >= 0) - *d++ = gain * *source++; + if (gain == 0) + { + zeromem (d, sizeof (float) * numSamples); + } + else + { + while (--numSamples >= 0) + *d++ = gain * *source++; + } } else { @@ -27082,10 +27089,10 @@ bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw() && (returnTrueForVelocity0 || data[2] != 0); } -bool MidiMessage::isNoteOff() const throw() +bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw() { return ((data[0] & 0xf0) == 0x80) - || ((data[2] == 0) && ((data[0] & 0xf0) == 0x90)); + || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90)); } bool MidiMessage::isNoteOnOrOff() const throw() @@ -39475,7 +39482,7 @@ void Component::internalUpdateMouseCursor (bool forcedUpdate) throw() if (peer != 0) { - MouseCursor mc (getMouseCursor()); + MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this)); if (isUnboundedMouseModeOn && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0 @@ -63798,6 +63805,11 @@ void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName) defaultSans = newName; } +const MouseCursor LookAndFeel::getMouseCursorFor (Component& component) +{ + return component.getMouseCursor(); +} + void LookAndFeel::drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour, @@ -70083,15 +70095,12 @@ void MouseCursor::showWaitCursor() throw() void MouseCursor::hideWaitCursor() throw() { - if (Component::getComponentUnderMouse()->isValidComponent()) - { - Component::getComponentUnderMouse()->getMouseCursor().showInAllWindows(); - } - else - { - const MouseCursor mc (MouseCursor::NormalCursor); - mc.showInAllWindows(); - } + Component* const c = Component::getComponentUnderMouse(); + + MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c) + : MouseCursor::NormalCursor); + + mc.showInAllWindows(); } END_JUCE_NAMESPACE diff --git a/juce_amalgamated.h b/juce_amalgamated.h index bfc922a1a6..e03fbb125e 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -25851,11 +25851,12 @@ public: /** Returns true if this message is a 'key-up' event. - This will also return true for a note-on event with a velocity of 0. + If returnTrueForNoteOnVelocity0 is true, then his will also return true + for a note-on event with a velocity of 0. @see isNoteOn, getNoteNumber, getVelocity, noteOff */ - bool isNoteOff() const throw(); + bool isNoteOff (const bool returnTrueForNoteOnVelocity0 = true) const throw(); /** Creates a key-up message. @@ -54756,6 +54757,11 @@ public: */ void setDefaultSansSerifTypefaceName (const String& newName); + /** Override this to get the chance to swap a component's mouse cursor for a + customised one. + */ + virtual const MouseCursor getMouseCursorFor (Component& component); + /** Draws the lozenge-shaped background for a standard button. */ virtual void drawButtonBackground (Graphics& g, Button& button, diff --git a/src/audio/dsp/juce_AudioSampleBuffer.cpp b/src/audio/dsp/juce_AudioSampleBuffer.cpp index 5aafe346e9..ccb6be81c4 100644 --- a/src/audio/dsp/juce_AudioSampleBuffer.cpp +++ b/src/audio/dsp/juce_AudioSampleBuffer.cpp @@ -454,14 +454,21 @@ void AudioSampleBuffer::copyFrom (const int destChannel, jassert (destStartSample >= 0 && destStartSample + numSamples <= size); jassert (source != 0); - if (numSamples > 0 && gain != 0) + if (numSamples > 0) { float* d = channels [destChannel] + destStartSample; if (gain != 1.0f) { - while (--numSamples >= 0) - *d++ = gain * *source++; + if (gain == 0) + { + zeromem (d, sizeof (float) * numSamples); + } + else + { + while (--numSamples >= 0) + *d++ = gain * *source++; + } } else { diff --git a/src/audio/midi/juce_MidiMessage.cpp b/src/audio/midi/juce_MidiMessage.cpp index 08e18e00f0..8b337babd6 100644 --- a/src/audio/midi/juce_MidiMessage.cpp +++ b/src/audio/midi/juce_MidiMessage.cpp @@ -310,10 +310,10 @@ bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw() && (returnTrueForVelocity0 || data[2] != 0); } -bool MidiMessage::isNoteOff() const throw() +bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw() { return ((data[0] & 0xf0) == 0x80) - || ((data[2] == 0) && ((data[0] & 0xf0) == 0x90)); + || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90)); } bool MidiMessage::isNoteOnOrOff() const throw() diff --git a/src/audio/midi/juce_MidiMessage.h b/src/audio/midi/juce_MidiMessage.h index 584e85bb9d..a83793fe3c 100644 --- a/src/audio/midi/juce_MidiMessage.h +++ b/src/audio/midi/juce_MidiMessage.h @@ -241,11 +241,12 @@ public: /** Returns true if this message is a 'key-up' event. - This will also return true for a note-on event with a velocity of 0. + If returnTrueForNoteOnVelocity0 is true, then his will also return true + for a note-on event with a velocity of 0. @see isNoteOn, getNoteNumber, getVelocity, noteOff */ - bool isNoteOff() const throw(); + bool isNoteOff (const bool returnTrueForNoteOnVelocity0 = true) const throw(); /** Creates a key-up message. diff --git a/src/gui/components/juce_Component.cpp b/src/gui/components/juce_Component.cpp index f068a18b35..e8b9136431 100644 --- a/src/gui/components/juce_Component.cpp +++ b/src/gui/components/juce_Component.cpp @@ -1619,7 +1619,7 @@ void Component::internalUpdateMouseCursor (bool forcedUpdate) throw() if (peer != 0) { - MouseCursor mc (getMouseCursor()); + MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this)); if (isUnboundedMouseModeOn && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0 diff --git a/src/gui/components/lookandfeel/juce_LookAndFeel.cpp b/src/gui/components/lookandfeel/juce_LookAndFeel.cpp index badb73e5ef..b0e3cd12c1 100644 --- a/src/gui/components/lookandfeel/juce_LookAndFeel.cpp +++ b/src/gui/components/lookandfeel/juce_LookAndFeel.cpp @@ -335,6 +335,12 @@ void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName) defaultSans = newName; } +//============================================================================== +const MouseCursor LookAndFeel::getMouseCursorFor (Component& component) +{ + return component.getMouseCursor(); +} + //============================================================================== void LookAndFeel::drawButtonBackground (Graphics& g, Button& button, diff --git a/src/gui/components/lookandfeel/juce_LookAndFeel.h b/src/gui/components/lookandfeel/juce_LookAndFeel.h index 2e9c2a0b13..73a48b0b51 100644 --- a/src/gui/components/lookandfeel/juce_LookAndFeel.h +++ b/src/gui/components/lookandfeel/juce_LookAndFeel.h @@ -139,6 +139,12 @@ public: */ void setDefaultSansSerifTypefaceName (const String& newName); + //============================================================================== + /** Override this to get the chance to swap a component's mouse cursor for a + customised one. + */ + virtual const MouseCursor getMouseCursorFor (Component& component); + //============================================================================== /** Draws the lozenge-shaped background for a standard button. */ virtual void drawButtonBackground (Graphics& g, diff --git a/src/gui/components/mouse/juce_MouseCursor.cpp b/src/gui/components/mouse/juce_MouseCursor.cpp index 6667010810..aad8229b01 100644 --- a/src/gui/components/mouse/juce_MouseCursor.cpp +++ b/src/gui/components/mouse/juce_MouseCursor.cpp @@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE #include "juce_MouseCursor.h" #include "../juce_Component.h" +#include "../lookandfeel/juce_LookAndFeel.h" #include "../../../threads/juce_ScopedLock.h" void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw(); @@ -185,15 +186,12 @@ void MouseCursor::showWaitCursor() throw() void MouseCursor::hideWaitCursor() throw() { - if (Component::getComponentUnderMouse()->isValidComponent()) - { - Component::getComponentUnderMouse()->getMouseCursor().showInAllWindows(); - } - else - { - const MouseCursor mc (MouseCursor::NormalCursor); - mc.showInAllWindows(); - } + Component* const c = Component::getComponentUnderMouse(); + + MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c) + : MouseCursor::NormalCursor); + + mc.showInAllWindows(); } END_JUCE_NAMESPACE