From 0ec53673ce1c81e90690ffc38439691b84eb3f69 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 4 Nov 2014 11:41:36 +0000 Subject: [PATCH] Demo cleanups. --- extras/Demo/Source/Demos/AnimationDemo.cpp | 25 +++++---- .../Source/Demos/AudioLiveScrollingDisplay.h | 2 +- .../Demo/Source/Demos/AudioPlaybackDemo.cpp | 2 +- .../Source/Demos/AudioSynthesiserDemo.cpp | 4 +- extras/Demo/Source/Demos/Box2DDemo.cpp | 2 +- extras/Demo/Source/Demos/GraphicsDemo.cpp | 5 +- .../Demo/Source/Demos/TimersAndEventsDemo.cpp | 2 +- extras/Demo/Source/IntroScreen.cpp | 52 +++++++------------ .../juce_GenericAudioProcessorEditor.cpp | 2 +- .../gui/juce_MidiKeyboardComponent.cpp | 2 +- .../layout/juce_AnimatedPosition.h | 6 +-- .../layout/juce_ComponentAnimator.cpp | 2 +- .../misc/juce_AnimatedAppComponent.cpp | 2 +- 13 files changed, 46 insertions(+), 62 deletions(-) diff --git a/extras/Demo/Source/Demos/AnimationDemo.cpp b/extras/Demo/Source/Demos/AnimationDemo.cpp index c5dde858fd..34a8e86a1f 100644 --- a/extras/Demo/Source/Demos/AnimationDemo.cpp +++ b/extras/Demo/Source/Demos/AnimationDemo.cpp @@ -147,11 +147,13 @@ public: for (int i = 0; i < componentsToAnimate.size(); ++i) { - int newIndex = (i + 3) % componentsToAnimate.size(); - float angle = newIndex * 2.0f * float_Pi / componentsToAnimate.size(); - float radius = getWidth() * 0.35f; + const int newIndex = (i + 3) % componentsToAnimate.size(); + const float angle = newIndex * 2.0f * float_Pi / componentsToAnimate.size(); + const float radius = getWidth() * 0.35f; - Rectangle r (getWidth() / 2 + radius * sin (angle) - 50, getHeight() / 2 + radius * cos (angle) - 50, 100, 100); + Rectangle r (getWidth() / 2 + (int) (radius * std::sin (angle)) - 50, + getHeight() / 2 + (int) (radius * std::cos (angle)) - 50, + 100, 100); animator.animateComponent (componentsToAnimate.getUnchecked(i), r.reduced (10), @@ -162,7 +164,7 @@ public: 0.0); } - startTimer (1000 / 60); + startTimerHz (60); } void paint (Graphics& g) override @@ -253,12 +255,12 @@ private: { for (int i = 0; i < componentsToAnimate.size(); ++i) { - int newIndex = (i + 3 * cycleCount) % componentsToAnimate.size(); - float angle = newIndex * 2.0f * float_Pi / componentsToAnimate.size(); - float radius = getWidth() * 0.35f; + const int newIndex = (i + 3 * cycleCount) % componentsToAnimate.size(); + const float angle = newIndex * 2.0f * float_Pi / componentsToAnimate.size(); + const float radius = getWidth() * 0.35f; - Rectangle r (getWidth() / 2 + (int) (radius * sin (angle) - 50), - getHeight() / 2 + (int) (radius * cos (angle) - 50), + Rectangle r (getWidth() / 2 + (int) (radius * std::sin (angle)) - 50, + getHeight() / 2 + (int) (radius * std::cos (angle)) - 50, 100, 100); animator.animateComponent (componentsToAnimate.getUnchecked(i), @@ -269,7 +271,8 @@ private: 0.0, 0.0); } - cycleCount++; + + ++cycleCount; } void timerCallback() override diff --git a/extras/Demo/Source/Demos/AudioLiveScrollingDisplay.h b/extras/Demo/Source/Demos/AudioLiveScrollingDisplay.h index ef9e87772c..2699811ebf 100644 --- a/extras/Demo/Source/Demos/AudioLiveScrollingDisplay.h +++ b/extras/Demo/Source/Demos/AudioLiveScrollingDisplay.h @@ -44,7 +44,7 @@ public: setOpaque (true); clear(); - startTimer (1000 / 75); // use a timer to keep repainting this component + startTimerHz (75); // use a timer to keep repainting this component } //============================================================================== diff --git a/extras/Demo/Source/Demos/AudioPlaybackDemo.cpp b/extras/Demo/Source/Demos/AudioPlaybackDemo.cpp index 05d7d75bc3..f57c079cc6 100644 --- a/extras/Demo/Source/Demos/AudioPlaybackDemo.cpp +++ b/extras/Demo/Source/Demos/AudioPlaybackDemo.cpp @@ -70,7 +70,7 @@ public: scrollbar.setRangeLimits (newRange); setRange (newRange); - startTimer (1000 / 40); + startTimerHz (40); } } diff --git a/extras/Demo/Source/Demos/AudioSynthesiserDemo.cpp b/extras/Demo/Source/Demos/AudioSynthesiserDemo.cpp index 39f0093233..b602f577ef 100644 --- a/extras/Demo/Source/Demos/AudioSynthesiserDemo.cpp +++ b/extras/Demo/Source/Demos/AudioSynthesiserDemo.cpp @@ -101,7 +101,7 @@ struct SineWaveVoice : public SynthesiserVoice { while (--numSamples >= 0) { - const float currentSample = (float) (sin (currentAngle) * level * tailOff); + const float currentSample = std::sin (currentAngle) * level * tailOff; for (int i = outputBuffer.getNumChannels(); --i >= 0;) outputBuffer.addSample (i, startSample, currentSample); @@ -124,7 +124,7 @@ struct SineWaveVoice : public SynthesiserVoice { while (--numSamples >= 0) { - const float currentSample = (float) (sin (currentAngle) * level); + const float currentSample = std::sin (currentAngle) * level; for (int i = outputBuffer.getNumChannels(); --i >= 0;) outputBuffer.addSample (i, startSample, currentSample); diff --git a/extras/Demo/Source/Demos/Box2DDemo.cpp b/extras/Demo/Source/Demos/Box2DDemo.cpp index 52997971aa..ccb37038bb 100644 --- a/extras/Demo/Source/Demos/Box2DDemo.cpp +++ b/extras/Demo/Source/Demos/Box2DDemo.cpp @@ -190,7 +190,7 @@ public: instructions.setReadOnly (true); instructions.setColour (TextEditor::backgroundColourId, Colours::lightgrey); - startTimer (1000 / 60); + startTimerHz (60); } ~Box2DDemo() diff --git a/extras/Demo/Source/Demos/GraphicsDemo.cpp b/extras/Demo/Source/Demos/GraphicsDemo.cpp index ec1a37341a..08c94595f3 100644 --- a/extras/Demo/Source/Demos/GraphicsDemo.cpp +++ b/extras/Demo/Source/Demos/GraphicsDemo.cpp @@ -592,10 +592,7 @@ public: if (currentDemo != nullptr) { addAndMakeVisible (currentDemo); - - const int fps = 60; - startTimer (1000 / fps); - + startTimerHz (60); resized(); } } diff --git a/extras/Demo/Source/Demos/TimersAndEventsDemo.cpp b/extras/Demo/Source/Demos/TimersAndEventsDemo.cpp index 3441580a7b..8f7cd09144 100644 --- a/extras/Demo/Source/Demos/TimersAndEventsDemo.cpp +++ b/extras/Demo/Source/Demos/TimersAndEventsDemo.cpp @@ -68,7 +68,7 @@ public: void startFlashing() { flashAlpha = 1.0f; - startTimer (1000 / 25); + startTimerHz (25); } /** Stops this component flashing without sending a change message. */ diff --git a/extras/Demo/Source/IntroScreen.cpp b/extras/Demo/Source/IntroScreen.cpp index e5e2cec96c..eeac460fc5 100644 --- a/extras/Demo/Source/IntroScreen.cpp +++ b/extras/Demo/Source/IntroScreen.cpp @@ -71,53 +71,39 @@ private: struct LogoDrawComponent : public Component, private Timer { - LogoDrawComponent() : logoPath (MainAppWindow::getJUCELogoPath()) + LogoDrawComponent() : logoPath (MainAppWindow::getJUCELogoPath()), elapsed (0.0f) { setBounds (logoPath.getBounds().withPosition (Point()).getSmallestIntegerContainer()); - startTimer (1000 / 60); // try to repaint at 60 fps - - elapsed = 0.0f; + startTimerHz (60); // try to repaint at 60 fps } void paint (Graphics& g) override { - //g.setGradientFill (getGradient()); - g.setColour (Colour::greyLevel (0.3f)); + Path wavePath; float waveStep = 10.0f; + int i = 0; - for (int i = 0; i < getWidth()/waveStep; ++i) + for (float x = waveStep * 0.5f; x < getWidth(); x += waveStep) { - float x = waveStep*0.5f + waveStep * i; - float y1 = getHeight() * 0.5f + getHeight() * 0.05f * sin (i * 0.38f + elapsed); - float y2 = getHeight() * 0.5 + getHeight() * 0.1f * sin (i * 0.2f + elapsed * 2.0f); - g.drawLine (x, y1, x, y2, 2.0f); - g.fillEllipse (x - waveStep * 0.3f, y1 - waveStep * 0.3f, waveStep*0.6f, waveStep*0.6f); - g.fillEllipse (x - waveStep * 0.3f, y2 - waveStep * 0.3f, waveStep*0.6f, waveStep*0.6f); + const float y1 = getHeight() * 0.5f + getHeight() * 0.05f * std::sin (i * 0.38f + elapsed); + const float y2 = getHeight() * 0.5f + getHeight() * 0.10f * std::sin (i * 0.20f + elapsed * 2.0f); + + wavePath.addLineSegment (Line (x, y1, x, y2), 2.0f); + wavePath.addEllipse (x - waveStep * 0.3f, y1 - waveStep * 0.3f, waveStep * 0.6f, waveStep * 0.6f); + wavePath.addEllipse (x - waveStep * 0.3f, y2 - waveStep * 0.3f, waveStep * 0.6f, waveStep * 0.6f); + + ++i; } + g.setColour (Colour::greyLevel (0.3f)); + g.fillPath (wavePath); + g.setColour (Colours::orange); g.fillPath (logoPath, RectanglePlacement (RectanglePlacement::stretchToFit) - .getTransformToFit (logoPath.getBounds(), getLocalBounds().toFloat().reduced (30, 30))); - } - - ColourGradient getGradient() const - { - Colour c1 = Colour::fromHSV (hues[0].getValue(), 0.9f, 0.9f, 1.0f); - Colour c2 = Colour::fromHSV (hues[1].getValue(), 0.9f, 0.9f, 1.0f); - Colour c3 = Colour::fromHSV (hues[2].getValue(), 0.9f, 0.9f, 1.0f); - - float x1 = getWidth() * gradientPos[0].getValue(); - float x2 = getWidth() * gradientPos[1].getValue(); - float y1 = getHeight() * gradientPos[2].getValue(); - float y2 = getHeight() * gradientPos[3].getValue(); - - ColourGradient gradient (c1, x1, y1, - c2, x2, y2, false); - - gradient.addColour (0.5, c3); - return gradient; + .getTransformToFit (logoPath.getBounds(), + getLocalBounds().toFloat().reduced (30, 30))); } void updateTransform() @@ -138,13 +124,11 @@ private: private: void timerCallback() override { - //updateTransform(); repaint(); elapsed += 0.01f; } Path logoPath; - BouncingNumber gradientPos[4], hues[3], size, angle; float elapsed; }; diff --git a/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp b/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp index c94411d7b1..196e9ac9c2 100644 --- a/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp +++ b/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp @@ -67,7 +67,7 @@ public: if (paramHasChanged) { refresh(); - startTimer (1000 / 50); + startTimerHz (50); } else { diff --git a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp index fae07b732e..e0aa000995 100644 --- a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp @@ -97,7 +97,7 @@ MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& s, state.addListener (this); - startTimer (1000 / 20); + startTimerHz (20); } MidiKeyboardComponent::~MidiKeyboardComponent() diff --git a/modules/juce_gui_basics/layout/juce_AnimatedPosition.h b/modules/juce_gui_basics/layout/juce_AnimatedPosition.h index dac6ce174f..2f82e03cf1 100644 --- a/modules/juce_gui_basics/layout/juce_AnimatedPosition.h +++ b/modules/juce_gui_basics/layout/juce_AnimatedPosition.h @@ -94,7 +94,7 @@ public: */ void endDrag() { - startTimer (1000 / 60); + startTimerHz (60); } /** Called outside of a drag operation to cause a nudge in the specified direction. @@ -102,7 +102,7 @@ public: */ void nudge (double deltaFromCurrentPosition) { - startTimer (100); + startTimerHz (10); moveTo (position + deltaFromCurrentPosition); } @@ -197,7 +197,7 @@ private: if (behaviour.isStopped (newPos)) stopTimer(); else - startTimer (1000 / 60); + startTimerHz (60); setPositionAndSendChange (newPos); } diff --git a/modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp b/modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp index 6f28e8be6f..3507fc839f 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp +++ b/modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp @@ -231,7 +231,7 @@ void ComponentAnimator::animateComponent (Component* const component, if (! isTimerRunning()) { lastTime = Time::getMillisecondCounter(); - startTimer (1000 / 50); + startTimerHz (50); } } } diff --git a/modules/juce_gui_extra/misc/juce_AnimatedAppComponent.cpp b/modules/juce_gui_extra/misc/juce_AnimatedAppComponent.cpp index 4df344eed0..01708c5acc 100644 --- a/modules/juce_gui_extra/misc/juce_AnimatedAppComponent.cpp +++ b/modules/juce_gui_extra/misc/juce_AnimatedAppComponent.cpp @@ -31,7 +31,7 @@ AnimatedAppComponent::AnimatedAppComponent() void AnimatedAppComponent::setFramesPerSecond (int framesPerSecond) { jassert (framesPerSecond > 0 && framesPerSecond < 1000); - startTimer (1000 / framesPerSecond); + startTimerHz (framesPerSecond); } int AnimatedAppComponent::getMillisecondsSinceLastUpdate() const noexcept