Go Back   Cockos Incorporated Forums > REAPER Forums > newbieland

Reply
 
Thread Tools Display Modes
Old 04-15-2021, 09:31 AM   #1
MixR
Human being with feelings
 
Join Date: Jan 2017
Location: London
Posts: 328
Default [Solved] Best way to enable/disable mousehwheel action via toolbar

I have the action Script: Move contents of items left right by grid unit (mousewheel).lua set to alt+mousewheel but keep accidentally using it. Therefore I would like to toggle it via a toolbar icon/action.
When I create a toolbar action, however, it runs the command as opposed to enabling/disabling it. Seeing there is no universal toggle enable/disable following action command I am scratching my head.
__________________
PC Ryzen 7950x|W11 Pro|Reaper (latest)
2x RME HDSPe MADI FX | SSL UF8|UF1|UC1
PC Ryzen 5950X|W11 Pro|AudioGridder Server

Last edited by MixR; 04-21-2021 at 03:48 AM.
MixR is offline   Reply With Quote
Old 04-16-2021, 01:30 PM   #2
AB1
Human being with feelings
 
Join Date: Apr 2020
Location: UK
Posts: 79
Default

https://forum.cockos.com/showthread.php?t=245955

Have not tested this with a mousewheel triggered action. Let us know if it works.
AB1 is offline   Reply With Quote
Old 04-17-2021, 12:43 PM   #3
AB1
Human being with feelings
 
Join Date: Apr 2020
Location: UK
Posts: 79
Default

Was able to test this today. Yes, it works.
AB1 is offline   Reply With Quote
Old 04-20-2021, 02:17 AM   #4
MixR
Human being with feelings
 
Join Date: Jan 2017
Location: London
Posts: 328
Default

Quote:
Originally Posted by AB1 View Post
Was able to test this today. Yes, it works.
Thank you so much for your reply and suggestion.
Having tried to follow the instructions in the post you linked to I am failing at getting this to work. My cycle action is:
Code:
IF
_S&M_DUMMY_TGL1
_RS5e9f46d126ea0ab3066f4d00aac191f9f6d85112 (Script: Move contents of items left right by grid unit (mousewheel).lua)
 ENDIF
With the action above assigned to the shortcut alt+Mousewheel
nothing happens - the assigned action is never triggered regardless of the toolbar action's state.
__________________
PC Ryzen 7950x|W11 Pro|Reaper (latest)
2x RME HDSPe MADI FX | SSL UF8|UF1|UC1
PC Ryzen 5950X|W11 Pro|AudioGridder Server

Last edited by MixR; 04-20-2021 at 02:23 AM.
MixR is offline   Reply With Quote
Old 04-20-2021, 03:15 AM   #5
AB1
Human being with feelings
 
Join Date: Apr 2020
Location: UK
Posts: 79
Default

You're welcome.

You have probably already done this but just check that your toolbar button is set to the same dummy toggle as in the cycle action and that the toolbar button highlight toggles on and off to confirm that it is working. You should also see the 'state' column in the action list showing the on or off state, though this does not update in real time so you will need to close and re-open the action list window or something like that to get the state to update.

Your cycle action looks good although in my cycle action editor I do not see the script description directly following the command ID (it is in the next column) although that may just be how you have copied and pasted into this forum post. There should also not be a space before the ENDIF. Make sure you added these items to the cycle action by right clicking and choosing the appropriate option rather than just typing them in. I'm sure you did it right but just in case. Also check you 'apply' the action and that your chosen keyboard shortcut is then set to the cycle action rather than the action or script you actually want to trigger.

The other thing you could try is setting up another cycle action using dummy toggle 2 and a native REAPER action rather than a script, with a simple keyboard shortcut rather than one that uses the mousewheel. The mousewheel DOES work but just to keep things simple to get it working.
AB1 is offline   Reply With Quote
Old 04-20-2021, 04:18 AM   #6
MixR
Human being with feelings
 
Join Date: Jan 2017
Location: London
Posts: 328
Default

Quote:
Originally Posted by AB1 View Post
You're welcome.

You have probably already done this but just check that your toolbar button is set to the same dummy toggle as in the cycle action and that the toolbar button highlight toggles on and off to confirm that it is working. You should also see the 'state' column in the action list showing the on or off state, though this does not update in real time so you will need to close and re-open the action list window or something like that to get the state to update.

Your cycle action looks good although in my cycle action editor I do not see the script description directly following the command ID (it is in the next column) although that may just be how you have copied and pasted into this forum post. There should also not be a space before the ENDIF. Make sure you added these items to the cycle action by right clicking and choosing the appropriate option rather than just typing them in. I'm sure you did it right but just in case. Also check you 'apply' the action and that your chosen keyboard shortcut is then set to the cycle action rather than the action or script you actually want to trigger.

The other thing you could try is setting up another cycle action using dummy toggle 2 and a native REAPER action rather than a script, with a simple keyboard shortcut rather than one that uses the mousewheel. The mousewheel DOES work but just to keep things simple to get it working.
Thank you for the great troubleshooting instructions. I have checked all the above (and yes, I pasted the action text in for readability) but am still getting nothing.
However, a second dummy action/toolbar button with a keyboard shortcut does work so it looks that I have done everything correctly in principle
__________________
PC Ryzen 7950x|W11 Pro|Reaper (latest)
2x RME HDSPe MADI FX | SSL UF8|UF1|UC1
PC Ryzen 5950X|W11 Pro|AudioGridder Server
MixR is offline   Reply With Quote
Old 04-20-2021, 04:25 AM   #7
AB1
Human being with feelings
 
