@tonaljs/core 4.6.5 → 4.6.10

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/dist/index.js CHANGED
@@ -1,381 +1,294 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Core = {}));
5
- }(this, (function (exports) { 'use strict';
6
-
7
- /**
8
- * Fill a string with a repeated character
9
- *
10
- * @param character
11
- * @param repetition
12
- */
13
- var fillStr = function (s, n) { return Array(Math.abs(n) + 1).join(s); };
14
- function deprecate(original, alternative, fn) {
15
- return function () {
16
- var args = [];
17
- for (var _i = 0; _i < arguments.length; _i++) {
18
- args[_i] = arguments[_i];
19
- }
20
- // tslint:disable-next-line
21
- console.warn(original + " is deprecated. Use " + alternative + ".");
22
- return fn.apply(this, args);
23
- };
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
25
19
 
26
- function isNamed(src) {
27
- return src !== null && typeof src === "object" && typeof src.name === "string"
28
- ? true
29
- : false;
30
- }
20
+ // index.ts
21
+ var core_exports = {};
22
+ __export(core_exports, {
23
+ accToAlt: () => accToAlt,
24
+ altToAcc: () => altToAcc,
25
+ coordToInterval: () => coordToInterval,
26
+ coordToNote: () => coordToNote,
27
+ decode: () => decode,
28
+ deprecate: () => deprecate,
29
+ distance: () => distance,
30
+ encode: () => encode,
31
+ fillStr: () => fillStr,
32
+ interval: () => interval,
33
+ isNamed: () => isNamed,
34
+ isPitch: () => isPitch,
35
+ note: () => note,
36
+ stepToLetter: () => stepToLetter,
37
+ tokenizeInterval: () => tokenizeInterval,
38
+ tokenizeNote: () => tokenizeNote,
39
+ transpose: () => transpose
40
+ });
41
+ module.exports = __toCommonJS(core_exports);
31
42
 
32
- function isPitch(pitch) {
33
- return pitch !== null &&
34
- typeof pitch === "object" &&
35
- typeof pitch.step === "number" &&
36
- typeof pitch.alt === "number"
37
- ? true
38
- : false;
39
- }
40
- // The number of fifths of [C, D, E, F, G, A, B]
41
- var FIFTHS = [0, 2, 4, -1, 1, 3, 5];
42
- // The number of octaves it span each step
43
- var STEPS_TO_OCTS = FIFTHS.map(function (fifths) {
44
- return Math.floor((fifths * 7) / 12);
45
- });
46
- function encode(pitch) {
47
- var step = pitch.step, alt = pitch.alt, oct = pitch.oct, _a = pitch.dir, dir = _a === void 0 ? 1 : _a;
48
- var f = FIFTHS[step] + 7 * alt;
49
- if (oct === undefined) {
50
- return [dir * f];
51
- }
52
- var o = oct - STEPS_TO_OCTS[step] - 4 * alt;
53
- return [dir * f, dir * o];
54
- }
55
- // We need to get the steps from fifths
56
- // Fifths for CDEFGAB are [ 0, 2, 4, -1, 1, 3, 5 ]
57
- // We add 1 to fifths to avoid negative numbers, so:
58
- // for ["F", "C", "G", "D", "A", "E", "B"] we have:
59
- var FIFTHS_TO_STEPS = [3, 0, 4, 1, 5, 2, 6];
60
- function decode(coord) {
61
- var f = coord[0], o = coord[1], dir = coord[2];
62
- var step = FIFTHS_TO_STEPS[unaltered(f)];
63
- var alt = Math.floor((f + 1) / 7);
64
- if (o === undefined) {
65
- return { step: step, alt: alt, dir: dir };
66
- }
67
- var oct = o + 4 * alt + STEPS_TO_OCTS[step];
68
- return { step: step, alt: alt, oct: oct, dir: dir };
69
- }
70
- // Return the number of fifths as if it were unaltered
71
- function unaltered(f) {
72
- var i = (f + 1) % 7;
73
- return i < 0 ? 7 + i : i;
74
- }
43
+ // src/utils.ts
44
+ var fillStr = (s, n) => Array(Math.abs(n) + 1).join(s);
45
+ function deprecate(original, alternative, fn) {
46
+ return function(...args) {
47
+ console.warn(`${original} is deprecated. Use ${alternative}.`);
48
+ return fn.apply(this, args);
49
+ };
50
+ }
75
51
 
76
- var NoNote = { empty: true, name: "", pc: "", acc: "" };
77
- var cache$1 = new Map();
78
- var stepToLetter = function (step) { return "CDEFGAB".charAt(step); };
79
- var altToAcc = function (alt) {
80
- return alt < 0 ? fillStr("b", -alt) : fillStr("#", alt);
81
- };
82
- var accToAlt = function (acc) {
83
- return acc[0] === "b" ? -acc.length : acc.length;
84
- };
85
- /**
86
- * Given a note literal (a note name or a note object), returns the Note object
87
- * @example
88
- * note('Bb4') // => { name: "Bb4", midi: 70, chroma: 10, ... }
89
- */
90
- function note(src) {
91
- var cached = cache$1.get(src);
92
- if (cached) {
93
- return cached;
94
- }
95
- var value = typeof src === "string"
96
- ? parse$1(src)
97
- : isPitch(src)
98
- ? note(pitchName$1(src))
99
- : isNamed(src)
100
- ? note(src.name)
101
- : NoNote;
102
- cache$1.set(src, value);
103
- return value;
104
- }
105
- var REGEX$1 = /^([a-gA-G]?)(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)$/;
106
- /**
107
- * @private
108
- */
109
- function tokenizeNote(str) {
110
- var m = REGEX$1.exec(str);
111
- return [m[1].toUpperCase(), m[2].replace(/x/g, "##"), m[3], m[4]];
112
- }
113
- /**
114
- * @private
115
- */
116
- function coordToNote(noteCoord) {
117
- return note(decode(noteCoord));
118
- }
119
- var mod = function (n, m) { return ((n % m) + m) % m; };
120
- var SEMI = [0, 2, 4, 5, 7, 9, 11];
121
- function parse$1(noteName) {
122
- var tokens = tokenizeNote(noteName);
123
- if (tokens[0] === "" || tokens[3] !== "") {
124
- return NoNote;
125
- }
126
- var letter = tokens[0];
127
- var acc = tokens[1];
128
- var octStr = tokens[2];
129
- var step = (letter.charCodeAt(0) + 3) % 7;
130
- var alt = accToAlt(acc);
131
- var oct = octStr.length ? +octStr : undefined;
132
- var coord = encode({ step: step, alt: alt, oct: oct });
133
- var name = letter + acc + octStr;
134
- var pc = letter + acc;
135
- var chroma = (SEMI[step] + alt + 120) % 12;
136
- var height = oct === undefined
137
- ? mod(SEMI[step] + alt, 12) - 12 * 99
138
- : SEMI[step] + alt + 12 * (oct + 1);
139
- var midi = height >= 0 && height <= 127 ? height : null;
140
- var freq = oct === undefined ? null : Math.pow(2, (height - 69) / 12) * 440;
141
- return {
142
- empty: false,
143
- acc: acc,
144
- alt: alt,
145
- chroma: chroma,
146
- coord: coord,
147
- freq: freq,
148
- height: height,
149
- letter: letter,
150
- midi: midi,
151
- name: name,
152
- oct: oct,
153
- pc: pc,
154
- step: step,
155
- };
156
- }
157
- function pitchName$1(props) {
158
- var step = props.step, alt = props.alt, oct = props.oct;
159
- var letter = stepToLetter(step);
160
- if (!letter) {
161
- return "";
162
- }
163
- var pc = letter + altToAcc(alt);
164
- return oct || oct === 0 ? pc + oct : pc;
165
- }
52
+ // src/named.ts
53
+ function isNamed(src) {
54
+ return src !== null && typeof src === "object" && typeof src.name === "string" ? true : false;
55
+ }
166
56
 
167
- var NoInterval = { empty: true, name: "", acc: "" };
168
- // shorthand tonal notation (with quality after number)
169
- var INTERVAL_TONAL_REGEX = "([-+]?\\d+)(d{1,4}|m|M|P|A{1,4})";
170
- // standard shorthand notation (with quality before number)
171
- var INTERVAL_SHORTHAND_REGEX = "(AA|A|P|M|m|d|dd)([-+]?\\d+)";
172
- var REGEX = new RegExp("^" + INTERVAL_TONAL_REGEX + "|" + INTERVAL_SHORTHAND_REGEX + "$");
173
- /**
174
- * @private
175
- */
176
- function tokenizeInterval(str) {
177
- var m = REGEX.exec("" + str);
178
- if (m === null) {
179
- return ["", ""];
180
- }
181
- return m[1] ? [m[1], m[2]] : [m[4], m[3]];
182
- }
183
- var cache = {};
184
- /**
185
- * Get interval properties. It returns an object with:
186
- *
187
- * - name: the interval name
188
- * - num: the interval number
189
- * - type: 'perfectable' or 'majorable'
190
- * - q: the interval quality (d, m, M, A)
191
- * - dir: interval direction (1 ascending, -1 descending)
192
- * - simple: the simplified number
193
- * - semitones: the size in semitones
194
- * - chroma: the interval chroma
195
- *
196
- * @param {string} interval - the interval name
197
- * @return {Object} the interval properties
198
- *
199
- * @example
200
- * import { interval } from '@tonaljs/core'
201
- * interval('P5').semitones // => 7
202
- * interval('m3').type // => 'majorable'
203
- */
204
- function interval(src) {
205
- return typeof src === "string"
206
- ? cache[src] || (cache[src] = parse(src))
207
- : isPitch(src)
208
- ? interval(pitchName(src))
209
- : isNamed(src)
210
- ? interval(src.name)
211
- : NoInterval;
212
- }
213
- var SIZES = [0, 2, 4, 5, 7, 9, 11];
214
- var TYPES = "PMMPPMM";
215
- function parse(str) {
216
- var tokens = tokenizeInterval(str);
217
- if (tokens[0] === "") {
218
- return NoInterval;
219
- }
220
- var num = +tokens[0];
221
- var q = tokens[1];
222
- var step = (Math.abs(num) - 1) % 7;
223
- var t = TYPES[step];
224
- if (t === "M" && q === "P") {
225
- return NoInterval;
226
- }
227
- var type = t === "M" ? "majorable" : "perfectable";
228
- var name = "" + num + q;
229
- var dir = num < 0 ? -1 : 1;
230
- var simple = num === 8 || num === -8 ? num : dir * (step + 1);
231
- var alt = qToAlt(type, q);
232
- var oct = Math.floor((Math.abs(num) - 1) / 7);
233
- var semitones = dir * (SIZES[step] + alt + 12 * oct);
234
- var chroma = (((dir * (SIZES[step] + alt)) % 12) + 12) % 12;
235
- var coord = encode({ step: step, alt: alt, oct: oct, dir: dir });
236
- return {
237
- empty: false,
238
- name: name,
239
- num: num,
240
- q: q,
241
- step: step,
242
- alt: alt,
243
- dir: dir,
244
- type: type,
245
- simple: simple,
246
- semitones: semitones,
247
- chroma: chroma,
248
- coord: coord,
249
- oct: oct,
250
- };
251
- }
252
- /**
253
- * @private
254
- *
255
- * forceDescending is used in the case of unison (#243)
256
- */
257
- function coordToInterval(coord, forceDescending) {
258
- var f = coord[0], _a = coord[1], o = _a === void 0 ? 0 : _a;
259
- var isDescending = f * 7 + o * 12 < 0;
260
- var ivl = forceDescending || isDescending ? [-f, -o, -1] : [f, o, 1];
261
- return interval(decode(ivl));
262
- }
263
- function qToAlt(type, q) {
264
- return (q === "M" && type === "majorable") ||
265
- (q === "P" && type === "perfectable")
266
- ? 0
267
- : q === "m" && type === "majorable"
268
- ? -1
269
- : /^A+$/.test(q)
270
- ? q.length
271
- : /^d+$/.test(q)
272
- ? -1 * (type === "perfectable" ? q.length : q.length + 1)
273
- : 0;
274
- }
275
- // return the interval name of a pitch
276
- function pitchName(props) {
277
- var step = props.step, alt = props.alt, _a = props.oct, oct = _a === void 0 ? 0 : _a, dir = props.dir;
278
- if (!dir) {
279
- return "";
280
- }
281
- var calcNum = step + 1 + 7 * oct;
282
- // this is an edge case: descending pitch class unison (see #243)
283
- var num = calcNum === 0 ? step + 1 : calcNum;
284
- var d = dir < 0 ? "-" : "";
285
- var type = TYPES[step] === "M" ? "majorable" : "perfectable";
286
- var name = d + num + altToQ(type, alt);
287
- return name;
288
- }
289
- function altToQ(type, alt) {
290
- if (alt === 0) {
291
- return type === "majorable" ? "M" : "P";
292
- }
293
- else if (alt === -1 && type === "majorable") {
294
- return "m";
295
- }
296
- else if (alt > 0) {
297
- return fillStr("A", alt);
298
- }
299
- else {
300
- return fillStr("d", type === "perfectable" ? alt : alt + 1);
301
- }
57
+ // src/pitch.ts
58
+ function isPitch(pitch) {
59
+ return pitch !== null && typeof pitch === "object" && typeof pitch.step === "number" && typeof pitch.alt === "number" ? true : false;
60
+ }
61
+ var FIFTHS = [0, 2, 4, -1, 1, 3, 5];
62
+ var STEPS_TO_OCTS = FIFTHS.map(
63
+ (fifths) => Math.floor(fifths * 7 / 12)
64
+ );
65
+ function encode(pitch) {
66
+ const { step, alt, oct, dir = 1 } = pitch;
67
+ const f = FIFTHS[step] + 7 * alt;
68
+ if (oct === void 0) {
69
+ return [dir * f];
302
70
  }
303
-
304
- /**
305
- * Transpose a note by an interval.
306
- *
307
- * @param {string} note - the note or note name
308
- * @param {string} interval - the interval or interval name
309
- * @return {string} the transposed note name or empty string if not valid notes
310
- * @example
311
- * import { tranpose } from "@tonaljs/core"
312
- * transpose("d3", "3M") // => "F#3"
313
- * transpose("D", "3M") // => "F#"
314
- * ["C", "D", "E", "F", "G"].map(pc => transpose(pc, "M3)) // => ["E", "F#", "G#", "A", "B"]
315
- */
316
- function transpose(noteName, intervalName) {
317
- var note$1 = note(noteName);
318
- var interval$1 = interval(intervalName);
319
- if (note$1.empty || interval$1.empty) {
320
- return "";
321
- }
322
- var noteCoord = note$1.coord;
323
- var intervalCoord = interval$1.coord;
324
- var tr = noteCoord.length === 1
325
- ? [noteCoord[0] + intervalCoord[0]]
326
- : [noteCoord[0] + intervalCoord[0], noteCoord[1] + intervalCoord[1]];
327
- return coordToNote(tr).name;
328
- }
329
- /**
330
- * Find the interval distance between two notes or coord classes.
331
- *
332
- * To find distance between coord classes, both notes must be coord classes and
333
- * the interval is always ascending
334
- *
335
- * @param {Note|string} from - the note or note name to calculate distance from
336
- * @param {Note|string} to - the note or note name to calculate distance to
337
- * @return {string} the interval name or empty string if not valid notes
338
- *
339
- */
340
- function distance(fromNote, toNote) {
341
- var from = note(fromNote);
342
- var to = note(toNote);
343
- if (from.empty || to.empty) {
344
- return "";
345
- }
346
- var fcoord = from.coord;
347
- var tcoord = to.coord;
348
- var fifths = tcoord[0] - fcoord[0];
349
- var octs = fcoord.length === 2 && tcoord.length === 2
350
- ? tcoord[1] - fcoord[1]
351
- : -Math.floor((fifths * 7) / 12);
352
- // If it's unison and not pitch class, it can be descending interval (#243)
353
- var forceDescending = to.height === from.height &&
354
- to.midi !== null &&
355
- from.midi !== null &&
356
- from.step > to.step;
357
- return coordToInterval([fifths, octs], forceDescending).name;
71
+ const o = oct - STEPS_TO_OCTS[step] - 4 * alt;
72
+ return [dir * f, dir * o];
73
+ }
74
+ var FIFTHS_TO_STEPS = [3, 0, 4, 1, 5, 2, 6];
75
+ function decode(coord) {
76
+ const [f, o, dir] = coord;
77
+ const step = FIFTHS_TO_STEPS[unaltered(f)];
78
+ const alt = Math.floor((f + 1) / 7);
79
+ if (o === void 0) {
80
+ return { step, alt, dir };
358
81
  }
82
+ const oct = o + 4 * alt + STEPS_TO_OCTS[step];
83
+ return { step, alt, oct, dir };
84
+ }
85
+ function unaltered(f) {
86
+ const i = (f + 1) % 7;
87
+ return i < 0 ? 7 + i : i;
88
+ }
359
89
 
360
- exports.accToAlt = accToAlt;
361
- exports.altToAcc = altToAcc;
362
- exports.coordToInterval = coordToInterval;
363
- exports.coordToNote = coordToNote;
364
- exports.decode = decode;
365
- exports.deprecate = deprecate;
366
- exports.distance = distance;
367
- exports.encode = encode;
368
- exports.fillStr = fillStr;
369
- exports.interval = interval;
370
- exports.isNamed = isNamed;
371
- exports.isPitch = isPitch;
372
- exports.note = note;
373
- exports.stepToLetter = stepToLetter;
374
- exports.tokenizeInterval = tokenizeInterval;
375
- exports.tokenizeNote = tokenizeNote;
376
- exports.transpose = transpose;
90
+ // src/note.ts
91
+ var NoNote = { empty: true, name: "", pc: "", acc: "" };
92
+ var cache = /* @__PURE__ */ new Map();
93
+ var stepToLetter = (step) => "CDEFGAB".charAt(step);
94
+ var altToAcc = (alt) => alt < 0 ? fillStr("b", -alt) : fillStr("#", alt);
95
+ var accToAlt = (acc) => acc[0] === "b" ? -acc.length : acc.length;
96
+ function note(src) {
97
+ const cached = cache.get(src);
98
+ if (cached) {
99
+ return cached;
100
+ }
101
+ const value = typeof src === "string" ? parse(src) : isPitch(src) ? note(pitchName(src)) : isNamed(src) ? note(src.name) : NoNote;
102
+ cache.set(src, value);
103
+ return value;
104
+ }
105
+ var REGEX = /^([a-gA-G]?)(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)$/;
106
+ function tokenizeNote(str) {
107
+ const m = REGEX.exec(str);
108
+ return [m[1].toUpperCase(), m[2].replace(/x/g, "##"), m[3], m[4]];
109
+ }
110
+ function coordToNote(noteCoord) {
111
+ return note(decode(noteCoord));
112
+ }
113
+ var mod = (n, m) => (n % m + m) % m;
114
+ var SEMI = [0, 2, 4, 5, 7, 9, 11];
115
+ function parse(noteName) {
116
+ const tokens = tokenizeNote(noteName);
117
+ if (tokens[0] === "" || tokens[3] !== "") {
118
+ return NoNote;
119
+ }
120
+ const letter = tokens[0];
121
+ const acc = tokens[1];
122
+ const octStr = tokens[2];
123
+ const step = (letter.charCodeAt(0) + 3) % 7;
124
+ const alt = accToAlt(acc);
125
+ const oct = octStr.length ? +octStr : void 0;
126
+ const coord = encode({ step, alt, oct });
127
+ const name = letter + acc + octStr;
128
+ const pc = letter + acc;
129
+ const chroma = (SEMI[step] + alt + 120) % 12;
130
+ const height = oct === void 0 ? mod(SEMI[step] + alt, 12) - 12 * 99 : SEMI[step] + alt + 12 * (oct + 1);
131
+ const midi = height >= 0 && height <= 127 ? height : null;
132
+ const freq = oct === void 0 ? null : Math.pow(2, (height - 69) / 12) * 440;
133
+ return {
134
+ empty: false,
135
+ acc,
136
+ alt,
137
+ chroma,
138
+ coord,
139
+ freq,
140
+ height,
141
+ letter,
142
+ midi,
143
+ name,
144
+ oct,
145
+ pc,
146
+ step
147
+ };
148
+ }
149
+ function pitchName(props) {
150
+ const { step, alt, oct } = props;
151
+ const letter = stepToLetter(step);
152
+ if (!letter) {
153
+ return "";
154
+ }
155
+ const pc = letter + altToAcc(alt);
156
+ return oct || oct === 0 ? pc + oct : pc;
157
+ }
377
158
 
378
- Object.defineProperty(exports, '__esModule', { value: true });
159
+ // src/interval.ts
160
+ var NoInterval = { empty: true, name: "", acc: "" };
161
+ var INTERVAL_TONAL_REGEX = "([-+]?\\d+)(d{1,4}|m|M|P|A{1,4})";
162
+ var INTERVAL_SHORTHAND_REGEX = "(AA|A|P|M|m|d|dd)([-+]?\\d+)";
163
+ var REGEX2 = new RegExp(
164
+ "^" + INTERVAL_TONAL_REGEX + "|" + INTERVAL_SHORTHAND_REGEX + "$"
165
+ );
166
+ function tokenizeInterval(str) {
167
+ const m = REGEX2.exec(`${str}`);
168
+ if (m === null) {
169
+ return ["", ""];
170
+ }
171
+ return m[1] ? [m[1], m[2]] : [m[4], m[3]];
172
+ }
173
+ var cache2 = {};
174
+ function interval(src) {
175
+ return typeof src === "string" ? cache2[src] || (cache2[src] = parse2(src)) : isPitch(src) ? interval(pitchName2(src)) : isNamed(src) ? interval(src.name) : NoInterval;
176
+ }
177
+ var SIZES = [0, 2, 4, 5, 7, 9, 11];
178
+ var TYPES = "PMMPPMM";
179
+ function parse2(str) {
180
+ const tokens = tokenizeInterval(str);
181
+ if (tokens[0] === "") {
182
+ return NoInterval;
183
+ }
184
+ const num = +tokens[0];
185
+ const q = tokens[1];
186
+ const step = (Math.abs(num) - 1) % 7;
187
+ const t = TYPES[step];
188
+ if (t === "M" && q === "P") {
189
+ return NoInterval;
190
+ }
191
+ const type = t === "M" ? "majorable" : "perfectable";
192
+ const name = "" + num + q;
193
+ const dir = num < 0 ? -1 : 1;
194
+ const simple = num === 8 || num === -8 ? num : dir * (step + 1);
195
+ const alt = qToAlt(type, q);
196
+ const oct = Math.floor((Math.abs(num) - 1) / 7);
197
+ const semitones = dir * (SIZES[step] + alt + 12 * oct);
198
+ const chroma = (dir * (SIZES[step] + alt) % 12 + 12) % 12;
199
+ const coord = encode({ step, alt, oct, dir });
200
+ return {
201
+ empty: false,
202
+ name,
203
+ num,
204
+ q,
205
+ step,
206
+ alt,
207
+ dir,
208
+ type,
209
+ simple,
210
+ semitones,
211
+ chroma,
212
+ coord,
213
+ oct
214
+ };
215
+ }
216
+ function coordToInterval(coord, forceDescending) {
217
+ const [f, o = 0] = coord;
218
+ const isDescending = f * 7 + o * 12 < 0;
219
+ const ivl = forceDescending || isDescending ? [-f, -o, -1] : [f, o, 1];
220
+ return interval(decode(ivl));
221
+ }
222
+ function qToAlt(type, q) {
223
+ return q === "M" && type === "majorable" || q === "P" && type === "perfectable" ? 0 : q === "m" && type === "majorable" ? -1 : /^A+$/.test(q) ? q.length : /^d+$/.test(q) ? -1 * (type === "perfectable" ? q.length : q.length + 1) : 0;
224
+ }
225
+ function pitchName2(props) {
226
+ const { step, alt, oct = 0, dir } = props;
227
+ if (!dir) {
228
+ return "";
229
+ }
230
+ const calcNum = step + 1 + 7 * oct;
231
+ const num = calcNum === 0 ? step + 1 : calcNum;
232
+ const d = dir < 0 ? "-" : "";
233
+ const type = TYPES[step] === "M" ? "majorable" : "perfectable";
234
+ const name = d + num + altToQ(type, alt);
235
+ return name;
236
+ }
237
+ function altToQ(type, alt) {
238
+ if (alt === 0) {
239
+ return type === "majorable" ? "M" : "P";
240
+ } else if (alt === -1 && type === "majorable") {
241
+ return "m";
242
+ } else if (alt > 0) {
243
+ return fillStr("A", alt);
244
+ } else {
245
+ return fillStr("d", type === "perfectable" ? alt : alt + 1);
246
+ }
247
+ }
379
248
 
380
- })));
381
- //# sourceMappingURL=index.js.map
249
+ // src/distance.ts
250
+ function transpose(noteName, intervalName) {
251
+ const note2 = note(noteName);
252
+ const interval2 = interval(intervalName);
253
+ if (note2.empty || interval2.empty) {
254
+ return "";
255
+ }
256
+ const noteCoord = note2.coord;
257
+ const intervalCoord = interval2.coord;
258
+ const tr = noteCoord.length === 1 ? [noteCoord[0] + intervalCoord[0]] : [noteCoord[0] + intervalCoord[0], noteCoord[1] + intervalCoord[1]];
259
+ return coordToNote(tr).name;
260
+ }
261
+ function distance(fromNote, toNote) {
262
+ const from = note(fromNote);
263
+ const to = note(toNote);
264
+ if (from.empty || to.empty) {
265
+ return "";
266
+ }
267
+ const fcoord = from.coord;
268
+ const tcoord = to.coord;
269
+ const fifths = tcoord[0] - fcoord[0];
270
+ const octs = fcoord.length === 2 && tcoord.length === 2 ? tcoord[1] - fcoord[1] : -Math.floor(fifths * 7 / 12);
271
+ const forceDescending = to.height === from.height && to.midi !== null && from.midi !== null && from.step > to.step;
272
+ return coordToInterval([fifths, octs], forceDescending).name;
273
+ }
274
+ // Annotate the CommonJS export names for ESM import in node:
275
+ 0 && (module.exports = {
276
+ accToAlt,
277
+ altToAcc,
278
+ coordToInterval,
279
+ coordToNote,
280
+ decode,
281
+ deprecate,
282
+ distance,
283
+ encode,
284
+ fillStr,
285
+ interval,
286
+ isNamed,
287
+ isPitch,
288
+ note,
289
+ stepToLetter,
290
+ tokenizeInterval,
291
+ tokenizeNote,
292
+ transpose
293
+ });
294
+ //# sourceMappingURL=index.js.map