@r_masseater/song-format 0.1.0 → 0.2.1

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.
Files changed (57) hide show
  1. package/README.md +33 -1
  2. package/dist/als-to-fumx.mjs +525 -0
  3. package/dist/als-to-fumx.mjs.map +1 -0
  4. package/dist/analysis.d.mts +95 -0
  5. package/dist/analysis.mjs +328 -0
  6. package/dist/analysis.mjs.map +1 -0
  7. package/dist/convert-als.d.mts +18 -0
  8. package/dist/convert-als.mjs +512 -0
  9. package/dist/convert-als.mjs.map +1 -0
  10. package/dist/convert-midi.d.mts +2 -75
  11. package/dist/convert-midi.mjs +5 -650
  12. package/dist/convert-midi.mjs.map +1 -1
  13. package/dist/fumx-language-server.mjs +1 -1
  14. package/dist/fumx-language-server.mjs.map +1 -1
  15. package/dist/fumx-module-CqxUe07y.mjs +12485 -0
  16. package/dist/fumx-module-CqxUe07y.mjs.map +1 -0
  17. package/dist/fumx-module-CtXvLKU1.mjs +2632 -0
  18. package/dist/fumx-module-CtXvLKU1.mjs.map +1 -0
  19. package/dist/grammar-86_uhiTo.mjs +9836 -0
  20. package/dist/grammar-86_uhiTo.mjs.map +1 -0
  21. package/dist/index-Cup9xTad.d.mts +105 -0
  22. package/dist/index-DPt8MZ6e.d.mts +796 -0
  23. package/dist/index-JXjnMHXw.d.mts +1350 -0
  24. package/dist/index.d.mts +9 -0
  25. package/dist/index.mjs +4 -0
  26. package/dist/language.d.mts +13 -0
  27. package/dist/language.mjs +3 -0
  28. package/dist/mapper.mjs +1 -1
  29. package/dist/midi-to-fumx.mjs +12 -854
  30. package/dist/midi-to-fumx.mjs.map +1 -1
  31. package/dist/read-song-BzqX5MuZ.mjs +122 -0
  32. package/dist/read-song-BzqX5MuZ.mjs.map +1 -0
  33. package/dist/read-song-CzMPm8u8.mjs +123 -0
  34. package/dist/read-song-CzMPm8u8.mjs.map +1 -0
  35. package/dist/round-trip-Cz8iQlpW.mjs +946 -0
  36. package/dist/round-trip-Cz8iQlpW.mjs.map +1 -0
  37. package/dist/run-main-Bf32CgzU.mjs +26 -0
  38. package/dist/run-main-Bf32CgzU.mjs.map +1 -0
  39. package/dist/song-3Zm9g84K.d.mts +1478 -0
  40. package/dist/song-CYFBSTbH.mjs +387 -0
  41. package/dist/song-CYFBSTbH.mjs.map +1 -0
  42. package/dist/song-report.mjs +327 -4
  43. package/dist/song-report.mjs.map +1 -1
  44. package/dist/ticks-CXehHP2w.mjs +27 -0
  45. package/dist/ticks-CXehHP2w.mjs.map +1 -0
  46. package/dist/{transform-C24h3upp.mjs → transform-BoSDqqPW.mjs} +4 -3
  47. package/dist/transform-BoSDqqPW.mjs.map +1 -0
  48. package/dist/vite.mjs +4 -3
  49. package/dist/vite.mjs.map +1 -1
  50. package/dist/write-CuDbIkpM.mjs +747 -0
  51. package/dist/write-CuDbIkpM.mjs.map +1 -0
  52. package/package.json +49 -12
  53. package/skills/read-fumx/SKILL.md +85 -0
  54. package/skills/use-fumx-tools/SKILL.md +1 -2
  55. package/dist/app-CdpGdiWq.mjs +0 -190
  56. package/dist/app-CdpGdiWq.mjs.map +0 -1
  57. package/dist/transform-C24h3upp.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-CuDbIkpM.mjs","names":["NONE","NEXT","Arr","Rec","Arr","Rec","Str","NONE","NEXT","Arr","Rec","Arr","NONE","FULL","Arr","Str","NONE","NEXT","Arr","NEXT","headOf","cellsOf","Arr","Rec","Arr","SINGLE","Arr","Arr"],"sources":["../src/entities/timeline/model/general-midi.ts","../src/entities/timeline/model/groups.ts","../src/entities/timeline/model/names.ts","../src/entities/timeline/model/plan.ts","../src/entities/timeline/model/tempo-units.ts","../src/entities/timeline/model/events.ts","../src/entities/timeline/model/cells.ts","../src/entities/timeline/model/layout.ts","../src/entities/timeline/model/control-lines.ts","../src/entities/timeline/model/mix-lines.ts","../src/entities/timeline/model/voice-lines.ts","../src/entities/timeline/model/write.ts"],"sourcesContent":["export const PROGRAMS = [\n \"acoustic-grand-piano\",\n \"bright-acoustic-piano\",\n \"electric-grand-piano\",\n \"honky-tonk-piano\",\n \"electric-piano-1\",\n \"electric-piano-2\",\n \"harpsichord\",\n \"clavinet\",\n \"celesta\",\n \"glockenspiel\",\n \"music-box\",\n \"vibraphone\",\n \"marimba\",\n \"xylophone\",\n \"tubular-bells\",\n \"dulcimer\",\n \"drawbar-organ\",\n \"percussive-organ\",\n \"rock-organ\",\n \"church-organ\",\n \"reed-organ\",\n \"accordion\",\n \"harmonica\",\n \"tango-accordion\",\n \"acoustic-guitar-nylon\",\n \"acoustic-guitar-steel\",\n \"electric-guitar-jazz\",\n \"electric-guitar-clean\",\n \"electric-guitar-muted\",\n \"overdriven-guitar\",\n \"distortion-guitar\",\n \"guitar-harmonics\",\n \"acoustic-bass\",\n \"electric-bass-finger\",\n \"electric-bass-pick\",\n \"fretless-bass\",\n \"slap-bass-1\",\n \"slap-bass-2\",\n \"synth-bass-1\",\n \"synth-bass-2\",\n \"violin\",\n \"viola\",\n \"cello\",\n \"contrabass\",\n \"tremolo-strings\",\n \"pizzicato-strings\",\n \"orchestral-harp\",\n \"timpani\",\n \"string-ensemble-1\",\n \"string-ensemble-2\",\n \"synth-strings-1\",\n \"synth-strings-2\",\n \"choir-aahs\",\n \"voice-oohs\",\n \"synth-voice\",\n \"orchestra-hit\",\n \"trumpet\",\n \"trombone\",\n \"tuba\",\n \"muted-trumpet\",\n \"french-horn\",\n \"brass-section\",\n \"synth-brass-1\",\n \"synth-brass-2\",\n \"soprano-sax\",\n \"alto-sax\",\n \"tenor-sax\",\n \"baritone-sax\",\n \"oboe\",\n \"english-horn\",\n \"bassoon\",\n \"clarinet\",\n \"piccolo\",\n \"flute\",\n \"recorder\",\n \"pan-flute\",\n \"blown-bottle\",\n \"shakuhachi\",\n \"whistle\",\n \"ocarina\",\n \"lead-1-square\",\n \"lead-2-sawtooth\",\n \"lead-3-calliope\",\n \"lead-4-chiff\",\n \"lead-5-charang\",\n \"lead-6-voice\",\n \"lead-7-fifths\",\n \"lead-8-bass-and-lead\",\n \"pad-1-new-age\",\n \"pad-2-warm\",\n \"pad-3-polysynth\",\n \"pad-4-choir\",\n \"pad-5-bowed\",\n \"pad-6-metallic\",\n \"pad-7-halo\",\n \"pad-8-sweep\",\n \"fx-1-rain\",\n \"fx-2-soundtrack\",\n \"fx-3-crystal\",\n \"fx-4-atmosphere\",\n \"fx-5-brightness\",\n \"fx-6-goblins\",\n \"fx-7-echoes\",\n \"fx-8-sci-fi\",\n \"sitar\",\n \"banjo\",\n \"shamisen\",\n \"koto\",\n \"kalimba\",\n \"bagpipe\",\n \"fiddle\",\n \"shanai\",\n \"tinkle-bell\",\n \"agogo\",\n \"steel-drums\",\n \"woodblock\",\n \"taiko-drum\",\n \"melodic-tom\",\n \"synth-drum\",\n \"reverse-cymbal\",\n \"guitar-fret-noise\",\n \"breath-noise\",\n \"seashore\",\n \"bird-tweet\",\n \"telephone-ring\",\n \"helicopter\",\n \"applause\",\n \"gunshot\",\n] as const;\n\nexport const FIRST_DRUM = 35;\n\nexport const DRUMS = [\n \"acoustic-bass-drum\",\n \"bass-drum-1\",\n \"side-stick\",\n \"acoustic-snare\",\n \"hand-clap\",\n \"electric-snare\",\n \"low-floor-tom\",\n \"closed-hi-hat\",\n \"high-floor-tom\",\n \"pedal-hi-hat\",\n \"low-tom\",\n \"open-hi-hat\",\n \"low-mid-tom\",\n \"hi-mid-tom\",\n \"crash-cymbal-1\",\n \"high-tom\",\n \"ride-cymbal-1\",\n \"chinese-cymbal\",\n \"ride-bell\",\n \"tambourine\",\n \"splash-cymbal\",\n \"cowbell\",\n \"crash-cymbal-2\",\n \"vibraslap\",\n \"ride-cymbal-2\",\n \"hi-bongo\",\n \"low-bongo\",\n \"mute-hi-conga\",\n \"open-hi-conga\",\n \"low-conga\",\n \"high-timbale\",\n \"low-timbale\",\n \"high-agogo\",\n \"low-agogo\",\n \"cabasa\",\n \"maracas\",\n \"short-whistle\",\n \"long-whistle\",\n \"short-guiro\",\n \"long-guiro\",\n \"claves\",\n \"hi-wood-block\",\n \"low-wood-block\",\n \"mute-cuica\",\n \"open-cuica\",\n \"mute-triangle\",\n \"open-triangle\",\n] as const;\n\nexport const DRUM_CHANNEL = 9;\n","import { Array as Arr, Option, Order, Record as Rec, pipe } from \"effect\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\n\nimport type { Part, TimelineNote } from \"./events.ts\";\nimport { DRUM_CHANNEL } from \"./general-midi.ts\";\n\nconst NONE = 0;\nconst NEXT = 1;\n\nexport const isDrumPart: From<Part, boolean> = (part) => part.channel === DRUM_CHANNEL;\n\nexport interface Group {\n readonly start: number;\n readonly end: number;\n readonly midis: readonly number[];\n readonly velocity: number;\n readonly release: number;\n readonly lyric: Option.Option<string>;\n}\n\nexport type Line = readonly Group[];\n\nconst chordKeyOf: From<TimelineNote, string> = (note) =>\n `${String(note.tick)}:${String(note.end)}:${String(note.velocity)}:${String(note.release)}`;\n\nconst groupOf: From<readonly TimelineNote[], Option.Option<Group>> = (notes) =>\n pipe(\n Arr.head(notes),\n Option.map((first) => ({\n start: first.tick,\n end: first.end,\n midis: pipe(\n notes,\n Arr.map((note) => note.midi),\n ),\n velocity: first.velocity,\n release: first.release,\n lyric: Option.none(),\n })),\n );\n\nconst stackedOf: From<readonly TimelineNote[], readonly (readonly TimelineNote[])[]> = (chord) =>\n pipe(\n chord,\n Arr.map((note, index) => ({\n note,\n layer: pipe(\n Arr.take(chord, index),\n Arr.countBy((earlier) => earlier.midi === note.midi),\n ),\n })),\n Arr.groupBy(({ layer }) => String(layer)),\n Rec.values,\n Arr.map((layer) =>\n pipe(\n layer,\n Arr.map(({ note }) => note),\n ),\n ),\n );\n\nconst chordsOf: From<Part, readonly (readonly TimelineNote[])[]> = (part) => {\n if (isDrumPart(part)) {\n return pipe(\n part.notes,\n Arr.map((note) => [note]),\n );\n }\n return pipe(part.notes, Arr.groupBy(chordKeyOf), Rec.values, Arr.flatMap(stackedOf));\n};\n\nconst byStartThenLonger = Order.combine(\n Order.mapInput(Order.Number, (group: Group) => group.start),\n Order.mapInput(Order.flip(Order.Number), (group: Group) => group.end),\n);\n\nconst withLyrics =\n (part: Part): From<readonly Group[], readonly Group[]> =>\n (groups) =>\n pipe(\n groups,\n Arr.map((group, index) => {\n const leads = pipe(\n Arr.get(groups, index - NEXT),\n Option.match({\n onNone: () => true,\n onSome: (previous) => previous.start !== group.start,\n }),\n );\n const lyric = pipe(\n Arr.findFirst(part.lyrics, (candidate) => candidate.tick === group.start),\n Option.filter(() => leads),\n Option.map((found) => found.text),\n );\n return { ...group, lyric };\n }),\n );\n\nexport const groupsOf: From<Part, readonly Group[]> = (part) => {\n const groups = pipe(chordsOf(part), Arr.map(groupOf), Arr.getSomes);\n return withLyrics(part)(Arr.sort(groups, byStartThenLonger));\n};\n\nconst endOfLine: From<Line, number> = (line) =>\n Option.match(Arr.last(line), { onNone: () => NONE, onSome: (group) => group.end });\n\nconst placeGroup = (lines: readonly Line[], group: Group): readonly Line[] =>\n Option.match(\n Arr.findFirstIndex(lines, (line) => endOfLine(line) <= group.start),\n {\n onNone: () => [...lines, [group]],\n onSome: (index) =>\n pipe(\n lines,\n Arr.map((line, position): Line => {\n if (position === index) {\n return [...line, group];\n }\n return line;\n }),\n ),\n },\n );\n\nexport const linesOf: From<readonly Group[], readonly Line[]> = (groups) =>\n Arr.reduce(groups, [] as readonly Line[], placeGroup);\n","import { Array as Arr, Option, Record as Rec, String as Str, pipe } from \"effect\";\nimport { AstUtils, GrammarAST } from \"langium\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\nimport { FumxTerminals } from \"#generated/langium/ast.ts\";\nimport { FumxGrammar } from \"#generated/langium/grammar.ts\";\n\nconst FIRST_SUFFIX = 2;\n\nconst keywordsIn: From<GrammarAST.Grammar | GrammarAST.AbstractRule, ReadonlySet<string>> = (\n node,\n) =>\n new Set(\n AstUtils.streamAst(node)\n .filter((child): child is GrammarAST.Keyword => GrammarAST.isKeyword(child))\n .map((keyword) => keyword.value),\n );\n\nconst grammar = FumxGrammar();\n\nconst allowedKeywords = pipe(\n grammar.rules,\n Arr.findFirst((rule) => rule.name === \"Name\"),\n Option.match({ onNone: () => new Set<string>(), onSome: keywordsIn }),\n);\n\nconst allKeywords = Arr.fromIterable(keywordsIn(grammar));\n\nconst reserved = new Set(\n pipe(\n allKeywords,\n Arr.filter((keyword) => !allowedKeywords.has(keyword)),\n ),\n);\n\nconst otherTerminals = pipe(\n Rec.toEntries(FumxTerminals),\n Arr.filter(([name]) => name !== \"ID\"),\n Arr.map(([, pattern]) => new RegExp(`^(?:${pattern.source})$`, \"u\")),\n);\n\nconst identifier = new RegExp(`^(?:${FumxTerminals.ID.source})$`, \"u\");\n\nconst isUsable: From<string, boolean> = (name) =>\n identifier.test(name) &&\n !reserved.has(name) &&\n !pipe(\n otherTerminals,\n Arr.some((pattern) => pattern.test(name)),\n );\n\nconst slugOf: From<string, string> = (text) =>\n pipe(\n text,\n Str.normalize(\"NFKD\"),\n Str.toLowerCase,\n Str.replaceAll(/[^a-z0-9]+/gu, \"-\"),\n Str.replaceAll(/^[-0-9]+|-+$/gu, \"\"),\n );\n\nexport const nameFrom: From<readonly string[], string> = (candidates) =>\n pipe(\n candidates,\n Arr.map(slugOf),\n Arr.findFirst(isUsable),\n Option.getOrElse(() => \"part\"),\n );\n\nexport const uniqueAmong: From<ReadonlySet<string>, From<string, string>> = (taken) => (name) =>\n pipe(\n Arr.range(FIRST_SUFFIX, taken.size + FIRST_SUFFIX),\n Arr.map((suffix) => `${name}-${String(suffix)}`),\n Arr.prepend(name),\n Arr.findFirst((candidate) => isUsable(candidate) && !taken.has(candidate)),\n Option.getOrElse(() => `${name}-${String(taken.size)}`),\n );\n","import { Array as Arr, Option, Order, Record as Rec, pipe } from \"effect\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\n\nimport type { Level, Part, Timeline, TimelineControl, TrackMix } from \"./events.ts\";\nimport { DRUMS, FIRST_DRUM, PROGRAMS } from \"./general-midi.ts\";\nimport { groupsOf, isDrumPart, linesOf } from \"./groups.ts\";\nimport type { Line } from \"./groups.ts\";\nimport { nameFrom, uniqueAmong } from \"./names.ts\";\n\nconst NONE = 0;\nconst NEXT = 1;\nconst SHARED = 1;\nconst DEFAULT_PROGRAM = 0;\n\nexport type Source =\n | { readonly kind: \"instrument\"; readonly instrument: string; readonly program: number }\n | { readonly kind: \"kit\" };\n\nexport interface PlannedPart {\n readonly part: Part;\n readonly name: string;\n readonly source: Source;\n readonly lines: readonly Line[];\n readonly controls: readonly TimelineControl[];\n readonly mix: TrackMix;\n}\n\nexport interface PlannedBus {\n readonly name: string;\n readonly level: Level;\n}\n\nexport interface Plan {\n readonly parts: readonly PlannedPart[];\n readonly buses: readonly PlannedBus[];\n readonly instruments: ReadonlyMap<number, string>;\n readonly drumVoices: ReadonlyMap<number, string>;\n}\n\nconst drumNameOf: From<number, string> = (midi) =>\n Option.getOrElse(Arr.get(DRUMS, midi - FIRST_DRUM), () => `note-${String(midi)}`);\n\nconst programNameOf: From<number, string> = (program) =>\n Option.getOrElse(Arr.get(PROGRAMS, program), () => `program-${String(program)}`);\n\nexport const controllerKeyOf: From<Pick<TimelineControl, \"controller\">, string> = ({\n controller,\n}) => {\n if (controller.kind === \"cc\") {\n return `cc ${String(controller.number)}`;\n }\n if (controller.kind === \"pressure\") {\n return Option.match(controller.midi, {\n onNone: () => \"pressure\",\n onSome: (midi) => `pressure ${String(midi)}`,\n });\n }\n return controller.kind;\n};\n\nconst isLastAtTick: From<readonly TimelineControl[], From<number, boolean>> =\n (controls) => (index) =>\n pipe(\n Option.all([Arr.get(controls, index), Arr.get(controls, index + NEXT)]),\n Option.match({\n onNone: () => true,\n onSome: ([control, next]) =>\n next.tick !== control.tick || controllerKeyOf(next) !== controllerKeyOf(control),\n }),\n );\n\nconst byControllerThenTick = Order.combine(\n Order.mapInput(Order.String, controllerKeyOf),\n Order.mapInput(Order.Number, (control: TimelineControl) => control.tick),\n);\n\nconst controlsOf: From<Part, readonly TimelineControl[]> = (part) => {\n const drumProgram = pipe(\n part.program,\n Option.filter(() => isDrumPart(part)),\n Option.map((value): TimelineControl => ({\n tick: NONE,\n controller: { kind: \"program\" },\n value,\n })),\n Option.toArray,\n );\n const sorted = Arr.sort([...drumProgram, ...part.controls], byControllerThenTick);\n return pipe(\n sorted,\n Arr.filter((_control, index) => isLastAtTick(sorted)(index)),\n );\n};\n\nconst programOf: From<Part, number> = (part) =>\n Option.getOrElse(part.program, () => DEFAULT_PROGRAM);\n\nconst labelOf: From<Part, string> = (part) => Option.getOrElse(part.name, () => \"\");\n\nconst instrumentsOf: From<readonly Part[], ReadonlyMap<number, string>> = (parts) =>\n new Map(\n pipe(\n parts,\n Arr.filter((part) => !isDrumPart(part)),\n Arr.map(programOf),\n Arr.dedupe,\n Arr.map((program) => [program, nameFrom([programNameOf(program)])] as const),\n ),\n );\n\nconst drumVoicesOf: From<readonly Part[], ReadonlyMap<number, string>> = (parts) => {\n const midis = pipe(\n parts,\n Arr.filter(isDrumPart),\n Arr.flatMap((part) => part.notes),\n Arr.map((note) => note.midi),\n Arr.dedupe,\n );\n return new Map(\n pipe(\n Arr.sort(midis, Order.Number),\n Arr.map((midi) => [midi, drumNameOf(midi)] as const),\n ),\n );\n};\n\nconst channelledOf: From<ReadonlySet<string>, From<Part, string>> = (shared) => (part) => {\n const label = labelOf(part);\n if (shared.has(label)) {\n return `${label} ch${String(part.channel + NEXT)}`;\n }\n return label;\n};\n\nconst fallbackOf: From<Part, string> = (part) => {\n if (isDrumPart(part)) {\n return \"drums\";\n }\n return programNameOf(programOf(part));\n};\n\nconst candidatesOf: From<ReadonlySet<string>, From<Part, readonly string[]>> =\n (shared) => (part) => [\n channelledOf(shared)(part),\n fallbackOf(part),\n `track ${String(part.track)}`,\n ];\n\nconst sharedLabelsOf: From<readonly Part[], ReadonlySet<string>> = (parts) =>\n new Set(\n pipe(\n parts,\n Arr.groupBy(labelOf),\n Rec.filter((same) => same.length > SHARED),\n Rec.keys,\n ),\n );\n\nconst sourceOf: From<ReadonlyMap<number, string>, From<Part, Source>> = (instruments) => (part) => {\n if (isDrumPart(part)) {\n return { kind: \"kit\" };\n }\n const program = programOf(part);\n return { kind: \"instrument\", instrument: instruments.get(program) ?? \"\", program };\n};\n\nconst namesOf: From<readonly PlannedPart[], ReadonlySet<string>> = (planned) =>\n new Set(\n pipe(\n planned,\n Arr.map((done) => done.name),\n ),\n );\n\ninterface Naming {\n readonly instruments: Plan[\"instruments\"];\n readonly candidates: From<Part, readonly string[]>;\n readonly mixes: Timeline[\"mix\"][\"tracks\"];\n}\n\nconst UNMIXED: TrackMix = {\n level: { decibels: NONE, pan: NONE, muted: false },\n sends: [],\n envelopes: [],\n};\n\ntype Reducer<State, Item> = (state: State, item: Item) => State;\n\nconst NO_PARTS: readonly PlannedPart[] = [];\n\nconst nextPart: From<Naming, Reducer<readonly PlannedPart[], Part>> =\n (naming) => (planned, part) => {\n const name = uniqueAmong(namesOf(planned))(nameFrom(naming.candidates(part)));\n return Arr.append(planned, {\n part,\n name,\n source: sourceOf(naming.instruments)(part),\n lines: linesOf(groupsOf(part)),\n controls: controlsOf(part),\n mix: naming.mixes.get(part.track) ?? UNMIXED,\n });\n };\n\ntype BusNaming = Readonly<{ taken: ReadonlySet<string>; buses: Timeline[\"mix\"][\"buses\"] }>;\n\nconst busesOf: From<BusNaming, readonly PlannedBus[]> = ({ taken, buses }) => {\n const used = new Set(taken);\n const named: PlannedBus[] = [];\n for (const [index, bus] of buses.entries()) {\n const name = uniqueAmong(used)(\n nameFrom([...Option.toArray(bus.name), `bus ${String(index + NEXT)}`]),\n );\n used.add(name);\n named.push({ name, level: bus.level });\n }\n return named;\n};\n\nexport const planOf: From<Timeline, Plan> = (timeline) => {\n const instruments = instrumentsOf(timeline.parts);\n const candidates = candidatesOf(sharedLabelsOf(timeline.parts));\n const parts = Arr.reduce(\n timeline.parts,\n NO_PARTS,\n nextPart({ instruments, candidates, mixes: timeline.mix.tracks }),\n );\n return {\n parts,\n buses: busesOf({ taken: namesOf(parts), buses: timeline.mix.buses }),\n instruments,\n drumVoices: drumVoicesOf(timeline.parts),\n };\n};\n","import type { From } from \"#/shared/lib/from.ts\";\n\nconst MICROSECONDS_PER_MINUTE = 60_000_000;\n\nexport const bpmOf: From<number, number> = (microseconds) => MICROSECONDS_PER_MINUTE / microseconds;\n\nexport const microsecondsOf: From<number, number> = (bpm) =>\n Math.round(MICROSECONDS_PER_MINUTE / bpm);\n","import { Array as Arr, Order } from \"effect\";\nimport type { Option } from \"effect\";\n\nimport type { Controller, MixerParameter } from \"#/entities/song/@x/timeline.ts\";\n\nexport interface Timed {\n readonly tick: number;\n}\n\nexport interface TimelineNote extends Timed {\n readonly end: number;\n readonly midi: number;\n readonly velocity: number;\n readonly release: number;\n}\n\nexport interface TimelineControl extends Timed {\n readonly controller: Controller;\n readonly value: number;\n}\n\nexport interface Text extends Timed {\n readonly text: string;\n}\n\nexport interface Part {\n readonly track: number;\n readonly channel: number;\n readonly name: Option.Option<string>;\n readonly program: Option.Option<number>;\n readonly notes: readonly TimelineNote[];\n readonly controls: readonly TimelineControl[];\n readonly lyrics: readonly Text[];\n}\n\nexport interface Meter extends Timed {\n readonly numerator: number;\n readonly denominator: number;\n}\n\nexport interface TempoChange extends Timed {\n readonly microseconds: number;\n readonly target: Option.Option<number>;\n}\n\nexport interface Level {\n readonly decibels: number;\n readonly pan: number;\n readonly muted: boolean;\n}\n\nexport interface TrackSend {\n readonly bus: number;\n readonly amount: number;\n}\n\nexport type MixParameter = MixerParameter;\n\nexport interface MixPoint extends Timed {\n readonly value: number;\n}\n\nexport interface Envelope {\n readonly parameter: MixParameter;\n readonly points: readonly MixPoint[];\n}\n\nexport interface TrackMix {\n readonly level: Level;\n readonly sends: readonly TrackSend[];\n readonly envelopes: readonly Envelope[];\n}\n\nexport interface BusMix {\n readonly name: Option.Option<string>;\n readonly level: Level;\n}\n\nexport interface Mix {\n readonly tracks: ReadonlyMap<number, TrackMix>;\n readonly buses: readonly BusMix[];\n}\n\nexport const NO_MIX: Mix = { tracks: new Map(), buses: [] };\n\nexport interface Timeline {\n readonly title: Option.Option<string>;\n readonly end: number;\n readonly offGrid: number;\n readonly tempos: readonly TempoChange[];\n readonly meters: readonly Meter[];\n readonly markers: readonly Text[];\n readonly parts: readonly Part[];\n readonly mix: Mix;\n}\n\nconst byTick = Order.mapInput(Order.Number, (timed: Timed) => timed.tick);\n\nexport const sortedByTick = <Item extends Timed>(items: readonly Item[]): readonly Item[] =>\n Arr.sort(items, byTick);\n\nconst byTickThenPitch = Order.combine(\n Order.mapInput(Order.Number, (note: TimelineNote) => note.tick),\n Order.mapInput(Order.Number, (note: TimelineNote) => note.midi),\n);\n\nexport const sortedNotes = (notes: readonly TimelineNote[]): readonly TimelineNote[] =>\n Arr.sort(notes, byTickThenPitch);\n","import { Array as Arr, Option, String as Str, pipe } from \"effect\";\nimport { Midi } from \"tonal\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\nimport { fractionOf } from \"#/shared/lib/ticks.ts\";\n\nconst NONE = 0;\nconst FULL = 127;\nconst SHARE_DECIMALS = 3;\nconst SEMITONE_DECIMALS = 12;\nconst LAST = 1;\n\nexport interface Cell {\n readonly head: string;\n readonly attributes: readonly string[];\n readonly length: number;\n}\n\nexport const durationText: From<number, string> = (length) => {\n if (length === NONE) {\n return \"0/1\";\n }\n return fractionOf(length);\n};\n\nexport const restCell: From<number, Cell> = (length) => ({ head: \"rest\", attributes: [], length });\n\nexport const restsOf: From<number, readonly Cell[]> = (length) => {\n if (length > NONE) {\n return [restCell(length)];\n }\n return [];\n};\n\nconst isRest: From<Cell, boolean> = (cell) => cell.head === \"rest\";\n\nconst mergeRests = (merged: readonly Cell[], cell: Cell): readonly Cell[] =>\n pipe(\n Arr.last(merged),\n Option.filter((previous) => isRest(previous) && isRest(cell)),\n Option.match({\n onNone: () => [...merged, cell],\n onSome: (previous) => [\n ...Arr.dropRight(merged, LAST),\n restCell(previous.length + cell.length),\n ],\n }),\n );\n\nconst NO_CELLS: readonly Cell[] = [];\n\nconst cellText: From<Cell, string> = (cell) =>\n Arr.join([cell.head, durationText(cell.length), ...cell.attributes], \" \");\n\nexport const cellsText: From<readonly Cell[], string> = (cells) =>\n pipe(Arr.reduce(cells, NO_CELLS, mergeRests), Arr.map(cellText), Arr.join(\", \"));\n\nexport const quoted: From<string, string> = (text) =>\n `\"${pipe(\n text,\n Str.replaceAll(\"\\\\\", String.raw`\\\\`),\n Str.replaceAll('\"', String.raw`\\\"`),\n Str.replaceAll(\"\\n\", String.raw`\\n`),\n Str.replaceAll(\"\\r\", String.raw`\\r`),\n Str.replaceAll(\"\\t\", String.raw`\\t`),\n )}\"`;\n\nexport const shareText: From<number, string> = (value) =>\n String(Number((value / FULL).toFixed(SHARE_DECIMALS)));\n\nexport const semitoneText: From<number, string> = (value) => {\n const text = String(Number(value.toFixed(SEMITONE_DECIMALS)));\n if (value > NONE) {\n return `+${text}st`;\n }\n return `${text}st`;\n};\n\nexport const pitchText: From<number, string> = (midi) =>\n Midi.midiToNoteName(midi, { sharps: true });\n","import { Array as Arr, Option, pipe } from \"effect\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\nimport { TICKS_PER_WHOLE, fractionOf } from \"#/shared/lib/ticks.ts\";\n\nimport type { Meter, TempoChange, Text, Timeline } from \"./events.ts\";\nimport { bpmOf, microsecondsOf } from \"./tempo-units.ts\";\n\nconst NONE = 0;\nconst NEXT = 1;\nconst QUARTER = 4;\nconst DEFAULT_METER = { numerator: QUARTER, denominator: QUARTER };\nconst DEFAULT_MICROSECONDS = 500_000;\nconst MAX_DECIMALS = 9;\n\nexport interface LaidTempo {\n readonly offset: number;\n readonly length: number;\n readonly microseconds: number;\n readonly target: Option.Option<number>;\n}\n\nexport interface Span {\n readonly start: number;\n readonly length: number;\n}\n\nexport interface LaidBar extends Span {\n readonly meter: string;\n readonly tempo: readonly LaidTempo[];\n readonly marks: readonly string[];\n}\n\ninterface Signature {\n readonly numerator: number;\n readonly denominator: number;\n}\n\nexport const endOfSpan: From<Span, number> = (span) => span.start + span.length;\n\nconst latestAt =\n (tick: number) =>\n <Item extends { readonly tick: number }>(items: readonly Item[]): Option.Option<Item> =>\n pipe(\n items,\n Arr.filter((item) => item.tick <= tick),\n Arr.last,\n );\n\nconst lengthOf: From<Signature, number> = (signature) =>\n (TICKS_PER_WHOLE * signature.numerator) / signature.denominator;\n\nconst meterText =\n (signature: Signature): From<number, string> =>\n (length) => {\n const beats = (length * signature.denominator) / TICKS_PER_WHOLE;\n if (Number.isInteger(beats)) {\n return `${String(beats)}/${String(signature.denominator)}`;\n }\n return fractionOf(length);\n };\n\ninterface Ramp {\n readonly start: TempoChange;\n readonly end: number;\n readonly target: number;\n}\n\nconst rampAt =\n (tempos: readonly TempoChange[]): From<number, Option.Option<Ramp>> =>\n (tick) =>\n pipe(\n latestAt(tick)(tempos),\n Option.flatMap((start) =>\n pipe(\n start.target,\n Option.flatMap((target) =>\n pipe(\n Arr.findFirst(tempos, (tempo) => tempo.tick > start.tick),\n Option.map((next) => ({ start, end: next.tick, target })),\n ),\n ),\n ),\n ),\n );\n\nconst interpolated =\n (ramp: Ramp): From<number, number> =>\n (tick) => {\n const from = bpmOf(ramp.start.microseconds);\n const to = bpmOf(ramp.target);\n const share = (tick - ramp.start.tick) / (ramp.end - ramp.start.tick);\n return microsecondsOf(from + (to - from) * share);\n };\n\nconst rampedAt =\n (tempos: readonly TempoChange[]) =>\n (tick: number, at: number): Option.Option<number> =>\n pipe(\n rampAt(tempos)(tick),\n Option.map((ramp) => interpolated(ramp)(at)),\n );\n\nconst steadyAt =\n (tempos: readonly TempoChange[]): From<number, number> =>\n (tick) =>\n pipe(\n latestAt(tick)(tempos),\n Option.match({\n onNone: () => DEFAULT_MICROSECONDS,\n onSome: (tempo) => tempo.microseconds,\n }),\n );\n\nconst tempoAt =\n (tempos: readonly TempoChange[]): From<number, number> =>\n (tick) =>\n Option.getOrElse(rampedAt(tempos)(tick, tick), () => steadyAt(tempos)(tick));\n\nconst tempoStepsOf =\n (tempos: readonly TempoChange[]): From<Span, readonly LaidTempo[]> =>\n (bar) => {\n const end = endOfSpan(bar);\n const points = [\n bar.start,\n ...pipe(\n tempos,\n Arr.filter((tempo) => tempo.tick > bar.start && tempo.tick < end),\n Arr.map((tempo) => tempo.tick),\n Arr.dedupe,\n ),\n ];\n return pipe(\n points,\n Arr.map((tick, index) => {\n const stepEnd = Option.getOrElse(Arr.get(points, index + NEXT), () => end);\n return {\n offset: tick - bar.start,\n length: stepEnd - tick,\n microseconds: tempoAt(tempos)(tick),\n target: rampedAt(tempos)(tick, stepEnd),\n };\n }),\n );\n };\n\nconst marksOf =\n (markers: readonly Text[]): From<Span, readonly string[]> =>\n (bar) =>\n pipe(\n markers,\n Arr.filter((marker) => marker.tick >= bar.start && marker.tick < endOfSpan(bar)),\n Arr.map((marker) => marker.text),\n );\n\nconst spanAt =\n (meters: readonly Meter[]): From<number, Span & { readonly signature: Signature }> =>\n (start) => {\n const signature = Option.getOrElse(latestAt(start)(meters), () => DEFAULT_METER);\n const full = start + lengthOf(signature);\n const end = pipe(\n Arr.findFirst(meters, (meter) => meter.tick > start),\n Option.match({ onNone: () => full, onSome: (meter) => Math.min(meter.tick, full) }),\n );\n return { start, length: end - start, signature };\n };\n\nexport const barsOf: From<Timeline, readonly LaidBar[]> = (timeline) =>\n Arr.unfold({ start: NONE, first: true }, (cursor) => {\n if (!cursor.first && cursor.start >= timeline.end) {\n return Option.none();\n }\n const span = spanAt(timeline.meters)(cursor.start);\n const bar: LaidBar = {\n start: span.start,\n length: span.length,\n meter: meterText(span.signature)(span.length),\n tempo: tempoStepsOf(timeline.tempos)(span),\n marks: marksOf(timeline.markers)(span),\n };\n return Option.some([bar, { start: endOfSpan(span), first: false }] as const);\n });\n\nexport const bpmText: From<number, string> = (microseconds) => {\n const exact = bpmOf(microseconds);\n const text = pipe(\n Arr.range(NONE, MAX_DECIMALS),\n Arr.map((decimals) => String(Number(exact.toFixed(decimals)))),\n Arr.findFirst((candidate) => microsecondsOf(Number(candidate)) === microseconds),\n Option.getOrElse(() => String(exact)),\n );\n return `${text}bpm`;\n};\n","import { Array as Arr, Option, Record as Rec, pipe } from \"effect\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\n\nimport { cellsText, pitchText, restsOf, semitoneText } from \"./cells.ts\";\nimport type { Cell } from \"./cells.ts\";\nimport type { TimelineControl } from \"./events.ts\";\nimport { endOfSpan } from \"./layout.ts\";\nimport type { Span } from \"./layout.ts\";\nimport { controllerKeyOf } from \"./plan.ts\";\nimport type { PlannedPart } from \"./plan.ts\";\n\nconst NEXT = 1;\n\nconst valueText: From<TimelineControl, string> = (control) => {\n if (control.controller.kind === \"bend\") {\n return semitoneText(control.value);\n }\n return String(control.value);\n};\n\nconst headOf =\n (planned: PlannedPart): From<TimelineControl, string> =>\n ({ controller }) => {\n if (controller.kind === \"pressure\") {\n return Option.match(controller.midi, {\n onNone: () => `${planned.name}.pressure`,\n onSome: (midi) => `${planned.name}.pressure ${pitchText(midi)}`,\n });\n }\n return `${planned.name}.${controllerKeyOf({ controller })}`;\n };\n\nconst cellsOf =\n (bar: Span): From<readonly TimelineControl[], readonly Cell[]> =>\n (controls) => {\n const lead = pipe(\n Arr.head(controls),\n Option.map((first) => first.tick - bar.start),\n Option.toArray,\n Arr.flatMap(restsOf),\n );\n const steps = pipe(\n controls,\n Arr.map((control, index) => ({\n head: valueText(control),\n attributes: [],\n length:\n pipe(\n Arr.get(controls, index + NEXT),\n Option.match({ onNone: () => endOfSpan(bar), onSome: (next) => next.tick }),\n ) - control.tick,\n })),\n );\n return [...lead, ...steps];\n };\n\nexport const controlLinesOf =\n (bar: Span): From<PlannedPart, readonly string[]> =>\n (planned) =>\n pipe(\n planned.controls,\n Arr.filter((control) => control.tick >= bar.start && control.tick < endOfSpan(bar)),\n Arr.groupBy((control: TimelineControl) => controllerKeyOf(control)),\n Rec.values,\n Arr.map((controls) =>\n pipe(\n Arr.head(controls),\n Option.map((first) => `${headOf(planned)(first)}: ${cellsText(cellsOf(bar)(controls))}`),\n ),\n ),\n Arr.getSomes,\n );\n","import { Array as Arr, Option, pipe } from \"effect\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\n\nimport type { Envelope, Level, MixParameter, MixPoint, TrackMix } from \"./events.ts\";\nimport { endOfSpan } from \"./layout.ts\";\nimport type { Span } from \"./layout.ts\";\nimport type { PlannedBus, PlannedPart } from \"./plan.ts\";\n\nconst DECIMALS = 1;\nconst PERCENT = 100;\nconst NONE = 0;\nconst NEXT = 1;\n\nconst amountText = (value: number, unit: string): string => {\n const text = Number(value.toFixed(DECIMALS));\n if (text > NONE) {\n return `+${String(text)}${unit}`;\n }\n return `${String(text)}${unit}`;\n};\n\nconst UNITS: Readonly<Record<MixParameter, From<number, string>>> = {\n volume: (decibels) => amountText(decibels, \"dB\"),\n pan: (pan) => amountText(pan * PERCENT, \"%\"),\n};\n\nconst levelWords: From<Level, readonly string[]> = (level) => [\n ...pipe(\n Option.some(level.decibels),\n Option.filter((decibels) => UNITS.volume(decibels) !== UNITS.volume(NONE)),\n Option.map((decibels) => `volume ${UNITS.volume(decibels)}`),\n Option.toArray,\n ),\n ...pipe(\n Option.some(level.pan),\n Option.filter((pan) => UNITS.pan(pan) !== UNITS.pan(NONE)),\n Option.map((pan) => `pan ${UNITS.pan(pan)}`),\n Option.toArray,\n ),\n ...pipe(\n Option.some(\"mute\"),\n Option.filter(() => level.muted),\n Option.toArray,\n ),\n];\n\nexport type Mixing = Readonly<{ mix: TrackMix; buses: readonly PlannedBus[] }>;\n\nexport const trackMixWords: From<Mixing, readonly string[]> = ({ mix, buses }) => [\n ...levelWords(mix.level),\n ...pipe(\n mix.sends,\n Arr.filter((send) => send.amount > NONE),\n Arr.flatMap((send) =>\n pipe(\n Arr.get(buses, send.bus),\n Option.map((bus) => `send ${bus.name} ${amountText(send.amount * PERCENT, \"%\")}`),\n Option.toArray,\n ),\n ),\n ),\n];\n\nexport const busLineOf: From<PlannedBus, string> = (bus) =>\n Arr.join([\"bus\", bus.name, ...levelWords(bus.level)], \" \");\n\nconst valueAt =\n (points: readonly MixPoint[]): From<number, number> =>\n (tick) => {\n const before = pipe(\n points,\n Arr.filter((point) => point.tick <= tick),\n Arr.last,\n );\n const after = pipe(\n points,\n Arr.findFirst((point) => point.tick > tick),\n );\n return Option.match(before, {\n onNone: () => Option.match(after, { onNone: () => NONE, onSome: (point) => point.value }),\n onSome: (left) =>\n Option.match(after, {\n onNone: () => left.value,\n onSome: (right) =>\n left.value +\n ((right.value - left.value) * (tick - left.tick)) / (right.tick - left.tick),\n }),\n });\n };\n\nconst rampOf =\n (bar: Span, name: string): From<Envelope, Option.Option<string>> =>\n (envelope) => {\n const at = valueAt(envelope.points);\n const unit = UNITS[envelope.parameter];\n const from = unit(at(bar.start));\n const to = unit(at(endOfSpan(bar)));\n return pipe(\n Option.some(`automate ${name}.${envelope.parameter} ${from} -> ${to} over 1bar`),\n Option.filter(() => from !== to),\n );\n };\n\nexport const automationLinesOf =\n (bar: Span): From<PlannedPart, readonly string[]> =>\n (planned) =>\n pipe(\n planned.mix.envelopes,\n Arr.filter((envelope) => Arr.length(envelope.points) > NEXT),\n Arr.map(rampOf(bar, planned.name)),\n Arr.getSomes,\n );\n","import { Array as Arr, Option, Order, pipe } from \"effect\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\n\nimport { cellsText, pitchText, quoted, restsOf, shareText } from \"./cells.ts\";\nimport type { Cell } from \"./cells.ts\";\nimport type { Group, Line } from \"./groups.ts\";\nimport { endOfSpan } from \"./layout.ts\";\nimport type { Span } from \"./layout.ts\";\nimport type { Plan, PlannedPart } from \"./plan.ts\";\n\nconst FULL = 127;\nconst DEFAULT_RELEASE = 64;\nconst SINGLE = 1;\n\ninterface Segment {\n readonly group: Group;\n readonly start: number;\n readonly end: number;\n}\n\ninterface VoiceText {\n readonly text: string;\n readonly continues: boolean;\n}\n\nconst touches =\n (bar: Span): From<Group, boolean> =>\n (group) => {\n if (group.end === group.start) {\n return group.start >= bar.start && group.start < endOfSpan(bar);\n }\n return group.start < endOfSpan(bar) && group.end > bar.start;\n };\n\nconst segmentOf =\n (bar: Span): From<Group, Segment> =>\n (group) => ({\n group,\n start: Math.max(group.start, bar.start),\n end: Math.min(group.end, endOfSpan(bar)),\n });\n\nconst pitchesText: From<readonly number[], string> = (midis) => {\n if (midis.length === SINGLE) {\n return Arr.join(pipe(midis, Arr.map(pitchText)), \"\");\n }\n return `[${Arr.join(pipe(midis, Arr.map(pitchText)), \" \")}]`;\n};\n\nconst headOf =\n (voices: Option.Option<ReadonlyMap<number, string>>): From<Group, string> =>\n (group) =>\n Option.match(voices, {\n onNone: () => pitchesText(group.midis),\n onSome: (map) =>\n pipe(\n Arr.head(group.midis),\n Option.flatMap((midi) => Option.fromNullishOr(map.get(midi))),\n Option.getOrElse(() => \"\"),\n ),\n });\n\nconst when = (condition: boolean, text: string): readonly string[] => {\n if (condition) {\n return [text];\n }\n return [];\n};\n\nconst attributesOf: From<Segment, readonly string[]> = ({ group, start, end }) => {\n const last = end === group.end;\n return [\n ...when(group.velocity !== FULL, `vel ${shareText(group.velocity)}`),\n ...when(last && group.release !== DEFAULT_RELEASE, `off ${shareText(group.release)}`),\n ...when(!last, \"tie\"),\n ...pipe(\n group.lyric,\n Option.filter(() => start === group.start),\n Option.map((text) => `lyric ${quoted(text)}`),\n Option.toArray,\n ),\n ];\n};\n\nconst cellsOf = (\n segments: readonly Segment[],\n bar: Span,\n head: From<Group, string>,\n): readonly Cell[] => {\n const placed = Arr.reduce(\n segments,\n { cells: [] as readonly Cell[], cursor: bar.start },\n ({ cells, cursor }, segment) => ({\n cells: [\n ...cells,\n ...restsOf(segment.start - cursor),\n {\n head: head(segment.group),\n attributes: attributesOf(segment),\n length: segment.end - segment.start,\n },\n ],\n cursor: segment.end,\n }),\n );\n return [...placed.cells, ...restsOf(endOfSpan(bar) - placed.cursor)];\n};\n\nconst lineTextOf =\n (\n planned: PlannedPart,\n voices: Option.Option<ReadonlyMap<number, string>>,\n bar: Span,\n ): From<Line, Option.Option<VoiceText>> =>\n (line) => {\n const segments = pipe(line, Arr.filter(touches(bar)), Arr.map(segmentOf(bar)));\n return pipe(\n Arr.head(segments),\n Option.map((first) => ({\n text: `${planned.name}: ${cellsText(cellsOf(segments, bar, headOf(voices)))}`,\n continues: first.start > first.group.start,\n })),\n );\n };\n\nconst continuedFirst = Order.mapInput(Order.Boolean, (voice: VoiceText) => !voice.continues);\n\nexport interface VoiceContext {\n readonly plan: Plan;\n readonly bar: Span;\n}\n\nexport const voiceLinesOf: From<VoiceContext, From<PlannedPart, readonly string[]>> =\n ({ plan, bar }) =>\n (planned) => {\n const voices = pipe(\n Option.some(plan.drumVoices),\n Option.filter(() => planned.source.kind === \"kit\"),\n );\n const texts = pipe(planned.lines, Arr.map(lineTextOf(planned, voices, bar)), Arr.getSomes);\n return pipe(\n Arr.sort(texts, continuedFirst),\n Arr.map((voice) => voice.text),\n );\n };\n","import { Array as Arr, Option, pipe } from \"effect\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\nimport { fractionOf } from \"#/shared/lib/ticks.ts\";\n\nimport { quoted } from \"./cells.ts\";\nimport { controlLinesOf } from \"./control-lines.ts\";\nimport type { Timeline } from \"./events.ts\";\nimport { barsOf, bpmText } from \"./layout.ts\";\nimport type { LaidBar, LaidTempo } from \"./layout.ts\";\nimport { automationLinesOf, busLineOf, trackMixWords } from \"./mix-lines.ts\";\nimport { planOf } from \"./plan.ts\";\nimport type { Plan, PlannedPart } from \"./plan.ts\";\nimport { voiceLinesOf } from \"./voice-lines.ts\";\n\nconst SINGLE = 1;\nconst INDENT = \" \";\n\nexport interface Written {\n readonly text: string;\n readonly plan: Plan;\n readonly bars: readonly LaidBar[];\n}\n\ninterface Previous {\n readonly meter: Option.Option<string>;\n readonly microseconds: Option.Option<number>;\n}\n\nconst START: Previous = { meter: Option.none(), microseconds: Option.none() };\n\nconst isRamp: From<LaidTempo, boolean> = (step) => Option.isSome(step.target);\n\nconst stepText: From<LaidTempo, string> = (step) => {\n const ramp = Option.match(step.target, {\n onNone: () => \"\",\n onSome: (target) => ` -> ${bpmText(target)}`,\n });\n return `${bpmText(step.microseconds)}${ramp} ${fractionOf(step.length)}`;\n};\n\nconst isSteady: From<LaidBar, boolean> = (bar) =>\n bar.tempo.length <= SINGLE && !pipe(bar.tempo, Arr.some(isRamp));\n\nconst tempoLineOf: From<LaidBar, Option.Option<string>> = (bar) => {\n if (isSteady(bar)) {\n return Option.none();\n }\n const steps = pipe(bar.tempo, Arr.map(stepText));\n return Option.some(`tempo: ${Arr.join(steps, \", \")}`);\n};\n\nconst differs =\n <Value>(previous: Option.Option<Value>): From<Value, boolean> =>\n (current) =>\n Option.match(previous, { onNone: () => true, onSome: (value) => value !== current });\n\nconst headerTempoOf =\n (previous: Previous): From<LaidBar, readonly string[]> =>\n (bar) =>\n pipe(\n Arr.head(bar.tempo),\n Option.filter(() => isSteady(bar)),\n Option.map((step) => step.microseconds),\n Option.filter(differs(previous.microseconds)),\n Option.map((microseconds) => `tempo ${bpmText(microseconds)}`),\n Option.toArray,\n );\n\nconst barHeadOf =\n (previous: Previous): From<LaidBar, string> =>\n (bar) => {\n const meter = pipe(\n Option.some(bar.meter),\n Option.filter(differs(previous.meter)),\n Option.map((current) => `meter ${current}`),\n Option.toArray,\n );\n const mark = pipe(\n Option.some(bar.marks),\n Option.filter(Arr.isReadonlyArrayNonEmpty),\n Option.map((marks) => `mark ${quoted(Arr.join(marks, \" / \"))}`),\n Option.toArray,\n );\n return Arr.join([\"bar\", ...meter, ...headerTempoOf(previous)(bar), ...mark, \"{\"], \" \");\n };\n\nconst barBodyOf: From<Plan, From<LaidBar, readonly string[]>> = (plan) => (bar) => [\n ...Option.toArray(tempoLineOf(bar)),\n ...pipe(\n plan.parts,\n Arr.flatMap((planned) => [\n ...voiceLinesOf({ plan, bar })(planned),\n ...controlLinesOf(bar)(planned),\n ...automationLinesOf(bar)(planned),\n ]),\n ),\n];\n\ninterface Walk {\n readonly lines: readonly string[];\n readonly previous: Previous;\n}\n\nconst afterBar: From<LaidBar, Previous> = (bar) => ({\n meter: Option.some(bar.meter),\n microseconds: pipe(\n Arr.last(bar.tempo),\n Option.map((step) => Option.getOrElse(step.target, () => step.microseconds)),\n ),\n});\n\nconst walkStep: From<Plan, (walk: Walk, bar: LaidBar) => Walk> =\n (plan) =>\n ({ lines, previous }, bar) => ({\n lines: [\n ...lines,\n \"\",\n barHeadOf(previous)(bar),\n ...pipe(\n barBodyOf(plan)(bar),\n Arr.map((line) => `${INDENT}${line}`),\n ),\n \"}\",\n ],\n previous: afterBar(bar),\n });\n\nconst instrumentLinesOf: From<Plan, readonly string[]> = (plan) =>\n pipe(\n Arr.fromIterable(plan.instruments),\n Arr.map(([program, name]) => `instrument ${name} plugin gm program ${String(program)}`),\n );\n\nconst kitLinesOf: From<Plan, readonly string[]> = (plan) => {\n if (plan.drumVoices.size < SINGLE) {\n return [];\n }\n const voices = pipe(\n Arr.fromIterable(plan.drumVoices.values()),\n Arr.map((name) => `${INDENT}${name} ${quoted(`gm-drums/${name}.flac`)}`),\n );\n return [\"kit gm-drums {\", ...voices, \"}\"];\n};\n\nconst sourceWordsOf: From<PlannedPart, readonly string[]> = (planned) => {\n if (planned.source.kind === \"kit\") {\n return [\"kit gm-drums role drums\"];\n }\n return [`instrument ${planned.source.instrument}`];\n};\n\nconst trackLineOf =\n (plan: Plan): From<PlannedPart, string> =>\n (planned) =>\n Arr.join(\n [\n \"track\",\n planned.name,\n ...sourceWordsOf(planned),\n ...trackMixWords({ mix: planned.mix, buses: plan.buses }),\n ],\n \" \",\n );\n\ninterface Heading {\n readonly plan: Plan;\n readonly title: string;\n}\n\nconst headerOf: From<Heading, readonly string[]> = ({ plan, title }) => [\n `song ${quoted(title)}`,\n \"\",\n 'plugin gm from \"./gm.ts\" { program: number = 0 }',\n \"\",\n ...instrumentLinesOf(plan),\n ...kitLinesOf(plan),\n \"\",\n ...pipe(plan.buses, Arr.map(busLineOf)),\n ...pipe(plan.parts, Arr.map(trackLineOf(plan))),\n];\n\nexport interface WriteInput {\n readonly timeline: Timeline;\n readonly title: string;\n}\n\nexport const writeFumx: From<WriteInput, Written> = ({ timeline, title }) => {\n const plan = planOf(timeline);\n const bars = barsOf(timeline);\n const walked = Arr.reduce(\n bars,\n { lines: headerOf({ plan, title }), previous: START },\n walkStep(plan),\n );\n return { text: `${Arr.join(walked.lines, \"\\n\")}\\n`, plan, bars };\n};\n"],"mappings":";;;;;;AAAA,MAAa,WAAW;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAa,QAAQ;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AC9KA,MAAMA,SAA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AAM,OAAO,OAAO,QAAQ;CAC5B,MAAM,OAAO,OAAO,QAAQ;CAC5B,MAAM,SAASA,MAAI,OACjB,MACA;EAAE,OAAO,SAAS;GAAE;GAAM;EAAM,CAAC;EAAG,UAAU;CAAM,GACpD,SAAS,IAAI,CACf;CACA,OAAO;EAAE,MAAM,GAAGA,MAAI,KAAK,OAAO,OAAO,IAAI,EAAE;EAAK;EAAM;CAAK;AACjE"}
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@r_masseater/song-format",
3
- "version": "0.1.0",
4
- "description": "Tooling for .fumx songs: import a song from TypeScript with Vite, a language server, MIDI to .fumx conversion that checks the result against the original, and a song report.",
3
+ "version": "0.2.1",
4
+ "description": "The .fumx song format: a reader that turns a song into a typed value, key and chord analysis, import from TypeScript with Vite, a language server, MIDI and Ableton Live Set conversion that checks the result against the original, and a song report.",
5
5
  "keywords": [
6
6
  "fumx",
7
+ "langium",
7
8
  "language-server",
8
9
  "midi",
9
10
  "music",
11
+ "parser",
10
12
  "tanstack-intent",
11
13
  "vite-plugin"
12
14
  ],
