====== Mozaic: CC-Switch ======
===== Original =====
by mbncp ( [[https://forum.audiob.us/discussion/comment/656597#Comment_656597|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
===== Modification =====
Per pad
* Channel
* CC
* Value for on and off state
all defined directly in the script code
// CC-Switch (Mozaic v1.03) mod by -ki
// main functionality by mbncp @ audiobus forum
// 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
CCValRange = 15 // CC input value tolerance, for a knob use 64
// A list of off/on CC values send, two numbers per pad
CCVal[ 0] = [0,127, 0,127, 0,127, 0,127] // CC Values for pads 0.. 3
CCVal[ 8] = [0,127, 0,127, 0,127, 0,127] // pads 4.. 7
CCVal[16] = [0,127, 0,127, 0,127, 0,127] // pad 8..11
CCVal[24] = [0,127, 0,127, 0,127, 0,127] // pad 12..15
OutCC[0] = [10,11,12,13,14,15,16,17] // CCs for upper row
OutCC[8] = [40,41,42,43,44,45,46,47] // CCs for lower row
OutCH[0] = [0,0,0,0,0,0,0,0] // Output channel (0..15) for upper row
OutCH[8] = [0,0,0,0,0,0,0,0] // Output channel (0..15) for lower row
//
FillArray TrigState, 0,16 // keep state of all channels
FillArray TrigReset, 1,16
SetShortName {Switch}
LabelPads {CC Switch}
LabelKnobs { }
for k = 0 to 3
LabelKnob k,{ }
SetKnobValue k,0
endfor
ShowLayout 2
for n = 0 to 15
LabelPad n, {CC },OutCC[n], { ----------- },{ch},OutCH[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]
idx = MIDIChannel * 2 + TrigState[MIDIChannel]
SendMIDICC OutCH[MIDIChannel], OutCC[MIDIChannel], CCVal[idx]
TrigReset[MIDIChannel] = 0
Call @UpdateGUI
ElseIf MidiByte3 < CCValRange
TrigReset[MIDIChannel] = 1
EndIf
Else
SendMIDIThru
EndIf
@End
@OnPadUp
TrigState[LastPad] = not TrigState[LastPad]
idx = LastPad * 2 + TrigState[LastPad]
SendMIDICC OutCH[LastPad], OutCC[LastPad], CCVal[idx]
TrigReset[LastPad] = 1
Call @UpdateGUI
@End
@UpdateGUI
for n = 0 to 15
LatchPad n, TrigState[n]
endfor
@End
{{tag>Mozaic midi_scripting}}