Old 12-11-2019, 09:25 AM   #1
The Bunker
Human being with feelings
 
Join Date: Nov 2016
Posts: 443
Default Go to region X and create time selection

Does anybody know if there is anyway to command Reaper to go to a certain region and create a time selection from the region by just using one keyboard shortcut? Like something similar to the "jump to" feature which currently allows you to jump to the start a certain region but you would then still have to follow that action up with double clicking on the region in order to create a time selection out of the region. I am hoping to be able to do both of those things with just one action.

The closest thing I have managed to do is to use the Region Management window to select and create a time selection by clicking on any given region in the list there but the downside of this is that it will also play the region as well as soon as I click it which is a bit annoying and less than ideal if I just want to have a time selection created from the region but may not necessarily want playback to start right away.
The Bunker is offline   Reply With Quote
Old 12-11-2019, 11:30 AM   #2
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

Sws has actions to select next/previous region, which doesn't change playback but if you want specific regions, I guess you'll need script for that.

Of if you can get the cursor to the start of the region you want there is a thonex script to set the time selection to the region at the cursor.
__________________
foxyyymusic
foxAsteria is online now   Reply With Quote
Old 12-11-2019, 11:51 AM   #3
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default RE-POST

Came up with this, with the help of code by X-Raym's "Go to start of next region". Requires SWS extension.
We could code in an inputbox so the script asks what region # to go to. ?

EDIT Code removed, it only worked if there were no markers.

Last edited by Edgemeal; 12-11-2019 at 02:36 PM.
Edgemeal is offline   Reply With Quote
Old 12-11-2019, 11:52 AM   #4
xpander
Human being with feelings
 
xpander's Avatar
 
Join Date: Jun 2007
Location: Terra incognita
Posts: 7,670
Default

There are SWS actions for going to specific regions by region numbers.
Regions: Go to region 01 after current region finishes playing (smooth seek) etc. Playback could be stopped separately if smooth seek is not needed.

Scripts for selecting regions by the name. Lua script by MusoBob in post #14 also sets the time selection to the given region.

---
edit: didn't see the above, thanks Edgemeal.

Quote:
Originally Posted by Edgemeal View Post
We could code in an inputbox so the script asks what region # to go to. ?
That would be nice. Make that number or region name and it would be extra nice.
xpander is offline   Reply With Quote
Old 12-11-2019, 04:17 PM   #5
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

OK lets try this again I'm not familiar with EnumProjectMarkers

Code:
-- Go to region number and select region area

function Main()
  local ret, str = reaper.GetUserInputs("Go to region and select", 1, "Enter region number: ", "1")
  if not ret then return end
  target_region = tonumber(str) 
  if target_region == nil then reaper.MB("Invalid: Please enter a number.","Number required",0) return end
  
  i=0
  region=0
  repeat 
   iRetval, bIsrgnOut, iPosOut, _, _, _, _, _ = reaper.EnumProjectMarkers3(0,i)
    if iRetval >= 1 then
      if bIsrgnOut == true then 
        if region == target_region-1 then
          reaper.SetEditCurPos(iPosOut-0.1, false, false)
          reaper.Main_OnCommand(reaper.NamedCommandLookup('_SWS_SELNEXTMORR'), 0) -- SWS: Goto/select next marker/region 
          break
        end
        region=region+1 
      end
      i=i+1
    end
  until iRetval == 0
end

Main()
reaper.defer(function () end)
Edgemeal is offline   Reply With Quote
Old 12-11-2019, 04:42 PM   #6
xpander
Human being with feelings
 
xpander's Avatar
 
Join Date: Jun 2007
Location: Terra incognita
Posts: 7,670
Default

It works, thanks Edgemeal!
xpander is offline   Reply With Quote
Old 12-13-2019, 07:01 AM   #7
The Bunker
Human being with feelings
 
Join Date: Nov 2016
Posts: 443
Default

Quote:
Originally Posted by Edgemeal View Post
OK lets try this again I'm not familiar with EnumProjectMarkers

Code:
-- Go to region number and select region area

