midichordOUT

Sends 3 notes (triad) with pitchbend offset whenever one of the input changes. To be used with the pythagorean tonnetz sequencer and "midichordIN" modules. This way the frequencies being generated by the tonnetz sequencer can also be send to external boards. Inputs are frequency inputs (outputs of pythagorean tonnetz sequencer) that get converted internally to note numbers plus pitchbend offset.
Author: Remco van der Most
License: BSD
Github: sss/midi/midichordOUT.axo

Inlets

frac32 f1

frac32 f2

frac32 f3

Outlets

None

Attributes

spinner channel

combo device

Declaration
int ntrig;
int32_t pn1;
int32_t pn2;
int32_t pn3;
bool DO;
int32_t f1, f2, f3;
int32_t MN(int32_t tmp) {
  int32_t qnt = (tmp + 0x100000) & 0xFFE00000;
  tmp -= qnt;
  tmp = tmp << 7;
  int32_t lastnote = (64 + (qnt >> 21)) & 0x7F;
  MidiSend3((midi_device_t)attr_device, MIDI_NOTE_ON + (attr_channel - 1),
            lastnote, 64);
  MidiSend3((midi_device_t)attr_device, MIDI_PITCH_BEND + (attr_channel - 1),
            (tmp >> 14) & 0x7F, (tmp >> 21) + 64);
}

int32_t out;
int32_t LOG(int32_t in) {
  Float_t f;
  f.f = in;
  int32_t r1 = ((f.parts.exponent & 0x7F) - 18) << 24;
  int32_t r3 = logt[f.parts.mantissa >> 15] << 10;
  out = r1 + r3;
}

int32_t FTOM(int32_t freq) {
  int32_t ptch;
  int32_t mid;
  MTOFEXTENDED(0, mid);
  LOG(mid);
  mid = out;

  int32_t to;
  LOG(freq);
  to = out;
  return ptch = (to - mid >> 1) * 3;
};
Init
DO = 1;
Control Rate
f1 = FTOM(inlet_f1);
f2 = FTOM(inlet_f2);
f3 = FTOM(inlet_f3);
bool trig = (!(pn1 == f1)) || (!(pn2 == f2)) || (!(pn3 == f3)) || DO;

if ((trig > 0) && !ntrig) {
  MN(f1);
  MN(f2);
  MN(f3);
  ntrig = 1;
  DO = 0;
}
if (!(trig > 0) && ntrig) {
  ntrig = 0;
}

pn1 = f1;
pn2 = f2;
pn3 = f3;

Privacy

© 2024 Zrna Research