Hi VPR, many many thanks for this example of how to get midi input data with the library TheMidiBus, I am using this library for several months but I only managed to list the midi devices, open ports and send noteOn, noteOff and ControlChange ....
Now I can finally also receive midi events and this is very nice....
I saw that you have created an external class to receive MIDI data, this is not necessary, you can also use (Me) as an instance to the constructor and put the Subs to receive midi events directly in the Form code.
I have attached a small example that adds further explanation of how the TheMidiBus
library works and soon I will post other examples a little more complex where I have listed the midi devices within certain List and where you can open or close any of them, send simple sequences of notes and ControlChanges, receive midi events and displays them in a TextBox.
I added this to pick up the RAW midi data but does not seem to work.... you know how to do? You should receive an array of Bytes (I need this to get PithcBender and system exclusive messages):
|
Source code
|
1
2
3
|
Public Sub rawMidi(rawData() As Byte)
Text1.Text = Text1.Text & "raw - " & rawData(0) & vbCrLf
End Sub
|
Sorry for my poor english but I'm Italian.
Regards
Max
SOURCE CODE: (I've attached even Zip file with project)
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
'Import themidibus#* 'I see that this is not really needed (just add themidibus.jar to ClassPath)
'************************************** SYNTAX FOR MIDIBUS COSTRUCTOR ************************************
'** (These are just a few costructors) there are actually many more (please refer to TheMidiBus JavaDoc **
'******** not passing anything as an argument is left to decide what to do TheMidiBus library ************
'*********************************************************************************************************
' Parent In Out
' | | |
'myBus = New MidiBus(this, 0, 1); // Create a New MidiBus using the device index To Select the Midi input And output devices respectively.
' Parent In Out
' | | |
'myBus = New MidiBus(this, "IncomingDeviceName", "OutgoingDeviceName"); // Create a New MidiBus using the device names To Select the Midi input And output devices respectively.
' Parent In Out
' | | |
'myBus = New MidiBus(this, -1, "Java Sound Synthesizer"); // Create a New MidiBus With no input device and the default Java Sound Synthesizer As the output device.
' 0 and 1 in this case refer to the MIDI input and output devices that you wish you use.
' You will need To enumerate your devices using midibus.list (below) And choose the appropriate values.
'Dim MB As New MBClass 'use external class for midi input events (not used in this example because we use this istance (Me))
'Dim myBus As New MidiBus(MB,0,1) 'use external class for midi input events (not used in this example because we use this istance (Me))
Dim myBus As New MidiBus(Me,0,1) 'use this istance for midi input events
'Dim myBus As New MidiBus() 'if default costructor is used then you need to use "INITIALIZE"
'Dim Note AS Note 'use this if you want manipulate Note class of TheMidiBus library
'Dim CChange As ControlChange 'use this if you want manipulate ControlChange class of TheMidiBus library
'Dim Message As MidiMessage 'use this if you want manipulate low level javafx.sound.midi MidiMessage
Dim Count As Integer = 0
Public Sub Form_Load()
MidiBus.list
' INITIALIZE (use this if you have previously used the constructor with no parameters)
' myBus.addInput(0)
' myBus.addOutput(1)
' myBus.registerParent(Me)
End Sub
Public Sub Form_Unload(cancel As Integer)
myBus.close
End Sub
Sub cmd1_Click()
Text1.Text = ""
Count = 0 : lblCount.Caption = Count
End Sub
Sub RefreshLabel
Count = Count + 1 : lblCount.Caption = Count
' Text1.SelStart = Count*100
End Sub
Public Sub controllerChange(ch As Integer, ctrl As Integer, val As Integer)
Text1.Text = Text1.Text & "ControlChange - Channel: " & ch+1 & " Control: " & ctrl & " Value: " & val & vbCrLf
RefreshLabel
End Sub
Public Sub noteOn(ch As Integer, note As Integer, vel As Integer)
Text1.Text = Text1.Text & "NoteOn - Channel: " & ch+1 & " Note: " & note & " Velocity: " & vel & vbCrLf
RefreshLabel
End Sub
Public Sub noteOff(ch As Integer, note As Integer, vel As Integer)
Text1.Text = Text1.Text & "NoteOff - Channel: " & ch+1 & " Note: " & note & " Velocity: " & vel & vbCrLf
RefreshLabel
End Sub
Public Sub rawMidi(rawData() As Byte)
Text1.Text = Text1.Text & "raw - " & rawData(0) & vbCrLf
RefreshLabel
End Sub
|