pianoDecoder

Decodes the polyphonic "pianobar" sequencer and sends the data as midi internally or externally. Each velocity-step can be set to it's own velocity and midi-channel. Useful to write three polyphonic melody lines in a single sequencer, mixable/automatable using the three velocity inputs.
Author: Remco van der Most
License: BSD
Github: sss/seq/pianoDecoder.axo

Inlets

frac32buffer notes

bool32 clock

frac32 vel1

frac32 vel2

frac32 vel3

Outlets

None

Parameters

int32 channel1

int32 channel2

int32 channel3

int32 lownote

frac32.u.map vel1

frac32.u.map vel2

frac32.u.map vel3

Attributes

spinner channel

combo device

Declaration
int i;
int32_t prv[72];
int32_t gate[72];
bool trg[72], clk;
int32_t vel[4];
int32_t channel[4];
Init
for (i = 0; i < 72; i++) {
  gate[i] = 0;
  prv[i] = 0;
}

channel[0] = 0;
vel[0] = 0;
Control Rate
vel[1] = __USAT(param_vel1 + inlet_vel1, 27);
vel[2] = __USAT(param_vel2 + inlet_vel2, 27);
vel[3] = __USAT(param_vel3 + inlet_vel3, 27);

channel[1] = param_channel1 - 1;
channel[2] = param_channel2 - 1;
channel[3] = param_channel3 - 1;

if ((inlet_clock > 0) && !clk) {
  clk = 1;

  for (i = 0; i < 6; i++) {
    int k = i * 12;
    for (int j = 0; j < 12; j++) {
      gate[k + j] = (inlet_notes[j] >> (i << 1)) & 1;
      gate[k + j] += ((inlet_notes[j] >> ((i << 1) + 1)) & 1) << 1;
    }
  }

  for (i = 0; i < 72; i++) {
    if (!(prv[i] == gate[i])) {
      int tg = gate[i];
      int tp = prv[i];
      int lastnote = i + param_lownote;
      if (tg > 0) {
        MidiSend3((midi_device_t)attr_device, MIDI_NOTE_ON + channel[tg],
                  lastnote, vel[tg] >> 20);
      } else if (tg < 1) {
        MidiSend3((midi_device_t)attr_device, MIDI_NOTE_OFF + channel[tp],
                  lastnote, vel[tp] >> 20);
      }
      prv[i] = gate[i];
    }
  }
} else if (inlet_clock < 1) {
  clk = 0;
}

Privacy

© 2024 Zrna Research