@@ -28,13 +30,34 @@
28
30
  "files": [
29
31
  "LICENSE",
30
32
  "dist",
33
+ "skills/read-fumx",
31
34
  "skills/use-fumx-tools"
32
35
  ],
33
36
  "type": "module",
37
+ "sideEffects": [
38
+ "./dist/mapper.mjs"
39
+ ],
34
40
  "imports": {
35
- "#/*": "./src/*"
41
+ "#/*": "./src/*",
42
+ "#generated/*": "./generated/*"
36
43
  },
37
44
  "exports": {
45
+ ".": {
46
+ "types": "./dist/index.d.mts",
47
+ "default": "./dist/index.mjs"
48
+ },
49
+ "./analysis": {
50
+ "types": "./dist/analysis.d.mts",
51
+ "default": "./dist/analysis.mjs"
52
+ },
53
+ "./language": {
54
+ "types": "./dist/language.d.mts",
55
+ "default": "./dist/language.mjs"
56
+ },
57
+ "./convert-als": {
58
+ "types": "./dist/convert-als.d.mts",
59
+ "default": "./dist/convert-als.mjs"
60
+ },
38
61
  "./convert-midi": {
39
62
  "types": "./dist/convert-midi.d.mts",
40
63
  "default": "./dist/convert-midi.mjs"
@@ -51,30 +74,45 @@
51
74
  "provenance": true
52
75
  },
53
76
  "dependencies": {
54
- "@effect/platform-node-shared": "^4.1.5",
55
- "@r_masseater/fumx-parser": "^0.2.0",
56
- "@r_masseater/mapped-import": "^0.1.0",
57
- "ableton-als": "^0.5.0",
77
+ "@effect/platform-node": "^4.1.5",
78
+ "ableton-als": "^0.5.1",
58
79
  "fast-xml-parser": "^5.12.1",
59
80
  "langium": "^4.4.2",
60
81
  "midi-file": "^1.2.4",
61
82
  "tonal": "^6.9.0",
62
- "ts-content-mapper": "^0.1.1",
63
83
  "vscode-languageserver": "^11.0.1"
64
84
  },
65
85
  "devDependencies": {
86
+ "@effect/platform-node-shared": "4.1.5",
66
87
  "@effect/vitest": "4.1.5",
88
+ "@r_masseater/mapped-import": "^0.1.0",
67
89
  "@r_masseater/node-main": "0.1.0",
68
- "@r_masseater/song-format": "0.1.0",
69
- "@types/node": "26.6.6",
90
+ "@r_masseater/song-format": "0.2.1",
91
+ "@types/node": "26.6.10",
70
92
  "effect": "4.1.5",
93
+ "langium-cli": "4.4.1",
94
+ "ts-content-mapper": "0.1.1",
71
95
  "typescript": "7.1.0-dev.20261124.1",
72
96
  "vite-plus": "1.8.0"
73
97
  },
74
98
  "peerDependencies": {
99
+ "@effect/platform-node-shared": ">=4.1.5",
100
+ "@r_masseater/mapped-import": "^0.1.0",
75
101
  "effect": "^4.1.0",
102
+ "ts-content-mapper": ">=0.1.1",
76
103
  "vite-plus": "^1.8.0"
77
104
  },
105
+ "peerDependenciesMeta": {
106
+ "@effect/platform-node-shared": {
107
+ "optional": true
108
+ },
109
+ "@r_masseater/mapped-import": {
110
+ "optional": true
111
+ },
112
+ "ts-content-mapper": {
113
+ "optional": true
114
+ }
115
+ },
78
116
  "typescript": {
79
117
  "contentMapper": {
80
118
  "compilerOptions": [],
@@ -89,6 +127,5 @@
89
127
  },
90
128
  "engines": {
91
129
  "node": ">=26.13.1"
92
- },
93
- "scripts": {}
130
+ }
94
131
  }
