App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/res/abc/abc2svg/grid3-1.js view on Meta::CPAN
while (1) {
cl = cells[nr][i++]
if (!cl)
break
if (cl.length == 2) {
cl[2] = cl[1] // "| A B |" => "|A - B|"
cl[1] = ''
}
w = abc.strwh(cl.join(''))[0]
if (w > wc)
wc = w
}
nr++
}
wc += abc.strwh(' ')[0]
// build the grid and insert it in the music
build_grid()
abc.blk_flush()
}, // block_gen()
// handle %%begingrid
do_begin_end: function(of, type, opt, txt) {
var i, s, v,
lm = -1, // left margin - default: center the grid
width // grid width - default: computed
if (type != "grid") {
of(type, opt, txt)
return
}
// replace the accidentals
txt = txt.replace(/#|=|b/g,
function(x) {
switch (x) {
case '#': return "\u266f"
case '=': return "\u266e"
// case 'b': return "\u266d"
}
return "\u266d"
})
opt = opt.trim().split(/\s+/)
while (1) {
i = opt.shift()
if (!i)
break
switch (i[0]) {
case 'c': // chord-define
this.cfmt().csdef = txt
break
case 'n': // noprint
type = ""
break
case 'l': // lm=..
case 'w': // width=..
v = i.match(/-?[\d.]+.?.?/)
if (v) {
v = this.get_unit(v[0])
if (!isNaN(v)) {
if (i[0] == 'l')
lm = v
else
width = v
}
}
break
}
}
if (type) {
type += "3"
if (this.get_parse().state >= 2) {
s = this.new_block(type)
s.text = txt
s.lm = lm
s.width = width
} else {
abc2svg.grid3.block_gen.call(this, null, {
subtype: type,
text: txt,
lm: lm,
width: width
})
}
}
}, // do_begin_end()
output_music: function(of) {
var ln, i, dt, ss, ntim, p_vc, s3, cl,
C = abc2svg.C,
abc = this,
s = abc.get_tsfirst(),
vt = abc.get_voice_tb(),
t = abc.cfmt().csdef,
cs = []
// add a chord symbol
function add_cs(ss, ch) {
var s = { // invisible rest in the voice "grid3"
type: C.REST,
fname: ss.fname,
istart: ss.istart,
iend: ss.iend,
v: p_vc.v,
p_v: p_vc,
time: ntim,
st: 0,
fmt: ss.fmt,
dur: 0,
dur_orig: 0,
invis: true,
seqst: true,
nhd: 0,
notes: [{
pit: 18,
dur: 0
}]
}
( run in 0.753 second using v1.01-cache-2.11-cpan-140bd7fdf52 )