Plaquette
 
Loading...
Searching...
No Matches
pq::Ramp Class Reference

Provides a ramping / tweening mechanism that allows smooth transitions between two values. More...

#include <Ramp.h>

Inheritance diagram for pq::Ramp:
Collaboration diagram for pq::Ramp:

Public Member Functions

 Ramp (Engine &engine=Engine::primary())
 Constructor.
 
 Ramp (float duration, Engine &engine=Engine::primary())
 Constructor with duration.
 
virtual float get ()
 Returns value of ramp.
 
virtual float put (float value)
 Forces value in the ramp.
 
virtual float mapTo (float toLow, float toHigh)
 Maps value to new range.
 
void easing (easing_function easing)
 Sets easing function to apply to ramp.
 
void noEasing ()
 Remove easing function (linear/no easing).
 
virtual void to (float to)
 Assign final value of the ramp starting from current value.
 
virtual void from (float from)
 Assign initial value of the ramp.
 
virtual void fromTo (float from, float to)
 Assign initial and final values of the ramp.
 
virtual void duration (float duration)
 Sets the duration of the chronometer.
 
virtual float duration () const
 Returns duration.
 
virtual void speed (float speed)
 Sets the speed (rate of change) of the ramp in change-per-second.
 
virtual float speed () const
 Returns speed (rate of change) of the ramp in change-per-second.
 
virtual void start ()
 Starts/restarts the ramp. Will repeat the last ramp.
 
virtual void go (float from, float to, float durationOrSpeed, easing_function easing=0)
 Starts a new ramp.
 
virtual void go (float to, float durationOrSpeed, easing_function easing=0)
 Starts a new ramp, starting from current value.
 
virtual void go (float to, easing_function easing=0)
 Starts a new ramp, starting from current value (keeping the same duration/speed).
 
virtual void mode (uint8_t mode)
 Changes the mode of the component (RAMP_DURATION or RAMP_SPEED).
 
uint8_t mode () const
 Returns the mode of the component (RAMP_DURATION or RAMP_SPEED).
 
virtual bool finished ()
 Returns true iff the ramp just finished its process this step.
 
virtual void onFinish (EventCallback callback)
 Registers event callback on finish event.
 
virtual void setTime (float time)
 Forces current time (in seconds).
 
float durationToSpeed (float duration) const
 Returns speed based on duration.
 
float speedToDuration (float speed) const
 Returns duration based on speed.
 
virtual void start (float to, float durationOrSpeed, easing_function easing=0)
 
virtual void start (float from, float to, float durationOrSpeed, easing_function easing=0)
 
virtual void clearEvents ()
 
float seconds () const
 Returns engine time in seconds.
 
uint32_t milliSeconds () const
 Returns engine time in milliseconds.
 
uint64_t microSeconds () const
 Returns engine time in microseconds.
 
unsigned long nSteps () const
 Returns number of engine steps.
 
float sampleRate () const
 Returns engine sample rate.
 
float samplePeriod () const
 Returns enginesample period.
 
 operator float ()
 Object can be used directly to access its value.
 
 operator bool ()
 Operator that allows usage in conditional expressions.
 
virtual void start (float duration)
 Starts/restarts the chronometer with specific duration.
 
virtual float progress () const
 The progress of the timer process (in %).
 
virtual bool isFinished () const
 Returns true iff the chronometer has finished its process.
 
virtual bool isComplete () const
 
virtual void pause ()
 Interrupts the chronometer.
 
virtual void resume ()
 Resumes process.
 
virtual float elapsed () const
 The time currently elapsed by the chronometer (in seconds).
 
virtual bool hasPassed (float timeout) const
 Returns true iff elapsed time has passed given timeout.
 
virtual bool hasPassed (float timeout, bool restartIfPassed)
 
virtual void addTime (float time)
 Adds/subtracts time to the chronometer.
 
virtual bool isRunning () const
 Returns true iff the chronometer is currently running.
 
bool isStarted () const
 
virtual void stop ()
 Interrupts the chronometer and resets to zero.
 
virtual void togglePause ()
 Toggles pause/unpause.
 

Static Public Member Functions

static bool analogToDigital (float f)
 Converts analog (float) value to digital (bool) value.
 
static float digitalToAnalog (bool b)
 Converts digital (bool) value to analog (float) value.
 

Protected Member Functions

virtual void begin ()
 
virtual void step ()
 
virtual bool eventTriggered (EventType eventType)
 Returns true iff an event of a certain type has been triggered.
 
void _durationOrSpeed (float durationOrSpeed)
 
float _durationOrSpeed () const
 
virtual float _time () const
 
virtual void onEvent (EventCallback callback, EventType eventType)
 Registers event callback.
 
Engineengine () const
 Returns the engine that owns this unit.
 
virtual void update ()
 
virtual void _setRunning (bool isRunning)
 

Protected Attributes

float _from
 
float _to
 
float _value
 
easing_function _easing
 
float _speed
 
uint8_t _mode: 1
 
uint8_t _finishedState: 2
 
bool _valueNeedsUpdate: 1
 
uint8_t _data: 4
 
float _duration
 
float _invDuration
 
float _startTime
 
float _offsetTime
 
float _elapsedTime
 
bool _isRunning
 

Detailed Description

Provides a ramping / tweening mechanism that allows smooth transitions between two values.

Constructor & Destructor Documentation

