| 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 |
if (typeof abc2svg == "undefined") |
| 29 |
var abc2svg = {} |
| 30 |
|
| 31 |
abc2svg.sth = { |
| 32 |
|
| 33 |
|
| 34 |
recal_beam: function(bm, s) { |
| 35 |
var staff_tb = this.get_staff_tb(), |
| 36 |
y = staff_tb[s.st].y, |
| 37 |
s2 = bm.s2, |
| 38 |
y2 = staff_tb[s2.st].y |
| 39 |
|
| 40 |
if (s.sth != undefined) |
| 41 |
s.ys = s.sth |
| 42 |
if (s2.sth != undefined) |
| 43 |
s2.ys = s2.sth; |
| 44 |
bm.a = (s.ys + y - s2.ys - y2) / (s.xs - s2.xs); |
| 45 |
bm.b = s.ys - s.xs * bm.a + y |
| 46 |
while (1) { |
| 47 |
s.ys = bm.a * s.xs + bm.b - y |
| 48 |
if (s.stem > 0) |
| 49 |
s.ymx = s.ys + 2.5 |
| 50 |
else |
| 51 |
s.ymn = s.ys - 2.5; |
| 52 |
s = s.next |
| 53 |
if (s == s2) |
| 54 |
break |
| 55 |
} |
| 56 |
}, |
| 57 |
|
| 58 |
|
| 59 |
set_sth: function() { |
| 60 |
var s, h, v, sth_a, p_voice, |
| 61 |
voice_tb = this.get_voice_tb() |
| 62 |
|
| 63 |
for (v = 0; v < voice_tb.length; v++) { |
| 64 |
p_voice = voice_tb[v] |
| 65 |
if (p_voice.sth != null) |
| 66 |
continue |
| 67 |
sth_a = [] |
| 68 |
for (s = p_voice.sym; s; s = s.next) { |
| 69 |
if (s.sth) { |
| 70 |
sth_a = s.sth; |
| 71 |
s.sth = null |
| 72 |
} |
| 73 |
if (sth_a.length == 0 |
| 74 |
|| s.nflags <= -2 || s.stemless |
| 75 |
|| !(s.beam_st || s.beam_end)) |
| 76 |
continue |
| 77 |
h = sth_a.shift() |
| 78 |
if (h == '*') |
| 79 |
continue |
| 80 |
if (h == '|') { |
| 81 |
for (s = s.next; s; s = s.next) { |
| 82 |
if (s.bar_type) |
| 83 |
break |
| 84 |
} |
| 85 |
continue |
| 86 |
} |
| 87 |
h = Number(h) |
| 88 |
if (isNaN(h) || !h) |
| 89 |
continue |
| 90 |
if (s.stem >= 0) { |
| 91 |
s.ys = s.y + h; |
| 92 |
s.ymx = (s.ys + 2.5) | 0 |
| 93 |
} else { |
| 94 |
s.ys = s.y - h; |
| 95 |
s.ymn = (s.ys - 2.5) | 0 |
| 96 |
} |
| 97 |
s.sth = s.ys |
| 98 |
} |
| 99 |
} |
| 100 |
}, |
| 101 |
|
| 102 |
calculate_beam: function(of, bm, s1) { |
| 103 |
var done = of(bm, s1) |
| 104 |
if (done && bm.s2 && (s1.sth || bm.s2.sth)) |
| 105 |
abc2svg.sth.recal_beam.call(this, bm, s1) |
| 106 |
return done |
| 107 |
}, |
| 108 |
|
| 109 |
new_note: function(of, grace, tp_fact) { |
| 110 |
var C = abc2svg.C, |
| 111 |
s = of(grace, tp_fact), |
| 112 |
curvoice = this.get_curvoice() |
| 113 |
|
| 114 |
if (curvoice.sth && s && s.type == C.NOTE) { |
| 115 |
s.sth = curvoice.sth; |
| 116 |
curvoice.sth = null |
| 117 |
} |
| 118 |
return s |
| 119 |
}, |
| 120 |
|
| 121 |
set_fmt: function(of, cmd, param) { |
| 122 |
if (cmd == "sth") { |
| 123 |
var curvoice = this.get_curvoice() |
| 124 |
if (curvoice) |
| 125 |
curvoice.sth = param.split(/[ \t;-]+/) |
| 126 |
return |
| 127 |
} |
| 128 |
of(cmd, param) |
| 129 |
}, |
| 130 |
|
| 131 |
set_stems: function(of) { |
| 132 |
of(); |
| 133 |
abc2svg.sth.set_sth.call(this) |
| 134 |
}, |
| 135 |
|
| 136 |
set_hooks: function(abc) { |
| 137 |
abc.calculate_beam = abc2svg.sth.calculate_beam.bind(abc, abc.calculate_beam); |
| 138 |
abc.new_note = abc2svg.sth.new_note.bind(abc, abc.new_note); |
| 139 |
abc.set_format = abc2svg.sth.set_fmt.bind(abc, abc.set_format); |
| 140 |
abc.set_stems = abc2svg.sth.set_stems.bind(abc, abc.set_stems) |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
if (!abc2svg.mhooks) |
| 145 |
abc2svg.mhooks = {} |
| 146 |
abc2svg.mhooks.sth = abc2svg.sth.set_hooks |