This sample project uses Jazz-Plugin as VBA control.
It demonstrates how to get a list of available MIDI devices, select the device, MIDI channel and instrument, and play notes.
The main form contains 24 buttons for piano keys, ComboBoxes Out, Channel and Tone, and invisible control Jazz.
Check here for the instructions on how to add Jazz-Plugin to your project.
The rest of the code should be obvious.
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' VBPiano ' ' ' ' This example demonstrates the use of Jazz-Plugin in Visual Basic ' ' You must have Jazz-Plugin version 1.0 or newer installed ' ' ' ' More information is available at http://jazz-soft.net ' ' ' ' This code is absolutely free to copy, modify and distribute ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' Public Class VBPiano Dim chan As Integer = 0 Private Sub Start(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim list As String() = Jazz.MidiOutList() For Each s In list Out.Items.Add(s) Next s Out.SelectedIndex = 0 Tone.SelectedIndex = 0 Channel.SelectedIndex = 0 End Sub Private Sub OutChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Out.SelectedIndexChanged Jazz.MidiOutOpen(Out.SelectedItem) End Sub Private Sub ChannelChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Channel.SelectedIndexChanged chan = Channel.SelectedIndex End Sub Private Sub ToneChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tone.SelectedIndexChanged Jazz.MidiOut(&HC0 + chan, Tone.SelectedIndex, 0) End Sub Private Function Note(ByVal obj As System.Object) If ReferenceEquals(obj, Button1) Then Return 53 ElseIf ReferenceEquals(obj, Button2) Then Return 55 ElseIf ReferenceEquals(obj, Button3) Then Return 57 ElseIf ReferenceEquals(obj, Button4) Then Return 59 ElseIf ReferenceEquals(obj, Button5) Then ' middle C Return 60 ElseIf ReferenceEquals(obj, Button6) Then Return 62 ElseIf ReferenceEquals(obj, Button7) Then Return 64 ElseIf ReferenceEquals(obj, Button8) Then Return 65 ElseIf ReferenceEquals(obj, Button9) Then Return 67 ElseIf ReferenceEquals(obj, Button10) Then Return 69 ElseIf ReferenceEquals(obj, Button11) Then Return 71 ElseIf ReferenceEquals(obj, Button12) Then Return 72 ElseIf ReferenceEquals(obj, Button13) Then Return 74 ElseIf ReferenceEquals(obj, Button14) Then Return 76 ElseIf ReferenceEquals(obj, Button15) Then Return 54 ElseIf ReferenceEquals(obj, Button16) Then Return 56 ElseIf ReferenceEquals(obj, Button17) Then Return 58 ElseIf ReferenceEquals(obj, Button18) Then Return 61 ElseIf ReferenceEquals(obj, Button19) Then Return 63 ElseIf ReferenceEquals(obj, Button20) Then Return 66 ElseIf ReferenceEquals(obj, Button21) Then Return 68 ElseIf ReferenceEquals(obj, Button22) Then Return 70 ElseIf ReferenceEquals(obj, Button23) Then Return 73 ElseIf ReferenceEquals(obj, Button24) Then Return 75 End If Return 0 End Function Private Sub Down(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown, Button2.MouseDown, Button3.MouseDown, Button4.MouseDown, Button5.MouseDown, Button6.MouseDown, Button7.MouseDown, Button8.MouseDown, Button9.MouseDown, Button10.MouseDown, Button11.MouseDown, Button12.MouseDown, Button13.MouseDown, Button14.MouseDown, Button15.MouseDown, Button16.MouseDown, Button17.MouseDown, Button18.MouseDown, Button19.MouseDown, Button20.MouseDown, Button21.MouseDown, Button22.MouseDown, Button23.MouseDown, Button24.MouseDown Jazz.MidiOut(&H90 + chan, Note(sender), 100) End Sub Private Sub Up(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp, Button2.MouseUp, Button3.MouseUp, Button4.MouseUp, Button5.MouseUp, Button6.MouseUp, Button7.MouseUp, Button8.MouseUp, Button9.MouseUp, Button10.MouseUp, Button11.MouseUp, Button12.MouseUp, Button13.MouseUp, Button14.MouseUp, Button15.MouseUp, Button16.MouseUp, Button17.MouseUp, Button18.MouseUp, Button19.MouseUp, Button20.MouseUp, Button21.MouseUp, Button22.MouseUp, Button23.MouseUp, Button24.MouseUp Jazz.MidiOut(&H80 + chan, Note(sender), 0) End Sub End Class
VBPiano.zip (15k) - Visual Studio 2008