App-Music-ChordPro

 view release on metacpan or  search on metacpan

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

	    var	s, i, w, bt, rep,
		bars = [],
		chords = [],
		parts = [],
		chord = [],
		beat = get_beat(voice_tb[0].meter),
		wm = voice_tb[0].meter.wmeasure,
		cur_beat = 0,
		beat_i = 0,
		tr = (tsfirst.p_v.key.k_sf + 12) * 5,	// transposition to "C"
		mode = tsfirst.p_v.key.k_mode

		// scan all the symbols
		bars.push('|')
		for (s = tsfirst; s; s = s.ts_next) {
			while (s.time > cur_beat) {
				if (beat_i < 3)	// only 2, 3 or 4 beats / measure...
					beat_i++
				cur_beat += beat
			}
			if (s.part)
				parts[chords.length] = s.part.text
			switch (s.type) {
			case C.KEY:
				tr = (s.k_sf + 12) * 5
				mode = s.k_mode
				break
			case C.NOTE:
			case C.REST:
				if (!s.a_gch)
					break

				// search a chord symbol
				for (i = 0; i < s.a_gch.length; i++) {
					if (s.a_gch[i].type == 'g') {
						if (!chord[beat_i]) {
							chord[beat_i] =
							    set_nm(s.a_gch[i].text,
									tr, mode)
						}
						break
					}
				}
				break
			case C.BAR:
				bt = s.bar_type
				if (s.time < wm) {		// if anacrusis
					if (chord.length) {
						chords.push(chord)
						bars.push(bt)
					} else {
						bars[0] = bt
					}
				} else {
					if (!s.bar_num)		// if not normal measure bar
						break
					chords.push(chord)
					bars.push(bt)
				}
				chord = []
				cur_beat = s.time	// synchronize in case of error
				beat_i = 0
				if (bt.indexOf(':') >= 0)
					rep = true	// some repeat
				while (s.ts_next && s.ts_next.type == C.BAR)
					s = s.ts_next
				break
			case C.METER:
				beat = get_beat(s)
				wm = s.wmeasure
				break
			}
		}

		if (chord.length) {
			bars.push('')
			chords.push(chord)
		}
		if (!chords.length)
			return			// no chord in this tune

		sb.chords = chords
		sb.bars = bars
		if (parts.length)
			sb.parts = parts
	} // build_chords

	// -------- set_stems --------

	// create a specific block
	if (nns) {
		C = abc2svg.C
		tsfirst = this.get_tsfirst()
		fmt = tsfirst.fmt
		voice_tb = this.get_voice_tb()
		p_v = voice_tb[this.get_top_v()]
		s = {
			type: C.BLOCK,
			subtype: 'nns',
			dur: 0,
			time: 0,
			p_v: p_v,
			v: p_v.v,
			st: p_v.st
		}

		build_chords(s)			// build the array of the chords

		// and insert it in the tune
		if (!s.chords) {		// if no chord
			;
		} else if (nns.nomusic) {	// if just the chords
			this.set_tsfirst(s)
		} else if (nns.n < 0) {		// below
			for (s2 = tsfirst; s2.ts_next; s2 = s2.ts_next)
				;
			s.time = s2.time
			s.prev = p_v.last_sym.prev // before the last symbol
			s.prev.next = s
			s.next = p_v.last_sym
			p_v.last_sym.prev = s



( run in 0.647 second using v1.01-cache-2.11-cpan-5b529ec07f3 )