@tonaljs/core 4.10.0 → 4.10.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 CHANGED
@@ -114,7 +114,7 @@ Examples:
114
114
  ```js
115
115
  transpose("d3", "3M"); // => "F#3"
116
116
  transpose("D", "3M"); // => "F#"
117
- ["C", "D", "E", "F", "G"].map(pc => transpose(pc, "M3"));
117
+ ["C", "D", "E", "F", "G"].map((pc) => transpose(pc, "M3"));
118
118
  // => ["E", "F#", "G#", "A", "B"]
119
119
  ```
120
120
 
@@ -0,0 +1,10 @@
1
+ export * from '@tonaljs/pitch';
2
+ export * from '@tonaljs/pitch-distance';
3
+ export * from '@tonaljs/pitch-interval';
4
+ export * from '@tonaljs/pitch-note';
5
+
6
+ declare const fillStr: (s: string, n: number) => string;
7
+ declare function deprecate<ResultFn extends (this: any, ...newArgs: any[]) => ReturnType<ResultFn>>(original: string, alternative: string, fn: ResultFn): (this: unknown, ...args: unknown[]) => ReturnType<ResultFn>;
8
+ declare const isNamed: (this: unknown, ...args: unknown[]) => boolean;
9
+
10
+ export { deprecate, fillStr, isNamed };
package/dist/index.d.ts CHANGED
@@ -1,172 +1,10 @@
1
- /**
2
- * Fill a string with a repeated character
3
- *
4
- * @param character
5
- * @param repetition
6
- */
1
+ export * from '@tonaljs/pitch';
2
+ export * from '@tonaljs/pitch-distance';
3
+ export * from '@tonaljs/pitch-interval';
4
+ export * from '@tonaljs/pitch-note';
5
+
7
6
  declare const fillStr: (s: string, n: number) => string;
8
7
  declare function deprecate<ResultFn extends (this: any, ...newArgs: any[]) => ReturnType<ResultFn>>(original: string, alternative: string, fn: ResultFn): (this: unknown, ...args: unknown[]) => ReturnType<ResultFn>;
8
+ declare const isNamed: (this: unknown, ...args: unknown[]) => boolean;
9
9
 
10
- interface Named {
11
- readonly name: string;
12
- }
13
- interface NamedFound {
14
- readonly empty: false;
15
- }
16
- interface NotFound extends Named {
17
- readonly empty: true;
18
- readonly name: "";
19
- }
20
- declare function isNamed(src: any): src is Named;
21
-
22
- type Fifths = number;
23
- type Octaves = number;
24
- type Direction = 1 | -1;
25
- type PitchClassCoordinates = [Fifths];
26
- type NoteCoordinates = [Fifths, Octaves];
27
- type IntervalCoordinates = [Fifths, Octaves, Direction];
28
- type PitchCoordinates = PitchClassCoordinates | NoteCoordinates | IntervalCoordinates;
29
- /**
30
- * Pitch properties
31
- *
32
- * - {number} step - The step number: 0 = C, 1 = D, ... 6 = B
33
- * - {number} alt - Number of alterations: -2 = 'bb', -1 = 'b', 0 = '', 1 = '#', ...
34
- * - {number} [oct] = The octave (undefined when is a coord class)
35
- * - {number} [dir] = Interval direction (undefined when is not an interval)
36
- */
37
- interface Pitch {
38
- readonly step: number;
39
- readonly alt: number;
40
- readonly oct?: number;
41
- readonly dir?: Direction;
42
- }
43
- declare function isPitch(pitch: any): pitch is Pitch;
44
- declare function encode(pitch: Pitch): PitchCoordinates;
45
- declare function decode(coord: PitchCoordinates): Pitch;
46
-
47
- type NoteWithOctave = string;
48
- type PcName = string;
49
- type NoteName = NoteWithOctave | PcName;
50
- type NoteLiteral = NoteName | Pitch | Named;
51
- interface Note extends Pitch, Named {
52
- readonly empty: boolean;
53
- readonly name: NoteName;
54
- readonly letter: string;
55
- readonly acc: string;
56
- readonly pc: PcName;
57
- readonly chroma: number;
58
- readonly height: number;
59
- readonly coord: PitchCoordinates;
60
- readonly midi: number | null;
61
- readonly freq: number | null;
62
- }
63
- interface NoNote extends Partial<Note> {
64
- empty: true;
65
- name: "";
66
- pc: "";
67
- acc: "";
68
- }
69
- declare const stepToLetter: (step: number) => string;
70
- declare const altToAcc: (alt: number) => string;
71
- declare const accToAlt: (acc: string) => number;
72
- /**
73
- * Given a note literal (a note name or a note object), returns the Note object
74
- * @example
75
- * note('Bb4') // => { name: "Bb4", midi: 70, chroma: 10, ... }
76
- */
77
- declare function note(src: NoteLiteral): Note | NoNote;
78
- type NoteTokens = [string, string, string, string];
79
- /**
80
- * @private
81
- */
82
- declare function tokenizeNote(str: string): NoteTokens;
83
- /**
84
- * @private
85
- */
86
- declare function coordToNote(noteCoord: PitchCoordinates): Note;
87
-
88
- type IntervalName = string;
89
- type IntervalLiteral = IntervalName | Pitch | Named;
90
- type Quality = "dddd" | "ddd" | "dd" | "d" | "m" | "M" | "P" | "A" | "AA" | "AAA" | "AAAA";
91
- type Type = "perfectable" | "majorable";
92
- interface Interval extends Pitch, Named {
93
- readonly empty: boolean;
94
- readonly name: IntervalName;
95
- readonly num: number;
96
- readonly q: Quality;
97
- readonly type: Type;
98
- readonly step: number;
99
- readonly alt: number;
100
- readonly dir: Direction;
101
- readonly simple: number;
102
- readonly semitones: number;
103
- readonly chroma: number;
104
- readonly coord: IntervalCoordinates;
105
- readonly oct: number;
106
- }
107
- interface NoInterval extends Partial<Interval> {
108
- readonly empty: true;
109
- readonly name: "";
110
- readonly acc: "";
111
- }
112
- type IntervalTokens = [string, string];
113
- /**
114
- * @private
115
- */
116
- declare function tokenizeInterval(str?: IntervalName): IntervalTokens;
117
- /**
118
- * Get interval properties. It returns an object with:
119
- *
120
- * - name: the interval name
121
- * - num: the interval number
122
- * - type: 'perfectable' or 'majorable'
123
- * - q: the interval quality (d, m, M, A)
124
- * - dir: interval direction (1 ascending, -1 descending)
125
- * - simple: the simplified number
126
- * - semitones: the size in semitones
127
- * - chroma: the interval chroma
128
- *
129
- * @param {string} interval - the interval name
130
- * @return {Object} the interval properties
131
- *
132
- * @example
133
- * import { interval } from '@tonaljs/core'
134
- * interval('P5').semitones // => 7
135
- * interval('m3').type // => 'majorable'
136
- */
137
- declare function interval(src: IntervalLiteral): Interval | NoInterval;
138
- /**
139
- * @private
140
- *
141
- * forceDescending is used in the case of unison (#243)
142
- */
143
- declare function coordToInterval(coord: PitchCoordinates, forceDescending?: boolean): Interval;
144
-
145
- /**
146
- * Transpose a note by an interval.
147
- *
148
- * @param {string} note - the note or note name
149
- * @param {string} interval - the interval or interval name
150
- * @return {string} the transposed note name or empty string if not valid notes
151
- * @example
152
- * import { tranpose } from "@tonaljs/core"
153
- * transpose("d3", "3M") // => "F#3"
154
- * transpose("D", "3M") // => "F#"
155
- * ["C", "D", "E", "F", "G"].map(pc => transpose(pc, "M3)) // => ["E", "F#", "G#", "A", "B"]
156
- */
157
- declare function transpose(noteName: NoteLiteral, intervalName: IntervalLiteral | [number, number]): NoteName;
158
- declare function tonicIntervalsTransposer(intervals: string[], tonic: string | undefined | null): (normalized: number) => string;
159
- /**
160
- * Find the interval distance between two notes or coord classes.
161
- *
162
- * To find distance between coord classes, both notes must be coord classes and
163
- * the interval is always ascending
164
- *
165
- * @param {Note|string} from - the note or note name to calculate distance from
166
- * @param {Note|string} to - the note or note name to calculate distance to
167
- * @return {string} the interval name or empty string if not valid notes
168
- *
169
- */
170
- declare function distance(fromNote: NoteLiteral, toNote: NoteLiteral): IntervalName;
171
-
172
- export { Direction, Interval, IntervalCoordinates, IntervalLiteral, IntervalName, Named, NamedFound, NoInterval, NoNote, NotFound, Note, NoteCoordinates, NoteLiteral, NoteName, NoteWithOctave, PcName, Pitch, PitchClassCoordinates, PitchCoordinates, accToAlt, altToAcc, coordToInterval, coordToNote, decode, deprecate, distance, encode, fillStr, interval, isNamed, isPitch, note, stepToLetter, tokenizeInterval, tokenizeNote, tonicIntervalsTransposer, transpose };
10
+ export { deprecate, fillStr, isNamed };
package/dist/index.js CHANGED
@@ -15,33 +15,22 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
- var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
20
 
20
21
  // index.ts
21
22
  var core_exports = {};
22
23
  __export(core_exports, {
23
- accToAlt: () => accToAlt,
24
- altToAcc: () => altToAcc,
25
- coordToInterval: () => coordToInterval,
26
- coordToNote: () => coordToNote,
27
- decode: () => decode,
28
24
  deprecate: () => deprecate,
29
- distance: () => distance,
30
- encode: () => encode,
31
25
  fillStr: () => fillStr,
32
- interval: () => interval,
33
- isNamed: () => isNamed,
34
- isPitch: () => isPitch,
35
- note: () => note,
36
- stepToLetter: () => stepToLetter,
37
- tokenizeInterval: () => tokenizeInterval,
38
- tokenizeNote: () => tokenizeNote,
39
- tonicIntervalsTransposer: () => tonicIntervalsTransposer,
40
- transpose: () => transpose
26
+ isNamed: () => isNamed
41
27
  });
