chordsheetjs 4.9.0 → 5.1.3
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.
- package/README.md +164 -138
- package/lib/chord.js +341 -35
- package/lib/chord_sheet/chord_lyrics_pair.js +1 -1
- package/lib/chord_sheet/chord_pro/composite.js +1 -1
- package/lib/chord_sheet/chord_pro/evaluation_error.js +7 -3
- package/lib/chord_sheet/chord_pro/literal.js +1 -1
- package/lib/chord_sheet/chord_pro/ternary.js +1 -1
- package/lib/chord_sheet/comment.js +1 -1
- package/lib/chord_sheet/line.js +1 -1
- package/lib/chord_sheet/metadata.js +4 -4
- package/lib/chord_sheet/paragraph.js +1 -1
- package/lib/chord_sheet/song.js +17 -5
- package/lib/chord_sheet/tag.js +29 -6
- package/lib/chord_sheet_serializer.js +1 -1
- package/lib/constants.js +14 -2
- package/lib/formatter/chord_pro_formatter.js +1 -1
- package/lib/formatter/html_div_formatter.js +4 -4
- package/lib/formatter/html_formatter.js +3 -2
- package/lib/formatter/html_table_formatter.js +4 -4
- package/lib/formatter/templates/html_div_formatter.js +31 -32
- package/lib/formatter/templates/html_table_formatter.js +7 -6
- package/lib/formatter/text_formatter.js +25 -17
- package/lib/helpers.js +32 -0
- package/lib/index.js +33 -10
- package/lib/key.js +311 -0
- package/lib/note.js +132 -0
- package/lib/parser/chord_pro_parser.js +1 -1
- package/lib/parser/chord_pro_peg_parser.js +2 -2
- package/lib/parser/chord_sheet_parser.js +1 -1
- package/lib/parser/parser_warning.js +1 -1
- package/lib/parser/ultimate_guitar_parser.js +4 -4
- package/lib/{handlebars_helpers.js → template_helpers.js} +21 -2
- package/lib/utilities.js +22 -23
- package/package.json +7 -6
- package/lib/chord_helpers.js +0 -222
- package/lib/chord_symbol.js +0 -139
- package/lib/numeric_chord.js +0 -138
- package/lib/parse_chord.js +0 -74
- package/lib/to_chord_symbol.js +0 -93
package/lib/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -75,6 +77,12 @@ Object.defineProperty(exports, "INDETERMINATE", {
|
|
|
75
77
|
return _constants.INDETERMINATE;
|
|
76
78
|
}
|
|
77
79
|
});
|
|
80
|
+
Object.defineProperty(exports, "Key", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function get() {
|
|
83
|
+
return _key["default"];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
78
86
|
Object.defineProperty(exports, "Line", {
|
|
79
87
|
enumerable: true,
|
|
80
88
|
get: function get() {
|
|
@@ -99,18 +107,36 @@ Object.defineProperty(exports, "NONE", {
|
|
|
99
107
|
return _constants.NONE;
|
|
100
108
|
}
|
|
101
109
|
});
|
|
110
|
+
Object.defineProperty(exports, "NUMERIC", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function get() {
|
|
113
|
+
return _constants.NUMERIC;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
102
116
|
Object.defineProperty(exports, "Paragraph", {
|
|
103
117
|
enumerable: true,
|
|
104
118
|
get: function get() {
|
|
105
119
|
return _paragraph["default"];
|
|
106
120
|
}
|
|
107
121
|
});
|
|
122
|
+
Object.defineProperty(exports, "SYMBOL", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function get() {
|
|
125
|
+
return _constants.SYMBOL;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
108
128
|
Object.defineProperty(exports, "Song", {
|
|
109
129
|
enumerable: true,
|
|
110
130
|
get: function get() {
|
|
111
131
|
return _song["default"];
|
|
112
132
|
}
|
|
113
133
|
});
|
|
134
|
+
Object.defineProperty(exports, "TAB", {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function get() {
|
|
137
|
+
return _constants.TAB;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
114
140
|
Object.defineProperty(exports, "Tag", {
|
|
115
141
|
enumerable: true,
|
|
116
142
|
get: function get() {
|
|
@@ -145,13 +171,7 @@ exports["default"] = void 0;
|
|
|
145
171
|
Object.defineProperty(exports, "parseChord", {
|
|
146
172
|
enumerable: true,
|
|
147
173
|
get: function get() {
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
Object.defineProperty(exports, "toChordSymbol", {
|
|
152
|
-
enumerable: true,
|
|
153
|
-
get: function get() {
|
|
154
|
-
return _to_chord_symbol["default"];
|
|
174
|
+
return _chord.parseChord;
|
|
155
175
|
}
|
|
156
176
|
});
|
|
157
177
|
|
|
@@ -193,11 +213,13 @@ var _chord_sheet_serializer = _interopRequireDefault(require("./chord_sheet_seri
|
|
|
193
213
|
|
|
194
214
|
var _constants = require("./constants");
|
|
195
215
|
|
|
196
|
-
var _chord =
|
|
216
|
+
var _chord = _interopRequireWildcard(require("./chord"));
|
|
217
|
+
|
|
218
|
+
var _key = _interopRequireDefault(require("./key"));
|
|
197
219
|
|
|
198
|
-
var
|
|
220
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
199
221
|
|
|
200
|
-
var
|
|
222
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
201
223
|
|
|
202
224
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
203
225
|
|
|
@@ -222,6 +244,7 @@ var _default = {
|
|
|
222
244
|
ChordSheetSerializer: _chord_sheet_serializer["default"],
|
|
223
245
|
CHORUS: _constants.CHORUS,
|
|
224
246
|
INDETERMINATE: _constants.INDETERMINATE,
|
|
247
|
+
TAB: _constants.TAB,
|
|
225
248
|
VERSE: _constants.VERSE,
|
|
226
249
|
NONE: _constants.NONE
|
|
227
250
|
};
|
package/lib/key.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _note = _interopRequireDefault(require("./note"));
|
|
11
|
+
|
|
12
|
+
var _constants = require("./constants");
|
|
13
|
+
|
|
14
|
+
var _MODIFIER_TRANSPOSITI;
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
|
|
22
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
|
+
|
|
24
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
25
|
+
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
|
+
|
|
28
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
29
|
+
|
|
30
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
31
|
+
|
|
32
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
33
|
+
|
|
34
|
+
function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { return groups[name] = result[g[name]], groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); return result && (result.groups = buildGroups(result, this)), result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != _typeof(args[args.length - 1]) && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
|
|
35
|
+
|
|
36
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
37
|
+
|
|
38
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
39
|
+
|
|
40
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
41
|
+
|
|
42
|
+
var FLAT = 'b';
|
|
43
|
+
var SHARP = '#';
|
|
44
|
+
var MODIFIER_TRANSPOSITION = (_MODIFIER_TRANSPOSITI = {}, _defineProperty(_MODIFIER_TRANSPOSITI, SHARP, 1), _defineProperty(_MODIFIER_TRANSPOSITI, FLAT, -1), _MODIFIER_TRANSPOSITI);
|
|
45
|
+
|
|
46
|
+
var symbolKeyRegex = /*#__PURE__*/_wrapRegExp(/^([A-G])(#|b)?$/i, {
|
|
47
|
+
note: 1,
|
|
48
|
+
modifier: 2
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
var numericKeyRegex = /*#__PURE__*/_wrapRegExp(/^(#|b)?([1-7])$/, {
|
|
52
|
+
modifier: 1,
|
|
53
|
+
note: 2
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
var regexes = [symbolKeyRegex, numericKeyRegex];
|
|
57
|
+
|
|
58
|
+
var _set = /*#__PURE__*/new WeakSet();
|
|
59
|
+
|
|
60
|
+
var Key = /*#__PURE__*/function () {
|
|
61
|
+
function Key(_ref) {
|
|
62
|
+
var note = _ref.note,
|
|
63
|
+
_ref$modifier = _ref.modifier,
|
|
64
|
+
modifier = _ref$modifier === void 0 ? null : _ref$modifier;
|
|
65
|
+
|
|
66
|
+
_classCallCheck(this, Key);
|
|
67
|
+
|
|
68
|
+
_classPrivateMethodInitSpec(this, _set);
|
|
69
|
+
|
|
70
|
+
this.note = note instanceof _note["default"] ? note : new _note["default"](note);
|
|
71
|
+
this.modifier = modifier || null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_createClass(Key, [{
|
|
75
|
+
key: "distanceTo",
|
|
76
|
+
value: function distanceTo(otherKey) {
|
|
77
|
+
var otherKeyObj = Key.wrap(otherKey);
|
|
78
|
+
var key = this.useModifier(otherKeyObj.modifier);
|
|
79
|
+
var delta = 0;
|
|
80
|
+
|
|
81
|
+
while (!key.equals(otherKeyObj) && delta < 20) {
|
|
82
|
+
key = key.transposeUp().useModifier(otherKeyObj.modifier);
|
|
83
|
+
delta += 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return delta;
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
key: "clone",
|
|
90
|
+
value: function clone() {
|
|
91
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {});
|
|
92
|
+
}
|
|
93
|
+
}, {
|
|
94
|
+
key: "toChordSymbol",
|
|
95
|
+
value: function toChordSymbol(key) {
|
|
96
|
+
if (this.is(_constants.SYMBOL)) {
|
|
97
|
+
return this.clone();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var transposeDistance = this.note.getTransposeDistance() + (MODIFIER_TRANSPOSITION[this.modifier] || 0);
|
|
101
|
+
return key.transpose(transposeDistance).normalize().useModifier(key.modifier);
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "toChordSymbolString",
|
|
105
|
+
value: function toChordSymbolString(key) {
|
|
106
|
+
return this.toChordSymbol(key).toString();
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
key: "is",
|
|
110
|
+
value: function is(type) {
|
|
111
|
+
return this.note.is(type);
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "isNumeric",
|
|
115
|
+
value: function isNumeric() {
|
|
116
|
+
return this.is(_constants.NUMERIC);
|
|
117
|
+
}
|
|
118
|
+
}, {
|
|
119
|
+
key: "isChordSymbol",
|
|
120
|
+
value: function isChordSymbol() {
|
|
121
|
+
return this.is(_constants.SYMBOL);
|
|
122
|
+
}
|
|
123
|
+
}, {
|
|
124
|
+
key: "toNumeric",
|
|
125
|
+
value: function toNumeric(key) {
|
|
126
|
+
if (this.isNumeric()) {
|
|
127
|
+
return this.clone();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
var numericKey = new Key({
|
|
131
|
+
note: 1
|
|
132
|
+
});
|
|
133
|
+
var symbolKey = key.clone();
|
|
134
|
+
var reference = this.clone().normalize().useModifier(key.modifier);
|
|
135
|
+
|
|
136
|
+
while (!symbolKey.equals(reference)) {
|
|
137
|
+
numericKey = numericKey.transposeUp().useModifier(key.modifier);
|
|
138
|
+
symbolKey = symbolKey.transposeUp().normalize().useModifier(key.modifier);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return numericKey;
|
|
142
|
+
}
|
|
143
|
+
}, {
|
|
144
|
+
key: "equals",
|
|
145
|
+
value: function equals(_ref2) {
|
|
146
|
+
var note = _ref2.note,
|
|
147
|
+
modifier = _ref2.modifier;
|
|
148
|
+
return this.note.equals(note) && this.modifier === modifier;
|
|
149
|
+
}
|
|
150
|
+
}, {
|
|
151
|
+
key: "toNumericString",
|
|
152
|
+
value: function toNumericString(key) {
|
|
153
|
+
return this.toNumeric(key).toString();
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
key: "toString",
|
|
157
|
+
value: function toString() {
|
|
158
|
+
if (this.is(_constants.NUMERIC)) {
|
|
159
|
+
return "".concat(this.modifier || '').concat(this.note);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return "".concat(this.note).concat(this.modifier || '');
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
key: "transpose",
|
|
166
|
+
value: function transpose(delta) {
|
|
167
|
+
if (delta === 0) {
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
var originalModifier = this.modifier;
|
|
172
|
+
var transposedKey = this.clone();
|
|
173
|
+
var func = delta < 0 ? 'transposeDown' : 'transposeUp';
|
|
174
|
+
|
|
175
|
+
for (var i = 0, count = Math.abs(delta); i < count; i += 1) {
|
|
176
|
+
transposedKey = transposedKey[func]();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return transposedKey.useModifier(originalModifier);
|
|
180
|
+
}
|
|
181
|
+
}, {
|
|
182
|
+
key: "transposeUp",
|
|
183
|
+
value: function transposeUp() {
|
|
184
|
+
if (this.modifier === FLAT) {
|
|
185
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
186
|
+
modifier: null
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (this.note.isOneOf(3, 7, 'E', 'B')) {
|
|
191
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
192
|
+
note: this.note.up()
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (this.modifier === SHARP) {
|
|
197
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
198
|
+
note: this.note.up(),
|
|
199
|
+
modifier: null
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
204
|
+
modifier: SHARP
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
key: "transposeDown",
|
|
209
|
+
value: function transposeDown() {
|
|
210
|
+
if (this.modifier === SHARP) {
|
|
211
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
212
|
+
modifier: null
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (this.note.isOneOf(1, 4, 'C', 'F')) {
|
|
217
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
218
|
+
note: this.note.down()
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (this.modifier === FLAT) {
|
|
223
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
224
|
+
note: this.note.down(),
|
|
225
|
+
modifier: null
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
230
|
+
modifier: FLAT
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "useModifier",
|
|
235
|
+
value: function useModifier(newModifier) {
|
|
236
|
+
if (this.modifier === FLAT && newModifier === SHARP) {
|
|
237
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
238
|
+
note: this.note.down(),
|
|
239
|
+
modifier: SHARP
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (this.modifier === SHARP && newModifier === FLAT) {
|
|
244
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
245
|
+
note: this.note.up(),
|
|
246
|
+
modifier: FLAT
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return this.clone();
|
|
251
|
+
}
|
|
252
|
+
}, {
|
|
253
|
+
key: "normalize",
|
|
254
|
+
value: function normalize() {
|
|
255
|
+
if (this.modifier === SHARP && this.note.isOneOf(3, 7, 'E', 'B')) {
|
|
256
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
257
|
+
note: this.note.up(),
|
|
258
|
+
modifier: null
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (this.modifier === FLAT && this.note.isOneOf(1, 4, 'C', 'F')) {
|
|
263
|
+
return _classPrivateMethodGet(this, _set, _set2).call(this, {
|
|
264
|
+
note: this.note.down(),
|
|
265
|
+
modifier: null
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return this.clone();
|
|
270
|
+
}
|
|
271
|
+
}], [{
|
|
272
|
+
key: "parse",
|
|
273
|
+
value: function parse(keyString) {
|
|
274
|
+
for (var i = 0, count = regexes.length; i < count; i += 1) {
|
|
275
|
+
var match = keyString.match(regexes[i]);
|
|
276
|
+
|
|
277
|
+
if (match) {
|
|
278
|
+
return new Key(match.groups);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
}, {
|
|
285
|
+
key: "wrap",
|
|
286
|
+
value: function wrap(keyStringOrObject) {
|
|
287
|
+
if (keyStringOrObject instanceof Key) {
|
|
288
|
+
return keyStringOrObject;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return this.parse(keyStringOrObject);
|
|
292
|
+
}
|
|
293
|
+
}, {
|
|
294
|
+
key: "distance",
|
|
295
|
+
value: function distance(oneKey, otherKey) {
|
|
296
|
+
return this.wrap(oneKey).distanceTo(otherKey);
|
|
297
|
+
}
|
|
298
|
+
}]);
|
|
299
|
+
|
|
300
|
+
return Key;
|
|
301
|
+
}();
|
|
302
|
+
|
|
303
|
+
function _set2(attributes) {
|
|
304
|
+
return new this.constructor(_objectSpread({
|
|
305
|
+
note: this.note.clone(),
|
|
306
|
+
modifier: this.modifier
|
|
307
|
+
}, attributes));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var _default = Key;
|
|
311
|
+
exports["default"] = _default;
|
package/lib/note.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _constants = require("./constants");
|
|
9
|
+
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
|
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
13
|
+
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
|
|
16
|
+
var A = 'A'.charCodeAt(0);
|
|
17
|
+
var G = 'G'.charCodeAt(0);
|
|
18
|
+
var TRANSPOSE_DISTANCE = [null, 0, 2, 4, 5, 7, 9, 11];
|
|
19
|
+
|
|
20
|
+
function keyToCharCode(key) {
|
|
21
|
+
return key.toUpperCase().charCodeAt(0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function clamp(note, min, max) {
|
|
25
|
+
var newNote = note;
|
|
26
|
+
|
|
27
|
+
if (newNote < min) {
|
|
28
|
+
newNote += 7;
|
|
29
|
+
} else if (newNote > max) {
|
|
30
|
+
newNote -= 7;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return newNote;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var Note = /*#__PURE__*/function () {
|
|
37
|
+
function Note(note) {
|
|
38
|
+
_classCallCheck(this, Note);
|
|
39
|
+
|
|
40
|
+
if (/^[A-Ga-g]$/.test(note)) {
|
|
41
|
+
this.note = note.toUpperCase();
|
|
42
|
+
this.type = _constants.SYMBOL;
|
|
43
|
+
} else if (/^[1-7]$/.test(note)) {
|
|
44
|
+
this.note = parseInt(note, 10);
|
|
45
|
+
this.type = _constants.NUMERIC;
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error("Invalid note ".concat(note));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_createClass(Note, [{
|
|
52
|
+
key: "equals",
|
|
53
|
+
value: function equals(otherNote) {
|
|
54
|
+
return this.note === otherNote.note && this.type === otherNote.type;
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "clone",
|
|
58
|
+
value: function clone() {
|
|
59
|
+
return new this.constructor(this.note);
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "up",
|
|
63
|
+
value: function up() {
|
|
64
|
+
return this.change(1);
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
key: "down",
|
|
68
|
+
value: function down() {
|
|
69
|
+
return this.change(-1);
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
key: "isOneOf",
|
|
73
|
+
value: function isOneOf() {
|
|
74
|
+
for (var _len = arguments.length, options = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
75
|
+
options[_key] = arguments[_key];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return options.includes(this.note);
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "isNumeric",
|
|
82
|
+
value: function isNumeric() {
|
|
83
|
+
return this.is(_constants.NUMERIC);
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: "isChordSymbol",
|
|
87
|
+
value: function isChordSymbol() {
|
|
88
|
+
return this.is(_constants.SYMBOL);
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "is",
|
|
92
|
+
value: function is(noteType) {
|
|
93
|
+
return this.type === noteType;
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "getTransposeDistance",
|
|
97
|
+
value: function getTransposeDistance() {
|
|
98
|
+
return TRANSPOSE_DISTANCE[this.note];
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "change",
|
|
102
|
+
value: function change(delta) {
|
|
103
|
+
if (this.isNumeric()) {
|
|
104
|
+
var newNote = clamp(this.note + delta, 1, 7);
|
|
105
|
+
|
|
106
|
+
if (newNote < 1) {
|
|
107
|
+
newNote += 7;
|
|
108
|
+
} else if (newNote > 7) {
|
|
109
|
+
newNote -= 7;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return new Note(newNote);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
var charCode;
|
|
116
|
+
charCode = keyToCharCode(this.note);
|
|
117
|
+
charCode += delta;
|
|
118
|
+
charCode = clamp(charCode, A, G);
|
|
119
|
+
return new Note(String.fromCharCode(charCode));
|
|
120
|
+
}
|
|
121
|
+
}, {
|
|
122
|
+
key: "toString",
|
|
123
|
+
value: function toString() {
|
|
124
|
+
return "".concat(this.note);
|
|
125
|
+
}
|
|
126
|
+
}]);
|
|
127
|
+
|
|
128
|
+
return Note;
|
|
129
|
+
}();
|
|
130
|
+
|
|
131
|
+
var _default = Note;
|
|
132
|
+
exports["default"] = _default;
|
|
@@ -15,7 +15,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
15
15
|
|
|
16
16
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
17
17
|
|
|
18
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Parses a ChordPro chord sheet
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
9
|
|
|
10
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
11
|
|
|
12
12
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
13
|
|
|
@@ -13,7 +13,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
13
13
|
|
|
14
14
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
15
15
|
|
|
16
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
16
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
17
17
|
|
|
18
18
|
var WHITE_SPACE = /\s/;
|
|
19
19
|
var CHORD_LINE_REGEX = /^\s*((([A-G])(#|b)?([^/\s]*)(\/([A-G])(#|b)?)?)(\s|$)+)+(\s|$)+/;
|
|
@@ -9,7 +9,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
9
9
|
|
|
10
10
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
11
11
|
|
|
12
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Represents a parser warning, currently only used by ChordProParser.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -25,13 +25,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
25
25
|
|
|
26
26
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
27
27
|
|
|
28
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
28
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
29
29
|
|
|
30
|
-
function _get(
|
|
30
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
31
31
|
|
|
32
32
|
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
33
33
|
|
|
34
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
34
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
35
35
|
|
|
36
36
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
37
37
|
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasTextContents = void 0;
|
|
7
|
+
|
|
3
8
|
var _handlebars = _interopRequireDefault(require("handlebars"));
|
|
4
9
|
|
|
5
10
|
var _chord_lyrics_pair = _interopRequireDefault(require("./chord_sheet/chord_lyrics_pair"));
|
|
@@ -8,6 +13,8 @@ var _tag = _interopRequireDefault(require("./chord_sheet/tag"));
|
|
|
8
13
|
|
|
9
14
|
var _constants = require("./constants");
|
|
10
15
|
|
|
16
|
+
var _helpers = require("./helpers");
|
|
17
|
+
|
|
11
18
|
var _utilities = require("./utilities");
|
|
12
19
|
|
|
13
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -17,6 +24,16 @@ var lineHasContents = function lineHasContents(line) {
|
|
|
17
24
|
return item.isRenderable();
|
|
18
25
|
});
|
|
19
26
|
};
|
|
27
|
+
/* eslint import/prefer-default-export: 0 */
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var hasTextContents = function hasTextContents(line) {
|
|
31
|
+
return line.items.some(function (item) {
|
|
32
|
+
return item instanceof _chord_lyrics_pair["default"] && item.lyrics || item instanceof _tag["default"] && item.isRenderable() || (0, _utilities.isEvaluatable)(item);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.hasTextContents = hasTextContents;
|
|
20
37
|
|
|
21
38
|
_handlebars["default"].registerHelper('isChordLyricsPair', function (item) {
|
|
22
39
|
return item instanceof _chord_lyrics_pair["default"];
|
|
@@ -40,7 +57,7 @@ _handlebars["default"].registerHelper('shouldRenderLine', function (line, option
|
|
|
40
57
|
|
|
41
58
|
_handlebars["default"].registerHelper('hasChordContents', _utilities.hasChordContents);
|
|
42
59
|
|
|
43
|
-
_handlebars["default"].registerHelper('hasTextContents',
|
|
60
|
+
_handlebars["default"].registerHelper('hasTextContents', hasTextContents);
|
|
44
61
|
|
|
45
62
|
_handlebars["default"].registerHelper('lineHasContents', lineHasContents);
|
|
46
63
|
|
|
@@ -76,4 +93,6 @@ _handlebars["default"].registerHelper('evaluate', function (item, metadata) {
|
|
|
76
93
|
}
|
|
77
94
|
|
|
78
95
|
return item.evaluate(metadata);
|
|
79
|
-
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
_handlebars["default"].registerHelper('renderChord', _helpers.renderChord);
|