-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht-staff.typ
162 lines (154 loc) · 4.54 KB
/
t-staff.typ
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#import "t-attributes.typ": *
// paint eigth note
#let eigth(x, k, h, c, mark) = {
let y = -k * h / 8
let p = h / 4 * 0.5
place(bottom, dx: x, dy: y - p/2)[#ellipse(
height: (h/4-p),
width : (h/4-p)*1.5,
fill : c,
stroke: none,
)]
if calc.abs(mark - 0.0) >= 0.0001 {
let dec = if calc.abs(mark - 0.1) < 0.0001 {
[♯]
} else if calc.abs(mark - 0.2) < 0.0001 {
[♭]
} else {
[♮]
}
place(bottom, dx: x + h/4, dy: y)[#text(size: h/2, fill: c, weight: "bold")[#dec]]
}
{
let x = x + (h/4-p)*1.5 - h/48
let d = if k <= 100000 { h/6 } else { -h/6 }
let y = if k <= 100000 {
y - 3*h/4 + d - h/8
} else {
y + 3*h/4
}
place(bottom, dx: x, dy: y)[#polygon(
fill: c.transparentize(20%),
stroke: c + h/24,
(0pt, 0pt),
(0pt, h/4 - p),
(h*7/24, h/4 + d - p),
(h*7/24, 0pt + d),
)]
}
{
let x = x + (h/4-p)*1.5 - h/48
let y = if k <= 100000 { y } else { y + 3*h/4 };
place(bottom, dx: x, dy: y - h/8)[#line(
stroke: h/24 + c,
start : (0pt, 0pt),
end : (0pt, 3*h/4),
)]
}
}
// paint eigth note
#let sixteenth(x, k, h, c, mark) = {
let y = -k * h / 8
let p = h / 4 * 0.5
place(bottom, dx: x, dy: y - p/2)[#ellipse(
height: (h/4-p),
width : (h/4-p)*1.5,
fill : c,
stroke: none,
)]
if calc.abs(mark - 0.0) >= 0.0001 {
let dec = if calc.abs(mark - 0.1) < 0.0001 {
[♯]
} else if calc.abs(mark - 0.2) < 0.0001 {
[♭]
} else {
[♮]
}
place(bottom, dx: x + h/4, dy: y)[#text(size: h/2, fill: c)[#dec]]
}
{
let x = x + (h/4-p)*1.5 - h/48
let d = if k <= 100000 { h/6 } else { -h/6 }
let y = if k <= 100000 {
y - 3*h/4 + d - h/8
} else {
y + 3*h/4
}
place(bottom, dx: x, dy: y)[#polygon(
stroke: c + h/24,
fill: none,
(0pt, 0pt),
(0pt, h/8),
(h*7/24, h/8 + d),
(h*7/24, 0pt + d),
)]
}
{
let x = x + (h/4-p)*1.5 - h/48
let y = if k <= 100000 { y } else { y + 3*h/4 };
place(bottom, dx: x, dy: y - h/8)[#line(
stroke: h/24 + c,
start : (0pt, 0pt),
end : (0pt, 3*h/4),
)]
}
}
// paint quater note
#let quater(x, k, h, c, mark) = {
let y = -k * h / 8
let p = h / 4 * 0.5
place(bottom, dx: x, dy: y - p/2)[#ellipse(
height: (h/4-p),
width : (h/4-p)*1.5,
fill : c,
stroke: none,
)]
if calc.abs(mark - 0.0) >= 0.0001 {
let dec = if calc.abs(mark - 0.1) < 0.0001 {
[♯]
} else if calc.abs(mark - 0.2) < 0.0001 {
[♭]
} else {
[♮]
}
place(bottom, dx: x + h/4, dy: y)[#text(size: h/2, fill: c, weight: "bold")[#dec]]
}
let y = if k <= 100000 { y } else { y + 3*h/4 };
place(bottom, dx: x + (h/4-p)*1.5 - h/48, dy: y - h/8)[#line(
stroke: h/24 + fg-color,
start : (0pt, 0pt),
end : (0pt, 3*h/4),
)]
}
#let staff(w: 100%, h: 2cm, ..data) = rect(width: w, height: h, stroke: 0.5pt + fg-color, inset: 0pt, outset: 0pt, fill: bg-color)[
// display staff lines
#for i in (0,1,2,3,4) {
place(bottom, dy: -i/4*h)[#line(stroke: 0.5pt + fg-color, length: 100%)]
}
// display key
#place(bottom)[#text(size: h, fill: fg-color)[𝄞]]
// compute length
#let len = data.pos().len()
// display each note on staff
#for (j, last, (sym, c, k)) in zip-shl(data.pos()).enumerate() {
if sym == "quater" { for t in k {
quater(h+j/len*(w - h), int(t), h, c, t - int(t))
}}
if sym == "eigth" { for t in k {
eigth(h+j/len*(w - h), int(t), h, c, t - int(t))
}}
if sym == "sixteenth" { for t in k {
sixteenth(h+j/len*(w - h), int(t), h, c, t - int(t))
}}
}
]
#let zip-shl(x) = {
let y = (none, ..x.slice(0, -1))
(..for i in range(x.len()) { ((y.at(i), x.at(i)), ) })
}
#let g(x) = ("g", x)
#let qua(c: fg-color, ..x) = ("quater", c, x.pos().sorted())
#let eig(c: fg-color, ..x) = ("eigth" , c, x.pos().sorted())
#let six(c: fg-color, ..x) = ("sixteenth", c, x.pos().sorted())
#let rest(x) = ("rest", x)
#set page(fill: bg-color)