@libraz/libcantus 1.0.0 → 1.1.0
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 +27 -65
- package/README_ja.md +28 -66
- package/dist/analyze/index.cjs +11 -7
- package/dist/analyze/index.cjs.map +1 -1
- package/dist/analyze/index.d.cts +79 -144
- package/dist/analyze/index.d.ts +79 -144
- package/dist/analyze/index.js +20 -16
- package/dist/{chunk-TTCLJX6D.js → chunk-57WB2EDF.js} +10 -8
- package/dist/chunk-57WB2EDF.js.map +1 -0
- package/dist/chunk-5JJ6EHEZ.cjs +457 -0
- package/dist/chunk-5JJ6EHEZ.cjs.map +1 -0
- package/dist/{chunk-AFM2ULJH.cjs → chunk-5KW7DNCJ.cjs} +1567 -1067
- package/dist/chunk-5KW7DNCJ.cjs.map +1 -0
- package/dist/chunk-7GOKQJTQ.js +145 -0
- package/dist/chunk-7GOKQJTQ.js.map +1 -0
- package/dist/{chunk-H3VORETI.js → chunk-AWEMD747.js} +487 -592
- package/dist/chunk-AWEMD747.js.map +1 -0
- package/dist/{chunk-4A2RMUCC.js → chunk-DKICR7AN.js} +1216 -611
- package/dist/chunk-DKICR7AN.js.map +1 -0
- package/dist/{chunk-INHVXP6Z.js → chunk-FPBZFNCD.js} +1159 -415
- package/dist/chunk-FPBZFNCD.js.map +1 -0
- package/dist/{chunk-M4CWTJWJ.cjs → chunk-GDKE6RQW.cjs} +1453 -848
- package/dist/chunk-GDKE6RQW.cjs.map +1 -0
- package/dist/chunk-H66ARFU5.js +363 -0
- package/dist/chunk-H66ARFU5.js.map +1 -0
- package/dist/{chunk-YH3BIKHH.js → chunk-HOHFYGKW.js} +146 -49
- package/dist/chunk-HOHFYGKW.js.map +1 -0
- package/dist/chunk-HSY2VQXZ.js +2272 -0
- package/dist/chunk-HSY2VQXZ.js.map +1 -0
- package/dist/{chunk-E3F4AHAH.cjs → chunk-J772DL3B.cjs} +221 -134
- package/dist/chunk-J772DL3B.cjs.map +1 -0
- package/dist/chunk-K6OZXIR6.js +1 -0
- package/dist/{chunk-VTI6FOLB.js → chunk-PQL7E5F6.js} +709 -133
- package/dist/chunk-PQL7E5F6.js.map +1 -0
- package/dist/chunk-Q6R3QAZD.cjs +3329 -0
- package/dist/chunk-Q6R3QAZD.cjs.map +1 -0
- package/dist/{chunk-MXO72PLY.cjs → chunk-QCXYKSZS.cjs} +21 -19
- package/dist/chunk-QCXYKSZS.cjs.map +1 -0
- package/dist/{chunk-VOHZB45S.js → chunk-R5VUXQMP.js} +1321 -821
- package/dist/chunk-R5VUXQMP.js.map +1 -0
- package/dist/chunk-R7B5N2JK.cjs +363 -0
- package/dist/chunk-R7B5N2JK.cjs.map +1 -0
- package/dist/{chunk-WWURE4XT.cjs → chunk-RVS4G4MR.cjs} +624 -729
- package/dist/chunk-RVS4G4MR.cjs.map +1 -0
- package/dist/chunk-TT6PKMPR.cjs +145 -0
- package/dist/chunk-TT6PKMPR.cjs.map +1 -0
- package/dist/chunk-UGLFDG7L.cjs +1 -0
- package/dist/chunk-UGLFDG7L.cjs.map +1 -0
- package/dist/chunk-VLE5R7PF.js +3329 -0
- package/dist/chunk-VLE5R7PF.js.map +1 -0
- package/dist/{chunk-FVSI36UV.js → chunk-X6RJAHII.js} +197 -110
- package/dist/chunk-X6RJAHII.js.map +1 -0
- package/dist/{chunk-Q2WGKJNN.cjs → chunk-XKSO2V5I.cjs} +699 -123
- package/dist/chunk-XKSO2V5I.cjs.map +1 -0
- package/dist/chunk-XVMJO3QF.cjs +2272 -0
- package/dist/chunk-XVMJO3QF.cjs.map +1 -0
- package/dist/{chunk-UADYAYAT.cjs → chunk-YPB3A3EY.cjs} +1309 -565
- package/dist/chunk-YPB3A3EY.cjs.map +1 -0
- package/dist/{index-C_8o--VE.d.cts → coerce-CJlgULrQ.d.cts} +210 -199
- package/dist/{index-szBv3496.d.ts → coerce-wwdELNYS.d.ts} +210 -199
- package/dist/core/index.cjs +9 -5
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +122 -108
- package/dist/core/index.d.ts +122 -108
- package/dist/core/index.js +32 -28
- package/dist/generate/index.cjs +8 -8
- package/dist/generate/index.d.cts +168 -84
- package/dist/generate/index.d.ts +168 -84
- package/dist/generate/index.js +7 -7
- package/dist/{index-CGpRv5sl.d.cts → index-9eoQs2C1.d.ts} +34 -19
- package/dist/{index-Dzr13q3d.d.cts → index-B3WCj_Hm.d.cts} +135 -58
- package/dist/{index-BO6xE9YU.d.cts → index-BUtIf2go.d.ts} +460 -254
- package/dist/{index-CCNJRG-P.d.cts → index-BaoKVVhE.d.cts} +293 -56
- package/dist/{index-Chbst3Jx.d.ts → index-BpWOhkkE.d.ts} +135 -58
- package/dist/{index-BGFW-8P2.d.cts → index-BzLNkmA7.d.cts} +196 -114
- package/dist/{index-CunYKLiu.d.ts → index-CBCP84rv.d.cts} +1 -1
- package/dist/{index-BkGmlyI3.d.cts → index-Ci3xyows.d.ts} +60 -23
- package/dist/{index-9wcMhG73.d.ts → index-CnHQgqNh.d.ts} +293 -56
- package/dist/{index-B4o55NDr.d.cts → index-CnIdP4EZ.d.ts} +1 -1
- package/dist/{index-B9MNZboQ.d.ts → index-Cy15oTvh.d.cts} +52 -22
- package/dist/{index-B9MNZboQ.d.cts → index-Cy15oTvh.d.ts} +52 -22
- package/dist/{index-D57QRbVn.d.ts → index-DTsKaPaC.d.cts} +460 -254
- package/dist/{index-Cj49F892.d.ts → index-D_hzxD8w.d.cts} +60 -23
- package/dist/{index-CgHqxdps.d.ts → index-DpC-mDlV.d.ts} +196 -114
- package/dist/{index-G1uwGGWQ.d.ts → index-cHvbYgJI.d.cts} +34 -19
- package/dist/index.cjs +42 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.js +82 -54
- package/dist/{masks-DYbE485J.d.ts → masks-C8TWLFIi.d.cts} +49 -2
- package/dist/{masks-DYbE485J.d.cts → masks-O73Rhj5d.d.ts} +49 -2
- package/dist/model/index.cjs +19 -12
- package/dist/model/index.cjs.map +1 -1
- package/dist/model/index.d.cts +502 -181
- package/dist/model/index.d.ts +502 -181
- package/dist/model/index.js +18 -11
- package/dist/{positional-Cptlj-xs.d.ts → positional-DJgs6ltD.d.ts} +85 -8
- package/dist/{positional-DvH_sd8u.d.cts → positional-DMZer-FM.d.cts} +85 -8
- package/dist/theory/index.cjs +35 -6
- package/dist/theory/index.cjs.map +1 -1
- package/dist/theory/index.d.cts +257 -62
- package/dist/theory/index.d.ts +257 -62
- package/dist/theory/index.js +41 -12
- package/package.json +6 -5
- package/dist/chunk-3JXCW6DX.cjs +0 -3220
- package/dist/chunk-3JXCW6DX.cjs.map +0 -1
- package/dist/chunk-4A2RMUCC.js.map +0 -1
- package/dist/chunk-6XPTBE7Y.cjs +0 -49
- package/dist/chunk-6XPTBE7Y.cjs.map +0 -1
- package/dist/chunk-AFM2ULJH.cjs.map +0 -1
- package/dist/chunk-E3F4AHAH.cjs.map +0 -1
- package/dist/chunk-ELCTZUJJ.js +0 -379
- package/dist/chunk-ELCTZUJJ.js.map +0 -1
- package/dist/chunk-FVSI36UV.js.map +0 -1
- package/dist/chunk-GOZG57ER.js +0 -3220
- package/dist/chunk-GOZG57ER.js.map +0 -1
- package/dist/chunk-H3VORETI.js.map +0 -1
- package/dist/chunk-H42UHPYW.js +0 -1577
- package/dist/chunk-H42UHPYW.js.map +0 -1
- package/dist/chunk-HFPS7JFD.js +0 -1
- package/dist/chunk-INHVXP6Z.js.map +0 -1
- package/dist/chunk-K4ZJUGF4.cjs +0 -379
- package/dist/chunk-K4ZJUGF4.cjs.map +0 -1
- package/dist/chunk-KNJEKLKV.js +0 -49
- package/dist/chunk-KNJEKLKV.js.map +0 -1
- package/dist/chunk-M4CWTJWJ.cjs.map +0 -1
- package/dist/chunk-MXO72PLY.cjs.map +0 -1
- package/dist/chunk-NLEU4QSE.cjs +0 -360
- package/dist/chunk-NLEU4QSE.cjs.map +0 -1
- package/dist/chunk-OE6WK2Y2.cjs +0 -1577
- package/dist/chunk-OE6WK2Y2.cjs.map +0 -1
- package/dist/chunk-Q2WGKJNN.cjs.map +0 -1
- package/dist/chunk-RHIJ3S4I.cjs +0 -1
- package/dist/chunk-RHIJ3S4I.cjs.map +0 -1
- package/dist/chunk-TTCLJX6D.js.map +0 -1
- package/dist/chunk-UADYAYAT.cjs.map +0 -1
- package/dist/chunk-VOHZB45S.js.map +0 -1
- package/dist/chunk-VTI6FOLB.js.map +0 -1
- package/dist/chunk-WWURE4XT.cjs.map +0 -1
- package/dist/chunk-YH3BIKHH.js.map +0 -1
- /package/dist/{chunk-HFPS7JFD.js.map → chunk-K6OZXIR6.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/libcantus/libcantus/dist/chunk-MXO72PLY.cjs","../src/analyze/spelling/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AC0CA,IAAM,eAAA,EAAiB,EAAA;AAGvB,IAAM,oBAAA,EAAsB,EAAA;AAG5B,IAAM,sBAAA,EAAwB,CAAA;AAS9B,IAAM,sBAAA,EAAwB,CAAA;AAG9B,IAAM,kBAAA,EAAoB,CAAA;AAG1B,IAAM,aAAA,EAAe,CAAA;AAGrB,IAAM,WAAA,EAAa,CAAA;AAGnB,IAAM,SAAA,EAAW,CAAA;AAGjB,IAAM,UAAA,EAAY,CAAA;AASlB,IAAM,oBAAA,EAAsB,CAAA;AAY5B,IAAM,0BAAA,EAA4D;AAAA,EAChE,CAAC,CAAC,CAAA;AAAA;AAAA,EACF,CAAC,CAAA,EAAG,CAAC,CAAA;AAAA;AAAA,EACL,CAAC,CAAC,CAAA;AAAA;AAAA,EACF,CAAC,CAAC,CAAA;AAAA;AAAA,EACF,CAAC,CAAC,CAAA;AAAA;AAAA,EACF,CAAC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,GAAA,UAAK,GAAA;AAAA,EACpC;AACA,EAAA,OAAO,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,EAAA,oBAAU,KAAA,CAAM,UAAA,kBAAW,MAAA,CAAO,KAAK,CAAA,UAAK,GAAC,CAAA,UAAK,KAAA,CAAM,WAAS,CAAA;AAC7F;ADjPA;AACA;AACE;AACF,8BAAC","file":"/home/runner/work/libcantus/libcantus/dist/chunk-MXO72PLY.cjs","sourcesContent":[null,"/**\n * Line spelling: name every note of a melodic line in one pass.\n *\n * {@link spellPitch} decides one note from the key, the root of the chord under\n * it and its two immediate neighbours. That is enough for a single note, but a\n * line spelled note by note can zig-zag between the two readings of one idea —\n * a rising whole-tone figure comes out F# Ab Bb, with a diminished third in the\n * middle of it.\n *\n * This module solves the whole line at once. The theory layer's own judgment\n * becomes the cost of emitting a spelling, the melodic rules become the cost of\n * moving from one spelling to the next, and a dynamic program takes the\n * cheapest path across the line. Nothing here re-decides what\n * {@link spellPitchClass} and {@link spellChord} already decide: it only weighs\n * their answers against the shape of the line they sit in.\n */\n\nimport type { Note, NoteLike } from '../../core/pitch/index.js';\nimport {\n diatonicLetterOf as mod7,\n pitchClassOf as mod12,\n naturalPitchClassOf as naturalPc,\n toNoteData,\n} from '../../core/pitch/index.js';\nimport type { KeyScale, NoteEvent } from '../../core/types.js';\nimport { assertGenerationBudget, assertNoteEvents } from '../../core/validation/index.js';\nimport type { Chord } from '../../theory/chord/index.js';\nimport { isScaleTone, type KeyLike, spelledKeyOf, toKeyScale } from '../../theory/scale/index.js';\nimport { assertTonicOf, spellChord, spellPitchClass } from '../../theory/spelling/index.js';\nimport type { ChordTimeline } from '../timeline/index.js';\n\n/**\n * The four rules, and what happens where they pull against each other.\n *\n * The costs below are spread far enough apart that a rule can never be\n * outvoted by any number of the rules under it, which fixes the precedence:\n *\n * 1. **The sounding chord.** A note the chord names takes the chord's own\n * spelling of that tone. This is the one place the line departs from\n * {@link spellPitchClass}, which never respells a tone of the key: over a\n * Db7 the seventh has to read Cb even in C major, where B is a scale tone,\n * because a dominant seventh spelled as a sixth is not the chord that was\n * played.\n * 2. **The key's scale.** Anything else the key itself spells — a scale tone,\n * and the tonic — keeps that spelling, exactly as the note-by-note path\n * keeps it. No amount of melodic pressure moves it.\n * 3. **The shape of the line, then its direction.** A chromatic note is spelled\n * so the letters of the intervals around it match the intervals actually\n * sounding, and a stepwise line then prefers sharps rising and flats\n * falling. Shape outranks direction because a rising line spelled with\n * sharps is still wrong if it spells a whole tone as a diminished third.\n * 4. **The key's chromatic convention, then the fewest accidentals.** What the\n * key alone would have said, as the tiebreak it is: the direction rule beats\n * it, which is why a chromatic ascent in C major spells C# D# G# A# rather\n * than the flats the key prefers, but one-sided evidence — a chromatic note\n * with only one stepwise neighbour — does not.\n */\n\n/** Emission cost for a spelling the chord sounding under the note does not name. */\nconst CHORD_MISMATCH = 64;\n\n/** Emission cost for respelling a tone the key's own scale already names. */\nconst SCALE_TONE_MISMATCH = 32;\n\n/** Transition cost per diatonic step an interval's letters miss its written size by. */\nconst LETTER_STEP_DEVIATION = 4;\n\n/**\n * How many steps of deviation are counted before the cost stops growing.\n *\n * Two letters out is already an interval no reading supports, and capping there\n * keeps the whole melodic term below {@link SCALE_TONE_MISMATCH}, so a badly\n * shaped line can never argue a scale tone out of its key spelling.\n */\nconst MAX_COUNTED_DEVIATION = 2;\n\n/** Transition cost for an accidental leaning against the direction of a stepwise line. */\nconst AGAINST_DIRECTION = 3;\n\n/** Emission cost for a chromatic spelling the key alone would not choose. */\nconst KEY_MISMATCH = 4;\n\n/** Emission cost per semitone of alteration: what minimises accidentals overall. */\nconst ACCIDENTAL = 1;\n\n/** Widest melodic interval still counted as a step, where the direction rule applies. */\nconst MAX_STEP = 2;\n\n/** Widest alteration a spelling may carry: a double accidental. */\nconst MAX_ALTER = 2;\n\n/**\n * Spellings each pitch class has within a double accidental.\n *\n * Always exactly three — a natural or its accidental, one letter above, one\n * letter below (C is C, B# and Dbb) — which is what bounds the work the dynamic\n * program is allowed to do.\n */\nconst SPELLINGS_PER_PITCH = 3;\n\n/**\n * The diatonic letter distances a melodic interval of a given size is\n * conventionally written with, indexed by its semitone class.\n *\n * Most sizes read only one way: a whole tone is a second, a minor third is a\n * third, so spelling one as anything else costs. Two sizes read two ways and\n * both are free — a semitone is either a chromatic inflection of one letter\n * (F to F#) or a diatonic step (E to F), and the tritone is either an augmented\n * fourth or a diminished fifth. Direction chooses between those.\n */\nconst CONVENTIONAL_LETTER_STEPS: readonly (readonly number[])[] = [\n [0], // unison\n [0, 1], // chromatic semitone or diatonic semitone\n [1], // second\n [2], // minor third\n [2], // major third\n [3], // fourth\n [3, 4], // augmented fourth or diminished fifth\n [4], // fifth\n [5], // minor sixth\n [5], // major sixth\n [6], // minor seventh\n [6], // major seventh\n];\n\n/**\n * Options for {@link spellLine}.\n *\n * @category Arrangement & Analysis\n */\nexport type SpellLineOptions = {\n /**\n * Tonic spelling to anchor the key, for a caller that already knows how the\n * piece is written. It must sound the key's own root pitch class; anything\n * else is rejected rather than spelled. Defaults to the conventional\n * spelling `spelledKeyOf` gives the key. Accepted as a note name, a MIDI\n * number, note data, or a `Note`.\n */\n tonic?: NoteLike;\n /** Upper bound on the work the line may cost; defaults to the generation budget. */\n budget?: number;\n};\n\n/** Shortest signed alteration (in [-6, 6]) taking a letter's natural pc to `pc`. */\nfunction alterationFor(letter: number, pc: number): number {\n const distance = mod12(pc - naturalPc(letter));\n return distance > 6 ? distance - 12 : distance;\n}\n\n/** The octave that reproduces `pitch` from a letter and its alteration. */\nfunction octaveFor(pitch: number, letter: number, alter: number): number {\n return (pitch - naturalPc(letter) - alter) / 12 - 1;\n}\n\n/** Whether two spellings name the same letter with the same alteration. */\nfunction sameSpelling(a: Note, b: Note): boolean {\n return a.letter === b.letter && a.alter === b.alter;\n}\n\n/**\n * Every spelling of `pitch` within a double accidental, `preferred` first.\n *\n * The order is what settles a tie: two readings that cost the same are equally\n * defensible, and the one the theory layer would have chosen alone is then the\n * one that stands.\n */\nfunction candidatesFor(pitch: number, preferred: Note): Note[] {\n const pc = mod12(pitch);\n const rest: Note[] = [];\n for (let letter = 0; letter < 7; letter += 1) {\n const alter = alterationFor(letter, pc);\n if (Math.abs(alter) > MAX_ALTER || letter === preferred.letter) {\n continue;\n }\n rest.push({ letter, alter, octave: octaveFor(pitch, letter, alter) });\n }\n rest.sort((a, b) => Math.abs(a.alter) - Math.abs(b.alter) || a.letter - b.letter);\n return [\n {\n letter: preferred.letter,\n alter: preferred.alter,\n octave: octaveFor(pitch, preferred.letter, preferred.alter),\n },\n ...rest,\n ];\n}\n\n/**\n * The chord's own spelling of a pitch class, or undefined when the chord does\n * not sound it.\n *\n * The tones come from {@link spellChord}, so a chord carrying its own spellings\n * — a parsed symbol, an augmented sixth — is read by them; a slash bass outside\n * the chord's tones is spelled from its hint when it has one.\n */\nfunction chordSpellingOf(pc: number, chord: Chord, tonic: Note, key: KeyScale): Note | undefined {\n for (const tone of spellChord(chord, tonic, key)) {\n if (mod12(naturalPc(tone.letter) + tone.alter) === pc) {\n return tone;\n }\n }\n const bass = chord.bassPc;\n if (bass === undefined || mod12(bass) !== pc) {\n return undefined;\n }\n const hint = chord.bassSpelling;\n return hint !== undefined && mod12(naturalPc(hint.letter) + hint.alter) === pc\n ? { letter: mod7(hint.letter), alter: hint.alter }\n : spellPitchClass(pc, tonic, key);\n}\n\n/** One note of the line, with the spellings open to it and what each costs. */\ntype LineState = {\n pitch: number;\n /** True when the key does not already spell this pitch, so direction may decide. */\n chromatic: boolean;\n candidates: Note[];\n emissions: number[];\n /** The spelling the note-by-note path would have chosen, used as the fallback. */\n reference: Note;\n};\n\n/**\n * Weigh every spelling open to one note against what the chord and the key say\n * about it.\n *\n * The reference spelling is the theory layer's own answer — the chord's, when\n * the chord names the note, and the key's otherwise — and the cost of departing\n * from it is what ranks the three rules that do not depend on the neighbours.\n */\nfunction stateFor(pitch: number, chord: Chord | null, tonic: Note, key: KeyScale): LineState {\n const pc = mod12(pitch);\n const fromChord = chord === null ? undefined : chordSpellingOf(pc, chord, tonic, key);\n const scaleTone = isScaleTone(pc, key);\n const reference = fromChord ?? spellPitchClass(pc, tonic, key);\n const mismatch =\n fromChord !== undefined ? CHORD_MISMATCH : scaleTone ? SCALE_TONE_MISMATCH : KEY_MISMATCH;\n const candidates = candidatesFor(pitch, reference);\n return {\n pitch,\n chromatic: !scaleTone,\n candidates,\n emissions: candidates.map(\n (candidate) =>\n (sameSpelling(candidate, reference) ? 0 : mismatch) +\n ACCIDENTAL * Math.abs(candidate.alter),\n ),\n reference,\n };\n}\n\n/** A spelling's position on the diatonic ladder, octave included. */\nfunction diatonicIndex(note: Note): number {\n return note.letter + 7 * (note.octave ?? 0);\n}\n\n/**\n * What the letters of a melodic interval cost when they do not match the\n * interval that actually sounds.\n *\n * Both notes are already spelled, so the sounding interval and the written one\n * are both known: a whole tone written F# to Ab is two letters apart where a\n * second is one, and pays for the difference.\n */\nfunction letterStepCost(from: Note, to: Note, semitones: number): number {\n const written = diatonicIndex(to) - diatonicIndex(from);\n const size = Math.abs(semitones);\n const octaves = Math.floor(size / 12);\n const direction = semitones < 0 ? -1 : 1;\n let deviation = Number.POSITIVE_INFINITY;\n for (const steps of CONVENTIONAL_LETTER_STEPS[size % 12] ?? []) {\n deviation = Math.min(deviation, Math.abs(written - direction * (octaves * 7 + steps)));\n }\n if (!Number.isFinite(deviation)) {\n return 0;\n }\n return LETTER_STEP_DEVIATION * Math.min(deviation, MAX_COUNTED_DEVIATION);\n}\n\n/**\n * What an accidental costs for leaning the wrong way in a stepwise line: a\n * rising line is written with sharps and a falling one with flats.\n *\n * Only steps are judged. The rule describes chromatic motion, and a leap onto a\n * flat says nothing about the flat — the key and the chord have the whole story\n * there.\n */\nfunction directionCost(note: Note, chromatic: boolean, semitones: number): number {\n if (!chromatic || semitones === 0 || Math.abs(semitones) > MAX_STEP) {\n return 0;\n }\n const rising = semitones > 0;\n return (rising && note.alter < 0) || (!rising && note.alter > 0) ? AGAINST_DIRECTION : 0;\n}\n\n/**\n * The cost of following one spelling with another.\n *\n * Direction is charged to both notes: a chromatic note is judged by the step it\n * arrives on and by the step it leaves on, so a note inside a run collects the\n * rule twice and a note at the end of one collects it once.\n */\nfunction transitionCost(from: LineState, source: Note, to: LineState, target: Note): number {\n const semitones = to.pitch - from.pitch;\n return (\n letterStepCost(source, target, semitones) +\n directionCost(target, to.chromatic, semitones) +\n directionCost(source, from.chromatic, semitones)\n );\n}\n\n/**\n * Spell a whole melodic line at once, so its notes agree with each other.\n *\n * Every note is spelled together with the rest of the line rather than one at a\n * time: each pitch offers the three spellings a double accidental allows, the\n * chord and the key price them, the intervals between neighbours price the\n * pairs, and the cheapest reading of the whole line wins. Ties fall to the\n * spelling {@link spellPitchClass} would have chosen alone, so the answer never\n * drifts from the theory layer without a reason.\n *\n * Four rules decide, in this order:\n *\n * 1. A note the sounding chord names takes that chord's spelling of it, even\n * when the key spells the pitch otherwise — the seventh of a Db7 reads Cb in\n * C major, not B.\n * 2. Anything else the key's scale spells keeps its key spelling, exactly as\n * the note-by-note path keeps it.\n * 3. A chromatic note is spelled so the written intervals around it match the\n * sounding ones, and then so a rising step carries a sharp and a falling\n * step a flat.\n * 4. Failing all of that, the key's own chromatic spelling stands, and the\n * fewest accidentals win.\n *\n * Without a timeline — pass `null` — rules 2 to 4 still apply in full, so a\n * diatonic line and a chromatic run come out the same. What is lost is rule 1:\n * a chromatic chord can no longer name its own tones, so the tones of a\n * borrowed or altered chord fall back to the key's convention (that Cb becomes\n * B), and an enharmonically ambiguous tone under a chord that would have fixed\n * it is decided by the line's direction instead.\n *\n * @param notes The line, monophonic and in time order. Notes sharing an onset\n * are read as consecutive, so split polyphonic material into voices first.\n * @param timeline The chords sounding under the line, or null when only the key\n * is known. Each note is judged against the chord at its own onset.\n * @param key The key the line is written in, as a key name, a key/scale, or a\n * `Key`.\n * @param opts Optional tonic spelling and work budget.\n * @returns One spelled note per input note, in input order, each carrying the\n * octave that reproduces its pitch.\n * @throws If `opts.tonic` does not sound the key's root pitch class, if a note\n * event is malformed, or if the line is longer than the budget allows.\n * @example\n * ```ts\n * import { chordTimelineFromChords, majorKey, noteNames, spellLine } from '@libraz/libcantus';\n * // A chromatic ascent spells with sharps, whatever the key would say alone.\n * const rising = [60, 61, 62, 63, 64].map((pitch, index) => ({\n * pitch,\n * startBeat: index,\n * durationBeat: 1,\n * }));\n * noteNames(spellLine(rising, null, majorKey(0)));\n * // ['C4', 'C#4', 'D4', 'D#4', 'E4']\n * // Under a Db7 the same B sounds as the chord's seventh.\n * const timeline = chordTimelineFromChords([{ rootPc: 1, quality: 'dom7', startBeat: 0 }], 4);\n * noteNames(spellLine([{ pitch: 71, startBeat: 0, durationBeat: 1 }], timeline, majorKey(0)));\n * // ['Cb5']\n * ```\n * @category Arrangement & Analysis\n */\nexport function spellLine(\n notes: readonly NoteEvent[],\n timeline: ChordTimeline | null,\n key: KeyLike,\n opts: SpellLineOptions = {},\n): Note[] {\n const scale = toKeyScale(key);\n const given = opts.tonic === undefined ? undefined : toNoteData(opts.tonic);\n assertNoteEvents(notes, 'line notes', {\n allowNonPositiveDuration: true,\n budget: opts.budget,\n });\n // The dynamic program compares every spelling of a note with every spelling\n // of the one before it, so the work is bounded before any of it is done.\n assertGenerationBudget(\n notes.length * SPELLINGS_PER_PITCH * SPELLINGS_PER_PITCH,\n 'line spelling states',\n opts.budget,\n );\n if (given !== undefined) {\n assertTonicOf(given, scale, 'spellLine');\n }\n if (notes.length === 0) {\n return [];\n }\n const tonic = given ?? spelledKeyOf(scale).tonic;\n const states = notes.map((note) =>\n stateFor(note.pitch, timeline?.at(note.startBeat) ?? null, tonic, scale),\n );\n\n // Viterbi across the line: `costs` holds the cheapest path reaching each\n // spelling of the current note, and `back` remembers which spelling of the\n // previous note that path came through.\n let costs: number[] = [];\n let previous: LineState | undefined;\n const back: number[][] = [];\n for (const current of states) {\n if (previous === undefined) {\n costs = [...current.emissions];\n back.push(current.candidates.map(() => 0));\n previous = current;\n continue;\n }\n const reached: number[] = [];\n const chosen: number[] = [];\n for (const [target, candidate] of current.candidates.entries()) {\n let best = Number.POSITIVE_INFINITY;\n let bestSource = 0;\n for (const [source, sourceNote] of previous.candidates.entries()) {\n const total =\n (costs[source] ?? Number.POSITIVE_INFINITY) +\n transitionCost(previous, sourceNote, current, candidate);\n if (total < best) {\n best = total;\n bestSource = source;\n }\n }\n reached.push(best + (current.emissions[target] ?? 0));\n chosen.push(bestSource);\n }\n costs = reached;\n back.push(chosen);\n previous = current;\n }\n\n let cursor = 0;\n for (const [index, cost] of costs.entries()) {\n if (cost < (costs[cursor] ?? Number.POSITIVE_INFINITY)) {\n cursor = index;\n }\n }\n const picked: number[] = new Array(states.length).fill(0);\n for (let index = states.length - 1; index >= 0; index -= 1) {\n picked[index] = cursor;\n cursor = back[index]?.[cursor] ?? 0;\n }\n return states.map((state, index) => state.candidates[picked[index] ?? 0] ?? state.reference);\n}\n"]}
|
package/dist/chunk-NLEU4QSE.cjs
DELETED
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _chunkQ2WGKJNNcjs = require('./chunk-Q2WGKJNN.cjs');
|
|
11
|
-
|
|
12
|
-
// src/core/duration/index.ts
|
|
13
|
-
var NOTE_VALUES = Object.freeze([
|
|
14
|
-
"whole",
|
|
15
|
-
"half",
|
|
16
|
-
"quarter",
|
|
17
|
-
"eighth",
|
|
18
|
-
"sixteenth",
|
|
19
|
-
"thirtySecond",
|
|
20
|
-
"sixtyFourth"
|
|
21
|
-
]);
|
|
22
|
-
var NOTE_VALUE_QUARTERS = Object.freeze({
|
|
23
|
-
whole: 4,
|
|
24
|
-
half: 2,
|
|
25
|
-
quarter: 1,
|
|
26
|
-
eighth: 0.5,
|
|
27
|
-
sixteenth: 0.25,
|
|
28
|
-
thirtySecond: 0.125,
|
|
29
|
-
sixtyFourth: 0.0625
|
|
30
|
-
});
|
|
31
|
-
var EPS = 1e-6;
|
|
32
|
-
var MAX_SPELLED_DOTS = 2;
|
|
33
|
-
var MAX_DOTS = 4;
|
|
34
|
-
var MAX_TUPLET = 64;
|
|
35
|
-
var SPELLED_TUPLETS = Object.freeze([
|
|
36
|
-
void 0,
|
|
37
|
-
{ actual: 3, normal: 2 },
|
|
38
|
-
{ actual: 5, normal: 4 },
|
|
39
|
-
{ actual: 7, normal: 4 }
|
|
40
|
-
]);
|
|
41
|
-
function quartersOfParts(base, dots, tuplet) {
|
|
42
|
-
const dotted = NOTE_VALUE_QUARTERS[base] * (2 - 2 ** -dots);
|
|
43
|
-
return tuplet === void 0 ? dotted : dotted * tuplet.normal / tuplet.actual;
|
|
44
|
-
}
|
|
45
|
-
function assertDuration(value, name) {
|
|
46
|
-
if (typeof value === "string") {
|
|
47
|
-
return { base: _chunkQ2WGKJNNcjs.assertOneOf.call(void 0, value, NOTE_VALUES, name), dots: 0 };
|
|
48
|
-
}
|
|
49
|
-
if (typeof value !== "object" || value === null) {
|
|
50
|
-
throw new (0, _chunkQ2WGKJNNcjs.InvalidInputError)(`${name} must be a note value or a duration; received ${value}`);
|
|
51
|
-
}
|
|
52
|
-
const base = _chunkQ2WGKJNNcjs.assertOneOf.call(void 0, value.base, NOTE_VALUES, `${name}.base`);
|
|
53
|
-
const dots = value.dots === void 0 ? 0 : _chunkQ2WGKJNNcjs.assertInteger.call(void 0, value.dots, `${name}.dots`, 0, MAX_DOTS);
|
|
54
|
-
if (value.tuplet === void 0) {
|
|
55
|
-
return { base, dots };
|
|
56
|
-
}
|
|
57
|
-
const tuplet = {
|
|
58
|
-
actual: _chunkQ2WGKJNNcjs.assertPositiveInt.call(void 0, value.tuplet.actual, `${name}.tuplet.actual`, MAX_TUPLET),
|
|
59
|
-
normal: _chunkQ2WGKJNNcjs.assertPositiveInt.call(void 0, value.tuplet.normal, `${name}.tuplet.normal`, MAX_TUPLET)
|
|
60
|
-
};
|
|
61
|
-
return { base, dots, tuplet };
|
|
62
|
-
}
|
|
63
|
-
function quartersOf(duration) {
|
|
64
|
-
return quartersOfParts(duration.base, _nullishCoalesce(duration.dots, () => ( 0)), duration.tuplet);
|
|
65
|
-
}
|
|
66
|
-
function beatQuarters(options) {
|
|
67
|
-
if (options.beatUnit === void 0) {
|
|
68
|
-
return NOTE_VALUE_QUARTERS.quarter;
|
|
69
|
-
}
|
|
70
|
-
return quartersOf(assertDuration(options.beatUnit, "beatUnit"));
|
|
71
|
-
}
|
|
72
|
-
function spellQuarters(quarters) {
|
|
73
|
-
for (const tuplet of SPELLED_TUPLETS) {
|
|
74
|
-
for (let dots = 0; dots <= MAX_SPELLED_DOTS; dots += 1) {
|
|
75
|
-
for (const base of NOTE_VALUES) {
|
|
76
|
-
if (Math.abs(quartersOfParts(base, dots, tuplet) - quarters) <= EPS) {
|
|
77
|
-
return tuplet === void 0 ? { base, dots } : { base, dots, tuplet: { actual: tuplet.actual, normal: tuplet.normal } };
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return void 0;
|
|
83
|
-
}
|
|
84
|
-
var PLAIN_VALUES = Object.freeze(
|
|
85
|
-
NOTE_VALUES.map((base) => ({ base, quarters: NOTE_VALUE_QUARTERS[base] }))
|
|
86
|
-
);
|
|
87
|
-
function assertPositiveBeats(beats, name) {
|
|
88
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, beats, name);
|
|
89
|
-
if (beats <= 0) {
|
|
90
|
-
throw new (0, _chunkQ2WGKJNNcjs.InvalidInputError)(`${name} must be positive; received ${beats}`);
|
|
91
|
-
}
|
|
92
|
-
return beats;
|
|
93
|
-
}
|
|
94
|
-
function durationToBeats(duration, options = {}) {
|
|
95
|
-
const quarters = quartersOf(assertDuration(duration, "duration"));
|
|
96
|
-
return quarters / beatQuarters(options);
|
|
97
|
-
}
|
|
98
|
-
function beatsToDuration(beats, options = {}) {
|
|
99
|
-
assertPositiveBeats(beats, "beats");
|
|
100
|
-
const spelled = spellQuarters(beats * beatQuarters(options));
|
|
101
|
-
if (spelled === void 0) {
|
|
102
|
-
throw new (0, _chunkQ2WGKJNNcjs.NoSolutionError)(`no single note value spells ${beats} beats`);
|
|
103
|
-
}
|
|
104
|
-
return spelled;
|
|
105
|
-
}
|
|
106
|
-
function beatsToTiedDurations(beats, options = {}) {
|
|
107
|
-
assertPositiveBeats(beats, "beats");
|
|
108
|
-
const quarters = beats * beatQuarters(options);
|
|
109
|
-
const single = spellQuarters(quarters);
|
|
110
|
-
if (single !== void 0) {
|
|
111
|
-
return [single];
|
|
112
|
-
}
|
|
113
|
-
_chunkQ2WGKJNNcjs.assertGenerationBudget.call(void 0,
|
|
114
|
-
Math.ceil(quarters / NOTE_VALUE_QUARTERS.whole) + PLAIN_VALUES.length,
|
|
115
|
-
"tie chain length"
|
|
116
|
-
);
|
|
117
|
-
const chain = [];
|
|
118
|
-
let remaining = quarters;
|
|
119
|
-
let previousQuarters = 0;
|
|
120
|
-
while (remaining > EPS) {
|
|
121
|
-
const next = PLAIN_VALUES.find((candidate) => candidate.quarters <= remaining + EPS);
|
|
122
|
-
if (next === void 0) {
|
|
123
|
-
throw new (0, _chunkQ2WGKJNNcjs.NoSolutionError)(`no chain of tied note values sums to ${beats} beats`);
|
|
124
|
-
}
|
|
125
|
-
const last = chain[chain.length - 1];
|
|
126
|
-
if (last !== void 0 && last.dots < MAX_SPELLED_DOTS && Math.abs(next.quarters * 2 - previousQuarters) <= EPS) {
|
|
127
|
-
last.dots += 1;
|
|
128
|
-
} else {
|
|
129
|
-
chain.push({ base: next.base, dots: 0 });
|
|
130
|
-
}
|
|
131
|
-
previousQuarters = next.quarters;
|
|
132
|
-
remaining -= next.quarters;
|
|
133
|
-
}
|
|
134
|
-
return chain;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/core/tempo/index.ts
|
|
138
|
-
var SECONDS_PER_MINUTE = 60;
|
|
139
|
-
var MAX_BPM = 1e3;
|
|
140
|
-
function assertTempoMap(map, name = "tempo map") {
|
|
141
|
-
if (!Array.isArray(map) || map.length === 0) {
|
|
142
|
-
throw new (0, _chunkQ2WGKJNNcjs.InvalidInputError)(`${name} must hold at least one tempo event`);
|
|
143
|
-
}
|
|
144
|
-
for (let index = 0; index < map.length; index += 1) {
|
|
145
|
-
const event = map[index];
|
|
146
|
-
if (event === void 0) {
|
|
147
|
-
throw new (0, _chunkQ2WGKJNNcjs.InvalidInputError)(`${name}[${index}] must be a tempo event; received undefined`);
|
|
148
|
-
}
|
|
149
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, event.startBeat, `${name}[${index}].startBeat`);
|
|
150
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, event.bpm, Number.MIN_VALUE, MAX_BPM, `${name}[${index}].bpm`);
|
|
151
|
-
const previous = map[index - 1];
|
|
152
|
-
if (previous !== void 0 && event.startBeat <= previous.startBeat) {
|
|
153
|
-
throw new (0, _chunkQ2WGKJNNcjs.InvalidInputError)(
|
|
154
|
-
`${name} must be sorted by startBeat with no repeats; [${index}].startBeat ${event.startBeat} does not follow ${previous.startBeat}`
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return map;
|
|
159
|
-
}
|
|
160
|
-
function firstEvent(map) {
|
|
161
|
-
const first = map[0];
|
|
162
|
-
if (first === void 0) {
|
|
163
|
-
throw new (0, _chunkQ2WGKJNNcjs.InvalidInputError)("tempo map must hold at least one tempo event");
|
|
164
|
-
}
|
|
165
|
-
return first;
|
|
166
|
-
}
|
|
167
|
-
function integrateSeconds(map, fromBeat, toBeat) {
|
|
168
|
-
if (toBeat < fromBeat) {
|
|
169
|
-
return -integrateSeconds(map, toBeat, fromBeat);
|
|
170
|
-
}
|
|
171
|
-
let seconds = 0;
|
|
172
|
-
for (let index = 0; index < map.length; index += 1) {
|
|
173
|
-
const event = map[index];
|
|
174
|
-
if (event === void 0) {
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
const segmentStart = index === 0 ? Number.NEGATIVE_INFINITY : event.startBeat;
|
|
178
|
-
const segmentEnd = _nullishCoalesce(_optionalChain([map, 'access', _ => _[index + 1], 'optionalAccess', _2 => _2.startBeat]), () => ( Number.POSITIVE_INFINITY));
|
|
179
|
-
const low = Math.max(fromBeat, segmentStart);
|
|
180
|
-
const high = Math.min(toBeat, segmentEnd);
|
|
181
|
-
if (high > low) {
|
|
182
|
-
seconds += (high - low) * SECONDS_PER_MINUTE / event.bpm;
|
|
183
|
-
}
|
|
184
|
-
if (toBeat <= segmentEnd) {
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return seconds;
|
|
189
|
-
}
|
|
190
|
-
function beatsToSeconds(beat, map) {
|
|
191
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, beat, "beat");
|
|
192
|
-
assertTempoMap(map);
|
|
193
|
-
return integrateSeconds(map, firstEvent(map).startBeat, beat);
|
|
194
|
-
}
|
|
195
|
-
function secondsToBeats(seconds, map) {
|
|
196
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, seconds, "seconds");
|
|
197
|
-
assertTempoMap(map);
|
|
198
|
-
const origin = firstEvent(map);
|
|
199
|
-
if (seconds < 0) {
|
|
200
|
-
return origin.startBeat + seconds * origin.bpm / SECONDS_PER_MINUTE;
|
|
201
|
-
}
|
|
202
|
-
let remaining = seconds;
|
|
203
|
-
for (let index = 0; index < map.length - 1; index += 1) {
|
|
204
|
-
const event = map[index];
|
|
205
|
-
const next = map[index + 1];
|
|
206
|
-
if (event === void 0 || next === void 0) {
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
const spanSeconds = (next.startBeat - event.startBeat) * SECONDS_PER_MINUTE / event.bpm;
|
|
210
|
-
if (remaining < spanSeconds) {
|
|
211
|
-
return event.startBeat + remaining * event.bpm / SECONDS_PER_MINUTE;
|
|
212
|
-
}
|
|
213
|
-
remaining -= spanSeconds;
|
|
214
|
-
}
|
|
215
|
-
const last = map[map.length - 1];
|
|
216
|
-
if (last === void 0) {
|
|
217
|
-
throw new (0, _chunkQ2WGKJNNcjs.InvalidInputError)("tempo map must hold at least one tempo event");
|
|
218
|
-
}
|
|
219
|
-
return last.startBeat + remaining * last.bpm / SECONDS_PER_MINUTE;
|
|
220
|
-
}
|
|
221
|
-
function durationToSeconds(startBeat, lengthBeats, map) {
|
|
222
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, startBeat, "startBeat");
|
|
223
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, lengthBeats, 0, Number.MAX_SAFE_INTEGER, "lengthBeats");
|
|
224
|
-
assertTempoMap(map);
|
|
225
|
-
return integrateSeconds(map, startBeat, startBeat + lengthBeats);
|
|
226
|
-
}
|
|
227
|
-
function tempoAt(beat, map) {
|
|
228
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, beat, "beat");
|
|
229
|
-
assertTempoMap(map);
|
|
230
|
-
let bpm = firstEvent(map).bpm;
|
|
231
|
-
for (const event of map) {
|
|
232
|
-
if (event.startBeat > beat) {
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
bpm = event.bpm;
|
|
236
|
-
}
|
|
237
|
-
return bpm;
|
|
238
|
-
}
|
|
239
|
-
function beatsToTicks(beat, ppq) {
|
|
240
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, beat, "beat");
|
|
241
|
-
_chunkQ2WGKJNNcjs.assertPositiveInt.call(void 0, ppq, "ppq");
|
|
242
|
-
return Math.round(beat * ppq);
|
|
243
|
-
}
|
|
244
|
-
function ticksToBeats(ticks, ppq) {
|
|
245
|
-
_chunkQ2WGKJNNcjs.assertInteger.call(void 0, ticks, "ticks");
|
|
246
|
-
_chunkQ2WGKJNNcjs.assertPositiveInt.call(void 0, ppq, "ppq");
|
|
247
|
-
return ticks / ppq;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// src/core/tuning/index.ts
|
|
251
|
-
var TWELVE_TET = Object.freeze({ refStep: 69, refFreq: 440, divisions: 12 });
|
|
252
|
-
function assertTuning(tuning) {
|
|
253
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, tuning.refStep, "tuning.refStep");
|
|
254
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, tuning.refFreq, Number.MIN_VALUE, Number.MAX_VALUE, "tuning.refFreq");
|
|
255
|
-
_chunkQ2WGKJNNcjs.assertPositiveInt.call(void 0, tuning.divisions, "tuning.divisions");
|
|
256
|
-
return tuning;
|
|
257
|
-
}
|
|
258
|
-
function edo(n, refFreq = 440, refStep = 69) {
|
|
259
|
-
_chunkQ2WGKJNNcjs.assertPositiveInt.call(void 0, n, "EDO divisions");
|
|
260
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, refFreq, Number.MIN_VALUE, Number.MAX_VALUE, "reference frequency");
|
|
261
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, refStep, "reference step");
|
|
262
|
-
return { refStep, refFreq, divisions: n };
|
|
263
|
-
}
|
|
264
|
-
function frequencyOf(step, tuning = TWELVE_TET) {
|
|
265
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, step, "step");
|
|
266
|
-
assertTuning(tuning);
|
|
267
|
-
const result = tuning.refFreq * 2 ** ((step - tuning.refStep) / tuning.divisions);
|
|
268
|
-
return _chunkQ2WGKJNNcjs.assertRange.call(void 0, result, Number.MIN_VALUE, Number.MAX_VALUE, "frequency result");
|
|
269
|
-
}
|
|
270
|
-
function nearestStep(freq, tuning = TWELVE_TET) {
|
|
271
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, freq, Number.MIN_VALUE, Number.MAX_VALUE, "frequency");
|
|
272
|
-
assertTuning(tuning);
|
|
273
|
-
return Math.round(tuning.refStep + tuning.divisions * Math.log2(freq / tuning.refFreq));
|
|
274
|
-
}
|
|
275
|
-
function stepOf(freq, tuning = TWELVE_TET) {
|
|
276
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, freq, Number.MIN_VALUE, Number.MAX_VALUE, "frequency");
|
|
277
|
-
assertTuning(tuning);
|
|
278
|
-
return tuning.refStep + tuning.divisions * Math.log2(freq / tuning.refFreq);
|
|
279
|
-
}
|
|
280
|
-
function centsFromNearestStep(freq, tuning = TWELVE_TET) {
|
|
281
|
-
const exact = stepOf(freq, tuning);
|
|
282
|
-
return centsOfSteps(exact - Math.round(exact), tuning);
|
|
283
|
-
}
|
|
284
|
-
function stepsOfCents(cents, tuning = TWELVE_TET) {
|
|
285
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, cents, "cents");
|
|
286
|
-
assertTuning(tuning);
|
|
287
|
-
return _chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, cents * tuning.divisions / 1200, "steps result");
|
|
288
|
-
}
|
|
289
|
-
function centsToRatio(cents) {
|
|
290
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, cents, "cents");
|
|
291
|
-
return 2 ** (cents / 1200);
|
|
292
|
-
}
|
|
293
|
-
function centsBetweenFreq(a, b) {
|
|
294
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, a, Number.MIN_VALUE, Number.MAX_VALUE, "first frequency");
|
|
295
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, b, Number.MIN_VALUE, Number.MAX_VALUE, "second frequency");
|
|
296
|
-
return 1200 * (Math.log2(b) - Math.log2(a));
|
|
297
|
-
}
|
|
298
|
-
function centsOfSteps(steps, tuning = TWELVE_TET) {
|
|
299
|
-
_chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, steps, "steps");
|
|
300
|
-
assertTuning(tuning);
|
|
301
|
-
return _chunkQ2WGKJNNcjs.assertFiniteNumber.call(void 0, steps * 1200 / tuning.divisions, "cents result");
|
|
302
|
-
}
|
|
303
|
-
function ratioToCents(numerator, denominator) {
|
|
304
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, numerator, Number.MIN_VALUE, Number.MAX_VALUE, "ratio numerator");
|
|
305
|
-
_chunkQ2WGKJNNcjs.assertRange.call(void 0, denominator, Number.MIN_VALUE, Number.MAX_VALUE, "ratio denominator");
|
|
306
|
-
return 1200 * (Math.log2(numerator) - Math.log2(denominator));
|
|
307
|
-
}
|
|
308
|
-
function justRatio(numerator, denominator) {
|
|
309
|
-
return Object.freeze([numerator, denominator]);
|
|
310
|
-
}
|
|
311
|
-
var JUST_RATIOS = Object.freeze({
|
|
312
|
-
0: justRatio(1, 1),
|
|
313
|
-
1: justRatio(16, 15),
|
|
314
|
-
2: justRatio(9, 8),
|
|
315
|
-
3: justRatio(6, 5),
|
|
316
|
-
4: justRatio(5, 4),
|
|
317
|
-
5: justRatio(4, 3),
|
|
318
|
-
6: justRatio(45, 32),
|
|
319
|
-
7: justRatio(3, 2),
|
|
320
|
-
8: justRatio(8, 5),
|
|
321
|
-
9: justRatio(5, 3),
|
|
322
|
-
10: justRatio(9, 5),
|
|
323
|
-
11: justRatio(15, 8),
|
|
324
|
-
12: justRatio(2, 1)
|
|
325
|
-
});
|
|
326
|
-
function justDeviationCents(semitoneClass) {
|
|
327
|
-
_chunkQ2WGKJNNcjs.assertInteger.call(void 0, semitoneClass, "semitone class", 0, 12);
|
|
328
|
-
const ratio = JUST_RATIOS[semitoneClass];
|
|
329
|
-
if (!ratio) {
|
|
330
|
-
throw new (0, _chunkQ2WGKJNNcjs.InvalidInputError)(`semitone class has no just ratio: ${semitoneClass}`);
|
|
331
|
-
}
|
|
332
|
-
return ratioToCents(ratio[0], ratio[1]) - semitoneClass * 100;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
exports.NOTE_VALUES = NOTE_VALUES; exports.durationToBeats = durationToBeats; exports.beatsToDuration = beatsToDuration; exports.beatsToTiedDurations = beatsToTiedDurations; exports.beatsToSeconds = beatsToSeconds; exports.secondsToBeats = secondsToBeats; exports.durationToSeconds = durationToSeconds; exports.tempoAt = tempoAt; exports.beatsToTicks = beatsToTicks; exports.ticksToBeats = ticksToBeats; exports.TWELVE_TET = TWELVE_TET; exports.edo = edo; exports.frequencyOf = frequencyOf; exports.nearestStep = nearestStep; exports.stepOf = stepOf; exports.centsFromNearestStep = centsFromNearestStep; exports.stepsOfCents = stepsOfCents; exports.centsToRatio = centsToRatio; exports.centsBetweenFreq = centsBetweenFreq; exports.centsOfSteps = centsOfSteps; exports.ratioToCents = ratioToCents; exports.JUST_RATIOS = JUST_RATIOS; exports.justDeviationCents = justDeviationCents;
|
|
360
|
-
//# sourceMappingURL=chunk-NLEU4QSE.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/libcantus/libcantus/dist/chunk-NLEU4QSE.cjs","../src/core/duration/index.ts","../src/core/tempo/index.ts","../src/core/tuning/index.ts"],"names":[],"mapp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F1DiC;AACA;AGnNsB;AAEC;AAC5B,EAAA;AACE,EAAA;AACH,EAAA;AAClB,EAAA;AACT;AAiB8C;AACvB,EAAA;AACO,EAAA;AACA,EAAA;AACD,EAAA;AAC7B;AAgB0C;AACT,EAAA;AACZ,EAAA;AACG,EAAA;AACK,EAAA;AAC7B;AAW0C;AACf,EAAA;AACN,EAAA;AACM,EAAA;AAC3B;AAmB2D;AAChC,EAAA;AACN,EAAA;AACY,EAAA;AACjC;AAiBqC;AACR,EAAA;AACC,EAAA;AAC9B;AAW4C;AAChB,EAAA;AACP,EAAA;AACQ,EAAA;AAC7B;AAkBoD;AACxB,EAAA;AACL,EAAA;AACvB;AAU+D;AACvC,EAAA;AACA,EAAA;AACQ,EAAA;AAChC;AAU4C;AAChB,EAAA;AACP,EAAA;AACQ,EAAA;AAC7B;AAWgD;AAChB,EAAA;AACL,EAAA;AACA,EAAA;AAC3B;AAQsC;AACd,EAAA;AACxB;AAQ8F;AAC3E,EAAA;AACE,EAAA;AACF,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACE,EAAA;AACF,EAAA;AACA,EAAA;AACA,EAAA;AACC,EAAA;AACC,EAAA;AACD,EAAA;AACnB;AAWkC;AACJ,EAAA;AACH,EAAA;AACd,EAAA;AACkB,IAAA;AAC9B,EAAA;AAC8B,EAAA;AAChC;AH0DiC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/libcantus/libcantus/dist/chunk-NLEU4QSE.cjs","sourcesContent":[null,"/**\n * Note values: the written durations a score shows — a base value, its\n * augmentation dots, and an optional tuplet ratio — and the conversion between\n * them and the quarter-note beats the rest of the library measures in.\n *\n * The base values are named the American way (whole, half, quarter, eighth),\n * matching the library's \"quarter-note beat\" convention and the vocabulary of\n * the MIDI and DAW world this engine reads events from.\n */\n\nimport { InvalidInputError, NoSolutionError } from '../errors/index.js';\nimport {\n assertFiniteNumber,\n assertGenerationBudget,\n assertInteger,\n assertOneOf,\n assertPositiveInt,\n} from '../validation/index.js';\n\n/**\n * A written base note value, from the whole note down to the sixty-fourth.\n *\n * Longer values (the breve and beyond) are written as tied notes; see\n * {@link beatsToTiedDurations}.\n *\n * @category Rhythm & Meter\n */\nexport type NoteValue =\n | 'whole'\n | 'half'\n | 'quarter'\n | 'eighth'\n | 'sixteenth'\n | 'thirtySecond'\n | 'sixtyFourth';\n\n/**\n * Every base note value, longest first.\n *\n * @category Rhythm & Meter\n */\nexport const NOTE_VALUES: readonly NoteValue[] = Object.freeze([\n 'whole',\n 'half',\n 'quarter',\n 'eighth',\n 'sixteenth',\n 'thirtySecond',\n 'sixtyFourth',\n] as const);\n\n/**\n * A tuplet ratio: `actual` written notes played in the time of `normal` ones —\n * `{ actual: 3, normal: 2 }` for a triplet, `{ actual: 5, normal: 4 }` for a\n * quintuplet.\n *\n * @category Rhythm & Meter\n */\nexport type Tuplet = {\n /** How many notes are written. */\n actual: number;\n /** How many of the same base value they occupy. */\n normal: number;\n};\n\n/**\n * A written duration: a base value, optional augmentation dots, and an optional\n * tuplet ratio. Its length is `base * (2 - 2^-dots) * normal / actual`.\n *\n * @category Rhythm & Meter\n */\nexport type DurationData = {\n base: NoteValue;\n /** Augmentation dots, 0 when absent; up to four are accepted. */\n dots?: number;\n tuplet?: Tuplet;\n};\n\n/**\n * A duration as {@link beatsToDuration} spells it, with the dot count always\n * stated.\n *\n * @category Rhythm & Meter\n */\nexport type SpelledDuration = {\n base: NoteValue;\n dots: number;\n tuplet?: Tuplet;\n};\n\n/** Length of each base value in quarter notes. */\nconst NOTE_VALUE_QUARTERS: Readonly<Record<NoteValue, number>> = Object.freeze({\n whole: 4,\n half: 2,\n quarter: 1,\n eighth: 0.5,\n sixteenth: 0.25,\n thirtySecond: 0.125,\n sixtyFourth: 0.0625,\n});\n\n/**\n * Match tolerance in quarter-note beats. Wide enough to read a seven-digit\n * decimal such as 0.3333333 as a triplet, and still far below one tick at\n * PPQ 960 (≈ 0.00104 beats), so no two spellings a sequencer can distinguish\n * collapse into one.\n */\nconst EPS = 1e-6;\n\n/** Most dots {@link beatsToDuration} will spell; more is never the reading. */\nconst MAX_SPELLED_DOTS = 2;\n\n/** Most dots {@link durationToBeats} will read; triple dots occur, four is the ceiling. */\nconst MAX_DOTS = 4;\n\n/** Upper bound on either side of a tuplet ratio. */\nconst MAX_TUPLET = 64;\n\n/**\n * The tuplet families {@link beatsToDuration} spells, in preference order, with\n * the plain (non-tuplet) reading first. Quintuplets and septuplets are taken in\n * the time of four, the reading that fills one beat of their base value.\n */\nconst SPELLED_TUPLETS: readonly (Tuplet | undefined)[] = Object.freeze([\n undefined,\n { actual: 3, normal: 2 },\n { actual: 5, normal: 4 },\n { actual: 7, normal: 4 },\n]);\n\n/** Length in quarter notes of a base value with dots and an optional tuplet. */\nfunction quartersOfParts(base: NoteValue, dots: number, tuplet: Tuplet | undefined): number {\n const dotted = NOTE_VALUE_QUARTERS[base] * (2 - 2 ** -dots);\n return tuplet === undefined ? dotted : (dotted * tuplet.normal) / tuplet.actual;\n}\n\n/** Validate a duration, accepting the bare base value as shorthand. */\nfunction assertDuration(value: NoteValue | DurationData, name: string): DurationData {\n if (typeof value === 'string') {\n return { base: assertOneOf(value, NOTE_VALUES, name), dots: 0 };\n }\n if (typeof value !== 'object' || value === null) {\n throw new InvalidInputError(`${name} must be a note value or a duration; received ${value}`);\n }\n const base = assertOneOf(value.base, NOTE_VALUES, `${name}.base`);\n const dots =\n value.dots === undefined ? 0 : assertInteger(value.dots, `${name}.dots`, 0, MAX_DOTS);\n if (value.tuplet === undefined) {\n return { base, dots };\n }\n const tuplet = {\n actual: assertPositiveInt(value.tuplet.actual, `${name}.tuplet.actual`, MAX_TUPLET),\n normal: assertPositiveInt(value.tuplet.normal, `${name}.tuplet.normal`, MAX_TUPLET),\n };\n return { base, dots, tuplet };\n}\n\n/** Length of a validated duration in quarter notes. */\nfunction quartersOf(duration: DurationData): number {\n return quartersOfParts(duration.base, duration.dots ?? 0, duration.tuplet);\n}\n\n/** Length of the beat unit in quarter notes; a quarter note unless overridden. */\nfunction beatQuarters(options: { beatUnit?: NoteValue | DurationData }): number {\n if (options.beatUnit === undefined) {\n return NOTE_VALUE_QUARTERS.quarter;\n }\n return quartersOf(assertDuration(options.beatUnit, 'beatUnit'));\n}\n\n/** The conventional spelling of a length in quarter notes, if it has one. */\nfunction spellQuarters(quarters: number): SpelledDuration | undefined {\n for (const tuplet of SPELLED_TUPLETS) {\n for (let dots = 0; dots <= MAX_SPELLED_DOTS; dots += 1) {\n for (const base of NOTE_VALUES) {\n if (Math.abs(quartersOfParts(base, dots, tuplet) - quarters) <= EPS) {\n return tuplet === undefined\n ? { base, dots }\n : { base, dots, tuplet: { actual: tuplet.actual, normal: tuplet.normal } };\n }\n }\n }\n }\n return undefined;\n}\n\n/** The undotted values a tie chain is built from, longest first. */\nconst PLAIN_VALUES: readonly { base: NoteValue; quarters: number }[] = Object.freeze(\n NOTE_VALUES.map((base) => ({ base, quarters: NOTE_VALUE_QUARTERS[base] })),\n);\n\n/** Require a positive, finite beat count. */\nfunction assertPositiveBeats(beats: number, name: string): number {\n assertFiniteNumber(beats, name);\n if (beats <= 0) {\n throw new InvalidInputError(`${name} must be positive; received ${beats}`);\n }\n return beats;\n}\n\n/**\n * Length of a written duration in beats.\n *\n * @param duration The duration, or a bare base value as shorthand for an\n * undotted one.\n * @param options `beatUnit` sets what one beat is; a quarter note by default,\n * so a dotted quarter reads as 1.5. Pass `{ base: 'quarter', dots: 1 }` to\n * count in the felt beats of a compound meter.\n * @returns The length in beats.\n * @throws If the base value is unknown, the dot count is not an integer in\n * 0..4, or a tuplet side is not a positive integer.\n * @example\n * ```ts\n * import { durationToBeats } from '@libraz/libcantus';\n * durationToBeats('quarter'); // 1\n * durationToBeats({ base: 'quarter', dots: 1 }); // 1.5\n * durationToBeats({ base: 'eighth', tuplet: { actual: 3, normal: 2 } }); // 1/3\n * ```\n * @category Rhythm & Meter\n */\nexport function durationToBeats(\n duration: NoteValue | DurationData,\n options: { beatUnit?: NoteValue | DurationData } = {},\n): number {\n const quarters = quartersOf(assertDuration(duration, 'duration'));\n return quarters / beatQuarters(options);\n}\n\n/**\n * Spell a length in beats as the note value a score would show.\n *\n * The spelling is the conventional one, not merely an arithmetically valid one:\n * 1.5 beats is a dotted quarter rather than a quarter tied to an eighth, and a\n * third of a beat is an eighth triplet rather than a twenty-fourth note. Plain\n * values are preferred to dotted ones and both to tuplets, and within the\n * tuplets triplets come before quintuplets and septuplets.\n *\n * Lengths are matched within 1e-6 beats, so a rounded decimal such as 0.3333333\n * still reads as a triplet.\n *\n * @param beats The length in beats.\n * @param options `beatUnit` sets what one beat is; a quarter note by default.\n * @returns The base value, its dot count, and its tuplet when it has one.\n * @throws If `beats` is not positive, or — as a `NoSolutionError` — if no single\n * note value spells it, as for 5 beats in 4/4. Use\n * {@link beatsToTiedDurations} for those.\n * @example\n * ```ts\n * import { beatsToDuration } from '@libraz/libcantus';\n * beatsToDuration(1.5); // { base: 'quarter', dots: 1 }\n * beatsToDuration(1 / 3); // { base: 'eighth', dots: 0, tuplet: { actual: 3, normal: 2 } }\n * ```\n * @category Rhythm & Meter\n */\nexport function beatsToDuration(\n beats: number,\n options: { beatUnit?: NoteValue | DurationData } = {},\n): SpelledDuration {\n assertPositiveBeats(beats, 'beats');\n const spelled = spellQuarters(beats * beatQuarters(options));\n if (spelled === undefined) {\n throw new NoSolutionError(`no single note value spells ${beats} beats`);\n }\n return spelled;\n}\n\n/**\n * Spell a length in beats as a chain of tied note values.\n *\n * A length with a single spelling comes back as a one-element chain. Anything\n * else is broken into undotted values, longest first, and a value immediately\n * followed by its own half is then written as a dot instead: 5 beats reads as a\n * whole note tied to a quarter, and 1.9375 beats as a double-dotted quarter tied\n * to a dotted thirty-second. The chain knows nothing of barlines or beat\n * grouping — an engraver splits further at those — and it uses no tuplets, so a\n * length off the plain grid and with no single spelling has no chain either.\n *\n * @param beats The length in beats.\n * @param options `beatUnit` sets what one beat is; a quarter note by default.\n * @returns The tied durations, longest first, summing to `beats`.\n * @throws If `beats` is not positive, if the chain would exceed the generation\n * budget, or — as a `NoSolutionError` — if no chain of plain and dotted values\n * sums to it.\n * @example\n * ```ts\n * import { beatsToTiedDurations } from '@libraz/libcantus';\n * beatsToTiedDurations(5); // [{ base: 'whole', dots: 0 }, { base: 'quarter', dots: 0 }]\n * ```\n * @category Rhythm & Meter\n */\nexport function beatsToTiedDurations(\n beats: number,\n options: { beatUnit?: NoteValue | DurationData } = {},\n): SpelledDuration[] {\n assertPositiveBeats(beats, 'beats');\n const quarters = beats * beatQuarters(options);\n const single = spellQuarters(quarters);\n if (single !== undefined) {\n return [single];\n }\n assertGenerationBudget(\n Math.ceil(quarters / NOTE_VALUE_QUARTERS.whole) + PLAIN_VALUES.length,\n 'tie chain length',\n );\n const chain: SpelledDuration[] = [];\n let remaining = quarters;\n let previousQuarters = 0;\n while (remaining > EPS) {\n const next = PLAIN_VALUES.find((candidate) => candidate.quarters <= remaining + EPS);\n if (next === undefined) {\n throw new NoSolutionError(`no chain of tied note values sums to ${beats} beats`);\n }\n const last = chain[chain.length - 1];\n // A value followed by exactly its own half is one dotted note, not a tie.\n if (\n last !== undefined &&\n last.dots < MAX_SPELLED_DOTS &&\n Math.abs(next.quarters * 2 - previousQuarters) <= EPS\n ) {\n last.dots += 1;\n } else {\n chain.push({ base: next.base, dots: 0 });\n }\n previousQuarters = next.quarters;\n remaining -= next.quarters;\n }\n return chain;\n}\n","/**\n * Tempo and time conversion: beats to wall-clock seconds across tempo changes,\n * and beats to MIDI ticks.\n *\n * Positions are measured in quarter-note beats, matching the rest of the\n * library's beat convention. A {@link TempoMap} is piecewise constant: each\n * entry sets the tempo from its beat onwards, so the elapsed time over a span is\n * the sum of the segments it crosses rather than the tempo at either end.\n */\n\nimport { InvalidInputError } from '../errors/index.js';\nimport {\n assertFiniteNumber,\n assertInteger,\n assertPositiveInt,\n assertRange,\n} from '../validation/index.js';\n\n/**\n * A tempo change: the beat it takes effect on, and the tempo it sets.\n *\n * The tempo holds until the next entry, so a map of one entry is a constant\n * tempo for the whole timeline.\n *\n * @category Rhythm & Meter\n */\nexport type TempoEvent = {\n /** Onset in quarter-note beats, absolute from the start of the timeline. */\n readonly startBeat: number;\n /** Quarter-note beats per minute from `startBeat` onwards. */\n readonly bpm: number;\n};\n\n/**\n * A tempo track: {@link TempoEvent}s sorted by `startBeat`, strictly ascending.\n *\n * The first entry is the time origin — {@link beatsToSeconds} returns 0 for its\n * `startBeat` — and its tempo also governs the beats before it, which is where\n * a pickup sounds. A map cannot say anything else about that stretch, and a\n * piece is played into its first downbeat at the tempo it starts in, so elapsed\n * time there is negative rather than an error.\n *\n * @category Rhythm & Meter\n */\nexport type TempoMap = readonly TempoEvent[];\n\nconst SECONDS_PER_MINUTE = 60;\n\n/**\n * Upper bound on a tempo, matching the bound the generators accept. A faster\n * marking is a notation of a slower pulse, not a distinct tempo.\n */\nconst MAX_BPM = 1000;\n\n/**\n * Validate a tempo map: non-empty, strictly ascending, finite onsets, and\n * positive tempos.\n *\n * An onset is not bounded below, for the reason the note events are not: beat 0\n * is the first downbeat, so a piece that opens with a pickup marks its tempo\n * before it.\n *\n * An unsorted map is rejected rather than sorted: reordering it would silently\n * accept a data error, and two entries on the same beat name no segment at all.\n */\nfunction assertTempoMap(map: TempoMap, name = 'tempo map'): TempoMap {\n if (!Array.isArray(map) || map.length === 0) {\n throw new InvalidInputError(`${name} must hold at least one tempo event`);\n }\n for (let index = 0; index < map.length; index += 1) {\n const event = map[index];\n if (event === undefined) {\n throw new InvalidInputError(`${name}[${index}] must be a tempo event; received undefined`);\n }\n assertFiniteNumber(event.startBeat, `${name}[${index}].startBeat`);\n assertRange(event.bpm, Number.MIN_VALUE, MAX_BPM, `${name}[${index}].bpm`);\n const previous = map[index - 1];\n if (previous !== undefined && event.startBeat <= previous.startBeat) {\n throw new InvalidInputError(\n `${name} must be sorted by startBeat with no repeats; ` +\n `[${index}].startBeat ${event.startBeat} does not follow ${previous.startBeat}`,\n );\n }\n }\n return map;\n}\n\n/** The map's first event, which is its time origin. */\nfunction firstEvent(map: TempoMap): TempoEvent {\n const first = map[0];\n if (first === undefined) {\n throw new InvalidInputError('tempo map must hold at least one tempo event');\n }\n return first;\n}\n\n/**\n * Elapsed seconds over `[fromBeat, toBeat]`, summed segment by segment. Both\n * bounds are assumed validated; a span running backwards reports negative time,\n * which is what keeps the integral additive across the origin.\n */\nfunction integrateSeconds(map: TempoMap, fromBeat: number, toBeat: number): number {\n if (toBeat < fromBeat) {\n return -integrateSeconds(map, toBeat, fromBeat);\n }\n let seconds = 0;\n for (let index = 0; index < map.length; index += 1) {\n const event = map[index];\n if (event === undefined) {\n continue;\n }\n // The opening tempo reaches back before the beat it is marked on: a pickup\n // is played at the tempo of the piece it leads into, and the map names no\n // other one to play it at.\n const segmentStart = index === 0 ? Number.NEGATIVE_INFINITY : event.startBeat;\n const segmentEnd = map[index + 1]?.startBeat ?? Number.POSITIVE_INFINITY;\n const low = Math.max(fromBeat, segmentStart);\n const high = Math.min(toBeat, segmentEnd);\n if (high > low) {\n seconds += ((high - low) * SECONDS_PER_MINUTE) / event.bpm;\n }\n if (toBeat <= segmentEnd) {\n break;\n }\n }\n return seconds;\n}\n\n/**\n * Wall-clock seconds from the start of a tempo map to a beat.\n *\n * The result integrates every tempo segment the span crosses; it is not the\n * tempo in effect at `beat` applied to the whole span.\n *\n * A beat before the map's first event reports negative elapsed time, at the\n * opening tempo: a pickup sounds before the downbeat, and asking when it sounds\n * is a fair question.\n *\n * @param beat Position in quarter-note beats.\n * @param map The tempo map; its first event is the time origin.\n * @returns Elapsed seconds, 0 at the map's first event and negative before it.\n * @throws If the map is empty, unsorted, or carries a non-positive tempo.\n * @example\n * ```ts\n * import { beatsToSeconds } from '@libraz/libcantus';\n * const map = [{ startBeat: 0, bpm: 120 }, { startBeat: 4, bpm: 60 }];\n * beatsToSeconds(8, map); // 6 = 4 beats at 120 + 4 beats at 60\n * ```\n * @category Rhythm & Meter\n */\nexport function beatsToSeconds(beat: number, map: TempoMap): number {\n assertFiniteNumber(beat, 'beat');\n assertTempoMap(map);\n return integrateSeconds(map, firstEvent(map).startBeat, beat);\n}\n\n/**\n * The beat reached after a number of seconds — the inverse of\n * {@link beatsToSeconds}.\n *\n * @param seconds Elapsed seconds from the map's first event; negative for a\n * position before it, such as a pickup.\n * @param map The tempo map.\n * @returns The position in quarter-note beats.\n * @throws If the map is malformed or `seconds` is not finite.\n * @example\n * ```ts\n * import { secondsToBeats } from '@libraz/libcantus';\n * const map = [{ startBeat: 0, bpm: 120 }, { startBeat: 4, bpm: 60 }];\n * secondsToBeats(6, map); // 8\n * ```\n * @category Rhythm & Meter\n */\nexport function secondsToBeats(seconds: number, map: TempoMap): number {\n assertFiniteNumber(seconds, 'seconds');\n assertTempoMap(map);\n const origin = firstEvent(map);\n if (seconds < 0) {\n // Before the origin only the opening tempo is in force, which is the same\n // segment {@link beatsToSeconds} integrates backwards over.\n return origin.startBeat + (seconds * origin.bpm) / SECONDS_PER_MINUTE;\n }\n let remaining = seconds;\n for (let index = 0; index < map.length - 1; index += 1) {\n const event = map[index];\n const next = map[index + 1];\n if (event === undefined || next === undefined) {\n continue;\n }\n const spanSeconds = ((next.startBeat - event.startBeat) * SECONDS_PER_MINUTE) / event.bpm;\n if (remaining < spanSeconds) {\n return event.startBeat + (remaining * event.bpm) / SECONDS_PER_MINUTE;\n }\n remaining -= spanSeconds;\n }\n const last = map[map.length - 1];\n if (last === undefined) {\n throw new InvalidInputError('tempo map must hold at least one tempo event');\n }\n return last.startBeat + (remaining * last.bpm) / SECONDS_PER_MINUTE;\n}\n\n/**\n * Duration in seconds of a span of beats.\n *\n * Equal to the difference of two {@link beatsToSeconds} calls — the integral is\n * additive, so that reading is exact — but integrated over the span directly, so\n * a short note late in a long piece does not lose precision to the subtraction\n * of two large elapsed times.\n *\n * @param startBeat Where the span begins, in quarter-note beats; a pickup\n * starts before the map's first event and is measured like any other span.\n * @param lengthBeats How long the span lasts, in quarter-note beats.\n * @param map The tempo map.\n * @returns The span's duration in seconds, never negative.\n * @throws If the map is malformed or the length is negative.\n * @example\n * ```ts\n * import { durationToSeconds } from '@libraz/libcantus';\n * const map = [{ startBeat: 0, bpm: 120 }, { startBeat: 4, bpm: 60 }];\n * durationToSeconds(2, 4, map); // 3 = 2 beats at 120 + 2 beats at 60\n * ```\n * @category Rhythm & Meter\n */\nexport function durationToSeconds(startBeat: number, lengthBeats: number, map: TempoMap): number {\n assertFiniteNumber(startBeat, 'startBeat');\n assertRange(lengthBeats, 0, Number.MAX_SAFE_INTEGER, 'lengthBeats');\n assertTempoMap(map);\n return integrateSeconds(map, startBeat, startBeat + lengthBeats);\n}\n\n/**\n * The tempo in effect at a beat.\n *\n * A beat before the first event reads the opening tempo, which is the tempo a\n * pickup is played at.\n *\n * @param beat Position in quarter-note beats.\n * @param map The tempo map.\n * @returns Quarter-note beats per minute.\n * @throws If the map is malformed.\n * @example\n * ```ts\n * import { tempoAt } from '@libraz/libcantus';\n * tempoAt(5, [{ startBeat: 0, bpm: 120 }, { startBeat: 4, bpm: 60 }]); // 60\n * ```\n * @category Rhythm & Meter\n */\nexport function tempoAt(beat: number, map: TempoMap): number {\n assertFiniteNumber(beat, 'beat');\n assertTempoMap(map);\n let bpm = firstEvent(map).bpm;\n for (const event of map) {\n if (event.startBeat > beat) {\n break;\n }\n bpm = event.bpm;\n }\n return bpm;\n}\n\n/**\n * Convert quarter-note beats to MIDI ticks.\n *\n * Ticks are whole units of a sequencer's grid, so the result is rounded to the\n * nearest tick; a beat that is not on the grid is not representable and comes\n * back quantized.\n *\n * A position before the first downbeat is a negative tick count, which is how a\n * pickup crosses the MIDI boundary and comes back.\n *\n * @param beat Position or length in quarter-note beats.\n * @param ppq Pulses (ticks) per quarter note, e.g. 96, 480, or 960.\n * @returns The whole tick count.\n * @throws If `beat` is not finite or `ppq` is not a positive integer.\n * @example\n * ```ts\n * import { beatsToTicks } from '@libraz/libcantus';\n * beatsToTicks(1.5, 480); // 720\n * ```\n * @category Rhythm & Meter\n */\nexport function beatsToTicks(beat: number, ppq: number): number {\n assertFiniteNumber(beat, 'beat');\n assertPositiveInt(ppq, 'ppq');\n return Math.round(beat * ppq);\n}\n\n/**\n * Convert MIDI ticks to quarter-note beats.\n *\n * @param ticks Whole tick count, negative before the first downbeat.\n * @param ppq Pulses (ticks) per quarter note, e.g. 96, 480, or 960.\n * @returns The position or length in quarter-note beats.\n * @throws If `ticks` is not an integer or `ppq` is not a positive integer.\n * @example\n * ```ts\n * import { ticksToBeats } from '@libraz/libcantus';\n * ticksToBeats(720, 480); // 1.5\n * ```\n * @category Rhythm & Meter\n */\nexport function ticksToBeats(ticks: number, ppq: number): number {\n assertInteger(ticks, 'ticks');\n assertPositiveInt(ppq, 'ppq');\n return ticks / ppq;\n}\n","/**\n * Tuning and microtonality: frequency conversion, cents, arbitrary equal\n * temperaments (EDO), and just-intonation ratios.\n *\n * The rest of the library reasons in twelve-tone pitch classes, which is a\n * deliberate scope choice for tonal theory. This module is the escape hatch for\n * anyone who needs actual frequencies, cents, non-12 equal temperaments, or the\n * acoustic (just) tuning behind the tempered intervals.\n */\n\nimport { InvalidInputError } from '../errors/index.js';\nimport {\n assertFiniteNumber,\n assertInteger,\n assertPositiveInt,\n assertRange,\n} from '../validation/index.js';\n\n/**\n * An equal-tempered tuning: a reference pitch and a number of equal divisions of\n * the octave. With `divisions === 12` a step index is an ordinary MIDI number.\n *\n * @category Pitch & Intervals\n */\nexport type TuningTable = {\n /** Step index (MIDI number when `divisions` is 12) whose frequency is `refFreq`. */\n readonly refStep: number;\n /** Frequency in Hz of `refStep`. */\n readonly refFreq: number;\n /** Equal divisions of the octave (12 standard; e.g. 19 or 31 for microtonal). */\n readonly divisions: number;\n};\n\n/**\n * Standard twelve-tone equal temperament, A4 (MIDI 69) = 440 Hz.\n *\n * @category Pitch & Intervals\n */\nexport const TWELVE_TET: TuningTable = Object.freeze({ refStep: 69, refFreq: 440, divisions: 12 });\n\nfunction assertTuning(tuning: TuningTable): TuningTable {\n assertFiniteNumber(tuning.refStep, 'tuning.refStep');\n assertRange(tuning.refFreq, Number.MIN_VALUE, Number.MAX_VALUE, 'tuning.refFreq');\n assertPositiveInt(tuning.divisions, 'tuning.divisions');\n return tuning;\n}\n\n/**\n * Build an equal temperament with `n` divisions of the octave.\n *\n * @param n Divisions of the octave (e.g. 19, 24, 31).\n * @param refFreq Reference frequency in Hz (default 440).\n * @param refStep Step index of the reference (default 69).\n * @returns The tuning.\n * @example\n * ```ts\n * import { edo, frequencyOf } from '@libraz/libcantus';\n * const et19 = edo(19); // { refStep: 69, refFreq: 440, divisions: 19 }\n * frequencyOf(70, et19); // one 19-EDO step above A4\n * ```\n * @category Pitch & Intervals\n */\nexport function edo(n: number, refFreq = 440, refStep = 69): TuningTable {\n assertPositiveInt(n, 'EDO divisions');\n assertRange(refFreq, Number.MIN_VALUE, Number.MAX_VALUE, 'reference frequency');\n assertFiniteNumber(refStep, 'reference step');\n return { refStep, refFreq, divisions: n };\n}\n\n/**\n * Frequency in Hz of a step index under a tuning.\n *\n * @param step Step index (a MIDI number under 12-EDO).\n * @param tuning The tuning (default 12-TET).\n * @returns The frequency in Hz.\n * @example\n * ```ts\n * import { frequencyOf } from '@libraz/libcantus';\n * frequencyOf(69); // 440 (A4 in 12-TET)\n * frequencyOf(60); // middle C in Hz\n * ```\n * @category Pitch & Intervals\n */\nexport function frequencyOf(step: number, tuning: TuningTable = TWELVE_TET): number {\n assertFiniteNumber(step, 'step');\n assertTuning(tuning);\n const result = tuning.refFreq * 2 ** ((step - tuning.refStep) / tuning.divisions);\n return assertRange(result, Number.MIN_VALUE, Number.MAX_VALUE, 'frequency result');\n}\n\n/**\n * Nearest step index to a frequency under a tuning (the inverse of\n * {@link frequencyOf}, rounded).\n *\n * @param freq Frequency in Hz.\n * @param tuning The tuning (default 12-TET).\n * @returns The nearest step index.\n * @category Pitch & Intervals\n */\nexport function nearestStep(freq: number, tuning: TuningTable = TWELVE_TET): number {\n assertRange(freq, Number.MIN_VALUE, Number.MAX_VALUE, 'frequency');\n assertTuning(tuning);\n return Math.round(tuning.refStep + tuning.divisions * Math.log2(freq / tuning.refFreq));\n}\n\n/**\n * Step index of a frequency under a tuning, unrounded.\n *\n * The exact inverse of {@link frequencyOf}. {@link nearestStep} rounds it,\n * which discards how far off the pitch actually is — the figure a tuner\n * display, a pitch-bend amount, or an intonation check is built on.\n *\n * @param freq Frequency in Hz.\n * @param tuning The tuning (default 12-TET).\n * @returns The fractional step index.\n * @example\n * ```ts\n * import { stepOf } from '@libraz/libcantus';\n * stepOf(442); // slightly above 69, the step for A440\n * ```\n * @category Pitch & Intervals\n */\nexport function stepOf(freq: number, tuning: TuningTable = TWELVE_TET): number {\n assertRange(freq, Number.MIN_VALUE, Number.MAX_VALUE, 'frequency');\n assertTuning(tuning);\n return tuning.refStep + tuning.divisions * Math.log2(freq / tuning.refFreq);\n}\n\n/**\n * How far a frequency sits from its nearest step, in cents.\n *\n * Positive means sharp of the step, negative flat.\n *\n * @param freq Frequency in Hz.\n * @param tuning The tuning (default 12-TET).\n * @returns The signed deviation in cents.\n * @example\n * ```ts\n * import { centsFromNearestStep } from '@libraz/libcantus';\n * Math.round(centsFromNearestStep(442)); // 8\n * ```\n * @category Pitch & Intervals\n */\nexport function centsFromNearestStep(freq: number, tuning: TuningTable = TWELVE_TET): number {\n const exact = stepOf(freq, tuning);\n return centsOfSteps(exact - Math.round(exact), tuning);\n}\n\n/**\n * Steps spanned by an interval in cents, unrounded — the inverse of\n * {@link centsOfSteps}.\n *\n * @param cents The interval in cents.\n * @param tuning The tuning (default 12-TET).\n * @returns The fractional step count.\n * @category Pitch & Intervals\n */\nexport function stepsOfCents(cents: number, tuning: TuningTable = TWELVE_TET): number {\n assertFiniteNumber(cents, 'cents');\n assertTuning(tuning);\n return assertFiniteNumber((cents * tuning.divisions) / 1200, 'steps result');\n}\n\n/**\n * The frequency ratio an interval in cents spans — the inverse of\n * {@link ratioToCents}.\n *\n * Multiply a frequency by this to move it by that many cents, which is how a\n * cents offset (a pitch-bend spec, a tuning table entry) is applied.\n *\n * @param cents The interval in cents.\n * @returns The frequency ratio.\n * @example\n * ```ts\n * import { centsToRatio } from '@libraz/libcantus';\n * 440 * centsToRatio(14); // A440 raised by 14 cents\n * ```\n * @category Pitch & Intervals\n */\nexport function centsToRatio(cents: number): number {\n assertFiniteNumber(cents, 'cents');\n return 2 ** (cents / 1200);\n}\n\n/**\n * Interval in cents between two frequencies.\n *\n * @param a Lower/first frequency in Hz.\n * @param b Upper/second frequency in Hz.\n * @returns Cents from `a` to `b` (negative if `b` is lower).\n * @category Pitch & Intervals\n */\nexport function centsBetweenFreq(a: number, b: number): number {\n assertRange(a, Number.MIN_VALUE, Number.MAX_VALUE, 'first frequency');\n assertRange(b, Number.MIN_VALUE, Number.MAX_VALUE, 'second frequency');\n return 1200 * (Math.log2(b) - Math.log2(a));\n}\n\n/**\n * Cents spanned by a number of equal-temperament steps.\n *\n * @param steps Number of steps.\n * @param tuning The tuning (default 12-TET).\n * @returns The cents.\n * @category Pitch & Intervals\n */\nexport function centsOfSteps(steps: number, tuning: TuningTable = TWELVE_TET): number {\n assertFiniteNumber(steps, 'steps');\n assertTuning(tuning);\n return assertFiniteNumber((steps * 1200) / tuning.divisions, 'cents result');\n}\n\n/**\n * Cents of a frequency ratio, e.g. `ratioToCents(3, 2)` ≈ 701.955 for the just\n * perfect fifth.\n *\n * @param numerator Ratio numerator.\n * @param denominator Ratio denominator.\n * @returns The interval in cents.\n * @category Pitch & Intervals\n */\nexport function ratioToCents(numerator: number, denominator: number): number {\n assertRange(numerator, Number.MIN_VALUE, Number.MAX_VALUE, 'ratio numerator');\n assertRange(denominator, Number.MIN_VALUE, Number.MAX_VALUE, 'ratio denominator');\n return 1200 * (Math.log2(numerator) - Math.log2(denominator));\n}\n\n/**\n * Five-limit just-intonation ratios for the twelve interval classes above a\n * unison, indexed by semitone class (0..12).\n *\n * @category Pitch & Intervals\n */\nfunction justRatio(numerator: number, denominator: number): readonly [number, number] {\n return Object.freeze([numerator, denominator] as [number, number]);\n}\n\n/**\n * Five-limit just-intonation ratios for the twelve interval classes above a\n * unison, indexed by semitone class (0..12).\n *\n * @category Pitch & Intervals\n */\nexport const JUST_RATIOS: Readonly<Record<number, readonly [number, number]>> = Object.freeze({\n 0: justRatio(1, 1),\n 1: justRatio(16, 15),\n 2: justRatio(9, 8),\n 3: justRatio(6, 5),\n 4: justRatio(5, 4),\n 5: justRatio(4, 3),\n 6: justRatio(45, 32),\n 7: justRatio(3, 2),\n 8: justRatio(8, 5),\n 9: justRatio(5, 3),\n 10: justRatio(9, 5),\n 11: justRatio(15, 8),\n 12: justRatio(2, 1),\n});\n\n/**\n * Cents by which a five-limit just interval departs from its 12-TET tempering\n * (positive means the just interval is wider).\n *\n * @param semitoneClass Semitone class in [0, 12].\n * @returns The deviation in cents.\n * @throws If `semitoneClass` is not an integer in [0, 12].\n * @category Pitch & Intervals\n */\nexport function justDeviationCents(semitoneClass: number): number {\n assertInteger(semitoneClass, 'semitone class', 0, 12);\n const ratio = JUST_RATIOS[semitoneClass];\n if (!ratio) {\n throw new InvalidInputError(`semitone class has no just ratio: ${semitoneClass}`);\n }\n return ratioToCents(ratio[0], ratio[1]) - semitoneClass * 100;\n}\n"]}
|