2017-08-04 17:19:36 -04:00
|
|
|
#ifndef __bb_h__
|
|
|
|
#define __bb_h__
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <jack/jack.h>
|
|
|
|
|
2017-08-05 02:03:43 -04:00
|
|
|
#include "ardour/midi_state_tracker.h"
|
|
|
|
|
2017-08-04 17:19:36 -04:00
|
|
|
typedef uint64_t superclock_t;
|
|
|
|
|
2017-08-04 17:40:35 -04:00
|
|
|
static const superclock_t superclock_ticks_per_second = 508032000; // 2^10 * 3^4 * 5^3 * 7^2
|
2017-08-04 17:19:36 -04:00
|
|
|
inline superclock_t superclock_to_samples (superclock_t s, int sr) { return (s * sr) / superclock_ticks_per_second; }
|
|
|
|
inline superclock_t samples_to_superclock (int samples, int sr) { return (samples * superclock_ticks_per_second) / sr; }
|
|
|
|
|
2017-08-18 12:17:46 -04:00
|
|
|
namespace ARDOUR {
|
|
|
|
class Session;
|
|
|
|
}
|
|
|
|
|
2017-08-04 17:19:36 -04:00
|
|
|
class BeatBox {
|
|
|
|
public:
|
|
|
|
BeatBox (int sample_rate);
|
|
|
|
~BeatBox ();
|
|
|
|
|
|
|
|
int register_ports (jack_client_t*);
|
|
|
|
int process (int nframes);
|
|
|
|
|
|
|
|
bool running() const { return _running || _start_requested; }
|
|
|
|
void start ();
|
|
|
|
void stop ();
|
|
|
|
void clear ();
|
|
|
|
|
|
|
|
void set_measure_count (int measures);
|
|
|
|
void set_meter (int beats, int beat_type);
|
|
|
|
void set_tempo (float bpm);
|
|
|
|
|
|
|
|
void set_quantize (int divisor);
|
|
|
|
|
2017-08-04 17:40:55 -04:00
|
|
|
float tempo() const { return _tempo; }
|
|
|
|
int meter_beats() const { return _meter_beats; }
|
|
|
|
int meter_beat_type() const { return _meter_beat_type; }
|
|
|
|
|
2017-08-04 17:19:36 -04:00
|
|
|
private:
|
|
|
|
bool _start_requested;
|
|
|
|
bool _running;
|
|
|
|
int _measures;
|
|
|
|
float _tempo;
|
2017-08-04 18:09:31 -04:00
|
|
|
float _tempo_request;
|
2017-08-04 17:19:36 -04:00
|
|
|
int _meter_beats;
|
|
|
|
int _meter_beat_type;
|
|
|
|
jack_port_t* _input;
|
|
|
|
jack_port_t* _output;
|
|
|
|
superclock_t superclock_cnt;
|
|
|
|
superclock_t last_start;
|
|
|
|
|
|
|
|
int _sample_rate;
|
|
|
|
superclock_t whole_note_superclocks;
|
|
|
|
superclock_t beat_superclocks;
|
|
|
|
superclock_t measure_superclocks;
|
|
|
|
int _quantize_divisor;
|
|
|
|
bool clear_pending;
|
2022-02-01 18:20:28 -05:00
|
|
|
ARDOUR::MidiNoteTracker inbound_tracker;
|
|
|
|
ARDOUR::MidiNoteTracker outbound_tracker;
|
2017-08-04 17:19:36 -04:00
|
|
|
|
|
|
|
struct Event {
|
|
|
|
superclock_t time;
|
2017-08-04 18:09:31 -04:00
|
|
|
superclock_t whole_note_superclocks;
|
2017-08-04 17:19:36 -04:00
|
|
|
size_t size;
|
|
|
|
unsigned char buf[24];
|
|
|
|
|
|
|
|
Event () : time (0), size (0) {}
|
|
|
|
Event (jack_nframes_t t, size_t sz, unsigned char* b) : time (t), size (sz) { memcpy (buf, b, std::min (sizeof (buf), sz)); }
|
|
|
|
Event (Event const & other) : time (other.time), size (other.size) { memcpy (buf, other.buf, other.size); }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EventComparator {
|
|
|
|
bool operator () (Event const * a, Event const * b) const;
|
|
|
|
};
|
|
|
|
|
2017-08-18 12:17:46 -04:00
|
|
|
typedef std::vector<Event*> IncompleteNotes;
|
|
|
|
IncompleteNotes _incomplete_notes;
|
|
|
|
|
2017-08-04 17:19:36 -04:00
|
|
|
typedef std::set<Event*,EventComparator> Events;
|
|
|
|
Events _current_events;
|
|
|
|
|
|
|
|
typedef std::vector<Event*> EventPool;
|
|
|
|
EventPool event_pool;
|
2017-08-04 18:09:31 -04:00
|
|
|
|
|
|
|
void compute_tempo_clocks ();
|
2017-08-04 17:19:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* __bb_h__ */
|