Ejemplo n.º 1
0
 void send (const MIDIPacketList* const packets) noexcept
 {
     if (port != 0)
         MIDISend (port, endPoint, packets);
     else
         MIDIReceived (endPoint, packets);
 }
Ejemplo n.º 2
0
//------------------------------------------------------------------------
void TJackSynchro::SendEvent(Byte c)
{
    MIDIPacketList realtimePacketList;
    realtimePacketList.numPackets = 1;
    realtimePacketList.packet[0].timeStamp = 0;
    realtimePacketList.packet[0].length = 1;
    realtimePacketList.packet[0].data[0] = c;
    OSStatus err = MIDIReceived(fSource, &realtimePacketList);
}
Ejemplo n.º 3
0
void CoreMidiManager::SendMIDI(char actionType, int noteNum, int value)
{
  uint8_t buffer[PACKET_BUF_SIZE];
  uint8_t msg[3];
  
  MIDIPacketList *packetList = (MIDIPacketList*) buffer;
  MIDIPacket *curPacket = MIDIPacketListInit(packetList);
  
  curPacket = MIDIPacketListAdd(packetList,
				PACKET_BUF_SIZE,
				curPacket,
				AudioGetCurrentHostTime(),
				actionType == 'C' ? 2 : 3,
				msg);
  if (!curPacket)
    midimsg_die("packet list allocation failed");
  
  midimsg_attempt(MIDIReceived(m_midiendpoint, packetList), "error sending midi");
}
// _________________________________________________________________________________________
// USBMIDIDriverBase::USBMIDIHandleInput
//
void	USBMIDIDriverBase::USBMIDIHandleInput(	USBMIDIDevice *	usbmDev, 
												MIDITimeStamp	when, 
												Byte *			readBuf,
												ByteCount		bufSize)
{
	Byte *src = readBuf, *srcend = src + bufSize;
	Byte pbuf[512];
	MIDIPacketList *pktlist = (MIDIPacketList *)pbuf;
	MIDIPacket *pkt = MIDIPacketListInit(pktlist);
	int prevCable = -1;	// signifies none
	bool insysex = false;

	for ( ; src < srcend; src += 4) {
		int cin = src[0] & 0x0F;
		
		if (cin < 2)
			// skip over reserved cin's before doing any more work
			continue;
		
		int cable = src[0] >> 4;
		int msglen;
		// support single-entity devices that seem to use an arbitrary cable number
		// (besides which, it's good to have range-checking)
		if (cable < 0) cable = 0;
		else if (cable >= usbmDev->mNumEntities) cable = usbmDev->mNumEntities - 1;
		
		if (prevCable != -1 && cable != prevCable) {
			MIDIReceived(usbmDev->mSources[prevCable], pktlist);
			pkt = MIDIPacketListInit(pktlist);
			insysex = false;
		}
		prevCable = cable;
		
		#if SYSEX_DEBUG_LEVEL >= 2
			if (gSysExTraceCount >= 0)
				gSysExTraceBuf[gSysExTraceCount++] = *(UInt32 *)src;
		#endif

		switch (cin) {
		case 0x0:		// reserved
		case 0x1:		// reserved
			break;
		case 0xF:		// single byte
			msglen = 1;
AddMessage:
			while (true) {
				pkt = MIDIPacketListAdd(pktlist, sizeof(pbuf), pkt, when, msglen, src + 1);
				if (pkt != NULL) break;
				if (prevCable != -1)
					MIDIReceived(usbmDev->mSources[prevCable], pktlist);
				pkt = MIDIPacketListInit(pktlist);
				insysex = false;
			}
			break;
		case 0x2:		// 2-byte system common
		case 0xC:		// program change
		case 0xD:		// mono pressure
			msglen = 2;
			goto AddMessage;
		case 0x4:		// sysex starts or continues			
			#if SYSEX_DEBUG_LEVEL >= 2
				if (gSysExCount == -1) {
					gSysExTraceCount = 0;
					gSysExCount = 0;
					gSysExTraceBuf[gSysExTraceCount++] = *(UInt32 *)src;
				}
				gSysExCount += 3;
			#elif SYSEX_DEBUG_LEVEL >= 1
				if (gSysExCount == -1)
					gSysExCount = 0;
				gSysExCount += 3;
			#endif
			if (insysex) {
				// MIDIPacketListAdd will make a separate packet unnecessarily,
				// so do our own concatentation onto the current packet
				msglen = 3;
AddSysEx:
				Byte *dest = &pkt->data[pkt->length];
				if (dest + msglen > pbuf + sizeof(pbuf)) {
					if (prevCable != -1)
						MIDIReceived(usbmDev->mSources[prevCable], pktlist);
					pkt = MIDIPacketListInit(pktlist);
					insysex = false;
					goto AddMessage;
				}
				memcpy(dest, src + 1, msglen);
				pkt->length += msglen;
				break;
			}
			insysex = true;
			// --- fall ---
		case 0x3:		// 3-byte system common
		case 0x8:		// note-off
		case 0x9:		// note-on
		case 0xA:		// poly pressure
		case 0xB:		// control change
		case 0xE:		// pitch bend
			msglen = 3;
			goto AddMessage;
		case 0x5:		// single byte system-common, or sys-ex ends with one byte
			if (src[1] != 0xF7) {
				msglen = 1;
				goto AddMessage;
			}
			// --- fall ---
		case 0x6:		// sys-ex ends with two bytes
		case 0x7:		// sys-ex ends with three bytes
			msglen = cin - 4;

			#if SYSEX_DEBUG_LEVEL >= 1
				if (gSysExCount > 0) {
					gSysExCount += msglen;
					
					#if SYSEX_DEBUG_LEVEL >= 2
						char fname[64];
						sprintf(fname, "/tmp/sysx%d", ++gSysExMessages);
						FILE *f = fopen(fname, "w");
						for (int i = 0; i < gSysExTraceCount; ++i) {
							if (gSysExTraceBuf[i] == 0)
								fprintf(f, "\n");
							else
								fprintf(f, "%08x\n", gSysExTraceBuf[i]);
						}
						fclose(f);
						gSysExTraceCount = -1;
					#endif
					
					printf("=== driver: sysex end, %d bytes ===\n", gSysExCount);
					
					gSysExCount = -1;
				}
			#endif
			
			if (insysex) {
				insysex = false;
				goto AddSysEx;
			}
			goto AddMessage;
		}
	}
	#if SYSEX_DEBUG_LEVEL >= 2
		gSysExTraceBuf[gSysExTraceCount++] = 0;
		//syscall(180, 0xd0000000 + (src - readBuf), src-readBuf, 0, 0, 0);
	#endif
	
	if (pktlist->numPackets > 0 && prevCable != -1)
		MIDIReceived(usbmDev->mSources[prevCable], pktlist);
}
Ejemplo n.º 5
0
//--------------------------------------------------------------------------------------------
void TJackSynchro::ReadMidiProc8(const MIDIPacketList *pktlist, void *refCon, void *connRefCon)
{
    TJackSynchro* synchro = (TJackSynchro*)refCon;
    if (synchro->fThru)
        OSStatus err = MIDIReceived(synchro->fMidiInput[3], pktlist);
}
JNIEXPORT jint JNICALL Java_com_apple_audio_midi_MIDIEndpoint_MIDIReceived
  (JNIEnv *, jclass, jint src, jint pktlist)
{
	return (jint)MIDIReceived((MIDIEndpointRef)src, (const MIDIPacketList *)pktlist);
}