Platforms to show: All Mac Windows Linux Cross-Platform

/MacCF/MIDI/MidiPlaybackMBS with reverb


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: /MacCF/MIDI/MidiPlaybackMBS with reverb

This example is the version from Sun, 17th Mar 2012.

Project "MidiPlaybackMBS with reverb.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control tunSlider Inherits Slider
ControlInstance tunSlider Inherits Slider
EventHandler Sub ValueChanged() if not settingUp then theSynth.Tuning = me.value end if tunField.text = str(me.value) End EventHandler
End Control
Control revSlider Inherits Slider
ControlInstance revSlider Inherits Slider
EventHandler Sub ValueChanged() if not settingUp then theSynth.ReverbVolume = me.value end if revField.text = str(me.value) End EventHandler
End Control
Control playBut Inherits PushButton
ControlInstance playBut Inherits PushButton
EventHandler Sub Action() theSynth.Start scaleTimer.mode = 1 End EventHandler
End Control
Control scaleTimer Inherits Timer
ControlInstance scaleTimer Inherits Timer
EventHandler Sub Action() //PLAY A CHROMATIC SCALE 'turn off previous note theSynth.SendMidiEvent(144+ch, scaleTone+60, 0, 0) 'move to next note scaleTone = scaleTone + 1 if scaleTone < 14 then 'turn on this note theSynth.SendMidiEvent(144+ch, scaleTone+60, 100, 0) me.mode = 1 else 'reset scale scaleTone = 0 me.mode = 0 end if End EventHandler
End Control
Control sText Inherits Label
ControlInstance sText(0) Inherits Label
ControlInstance sText(1) Inherits Label
ControlInstance sText(2) Inherits Label
ControlInstance sText(3) Inherits Label
ControlInstance sText(4) Inherits Label
ControlInstance sText(5) Inherits Label
End Control
Control streamCheck Inherits CheckBox
ControlInstance streamCheck Inherits CheckBox
EventHandler Sub Action() if not settingUp then theSynth.StreamFromDisk=me.Value end if End EventHandler
End Control
Control revCheck Inherits CheckBox
ControlInstance revCheck Inherits CheckBox
EventHandler Sub Action() if not settingUp then theSynth.UsesInternalReverb = me.value end if End EventHandler
End Control
Control volSlider Inherits Slider
ControlInstance volSlider Inherits Slider
EventHandler Sub ValueChanged() if not settingUp then theSynth.Volume = me.value end if volField.text = str(me.value) End EventHandler
End Control
Control samplePop Inherits PopupMenu
ControlInstance samplePop Inherits PopupMenu
EventHandler Sub Change() if settingUp then return loadSampleSet(me.text, me.RowTag(me.ListIndex)) End EventHandler
End Control
Control patchPop Inherits PopupMenu
ControlInstance patchPop Inherits PopupMenu
EventHandler Sub Change() if settingUp then return 'patch change theSynth.SendMidiEvent(192+ch, me.rowTag(me.listIndex), 0, 0) End EventHandler
End Control
Control channelPop Inherits PopupMenu
ControlInstance channelPop Inherits PopupMenu
End Control
Control tunField Inherits TextField
ControlInstance tunField Inherits TextField
End Control
Control revField Inherits TextField
ControlInstance revField Inherits TextField
End Control
Control volField Inherits TextField
ControlInstance volField Inherits TextField
End Control
EventHandler Sub Open() setup End EventHandler
Sub loadSampleSet(n as string, tag as variant) dim j as integer if n = "Quicktime Instruments" then //LOAD QUICKTIME theSynth = Nil theSynth = new MidiPlaybackMBS(true) else //LOAD SOUNDFONT for j = 0 to Ubound(soundfontList) if soundfontList(j) <> Nil then if n = NthField(soundfontList(j).name, ".", 1) then theSynth.LoadSoundBankFile(soundfontList(j)) end if end if next end if //STORE PATCH LIST redim patch(-1) 'not all 127 are used for every sample set for j = 0 to 127 patch.Append trim(theSynth.InstrumentName(j)) next //PATCH POPUP settingUp = true patchPop.DeleteAllRows for j = 0 to 127 'sample set instrument names 'sound fonts usually do not use all 127 instruments if asc(patch(j)) > 31 and patch(j) <> "" then patchPop.AddRow patch(j) 'the rowtag gives the actual patch number patchPop.RowTag(patchPop.ListCount-1) = j end if next settingUp = false patchPop.ListIndex = 0 End Sub
Sub scanSoundfonts() dim j, m as integer dim f as folderItem redim soundfontList(-1) //STORE SOUNDFONT FILE POINTERS IN A GLOBAL ARRAY for m = 0 to 1 if m = 0 then 'check user banks first f = SpecialFolder.UserHome.Child("Library").Child("Audio").Child("Sounds").Child("Banks") else 'then check system banks f = Volume(0).Child("Library").Child("Audio").Child("Sounds").Child("Banks") end if if f <> Nil then if f.Directory then if f.Count > 0 then 'add each soundfont for j = 1 to f.Count f.item(j).ExtensionVisible = true if lowercase(right(f.item(j).name,4)) = ".sf2" then 'don't add duplicate files if soundfontList.IndexOf(f.item(j)) = -1 then soundfontList.append f.item(j) end if end if next end if end if end if next End Sub
Sub setup() dim j as integer settingUp = true //SYNTH theSynth = new MidiPlaybackMBS(true) if theSynth.Inited=false then msgbox "Synth failed to initialize." quit Return end if //BUILD SOUNDFONT LIST scanSoundfonts //SAMPLE SET POPUP samplePop.DeleteAllRows 'QT synth samplePop.AddRow "Quicktime Instruments" samplePop.AddSeparator 'SoundFonts for j = 0 to UBound(soundfontList) samplePop.Addrow NthField(soundfontList(j).name, ".", 1) next //DEFAULT PATCH LIST for j = 0 to 127 patch.Append trim(theSynth.InstrumentName(j)) next revCheck.Value=theSynth.UsesInternalReverb streamCheck.Value=theSynth.StreamFromDisk tunSlider.Value=theSynth.Tuning revSlider.Value=theSynth.ReverbVolume volSlider.Value=theSynth.Volume settingUp = false //DEFAULT SAMPLE SET and PATCH samplePop.ListIndex = 0 patchPop.ListIndex = 0 End Sub
Property ch As Integer
MIDI channel
Property patch() As string
list of available patches for the current sample set
Property scaleTone As Integer
scale tone number for Play Scale timer
Property settingUp As boolean
tells popup menus whether to react to Change events
Property soundFontList() As folderItem
references to sound font files installed in system + user sound bank library
Property theSynth As MidiPlaybackMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

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


The biggest plugin in space...