View Single Post
Old 04-28-2018, 06:44 PM   #1641
Human being with feelings
FnA's Avatar
Join Date: Jun 2012
Posts: 2,173

Hi cool. I rearranged it a small amount to get it closer to what you want, but it sounds like script was a compromise? If you want different priorities, and can't get it yourself, try to phrase a new pseudo code question.

Lua provides the following relational operators:
<   >   <=  >=  ==  ~=
All these operators always result in true or false.

You can use and,or,not in comparisons. Or you can nest "ifs" to an even greater depth than is present in the script you posted.
if (A > 0) and (not(B < A)) then
  if C ~= D then
    if (E > F) or (G <= H) then
That's not all there is to the discussion or anything, but enough to phrase your request, hopefully. Some things in Reaper can't be queried for a value...

You see the difference in using GetSet_LoopTimeRange()? The TWO values returned may be at the same time position and not at 0 if you snap the ends together with the mouse for example.

I use GetCursorContext2(). It tries to return most recent value if something other than track/item/envelope has focus. 0 for track, 1 for items, 2 for envelope.

Don't use NamedCommandLookup() for native REAPER actions.

-- cool.lua

start, ending = reaper.GetSet_LoopTimeRange( 0, 0, 0, 0, 0 )
--focus = reaper.GetCursorContext()
focus = reaper.GetCursorContext2(true) -- unlikely to get unknown(-1) when arrange not focused

if start == ending then
  reaper.Main_OnCommand(40697, 0)
  if focus == 1 then
    reaper.Main_OnCommand(40312, 0)
  elseif focus == 2 then
    reaper.Main_OnCommand(40089, 0)
  else -- alternatively -- elseif focus == 0 then
    reaper.Main_OnCommand(40005, 0) -- remove tracks
FnA is offline   Reply With Quote