matrix set colormap

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

Inlets

bool32.rising redraw

bool32.risingfalling select

bool32.risingfalling mute

int32 pad

Outlets

None

Attributes

spinner index

spinner brtOn

spinner brtOff

spinner brtHold

spinner brtSelect

spinner thin

objref colormap

objref statemap

objref holdmap

combo blocksize

combo clrHold

combo clrSelect

Declaration
uint8_t out[64];
uint8_t preout[64];
uint8_t counter;
uint8_t mbrt;
bool trig;
uint8_t thin;
uint8_t map[16] = {0, 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57};

// 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;
}
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;

  // write output map
  if (!attr_colormap.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(
        map[(attr_colormap.array[(counter << attr_blocksize) + attr_index]
             << attr_colormap.GAIN) >>
            23],
        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