void MidiDriver_DMEDIA::send(uint32 b) { MDevent event; byte status_byte = (b & 0x000000FF); byte first_byte = (b & 0x0000FF00) >> 8; byte second_byte = (b & 0x00FF0000) >> 16; event.sysexmsg = NULL; event.msg[0] = status_byte; event.msg[1] = first_byte; event.msg[2] = second_byte; switch (status_byte & 0xF0) { case 0x80: // Note Off case 0x90: // Note On case 0xA0: // Polyphonic Aftertouch case 0xB0: // Controller Change case 0xE0: // Pitch Bending event.msglen = 3; break; case 0xC0: // Programm Change case 0xD0: // Monophonic Aftertouch event.msglen = 2; break; default: warning("DMediaMIDI driver encountered unsupported status byte: 0x%02x", status_byte); event.msglen = 3; break; } if (mdSend(_midiPort, &event, 1) != 1) { warning("failed sending MIDI event (dump follows...)"); warning("MIDI Event (len=%u):", event.msglen); for (int i = 0; i < event.msglen; i++) warning("%02x ", (int)event.msg[i]); } }
int mus_midi_write(int line, unsigned char *buffer, int bytes) { int i; MDevent mdv; if ((line < 0) || (line >= midis)) return(-1); if (midi_directions[line] == MIDI_WRITE) { /* no sysex for now */ mdv.sysexmsg = NULL; mdv.msglen = 0; for (i = 0; i < bytes; i += 3) { mdv.msg[0] = buffer[i]; mdv.msg[1] = buffer[i + 1]; mdv.msg[2] = buffer[i + 2]; mdSend(midi_lines[line], &mdv, 1); } return(bytes); } #ifdef NO_SNDLIB fprintf(stderr, "can't write to input %s\n", midi_names[line]); return(-1); #else return(mus_error(MUS_MIDI_WRITE_ERROR, "can't write to input %s", midi_names[line])); #endif }
void MidiDriver_DMEDIA::sysEx (const byte *msg, uint16 length) { MDevent event; char buf [1024]; assert(length + 2 <= 256); memcpy(buf, msg, length); buf[length] = MD_EOX; event.sysexmsg = buf; event.msglen = length; event.msg[0] = MD_SYSEX; event.msg[1] = 0; event.msg[2] = 0; if (mdSend(_midiPort, &event, 1) != 1) { fprintf(stderr, "failed sending MIDI SYSEX event (dump follows...)\n"); for (int i = 0; i < event.msglen; i++) warning("%02x ", (int)event.msg[i]); } }