function Main()
  local ret, str = reaper.GetUserInputs("Go to region and select", 1, "Enter region number: ", "1")
  if not ret then return end
  target_region = tonumber(str) 
  if target_region == nil then reaper.MB("Invalid: Please enter a number.","Number required",0) return end
  
  i=0
  region=0
  repeat 
   iRetval, bIsrgnOut, iPosOut, _, _, _, _, _ = reaper.EnumProjectMarkers3(0,i)
    if iRetval >= 1 then
      if bIsrgnOut == true then 
        if region == target_region-1 then
          reaper.SetEditCurPos(iPosOut-0.1, false, false)
          reaper.Main_OnCommand(reaper.NamedCommandLookup('_SWS_SELNEXTMORR'), 0) -- SWS: Goto/select next marker/region 
          break
        end
        region=region+1 
      end
      i=i+1
    end
  until iRetval == 0
end

Main()
reaper.defer(function () end)
Thanks for this, so how does this code work? Sorry for the noobish question, I do use some custom scripts in reaper but never added my own in.
The Bunker is offline   Reply With Quote
Old 12-13-2019, 07:06 AM   #8
The Bunker
Human being with feelings
 
Join Date: Nov 2016
Posts: 443
Default

Quote:
Originally Posted by The Bunker View Post
Thanks for this, so how does this code work? Sorry for the noobish question, I do use some custom scripts in reaper but never added my own in.
Actually NVM I just worked it out and it works perfect and does exactly what I want, thanks sooo much
The Bunker is offline   Reply With Quote
Old 12-13-2019, 07:22 AM   #9
The Bunker
Human being with feelings
 
Join Date: Nov 2016
Posts: 443
Default

Quote:
Originally Posted by Edgemeal View Post
OK lets try this again I'm not familiar with EnumProjectMarkers

Code:
-- Go to region number and select region area

function Main()
  local ret, str = reaper.GetUserInputs("Go to region and select", 1, "Enter region number: ", "1")
  if not ret then return end
  target_region = tonumber(str) 
  if target_region == nil then reaper.MB("Invalid: Please enter a number.","Number required",0) return end
  
  i=0
  region=0
  repeat 
   iRetval, bIsrgnOut, iPosOut, _, _, _, _, _ = reaper.EnumProjectMarkers3(0,i)
    if iRetval >= 1 then
      if bIsrgnOut == true then 
        if region == target_region-1 then
          reaper.SetEditCurPos(iPosOut-0.1, false, false)
          reaper.Main_OnCommand(reaper.NamedCommandLookup('_SWS_SELNEXTMORR'), 0) -- SWS: Goto/select next marker/region 
          break
        end
        region=region+1 
      end
      i=i+1
    end
  until iRetval == 0
end

Main()
reaper.defer(function () end)
Actually I just tested it and it seems like it works for the first 2 regions I create but after that it just goes to the numbered region without also selecting the time. Is it just me or is there some thing wrong with the code?
The Bunker is offline   Reply With Quote
Old 12-13-2019, 08:27 AM   #10
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by The Bunker View Post
Actually I just tested it and it seems like it works for the first 2 regions I create but after that it just goes to the numbered region without also selecting the time. Is it just me or is there some thing wrong with the code?
Ya I seen it fail here too with just 7 regions, it oddly wouldn't set a time selection on #4 region, after a few other tries #4 started working again. Weird. Heres another version without SWS and no cursor movement which you can re-enable if you want.

Code:
function Main()
  local ret, str = reaper.GetUserInputs("Go to region and select", 1, "Enter region number: ", "1")
  if not ret then return end
  target_region = tonumber(str) 
  if target_region == nil then reaper.MB("Invalid: Please enter a number.","Number required",0) return end
  
  i=0
  region=0
  repeat 
   local retval, isrgn, pos, rgnend, name, _, _ = reaper.EnumProjectMarkers3(0,i)
    if retval >= 1 then
      if isrgn then 
        if region == target_region-1 then
          -- reaper.SetEditCurPos(pos, true, false) --< OPTIONAL: Move Cursor to start of region. params = (time, moveview, seekplay)
          reaper.GetSet_LoopTimeRange(true, true, pos, rgnend, false)-- params = (isSet, isLoop, start, end, allowautoseek)
          reaper.UpdateArrange() 
          break
        end
        region=region+1 
      end
      i=i+1
    end
  until retval == 0 
end

Main()
reaper.defer(function () end)

Last edited by Edgemeal; 12-13-2019 at 08:54 AM. Reason: Change SetEditCurPos moveview to True, + params
Edgemeal is offline   Reply With Quote
Old 12-13-2019, 10:40 AM   #11
The Bunker
Human being with feelings
 
