clock

Midi clock master, als outputs Midi clock, start, stop, and continue messages. Sends to midi/in/* objects only.
Author: Johannes Taelman
License: BSD
Github: midi/intern/clock.axo

Inlets

bool32 Run

bool32.rising Reset

Outlets

bool32 Song is playing

int32 Position in 4 counts per quarter

int32 Position in 24 counts per quarter

Parameters

frac32.u.map bpm

Declaration
bool _active;
int32_t _posfrac;
int32_t _pos24ppq;
bool rstp;
Init
_active = 0;
_posfrac = 0;
_pos24ppq = 0;
rstp = 0;
Control Rate
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;

Privacy

© 2024 Zrna Research