App-Music-ChordPro

 view release on metacpan or  search on metacpan

lib/ChordPro/res/abc/abc2svg/diag-1.js  view on Meta::CPAN

		glyphs[nm] = dc
	} // diag_add()

	// --- draw_gchord ---
	of(i, s, x, y)		// draw the chord symbols and the annotations

	if ((s.invis && s.play)	// play sequence: no chord nor annotation
	 || !n)			// no %%diagram
		return
	gch = s.a_gch[i]
	if (!gch || gch.type != 'g' || gch.capo)
		return
	nm = n + ch_cnv(gch.text)	// glyph name

	// build a glyph if not done yet
	if (!glyphs[nm])
		diag_add(nm)

	// output the diagram above the chord symbol
	if (glyphs[nm]) {
		x = s.x
		y = this.y_get(s.st, 1, x - 10, 20)
		this.xygl(x, y + 2, nm)
		this.y_set(s.st, 1, x - 10, 20, y + 34)
	}
    }, // draw_gchord()

    set_fmt: function(of, cmd, param) {
    var	a, d, n,
	cfmt = this.cfmt()

	switch (cmd) {
	case "diagram":
		n = param
		if (n == '0')
			n = ''
		else if (n != '4')
			n = '6'
		cfmt.diag = n
		return
	case "setdiag":
		n = cfmt.diag
		if (!n)
			n = "6"		// default = 6 strings guitar
		a = param.match(/(\S*)\s+(.*)/)
		if (a && a.length == 3) {
			d = a[2].split(' ')
			if (d && d.length >= 3) {
				abc2svg.diag["cd" + n][a[1].replace('/', '.')]
					= a[2]
				return
			}
		}
		this.syntax(1, this.errs.bad_val, "%%setdiag")
		return
	}
	of(cmd, param)
    },

    set_hooks: function(abc) {
	abc.draw_gchord = abc2svg.diag.draw_gchord.bind(abc,abc.draw_gchord)
	abc.set_format = abc2svg.diag.set_fmt.bind(abc, abc.set_format)
    }
} // diag

if (!abc2svg.mhooks)
	abc2svg.mhooks = {}
abc2svg.mhooks.diag = abc2svg.diag.set_hooks



( run in 1.534 second using v1.01-cache-2.11-cpan-2398b32b56e )