mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
79 lines
2.5 KiB
C
79 lines
2.5 KiB
C
/*
|
|
==============================================================================
|
|
|
|
This file is part of the JUCE library.
|
|
Copyright (c) 2017 - ROLI Ltd.
|
|
|
|
JUCE is an open source library subject to commercial or open-source
|
|
licensing.
|
|
|
|
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
|
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
|
27th April 2017).
|
|
|
|
End User License Agreement: www.juce.com/juce-5-licence
|
|
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
|
|
|
Or: You may also use this code under the terms of the GPL v3 (see
|
|
www.gnu.org/licenses).
|
|
|
|
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
|
|
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
|
|
DISCLAIMED.
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
//==============================================================================
|
|
/*
|
|
This file contains a bunch of miscellaneous utilities that are
|
|
used by the various demos.
|
|
*/
|
|
|
|
//==============================================================================
|
|
inline Colour getRandomColour (float brightness)
|
|
{
|
|
return Colour::fromHSV (Random::getSystemRandom().nextFloat(), 0.5f, brightness, 1.0f);
|
|
}
|
|
|
|
inline Colour getRandomBrightColour() { return getRandomColour (0.8f); }
|
|
inline Colour getRandomDarkColour() { return getRandomColour (0.3f); }
|
|
|
|
inline Colour getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour uiColour, Colour fallback = Colour (0xff4d4d4d))
|
|
{
|
|
if (auto* v4 = dynamic_cast<LookAndFeel_V4*> (&LookAndFeel::getDefaultLookAndFeel()))
|
|
return v4->getCurrentColourScheme().getUIColour (uiColour);
|
|
|
|
return fallback;
|
|
}
|
|
|
|
//==============================================================================
|
|
// This is basically a sawtooth wave generator - maps a value that bounces between
|
|
// 0.0 and 1.0 at a random speed
|
|
struct BouncingNumber
|
|
{
|
|
BouncingNumber()
|
|
: speed (0.0004 + 0.0007 * Random::getSystemRandom().nextDouble()),
|
|
phase (Random::getSystemRandom().nextDouble())
|
|
{
|
|
}
|
|
|
|
float getValue() const
|
|
{
|
|
double v = fmod (phase + speed * Time::getMillisecondCounterHiRes(), 2.0);
|
|
return (float) (v >= 1.0 ? (2.0 - v) : v);
|
|
}
|
|
|
|
protected:
|
|
double speed, phase;
|
|
};
|
|
|
|
struct SlowerBouncingNumber : public BouncingNumber
|
|
{
|
|
SlowerBouncingNumber()
|
|
{
|
|
speed *= 0.3;
|
|
}
|
|
};
|