note play

Plays midi notes. for use with the midi looper objects.
Author: Mattilyn Mattroe
License: you may never, ever use this. or else. otherwise, do as you will
Github: matroe/midi looper/note play.axo

Inlets

bool32 on

bool32 clear

int32 polyphony

int32 sets an offset for writing to the table

int32 stepunQ

int32 erasenote

Outlets

None

Attributes

objref table

combo buffer

spinner bar

spinner voices

spinner channel

Declaration
int on;
int outon;
int budd;
int ontrig;
int TlastnoteA;
int seqlengthUNQ;
int voiceoffset;
int offtrig;
int offsetunQ1;
int noteonA;
int noteoffA;
int noteA;
int holdvelA;
int TvelA;
int prevstepunQ;
Init
noteonA = 0;
seqlengthUNQ = ((attr_bar << 9) - ((attr_bar << 9) >> 2));

voiceoffset = (seqlengthUNQ + seqlengthUNQ + seqlengthUNQ);
budd = ((seqlengthUNQ + seqlengthUNQ + seqlengthUNQ) * attr_voices);
Control Rate
on = inlet_on;
// send note off if stopped/cleared to stop hanging notes
if (((inlet_clear && !offtrig)) || ((!on) && (ontrig))) {
  if (inlet_polyphony == 0) {
    MidiSend3((midi_device_t)attr_buffer,
              MIDI_CONTROL_CHANGE + (attr_channel - 1), MIDI_C_ALL_NOTES_OFF,
              127);
  }
  ontrig = 0;
  offtrig = 1;
}

else if (!inlet_clear) {
  offtrig = 0;
}

// position on table
offsetunQ1 = (inlet_offset + inlet_stepunQ) + ((voiceoffset)*inlet_polyphony);

// note/noteon/noteoff data... noteonA is also velocity
if (inlet_erasenote > 0) {
  if ((attr_table.array[(offsetunQ1)]) == inlet_erasenote) {
    attr_table.array[(offsetunQ1)] = 0;
  }
}
noteA = attr_table.array[(offsetunQ1)];
noteonA = attr_table.array[(offsetunQ1 + seqlengthUNQ)];
noteoffA = attr_table.array[(offsetunQ1 + seqlengthUNQ + seqlengthUNQ)];

// playback
if (on) {
  ontrig = 1;
  if (inlet_stepunQ != prevstepunQ) {

    if (noteonA > 0) {
      holdvelA = noteonA;
      TvelA = holdvelA;
      MidiSend3((midi_device_t)attr_buffer, MIDI_NOTE_ON + (attr_channel - 1),
                noteA, noteonA);
      TlastnoteA = noteA;
      outon = 1;
    }

    if (noteoffA > 0) {
      MidiSend3((midi_device_t)attr_buffer, MIDI_NOTE_OFF + (attr_channel - 1),
                noteA, TvelA);
      outon = 0;
    }

    prevstepunQ = inlet_stepunQ;
  }
}

Privacy

© 2024 Zrna Research