Join Date: Nov 2016
Posts: 443
Default

Quote:
Originally Posted by Edgemeal View Post
Ya I seen it fail here too with just 7 regions, it oddly wouldn't set a time selection on #4 region, after a few other tries #4 started working again. Weird. Heres another version without SWS and no cursor movement which you can re-enable if you want.

Code:
function Main()
  local ret, str = reaper.GetUserInputs("Go to region and select", 1, "Enter region number: ", "1")
  if not ret then return end
  target_region = tonumber(str) 
  if target_region == nil then reaper.MB("Invalid: Please enter a number.","Number required",0) return end
  
  i=0
  region=0
  repeat 
   local retval, isrgn, pos, rgnend, name, _, _ = reaper.EnumProjectMarkers3(0,i)
    if retval >= 1 then
      if isrgn then 
        if region == target_region-1 then
          -- reaper.SetEditCurPos(pos, true, false) --< OPTIONAL: Move Cursor to start of region. params = (time, moveview, seekplay)
          reaper.GetSet_LoopTimeRange(true, true, pos, rgnend, false)-- params = (isSet, isLoop, start, end, allowautoseek)
          reaper.UpdateArrange() 
          break
        end
        region=region+1 
      end
      i=i+1
    end
  until retval == 0 
end

Main()
reaper.defer(function () end)
Thanks that works perfect, I just combine that with the "go to start of time selection" command into a macro and it does exactly as I want it.
The Bunker is offline   Reply With Quote
Old 12-13-2019, 10:47 AM   #12
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by The Bunker View Post
Thanks that works perfect, I just combine that with the "go to start of time selection" command into a macro and it does exactly as I want it.
OK glad it works!

Quote:
"go to start of time selection"
That's what this line does,
Code:
-- reaper.SetEditCurPos(pos, true, false) --
But its disabled, just remove the two dashes at the beginning of the line to this,
Code:
reaper.SetEditCurPos(pos, true, false) --
Edgemeal is offline   Reply With Quote
Old 12-13-2019, 02:09 PM   #13
The Bunker
Human being with feelings
 
Join Date: Nov 2016
Posts: 443
Default

Quote:
Originally Posted by Edgemeal View Post
OK glad it works!



That's what this line does,
Code:
-- reaper.SetEditCurPos(pos, true, false) --
But its disabled, just remove the two dashes at the beginning of the line to this,
Code:
reaper.SetEditCurPos(pos, true, false) --
Oh ok, so if I do that then I don't need to make the macro? Also if I do that to the code then will it break it again like how it was before?
The Bunker is offline   Reply With Quote
Old 12-13-2019, 02:55 PM   #14
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by The Bunker View Post
Oh ok, so if I do that then I don't need to make the macro?
No you shouldn't need to make a custom action since that line of code should move the cursor for you, but do what ever works best for you!
Edgemeal is offline   Reply With Quote
Old 12-14-2019, 02:53 PM   #15
The Bunker
Human being with feelings
 
Join Date: Nov 2016
Posts: 443
Default

Quote:
Originally Posted by Edgemeal View Post
No you shouldn't need to make a custom action since that line of code should move the cursor for you, but do what ever works best for you!
Ok thanks I'll try that, but so just curious, what was making the first version of the script not select anything beyond region number 2?
The Bunker is offline   Reply With Quote
Old 12-14-2019, 03:30 PM   #16
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by The Bunker View Post
Ok thanks I'll try that, but so just curious, what was making the first version of the script not select anything beyond region number 2?
Pretty sure the line that calls the SWS command (SWS: Goto/select next marker/region) was the cause. It worked for me, but then it didn't, then it started working again LOL. I haven't actually tested the newer script that much either.
Edgemeal is offline   Reply With Quote
Old 12-15-2019, 01:43 PM   #17
The Bunker
Human being with feelings
 
Join Date: Nov 2016
Posts: 443
Default

Quote:
Originally Posted by Edgemeal View Post
Pretty sure the line that calls the SWS command (SWS: Goto/select next marker/region) was the cause. It worked for me, but then it didn't, then it started working again LOL. I haven't actually tested the newer script that much either.
Ok cool I think I'll stick with the macro for now as it seems to be working fine. Thanks again.
The Bunker 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 09:11 AM.


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