Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Util Plugin, MBS Audio Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Audio/Windows Midi
This example is the version from Sun, 17th Mar 2012.
Project "Windows Midi.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control inList Inherits Listbox
ControlInstance inList Inherits Listbox
End Control
Control outList Inherits Listbox
ControlInstance outList Inherits Listbox
End Control
Control PlayButton Inherits PushButton
ControlInstance PlayButton Inherits PushButton
EventHandler Sub Action()
dim l as Integer
l=outList.ListIndex
output=new MyWindowsMidiOutputMBS
output.list=eList
if l=-1 then
output.OpenDefault
else
output.Open l
end if
if output.Lasterror<>0 then
MsgBox str(output.Lasterror)
Return
end if
output.SendMessage &h90, &h3C, &h40 // status, data1, data2
if output.Lasterror<>0 then
MsgBox str(output.Lasterror)
Return
end if
DelayMBS 0.1 // wait for playback
output.SendMessage &h90, &h40, &h40
if output.Lasterror<>0 then
MsgBox str(output.Lasterror)
Return
end if
DelayMBS 0.1 // wait for playback
output.SendMessage &h404390
if output.Lasterror<>0 then
MsgBox str(output.Lasterror)
Return
end if
DelayMBS 0.1 // wait for playback
output.SendMessage &h004090 // all three in one integer
if output.Lasterror<>0 then
MsgBox str(output.Lasterror)
Return
end if
output.SendMessage &h90, &h3C, &h00
if output.Lasterror<>0 then
MsgBox str(output.Lasterror)
Return
end if
output.SendMessage &h004390
if output.Lasterror<>0 then
MsgBox str(output.Lasterror)
Return
end if
DelayMBS 0.5 // wait for playback
output.Close
End EventHandler
End Control
Control SysExButton Inherits PushButton
ControlInstance SysExButton Inherits PushButton
EventHandler Sub Action()
dim m as MemoryBlock
dim l as Integer
dim o as MyWindowsMidiOutputMBS
l=outList.ListIndex
o=new MyWindowsMidiOutputMBS
o.list=eList
output=o
if l=-1 then
o.OpenDefault
else
o.Open l
end if
if o.Lasterror<>0 then
MsgBox str(o.Lasterror)
Return
end if
m=NewMemoryBlock(8)
m.Byte(0)=&hF0
m.Byte(1)=&h7F
m.Byte(2)=&h7F
m.Byte(3)=&h04
m.Byte(4)=&h01
m.Byte(5)=&h7F
m.Byte(6)=&h7F
m.Byte(7)=&hF7
o.SendData m
DelayMBS 0.5 // wait for playback
o.Close
End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
dim l as Integer
l=inList.ListIndex
input=new MyWindowsMidiInputMBS
input.list=eList
if l=-1 then
MsgBox "Please select an input device."
Return
else
input.Open l,65536
end if
if input.Lasterror<>0 then
MsgBox str(input.Lasterror)
Return
end if
input.Start
if input.Lasterror<>0 then
MsgBox str(input.Lasterror)
Return
end if
End EventHandler
End Control
Control eList Inherits Listbox
ControlInstance eList Inherits Listbox
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
if midi<>nil then
midi.Idle
end if
End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
input.Close
End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
// Report if one of this properties is ever over 0!
MsgBox str(midi.DataLost)+" data blocks lost and "+str(midi.EventsLost)+" events lost."
End EventHandler
End Control
EventHandler Sub Open()
dim i as WindowsMidiInputInfoMBS
dim o as WindowsMidiOutputInfoMBS
dim c,n as integer
midi=new WindowsMidiMBS
c=midi.NumberOfMidiInputDevices-1
for n=0 to c
i=midi.InputDevice(n)
inList.AddRow str(n+1)
inList.Cell(inList.LastIndex,1)=i.Name
inList.Cell(inList.LastIndex,2)=hex(i.DriverVersion)
next
c=midi.NumberOfMidiOutputDevices-1
for n=0 to c
o=midi.OutputDevice(n)
outList.AddRow str(n+1)
outList.Cell(outList.LastIndex,1)=o.Name
outList.Cell(outList.LastIndex,2)=hex(o.DriverVersion)
next
End EventHandler
Property Protected input As MyWindowsMidiInputMBS
Property Protected midi As WindowsMidiMBS
Property output As MyWindowsMidiOutputMBS
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class MyWindowsMidiInputMBS Inherits WindowsMidiInputMBS
EventHandler Sub DeviceClose()
list.AddRow "Input: Close"
End EventHandler
EventHandler Sub DeviceData(timestamp as integer, status as integer, data1 as integer, data2 as integer)
list.AddRow "Input: Data "+hex(status)+" "+hex(data1)+" "+hex(data2)+" "+hex(timestamp)
End EventHandler
EventHandler Sub DeviceError(timestamp as integer, status as integer, data1 as integer, data2 as integer)
list.AddRow "Input: Error "+hex(status)+" "+hex(data1)+" "+hex(data2)+" "+hex(timestamp)
End EventHandler
EventHandler Sub DeviceLongData(timestamp as integer, data as string)
list.AddRow "Input: Long Data "+hex(timestamp)+" "+EncodingToHexMBS(data)
End EventHandler
EventHandler Sub DeviceLongError(timestamp as integer, data as string)
list.AddRow "Input: Long Error "+hex(timestamp)+" "+EncodingToHexMBS(data)
End EventHandler
EventHandler Sub DeviceOpen()
list.AddRow "Input: Open"
End EventHandler
Property list As listbox
End Class
Class MyWindowsMidiOutputMBS Inherits WindowsMidiOutputMBS
EventHandler Sub DeviceClose()
list.AddRow "Output: Close"
End EventHandler
EventHandler Sub DeviceDataSent()
list.AddRow "Output: Data sent"
End EventHandler
EventHandler Sub DeviceOpen()
list.AddRow "Output: Open"
End EventHandler
EventHandler Sub DevicePositionCallback()
list.AddRow "Output: Position Callback"
End EventHandler
Property list As listbox
End Class
End Project
See also:
The items on this page are in the following plugins: MBS Audio Plugin.