clock out dual

Midi clock master, also outputs Midi clock, start, stop, and continue messages on two separate Midi devices. The secondary device can be switched on or off (when off, the behavior is identical to the midi/out/clock by Johannes. Based on midi/out/clock by Johannes Taelman.
Author: Sputnki
License: BSD
Github: sptnk/sequencer/clock out dual.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

bool32.tgl secondary

frac32.u.map bpm

Attributes

combo device

combo secondary

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);
    if (param_secondary)
      MidiSend1((midi_device_t)attr_secondary, MIDI_CONTINUE);
  } else {
    MidiSend1((midi_device_t)attr_device, MIDI_START);
    if (param_secondary)
      MidiSend1((midi_device_t)attr_secondary, MIDI_START);
  }
} else if (!inlet_run && _active) {
  _active = 0;
  MidiSend1((midi_device_t)attr_device, MIDI_STOP);
  if (param_secondary)
    MidiSend1((midi_device_t)attr_secondary, 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);
    if (param_secondary)
      MidiSend1((midi_device_t)attr_secondary, MIDI_TIMING_CLOCK);
  }
}
outlet_pos4ppq = _pos24ppq / 6;
outlet_pos24ppq = _pos24ppq;

Privacy

© 2024 Zrna Research