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

Chronometer digital unit which emits 1/true/"on" for one frame, at a regular pace. More...

#include <Metronome.h>

Inheritance diagram for pq::Metronome:
Collaboration diagram for pq::Metronome:

Public Member Functions

 Metronome (Engine &engine=Engine::primary())
 Constructor.
 
 Metronome (float period, Engine &engine=Engine::primary())
 Constructor.
 
virtual bool isOn ()
 Returns true iff the metronome fires.
 
virtual void onBang (EventCallback callback)
 Registers event callback on metronome tick ("bang") event.
 
virtual bool isOff ()
 Returns true iff the input is "off".
 
virtual int getInt ()
 Returns value as integer (0 or 1).
 
virtual float get ()
 Returns value as float (either 0.0 or 1.0).
 
virtual bool on ()
 Sets output to "on" (ie. true, 1).
 
virtual bool off ()
 Sets output to "off" (ie. false, 0).
 
virtual float put (float value)
 Pushes value into the unit.
 
virtual bool putOn (bool value)
 Pushes value into the unit.
 
virtual float mapTo (float toLow, float toHigh)
 Maps value to new range.
 
 operator bool ()
 Operator that allows usage in conditional expressions.
 
 operator float ()
 
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.
 
virtual void period (float period)
 Sets the period (in seconds).
 
virtual float period () const
 Returns the period (in seconds).
 
virtual void frequency (float frequency)
 Sets the frequency (in Hz).
 
virtual float frequency () const
 Returns the frequency (in Hz).
 
virtual void bpm (float bpm)
 Sets the frequency in beats-per-minute.
 
virtual float bpm () const
 Returns the frequency (in BPM).
 
virtual void phase (float phase)
 Sets the phase at % of period.
 
virtual float phase () const
 Returns the phase (in % of period).
 
