Yet Another Synthesizer Engine
 
Loading...
Searching...
No Matches
yase::Timer Class Reference

#include <timer.hh>

+ Inheritance diagram for yase::Timer:
+ Collaboration diagram for yase::Timer:

Detailed Description

A timer that can be used to do something one or more times in the future.

For example, the following prints "Time's up!" every second.

Timer timer;
Container container;
container.add(timer)
timer.set(1, [&]() {
std::cout << "Time's up!";
timer.reset();
});
A module and event manager that can contain other modules.
Definition container.hh:63
Container & add(Module &module)
Definition container.cc:62
A timer that can be used to do something one or more times in the future.
Definition timer.hh:42
void set(float t, function< void()> f)
Definition timer.cc:35
void reset()
Definition timer.cc:44

This module has no inputs or outputs

Public Member Functions

void set (float t, function< void()> f)
 
void reset ()
 
void reset (float t)
 
void init ()
 
void update ()
 
- Public Member Functions inherited from yase::Module
virtual void init ()=0
 
virtual void update ()=0
 
int add_input (string name)
 
int add_output (string name)
 
int get_input_index (string name) const
 
string get_input_name (int index) const
 
string get_output_name (int index) const
 
int get_output_index (string name) const
 
void set_input (string name, double value)
 
void set_input (int index, double value)
 
double get_input (int index) const
 
double get_input (string name) const
 
double get_output (string name) const
 
double get_output (int index) const
 
void set_output (int index, double value)
 
void copy_inputs (const Module &source)
 
void copy_outputs (Module &destination) const
 
void configure (std::vector< std::tuple< string, double > > assignments)
 
int num_inputs () const
 
int num_outputs () const
 
void emit (Event e)
 
void set_ts (double s)
 
double get_ts ()
 

Member Function Documentation

◆ init()

void yase::Timer::init ( )
virtual

This method should be overridden by derived classes. It will usually be called once, after all modules and connections objects have been added to a synthesizer, but before the synthesizer starts running.

Implements yase::Module.

◆ reset()

void yase::Timer::reset ( )

Reset the timer. Calling set on a timer only triggers its method once. If you want it to trigger again (with the same associated method) cal reset.

◆ set()

void yase::Timer::set ( float  t,
function< void()>  f 
)

Set the duration of a timer and define what to do when the time is up.

Parameters
tThe duration, in seconds
fA method, for example expressed as a lambda

◆ update()

void yase::Timer::update ( )
virtual

This method should be overridden by derived classes. It will be called repeatedly by a synthesizer at a frequency determined by SAMPLE_RATE.

Implements yase::Module.


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