matrix set playmodes

sends a note / a velocity when either changes
Author: robert schirmer
License: BSD
Github: rbrt/push/matrix set playmodes.axo

Inlets

bool32.rising redraw

bool32.risingfalling select

bool32.risingfalling mute

int32 pad

Outlets

None

Attributes

objref playmode

objref statemap

objref holdmap

combo blocksize

combo clrMode1

combo clrMode2

combo clrMode3

combo clrHold

combo clrSelect

spinner index

spinner brtOn

spinner brtOff

spinner brtHold

spinner brtSelect

spinner thin

Declaration
uint8_t out[64];
uint8_t preout[64];
uint8_t counter;
uint8_t mcolor[4];
uint8_t mbrt;
bool trig;
uint8_t thin;

// calculate color and brightness
uint8_t getcolor(uint8_t color, uint8_t brightness) {
  uint8_t result;
  uint8_t bness;
  if (color > 1)
    bness = (2 - (brightness));
  else
    bness = brightness;
  result = color + bness;
  return result;
}
Init
mcolor[1] = attr_clrMode1;
mcolor[2] = attr_clrMode2;
mcolor[3] = attr_clrMode3;
Control Rate
if (!inlet_mute) {
  if (inlet_redraw && !trig) {
    trig = 1;
    int i;
    for (i = 0; i < 64; i++)
      preout[i] = 128;
  }
  if (!inlet_redraw)
    trig = 0;

  if (!attr_playmode.array[(counter << attr_blocksize) + attr_index]) {
    if (attr_holdmap.array[counter])
      out[counter] = getcolor(attr_clrHold, attr_brtHold);
    else
      out[counter] = 0;
  } else {
    if (attr_statemap.array[counter])
      mbrt = attr_brtOn;
    else
      mbrt = attr_brtOff;
    out[counter] = getcolor(
        mcolor[attr_playmode.array[(counter << attr_blocksize) + attr_index]],
        mbrt);
  }
  // override the selected pad
  if (inlet_select)
    out[inlet_pad] = getcolor(attr_clrSelect, attr_brtSelect);

  // send output map
  if (!thin) {
    if ((out[counter] != preout[counter]) &&
        !MidiGetOutputBufferPending(MIDI_DEVICE_USB_HOST)) {
      MidiSend3(MIDI_DEVICE_USB_HOST, 2, MIDI_NOTE_ON, counter + 36,
                out[counter]);
      thin = attr_thin;
      preout[counter] = out[counter];
    }
  } else
    thin--;

  counter++;
  counter = counter % 64;
}

Privacy

© 2024 Zrna Research