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; }
27 BeatBox (int sample_rate);
30 int register_ports (jack_client_t*);
31 int process (int nframes);
33 bool running() const { return _running || _start_requested; }
38 void set_measure_count (int measures);
39 void set_meter (int beats, int beat_type);
40 void set_tempo (float bpm);
42 void set_quantize (int divisor);
44 float tempo() const { return _tempo; }
45 int meter_beats() const { return _meter_beats; }
46 int meter_beat_type() const { return _meter_beat_type; }
49 bool _start_requested;
58 superclock_t superclock_cnt;
59 superclock_t last_start;
62 superclock_t whole_note_superclocks;
63 superclock_t beat_superclocks;
64 superclock_t measure_superclocks;
65 int _quantize_divisor;
67 ARDOUR::MidiStateTracker inbound_tracker;
68 ARDOUR::MidiStateTracker outbound_tracker;
72 superclock_t whole_note_superclocks;
74 unsigned char buf[24];
76 Event () : time (0), size (0) {}
77 Event (jack_nframes_t t, size_t sz, unsigned char* b) : time (t), size (sz) { memcpy (buf, b, std::min (sizeof (buf), sz)); }
78 Event (Event const & other) : time (other.time), size (other.size) { memcpy (buf, other.buf, other.size); }
81 struct EventComparator {
82 bool operator () (Event const * a, Event const * b) const;
85 typedef std::vector<Event*> IncompleteNotes;
86 IncompleteNotes _incomplete_notes;
88 typedef std::set<Event*,EventComparator> Events;
89 Events _current_events;
91 typedef std::vector<Event*> EventPool;
94 void compute_tempo_clocks ();