Skip to content

Commit

Permalink
fix: improve region selection
Browse files Browse the repository at this point in the history
- moves edit cursor to start
- sets loop selection
  • Loading branch information
gwatcha committed May 28, 2020
1 parent 6b16c77 commit ecf8a9e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
5 changes: 2 additions & 3 deletions definitions/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ return {
NextNoteSamePitchEnd = {"SelectNextNoteSamePitch", "EventSelectionEnd"},
NextNoteSamePitchStart = {"SelectNextNoteSamePitch", "EventSelectionStart"},
NextNoteStart = {"SelectNextNote", "EventSelectionStart"},
NextRegion = util.selectNextRegion,
NextRegion = {"SetLoopRegionToNextRegion", "LoopStart", "SetTimeSelectionToLoopSelection"},
NextTab = 40861,
NextTake = 40125,
NextTrack = 40285,
Expand Down Expand Up @@ -253,7 +253,7 @@ return {
PrevNoteSamePitchEnd = {"SelectPrevNoteSamePitch", "EventSelectionEnd"},
PrevNoteSamePitchStart = {"SelectPrevNoteSamePitch", "EventSelectionStart"},
PrevNoteStart = {"SelectPrevNote", "EventSelectionStart"},
PrevRegion = util.selectPrevRegion,
PrevRegion = {"SetLoopRegionToPrevRegion", "LoopStart", "SetTimeSelectionToLoopSelection"},
PrevTab = 40862,
PrevTake = 40126,
PrevTrack = 40286,
Expand Down Expand Up @@ -359,7 +359,6 @@ return {
SetLoopEnd = 40223,
SetLoopRegionToNextRegion = "_SWS_SELNEXTREG",
SetLoopRegionToPrevRegion = "_SWS_SELPREVREG",
SetLoopRegionToPrevRegion = "_SWS_SELPREVREG",
SetLoopSelectionToTimeSelection = 40622,
SetLoopStart = 40222,
SetModeNormal = lib.setModeNormal,
Expand Down
34 changes: 1 addition & 33 deletions internal/utils/reaper_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ end

function selectRegion(id)
local ok, is_region, start_pos, end_pos, _, got_id = reaper.EnumProjectMarkers(id)
if ok and is_region and got_id == id + 1 then
if ok and is_region then
reaper.GetSet_LoopTimeRange(true, false, start_pos, end_pos, false)
return true
end
Expand All @@ -321,36 +321,4 @@ function reaper_util.selectInnerRegion()
selectRegion(region_id)
end

function reaper_util.selectNextRegion()
local current_position, _ = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
if not current_position then
current_position = reaper.GetCursorPosition()
end

_, region_id = reaper.GetLastMarkerAndCurRegion(0, current_position)
if selectRegion(region_id + 1) == false then
selectRegion(0)
end
end

function reaper_util.selectPrevRegion()
local current_position, _ = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
if not current_position then
current_position = reaper.GetCursorPosition()
end

_, region_id = reaper.GetLastMarkerAndCurRegion(0, current_position)
if region_id == 0 then
-- no convenient way to find the last region, so keep going until we get false
for i=1,100 do
if selectRegion(i) == false then
selectRegion(i-1)
return
end
end
end

selectRegion(region_id - 1)
end

return reaper_util

0 comments on commit ecf8a9e

Please sign in to comment.