-
Notifications
You must be signed in to change notification settings - Fork 1
/
videolyrics.röd
92 lines (89 loc) · 2.02 KB
/
videolyrics.röd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
fileutil := require("fileutil")
cp := fileutil.cp
rm := fileutil.rm
frame := 0
}
outfile out, ext, prev=0 {
out ~= "#", ""..frame-prev
return `$out.$ext`
}
main midi, first, fps, out {
fps = parseInteger(fps)
push "0 s"
prev_svgs := new map
prev_lines := [first]
{} | bufferedExec "perl", "lyrics.pl", midi | for line do
space := indexOf(" ", line)
time := line[:space]
text := line[space+1:]
until [ text[-1:] = "\\" ] do
pull line
space := indexOf(" ", line)
text .= " "..line[space+1:]
done
text ~= "- ", "", " -", "", `\\`, "", "&", "ä", "%", "ö"
i := 0
lines := [""]
split text | for word do
lines[-1] .= " "..word
i += #word
if [ i > 20 ] do
lines += ""
i = 0
done
done
print "\r", text
time = parseFloating(time)
while [ frame/fps < time ] do
frame ++
svg := `<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg"
width="100%" height="100%" viewBox="0 0 1600 900">
<style>
/* <![CDATA[ */
tspan {
fill: white;
text-align: center;
font-family: monospace;
font-size: 80px;
}
tspan.smalltext {
font-size: 40px;
}
rect {
fill: black;
}
/* ]]> */
</style>
<rect width="100%" height="100%" />
<text y="50%" baseline-anchor="middle">
<tspan x="50%" text-anchor="middle">${prev_lines[0]}</tspan>`
for line in prev_lines[1:] do
svg .= `
<tspan x="50%" text-anchor="middle" dy="80">$line</tspan>`
done
svg .=`
<tspan x="50%" text-anchor="middle" dy="80" class="smalltext">${lines[0]}</tspan>`
for line in lines[1:] do
svg .=`
<tspan x="50%" text-anchor="middle" dy="40" class="smalltext">$line</tspan>`
done
svg .= `
</text>
</svg>
`
unless [ prev_svgs[svg]? ] do
push svg | writeStrings outfile(out, "svg")
{} | exec("convert", outfile(out, "svg"), outfile(out, "png")) | {}
rm outfile(out, "svg")
else
cp prev_svgs[svg], outfile(out, "png")
done
prev_svgs[svg] = outfile(out, "png")
push "\r", round(100*frame/fps)/100, " s"
done
prev_lines = lines
done
print ""
}