abc2svg
Diff
Not logged in

Differences From Artifact [394c7934f8]:

To Artifact [eb87cc4e2f]:


771
772
773
774
775
776
777
778
779

780
781
782
783
784
785
786
787
788
789
790
791
792
793




794
795
796







797
798
799



800
801
802
803
804
805
806
771
772
773
774
775
776
777


778


779
780
781
782
783
784
785
786
787
788


789
790
791
792
793


794
795
796
797
798
799
800
801


802
803
804
805
806
807
808
809
810
811







-
-
+
-
-










-
-
+
+
+
+

-
-
+
+
+
+
+
+
+

-
-
+
+
+







	an = abc2svg.b40a(b40)			// new accidental

	if (sk.k_none) {			// if atonal music
		b40 %= 40
		if (an == -2 || an == 2		// __ or ^^
		 || b40 == 1 || b40 == 38 || b40 == 18 || b40 == 15) {
						// _C, ^B, _F, ^E
			if (an < 0)
				note.pit--
			note.pit += (an > 0) ? 1 : -1
			else
				note.pit++
			an = 0
		}
	}

	if (a) {
		if (sk.k_a_acc) {		// if accidental list
			ak = sk.k_map[(note.pit + 19) % 7]
			if (ak == an)
				an = 0		// accidental in the key
		}
		if (!an)
			an = 3
		if (!an) {
			n = same_pit(s, note)
			an = (n && n.acc) ? 3 : 0
		}
	} else if (sk.k_none) {			// if no key
		if (acc_same_pitch(s, note.midi)) // and accidental from previous notes
			return			// no change
		n = same_pit(s, note)
		if (n) {
			if (n.acc == an)
				return
			if (!an)
				an = 3
		}
	} else if (sk.k_a_acc) {		// if accidental list
		if (acc_same_pitch(s, note.midi)) // and accidental from previous notes
			return			// no change
		n = same_pit(s, note)
		if (n && n.acc == an)
			return
		ak = sk.k_map[(note.pit + 19) % 7]
		if (ak)
			an = 3		// natural
	} else {
		return			// same accidental (in the key)
	}
	if (d && an != a) {
1480
1481
1482
1483
1484
1485
1486
1487
1488


1489
1490
1491



1492
1493

1494
1495
1496
1497
1498

1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513



1514
1515
1516
1517
1518
1519


1520
1521
1522
1523
1524
1525
1526
1485
1486
1487
1488
1489
1490
1491


1492
1493
1494


1495
1496
1497
1498
1499
1500
1501
1502
1503
1504

1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518


1519
1520
1521
1522
1523
1524
1525


1526
1527
1528
1529
1530
1531
1532
1533
1534







-
-
+
+

-
-
+
+
+


+




-
+













-
-
+
+
+




-
-
+
+








   var sf = abc2svg.b40sf[n_b40]
	sk.k_sf = sf
	sk.k_map = abc2svg.keys[sf + 7]	// map of the notes with accidentals
}

/*
 * for transpose purpose, check if a pitch is already in the measure or
 * if it is tied from a previous note
 * for transpose purpose, search a note that has the same pitch
 * as a note in the measure or tied from a previous note
 */
function acc_same_pitch(s, midi) {
    var	i, a,
function same_pit(s, note) {
    var	i,
	pit = note.pit,
	time = s.time

//fixme: other voice?
	for (s = s.prev; s; s = s.prev) {
		switch (s.type) {
		case C.BAR:
			if (s.time < time)
				return //undefined // not the same pitch
				return //undefined
			while (1) {
				s = s.prev
				if (!s)
					return //undefined
				if (s.type == C.NOTE) {
					if (s.time + s.dur == time)
						break
					return //undefined
				}
				if (s.time < time)
					return //undefined
			}
			for (i = 0; i <= s.nhd; i++) {
				if (s.notes[i].midi == midi)
					return 1 //true
				if (s.notes[i].pit == pit
				 && s.notes[i].tie_ty)
					return s.notes[i]
			}
			return //undefined
		case C.NOTE:
			for (i = 0; i <= s.nhd; i++) {
				if (s.notes[i].midi == midi)
					return 1 //true
				if (s.notes[i].pit == pit)
					return s.notes[i]
			}
			break
		}
	}
	return //undefined
}