void CoreMidiDriver::handleQueueNote(Note* pNote) { if (cmH2Dst == NULL ) { ERRORLOG( "cmH2Dst = NULL " ); return; } int channel = pNote->get_instrument()->get_midi_out_channel(); if (channel < 0) { return; } int key = pNote->get_midi_key(); int velocity = pNote->get_midi_velocity(); MIDIPacketList packetList; packetList.numPackets = 1; packetList.packet->timeStamp = 0; packetList.packet->length = 3; packetList.packet->data[0] = 0x80 | channel; packetList.packet->data[1] = key; packetList.packet->data[2] = velocity; MIDISend(h2OutputRef, cmH2Dst, &packetList); packetList.packet->data[0] = 0x90 | channel; packetList.packet->data[1] = key; packetList.packet->data[2] = velocity; MIDISend(h2OutputRef, cmH2Dst, &packetList); }
void CoreMidiOutputDevice::writeSysEx(QByteArray message) { if(message.isEmpty()) return; if (isOpen() == false) return; int bufferSize = message.count() + 100; // Todo this is not correct Byte buffer[bufferSize]; // osx max=65536 MIDIPacketList* list = (MIDIPacketList*) buffer; MIDIPacket* packet = MIDIPacketListInit(list); /* Add the MIDI command to the packet list */ packet = MIDIPacketListAdd(list, bufferSize, packet, 0, message.count(), (Byte *)message.data()); if (packet == 0) { qWarning() << "MIDIOut buffer overflow"; return; } /* Send the MIDI packet list */ OSStatus s = MIDISend(m_outPort, m_destination, list); if (s != 0) qWarning() << Q_FUNC_INFO << "Unable to send MIDI data to" << name(); }
void CoreMidiOutputDevice::writeFeedback(uchar cmd, uchar data1, uchar data2) { if (isOpen() == false) return; Byte buffer[128]; // Should be enough for 1 message MIDIPacketList* list = (MIDIPacketList*) buffer; MIDIPacket* packet = MIDIPacketListInit(list); Byte message[3]; message[0] = cmd; message[1] = data1; message[2] = data2; /* Add the MIDI command to the packet list */ packet = MIDIPacketListAdd(list, sizeof(buffer), packet, 0, sizeof(message), message); if (packet == 0) { qWarning() << "MIDIOut buffer overflow"; return; } /* Send the MIDI packet list */ OSStatus s = MIDISend(m_outPort, m_destination, list); if (s != 0) qWarning() << Q_FUNC_INFO << "Unable to send MIDI data to" << name(); }
void send (const MIDIPacketList* const packets) noexcept { if (port != 0) MIDISend (port, endPoint, packets); else MIDIReceived (endPoint, packets); }
void CoreMidiDriver::handleQueueAllNoteOff() { if (cmH2Dst == NULL ) { ERRORLOG( "cmH2Dst = NULL " ); return; } InstrumentList *instList = Hydrogen::get_instance()->getSong()->get_instrument_list(); unsigned int numInstruments = instList->size(); for (int index = 0; index < numInstruments; ++index) { Instrument *curInst = instList->get(index); int channel = curInst->get_midi_out_channel(); if (channel < 0) { continue; } int key = curInst->get_midi_out_note(); MIDIPacketList packetList; packetList.numPackets = 1; packetList.packet->timeStamp = 0; packetList.packet->length = 3; packetList.packet->data[0] = 0x80 | channel; packetList.packet->data[1] = key; packetList.packet->data[2] = 0; MIDISend(h2OutputRef, cmH2Dst, &packetList); } }
static void _macosx_drain(struct midi_port *p) { struct macosx_midi *m; m = (struct macosx_midi *)p->userdata; if (m->x) { MIDISend(portOut, m->ep, m->pl); m->x = NULL; } }
void MIDIOut_Send(MIDIPortRef port, MIDIEndpointRef dest, UInt8 *buffer, unsigned length) { Byte packetBuff[512]; MIDIPacketList *packetList = (MIDIPacketList *)packetBuff; MIDIPacket *packet = MIDIPacketListInit(packetList); packet = MIDIPacketListAdd(packetList, sizeof(packetBuff), packet, mach_absolute_time(), length, buffer); if (packet) MIDISend(port, dest, packetList); }
int mus_midi_write(int line, unsigned char *buffer, int bytes) { MIDIPacketList *list = (MIDIPacketList *)bb; MIDIPacket *pk; if ((line < 1) || (buffer == NULL) || (outp == NULL)) return(-1); /* create the packetlist and packet */ pk = MIDIPacketListInit(list); MIDIPacketListAdd(list, sizeof(bb), pk, 0, bytes, (Byte *)buffer); /* 0 is the time stamp = now? */ MIDISend(outp, MIDIGetDestination(0), list); return(0); }
void sendmidi(int port, MIDIEndpointRef dest, int length, int hiStatus, int loStatus, int aval, int bval, float late) { MIDIPacketList mpktlist; MIDIPacketList * pktlist = &mpktlist; MIDIPacket * pk = MIDIPacketListInit(pktlist); ByteCount nData = (ByteCount) length; pk->data[0] = (Byte) (hiStatus & 0xF0) | (loStatus & 0x0F); pk->data[1] = (Byte) aval; pk->data[2] = (Byte) bval; pk = MIDIPacketListAdd(pktlist, sizeof(struct MIDIPacketList) , pk, midiTime(late), nData, pk->data); /*OSStatus error =*/ MIDISend(gMIDIOutPort[port], dest, pktlist ); }
void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue) { // send this up the MIDI. Construct sysex: unsigned char data[] = {0xF0, 0x00, 0x20, 0x29, 0x02, 0x10, 0x0B, index, red, green, blue, 0xF7}; static const int MAX_OUTPUT_BUFFER_SIZE = 256; MIDIPacketList packetLst; MIDIPacket *packet = MIDIPacketListInit(&packetLst); MIDIPacketListAdd(&packetLst, MAX_OUTPUT_BUFFER_SIZE, packet, 0, sizeof(data), data); MIDISend(g_outDevPort, g_outDevEndpoint, &packetLst); }
int lp_send_midi_msg(lp_device_t device, uint8_t data[256], size_t len) { uint8_t buf[256]; bzero(buf, 256); MIDIPacketList *list = (MIDIPacketList *)buf; (void)MIDIPacketListInit(list); list->numPackets = 1; list->packet[0].length = len; list->packet[0].timeStamp = 0; memcpy(list->packet[0].data, data, len); return MIDISend(_lp_ctx.outport, device->dest, (const MIDIPacketList *)list); }
//_________________________________________________________ static void SendSmallEv(SlotPtr slot, MidiEvPtr e, sendState* state) { MIDIPacketList* pktlist = (MIDIPacketList*)state->packetBuffer; MIDIPacket* packet = MIDIPacketListInit(pktlist); unsigned char * ptr = state->evBuffer; OSErr err; int n = 0; e = MidiStreamPutEvent (&state->outsmall, e); if (e) MidiTask (KOffTask, Date(e), gRefNum, (long)e, (long)slot, 0); // typeNote while (MidiStreamGetByte (&state->outsmall, ptr++)) {n++;} MIDIPacketListAdd(pktlist,sizeof(state->packetBuffer),packet,MIDIGetCurrentHostTime(),n,state->evBuffer); err = MIDISend(slot->port,slot->dest,pktlist); if (err != noErr) fprintf(stderr, "MIDISend : error %ld\n", err); }
void MidiDriver_CoreMIDI::send(uint32 b) { assert(mOutPort != 0); assert(mDest != 0); // Extract the MIDI data byte status_byte = (b & 0x000000FF); byte first_byte = (b & 0x0000FF00) >> 8; byte second_byte = (b & 0x00FF0000) >> 16; // Generate a single MIDI packet with that data MIDIPacketList packetList; MIDIPacket *packet = &packetList.packet[0]; packetList.numPackets = 1; packet->timeStamp = 0; packet->data[0] = status_byte; packet->data[1] = first_byte; packet->data[2] = second_byte; // Compute the correct length of the MIDI command. This is important, // else things may screw up badly... switch (status_byte & 0xF0) { case 0x80: // Note Off case 0x90: // Note On case 0xA0: // Polyphonic Aftertouch case 0xB0: // Controller Change case 0xE0: // Pitch Bending packet->length = 3; break; case 0xC0: // Programm Change case 0xD0: // Monophonic Aftertouch packet->length = 2; break; default: warning("CoreMIDI driver encountered unsupported status byte: 0x%02x", status_byte); packet->length = 3; break; } // Finally send it out to the synthesizer. MIDISend(mOutPort, mDest, &packetList); }
static void MyReadProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon) { if (gOutPort != NULL && gDest != NULL) { MIDIPacket *packet = (MIDIPacket *)pktlist->packet; // remove const (!) for (unsigned int j = 0; j < pktlist->numPackets; ++j) { for (int i = 0; i < packet->length; ++i) { // printf("%02X ", packet->data[i]); // rechannelize status bytes if (packet->data[i] >= 0x80 && packet->data[i] < 0xF0) packet->data[i] = (packet->data[i] & 0xF0) | gChannel; } // printf("\n"); packet = MIDIPacketNext(packet); } MIDISend(gOutPort, gDest, pktlist); } }
void MIDIChango::update(float *vals){ for( int i = 0; i < NUM_WAVES ; i ++ ){ /*On*/ packetList.numPackets = 1; packetList.packet[0].length = 3; packetList.packet[0].data[0] = 0x90; // note ON packetList.packet[0].data[1] = 0x7f & ((int)mtones[i]); // C packetList.packet[0].data[2] = ((int)(vals[i]*127)); // velocity packetList.packet[0].timeStamp = 0; MIDISend(outputPort,eps[i],&packetList); fflush(stdout); } }
void MidiDriver_CoreMIDI::sysEx(const byte *msg, uint16 length) { assert(isOpen()); byte buf[384]; MIDIPacketList *packetList = (MIDIPacketList *)buf; MIDIPacket *packet = packetList->packet; assert(sizeof(buf) >= sizeof(UInt32) + sizeof(MIDITimeStamp) + sizeof(UInt16) + length + 2); packetList->numPackets = 1; packet->timeStamp = 0; // Add SysEx frame packet->length = length + 2; packet->data[0] = 0xF0; memcpy(packet->data + 1, msg, length); packet->data[length + 1] = 0xF7; // Send it MIDISend(mOutPort, mDest, packetList); }
void MidiApple::sendMidiOut( MIDIEndpointRef &endPointRef, const MidiEvent& event ) { MIDIPacketList packetList=createMidiPacketList(event); MIDIPortRef port = m_sourcePortRef.value(endPointRef); MIDISend(port, endPointRef, &packetList); }
void MIDIDevice::outputDMX(const QByteArray& universe) { /* If there's no output port or a destination, the endpoint probably doesn't have a MIDI OUT port. */ if (m_outPort == 0 || m_destination == 0) return; Byte buffer[512]; // Should be enough for 128 channels MIDIPacketList* list = (MIDIPacketList*) buffer; MIDIPacket* packet = MIDIPacketListInit(list); /* Since MIDI devices can have only 128 real channels, we don't attempt to write more than that */ for (Byte channel = 0; channel < MAX_MIDI_DMX_CHANNELS; channel++) { Byte cmd[3]; cmd[1] = channel; cmd[2] = DMX2MIDI(universe[channel]); /* Since MIDI is so slow, we only send values that are actually changed. */ if (m_values[channel] == cmd[2]) continue; /* Store the changed MIDI value. */ m_values[channel] = cmd[2]; if (m_mode == Note) { if (cmd[2] == 0) { /* Zero is sent as a note off command */ cmd[0] = MIDI_NOTE_OFF; } else { /* 1-127 is sent as note on command */ cmd[0] = MIDI_NOTE_ON; } } else { /* Control change */ cmd[0] = MIDI_CONTROL_CHANGE; } /* Encode MIDI channel to the command */ cmd[0] |= (Byte) midiChannel(); /* Add the MIDI command to the packet list */ packet = MIDIPacketListAdd(list, sizeof(buffer), packet, 0, sizeof(cmd), cmd); if (packet == 0) { qWarning() << "MIDIOut buffer overflow"; break; } } /* Send the MIDI packet list */ OSStatus s = MIDISend(m_outPort, m_destination, list); if (s != 0) qWarning() << "Unable to send MIDI data to" << name(); }
void CoreMidiOutputDevice::writeUniverse(const QByteArray& universe) { if (isOpen() == false) return; Byte buffer[512]; // Should be enough for 128 channels MIDIPacketList* list = (MIDIPacketList*) buffer; MIDIPacket* packet = MIDIPacketListInit(list); /* Since MIDI devices can have only 128 real channels, we don't attempt to write more than that */ for (Byte channel = 0; channel < MAX_MIDI_DMX_CHANNELS && channel < universe.size(); channel++) { Byte cmd[3]; cmd[1] = channel; cmd[2] = DMX2MIDI(uchar(universe[channel])); /* Since MIDI is so slow, we only send values that are actually changed. */ if (uchar(m_universe[channel]) == cmd[2]) continue; /* Store the changed MIDI value. */ m_universe[channel] = cmd[2]; if (mode() == Note) { if (cmd[2] == 0) { /* Zero is sent as a note off command */ cmd[0] = MIDI_NOTE_OFF; } else { /* 1-127 is sent as note on command */ cmd[0] = MIDI_NOTE_ON; } } else if (mode() == ProgramChange) { /* Program change */ cmd[0] = MIDI_PROGRAM_CHANGE; } else { /* Control change */ cmd[0] = MIDI_CONTROL_CHANGE; } /* Encode MIDI channel to the command */ cmd[0] |= (Byte) midiChannel(); /* Add the MIDI command to the packet list */ packet = MIDIPacketListAdd(list, sizeof(buffer), packet, 0, sizeof(cmd), cmd); if (packet == 0) { qWarning() << "MIDIOut buffer overflow"; break; } } /* Send the MIDI packet list */ OSStatus s = MIDISend(m_outPort, m_destination, list); if (s != 0) qWarning() << Q_FUNC_INFO << "Unable to send MIDI data to" << name(); }