42
28
  module.exports = __toCommonJS(core_exports);
43
-
44
- // src/utils.ts
29
+ var import_pitch = require("@tonaljs/pitch");
30
+ __reExport(core_exports, require("@tonaljs/pitch"), module.exports);
31
+ __reExport(core_exports, require("@tonaljs/pitch-distance"), module.exports);
32
+ __reExport(core_exports, require("@tonaljs/pitch-interval"), module.exports);
33
+ __reExport(core_exports, require("@tonaljs/pitch-note"), module.exports);
45
34
  var fillStr = (s, n) => Array(Math.abs(n) + 1).join(s);
46
35
  function deprecate(original, alternative, fn) {
47
36
  return function(...args) {
@@ -49,259 +38,15 @@ function deprecate(original, alternative, fn) {
49
38
  return fn.apply(this, args);
50
39
  };
51
40
  }
52
-
53
- // src/named.ts
54
- function isNamed(src) {
55
- return src !== null && typeof src === "object" && typeof src.name === "string" ? true : false;
56
- }
57
-
58
- // src/pitch.ts
59
- function isPitch(pitch) {
60
- return pitch !== null && typeof pitch === "object" && typeof pitch.step === "number" && typeof pitch.alt === "number" ? true : false;
61
- }
62
- var FIFTHS = [0, 2, 4, -1, 1, 3, 5];
63
- var STEPS_TO_OCTS = FIFTHS.map(
64
- (fifths) => Math.floor(fifths * 7 / 12)
65
- );
66
- function encode(pitch) {
67
- const { step, alt, oct, dir = 1 } = pitch;
68
- const f = FIFTHS[step] + 7 * alt;
69
- if (oct === void 0) {
70
- return [dir * f];
71
- }
72
- const o = oct - STEPS_TO_OCTS[step] - 4 * alt;
73
- return [dir * f, dir * o];
74
- }
75
- var FIFTHS_TO_STEPS = [3, 0, 4, 1, 5, 2, 6];
76
- function decode(coord) {
77
- const [f, o, dir] = coord;
78
- const step = FIFTHS_TO_STEPS[unaltered(f)];
79
- const alt = Math.floor((f + 1) / 7);
80
- if (o === void 0) {
81
- return { step, alt, dir };
82
- }
83
- const oct = o + 4 * alt + STEPS_TO_OCTS[step];
84
- return { step, alt, oct, dir };
85
- }
86
- function unaltered(f) {
87
- const i = (f + 1) % 7;
88
- return i < 0 ? 7 + i : i;
89
- }
90
-
91
- // src/note.ts
92
- var NoNote = { empty: true, name: "", pc: "", acc: "" };
93
- var cache = /* @__PURE__ */ new Map();
94
- var stepToLetter = (step) => "CDEFGAB".charAt(step);
95
- var altToAcc = (alt) => alt < 0 ? fillStr("b", -alt) : fillStr("#", alt);
96
- var accToAlt = (acc) => acc[0] === "b" ? -acc.length : acc.length;
97
- function note(src) {
98
- const stringSrc = JSON.stringify(src);
99
- const cached = cache.get(stringSrc);
100
- if (cached) {
101
- return cached;
102
- }
103
- const value = typeof src === "string" ? parse(src) : isPitch(src) ? note(pitchName(src)) : isNamed(src) ? note(src.name) : NoNote;
104
- cache.set(stringSrc, value);
105
- return value;
106
- }
107
- var REGEX = /^([a-gA-G]?)(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)$/;
108
- function tokenizeNote(str) {
109
- const m = REGEX.exec(str);
110
- return [m[1].toUpperCase(), m[2].replace(/x/g, "##"), m[3], m[4]];
111
- }
112
- function coordToNote(noteCoord) {
113
- return note(decode(noteCoord));
114
- }
115
- var mod = (n, m) => (n % m + m) % m;
116
- var SEMI = [0, 2, 4, 5, 7, 9, 11];
117
- function parse(noteName) {
118
- const tokens = tokenizeNote(noteName);
119
- if (tokens[0] === "" || tokens[3] !== "") {
120
- return NoNote;
121
- }
122
- const letter = tokens[0];
123
- const acc = tokens[1];
124
- const octStr = tokens[2];
125
- const step = (letter.charCodeAt(0) + 3) % 7;
126
- const alt = accToAlt(acc);
127
- const oct = octStr.length ? +octStr : void 0;
128
- const coord = encode({ step, alt, oct });
129
- const name = letter + acc + octStr;
130
- const pc = letter + acc;
131
- const chroma = (SEMI[step] + alt + 120) % 12;
132
- const height = oct === void 0 ? mod(SEMI[step] + alt, 12) - 12 * 99 : SEMI[step] + alt + 12 * (oct + 1);
133
- const midi = height >= 0 && height <= 127 ? height : null;
134
- const freq = oct === void 0 ? null : Math.pow(2, (height - 69) / 12) * 440;
135
- return {
136
- empty: false,
137
- acc,
138
- alt,
139
- chroma,
140
- coord,
141
- freq,
142
- height,
143
- letter,
144
- midi,
145
- name,
146
- oct,
147
- pc,
148
- step
149
- };
150
- }
151
- function pitchName(props) {
152
- const { step, alt, oct } = props;
153
- const letter = stepToLetter(step);
154
- if (!letter) {
155
- return "";
156
- }
157
- const pc = letter + altToAcc(alt);
158
- return oct || oct === 0 ? pc + oct : pc;
159
- }
160
-
161
- // src/interval.ts
162
- var NoInterval = { empty: true, name: "", acc: "" };
163
- var INTERVAL_TONAL_REGEX = "([-+]?\\d+)(d{1,4}|m|M|P|A{1,4})";
164
- var INTERVAL_SHORTHAND_REGEX = "(AA|A|P|M|m|d|dd)([-+]?\\d+)";
165
- var REGEX2 = new RegExp(
166
- "^" + INTERVAL_TONAL_REGEX + "|" + INTERVAL_SHORTHAND_REGEX + "$"
167
- );
168
- function tokenizeInterval(str) {
169
- const m = REGEX2.exec(`${str}`);
170
- if (m === null) {
171
- return ["", ""];
172
- }
173
- return m[1] ? [m[1], m[2]] : [m[4], m[3]];
174
- }
175
- var cache2 = {};
176
- function interval(src) {
177
- return typeof src === "string" ? cache2[src] || (cache2[src] = parse2(src)) : isPitch(src) ? interval(pitchName2(src)) : isNamed(src) ? interval(src.name) : NoInterval;
178
- }
179
- var SIZES = [0, 2, 4, 5, 7, 9, 11];
180
- var TYPES = "PMMPPMM";
181
- function parse2(str) {
182
- const tokens = tokenizeInterval(str);
183
- if (tokens[0] === "") {
184
- return NoInterval;
185
- }
186
- const num = +tokens[0];
187
- const q = tokens[1];
188
- const step = (Math.abs(num) - 1) % 7;
189
- const t = TYPES[step];
190
- if (t === "M" && q === "P") {
191
- return NoInterval;
192
- }
193
- const type = t === "M" ? "majorable" : "perfectable";
194
- const name = "" + num + q;
195
- const dir = num < 0 ? -1 : 1;
196
- const simple = num === 8 || num === -8 ? num : dir * (step + 1);
197
- const alt = qToAlt(type, q);
198
- const oct = Math.floor((Math.abs(num) - 1) / 7);
199
- const semitones = dir * (SIZES[step] + alt + 12 * oct);
200
- const chroma = (dir * (SIZES[step] + alt) % 12 + 12) % 12;
201
- const coord = encode({ step, alt, oct, dir });
202
- return {
203
- empty: false,
204
- name,
205
- num,
206
- q,
207
- step,
208
- alt,
209
- dir,
210
- type,
211
- simple,
212
- semitones,
213
- chroma,
214
- coord,
215
- oct
216
- };
217
- }
218
- function coordToInterval(coord, forceDescending) {
219
- const [f, o = 0] = coord;
220
- const isDescending = f * 7 + o * 12 < 0;
221
- const ivl = forceDescending || isDescending ? [-f, -o, -1] : [f, o, 1];
222
- return interval(decode(ivl));
223
- }
224
- function qToAlt(type, q) {
225
- 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;
226
- }
227
- function pitchName2(props) {
228
- const { step, alt, oct = 0, dir } = props;
229
- if (!dir) {
230
- return "";
231
- }
232
- const calcNum = step + 1 + 7 * oct;
233
- const num = calcNum === 0 ? step + 1 : calcNum;
234
- const d = dir < 0 ? "-" : "";
235
- const type = TYPES[step] === "M" ? "majorable" : "perfectable";
236
- const name = d + num + altToQ(type, alt);
237
- return name;
238
- }
239
- function altToQ(type, alt) {
240
- if (alt === 0) {
241
- return type === "majorable" ? "M" : "P";
242
- } else if (alt === -1 && type === "majorable") {
243
- return "m";
244
- } else if (alt > 0) {
245
- return fillStr("A", alt);
246
- } else {
247
- return fillStr("d", type === "perfectable" ? alt : alt + 1);
248
- }
249
- }
250
-
251
- // src/distance.ts
252
- function transpose(noteName, intervalName) {
253
- const note2 = note(noteName);
254
- const intervalCoord = Array.isArray(intervalName) ? intervalName : interval(intervalName).coord;
255
- if (note2.empty || !intervalCoord || intervalCoord.length < 2) {
256
- return "";
257
- }
258
- const noteCoord = note2.coord;
259
- const tr = noteCoord.length === 1 ? [noteCoord[0] + intervalCoord[0]] : [noteCoord[0] + intervalCoord[0], noteCoord[1] + intervalCoord[1]];
260
- return coordToNote(tr).name;
261
- }
262
- function tonicIntervalsTransposer(intervals, tonic) {
263
- const len = intervals.length;
264
- return (normalized) => {
265
- if (!tonic)
266
- return "";
267
- const index = normalized < 0 ? (len - -normalized % len) % len : normalized % len;
268
- const octaves = Math.floor(normalized / len);
269
- const root = transpose(tonic, [0, octaves]);
270
- return transpose(root, intervals[index]);
271
- };
272
- }
273
- function distance(fromNote, toNote) {
274
- const from = note(fromNote);
275
- const to = note(toNote);
276
- if (from.empty || to.empty) {
277
- return "";
278
- }
279
- const fcoord = from.coord;
280
- const tcoord = to.coord;
281
- const fifths = tcoord[0] - fcoord[0];
282
- const octs = fcoord.length === 2 && tcoord.length === 2 ? tcoord[1] - fcoord[1] : -Math.floor(fifths * 7 / 12);
283
- const forceDescending = to.height === from.height && to.midi !== null && from.midi !== null && from.step > to.step;
284
- return coordToInterval([fifths, octs], forceDescending).name;
285
- }
41
+ var isNamed = deprecate("isNamed", "isNamedPitch", import_pitch.isNamedPitch);
286
42
  // Annotate the CommonJS export names for ESM import in node:
287
43
  0 && (module.exports = {
288
- accToAlt,
289
- altToAcc,
290
- coordToInterval,
291
- coordToNote,
292
- decode,
293
44
  deprecate,
294
- distance,
295
- encode,
296
45
  fillStr,
297
- interval,
298
46
  isNamed,
299
- isPitch,
300
- note,
301
- stepToLetter,
302
- tokenizeInterval,
303
- tokenizeNote,
304
- tonicIntervalsTransposer,
305
- transpose
47
+ ...require("@tonaljs/pitch"),
48
+ ...require("@tonaljs/pitch-distance"),
49
+ ...require("@tonaljs/pitch-interval"),
50
+ ...require("@tonaljs/pitch-note")
306
51
  });
307
52
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../src/utils.ts","../src/named.ts","../src/pitch.ts","../src/note.ts","../src/interval.ts","../src/distance.ts"],"sourcesContent":["export * from \"./src/utils\";\nexport * from \"./src/named\";\nexport * from \"./src/pitch\";\nexport * from \"./src/note\";\nexport * from \"./src/interval\";\nexport * from \"./src/distance\";\n","/**\n * Fill a string with a repeated character\n *\n * @param character\n * @param repetition\n */\nexport const fillStr = (s: string, n: number) => Array(Math.abs(n) + 1).join(s);\n\nexport function deprecate<\n ResultFn extends (this: any, ...newArgs: any[]) => ReturnType<ResultFn>\n>(original: string, alternative: string, fn: ResultFn) {\n return function (this: unknown, ...args: unknown[]): ReturnType<ResultFn> {\n // tslint:disable-next-line\n console.warn(`${original} is deprecated. Use ${alternative}.`);\n return fn.apply(this, args);\n };\n}\n","export interface Named {\n readonly name: string;\n}\n\nexport interface NamedFound {\n readonly empty: false;\n}\n\nexport interface NotFound extends Named {\n readonly empty: true;\n readonly name: \"\";\n}\n\nexport function isNamed(src: any): src is Named {\n return src !== null && typeof src === \"object\" && typeof src.name === \"string\"\n ? true\n : false;\n}\n","import { Named } from \"./named\";\n\ntype Fifths = number;\ntype Octaves = number;\nexport type Direction = 1 | -1;\n\nexport type PitchClassCoordinates = [Fifths];\nexport type NoteCoordinates = [Fifths, Octaves];\nexport type IntervalCoordinates = [Fifths, Octaves, Direction];\nexport type PitchCoordinates =\n | PitchClassCoordinates\n | NoteCoordinates\n | IntervalCoordinates;\n\n/**\n * Pitch properties\n *\n * - {number} step - The step number: 0 = C, 1 = D, ... 6 = B\n * - {number} alt - Number of alterations: -2 = 'bb', -1 = 'b', 0 = '', 1 = '#', ...\n * - {number} [oct] = The octave (undefined when is a coord class)\n * - {number} [dir] = Interval direction (undefined when is not an interval)\n */\nexport interface Pitch {\n readonly step: number;\n readonly alt: number;\n readonly oct?: number; // undefined for pitch classes\n readonly dir?: Direction; // undefined for notes\n}\n\nexport function isPitch(pitch: any): pitch is Pitch {\n return pitch !== null &&\n typeof pitch === \"object\" &&\n typeof pitch.step === \"number\" &&\n typeof pitch.alt === \"number\"\n ? true\n : false;\n}\n\n// The number of fifths of [C, D, E, F, G, A, B]\nconst FIFTHS = [0, 2, 4, -1, 1, 3, 5];\n// The number of octaves it span each step\nconst STEPS_TO_OCTS = FIFTHS.map((fifths: number) =>\n Math.floor((fifths * 7) / 12)\n);\n\nexport function encode(pitch: Pitch): PitchCoordinates {\n const { step, alt, oct, dir = 1 } = pitch;\n const f = FIFTHS[step] + 7 * alt;\n if (oct === undefined) {\n return [dir * f];\n }\n const o = oct - STEPS_TO_OCTS[step] - 4 * alt;\n return [dir * f, dir * o];\n}\n\n// We need to get the steps from fifths\n// Fifths for CDEFGAB are [ 0, 2, 4, -1, 1, 3, 5 ]\n// We add 1 to fifths to avoid negative numbers, so:\n// for [\"F\", \"C\", \"G\", \"D\", \"A\", \"E\", \"B\"] we have:\nconst FIFTHS_TO_STEPS = [3, 0, 4, 1, 5, 2, 6];\n\nexport function decode(coord: PitchCoordinates): Pitch {\n const [f, o, dir] = coord;\n const step = FIFTHS_TO_STEPS[unaltered(f)];\n const alt = Math.floor((f + 1) / 7);\n if (o === undefined) {\n return { step, alt, dir };\n }\n const oct = o + 4 * alt + STEPS_TO_OCTS[step];\n return { step, alt, oct, dir };\n}\n\n// Return the number of fifths as if it were unaltered\nfunction unaltered(f: number): number {\n const i = (f + 1) % 7;\n return i < 0 ? 7 + i : i;\n}\n","import { isNamed, Named } from \"./named\";\nimport { decode, encode, isPitch, Pitch, PitchCoordinates } from \"./pitch\";\nimport { fillStr } from \"./utils\";\n\nexport type NoteWithOctave = string;\nexport type PcName = string;\nexport type NoteName = NoteWithOctave | PcName;\nexport type NoteLiteral = NoteName | Pitch | Named;\n\nexport interface Note extends Pitch, Named {\n readonly empty: boolean;\n readonly name: NoteName;\n readonly letter: string;\n readonly acc: string;\n readonly pc: PcName;\n readonly chroma: number;\n readonly height: number;\n readonly coord: PitchCoordinates;\n readonly midi: number | null;\n readonly freq: number | null;\n}\n\nexport interface NoNote extends Partial<Note> {\n empty: true;\n name: \"\";\n pc: \"\";\n acc: \"\";\n}\nconst NoNote: NoNote = { empty: true, name: \"\", pc: \"\", acc: \"\" };\n\nconst cache: Map<NoteLiteral | undefined, Note | NoNote> = new Map();\n\nexport const stepToLetter = (step: number) => \"CDEFGAB\".charAt(step);\nexport const altToAcc = (alt: number): string =>\n alt < 0 ? fillStr(\"b\", -alt) : fillStr(\"#\", alt);\nexport const accToAlt = (acc: string): number =>\n acc[0] === \"b\" ? -acc.length : acc.length;\n\n/**\n * Given a note literal (a note name or a note object), returns the Note object\n * @example\n * note('Bb4') // => { name: \"Bb4\", midi: 70, chroma: 10, ... }\n */\nexport function note(src: NoteLiteral): Note | NoNote {\n const stringSrc = JSON.stringify(src);\n\n const cached = cache.get(stringSrc);\n if (cached) {\n return cached;\n }\n\n const value =\n typeof src === \"string\"\n ? parse(src)\n : isPitch(src)\n ? note(pitchName(src))\n : isNamed(src)\n ? note(src.name)\n : NoNote;\n cache.set(stringSrc, value);\n return value;\n}\n\ntype NoteTokens = [string, string, string, string];\n\nconst REGEX = /^([a-gA-G]?)(#{1,}|b{1,}|x{1,}|)(-?\\d*)\\s*(.*)$/;\n\n/**\n * @private\n */\nexport function tokenizeNote(str: string): NoteTokens {\n const m = REGEX.exec(str) as string[];\n return [m[1].toUpperCase(), m[2].replace(/x/g, \"##\"), m[3], m[4]];\n}\n\n/**\n * @private\n */\nexport function coordToNote(noteCoord: PitchCoordinates): Note {\n return note(decode(noteCoord)) as Note;\n}\n\nconst mod = (n: number, m: number) => ((n % m) + m) % m;\n\nconst SEMI = [0, 2, 4, 5, 7, 9, 11];\nfunction parse(noteName: NoteName): Note | NoNote {\n const tokens = tokenizeNote(noteName);\n if (tokens[0] === \"\" || tokens[3] !== \"\") {\n return NoNote;\n }\n\n const letter = tokens[0];\n const acc = tokens[1];\n const octStr = tokens[2];\n\n const step = (letter.charCodeAt(0) + 3) % 7;\n const alt = accToAlt(acc);\n const oct = octStr.length ? +octStr : undefined;\n const coord = encode({ step, alt, oct });\n\n const name = letter + acc + octStr;\n const pc = letter + acc;\n const chroma = (SEMI[step] + alt + 120) % 12;\n const height =\n oct === undefined\n ? mod(SEMI[step] + alt, 12) - 12 * 99\n : SEMI[step] + alt + 12 * (oct + 1);\n const midi = height >= 0 && height <= 127 ? height : null;\n const freq = oct === undefined ? null : Math.pow(2, (height - 69) / 12) * 440;\n\n return {\n empty: false,\n acc,\n alt,\n chroma,\n coord,\n freq,\n height,\n letter,\n midi,\n name,\n oct,\n pc,\n step,\n };\n}\n\nfunction pitchName(props: Pitch): NoteName {\n const { step, alt, oct } = props;\n const letter = stepToLetter(step);\n if (!letter) {\n return \"\";\n }\n\n const pc = letter + altToAcc(alt);\n return oct || oct === 0 ? pc + oct : pc;\n}\n","import { isNamed, Named } from \"./named\";\nimport {\n decode,\n Direction,\n encode,\n IntervalCoordinates,\n isPitch,\n Pitch,\n PitchCoordinates,\n} from \"./pitch\";\nimport { fillStr } from \"./utils\";\n\nexport type IntervalName = string;\nexport type IntervalLiteral = IntervalName | Pitch | Named;\n\ntype Quality =\n | \"dddd\"\n | \"ddd\"\n | \"dd\"\n | \"d\"\n | \"m\"\n | \"M\"\n | \"P\"\n | \"A\"\n | \"AA\"\n | \"AAA\"\n | \"AAAA\";\ntype Type = \"perfectable\" | \"majorable\";\n\nexport interface Interval extends Pitch, Named {\n readonly empty: boolean;\n readonly name: IntervalName;\n readonly num: number;\n readonly q: Quality;\n readonly type: Type;\n readonly step: number;\n readonly alt: number;\n readonly dir: Direction;\n readonly simple: number;\n readonly semitones: number;\n readonly chroma: number;\n readonly coord: IntervalCoordinates;\n readonly oct: number;\n}\n\nexport interface NoInterval extends Partial<Interval> {\n readonly empty: true;\n readonly name: \"\";\n readonly acc: \"\";\n}\n\nconst NoInterval: NoInterval = { empty: true, name: \"\", acc: \"\" };\n\n// shorthand tonal notation (with quality after number)\nconst INTERVAL_TONAL_REGEX = \"([-+]?\\\\d+)(d{1,4}|m|M|P|A{1,4})\";\n// standard shorthand notation (with quality before number)\nconst INTERVAL_SHORTHAND_REGEX = \"(AA|A|P|M|m|d|dd)([-+]?\\\\d+)\";\nconst REGEX = new RegExp(\n \"^\" + INTERVAL_TONAL_REGEX + \"|\" + INTERVAL_SHORTHAND_REGEX + \"$\"\n);\n\ntype IntervalTokens = [string, string];\n\n/**\n * @private\n */\nexport function tokenizeInterval(str?: IntervalName): IntervalTokens {\n const m = REGEX.exec(`${str}`);\n if (m === null) {\n return [\"\", \"\"];\n }\n return m[1] ? [m[1], m[2]] : [m[4], m[3]];\n}\n\nconst cache: { [key in string]: Interval | NoInterval } = {};\n\n/**\n * Get interval properties. It returns an object with:\n *\n * - name: the interval name\n * - num: the interval number\n * - type: 'perfectable' or 'majorable'\n * - q: the interval quality (d, m, M, A)\n * - dir: interval direction (1 ascending, -1 descending)\n * - simple: the simplified number\n * - semitones: the size in semitones\n * - chroma: the interval chroma\n *\n * @param {string} interval - the interval name\n * @return {Object} the interval properties\n *\n * @example\n * import { interval } from '@tonaljs/core'\n * interval('P5').semitones // => 7\n * interval('m3').type // => 'majorable'\n */\nexport function interval(src: IntervalLiteral): Interval | NoInterval {\n return typeof src === \"string\"\n ? cache[src] || (cache[src] = parse(src))\n : isPitch(src)\n ? interval(pitchName(src))\n : isNamed(src)\n ? interval(src.name)\n : NoInterval;\n}\n\nconst SIZES = [0, 2, 4, 5, 7, 9, 11];\nconst TYPES = \"PMMPPMM\";\nfunction parse(str?: string): Interval | NoInterval {\n const tokens = tokenizeInterval(str);\n if (tokens[0] === \"\") {\n return NoInterval;\n }\n const num = +tokens[0];\n const q = tokens[1] as Quality;\n const step = (Math.abs(num) - 1) % 7;\n const t = TYPES[step];\n if (t === \"M\" && q === \"P\") {\n return NoInterval;\n }\n const type = t === \"M\" ? \"majorable\" : \"perfectable\";\n\n const name = \"\" + num + q;\n const dir = num < 0 ? -1 : 1;\n const simple = num === 8 || num === -8 ? num : dir * (step + 1);\n const alt = qToAlt(type, q);\n const oct = Math.floor((Math.abs(num) - 1) / 7);\n const semitones = dir * (SIZES[step] + alt + 12 * oct);\n const chroma = (((dir * (SIZES[step] + alt)) % 12) + 12) % 12;\n const coord = encode({ step, alt, oct, dir }) as IntervalCoordinates;\n return {\n empty: false,\n name,\n num,\n q,\n step,\n alt,\n dir,\n type,\n simple,\n semitones,\n chroma,\n coord,\n oct,\n };\n}\n\n/**\n * @private\n *\n * forceDescending is used in the case of unison (#243)\n */\nexport function coordToInterval(\n coord: PitchCoordinates,\n forceDescending?: boolean\n): Interval {\n const [f, o = 0] = coord;\n const isDescending = f * 7 + o * 12 < 0;\n const ivl: IntervalCoordinates =\n forceDescending || isDescending ? [-f, -o, -1] : [f, o, 1];\n return interval(decode(ivl)) as Interval;\n}\n\nfunction qToAlt(type: Type, q: string): number {\n return (q === \"M\" && type === \"majorable\") ||\n (q === \"P\" && type === \"perfectable\")\n ? 0\n : q === \"m\" && type === \"majorable\"\n ? -1\n : /^A+$/.test(q)\n ? q.length\n : /^d+$/.test(q)\n ? -1 * (type === \"perfectable\" ? q.length : q.length + 1)\n : 0;\n}\n\n// return the interval name of a pitch\nfunction pitchName(props: Pitch): string {\n const { step, alt, oct = 0, dir } = props;\n if (!dir) {\n return \"\";\n }\n const calcNum = step + 1 + 7 * oct;\n // this is an edge case: descending pitch class unison (see #243)\n const num = calcNum === 0 ? step + 1 : calcNum;\n const d = dir < 0 ? \"-\" : \"\";\n const type = TYPES[step] === \"M\" ? \"majorable\" : \"perfectable\";\n const name = d + num + altToQ(type, alt);\n return name;\n}\n\nfunction altToQ(type: Type, alt: number): Quality {\n if (alt === 0) {\n return type === \"majorable\" ? \"M\" : \"P\";\n } else if (alt === -1 && type === \"majorable\") {\n return \"m\";\n } else if (alt > 0) {\n return fillStr(\"A\", alt) as Quality;\n } else {\n return fillStr(\"d\", type === \"perfectable\" ? alt : alt + 1) as Quality;\n }\n}\n","import {\n coordToInterval,\n interval as asInterval,\n IntervalLiteral,\n IntervalName,\n} from \"./interval\";\nimport { coordToNote, note as asNote, NoteLiteral, NoteName } from \"./note\";\nimport { PitchCoordinates } from \"./pitch\";\n\n/**\n * Transpose a note by an interval.\n *\n * @param {string} note - the note or note name\n * @param {string} interval - the interval or interval name\n * @return {string} the transposed note name or empty string if not valid notes\n * @example\n * import { tranpose } from \"@tonaljs/core\"\n * transpose(\"d3\", \"3M\") // => \"F#3\"\n * transpose(\"D\", \"3M\") // => \"F#\"\n * [\"C\", \"D\", \"E\", \"F\", \"G\"].map(pc => transpose(pc, \"M3)) // => [\"E\", \"F#\", \"G#\", \"A\", \"B\"]\n */\nexport function transpose(\n noteName: NoteLiteral,\n intervalName: IntervalLiteral | [number, number]\n): NoteName {\n const note = asNote(noteName);\n const intervalCoord = Array.isArray(intervalName)\n ? intervalName\n : asInterval(intervalName).coord;\n if (note.empty || !intervalCoord || intervalCoord.length < 2) {\n return \"\";\n }\n const noteCoord = note.coord;\n const tr: PitchCoordinates =\n noteCoord.length === 1\n ? [noteCoord[0] + intervalCoord[0]]\n : [noteCoord[0] + intervalCoord[0], noteCoord[1] + intervalCoord[1]];\n return coordToNote(tr).name;\n}\n\n// Private\nexport function tonicIntervalsTransposer(\n intervals: string[],\n tonic: string | undefined | null\n) {\n const len = intervals.length;\n return (normalized: number) => {\n if (!tonic) return \"\";\n const index =\n normalized < 0 ? (len - (-normalized % len)) % len : normalized % len;\n const octaves = Math.floor(normalized / len);\n const root = transpose(tonic, [0, octaves]);\n return transpose(root, intervals[index]);\n };\n}\n\n/**\n * Find the interval distance between two notes or coord classes.\n *\n * To find distance between coord classes, both notes must be coord classes and\n * the interval is always ascending\n *\n * @param {Note|string} from - the note or note name to calculate distance from\n * @param {Note|string} to - the note or note name to calculate distance to\n * @return {string} the interval name or empty string if not valid notes\n *\n */\nexport function distance(\n fromNote: NoteLiteral,\n toNote: NoteLiteral\n): IntervalName {\n const from = asNote(fromNote);\n const to = asNote(toNote);\n if (from.empty || to.empty) {\n return \"\";\n }\n\n const fcoord = from.coord;\n const tcoord = to.coord;\n const fifths = tcoord[0] - fcoord[0];\n const octs =\n fcoord.length === 2 && tcoord.length === 2\n ? tcoord[1] - fcoord[1]\n : -Math.floor((fifths * 7) / 12);\n\n // If it's unison and not pitch class, it can be descending interval (#243)\n const forceDescending =\n to.height === from.height &&\n to.midi !== null &&\n from.midi !== null &&\n from.step > to.step;\n return coordToInterval([fifths, octs], forceDescending).name;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,UAAU,CAAC,GAAW,MAAc,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;AAEvE,SAAS,UAEd,UAAkB,aAAqB,IAAc;AACrD,SAAO,YAA4B,MAAuC;AAExE,YAAQ,KAAK,GAAG,+BAA+B,cAAc;AAC7D,WAAO,GAAG,MAAM,MAAM,IAAI;AAAA,EAC5B;AACF;;;ACHO,SAAS,QAAQ,KAAwB;AAC9C,SAAO,QAAQ,QAAQ,OAAO,QAAQ,YAAY,OAAO,IAAI,SAAS,WAClE,OACA;AACN;;;ACYO,SAAS,QAAQ,OAA4B;AAClD,SAAO,UAAU,QACf,OAAO,UAAU,YACjB,OAAO,MAAM,SAAS,YACtB,OAAO,MAAM,QAAQ,WACnB,OACA;AACN;AAGA,IAAM,SAAS,CAAC,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;AAEpC,IAAM,gBAAgB,OAAO;AAAA,EAAI,CAAC,WAChC,KAAK,MAAO,SAAS,IAAK,EAAE;AAC9B;AAEO,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AO,CAAC,eAAuB;AAC7B,QAAI,CAAC;AAAO,aAAO;AACnB,UAAM,QACJ,aAAa,KAAK,MAAO,CAAC,aAAa,OAAQ,MAAM,aAAa;AACpE,UAAM,UAAU,KAAK,MAAM,aAAa,GAAG;AAC3C,UAAM,OAAO,UAAU,OAAO,CAAC,GAAG,OAAO,CAAC;AAC1C,WAAO,UAAU,MAAM,UAAU,MAAM;AAAA,EACzC;AACF;AAaO,SAAS,SACd,UACA,QACc;AACd,QAAM,OAAO,KAAO,QAAQ;AAC5B,QAAM,KAAK,KAAO,MAAM;AACxB,MAAI,KAAK,SAAS,GAAG,OAAO;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,KAAK;AACpB,QAAM,SAAS,GAAG;AAClB,QAAM,SAAS,OAAO,KAAK,OAAO;AAClC,QAAM,OACJ,OAAO,WAAW,KAAK,OAAO,WAAW,IACrC,OAAO,KAAK,OAAO,KACnB,CAAC,KAAK,MAAO,SAAS,IAAK,EAAE;AAGnC,QAAM,kBACJ,GAAG,WAAW,KAAK,UACnB,GAAG,SAAS,QACZ,KAAK,SAAS,QACd,KAAK,OAAO,GAAG;AACjB,SAAO,gBAAgB,CAAC,QAAQ,IAAI,GAAG,eAAe,EAAE;AAC1D;","names":["REGEX","cache","parse","pitchName","note"]}
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import { isNamedPitch } from \"@tonaljs/pitch\";\n\nexport * from \"@tonaljs/pitch\";\nexport * from \"@tonaljs/pitch-distance\";\nexport * from \"@tonaljs/pitch-interval\";\nexport * from \"@tonaljs/pitch-note\";\n\nexport const fillStr = (s: string, n: number) => Array(Math.abs(n) + 1).join(s);\n\nexport function deprecate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ResultFn extends (this: any, ...newArgs: any[]) => ReturnType<ResultFn>,\n>(original: string, alternative: string, fn: ResultFn) {\n return function (this: unknown, ...args: unknown[]): ReturnType<ResultFn> {\n // tslint:disable-next-line\n console.warn(`${original} is deprecated. Use ${alternative}.`);\n return fn.apply(this, args);\n };\n}\n\nexport const isNamed = deprecate(\"isNamed\", \"isNamedPitch\", isNamedPitch);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6B;AAE7B,yBAAc,2BAFd;AAGA,yBAAc,oCAHd;AAIA,yBAAc,oCAJd;AAKA,yBAAc,gCALd;AAOO,IAAM,UAAU,CAAC,GAAW,MAAc,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;AAEvE,SAAS,UAGd,UAAkB,aAAqB,IAAc;AACrD,SAAO,YAA4B,MAAuC;AAExE,YAAQ,KAAK,GAAG,QAAQ,uBAAuB,WAAW,GAAG;AAC7D,WAAO,GAAG,MAAM,MAAM,IAAI;AAAA,EAC5B;AACF;AAEO,IAAM,UAAU,UAAU,WAAW,gBAAgB,yBAAY;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,4 +1,9 @@
1
- // src/utils.ts
1
+ // index.ts
2
+ import { isNamedPitch } from "@tonaljs/pitch";
3
+ export * from "@tonaljs/pitch";
4
+ export * from "@tonaljs/pitch-distance";
5
+ export * from "@tonaljs/pitch-interval";
6
+ export * from "@tonaljs/pitch-note";
2
7
  var fillStr = (s, n) => Array(Math.abs(n) + 1).join(s);
