Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Q&A, Tips, Tricks and Howto

Reply
 
Thread Tools Display Modes
Old 08-12-2019, 03:43 PM   #1
puddi
Human being with feelings
 
puddi's Avatar
 
Join Date: Jun 2018
Posts: 239
Default Is there a script that can tell Reaper if a time selection is active or not?

I'm not sure if this makes any sense but basically I'm looking for a way to tell REAPER if a time selection is ON or OFF, like a toggle state. It could be useful in some cycle actions with the "IF" statements, so for example if a time selection is 'ON' then the action duplicates the selected area, else it duplicates the selected item (or whatever).

Thanks!
puddi is online now   Reply With Quote
Old 08-13-2019, 08:54 AM   #2
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 3,710
Default

Here's an example for checking the time selection state via LUA script:
Code:
starttime, endtime = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false)

if starttime == endtime then
  reaper.ShowMessageBox("No Time selection", "Info", 0)
else
  reaper.ShowMessageBox("Time selection exists", "Info", 0)
end

And another version which toggles the state of the action:
Code:
local self = ({reaper.get_action_context()})[4]
starttime, endtime = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false)

if starttime == endtime then
  reaper.SetToggleCommandState(0, self, 0)
else
  reaper.SetToggleCommandState(0, self, 1)
end
But I can't remember right now if it's also possible to use such a script as IF condition in a Cycle Action.
__________________
ReaLauncher
solger is offline   Reply With Quote
Old 08-13-2019, 08:58 AM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,144
Default

Cycle actions can check the state of other actions that are registered as a toggle (i.e. the ones that show On/Off in the action list). I think you could have the cycle action run a script prior to the If, the script would update its own state in the list based on the time selection as above, and then the cycle action could check it for the If.

However, I've never used cycle actions or the API command above so I'm not sure exactly how to do it.
Lokasenna is online now   Reply With Quote
Old 08-13-2019, 10:55 AM   #4
puddi
Human being with feelings
 
puddi's Avatar
 
Join Date: Jun 2018
Posts: 239
Default

Quote:
Originally Posted by solger View Post
Here's an example for checking the time selection state via LUA script:
Code:
starttime, endtime = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false)

if starttime == endtime then
  reaper.ShowMessageBox("No Time selection", "Info", 0)
else
  reaper.ShowMessageBox("Time selection exists", "Info", 0)
end

And another version which toggles the state of the action:
Code:
local self = ({reaper.get_action_context()})[4]
starttime, endtime = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false)

if starttime == endtime then
  reaper.SetToggleCommandState(0, self, 0)
else
  reaper.SetToggleCommandState(0, self, 1)
end
But I can't remember right now if it's also possible to use such a script as IF condition in a Cycle Action.
Nice, so it is possible! Now I just need to figure out how to implement it in to cycle actions since it seems like they can't register the toggle states of scripts.
puddi is online now   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 08:18 AM.


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