Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 08-08-2022, 04:45 AM   #1
Gass n Klang
Human being with feelings
 
Gass n Klang's Avatar
 
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
Default SWS: Toggle zoom to selected items or time selection => Add razor area zoom

hey guys,
razor edit is a blast. Too bad, many actions work with time selection but not with razor edits. I'd love to have an Action that does what "SWS: Toggle zoom to selected items or time selection" does but with razor edit included, with the following priority:

1) if one ore more razor edit area is set, zoom to that/these area(s) horizontally and vertically
2) if an item is selected, do 1)
3) if time selection is set, do 1)

running the action a second time should reset the zooms.
Perhaps a second and third version with only horizontal or vertical zoom would be helpful as well.
__________________
https://juliusgass.de
Gass n Klang is offline   Reply With Quote
Old 08-08-2022, 04:47 AM   #2
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

Quote:
Originally Posted by Gass n Klang View Post
hey guys,
razor edit is a blast. Too bad, many actions work with time selection but not with razor edits. I'd love to have an Action that does what "SWS: Toggle zoom to selected items or time selection" does but with razor edit included, with the following priority:

1) if one ore more razor edit area is set, zoom to that/these area(s) horizontally and vertically
2) if an item is selected, do 1)
3) if time selection is set, do 1)

running the action a second time should reset the zooms.
Perhaps a second and third version with only horizontal or vertical zoom would be helpful as well.
I just wrote this script this morning. If you want to test it (requires SWS and JS extensions):

sockmonkey72_Smarter_Zoom.lua

Code:
-- @description Smarter Zoom
-- @author sockmonkey72
-- @version 1.03
-- @changelog 1.03 initial upload
-- @about Zoom and scroll to razor edit region, item selection or time selection. Requires JS and SWS extensions

local reaper = reaper

local doRE = false
local doItems = false
local doTimeSel = false

local trackview = reaper.JS_Window_FindChildByID(reaper.GetMainHwnd(), 1000)
local _, arrange_width, arrange_height = reaper.JS_Window_GetClientSize(trackview)

local trackCount = reaper.CountTracks(0)
local firstTrack = -1
local lastTrack = -1

local REtracks = {}

 minTime = 0xFFFFFFFFF -- whatever, something big
 maxTime = 0

for i = 0, trackCount-1 do
  local track = reaper.GetTrack(0, i)
  if track and reaper.IsTrackVisible(track, false) then
    local rv, razorEdits = reaper.GetSetMediaTrackInfo_String(track, "P_RAZOREDITS", "", false)
    if rv == true and razorEdits ~= "" then
      if firstTrack == -1 then firstTrack = i
      else lastTrack = i end

      REtracks[#REtracks + 1] = track

      local count = 0
      for str in string.gmatch(razorEdits, "([^%s]+)") do
        if count % 3 == 0 then
          local value = tonumber(str)
          if value < minTime then
            minTime = value
          end
        elseif count % 3 == 1 then
          local value = tonumber(str)
          if value > maxTime then
            maxTime = value
          end
        end
        count = count + 1
      end
    end
  end
end

if #REtracks ~= 0 then doRE = true end

if doRE == false then
  numSelectedItems = reaper.CountSelectedMediaItems(0)
  if numSelectedItems > 0 then doItems = true
  else
    minTime, maxTime = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false)
    doTimeSel = minTime ~= maxTime and true or false
  end
end

