#ifndef METRONOME_H #define METRONOME_H #include #include #include class Metronome { // Private Constructor Metronome(); Metronome(Metronome const& copy) = delete; Metronome& operator=(Metronome const& copy) = delete; public: static Metronome& manager () { // The only instance static Metronome _instance; return _instance; } bool init (); void terminate (); void setEnabled (bool on); bool enabled () const; void setTempo (double t); double tempo () const; void setQuantum (double q); double quantum () const; void setStartStopSync (bool on); bool startStopSync () const; void restart(); // get beat and phase double beats () const; double phase () const; // mechanisms to delay execution to next beat of phase std::chrono::microseconds timeToBeat(); void executeAtBeat( std::function f ); size_t peers () const; }; /// Example calls to executeAtBeat /// /// With a Lamda function calling a member function of an object /// - without parameter /// Metronome::manager().executeAtBeat( std::bind([](MediaPlayer *p) { p->rewind(); }, mediaplayer_) ); /// /// - with parameter /// Metronome::manager().executeAtBeat( std::bind([](MediaPlayer *p, bool o) { p->play(o); }, mediaplayer_, on) ); /// #endif // METRONOME_H