This is an old revision of the document!
Mozaic: CC-Switch
by mbncp ( Link to thread )
// CC-Switch (Mozaic v1.03)
// Allows the use of a Controller to act like a switch
// Usefull with controllers that return to their initial position once you release them
// The state is stored for each midi channel
// Off course you can also use the pads
@OnLoad
// Adjust to your needs
TrigCC = 64 // Incoming CC to make it act like a switch
OutCC = 64 // CC to send on switch change
CCVal = [0,127] // CC value on switch OFF, ON
CCValRange = 15 // CC input value tolerance, for a knob use 64
//
FillArray TrigState, 0,16 // keep state of all channels
FillArray TrigReset, 1,16
SetShortName {Switch}
LabelPads {CC }, OutCC, { State for Chn 1-16}
ShowLayout 2
for n = 0 to 15
LabelPad n, n+1
endfor
Call @UpdateGUI
@End
@OnMidiInput
If MIDICommand = 0xB0 And MIDIByte2 = TrigCC
If MidiByte3 > (127 - CCValRange) And TrigReset[MIDIChannel]
TrigState[MIDIChannel] = not TrigState[MIDIChannel]
SendMIDICC MIDIChannel, OutCC, CCVal[TrigState[MIDIChannel]]
TrigReset[MIDIChannel] = 0
Call @UpdateGUI
ElseIf MidiByte3 < CCValRange
TrigReset[MIDIChannel] = 1
EndIf
Else
SendMIDIThru
EndIf
@End
@OnPadUp
TrigState[LastPad] = not TrigState[LastPad]
SendMIDICC LastPad, OutCC, CCVal[TrigState[LastPad]]
TrigReset[LastPad] = 1
Call @UpdateGUI
@End
@UpdateGUI
for n = 0 to 15
LatchPad n, TrigState[n]
endfor
@End