mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
77 lines
2.5 KiB
C
77 lines
2.5 KiB
C
/*
|
|
==============================================================================
|
|
|
|
This file is part of the JUCE library.
|
|
Copyright (c) 2015 - ROLI Ltd.
|
|
|
|
Permission is granted to use this software under the terms of either:
|
|
a) the GPL v2 (or any later version)
|
|
b) the Affero GPL v3
|
|
|
|
Details of these licenses can be found at: www.gnu.org/licenses
|
|
|
|
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
To release a closed-source product which uses JUCE, commercial licenses are
|
|
available: visit www.juce.com for more information.
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
#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;
|
|
}
|
|
};
|