You are not logged in.

vpr

Beginner

  • "vpr" is male
  • "vpr" started this thread

Posts: 30

Date of registration: May 21st 2014

  • Send private message

1

Thursday, October 9th 2014, 12:25am

MIDI Input Example

Here's an example of how to receive MIDI controller information in Jabaco with The Midibus.

First download The Midibus from here:

http://www.smallbutdigital.com/releases/…ibus-latest.zip

and add the JAR archive to your project. Then add the core.JAR archive from Processing, which you can download from here:

https://processing.org/download/

Create a form and in the code section add the following code:

Jabaco Source

1
2
3
4
5
6
7
8
9
Import themidibus#*
Dim MB As New MBClass
Dim myBus As New MidiBus(MB,0,1)

' 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.

Public Sub Form_Load()
midibus.list
End Sub


Now create a class called MBClass and give it the SuperClass 'processing/core/PApplet' from your Processing core JAR.

Add the following code to this class:

Jabaco Source

1
2
3
4
5
Public Sub controllerChange(channel As Integer,number As Integer,value As Integer)

system.out.println("Channel: " & channel & " Number: " & number & " Value: " & value)

End Sub


Now connect a MIDI controller device, turn a knob and you will see MIDI input information printed to the debug window.

Hope this helps someone :)

maxer73

Beginner

  • "maxer73" is male

Posts: 1

Date of registration: Feb 18th 2013

Location: Varese, Italy

Hobbies: programming, electronic engeenering, 3D graphic with CAD

  • Send private message

2

Sunday, October 12th 2014, 7:39pm

TheMidiBus library "Receive midi data"

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.... :thumbsup: 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
maxer73 has attached the following file:

This post has been edited 5 times, last edit by "maxer73" (Oct 12th 2014, 8:44pm)


vpr

Beginner

  • "vpr" is male
  • "vpr" started this thread

Posts: 30

Date of registration: May 21st 2014

  • Send private message

3

Sunday, October 12th 2014, 11:50pm

Hi Maxer,

You're very welcome, and thank you for your example. I have also had difficulty getting any data from rawMidi but I will look into it. As a workaround might I suggest working with midiMessage. I have not tested this yet but it might enable you to get pitchbend and SysEx data.

I'm just getting started with Jabaco and Java so your advice is very welcome. Let me know if you have any success with the code below:

Jabaco Source

1
2
3
4
5
6
7
8
9
Dim data() as byte
Dim a as integer

Public Sub midiMessage(Message As javax#sound#midi#MidiMessage)
data()=Message.getMessage 'your MIDI byte array
For a=0 To (Message.getLength)-1
system.out.println(data(a))
Next a
End Sub

Rate this thread
WoltLab Burning Board