428
433
if (p.buffer && p.enabled) {
429
434
uint32_t *buffer = (quadlet_t *)(p.buffer);
430
435
buffer += offset;
431
for (j = p.location;j < nevents; j += 8) {
437
/* clear output (to jackd) buffer for MIDI data */
438
memset (buffer, 0, nevents*sizeof(*buffer));
440
for (j = 0; j < nevents; j += 1) {
432
441
target_event = (quadlet_t *) (data + ((j * m_dimension) + p.position));
433
442
sample_int = CondSwapFromBus32(*target_event);
435
444
// FIXME: this assumes that 2X and 3X speed isn't used,
436
445
// because only the 1X slot is put into the ringbuffer
437
if(IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_1X)) {
446
if(unlikely(IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_1X))) {
438
447
sample_int=(sample_int >> 16) & 0x000000FF;
439
448
sample_int |= 0x01000000; // flag that there is a midi event present
440
*buffer = sample_int;
441
debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "(%p) MIDI [%d]: %08X\n", this, i, sample_int);
442
} else if(IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_2X)
443
|| IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_3X) ) {
444
debugOutput(DEBUG_LEVEL_VERBOSE, "Midi mode %X not supported.\n", IEC61883_AM824_GET_LABEL(sample_int));
446
// make sure no event is received
449
midibuffer[mb_head++] = sample_int;
450
mb_head &= RX_MIDIBUFFER_SIZE-1;
451
if (unlikely(mb_head == mb_tail)) {
452
debugWarning("MOTU rx MIDI buffer overflow\n");
453
/* Dump oldest byte. This overflow can only happen if the
454
* rate coming in from the hardware MIDI port grossly
455
* exceeds the official MIDI baud rate of 31250 bps, so it
456
* should never occur in practice.
458
mb_tail = (mb_tail + 1) & (RX_MIDIBUFFER_SIZE-1);
461
debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "(%p) MIDI [%d]: %08X\n", this,
463
} else if(unlikely((IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_2X)
464
|| IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_3X) ))) {
465
debugOutput(DEBUG_LEVEL_VERBOSE, "Midi mode %X not supported.\n",
466
IEC61883_AM824_GET_LABEL(sample_int));
468
/* Write to the buffer if we're at an 8-sample boundary */
469
if (unlikely(0 == j % 8)) {
470
if (mb_head != mb_tail) {
471
*buffer = midibuffer[mb_tail++];
472
mb_tail &= RX_MIDIBUFFER_SIZE-1;