|
| 1 | +-- @description Smooth scroll arrange view 1 measure left |
| 2 | +-- @author amagalma |
| 3 | +-- @version 1.00 |
| 4 | +-- @provides |
| 5 | +-- . |
| 6 | +-- [main] . > amagalma_Smooth scroll arrange view 2 measures left.lua |
| 7 | +-- [main] . > amagalma_Smooth scroll arrange view 4 measures left.lua |
| 8 | +-- [main] . > amagalma_Smooth scroll arrange view 8 measures left.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 | +local a0, b0 = Set( 0, 0, 0, 0, 0, 0 ) |
| 16 | +if a0 == 0 then return reaper.defer(function() end) end |
| 17 | + |
| 18 | +local qn_current = floor(reaper.TimeMap_timeToQN( a0 )) |
| 19 | +local measure_start = reaper.TimeMap_QNToMeasures(0, qn_current ) |
| 20 | +local measure_time, qn_start, qn_end = reaper.TimeMap_GetMeasureInfo( 0, measure_start-1 ) |
| 21 | +local first_visible_measure = measure_start |
| 22 | +local first_visible_measure_time = measure_time |
| 23 | +if measure_time + 0.00001 < a0 then |
| 24 | + first_visible_measure = measure_start + 1 |
| 25 | + first_visible_measure_time = reaper.TimeMap_GetMeasureInfo( 0, first_visible_measure-1 ) |
| 26 | +end |
| 27 | +local wanted_time = reaper.TimeMap_GetMeasureInfo( 0, first_visible_measure-1-measures ) |
| 28 | +if wanted_time < 0 then wanted_time = 0 end |
| 29 | +local total_shift = a0 - wanted_time |
| 30 | + |
| 31 | +local ret = tonumber(reaper.GetExtState("amagalma_Smooth Scroll", "max_duration")) |
| 32 | +local max_duration = ret and ret or 400 |
| 33 | +local max_max_duration = max_duration*1.25 |
| 34 | +local hzoom = reaper.GetHZoomLevel() |
| 35 | +if hzoom > 200 then |
| 36 | + max_duration = max_duration*0.25 |
| 37 | +else |
| 38 | + max_duration = max_duration * log(hzoom) / 4 |
| 39 | +end |
| 40 | + if max_duration < 40 then max_duration = 40 end |
| 41 | + if max_duration > max_max_duration then max_duration = max_max_duration end |
| 42 | +local total_frames = floor(max_duration / 31 + 0.5) |
| 43 | +local delta = total_shift / total_frames |
| 44 | + |
| 45 | +local frame = 0 |
| 46 | + |
| 47 | +local function scroll_left() |
| 48 | + frame = frame + 1 |
| 49 | + local a = a0 - delta * frame |
| 50 | + local b = b0 - delta * frame |
| 51 | + Set( 0, 1, 0, 0, a, b ) |
| 52 | + |
| 53 | + if frame ~= total_frames then |
| 54 | + reaper.defer(scroll_left) |
| 55 | + else |
| 56 | + return reaper.defer(function() end) |
| 57 | + end |
| 58 | +end |
| 59 | + |
| 60 | +scroll_left() |
0 commit comments