Old 12-08-2019, 08:50 AM   #1
JLP
Human being with feelings
 
Join Date: Jul 2019
Posts: 3
Default 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 !
JLP is offline   Reply With Quote
Old 12-08-2019, 01:16 PM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,594
Default

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)
Edgemeal is offline   Reply With Quote
Old 12-09-2019, 12:38 AM   #3
JLP
Human being with feelings
 
Join Date: Jul 2019
Posts: 3
Default

Thank you for your reply, I will dig this path !
JLP is offline   Reply With Quote
Old 12-09-2019, 11:55 AM   #4
JLP
Human being with feelings
 
Join Date: Jul 2019
Posts: 3
Default

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 )
JLP 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:35 PM.


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