| 1 |
|
| 2 |
|
| 3 |
e |
| 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 |
"use strict" |
| 29 |
if (typeof abc2svg == "undefined") |
| 30 |
var abc2svg = {} |
| 31 |
|
| 32 |
abc2svg.swing = { |
| 33 |
|
| 34 |
swing: function(first, voice_tb, cfmt) { |
| 35 |
var v, p_v, sw, s, s2, d, m, beat, anac, |
| 36 |
C = abc2svg.C, |
| 37 |
a_dur = [], |
| 38 |
nv = voice_tb.length |
| 39 |
|
| 40 |
|
| 41 |
function set_dur(s) { |
| 42 |
if (!s.a_meter[0] || s.a_meter[0].top[0] == 'C' |
| 43 |
|| !s.a_meter[0].bot) |
| 44 |
beat = C.BLEN / 4 |
| 45 |
else if (s.a_meter[0].bot[0] == 8 |
| 46 |
&& s.a_meter[0].top[0] % 3 == 0) |
| 47 |
return 1 |
| 48 |
else |
| 49 |
beat = C.BLEN / s.a_meter[0].bot[0] |0 |
| 50 |
a_dur[0] = beat / 2 |
| 51 |
a_dur[1] = beat / 4 |
| 52 |
|
| 53 |
|
| 54 |
if (!s.time) { |
| 55 |
anac = 0 |
| 56 |
var wm = s.wmeasure |
| 57 |
while (s && s.time < wm) { |
| 58 |
if (s.bar_type) { |
| 59 |
anac = wm - s.time |
| 60 |
break |
| 61 |
} |
| 62 |
s = s.next |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
for (v = 0; v < nv; v++) { |
| 68 |
p_v = voice_tb[v] |
| 69 |
sw = cfmt.swing || p_v.swing |
| 70 |
if (!sw || !p_v.sym) |
| 71 |
continue |
| 72 |
if (set_dur(p_v.meter)) |
| 73 |
continue |
| 74 |
for (s = p_v.sym; s.next; s = s.next) { |
| 75 |
if (s.subtype == "swing") |
| 76 |
sw = s.sw |
| 77 |
if (!sw |
| 78 |
|| !s.dur) { |
| 79 |
if (s.a_meter) |
| 80 |
set_dur(s) |
| 81 |
continue |
| 82 |
} |
| 83 |
if ((s.time + anac - a_dur[0]) % beat |
| 84 |
&& (s.time + anac - a_dur[1]) % beat) { |
| 85 |
s2 = s |
| 86 |
continue |
| 87 |
} |
| 88 |
if (s2 && s2.time + s2.dur == s.time) { |
| 89 |
d = s2.dur - (s2.time + s2.dur) % beat + sw[0] * beat |
| 90 |
s2.dur = d |
| 91 |
for (m = 0; m < s.nhd; m++) |
| 92 |
s2.notes[m].dur = d |
| 93 |
} |
| 94 |
d = s.time + s.dur |
| 95 |
s.time = ((s.time / beat | 0) + sw[0] + sw[1]) * beat |
| 96 |
if (s.dur > beat / 2 || s.ti1) |
| 97 |
d -= s.time |
| 98 |
else |
| 99 |
d = sw[2] * beat |
| 100 |
s.dur = d |
| 101 |
for (m = 0; m < s.nhd; m++) |
| 102 |
s.notes[m].dur = d |
| 103 |
s2 = s |
| 104 |
} |
| 105 |
} |
| 106 |
}, |
| 107 |
|
| 108 |
set_fmt: function(of, cmd, parm) { |
| 109 |
var parse, sw, curvoice, i, s |
| 110 |
|
| 111 |
if (cmd == "playswing") { |
| 112 |
parse = this.get_parse(), |
| 113 |
curvoice = this.get_curvoice() |
| 114 |
sw = /(\d+)\s+(\d+)\s+(\d+)/.exec(parm) |
| 115 |
|
| 116 |
if (sw) { |
| 117 |
sw = sw.splice(1) |
| 118 |
if (+sw[0] + +sw[1] + +sw[2] > 100) |
| 119 |
return abc.syntax(1, "playswing greater than 100%") |
| 120 |
for (i = 0; i < 3; i++) |
| 121 |
sw[i] = +sw[i] / 100 |
| 122 |
} |
| 123 |
if (parse.state >= 2) { |
| 124 |
s = this.new_block("swing") |
| 125 |
s.play = s.invis = 1 |
| 126 |
s.sw = sw |
| 127 |
if (sw) |
| 128 |
curvoice.swing = 1 |
| 129 |
} else { |
| 130 |
this.cfmt().swing = sw |
| 131 |
} |
| 132 |
return |
| 133 |
} |
| 134 |
of(cmd, parm) |
| 135 |
}, |
| 136 |
|
| 137 |
set_hooks: function(abc) { |
| 138 |
abc.set_format = abc2svg.swing.set_fmt.bind(abc, abc.set_format) |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
if (!abc2svg.mhooks) |
| 143 |
abc2svg.mhooks = {} |
| 144 |
abc2svg.mhooks.swing = abc2svg.swing.set_hooks |