@@ -0,0 +1,85 @@
1
+ ---
2
+ name: read-fumx
3
+ description: >
4
+ Use when code must read a .fumx song into data with @r_masseater/song-format: readSong and its read
5
+ callback, the valid and invalid results, the Song value's notes, hits, controls and bars, ticks and
6
+ fractionOf, and writing a lint rule over the result.
7
+ metadata:
8
+ type: core
9
+ library: "@r_masseater/song-format"
10
+ sources:
11
+ - src/app/index.ts
12
+ - src/app/analysis.ts
13
+ - src/entities/song/**
14
+ - src/features/read-song/model/read-song.ts
15
+ - src/features/analyze-song/**
16
+ - README.md
17
+ ---
18
+
19
+ # read-fumx
20
+
21
+ `readSong` turns `.fumx` text into a `Song`. Every note, hit and controller event has a track, a bar and an absolute `start` and `length` in ticks, so a rule about music is a filter over plain data.
22
+
23
+ ## Read a song
24
+
25
+ ```ts
26
+ import { readSong } from "@r_masseater/song-format";
27
+ import { Effect, FileSystem } from "effect";
28
+
29
+ const program = Effect.gen(function* () {
30
+ const fileSystem = yield* FileSystem.FileSystem;
31
+ return yield* readSong({
32
+ path: "/songs/demo.fumx",
33
+ read: (path) => fileSystem.readFileString(path),
34
+ });
35
+ });
36
+ ```
37
+
38
+ `read` is called for the entry file and for every file it imports. Its error type flows into the result.
39
+
40
+ `source.status` is `"valid"` with `song`, or `"invalid"` with `issues` (`path`, `line`, `column`, `start`, `end`, `message`). Both carry an `outline` of where names are declared. Messages are in Japanese.
41
+
42
+ ## The song value
43
+
44
+ | Field | Holds |
45
+ | ------------------------------- | ---------------------------------------------------------------------------------------------- |
46
+ | `notes` | Pitched notes: `midi`, `velocity` (0 to 1), `releaseVelocity`, `gate`, `lyric`, `bend` |
47
+ | `hits` | Drum hits: kit `voice`, `velocity`, `releaseVelocity`, `bend` |
48
+ | `controls` | Controller events: `controller.kind` is `cc` (with `number`), `pressure`, `bend` or `program` |
49
+ | `bars` | Each bar's `start`, `length`, `meter`, `tempo`, `tempoSteps`, `section` and `mark` |
50
+ | `tracks`, `instruments`, `kits` | The declarations in the header. A track with `into` is a layer of another track |
51
+ | `mix`, `tailSeconds` | The `master` line: a mix plugin that replaces the built-in mixdown, and the tail after the end |
52
+
53
+ Ties are already joined: a note tied over a bar line is one note.
54
+
55
+ Notes and hits carry `args`, the values a `with { … }` attribute passes to plugins, and `nudgeSeconds`. Times and shares written as decimals (`nudge 0.4ms`, `pan -35%`) are read as the double that the decimal names, so `seconds` is exact rather than `milliseconds * 0.001`. `vel` stays between 0 and 1; `amp` multiplies the level linearly and may go above 1.
56
+
57
+ Times are ticks. `TICKS_PER_WHOLE` ticks make a whole note, and `fractionOf(ticks)` prints `"3/8"`. Compare with ticks, not with fractions.
58
+
59
+ ## Write a rule
60
+
61
+ ```ts
62
+ import type { Song } from "@r_masseater/song-format";
63
+
64
+ declare const song: Song;
65
+
66
+ const outOfRange = song.notes.filter(
67
+ (note) => note.track === "bass" && (note.midi < 28 || note.midi > 55),
68
+ );
69
+ ```
70
+
71
+ Report a finding with the note's `sourceLine` and `sourceColumn`, the position of the note in the file. `line` is the index of the voice line inside its bar, not a file line.
72
+
73
+ ## Keys and chords
74
+
75
+ The file does not write keys or chords. `@r_masseater/song-format/analysis` estimates them from the notes:
76
+
77
+ ```ts
78
+ import { analyze, keyIn, soundingsOf } from "@r_masseater/song-format/analysis";
79
+
80
+ const report = analyze(song);
81
+ const verseKey = keyIn(song)({ fromBar: 1, toBar: 8 });
82
+ const heard = soundingsOf(song);
83
+ ```
84
+
85
+ `analyze` returns the key of the whole song, the key of every four bars, the chord on each beat and bars that repeat. `soundingsOf` lists the notes of unmuted tracks with their track `role`, source `line` and `column`, and an `end` that the note's `gate` shortens. For ready-made rules, use `@r_masseater/i68` and `@r_masseater/i68/presets`.
@@ -8,7 +8,6 @@ description: >
8
8
  metadata:
9
9
  type: core
10
10
  library: "@r_masseater/song-format"
11
- library_version: 0.1.0
12
11
  sources:
13
12
  - src/**
14
13
  - bin/**
@@ -17,7 +16,7 @@ sources:
17
16
 
18
17
  # use-fumx-tools
19
18
 
20
- `.fumx` is a text format for music. This package turns it into something TypeScript, an editor and an agent can use. The grammar and the reader are in `@r_masseater/fumx-parser`.
19
+ `.fumx` is a text format for music. This package turns it into something TypeScript, an editor and an agent can use.
21
20
 
22
21
  ## Setup
23
22
 
@@ -1,190 +0,0 @@
1
- import { Duration, Effect, Layer, Option } from "effect";
2
- import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime";
3
- import * as Layer$1 from "effect/Layer";
4
- import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem";
5
- import * as NodePath from "@effect/platform-node-shared/NodePath";
6
- import * as NodeStdio from "@effect/platform-node-shared/NodeStdio";
7
- import * as NodeTerminal from "@effect/platform-node-shared/NodeTerminal";
8
- import { FetchHttpClient } from "effect/http";
9
- import { Otlp, OtlpSerialization } from "effect/observability";
10
- // \0rolldown/runtime.js
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __hasOwnProp = Object.prototype.hasOwnProperty;
15
- var __exportAll = (all, no_symbols) => {
16
- let target = {};
17
- for (var name in all) __defProp(target, name, {
18
- get: all[name],
19
- enumerable: true
20
- });
21
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
22
- return target;
23
- };
24
- var __copyProps = (to, from, except, desc) => {
25
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
26
- key = keys[i];
27
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
28
- get: ((k) => from[k]).bind(null, key),
29
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
30
- });
31
- }
32
- return to;
33
- };
34
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
35
- Duration.fromInputUnsafe("2 seconds");
36
- // ../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeRuntime.js
37
- /**
38
- * Node.js process runner for Effect programs.
39
- *
40
- * This module exports `runMain`, which runs one Effect as the main process
41
- * fiber in Node.js. It reuses the shared Node runtime runner, including its
42
- * error reporting, `SIGINT` / `SIGTERM` interruption, and optional teardown
43
- * behavior.
44
- *
45
- * @stability unstable
46
- * @since 4.0.0
47
- */
48
- /**
49
- * Helps you run a main effect with built-in error handling, logging, and signal management.
50
- *
51
- * **When to use**
52
- *
53
- * Use to run a Node.js application's main Effect with structured error
54
- * handling, log management, interrupt support, or advanced teardown
55
- * capabilities.
56
- *
57
- * **Details**
58
- *
59
- * This function launches an Effect as the main entry point, setting exit codes
60
- * based on success or failure, handling interrupts (e.g., Ctrl+C), and optionally
61
- * logging errors. By default, it logs errors and uses a "pretty" format, but both
62
- * behaviors can be turned off. You can also provide custom teardown logic to
63
- * finalize resources or produce different exit codes.
64
- *
65
- * The optional configuration object can include:
66
- * - `disableErrorReporting`: Turn off automatic error logging.
67
- * - `teardown`: Provide custom finalization logic.
68
- *
69
- * @stability unstable
70
- * @category running
71
- * @since 4.0.0
72
- */
73
- const runMain$1 = NodeRuntime.runMain;
74
- // ../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeChildProcessSpawner.js
75
- var NodeChildProcessSpawner_exports = /* @__PURE__ */ __exportAll({});
76
- import * as import__effect_platform_node_shared_NodeChildProcessSpawner from "@effect/platform-node-shared/NodeChildProcessSpawner";
77
- __reExport(NodeChildProcessSpawner_exports, import__effect_platform_node_shared_NodeChildProcessSpawner);
78
- // ../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeFileSystem.js
79
- /**
80
- * Node.js `FileSystem` layer for programs that perform real filesystem I/O.
81
- *
82
- * The exported layer satisfies the platform-independent `FileSystem` service
83
- * with Node-backed operations for files, directories, metadata, permissions,
84
- * links, temporary paths, and path watching. Effects still call the service from
85
- * `effect/FileSystem`; this module only chooses the Node implementation.
86
- *
87
- * @stability unstable
88
- * @since 4.0.0
89
- */
90
- /**
91
- * Provides the `FileSystem` service backed by Node filesystem APIs.
92
- *
93
- * @stability unstable
94
- * @category layers
95
- * @since 4.0.0
96
- */
97
- const layer$4 = NodeFileSystem.layer;
98
- // ../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodePath.js
99
- /**
100
- * Node.js layers for Effect's `Path` service.
101
- *
102
- * This module provides the default, POSIX, and Windows variants of the
103
- * platform-independent `Path` service by reusing the shared Node path
104
- * implementation. The provided path services include Node file URL conversion
105
- * behavior.
106
- *
107
- * @stability unstable
108
- * @since 4.0.0
109
- */
110
- /**
111
- * Provides the default Node `Path` service using the platform's `node:path`
112
- * implementation.
113
- *
114
- * @stability unstable
115
- * @category layers
116
- * @since 4.0.0
117
- */
118
- const layer$3 = NodePath.layer;
119
- // ../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeStdio.js
120
- /**
121
- * Node.js `Stdio` layer for the current process.
122
- *
123
- * The exported layer reuses the shared Node stdio implementation. It satisfies
124
- * the platform-independent `Stdio` service by reading command-line arguments
125
- * from `process.argv`, consuming input from `process.stdin`, and writing output
126
- * streams to `process.stdout` and `process.stderr`.
127
- *
128
- * @stability unstable
129
- * @since 4.0.0
130
- */
131
- /**
132
- * Provides the `Stdio` service backed by the current process arguments,
133
- * stdin, stdout, and stderr streams.
134
- *
135
- * @stability unstable
136
- * @category layers
137
- * @since 4.0.0
138
- */
139
- const layer$2 = NodeStdio.layer;
140
- // ../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeTerminal.js
141
- /**
142
- * Node.js implementation of the Effect `Terminal` service.
143
- *
144
- * This module reuses the shared Node terminal implementation. `make` creates a
145
- * scoped process-backed `Terminal` service, and `layer` provides the default
146
- * service with the standard quit behavior for key input.
147
- *
148
- * @stability unstable
149
- * @since 4.0.0
150
- */
151
- /**
152
- * Provides the default process-backed `Terminal` service, ending key input on
153
- * bare Esc, Ctrl+C, or Ctrl+D.
154
- *
155
- * @stability unstable
156
- * @category layers
157
- * @since 4.0.0
158
- */
159
- const layer$1 = NodeTerminal.layer;
160
- // ../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeServices.js
161
- /**
162
- * Provides the default Node implementations for child process spawning,
163
- * filesystem, path, stdio, and terminal services.
164
- *
165
- * @stability unstable
166
- * @category layers
167
- * @since 4.0.0
168
- */
169
- const layer = /*#__PURE__*/ Layer$1.provideMerge(NodeChildProcessSpawner_exports.layer, /*#__PURE__*/ Layer$1.mergeAll(layer$4, layer$3, layer$2, layer$1));
170
- // ../node-main/src/features/run-main/model/run-main.ts
171
- const platform = Layer.mergeAll(layer, FetchHttpClient.layer);
172
- const runWithTracingAnd = ({ serviceName, services, onFailure }) => (program) => {
173
- const tracing = Otlp.layerFromConfig({ resource: { serviceName } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));
174
- const provided = Layer.provideMerge(services, platform);
175
- const report = Option.fromNullishOr(onFailure);
176
- const reported = Option.match(report, {
177
- onNone: () => program,
178
- onSome: (handler) => Effect.tapCause(program, handler)
179
- });
180
- runMain$1(Layer.mergeAll(tracing, provided).pipe(Layer.build, Effect.flatMap((context) => Effect.provideContext(reported, context)), Effect.scoped), { disableErrorReporting: Option.isSome(report) });
181
- };
182
- const runWithTracing = (serviceName) => runWithTracingAnd({
183
- serviceName,
184
- services: Layer.empty
185
- });
186
- /** @internal */
187
- const runMain = runWithTracing;
188
- export { runMain as t };
189
-
190
- //# sourceMappingURL=app-CdpGdiWq.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app-CdpGdiWq.mjs","names":["runMain","layer","layer","layer","layer","NodeChildProcessSpawner","NodeFileSystem.layer","NodePath.layer","NodeStdio.layer","NodeTerminal.layer","nodeServices"],"sources":["../../node-main/src/features/watch-parent/model/parent-process.ts","../../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeRuntime.js","../../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeChildProcessSpawner.js","../../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeFileSystem.js","../../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodePath.js","../../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeStdio.js","../../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeTerminal.js","../../../node_modules/.pnpm/@effect+platform-node@4.1.5_effect@4.1.5_redis@6.2.1_@opentelemetry+api@1.10.0_/node_modules/@effect/platform-node/dist/NodeServices.js","../../node-main/src/features/run-main/model/run-main.ts"],"sourcesContent":["import { Duration, Effect, Option, Schedule, pipe } from \"effect\";\n\nconst PARENT_CHECK_INTERVAL = Duration.fromInputUnsafe(\"2 seconds\");\nconst SIGNAL_PROBE = 0;\n\nconst isAlive = (pid: number): boolean => {\n try {\n return globalThis.process.kill(pid, SIGNAL_PROBE);\n } catch {\n return false;\n }\n};\n\nconst untilExits = (pid: number): Effect.Effect<void> =>\n Effect.sync(() => isAlive(pid)).pipe(\n Effect.repeat({ schedule: Schedule.spaced(PARENT_CHECK_INTERVAL), while: (alive) => alive }),\n Effect.asVoid,\n );\n\nexport const whileParentAlive =\n (parentPid: Option.Option<string>) =>\n <Value, Failure, Requirements>(\n program: Effect.Effect<Value, Failure, Requirements>,\n ): Effect.Effect<void, Failure, Requirements> =>\n Effect.raceFirst(\n Effect.asVoid(program),\n pipe(\n parentPid,\n Option.map((pid) => untilExits(globalThis.Number(pid))),\n Option.getOrElse(() => Effect.never),\n ),\n );\n","/**\n * Node.js process runner for Effect programs.\n *\n * This module exports `runMain`, which runs one Effect as the main process\n * fiber in Node.js. It reuses the shared Node runtime runner, including its\n * error reporting, `SIGINT` / `SIGTERM` interruption, and optional teardown\n * behavior.\n *\n * @stability unstable\n * @since 4.0.0\n */\nimport * as NodeRuntime from \"@effect/platform-node-shared/NodeRuntime\";\n/**\n * Helps you run a main effect with built-in error handling, logging, and signal management.\n *\n * **When to use**\n *\n * Use to run a Node.js application's main Effect with structured error\n * handling, log management, interrupt support, or advanced teardown\n * capabilities.\n *\n * **Details**\n *\n * This function launches an Effect as the main entry point, setting exit codes\n * based on success or failure, handling interrupts (e.g., Ctrl+C), and optionally\n * logging errors. By default, it logs errors and uses a \"pretty\" format, but both\n * behaviors can be turned off. You can also provide custom teardown logic to\n * finalize resources or produce different exit codes.\n *\n * The optional configuration object can include:\n * - `disableErrorReporting`: Turn off automatic error logging.\n * - `teardown`: Provide custom finalization logic.\n *\n * @stability unstable\n * @category running\n * @since 4.0.0\n */\nexport const runMain = NodeRuntime.runMain;\n//# sourceMappingURL=NodeRuntime.js.map","/**\n * Node.js implementation of `ChildProcessSpawner`.\n *\n * @stability unstable\n * @since 4.0.0\n */\nexport * from \"@effect/platform-node-shared/NodeChildProcessSpawner\";\n//# sourceMappingURL=NodeChildProcessSpawner.js.map","/**\n * Node.js `FileSystem` layer for programs that perform real filesystem I/O.\n *\n * The exported layer satisfies the platform-independent `FileSystem` service\n * with Node-backed operations for files, directories, metadata, permissions,\n * links, temporary paths, and path watching. Effects still call the service from\n * `effect/FileSystem`; this module only chooses the Node implementation.\n *\n * @stability unstable\n * @since 4.0.0\n */\nimport * as NodeFileSystem from \"@effect/platform-node-shared/NodeFileSystem\";\n/**\n * Provides the `FileSystem` service backed by Node filesystem APIs.\n *\n * @stability unstable\n * @category layers\n * @since 4.0.0\n */\nexport const layer = NodeFileSystem.layer;\n//# sourceMappingURL=NodeFileSystem.js.map","/**\n * Node.js layers for Effect's `Path` service.\n *\n * This module provides the default, POSIX, and Windows variants of the\n * platform-independent `Path` service by reusing the shared Node path\n * implementation. The provided path services include Node file URL conversion\n * behavior.\n *\n * @stability unstable\n * @since 4.0.0\n */\nimport * as NodePath from \"@effect/platform-node-shared/NodePath\";\n/**\n * Provides the default Node `Path` service using the platform's `node:path`\n * implementation.\n *\n * @stability unstable\n * @category layers\n * @since 4.0.0\n */\nexport const layer = NodePath.layer;\n/**\n * Provides the `Path` service using Node's POSIX path implementation,\n * regardless of the host platform.\n *\n * @stability unstable\n * @category layers\n * @since 4.0.0\n */\nexport const layerPosix = NodePath.layerPosix;\n/**\n * Provides the `Path` service using Node's Windows path implementation,\n * regardless of the host platform.\n *\n * @stability unstable\n * @category layers\n * @since 4.0.0\n */\nexport const layerWin32 = NodePath.layerWin32;\n//# sourceMappingURL=NodePath.js.map","/**\n * Node.js `Stdio` layer for the current process.\n *\n * The exported layer reuses the shared Node stdio implementation. It satisfies\n * the platform-independent `Stdio` service by reading command-line arguments\n * from `process.argv`, consuming input from `process.stdin`, and writing output\n * streams to `process.stdout` and `process.stderr`.\n *\n * @stability unstable\n * @since 4.0.0\n */\nimport * as NodeStdio from \"@effect/platform-node-shared/NodeStdio\";\n/**\n * Provides the `Stdio` service backed by the current process arguments,\n * stdin, stdout, and stderr streams.\n *\n * @stability unstable\n * @category layers\n * @since 4.0.0\n */\nexport const layer = NodeStdio.layer;\n//# sourceMappingURL=NodeStdio.js.map","/**\n * Node.js implementation of the Effect `Terminal` service.\n *\n * This module reuses the shared Node terminal implementation. `make` creates a\n * scoped process-backed `Terminal` service, and `layer` provides the default\n * service with the standard quit behavior for key input.\n *\n * @stability unstable\n * @since 4.0.0\n */\nimport * as NodeTerminal from \"@effect/platform-node-shared/NodeTerminal\";\n/**\n * Creates a scoped `Terminal` service backed by process stdin/stdout.\n * By default, Esc, Ctrl+C, and Ctrl+D end key input. Supply `shouldQuit` to\n * override these quit keys.\n *\n * @stability unstable\n * @category constructors\n * @since 4.0.0\n */\nexport const make = NodeTerminal.make;\n/**\n * Provides the default process-backed `Terminal` service, ending key input on\n * bare Esc, Ctrl+C, or Ctrl+D.\n *\n * @stability unstable\n * @category layers\n * @since 4.0.0\n */\nexport const layer = NodeTerminal.layer;\n//# sourceMappingURL=NodeTerminal.js.map","import * as Layer from \"effect/Layer\";\nimport * as NodeChildProcessSpawner from \"./NodeChildProcessSpawner.js\";\nimport * as NodeFileSystem from \"./NodeFileSystem.js\";\nimport * as NodePath from \"./NodePath.js\";\nimport * as NodeStdio from \"./NodeStdio.js\";\nimport * as NodeTerminal from \"./NodeTerminal.js\";\n/**\n * Provides the default Node implementations for child process spawning,\n * filesystem, path, stdio, and terminal services.\n *\n * @stability unstable\n * @category layers\n * @since 4.0.0\n */\nexport const layer = /*#__PURE__*/Layer.provideMerge(NodeChildProcessSpawner.layer, /*#__PURE__*/Layer.mergeAll(NodeFileSystem.layer, NodePath.layer, NodeStdio.layer, NodeTerminal.layer));\n//# sourceMappingURL=NodeServices.js.map","import { runMain as nodeRuntimeRunMain } from \"@effect/platform-node/NodeRuntime\";\nimport { layer as nodeServices } from \"@effect/platform-node/NodeServices\";\nimport type { NodeServices } from \"@effect/platform-node/NodeServices\";\nimport { Effect, Layer, Option } from \"effect\";\nimport type { Cause } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport type { HttpClient } from \"effect/http\";\nimport { Otlp, OtlpSerialization } from \"effect/observability\";\n\n/** @internal */\nexport type Platform = NodeServices | HttpClient.HttpClient;\n\n/** @internal */\nexport type Run<Provided> = <Success, Failure>(\n program: Effect.Effect<Success, Failure, Platform | Provided>,\n) => void;\n\n/** @internal */\nexport type Report<Provided> = <Failure>(\n cause: Cause.Cause<Failure>,\n) => Effect.Effect<void, never, Platform | Provided>;\n\nconst platform = Layer.mergeAll(nodeServices, FetchHttpClient.layer);\n\nconst runWithTracingAnd =\n <Provided, LayerFailure>({\n serviceName,\n services,\n onFailure,\n }: Readonly<{\n serviceName: string;\n services: Layer.Layer<Provided, LayerFailure, Platform>;\n onFailure?: Report<Provided>;\n }>): Run<Provided> =>\n (program) => {\n const tracing = Otlp.layerFromConfig({ resource: { serviceName } }).pipe(\n Layer.provide(OtlpSerialization.layerJson),\n Layer.provide(FetchHttpClient.layer),\n );\n const provided = Layer.provideMerge(services, platform);\n const report = Option.fromNullishOr(onFailure);\n const reported = Option.match(report, {\n onNone: () => program,\n onSome: (handler) => Effect.tapCause(program, handler),\n });\n nodeRuntimeRunMain(\n Layer.mergeAll(tracing, provided).pipe(\n Layer.build,\n Effect.flatMap((context) => Effect.provideContext(reported, context)),\n Effect.scoped,\n ),\n { disableErrorReporting: Option.isSome(report) },\n );\n };\n\nconst runWithTracing = (serviceName: string): Run<never> =>\n runWithTracingAnd({ serviceName, services: Layer.empty });\n\n/** @internal */\nexport const runMainWith = runWithTracingAnd;\n\n/** @internal */\nexport const runMain = runWithTracing;\n"],"ignoreList":[1,2,3,4,5,6,7],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE8B,SAAS,gBAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACmClE,MAAaA,YAAU,YAAY;;;;;;;;;;;;;;;;;;;;;;;;AElBnC,MAAaC,UAAQ,eAAe;;;;;;;;;;;;;;;;;;;;;ACCpC,MAAaC,UAAQ,SAAS;;;;;;;;;;;;;;;;;;;;;ACA9B,MAAaC,UAAQ,UAAU;;;;;;;;;;;;;;;;;;;;ACS/B,MAAaC,UAAQ,aAAa;;;;;;;;;;ACflC,MAAa,QAAqB,sBAAM,aAAaC,gCAAwB,OAAoB,sBAAM,SAASC,SAAsBC,SAAgBC,SAAiBC,OAAkB,CAAC;;ACQ1L,MAAM,WAAW,MAAM,SAASC,OAAc,gBAAgB,KAAK;AAEnE,MAAM,qBACqB,EACvB,aACA,UACA,iBAMD,YAAY;CACX,MAAM,UAAU,KAAK,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,KAClE,MAAM,QAAQ,kBAAkB,SAAS,GACzC,MAAM,QAAQ,gBAAgB,KAAK,CACrC;CACA,MAAM,WAAW,MAAM,aAAa,UAAU,QAAQ;CACtD,MAAM,SAAS,OAAO,cAAc,SAAS;CAC7C,MAAM,WAAW,OAAO,MAAM,QAAQ;EACpC,cAAc;EACd,SAAS,YAAY,OAAO,SAAS,SAAS,OAAO;CACvD,CAAC;CACD,UACE,MAAM,SAAS,SAAS,QAAQ,CAAC,CAAC,KAChC,MAAM,OACN,OAAO,SAAS,YAAY,OAAO,eAAe,UAAU,OAAO,CAAC,GACpE,OAAO,MACT,GACA,EAAE,uBAAuB,OAAO,OAAO,MAAM,EAAE,CACjD;AACF;AAEF,MAAM,kBAAkB,gBACtB,kBAAkB;CAAE;CAAa,UAAU,MAAM;AAAM,CAAC;;AAM1D,MAAa,UAAU"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform-C24h3upp.mjs","names":["Arr","Rec"],"sources":["../src/features/build-song-module/model/song-module.ts","../src/app/transform.ts"],"sourcesContent":["import { SongSchema, readSong } from \"@r_masseater/fumx-parser\";\nimport type { Song, Named, Outline, SongSource, SourceIssue } from \"@r_masseater/fumx-parser\";\nimport { nameLiteral, quoted, text } from \"@r_masseater/mapped-import\";\nimport type { Segment } from \"@r_masseater/mapped-import\";\nimport type { Issue, Mapped } from \"@r_masseater/mapped-import/mapper\";\nimport { Array as Arr, Effect, Option, Record as Rec, Schema, pipe } from \"effect\";\n\nexport interface SongModuleSource<Failure> {\n readonly path: string;\n readonly content: string;\n readonly read: (path: string) => Effect.Effect<string, Failure>;\n}\n\nexport interface SongModule {\n readonly mapped: Mapped;\n readonly song: Option.Option<Song>;\n readonly files: readonly string[];\n}\n\ntype NamedField = {\n readonly [Field in keyof Song]: Song[Field] extends readonly { readonly name: string }[]\n ? Field\n : never;\n}[keyof Song];\n\nconst NAMED_FIELDS = {\n samples: \"Sample\",\n kits: \"Kit\",\n instruments: \"Instrument\",\n buses: \"Bus\",\n tracks: \"Track\",\n plugins: \"Plugin\",\n} as const satisfies Readonly<Record<NamedField, Named[\"$type\"]>>;\n\nconst SONG_MODULE = \"@r_masseater/fumx-parser\";\n\nconst NEVER_SONG = \"export declare const song: never;\\n\";\n\nconst titleSegments = (song: Song, outline: Outline): readonly Segment[] =>\n Option.match(outline.title, {\n onNone: () => [text(quoted(song.title))],\n onSome: ({ start, end }): readonly Segment[] => [\n { kind: \"alias\", text: quoted(song.title), start, end },\n ],\n });\n\nconst fieldSegments =\n (song: Song, outline: Outline) =>\n ([field, type]: readonly [NamedField, Named[\"$type\"]]): readonly Segment[] => [\n text(` readonly ${field}: readonly [\\n`),\n ...pipe(\n song[field],\n Arr.flatMap(({ name }) => [\n text(` Song[\"${field}\"][number] & { readonly name: `),\n ...nameLiteral({\n name,\n span: pipe(\n outline.names,\n Arr.findFirst((found) => found.type === type && found.name === name),\n Option.map((found) => found.span),\n ),\n }),\n text(\" },\\n\"),\n ]),\n ),\n text(\" ];\\n\"),\n ];\n\nconst segmentsOf = (song: Song, outline: Outline): readonly Segment[] => [\n text(`import type { Song } from \"${SONG_MODULE}\";\\n`),\n text(\"export declare const song: Song & {\\n readonly title: \"),\n ...titleSegments(song, outline),\n text(\";\\n\"),\n ...pipe(Rec.toEntries(NAMED_FIELDS), Arr.flatMap(fieldSegments(song, outline))),\n text(\"};\\n\"),\n];\n\nconst issueOf =\n ({ path, outline }: Readonly<{ path: string; outline: Outline }>) =>\n (issue: SourceIssue): Issue => {\n if (issue.path === path) {\n return { message: issue.message, start: issue.start, end: issue.end };\n }\n const at = pipe(\n outline.imports,\n Arr.findFirst((found) => found.path === issue.path),\n Option.map((found) => found.span),\n Option.getOrElse(() => ({ start: 0, end: 0 })),\n );\n return {\n message: `${issue.path}:${String(issue.line)}:${String(issue.column)} ${issue.message}`,\n ...at,\n };\n };\n\nconst moduleOf =\n (path: string) =>\n (source: SongSource): SongModule => {\n if (source.status === \"invalid\") {\n return {\n mapped: {\n status: \"error\",\n fallback: NEVER_SONG,\n issues: pipe(source.issues, Arr.map(issueOf({ path, outline: source.outline }))),\n },\n song: Option.none(),\n files: source.outline.files,\n };\n }\n return {\n mapped: { status: \"ok\", segments: segmentsOf(source.song, source.outline) },\n song: Option.some(source.song),\n files: source.outline.files,\n };\n };\n\nexport const songModuleOf = <Failure>({\n path,\n content,\n read,\n}: SongModuleSource<Failure>): Effect.Effect<SongModule> =>\n readSong({\n path,\n read: (target) => {\n if (target === path) {\n return Effect.succeed(content);\n }\n return read(target);\n },\n }).pipe(Effect.map(moduleOf(path)));\n\nconst encodeSong = Schema.encodeEffect(Schema.fromJsonString(SongSchema));\n\nexport const songCodeOf = (song: Song): Effect.Effect<string> =>\n encodeSong(song).pipe(\n Effect.orDie,\n Effect.map(\n (json) =>\n `import { Schema } from \"effect\";\\nimport { SongSchema } from \"${SONG_MODULE}\";\\nexport const song = Schema.decodeSync(Schema.fromJsonString(SongSchema))(${quoted(json)});\\n`,\n ),\n );\n","import { NodeFileSystem } from \"@effect/platform-node-shared\";\nimport { mappedOutput } from \"@r_masseater/mapped-import/mapper\";\nimport type { Request } from \"@r_masseater/mapped-import/mapper\";\nimport { Effect, FileSystem, ManagedRuntime } from \"effect\";\nimport type { TransformResult } from \"ts-content-mapper\";\n\nimport { songModuleOf } from \"#/features/build-song-module/index.ts\";\n\nconst transformSong = Effect.fn(\"transformSong\")(function* transformSong(request: Request) {\n const fileSystem = yield* FileSystem.FileSystem;\n const { mapped } = yield* songModuleOf({\n path: request.fileName,\n content: request.content,\n read: (path) => fileSystem.readFileString(path),\n });\n return mappedOutput({ request, mapped });\n});\n\nconst runtime = ManagedRuntime.make(NodeFileSystem.layer);\n\nexport const transform = (request: Request): Promise<TransformResult> =>\n runtime.runPromise(transformSong(request));\n"],"mappings":";;;;;;AAyBA,MAAM,eAAe;CACnB,SAAS;CACT,MAAM;CACN,aAAa;CACb,OAAO;CACP,QAAQ;CACR,SAAS;AACX;AAEA,MAAM,cAAc;AAEpB,MAAM,aAAa;AAEnB,MAAM,iBAAiB,MAAY,YACjC,OAAO,MAAM,QAAQ,OAAO;CAC1B,cAAc,CAAC,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC;CACvC,SAAS,EAAE,OAAO,UAA8B,CAC9C;EAAE,MAAM;EAAS,MAAM,OAAO,KAAK,KAAK;EAAG;EAAO;CAAI,CACxD;AACF,CAAC;AAEH,MAAM,iBACH,MAAY,aACZ,CAAC,OAAO,UAAqE;CAC5E,KAAK,cAAc,MAAM,eAAe;CACxC,GAAG,KACD,KAAK,QACLA,MAAI,SAAS,EAAE,WAAW;EACxB,KAAK,aAAa,MAAM,+BAA+B;EACvD,GAAG,YAAY;GACb;GACA,MAAM,KACJ,QAAQ,OACRA,MAAI,WAAW,UAAU,MAAM,SAAS,QAAQ,MAAM,SAAS,IAAI,GACnE,OAAO,KAAK,UAAU,MAAM,IAAI,CAClC;EACF,CAAC;EACD,KAAK,OAAO;CACd,CAAC,CACH;CACA,KAAK,QAAQ;AACf;AAEF,MAAM,cAAc,MAAY,YAAyC;CACvE,KAAK,8BAA8B,YAAY,KAAK;CACpD,KAAK,yDAAyD;CAC9D,GAAG,cAAc,MAAM,OAAO;CAC9B,KAAK,KAAK;CACV,GAAG,KAAKC,OAAI,UAAU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