App-Music-ChordPro

 view release on metacpan or  search on metacpan

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

// along with abc2svg.  If not, see <http://www.gnu.org/licenses/>.
//
// This module is loaded when "%%gamelan" appears in a ABC source.
//
// Parameters (none)
//	%%gamelan 1
// scale:
// - sléndro - 5 equal tones
//	5-TET	C   D   E     G   A
//	detune	0 +40 +80 . +20 +60 .
// - pélog - 7 unequal tones
//		D _E+ F- ^G+ A _B c+ d
//		1  2  3   4  5  6 7  1
// (first note = ding)
//   Bali
//	selisir ^C D E ^G A	12356
//	tembung	E F A B c	45612
//	sunaren	F G B c d (?)	56723
//   Java
//	bem	D_E ^G A _B	12456
//	barang	_E F A _B c	23567
// numbers
//	??	E F G B c
//	??	C ^C _E G _A (or ^C D E ^G A)
// dot = continuation (not rest)

if (typeof abc2svg == "undefined")
    var	abc2svg = {}

abc2svg.gamelan = {

  cde2fcg: new Int8Array([0, 2, 4, -1, 1, 3, 5]),
  cgd2cde: new Int8Array([0, -4, -1, -5, -2, -6, -3,
			  0, -4, -1, -5, -2, -6, -3, 0]),
  acc2: new Int8Array([-2, -1, 3, 1, 2]),

// change %%staves and %%score
  do_pscom: function(of, p) {
	switch (p.match(/\w+/)[0]) {
	case 'staves':
	case 'score':
		p = p.replace(/\(|\)/g, '')
		break
	}
	of(p)
  },

// adjust some symbols before the generation
  output_music: function(of) {
    var	v,
	C = abc2svg.C,
	abc = this,
	cur_sy = abc.get_cur_sy(),
	voice_tb = abc.get_voice_tb()

	if (!abc.cfmt().gamelan) {
		of()
		return
	}

	// expand dots and long notes/rests
	function slice(s) {
	    var	m, n, s2, s3, d, d_orig

		if (s.dur <= C.BLEN * 3 / 8) {
			if ((s.dur_orig / 9 | 0) * 9 != s.dur_orig)
				return
			d = s.dur / 3
			d_orig = s.dur_orig / 3
			s.dur -= d
			s.dur_orig -= d_orig
			n = 1
		} else {
			if (s.dur >= C.BLEN)
				n = 3
			else if (s.dur == C.BLEN / 2)
				n = 1
			else
				n = 2
			d = d_orig = C.BLEN / 4
			s.dur = s.dur_orig = C.BLEN / 4
		}
		for (m = 0; m <= s.nhd; m++)
			s.notes[m].dur = s.dur
		s.beam_on = true
		while (--n >= 0) {
			s2 = {
				type: C.REST,
				v: s.v,
				p_v: s.p_v,
				st: s.st,
				fmt: s.fmt,
				dur: d,
				dur_orig: d_orig,
				stem: 1,
				multi: 0,
				nhd: 0,
				notes: [{
					pit: s.notes[0].pit,
					jn: 8
				}],
				xmx: 0,
				beam_on: true,
				noplay: true,
				time: s.time + s.dur,
				prev: s,
				next: s.next
			}
			s.next = s2
			if (s2.next)
				s2.next.prev = s2

			if (!s.ts_next) {
				s.ts_next = s2
				if (s.soln)
					s.soln = false
				s2.ts_prev = s
				s2.seqst = true
			} else {
			    for (s3 = s.ts_next; s3; s3 = s3.ts_next) {
				if (s3.time < s2.time)



( run in 1.440 second using v1.01-cache-2.11-cpan-d01c6094234 )