31 : tick_rate_hz_(tick_rate_hz)
41 ticks_per_bar_ = (
static_cast<uint32_t
>(tick_rate_hz_) * 60 * beats_per_bar_) / bpm_;
42 ticks_per_beat_ = ticks_per_bar_ / beats_per_bar_;
43 gate_off_tick_ = (ticks_per_bar_ * gate_percent_) / 100;
48 if (percent > 100) percent = 100;
49 gate_percent_ = percent;
50 gate_off_tick_ = (ticks_per_bar_ * gate_percent_) / 100;
55 if (++tick_ >= ticks_per_bar_) {
64 return ticks_per_beat_ > 0 && (tick_ % ticks_per_beat_) == 0;
74 uint16_t
bpm()
const {
return bpm_; }
75 uint32_t
tick()
const {
return tick_; }
81 uint16_t tick_rate_hz_;
82 uint8_t beats_per_bar_;
83 uint8_t gate_percent_ = 75;
86 uint32_t ticks_per_bar_ = 0;
87 uint32_t ticks_per_beat_ = 0;
88 uint32_t gate_off_tick_ = 0;
bool at_gate_off() const
True at the gate-off point within the bar.
void reset()
Reset tick counter to start of bar.
BeatClock(uint16_t tick_rate_hz, uint8_t beats_per_bar=4)
Construct with tick rate (Hz) and time signature.
void set_gate_percent(uint8_t percent)
Set gate duration as percentage of bar (0-100). Default 75%.
uint8_t beats_per_bar() const
bool advance()
Advance one tick. Returns true on bar boundary (tick wraps to 0).
uint32_t ticks_per_bar() const
bool at_beat() const
True when current tick is on a beat boundary.
void set_bpm(uint16_t bpm)
Set tempo. Recalculates all derived tick counts.
uint32_t ticks_per_beat() const
Root namespace for all Sound Byte Libs functionality.