Mutually exclusive buttons & open window

 Print (ModifierKeys() )
1 Like

ahā€¦ and you have to compile while holding down the modifier to get the results:

  • SHIFT = 1
  • CTRL = 2
  • SHIFT + CTRL = 3
  • ALT = 4
  • SHIFT + ALT = 5
  • CTRL+ALT = 6
  • SHIFT + CTRL + ALT = 7

So what I can not test for is right-click and if I change the script to use CTRL or ALTā€¦ right click doesnā€™t function in a modified way so I just wanted to see if this was a known possibility?

Or put it inside a widget callback and then just turn a button while holding down keys

I wanted to ask a follow up question here because itā€™s really a variation of sorts on this original idea.

I have three buttons: btn1, btn2, btn3.

I have another button: btn_z

I want any of the first three buttons to be able to turn on btn_z and I want the absence of all of them on to turn off btn_z. If I only turn off btn1 and btn2 for instance and btn3 is onā€¦ I want btn_z to remain on.

This is what i have so far an itā€™s not working:

> On WidgetValueChanged (bval: double) from btn1
>     If bval == 1.0 Then
>         SetWidgetValue(btn_z, 1)
>     Elsif bval == 0 Then
>         SetWidgetValue(btn_z, 0)
>     End
> End
> 
> On WidgetValueChanged (bval: double) from btn2
>     If bval == 1.0 Then
>         SetWidgetValue(btn_z, 1)
>     Elsif bval == 0 Then
>         SetWidgetValue(btn_z, 0)
>     End
> End
> 
> On WidgetValueChanged (bval: double) from btn3
>     If bval == 1.0 Then
>         SetWidgetValue(btn_z, 1)
>     Elsif bval == 0 Then
>         SetWidgetValue(btn_z, 0)
>     End
> End

In this script if btn1, 2, or 3 is turned off, it turns off button_z.

I tried Or but that didnā€™t work out. And arguments donā€™t seem to apply in GPscript? Is this where one would use an array? I tried that but there is no ā€œOn ArrayValueChangedā€ option.

Thanks for any an all help with this.

bk

I posted a script in this thread for someone wanting a similar result as you.
Have a look and see if that helps.

In that script, StratBypass,TeleBypass, and LesPaulBypass are the equivalent of your btn1, btn2, btn3 and AmplitubeBypass is the equivalent of your btn_zā€¦

1 Like

@edm11

That was close to what I wanted but it got me to a place where I could get to where I wanted to go by tweaking so thank you for that. I was able to get ā€˜orā€™ working in place of your ā€˜andā€™ statements.

Attached is what I was ultimately afterā€¦ behaves like ā€˜soloā€™ mode does on a Mackie mixer:

> Var
> A : Double
> B : Double
> C : Double
> group1_btn : widget
> group2_btn : widget
> group3_btn : widget
> group5_btn : widget
> 
> On WidgetValueChanged(newValue : double) from group1_btn
> A = GetWidgetValue(group1_btn)
> B = GetWidgetValue(group2_btn)
> C = GetWidgetValue(group3_btn)
>     If A == 1.0 or B == 1.0 or C == 1.0
>         then SetWidgetValue(group5_btn,1.0)
>     Elsif newValue == 0.0
>         then SetWidgetValue(group5_btn,0.0)
>     End
> End
> 
> On WidgetValueChanged(newValue : double) from group2_btn
> A = GetWidgetValue(group1_btn)
> B = GetWidgetValue(group2_btn)
> C = GetWidgetValue(group3_btn)
>     If A == 1.0 or B == 1.0 or C == 1.0
>         then SetWidgetValue(group5_btn,1.0)
>     Elsif newValue == 0.0
>         then SetWidgetValue(group5_btn,0.0)
>     End
> End
> 
> On WidgetValueChanged(newValue : double) from group3_btn
> A = GetWidgetValue(group1_btn)
> B = GetWidgetValue(group2_btn)
> C = GetWidgetValue(group3_btn)
>     If A == 1.0 or B == 1.0 or C == 1.0
>         then SetWidgetValue(group5_btn,1.0)
>     Elsif newValue == 0.0
>         then SetWidgetValue(group5_btn,0.0)
>     End
> End
1 Like

I knew youā€™d pick that up quickly! Iā€™m glad it helped. Well done.

1 Like

@edm11

So I evolved this a bit further so that if the target button was already on the source buttons wouldnā€™t have any effect. This was to solve an issue where it was doing something unexpected elsewhere.

However when I added the and statementā€¦ while it complies and still works, the result is the or statement just before it, in this case the ā€œDā€ value, creates the issue where the ā€œDā€ button turns on and off the target button, but it gets ignored if any other button is the second to last to be turned off. No one cares what ā€œDā€ thinks!

I swapped A for D and got the same result only on the A button so it has something to do with the syntax of adding the ā€œandā€ argument right after the last ā€œorā€ argument.

hereā€™s just the last buttonā€™s script:

> On WidgetValueChanged(newValue : double) from group4_aux_send_btn
> A = GetWidgetValue(group1_aux_send_btn)
> B = GetWidgetValue(group2_aux_send_btn)
> C = GetWidgetValue(group3_aux_send_btn)
> D = GetWidgetValue(group4_aux_send_btn)
> E = GetWidgetValue(group5_btn1)
>     If A == 1.0 or B == 1.0 or C == 1.0 **or D == 1.0 and E == 0.0**
>         then SetWidgetValue(group5_btn1,1.0)
>     Elsif newValue == 0.0
>         then SetWidgetValue(group5_btn1,0.0)
>     End
> End

Would you have any guidance on how to fix this so D isnā€™t ignored by A, B or C?

Many thanks.

Hmmm, if you had the arithmetic expression

 1 + 2 + 3 + 4 * 5

