bool32 Run
bool32.rising Reset
bool32 Song is playing
int32 Position in 4 counts per quarter
int32 Position in 24 counts per quarter
frac32.u.map bpm
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) {
PatchMidiInHandler(MIDI_DEVICE_INTERNAL, 0, MIDI_CONTINUE, 0, 0);
} else {
PatchMidiInHandler(MIDI_DEVICE_INTERNAL, 0, MIDI_START, 0, 0);
PatchMidiInHandler(MIDI_DEVICE_INTERNAL, 0, MIDI_TIMING_CLOCK, 0, 0);
}
} else if (!inlet_run && _active) {
_active = 0;
PatchMidiInHandler(MIDI_DEVICE_INTERNAL, 0, MIDI_STOP, 0, 0);
}
if (_active) {
_posfrac += param_bpm;
if (_posfrac & 1 << 31) {
_posfrac &= (1 << 31) - 1;
_pos24ppq++;
PatchMidiInHandler(MIDI_DEVICE_INTERNAL, 0, MIDI_TIMING_CLOCK, 0, 0);
}
}
outlet_pos4ppq = _pos24ppq / 6;
outlet_pos24ppq = _pos24ppq;