I just worked on this topic last week and here is how I do it:
Master_Ratio_Fader_GP4.gig (118.8 KB)
var
FADER_1, FADER_2,FADER_3,FADER_4,FADER_5,FADER_6,FADER_7,FADER_8, FADER_M : Widget;
FADER : widget array = [FADER_1, FADER_2,FADER_3,FADER_4,FADER_5,FADER_6,FADER_7,FADER_8];
FADER_LoopBlocker : Integer array = [0, 0, 0, 0, 0, 0, 0, 0];
FADER_M_LoopBlocker : Integer = 0;
faderValue : double array = [FADER_1.GetWidgetValue(), FADER_2.GetWidgetValue(), FADER_3.GetWidgetValue(), FADER_4.GetWidgetValue(),
FADER_5.GetWidgetValue(), FADER_6.GetWidgetValue(), FADER_7.GetWidgetValue(), FADER_8.GetWidgetValue()];
function NormalizeToMax(value : double array) // change the name as it doesn't take care of zeros
Var
i : integer;
idOfMax : integer = iMax(value);
normalizingValue : double = value[idOfMax];
If value[idOfMax] != 1.0
Then
If normalizingValue != 0.0
Then
For i=0; i<value.Size(); i=i+1 Do value[i] = value[i] / normalizingValue; End
Else
For i=0; i<value.Size(); i=i+1 Do value[i] = 1.0; End
End
End
End
On WidgetValueChanged(FADER_i : Widget, i : integer, newValue : double) from FADER_1, FADER_2,FADER_3,FADER_4,FADER_5,FADER_6,FADER_7,FADER_8
Var
volumeMax : double;
If FADER_LoopBlocker[i] == 0
Then
faderValue[i] = newValue / (FADER_M.GetWidgetValue()+0.000001);
NormalizeToMax(faderValue);
volumeMax = GetWidgetValue(FADER[iMax(faderValue)]);
If FADER_M.GetWidgetValue() != volumeMax
Then
FADER_M.SetWidgetValue(volumeMax);
FADER_M_LoopBlocker = FADER_M_LoopBlocker+1;
End
Else
FADER_LoopBlocker[i] = FADER_LoopBlocker[i]-1;
End
End
On WidgetValueChanged (newValue : double) from FADER_M
Var
i :integer;
If FADER_M_LoopBlocker == 0
Then
For i=0; i<faderValue.Size(); i=i+1
Do // Test necessary to avoir incrementing the locker while hte callbac won't be called if the set value is identical
If GetWidgetValue(FADER[i]) != faderValue[i] * newValue Then SetWidgetValue(FADER[i], faderValue[i] * newValue); FADER_LoopBlocker[i] = FADER_LoopBlocker[i]+1; End
End
Else
FADER_M_LoopBlocker = FADER_M_LoopBlocker-1;
End
End
On Variation(oldVariation : integer, newVariation : integer)
Var i : Integer=0;
For i=0; i<FADER.Size(); i=i+1 Do faderValue[i]=GetWidgetValue(FADER[i]); End
NormalizeToMax(faderValue);
FADER_M_LoopBlocker = 1;
FADER_M.SetWidgetValue(GetWidgetValue(FADER[iMax(faderValue)]));
End
Initialization
NormalizeToMax(faderValue);
FADER_M_LoopBlocker = 1;
FADER_M.SetWidgetValue(GetWidgetValue(FADER[iMax(faderValue)]));
End