commit 9161432e1a0c38c41190e2f79ee7ac931fc10f8c
parent 870db5d80c0ad8f0bfb281de0c4272802f884b6d
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Fri, 28 Oct 2022 19:12:40 -0500
make time field a table with start and stop time, animate lines
Diffstat:
M | smallpond.lua | | | 57 | ++++++++++++++++++++++++++++++++++++++++----------------- |
1 file changed, 40 insertions(+), 17 deletions(-)
diff --git a/smallpond.lua b/smallpond.lua
@@ -424,13 +424,13 @@ local staff3ify = function(timing, el, staff)
local ry = (em*head.y) / 2 + 2*em
if not lowheight then lowheight = ry end
if not highheight then highheight = ry end
- table.insert(staff3[staff], {kind="glyph", glyph=glyph, x=preoffset + rx, y=ry, time=timing})
+ table.insert(staff3[staff], {kind="glyph", glyph=glyph, x=preoffset + rx, y=ry, time={start=timing, stop=timing+1}})
if head.acc == "s" then
- table.insert(staff3[staff], {kind="glyph", glyph=Glyph["accidentalSharp"], x=rx, y=ry, time=timing})
+ table.insert(staff3[staff], {kind="glyph", glyph=Glyph["accidentalSharp"], x=rx, y=ry, time={start=timing, stop=timing+1}})
elseif head.acc == "f" then
- table.insert(staff3[staff], {kind="glyph", glyph=Glyph["accidentalFlat"], x=rx, y=ry, time=timing})
+ table.insert(staff3[staff], {kind="glyph", glyph=Glyph["accidentalFlat"], x=rx, y=ry, time={start=timing, stop=timing+1}})
elseif head.acc == "n" then
- table.insert(staff3[staff], {kind="glyph", glyph=Glyph["accidentalNatural"], x=rx, y=ry, time=timing})
+ table.insert(staff3[staff], {kind="glyph", glyph=Glyph["accidentalNatural"], x=rx, y=ry, time={start=timing, stop=timing+1}})
end
lowheight = math.min(lowheight, ry)
@@ -440,13 +440,13 @@ local staff3ify = function(timing, el, staff)
-- leger lines
if head.y <= -6 then
for j = -6, head.y, -2 do
- table.insert(staff3[staff], {kind="line", t=1.2, x1=preoffset + rx - .2*em, y1=(em * (j + 4)) / 2, x2=preoffset + rx + w + .2*em, y2=(em * (j + 4)) / 2, time=timing})
+ table.insert(staff3[staff], {kind="line", t=1.2, x1=preoffset + rx - .2*em, y1=(em * (j + 4)) / 2, x2=preoffset + rx + w + .2*em, y2=(em * (j + 4)) / 2, time={start=timing, stop=timing+1}})
end
end
if head.y >= 6 then
for j = 6, head.y, 2 do
- table.insert(staff3[staff], {kind="line", t=1.2, x1=preoffset + rx - .2*em, y1=(em * (j + 4)) / 2, x2=preoffset + rx + w + .2*em, y2=(em * (j + 4)) / 2, time=timing})
+ table.insert(staff3[staff], {kind="line", t=1.2, x1=preoffset + rx - .2*em, y1=(em * (j + 4)) / 2, x2=preoffset + rx + w + .2*em, y2=(em * (j + 4)) / 2, time={start=timing, stop=timing+1}})
end
end
end
@@ -466,13 +466,13 @@ local staff3ify = function(timing, el, staff)
-- advance width for bravura is 1.18 - .1 for stem width
el.stemx = w + rx - 1.08 + preoffset
el.stemy = lowheight -.168*em - el.stemlen*em
- local stem = {kind="line", t=1, x1=el.stemx, y1=highheight - .168*em, x2=el.stemx, y2=lowheight -.168*em - el.stemlen*em, time=timing}
+ local stem = {kind="line", t=1, x1=el.stemx, y1=highheight - .168*em, x2=el.stemx, y2=lowheight -.168*em - el.stemlen*em, time={start=timing, stop=timing+.125}}
el.stem = stem
table.insert(staff3[staff], el.stem)
else
el.stemx = rx + .5 + preoffset
el.stemy = lowheight + el.stemlen*em
- local stem = {kind="line", t=1, x1=el.stemx, y1=lowheight + .168*em, x2=el.stemx, y2=highheight + el.stemlen*em, time=timing}
+ local stem = {kind="line", t=1, x1=el.stemx, y1=lowheight + .168*em, x2=el.stemx, y2=highheight + el.stemlen*em, time={start=timing, stop=timing+.125}}
el.stem = stem
table.insert(staff3[staff], stem)
end
@@ -481,11 +481,11 @@ local staff3ify = function(timing, el, staff)
if el.length == 8 and el.beamed == 0 then
if el.stemdir == 1 then
local fx, fy = glyph_extents(Glyph["flag8thDown"])
- table.insert(staff3[staff], {kind="glyph", glyph=Glyph["flag8thDown"], x=preoffset + rx, y=highheight + 3.5*em, time=timing})
+ table.insert(staff3[staff], {kind="glyph", glyph=Glyph["flag8thDown"], x=preoffset + rx, y=highheight + 3.5*em, time={start=timing, stop=timing+1}})
else
-- TODO: move glyph extents to a precalculated table or something
local fx, fy = glyph_extents(Glyph["flag8thUp"])
- table.insert(staff3[staff], {kind="glyph", glyph=Glyph["flag8thUp"], x=el.stemx - .48, y=lowheight -.168*em - 3.5*em, time=timing})
+ table.insert(staff3[staff], {kind="glyph", glyph=Glyph["flag8thUp"], x=el.stemx - .48, y=lowheight -.168*em - 3.5*em, time={start=timing, stop=timing+1}})
xdiff = xdiff + fx
end
end
@@ -518,17 +518,17 @@ local staff3ify = function(timing, el, staff)
inc = 7
end
for yoff=first, last, inc do
- table.insert(staff3[staff], {kind="quad", x1=x1 - 0.5, y1=y0 + m*(x1 - x0) + yoff, x2=x2, y2=y0 + m*(x2 - x0) + yoff, x3=x2, y3=y0 + m*(x2 - x0) + 5 + yoff, x4=x1 - 0.5, y4=y0 + m*(x1 - x0) + 5 + yoff, time=timing})
+ table.insert(staff3[staff], {kind="quad", x1=x1 - 0.5, y1=y0 + m*(x1 - x0) + yoff, x2=x2, y2=y0 + m*(x2 - x0) + yoff, x3=x2, y3=y0 + m*(x2 - x0) + 5 + yoff, x4=x1 - 0.5, y4=y0 + m*(x1 - x0) + 5 + yoff, time={start=timing, stop=timing+1}})
end
::continue::
end
elseif el.kind == "clef" then
- table.insert(staff3[staff], {kind="glyph", glyph=el.class.glyph, x=x, y=el.class.yoff, time=timing})
+ table.insert(staff3[staff], {kind="glyph", glyph=el.class.glyph, x=x, y=el.class.yoff, time={start=timing, stop=timing+1}})
xdiff = 30
elseif el.kind == "time" then
-- TODO: draw multidigit time signatures properly
- table.insert(staff3[staff], {kind="glyph", glyph=numerals[el.num], x=x, y=em, time=timing})
- table.insert(staff3[staff], {kind="glyph", glyph=numerals[el.denom], x=x, y=3*em, time=timing})
+ table.insert(staff3[staff], {kind="glyph", glyph=numerals[el.num], x=x, y=em, time={start=timing, stop=timing+1}})
+ table.insert(staff3[staff], {kind="glyph", glyph=numerals[el.denom], x=x, y=3*em, time={start=timing, stop=timing+1}})
xdiff = 30
end
@@ -715,19 +715,42 @@ end
function drawframe(time)
local toff = 0
- print(framewidth - toff, xmax)
+ --print(framewidth - toff, xmax)
if time > 4 then
return true
end
for _, staff in ipairs(stafforder) do
local extent = extents[staff]
for i, d in ipairs(staff3[staff]) do
- if d.time < time then
+ if d.time.start < time then
+ local delta = (time - d.time.start) / (d.time.stop - d.time.start)
if d.kind == "glyph" then
draw_glyph(d.glyph, toff + d.x - extent.xmin, d.y - extent.ymin + extent.yoff)
elseif d.kind == "line" then
- draw_line(d.t, toff + d.x1 - extent.xmin, d.y1 - extent.ymin + extent.yoff, toff + d.x2 - extent.xmin, d.y2 - extent.ymin + extent.yoff)
+ local endx, endy
+ if d.x1 < d.x2 then
+ endx = math.min(d.x1 + delta*(d.x2 - d.x1), d.x2)
+ else
+ endx = math.max(d.x1 + delta*(d.x2 - d.x1), d.x2)
+ end
+ if d.y1 < d.y2 then
+ endy = math.min(d.y1 + delta*(d.y2 - d.y1), d.y2)
+ else
+ endy = math.max(d.y1 + delta*(d.y2 - d.y1), d.y2)
+ end
+ draw_line(d.t, toff + d.x1 - extent.xmin, d.y1 - extent.ymin + extent.yoff, toff + endx - extent.xmin, endy - extent.ymin + extent.yoff)
elseif d.kind == "quad" then
+ local endx, endy
+ if d.x1 < d.x2 then
+ endx = math.min(d.x1 + delta*(d.x2 - d.x1), d.x2)
+ else
+ endx = math.max(d.x1 + delta*(d.x2 - d.x1), d.x2)
+ end
+ if d.y1 < d.y2 then
+ endy = math.min(d.y1 + delta*(d.y2 - d.y1), d.y2)
+ else
+ endy = math.max(d.y1 + delta*(d.y2 - d.y1), d.y2)
+ end
draw_quad(d.t, toff + d.x1 - extent.xmin, d.y1 - extent.ymin + extent.yoff, toff + d.x2 - extent.xmin, d.y2 - extent.ymin + extent.yoff, toff + d.x3 - extent.xmin, d.y3 - extent.ymin + extent.yoff, toff + d.x4 - extent.xmin, d.y4 - extent.ymin + extent.yoff)
end
end