abcjs 6.0.4 → 6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,6 +48,8 @@ var tuneBook = __webpack_require__(/*! ./src/api/abc_tunebook */ "./src/api/abc_
48
48
 
49
49
  var sequence = __webpack_require__(/*! ./src/synth/abc_midi_sequencer */ "./src/synth/abc_midi_sequencer.js");
50
50
 
51
+ var strTranspose = __webpack_require__(/*! ./src/str/output */ "./src/str/output.js");
52
+
51
53
  var abcjs = {};
52
54
  abcjs.signature = "abcjs-basic v" + version;
53
55
  Object.keys(animation).forEach(function (key) {
@@ -62,6 +64,7 @@ abcjs.TimingCallbacks = __webpack_require__(/*! ./src/api/abc_timing_callbacks *
62
64
  var glyphs = __webpack_require__(/*! ./src/write/abc_glyphs */ "./src/write/abc_glyphs.js");
63
65
 
64
66
  abcjs.setGlyph = glyphs.setSymbol;
67
+ abcjs.strTranspose = strTranspose;
65
68
 
66
69
  var CreateSynth = __webpack_require__(/*! ./src/synth/create-synth */ "./src/synth/create-synth.js");
67
70
 
@@ -1098,101 +1101,6 @@ function renderOne(div, tune, params, tuneNumber, lineOffset) {
1098
1101
  var parent = div.parentNode;
1099
1102
  parent.style.width = div.style.width;
1100
1103
  }
1101
- }
1102
-
1103
- function renderEachLineSeparately(div, tune, params, tuneNumber) {
1104
- function initializeTuneLine(tune) {
1105
- var obj = new Tune();
1106
- obj.formatting = tune.formatting;
1107
- obj.media = tune.media;
1108
- obj.version = tune.version;
1109
- return obj;
1110
- } // Before rendering, chop up the returned tune into an array where each element is a line.
1111
- // The first element of the array gets the title and other items that go on top, the last element
1112
- // of the array gets the extra text that goes on bottom. Each element gets any non-music info that comes before it.
1113
-
1114
-
1115
- var tunes = [];
1116
- var tuneLine;
1117
-
1118
- for (var i = 0; i < tune.lines.length; i++) {
1119
- var line = tune.lines[i];
1120
- if (!tuneLine) tuneLine = initializeTuneLine(tune);
1121
-
1122
- if (i === 0) {
1123
- // These items go on top of the music
1124
- tuneLine.copyTopInfo(tune);
1125
- } // push the lines until we get to a music line
1126
-
1127
-
1128
- tuneLine.lines.push(line);
1129
-
1130
- if (line.staff) {
1131
- tunes.push(tuneLine);
1132
- tuneLine = undefined;
1133
- }
1134
- } // Add any extra stuff to the last line.
1135
-
1136
-
1137
- if (tuneLine) {
1138
- var lastLine = tunes[tunes.length - 1];
1139
-
1140
- for (var j = 0; j < tuneLine.lines.length; j++) {
1141
- lastLine.lines.push(tuneLine.lines[j]);
1142
- }
1143
- } // These items go below the music
1144
-
1145
-
1146
- tuneLine = tunes[tunes.length - 1];
1147
- tuneLine.copyBottomInfo(tune); // Now create sub-divs and render each line. Need to copy the params to change the padding for the interior slices.
1148
-
1149
- var ep = {};
1150
-
1151
- for (var key in params) {
1152
- if (params.hasOwnProperty(key)) {
1153
- ep[key] = params[key];
1154
- }
1155
- }
1156
-
1157
- var origPaddingTop = ep.paddingtop;
1158
- var origPaddingBottom = ep.paddingbottom;
1159
- var currentScrollY = div.parentNode.scrollTop; // If there is scrolling it will be lost during the redraw so remember it.
1160
-
1161
- var currentScrollX = div.parentNode.scrollLeft;
1162
- div.innerHTML = "";
1163
- var lineCount = 0;
1164
-
1165
- for (var k = 0; k < tunes.length; k++) {
1166
- var lineEl = document.createElement("div");
1167
- div.appendChild(lineEl);
1168
-
1169
- if (k === 0) {
1170
- ep.paddingtop = origPaddingTop;
1171
- ep.paddingbottom = 0;
1172
- } else if (k === tunes.length - 1) {
1173
- ep.paddingtop = 10;
1174
- ep.paddingbottom = origPaddingBottom;
1175
- } else {
1176
- ep.paddingtop = 10;
1177
- ep.paddingbottom = 0;
1178
- }
1179
-
1180
- if (k < tunes.length - 1) {
1181
- // If it is not the last line, force stretchlast. If it is, stretchlast might have been set by the input parameters.
1182
- tunes[k].formatting = parseCommon.clone(tunes[k].formatting);
1183
- tunes[k].formatting.stretchlast = true;
1184
- }
1185
-
1186
- renderOne(lineEl, tunes[k], ep, tuneNumber, lineCount);
1187
- lineCount += tunes[k].lines.length;
1188
- if (k === 0) tune.engraver = tunes[k].engraver;else {
1189
- if (!tune.engraver.staffgroups) tune.engraver.staffgroups = tunes[k].engraver.staffgroups;else if (tunes[k].engraver.staffgroups.length > 0) tune.engraver.staffgroups.push(tunes[k].engraver.staffgroups[0]);
1190
- }
1191
- }
1192
-
1193
- if (currentScrollX || currentScrollY) {
1194
- div.parentNode.scrollTo(currentScrollX, currentScrollY);
1195
- }
1196
1104
  } // A quick way to render a tune from javascript when interactivity is not required.
1197
1105
  // This is used when a javascript routine has some abc text that it wants to render
1198
1106
  // in a div or collection of divs. One tune or many can be rendered.
@@ -1263,8 +1171,9 @@ var renderAbc = function renderAbc(output, abc, parserParams, engraverParams, re
1263
1171
  if (!removeDiv && params.wrap && params.staffwidth) {
1264
1172
  tune = doLineWrapping(div, tune, tuneNumber, abcString, params);
1265
1173
  return tune;
1266
- } else if (removeDiv || !params.oneSvgPerLine || tune.lines.length < 2) renderOne(div, tune, params, tuneNumber, 0);else renderEachLineSeparately(div, tune, params, tuneNumber);
1174
+ }
1267
1175
 
1176
+ renderOne(div, tune, params, tuneNumber, 0);
1268
1177
  if (removeDiv) div.parentNode.removeChild(div);
1269
1178
  return null;
1270
1179
  }
@@ -1285,7 +1194,7 @@ function doLineWrapping(div, tune, tuneNumber, abcString, params) {
1285
1194
  if (warnings) tune.warnings = warnings;
1286
1195
  }
1287
1196
 
1288
- if (!params.oneSvgPerLine || tune.lines.length < 2) renderOne(div, tune, ret.revisedParams, tuneNumber, 0);else renderEachLineSeparately(div, tune, ret.revisedParams, tuneNumber);
1197
+ renderOne(div, tune, ret.revisedParams, tuneNumber, 0);
1289
1198
  tune.explanation = ret.explanation;
1290
1199
  return tune;
1291
1200
  }
@@ -1294,6 +1203,262 @@ module.exports = renderAbc;
1294
1203
 
1295
1204
  /***/ }),
1296
1205
 
