clock

Midi clock slave -also outputs a 4ppq and 24ppq clock -time output gives the sample-time for a 4ppq clock.
Author: Johannes Taelman
License: BSD
Github: sss/midi/clock.axo

Inlets

None

Outlets

bool32 Song is playing

bool32 trig4ppq

bool32 trig24ppq

int32 Position in 4 counts per quarter

int32 Position in 24 counts per quarter

int32 time

frac32 baserate

Declaration
int32_t _active;
int32_t _pos;
int32_t _pos_shadow;
int trg4;
int trg24;
int count;
int32_t cnt;
int32_t TIME;
int32_t val1;
int32_t val2;
int32_t Time;
Init
_active = 0;
_pos = 0;
_pos_shadow = 0;
Control Rate
outlet_active = _active;
outlet_pos4ppq = _pos / 6;
outlet_pos24ppq = _pos;
outlet_trig4ppq = trg4;
outlet_trig24ppq = trg24;
trg24 = 0;
trg4 = 0;

val1 += ((TIME << 8) - val1) >> 8;
val2 += (val1 - val2) >> 8;
if ((val2 > Time + 2000) || (val2 < Time - 2000)) {
  Time = val2;
}
outlet_time = TIME;
outlet_baserate = (int32_t)((float32_t)(1 << 29) / Time) << 12;
Audio Rate
cnt += 1;
Midi Handler
if (status == MIDI_TIMING_CLOCK) {
  _pos_shadow++;
  _pos = _pos_shadow;
  count += 1;
  count = count - count / 6 * 6;

  if (count == 0) {
    trg4 = 1;
    TIME = cnt;
    cnt = 0;
  }
  trg24 = 1;
} else if (status == MIDI_START) {
  _active = 1;
  _pos = 0;
  _pos_shadow = -1;
} else if (status == MIDI_STOP) {
  _active = 0;
  _pos = -1;
} else if (status == MIDI_CONTINUE) {
  _active = 1;
} else if (status == MIDI_SONG_POSITION) {
  _pos_shadow = 6 * ((data2 << 7) + data1) - 1;
}

Privacy

© 2024 Zrna Research