bool32.rising Reset
bool32 Run
bool32 Song is playing
int32 Position in 4 counts per quarter
int32 Position in 24 counts per quarter
frac32.u.map bpm
combo device
bool _active;
int32_t _posfrac;
int32_t _pos24ppq;
bool rstp;
_active = 0;
_posfrac = 0;
_pos24ppq = 0;
rstp = 0;
if (inlet_rst & !rstp) {
rstp = 1;
_posfrac = 0;
_pos24ppq = 0;
} else if (!inlet_rst) {
rstp = 0;
}
if (inlet_run && !_active) {
_active = 1;
if (_pos24ppq) {
MidiSend1((midi_device_t)attr_device, MIDI_CONTINUE);
} else {
MidiSend1((midi_device_t)attr_device, MIDI_START);
MidiSend1((midi_device_t)attr_device, MIDI_TIMING_CLOCK);
}
} else if (!inlet_run && _active) {
_active = 0;
MidiSend1((midi_device_t)attr_device, MIDI_STOP);
}
if (_active) {
_posfrac += param_bpm;
if (_posfrac & 1 << 31) {
_posfrac &= (1 << 31) - 1;
_pos24ppq++;
MidiSend1((midi_device_t)attr_device, MIDI_TIMING_CLOCK);
}
}
outlet_pos4ppq = _pos24ppq / 6;
outlet_pos24ppq = _pos24ppq;
outlet_active = _active;