Skip to content

Commit 658da5d

Browse files
authored
Create amagalma_Smooth scroll arrange view 1 measure right.lua
1 parent 56854ca commit 658da5d

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- @description Smooth scroll arrange view 1 measure right
2+
-- @author amagalma
3+
-- @version 1.00
4+
-- @provides
5+
-- .
6+
-- [main] . > amagalma_Smooth scroll arrange view 2 measures right.lua
7+
-- [main] . > amagalma_Smooth scroll arrange view 4 measures right.lua
8+
-- [main] . > amagalma_Smooth scroll arrange view 8 measures right.lua
9+
-- @donation https://www.paypal.me/amagalma
10+
11+
reaper.set_action_options( 1|2 )
12+
13+
local Set, floor, log = reaper.GetSet_ArrangeView2, math.floor, math.log
14+
local measures = tonumber((({reaper.get_action_context()})[2]):match(".-(%d+).-$"))
15+
16+
local a0, b0 = Set( 0, 0, 0, 0, 0, 0 )
17+
local qn_current = floor(reaper.TimeMap_timeToQN( a0 ))
18+
local measure_start = reaper.TimeMap_QNToMeasures(0, qn_current )
19+
local measure_time, qn_start, qn_end = reaper.TimeMap_GetMeasureInfo( 0, measure_start-1 )
20+
local first_visible_measure = measure_start
21+
local first_visible_measure_time = measure_time
22+
if measure_time + 0.00001 < a0 then
23+
first_visible_measure = measure_start + 1
24+
first_visible_measure_time = reaper.TimeMap_GetMeasureInfo( 0, first_visible_measure-1 )
25+
end
26+
local wanted_time = reaper.TimeMap_GetMeasureInfo( 0, first_visible_measure-1+measures )
27+
local total_shift = wanted_time - a0
28+
29+
local ret = tonumber(reaper.GetExtState("amagalma_Smooth Scroll", "max_duration"))
30+
local max_duration = ret and ret or 400
31+
local max_max_duration = max_duration*1.25
32+
local hzoom = reaper.GetHZoomLevel()
33+
if hzoom > 200 then
34+
max_duration = max_duration*0.25
35+
else
36+
max_duration = max_duration * log(hzoom) / 4
37+
end
38+
if max_duration < 40 then max_duration = 40 end
39+
if max_duration > max_max_duration then max_duration = max_max_duration end
40+
local total_frames = floor(max_duration / 31 + 0.5)
41+
local delta = total_shift / total_frames
42+
43+
local frame = 0
44+
45+
local function scroll_right()
46+
frame = frame + 1
47+
local a = a0 + delta * frame
48+
local b = b0 + delta * frame
49+
Set( 0, 1, 0, 0, a, b )
50+
51+
if frame ~= total_frames then
52+
reaper.defer(scroll_right)
53+
else
54+
return reaper.defer(function() end)
55+
end
56+
end
57+
58+
scroll_right()

0 commit comments

Comments
 (0)