Hello all. I’m taking a crack at my first custom function, after @dhj graciously demonstrated their power to me in another thread.
I have a Fantom 6 workstation, and I was hoping to create a Rackspace with two widgets that could control the “scene” selection. The Fantoms are arranged in 4 banks (A, B, C, D) with 127 programs in each bank. The workstation listens for bank and program messages on channel 16, by default.
First, I created a lengthy script in my usual, inelegant fashion until it was accomplishing what I wanted: one knob to control the scene banks, and one to select the program. The midi message is sent when either one of the knobs is turned.
The code is:
var fantom_bank, fantom_program, toggle: Widget
var fantomMSB : Integer = 85
var fantomChannel : Integer = 16
var fantomOut : MidiOutBlock
On WidgetValueChanged(w: Widget, index: Integer, newValue: Double) from fantom_bank, fantom_program
var fantomLSB : Integer
var fantomMSB: Integer = 85
var fantomChannel : Integer = 16
var fantomProgramNumber : Integer
if index == 0 then
fantomLSB = ScaleRange(newValue, 0, 3)
if fantomLSB == 0 then
SetWidgetLabel(fantom_bank, "A")
elsif fantomLSB == 1 then
SetWidgetLabel(fantom_bank, "B")
elsif fantomLSB == 2 then
SetWidgetLabel(fantom_bank, "C")
elsif fantomLSB == 3 then
SetWidgetLabel(fantom_bank, "D")
end
fantomProgramNumber = ScaleRange(GetWidgetValue(fantom_program), 0, 127)
elsif index == 1 then
fantomLSB = ScaleRange(GetWidgetValue(fantom_bank), 0, 3)
fantomProgramNumber = ScaleRange(newValue, 0, 127)
SetWidgetLabel(fantom_program, fantomProgramNumber + 1)
End
SendNowExternal(fantomOut, MakeControlChangeMessageEx(0, fantomMSB, fantomChannel))
SendNowExternal(fantomOut, MakeControlChangeMessageEx(32, fantomLSB, fantomChannel))
SendNowExternal(fantomOut, MakeProgramChangeMessageEx(fantomProgramNumber, fantomChannel))
end
Next, I attempted to write a custom function that would simplify it. I really thought I’d done it; testing the two different rackspaces with a MIDI monitor on the output I was getting the exact same messages. However, when physically connected to my Fantom, only the first script works. The second does nothing. The custom function version is:
//ROLAND FANTOM PRESET SELECTOR//
var fantom_bank, fantom_program: Widget
var fantomOut : MidiOutBlock //this midi out block must exist and be routed physically to your Fantom
var fantomMSB : Integer = 85 //85 is the default MSB for the Fantom
var fantomLSB : Integer //LSB will be set by the Fantom widget
var fantomProgramNumber : Integer //Integer value of the fantom program change
var fantomChannel : Integer = 16 //ch 16 is the default channel for receiving scene control on Fantom, change if you change inside the fantom
var fantomSceneBank : String Array = ["A", "B", "C", "D"] //scene banks in the fantom are categorized as A000-D127
Function SetFantomScene (fantomMSB : Integer, fantomProgramNumber : Integer, fantomChannel: Integer)
fantomLSB = ScaleRange(GetWidgetValue(fantom_bank), 0, 3) //Scales the fantom_program widget to an integer between 0 and 3
fantomProgramNumber = ScaleRange(GetWidgetValue(fantom_program), 0, 127) //Labels the fantom_program widget based on the scaled value
SetWidgetLabel(fantom_bank, fantomSceneBank[fantomLSB])//Labels the fantom_bank widget based on fantomSceneBank String Array
SetWidgetLabel(fantom_program, fantomProgramNumber + 1)//Offset the label by 1 to match the Fantom's display
SendNowExternal(fantomOut, MakeControlChangeMessageEx(0, fantomLSB, fantomChannel)) //LSB
SendNowExternal(fantomOut, MakeControlChangeMessageEx(32, fantomMSB, fantomChannel))//MSB
SendNowExternal(fantomOut, MakeProgramChangeMessageEx(fantomProgramNumber, fantomChannel))//Program Change Message
End
On WidgetValueChanged(newValue: Double) from fantom_bank, fantom_program
SetFantomScene (fantomMSB, fantomProgramNumber, fantomChannel)
end
I’m trying to understand where I’ve gone astray. I just can’t understand why I would be getting identical outgoing messages, and yet the second option doesn’t control the scenes on the workstation. Please help if you see something wrong.
Fantom Controller.gig (83.5 KB)