Skip to content

Instantly share code, notes, and snippets.

@cfillion
Last active November 17, 2019 12:47
Show Gist options
  • Save cfillion/03097fe9e77a77c5e83f137e26dd79eb to your computer and use it in GitHub Desktop.
Save cfillion/03097fe9e77a77c5e83f137e26dd79eb to your computer and use it in GitHub Desktop.
Test script of my new dynamic ruler lane height logic for SWS https://i.imgur.com/sR44czh.png
Ruler Height Regions Markers Tempo
66 14 14 11
69 15 15 12
75 16 16 13
80 17 17 14
85 18 18 15
90 19 19 16
96 20 20 17
104 37 20 17
121 37 37 17
138 54 37 17
155 54 54 17
172 71 54 17
189 71 71 17
206 88 71 17
function GetRulerLanesHeight()
local rowMaxHeight = 16
local lanes = {1, 1, 1, 3}
local limits = {255, 255, 3, 3}
for i=0,2 do
if reaper.GetToggleCommandState(42323 + i) == 0 then
limits[i + 1] = lanes[i + 1]
end
end
local minRowCount = sum(lanes)
local rowHeight = math.min(math.ceil(rulerHeight / minRowCount), rowMaxHeight)
local availableRows = math.ceil(rulerHeight / rowHeight) - minRowCount
availableRows = math.min(availableRows, sum(limits) - minRowCount)
local lane = 0
while availableRows > 0 do
if limits[lane + 1] > lanes[lane + 1] then
lanes[lane + 1] = lanes[lane + 1] + 1
availableRows = availableRows - 1
end
lane = (lane + 1) % 4
end
-- convert rows into pixels
for i=1,4 do
lanes[i] = lanes[i] * rowHeight
end
return lanes
end
function sum(t)
local s = 0
for _,v in ipairs(t) do
s = s + v
end
return s
end
function drawLane(name, color, height)
gfx.r, gfx.g, gfx.b = color, color, color
gfx.rect(0, gfx.y, gfx.w, height)
gfx.r, gfx.g, gfx.b = 1, 1, 1
gfx.x = 0
gfx.drawstr(name)
gfx.y = gfx.y + height
end
function loop()
if gfx.getchar() < 0 then
return
else
reaper.defer(loop)
end
if gfx.mouse_cap & 1 == 1 then
rulerHeight = math.max(70, math.min(gfx.h, gfx.mouse_y))
end
lanes = GetRulerLanesHeight()
gfx.y = 0
drawLane("Regions", 0.2, lanes[1])
drawLane("Markers", 0.4, lanes[2])
drawLane("Tempo", 0.2, lanes[3])
drawLane("Timeline", 0.4, lanes[4])
gfx.r, gfx.g, gfx.b = 1, 0, 0
gfx.line(0, rulerHeight, gfx.w, rulerHeight)
gfx.update()
end
rulerHeight = 70
gfx.init("REAPER 5.65 dynamic ruler height test", 300, 300, 0, 1000, 14)
gfx.setcursor(32645)
loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment