11 #include <jack/jack.h>
13 typedef uint64_t superclock_t;
15 static const superclock_t superclock_ticks_per_second = 508032000; // 2^10 * 3^4 * 5^3 * 7^2
16 inline superclock_t superclock_to_samples (superclock_t s, int sr) { return (s * sr) / superclock_ticks_per_second; }
17 inline superclock_t samples_to_superclock (int samples, int sr) { return (samples * superclock_ticks_per_second) / sr; }
21 BeatBox (int sample_rate);
24 int register_ports (jack_client_t*);
25 int process (int nframes);
27 bool running() const { return _running || _start_requested; }
32 void set_measure_count (int measures);
33 void set_meter (int beats, int beat_type);
34 void set_tempo (float bpm);
36 void set_quantize (int divisor);
38 float tempo() const { return _tempo; }
39 int meter_beats() const { return _meter_beats; }
40 int meter_beat_type() const { return _meter_beat_type; }
43 bool _start_requested;
52 superclock_t superclock_cnt;
53 superclock_t last_start;
56 superclock_t whole_note_superclocks;
57 superclock_t beat_superclocks;
58 superclock_t measure_superclocks;
59 int _quantize_divisor;
64 superclock_t whole_note_superclocks;
66 unsigned char buf[24];
68 Event () : time (0), size (0) {}
69 Event (jack_nframes_t t, size_t sz, unsigned char* b) : time (t), size (sz) { memcpy (buf, b, std::min (sizeof (buf), sz)); }
70 Event (Event const & other) : time (other.time), size (other.size) { memcpy (buf, other.buf, other.size); }
73 struct EventComparator {
74 bool operator () (Event const * a, Event const * b) const;
77 typedef std::set<Event*,EventComparator> Events;
78 Events _current_events;
80 typedef std::vector<Event*> EventPool;
83 void compute_tempo_clocks ();