Platforms to show: All Mac Windows Linux Cross-Platform

/Audio/PortMidi
Function:
Required plugins for this example: MBS Audio Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Audio/PortMidi
This example is the version from Tue, 23th May 2016.
Project "PortMidi.xojo_binary_project"
Class MainWindow Inherits Window
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
EventHandler Sub Change() if me.ListIndex<0 then ReadButton.Enabled=False WriteButton.Enabled=false else if me.Cell(me.ListIndex,2)="yes" then ReadButton.Enabled=true else ReadButton.Enabled=False end if if me.Cell(me.ListIndex,3)="yes" then WriteButton.Enabled=true else WriteButton.Enabled=False end if end if End EventHandler
End Control
Control ReadButton Inherits PushButton
ControlInstance ReadButton Inherits PushButton
EventHandler Sub Action() dim i as integer i=val(ListBox1.Cell(ListBox1.ListIndex,4)) OpenReadDevice i,ListBox1.Cell(ListBox1.ListIndex,0) End EventHandler
End Control
Control WriteButton Inherits PushButton
ControlInstance WriteButton Inherits PushButton
EventHandler Sub Action() dim i as integer i=val(ListBox1.Cell(ListBox1.ListIndex,4)) OpenWriteDevice i,ListBox1.Cell(ListBox1.ListIndex,0) End EventHandler
End Control
Control WriteButton1 Inherits PushButton
ControlInstance WriteButton1 Inherits PushButton
EventHandler Sub Action() dim i as integer dim c as integer = WindowCount-1 dim w as window // close other windows so portmidi is not used. for i=c DownTo 0 w = window(c) if w isa MainWindow then // ignore else w.Close end if next dim e as integer = p.ReInitialize if e=0 then // ok else MsgBox "Error: "+str(e) end if run End EventHandler
End Control
EventHandler Sub Open() p=new PortMidiMBS me.show me.run End EventHandler
Protected Sub OpenReadDevice(DeviceID as integer, Name as string) // Open the device for reading dim p as PortMidiMBS dim s as PortMidiStreamMBS dim e as integer // filter active sensing messages (&hFE): */ const PM_FILT_ACTIVE= &h1 // filter system exclusive messages (&hF0): */ const PM_FILT_SYSEX= &h2 // filter clock messages (&hF8 only, does not filter clock start, etc.): */ const PM_FILT_CLOCK= &h4 // filter play messages (start= &hFA, stop= &hFC, continue= &hFB) */ const PM_FILT_PLAY= &h8 // filter undefined F9 messages (some equipment uses this as a 10ms 'tick') */ const PM_FILT_F9= &h10 const PM_FILT_TICK = PM_FILT_F9 // filter undefined FD messages */ const PM_FILT_FD= &h20 // filter undefined real-time messages */ const PM_FILT_UNDEFINED = &h30 // (PM_FILT_F9 | PM_FILT_FD) // filter reset messages (&hFF) */ const PM_FILT_RESET= &h40 // filter all real-time messages */ const PM_FILT_REALTIME = &h7F // (PM_FILT_ACTIVE | PM_FILT_SYSEX | PM_FILT_CLOCK | PM_FILT_PLAY | PM_FILT_UNDEFINED | PM_FILT_RESET) // filter note-on and note-off (&h90-&h9F and= &h80-&h8F */ const PM_FILT_NOTE= &h80 // filter channel aftertouch (most midi controllers use this) (&hD0-&hDF)*/ const PM_FILT_CHANNEL_AFTERTOUCH= &h100 // per-note aftertouch (&hA0-&hAF) */ const PM_FILT_POLY_AFTERTOUCH= &h200 // filter both channel and poly aftertouch */ const PM_FILT_AFTERTOUCH = &h300 // (PM_FILT_CHANNEL_AFTERTOUCH | PM_FILT_POLY_AFTERTOUCH) // Program changes (&hC0-&hCF) */ const PM_FILT_PROGRAM= &h400 // Control Changes (CC's) (&hB0-&hBF)*/ const PM_FILT_CONTROL= &h800 // Pitch Bender (&hE0-&hEF*/ const PM_FILT_PITCHBEND= &h1000 // MIDI Time Code (&hF1)*/ const PM_FILT_MTC= &h2000 // Song Position (&hF2) */ const PM_FILT_SONG_POSITION= &h4000 // Song Select (&hF3)*/ const PM_FILT_SONG_SELECT= &h8000 // Tuning request (&hF6)*/ const PM_FILT_TUNE= &h10000 // All System Common messages (mtc, song position, song select, tune request) */ const PM_FILT_SYSTEMCOMMON = &h1E000 // (PM_FILT_MTC | PM_FILT_SONG_POSITION | PM_FILT_SONG_SELECT | PM_FILT_TUNE) s=new PortMidiStreamMBS e=s.OpenInput(DeviceID,100) if e=0 then 'e=s.SetFilter(&hFFFFF) ReadWindow.Show ReadWindow.Title="Read from "+name ReadWindow.p=p ReadWindow.s=S else MsgBox "OpenInput returns "+str(e) end if End Sub
Protected Sub OpenWriteDevice(DeviceID as integer, Name as string) // Open the device for reading dim p as PortMidiMBS dim s as PortMidiStreamMBS dim e as integer s=new PortMidiStreamMBS e=s.OpenOutput(DeviceID,10000,100) if e=0 then 'e=s.SetFilter(&hFFFFF) WriteWindow.Show WriteWindow.Title="Write to "+name WriteWindow.p=p WriteWindow.s=S else MsgBox "OpenOutput returns "+str(e) end if End Sub
Sub run() dim i,c as integer dim info as PortMidiDeviceInfoMBS dim s as string ListBox1.DeleteAllRows // Show the device list c=p.CountDevices-1 for i=0 to c info=p.DeviceInfo(i) if info<>Nil then ListBox1.AddRow info.Name ListBox1.Cell(ListBox1.LastIndex,1)=info.InterfaceName if info.HasInput then s="yes" else s="no" end if ListBox1.Cell(ListBox1.LastIndex,2)=s if info.HasOutput then s="yes" else s="no" end if ListBox1.Cell(ListBox1.LastIndex,3)=s ListBox1.Cell(ListBox1.LastIndex,4)=str(i) end if next End Sub
Property Protected p As PortMidiMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem FileClose = "Close"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() MainWindow.Show End EventHandler
End Class
Class ReadWindow Inherits Window
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() Run End EventHandler
End Control
Function FileClose() As Boolean close Return true End Function
Protected Sub Run() dim d as PortMidiEventMBS dim e as integer while s.Poll<>0 e=s.Read(d) System.DebugLog "Read "+str(e) if e=1 then ListBox1.AddRow Format(d.When,"0") ListBox1.Cell(ListBox1.LastIndex,1)=str(d.Status) ListBox1.Cell(ListBox1.LastIndex,2)=str(d.Data1) ListBox1.Cell(ListBox1.LastIndex,3)=str(d.Data2) end if wend End Sub
Property p As PortMidiMBS
Property s As PortMidiStreamMBS
End Class
Class WriteWindow Inherits Window
Control Bevel Inherits BevelButton
ControlInstance Bevel(0) Inherits BevelButton
ControlInstance Bevel(1) Inherits BevelButton
ControlInstance Bevel(2) Inherits BevelButton
ControlInstance Bevel(3) Inherits BevelButton
ControlInstance Bevel(4) Inherits BevelButton
ControlInstance Bevel(5) Inherits BevelButton
ControlInstance Bevel(6) Inherits BevelButton
ControlInstance Bevel(7) Inherits BevelButton
ControlInstance Bevel(8) Inherits BevelButton
ControlInstance Bevel(9) Inherits BevelButton
ControlInstance Bevel(10) Inherits BevelButton
ControlInstance Bevel(11) Inherits BevelButton
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean me.Value=true SendNoteOn index Return true End EventHandler
EventHandler Function MouseUp(X As Integer, Y As Integer) As Boolean me.Value=false SendNoteOff index Return true End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control PopupMenu1 Inherits PopupMenu
ControlInstance PopupMenu1 Inherits PopupMenu
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control Slider1 Inherits Slider
ControlInstance Slider1 Inherits Slider
EventHandler Sub ValueChanged() StaticText4.text=str(me.Value) End EventHandler
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Function FileClose() As Boolean close Return true End Function
Function GetOffset() As integer Return PopupMenu1.ListIndex*12 End Function
Function GetVelocity() As integer Return Slider1.Value End Function
Sub SendNoteOff(noteValue as integer) dim d as PortMidiEventMBS dim e as integer d=new PortMidiEventMBS d.Set &h80, noteValue + GetOffset,GetVelocity e=s.Write(d) StaticText6.text=Str(e) End Sub
Sub SendNoteOn(noteValue as integer) dim d as PortMidiEventMBS dim e as integer d=new PortMidiEventMBS d.Set &h90, noteValue + GetOffset,GetVelocity e=s.Write(d) StaticText6.text=Str(e) End Sub
Property p As PortMidiMBS
Property s As PortMidiStreamMBS
End Class
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Audio Plugin.

The biggest plugin in space...




Links
MBS FileMaker Plugins

Start Chat