notechannel

Monophonic MIDI keyboard note input, gate, velocity and release velocity modulation source
Author: Johannes Taelman
License: BSD
Github: sss/midi/notechannel.axo

Inlets

None

Outlets

frac32.bipolar midi note number (-64..63)

bool32 key pressed, no retrigger legato

bool32 key pressed, retrigger on legato

frac32.positive note-on velocity

frac32.positive note-off velocity

Parameters

int32 midichannel

Declaration
int8_t _note;
int32_t _gate;
int32_t _gate2;
uint8_t _velo;
uint8_t _rvelo;
int midichannel;
Init
_gate = 0;
_note = 0;
Control Rate
outlet_note = _note << 21;
outlet_gate = _gate;
outlet_gate2 = _gate2;
_gate2 = _gate;
outlet_velocity = _velo << 20;
outlet_releaseVelocity = _rvelo << 20;
midichannel = param_midichannel;
Midi Handler
if ((status == MIDI_NOTE_ON + midichannel - 1) && (data2)) {
  _velo = data2;
  _note = data1 - 64;
  _gate = 1 << 27;
  _gate2 = 0;
  PExModulationSourceChange(
      &parent->GetModulationTable()[parent->MODULATOR_attr_name_velocity *
                                    NMODULATIONTARGETS],
      NMODULATIONTARGETS, &parent->PExch[0],
      &parent->PExModulationPrevVal[parent->polyIndex]
                                   [parent->MODULATOR_attr_name_velocity],
      _velo << 20);
  PExModulationSourceChange(
      &parent->GetModulationTable()[parent->MODULATOR_attr_name_note *
                                    NMODULATIONTARGETS],
      NMODULATIONTARGETS, &parent->PExch[0],
      &parent->PExModulationPrevVal[parent->polyIndex]
                                   [parent->MODULATOR_attr_name_note],
      _note << 21);
} else if (((status == MIDI_NOTE_ON + midichannel - 1) && (!data2)) ||
           (status == MIDI_NOTE_OFF + midichannel - 1)) {
  if (_note == data1 - 64) {
    _rvelo = data2;
    _gate = 0;
    PExModulationSourceChange(
        &parent->GetModulationTable()
             [parent->MODULATOR_attr_name_releasevelocity * NMODULATIONTARGETS],
        NMODULATIONTARGETS, &parent->PExch[0],
        &parent->PExModulationPrevVal
             [parent->polyIndex][parent->MODULATOR_attr_name_releasevelocity],
        _rvelo << 20);
  }
} else if ((status == midichannel - 1 + MIDI_CONTROL_CHANGE) &&
           (data1 == MIDI_C_ALL_NOTES_OFF)) {
  _gate = 0;
}

Privacy

© 2024 Zrna Research