clock_rx

MIDI clock receiver
Author: Are Leistad
License: BSD
Github: drj/midi/clock_rx.axo

Inlets

None

Outlets

int32 Song selection

int32 Song position

bool32.pulse Pulse on 24 PPQ clock

bool32.pulse Pulse on start

bool32.pulse Pulse on stop

bool32.pulse Pulse on continue

bool32.pulse Pulse on song selection

bool32.pulse Pulse on song position

Attributes

combo device

Declaration
//#define DEBUGF LogTextMessage
#define DEBUGF(...)                                                            \
  {}

uint32_t pulse_24ppq;
uint32_t pulse_start;
uint32_t pulse_stop;
uint32_t pulse_continue;
// uint32_t  pulse_reset;
uint32_t pulse_songsel;
uint32_t song_selected;
uint32_t pulse_songpos;
uint32_t song_position;

__attribute__((always_inline)) __STATIC_INLINE int
midi_device_test(midi_device_t dev, uint8_t port, int selected_dev,
                 uint8_t selected_port) {
  if ((selected_dev == MIDI_DEVICE_OMNI) ||
      (selected_dev == dev && selected_port == port))
    return 1;
  return 0;
}
Init
pulse_24ppq = 0;
pulse_start = 0;
pulse_stop = 0;
pulse_continue = 0;
// pulse_reset     = 0;
pulse_songsel = 0;
song_selected = 0;
pulse_songpos = 0;
song_position = 0;
Control Rate
outlet_24ppq = pulse_24ppq;
outlet_start = pulse_start;
outlet_stop = pulse_stop;
outlet_continue = pulse_continue;
// outlet_reset    = pulse_reset;
outlet_songpos = pulse_songpos;
outlet_selected = song_selected;
outlet_songsel = pulse_songsel;
outlet_position = song_position;
pulse_24ppq = 0;
pulse_start = 0;
pulse_stop = 0;
pulse_continue = 0;
// pulse_reset     = 0;
pulse_songsel = 0;
pulse_songpos = 0;
Midi Handler
if (midi_device_test(dev, port, attr_device) == 1) {
  if (status == MIDI_TIMING_CLOCK) {
    pulse_24ppq = 1;
  } else if (status == MIDI_START) {
    pulse_start = 1;
  } else if (status == MIDI_STOP) {
    pulse_stop = 1;
  } else if (status == MIDI_CONTINUE) {
    pulse_continue = 1;
  } else if (status == MIDI_SONG_POSITION) {
    song_position = 6 * ((data2 << 7) + data1);
    pulse_songpos = 1;
  } else if (status == MIDI_SONG_SELECT) {
    song_selected = data1;
    pulse_songsel = 1;
  }
  // else if( status == MIDI_RESET )
  //  {
  //    pulse_reset = 1;
  //  }
}

Privacy

© 2024 Zrna Research