Alright… it became kind of a personal challenge to solve this problem.
I hope i understood everythig right…
You have on your keyboard two rows of three buttons each (lower/upper presets).
The lower row sends on CH8 and CC#79 where the buttons 1-3 each send out the CC values 0, 64, 127.
The upper row sends the same CC values but on CH9 and CC#80
Those three CC values shall be coverted to the note values A0, Bb0, B0 which then can be sent to a connected organ plugin.
If there are diffrences to that, you might have to edit the code and change the values to your needs.
But if all is right, you can just use this gig file, but you probably have to exchange the organ plugn since i don’t own the VB3 plugin (i used the Blue3)…
The GPscript behind it has become a bit extensive, but it should work… and i put many comments into it, so you might see what the code is doing.
var
btn_u1, btn_u2, btn_u3, btn_l1, btn_l2, btn_l3 : Widget //used button's names
u_last, l_last : Integer // buffer variables to store the last pressed button
//Declaration of widget arrays for upper and lower preset buttons
u_buttons : Widget Array = [btn_u1, btn_u2, btn_u3]
l_buttons : Widget Array = [btn_l1, btn_l2, btn_l3]
//MIDI IN and OUT ports
CX3_midi_in : MidiInBlock
//##################### Values for UPPER preset keys ###################
u_ch : Integer = 9 //UPPER MIDI channel
//CC# see ControlChange Callback
u_ccval1 : Integer = 0 //cc value 1
u_ccval2 : Integer = 64 //cc value 2
u_ccval3 : Integer = 127 //cc value 3
u_note1 : Integer = A0 //note 1
u_note2 : Integer = Bb0 //note 2
u_note3 : Integer = B0 //note 3
u_ccvals : Integer Array = [u_ccval1, u_ccval2, u_ccval3]
u_notes : Integer Array = [u_note1, u_note2, u_note3]
//##################### Values for LOWER preset keys ###################
l_ch : Integer = 8 //LOWER MIDI channel
//CC# see ControlChange Callback
l_ccval1 : Integer = 0 //cc value 1
l_ccval2 : Integer = 64 //cc value 2
l_ccval3 : Integer = 127 //cc value 3
l_note1 : Integer = A0 //note 1
l_note2 : Integer = Bb0 //note 2
l_note3 : Integer = B0 //note 3
l_ccvals : Integer Array = [l_ccval1, l_ccval2, l_ccval3]
l_notes : Integer Array = [l_note1, l_note2, l_note3]
Initialization //Called on first run
var i : Integer
//Check & store state of buttons - if all off, assume the first as "ON"
For i = 0; i < Size(u_buttons); i = i + 1 Do
If GetWidgetValue(u_buttons[i]) == 1.0 Then
u_last = i
Else
u_last = 0
End
End
For i = 0; i < Size(l_buttons); i = i + 1 Do
If GetWidgetValue(l_buttons[i]) == 1.0 Then
l_last = i
Else
l_last = 0
End
End
End
//Called when a CC message is received at some MidiIn block
//The CC numbers must be within the specified range
On ControlChangeEvent(m : ControlChangeMessage) Matching [79..80] from CX3_midi_in
//Check for CC# and mark button row 0 will be LOWER, 1 will be UPPER
If GetCCNumber(m) == 79 Then //react to LOWER buttons
Select
GetCCValue(m) == l_ccval1 do
SetWidgetValue (l_buttons[0],1.0)
GetCCValue(m) == l_ccval2 do
SetWidgetValue (l_buttons[1],1.0)
GetCCValue(m) == l_ccval3 do
SetWidgetValue (l_buttons[2],1.0)
End
Elsif GetCCNumber(m) == 80 Then //react to UPPER buttons
Select
GetCCValue(m) == u_ccval1 do
SetWidgetValue (u_buttons[0],1.0)
GetCCValue(m) == u_ccval2 do
SetWidgetValue (u_buttons[1],1.0)
GetCCValue(m) == u_ccval3 do
SetWidgetValue (u_buttons[2],1.0)
End
End
End
// Called when any of several widgets changed -> This is the block for UPPER presets
On WidgetValueChanged(w : Widget, index: integer, newValue : double) from btn_u1, btn_u2, btn_u3
var i : integer
if newValue == 1.0 and index <> u_last then
// Set
Print("UPPER Notevalue sent: " + u_notes[index])
SendNow(CX3_midi_in, MakeNoteMessageEx(u_notes[index], 100, u_ch))
SendLater(CX3_midi_in, MakeNoteMessageEx(u_notes[index], 0, u_ch),200)
// Deselect other buttons
for i = 0; i < Size(u_buttons); i = i + 1 do
if i <> index then SetWidgetValue(u_buttons[i],0.0) end
end
u_last = index
end
If newValue == 0.0 and index == u_last Then
SetWidgetValue(u_buttons[index],1.0)
End
End
// Called when any of several widgets changed -> This is the block for LOWER presets
On WidgetValueChanged(w : Widget, index: integer, newValue : double) from btn_l1, btn_l2, btn_l3
var i : integer
if newValue == 1.0 and index <> l_last then
// Set
Print("LOWER Notevalue sent: " + l_notes[index])
SendNow(CX3_midi_in, MakeNoteMessageEx(l_notes[index], 100, l_ch))
SendLater(CX3_midi_in, MakeNoteMessageEx(l_notes[index], 0, l_ch),200)
// Deselect other buttons
for i = 0; i < Size(l_buttons); i = i + 1 do
if i <> index then SetWidgetValue(l_buttons[i],0.0) end
end
l_last = index
end
If newValue == 0.0 and index == l_last Then
SetWidgetValue(l_buttons[index],1.0)
End
End
CX3-Buttons.gig (90.0 KB)
Good luck with that, and if you have questions: Don’t hesitate to ask!
Cheers!
Erik