what value do you expect this to evaluate to (without actually trying it in GP Script)

fifty or twentysix

dunno

@dhj are you implying that

If A == 1.0 or B == 1.0 or C == 1.0 or D == 1.0 and E == 0.0

gets evaluated in the script as

If A == 1.0 or B == 1.0 or C == 1.0 or (D == 1.0 and E == 0.0)
?

1 Like

Yes !

twenty six is the correct answer with conventional precedence rules

@dhj

So what I really want, following your analogy is:

1 * 5 + 2 * 5 + 3 * 5 + 4 * 5
(= 50)

Soā€¦

If A == 1.0 and E == 0.0 or B == 1.0 and E == 0.0 or C == 1.0 and E == 0.0 or D == 1.0 and E == 0.0

?

that has the opposite effect I am after

Which is the same as
(1 + 2 + 3 + 4) * 5

I donā€™t know what you really want, I didnā€™t read your script in any detail, just noticed the end of that boolean and guessed you were probably being bitten by precedence. What you might have wanted (but again, I donā€™t know what youā€™re trying to do) is

 If (A == 1.0 or B == 1.0 or C == 1.0 or D == 1.0) and E == 0.0

that is more elegant that thisā€¦

ā€¦but it functions the same.

the result is that if A, B, C or D were once 1.0 but after a WidgetValueChanged are now 0.0, then E will now == 0.0

what I had originally which nearly worked as desired, (except that A, B and C were ignoring if D == 1.0) resulted in E == 0.0 unless A or B or C == 1.0 in which case E also == 1.0.

In plain English, Iā€™d like it if any button (ABCD) were turned on and E were off already, E gets turned onā€¦ but if (ABCD) buttons are all turned off then if E is on, E gets switched off. I had this working but I needed to add the disclaimer that if E were already on and ABCD gets switched on, E ignores any action because it was impacting something that E was linked to elsewhere.

When I added that ā€œandā€ argument it complicated things.

The only way I can think I can do this would likely take 16 full arguments per button to cross reference the state of any combinationā€¦ but I am sure there is a better way.

@brandon
Try this:

Var
   group1_aux_send_btn : Widget
   group2_aux_send_btn : Widget
   group3_aux_send_btn : Widget
   group4_aux_send_btn : Widget
   group5_btn1 : Widget
   A : double
   B : double
   C : double
   D : double
   E : double

On WidgetValueChanged(newValue : double) from group1_aux_send_btn
A = GetWidgetValue(group1_aux_send_btn)
B = GetWidgetValue(group2_aux_send_btn)
C = GetWidgetValue(group3_aux_send_btn)
D = GetWidgetValue(group4_aux_send_btn)
E = GetWidgetValue(group5_btn1)
    If A == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif B == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif C == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif D == 1.0
    then SetWidgetValue(group5_btn1,1.0)    
    Elsif newValue == 0.0
    then SetWidgetValue(group5_btn1,0.0)
End
End

On WidgetValueChanged(newValue : double) from group2_aux_send_btn
A = GetWidgetValue(group1_aux_send_btn)
B = GetWidgetValue(group2_aux_send_btn)
C = GetWidgetValue(group3_aux_send_btn)
D = GetWidgetValue(group4_aux_send_btn)
E = GetWidgetValue(group5_btn1)
    If A == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif B == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif C == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif D == 1.0
    then SetWidgetValue(group5_btn1,1.0)    
    Elsif newValue == 0.0
    then SetWidgetValue(group5_btn1,0.0)
End
End

On WidgetValueChanged(newValue : double) from group3_aux_send_btn
A = GetWidgetValue(group1_aux_send_btn)
B = GetWidgetValue(group2_aux_send_btn)
C = GetWidgetValue(group3_aux_send_btn)
D = GetWidgetValue(group4_aux_send_btn)
E = GetWidgetValue(group5_btn1)
    If A == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif B == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif C == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif D == 1.0
    then SetWidgetValue(group5_btn1,1.0)    
    Elsif newValue == 0.0
    then SetWidgetValue(group5_btn1,0.0)
End
End

On WidgetValueChanged(newValue : double) from group4_aux_send_btn
A = GetWidgetValue(group1_aux_send_btn)
B = GetWidgetValue(group2_aux_send_btn)
C = GetWidgetValue(group3_aux_send_btn)
D = GetWidgetValue(group4_aux_send_btn)
E = GetWidgetValue(group5_btn1)
    If A == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif B == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif C == 1.0
    then SetWidgetValue(group5_btn1,1.0)
    Elsif D == 1.0
    then SetWidgetValue(group5_btn1,1.0)    
    Elsif newValue == 0.0
    then SetWidgetValue(group5_btn1,0.0)
End
End
1 Like

yes! thank you. learning!

1 Like

Me tooā€¦

1 Like

Is there a way to have multiple actions from a WidgetValueChanged?

For instanceā€¦ this script opens a plugin window only when a modifier key is held down.:

On WidgetValueChanged (btval : double) from group1_btn1
if ModifierKeys() == 2
and btval > 0.5
then OpenPlugin(group1_sound1)
Else ClosePlugin(group1_sound1)
End
End

If I add another script after this that is also triggered from that same button i get this:

Semantic error in ā€œMainā€: On WidgetValueChanged already defined for this widget

What I would like to do is combine two functions into the same button.

  1. Open the plugin window when a modifier key is held down
  2. Bypass/Un-bypass toggle the plugin regardless if the modifier key is held down

I realize that Bypass is easily mapped as a plugin parameter but I want to script it to the plugin handle and not use the plugin itself.

I have tried adding SetPluginBypassed in the above script as an Elsif addendum but I end up with not a sufficient statement or an incompatible value.