11 #include <jack/jack.h>
13 #include "ardour/midi_state_tracker.h"
15 typedef uint64_t superclock_t;
17 static const superclock_t superclock_ticks_per_second = 508032000; // 2^10 * 3^4 * 5^3 * 7^2
18 inline superclock_t superclock_to_samples (superclock_t s, int sr) { return (s * sr) / superclock_ticks_per_second; }
19 inline superclock_t samples_to_superclock (int samples, int sr) { return (samples * superclock_ticks_per_second) / sr; }
23 BeatBox (int sample_rate);
26 int register_ports (jack_client_t*);
27 int process (int nframes);
29 bool running() const { return _running || _start_requested; }
34 void set_measure_count (int measures);
35 void set_meter (int beats, int beat_type);
36 void set_tempo (float bpm);
38 void set_quantize (int divisor);
40 float tempo() const { return _tempo; }
41 int meter_beats() const { return _meter_beats; }
42 int meter_beat_type() const { return _meter_beat_type; }
45 bool _start_requested;
54 superclock_t superclock_cnt;
55 superclock_t last_start;
58 superclock_t whole_note_superclocks;
59 superclock_t beat_superclocks;
60 superclock_t measure_superclocks;
61 int _quantize_divisor;
63 ARDOUR::MidiStateTracker inbound_tracker;
64 ARDOUR::MidiStateTracker outbound_tracker;
68 superclock_t whole_note_superclocks;
70 unsigned char buf[24];
72 Event () : time (0), size (0) {}
73 Event (jack_nframes_t t, size_t sz, unsigned char* b) : time (t), size (sz) { memcpy (buf, b, std::min (sizeof (buf), sz)); }
74 Event (Event const & other) : time (other.time), size (other.size) { memcpy (buf, other.buf, other.size); }
77 struct EventComparator {
78 bool operator () (Event const * a, Event const * b) const;
81 typedef std::set<Event*,EventComparator> Events;
82 Events _current_events;
84 typedef std::vector<Event*> EventPool;
87 void compute_tempo_clocks ();