|
|
|
08-08-2022, 04:45 AM
|
#1
|
Human being with feelings
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
|
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.
|
|
|
08-08-2022, 04:47 AM
|
#2
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
Quote:
Originally Posted by Gass n Klang
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
Last edited by sockmonkey72; 08-09-2022 at 02:26 AM.
|
|
|
08-08-2022, 04:48 AM
|
#3
|
Human being with feelings
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
|
Damn that was quick thanks, testing
|
|
|
08-08-2022, 04:51 AM
|
#4
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
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. :-)
|
|
|
08-08-2022, 04:58 AM
|
#5
|
Human being with feelings
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
|
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
|
|
|
08-08-2022, 05:03 AM
|
#6
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
Quote:
Originally Posted by Gass n Klang
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)
|
|
|
08-08-2022, 05:04 AM
|
#7
|
Human being with feelings
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
|
Quote:
Originally Posted by sockmonkey72
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.
|
|
|
08-08-2022, 05:26 AM
|
#8
|
Human being with feelings
Join Date: Mar 2022
Posts: 110
|
Quote:
Originally Posted by Gass n Klang
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
|
|
|
08-08-2022, 08:16 AM
|
#9
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
updated the code in the post above, should work reliably now -- thanks to ferolyte for figuring out what the problem was!
|
|
|
08-09-2022, 02:27 AM
|
#10
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
Updated script again, now it supports REs, item selection or time selection. Give it a shot.
|
|
|
08-09-2022, 04:55 AM
|
#11
|
Human being with feelings
Join Date: Nov 2015
Location: Cologne
Posts: 1,636
|
perfect thanks
|
|
|
08-09-2022, 08:43 AM
|
#12
|
Human being with feelings
Join Date: Oct 2021
Location: Singapore
Posts: 182
|
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!
|
|
|
08-09-2022, 09:10 AM
|
#13
|
Human being with feelings
Join Date: Oct 2021
Location: Singapore
Posts: 182
|
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
|
|
|
08-09-2022, 09:12 AM
|
#14
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
Quote:
Originally Posted by pcp
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!
|
|
|
08-09-2022, 09:21 AM
|
#15
|
Human being with feelings
Join Date: Oct 2021
Location: Singapore
Posts: 182
|
Ah makes sense, yes I'm on Windows.
|
|
|
02-19-2024, 08:46 AM
|
#16
|
Human being with feelings
Join Date: Sep 2018
Posts: 29
|
Quote:
Originally Posted by sockmonkey72
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
|
|
|
02-19-2024, 08:49 AM
|
#17
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
Quote:
Originally Posted by Ville
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!
|
|
|
02-19-2024, 10:44 AM
|
#18
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
Quote:
Originally Posted by Ville
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?
|
|
|
02-20-2024, 10:05 PM
|
#19
|
Human being with feelings
Join Date: Sep 2018
Posts: 29
|
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.
|
|
|
02-21-2024, 12:47 AM
|
#20
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
Quote:
Originally Posted by Ville
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.
|
|
|
02-21-2024, 01:58 AM
|
#21
|
Human being with feelings
Join Date: Sep 2018
Posts: 29
|
Quote:
Originally Posted by sockmonkey72
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
|
|
|
02-21-2024, 06:49 AM
|
#22
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
SWS/NF: Toggle obey track height lock in vertical zoom and track height actions?
|
|
|
02-21-2024, 06:50 AM
|
#23
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
Quote:
Originally Posted by cfillion
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.
|
|
|
02-21-2024, 11:43 AM
|
#24
|
Human being with feelings
Join Date: Sep 2018
Posts: 29
|
Oh wow! Thanks a lot both of you cfillion and sockmonkey72! 😄
Edit:
Quote:
Originally Posted by sockmonkey72
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.
|
|
|
02-21-2024, 11:50 AM
|
#25
|
Human being with feelings
Join Date: Sep 2021
Location: Berlin
Posts: 1,935
|
Quote:
Originally Posted by Ville
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.
|
|
|
02-21-2024, 11:53 AM
|
#26
|
Human being with feelings
Join Date: Sep 2018
Posts: 29
|
Quote:
Originally Posted by sockmonkey72
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. 😅
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:07 AM.
|