Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacOSX Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacOSX/Play Keys
This example is the version from Sun, 17th Mar 2012.
Project "Play Keys.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control notes Inherits BevelButton
ControlInstance notes(0) Inherits BevelButton
ControlInstance notes(1) Inherits BevelButton
ControlInstance notes(2) Inherits BevelButton
ControlInstance notes(3) Inherits BevelButton
ControlInstance notes(4) Inherits BevelButton
ControlInstance notes(5) Inherits BevelButton
ControlInstance notes(6) Inherits BevelButton
ControlInstance notes(7) Inherits BevelButton
ControlInstance notes(8) Inherits BevelButton
ControlInstance notes(9) Inherits BevelButton
ControlInstance notes(10) Inherits BevelButton
ControlInstance notes(11) Inherits BevelButton
ControlInstance notes(12) Inherits BevelButton
EventHandler Function MouseDown(index as Integer, X As Integer, Y As Integer) As Boolean
me.value = true
SendNoteOn(index)
return true
End EventHandler
EventHandler Function MouseUp(index as Integer, X As Integer, Y As Integer) As Boolean
me.value = false
SendNoteOff(index)
return true
End EventHandler
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action()
if me.Value then
// switch to Drum Kit sound bank
midi.SendMidiEvent(176, 0, 0, 0)
midi.SendMidiEvent(176, 32, 1, 0)
midi.SendMidiEvent(192, 1, 0, 0)
InstrumentMenu.Enabled = false
else
// switch to regular sound bank
midi.SendMidiEvent(176, 0, 0, 0)
midi.SendMidiEvent(176, 32, 0, 0)
InstrumentMenu.Enabled = true
midi.InstrumentIDOnChannel(0) = InstrumentMenu.RowTag(InstrumentMenu.ListIndex)
end if
End EventHandler
End Control
Control InstrumentMenu Inherits PopupMenu
ControlInstance InstrumentMenu Inherits PopupMenu
EventHandler Sub Change()
if me.ListIndex>=0 then
midi.InstrumentIDOnChannel(0) = me.RowTag(me.ListIndex)
end if
End EventHandler
End Control
EventHandler Function KeyDown(Key As String) As Boolean
Select case asc(key)
case asc("c")
SendNoteOn 0
case asc("C")
SendNoteOn 1
case asc("d")
SendNoteOn 2
case asc("D")
SendNoteOn 3
case asc("e")
SendNoteOn 4
case asc("f")
SendNoteOn 5
case asc("F")
SendNoteOn 6
case asc("g")
SendNoteOn 7
case asc("G")
SendNoteOn 8
case asc("a")
SendNoteOn 9
case asc("A")
SendNoteOn 10
case asc("b")
SendNoteOn 11
else
Return false
end Select
Return true
End EventHandler
EventHandler Sub KeyUp(Key As String)
Select case asc(key)
case asc("c")
SendNoteOff 0
case asc("C")
SendNoteOff 1
case asc("d")
SendNoteOff 2
case asc("D")
SendNoteOff 3
case asc("e")
SendNoteOff 4
case asc("f")
SendNoteOff 5
case asc("F")
SendNoteOff 6
case asc("g")
SendNoteOff 7
case asc("G")
SendNoteOff 8
case asc("a")
SendNoteOff 9
case asc("A")
SendNoteOff 10
case asc("b")
SendNoteOff 11
end Select
End EventHandler
EventHandler Sub Open()
midi = new MidiPlaybackMBS
dim u as integer = midi.InstrumentCount-1
for i as integer = 0 to u
dim ID as integer = midi.InstrumentID(i)
dim Name as string = midi.InstrumentName(i)
InstrumentMenu.AddRow name
InstrumentMenu.RowTag(i) = ID
next
InstrumentMenu.ListIndex = 0
midi.Start
End EventHandler
Sub SendNoteOff(noteValue as integer)
dim NoteOn as integer = &h80
dim Note as integer = noteValue + 48
dim Velocity as integer = &h7C
midi.SendMidiEvent NoteOn, note, Velocity, 0
End Sub
Sub SendNoteOn(noteValue as integer)
dim NoteOn as integer = &h90
dim Note as integer = noteValue + 48
dim Velocity as integer = &h7C
midi.SendMidiEvent NoteOn, note, Velocity, 0
End Sub
Property midi As MidiPlaybackMBS
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
if not TargetMacOS then
MsgBox "This example is Mac only."
end if
End EventHandler
End Class
End Project
The items on this page are in the following plugins: MBS MacOSX Plugin.