Thanks, pianopaul!
In the meantime I found a tricky solution myself. Here is the code snipped just for the Oboe.
The declarations in the beginning and the callback functions at the end have to be repeated for every instrument. The functions in the middle are fully parameterized.
Works like a charm now! And it doesn’t bother me anymore, that the LED can be pressed manually. It’s just the same as if you press the keyswitch on the keyboard.
// DO NOT EDIT THIS SECTION MANUALLY
Var
OboeMidi : MidiInBlock
OboeA : Widget
OboeB : Widget
OboeAis : Widget
OboeLedB : Widget
OboeLedAis : Widget
OboeLedA : Widget
//$</AutoDeclare>
OboeRadio : Widget Array
OboeLed : widget Array
initialization
var i : integer
OboeRadio = [OboeA,OboeAis,OboeB]
OboeLed = [OboeLedA,OboeLedAis,OboeLedB]
end
// **** sends Note to MidiInBlock
Function SendKeySwitch (MidiBlock: MidiInBlock, Note: integer)
var Message: MidiMessage
Message:= MakeNoteMessage(Note, 100)
Print (Note)
SendNow(MidiBlock,Message) // send with low Velocity
SendNow(MidiBlock,ReinterpretAsNoteOffMessage(Message)) //and Note Off
End
// **** when RadioButton is pressed ****
Function SetRadio(MidiBlock: MidiInBlock, LedArray: Widget Array, RadioArray: Widget Array, StartKey: integer, Index : integer, Value : Double)
var i: integer
if Value>0 then // has the button been activated?
SetWidgetValue(LedArray[Index], 1)
for i = 0; i < Size(RadioArray); i = i + 1 do // deactivate all others
if not (i==Index) then
SetWidgetValue(RadioArray[i], 0)
SetWidgetValue(LedArray[i], 0)
end
end
end
End
// **** when an LED is activated ****
Function SetLed(MidiBlock: MidiInBlock, LedArray: Widget Array, StartKey: integer, Index : integer, Value : Double)
var i: integer
if Value>0 then // has the LED been activated?
SendKeySwitch (MidiBlock, StartKey+Index) // send KeySwitch Note
for i = 0; i < Size(LedArray); i = i + 1 do // deactivate all others
if not (i==Index) then
SetWidgetValue(LedArray[i], 0)
end
end
end
End
// **** when a KeySwitch has been pressed manually on the keyboard ****
Function ManualKeyswitch(MidiBlock: MidiInBlock, LedArray: Widget Array, StartKey: integer, Note:NoteMessage)
var Index: integer
Index:=GetNoteNumber(Note)-StartKey
SetWidgetValue(LedArray[Index], 1)
end
On WidgetValueChanged(val : double) from OboeA
SetRadio(OboeMidi, OboeLed, OboeRadio, A-1, 0, val)
end
On WidgetValueChanged(val : double) from OboeAis
SetRadio(OboeMidi, OboeLed, OboeRadio, A-1, 1, val)
end
On WidgetValueChanged(val : double) from OboeB
SetRadio(OboeMidi, OboeLed, OboeRadio, A-1, 2, val)
end
On WidgetValueChanged(val : double) from OboeLedA
SetLed(OboeMidi, OboeLed, A-1, 0, val)
end
On WidgetValueChanged(val : double) from OboeLedAis
SetLed(OboeMidi, OboeLed, A-1, 1, val)
end
On WidgetValueChanged(val : double) from OboeLedB
SetLed(OboeMidi, OboeLed, A-1, 2, val)
end
On NoteOnEvent(Note: NoteMessage) From OboeMidi
if Note in [A-1..B-1] then
ManualKeyswitch(OboeMidi, OboeLed, A-1, Note)
else
SendNow(OboeMidi, Note)
end
end