if doRE == true or doItems == true  or doTimeSel == true then
  reaper.PreventUIRefresh(1)

  reaper.Undo_BeginBlock2(0)

  if doRE == true then
    local selectedTracks = {}
    local selCount = reaper.CountSelectedTracks(0)
    for i = 0, selCount - 1 do
      selectedTracks[#selectedTracks + 1] = reaper.GetSelectedTrack(0, i)
    end

    reaper.Main_OnCommandEx(40297, 0, 0) -- unselect all tracks

    for _, track in pairs(REtracks) do
      if track then reaper.SetTrackSelected(track, true) end
    end

    reaper.PreventUIRefresh(-1)

    reaper.Main_OnCommandEx(40913, 0, 0)
    reaper.Main_OnCommandEx(reaper.NamedCommandLookup("_SWS_VZOOMFIT"), 0, 0) -- vert zoom to selected tracks

    local buffer = (maxTime - minTime) * 0.01
    reaper.GetSet_ArrangeView2(0, true, 0, 0, minTime - buffer, maxTime + 2 * buffer)

    reaper.PreventUIRefresh(1)

    reaper.Main_OnCommandEx(40297, 0, 0) -- unselect all tracks

    for _, track in pairs(selectedTracks) do
      reaper.SetTrackSelected(track, true)
    end
  elseif doItems == true then
    reaper.Main_OnCommandEx(41622, 0, 0)
  elseif doTimeSel == true then
    local buffer = (maxTime - minTime) * 0.01
    reaper.GetSet_ArrangeView2(0, true, 0, 0, minTime - buffer, maxTime + 2 * buffer)
  end

  reaper.PreventUIRefresh(-1)

  reaper.Undo_EndBlock2(0, "Zoom to Razor Edit", -1)

  reaper.UpdateTimeline()
end
__________________
ReaPack Repository: right-click and copy index URL

Last edited by sockmonkey72; 08-09-2022 at 02:26 AM.
sockmonkey72 is offline   Reply With Quote
Old 08-08-2022, 04:48 AM   #3
Gass n Klang
Human being with feelings
 
Gass n Klang's Avatar
 
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
Default

Damn that was quick thanks, testing
__________________
https://juliusgass.de
Gass n Klang is offline   Reply With Quote
Old 08-08-2022, 04:51 AM   #4
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

It doesn't do the adaptation you're asking for, but that could be added without much trouble. In any case, the razor edit part is covered for now. :-)
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 08-08-2022, 04:58 AM   #5
Gass n Klang
Human being with feelings
 
Gass n Klang's Avatar
 
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
Default

it seems to do a good job on horizontal zoom, but vertical zooms don't work at all if you have a razor area over one track. with multiple tracks it does vertical zoom but not to the expected area. Besides I think the reset to the previous zoom is much needed. If you could implement time selection and item that would be supernice, too
__________________
https://juliusgass.de
Gass n Klang is offline   Reply With Quote
Old 08-08-2022, 05:03 AM   #6
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

Quote:
Originally Posted by Gass n Klang View Post
it seems to do a good job on horizontal zoom, but vertical zooms don't work at all if you have a razor area over one track. with multiple tracks it does vertical zoom but not to the expected area. Besides I think the reset to the previous zoom is much needed. If you could implement time selection and item that would be supernice, too
Weird, it's working for me, but I'll check it out. I wonder if it's because I'm a) on macOS and b) using the latest SWS pre-release?

Reset to previous zoom works via the native "View: Restore previous zoom level" (for me)
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 08-08-2022, 05:04 AM   #7
Gass n Klang
Human being with feelings
 
Gass n Klang's Avatar
 
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
Default

Quote:
Originally Posted by sockmonkey72 View Post
Weird, it's working for me, but I'll check it out. I wonder if it's because I'm a) on macOS and b) using the latest SWS pre-release?

Reset to previous zoom works via the native "View: Restore previous zoom level" (for me)
ah ok I have to check the latest sws pre. Restore previous zoom level might work. I thought a cycleaction could be cool, but I can do that for myself.
__________________
https://juliusgass.de
Gass n Klang is offline   Reply With Quote
Old 08-08-2022, 05:26 AM   #8
fero@reaper
Human being with feelings
 
Join Date: Mar 2022
Posts: 110
Default

Quote:
Originally Posted by Gass n Klang View Post
hey guys,
razor edit is a blast. Too bad, many actions work with time selection but not with razor edits. I'd love to have an Action that does what "SWS: Toggle zoom to selected items or time selection" does but with razor edit included, with the following priority:

1) if one ore more razor edit area is set, zoom to that/these area(s) horizontally and vertically
2) if an item is selected, do 1)
3) if time selection is set, do 1)

running the action a second time should reset the zooms.
Perhaps a second and third version with only horizontal or vertical zoom would be helpful as well.

not exactly with razor edits but,

https://forum.cockos.com/showthread.php?t=215575
This one is pretty neat, until the one with razor edit shows up
fero@reaper is offline   Reply With Quote
Old 08-08-2022, 08:16 AM   #9
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

