clock

Midi clock master, als outputs Midi clock, start, stop, and continue messages
Author: Johannes Taelman
License: BSD
Github: midi/out/clock.axo

Inlets

bool32.rising Reset

bool32 Run

Outlets

bool32 Song is playing

int32 Position in 4 counts per quarter

int32 Position in 24 counts per quarter

Parameters

frac32.u.map bpm

Attributes

combo device

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) {
    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;

Privacy

© 2024 Zrna Research