Join Date: Apr 2020
Location: UK
Posts: 79
Default

Hmmm. That's odd. It may be possible that particular script is bypassing the normal shortcut system and doing its own keypress and/or mousewheel detection. That might explain it. I don't have access to ReaPack on this computer so cannot have a look at it right now but will get to it later today.
AB1 is offline   Reply With Quote
Old 04-20-2021, 06:12 AM   #8
AB1
Human being with feelings
 
Join Date: Apr 2020
Location: UK
Posts: 79
Default

Looks like the script you are using is not in ReaPack but I found the thread where it likely came from.

If this is it...
https://forum.cockos.com/showthread.php?t=245914
...then I was right about the problem.

The 'reaper.get_action_context()' function is getting the mousewheel up or down state directly, as the script is triggered. But using a cycle action 'in between' the shortcut and the script means the script is not triggered DIRECTLY by the mousewheel so there is no 'action context' for the mousewheel and the script does not run as expected.

OK. Plan B. Keep the dummy toggle on your toolbar but ditch the cycle action. I use scripts for even the simplest custom actions and this is a good example of why.

Try this as your Alt+Mousewheel script. Don't forget to paste in YOUR commandID's for the other 2 scripts within this one.

Code:
togState = reaper.GetToggleCommandState(reaper.NamedCommandLookup("_S&M_DUMMY_TGL1"))
if togState == 1 then
  newValue,_ ,_ ,_,_,_ , val = reaper.get_action_context()
  if newValue then
      if val > 0 then
        reaper.Main_OnCommand(reaper.NamedCommandLookup("_RS61d51f1869daa4307621c3969136eb2b1ff20713"), 0) -- Script: me2beats_Move item content left one grid unit.lua
      else
        reaper.Main_OnCommand(reaper.NamedCommandLookup("_RSd2eaaeb59f562f0366fcf689fe210d070cc207b7"), 0) -- Script: me2beats_Move item content right one grid unit.lua
      end
  end
end
AB1 is offline   Reply With Quote
Old 04-21-2021, 03:48 AM   #9
MixR
Human being with feelings
 
Join Date: Jan 2017
Location: London
Posts: 328
Default

Quote:
Originally Posted by AB1 View Post
Looks like the script you are using is not in ReaPack but I found the thread where it likely came from.

If this is it...
https://forum.cockos.com/showthread.php?t=245914
...then I was right about the problem.

The 'reaper.get_action_context()' function is getting the mousewheel up or down state directly, as the script is triggered. But using a cycle action 'in between' the shortcut and the script means the script is not triggered DIRECTLY by the mousewheel so there is no 'action context' for the mousewheel and the script does not run as expected.

OK. Plan B. Keep the dummy toggle on your toolbar but ditch the cycle action. I use scripts for even the simplest custom actions and this is a good example of why.

Try this as your Alt+Mousewheel script. Don't forget to paste in YOUR commandID's for the other 2 scripts within this one.

Code:
togState = reaper.GetToggleCommandState(reaper.NamedCommandLookup("_S&M_DUMMY_TGL1"))
if togState == 1 then
  newValue,_ ,_ ,_,_,_ , val = reaper.get_action_context()
  if newValue then
      if val > 0 then
        reaper.Main_OnCommand(reaper.NamedCommandLookup("_RS61d51f1869daa4307621c3969136eb2b1ff20713"), 0) -- Script: me2beats_Move item content left one grid unit.lua
      else
        reaper.Main_OnCommand(reaper.NamedCommandLookup("_RSd2eaaeb59f562f0366fcf689fe210d070cc207b7"), 0) -- Script: me2beats_Move item content right one grid unit.lua
      end
  end
end
Thank you!
That worked very nicely. Unfortunately even this basic level of coding is too difficult for me - though I do understand what each step is supposed to be doing. But how on earth I would ever be able to do this myself I have no idea
__________________
PC Ryzen 7950x|W11 Pro|Reaper (latest)
2x RME HDSPe MADI FX | SSL UF8|UF1|UC1
PC Ryzen 5950X|W11 Pro|AudioGridder Server
MixR is offline   Reply With Quote
Old 04-21-2021, 05:49 AM   #10
AB1
Human being with feelings
 
Join Date: Apr 2020
Location: UK
Posts: 79
Default

Glad you got this working.

I will make a note in the first thread I linked to, of the problem with running some scripts from within a custom or cycle action. I should have realised that. I am aware this is the newbieland sub-forum and that is why I initially recommend a cycle action rather than a script, even though scripts are more versatile. The explanation part above was included to help anyone else reading this.

Quote:
Originally Posted by MixR View Post
But how on earth I would ever be able to do this myself I have no idea
I am not going so say that "everyone should learn to code" but I will say this. It looks much more complicated than it is and the fact that you understand what each step is supposed to be doing is far more important for a beginner than knowing exactly what 'newValue,_ ,_ ,_,_,_ , val = reaper.get_action_context()' means.

Hopefully you can see that the first two and last lines in the script above are doing the same thing as the cycle action was trying to do, and that you could use those lines in a new script with any other action or script (indented with a single 'tab' as above) that you wished to be able to disable. The same dummy toggle number can optionally be used so that you can enable/disable a group of actions or scripts with a single toggle button if required.
AB1 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.