updated the code in the post above, should work reliably now -- thanks to ferolyte for figuring out what the problem was!
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 08-09-2022, 02:27 AM   #10
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

Updated script again, now it supports REs, item selection or time selection. Give it a shot.
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 08-09-2022, 04:55 AM   #11
Gass n Klang
Human being with feelings
 
Gass n Klang's Avatar
 
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
Default

perfect thanks
__________________
https://juliusgass.de
Gass n Klang is offline   Reply With Quote
Old 08-09-2022, 08:43 AM   #12
pcp
Human being with feelings
 
pcp's Avatar
 
Join Date: Oct 2021
Location: Singapore
Posts: 182
Default

Amazing, thanks sockmonkey - seems to work great as a direct replacement for 'SWS toggle zoom to selected items/time selection', with the addition of razor edits. My shortcut has already been reassigned... super-handy!
pcp is offline   Reply With Quote
Old 08-09-2022, 09:10 AM   #13
pcp
Human being with feelings
 
pcp's Avatar
 
Join Date: Oct 2021
Location: Singapore
Posts: 182
Default

One little thing, the default RE zoom in your script goes right to the edges of the arrange view, which makes it difficult to do anything with the zoomed item as it's not easy to deselect the RE with an off-item mouse click. The native zoom actions have more generous buffer zones at the sides. I played around with the buffer setting in your script and found that you can get similar buffers to 'zoom selected items' by increasing the buffer in line 88 from 0.01 to 0.07, i.e. 7 times the space either side of the zoomed RE.

Code:
 local buffer = (maxTime - minTime) * 0.07
pcp is offline   Reply With Quote
Old 08-09-2022, 09:12 AM   #14
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

Quote:
Originally Posted by pcp View Post
One little thing, the default RE zoom in your script goes right to the edges of the arrange view, which makes it difficult to do anything with the zoomed item as it's not easy to deselect the RE with an off-item mouse click. The native zoom actions have more generous buffer zones at the sides. I played around with the buffer setting in your script and found that you can get similar buffers to 'zoom selected items' by increasing the buffer in line 88 from 0.01 to 0.07, i.e. 7 times the space either side of the zoomed RE.

Code:
 local buffer = (maxTime - minTime) * 0.07
