Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacCF Plugin, MBS MacOSX Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCF/MIDI/MIDI Input Synth
This example is the version from Sun, 17th Mar 2012.
Project "MIDI Input Synth.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
EventHandler Sub Close()
closeMidiClient
End EventHandler
EventHandler Sub Open()
Client=new MidiClientMBS
openMidiClient
player=new MidiPlaybackMBS
if player.Inited then
port.SetCallback player.Callback,player
end if
End EventHandler
Protected Sub closeMidiClient()
End Sub
Sub openMidiClient()
dim myname,portname as CFStringMBS
dim s as MidiEndpointMBS
dim i,n as Integer
myname=NewCFStringMBS("MidiTest")
Client.Init(myname)
if Client.Lasterror <> 0 then
MsgBox "MidiClient MBS Init failed: " + str(Client.Lasterror)
end
portname=NewCFStringMBS("Testport")
port=new MyMidiPort
Client.CreateInputPort portname, port
if port.Handle=0 then
MsgBox "There was an error: "+str(Client.Lasterror)
end if
system.debuglog "port.handle: "+hex(port.Handle)
n = Client.NumberOfSources
for i=0 to n-1
s=Client.GetSource(i)
ListBox1.AddRow "Connect to "+s.StringProperty(s.kMIDIPropertyName).str
port.ConnectSource s
sources.Append s
next
End Sub
Note "bla"
dim i,n as Integer
dim p as MidiPacketMBS
n=list.Count
for i=0 to n-1
p=list.Item(i)
EditField1.Text=EditField1.Text + p.DataString
next
Property Protected Client As midiclientMBS
Property Protected player As MidiPLaybackMBS
Property Protected port As myMidiPort
Property Protected sources() As MidiEndpointMBS
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class MyMidiPort Inherits MidiPortMBS
EventHandler Sub Read(endpoint as MidiEndpointMBS, list as MidiPacketListMBS)
dim i, j, n, x as integer
dim pack as MIDIPacketMBS
dim s,f as string
dim cs as CFStringMBS
dim data as memoryBlock
dim k as integer
system.debuglog "endpoint.Handle: "+hex(endpoint.Handle)
count=count+1
k=count
n = list.Count-1
system.debuglog str(k)+" "+str(list.Count)+" packets."
for i = 0 to n
system.debuglog str(k)+" "+str(i)
pack = list.item(i)
data = pack.dataMemory
x = data.size
if data.byte(0) >= &h90 and data.byte(0) <= &h9F then
'note on
s = "Note on(" + str(data.byte(1)) + ") + velocity("+str(data.byte(2)) + ")"
elseif data.byte(0) >= &h80 and data.byte(0) <= &h8F then
'note off
s = "Note off(" + str(data.byte(1)) + ") + velocity("+str(data.byte(2)) + ")"
elseif data.byte(0) >= &hB0 and data.byte(0) <= &hBF then
s = "Controller change(" + str(data.byte(1)) + ") + value("+str(data.byte(2)) + ")"
elseif data.byte(0) >= &hE0 and data.byte(0) <= &hEF then
s = "Pitchbend"
elseif data.byte(0) = &hFE then
'don't do anything with active sensing
s = ""
else
system.debuglog str(k)+" something else"
'more midi events go here
s = ""
for j = 0 to x-1
s = s + str(data.byte(j)) + " "
next
end
if s <> "" then
system.debuglog str(k)+" insertrow"
cs=endpoint.StringProperty(endpoint.kMIDIPropertyName)
if cs<>Nil then
f=cs.str
else
f=""
end if
window1.ListBox1.Insertrow 0,s+" from "+f
end
next
system.debuglog str(k)+" finished. "
End EventHandler
Property Protected count As integer
End Class
End Project
See also:
The items on this page are in the following plugins: MBS MacCF Plugin.