3
8
  function deprecate(original, alternative, fn) {
4
9
  return function(...args) {
@@ -6,258 +11,10 @@ function deprecate(original, alternative, fn) {
6
11
  return fn.apply(this, args);
7
12
  };
8
13
  }
9
-
10
- // src/named.ts
11
- function isNamed(src) {
12
- return src !== null && typeof src === "object" && typeof src.name === "string" ? true : false;
13
- }
14
-
15
- // src/pitch.ts
16
- function isPitch(pitch) {
17
- return pitch !== null && typeof pitch === "object" && typeof pitch.step === "number" && typeof pitch.alt === "number" ? true : false;
18
- }
19
- var FIFTHS = [0, 2, 4, -1, 1, 3, 5];
20
- var STEPS_TO_OCTS = FIFTHS.map(
21
- (fifths) => Math.floor(fifths * 7 / 12)
22
- );
23
- function encode(pitch) {
24
- const { step, alt, oct, dir = 1 } = pitch;
25
- const f = FIFTHS[step] + 7 * alt;
26
- if (oct === void 0) {
27
- return [dir * f];
28
- }
29
- const o = oct - STEPS_TO_OCTS[step] - 4 * alt;
30
- return [dir * f, dir * o];
31
- }
32
- var FIFTHS_TO_STEPS = [3, 0, 4, 1, 5, 2, 6];
33
- function decode(coord) {
34
- const [f, o, dir] = coord;
35
- const step = FIFTHS_TO_STEPS[unaltered(f)];
36
- const alt = Math.floor((f + 1) / 7);
37
- if (o === void 0) {
38
- return { step, alt, dir };
39
- }
40
- const oct = o + 4 * alt + STEPS_TO_OCTS[step];
41
- return { step, alt, oct, dir };
42
- }
43
- function unaltered(f) {
44
- const i = (f + 1) % 7;
45
- return i < 0 ? 7 + i : i;
46
- }
47
-
48
- // src/note.ts
49
- var NoNote = { empty: true, name: "", pc: "", acc: "" };
50
- var cache = /* @__PURE__ */ new Map();
51
- var stepToLetter = (step) => "CDEFGAB".charAt(step);
52
- var altToAcc = (alt) => alt < 0 ? fillStr("b", -alt) : fillStr("#", alt);
53
- var accToAlt = (acc) => acc[0] === "b" ? -acc.length : acc.length;
54
- function note(src) {
55
- const stringSrc = JSON.stringify(src);
56
- const cached = cache.get(stringSrc);
57
- if (cached) {
58
- return cached;
59
- }
60
- const value = typeof src === "string" ? parse(src) : isPitch(src) ? note(pitchName(src)) : isNamed(src) ? note(src.name) : NoNote;
61
- cache.set(stringSrc, value);
62
- return value;
63
- }
64
- var REGEX = /^([a-gA-G]?)(#{1,}|b{1,}|x{1,}|)(-?\d*)\s*(.*)$/;
65
- function tokenizeNote(str) {
66
- const m = REGEX.exec(str);
67
- return [m[1].toUpperCase(), m[2].replace(/x/g, "##"), m[3], m[4]];
68
- }
69
- function coordToNote(noteCoord) {
70
- return note(decode(noteCoord));
71
- }
72
- var mod = (n, m) => (n % m + m) % m;
73
- var SEMI = [0, 2, 4, 5, 7, 9, 11];
74
- function parse(noteName) {
75
- const tokens = tokenizeNote(noteName);
76
- if (tokens[0] === "" || tokens[3] !== "") {
77
- return NoNote;
78
- }
79
- const letter = tokens[0];
80
- const acc = tokens[1];
81
- const octStr = tokens[2];
82
- const step = (letter.charCodeAt(0) + 3) % 7;
83
- const alt = accToAlt(acc);
84
- const oct = octStr.length ? +octStr : void 0;
85
- const coord = encode({ step, alt, oct });
86
- const name = letter + acc + octStr;
87
- const pc = letter + acc;
88
- const chroma = (SEMI[step] + alt + 120) % 12;
89
- const height = oct === void 0 ? mod(SEMI[step] + alt, 12) - 12 * 99 : SEMI[step] + alt + 12 * (oct + 1);
90
- const midi = height >= 0 && height <= 127 ? height : null;
91
- const freq = oct === void 0 ? null : Math.pow(2, (height - 69) / 12) * 440;
92
- return {
93
- empty: false,
94
- acc,
95
- alt,
96
- chroma,
97
- coord,
98
- freq,
99
- height,
100
- letter,
101
- midi,
102
- name,
103
- oct,
104
- pc,
105
- step
106
- };
107
- }
108
- function pitchName(props) {
109
- const { step, alt, oct } = props;
110
- const letter = stepToLetter(step);
111
- if (!letter) {
112
- return "";
113
- }
114
- const pc = letter + altToAcc(alt);
115
- return oct || oct === 0 ? pc + oct : pc;
116
- }
117
-
118
- // src/interval.ts
119
- var NoInterval = { empty: true, name: "", acc: "" };
120
- var INTERVAL_TONAL_REGEX = "([-+]?\\d+)(d{1,4}|m|M|P|A{1,4})";
121
- var INTERVAL_SHORTHAND_REGEX = "(AA|A|P|M|m|d|dd)([-+]?\\d+)";
122
- var REGEX2 = new RegExp(
123
- "^" + INTERVAL_TONAL_REGEX + "|" + INTERVAL_SHORTHAND_REGEX + "$"
124
- );
125
- function tokenizeInterval(str) {
126
- const m = REGEX2.exec(`${str}`);
127
- if (m === null) {
128
- return ["", ""];
129
- }
130
- return m[1] ? [m[1], m[2]] : [m[4], m[3]];
131
- }
132
- var cache2 = {};
133
- function interval(src) {
134
- return typeof src === "string" ? cache2[src] || (cache2[src] = parse2(src)) : isPitch(src) ? interval(pitchName2(src)) : isNamed(src) ? interval(src.name) : NoInterval;
135
- }
136
- var SIZES = [0, 2, 4, 5, 7, 9, 11];
137
- var TYPES = "PMMPPMM";
138
- function parse2(str) {
139
- const tokens = tokenizeInterval(str);
140
- if (tokens[0] === "") {
141
- return NoInterval;
142
- }
143
- const num = +tokens[0];
144
- const q = tokens[1];
145
- const step = (Math.abs(num) - 1) % 7;
146
- const t = TYPES[step];
147
- if (t === "M" && q === "P") {
148
- return NoInterval;
149
- }
150
- const type = t === "M" ? "majorable" : "perfectable";
151
- const name = "" + num + q;
152
- const dir = num < 0 ? -1 : 1;
153
- const simple = num === 8 || num === -8 ? num : dir * (step + 1);
154
- const alt = qToAlt(type, q);
155
- const oct = Math.floor((Math.abs(num) - 1) / 7);
156
- const semitones = dir * (SIZES[step] + alt + 12 * oct);
157
- const chroma = (dir * (SIZES[step] + alt) % 12 + 12) % 12;
158
- const coord = encode({ step, alt, oct, dir });
159
- return {
160
- empty: false,
161
- name,
162
- num,
163
- q,
164
- step,
165
- alt,
166
- dir,
167
- type,
168
- simple,
169
- semitones,
170
- chroma,
171
- coord,
172
- oct
173
- };
174
- }
175
- function coordToInterval(coord, forceDescending) {
176
- const [f, o = 0] = coord;
177
- const isDescending = f * 7 + o * 12 < 0;
178
- const ivl = forceDescending || isDescending ? [-f, -o, -1] : [f, o, 1];
179
- return interval(decode(ivl));
180
- }
181
- function qToAlt(type, q) {
182
- 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;
183
- }
184
- function pitchName2(props) {
185
- const { step, alt, oct = 0, dir } = props;
186
- if (!dir) {
187
- return "";
188
- }
189
- const calcNum = step + 1 + 7 * oct;
190
- const num = calcNum === 0 ? step + 1 : calcNum;
191
- const d = dir < 0 ? "-" : "";
192
- const type = TYPES[step] === "M" ? "majorable" : "perfectable";
193
- const name = d + num + altToQ(type, alt);
194
- return name;
195
- }
196
- function altToQ(type, alt) {
197
- if (alt === 0) {
198
- return type === "majorable" ? "M" : "P";
199
- } else if (alt === -1 && type === "majorable") {
200
- return "m";
201
- } else if (alt > 0) {
202
- return fillStr("A", alt);
203
- } else {
204
- return fillStr("d", type === "perfectable" ? alt : alt + 1);
205
- }
206
- }
207
-
208
- // src/distance.ts
209
- function transpose(noteName, intervalName) {
210
- const note2 = note(noteName);
211
- const intervalCoord = Array.isArray(intervalName) ? intervalName : interval(intervalName).coord;
212
- if (note2.empty || !intervalCoord || intervalCoord.length < 2) {
213
- return "";
214
- }
215
- const noteCoord = note2.coord;
216
- const tr = noteCoord.length === 1 ? [noteCoord[0] + intervalCoord[0]] : [noteCoord[0] + intervalCoord[0], noteCoord[1] + intervalCoord[1]];
217
- return coordToNote(tr).name;
218
- }
219
- function tonicIntervalsTransposer(intervals, tonic) {
220
- const len = intervals.length;
221
- return (normalized) => {
222
- if (!tonic)
223
- return "";
224
- const index = normalized < 0 ? (len - -normalized % len) % len : normalized % len;
225
- const octaves = Math.floor(normalized / len);
226
- const root = transpose(tonic, [0, octaves]);
227
- return transpose(root, intervals[index]);
228
- };
229
- }
230
- function distance(fromNote, toNote) {
231
- const from = note(fromNote);
232
- const to = note(toNote);
233
- if (from.empty || to.empty) {
234
- return "";
235
- }
236
- const fcoord = from.coord;
237
- const tcoord = to.coord;
238
- const fifths = tcoord[0] - fcoord[0];
239
- const octs = fcoord.length === 2 && tcoord.length === 2 ? tcoord[1] - fcoord[1] : -Math.floor(fifths * 7 / 12);
240
- const forceDescending = to.height === from.height && to.midi !== null && from.midi !== null && from.step > to.step;
241
- return coordToInterval([fifths, octs], forceDescending).name;
242
- }
14
+ var isNamed = deprecate("isNamed", "isNamedPitch", isNamedPitch);
243
15
  export {
244
- accToAlt,
245
- altToAcc,
246
- coordToInterval,
247
- coordToNote,
248
- decode,
249
16
  deprecate,
250
- distance,
251
- encode,
252
17
  fillStr,
253
- interval,
254
- isNamed,
255
- isPitch,
256
- note,
257
- stepToLetter,
258
- tokenizeInterval,
259
- tokenizeNote,
260
- tonicIntervalsTransposer,
261
- transpose
18
+ isNamed
262
19
  };
263
20
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.ts","../src/named.ts","../src/pitch.ts","../src/note.ts","../src/interval.ts","../src/distance.ts"],"sourcesContent":["/**\n * Fill a string with a repeated character\n *\n * @param character\n * @param repetition\n */\nexport const fillStr = (s: string, n: number) => Array(Math.abs(n) + 1).join(s);\n\nexport function deprecate<\n ResultFn extends (this: any, ...newArgs: any[]) => ReturnType<ResultFn>\n>(original: string, alternative: string, fn: ResultFn) {\n return function (this: unknown, ...args: unknown[]): ReturnType<ResultFn> {\n // tslint:disable-next-line\n console.warn(`${original} is deprecated. Use ${alternative}.`);\n return fn.apply(this, args);\n };\n}\n","export interface Named {\n readonly name: string;\n}\n\nexport interface NamedFound {\n readonly empty: false;\n}\n\nexport interface NotFound extends Named {\n readonly empty: true;\n readonly name: \"\";\n}\n\nexport function isNamed(src: any): src is Named {\n return src !== null && typeof src === \"object\" && typeof src.name === \"string\"\n ? true\n : false;\n}\n","import { Named } from \"./named\";\n\ntype Fifths = number;\ntype Octaves = number;\nexport type Direction = 1 | -1;\n\nexport type PitchClassCoordinates = [Fifths];\nexport type NoteCoordinates = [Fifths, Octaves];\nexport type IntervalCoordinates = [Fifths, Octaves, Direction];\nexport type PitchCoordinates =\n | PitchClassCoordinates\n | NoteCoordinates\n | IntervalCoordinates;\n\n/**\n * Pitch properties\n *\n * - {number} step - The step number: 0 = C, 1 = D, ... 6 = B\n * - {number} alt - Number of alterations: -2 = 'bb', -1 = 'b', 0 = '', 1 = '#', ...\n * - {number} [oct] = The octave (undefined when is a coord class)\n * - {number} [dir] = Interval direction (undefined when is not an interval)\n */\nexport interface Pitch {\n readonly step: number;\n readonly alt: number;\n readonly oct?: number; // undefined for pitch classes\n readonly dir?: Direction; // undefined for notes\n}\n\nexport function isPitch(pitch: any): pitch is Pitch {\n return pitch !== null &&\n typeof pitch === \"object\" &&\n typeof pitch.step === \"number\" &&\n typeof pitch.alt === \"number\"\n ? true\n : false;\n}\n\n// The number of fifths of [C, D, E, F, G, A, B]\nconst FIFTHS = [0, 2, 4, -1, 1, 3, 5];\n// The number of octaves it span each step\nconst STEPS_TO_OCTS = FIFTHS.map((fifths: number) =>\n Math.floor((fifths * 7) / 12)\n);\n\nexport function encode(pitch: Pitch): PitchCoordinates {\n const { step, alt, oct, dir = 1 } = pitch;\n const f = FIFTHS[step] + 7 * alt;\n if (oct === undefined) {\n return [dir * f];\n }\n const o = oct - STEPS_TO_OCTS[step] - 4 * alt;\n return [dir * f, dir * o];\n}\n\n// We need to get the steps from fifths\n// Fifths for CDEFGAB are [ 0, 2, 4, -1, 1, 3, 5 ]\n// We add 1 to fifths to avoid negative numbers, so:\n// for [\"F\", \"C\", \"G\", \"D\", \"A\", \"E\", \"B\"] we have:\nconst FIFTHS_TO_STEPS = [3, 0, 4, 1, 5, 2, 6];\n\nexport function decode(coord: PitchCoordinates): Pitch {\n const [f, o, dir] = coord;\n const step = FIFTHS_TO_STEPS[unaltered(f)];\n const alt = Math.floor((f + 1) / 7);\n if (o === undefined) {\n return { step, alt, dir };\n }\n const oct = o + 4 * alt + STEPS_TO_OCTS[step];\n return { step, alt, oct, dir };\n}\n\n// Return the number of fifths as if it were unaltered\nfunction unaltered(f: number): number {\n const i = (f + 1) % 7;\n return i < 0 ? 7 + i : i;\n}\n","import { isNamed, Named } from \"./named\";\nimport { decode, encode, isPitch, Pitch, PitchCoordinates } from \"./pitch\";\nimport { fillStr } from \"./utils\";\n\nexport type NoteWithOctave = string;\nexport type PcName = string;\nexport type NoteName = NoteWithOctave | PcName;\nexport type NoteLiteral = NoteName | Pitch | Named;\n\nexport interface Note extends Pitch, Named {\n readonly empty: boolean;\n readonly name: NoteName;\n readonly letter: string;\n readonly acc: string;\n readonly pc: PcName;\n readonly chroma: number;\n readonly height: number;\n readonly coord: PitchCoordinates;\n readonly midi: number | null;\n readonly freq: number | null;\n}\n\nexport interface NoNote extends Partial<Note> {\n empty: true;\n name: \"\";\n pc: \"\";\n acc: \"\";\n}\nconst NoNote: NoNote = { empty: true, name: \"\", pc: \"\", acc: \"\" };\n\nconst cache: Map<NoteLiteral | undefined, Note | NoNote> = new Map();\n\nexport const stepToLetter = (step: number) => \"CDEFGAB\".charAt(step);\nexport const altToAcc = (alt: number): string =>\n alt < 0 ? fillStr(\"b\", -alt) : fillStr(\"#\", alt);\nexport const accToAlt = (acc: string): number =>\n acc[0] === \"b\" ? -acc.length : acc.length;\n\n/**\n * Given a note literal (a note name or a note object), returns the Note object\n * @example\n * note('Bb4') // => { name: \"Bb4\", midi: 70, chroma: 10, ... }\n */\nexport function note(src: NoteLiteral): Note | NoNote {\n const stringSrc = JSON.stringify(src);\n\n const cached = cache.get(stringSrc);\n if (cached) {\n return cached;\n }\n\n const value =\n typeof src === \"string\"\n ? parse(src)\n : isPitch(src)\n ? note(pitchName(src))\n : isNamed(src)\n ? note(src.name)\n : NoNote;\n cache.set(stringSrc, value);\n return value;\n}\n\ntype NoteTokens = [string, string, string, string];\n\nconst REGEX = /^([a-gA-G]?)(#{1,}|b{1,}|x{1,}|)(-?\\d*)\\s*(.*)$/;\n\n/**\n * @private\n */\nexport function tokenizeNote(str: string): NoteTokens {\n const m = REGEX.exec(str) as string[];\n return [m[1].toUpperCase(), m[2].replace(/x/g, \"##\"), m[3], m[4]];\n}\n\n/**\n * @private\n */\nexport function coordToNote(noteCoord: PitchCoordinates): Note {\n return note(decode(noteCoord)) as Note;\n}\n\nconst mod = (n: number, m: number) => ((n % m) + m) % m;\n\nconst SEMI = [0, 2, 4, 5, 7, 9, 11];\nfunction parse(noteName: NoteName): Note | NoNote {\n const tokens = tokenizeNote(noteName);\n if (tokens[0] === \"\" || tokens[3] !== \"\") {\n return NoNote;\n }\n\n const letter = tokens[0];\n const acc = tokens[1];\n const octStr = tokens[2];\n\n const step = (letter.charCodeAt(0) + 3) % 7;\n const alt = accToAlt(acc);\n const oct = octStr.length ? +octStr : undefined;\n const coord = encode({ step, alt, oct });\n\n const name = letter + acc + octStr;\n const pc = letter + acc;\n const chroma = (SEMI[step] + alt + 120) % 12;\n const height =\n oct === undefined\n ? mod(SEMI[step] + alt, 12) - 12 * 99\n : SEMI[step] + alt + 12 * (oct + 1);\n const midi = height >= 0 && height <= 127 ? height : null;\n const freq = oct === undefined ? null : Math.pow(2, (height - 69) / 12) * 440;\n\n return {\n empty: false,\n acc,\n alt,\n chroma,\n coord,\n freq,\n height,\n letter,\n midi,\n name,\n oct,\n pc,\n step,\n };\n}\n\nfunction pitchName(props: Pitch): NoteName {\n const { step, alt, oct } = props;\n const letter = stepToLetter(step);\n if (!letter) {\n return \"\";\n }\n\n const pc = letter + altToAcc(alt);\n return oct || oct === 0 ? pc + oct : pc;\n}\n","import { isNamed, Named } from \"./named\";\nimport {\n decode,\n Direction,\n encode,\n IntervalCoordinates,\n isPitch,\n Pitch,\n PitchCoordinates,\n} from \"./pitch\";\nimport { fillStr } from \"./utils\";\n\nexport type IntervalName = string;\nexport type IntervalLiteral = IntervalName | Pitch | Named;\n\ntype Quality =\n | \"dddd\"\n | \"ddd\"\n | \"dd\"\n | \"d\"\n | \"m\"\n | \"M\"\n | \"P\"\n | \"A\"\n | \"AA\"\n | \"AAA\"\n | \"AAAA\";\ntype Type = \"perfectable\" | \"majorable\";\n\nexport interface Interval extends Pitch, Named {\n readonly empty: boolean;\n readonly name: IntervalName;\n readonly num: number;\n readonly q: Quality;\n readonly type: Type;\n readonly step: number;\n readonly alt: number;\n readonly dir: Direction;\n readonly simple: number;\n readonly semitones: number;\n readonly chroma: number;\n readonly coord: IntervalCoordinates;\n readonly oct: number;\n}\n\nexport interface NoInterval extends Partial<Interval> {\n readonly empty: true;\n readonly name: \"\";\n readonly acc: \"\";\n}\n\nconst NoInterval: NoInterval = { empty: true, name: \"\", acc: \"\" };\n\n// shorthand tonal notation (with quality after number)\nconst INTERVAL_TONAL_REGEX = \"([-+]?\\\\d+)(d{1,4}|m|M|P|A{1,4})\";\n// standard shorthand notation (with quality before number)\nconst INTERVAL_SHORTHAND_REGEX = \"(AA|A|P|M|m|d|dd)([-+]?\\\\d+)\";\nconst REGEX = new RegExp(\n \"^\" + INTERVAL_TONAL_REGEX + \"|\" + INTERVAL_SHORTHAND_REGEX + \"$\"\n);\n\ntype IntervalTokens = [string, string];\n\n/**\n * @private\n */\nexport function tokenizeInterval(str?: IntervalName): IntervalTokens {\n const m = REGEX.exec(`${str}`);\n if (m === null) {\n return [\"\", \"\"];\n }\n return m[1] ? [m[1], m[2]] : [m[4], m[3]];\n}\n\nconst cache: { [key in string]: Interval | NoInterval } = {};\n\n/**\n * Get interval properties. It returns an object with:\n *\n * - name: the interval name\n * - num: the interval number\n * - type: 'perfectable' or 'majorable'\n * - q: the interval quality (d, m, M, A)\n * - dir: interval direction (1 ascending, -1 descending)\n * - simple: the simplified number\n * - semitones: the size in semitones\n * - chroma: the interval chroma\n *\n * @param {string} interval - the interval name\n * @return {Object} the interval properties\n *\n * @example\n * import { interval } from '@tonaljs/core'\n * interval('P5').semitones // => 7\n * interval('m3').type // => 'majorable'\n */\nexport function interval(src: IntervalLiteral): Interval | NoInterval {\n return typeof src === \"string\"\n ? cache[src] || (cache[src] = parse(src))\n : isPitch(src)\n ? interval(pitchName(src))\n : isNamed(src)\n ? interval(src.name)\n : NoInterval;\n}\n\nconst SIZES = [0, 2, 4, 5, 7, 9, 11];\nconst TYPES = \"PMMPPMM\";\nfunction parse(str?: string): Interval | NoInterval {\n const tokens = tokenizeInterval(str);\n if (tokens[0] === \"\") {\n return NoInterval;\n }\n const num = +tokens[0];\n const q = tokens[1] as Quality;\n const step = (Math.abs(num) - 1) % 7;\n const t = TYPES[step];\n if (t === \"M\" && q === \"P\") {\n return NoInterval;\n }\n const type = t === \"M\" ? \"majorable\" : \"perfectable\";\n\n const name = \"\" + num + q;\n const dir = num < 0 ? -1 : 1;\n const simple = num === 8 || num === -8 ? num : dir * (step + 1);\n const alt = qToAlt(type, q);\n const oct = Math.floor((Math.abs(num) - 1) / 7);\n const semitones = dir * (SIZES[step] + alt + 12 * oct);\n const chroma = (((dir * (SIZES[step] + alt)) % 12) + 12) % 12;\n const coord = encode({ step, alt, oct, dir }) as IntervalCoordinates;\n return {\n empty: false,\n name,\n num,\n q,\n step,\n alt,\n dir,\n type,\n simple,\n semitones,\n chroma,\n coord,\n oct,\n };\n}\n\n/**\n * @private\n *\n * forceDescending is used in the case of unison (#243)\n */\nexport function coordToInterval(\n coord: PitchCoordinates,\n forceDescending?: boolean\n): Interval {\n const [f, o = 0] = coord;\n const isDescending = f * 7 + o * 12 < 0;\n const ivl: IntervalCoordinates =\n forceDescending || isDescending ? [-f, -o, -1] : [f, o, 1];\n return interval(decode(ivl)) as Interval;\n}\n\nfunction qToAlt(type: Type, q: string): number {\n return (q === \"M\" && type === \"majorable\") ||\n (q === \"P\" && type === \"perfectable\")\n ? 0\n : q === \"m\" && type === \"majorable\"\n ? -1\n : /^A+$/.test(q)\n ? q.length\n : /^d+$/.test(q)\n ? -1 * (type === \"perfectable\" ? q.length : q.length + 1)\n : 0;\n}\n\n// return the interval name of a pitch\nfunction pitchName(props: Pitch): string {\n const { step, alt, oct = 0, dir } = props;\n if (!dir) {\n return \"\";\n }\n const calcNum = step + 1 + 7 * oct;\n // this is an edge case: descending pitch class unison (see #243)\n const num = calcNum === 0 ? step + 1 : calcNum;\n const d = dir < 0 ? \"-\" : \"\";\n const type = TYPES[step] === \"M\" ? \"majorable\" : \"perfectable\";\n const name = d + num + altToQ(type, alt);\n return name;\n}\n\nfunction altToQ(type: Type, alt: number): Quality {\n if (alt === 0) {\n return type === \"majorable\" ? \"M\" : \"P\";\n } else if (alt === -1 && type === \"majorable\") {\n return \"m\";\n } else if (alt > 0) {\n return fillStr(\"A\", alt) as Quality;\n } else {\n return fillStr(\"d\", type === \"perfectable\" ? alt : alt + 1) as Quality;\n }\n}\n","import {\n coordToInterval,\n interval as asInterval,\n IntervalLiteral,\n IntervalName,\n} from \"./interval\";\nimport { coordToNote, note as asNote, NoteLiteral, NoteName } from \"./note\";\nimport { PitchCoordinates } from \"./pitch\";\n\n/**\n * Transpose a note by an interval.\n *\n * @param {string} note - the note or note name\n * @param {string} interval - the interval or interval name\n * @return {string} the transposed note name or empty string if not valid notes\n * @example\n * import { tranpose } from \"@tonaljs/core\"\n * transpose(\"d3\", \"3M\") // => \"F#3\"\n * transpose(\"D\", \"3M\") // => \"F#\"\n * [\"C\", \"D\", \"E\", \"F\", \"G\"].map(pc => transpose(pc, \"M3)) // => [\"E\", \"F#\", \"G#\", \"A\", \"B\"]\n */\nexport function transpose(\n noteName: NoteLiteral,\n intervalName: IntervalLiteral | [number, number]\n): NoteName {\n const note = asNote(noteName);\n const intervalCoord = Array.isArray(intervalName)\n ? intervalName\n : asInterval(intervalName).coord;\n if (note.empty || !intervalCoord || intervalCoord.length < 2) {\n return \"\";\n }\n const noteCoord = note.coord;\n const tr: PitchCoordinates =\n noteCoord.length === 1\n ? [noteCoord[0] + intervalCoord[0]]\n : [noteCoord[0] + intervalCoord[0], noteCoord[1] + intervalCoord[1]];\n return coordToNote(tr).name;\n}\n\n// Private\nexport function tonicIntervalsTransposer(\n intervals: string[],\n tonic: string | undefined | null\n) {\n const len = intervals.length;\n return (normalized: number) => {\n if (!tonic) return \"\";\n const index =\n normalized < 0 ? (len - (-normalized % len)) % len : normalized % len;\n const octaves = Math.floor(normalized / len);\n const root = transpose(tonic, [0, octaves]);\n return transpose(root, intervals[index]);\n };\n}\n\n/**\n * Find the interval distance between two notes or coord classes.\n *\n * To find distance between coord classes, both notes must be coord classes and\n * the interval is always ascending\n *\n * @param {Note|string} from - the note or note name to calculate distance from\n * @param {Note|string} to - the note or note name to calculate distance to\n * @return {string} the interval name or empty string if not valid notes\n *\n */\nexport function distance(\n fromNote: NoteLiteral,\n toNote: NoteLiteral\n): IntervalName {\n const from = asNote(fromNote);\n const to = asNote(toNote);\n if (from.empty || to.empty) {\n return \"\";\n }\n\n const fcoord = from.coord;\n const tcoord = to.coord;\n const fifths = tcoord[0] - fcoord[0];\n const octs =\n fcoord.length === 2 && tcoord.length === 2\n ? tcoord[1] - fcoord[1]\n : -Math.floor((fifths * 7) / 12);\n\n // If it's unison and not pitch class, it can be descending interval (#243)\n const forceDescending =\n to.height === from.height &&\n to.midi !== null &&\n from.midi !== null &&\n from.step > to.step;\n return coordToInterval([fifths, octs], forceDescending).name;\n}\n"],"mappings":";AAMO,IAAM,UAAU,CAAC,GAAW,MAAc,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;AAEvE,SAAS,UAEd,UAAkB,aAAqB,IAAc;AACrD,SAAO,YAA4B,MAAuC;AAExE,YAAQ,KAAK,GAAG,+BAA+B,cAAc;AAC7D,WAAO,GAAG,MAAM,MAAM,IAAI;AAAA,EAC5B;AACF;;;ACHO,SAAS,QAAQ,KAAwB;AAC9C,SAAO,QAAQ,QAAQ,OAAO,QAAQ,YAAY,OAAO,IAAI,SAAS,WAClE,OACA;AACN;;;ACYO,SAAS,QAAQ,OAA4B;AAClD,SAAO,UAAU,QACf,OAAO,UAAU,YACjB,OAAO,MAAM,SAAS,YACtB,OAAO,MAAM,QAAQ,WACnB,OACA;AACN;AAGA,IAAM,SAAS,CAAC,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;AAEpC,IAAM,gBAAgB,OAAO;AAAA,EAAI,CAAC,WAChC,KAAK,MAAO,SAAS,IAAK,EAAE;AAC9B;AAEO,SAAS,OAAO,OAAgC;AACrD,QAAM,EAAE,MAAM,KAAK,KAAK,MAAM,EAAE,IAAI;AACpC,QAAM,IAAI,OAAO,QAAQ,IAAI;AAC7B,MAAI,QAAQ,QAAW;AACrB,WAAO,CAAC,MAAM,CAAC;AAAA,EACjB;AACA,QAAM,IAAI,MAAM,cAAc,QAAQ,IAAI;AAC1C,SAAO,CAAC,MAAM,GAAG,M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A,EACzC;AACF;AAaO,SAAS,SACd,UACA,QACc;AACd,QAAM,OAAO,KAAO,QAAQ;AAC5B,QAAM,KAAK,KAAO,MAAM;AACxB,MAAI,KAAK,SAAS,GAAG,OAAO;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,KAAK;AACpB,QAAM,SAAS,GAAG;AAClB,QAAM,SAAS,OAAO,KAAK,OAAO;AAClC,QAAM,OACJ,OAAO,WAAW,KAAK,OAAO,WAAW,IACrC,OAAO,KAAK,OAAO,KACnB,CAAC,KAAK,MAAO,SAAS,IAAK,EAAE;AAGnC,QAAM,kBACJ,GAAG,WAAW,KAAK,UACnB,GAAG,SAAS,QACZ,KAAK,SAAS,QACd,KAAK,OAAO,GAAG;AACjB,SAAO,gBAAgB,CAAC,QAAQ,IAAI,GAAG,eAAe,EAAE;AAC1D;","names":["REGEX","cache","parse","pitchName","note"]}
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import { isNamedPitch } from \"@tonaljs/pitch\";\n\nexport * from \"@tonaljs/pitch\";\nexport * from \"@tonaljs/pitch-distance\";\nexport * from \"@tonaljs/pitch-interval\";\nexport * from \"@tonaljs/pitch-note\";\n\nexport const fillStr = (s: string, n: number) => Array(Math.abs(n) + 1).join(s);\n\nexport function deprecate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ResultFn extends (this: any, ...newArgs: any[]) => ReturnType<ResultFn>,\n>(original: string, alternative: string, fn: ResultFn) {\n return function (this: unknown, ...args: unknown[]): ReturnType<ResultFn> {\n // tslint:disable-next-line\n console.warn(`${original} is deprecated. Use ${alternative}.`);\n return fn.apply(this, args);\n };\n}\n\nexport const isNamed = deprecate(\"isNamed\", \"isNamedPitch\", isNamedPitch);\n"],"mappings":";AAAA,SAAS,oBAAoB;AAE7B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEP,IAAM,UAAU,CAAC,GAAW,MAAc,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;AAEvE,SAAS,UAGd,UAAkB,aAAqB,IAAc;AACrD,SAAO,YAA4B,MAAuC;AAExE,YAAQ,KAAK,GAAG,QAAQ,uBAAuB,WAAW,GAAG;AAC7D,WAAO,GAAG,MAAM,MAAM,IAAI;AAAA,EAC5B;AACF;AAEO,IAAM,UAAU,UAAU,WAAW,gBAAgB,YAAY;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonaljs/core",
3
- "version": "4.10.0",
3
+ "version": "4.10.3",
4
4
  "description": "Music theory library",
5
5
  "keywords": [
6
6
  "music",
@@ -17,6 +17,12 @@
17
17
  "publishConfig": {
18
18
  "access": "public"
19
19
  },
20
+ "dependencies": {
21
+ "@tonaljs/pitch": "^5.0.1",
22
+ "@tonaljs/pitch-interval": "^5.0.1",
23
+ "@tonaljs/pitch-distance": "^5.0.1",
24
+ "@tonaljs/pitch-note": "^5.0.1"
25
+ },
20
26
  "scripts": {
21
27
  "build": "tsup index.ts --sourcemap --dts --format esm,cjs"
22
28
  }