◆ Ramp() [1/2]

pq::Ramp::Ramp ( Engine engine = Engine::primary())

Constructor.

Parameters
enginethe engine running this unit

◆ Ramp() [2/2]

pq::Ramp::Ramp ( float  duration,
Engine engine = Engine::primary() 
)

Constructor with duration.

Parameters
durationduration of the ramp
enginethe engine running this unit

Member Function Documentation

◆ _setRunning()

virtual void pq::AbstractChronometer::_setRunning ( bool  isRunning)
inlineprotectedvirtualinherited

Implements pq::Timeable.

◆ _time()

float pq::Ramp::_time ( ) const
protectedvirtual

◆ addTime()

void pq::AbstractChronometer::addTime ( float  time)
virtualinherited

Adds/subtracts time to the chronometer.

Implements pq::Timeable.

◆ begin()

void pq::Ramp::begin ( )
protectedvirtual

Reimplemented from pq::Unit.

◆ duration() [1/2]

virtual float pq::Ramp::duration ( ) const
inlinevirtual

Returns duration.

Reimplemented from pq::AbstractTimer.

◆ duration() [2/2]

void pq::Ramp::duration ( float  duration)
virtual

Sets the duration of the chronometer.

Reimplemented from pq::AbstractTimer.

◆ easing()

void pq::Ramp::easing ( easing_function  easing)

Sets easing function to apply to ramp.

Parameters
easingthe easing function

◆ eventTriggered()

virtual bool pq::Ramp::eventTriggered ( EventType  eventType)
inlineprotectedvirtual

Returns true iff an event of a certain type has been triggered.

Reimplemented from pq::Unit.

◆ from()

void pq::Ramp::from ( float  from)
virtual

Assign initial value of the ramp.

Parameters
fromthe initial value

◆ fromTo()

void pq::Ramp::fromTo ( float  from,
float  to 
)
virtual

Assign initial and final values of the ramp.

Parameters
fromthe initial value
tothe final value

◆ get()

float pq::Ramp::get ( )
virtual

Returns value of ramp.

Reimplemented from pq::Chainable.

◆ go() [1/3]

void pq::Ramp::go ( float  from,
float  to,
float  durationOrSpeed,
easing_function  easing = 0 
)
virtual

Starts a new ramp.

Parameters
fromthe initial value
tothe final value
durationOrSpeedthe duration of the ramp (in seconds) or speed (in change-per-second) depending on mode
easingthe easing function (optional).

◆ go() [2/3]

void pq::Ramp::go ( float  to,
easing_function  easing = 0 
)
virtual

Starts a new ramp, starting from current value (keeping the same duration/speed).

Parameters
tothe final value
easingthe easing function (optional)

◆ go() [3/3]

void pq::Ramp::go ( float  to,
float  durationOrSpeed,
easing_function  easing = 0 
)
virtual

Starts a new ramp, starting from current value.

Parameters
tothe final value
durationOrSpeedthe duration of the ramp (in seconds) or speed (in change-per-second) depending on mode
easingthe easing function (optional)

◆ hasPassed()

bool pq::AbstractChronometer::hasPassed ( float  timeout,
bool  restartIfPassed 
)
virtualinherited
Deprecated:
Returns true iff elapsed time has passed given timeout (optional argument to automatically restart if true).

◆ isComplete()

virtual bool pq::AbstractTimer::isComplete ( ) const
inlinevirtualinherited

◆ isRunning()

virtual bool pq::AbstractChronometer::isRunning ( ) const
inlinevirtualinherited

Returns true iff the chronometer is currently running.

Implements pq::Timeable.

◆ isStarted()

bool pq::AbstractChronometer::isStarted ( ) const
inlineinherited

◆ mapTo()

float pq::Ramp::mapTo ( float  toLow,
float  toHigh 
)
virtual

Maps value to new range.

Reimplemented from pq::Chainable.

◆ pause()

void pq::AbstractChronometer::pause ( )
virtualinherited

Interrupts the chronometer.

Reimplemented from pq::Timeable.

◆ put()

float pq::Ramp::put ( float  value)
virtual

Forces value in the ramp.

If this happens while the ramp is running, it will interrupt the ramp.

Parameters
valuethe value sent to the unit
Returns
the new value of the unit

Reimplemented from pq::Chainable.

◆ resume()

void pq::AbstractChronometer::resume ( )
virtualinherited

Resumes process.

Reimplemented from pq::Timeable.

◆ setTime()

void pq::Ramp::setTime ( float  time)
virtual

Forces current time (in seconds).

Reimplemented from pq::AbstractChronometer.

◆ start() [1/3]

void pq::Ramp::start ( )
virtual

Starts/restarts the ramp. Will repeat the last ramp.

Reimplemented from pq::AbstractTimer.

◆ start() [2/3]

void pq::Ramp::start ( float  from,
float  to,
float  durationOrSpeed,
easing_function  easing = 0 
)
virtual

◆ start() [3/3]

void pq::Ramp::start ( float  to,
float  durationOrSpeed,
easing_function  easing = 0 
)
virtual

◆ step()

void pq::Ramp::step ( )
protectedvirtual

Reimplemented from pq::Unit.

◆ to()

void pq::Ramp::to ( float  to)
virtual

Assign final value of the ramp starting from current value.

Parameters
tothe final value

The documentation for this class was generated from the following files: