|
|
|
12-08-2019, 08:50 AM
|
#1
|
Human being with feelings
Join Date: Jul 2019
Posts: 43
|
Script toggle state depedent on project tab
Hello there,
I'm working quiet a lot with reascript lately, but I can't figure a way to create a script that is dependent on the project tab selection.
My goal is to have a script that act like a toggle but which can be set differently on different project tab. As an exemple, I would like the users of this script to be able to set it on for project tab 1 and off for project tab 2.
There are few native toggle in reaper that behave like that (the metronome for exemple).
Could someone help me with this ?
Thank you !
|
|
|
12-08-2019, 01:16 PM
|
#2
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
|
Maybe using 'reaper.EnumProjects', you could determine which tab is the active one, by either the project or project name? Just spit balling here,..
Code:
function ProjectTabIndex(FindByName)
local proj,cnt,ret = "",0,1
while ret~=nil do
ret, proj = reaper.EnumProjects(cnt, "")
if proj == FindByName then return cnt end
cnt=cnt+1
end
end
-- get active tab
ret, proj = reaper.EnumProjects(-1, "")
-- get index of the active tab
index = ProjectTabIndex(proj)
|
|
|
12-09-2019, 12:38 AM
|
#3
|
Human being with feelings
Join Date: Jul 2019
Posts: 43
|
Thank you for your reply, I will dig this path !
|
|
|
12-09-2019, 11:55 AM
|
#4
|
Human being with feelings
Join Date: Jul 2019
Posts: 43
|
I've finally got something that work ! Thank you Edgemeal
If someone need a similar function or if anyone see a better way of doing it : here is the code
Code:
function Msg(val)
reaper.ShowConsoleMsg(tostring(val).."\n")
end
-- Set ToolBar Button ON
function SetButtonON()
is_new_value, filename, sec, cmd, mode, resolution, val = reaper.get_action_context()
state = reaper.GetToggleCommandStateEx( sec, cmd )
reaper.SetToggleCommandState( sec, cmd, 1 ) -- Set ON
reaper.RefreshToolbar2( sec, cmd )
end
-- Set ToolBar Button OFF
function SetButtonOFF()
is_new_value, filename, sec, cmd, mode, resolution, val = reaper.get_action_context()
state = reaper.GetToggleCommandStateEx( sec, cmd )
reaper.SetToggleCommandState( sec, cmd, 0 ) -- Set OFF
reaper.RefreshToolbar2( sec, cmd )
end
--get project tab by name
function ProjectTabIndex(FindByName)
local proj,cnt,ret = "",0,1
while ret~=nil do
ret, proj = reaper.EnumProjects(cnt)
if proj == FindByName then return cnt end
cnt=cnt+1
end
end
--Fix Index--
fixIndex = 0
function setFixIndex(value)
fixIndex = value
end
function getFixIndex()
return fixIndex
end
function main()
local fixIndex = getFixIndex()
ret, proj2 = reaper.EnumProjects(-1)
-- get index of the active tab
indexCurrentTab = ProjectTabIndex(proj2)
--Msg(indexCurrentTab)
--Msg(fixIndex)
if indexCurrentTab == fixIndex then
SetButtonON()
else
SetButtonOFF()
end
reaper.defer(main)
end
-- get active tab
ret, proj = reaper.EnumProjects(-1)
-- get index of the active tab
index = ProjectTabIndex(proj)
setFixIndex(index)
SetButtonON()
main()
reaper.atexit( SetButtonOFF )
|
|
|
12-29-2020, 02:38 AM
|
#5
|
Human being with feelings
Join Date: Mar 2016
Location: Italy
Posts: 322
|
Hi guys, I've made a script which has a toggle state that changes some mouse modifiers. What's the best way to update the toolbar state and when i open Reaper?
EDIT
I've been able to do it using reaper.defer function and reaper.atexit like you are using in your function.
but i'm still wondering if there's any solution which doesn't imply a background loop and a final exit state but just storing a toggle state somewhere in the resources
Last edited by 80icio; 12-29-2020 at 03:05 AM.
|
|
|
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 03:39 PM.
|