|
|
|
08-29-2018, 12:38 PM
|
#1
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Q: Toolbar button behavior like "SWS/S&M: Dummy toggle"
Is it possible to set a toolbar button to work like "SWS/S&M: Dummy toggle" from a single script? The toolbar button would also be mapped to this particular script. It would be a visual indicator and the script would read its state for running different block of code, depending on the button state.
This is how it works with "SWS/S&M: Dummy toggle", but I would want to achieve this without using the SWS action:
If " Dummy toggle" -button" is "ON" - Pressing space bar would run "play from play marker" -script
If " Dummy toggle" -button" is "OFF" - Pressing space bar would run Transport: Play/stop
(Play marker concept)
Code:
-- NOTE: Add "SWS/S&M: Dummy toggle 1" to a toolbar.
-------------------
-- User settings --
-------------------
--Example: Start playback from a project marker named 'Play start':
local project_marker_name = "Play start" -- set marker name here
local play_start_offset = 0 -- pre-roll in seconds
-------------------
local marker_exists = false
local i = 0
local cursor_pos = reaper.GetCursorPosition()
local arr_start, arr_end = reaper.GetSet_ArrangeView2(0, false, 0, 0)
function play_from_pos()
local state = reaper.GetToggleCommandState(reaper.NamedCommandLookup("_S&M_DUMMY_TGL1"))
if state == 0 then
reaper.Main_OnCommand(40044, 0) -- Transport: Play/stop
return
end
while true do
local ret, isrgn, pos, rgnend, name, markrgnindexnumber = reaper.EnumProjectMarkers(i)
if ret == 0 then
break
elseif name == project_marker_name then
reaper.PreventUIRefresh(1)
reaper.SetEditCurPos2(0, pos + play_start_offset, false, false)
reaper.Main_OnCommand(40044, 0) -- Transport: Play/stop
reaper.SetEditCurPos2(0, cursor_pos, false, false)
reaper.GetSet_ArrangeView2(0, true, 0,0, arr_start, arr_end)
reaper.PreventUIRefresh(-1)
marker_exists = true
break
end
i = i + 1
end
if not marker_exists then
local mb_ret = reaper.MB("Couldn't find marker named '" .. project_marker_name .. "'.\nPress 'OK' to insert the marker at edit cursor.", "", 1)
if mb_ret == 1 then
reaper.AddProjectMarker2(0, false, cursor_pos, 0, project_marker_name, 1, 0)
end
end
end
reaper.defer(play_from_pos)
|
|
|
08-29-2018, 02:45 PM
|
#2
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Haven't tried, but I believe you can use this to set the script's toggle state as long as it's registered in the action list:
Code:
boolean reaper.SetToggleCommandState(integer section_id, integer command_id, integer state)
Updates the toggle state of an action, returns true if succeeded. Only ReaScripts can have their toggle states changed programmatically. See RefreshToolbar2.
You can get the ID with:
Code:
reaper.get_action_context()
is_new_value,filename,sectionID,cmdID,mode,resolution,val = reaper.get_action_context()
Returns contextual information about the script, typically MIDI/OSC input values.
val will be set to a relative or absolute value depending on mode (=0: absolute mode, >0: relative modes). resolution=127 for 7-bit resolution, =16383 for 14-bit resolution.
Notes: sectionID, and cmdID will be set to -1 if the script is not part of the action list. mode, resolution and val will be set to -1 if the script was not triggered via MIDI/OSC.
|
|
|
08-30-2018, 06:57 AM
|
#3
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
I tried Set/GetToggleCommandState, RefreshToolbar, get_action_context and Get/Setextstate etc. but couldn't get it working as I wanted.
I guess I'd need a toolbar button that is... - somehow attached to certain script
- is toggleable (by clicking the left mouse button on it, no need to set the state programmatically)
- doesn't do anything, except changes its own state (script should be able to read its state)
Any ideas?
|
|
|
08-30-2018, 07:03 AM
|
#4
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
SWS Dummy toggles (1-8) work perfectly for this purpose, but they can be already in use for some other tasks.
|
|
|
08-30-2018, 07:11 AM
|
#5
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Working here. The script doesn't start with an assigned state, so you have to allow a value of -1 to work.
Code:
local is_new_value,filename,sectionID,cmdID,mode,resolution,val = reaper.get_action_context()
local state = reaper.GetToggleCommandStateEx( sectionID, cmdID )
reaper.ShowConsoleMsg("current state is: " .. tostring(state))
reaper.ShowConsoleMsg("\ttoggling to: " .. tostring(state == 1 and 0 or 1))
reaper.SetToggleCommandState(sectionID, cmdID, state == 1 and 0 or 1)
reaper.RefreshToolbar2(sectionID, cmdID)
Register it in the action list, put it on a toolbar button, boom.
|
|
|
08-30-2018, 07:31 AM
|
#6
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Thanks Lokasenna, but I think it's not even possible to do what I want it to do (from a single script) .
It should change its state only when pressing left mouse button on it.
If you have time, please check the script I posted on the post#1. (put "SWS/S&M: Dummy toggle 1" on a toolbar and run the script and add e.g. space bar as a shortcut to it)
|
|
|
08-30-2018, 07:44 AM
|
#7
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
There's no way to do it as a single script, no, since the script has no idea when you run it whether you want to toggle the button or do the script code.
If you just don't want to use Dummy Toggle, you can use a script just for the button and have a separate script with the main code that just checks the first script's toggle state.
If it helps, don't forget that ReaPack can install and register multiple scripts from one source, with different filenames, so they can read their filename and perform different actions. You could have it install one to use for the toolbar and a separate one that checks the toolbar action's state.
|
|
|
08-30-2018, 07:55 AM
|
#8
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
That's what I thought too, thanks!
I wish that get_action_context would also return a value that shows where the script is run from (from toolbar button, shortcut key, action list etc.)
|
|
|
09-22-2020, 12:13 AM
|
#9
|
Human being with feelings
Join Date: May 2017
Posts: 236
|
Quote:
Originally Posted by spk77
SWS Dummy toggles (1-8) work perfectly for this purpose, but they can be already in use for some other tasks.
|
That is exactly right and the only limitation. But I have found it to be advantageous and a great performance feature, in fact, the greatest feature.
|
|
|
09-22-2020, 11:31 AM
|
#10
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
Quote:
Originally Posted by Beastmode Beats
That is exactly right and the only limitation. But I have found it to be advantageous and a great performance feature, in fact, the greatest feature.
|
You can set the number of available dummy toggles in the S&M.ini file (look for entry S&M_DUMMY_TGL=.
|
|
|
09-23-2020, 06:45 AM
|
#11
|
Human being with feelings
Join Date: May 2017
Posts: 236
|
Yes I have done this without scripts, use two cycle actions. One cycle action activates the active dummy toggle, the cycle is OFF, ON, ON, for sending 3 toggles to the second cycle action for example. OFF, On,On, On, On for 4 toggles (4BANKS) The second cycle action is simply used for toggle states when each dummy toggle is active for the first cycle action. If the next action is ON Dummy toggle 1, Toggle record arm for selected track, end of conditional statement, if the next actions is ON dummy Toggle 2, toggle solo etc... Just remember not to place a step in the second cycle action for receiving the active dummy toggle. After that, you just add a new toolbar to the top of cycle action 1’s statement, then you go into the toolbar and add all dummy toggles from the actions list to that toolbar and rename them based on their toggle actions, and once you assign each cycle action to
a CC, One button can control multiple banks and increase your productivity, it is a performance feature, because once you add your own fx it will help you browse faster than the average person
Last edited by Beastmode Beats; 10-01-2020 at 11:25 AM.
|
|
|
09-23-2020, 06:59 AM
|
#12
|
Human being with feelings
Join Date: May 2017
Posts: 236
|
Quote:
Originally Posted by nofish
You can set the number of available dummy toggles in the S&M.ini file (look for entry S&M_DUMMY_TGL=.
|
I am aware the total value is 255
|
|
|
09-23-2020, 07:04 AM
|
#13
|
Human being with feelings
Join Date: May 2017
Posts: 236
|
What I am trying to get many of you to understand is you only need 8 dummy toggles. Because if you only have 8 buttons for example, that is 32 dummy toggles with 4 banks all from 2 MIDI CC assignments, and you can take your configuration and keep your custom actions on the go thanks to Reaper 🙂, no more limited control surface links.
|
|
|
12-30-2021, 01:31 PM
|
#14
|
Banned
Join Date: Dec 2018
Posts: 642
|
Toolbar icons for multi-state toggles with 3 or more states?
Anybody here know the answer to the question below, which seems to be relevant to this thread as well (post link below)?
p=2511138
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:50 AM.
|