| 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 |
if (typeof Object.assign !== 'function') { |
| 31 |
|
| 32 |
Object.defineProperty(Object, "assign", { |
| 33 |
value: function assign(target, varArgs) { |
| 34 |
'use strict'; |
| 35 |
if (target === null || target === undefined) { |
| 36 |
throw new TypeError('Cannot convert undefined or null to object'); |
| 37 |
} |
| 38 |
|
| 39 |
var to = Object(target); |
| 40 |
|
| 41 |
for (var index = 1; index < arguments.length; index++) { |
| 42 |
var nextSource = arguments[index]; |
| 43 |
|
| 44 |
if (nextSource !== null && nextSource !== undefined) { |
| 45 |
for (var nextKey in nextSource) { |
| 46 |
|
| 47 |
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { |
| 48 |
to[nextKey] = nextSource[nextKey]; |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
return to; |
| 54 |
}, |
| 55 |
writable: true, |
| 56 |
configurable: true |
| 57 |
}); |
| 58 |
} |
| 59 |
|
| 60 |
if (typeof abc2svg == "undefined") |
| 61 |
var abc2svg = {} |
| 62 |
|
| 63 |
abc2svg.mdnn = { |
| 64 |
|
| 65 |
cde2fcg: new Int8Array([0, 2, 4, -1, 1, 3, 5]), |
| 66 |
cgd2cde: new Int8Array([0, -4, -1, -5, -2, -6, -3, |
| 67 |
0, -4, -1, -5, -2, -6, -3, 0]), |
| 68 |
acc_tb: ["aff", "af", "n", "s", "ss"], |
| 69 |
|
| 70 |
glyphs: { |
| 71 |
n1: '<text id="n1" class="bn" x="-1.5" y="16">1</text>', |
| 72 |
n2: '<text id="n2" class="bn" x="-1.5" y="16">2</text>', |
| 73 |
n3: '<text id="n3" class="bn" x="-1.5" y="16">3</text>', |
| 74 |
n4: '<text id="n4" class="bn" x="-1.5" y="16">4</text>', |
| 75 |
n5: '<text id="n5" class="bn" x="-1.5" y="16">5</text>', |
| 76 |
n6: '<text id="n6" class="bn" x="-1.5" y="16">6</text>', |
| 77 |
n7: '<text id="n7" class="bn" x="-1.5" y="16">7</text>', |
| 78 |
nq: '<text id="nq" class="bn" x="8" y="16">\'</text>', |
| 79 |
nc: '<text id="nc" class="bn" x="8" y="16">,</text>', |
| 80 |
nh: '<path id="nh" class="stroke" d="m3.5 0l-7.2 0 0 -6.2 7.2 0"/>', |
| 81 |
nw: '<path id="nw" class="stroke" d="m6 -5l-7.2 0 0 -6.2 7.2 0 0 6.2"/>', |
| 82 |
aff: '<text id="aff" class="music" x="-8" y="11"></text>', |
| 83 |
af: '<text id="af" class="music" x="-8" y="11"></text>', |
| 84 |
nn: '<text id="nn" class="music" x="-8" y="11"></text>', |
| 85 |
ns: '<text id="ns" class="music" x="-8" y="11"></text>', |
| 86 |
nss: '<text id="nss" class="music" x="-8" y="11"></text>' |
| 87 |
}, |
| 88 |
|
| 89 |
decos: { |
| 90 |
n1: "9 n1 0 0 0", |
| 91 |
n2: "9 n2 0 0 0", |
| 92 |
n3: "9 n3 0 0 0", |
| 93 |
n4: "9 n4 0 0 0", |
| 94 |
n5: "9 n5 0 0 0", |
| 95 |
n6: "9 n6 0 0 0", |
| 96 |
n7: "9 n7 0 0 0", |
| 97 |
q: "0 nq 0 0 0", |
| 98 |
c: "0 nc 0 0 0", |
| 99 |
h: "0 nh 0 0 0", |
| 100 |
w: "0 nw 0 0 0", |
| 101 |
aff: "0 aff 0 0 0", |
| 102 |
af: "0 af 0 0 0", |
| 103 |
n: "0 nn 0 0 0", |
| 104 |
s: "0 ns 0 0 0", |
| 105 |
ss: "0 nss 0 0 0" |
| 106 |
}, |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
output_music: function(of) { |
| 111 |
var C = abc2svg.C, |
| 112 |
abc = this, |
| 113 |
cfmt = abc.cfmt(), |
| 114 |
cur_sy = abc.get_cur_sy(), |
| 115 |
voice_tb = abc.get_voice_tb(), |
| 116 |
sf = voice_tb[0].key.k_sf, |
| 117 |
delta = abc2svg.mdnn.cgd2cde[sf + 7] - 2 |
| 118 |
var s, s2, note, pit, nn, p, a, i, |
| 119 |
prev_oct = -10 |
| 120 |
|
| 121 |
if (!cfmt.mdnn) { |
| 122 |
of() |
| 123 |
return |
| 124 |
} |
| 125 |
|
| 126 |
delete voice_tb[0].key.k_a_acc |
| 127 |
voice_tb[0].clef.invis = true |
| 128 |
cur_sy.staves[0].stafflines = "..." |
| 129 |
|
| 130 |
|
| 131 |
for (s = voice_tb[0].sym; s; s = s.next) { |
| 132 |
switch (s.type) { |
| 133 |
case C.CLEF: |
| 134 |
s.invis = true |
| 135 |
continue |
| 136 |
case C.KEY: |
| 137 |
|
| 138 |
|
| 139 |
sf = s.k_sf |
| 140 |
delta = abc2svg.mdnn.cgd2cde[sf + 7] - 2 |
| 141 |
nn = sf - s.k_old_sf |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
s.k_old_sf = 0 |
| 151 |
s.k_sf = nn |
| 152 |
continue |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
default: |
| 198 |
continue |
| 199 |
case C.NOTE: |
| 200 |
break |
| 201 |
} |
| 202 |
note = s.notes[0] |
| 203 |
|
| 204 |
|
| 205 |
p = note.pit |
| 206 |
pit = p + delta |
| 207 |
nn = ((pit + 77) % 7) + 1 |
| 208 |
abc.dh_put('n' + nn, s, note) |
| 209 |
|
| 210 |
|
| 211 |
note.pit = 23 |
| 212 |
s.stem = 1 |
| 213 |
|
| 214 |
|
| 215 |
nn = (pit / 7) | 0 |
| 216 |
if (nn > prev_oct) { |
| 217 |
if (prev_oct != -10) |
| 218 |
abc.dh_put('q', s, note) |
| 219 |
prev_oct = nn |
| 220 |
} else if (nn < prev_oct) { |
| 221 |
abc.dh_put('c', s, note) |
| 222 |
prev_oct = nn |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
if (s.dur >= C.BLEN / 2) |
| 227 |
abc.dh_put(s.dur >= C.BLEN ? 'w' : 'h', s, note) |
| 228 |
|
| 229 |
|
| 230 |
a = note.acc |
| 231 |
if (a) { |
| 232 |
note.acc = 0 |
| 233 |
nn = abc2svg.mdnn.cde2fcg[(p + 5 + 16 * 7) % 7] - sf |
| 234 |
if (a != 3) |
| 235 |
nn += a * 7 |
| 236 |
nn = ((((nn + 1 + 21) / 7) | 0) + 2 - 3 + 32 * 5) % 5 |
| 237 |
abc.dh_put(abc2svg.mdnn.acc_tb[nn], s, note) |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
if (s.sls) { |
| 242 |
for (i = 0; i < s.sls.length; i++) |
| 243 |
s.sls[i].ty = C.SL_ABOVE |
| 244 |
} |
| 245 |
if (note.sls) { |
| 246 |
for (i = 0; i < note.sls.length; i++) |
| 247 |
note.sls[i].ty = C.SL_ABOVE |
| 248 |
} |
| 249 |
if (note.tie_ty != undefined) |
| 250 |
note.tie_ty = C.SL_ABOVE |
| 251 |
} |
| 252 |
|
| 253 |
of() |
| 254 |
}, |
| 255 |
|
| 256 |
set_fmt: function(of, cmd, param) { |
| 257 |
if (cmd == "mdnn") |
| 258 |
this.cfmt().mdnn = param |
| 259 |
else |
| 260 |
of(cmd, param) |
| 261 |
}, |
| 262 |
|
| 263 |
|
| 264 |
set_pitch: function(of, last_s) { |
| 265 |
of(last_s) |
| 266 |
if (!last_s |
| 267 |
|| !this.cfmt().mdnn) |
| 268 |
return |
| 269 |
|
| 270 |
var C = abc2svg.C, |
| 271 |
s = this.get_tsfirst() |
| 272 |
|
| 273 |
if (s && s.next && s.next.type == C.KEY) |
| 274 |
|
| 275 |
delete s.next.k_a_acc |
| 276 |
|
| 277 |
}, |
| 278 |
|
| 279 |
set_hooks: function(abc) { |
| 280 |
abc.output_music = abc2svg.mdnn.output_music.bind(abc, abc.output_music) |
| 281 |
abc.set_format = abc2svg.mdnn.set_fmt.bind(abc, abc.set_format) |
| 282 |
abc.set_pitch = abc2svg.mdnn.set_pitch.bind(abc, abc.set_pitch) |
| 283 |
|
| 284 |
Object.assign(abc.get_glyphs(), abc2svg.mdnn.glyphs) |
| 285 |
Object.assign(abc.get_decos(), abc2svg.mdnn.decos) |
| 286 |
abc.add_style("\n.bn {font-family:sans-serif; font-size:15px}") |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
if (!abc2svg.mhooks) |
| 291 |
abc2svg.mhooks = {} |
| 292 |
abc2svg.mhooks.mdnn = abc2svg.mdnn.set_hooks |