virtual void phaseShift (float phaseShift)
 Sets the phase shift (ie.
 
virtual float phaseShift () const
 Returns the phase shift (ie.
 
virtual float timeToPhase (float time) const
 Utility function to convert time to phase.
 
virtual void setTime (float time)
 Forces current time (in seconds).
 
virtual void addTime (float time)
 Adds time to current time (in seconds).
 
virtual bool isRunning () const
 Returns true iff the wave is currently running.
 
virtual bool isForward () const
 Returns true iff the wave is moving forward in time.
 
virtual void setForward (bool isForward)
 Sets the direction of oscillation.
 
virtual void forward ()
 Sets the direction of oscillation to move forward in time.
 
virtual void reverse ()
 Sets the direction of oscillation to move backward in time.
 
virtual void toggleReverse ()
 Toggles the direction of oscillation.
 
virtual float randomness () const
 Returns the randomness level in [0, 1].
 
virtual void randomize (float randomness=1.0f)
 Sets the randomness level in [0, 1] (0: no randomness, 1: full randomness).
 
virtual void noRandomize ()
 Disables randomness.
 
virtual void start ()
 Starts/restarts the chronometer.
 
virtual void stop ()
 Interrupts the chronometer and resets to zero.
 
virtual void pause ()
 Interrupts the chronometer.
 
virtual void resume ()
 Resumes process.
 
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.
 
virtual void onEvent (EventCallback callback, EventType eventType)
 Registers event callback.
 
Engineengine () const
 Returns the engine that owns this unit.
 
void _stepPhase (float deltaTimeSecondsTimesFixed32Max)
 
virtual void _setPhase32 (q0_32u_t phase32)
 
virtual void _setRunning (bool isRunning)
 
void _randomPickNext ()
 

Protected Attributes

float _period
 
float _frequency
 
float _phaseShiftOrRandomFrequencyRatio = 0
 
q0_32u_t _phase32
 
bool _overflowed: 1
 
bool _isRunning: 1
 
bool _isForward: 1
 
bool _valueNeedsUpdate: 1
 
uint8_t _randomness: 4
 

Detailed Description

Chronometer digital unit which emits 1/true/"on" for one frame, at a regular pace.

Constructor & Destructor Documentation

◆ Metronome() [1/2]

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

Constructor.

Parameters
enginethe engine running this unit

◆ Metronome() [2/2]

pq::Metronome::Metronome ( float  period,
Engine engine = Engine::primary() 
)

Constructor.

Parameters
periodthe period of oscillation (in seconds)
enginethe engine running this unit

Member Function Documentation

◆ _setRunning()

void pq::AbstractOscillator::_setRunning ( bool  isRunning)
protectedvirtualinherited

Implements pq::Timeable.

◆ addTime()

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

Adds time to current time (in seconds).

Warning
This function is disabled if randomness() > 0.

Implements pq::Timeable.

◆ begin()

void pq::Metronome::begin ( )
protectedvirtual

Reimplemented from pq::Unit.

◆ bpm()

void pq::AbstractOscillator::bpm ( float  bpm)
virtualinherited

Sets the frequency in beats-per-minute.

Parameters
bpmthe frequency of oscillation (in BPM)

◆ eventTriggered()

bool pq::Metronome::eventTriggered ( EventType  eventType)
protectedvirtual

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

Reimplemented from pq::Unit.

◆ frequency()

void pq::AbstractOscillator::frequency ( float  frequency)
virtualinherited

Sets the frequency (in Hz).

Parameters
frequencythe frequency of oscillation (in Hz)

◆ get()

virtual float pq::DigitalUnit::get ( )
inlinevirtualinherited

Returns value as float (either 0.0 or 1.0).

Reimplemented from pq::Chainable.

◆ isOn()

virtual bool pq::Metronome::isOn ( )
inlinevirtual

Returns true iff the metronome fires.

Reimplemented from pq::DigitalUnit.

◆ isRunning()

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

Returns true iff the wave is currently running.

Implements pq::Timeable.

◆ mapTo()

virtual float pq::DigitalUnit::mapTo ( float  toLow,
float  toHigh 
)
inlinevirtualinherited

Maps value to new range.

Reimplemented from pq::Chainable.

◆ pause()

void pq::Timeable::pause ( )
virtualinherited

Interrupts the chronometer.

Reimplemented in pq::AbstractChronometer.

◆ period()

void pq::AbstractOscillator::period ( float  period)
virtualinherited

Sets the period (in seconds).

Parameters
periodthe period of oscillation (in seconds)

◆ phase()

void pq::AbstractOscillator::phase ( float  phase)
virtualinherited

Sets the phase at % of period.

Parameters
phasethe phase (in % of period)

◆ phaseShift() [1/2]

float pq::AbstractOscillator::phaseShift ( ) const
virtualinherited

Returns the phase shift (ie.

the offset, in % of period).

Warning
This function always returns 0 when randomness() > 0.

◆ phaseShift() [2/2]

void pq::AbstractOscillator::phaseShift ( float  phaseShift)
virtualinherited

Sets the phase shift (ie.

the offset, in % of period).

Parameters
phaseShiftthe phase shift (in % of period)
Warning
This function is disabled if randomness() > 0.

◆ put()

virtual float pq::DigitalUnit::put ( float  value)
inlinevirtualinherited

Pushes value into the unit.

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

Reimplemented from pq::Chainable.

Reimplemented in pq::PeakDetector.

◆ putOn()

virtual bool pq::DigitalUnit::putOn ( bool  value)
inlinevirtualinherited

Pushes value into the unit.

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

Reimplemented in pq::DigitalSource.

◆ resume()

void pq::Timeable::resume ( )
virtualinherited

Resumes process.

Reimplemented in pq::AbstractChronometer.

◆ setForward()

virtual void pq::AbstractOscillator::setForward ( bool  isForward)
inlinevirtualinherited

Sets the direction of oscillation.

Parameters
isForwardtrue iff the wave is moving forward in time

◆ setTime()

void pq::AbstractOscillator::setTime ( float  time)
virtualinherited

Forces current time (in seconds).

Warning
This function is disabled if randomness() > 0.

Implements pq::Timeable.

◆ start()

void pq::Timeable::start ( )
virtualinherited

Starts/restarts the chronometer.

Reimplemented in pq::AbstractTimer, and pq::Ramp.

◆ step()

void pq::Metronome::step ( )
protectedvirtual

Reimplemented from pq::Unit.

◆ timeToPhase()

float pq::AbstractOscillator::timeToPhase ( float  time) const
virtualinherited

Utility function to convert time to phase.

Parameters
timerelative time in seconds
Returns
the equivalent phase

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