korgKP3control

Dedicated Korg Kaosspad 3 external midi controller object -program change inputs for selecting FX (better only do this while gate is low and not at the beginning when the gate goes high) -gate/X/Y/fx-depth midi control (with midi message thinning, also only sends when gate is high) -selectable clock source (pin input, external midi or off) -trigger inputs for sample A to D
Author: Remco van der Most
License: BSD
Github: sss/midi/korgKP3control.axo

Inlets

int32.positive prgram number (0-127)

bool32.rising trigger

bool32.rising clock

frac32.positive X

frac32.positive Y

frac32.positive fxdepth

bool32.risingfalling gate

bool32.risingfalling active

bool32 sampleA

bool32 sampleB

bool32 sampleC

bool32 sampleD

Outlets

None

Attributes

combo device

combo clock

combo range

spinner channel

Declaration
int ntrig, _active, ctrig, mtrig, sa, sb, sc, sd;
int32_t D, X, Y;
int cnt[3];
Control Rate
if ((inlet_trig > 0) && !ntrig) {
  MidiSend2((midi_device_t)attr_device,
            MIDI_PROGRAM_CHANGE + (attr_channel - 1),
            (inlet_pgm & 0x7F) % (attr_range > 0 ? 0x7F : 97));
  ntrig = 1;
} else if (!(inlet_trig > 0)) {
  ntrig = 0;
}

if (attr_clock < 1) {
  if (inlet_active) {
    if (inlet_clock && !ctrig) {
      MidiSend1((midi_device_t)attr_device, MIDI_TIMING_CLOCK);
      ctrig = 1;
    } else if (!inlet_clock) {
      ctrig = 0;
    }
    if (!_active) {
      _active = 1;
      MidiSend1((midi_device_t)attr_device, MIDI_START);
    }
  } else if (!inlet_active && _active) {
    _active = 0;
    MidiSend1((midi_device_t)attr_device, MIDI_STOP);
  }
}

if ((inlet_gate > 0) && !mtrig) {
  MidiSend3((midi_device_t)attr_device,
            MIDI_CONTROL_CHANGE + (attr_channel - 1), 92, 127);
  mtrig = 1;
}
if ((!inlet_gate) && mtrig) {
  mtrig = 0;
  MidiSend3((midi_device_t)attr_device,
            MIDI_CONTROL_CHANGE + (attr_channel - 1), 92, 0);
}

int x, y, d;
x = __USAT(inlet_X >> 20, 7);
y = __USAT(inlet_Y >> 20, 7);
d = __USAT(inlet_fxdepth >> 20, 7);
if (inlet_gate > 0) {
  if (!(x == X)) {
    if (cnt[0] > 30) {
      MidiSend3((midi_device_t)attr_device,
                MIDI_CONTROL_CHANGE + (attr_channel - 1), 12, x);
      cnt[0] = 0;
    }
  }
  if (!(y == Y)) {
    if (cnt[1] > 30) {
      MidiSend3((midi_device_t)attr_device,
                MIDI_CONTROL_CHANGE + (attr_channel - 1), 13, y);
      cnt[1] = 0;
    }
  }
  if (!(d == D)) {
    if (cnt[2] > 30) {
      MidiSend3((midi_device_t)attr_device,
                MIDI_CONTROL_CHANGE + (attr_channel - 1), 94, d);
      cnt[2] = 0;
    }
  }
}

if (inlet_sampleA && !sa) {
  sa = 1;
  MidiSend3((midi_device_t)attr_device, MIDI_NOTE_ON + (attr_channel - 1), 36,
            127);
} else if ((!inlet_sampleA) && sa) {
  sa = 0;
  MidiSend3((midi_device_t)attr_device, MIDI_NOTE_OFF + (attr_channel - 1), 36,
            0);
}

if (inlet_sampleB && !sb) {
  sb = 1;
  MidiSend3((midi_device_t)attr_device, MIDI_NOTE_ON + (attr_channel - 1), 37,
            127);
} else if ((!inlet_sampleB) && sb) {
  sb = 0;
  MidiSend3((midi_device_t)attr_device, MIDI_NOTE_OFF + (attr_channel - 1), 37,
            0);
}

if (inlet_sampleC && !sc) {
  sc = 1;
  MidiSend3((midi_device_t)attr_device, MIDI_NOTE_ON + (attr_channel - 1), 38,
            127);
} else if ((!inlet_sampleC) && sc) {
  sc = 0;
  MidiSend3((midi_device_t)attr_device, MIDI_NOTE_OFF + (attr_channel - 1), 38,
            0);
}

if (inlet_sampleD && !sd) {
  sd = 1;
  MidiSend3((midi_device_t)attr_device, MIDI_NOTE_ON + (attr_channel - 1), 39,
            127);
} else if ((!inlet_sampleD) && sd) {
  sd = 0;
  MidiSend3((midi_device_t)attr_device, MIDI_NOTE_OFF + (attr_channel - 1), 39,
            0);
}

for (int i = 0; i < 3; i++) {
  if (cnt[i] < 800) {
    cnt[i] += 1;
  }
}

X = x;
Y = y;
D = d;
Midi Handler
if (attr_clock == 1) {
  if (status == MIDI_TIMING_CLOCK) {
    MidiSend1((midi_device_t)attr_device, MIDI_TIMING_CLOCK);
  } else if (status == MIDI_START) {
    _active = 1;
    MidiSend1((midi_device_t)attr_device, MIDI_START);
  } else if (status == MIDI_STOP) {
    _active = 0;
    MidiSend1((midi_device_t)attr_device, MIDI_STOP);
  } else if (status == MIDI_CONTINUE) {
    _active = 1;
    MidiSend1((midi_device_t)attr_device, MIDI_CONTINUE);
  }
}

Privacy

© 2024 Zrna Research