Hello all,
i finally succeeded in mimicking a DCA-behaviour in Gig Performer via GP-Script.
The regarding rackspace has three faders, a knob and a switch…
The switch changes between “direct mode” and “relative mode”, means:
Direct mode:
- the knob will vanish and you can adjust the three faders independently at will
- this will then be the initial positions for the “relative movement”
Relative mode:
- the knob will be shown and take the value of the highest fader position
- movement of the individual faders will be blocked
- moving the knob will move all faders together, respecting their relative positions to each other
- the faders won’t move further if the fader with the max. position has reached the top
- the faders can be moved to "flat zero but will return to their relative positions
when climbing higher again
This is how it looks like:
This is the rackspace file (download & import it):
Relative Faders.rackspace (86.7 KB)
And this is the code:
var
// the widgets used
knb_rel : widget
fdr1, fdr2, fdr3 : widget
swt_rel : widget
//the arrays used
faders : widget array = [fdr1, fdr2, fdr3]
fdr_buffers : double array = [0.0,0.0,0.0]
fdr_offsets : double array = [0.0,0.0,0.0]
maxfader_index : integer // stores the fader-array index nr. with the largest value
maxfader_value : double // stores the actual largest fader value
faderlock : boolean // auxiliary flag if fader movement should be blocked
knb_rel_old : double // stores the "old" value of the relative knob
waiting_time : double = 20 //time to wait in ms
move_start : double //the moment the widget started to change
// user function to store the actual fader position into an array
function calc_buffers ()
var i : integer
for i=0; i<Size(fdr_buffers); i=i+1 Do
fdr_buffers[i] = GetWidgetValue (faders[i])
end
End
// user function to get the max value and index and update the fader-buffers
function calc_maxfader(index : integer, fdr_val : double)
fdr_buffers [index] = fdr_val
maxfader_value = LargestDouble(fdr_buffers)
maxfader_index = iMax(fdr_buffers)
// if the relative mode switch is ON then also adjust the rel.knob according to the max fader value
if GetWidgetValue (swt_rel) == 1.0 Then
SetWidgetValue (knb_rel, maxfader_value)
end
End
// user function to calculate the relative positions of the faders to the max. as negative offsets
function calc_offsets ()
var i : integer
for i=0; i<Size(fdr_buffers); i=i+1 Do
fdr_offsets[i] = fdr_buffers[i]-maxfader_value
end
knb_rel_old = maxfader_value //set the rel. knob accordingly to the max. fader value
End
// user function to move all faders together, relatively to the rel. knob's position
// and respecting their offset to the max.
function move_relative(kval:double)
var i : integer
faderlock = false //the faders may move now!
//loop through the offset-array and set the faders accordingly
for i=0; i<Size(fdr_offsets); i=i+1 Do
SetWidgetValue (faders[i], kval + fdr_offsets[i])
end
End
// will be executed on first use of the rackspace (or on compile)
Initialization
var i : integer
// get the initial fader-situation and max-value/index
for i=0; i<Size(faders); i=i+1 Do
calc_maxfader (i, GetWidgetValue (faders[i]))
end
//check the initial state of the relative-mode switch and set faderlock accordingly
if GetWidgetValue (swt_rel) == 1.0 Then //relative mode switch enabled?
faderlock = true
else
faderlock = false
end
// get the initial position of the rel.knob and store in buffer variable
knb_rel_old = GetWidgetValue (knb_rel)
calc_offsets() // get the initial offset situation for the fader values
End
// timer routine which works as a time-out for knob-movement
On TimerTick(ms : double)
If ms - move_start > waiting_time Then // if the waiting time is up then
SetTimersRunning(false) // stop the timer
calc_buffers() // refresh buffers
faderlock = true // prevent fader movement
End
End
// this happens when the faders move (multi-widget operation)
On WidgetValueChanged(w : Widget, index: integer, fval : double) from fdr1, fdr2, fdr3
if GetWidgetValue (swt_rel) == 0.0 and faderlock == false Then //relative mode disabled and faders unlocked?
calc_maxfader (index, fval) //yes: calculate the max-values and the buffers
Elsif faderlock == true Then //movement frozen
SetWidgetValue (faders[index], fdr_buffers[index]) //set the widgets to the (old) buffer values -> no movement
end
End
// this happens when the relative knob moves
On WidgetValueChanged (kval : double) from knb_rel
if GetWidgetValue (swt_rel) == 1.0 Then //relative mode switch enabled?
faderlock = false // allow fader movement
// start timer to wait for time-out
// -> while time is running the "On TimerTick()" routine will be permanently checked!
move_start = TimeSinceStartup() // get the starting moment
SetTimersRunning(true) // GO!
move_relative (kval)// now set all faders accordingly to the rel. knob
else //no relative mode: freeze the knob position to knb_rel_old
SetWidgetValue (knb_rel, knb_rel_old) // restore former position from buffer
end
End
// This happens when the relative switch is triggered
On WidgetValueChanged (sval : double) from swt_rel
if sval > 0.6 then // if relative-mode = ON
calc_offsets() // refresh offset values of the fader array
SetWidgetHideOnPresentation(knb_rel, false) // un-hide the reative knob
SetWidgetValue (knb_rel, maxfader_value) // set knob to the max. fader value
else // if relative mode = OFF
SetWidgetHideOnPresentation(knb_rel, true) // hide knob
faderlock = false // allow fader movement
end
End