I tried to send a note to a midi application. (eventually through Bluetooth). My code to output a midi note seems fine, but I receive nothing.
Not much data found, I combined several swift/pyhtonista combinations.
Sorry for the ugly code, just try to figure out how it works, clean up later.
Not sure what i'm doing wrong here.
I you want to test is, download Synth One. it shows up in the list of destinations, but i hear no triggered note....
Been struggling for days to get this working.
My goal is to write an application for showing chords/lyrics on on iPad. I want to send a midi program change after selecting a song via bluetooth midi to mainstage.
Got the base of the application running, also the bluetooth connection running.
The bluetooth shows up in the destinations.
I isolated the midi part. in this example
from objc_util import *
from ctypes import *
import time
NSBundle.bundleWithPath_('/System/Library/Frameworks/CoreAudioKit.framework').load()
CoreMIDI = NSBundle.bundleWithPath_('/System/Library/Frameworks/CoreMIDI.framework')
CoreMIDI.load()
#NOTE: `c` is defined in objc_util as `ctypes.cdll.LoadLibrary(None)`
MIDIClientCreate = c.MIDIClientCreate
MIDIClientCreate.restype = c_int
MIDIClientCreate.argtypes = [c_void_p, c_void_p, c_void_p, c_void_p]
MIDIObjectGetProperties = c.MIDIObjectGetProperties
MIDIObjectGetProperties.restype = c_int
MIDIObjectGetProperties.argtypes = [c_void_p, c_void_p, c_bool]
MIDIObjectGetStringProperty = c.MIDIObjectGetStringProperty
MIDIObjectGetStringProperty.restype = c_int
MIDIObjectGetStringProperty.argtypes = [c_void_p, c_void_p, c_void_p]
MIDIOutputPortCreate = c.MIDIOutputPortCreate
MIDIOutputPortCreate.restype = c_int
MIDIOutputPortCreate.argtypes = [c_void_p, c_void_p, c_void_p]
#device
MIDIGetNumberOfDevices = c.MIDIGetNumberOfDevices
MIDIGetNumberOfDevices.restype = c_int
MIDIGetNumberOfDevices.argtypes = []
MIDIGetDevice = c.MIDIGetDevice
MIDIGetDevice.restype = c_void_p
MIDIGetDevice.argtypes = [c_int]
MIDIPacketListInit = c.MIDIPacketListInit
MIDIPacketListInit.restype = c_void_p
MIDIPacketListInit.argtypes = [c_void_p]
MIDIPacketListAdd = c.MIDIPacketListAdd
MIDIPacketListAdd.restype = c_void_p
MIDIPacketListAdd.argtypes = [c_void_p, c_int, c_void_p, c_ulonglong, c_int, c_void_p]
MIDIReceived = c.MIDIReceived
MIDIReceived.restype = c_int
MIDIReceived.argtypes = [c_void_p, c_void_p]
#destinations
MIDIGetNumberOfDestinations = c.MIDIGetNumberOfDestinations
MIDIGetNumberOfDestinations.restype = c_int
MIDIGetNumberOfDestinations.argtypes = []
MIDIGetDestination = c.MIDIGetDestination
MIDIGetDestination.restype = c_void_p
MIDIGetDestination.argtypes = [c_int]
NumberOfDestinations = MIDIGetNumberOfDestinations()
print("NumberOfDestinations: ",NumberOfDestinations)
MIDIPacketList = create_string_buffer(64)
MIDIPacket = MIDIPacketListInit(MIDIPacketList)
print("MIDIPacket:",MIDIPacket)
myPacket = (c_char * 3)(0x90,60,100)
myPacketp = pointer(myPacket)
r = MIDIPacketListAdd(MIDIPacketList, 17, MIDIPacket,0,3,myPacketp)
print("MIDIPacketListAdd:", r)
print(repr(MIDIPacketList))
for i in range(17):
print(i, repr(MIDIPacketList[i]) )
for i in range(NumberOfDestinations):
time.sleep(1)
dst = MIDIGetDestination(i)
props = c_void_p()
MIDIObjectGetProperties(dst, byref(props), True)
uniqueID = c_void_p()
MIDIObjectGetStringProperty(dst, ns('uniqueID'), byref(uniqueID))
name = c_void_p()
MIDIObjectGetStringProperty(dst, ns('name'), byref(name))
print("=======================================")
print(i, " DESTINATION: ", ObjCInstance(props),"name: ", ObjCInstance(name))
#print(i, " ID: ", ObjCInstance(uniqueID),"name: ", ObjCInstance(name))
r = MIDIReceived(dst,MIDIPacketList)
print( "send: ", r)
time.sleep(5)
print("ready")
The output:
NumberOfDestinations: 2
MIDIPacket: 4487117236
MIDIPacketListAdd: 4487117236
<ctypes.c_char_Array_64 object at 0x10b76bcc8>
0 b'\x01'
1 b'\x00'
2 b'\x00'
3 b'\x00'
4 b'\x00'
5 b'\x00'
6 b'\x00'
7 b'\x00'
8 b'\x00'
9 b'\x00'
10 b'\x00'
11 b'\x00'
12 b'\x03'
13 b'\x00'
14 b'\x90'
15 b'<'
16 b'd'
=======================================
0 DESTINATION: {
uniqueID = "-1336782696";
} name: Session 1
send: 0
=======================================
1 DESTINATION: {
name = "AudioKit Synth One";
uniqueID = 95433;
} name: AudioKit Synth One
send: 0
ready