clock auto

internal midi clock with auto switching. (A mod of the internal factory objects and one of the thru objects) use a dial to set the bpm, trigger the run inlet to start the internal clock. it sends midi out to the outputs if they are turned on. if external midi clock is received the internal clock stops and switches to the external clock, and it thru's the external clock to the outputs. When the external clock stops you can trigger the run inlet to restart the internal clock
Author: Mattilyn Mattroe
License: Three chocolate bourbons per use of code, please
Github: matroe/midi/clock auto.axo

Inlets

bool32.rising starts/stops internal clock

bool32.rising Reset

frac32.positive speed and that, yeah bruv?

Outlets

bool32 Song is playing

bool32 external

bool32 internal

Parameters

bool32.tgl onA

bool32.tgl onB

bool32.tgl onC

bool32.tgl onD

Attributes

combo Aoutput

combo Boutput

combo Coutput

combo Doutput

Declaration
bool internal;
int32_t _posfrac;
int32_t _pos24ppq;
bool rstp;
int external;
int rtrig;
int run;

int paramon;
int paramonB;
int paramonC;
int paramonD;
Init
internal = 0;
_posfrac = 0;
_pos24ppq = 0;
rstp = 0;
run = 0;
Control Rate
paramon = param_onA;
paramonB = param_onB;
paramonC = param_onC;
paramonD = param_onD;

if (inlet_rst & !rstp) {
  rstp = 1;
  _posfrac = 0;
  _pos24ppq = 0;
} else if (!inlet_rst) {
  rstp = 0;
}

if (!external) {
  if (inlet_run && !rtrig) {
    rtrig = 1;
    run = !run;

  } else if (!inlet_run) {
    rtrig = 0;
  }
  if (run && !internal) {
    internal = 1;
    if (_pos24ppq) {
      PatchMidiInHandler(MIDI_DEVICE_INTERNAL, 0, MIDI_START, 0, 0);
    } else {
      PatchMidiInHandler(MIDI_DEVICE_INTERNAL, 0, MIDI_CONTINUE, 0, 0);
    }
  } else if (!run && internal) {
    internal = 0;
    PatchMidiInHandler(MIDI_DEVICE_INTERNAL, 0, MIDI_STOP, 0, 0);
  }
  if (internal) {
    _posfrac += inlet_bpm;
    if (_posfrac & 1 << 31) {
      _posfrac &= (1 << 31) - 1;
      _pos24ppq++;
      PatchMidiInHandler(MIDI_DEVICE_INTERNAL, 0, MIDI_TIMING_CLOCK, 0, 0);
    }
  }
}

outlet_external = external;
outlet_internal = internal;
outlet_active = external || internal;
Midi Handler
if ((dev == MIDI_DEVICE_INTERNAL) && (status == MIDI_START)) {

  external = 0;
}
if ((dev != MIDI_DEVICE_INTERNAL) && (status == MIDI_START)) {
  external = 1;
  internal = 0;
  run = 0;
}

if ((dev != MIDI_DEVICE_INTERNAL) && (status == MIDI_STOP)) {
  external = 0;
}

if ((status == MIDI_TIMING_CLOCK) || (status == MIDI_START) ||
    (status == MIDI_CONTINUE) || (status == MIDI_STOP)) {
  if (paramon) {
    MidiSend1((midi_device_t)attr_Aoutput, status);
  }
  if (paramonB) {
    MidiSend1((midi_device_t)attr_Boutput, status);
  }
  if (paramonC) {
    MidiSend1((midi_device_t)attr_Coutput, status);
  }
  if (paramonD) {
    MidiSend1((midi_device_t)attr_Doutput, status);
  }
}

Privacy

© 2024 Zrna Research