sclMIDICtrl

Key, scale, temperament and stretch controller Responds to external midi commands: key: cc87 scale: cc88 temperament: cc89 stretch: cc90 value==1 -> next key/scale/temperament or higher stretch value==127 -> former key/scale/temperament or lower stretch default value should be "0". press the "former" key button for a longer time (+- a second) to reset the parameters to zero.
Author: Remco van der Most
License: BSD
Github: sss/harmony/sclMIDICtrl.axo

Inlets

None

Outlets

int32 key

int32 scale

int32 temper

frac32 stretch

Displays

int32.label key

int32.label scale

int32.label temperament

frac32.s.dial stretch

Declaration
int scale;
int key;
int temper;
int32_t stretch;
uint32_t cnt;
bool DO;
Init
key = 0;
scale = 0;
temper = 0;
stretch = 0;
Control Rate
outlet_key = key;
outlet_scale = scale;
outlet_temper = temper;
outlet_stretch = stretch;
disp_key = key;
disp_scale = scale;
disp_temperament = temper;
disp_stretch = stretch;

if (DO > 0) {
  cnt += 1;
  if (cnt > 2000) {
    key = 0;
    scale = 0;
    temper = 0;
    stretch = 0;
  }
} else {
  cnt = 0;
}
Midi Handler
if ((status == 15 + MIDI_CONTROL_CHANGE) && (data1 == 87)) {
  if (data2 == 127) {
    key += 5;
    key = key - key / 12 * 12;
  }
  if (data2 == 1) {
    DO = 1;

    key += 7;
    key = key - key / 12 * 12;
  }
  if (data2 == 0) {
    DO = 0;
  }
}
if ((status == 15 + MIDI_CONTROL_CHANGE) && (data1 == 88)) {
  if (data2 == 127) {
    scale += 1;
    scale = scale - scale / 46 * 46;
  }
  if (data2 == 1) {
    scale += 45;
    scale = scale - scale / 46 * 46;
  }
}
if ((status == 15 + MIDI_CONTROL_CHANGE) && (data1 == 89)) {
  if (data2 == 127) {
    temper += 1;
    temper = temper - temper / 137 * 137;
  }
  if (data2 == 1) {
    temper += 136;
    temper = temper - temper / 137 * 137;
  }
}
if ((status == 15 + MIDI_CONTROL_CHANGE) && (data1 == 90)) {
  if (data2 == 127) {
    stretch += 1 << 20;
    stretch = __SSAT(stretch, 27);
  }
  if (data2 == 1) {
    stretch -= 1 << 20;
    stretch = __SSAT(stretch, 27);
  }
}

Privacy

© 2024 Zrna Research