| ︙ | | | ︙ | |
769
770
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
|
}
map[2] = a[i]
break
}
}
}
// set the transposition in the first key signature or in a new key
function set_transp() {
var s
if (curvoice.ckey.k_bagpipe || curvoice.ckey.k_drum)
return
if (cfmt.transp && curvoice.shift) // if %%transpose and shift=
syntax(0, "Mix of old and new transposition syntaxes");
if (is_voice_sig()) { // if no symbol yet
curvoice.okey.fmt = cfmt
curvoice.key = s = clone(curvoice.okey)
} else {
s = clone(curvoice.ckey)
if (!curvoice.new)
s.k_old_sf = s.k_sf
sym_link(s)
}
delete s.invis // needed if K:C/none at start of tune
key_transp(s)
curvoice.ckey = clone(s)
if (curvoice.key.k_none)
s.k_sf = 0
}
// set the control values (P: and Q:)
function set_ctrl() {
var s, tim, e
for (tim in parse.ctrl) {
// if (!parse.ctrl.hasOwnProperty(tim))
// continue
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
769
770
771
772
773
774
775
776
777
778
779
780
781
782
|
}
map[2] = a[i]
break
}
}
}
// set the control values (P: and Q:)
function set_ctrl() {
var s, tim, e
for (tim in parse.ctrl) {
// if (!parse.ctrl.hasOwnProperty(tim))
// continue
|
| ︙ | | | ︙ | |
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
|
cfmt.transp = 0
// fall thru
case 1:
cfmt.transp = (cfmt.transp || 0) + val
return
}
cfmt.transp = (cfmt.transp || 0) + val
set_transp()
return
case "tune":
//fixme: to do
return
case "user":
set_user(param)
return
|
|
|
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
|
cfmt.transp = 0
// fall thru
case 1:
cfmt.transp = (cfmt.transp || 0) + val
return
}
cfmt.transp = (cfmt.transp || 0) + val
key_trans()
return
case "tune":
//fixme: to do
return
case "user":
set_user(param)
return
|
| ︙ | | | ︙ | |
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
|
if (tsfirst) { // if non void, keep tune data for upper layers
tunes.push([tsfirst, voice_tb, info, cfmt])
tsfirst = null
}
}
// transpose a key
function key_transp(s) {
var i, n, a_acc, b40, d
if (s.k_none) // no key
return
// set the score transposition
n = (curvoice.score | 0) // new transposition
+ (curvoice.shift | 0)
+ (cfmt.transp | 0)
if ((curvoice.tr_sco | 0) == n)
return // same transposition
d = n
if (d == 0)
d = -curvoice.tr_sco // revert to no transposition
curvoice.tr_sco = n // b40 interval
b40 = (s.k_b40 + 200 + d) % 40
i = abc2svg.b40k[b40] - b40
if (i) {
if (d > 0)
curvoice.tr_sco -= i
else
curvoice.tr_sco += i
b40 += i
}
s.k_b40 = b40
s.k_sf = abc2svg.b40sf[b40]
// transpose the accidental list
if (!s.k_a_acc)
return
a_acc = []
|
|
|
|
>
>
>
|
|
>
>
>
>
>
|
>
>
>
>
|
>
>
>
|
|
>
>
|
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
|
if (tsfirst) { // if non void, keep tune data for upper layers
tunes.push([tsfirst, voice_tb, info, cfmt])
tsfirst = null
}
}
// transpose the current key of the voice (called on K: or V:)
function key_trans() {
var i, n, a_acc, b40,
s = curvoice.ckey, // current key
ti = s.time || 0
if (s.k_bagpipe || s.k_drum
|| s.k_none) // no key
return
// set the score transposition
n = (curvoice.score | 0) // new transposition
+ (curvoice.shift | 0)
+ (cfmt.transp | 0)
if ((curvoice.tr_sco | 0) == n)
return // same transposition
// get the current key or create a new one
if (is_voice_sig()) { // if no symbol yet
curvoice.key = s // new root key of the voice
} else if (curvoice.time != ti) { // if no K: at this time
s = clone(s.orig || s) // new key
if (!curvoice.new)
s.k_old_sf = curvoice.ckey.k_sf
curvoice.ckey = s
sym_link(s)
}
if (cfmt.transp && curvoice.shift) // if %%transpose and shift=
syntax(0, "Mix of old and new transposition syntaxes");
// define the new key
curvoice.tr_sco = n // b40 interval
b40 = (s.k_b40 + 200 + n) % 40 // (s.k_40 is the original K:)
i = abc2svg.b40k[b40] - b40
if (i) {
if (n > 0)
curvoice.tr_sco -= i
else
curvoice.tr_sco += i
b40 += i
}
s.orig = clone(s) // keep the original K: definition
s.k_b40 = b40
s.k_sf = abc2svg.b40sf[b40]
// transpose the accidental list
if (!s.k_a_acc)
return
a_acc = []
|
| ︙ | | | ︙ | |
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
|
curvoice.eoln = true
}
}
}
// treat K: (kp = key signature + parameters)
function get_key(parm) {
var v, p_voice, transp, sndtran, tr_p, nt,
// [s_key, a] = new_key(parm) // KO with nodejs
a = new_key(parm),
s_key = a[0],
s = s_key
a = a[1]
if (parse.state == 1) { // in tune header (first K:)
if (s_key.k_sf == undefined && !s_key.k_a_acc) { // empty K:
s_key.k_sf = 0;
s_key.k_none = true
s_key.k_map = abc2svg.keys[7]
}
for (v = 0; v < voice_tb.length; v++) {
p_voice = voice_tb[v];
p_voice.key = clone(s_key);
p_voice.okey = clone(s_key);
p_voice.ckey = clone(s_key)
}
parse.ckey = clone(s_key)
if (a.length) {
memo_kv_parm('*', a)
a = []
}
if (!glovar.ulen)
glovar.ulen = C.BLEN / 8;
goto_tune()
}
set_kv_parm(a)
tr_p = curvoice.tr_p // change in score transposition
curvoice.tr_p = 0
curvoice.tr_sco = 0
if (s.k_sf == undefined) { // if no key
if (!s.k_a_acc // if no accidental list
&& !tr_p) // and no score transposition
return // not a key signature
s_key.k_sf = curvoice.okey.k_sf // set the same key
s_key.k_b40 = curvoice.okey.k_b40
}
curvoice.okey = clone(s_key) // keep the original key
key_transp(s)
s_key.k_old_sf = curvoice.ckey.k_sf // memorize the key changes
if ((!s_key.k_a_acc || !s_key.k_a_acc.length)
&& !s_key.k_sf && !s_key.k_old_sf)
s_key.invis = true // don't display the key signature
if (!s_key.k_b40)
s_key.k_b40 = curvoice.ckey.k_b40
curvoice.ckey = s_key
if (is_voice_sig()) {
s_key.fmt = cfmt
curvoice.key = clone(s_key)
if (s_key.k_none)
curvoice.key.k_sf = 0
} else {
sym_link(s_key) // (don't move the key)
}
}
// get / create a new voice
function new_voice(id) {
var v, p_v_sav,
p_voice = voice_tb[0],
|
|
|
>
>
>
>
|
>
|
<
<
<
<
<
|
|
|
>
|
<
<
<
<
<
|
>
>
>
|
|
>
>
|
<
|
<
<
<
>
|
|
|
<
<
|
|
|
|
<
>
|
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
|
curvoice.eoln = true
}
}
}
// treat K: (kp = key signature + parameters)
function get_key(parm) {
var v, p_voice, transp, sndtran, nt,
// [s_key, a] = new_key(parm) // KO with nodejs
a = new_key(parm),
s_key = a[0],
s = s_key,
empty = s.k_sf == undefined && !s.k_a_acc
a = a[1]
if (empty)
s.invis = 1 //true // don't display empty K:
if (parse.state == 1) { // in tune header (first K:)
parse.ckey = s // root key
if (empty) {
s_key.k_sf = 0;
s_key.k_none = true
s_key.k_map = abc2svg.keys[7]
}
for (v = 0; v < voice_tb.length; v++) {
p_voice = voice_tb[v];
p_voice.ckey = clone(s_key)
}
if (a.length) {
memo_kv_parm('*', a)
a = []
}
if (!glovar.ulen)
glovar.ulen = C.BLEN / 8;
goto_tune()
} else if (!empty) {
s.k_old_sf = curvoice.ckey.k_sf // memorize the previous key
curvoice.ckey = s
sym_link(s)
if (curvoice.tr_sco)
curvoice.tr_sco = 0
}
// set the voice parameters
if (!curvoice) { // if first K:
if (!voice_tb.length) {
curvoice = new_voice("1")
var def = 1 // true
} else {
curvoice = voice_tb[staves_found < 0 ? 0 : par_sy.top_voice]
}
}
get_voice(curvoice.id + ' ' + a.join(' '))
if (def)
curvoice.default = 1 //true
if (s == parse.ckey // if first K:
&& curvoice.clef.clef_type == 'p') { // and percussion
s.k_drum = 1 //true // no transpose
s.k_sf = 0 // no accidental
s.k_b40 = 2
s.k_map = abc2svg.keys[7]
}
}
// get / create a new voice
function new_voice(id) {
var v, p_v_sav,
p_voice = voice_tb[0],
|
| ︙ | | | ︙ | |
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
|
// vol: 0
},
scale: 1,
// st: 0,
// cst: 0,
ulen: glovar.ulen,
dur_fact: 1,
key: clone(parse.ckey), // key at start of tune (parse / gene)
ckey: clone(parse.ckey), // current key (parse / gene)
okey: clone(parse.ckey), // key without transposition (parse)
meter: clone(glovar.meter),
wmeasure: glovar.meter.wmeasure,
staffnonote: 1,
clef: {
type: C.CLEF,
clef_auto: true,
clef_type: "a", // auto
time: 0
},
acc: [], // accidentals of the measure (parse)
sls: [], // slurs - used in parsing and in generation
hy_st: 0
}
voice_tb.push(p_voice);
if (cfmt.transp) // %%transpose
p_voice.tr_p = 1
// par_sy.voices[v] = {
// range: -1
// }
return p_voice
}
|
|
|
<
|
|
|
>
|
>
|
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
|
// vol: 0
},
scale: 1,
// st: 0,
// cst: 0,
ulen: glovar.ulen,
dur_fact: 1,
// key: clone(parse.ckey), // key at start of tune (parse / gene)
// ckey: clone(parse.ckey), // current key (parse / gene)
meter: clone(glovar.meter),
wmeasure: glovar.meter.wmeasure,
staffnonote: 1,
clef: {
type: C.CLEF,
clef_auto: true,
clef_type: "a", // auto
time: 0
},
acc: [], // accidentals of the measure (parse)
sls: [], // slurs - used in parsing and in generation
hy_st: 0
}
voice_tb.push(p_voice);
if (parse.state == 3) {
p_voice.key = parse.ckey
p_voice.ckey = clone(parse.ckey)
}
// par_sy.voices[v] = {
// range: -1
// }
return p_voice
}
|
| ︙ | | | ︙ | |
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
|
eol--
// insert the music sequence in each voice
include++;
for (i = 0; i < vs.length; i++) {
parse = Object.create(parse_sav) // create a new parse context
parse.line = Object.create(parse_sav.line)
get_voice(vs[i], a)
tosvg(parse.fname, file, bol, eol)
}
include--
parse = parse_sav // restore the parse context
}
// treat a 'V:' info
|
|
|
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
|
eol--
// insert the music sequence in each voice
include++;
for (i = 0; i < vs.length; i++) {
parse = Object.create(parse_sav) // create a new parse context
parse.line = Object.create(parse_sav.line)
get_voice(vs[i] + ' ' + a.join(' '))
tosvg(parse.fname, file, bol, eol)
}
include--
parse = parse_sav // restore the parse context
}
// treat a 'V:' info
|
| ︙ | | | ︙ | |
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
|
a: a,
bol: parse.iend
}
if (parse.file[curvoice.clone.bol - 1] != ']')
curvoice.clone.bol++ // start of new line
}
set_kv_parm(a)
if (curvoice.tr_p) {
curvoice.tr_p = 0
set_transp()
}
v = curvoice.v
if (curvoice.new) { // if new voice
delete curvoice.new
if (staves_found < 0) { // if no %%score/%%staves
curvoice.st = curvoice.cst = ++nstaff;
par_sy.nstaff = nstaff;
|
>
>
>
>
>
>
>
>
>
>
>
|
|
<
>
>
|
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
|
a: a,
bol: parse.iend
}
if (parse.file[curvoice.clone.bol - 1] != ']')
curvoice.clone.bol++ // start of new line
}
if (!curvoice.key) // if new voice
curvoice.key = parse.ckey
set_kv_parm(a)
if (curvoice.clef.clef_type == 'p') { // if percussion clef
var s = curvoice.ckey
s.k_drum = 1 //true
s.k_sf = 0
s.k_b40 = 2
s.k_map = abc2svg.keys[7]
if (curvoice.key = parse.ckey)
curvoice.key = s
}
key_trans()
v = curvoice.v
if (curvoice.new) { // if new voice
delete curvoice.new
if (staves_found < 0) { // if no %%score/%%staves
curvoice.st = curvoice.cst = ++nstaff;
par_sy.nstaff = nstaff;
|
| ︙ | | | ︙ | |
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
|
if (glovar.new_nbar) {
gene.nbar = glovar.new_nbar // measure numbering
glovar.new_nbar = 0
} else {
gene.nbar = 1
}
// if no voice yet, create the default voice
if (!voice_tb.length) {
get_voice("1");
curvoice.clef.istart = curvoice.key.istart;
curvoice.clef.iend = curvoice.key.iend;
// nstaff = 0;
curvoice.default = true
} else {
curvoice = voice_tb[staves_found < 0 ? 0 : par_sy.top_voice]
}
parse.state = 3 // in tune body
// update some voice parameters
for (v = 0; v < voice_tb.length; v++) {
p_voice = voice_tb[v];
p_voice.ulen = glovar.ulen
if (p_voice.ckey.k_bagpipe
|
<
<
<
<
<
<
<
<
<
<
<
|
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
|
if (glovar.new_nbar) {
gene.nbar = glovar.new_nbar // measure numbering
glovar.new_nbar = 0
} else {
gene.nbar = 1
}
parse.state = 3 // in tune body
// update some voice parameters
for (v = 0; v < voice_tb.length; v++) {
p_voice = voice_tb[v];
p_voice.ulen = glovar.ulen
if (p_voice.ckey.k_bagpipe
|
| ︙ | | | ︙ | |