int32 note
bool32.rising trigger
bool32 mute
int32 note
int32 velo
bool32.pulse noteOn
bool32.pulse noteOff
bool32 gate
objref busymap
objref trigger
spinner startNote
spinner endNote
spinner channel
spinner noteshift
bool trigon;
bool trigoff;
int8_t empty;
int8_t ton;
int8_t toff;
bool trig;
uint8_t _note;
uint8_t count;
uint8_t _velo;
ton = -1;
toff = -1;
if (inlet_trigger && !trig) {
trig = 1;
trigon = 1;
_note = inlet_note;
}
if (!inlet_trigger)
trig = 0;
outlet_noteOn = trigon;
outlet_noteOff = trigoff;
outlet_note = _note;
outlet_velo = _velo;
outlet_gate = bool(count);
if (!inlet_mute) {
if (trigon) {
ton = -1;
int i;
for (i = 0; i < attr_busymap.LENGTH; i++)
if (attr_busymap.array[i] == _note)
ton = i;
if (ton < 0) {
for (i = 0; i < attr_busymap.LENGTH; i++)
if (!attr_busymap.array[i])
ton = i;
}
if (ton > -1) {
attr_trigger.array[ton] = 2;
attr_busymap.array[ton] = _note;
}
}
}
if (trigoff) {
toff = -1;
int i;
for (i = 0; i < attr_busymap.LENGTH; i++)
if (attr_busymap.array[i] == _note)
toff = i;
if (toff > -1)
attr_trigger.array[toff] = 1;
}
trigon = 0;
trigoff = 0;
if ((status == MIDI_NOTE_ON + (attr_channel - 1)) && (data2)) {
if ((data1 >= attr_startNote) && (data1 <= attr_endNote)) {
trigon = 1;
count += 1;
if ((data1 + attr_noteshift) > -1)
_note = (data1 + attr_noteshift);
_velo = data2;
}
}
if (((status == MIDI_NOTE_ON + (attr_channel - 1)) && (!data2)) ||
(status == MIDI_NOTE_OFF + (attr_channel - 1))) {
if ((data1 >= attr_startNote) && (data1 <= attr_endNote)) {
if (count)
count -= 1;
if ((data1 + attr_noteshift) > -1)
_note = (data1 + attr_noteshift);
trigoff = 1;
_velo = 0;
}
} else if ((status == (attr_channel - 1) + MIDI_CONTROL_CHANGE) &&
(data1 == MIDI_C_ALL_NOTES_OFF)) {
count = 0;
}