@libraz/libcantus 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/analyze/index.cjs +1697 -0
- package/dist/analyze/index.cjs.map +1 -0
- package/dist/analyze/index.d.cts +429 -0
- package/dist/analyze/index.d.ts +429 -0
- package/dist/analyze/index.js +51 -0
- package/dist/analyze/index.js.map +1 -0
- package/dist/chunk-5HTNMQW4.js +653 -0
- package/dist/chunk-5HTNMQW4.js.map +1 -0
- package/dist/chunk-7Y7WF64D.js +410 -0
- package/dist/chunk-7Y7WF64D.js.map +1 -0
- package/dist/chunk-A4532ZFR.js +259 -0
- package/dist/chunk-A4532ZFR.js.map +1 -0
- package/dist/chunk-BHUT2S5G.js +22 -0
- package/dist/chunk-BHUT2S5G.js.map +1 -0
- package/dist/chunk-CCBLVAPK.js +42 -0
- package/dist/chunk-CCBLVAPK.js.map +1 -0
- package/dist/chunk-COKTX2G5.js +907 -0
- package/dist/chunk-COKTX2G5.js.map +1 -0
- package/dist/chunk-DYWFNC4A.js +152 -0
- package/dist/chunk-DYWFNC4A.js.map +1 -0
- package/dist/chunk-GQKN5KDT.js +159 -0
- package/dist/chunk-GQKN5KDT.js.map +1 -0
- package/dist/chunk-LN7ZZMD2.js +530 -0
- package/dist/chunk-LN7ZZMD2.js.map +1 -0
- package/dist/chunk-MSWFZF7J.js +118 -0
- package/dist/chunk-MSWFZF7J.js.map +1 -0
- package/dist/chunk-R3S2LUBH.js +2722 -0
- package/dist/chunk-R3S2LUBH.js.map +1 -0
- package/dist/chunk-SDM3VJJ5.js +41 -0
- package/dist/chunk-SDM3VJJ5.js.map +1 -0
- package/dist/chunk-XTC3X6MS.js +816 -0
- package/dist/chunk-XTC3X6MS.js.map +1 -0
- package/dist/chunk-ZXW5YIWK.js +55 -0
- package/dist/chunk-ZXW5YIWK.js.map +1 -0
- package/dist/core/index.cjs +432 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +210 -0
- package/dist/core/index.d.ts +210 -0
- package/dist/core/index.js +73 -0
- package/dist/core/index.js.map +1 -0
- package/dist/function-2bJW1Zp_.d.ts +187 -0
- package/dist/function-r2sh-jOO.d.cts +187 -0
- package/dist/generate/index.cjs +3787 -0
- package/dist/generate/index.cjs.map +1 -0
- package/dist/generate/index.d.cts +980 -0
- package/dist/generate/index.d.ts +980 -0
- package/dist/generate/index.js +52 -0
- package/dist/generate/index.js.map +1 -0
- package/dist/index-BMPxwjwV.d.ts +151 -0
- package/dist/index-BOBXBNwP.d.cts +157 -0
- package/dist/index-BdeQ1r_p.d.cts +56 -0
- package/dist/index-BreoJRw0.d.ts +127 -0
- package/dist/index-CGMZNCx6.d.cts +140 -0
- package/dist/index-CGMZNCx6.d.ts +140 -0
- package/dist/index-CM5W4rcm.d.ts +157 -0
- package/dist/index-CP3wAfEH.d.ts +56 -0
- package/dist/index-Cl7mhOFM.d.cts +164 -0
- package/dist/index-Cl7mhOFM.d.ts +164 -0
- package/dist/index-DZ1M21do.d.cts +127 -0
- package/dist/index-D_ZTUNKp.d.cts +151 -0
- package/dist/index.cjs +3016 -2984
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -3982
- package/dist/index.d.ts +14 -3982
- package/dist/index.js +170 -6504
- package/dist/index.js.map +1 -1
- package/dist/model/index.cjs +2435 -0
- package/dist/model/index.cjs.map +1 -0
- package/dist/model/index.d.cts +630 -0
- package/dist/model/index.d.ts +630 -0
- package/dist/model/index.js +21 -0
- package/dist/model/index.js.map +1 -0
- package/dist/styled-BjXtOFNk.d.cts +282 -0
- package/dist/styled-D7BAx3S3.d.ts +282 -0
- package/dist/theory/index.cjs +1677 -0
- package/dist/theory/index.cjs.map +1 -0
- package/dist/theory/index.d.cts +535 -0
- package/dist/theory/index.d.ts +535 -0
- package/dist/theory/index.js +149 -0
- package/dist/theory/index.js.map +1 -0
- package/dist/types-MGP29r3t.d.cts +30 -0
- package/dist/types-MGP29r3t.d.ts +30 -0
- package/package.json +27 -2
- package/src/analyze/arrange/index.ts +21 -0
- package/src/analyze/arrange/internal.ts +125 -0
- package/src/analyze/arrange/tension.ts +187 -0
- package/src/analyze/arrange/tracks.ts +279 -0
- package/src/{detect → analyze/detect}/index.ts +4 -4
- package/src/analyze/functional/borrowed.ts +84 -0
- package/src/analyze/functional/cadence.ts +66 -0
- package/src/analyze/functional/function.ts +184 -0
- package/src/analyze/functional/index.ts +23 -0
- package/src/analyze/functional/internal.ts +29 -0
- package/src/{functional/index.ts → analyze/functional/roman.ts} +9 -327
- package/src/analyze/index.ts +49 -0
- package/src/{timeline → analyze/timeline}/index.ts +7 -11
- package/src/{analysis → analyze/voice}/index.ts +8 -5
- package/src/core/index.ts +47 -0
- package/src/{bass → generate/bass}/index.ts +5 -5
- package/src/{countermelody → generate/countermelody}/index.ts +11 -11
- package/src/{drums → generate/drums}/index.ts +2 -2
- package/src/{drums → generate/drums}/rng.ts +2 -2
- package/src/{groove → generate/groove}/index.ts +3 -3
- package/src/{harmonize → generate/harmonize}/index.ts +13 -13
- package/src/generate/index.ts +59 -0
- package/src/{motif → generate/motif}/index.ts +7 -7
- package/src/{progression → generate/progression}/index.ts +11 -25
- package/src/{reharmony → generate/reharmony}/index.ts +11 -11
- package/src/{rhythm → generate/rhythm}/index.ts +2 -2
- package/src/index.ts +130 -117
- package/src/model/chord.ts +423 -0
- package/src/model/index.ts +5 -1096
- package/src/model/interval.ts +82 -0
- package/src/model/key.ts +266 -0
- package/src/model/note.ts +176 -0
- package/src/model/progression.ts +161 -0
- package/src/model/shared.ts +12 -0
- package/src/{chord → theory/chord}/index.ts +19 -1
- package/src/{counterpoint → theory/counterpoint}/index.ts +2 -2
- package/src/theory/index.ts +107 -0
- package/src/{safety → theory/safety}/index.ts +1 -1
- package/src/theory/scale/degrees.ts +123 -0
- package/src/theory/scale/index.ts +28 -0
- package/src/theory/scale/key.ts +56 -0
- package/src/theory/scale/masks.ts +153 -0
- package/src/{spelling → theory/spelling}/index.ts +3 -3
- package/src/{symbol → theory/symbol}/index.ts +8 -1
- package/src/theory/voicing/index.ts +5 -0
- package/src/theory/voicing/internal.ts +168 -0
- package/src/theory/voicing/leading.ts +112 -0
- package/src/theory/voicing/satb.ts +195 -0
- package/src/theory/voicing/styled.ts +176 -0
- package/src/arrange/index.ts +0 -571
- package/src/scale/index.ts +0 -331
- package/src/voicing/index.ts +0 -623
- /package/src/{interval → core/interval}/index.ts +0 -0
- /package/src/{meter → core/meter}/index.ts +0 -0
- /package/src/{pitch → core/pitch}/index.ts +0 -0
- /package/src/{random → core/random}/index.ts +0 -0
- /package/src/{tuning → core/tuning}/index.ts +0 -0
- /package/src/{types.ts → core/types.ts} +0 -0
- /package/src/{drums → generate/drums}/beat.ts +0 -0
- /package/src/{drums → generate/drums}/euclid.ts +0 -0
- /package/src/{drums → generate/drums}/fills.ts +0 -0
- /package/src/{drums → generate/drums}/ghost.ts +0 -0
- /package/src/{drums → generate/drums}/hihat.ts +0 -0
- /package/src/{drums → generate/drums}/hit.ts +0 -0
- /package/src/{drums → generate/drums}/internal.ts +0 -0
- /package/src/{drums → generate/drums}/kick.ts +0 -0
- /package/src/{drums → generate/drums}/percussion.ts +0 -0
- /package/src/{drums → generate/drums}/swing.ts +0 -0
- /package/src/{chordscale → theory/chordscale}/index.ts +0 -0
- /package/src/{harmony → theory/harmony}/index.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts","../../src/core/interval/index.ts","../../src/core/meter/index.ts","../../src/core/pitch/index.ts","../../src/core/random/index.ts","../../src/core/tuning/index.ts"],"sourcesContent":["/**\n * Public API of the core layer. Re-exports every core-layer module;\n * also available from the package root.\n */\nexport {\n classifyInterval,\n IntervalQuality,\n isConsonantInterval,\n isPerfectInterval,\n} from './interval/index.js';\nexport type { BarPosition, TimeSignature } from './meter/index.js';\nexport {\n barPositionToBeat,\n beatsPerBar,\n beatToBarPosition,\n formatTimeSignature,\n isCompound,\n isStrongBeat,\n metricWeight,\n parseTimeSignature,\n pulsesPerBar,\n tuplet,\n} from './meter/index.js';\nexport type { Note as NoteData, SpelledInterval } from './pitch/index.js';\nexport {\n formatNote,\n midiToNote,\n noteToMidi,\n noteToPitchClass,\n parseNote,\n spelledInterval,\n} from './pitch/index.js';\nexport type { Rng } from './random/index.js';\nexport { createRng } from './random/index.js';\nexport type { Tuning } from './tuning/index.js';\nexport {\n centsBetweenFreq,\n centsOfSteps,\n edo,\n frequencyOf,\n JUST_RATIOS,\n justDeviationCents,\n nearestStep,\n ratioToCents,\n TWELVE_TET,\n} from './tuning/index.js';\nexport type { KeyScale, NoteEvent } from './types.js';\n","/**\n * Counterpoint classification of a harmonic interval.\n *\n * @category Pitch & Intervals\n */\nexport enum IntervalQuality {\n PerfectConsonance = 0,\n ImperfectConsonance = 1,\n Dissonance = 2,\n}\n\n/** Reduce an interval to a simple interval class in the range [0, 11]. */\nfunction simpleInterval(semitones: number): number {\n return Math.abs(semitones) % 12;\n}\n\n/**\n * Classify an interval for counterpoint evaluation.\n *\n * The interval is reduced modulo 12, so compound intervals classify as their\n * simple equivalents. The perfect fourth (5) is context-dependent: with\n * `twoVoice` (the default) it classifies as a dissonance, matching\n * {@link isConsonantInterval}; otherwise it is an imperfect consonance.\n *\n * @param semitones Interval size in semitones (may be negative or compound).\n * @param twoVoice When true, the perfect fourth is treated as dissonant.\n * @returns The counterpoint quality of the interval.\n * @example\n * ```ts\n * import { classifyInterval, IntervalQuality } from '@libraz/libcantus';\n * classifyInterval(7); // IntervalQuality.PerfectConsonance\n * classifyInterval(5); // IntervalQuality.Dissonance (two-voice)\n * classifyInterval(5, false); // IntervalQuality.ImperfectConsonance\n * ```\n * @category Pitch & Intervals\n */\nexport function classifyInterval(semitones: number, twoVoice = true): IntervalQuality {\n const pc = simpleInterval(semitones);\n if (pc === 0 || pc === 7) {\n return IntervalQuality.PerfectConsonance;\n }\n if (pc === 3 || pc === 4 || pc === 8 || pc === 9) {\n return IntervalQuality.ImperfectConsonance;\n }\n if (pc === 5) {\n return twoVoice ? IntervalQuality.Dissonance : IntervalQuality.ImperfectConsonance;\n }\n return IntervalQuality.Dissonance;\n}\n\n/**\n * Test whether an interval is a perfect interval (unison/octave or fifth).\n *\n * @param semitones Interval size in semitones (may be negative or compound).\n * @returns True for the unison/octave (0) and the perfect fifth (7) mod 12.\n * @category Pitch & Intervals\n */\nexport function isPerfectInterval(semitones: number): boolean {\n const pc = simpleInterval(semitones);\n return pc === 0 || pc === 7;\n}\n\n/**\n * Test whether an interval is consonant.\n *\n * The consonant set is {0, 3, 4, 5, 7, 8, 9} mod 12. In two-voice counterpoint\n * the perfect fourth (5) is treated as a dissonance, so `twoVoice` set to true\n * excludes it.\n *\n * @param semitones Interval size in semitones (may be negative or compound).\n * @param twoVoice When true, the perfect fourth is treated as dissonant.\n * @returns True if the interval is consonant in the given context.\n * @category Pitch & Intervals\n */\nexport function isConsonantInterval(semitones: number, twoVoice = true): boolean {\n const pc = simpleInterval(semitones);\n if (pc === 5) {\n return !twoVoice;\n }\n return pc === 0 || pc === 3 || pc === 4 || pc === 7 || pc === 8 || pc === 9;\n}\n","/**\n * Meter and time signatures: bar/beat arithmetic, simple vs. compound meters,\n * metric-accent hierarchy, and tuplet subdivision.\n *\n * Positions and durations are measured in quarter-note beats, matching the rest\n * of the library's beat convention (four quarter-note beats per bar in 4/4).\n */\n\n/**\n * A time signature as a numerator over a note-value denominator.\n *\n * @category Rhythm & Meter\n */\nexport type TimeSignature = {\n numerator: number;\n denominator: number;\n /**\n * Optional additive grouping of the bar's main pulses, as the felt-beat\n * lengths in pulses — e.g. `[2, 2, 3]` for a 2+2+3 reading of 7/8, or\n * `[3, 2]` for 5/8. The entries must be positive integers summing to\n * {@link pulsesPerBar}. When present, the head pulse of each group (other\n * than the downbeat) is treated as a secondary strong pulse by\n * {@link metricWeight}/{@link isStrongBeat}; when absent, all main pulses\n * are weighted equally as flat, evenly divided pulses.\n */\n grouping?: number[];\n};\n\n/**\n * A position expressed as a bar index and a quarter-note offset within the bar.\n *\n * @category Rhythm & Meter\n */\nexport type BarPosition = {\n bar: number;\n /** Quarter-note offset from the start of the bar. */\n beat: number;\n};\n\nconst EPS = 1e-9;\n\n/** Whether `value` is an integer multiple of `unit` (within a float tolerance). */\nfunction isMultiple(value: number, unit: number): boolean {\n if (unit === 0) {\n return false;\n }\n const ratio = value / unit;\n return Math.abs(ratio - Math.round(ratio)) < EPS;\n}\n\n/**\n * Parse a time signature such as `\"4/4\"` or `\"6/8\"`.\n *\n * @param text The signature text.\n * @returns The parsed time signature.\n * @throws If the text is not `n/d` with positive integers.\n * @example\n * ```ts\n * import { parseTimeSignature } from '@libraz/libcantus';\n * parseTimeSignature('6/8'); // { numerator: 6, denominator: 8 }\n * ```\n * @category Rhythm & Meter\n */\nexport function parseTimeSignature(text: string): TimeSignature {\n const match = /^\\s*(\\d+)\\s*\\/\\s*(\\d+)\\s*$/.exec(text);\n if (!match) {\n throw new Error(`Invalid time signature: ${text}`);\n }\n const numerator = Number.parseInt(match[1] ?? '', 10);\n const denominator = Number.parseInt(match[2] ?? '', 10);\n if (numerator <= 0 || denominator <= 0) {\n throw new Error(`Invalid time signature: ${text}`);\n }\n return { numerator, denominator };\n}\n\n/**\n * Render a time signature as `\"n/d\"`.\n *\n * @category Rhythm & Meter\n */\nexport function formatTimeSignature(ts: TimeSignature): string {\n return `${ts.numerator}/${ts.denominator}`;\n}\n\n/**\n * Whether a meter is compound: its main pulses each divide into three, as in\n * 6/8, 9/8, 12/8, or 6/4. Compound meters are those whose numerator is a\n * multiple of three greater than three, independent of the denominator. Meters\n * like 3/8 and 3/4 (simple triples, numerator 3) are not compound.\n *\n * @param ts The time signature.\n * @returns True for compound meters.\n * @category Rhythm & Meter\n */\nexport function isCompound(ts: TimeSignature): boolean {\n return ts.numerator % 3 === 0 && ts.numerator > 3;\n}\n\n/** Length of one denominator unit in quarter-note beats. */\nfunction unitBeats(ts: TimeSignature): number {\n return 4 / ts.denominator;\n}\n\n/**\n * Length of a bar in quarter-note beats.\n *\n * @param ts The time signature.\n * @returns The bar length in quarter notes.\n * @category Rhythm & Meter\n */\nexport function beatsPerBar(ts: TimeSignature): number {\n return ts.numerator * unitBeats(ts);\n}\n\n/** Length of one main pulse (a dotted value in compound meters) in quarter notes. */\nfunction pulseBeats(ts: TimeSignature): number {\n return isCompound(ts) ? 3 * unitBeats(ts) : unitBeats(ts);\n}\n\n/**\n * Number of main pulses (felt beats) per bar: the numerator for simple meters,\n * a third of it for compound meters.\n *\n * For additive/irregular meters such as 7/8 or 5/8 this counts the raw pulses\n * (7 and 5 respectively), which are otherwise felt as flat, evenly divided and\n * equally accented pulses. To recover a 2+2+3 or 3+2 felt-beat grouping, set\n * {@link TimeSignature.grouping}; {@link metricWeight} then accents each\n * group's head pulse.\n *\n * @param ts The time signature.\n * @returns The pulse count per bar.\n * @category Rhythm & Meter\n */\nexport function pulsesPerBar(ts: TimeSignature): number {\n return beatsPerBar(ts) / pulseBeats(ts);\n}\n\n/**\n * Whether `grouping` is a valid additive grouping for a bar of `pulses` main\n * pulses: a non-empty list of positive integers summing to `pulses`.\n */\nfunction isValidGrouping(grouping: number[], pulses: number): boolean {\n if (grouping.length === 0) {\n return false;\n }\n let sum = 0;\n for (const g of grouping) {\n if (!Number.isInteger(g) || g <= 0) {\n return false;\n }\n sum += g;\n }\n return sum === pulses;\n}\n\n/** Whether `pulseIndex` is the head pulse of one of the additive groups. */\nfunction isGroupHead(grouping: number[], pulseIndex: number): boolean {\n let acc = 0;\n for (const g of grouping) {\n if (acc === pulseIndex) {\n return true;\n }\n acc += g;\n }\n return false;\n}\n\n/**\n * Convert an absolute quarter-note position to a bar index and in-bar offset.\n *\n * @param beatInQuarters Absolute position in quarter-note beats.\n * @param ts The time signature.\n * @returns The bar and in-bar quarter-note offset.\n * @example\n * ```ts\n * import { parseTimeSignature, beatToBarPosition } from '@libraz/libcantus';\n * const ts = parseTimeSignature('4/4');\n * beatToBarPosition(5, ts); // { bar: 1, beat: 1 }\n * ```\n * @category Rhythm & Meter\n */\nexport function beatToBarPosition(beatInQuarters: number, ts: TimeSignature): BarPosition {\n const barLen = beatsPerBar(ts);\n const bar = Math.floor(beatInQuarters / barLen);\n return { bar, beat: beatInQuarters - bar * barLen };\n}\n\n/**\n * Convert a bar index and in-bar offset back to an absolute quarter-note\n * position.\n *\n * @param pos The bar position.\n * @param ts The time signature.\n * @returns The absolute position in quarter-note beats.\n * @category Rhythm & Meter\n */\nexport function barPositionToBeat(pos: BarPosition, ts: TimeSignature): number {\n return pos.bar * beatsPerBar(ts) + pos.beat;\n}\n\n/**\n * Metric weight of a position within its bar, on a 0–3 scale:\n * 3 the downbeat, 2 a secondary strong pulse, 1 any other main pulse, and 0 an\n * off-pulse subdivision.\n *\n * The secondary strong pulse is the bar's midpoint in even simple/compound\n * meters. For an additive/irregular meter with {@link TimeSignature.grouping}\n * set (e.g. `[2, 2, 3]` for 7/8), each group's head pulse other than the\n * downbeat is the secondary strong pulse instead; without a grouping every\n * non-downbeat main pulse of such a meter weighs 1 (flat, evenly divided\n * pulses).\n *\n * @param beatInQuarters Absolute or in-bar quarter-note position.\n * @param ts The time signature.\n * @returns The metric weight (0–3).\n * @throws If `ts.grouping` is present but is not a positive-integer list\n * summing to {@link pulsesPerBar}.\n * @example\n * ```ts\n * import { parseTimeSignature, metricWeight } from '@libraz/libcantus';\n * const ts = parseTimeSignature('4/4');\n * metricWeight(0, ts); // 3 (the downbeat)\n * ```\n * @category Rhythm & Meter\n */\nexport function metricWeight(beatInQuarters: number, ts: TimeSignature): number {\n const { beat } = beatToBarPosition(beatInQuarters, ts);\n const pulse = pulseBeats(ts);\n if (!isMultiple(beat, pulse)) {\n return 0;\n }\n const pulses = pulsesPerBar(ts);\n const pulseIndex = Math.round(beat / pulse) % pulses;\n if (pulseIndex === 0) {\n return 3;\n }\n const grouping = ts.grouping;\n if (grouping !== undefined) {\n if (!isValidGrouping(grouping, pulses)) {\n throw new Error(\n `Invalid grouping [${grouping.join(', ')}] for ${formatTimeSignature(ts)}: ` +\n `entries must be positive integers summing to ${pulses}`,\n );\n }\n return isGroupHead(grouping, pulseIndex) ? 2 : 1;\n }\n if (pulses % 2 === 0 && pulseIndex === pulses / 2) {\n return 2;\n }\n return 1;\n}\n\n/**\n * Whether a position is metrically accented (weight 2 or more — a downbeat or a\n * secondary strong pulse).\n *\n * @param beatInQuarters Absolute or in-bar quarter-note position.\n * @param ts The time signature.\n * @returns True on strong beats.\n * @category Rhythm & Meter\n */\nexport function isStrongBeat(beatInQuarters: number, ts: TimeSignature): boolean {\n return metricWeight(beatInQuarters, ts) >= 2;\n}\n\n/**\n * Subdivide a span into `count` equal tuplet durations (e.g. an eighth-note\n * triplet is `tuplet(1, 3)`).\n *\n * @param totalBeats Total span in quarter-note beats.\n * @param count Number of equal parts.\n * @returns `count` equal durations summing to `totalBeats`.\n * @throws If `count` is not a positive integer.\n * @category Rhythm & Meter\n */\nexport function tuplet(totalBeats: number, count: number): number[] {\n if (!Number.isInteger(count) || count <= 0) {\n throw new Error(`Invalid tuplet count: ${count}`);\n }\n return new Array<number>(count).fill(totalBeats / count);\n}\n","/**\n * Pitch spelling: letter-name notes, enharmonic-aware conversion, and spelled\n * intervals.\n *\n * The rest of the library works in pitch classes (0..11), which cannot tell a\n * G# from an Ab or an augmented fourth from a diminished fifth. This module adds\n * an explicit spelling layer — a note is a diatonic letter plus a chromatic\n * alteration — so interval quality (P/M/m/A/d) and enharmonic identity are\n * preserved.\n */\n\n/** Semitone offset of each natural letter above C: C D E F G A B. */\nconst LETTER_SEMITONES = [0, 2, 4, 5, 7, 9, 11] as const;\n\n/** Letter glyphs indexed by letter number (0 = C .. 6 = B). */\nconst LETTER_NAMES = ['C', 'D', 'E', 'F', 'G', 'A', 'B'] as const;\n\n/**\n * A spelled note: a diatonic letter, a chromatic alteration, and an optional\n * octave.\n *\n * - `letter` is 0..6 for C..B.\n * - `alter` is the number of semitones of alteration: -2 double-flat, -1 flat,\n * 0 natural, +1 sharp, +2 double-sharp.\n * - `octave` follows scientific pitch notation (middle C = C4 = MIDI 60). When\n * absent, the note denotes a bare pitch class.\n *\n * @category Pitch & Intervals\n */\nexport type Note = {\n letter: number;\n alter: number;\n octave?: number;\n};\n\n/**\n * A spelled interval: a diatonic number, a quality label, and its semitone span.\n *\n * @category Pitch & Intervals\n */\nexport type SpelledInterval = {\n /** Diatonic size: 1 = unison, 2 = second, ... 8 = octave, and beyond. */\n number: number;\n /** Quality label: 'P', 'M', 'm', or repeated 'A'/'d' for (multiply) aug/dim. */\n quality: string;\n /** Signed semitone distance from the first note to the second. */\n semitones: number;\n};\n\n/** Reduce any integer to a pitch class in [0, 11]. */\nfunction mod12(n: number): number {\n return ((n % 12) + 12) % 12;\n}\n\n/** Reduce any integer to [0, 7). */\nfunction mod7(n: number): number {\n return ((n % 7) + 7) % 7;\n}\n\n/**\n * Parse scientific pitch notation into a {@link Note}.\n *\n * Accepts a letter (case-insensitive) followed by any number of same-direction\n * accidentals and an optional octave, e.g. `\"C\"`, `\"C#4\"`, `\"Bb\"`, `\"F##3\"`,\n * `\"Ebb2\"`. Both `#` and `x` (double-sharp) are accepted for sharps; `b` for\n * flats. Mixing sharps and flats (e.g. `\"C#b\"`) is rejected.\n *\n * @param text The note text.\n * @returns The parsed note.\n * @throws If the text is not a valid note.\n * @example\n * ```ts\n * import { parseNote, noteToMidi } from '@libraz/libcantus';\n * const n = parseNote('C#4');\n * noteToMidi(n); // 61\n * ```\n * @category Pitch & Intervals\n */\nexport function parseNote(text: string): Note {\n const match = /^([A-Ga-g])([#x]*|b*)(-?\\d+)?$/.exec(text.trim());\n if (!match) {\n throw new Error(`Invalid note: ${text}`);\n }\n const letterGlyph = (match[1] ?? '').toUpperCase();\n const letter = LETTER_NAMES.indexOf(letterGlyph as (typeof LETTER_NAMES)[number]);\n let alter = 0;\n for (const ch of match[2] ?? '') {\n if (ch === '#') {\n alter += 1;\n } else if (ch === 'x') {\n alter += 2;\n } else if (ch === 'b') {\n alter -= 1;\n }\n }\n const note: Note = { letter, alter };\n if (match[3] !== undefined) {\n note.octave = Number.parseInt(match[3], 10);\n }\n return note;\n}\n\n/** Render an alteration as accidental glyphs (`##`, `b`, empty for natural). */\nfunction formatAlter(alter: number): string {\n if (alter > 0) {\n return '#'.repeat(alter);\n }\n if (alter < 0) {\n return 'b'.repeat(-alter);\n }\n return '';\n}\n\n/**\n * Render a {@link Note} as scientific pitch notation.\n *\n * @param note The note to format.\n * @returns The note text, including the octave when present.\n * @example\n * ```ts\n * import { formatNote, parseNote } from '@libraz/libcantus';\n * formatNote(parseNote('C#4')); // 'C#4'\n * ```\n * @category Pitch & Intervals\n */\nexport function formatNote(note: Note): string {\n const glyph = LETTER_NAMES[mod7(note.letter)] ?? 'C';\n const octave = note.octave === undefined ? '' : String(note.octave);\n return `${glyph}${formatAlter(note.alter)}${octave}`;\n}\n\n/**\n * Pitch class (0..11) of a note, ignoring octave.\n *\n * @param note The note.\n * @returns The pitch class.\n * @example\n * ```ts\n * import { noteToPitchClass, parseNote } from '@libraz/libcantus';\n * noteToPitchClass(parseNote('Db')); // 1\n * ```\n * @category Pitch & Intervals\n */\nexport function noteToPitchClass(note: Note): number {\n const natural = LETTER_SEMITONES[mod7(note.letter)] ?? 0;\n return mod12(natural + note.alter);\n}\n\n/**\n * MIDI number of a note (middle C = C4 = 60).\n *\n * @param note The note; must carry an octave.\n * @returns The MIDI number.\n * @throws If the note has no octave.\n * @example\n * ```ts\n * import { noteToMidi, parseNote } from '@libraz/libcantus';\n * noteToMidi(parseNote('A4')); // 69\n * ```\n * @category Pitch & Intervals\n */\nexport function noteToMidi(note: Note): number {\n if (note.octave === undefined) {\n throw new Error('noteToMidi requires an octave');\n }\n const natural = LETTER_SEMITONES[mod7(note.letter)] ?? 0;\n return (note.octave + 1) * 12 + natural + note.alter;\n}\n\n/** Preferred spelling when naming a black key from a bare MIDI number. */\nconst SHARP_SPELLING: readonly [number, number][] = [\n [0, 0],\n [0, 1],\n [1, 0],\n [1, 1],\n [2, 0],\n [3, 0],\n [3, 1],\n [4, 0],\n [4, 1],\n [5, 0],\n [5, 1],\n [6, 0],\n];\n\nconst FLAT_SPELLING: readonly [number, number][] = [\n [0, 0],\n [1, -1],\n [1, 0],\n [2, -1],\n [2, 0],\n [3, 0],\n [4, -1],\n [4, 0],\n [5, -1],\n [5, 0],\n [6, -1],\n [6, 0],\n];\n\n/**\n * Name a MIDI number as a {@link Note}, choosing sharp or flat spelling.\n *\n * The input is rounded to the nearest integer but is not clamped to the MIDI\n * range 0..127: out-of-range values extrapolate linearly (e.g. `-1` -> `B-2`,\n * `128` -> `G#9`) and remain an exact inverse of {@link noteToMidi}.\n *\n * @param midi The MIDI number.\n * @param spelling Whether to prefer sharps or flats for black keys.\n * @returns The spelled note, with octave.\n * @example\n * ```ts\n * import { midiToNote, formatNote } from '@libraz/libcantus';\n * formatNote(midiToNote(61)); // 'C#4'\n * formatNote(midiToNote(61, 'flat')); // 'Db4'\n * ```\n * @category Pitch & Intervals\n */\nexport function midiToNote(midi: number, spelling: 'sharp' | 'flat' = 'sharp'): Note {\n const rounded = Math.round(midi);\n const pc = mod12(rounded);\n const octave = Math.floor(rounded / 12) - 1;\n const table = spelling === 'sharp' ? SHARP_SPELLING : FLAT_SPELLING;\n const entry = table[pc] ?? [0, 0];\n return { letter: entry[0], alter: entry[1], octave };\n}\n\n/** Reference semitone span of a perfect/major simple interval by diatonic number. */\nconst SIMPLE_REFERENCE = [0, 0, 2, 4, 5, 7, 9, 11] as const;\n\n/** Whether a simple diatonic number (1..7 within an octave) is a perfect kind. */\nfunction isPerfectNumber(simpleNumber: number): boolean {\n return simpleNumber === 1 || simpleNumber === 4 || simpleNumber === 5;\n}\n\n/** Quality label from a diatonic number and its actual semitone span. */\nfunction qualityFromSpan(numberValue: number, semitones: number): string {\n const octaves = Math.floor((numberValue - 1) / 7);\n const simple = numberValue - 7 * octaves;\n const reference = (SIMPLE_REFERENCE[simple] ?? 0) + 12 * octaves;\n const delta = semitones - reference;\n if (isPerfectNumber(simple)) {\n if (delta === 0) {\n return 'P';\n }\n return delta > 0 ? 'A'.repeat(delta) : 'd'.repeat(-delta);\n }\n if (delta === 0) {\n return 'M';\n }\n if (delta === -1) {\n return 'm';\n }\n return delta > 0 ? 'A'.repeat(delta) : 'd'.repeat(-delta - 1);\n}\n\n/** Diatonic ladder index of a note (letter + 7 * octave when octave-bearing). */\nfunction diatonicIndex(note: Note): number {\n return mod7(note.letter) + 7 * (note.octave ?? 0);\n}\n\n/**\n * The spelled interval from one note to another.\n *\n * When both notes carry octaves, the interval reflects their full signed\n * distance (so `C4 -> C5` is a perfect octave). When either lacks an octave the\n * interval is measured within a single ascending octave from `a` to `b`.\n *\n * @param a The lower/first note.\n * @param b The upper/second note.\n * @returns The diatonic number, quality, and semitone span.\n * @example\n * ```ts\n * import { spelledInterval, parseNote } from '@libraz/libcantus';\n * spelledInterval(parseNote('C4'), parseNote('G4'));\n * // { number: 5, quality: 'P', semitones: 7 }\n * ```\n * @category Pitch & Intervals\n */\nexport function spelledInterval(a: Note, b: Note): SpelledInterval {\n const octaved = a.octave !== undefined && b.octave !== undefined;\n let letterSteps: number;\n let semitones: number;\n if (octaved) {\n letterSteps = diatonicIndex(b) - diatonicIndex(a);\n // Signed pitch distance from a to b, so a note below a yields a negative span.\n semitones = noteToMidi(b) - noteToMidi(a);\n } else {\n letterSteps = mod7(b.letter - a.letter);\n let rawSemis = mod12(noteToPitchClass(b) - noteToPitchClass(a));\n // Lift the chromatic span into the octave nearest the diatonic reference so\n // wraparound intervals stay consistent with the diatonic number instead of\n // collapsing modulo 12. The correction is bidirectional: an upward wrap\n // (e.g. Ab -> G# = augmented seventh) adds an octave, while a same-letter or\n // downward chromatic step (e.g. E -> Eb, F# -> F, C -> Cb = descending\n // diminished/augmented unison) subtracts one so the sign follows pitch\n // direction instead of returning a garbage stack of augmentations.\n const reference = SIMPLE_REFERENCE[letterSteps + 1] ?? 0;\n if (reference - rawSemis > 6) {\n rawSemis += 12;\n } else if (rawSemis - reference > 6) {\n rawSemis -= 12;\n }\n semitones = rawSemis;\n }\n const absSteps = Math.abs(letterSteps);\n const number = absSteps + 1;\n // Quality comes from the absolute chromatic span; semitones keeps its sign.\n const quality = qualityFromSpan(number, Math.abs(semitones));\n return { number, quality, semitones };\n}\n","/**\n * Deterministic seeded pseudo-random number generation shared across the\n * generative modules (rhythm, drums, bass, groove, counter-melody). A single\n * mulberry32 core exposes the small set of samplers those modules need; given a\n * seed the stream is fully reproducible.\n */\n\n/**\n * A deterministic PRNG with the sampling helpers the generators need.\n *\n * @category Utilities\n */\nexport type Rng = {\n /** Next float in [0, 1). */\n next: () => number;\n /** True with probability `p`. */\n prob: (p: number) => boolean;\n /** Integer in the inclusive range [lo, hi]. */\n range: (lo: number, hi: number) => number;\n /** Float in [lo, hi). */\n float: (lo: number, hi: number) => number;\n};\n\n/**\n * Create a seeded PRNG (mulberry32) exposing the shared samplers.\n *\n * @param seed The 32-bit seed; the same seed always yields the same stream.\n * @returns The seeded generator.\n * @example\n * ```ts\n * import { createRng } from '@libraz/libcantus';\n * const rng = createRng(42);\n * rng.next(); // deterministic float in [0, 1)\n * rng.range(1, 6); // deterministic integer in [1, 6]\n * ```\n * @category Utilities\n */\nexport function createRng(seed: number): Rng {\n let state = seed >>> 0;\n const next = () => {\n state = (state + 0x6d2b79f5) >>> 0;\n let t = state;\n t = Math.imul(t ^ (t >>> 15), t | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n };\n return {\n next,\n prob: (p) => next() < p,\n range: (lo, hi) => lo + Math.floor(next() * (hi - lo + 1)),\n float: (lo, hi) => lo + next() * (hi - lo),\n };\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\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 Tuning = {\n /** Step index (MIDI number when `divisions` is 12) whose frequency is `refFreq`. */\n refStep: number;\n /** Frequency in Hz of `refStep`. */\n refFreq: number;\n /** Equal divisions of the octave (12 standard; e.g. 19 or 31 for microtonal). */\n 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: Tuning = { refStep: 69, refFreq: 440, divisions: 12 };\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): Tuning {\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: Tuning = TWELVE_TET): number {\n return tuning.refFreq * 2 ** ((step - tuning.refStep) / tuning.divisions);\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: Tuning = TWELVE_TET): number {\n return Math.round(tuning.refStep + tuning.divisions * Math.log2(freq / tuning.refFreq));\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 return 1200 * Math.log2(b / 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: Tuning = TWELVE_TET): number {\n return (steps * 1200) / tuning.divisions;\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 return 1200 * Math.log2(numerator / 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 */\nexport const JUST_RATIOS: Record<number, [number, number]> = {\n 0: [1, 1],\n 1: [16, 15],\n 2: [9, 8],\n 3: [6, 5],\n 4: [5, 4],\n 5: [4, 3],\n 6: [45, 32],\n 7: [3, 2],\n 8: [8, 5],\n 9: [5, 3],\n 10: [9, 5],\n 11: [15, 8],\n 12: [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, or NaN if the class has no listed ratio.\n * @category Pitch & Intervals\n */\nexport function justDeviationCents(semitoneClass: number): number {\n const ratio = JUST_RATIOS[semitoneClass];\n if (!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, c as beatsPerBar, f as formatTimeSignature, i as isCompound, d as isStrongBeat, m as metricWeight, p as parseTimeSignature, e as pulsesPerBar, t as tuplet } from '../index-Cl7mhOFM.cjs';
|
|
2
|
+
export { N as NoteData, S as SpelledInterval, f as formatNote, m as midiToNote, n as noteToMidi, a as noteToPitchClass, p as parseNote, s as spelledInterval } from '../index-CGMZNCx6.cjs';
|
|
3
|
+
export { K as KeyScale, N as NoteEvent } from '../types-MGP29r3t.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Counterpoint classification of a harmonic interval.
|
|
7
|
+
*
|
|
8
|
+
* @category Pitch & Intervals
|
|
9
|
+
*/
|
|
10
|
+
declare enum IntervalQuality {
|
|
11
|
+
PerfectConsonance = 0,
|
|
12
|
+
ImperfectConsonance = 1,
|
|
13
|
+
Dissonance = 2
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Classify an interval for counterpoint evaluation.
|
|
17
|
+
*
|
|
18
|
+
* The interval is reduced modulo 12, so compound intervals classify as their
|
|
19
|
+
* simple equivalents. The perfect fourth (5) is context-dependent: with
|
|
20
|
+
* `twoVoice` (the default) it classifies as a dissonance, matching
|
|
21
|
+
* {@link isConsonantInterval}; otherwise it is an imperfect consonance.
|
|
22
|
+
*
|
|
23
|
+
* @param semitones Interval size in semitones (may be negative or compound).
|
|
24
|
+
* @param twoVoice When true, the perfect fourth is treated as dissonant.
|
|
25
|
+
* @returns The counterpoint quality of the interval.
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { classifyInterval, IntervalQuality } from '@libraz/libcantus';
|
|
29
|
+
* classifyInterval(7); // IntervalQuality.PerfectConsonance
|
|
30
|
+
* classifyInterval(5); // IntervalQuality.Dissonance (two-voice)
|
|
31
|
+
* classifyInterval(5, false); // IntervalQuality.ImperfectConsonance
|
|
32
|
+
* ```
|
|
33
|
+
* @category Pitch & Intervals
|
|
34
|
+
*/
|
|
35
|
+
declare function classifyInterval(semitones: number, twoVoice?: boolean): IntervalQuality;
|
|
36
|
+
/**
|
|
37
|
+
* Test whether an interval is a perfect interval (unison/octave or fifth).
|
|
38
|
+
*
|
|
39
|
+
* @param semitones Interval size in semitones (may be negative or compound).
|
|
40
|
+
* @returns True for the unison/octave (0) and the perfect fifth (7) mod 12.
|
|
41
|
+
* @category Pitch & Intervals
|
|
42
|
+
*/
|
|
43
|
+
declare function isPerfectInterval(semitones: number): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Test whether an interval is consonant.
|
|
46
|
+
*
|
|
47
|
+
* The consonant set is {0, 3, 4, 5, 7, 8, 9} mod 12. In two-voice counterpoint
|
|
48
|
+
* the perfect fourth (5) is treated as a dissonance, so `twoVoice` set to true
|
|
49
|
+
* excludes it.
|
|
50
|
+
*
|
|
51
|
+
* @param semitones Interval size in semitones (may be negative or compound).
|
|
52
|
+
* @param twoVoice When true, the perfect fourth is treated as dissonant.
|
|
53
|
+
* @returns True if the interval is consonant in the given context.
|
|
54
|
+
* @category Pitch & Intervals
|
|
55
|
+
*/
|
|
56
|
+
declare function isConsonantInterval(semitones: number, twoVoice?: boolean): boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Deterministic seeded pseudo-random number generation shared across the
|
|
60
|
+
* generative modules (rhythm, drums, bass, groove, counter-melody). A single
|
|
61
|
+
* mulberry32 core exposes the small set of samplers those modules need; given a
|
|
62
|
+
* seed the stream is fully reproducible.
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* A deterministic PRNG with the sampling helpers the generators need.
|
|
66
|
+
*
|
|
67
|
+
* @category Utilities
|
|
68
|
+
*/
|
|
69
|
+
type Rng = {
|
|
70
|
+
/** Next float in [0, 1). */
|
|
71
|
+
next: () => number;
|
|
72
|
+
/** True with probability `p`. */
|
|
73
|
+
prob: (p: number) => boolean;
|
|
74
|
+
/** Integer in the inclusive range [lo, hi]. */
|
|
75
|
+
range: (lo: number, hi: number) => number;
|
|
76
|
+
/** Float in [lo, hi). */
|
|
77
|
+
float: (lo: number, hi: number) => number;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Create a seeded PRNG (mulberry32) exposing the shared samplers.
|
|
81
|
+
*
|
|
82
|
+
* @param seed The 32-bit seed; the same seed always yields the same stream.
|
|
83
|
+
* @returns The seeded generator.
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { createRng } from '@libraz/libcantus';
|
|
87
|
+
* const rng = createRng(42);
|
|
88
|
+
* rng.next(); // deterministic float in [0, 1)
|
|
89
|
+
* rng.range(1, 6); // deterministic integer in [1, 6]
|
|
90
|
+
* ```
|
|
91
|
+
* @category Utilities
|
|
92
|
+
*/
|
|
93
|
+
declare function createRng(seed: number): Rng;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Tuning and microtonality: frequency conversion, cents, arbitrary equal
|
|
97
|
+
* temperaments (EDO), and just-intonation ratios.
|
|
98
|
+
*
|
|
99
|
+
* The rest of the library reasons in twelve-tone pitch classes, which is a
|
|
100
|
+
* deliberate scope choice for tonal theory. This module is the escape hatch for
|
|
101
|
+
* anyone who needs actual frequencies, cents, non-12 equal temperaments, or the
|
|
102
|
+
* acoustic (just) tuning behind the tempered intervals.
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* An equal-tempered tuning: a reference pitch and a number of equal divisions of
|
|
106
|
+
* the octave. With `divisions === 12` a step index is an ordinary MIDI number.
|
|
107
|
+
*
|
|
108
|
+
* @category Pitch & Intervals
|
|
109
|
+
*/
|
|
110
|
+
type Tuning = {
|
|
111
|
+
/** Step index (MIDI number when `divisions` is 12) whose frequency is `refFreq`. */
|
|
112
|
+
refStep: number;
|
|
113
|
+
/** Frequency in Hz of `refStep`. */
|
|
114
|
+
refFreq: number;
|
|
115
|
+
/** Equal divisions of the octave (12 standard; e.g. 19 or 31 for microtonal). */
|
|
116
|
+
divisions: number;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Standard twelve-tone equal temperament, A4 (MIDI 69) = 440 Hz.
|
|
120
|
+
*
|
|
121
|
+
* @category Pitch & Intervals
|
|
122
|
+
*/
|
|
123
|
+
declare const TWELVE_TET: Tuning;
|
|
124
|
+
/**
|
|
125
|
+
* Build an equal temperament with `n` divisions of the octave.
|
|
126
|
+
*
|
|
127
|
+
* @param n Divisions of the octave (e.g. 19, 24, 31).
|
|
128
|
+
* @param refFreq Reference frequency in Hz (default 440).
|
|
129
|
+
* @param refStep Step index of the reference (default 69).
|
|
130
|
+
* @returns The tuning.
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { edo, frequencyOf } from '@libraz/libcantus';
|
|
134
|
+
* const et19 = edo(19); // { refStep: 69, refFreq: 440, divisions: 19 }
|
|
135
|
+
* frequencyOf(70, et19); // one 19-EDO step above A4
|
|
136
|
+
* ```
|
|
137
|
+
* @category Pitch & Intervals
|
|
138
|
+
*/
|
|
139
|
+
declare function edo(n: number, refFreq?: number, refStep?: number): Tuning;
|
|
140
|
+
/**
|
|
141
|
+
* Frequency in Hz of a step index under a tuning.
|
|
142
|
+
*
|
|
143
|
+
* @param step Step index (a MIDI number under 12-EDO).
|
|
144
|
+
* @param tuning The tuning (default 12-TET).
|
|
145
|
+
* @returns The frequency in Hz.
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* import { frequencyOf } from '@libraz/libcantus';
|
|
149
|
+
* frequencyOf(69); // 440 (A4 in 12-TET)
|
|
150
|
+
* frequencyOf(60); // middle C in Hz
|
|
151
|
+
* ```
|
|
152
|
+
* @category Pitch & Intervals
|
|
153
|
+
*/
|
|
154
|
+
declare function frequencyOf(step: number, tuning?: Tuning): number;
|
|
155
|
+
/**
|
|
156
|
+
* Nearest step index to a frequency under a tuning (the inverse of
|
|
157
|
+
* {@link frequencyOf}, rounded).
|
|
158
|
+
*
|
|
159
|
+
* @param freq Frequency in Hz.
|
|
160
|
+
* @param tuning The tuning (default 12-TET).
|
|
161
|
+
* @returns The nearest step index.
|
|
162
|
+
* @category Pitch & Intervals
|
|
163
|
+
*/
|
|
164
|
+
declare function nearestStep(freq: number, tuning?: Tuning): number;
|
|
165
|
+
/**
|
|
166
|
+
* Interval in cents between two frequencies.
|
|
167
|
+
*
|
|
168
|
+
* @param a Lower/first frequency in Hz.
|
|
169
|
+
* @param b Upper/second frequency in Hz.
|
|
170
|
+
* @returns Cents from `a` to `b` (negative if `b` is lower).
|
|
171
|
+
* @category Pitch & Intervals
|
|
172
|
+
*/
|
|
173
|
+
declare function centsBetweenFreq(a: number, b: number): number;
|
|
174
|
+
/**
|
|
175
|
+
* Cents spanned by a number of equal-temperament steps.
|
|
176
|
+
*
|
|
177
|
+
* @param steps Number of steps.
|
|
178
|
+
* @param tuning The tuning (default 12-TET).
|
|
179
|
+
* @returns The cents.
|
|
180
|
+
* @category Pitch & Intervals
|
|
181
|
+
*/
|
|
182
|
+
declare function centsOfSteps(steps: number, tuning?: Tuning): number;
|
|
183
|
+
/**
|
|
184
|
+
* Cents of a frequency ratio, e.g. `ratioToCents(3, 2)` ≈ 701.955 for the just
|
|
185
|
+
* perfect fifth.
|
|
186
|
+
*
|
|
187
|
+
* @param numerator Ratio numerator.
|
|
188
|
+
* @param denominator Ratio denominator.
|
|
189
|
+
* @returns The interval in cents.
|
|
190
|
+
* @category Pitch & Intervals
|
|
191
|
+
*/
|
|
192
|
+
declare function ratioToCents(numerator: number, denominator: number): number;
|
|
193
|
+
/**
|
|
194
|
+
* Five-limit just-intonation ratios for the twelve interval classes above a
|
|
195
|
+
* unison, indexed by semitone class (0..12).
|
|
196
|
+
*
|
|
197
|
+
* @category Pitch & Intervals
|
|
198
|
+
*/
|
|
199
|
+
declare const JUST_RATIOS: Record<number, [number, number]>;
|
|
200
|
+
/**
|
|
201
|
+
* Cents by which a five-limit just interval departs from its 12-TET tempering
|
|
202
|
+
* (positive means the just interval is wider).
|
|
203
|
+
*
|
|
204
|
+
* @param semitoneClass Semitone class in [0, 12].
|
|
205
|
+
* @returns The deviation in cents, or NaN if the class has no listed ratio.
|
|
206
|
+
* @category Pitch & Intervals
|
|
207
|
+
*/
|
|
208
|
+
declare function justDeviationCents(semitoneClass: number): number;
|
|
209
|
+
|
|
210
|
+
export { IntervalQuality, JUST_RATIOS, type Rng, TWELVE_TET, type Tuning, centsBetweenFreq, centsOfSteps, classifyInterval, createRng, edo, frequencyOf, isConsonantInterval, isPerfectInterval, justDeviationCents, nearestStep, ratioToCents };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
export { B as BarPosition, T as TimeSignature, b as barPositionToBeat, a as beatToBarPosition, c as beatsPerBar, f as formatTimeSignature, i as isCompound, d as isStrongBeat, m as metricWeight, p as parseTimeSignature, e as pulsesPerBar, t as tuplet } from '../index-Cl7mhOFM.js';
|
|
2
|
+
export { N as NoteData, S as SpelledInterval, f as formatNote, m as midiToNote, n as noteToMidi, a as noteToPitchClass, p as parseNote, s as spelledInterval } from '../index-CGMZNCx6.js';
|
|
3
|
+
export { K as KeyScale, N as NoteEvent } from '../types-MGP29r3t.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Counterpoint classification of a harmonic interval.
|
|
7
|
+
*
|
|
8
|
+
* @category Pitch & Intervals
|
|
9
|
+
*/
|
|
10
|
+
declare enum IntervalQuality {
|
|
11
|
+
PerfectConsonance = 0,
|
|
12
|
+
ImperfectConsonance = 1,
|
|
13
|
+
Dissonance = 2
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Classify an interval for counterpoint evaluation.
|
|
17
|
+
*
|
|
18
|
+
* The interval is reduced modulo 12, so compound intervals classify as their
|
|
19
|
+
* simple equivalents. The perfect fourth (5) is context-dependent: with
|
|
20
|
+
* `twoVoice` (the default) it classifies as a dissonance, matching
|
|
21
|
+
* {@link isConsonantInterval}; otherwise it is an imperfect consonance.
|
|
22
|
+
*
|
|
23
|
+
* @param semitones Interval size in semitones (may be negative or compound).
|
|
24
|
+
* @param twoVoice When true, the perfect fourth is treated as dissonant.
|
|
25
|
+
* @returns The counterpoint quality of the interval.
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { classifyInterval, IntervalQuality } from '@libraz/libcantus';
|
|
29
|
+
* classifyInterval(7); // IntervalQuality.PerfectConsonance
|
|
30
|
+
* classifyInterval(5); // IntervalQuality.Dissonance (two-voice)
|
|
31
|
+
* classifyInterval(5, false); // IntervalQuality.ImperfectConsonance
|
|
32
|
+
* ```
|
|
33
|
+
* @category Pitch & Intervals
|
|
34
|
+
*/
|
|
35
|
+
declare function classifyInterval(semitones: number, twoVoice?: boolean): IntervalQuality;
|
|
36
|
+
/**
|
|
37
|
+
* Test whether an interval is a perfect interval (unison/octave or fifth).
|
|
38
|
+
*
|
|
39
|
+
* @param semitones Interval size in semitones (may be negative or compound).
|
|
40
|
+
* @returns True for the unison/octave (0) and the perfect fifth (7) mod 12.
|
|
41
|
+
* @category Pitch & Intervals
|
|
42
|
+
*/
|
|
43
|
+
declare function isPerfectInterval(semitones: number): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Test whether an interval is consonant.
|
|
46
|
+
*
|
|
47
|
+
* The consonant set is {0, 3, 4, 5, 7, 8, 9} mod 12. In two-voice counterpoint
|
|
48
|
+
* the perfect fourth (5) is treated as a dissonance, so `twoVoice` set to true
|
|
49
|
+
* excludes it.
|
|
50
|
+
*
|
|
51
|
+
* @param semitones Interval size in semitones (may be negative or compound).
|
|
52
|
+
* @param twoVoice When true, the perfect fourth is treated as dissonant.
|
|
53
|
+
* @returns True if the interval is consonant in the given context.
|
|
54
|
+
* @category Pitch & Intervals
|
|
55
|
+
*/
|
|
56
|
+
declare function isConsonantInterval(semitones: number, twoVoice?: boolean): boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Deterministic seeded pseudo-random number generation shared across the
|
|
60
|
+
* generative modules (rhythm, drums, bass, groove, counter-melody). A single
|
|
61
|
+
* mulberry32 core exposes the small set of samplers those modules need; given a
|
|
62
|
+
* seed the stream is fully reproducible.
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* A deterministic PRNG with the sampling helpers the generators need.
|
|
66
|
+
*
|
|
67
|
+
* @category Utilities
|
|
68
|
+
*/
|
|
69
|
+
type Rng = {
|
|
70
|
+
/** Next float in [0, 1). */
|
|
71
|
+
next: () => number;
|
|
72
|
+
/** True with probability `p`. */
|
|
73
|
+
prob: (p: number) => boolean;
|
|
74
|
+
/** Integer in the inclusive range [lo, hi]. */
|
|
75
|
+
range: (lo: number, hi: number) => number;
|
|
76
|
+
/** Float in [lo, hi). */
|
|
77
|
+
float: (lo: number, hi: number) => number;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Create a seeded PRNG (mulberry32) exposing the shared samplers.
|
|
81
|
+
*
|
|
82
|
+
* @param seed The 32-bit seed; the same seed always yields the same stream.
|
|
83
|
+
* @returns The seeded generator.
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { createRng } from '@libraz/libcantus';
|
|
87
|
+
* const rng = createRng(42);
|
|
88
|
+
* rng.next(); // deterministic float in [0, 1)
|
|
89
|
+
* rng.range(1, 6); // deterministic integer in [1, 6]
|
|
90
|
+
* ```
|
|
91
|
+
* @category Utilities
|
|
92
|
+
*/
|
|
93
|
+
declare function createRng(seed: number): Rng;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Tuning and microtonality: frequency conversion, cents, arbitrary equal
|
|
97
|
+
* temperaments (EDO), and just-intonation ratios.
|
|
98
|
+
*
|
|
99
|
+
* The rest of the library reasons in twelve-tone pitch classes, which is a
|
|
100
|
+
* deliberate scope choice for tonal theory. This module is the escape hatch for
|
|
101
|
+
* anyone who needs actual frequencies, cents, non-12 equal temperaments, or the
|
|
102
|
+
* acoustic (just) tuning behind the tempered intervals.
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* An equal-tempered tuning: a reference pitch and a number of equal divisions of
|
|
106
|
+
* the octave. With `divisions === 12` a step index is an ordinary MIDI number.
|
|
107
|
+
*
|
|
108
|
+
* @category Pitch & Intervals
|
|
109
|
+
*/
|
|
110
|
+
type Tuning = {
|
|
111
|
+
/** Step index (MIDI number when `divisions` is 12) whose frequency is `refFreq`. */
|
|
112
|
+
refStep: number;
|
|
113
|
+
/** Frequency in Hz of `refStep`. */
|
|
114
|
+
refFreq: number;
|
|
115
|
+
/** Equal divisions of the octave (12 standard; e.g. 19 or 31 for microtonal). */
|
|
116
|
+
divisions: number;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Standard twelve-tone equal temperament, A4 (MIDI 69) = 440 Hz.
|
|
120
|
+
*
|
|
121
|
+
* @category Pitch & Intervals
|
|
122
|
+
*/
|
|
123
|
+
declare const TWELVE_TET: Tuning;
|
|
124
|
+
/**
|
|
125
|
+
* Build an equal temperament with `n` divisions of the octave.
|
|
126
|
+
*
|
|
127
|
+
* @param n Divisions of the octave (e.g. 19, 24, 31).
|
|
128
|
+
* @param refFreq Reference frequency in Hz (default 440).
|
|
129
|
+
* @param refStep Step index of the reference (default 69).
|
|
130
|
+
* @returns The tuning.
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { edo, frequencyOf } from '@libraz/libcantus';
|
|
134
|
+
* const et19 = edo(19); // { refStep: 69, refFreq: 440, divisions: 19 }
|
|
135
|
+
* frequencyOf(70, et19); // one 19-EDO step above A4
|
|
136
|
+
* ```
|
|
137
|
+
* @category Pitch & Intervals
|
|
138
|
+
*/
|
|
139
|
+
declare function edo(n: number, refFreq?: number, refStep?: number): Tuning;
|
|
140
|
+
/**
|
|
141
|
+
* Frequency in Hz of a step index under a tuning.
|
|
142
|
+
*
|
|
143
|
+
* @param step Step index (a MIDI number under 12-EDO).
|
|
144
|
+
* @param tuning The tuning (default 12-TET).
|
|
145
|
+
* @returns The frequency in Hz.
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* import { frequencyOf } from '@libraz/libcantus';
|
|
149
|
+
* frequencyOf(69); // 440 (A4 in 12-TET)
|
|
150
|
+
* frequencyOf(60); // middle C in Hz
|
|
151
|
+
* ```
|
|
152
|
+
* @category Pitch & Intervals
|
|
153
|
+
*/
|
|
154
|
+
declare function frequencyOf(step: number, tuning?: Tuning): number;
|
|
155
|
+
/**
|
|
156
|
+
* Nearest step index to a frequency under a tuning (the inverse of
|
|
157
|
+
* {@link frequencyOf}, rounded).
|
|
158
|
+
*
|
|
159
|
+
* @param freq Frequency in Hz.
|
|
160
|
+
* @param tuning The tuning (default 12-TET).
|
|
161
|
+
* @returns The nearest step index.
|
|
162
|
+
* @category Pitch & Intervals
|
|
163
|
+
*/
|
|
164
|
+
declare function nearestStep(freq: number, tuning?: Tuning): number;
|
|
165
|
+
/**
|
|
166
|
+
* Interval in cents between two frequencies.
|
|
167
|
+
*
|
|
168
|
+
* @param a Lower/first frequency in Hz.
|
|
169
|
+
* @param b Upper/second frequency in Hz.
|
|
170
|
+
* @returns Cents from `a` to `b` (negative if `b` is lower).
|
|
171
|
+
* @category Pitch & Intervals
|
|
172
|
+
*/
|
|
173
|
+
declare function centsBetweenFreq(a: number, b: number): number;
|
|
174
|
+
/**
|
|
175
|
+
* Cents spanned by a number of equal-temperament steps.
|
|
176
|
+
*
|
|
177
|
+
* @param steps Number of steps.
|
|
178
|
+
* @param tuning The tuning (default 12-TET).
|
|
179
|
+
* @returns The cents.
|
|
180
|
+
* @category Pitch & Intervals
|
|
181
|
+
*/
|
|
182
|
+
declare function centsOfSteps(steps: number, tuning?: Tuning): number;
|
|
183
|
+
/**
|
|
184
|
+
* Cents of a frequency ratio, e.g. `ratioToCents(3, 2)` ≈ 701.955 for the just
|
|
185
|
+
* perfect fifth.
|
|
186
|
+
*
|
|
187
|
+
* @param numerator Ratio numerator.
|
|
188
|
+
* @param denominator Ratio denominator.
|
|
189
|
+
* @returns The interval in cents.
|
|
190
|
+
* @category Pitch & Intervals
|
|
191
|
+
*/
|
|
192
|
+
declare function ratioToCents(numerator: number, denominator: number): number;
|
|
193
|
+
/**
|
|
194
|
+
* Five-limit just-intonation ratios for the twelve interval classes above a
|
|
195
|
+
* unison, indexed by semitone class (0..12).
|
|
196
|
+
*
|
|
197
|
+
* @category Pitch & Intervals
|
|
198
|
+
*/
|
|
199
|
+
declare const JUST_RATIOS: Record<number, [number, number]>;
|
|
200
|
+
/**
|
|
201
|
+
* Cents by which a five-limit just interval departs from its 12-TET tempering
|
|
202
|
+
* (positive means the just interval is wider).
|
|
203
|
+
*
|
|
204
|
+
* @param semitoneClass Semitone class in [0, 12].
|
|
205
|
+
* @returns The deviation in cents, or NaN if the class has no listed ratio.
|
|
206
|
+
* @category Pitch & Intervals
|
|
207
|
+
*/
|
|
208
|
+
declare function justDeviationCents(semitoneClass: number): number;
|
|
209
|
+
|
|
210
|
+
export { IntervalQuality, JUST_RATIOS, type Rng, TWELVE_TET, type Tuning, centsBetweenFreq, centsOfSteps, classifyInterval, createRng, edo, frequencyOf, isConsonantInterval, isPerfectInterval, justDeviationCents, nearestStep, ratioToCents };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JUST_RATIOS,
|
|
3
|
+
TWELVE_TET,
|
|
4
|
+
centsBetweenFreq,
|
|
5
|
+
centsOfSteps,
|
|
6
|
+
edo,
|
|
7
|
+
frequencyOf,
|
|
8
|
+
justDeviationCents,
|
|
9
|
+
nearestStep,
|
|
10
|
+
ratioToCents
|
|
11
|
+
} from "../chunk-ZXW5YIWK.js";
|
|
12
|
+
import {
|
|
13
|
+
createRng
|
|
14
|
+
} from "../chunk-BHUT2S5G.js";
|
|
15
|
+
import {
|
|
16
|
+
barPositionToBeat,
|
|
17
|
+
beatToBarPosition,
|
|
18
|
+
beatsPerBar,
|
|
19
|
+
formatTimeSignature,
|
|
20
|
+
isCompound,
|
|
21
|
+
isStrongBeat,
|
|
22
|
+
metricWeight,
|
|
23
|
+
parseTimeSignature,
|
|
24
|
+
pulsesPerBar,
|
|
25
|
+
tuplet
|
|
26
|
+
} from "../chunk-MSWFZF7J.js";
|
|
27
|
+
import {
|
|
28
|
+
formatNote,
|
|
29
|
+
midiToNote,
|
|
30
|
+
noteToMidi,
|
|
31
|
+
noteToPitchClass,
|
|
32
|
+
parseNote,
|
|
33
|
+
spelledInterval
|
|
34
|
+
} from "../chunk-DYWFNC4A.js";
|
|
35
|
+
import {
|
|
36
|
+
IntervalQuality,
|
|
37
|
+
classifyInterval,
|
|
38
|
+
isConsonantInterval,
|
|
39
|
+
isPerfectInterval
|
|
40
|
+
} from "../chunk-CCBLVAPK.js";
|
|
41
|
+
export {
|
|
42
|
+
IntervalQuality,
|
|
43
|
+
JUST_RATIOS,
|
|
44
|
+
TWELVE_TET,
|
|
45
|
+
barPositionToBeat,
|
|
46
|
+
beatToBarPosition,
|
|
47
|
+
beatsPerBar,
|
|
48
|
+
centsBetweenFreq,
|
|
49
|
+
centsOfSteps,
|
|
50
|
+
classifyInterval,
|
|
51
|
+
createRng,
|
|
52
|
+
edo,
|
|
53
|
+
formatNote,
|
|
54
|
+
formatTimeSignature,
|
|
55
|
+
frequencyOf,
|
|
56
|
+
isCompound,
|
|
57
|
+
isConsonantInterval,
|
|
58
|
+
isPerfectInterval,
|
|
59
|
+
isStrongBeat,
|
|
60
|
+
justDeviationCents,
|
|
61
|
+
metricWeight,
|
|
62
|
+
midiToNote,
|
|
63
|
+
nearestStep,
|
|
64
|
+
noteToMidi,
|
|
65
|
+
noteToPitchClass,
|
|
66
|
+
parseNote,
|
|
67
|
+
parseTimeSignature,
|
|
68
|
+
pulsesPerBar,
|
|
69
|
+
ratioToCents,
|
|
70
|
+
spelledInterval,
|
|
71
|
+
tuplet
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|