1206
+ /***/ "./src/const/key-accidentals.js":
1207
+ /*!**************************************!*\
1208
+ !*** ./src/const/key-accidentals.js ***!
1209
+ \**************************************/
1210
+ /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
1211
+
1212
+ var _require = __webpack_require__(/*! ./relative-major */ "./src/const/relative-major.js"),
1213
+ relativeMajor = _require.relativeMajor;
1214
+
1215
+ var key1sharp = {
1216
+ acc: 'sharp',
1217
+ note: 'f'
1218
+ };
1219
+ var key2sharp = {
1220
+ acc: 'sharp',
1221
+ note: 'c'
1222
+ };
1223
+ var key3sharp = {
1224
+ acc: 'sharp',
1225
+ note: 'g'
1226
+ };
1227
+ var key4sharp = {
1228
+ acc: 'sharp',
1229
+ note: 'd'
1230
+ };
1231
+ var key5sharp = {
1232
+ acc: 'sharp',
1233
+ note: 'A'
1234
+ };
1235
+ var key6sharp = {
1236
+ acc: 'sharp',
1237
+ note: 'e'
1238
+ };
1239
+ var key7sharp = {
1240
+ acc: 'sharp',
1241
+ note: 'B'
1242
+ };
1243
+ var key1flat = {
1244
+ acc: 'flat',
1245
+ note: 'B'
1246
+ };
1247
+ var key2flat = {
1248
+ acc: 'flat',
1249
+ note: 'e'
1250
+ };
1251
+ var key3flat = {
1252
+ acc: 'flat',
1253
+ note: 'A'
1254
+ };
1255
+ var key4flat = {
1256
+ acc: 'flat',
1257
+ note: 'd'
1258
+ };
1259
+ var key5flat = {
1260
+ acc: 'flat',
1261
+ note: 'G'
1262
+ };
1263
+ var key6flat = {
1264
+ acc: 'flat',
1265
+ note: 'c'
1266
+ };
1267
+ var key7flat = {
1268
+ acc: 'flat',
1269
+ note: 'F'
1270
+ };
1271
+ var keys = {
1272
+ 'C#': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp, key7sharp],
1273
+ 'F#': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp],
1274
+ 'B': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp],
1275
+ 'E': [key1sharp, key2sharp, key3sharp, key4sharp],
1276
+ 'A': [key1sharp, key2sharp, key3sharp],
1277
+ 'D': [key1sharp, key2sharp],
1278
+ 'G': [key1sharp],
1279
+ 'C': [],
1280
+ 'F': [key1flat],
1281
+ 'Bb': [key1flat, key2flat],
1282
+ 'Eb': [key1flat, key2flat, key3flat],
1283
+ 'Cm': [key1flat, key2flat, key3flat],
1284
+ 'Ab': [key1flat, key2flat, key3flat, key4flat],
1285
+ 'Db': [key1flat, key2flat, key3flat, key4flat, key5flat],
1286
+ 'Gb': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat],
1287
+ 'Cb': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat, key7flat],
1288
+ // The following are not in the 2.0 spec, but seem normal enough.
1289
+ // TODO-PER: These SOUND the same as what's written, but they aren't right
1290
+ 'A#': [key1flat, key2flat],
1291
+ 'B#': [],
1292
+ 'D#': [key1flat, key2flat, key3flat],
1293
+ 'E#': [key1flat],
1294
+ 'G#': [key1flat, key2flat, key3flat, key4flat],
1295
+ 'none': []
1296
+ };
1297
+
1298
+ function keyAccidentals(key) {
1299
+ var newKey = keys[relativeMajor(key)];
1300
+ if (!newKey) // If we don't recognize the key then there is no change
1301
+ return null;
1302
+ return JSON.parse(JSON.stringify(newKey));
1303
+ }
1304
+
1305
+ ;
1306
+ module.exports = keyAccidentals;
1307
+
1308
+ /***/ }),
1309
+
1310
+ /***/ "./src/const/relative-major.js":
1311
+ /*!*************************************!*\
1312
+ !*** ./src/const/relative-major.js ***!
1313
+ \*************************************/
1314
+ /***/ (function(module) {
1315
+
1316
+ // All these keys have the same number of accidentals
1317
+ var keys = {
1318
+ 'C': {
1319
+ modes: ['CMaj', 'Amin', 'Am', 'GMix', 'DDor', 'EPhr', 'FLyd', 'BLoc'],
1320
+ stepsFromC: 0
1321
+ },
1322
+ 'Db': {
1323
+ modes: ['DbMaj', 'Bbmin', 'Bbm', 'AbMix', 'EbDor', 'FPhr', 'GbLyd', 'CLoc'],
1324
+ stepsFromC: 1
1325
+ },
1326
+ 'D': {
1327
+ modes: ['DMaj', 'Bmin', 'Bm', 'AMix', 'EDor', 'F#Phr', 'GLyd', 'C#Loc'],
1328
+ stepsFromC: 2
1329
+ },
1330
+ 'Eb': {
1331
+ modes: ['EbMaj', 'Cmin', 'Cm', 'BbMix', 'FDor', 'GPhr', 'AbLyd', 'DLoc'],
1332
+ stepsFromC: 3
1333
+ },
1334
+ 'E': {
1335
+ modes: ['EMaj', 'C#min', 'C#m', 'BMix', 'F#Dor', 'G#Phr', 'ALyd', 'D#Loc'],
1336
+ stepsFromC: 4
1337
+ },
1338
+ 'F': {
1339
+ modes: ['FMaj', 'Dmin', 'Dm', 'CMix', 'GDor', 'APhr', 'BbLyd', 'ELoc'],
1340
+ stepsFromC: 5
1341
+ },
1342
+ 'Gb': {
1343
+ modes: ['GbMaj', 'Ebmin', 'Ebm', 'DbMix', 'AbDor', 'BbPhr', 'CbLyd', 'FLoc'],
1344
+ stepsFromC: 6
1345
+ },
1346
+ 'G': {
1347
+ modes: ['GMaj', 'Emin', 'Em', 'DMix', 'ADor', 'BPhr', 'CLyd', 'F#Loc'],
1348
+ stepsFromC: 7
1349
+ },
1350
+ 'Ab': {
1351
+ modes: ['AbMaj', 'Fmin', 'Fm', 'EbMix', 'BbDor', 'CPhr', 'DbLyd', 'GLoc'],
1352
+ stepsFromC: 8
1353
+ },
1354
+ 'A': {
1355
+ modes: ['AMaj', 'F#min', 'F#m', 'EMix', 'BDor', 'C#Phr', 'DLyd', 'G#Loc'],
1356
+ stepsFromC: 9
1357
+ },
1358
+ 'Bb': {
1359
+ modes: ['BbMaj', 'Gmin', 'Gm', 'FMix', 'CDor', 'DPhr', 'EbLyd', 'ALoc'],
1360
+ stepsFromC: 10
1361
+ },
1362
+ 'B': {
1363
+ modes: ['BMaj', 'G#min', 'G#m', 'F#Mix', 'C#Dor', 'D#Phr', 'ELyd', 'A#Loc'],
1364
+ stepsFromC: 11
1365
+ },
1366
+ // Enharmonic keys
1367
+ 'C#': {
1368
+ modes: ['C#Maj', 'A#min', 'A#m', 'G#Mix', 'D#Dor', 'E#Phr', 'F#Lyd', 'B#Loc'],
1369
+ stepsFromC: 1
1370
+ },
1371
+ 'F#': {
1372
+ modes: ['F#Maj', 'D#min', 'D#m', 'C#Mix', 'G#Dor', 'A#Phr', 'BLyd', 'E#Loc'],
1373
+ stepsFromC: 6
1374
+ },
1375
+ 'Cb': {
1376
+ modes: ['CbMaj', 'Abmin', 'Abm', 'GbMix', 'DbDor', 'EbPhr', 'FbLyd', 'BbLoc'],
1377
+ stepsFromC: 11
1378
+ }
1379
+ };
1380
+ var keyReverse = null;
1381
+
1382
+ function createKeyReverse() {
1383
+ keyReverse = {};
1384
+ var allKeys = Object.keys(keys);
1385
+
1386
+ for (var i = 0; i < allKeys.length; i++) {
1387
+ var keyObj = keys[allKeys[i]];
1388
+ keyReverse[allKeys[i].toLowerCase()] = allKeys[i];
1389
+
1390
+ for (var j = 0; j < keyObj.modes.length; j++) {
1391
+ var mode = keyObj.modes[j].toLowerCase();
1392
+ keyReverse[mode] = allKeys[i];
1393
+ }
1394
+ }
1395
+ }
1396
+
1397
+ function relativeMajor(key) {
1398
+ // Translate a key to its relative major. If it doesn't exist, do the best we can
1399
+ // by just returning the original key.
1400
+ // There are alternate spellings of these - so the search needs to be case insensitive.
1401
+ // To make this efficient, the first time this is called the "keys" object is reversed so this search is fast in the future
1402
+ if (!keyReverse) {
1403
+ createKeyReverse();
1404
+ } // get the key portion itself - there might be other stuff, like extra sharps and flats, or the mode written out.
1405
+
1406
+
1407
+ var mode = key.toLowerCase().match(/([a-g][b#]?)(maj|min|mix|dor|phr|lyd|loc|m)?/);
1408
+ if (!mode || !mode[2]) return key;
1409
+ mode = mode[1] + mode[2];
1410
+ var maj = keyReverse[mode];
1411
+ if (maj) return maj;
1412
+ return key;
1413
+ }
1414
+
1415
+ function relativeMode(majorKey, mode) {
1416
+ // The reverse of the relativeMajor. Translate it back to the original mode.
1417
+ // If it isn't a recognized mode or it is already major, then just return the major key.
1418
+ var group = keys[majorKey];
1419
+ if (!group) return majorKey;
1420
+ if (mode === '') return majorKey;
1421
+ var match = mode.toLowerCase().match(/^(maj|min|mix|dor|phr|lyd|loc|m)/);
1422
+ if (!match) return majorKey;
1423
+ var regMode = match[1];
1424
+
1425
+ for (var i = 0; i < group.modes.length; i++) {
1426
+ var thisMode = group.modes[i];
1427
+ var ind = thisMode.toLowerCase().indexOf(regMode);
1428
+ if (ind !== -1 && ind === thisMode.length - regMode.length) return thisMode.substring(0, thisMode.length - regMode.length);
1429
+ }
1430
+
1431
+ return majorKey;
1432
+ }
1433
+
1434
+ function transposeKey(key, steps) {
1435
+ // This takes a major key and adds the desired steps.
1436
+ // It assigns each key a number that is the number of steps from C so that there can just be arithmetic.
1437
+ var match = keys[key];
1438
+ if (!match) return key;
1439
+
1440
+ while (steps < 0) {
1441
+ steps += 12;
1442
+ }
1443
+
1444
+ var fromC = (match.stepsFromC + steps) % 12;
1445
+
1446
+ for (var i = 0; i < Object.keys(keys).length; i++) {
1447
+ var k = Object.keys(keys)[i];
1448
+ if (keys[k].stepsFromC === fromC) return k;
1449
+ }
1450
+
1451
+ return key;
1452
+ }
1453
+
1454
+ module.exports = {
1455
+ relativeMajor: relativeMajor,
1456
+ relativeMode: relativeMode,
1457
+ transposeKey: transposeKey
1458
+ };
1459
+
1460
+ /***/ }),
1461
+
1297
1462
  /***/ "./src/data/abc_tune.js":
1298
1463
  /*!******************************!*\
1299
1464
  !*** ./src/data/abc_tune.js ***!
@@ -3695,15 +3860,16 @@ var bookParser = function bookParser(book) {
3695
3860
  "use strict";
3696
3861
 
3697
3862
  var directives = "";
3863
+ var initialWhiteSpace = book.match(/(\s*)/);
3698
3864
  book = parseCommon.strip(book);
3699
3865
  var tuneStrings = book.split("\nX:"); // Put back the X: that we lost when splitting the tunes.
3700
3866
 
3701
3867
  for (var i = 1; i < tuneStrings.length; i++) {
3702
3868
  tuneStrings[i] = "X:" + tuneStrings[i];
3703
- } // Keep track of the character position each tune starts with.
3869
+ } // Keep track of the character position each tune starts with. If the string starts with white space, count that, too.
3704
3870
 
3705
3871
 
3706
- var pos = 0;
3872
+ var pos = initialWhiteSpace ? initialWhiteSpace[0].length : 0;
3707
3873
  var tunes = [];
3708
3874
  parseCommon.each(tuneStrings, function (tune) {
3709
3875
  tunes.push({
@@ -5996,179 +6162,7 @@ var parseKeyVoice = {};
5996
6162
  };
5997
6163
 
5998
6164
  parseKeyVoice.standardKey = function (keyName, root, acc, localTranspose) {
5999
- var key1sharp = {
6000
- acc: 'sharp',
6001
- note: 'f'
6002
- };
6003
- var key2sharp = {
6004
- acc: 'sharp',
6005
- note: 'c'
6006
- };
6007
- var key3sharp = {
6008
- acc: 'sharp',
6009
- note: 'g'
6010
- };
6011
- var key4sharp = {
6012
- acc: 'sharp',
6013
- note: 'd'
6014
- };
6015
- var key5sharp = {
6016
- acc: 'sharp',
6017
- note: 'A'
6018
- };
6019
- var key6sharp = {
6020
- acc: 'sharp',
6021
- note: 'e'
6022
- };
6023
- var key7sharp = {
6024
- acc: 'sharp',
6025
- note: 'B'
6026
- };
6027
- var key1flat = {
6028
- acc: 'flat',
6029
- note: 'B'
6030
- };
6031
- var key2flat = {
6032
- acc: 'flat',
6033
- note: 'e'
6034
- };
6035
- var key3flat = {
6036
- acc: 'flat',
6037
- note: 'A'
6038
- };
6039
- var key4flat = {
6040
- acc: 'flat',
6041
- note: 'd'
6042
- };
6043
- var key5flat = {
6044
- acc: 'flat',
6045
- note: 'G'
6046
- };
6047
- var key6flat = {
6048
- acc: 'flat',
6049
- note: 'c'
6050
- };
6051
- var key7flat = {
6052
- acc: 'flat',
6053
- note: 'F'
6054
- };
6055
- var keys = {
6056
- 'C#': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp, key7sharp],
6057
- 'A#m': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp, key7sharp],
6058
- 'G#Mix': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp, key7sharp],
6059
- 'D#Dor': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp, key7sharp],
6060
- 'E#Phr': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp, key7sharp],
6061
- 'F#Lyd': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp, key7sharp],
6062
- 'B#Loc': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp, key7sharp],
6063
- 'F#': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp],
6064
- 'D#m': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp],
6065
- 'C#Mix': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp],
6066
- 'G#Dor': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp],
6067
- 'A#Phr': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp],
6068
- 'BLyd': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp],
6069
- 'E#Loc': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp],
6070
- 'B': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp],
6071
- 'G#m': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp],
6072
- 'F#Mix': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp],
6073
- 'C#Dor': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp],
6074
- 'D#Phr': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp],
6075
- 'ELyd': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp],
6076
- 'A#Loc': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp],
6077
- 'E': [key1sharp, key2sharp, key3sharp, key4sharp],
6078
- 'C#m': [key1sharp, key2sharp, key3sharp, key4sharp],
6079
- 'BMix': [key1sharp, key2sharp, key3sharp, key4sharp],
6080
- 'F#Dor': [key1sharp, key2sharp, key3sharp, key4sharp],
6081
- 'G#Phr': [key1sharp, key2sharp, key3sharp, key4sharp],
6082
- 'ALyd': [key1sharp, key2sharp, key3sharp, key4sharp],
6083
- 'D#Loc': [key1sharp, key2sharp, key3sharp, key4sharp],
6084
- 'A': [key1sharp, key2sharp, key3sharp],
6085
- 'F#m': [key1sharp, key2sharp, key3sharp],
6086
- 'EMix': [key1sharp, key2sharp, key3sharp],
6087
- 'BDor': [key1sharp, key2sharp, key3sharp],
6088
- 'C#Phr': [key1sharp, key2sharp, key3sharp],
6089
- 'DLyd': [key1sharp, key2sharp, key3sharp],
6090
- 'G#Loc': [key1sharp, key2sharp, key3sharp],
6091
- 'D': [key1sharp, key2sharp],
6092
- 'Bm': [key1sharp, key2sharp],
6093
- 'AMix': [key1sharp, key2sharp],
6094
- 'EDor': [key1sharp, key2sharp],
6095
- 'F#Phr': [key1sharp, key2sharp],
6096
- 'GLyd': [key1sharp, key2sharp],
6097
- 'C#Loc': [key1sharp, key2sharp],
6098
- 'G': [key1sharp],
6099
- 'Em': [key1sharp],
6100
- 'DMix': [key1sharp],
6101
- 'ADor': [key1sharp],
6102
- 'BPhr': [key1sharp],
6103
- 'CLyd': [key1sharp],
6104
- 'F#Loc': [key1sharp],
6105
- 'C': [],
6106
- 'Am': [],
6107
- 'GMix': [],
6108
- 'DDor': [],
6109
- 'EPhr': [],
6110
- 'FLyd': [],
6111
- 'BLoc': [],
6112
- 'F': [key1flat],
6113
- 'Dm': [key1flat],
6114
- 'CMix': [key1flat],
6115
- 'GDor': [key1flat],
6116
- 'APhr': [key1flat],
6117
- 'BbLyd': [key1flat],
6118
- 'ELoc': [key1flat],
6119
- 'Bb': [key1flat, key2flat],
6120
- 'Gm': [key1flat, key2flat],
6121
- 'FMix': [key1flat, key2flat],
6122
- 'CDor': [key1flat, key2flat],
6123
- 'DPhr': [key1flat, key2flat],
6124
- 'EbLyd': [key1flat, key2flat],
6125
- 'ALoc': [key1flat, key2flat],
6126
- 'Eb': [key1flat, key2flat, key3flat],
6127
- 'Cm': [key1flat, key2flat, key3flat],
6128
- 'BbMix': [key1flat, key2flat, key3flat],
6129
- 'FDor': [key1flat, key2flat, key3flat],
6130
- 'GPhr': [key1flat, key2flat, key3flat],
6131
- 'AbLyd': [key1flat, key2flat, key3flat],
6132
- 'DLoc': [key1flat, key2flat, key3flat],
6133
- 'Ab': [key1flat, key2flat, key3flat, key4flat],
6134
- 'Fm': [key1flat, key2flat, key3flat, key4flat],
6135
- 'EbMix': [key1flat, key2flat, key3flat, key4flat],
6136
- 'BbDor': [key1flat, key2flat, key3flat, key4flat],
6137
- 'CPhr': [key1flat, key2flat, key3flat, key4flat],
6138
- 'DbLyd': [key1flat, key2flat, key3flat, key4flat],
6139
- 'GLoc': [key1flat, key2flat, key3flat, key4flat],
6140
- 'Db': [key1flat, key2flat, key3flat, key4flat, key5flat],
6141
- 'Bbm': [key1flat, key2flat, key3flat, key4flat, key5flat],
6142
- 'AbMix': [key1flat, key2flat, key3flat, key4flat, key5flat],
6143
- 'EbDor': [key1flat, key2flat, key3flat, key4flat, key5flat],
6144
- 'FPhr': [key1flat, key2flat, key3flat, key4flat, key5flat],
6145
- 'GbLyd': [key1flat, key2flat, key3flat, key4flat, key5flat],
6146
- 'CLoc': [key1flat, key2flat, key3flat, key4flat, key5flat],
6147
- 'Gb': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat],
6148
- 'Ebm': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat],
6149
- 'DbMix': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat],
6150
- 'AbDor': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat],
6151
- 'BbPhr': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat],
6152
- 'CbLyd': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat],
6153
- 'FLoc': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat],
6154
- 'Cb': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat, key7flat],
6155
- 'Abm': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat, key7flat],
6156
- 'GbMix': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat, key7flat],
6157
- 'DbDor': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat, key7flat],
6158
- 'EbPhr': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat, key7flat],
6159
- 'FbLyd': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat, key7flat],
6160
- 'BbLoc': [key1flat, key2flat, key3flat, key4flat, key5flat, key6flat, key7flat],
6161
- // The following are not in the 2.0 spec, but seem normal enough.
6162
- // TODO-PER: These SOUND the same as what's written, but they aren't right
6163
- 'A#': [key1flat, key2flat],
6164
- 'B#': [],
6165
- 'D#': [key1flat, key2flat, key3flat],
6166
- 'E#': [key1flat],
6167
- 'G#': [key1flat, key2flat, key3flat, key4flat],
6168
- 'Gbm': [key1sharp, key2sharp, key3sharp, key4sharp, key5sharp, key6sharp, key7sharp],
6169
- 'none': []
6170
- };
6171
- return transpose.keySignature(multilineVars, keys, keyName, root, acc, localTranspose);
6165
+ return transpose.keySignature(multilineVars, keyName, root, acc, localTranspose);
6172
6166
  };
6173
6167
 
6174
6168
  var clefLines = {
@@ -7563,7 +7557,7 @@ MusicParser.prototype.parseMusic = function (line) {
7563
7557
  }
7564
7558
 
7565
7559
  multilineVars.addFormattingOptions(el, tune.formatting, 'bar');
7566
- tuneBuilder.appendElement('bar', startOfLine + i, startOfLine + i + ret[0], bar);
7560
+ tuneBuilder.appendElement('bar', startOfLine + startI, startOfLine + i + ret[0], bar);
7567
7561
  multilineVars.measureNotEmpty = false;
7568
7562
  el = {};
7569
7563
  }
@@ -10152,6 +10146,10 @@ module.exports = Tokenizer;
10152
10146
  // abc_transpose.js: Handles the automatic transposition of key signatures, chord symbols, and notes.
10153
10147
  var allNotes = __webpack_require__(/*! ./all-notes */ "./src/parse/all-notes.js");
10154
10148
 
10149
+ var transposeChordName = __webpack_require__(/*! ../parse/transpose-chord */ "./src/parse/transpose-chord.js");
10150
+
10151
+ var keyAccidentals = __webpack_require__(/*! ../const/key-accidentals */ "./src/const/key-accidentals.js");
10152
+
10155
10153
  var transpose = {};
10156
10154
  var keyIndex = {
10157
10155
  'C': 0,
@@ -10175,16 +10173,16 @@ var keyIndex = {
10175
10173
  var newKey = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'Ab', 'A', 'Bb', 'B'];
10176
10174
  var newKeyMinor = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'Bb', 'B'];
10177
10175
 
10178
- transpose.keySignature = function (multilineVars, keys, keyName, root, acc, localTranspose) {
10179
- if (multilineVars.clef.type === "perc") return {
10180
- accidentals: keys[keyName],
10176
+ transpose.keySignature = function (multilineVars, keyName, root, acc, localTranspose) {
10177
+ if (multilineVars.clef.type === "perc" || multilineVars.clef.type === "none") return {
10178
+ accidentals: keyAccidentals(keyName),
10181
10179
  root: root,
10182
10180
  acc: acc
10183
10181
  };
10184
10182
  if (!localTranspose) localTranspose = 0;
10185
10183
  multilineVars.localTransposeVerticalMovement = 0;
10186
10184
  multilineVars.localTransposePreferFlats = false;
10187
- var k = keys[keyName];
10185
+ var k = keyAccidentals(keyName);
10188
10186
  if (!k) return multilineVars.key; // If the key isn't in the list, it is non-standard. We won't attempt to transpose it.
10189
10187
 
10190
10188
  multilineVars.localTranspose = (multilineVars.globalTranspose ? multilineVars.globalTranspose : 0) + localTranspose;
@@ -10220,7 +10218,7 @@ transpose.keySignature = function (multilineVars, keys, keyName, root, acc, loca
10220
10218
  if (index > 11) index = index % 12;
10221
10219
  var newKeyName = keyName[0] === 'm' ? newKeyMinor[index] : newKey[index];
10222
10220
  var transposedKey = newKeyName + keyName;
10223
- var newKeySig = keys[transposedKey];
10221
+ var newKeySig = keyAccidentals(transposedKey);
10224
10222
  if (newKeySig.length > 0 && newKeySig[0].acc === 'flat') multilineVars.localTransposePreferFlats = true;
10225
10223
  var distance = transposedKey.charCodeAt(0) - baseKey.charCodeAt(0);
10226
10224
 
@@ -10249,76 +10247,8 @@ transpose.keySignature = function (multilineVars, keys, keyName, root, acc, loca
10249
10247
  };
10250
10248
  };
10251
10249
 
10252
- var sharpChords = ['C', 'C♯', 'D', "D♯", 'E', 'F', "F♯", 'G', 'G♯', 'A', 'A♯', 'B'];
10253
- var flatChords = ['C', 'D♭', 'D', 'E♭', 'E', 'F', 'G♭', 'G', 'A♭', 'A', 'B♭', 'B'];
10254
- var sharpChordsFree = ['C', 'C#', 'D', "D#", 'E', 'F', "F#", 'G', 'G#', 'A', 'A#', 'B'];
10255
- var flatChordsFree = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'];
10256
-
10257
10250
  transpose.chordName = function (multilineVars, chord) {
10258
- if (multilineVars.localTranspose && multilineVars.localTranspose % 12 !== 0) {
10259
- // The chords are the same if it is an exact octave change.
10260
- var transposeFactor = multilineVars.localTranspose;
10261
-
10262
- while (transposeFactor < 0) {
10263
- transposeFactor += 12;
10264
- }
10265
-
10266
- if (transposeFactor > 11) transposeFactor = transposeFactor % 12;
10267
-
10268
- if (multilineVars.freegchord) {
10269
- chord = chord.replace(/Cb/g, "`~11`");
10270
- chord = chord.replace(/Db/g, "`~1`");
10271
- chord = chord.replace(/Eb/g, "`~3`");
10272
- chord = chord.replace(/Fb/g, "`~4`");
10273
- chord = chord.replace(/Gb/g, "`~6`");
10274
- chord = chord.replace(/Ab/g, "`~8`");
10275
- chord = chord.replace(/Bb/g, "`~10`");
10276
- chord = chord.replace(/C#/g, "`~1`");
10277
- chord = chord.replace(/D#/g, "`~3`");
10278
- chord = chord.replace(/E#/g, "`~5`");
10279
- chord = chord.replace(/F#/g, "`~6`");
10280
- chord = chord.replace(/G#/g, "`~8`");
10281
- chord = chord.replace(/A#/g, "`~10`");
10282
- chord = chord.replace(/B#/g, "`~0`");
10283
- } else {
10284
- chord = chord.replace(/C♭/g, "`~11`");
10285
- chord = chord.replace(/D♭/g, "`~1`");
10286
- chord = chord.replace(/E♭/g, "`~3`");
10287
- chord = chord.replace(/F♭/g, "`~4`");
10288
- chord = chord.replace(/G♭/g, "`~6`");
10289
- chord = chord.replace(/A♭/g, "`~8`");
10290
- chord = chord.replace(/B♭/g, "`~10`");
10291
- chord = chord.replace(/C♯/g, "`~1`");
10292
- chord = chord.replace(/D♯/g, "`~3`");
10293
- chord = chord.replace(/E♯/g, "`~5`");
10294
- chord = chord.replace(/F♯/g, "`~6`");
10295
- chord = chord.replace(/G♯/g, "`~8`");
10296
- chord = chord.replace(/A♯/g, "`~10`");
10297
- chord = chord.replace(/B♯/g, "`~0`");
10298
- }
10299
-
10300
- chord = chord.replace(/C/g, "`~0`");
10301
- chord = chord.replace(/D/g, "`~2`");
10302
- chord = chord.replace(/E/g, "`~4`");
10303
- chord = chord.replace(/F/g, "`~5`");
10304
- chord = chord.replace(/G/g, "`~7`");
10305
- chord = chord.replace(/A/g, "`~9`");
10306
- chord = chord.replace(/B/g, "`~11`");
10307
- var arr = chord.split("`");
10308
-
10309
- for (var i = 0; i < arr.length; i++) {
10310
- if (arr[i][0] === '~') {
10311
- var chordNum = parseInt(arr[i].substr(1), 10);
10312
- chordNum += transposeFactor;
10313
- if (chordNum > 11) chordNum -= 12;
10314
- if (multilineVars.freegchord) arr[i] = multilineVars.localTransposePreferFlats ? flatChordsFree[chordNum] : sharpChordsFree[chordNum];else arr[i] = multilineVars.localTransposePreferFlats ? flatChords[chordNum] : sharpChords[chordNum];
10315
- }
10316
- }
10317
-
10318
- chord = arr.join("");
10319
- }
10320
-
10321
- return chord;
10251
+ return transposeChordName(chord, multilineVars.localTranspose, multilineVars.localTransposePreferFlats, multilineVars.freegchord);
10322
10252
  };
10323
10253
 
10324
10254
  var pitchToLetter = ['c', 'd', 'e', 'f', 'g', 'a', 'b'];
@@ -10435,6 +10365,83 @@ module.exports = allNotes;
10435
10365
 
10436
10366
  /***/ }),
10437
10367
 
10368
+ /***/ "./src/parse/transpose-chord.js":
10369
+ /*!**************************************!*\
10370
+ !*** ./src/parse/transpose-chord.js ***!
10371
+ \**************************************/
10372
+ /***/ (function(module) {
10373
+
10374
+ var sharpChords = ['C', 'C♯', 'D', "D♯", 'E', 'F', "F♯", 'G', 'G♯', 'A', 'A♯', 'B'];
10375
+ var flatChords = ['C', 'D♭', 'D', 'E♭', 'E', 'F', 'G♭', 'G', 'A♭', 'A', 'B♭', 'B'];
10376
+ var sharpChordsFree = ['C', 'C#', 'D', "D#", 'E', 'F', "F#", 'G', 'G#', 'A', 'A#', 'B'];
10377
+ var flatChordsFree = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'];
10378
+
10379
+ function transposeChordName(chord, steps, preferFlats, freeGCchord) {
10380
+ if (!steps || steps % 12 === 0) // The chords are the same if it is an exact octave change.
10381
+ return chord; // There are two things in the chord that might need to be transposed:
10382
+ // The chord will start with a letter from A-G, and might have one accidental after it.
10383
+ // That accidental might be an actual sharp or flat char, or it might be a pound sign or lower case "b".
10384
+ // Then there is a bunch of stuff that isn't transposed and should just be copied. That is stuff like "7" and more complicated chords.
10385
+ // But there is one other exception: right after a slash there will be a bass note and possibly an accidental. That should also be transposed.
10386
+
10387
+ while (steps < 0) {
10388
+ steps += 12;
10389
+ }
10390
+
10391
+ if (steps > 11) steps = steps % 12; // (chord name w/accidental) (a bunch of stuff) (/) (bass note) (anything else)
10392
+
10393
+ var match = chord.match(/^([A-G][b#♭♯]?)([^\/]+)?\/?([A-G][b#♭♯]?)?(.+)?/);
10394
+ if (!match) return chord; // We don't recognize the format of the chord, so skip it.
10395
+
10396
+ var name = match[1];
10397
+ var extra1 = match[2];
10398
+ var bass = match[3];
10399
+ var extra2 = match[4];
10400
+ var index = sharpChords.indexOf(name);
10401
+ if (index < 0) index = flatChords.indexOf(name);
10402
+ if (index < 0) index = sharpChordsFree.indexOf(name);
10403
+ if (index < 0) index = flatChordsFree.indexOf(name);
10404
+ if (index < 0) return chord; // This should never happen, but if we can't find the chord just bail.
10405
+
10406
+ index += steps;
10407
+ index = index % 12;
10408
+
10409
+ if (preferFlats) {
10410
+ if (freeGCchord) chord = flatChordsFree[index];else chord = flatChords[index];
10411
+ } else {
10412
+ if (freeGCchord) chord = sharpChordsFree[index];else chord = sharpChords[index];
10413
+ }
10414
+
10415
+ if (extra1) chord += extra1;
10416
+
10417
+ if (bass) {
10418
+ var index = sharpChords.indexOf(bass);
10419
+ if (index < 0) index = flatChords.indexOf(bass);
10420
+ if (index < 0) index = sharpChordsFree.indexOf(bass);
10421
+ if (index < 0) index = flatChordsFree.indexOf(bass);
10422
+ chord += '/';
10423
+
10424
+ if (index >= 0) {
10425
+ index += steps;
10426
+ index = index % 12;
10427
+
10428
+ if (preferFlats) {
10429
+ if (freeGCchord) chord += flatChordsFree[index];else chord += flatChords[index];
10430
+ } else {
10431
+ if (freeGCchord) chord += sharpChordsFree[index];else chord += sharpChords[index];
10432
+ }
10433
+ } else chord += bass; // Don't know what to do so do nothing
10434
+
10435
+ }
10436
+
10437
+ if (extra2) chord += extra2;
10438
+ return chord;
10439
+ }
10440
+
10441
+ module.exports = transposeChordName;
10442
+
10443
+ /***/ }),
10444
+
10438
10445
  /***/ "./src/parse/tune-builder.js":
10439
10446
  /*!***********************************!*\
10440
10447
  !*** ./src/parse/tune-builder.js ***!
@@ -12011,6 +12018,575 @@ module.exports = {
12011
12018
 
12012
12019
  /***/ }),
12013
12020
 
12021
+ /***/ "./src/str/output.js":
12022
+ /*!***************************!*\
12023
+ !*** ./src/str/output.js ***!
12024
+ \***************************/
12025
+ /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
12026
+
12027
+ var keyAccidentals = __webpack_require__(/*! ../const/key-accidentals */ "./src/const/key-accidentals.js");
12028
+
12029
+ var _require = __webpack_require__(/*! ../const/relative-major */ "./src/const/relative-major.js"),
12030
+ relativeMajor = _require.relativeMajor,
12031
+ transposeKey = _require.transposeKey,
12032
+ relativeMode = _require.relativeMode;
12033
+
12034
+ var transposeChordName = __webpack_require__(/*! ../parse/transpose-chord */ "./src/parse/transpose-chord.js");
12035
+
12036
+ var strTranspose;
12037
+
12038
+ (function () {
12039
+ "use strict";
12040
+
12041
+ strTranspose = function strTranspose(abc, abcTune, steps) {
12042
+ if (abcTune === "TEST") // Backdoor way to get entry points for unit tests
12043
+ return {
12044
+ keyAccidentals: keyAccidentals,
12045
+ relativeMajor: relativeMajor,
12046
+ transposeKey: transposeKey,
12047
+ relativeMode: relativeMode,
12048
+ transposeChordName: transposeChordName
12049
+ };
12050
+ steps = parseInt(steps, 10);
12051
+ var changes = [];
12052
+ var i;
12053
+
12054
+ for (i = 0; i < abcTune.length; i++) {
12055
+ changes = changes.concat(transposeOneTune(abc, abcTune[i], steps));
12056
+ } // Reverse sort so that we are replacing strings from the end to the beginning so that the indexes aren't invalidated as we go.
12057
+ // (Because voices can be written in different ways we can't count on the notes being encountered in the order they appear in the string.)
12058
+
12059
+
12060
+ changes = changes.sort(function (a, b) {
12061
+ return b.start - a.start;
12062
+ });
12063
+ var output = abc.split('');
12064
+
12065
+ for (i = 0; i < changes.length; i++) {
12066
+ var ch = changes[i];
12067
+ output.splice(ch.start, ch.end - ch.start, ch.note);
12068
+ }
12069
+
12070
+ return output.join('');
12071
+ };
12072
+
12073
+ function transposeOneTune(abc, abcTune, steps) {
12074
+ var changes = []; // Don't transpose bagpipe music - that is a special case and is always a particular key
12075
+
12076
+ var key = abcTune.getKeySignature();
12077
+ if (key.root === 'Hp' || key.root === "HP") return changes;
12078
+ changes = changes.concat(changeAllKeySigs(abc, steps));
12079
+
12080
+ for (var i = 0; i < abcTune.lines.length; i++) {
12081
+ var staves = abcTune.lines[i].staff;
12082
+
12083
+ if (staves) {
12084
+ for (var j = 0; j < staves.length; j++) {
12085
+ var staff = staves[j];
12086
+ if (staff.clef.type !== "perc") changes = changes.concat(transposeVoices(abc, staff.voices, staff.key, steps));
12087
+ }
12088
+ }
12089
+ }
12090
+
12091
+ return changes;
12092
+ }
12093
+
12094
+ function changeAllKeySigs(abc, steps) {
12095
+ var changes = [];
12096
+ var arr = abc.split("K:"); // now each line except the first one will start with whatever is right after "K:"
12097
+
12098
+ var count = arr[0].length;
12099
+
12100
+ for (var i = 1; i < arr.length; i++) {
12101
+ var segment = arr[i];
12102
+ var match = segment.match(/^( *)([A-G])([#b]?)(\w*)/);
12103
+
12104
+ if (match) {
12105
+ var start = count + 2 + match[1].length; // move past the 'K:' and optional white space
12106
+
12107
+ var key = match[2] + match[3] + match[4]; // key name, accidental, and mode
12108
+
12109
+ var destinationKey = newKey({
12110
+ root: match[2],
12111
+ acc: match[3],
12112
+ mode: match[4]
12113
+ }, steps);
12114
+ var dest = destinationKey.root + destinationKey.acc + destinationKey.mode;
12115
+ changes.push({
12116
+ start: start,
12117
+ end: start + key.length,
12118
+ note: dest
12119
+ });
12120
+ }
12121
+
12122
+ count += segment.length + 2;
12123
+ }
12124
+
12125
+ return changes;
12126
+ }
12127
+
12128
+ function transposeVoices(abc, voices, key, steps) {
12129
+ var changes = [];
12130
+ var destinationKey = newKey(key, steps);
12131
+
12132
+ for (var i = 0; i < voices.length; i++) {
12133
+ changes = changes.concat(transposeVoice(abc, voices[i], key.root, createKeyAccidentals(key), destinationKey, steps));
12134
+ }
12135
+
12136
+ return changes;
12137
+ }
12138
+
12139
+ function createKeyAccidentals(key) {
12140
+ var ret = {};
12141
+
12142
+ for (var i = 0; i < key.accidentals.length; i++) {
12143
+ var acc = key.accidentals[i];
12144
+ if (acc.acc === 'flat') ret[acc.note.toUpperCase()] = '_';else if (acc.acc === 'sharp') ret[acc.note.toUpperCase()] = '^';
12145
+ }
12146
+
12147
+ return ret;
12148
+ }
12149
+
12150
+ function setLetterDistance(destinationKey, keyRoot, steps) {
12151
+ var letterDistance = letters.indexOf(destinationKey.root) - letters.indexOf(keyRoot);
12152
+ if (keyRoot === "none") letterDistance = letters.indexOf(destinationKey.root);
12153
+
12154
+ if (letterDistance === 0) {
12155
+ // This could either be a half step (like Eb => E) or almost an octave (like E => Eb)
12156
+ if (steps > 2) // If it is a large leap, then we are going up an octave
12157
+ letterDistance += 7;else if (steps === -12) // If it is a large leap, then we are going down an octave
12158
+ letterDistance -= 7;
12159
+ } else if (steps > 0 && letterDistance < 0) letterDistance += 7;else if (steps < 0 && letterDistance > 0) letterDistance -= 7;
12160
+
12161
+ if (steps > 12) letterDistance += 7;else if (steps < -12) letterDistance -= 7;
12162
+ return letterDistance;
12163
+ }
12164
+
12165
+ function transposeVoice(abc, voice, keyRoot, keyAccidentals, destinationKey, steps) {
12166
+ var changes = [];
12167
+ var letterDistance = setLetterDistance(destinationKey, keyRoot, steps);
12168
+ var measureAccidentals = {};
12169
+ var transposedMeasureAccidentals = {};
12170
+
12171
+ for (var i = 0; i < voice.length; i++) {
12172
+ var el = voice[i];
12173
+
12174
+ if (el.chord) {
12175
+ for (var c = 0; c < el.chord.length; c++) {
12176
+ var ch = el.chord[c];
12177
+
12178
+ if (ch.position === 'default') {
12179
+ var prefersFlats = destinationKey.accidentals.length && destinationKey.accidentals[0].acc === 'flat';
12180
+ var newChord = transposeChordName(ch.name, steps, prefersFlats, true);
12181
+ newChord = newChord.replace(/♭/g, "b").replace(/♯/g, "#");
12182
+ if (newChord !== ch.name) // If we didn't recognize the chord the input is returned unchanged and there is nothing to replace
12183
+ changes.push(replaceChord(abc, el.startChar, el.endChar, newChord));
12184
+ }
12185
+ }
12186
+ }
12187
+
12188
+ if (el.el_type === 'note' && el.pitches) {
12189
+ for (var j = 0; j < el.pitches.length; j++) {
12190
+ var note = parseNote(el.pitches[j].name, keyRoot, keyAccidentals, measureAccidentals);
12191
+ if (note.acc) measureAccidentals[note.name.toUpperCase()] = note.acc;
12192
+ var newPitch = transposePitch(note, destinationKey, letterDistance, transposedMeasureAccidentals);
12193
+ if (newPitch.acc) transposedMeasureAccidentals[newPitch.upper] = newPitch.acc;
12194
+ changes.push(replaceNote(abc, el.startChar, el.endChar, newPitch.acc + newPitch.name, j));
12195
+ }
12196
+
12197
+ if (el.gracenotes) {
12198
+ for (var g = 0; g < el.gracenotes.length; g++) {
12199
+ var grace = parseNote(el.gracenotes[g].name, keyRoot, keyAccidentals, measureAccidentals);
12200
+ if (grace.acc) measureAccidentals[grace.name.toUpperCase()] = grace.acc;
12201
+ var newGrace = transposePitch(grace, destinationKey, letterDistance, measureAccidentals);
12202
+ if (newGrace.acc) transposedMeasureAccidentals[newGrace.upper] = newGrace.acc;
12203
+ changes.push(replaceGrace(abc, el.startChar, el.endChar, newGrace.acc + newGrace.name, g));
12204
+ }
12205
+ }
12206
+ } else if (el.el_type === "bar") {
12207
+ measureAccidentals = {};
12208
+ transposedMeasureAccidentals = {};
12209
+ } else if (el.el_type === "keySignature") {
12210
+ keyRoot = el.root;
12211
+ keyAccidentals = createKeyAccidentals(el);
12212
+ destinationKey = newKey(el, steps);
12213
+ letterDistance = setLetterDistance(destinationKey, keyRoot, steps);
12214
+ }
12215
+ }
12216
+
12217
+ return changes;
12218
+ }
12219
+
12220
+ var letters = "CDEFGAB";
12221
+ var octaves = [",,,,", ",,,", ",,", ",", "", "'", "''", "'''", "''''"];
12222
+
12223
+ function newKey(key, steps) {
12224
+ if (key.root === "none") {
12225
+ return {
12226
+ root: transposeKey("C", steps),
12227
+ mode: "",
12228
+ acc: "",
12229
+ accidentals: []
12230
+ };
12231
+ }
12232
+
12233
+ var major = relativeMajor(key.root + key.acc + key.mode);
12234
+ var newMajor = transposeKey(major, steps);
12235
+ var newMode = relativeMode(newMajor, key.mode);
12236
+ var acc = keyAccidentals(newMajor);
12237
+ return {
12238
+ root: newMode[0],
12239
+ mode: key.mode,
12240
+ acc: newMode.length > 1 ? newMode[1] : '',
12241
+ accidentals: acc
12242
+ };
12243
+ }
12244
+
12245
+ function transposePitch(note, key, letterDistance, measureAccidentals) {
12246
+ // Depending on what the current note and new note are, the octave might have changed
12247
+ // The letterDistance is how far the change is to see if we passed "C" when transposing.
12248
+ var pitch = note.pitch;
12249
+ var origDistFromC = letters.indexOf(note.name);
12250
+ var root = letters.indexOf(key.root);
12251
+ var index = (root + pitch) % 7; // if the note crosses "c" then the octave changes, so that is true of "B" when going up one step, "A" and "B" when going up two steps, etc., and reverse when going down.
12252
+
12253
+ var newDistFromC = origDistFromC + letterDistance;
12254
+ var oct = note.oct;
12255
+
12256
+ while (newDistFromC > 6) {
12257
+ oct++;
12258
+ newDistFromC -= 7;
12259
+ }
12260
+
12261
+ while (newDistFromC < 0) {
12262
+ oct--;
12263
+ newDistFromC += 7;
12264
+ }
12265
+
12266
+ var name = letters[index];
12267
+ var acc = '';
12268
+ var adj = note.adj; // the amount of adjustment depends on the key - if there is a sharp in the key sig, then -1 is a natural, if there isn't, then -1 is a flat.
12269
+
12270
+ var keyAcc = '=';
12271
+
12272
+ for (var i = 0; i < key.accidentals.length; i++) {
12273
+ if (key.accidentals[i].note.toLowerCase() === name.toLowerCase()) {
12274
+ adj = adj + (key.accidentals[i].acc === 'flat' ? -1 : 1);
12275
+ keyAcc = key.accidentals[i].acc === 'flat' ? '_' : '^';
12276
+ break;
12277
+ }
12278
+ }
12279
+
12280
+ switch (adj) {
12281
+ case -2:
12282
+ acc = "__";
12283
+ break;
12284
+
12285
+ case -1:
12286
+ acc = "_";
12287
+ break;
12288
+
12289
+ case 0:
12290
+ acc = "=";
12291
+ break;
12292
+
12293
+ case 1:
12294
+ acc = "^";
12295
+ break;
12296
+
12297
+ case 2:
12298
+ acc = "^^";
12299
+ break;
12300
+
12301
+ case -3:
12302
+ // This requires a triple flat, so bump down the pitch and try again
12303
+ var newNote = {};
12304
+ newNote.pitch = note.pitch - 1;
12305
+ newNote.oct = note.oct;
12306
+ newNote.name = letters[letters.indexOf(note.name) - 1];
12307
+
12308
+ if (!newNote.name) {
12309
+ newNote.name = "B";
12310
+ newNote.oct--;
12311
+ }
12312
+
12313
+ if (newNote.name === "B" || newNote.name === "E") newNote.adj = note.adj + 1;else newNote.adj = note.adj + 2;
12314
+ return transposePitch(newNote, key, letterDistance + 1, measureAccidentals);
12315
+
12316
+ case 3:
12317
+ // This requires a triple sharp, so bump up the pitch and try again
12318
+ var newNote = {};
12319
+ newNote.pitch = note.pitch + 1;
12320
+ newNote.oct = note.oct;
12321
+ newNote.name = letters[letters.indexOf(note.name) + 1];
12322
+
12323
+ if (!newNote.name) {
12324
+ newNote.name = "C";
12325
+ newNote.oct++;
12326
+ }
12327
+
12328
+ if (newNote.name === "C" || newNote.name === "F") newNote.adj = note.adj - 1;else newNote.adj = note.adj - 2;
12329
+ return transposePitch(newNote, key, letterDistance + 1, measureAccidentals);
12330
+ }
12331
+
12332
+ if ((measureAccidentals[name] === acc || !measureAccidentals[name] && acc === keyAcc) && !note.courtesy) acc = "";
12333
+
12334
+ switch (oct) {
12335
+ case 0:
12336
+ name = name + ",,,";
12337
+ break;
12338
+
12339
+ case 1:
12340
+ name = name + ",,";
12341
+ break;
12342
+
12343
+ case 2:
12344
+ name = name + ",";
12345
+ break;
12346
+ // case 3: it is already correct
12347
+
12348
+ case 4:
12349
+ name = name.toLowerCase();
12350
+ break;
12351
+
12352
+ case 5:
12353
+ name = name.toLowerCase() + "'";
12354
+ break;
12355
+
12356
+ case 6:
12357
+ name = name.toLowerCase() + "''";
12358
+ break;
12359
+
12360
+ case 7:
12361
+ name = name.toLowerCase() + "'''";
12362
+ break;
12363
+
12364
+ case 8:
12365
+ name = name.toLowerCase() + "''''";
12366
+ break;
12367
+ }
12368
+
12369
+ if (oct > 4) name = name.toLowerCase();
12370
+ return {
12371
+ acc: acc,
12372
+ name: name,
12373
+ upper: name.toUpperCase()
12374
+ };
12375
+ }
12376
+
12377
+ var regPitch = /([_^=]*)([A-Ga-g])([,']*)/;
12378
+ var regNote = /([_^=]*[A-Ga-g][,']*)(\d*\/*\d*)([\>\<\-\)\.\s\\]*)/;
12379
+ var regOptionalNote = /([_^=]*[A-Ga-g][,']*)?(\d*\/*\d*)?([\>\<\-\)]*)?/;
12380
+ var regSpace = /(\s*)$/; // This the relationship of the note to the tonic and an octave. So what is returned is a distance in steps from the tonic and the amount of adjustment from
12381
+ // a normal scale. That is - in the key of D an F# is two steps from the tonic and no adjustment. A G# is three steps from the tonic and one half-step higher.
12382
+ // I don't think there is any adjustment needed for minor keys since the adjustment is based on the key signature and the accidentals.
12383
+
12384
+ function parseNote(note, keyRoot, keyAccidentals, measureAccidentals) {
12385
+ var root = keyRoot === "none" ? 0 : letters.indexOf(keyRoot);
12386
+ var reg = note.match(regPitch); // reg[1] : "__", "_", "", "=", "^", or "^^"
12387
+ // reg[2] : A-G a-g
12388
+ // reg[3] : commas or apostrophes
12389
+
12390
+ var name = reg[2].toUpperCase();
12391
+ var pos = letters.indexOf(name) - root;
12392
+ if (pos < 0) pos += 7;
12393
+ var oct = octaves.indexOf(reg[3]);
12394
+ if (name === reg[2]) // See if it is a capital letter and subtract an octave if so.
12395
+ oct--;
12396
+ var currentAcc = measureAccidentals[name] || keyAccidentals[name] || "="; // use the key accidentals if they exist, but override with the measure accidentals, and if neither of them exist, use a natural.
12397
+
12398
+ return {
12399
+ acc: reg[1],
12400
+ name: name,
12401
+ pitch: pos,
12402
+ oct: oct,
12403
+ adj: calcAdjustment(reg[1], keyAccidentals[name], measureAccidentals[name]),
12404
+ courtesy: reg[1] === currentAcc
12405
+ };
12406
+ }
12407
+
12408
+ function replaceNote(abc, start, end, newPitch, index) {
12409
+ // There may be more than just the note between the start and end - there could be spaces, there could be a chord symbol, there could be a decoration.
12410
+ // This could also be a part of a chord. If so, then the particular note needs to be teased out.
12411
+ var note = abc.substring(start, end);
12412
+ var match = note.match(new RegExp(regNote.source + regSpace.source), '');
12413
+
12414
+ if (match) {
12415
+ // This will match a single note
12416
+ var noteLen = match[1].length;
12417
+ var trailingLen = match[2].length + match[3].length + match[4].length;
12418
+ var leadingLen = end - start - noteLen - trailingLen;
12419
+ start += leadingLen;
12420
+ end -= trailingLen;
12421
+ } else {
12422
+ // I don't know how to capture more than one note, so I'm separating them. There is a limit of the number of notes in a chord depending on the repeats I have here, but it is unlikely to happen in real music.
12423
+ var regPreBracket = /([^\[]*)/;
12424
+ var regOpenBracket = /\[/;
12425
+ var regCloseBracket = /\-?](\d*\/*\d*)?([\>\<\-\)]*)/;
12426
+ match = note.match(new RegExp(regPreBracket.source + regOpenBracket.source + regOptionalNote.source + regOptionalNote.source + regOptionalNote.source + regOptionalNote.source + regOptionalNote.source + regOptionalNote.source + regOptionalNote.source + regOptionalNote.source + regCloseBracket.source + regSpace.source));
12427
+
12428
+ if (match) {
12429
+ // This will match a chord
12430
+ // Get the number of chars used by the previous notes in this chord
12431
+ var count = 1 + match[1].length; // one character for the open bracket
12432
+
12433
+ for (var i = 0; i < index; i++) {
12434
+ // index is the iteration through the chord. This function gets called for each one.
12435
+ if (match[i * 3 + 2]) count += match[i * 3 + 2].length;
12436
+ if (match[i * 3 + 3]) count += match[i * 3 + 3].length;
12437
+ if (match[i * 3 + 4]) count += match[i * 3 + 4].length;
12438
+ }
12439
+
12440
+ start += count;
12441
+ var endLen = match[index * 3 + 2] ? match[index * 3 + 2].length : 0; // endLen += match[index * 3 + 3] ? match[index * 3 + 3].length : 0
12442
+ // endLen += match[index * 3 + 4] ? match[index * 3 + 4].length : 0
12443
+
12444
+ end = start + endLen;
12445
+ }
12446
+ }
12447
+
12448
+ return {
12449
+ start: start,
12450
+ end: end,
12451
+ note: newPitch
12452
+ };
12453
+ }
12454
+
12455
+ function replaceGrace(abc, start, end, newGrace, index) {
12456
+ var note = abc.substring(start, end); // I don't know how to capture more than one note, so I'm separating them. There is a limit of the number of notes in a chord depending on the repeats I have here, but it is unlikely to happen in real music.
12457
+
12458
+ var regOpenBrace = /\{/;
12459
+ var regCloseBrace = /\}/;
12460
+ var regPreBrace = /([^\{]*)/;
12461
+ var regPreNote = /(\/*)/;
12462
+ var match = note.match(new RegExp(regPreBrace.source + regOpenBrace.source + regPreNote.source + regOptionalNote.source + regPreNote.source + regOptionalNote.source + regPreNote.source + regOptionalNote.source + regPreNote.source + regOptionalNote.source + regPreNote.source + regOptionalNote.source + regPreNote.source + regOptionalNote.source + regPreNote.source + regOptionalNote.source + regPreNote.source + regOptionalNote.source + regCloseBrace.source));
12463
+
12464
+ if (match) {
12465
+ // This will match all notes inside a grace symbol
12466
+ // Get the number of chars used by the previous graces
12467
+ var count = 1 + match[1].length; // one character for the open brace, and whatever comes before the brace
12468
+
12469
+ for (var i = 0; i < index; i++) {
12470
+ // index is the iteration through the chord. This function gets called for each one.
12471
+ if (match[i * 3 + 2]) count += match[i * 3 + 2].length;
12472
+ if (match[i * 3 + 3]) count += match[i * 3 + 3].length;
12473
+ if (match[i * 3 + 4]) count += match[i * 3 + 4].length;
12474
+ if (match[i * 3 + 5]) count += match[i * 3 + 5].length;
12475
+ }
12476
+
12477
+ if (match[index * 3 + 2]) count += match[i * 3 + 2].length;
12478
+ start += count;
12479
+ var endLen = match[index * 3 + 3] ? match[index * 3 + 3].length : 0;
12480
+ endLen += match[index * 3 + 4] ? match[index * 3 + 4].length : 0;
12481
+ endLen += match[index * 3 + 5] ? match[index * 3 + 5].length : 0;
12482
+ end = start + endLen;
12483
+ }
12484
+
12485
+ return {
12486
+ start: start,
12487
+ end: end,
12488
+ note: newGrace
12489
+ };
12490
+ }
12491
+
12492
+ function replaceChord(abc, start, end, newChord) {
12493
+ // Isolate the chord and just replace that
12494
+ var match = abc.substring(start, end).match(/([^"]+)?(".+")+/);
12495
+ if (match[1]) start += match[1].length;
12496
+ end = start + match[2].length; // leave the quote in, so skip one more
12497
+
12498
+ return {
12499
+ start: start + 1,
12500
+ end: end - 1,
12501
+ note: newChord
12502
+ };
12503
+ }
12504
+
12505
+ function calcAdjustment(thisAccidental, keyAccidental, measureAccidental) {
12506
+ if (!thisAccidental && measureAccidental) {
12507
+ // There was no accidental on this note, but there was earlier in the measure, so we'll use that
12508
+ thisAccidental = measureAccidental;
12509
+ }
12510
+
12511
+ if (!thisAccidental) return 0; // there is no deviation from the key.
12512
+
12513
+ switch (keyAccidental) {
12514
+ case undefined:
12515
+ switch (thisAccidental) {
12516
+ case '__':
12517
+ return -2;
12518
+
12519
+ case '_':
12520
+ return -1;
12521
+
12522
+ case '=':
12523
+ return 0;
12524
+
12525
+ case '^':
12526
+ return 1;
12527
+
12528
+ case '^^':
12529
+ return 2;
12530
+
12531
+ default:
12532
+ return 0;
12533
+ // this should never happen
12534
+ }
12535
+
12536
+ case '_':
12537
+ switch (thisAccidental) {
12538
+ case '__':
12539
+ return -1;
12540
+
12541
+ case '_':
12542
+ return 0;
12543
+
12544
+ case '=':
12545
+ return 1;
12546
+
12547
+ case '^':
12548
+ return 2;
12549
+
12550
+ case '^^':
12551
+ return 3;
12552
+
12553
+ default:
12554
+ return 0;
12555
+ // this should never happen
12556
+ }
12557
+
12558
+ case '^':
12559
+ switch (thisAccidental) {
12560
+ case '__':
12561
+ return -3;
12562
+
12563
+ case '_':
12564
+ return -2;
12565
+
12566
+ case '=':
12567
+ return -1;
12568
+
12569
+ case '^':
12570
+ return 0;
12571
+
12572
+ case '^^':
12573
+ return 1;
12574
+
12575
+ default:
12576
+ return 0;
12577
+ // this should never happen
12578
+ }
12579
+
12580
+ }
12581
+
12582
+ return 0; // this should never happen
12583
+ }
12584
+ })();
12585
+
12586
+ module.exports = strTranspose;
12587
+
12588
+ /***/ }),
12589
+
12014
12590
  /***/ "./src/synth/abc_midi_flattener.js":
12015
12591
  /*!*****************************************!*\
12016
12592
  !*** ./src/synth/abc_midi_flattener.js ***!
@@ -21322,6 +21898,7 @@ var tablatures = __webpack_require__(/*! ../api/abc_tablatures */ "./src/api/abc
21322
21898
 
21323
21899
  var EngraverController = function EngraverController(paper, params) {
21324
21900
  params = params || {};
21901
+ this.oneSvgPerLine = params.oneSvgPerLine;
21325
21902
  this.selectionColor = params.selectionColor;
21326
21903
  this.dragColor = params.dragColor ? params.dragColor : params.selectionColor;
21327
21904
  this.dragging = !!params.dragging;
@@ -21538,8 +22115,82 @@ EngraverController.prototype.engraveTune = function (abcTune, tuneNumber, lineOf
21538
22115
  var ret = draw(this.renderer, this.classes, abcTune, this.width, maxWidth, this.responsive, scale, this.selectTypes, tuneNumber, lineOffset);
21539
22116
  this.staffgroups = ret.staffgroups;
21540
22117
  this.selectables = ret.selectables;
21541
- setupSelection(this);
21542
- };
22118
+
22119
+ if (this.oneSvgPerLine) {
22120
+ var div = this.renderer.paper.svg.parentNode;
22121
+ this.svgs = splitSvgIntoLines(div, abcTune.metaText.title, this.responsive);
22122
+ } else {
22123
+ this.svgs = [this.renderer.paper.svg];
22124
+ }
22125
+
22126
+ setupSelection(this, this.svgs);
22127
+ };
22128
+
22129
+ function splitSvgIntoLines(output, title, responsive) {
22130
+ // Each line is a top level <g> in the svg. To split it into separate
22131
+ // svgs iterate through each of those and put them in a new svg. Since
22132
+ // they are placed absolutely, the viewBox needs to be manipulated to
22133
+ // get the correct vertical positioning.
22134
+ // We copy all the attributes from the original svg except for the aria-label
22135
+ // since we want that to include a count. And the height is now a fraction of the original svg.
22136
+ if (!title) title = "Untitled";
22137
+ var source = output.querySelector("svg");
22138
+ if (responsive === 'resize') output.style.paddingBottom = '';
22139
+ var style = source.querySelector("style");
22140
+ var width = responsive === 'resize' ? source.viewBox.baseVal.width : source.getAttribute("width");
22141
+ var sections = output.querySelectorAll("svg > g"); // each section is a line, or the top matter or the bottom matter, or text that has been inserted.
22142
+
22143
+ var nextTop = 0; // There are often gaps between the elements for spacing, so the actual top and height needs to be inferred.
22144
+
22145
+ var wrappers = []; // Create all the elements and place them at once because we use the current svg to get data. It would disappear after placing the first line.
22146
+
22147
+ var svgs = [];
22148
+
22149
+ for (var i = 0; i < sections.length; i++) {
22150
+ var section = sections[i];
22151
+ var box = section.getBBox();
22152
+ var gapBetweenLines = box.y - nextTop; // take the margin into account
22153
+
22154
+ var height = box.height + gapBetweenLines;
22155
+ var wrapper = document.createElement("div");
22156
+ var divStyles = "overflow: hidden;";
22157
+ if (responsive !== 'resize') divStyles += "height:" + height + "px;";
22158
+ wrapper.setAttribute("style", divStyles);
22159
+ var svg = duplicateSvg(source);
22160
+ var fullTitle = "Sheet Music for \"" + title + "\" section " + (i + 1);
22161
+ svg.setAttribute("aria-label", fullTitle);
22162
+ if (responsive !== 'resize') svg.setAttribute("height", height);
22163
+ if (responsive === 'resize') svg.style.position = '';
22164
+ svg.setAttribute("viewBox", "0 " + nextTop + " " + width + " " + height);
22165
+ svg.appendChild(style.cloneNode(true));
22166
+ var titleEl = document.createElement("title");
22167
+ titleEl.innerText = fullTitle;
22168
+ svg.appendChild(titleEl);
22169
+ svg.appendChild(section);
22170
+ wrapper.appendChild(svg);
22171
+ svgs.push(svg);
22172
+ output.appendChild(wrapper); //wrappers.push(wrapper)
22173
+
22174
+ nextTop = box.y + box.height;
22175
+ } // for (i = 0; i < wrappers.length; i++)
22176
+ // output.appendChild(wrappers[i])
22177
+
22178
+
22179
+ output.removeChild(source);
22180
+ return svgs;
22181
+ }
22182
+
22183
+ function duplicateSvg(source) {
22184
+ var svgNS = "http://www.w3.org/2000/svg";
22185
+ var svg = document.createElementNS(svgNS, "svg");
22186
+
22187
+ for (var i = 0; i < source.attributes.length; i++) {
22188
+ var attr = source.attributes[i];
22189
+ if (attr.name !== "height" && attr.name != "aria-label") svg.setAttribute(attr.name, attr.value);
22190
+ }
22191
+
22192
+ return svg;
22193
+ }
21543
22194
 
21544
22195
  EngraverController.prototype.getDim = function (historyEl) {
21545
22196
  // Get the dimensions on demand because the getBBox call is expensive.
@@ -23906,8 +24557,10 @@ var Selectables = __webpack_require__(/*! ./selectables */ "./src/write/draw/sel
23906
24557
 
23907
24558
  function draw(renderer, classes, abcTune, width, maxWidth, responsive, scale, selectTypes, tuneNumber, lineOffset) {
23908
24559
  var selectables = new Selectables(renderer.paper, selectTypes, tuneNumber);
24560
+ renderer.paper.openGroup();
23909
24561
  renderer.moveY(renderer.padding.top);
23910
24562
  nonMusic(renderer, abcTune.topText, selectables);
24563
+ renderer.paper.closeGroup();
23911
24564
  renderer.moveY(renderer.spacing.music);
23912
24565
  var staffgroups = [];
23913
24566
 
@@ -23916,6 +24569,8 @@ function draw(renderer, classes, abcTune, width, maxWidth, responsive, scale, se
23916
24569
  var abcLine = abcTune.lines[line];
23917
24570
 
23918
24571
  if (abcLine.staff) {
24572
+ renderer.paper.openGroup();
24573
+
23919
24574
  if (abcLine.vskip) {
23920
24575
  renderer.moveY(abcLine.vskip);
23921
24576
  }
@@ -23925,17 +24580,22 @@ function draw(renderer, classes, abcTune, width, maxWidth, responsive, scale, se
23925
24580
  staffgroup.line = lineOffset + line; // If there are non-music lines then the staffgroup array won't line up with the line array, so this keeps track.
23926
24581
 
23927
24582
  staffgroups.push(staffgroup);
24583
+ renderer.paper.closeGroup();
23928
24584
  } else if (abcLine.nonMusic) {
24585
+ renderer.paper.openGroup();
23929
24586
  nonMusic(renderer, abcLine.nonMusic, selectables);
24587
+ renderer.paper.closeGroup();
23930
24588
  }
23931
24589
  }
23932
24590
 
23933
24591
  classes.reset();
23934
24592
 
23935
24593
  if (abcTune.bottomText && abcTune.bottomText.rows && abcTune.bottomText.rows.length > 0) {
24594
+ renderer.paper.openGroup();
23936
24595
  renderer.moveY(24); // TODO-PER: Empirically discovered. What variable should this be?
23937
24596
 
23938
24597
  nonMusic(renderer, abcTune.bottomText, selectables);
24598
+ renderer.paper.closeGroup();
23939
24599
  }
23940
24600
 
23941
24601
  setPaperSize(renderer, maxWidth, scale, responsive);
@@ -25002,8 +25662,8 @@ function drawStaffGroup(renderer, params, selectables, lineNumber) {
25002
25662
  // renderer.y will be offset at the beginning of each staff by the amount required to make the relative pitch work.
25003
25663
  // If there are multiple staves, then renderer.y will be incremented for each new staff.
25004
25664
  var colorIndex; // An invisible marker is useful to be able to find where each system starts.
25665
+ //addInvisibleMarker(renderer, "abcjs-top-of-system");
25005
25666
 
25006
- addInvisibleMarker(renderer, "abcjs-top-of-system");
25007
25667
  var startY = renderer.y; // So that it can be restored after we're done.
25008
25668
  // Set the absolute Y position for each staff here, so the voice drawing below can just use if.
25009
25669
 
@@ -25195,20 +25855,11 @@ function printBrace(renderer, absoluteY, brace, index, selectables) {
25195
25855
  }
25196
25856
  }
25197
25857
  }
25198
- }
25858
+ } // function addInvisibleMarker(renderer, className) {
25859
+ // var y = Math.round(renderer.y);
25860
+ // renderer.paper.pathToBack({path:"M 0 " + y + " L 0 0", stroke:"none", fill:"none", "stroke-opacity": 0, "fill-opacity": 0, 'class': renderer.controller.classes.generate(className), 'data-vertical': y });
25861
+ // }
25199
25862
 
25200
- function addInvisibleMarker(renderer, className) {
25201
- var y = Math.round(renderer.y);
25202
- renderer.paper.pathToBack({
25203
- path: "M 0 " + y + " L 0 0",
25204
- stroke: "none",
25205
- fill: "none",
25206
- "stroke-opacity": 0,
25207
- "fill-opacity": 0,
25208
- 'class': renderer.controller.classes.generate(className),
25209
- 'data-vertical': y
25210
- });
25211
- }
25212
25863
 
25213
25864
  function boxAllElements(renderer, voices, which) {
25214
25865
  for (var i = 0; i < which.length; i++) {
@@ -27375,7 +28026,7 @@ module.exports = layoutVoice;
27375
28026
 
27376
28027
  var spacing = __webpack_require__(/*! ./abc_spacing */ "./src/write/abc_spacing.js");
27377
28028
 
27378
- function setupSelection(engraver) {
28029
+ function setupSelection(engraver, svgs) {
27379
28030
  engraver.rangeHighlight = rangeHighlight;
27380
28031
 
27381
28032
  if (engraver.dragging) {
@@ -27392,14 +28043,21 @@ function setupSelection(engraver) {
27392
28043
  }
27393
28044
  }
27394
28045
 
27395
- engraver.renderer.paper.svg.addEventListener('mousedown', mouseDown.bind(engraver));
27396
- engraver.renderer.paper.svg.addEventListener('mousemove', mouseMove.bind(engraver));
27397
- engraver.renderer.paper.svg.addEventListener('mouseup', mouseUp.bind(engraver));
28046
+ for (var i = 0; i < svgs.length; i++) {
28047
+ svgs[i].addEventListener('touchstart', mouseDown.bind(engraver));
28048
+ svgs[i].addEventListener('touchmove', mouseMove.bind(engraver));
28049
+ svgs[i].addEventListener('touchend', mouseUp.bind(engraver));
28050
+ svgs[i].addEventListener('mousedown', mouseDown.bind(engraver));
28051
+ svgs[i].addEventListener('mousemove', mouseMove.bind(engraver));
28052
+ svgs[i].addEventListener('mouseup', mouseUp.bind(engraver));
28053
+ }
27398
28054
  }
27399
28055
 
27400
- function getCoord(ev, svg) {
28056
+ function getCoord(ev) {
27401
28057
  var scaleX = 1;
27402
- var scaleY = 1; // when renderer.options.responsive === 'resize' the click coords are in relation to the HTML
28058
+ var scaleY = 1;
28059
+ var svg = ev.target.closest('svg');
28060
+ var yOffset = 0; // when renderer.options.responsive === 'resize' the click coords are in relation to the HTML
27403
28061
  // element, we need to convert to the SVG viewBox coords
27404
28062
 
27405
28063
  if (svg.viewBox.baseVal) {
@@ -27407,6 +28065,7 @@ function getCoord(ev, svg) {
27407
28065
  // Chrome makes these values null when no viewBox is given.
27408
28066
  if (svg.viewBox.baseVal.width !== 0) scaleX = svg.viewBox.baseVal.width / svg.clientWidth;
27409
28067
  if (svg.viewBox.baseVal.height !== 0) scaleY = svg.viewBox.baseVal.height / svg.clientHeight;
28068
+ yOffset = svg.viewBox.baseVal.y;
27410
28069
  }
27411
28070
 
27412
28071
  var svgClicked = ev.target.tagName === "svg";
@@ -27424,7 +28083,7 @@ function getCoord(ev, svg) {
27424
28083
  x = x * scaleX;
27425
28084
  y = y * scaleY; //console.log(x, y)
27426
28085
 
27427
- return [x, y];
28086
+ return [x, y + yOffset];
27428
28087
  }
27429
28088
 
27430
28089
  function elementFocused(ev) {
@@ -27505,7 +28164,7 @@ function keyboardSelection(ev) {
27505
28164
 
27506
28165
  function findElementInHistory(selectables, el) {
27507
28166
  for (var i = 0; i < selectables.length; i++) {
27508
- if (el === selectables[i].svgEl) return i;
28167
+ if (el.dataset.index === selectables[i].svgEl.dataset.index) return i;
27509
28168
  }
27510
28169
 
27511
28170
  return -1;
@@ -27598,7 +28257,7 @@ function getMousePosition(self, ev) {
27598
28257
  y = box[1]; //console.log("clicked on", clickedOn, x, y, self.selectables[clickedOn].svgEl.getBBox(), ev.target.getBBox());
27599
28258
  } else {
27600
28259
  // See if they clicked close to an element.
27601
- box = getCoord(ev, self.renderer.paper.svg);
28260
+ box = getCoord(ev);
27602
28261
  x = box[0];
27603
28262
  y = box[1];
27604
28263
  clickedOn = findElementByCoord(self, x, y); //console.log("clicked near", clickedOn, x, y, printEl(ev.target));
@@ -27611,11 +28270,28 @@ function getMousePosition(self, ev) {
27611
28270
  };
27612
28271
  }
27613
28272
 
28273
+ function attachMissingTouchEventAttributes(touchEv) {
28274
+ var rect = touchEv.target.getBoundingClientRect();
28275
+ var offsetX = touchEv.touches[0].pageX - rect.left;
28276
+ var offsetY = touchEv.touches[0].pageY - rect.top;
28277
+ touchEv.touches[0].offsetX = offsetX;
28278
+ touchEv.touches[0].offsetY = offsetY;
28279
+ touchEv.touches[0].layerX = touchEv.touches[0].pageX;
28280
+ touchEv.touches[0].layerY = touchEv.touches[0].pageY;
28281
+ }
28282
+
27614
28283
  function mouseDown(ev) {
27615
28284
  // "this" is the EngraverController because of the bind(this) when setting the event listener.
27616
- var positioning = getMousePosition(this, ev); // Only start dragging if the user clicked close enough to an element and clicked with the main mouse button.
28285
+ var _ev = ev;
28286
+
28287
+ if (ev.type === 'touchstart') {
28288
+ attachMissingTouchEventAttributes(ev);
28289
+ _ev = ev.touches[0];
28290
+ }
27617
28291
 
27618
- if (positioning.clickedOn >= 0 && ev.button === 0) {
28292
+ var positioning = getMousePosition(this, _ev); // Only start dragging if the user clicked close enough to an element and clicked with the main mouse button.
28293
+
28294
+ if (positioning.clickedOn >= 0 && (ev.type === 'touchstart' || ev.button === 0)) {
27619
28295
  this.dragTarget = this.selectables[positioning.clickedOn];
27620
28296
  this.dragIndex = positioning.clickedOn;
27621
28297
  this.dragMechanism = "mouse";
@@ -27632,9 +28308,17 @@ function mouseDown(ev) {
27632
28308
  }
27633
28309
 
27634
28310
  function mouseMove(ev) {
27635
- // "this" is the EngraverController because of the bind(this) when setting the event listener.
28311
+ var _ev = ev;
28312
+
28313
+ if (ev.type === 'touchmove') {
28314
+ attachMissingTouchEventAttributes(ev);
28315
+ _ev = ev.touches[0];
28316
+ }
28317
+
28318
+ this.lastTouchMove = ev; // "this" is the EngraverController because of the bind(this) when setting the event listener.
28319
+
27636
28320
  if (!this.dragTarget || !this.dragging || !this.dragTarget.isDraggable || this.dragMechanism !== 'mouse') return;
27637
- var positioning = getMousePosition(this, ev);
28321
+ var positioning = getMousePosition(this, _ev);
27638
28322
  var yDist = Math.round((positioning.y - this.dragMouseStart.y) / spacing.STEP);
27639
28323
 
27640
28324
  if (yDist !== this.dragYStep) {
@@ -27645,6 +28329,13 @@ function mouseMove(ev) {
27645
28329
 
27646
28330
  function mouseUp(ev) {
27647
28331
  // "this" is the EngraverController because of the bind(this) when setting the event listener.
28332
+ var _ev = ev;
28333
+
28334
+ if (ev.type === 'touchend') {
28335
+ attachMissingTouchEventAttributes(this.lastTouchMove);
28336
+ _ev = this.lastTouchMove.touches[0];
28337
+ }
28338
+
27648
28339
  if (!this.dragTarget) return;
27649
28340
  clearSelection.bind(this)();
27650
28341
 
@@ -27653,7 +28344,7 @@ function mouseUp(ev) {
27653
28344
  this.dragTarget.absEl.highlight(undefined, this.selectionColor);
27654
28345
  }
27655
28346
 
27656
- notifySelect.bind(this)(this.dragTarget, this.dragYStep, this.selectables.length, this.dragIndex, ev);
28347
+ notifySelect.bind(this)(this.dragTarget, this.dragYStep, this.selectables.length, this.dragIndex, _ev);
27657
28348
 
27658
28349
  if (this.dragTarget.svgEl && this.dragTarget.svgEl.focus) {
27659
28350
  this.dragTarget.svgEl.focus();
@@ -28460,7 +29151,7 @@ module.exports = unhighlight;
28460
29151
  \********************/
28461
29152
  /***/ (function(module) {
28462
29153
 
28463
- var version = '6.0.4';
29154
+ var version = '6.1.2';
28464
29155
  module.exports = version;
28465
29156
 
28466
29157
  /***/ })