mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 02:40:00 +01:00
New Timer window in UI for Metronome (Ableton Link management) and replaces Timers. Former Timers in Metrics are replaced with Runtime (of session, of program and of total vimix runtime in settings). Temporarily disconnected Metronome from MediaPlayer actions.
64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
#ifndef METRONOME_H
|
|
#define METRONOME_H
|
|
|
|
#include <chrono>
|
|
#include <thread>
|
|
#include <functional>
|
|
|
|
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<void()> 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
|