Thanks, I suspect this is different on different systems (I'm on macOS Retina, so I got it looking good on my screen). I'll check out this change and integrate it, or something similar, for the next update!
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 08-09-2022, 09:21 AM   #15
pcp
Human being with feelings
 
pcp's Avatar
 
Join Date: Oct 2021
Location: Singapore
Posts: 182
Default

Ah makes sense, yes I'm on Windows.
pcp is offline   Reply With Quote
Old 02-19-2024, 08:46 AM   #16
Ville
Human being with feelings
 
Join Date: Sep 2018
Posts: 29
Default

Quote:
Originally Posted by sockmonkey72 View Post
I just wrote this script this morning. If you want to test it (requires SWS and JS extensions):

sockmonkey72_Smarter_Zoom.lua
Hi there
Just found this script last week and immediately put it behind a keycommand!

It has worked well except for one thing: it doesn't respect track height lock.
Not a huge issue, but would be sweet if you find the time to fix.

Thanks!
Ville
Ville is offline   Reply With Quote
Old 02-19-2024, 08:49 AM   #17
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

Quote:
Originally Posted by Ville View Post
Hi there
Just found this script last week and immediately put it behind a keycommand!

It has worked well except for one thing: it doesn't respect track height lock.
Not a huge issue, but would be sweet if you find the time to fix.

Thanks!
Ville
I'll get it fixed up!
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 02-19-2024, 10:44 AM   #18
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

Quote:
Originally Posted by Ville View Post
Hi there
Just found this script last week and immediately put it behind a keycommand!

It has worked well except for one thing: it doesn't respect track height lock.
Not a huge issue, but would be sweet if you find the time to fix.

Thanks!
Ville
To clarify, you want it to _not_ zoom if the track height lock is used?
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 02-20-2024, 10:05 PM   #19
Ville
Human being with feelings
 
Join Date: Sep 2018
Posts: 29
Default

Yes, I'd like for height locked tracks to keep their height the same in every situation.
I have the height of buses usually locked to minimum height. Now, when firing this script, the height of buses in between the tracks that I'm zooming to, changes.
Ville is offline   Reply With Quote
Old 02-21-2024, 12:47 AM   #20
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

Quote:
Originally Posted by Ville View Post
Yes, I'd like for height locked tracks to keep their height the same in every situation.
I have the height of buses usually locked to minimum height. Now, when firing this script, the height of buses in between the tracks that I'm zooming to, changes.
Interesting. This script uses SWS vertical zoom actions to do its thing, and it appears that there's no SWS vertical zoom action which respects track height locks. Might be worth a FR, since performing the entire zoom logic of SWS is "out of scope" for this script. :-)

The best I could do (quickly) would be to use the "minimize others" version of the SWS action.

Note that when you restore the previous zoom level of the arrange view, your track heights are correctly restored, but I understand why you'd want tracks in the middle to stay small.
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 02-21-2024, 01:58 AM   #21
Ville
Human being with feelings
 
Join Date: Sep 2018
Posts: 29
Default

Quote:
Originally Posted by sockmonkey72 View Post
Interesting. This script uses SWS vertical zoom actions to do its thing, and it appears that there's no SWS vertical zoom action which respects track height locks. Might be worth a FR, since performing the entire zoom logic of SWS is "out of scope" for this script. :-)

The best I could do (quickly) would be to use the "minimize others" version of the SWS action.

Note that when you restore the previous zoom level of the arrange view, your track heights are correctly restored, but I understand why you'd want tracks in the middle to stay small.
Ok, thanks for looking into this.

Yeah, I noticed that this works as a toggle so heights are restored when running the script again. I just don't always want to go back to previous zoom (or just forget the toggle nature of the script) 😅

Well, I'll just live with this as is for now. It's not a super essential part of my workflows.

Thanks
Ville is offline   Reply With Quote
Old 02-21-2024, 06:49 AM   #22
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

SWS/NF: Toggle obey track height lock in vertical zoom and track height actions?
cfillion is offline   Reply With Quote
Old 02-21-2024, 06:50 AM   #23
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

Quote:
Originally Posted by cfillion View Post
SWS/NF: Toggle obey track height lock in vertical zoom and track height actions?
LOL, how could I not find that, the name is so ... specific?

OK, Ville -- turn that on for now? I actually updated the script earlier today, and I will make a further update in a few minutes to ensure that this is enabled for the duration of the script so that it always behaves like that.
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 02-21-2024, 11:43 AM   #24
Ville
Human being with feelings
 
Join Date: Sep 2018
Posts: 29
Default

Oh wow! Thanks a lot both of you cfillion and sockmonkey72! 😄

Edit:

Quote:
Originally Posted by sockmonkey72 View Post
LOL, how could I not find that, the name is so ... specific?

OK, Ville -- turn that on for now? I actually updated the script earlier today, and I will make a further update in a few minutes to ensure that this is enabled for the duration of the script so that it always behaves like that.
Yeah, I'll definitely turn that on. From the top of my head I can't think why I'd want it otherwise.
Ville is offline   Reply With Quote
Old 02-21-2024, 11:50 AM   #25
sockmonkey72
Human being with feelings
 
sockmonkey72's Avatar
 
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
Default

Quote:
Originally Posted by Ville View Post
Oh wow! Thanks a lot both of you cfillion and sockmonkey72! 😄

Edit:



Yeah, I'll definitely turn that on. From the top of my head I can't think why I'd want it otherwise.
Shouldn't be necessary for the latest version of the script.
__________________
ReaPack Repository: right-click and copy index URL
sockmonkey72 is offline   Reply With Quote
Old 02-21-2024, 11:53 AM   #26
Ville
Human being with feelings
 
Join Date: Sep 2018
Posts: 29
Default

Quote:
Originally Posted by sockmonkey72 View Post
Shouldn't be necessary for the latest version of the script.
Yes, thanks, I got that, but I think I remember some situations where I would have wanted this setting on had I known it existed. 😅
Ville 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 02:27 AM.


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