@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":"als-to-fumx.mjs","names":["Arr","Rec","NONE","Arr","Arr","NEXT","pointsOf","NONE","NEXT","Arr","Arr","Bool"],"sources":["../src/features/convert-als/model/live-set.ts","../src/features/convert-als/model/clips.ts","../src/features/convert-als/model/tempo-map.ts","../src/features/convert-als/model/ticks.ts","../src/features/convert-als/model/mix.ts","../src/features/convert-als/model/timeline.ts","../src/features/convert-als/model/convert.ts","../src/app/als-to-fumx.ts","../bin/als-to-fumx.ts"],"sourcesContent":["import { Array as Arr, Effect, Option, Record as Rec, Schema, pipe } from \"effect\";\nimport { XMLParser } from \"fast-xml-parser\";\n\nconst taggedError = Schema.TaggedError;\n\nexport class UnreadableAls extends taggedError<UnreadableAls, { readonly brand: unique symbol }>()(\n \"UnreadableAls\",\n { message: Schema.String },\n { identifier: \"UnreadableAls\" },\n) {}\n\nconst REPEATED = new Set([\n \"MidiTrack\",\n \"AudioTrack\",\n \"GroupTrack\",\n \"ReturnTrack\",\n \"MidiClip\",\n \"AudioClip\",\n \"KeyTrack\",\n \"MidiNoteEvent\",\n \"Locator\",\n \"AutomationEnvelope\",\n \"FloatEvent\",\n \"EnumEvent\",\n \"BoolEvent\",\n \"TrackSendHolder\",\n]);\n\nconst ATTRIBUTES = \"@\";\n\nconst parser = new XMLParser({\n ignoreAttributes: false,\n attributeNamePrefix: \"\",\n attributesGroupName: ATTRIBUTES,\n parseTagValue: false,\n parseAttributeValue: false,\n jPath: false,\n isArray: (name: string): boolean => REPEATED.has(name),\n});\n\nconst Num = Schema.Struct({ Value: Schema.FiniteFromString });\nconst Text = Schema.Struct({ Value: Schema.String });\nconst Flag = Schema.Struct({ Value: Schema.Literals([\"true\", \"false\"]) });\n\nconst EventSchema = Schema.Struct({ Time: Schema.FiniteFromString, Value: Schema.String });\n\nexport type AutomationEvent = typeof EventSchema.Type;\n\nconst EventsSchema = Schema.Struct({\n FloatEvent: EventSchema.pipe(Schema.Array, Schema.optionalKey),\n EnumEvent: EventSchema.pipe(Schema.Array, Schema.optionalKey),\n BoolEvent: EventSchema.pipe(Schema.Array, Schema.optionalKey),\n});\n\nconst EnvelopeSchema = Schema.Struct({\n EnvelopeTarget: Schema.Struct({ PointeeId: Num }),\n Automation: Schema.Struct({ Events: EventsSchema }),\n});\n\nexport type AutomationEnvelope = typeof EnvelopeSchema.Type;\n\nconst EnvelopeListSchema = Schema.Struct({\n AutomationEnvelope: EnvelopeSchema.pipe(Schema.Array, Schema.optionalKey),\n});\n\nconst EnvelopesSchema = Schema.Struct({ Envelopes: EnvelopeListSchema });\n\nconst TargetSchema = Schema.Struct({ Id: Schema.FiniteFromString });\n\nconst ParameterSchema = Schema.Struct({\n Manual: Schema.optionalKey(Num),\n AutomationTarget: Schema.optionalKey(TargetSchema),\n ArrangerAutomation: Schema.optionalKey(Schema.Struct({ Events: EventsSchema })),\n});\n\nexport type Parameter = typeof ParameterSchema.Type;\n\nconst NoteSchema = Schema.Struct({\n Time: Schema.FiniteFromString,\n Duration: Schema.FiniteFromString,\n Velocity: Schema.FiniteFromString,\n OffVelocity: Schema.optionalKey(Schema.FiniteFromString),\n IsEnabled: Schema.optionalKey(Schema.Literals([\"true\", \"false\"])),\n Probability: Schema.optionalKey(Schema.FiniteFromString),\n VelocityDeviation: Schema.optionalKey(Schema.FiniteFromString),\n});\n\nconst NoteListSchema = Schema.Struct({\n MidiNoteEvent: NoteSchema.pipe(Schema.Array, Schema.optionalKey),\n});\n\nconst KeyTrackSchema = Schema.Struct({ Notes: NoteListSchema, MidiKey: Num });\n\nconst LoopSchema = Schema.Struct({\n LoopStart: Num,\n LoopEnd: Num,\n StartRelative: Num,\n LoopOn: Flag,\n});\n\nconst KeyTracksSchema = Schema.Struct({\n KeyTrack: KeyTrackSchema.pipe(Schema.Array, Schema.optionalKey),\n});\n\nconst ClipSchema = Schema.Struct({\n CurrentStart: Num,\n CurrentEnd: Num,\n Loop: LoopSchema,\n Disabled: Schema.optionalKey(Flag),\n Notes: Schema.Struct({ KeyTracks: KeyTracksSchema }),\n});\n\nexport type AlsClip = typeof ClipSchema.Type;\n\nconst NameSchema = Schema.Struct({\n EffectiveName: Schema.optionalKey(Text),\n UserName: Schema.optionalKey(Text),\n});\n\nconst DrumsSchema = Schema.Struct({ DrumGroupDevice: Schema.optionalKey(Schema.Unknown) });\n\nconst DevicesSchema = Schema.Struct({ Devices: Schema.optionalKey(DrumsSchema) });\n\nconst ClipEventsSchema = Schema.Struct({\n MidiClip: ClipSchema.pipe(Schema.Array, Schema.optionalKey),\n});\n\nconst ArrangementSchema = Schema.Struct({\n ArrangerAutomation: Schema.Struct({ Events: ClipEventsSchema }),\n});\n\nconst SendHolderSchema = Schema.Struct({ Send: ParameterSchema });\n\nconst SendsSchema = Schema.Struct({\n TrackSendHolder: SendHolderSchema.pipe(Schema.Array, Schema.optionalKey),\n});\n\nconst SpeakerSchema = Schema.Struct({ Manual: Schema.optionalKey(Flag) });\n\nconst TrackMixerSchema = Schema.Struct({\n Volume: ParameterSchema,\n Pan: ParameterSchema,\n Speaker: Schema.optionalKey(SpeakerSchema),\n Sends: Schema.optionalKey(SendsSchema),\n});\n\nexport type AlsMixer = typeof TrackMixerSchema.Type;\n\nconst TrackChainSchema = Schema.Struct({\n DeviceChain: Schema.optionalKey(DevicesSchema),\n Mixer: Schema.optionalKey(TrackMixerSchema),\n MainSequencer: Schema.Struct({ ClipTimeable: ArrangementSchema }),\n});\n\nconst MidiTrackSchema = Schema.Struct({\n Id: Schema.String,\n Name: NameSchema,\n AutomationEnvelopes: Schema.optionalKey(EnvelopesSchema),\n DeviceChain: TrackChainSchema,\n});\n\nexport type AlsMidiTrack = typeof MidiTrackSchema.Type;\n\nconst ReturnTrackSchema = Schema.Struct({\n Name: NameSchema,\n DeviceChain: Schema.Struct({ Mixer: Schema.optionalKey(TrackMixerSchema) }),\n});\n\nexport type AlsReturnTrack = typeof ReturnTrackSchema.Type;\n\nconst MixerSchema = Schema.Struct({ Tempo: ParameterSchema, TimeSignature: ParameterSchema });\n\nconst MasterSchema = Schema.Struct({\n AutomationEnvelopes: Schema.optionalKey(EnvelopesSchema),\n DeviceChain: Schema.optionalKey(Schema.Struct({ Mixer: MixerSchema })),\n MasterChain: Schema.optionalKey(Schema.Struct({ Mixer: MixerSchema })),\n});\n\nexport type AlsMaster = typeof MasterSchema.Type;\n\nconst LocatorSchema = Schema.Struct({ Time: Num, Name: Text });\n\nexport type AlsLocator = typeof LocatorSchema.Type;\n\nconst TracksSchema = Schema.Struct({\n MidiTrack: MidiTrackSchema.pipe(Schema.Array, Schema.optionalKey),\n ReturnTrack: ReturnTrackSchema.pipe(Schema.Array, Schema.optionalKey),\n});\n\nconst LocatorListSchema = Schema.Struct({\n Locator: LocatorSchema.pipe(Schema.Array, Schema.optionalKey),\n});\n\nconst LiveSetSchema = Schema.Struct({\n Tracks: TracksSchema,\n MasterTrack: Schema.optionalKey(MasterSchema),\n MainTrack: Schema.optionalKey(MasterSchema),\n Locators: Schema.optionalKey(Schema.Struct({ Locators: LocatorListSchema })),\n});\n\nexport type LiveSet = typeof LiveSetSchema.Type;\n\nconst DocumentSchema = Schema.Struct({\n Ableton: Schema.Struct({\n MajorVersion: Schema.String,\n MinorVersion: Schema.String,\n Creator: Schema.optionalKey(Schema.String),\n LiveSet: LiveSetSchema,\n }),\n});\n\nconst decodeDocument = Schema.decodeUnknownEffect(DocumentSchema);\n\nconst isElement = Schema.is(Schema.Record(Schema.String, Schema.Unknown));\nconst isAttributes = Schema.is(Schema.Record(Schema.String, Schema.String));\n\nconst flattened = (node: unknown): unknown => {\n if (node === \"\") {\n return {};\n }\n if (Arr.isArray(node)) {\n return pipe(\n node,\n Arr.map((child) => flattened(child)),\n );\n }\n if (isElement(node)) {\n const { [ATTRIBUTES]: attributes, ...children } = node;\n const own = pipe(\n Option.liftPredicate(attributes, isAttributes),\n Option.getOrElse((): Readonly<Record<string, string>> => ({})),\n );\n return {\n ...pipe(\n children,\n Rec.map((child) => flattened(child)),\n ),\n ...own,\n };\n }\n return node;\n};\n\nconst gunzip = (bytes: Uint8Array): Effect.Effect<string, UnreadableAls> =>\n Effect.tryPromise({\n try: () =>\n new Response(\n new Blob([Uint8Array.from(bytes)]).stream().pipeThrough(new DecompressionStream(\"gzip\")),\n ).text(),\n catch: (cause) => UnreadableAls.make({ message: `Not a gzipped Live Set: ${String(cause)}` }),\n });\n\nexport type AlsDocument = typeof DocumentSchema.Type;\n\nexport const readAlsDocument: (bytes: Uint8Array) => Effect.Effect<AlsDocument, UnreadableAls> =\n Effect.fn(\"readAlsDocument\")(function* read(\n bytes: Uint8Array,\n ): Effect.fn.Return<AlsDocument, UnreadableAls> {\n const xml = yield* gunzip(bytes);\n const parsed = yield* Effect.try({\n try: () => flattened(parser.parse(xml)),\n catch: (cause) => UnreadableAls.make({ message: `Not XML: ${String(cause)}` }),\n });\n return yield* decodeDocument(parsed).pipe(\n Effect.mapError((issue) =>\n UnreadableAls.make({ message: `Not a Live Set this converter reads: ${String(issue)}` }),\n ),\n );\n });\n","import { Array as Arr, Option, Order, pipe } from \"effect\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\n\nimport type { AlsClip } from \"./live-set.ts\";\n\nconst NONE = 0;\n\nexport interface PlayedNote {\n readonly beat: number;\n readonly length: number;\n readonly midi: number;\n readonly velocity: number;\n readonly release: number;\n}\n\ninterface Pass {\n readonly at: number;\n readonly from: number;\n readonly to: number;\n}\n\ninterface SourceNote {\n readonly time: number;\n readonly end: number;\n readonly midi: number;\n readonly velocity: number;\n readonly release: number;\n}\n\nconst DEFAULT_RELEASE = 64;\n\nconst modulo = (value: number, size: number): number => ((value % size) + size) % size;\n\nconst passesOf: From<AlsClip, readonly Pass[]> = (clip) => {\n const start = clip.CurrentStart.Value;\n const length = clip.CurrentEnd.Value - start;\n const loopStart = clip.Loop.LoopStart.Value;\n const loopLength = clip.Loop.LoopEnd.Value - loopStart;\n if (clip.Loop.LoopOn.Value === \"false\" || loopLength <= NONE) {\n return [{ at: start, from: loopStart, to: loopStart + length }];\n }\n const first = loopStart + modulo(clip.Loop.StartRelative.Value, loopLength);\n const walk = (elapsed: number, from: number, passes: readonly Pass[]): readonly Pass[] => {\n if (elapsed >= length) {\n return passes;\n }\n const span = Math.min(clip.Loop.LoopEnd.Value - from, length - elapsed);\n return walk(elapsed + span, loopStart, [\n ...passes,\n { at: start + elapsed, from, to: from + span },\n ]);\n };\n return walk(NONE, first, []);\n};\n\nconst releaseOf = (offVelocity: number | undefined): number =>\n pipe(\n Option.fromUndefinedOr(offVelocity),\n Option.filter((off) => off !== NONE),\n Option.match({ onNone: () => DEFAULT_RELEASE, onSome: Math.round }),\n );\n\nconst sourceNotesOf: From<AlsClip, readonly SourceNote[]> = (clip) =>\n pipe(\n clip.Notes.KeyTracks.KeyTrack ?? [],\n Arr.flatMap((keyTrack) =>\n pipe(\n keyTrack.Notes.MidiNoteEvent ?? [],\n Arr.filter((note) => note.IsEnabled !== \"false\"),\n Arr.map((note): SourceNote => ({\n time: note.Time,\n end: note.Time + note.Duration,\n midi: keyTrack.MidiKey.Value,\n velocity: Math.round(note.Velocity),\n release: releaseOf(note.OffVelocity),\n })),\n ),\n ),\n );\n\nconst inPass =\n (notes: readonly SourceNote[]): From<Pass, readonly PlayedNote[]> =>\n (pass) =>\n pipe(\n notes,\n Arr.filter((note) => note.time >= pass.from && note.time < pass.to),\n Arr.map((note): PlayedNote => ({\n beat: pass.at + note.time - pass.from,\n length: Math.min(note.end, pass.to) - note.time,\n midi: note.midi,\n velocity: note.velocity,\n release: note.release,\n })),\n );\n\nconst byStartThenPitch = Order.combine(\n Order.mapInput(Order.Number, (note: PlayedNote) => note.beat),\n Order.mapInput(Order.Number, (note: PlayedNote) => note.midi),\n);\n\nconst isDisabled: From<AlsClip, boolean> = (clip) =>\n Option.exists(Option.fromUndefinedOr(clip.Disabled), (flag) => flag.Value === \"true\");\n\nexport const notesOfClip: From<AlsClip, readonly PlayedNote[]> = (clip) => {\n if (isDisabled(clip)) {\n return [];\n }\n const notes = sourceNotesOf(clip);\n return pipe(passesOf(clip), Arr.flatMap(inPass(notes)), Arr.sortBy(byStartThenPitch));\n};\n","import { decodeTimeSignatureId } from \"ableton-als\";\nimport { Array as Arr, Option, Order, pipe } from \"effect\";\n\nimport type { From } from \"#/shared/lib/from.ts\";\n\nimport type {\n AlsLocator,\n AlsMaster,\n AutomationEnvelope,\n AutomationEvent,\n LiveSet,\n Parameter,\n} from \"./live-set.ts\";\n\nexport const SONG_START = 0;\n\nexport interface Point {\n readonly beat: number;\n readonly value: number;\n}\n\nexport interface TempoSegment {\n readonly beat: number;\n readonly bpm: number;\n readonly target: Option.Option<number>;\n}\n\nexport interface MeterChange {\n readonly beat: number;\n readonly numerator: number;\n readonly denominator: number;\n}\n\nexport interface Locator {\n readonly beat: number;\n readonly name: string;\n}\n\nconst masterOf: From<LiveSet, Option.Option<AlsMaster>> = (liveSet) =>\n Option.orElse(Option.fromUndefinedOr(liveSet.MasterTrack), () =>\n Option.fromUndefinedOr(liveSet.MainTrack),\n );\n\ninterface Mixer {\n readonly Tempo: Parameter;\n readonly TimeSignature: Parameter;\n}\n\nconst mixerOf: From<AlsMaster, Option.Option<Mixer>> = (master) =>\n pipe(\n Option.fromUndefinedOr(master.DeviceChain),\n Option.orElse(() => Option.fromUndefinedOr(master.MasterChain)),\n Option.map((chain) => chain.Mixer),\n );\n\nconst eventsOf = (events: {\n readonly FloatEvent?: readonly AutomationEvent[];\n readonly EnumEvent?: readonly AutomationEvent[];\n readonly BoolEvent?: readonly AutomationEvent[];\n}): readonly AutomationEvent[] => [\n ...(events.FloatEvent ?? []),\n ...(events.EnumEvent ?? []),\n ...(events.BoolEvent ?? []),\n];\n\nexport type Automated = Pick<AlsMaster, \"AutomationEnvelopes\">;\n\nconst automationEnvelopesOf = (owner: Automated): readonly AutomationEnvelope[] =>\n pipe(\n Option.fromUndefinedOr(owner.AutomationEnvelopes),\n Option.flatMap((envelopes) => Option.fromUndefinedOr(envelopes.Envelopes.AutomationEnvelope)),\n Option.getOrElse((): readonly AutomationEnvelope[] => []),\n );\n\nconst byTime = Order.mapInput(Order.Number, (event: AutomationEvent) => event.Time);\n\nexport const envelopeOf =\n (owner: Automated): From<Parameter, readonly AutomationEvent[]> =>\n (parameter) => {\n const inline = pipe(\n Option.fromUndefinedOr(parameter.ArrangerAutomation),\n Option.map((automation) => automation.Events),\n );\n const pointed = pipe(\n Option.fromUndefinedOr(parameter.AutomationTarget),\n Option.flatMap((target) =>\n pipe(\n automationEnvelopesOf(owner),\n Arr.findFirst((envelope) => envelope.EnvelopeTarget.PointeeId.Value === target.Id),\n ),\n ),\n Option.map((envelope) => envelope.Automation.Events),\n );\n return pipe(\n Option.orElse(pointed, () => inline),\n Option.map(eventsOf),\n Option.getOrElse((): readonly AutomationEvent[] => []),\n Arr.sortBy(byTime),\n );\n };\n\nconst SINGLE = 1;\nconst NEXT = 1;\n\ninterface Automation {\n readonly events: readonly AutomationEvent[];\n readonly manual: Option.Option<number>;\n}\n\nconst automationOf =\n (select: From<Mixer, Parameter>): From<LiveSet, Option.Option<Automation>> =>\n (liveSet) =>\n pipe(\n masterOf(liveSet),\n Option.flatMap((master) =>\n pipe(\n mixerOf(master),\n Option.map((mixer): Automation => {\n const parameter = select(mixer);\n return {\n events: envelopeOf(master)(parameter),\n manual: pipe(\n Option.fromUndefinedOr(parameter.Manual),\n Option.map((manual) => manual.Value),\n ),\n };\n }),\n ),\n ),\n );\n\nconst tempoAutomationOf = automationOf((mixer) => mixer.Tempo);\n\nconst pointsOf = (events: readonly AutomationEvent[]): readonly Point[] =>\n pipe(\n events,\n Arr.map((event): Point => ({ beat: event.Time, value: Number(event.Value) })),\n );\n\nconst tempoFrom =\n (resolve: From<Automation, readonly Point[]>): From<LiveSet, readonly Point[]> =>\n (liveSet) =>\n pipe(\n tempoAutomationOf(liveSet),\n Option.map(resolve),\n Option.getOrElse((): readonly Point[] => []),\n );\n\nexport const tempoEnvelopeOf = tempoFrom(({ events }) => pointsOf(events));\n\nconst manualPointsOf = tempoFrom(({ manual }) =>\n pipe(\n manual,\n Option.map((value): readonly Point[] => [{ beat: SONG_START, value }]),\n Option.getOrElse((): readonly Point[] => []),\n ),\n);\n\nexport const tempoPointsOf: From<LiveSet, readonly Point[]> = (liveSet) => {\n const envelope = tempoEnvelopeOf(liveSet);\n const manual = manualPointsOf(liveSet);\n if (envelope.length > SINGLE || !Arr.isReadonlyArrayNonEmpty(manual)) {\n return envelope;\n }\n return manual;\n};\n\nconst valueAt =\n (from: Point, to: Point): From<number, number> =>\n (beat) => {\n if (to.beat === from.beat) {\n return to.value;\n }\n return from.value + ((to.value - from.value) * (beat - from.beat)) / (to.beat - from.beat);\n };\n\nconst segmentOf = (from: Point, next: Option.Option<Point>): TempoSegment => {\n const start = Math.max(from.beat, SONG_START);\n return Option.match(next, {\n onNone: () => ({ beat: start, bpm: from.value, target: Option.none() }),\n onSome: (to) => {\n const bpm = valueAt(from, to)(start);\n if (to.beat <= start || to.value === bpm) {\n return { beat: start, bpm, target: Option.none() };\n }\n return { beat: start, bpm, target: Option.some(to.value) };\n },\n });\n};\n\nconst keptWith = (\n kept: readonly TempoSegment[],\n segment: TempoSegment,\n): readonly TempoSegment[] => {\n const earlier = pipe(\n Arr.last(kept),\n Option.filter((last) => last.beat === segment.beat),\n Option.match({ onNone: () => kept, onSome: () => Arr.dropRight(kept, SINGLE) }),\n );\n const redundant = pipe(\n Arr.last(earlier),\n Option.exists(\n (last) =>\n Option.isNone(last.target) && Option.isNone(segment.target) && last.bpm === segment.bpm,\n ),\n );\n if (redundant) {\n return earlier;\n }\n return [...earlier, segment];\n};\n\nconst withoutRepeats = (segments: readonly TempoSegment[]): readonly TempoSegment[] => {\n let kept: readonly TempoSegment[] = [];\n for (const segment of segments) {\n kept = keptWith(kept, segment);\n }\n return kept;\n};\n\nexport const tempoSegmentsOf: From<readonly Point[], readonly TempoSegment[]> = (points) =>\n pipe(\n points,\n Arr.map((point, index) => ({ point, next: Arr.get(points, index + NEXT) })),\n Arr.filter(({ next }) =>\n Option.match(next, { onNone: () => true, onSome: (to) => to.beat > SONG_START }),\n ),\n Arr.map(({ point, next }) => segmentOf(point, next)),\n withoutRepeats,\n );\n\nconst meterOfId = (beat: number, id: number): Option.Option<MeterChange> =>\n pipe(\n Option.fromNullishOr(decodeTimeSignatureId(id)),\n Option.map((signature) => ({\n beat: Math.max(beat, SONG_START),\n numerator: signature.num,\n denominator: signature.den,\n })),\n );\n\nexport const metersOf: From<LiveSet, readonly MeterChange[]> = (liveSet) =>\n pipe(\n automationOf((mixer) => mixer.TimeSignature)(liveSet),\n Option.map(({ events, manual }) => {\n if (events.length > SINGLE || Option.isNone(manual)) {\n return pipe(\n events,\n Arr.map((event) => meterOfId(event.Time, Number(event.Value))),\n Arr.getSomes,\n Arr.reverse,\n Arr.dedupeAdjacentWith((later, earlier) => later.beat === earlier.beat),\n Arr.reverse,\n );\n }\n return Option.toArray(meterOfId(SONG_START, manual.value));\n }),\n Option.getOrElse((): readonly MeterChange[] => []),\n );\n\nconst byBeat = Order.mapInput(Order.Number, (locator: Locator) => locator.beat);\n\nexport const locatorsOf: From<LiveSet, readonly Locator[]> = (liveSet) =>\n pipe(\n Option.fromUndefinedOr(liveSet.Locators),\n Option.flatMap((locators) => Option.fromUndefinedOr(locators.Locators.Locator)),\n Option.getOrElse((): readonly AlsLocator[] => []),\n Arr.map((locator): Locator => ({ beat: locator.Time.Value, name: locator.Name.Value })),\n Arr.sortBy(byBeat),\n );\n","import type { From } from \"#/shared/lib/from.ts\";\nimport { TICKS_PER_WHOLE } from \"#/shared/lib/ticks.ts\";\n\nconst QUARTERS_PER_WHOLE = 4;\nconst TICKS_PER_BEAT = TICKS_PER_WHOLE / QUARTERS_PER_WHOLE;\n\nexport interface Tick {\n readonly tick: number;\n readonly exact: boolean;\n}\n\nexport const tickOf: From<number, Tick> = (beat) => {\n const exact = beat * TICKS_PER_BEAT;\n return { tick: Math.round(exact), exact: Number.isInteger(exact) };\n};\n","import { Array as Arr, Option, pipe } from \"effect\";\n\nimport { MIXER_PARAMETERS } from \"#/entities/song/index.ts\";\nimport type {\n BusMix,\n Envelope,\n Level,\n Mix,\n MixParameter,\n MixPoint,\n TrackMix,\n TrackSend,\n} from \"#/entities/timeline/index.ts\";\nimport type { From } from \"#/shared/lib/from.ts\";\n\nimport type { AlsMidiTrack, AlsMixer, AlsReturnTrack, LiveSet, Parameter } from \"./live-set.ts\";\nimport { SONG_START, envelopeOf } from \"./tempo-map.ts\";\nimport type { Automated } from \"./tempo-map.ts\";\nimport { tickOf } from \"./ticks.ts\";\n\nconst DECIBELS_PER_DECADE = 20;\nconst SILENT_DECIBELS = -70;\nconst AUDIBLE_SEND = 0.001;\nconst NONE = 0;\nconst NEXT = 1;\n\nconst DECIMAL_BASE = 10;\nconst SILENT = DECIMAL_BASE ** (SILENT_DECIBELS / DECIBELS_PER_DECADE);\n\nconst decibelsOf: From<number, number> = (gain) =>\n DECIBELS_PER_DECADE * Math.log10(Math.max(gain, SILENT));\n\nconst [VOLUME, PAN] = MIXER_PARAMETERS;\n\nconst VALUES: Readonly<Record<MixParameter, From<number, number>>> = {\n volume: decibelsOf,\n pan: (pan) => pan,\n};\n\nconst RESTING: Readonly<Record<MixParameter, number>> = { volume: NONE, pan: NONE };\n\ntype Owned = Readonly<{ owner: Automated; parameter: MixParameter }>;\n\nconst pointsOf =\n ({ owner, parameter }: Owned): From<Parameter, readonly MixPoint[]> =>\n (control) =>\n pipe(\n envelopeOf(owner)(control),\n Arr.map((event) => ({\n tick: tickOf(Math.max(event.Time, SONG_START)).tick,\n value: VALUES[parameter](Number(event.Value)),\n })),\n Arr.filter((point) => Number.isFinite(point.value)),\n );\n\nconst startOf =\n (owned: Owned): From<Parameter, number> =>\n (control) =>\n pipe(\n pointsOf(owned)(control),\n Arr.head,\n Option.map((point) => point.value),\n Option.orElse(() =>\n pipe(\n Option.fromUndefinedOr(control.Manual),\n Option.map((manual) => VALUES[owned.parameter](manual.Value)),\n ),\n ),\n Option.getOrElse(() => RESTING[owned.parameter]),\n );\n\nconst levelOf =\n (owner: Automated): From<AlsMixer, Level> =>\n (mixer) => ({\n decibels: startOf({ owner, parameter: VOLUME })(mixer.Volume),\n pan: startOf({ owner, parameter: PAN })(mixer.Pan),\n muted: pipe(\n Option.fromUndefinedOr(mixer.Speaker),\n Option.flatMap((speaker) => Option.fromUndefinedOr(speaker.Manual)),\n Option.exists((manual) => manual.Value === \"false\"),\n ),\n });\n\nconst sendsOf: From<AlsMixer, readonly TrackSend[]> = (mixer) =>\n pipe(\n Option.fromUndefinedOr(mixer.Sends),\n Option.flatMap((sends) => Option.fromUndefinedOr(sends.TrackSendHolder)),\n Option.getOrElse(() => []),\n Arr.map((holder, bus) => ({\n bus,\n amount: pipe(\n Option.fromUndefinedOr(holder.Send.Manual),\n Option.match({ onNone: () => NONE, onSome: (manual) => manual.Value }),\n ),\n })),\n Arr.filter((send) => send.amount > AUDIBLE_SEND),\n );\n\nconst envelopesOf =\n (owner: Automated): From<AlsMixer, readonly Envelope[]> =>\n (mixer) =>\n pipe(\n [\n { parameter: \"volume\" as const, control: mixer.Volume },\n { parameter: \"pan\" as const, control: mixer.Pan },\n ],\n Arr.map(({ parameter, control }) => ({\n parameter,\n points: pointsOf({ owner, parameter })(control),\n })),\n Arr.filter((envelope) => envelope.points.length > NEXT),\n );\n\nconst trackMixOf: From<AlsMidiTrack, Option.Option<TrackMix>> = (track) =>\n pipe(\n Option.fromUndefinedOr(track.DeviceChain.Mixer),\n Option.map((mixer) => ({\n level: levelOf(track)(mixer),\n sends: sendsOf(mixer),\n envelopes: envelopesOf(track)(mixer),\n })),\n );\n\nconst NO_ENVELOPES: Automated = {};\n\nconst busOf =\n (nameOf: From<AlsReturnTrack[\"Name\"], Option.Option<string>>): From<AlsReturnTrack, BusMix> =>\n (track) => ({\n name: nameOf(track.Name),\n level: pipe(\n Option.fromUndefinedOr(track.DeviceChain.Mixer),\n Option.match({\n onNone: () => ({ decibels: NONE, pan: NONE, muted: false }),\n onSome: levelOf(NO_ENVELOPES),\n }),\n ),\n });\n\nexport const mixOf =\n (nameOf: From<AlsReturnTrack[\"Name\"], Option.Option<string>>): From<LiveSet, Mix> =>\n (liveSet) => ({\n tracks: new Map(\n pipe(\n liveSet.Tracks.MidiTrack ?? [],\n Arr.flatMap((track, index) =>\n pipe(\n trackMixOf(track),\n Option.map((mix) => [index, mix] as const),\n Option.toArray,\n ),\n ),\n ),\n ),\n buses: pipe(liveSet.Tracks.ReturnTrack ?? [], Arr.map(busOf(nameOf))),\n });\n","import { Array as Arr, Boolean as Bool, Option, pipe } from \"effect\";\n\nimport { microsecondsOf, sortedByTick, sortedNotes } from \"#/entities/timeline/index.ts\";\nimport type { Part, TempoChange, Timeline, TimelineNote } from \"#/entities/timeline/index.ts\";\nimport type { From } from \"#/shared/lib/from.ts\";\n\nimport { notesOfClip } from \"./clips.ts\";\nimport type { PlayedNote } from \"./clips.ts\";\nimport type { AlsMidiTrack, LiveSet } from \"./live-set.ts\";\nimport { mixOf } from \"./mix.ts\";\nimport { locatorsOf, metersOf, tempoPointsOf, tempoSegmentsOf } from \"./tempo-map.ts\";\nimport { tickOf } from \"./ticks.ts\";\n\nconst MELODIC_CHANNEL = 0;\nconst DRUM_CHANNEL = 9;\nconst NONE = 0;\nconst NEXT = 1;\n\nconst nameOf: From<AlsMidiTrack[\"Name\"], Option.Option<string>> = (label) =>\n pipe(\n [label.EffectiveName, label.UserName],\n Arr.map(Option.fromUndefinedOr),\n Arr.getSomes,\n Arr.map((name) => name.Value),\n Arr.findFirst((name) => name !== \"\"),\n );\n\nconst isDrumRack: From<AlsMidiTrack, boolean> = (track) =>\n pipe(\n Option.fromUndefinedOr(track.DeviceChain.DeviceChain),\n Option.flatMap((chain) => Option.fromUndefinedOr(chain.Devices)),\n Option.flatMap((devices) => Option.fromUndefinedOr(devices.DrumGroupDevice)),\n Option.isSome,\n );\n\ninterface TrackNotes {\n readonly notes: readonly TimelineNote[];\n readonly offGrid: number;\n}\n\nconst trackNotesOf: From<AlsMidiTrack, TrackNotes> = (track) => {\n const played: readonly PlayedNote[] = pipe(\n track.DeviceChain.MainSequencer.ClipTimeable.ArrangerAutomation.Events.MidiClip ?? [],\n Arr.flatMap(notesOfClip),\n );\n const placed = pipe(\n played,\n Arr.map((note) => ({\n note,\n start: tickOf(note.beat),\n end: tickOf(note.beat + note.length),\n })),\n );\n return {\n notes: sortedNotes(\n pipe(\n placed,\n Arr.map(({ note, start, end }): TimelineNote => ({\n tick: start.tick,\n end: end.tick,\n midi: note.midi,\n velocity: note.velocity,\n release: note.release,\n })),\n ),\n ),\n offGrid: Arr.countBy(placed, ({ start, end }) => !start.exact || !end.exact),\n };\n};\n\ninterface PartRead {\n readonly part: Part;\n readonly offGrid: number;\n}\n\nconst partOf = (track: AlsMidiTrack, index: number): PartRead => {\n const read = trackNotesOf(track);\n return {\n part: {\n track: index,\n channel: Bool.match(isDrumRack(track), {\n onFalse: () => MELODIC_CHANNEL,\n onTrue: () => DRUM_CHANNEL,\n }),\n name: nameOf(track.Name),\n program: Option.none(),\n notes: read.notes,\n controls: [],\n lyrics: [],\n },\n offGrid: read.offGrid,\n };\n};\n\nconst temposOf: From<LiveSet, readonly TempoChange[]> = (liveSet) =>\n pipe(\n tempoSegmentsOf(tempoPointsOf(liveSet)),\n Arr.map((segment): TempoChange => ({\n tick: tickOf(segment.beat).tick,\n microseconds: microsecondsOf(segment.bpm),\n target: pipe(segment.target, Option.map(microsecondsOf)),\n })),\n );\n\nconst lastOf: From<readonly number[], number> = (ticks) =>\n Arr.reduce(ticks, NONE, (latest, tick) => Math.max(latest, tick));\n\nexport const timelineOf: From<LiveSet, Timeline> = (liveSet) => {\n const reads = pipe(\n liveSet.Tracks.MidiTrack ?? [],\n Arr.map(partOf),\n Arr.filter((read) => Arr.isReadonlyArrayNonEmpty(read.part.notes)),\n );\n const parts = pipe(\n reads,\n Arr.map((read) => read.part),\n );\n const markers = sortedByTick(\n pipe(\n locatorsOf(liveSet),\n Arr.map((locator) => ({ tick: tickOf(locator.beat).tick, text: locator.name })),\n ),\n );\n const tempos = temposOf(liveSet);\n const meters = pipe(\n metersOf(liveSet),\n Arr.map((meter) => ({\n tick: tickOf(meter.beat).tick,\n numerator: meter.numerator,\n denominator: meter.denominator,\n })),\n );\n const noteEnds = pipe(\n parts,\n Arr.flatMap((part) => part.notes),\n Arr.map((note) => note.end),\n );\n const pointEnds = pipe(\n [...markers, ...tempos, ...meters],\n Arr.map((point) => point.tick + NEXT),\n );\n return {\n title: Option.none(),\n end: lastOf([...noteEnds, ...pointEnds]),\n offGrid: Arr.reduce(reads, NONE, (sum, read) => sum + read.offGrid),\n tempos,\n meters,\n markers,\n parts,\n mix: mixOf(nameOf)(liveSet),\n };\n};\n","import { Effect } from \"effect\";\n\nimport { writeFumx } from \"#/entities/timeline/index.ts\";\nimport type { Written } from \"#/entities/timeline/index.ts\";\n\nimport { readAlsDocument } from \"./live-set.ts\";\nimport { timelineOf } from \"./timeline.ts\";\n\nexport interface LiveSetFile {\n readonly bytes: Uint8Array;\n readonly title: string;\n}\n\nexport interface Fumx extends Written {\n readonly offGrid: number;\n}\n\nexport const alsToFumx = Effect.fn(\"alsToFumx\")(function* convert(input: LiveSetFile) {\n const document = yield* readAlsDocument(input.bytes);\n const timeline = yield* Effect.sync(() => timelineOf(document.Ableton.LiveSet)).pipe(\n Effect.withSpan(\"timelineOf\"),\n );\n const written = yield* Effect.sync(() => writeFumx({ timeline, title: input.title })).pipe(\n Effect.withSpan(\"writeFumx\"),\n );\n yield* Effect.annotateCurrentSpan({\n creator: document.Ableton.Creator ?? \"\",\n parts: written.plan.parts.length,\n bars: written.bars.length,\n });\n const fumx: Fumx = { ...written, offGrid: timeline.offGrid };\n return fumx;\n});\n","import { Effect } from \"effect\";\n\nimport { alsToFumx } from \"#/features/convert-als/index.ts\";\nimport type { LiveSetFile } from \"#/features/convert-als/index.ts\";\n\nimport { roundTrip } from \"./round-trip.ts\";\n\nexport interface LiveSetSource extends LiveSetFile {\n readonly path: string;\n}\n\nexport const convertLiveSetFile = Effect.fn(\"convertLiveSetFile\")(function* convert(\n source: LiveSetSource,\n) {\n const fumx = yield* alsToFumx(source);\n return yield* roundTrip(source.path, fumx);\n});\n","#!/usr/bin/env node\nimport { convertLiveSetFile } from \"#/app/als-to-fumx.ts\";\nimport { convertMain } from \"#/app/convert-command.ts\";\n\nconvertMain({\n name: \"als-to-fumx\",\n input: \"An Ableton Live Set (.als)\",\n source: \"Live Set\",\n convert: convertLiveSetFile,\n});\n"],"mappings":";;;;;;;;AAGA,MAAM,cAAc,OAAO;AAE3B,IAAa,gBAAb,cAAmC,YAA8D,CAAC,CAChG,iBACA,EAAE,SAAS,OAAO,OAAO,GACzB,EAAE,YAAY,gBAAgB,CAChC,CAAC,CAAC,CAAC;AAEH,MAAM,2B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-DPt8MZ6e.mjs";
2
+ import { d as Song, u as Role } from "./song-3Zm9g84K.mjs";
3
+ import { Option, Schema } from "effect";
4
+ export declare const AnalysisSchema: Schema.Struct<{
5
+ readonly bars: Schema.Int;
6
+ readonly key: Schema.OptionFromNullOr<Schema.Struct<{
7
+ readonly fromBar: Schema.Int;
8
+ readonly toBar: Schema.Int;
9
+ readonly tonic: Schema.String;
10
+ readonly pitchClass: Schema.Int;
11
+ readonly mode: Schema.Literals<readonly ["major", "minor"]>;
12
+ readonly correlation: Schema.Finite;
13
+ }>>;
14
+ readonly keys: Schema.$Array<Schema.Struct<{
15
+ readonly fromBar: Schema.Int;
16
+ readonly toBar: Schema.Int;
17
+ readonly tonic: Schema.String;
18
+ readonly pitchClass: Schema.Int;
19
+ readonly mode: Schema.Literals<readonly ["major", "minor"]>;
20
+ readonly correlation: Schema.Finite;
21
+ }>>;
22
+ readonly chords: Schema.$Array<Schema.Struct<{
23
+ readonly from: Schema.Struct<{
24
+ readonly bar: Schema.Int;
25
+ readonly offset: Schema.String;
26
+ }>;
27
+ readonly to: Schema.Struct<{
28
+ readonly bar: Schema.Int;
29
+ readonly offset: Schema.String;
30
+ }>;
31
+ readonly start: Schema.Int;
32
+ readonly end: Schema.Int;
33
+ readonly symbol: Schema.String;
34
+ readonly notes: Schema.$Array<Schema.String>;
35
+ }>>;
36
+ readonly repeats: Schema.$Array<Schema.Struct<{
37
+ fromBar: Schema.Int;
38
+ toBar: Schema.Int;
39
+ }>>;
40
+ }>;
41
+ type Analysis = typeof AnalysisSchema.Type;
42
+ export declare const analyze: (song: Song) => Analysis;
43
+ export declare const ChordSpanSchema: Schema.Struct<{
44
+ readonly from: Schema.Struct<{
45
+ readonly bar: Schema.Int;
46
+ readonly offset: Schema.String;
47
+ }>;
48
+ readonly to: Schema.Struct<{
49
+ readonly bar: Schema.Int;
50
+ readonly offset: Schema.String;
51
+ }>;
52
+ readonly start: Schema.Int;
53
+ readonly end: Schema.Int;
54
+ readonly symbol: Schema.String;
55
+ readonly notes: Schema.$Array<Schema.String>;
56
+ }>;
57
+ type ChordSpan = typeof ChordSpanSchema.Type;
58
+ export declare const chordsOf: (song: Song) => readonly ChordSpan[];
59
+ export declare const BarRangeSchema: Schema.Struct<{
60
+ fromBar: Schema.Int;
61
+ toBar: Schema.Int;
62
+ }>;
63
+ type BarRange = typeof BarRangeSchema.Type;
64
+ export declare const KeySpanSchema: Schema.Struct<{
65
+ readonly fromBar: Schema.Int;
66
+ readonly toBar: Schema.Int;
67
+ readonly tonic: Schema.String;
68
+ readonly pitchClass: Schema.Int;
69
+ readonly mode: Schema.Literals<readonly ["major", "minor"]>;
70
+ readonly correlation: Schema.Finite;
71
+ }>;
72
+ type KeySpan = typeof KeySpanSchema.Type;
73
+ export declare const keyIn: (song: Song) => (range: BarRange) => Option.Option<KeySpan>;
74
+ interface Span {
75
+ readonly start: number;
76
+ readonly end: number;
77
+ }
78
+ interface Sounding extends Span {
79
+ readonly track: string;
80
+ readonly line: number;
81
+ readonly column: number;
82
+ readonly bar: number;
83
+ readonly role: Option.Option<Role>;
84
+ readonly midi: number;
85
+ readonly spelling: string;
86
+ readonly pitchClass: string;
87
+ }
88
+ export declare const overlapOf: (left: Span) => (right: Span) => number;
89
+ export declare const soundingsOf: (song: Song) => readonly Sounding[];
90
+ export declare const positionOf: (song: Song) => (tick: number) => {
91
+ readonly bar: number;
92
+ readonly offset: string;
93
+ };
94
+ export type { Analysis, BarRange, ChordSpan, KeySpan, Sounding, Span };
95
+ //# sourceMappingURL=analysis.d.mts.map
@@ -0,0 +1,328 @@
1
+ import { n as fractionOf, t as TICKS_PER_WHOLE } from "./ticks-CXehHP2w.mjs";
2
+ import { Array, Option, Order, Record, Schema, String as String$1, pipe } from "effect";
3
+ import { Chord, Note } from "tonal";
4
+ // src/features/analyze-song/model/sounding.ts
5
+ const NONE$2 = 0;
6
+ const FIRST$3 = 1;
7
+ const CENTS = /[+-]\d+c$/u;
8
+ const pitchClassOf$1 = (note) => {
9
+ const written = Note.pitchClass(String$1.replace(CENTS, "")(note.spelling));
10
+ if (String$1.isNonEmpty(written)) return written;
11
+ return Note.pitchClass(Note.fromMidi(note.midi));
12
+ };
13
+ const overlapOf = (left) => (right) => Math.max(NONE$2, Math.min(left.end, right.end) - Math.max(left.start, right.start));
14
+ const soundingsOf = (song) => {
15
+ const audible = pipe(song.tracks, Array.filter((track) => !track.mixer.muted));
16
+ return pipe(song.notes, Array.flatMap((note) => pipe(audible, Array.findFirst((track) => track.name === note.track), Option.map((track) => ({
17
+ track: note.track,
18
+ line: note.sourceLine,
19
+ column: note.sourceColumn,
20
+ bar: note.bar,
21
+ role: track.role,
22
+ midi: note.midi,
23
+ spelling: note.spelling,
24
+ pitchClass: pitchClassOf$1(note),
25
+ start: note.start,
26
+ end: note.start + Math.round(note.length * note.gate)
27
+ })), Option.toArray)));
28
+ };
29
+ const positionOf = (song) => (tick) => pipe(song.bars, Array.findLast((bar) => bar.start <= tick), Option.match({
30
+ onNone: () => ({
31
+ bar: FIRST$3,
32
+ offset: fractionOf(tick)
33
+ }),
34
+ onSome: (bar) => ({
35
+ bar: bar.index,
36
+ offset: fractionOf(tick - bar.start)
37
+ })
38
+ }));
39
+ // src/features/analyze-song/model/chords.ts
40
+ const FIRST$2 = 1;
41
+ const HELD_SHARE = .25;
42
+ const UNKNOWN$1 = "?";
43
+ const PositionSchema = Schema.Struct({
44
+ bar: Schema.Int,
45
+ offset: Schema.String
46
+ });
47
+ const ChordSpanSchema = Schema.Struct({
48
+ from: PositionSchema,
49
+ to: PositionSchema,
50
+ start: Schema.Int,
51
+ end: Schema.Int,
52
+ symbol: Schema.String,
53
+ notes: Schema.Array(Schema.String)
54
+ });
55
+ const heldIn = (window) => (note) => overlapOf(note)(window) >= (window.end - window.start) * HELD_SHARE;
56
+ const isHarmonic = (note) => Option.exists(note.role, (role) => role === "bass" || role === "harmony");
57
+ const OCTAVE$1 = 12;
58
+ const UNISON = 0;
59
+ const samePitchClass = (left, right) => (left - right) % OCTAVE$1 === UNISON;
60
+ const byMidi = Order.mapInput(Order.Number, (note) => note.midi);
61
+ const harmonicOrAll = (held) => {
62
+ const harmonic = pipe(held, Array.filter(isHarmonic));
63
+ if (Array.isReadonlyArrayNonEmpty(harmonic)) return harmonic;
64
+ return held;
65
+ };
66
+ const chordNotesIn = (notes) => (window) => pipe(notes, Array.filter(heldIn(window)), harmonicOrAll, (held) => Array.sort(held, byMidi), Array.dedupeWith((left, right) => samePitchClass(left.midi, right.midi)), Array.map((note) => note.pitchClass));
67
+ const spells = (notes) => (symbol) => {
68
+ const spelled = Chord.get(symbol).notes;
69
+ return spelled.length === notes.length && pipe(spelled, Array.every((note) => Array.contains(notes, note)));
70
+ };
71
+ const symbolOf = (notes) => {
72
+ const candidates = Chord.detect(Array.copy(notes));
73
+ return pipe(candidates, Array.findFirst(spells(notes)), Option.orElse(() => Array.head(candidates)), Option.getOrElse(() => UNKNOWN$1));
74
+ };
75
+ const beatWindowsOf = (song) => pipe(song.bars, Array.flatMap((bar) => {
76
+ const beat = TICKS_PER_WHOLE / bar.meter.denominator;
77
+ return Array.makeBy(bar.meter.numerator, (index) => ({
78
+ start: bar.start + index * beat,
79
+ end: bar.start + (index + FIRST$2) * beat
80
+ }));
81
+ }));
82
+ const extend = (spans, beat) => Option.match(Array.last(spans), {
83
+ onNone: () => [beat],
84
+ onSome: (last) => {
85
+ if (last.symbol !== beat.symbol || last.end !== beat.start) return [...spans, beat];
86
+ return [...Array.dropRight(spans, FIRST$2), {
87
+ ...last,
88
+ end: beat.end
89
+ }];
90
+ }
91
+ });
92
+ const beatChordOf = (notes) => (window) => {
93
+ const held = chordNotesIn(notes)(window);
94
+ if (!Array.isReadonlyArrayNonEmpty(held)) return Option.none();
95
+ return Option.some({
96
+ ...window,
97
+ notes: held,
98
+ symbol: symbolOf(held)
99
+ });
100
+ };
101
+ const chordsOf = (song) => {
102
+ const notes = soundingsOf(song);
103
+ const beats = pipe(beatWindowsOf(song), Array.map(beatChordOf(notes)), Array.getSomes);
104
+ const at = positionOf(song);
105
+ return pipe(Array.reduce(beats, [], extend), Array.map((span) => ({
106
+ from: at(span.start),
107
+ to: at(span.end),
108
+ start: span.start,
109
+ end: span.end,
110
+ symbol: span.symbol,
111
+ notes: span.notes
112
+ })));
113
+ };
114
+ // src/features/analyze-song/model/keys.ts
115
+ const NONE$1 = 0;
116
+ const OCTAVE = 12;
117
+ const SQUARE = 2;
118
+ const ROUND = 1e3;
119
+ const UNKNOWN = "?";
120
+ const MAJOR_PROFILE = {
121
+ tonic: 6.35,
122
+ minorSecond: 2.23,
123
+ majorSecond: 3.48,
124
+ minorThird: 2.33,
125
+ majorThird: 4.38,
126
+ fourth: 4.09,
127
+ tritone: 2.52,
128
+ fifth: 5.19,
129
+ minorSixth: 2.39,
130
+ majorSixth: 3.66,
131
+ minorSeventh: 2.29,
132
+ majorSeventh: 2.88
133
+ };
134
+ const MINOR_PROFILE = {
135
+ tonic: 6.33,
136
+ minorSecond: 2.68,
137
+ majorSecond: 3.52,
138
+ minorThird: 5.38,
139
+ majorThird: 2.6,
140
+ fourth: 3.53,
141
+ tritone: 2.54,
142
+ fifth: 4.75,
143
+ minorSixth: 3.98,
144
+ majorSixth: 2.69,
145
+ minorSeventh: 3.34,
146
+ majorSeventh: 3.17
147
+ };
148
+ const MAJOR_TONICS = [
149
+ "C",
150
+ "Db",
151
+ "D",
152
+ "Eb",
153
+ "E",
154
+ "F",
155
+ "F#",
156
+ "G",
157
+ "Ab",
158
+ "A",
159
+ "Bb",
160
+ "B"
161
+ ];
162
+ const MINOR_TONICS = [
163
+ "C",
164
+ "C#",
165
+ "D",
166
+ "Eb",
167
+ "E",
168
+ "F",
169
+ "F#",
170
+ "G",
171
+ "G#",
172
+ "A",
173
+ "Bb",
174
+ "B"
175
+ ];
176
+ const ModeSchema = Schema.Literals(["major", "minor"]);
177
+ const barRangeFields = {
178
+ fromBar: Schema.Int,
179
+ toBar: Schema.Int
180
+ };
181
+ const BarRangeSchema = Schema.Struct(barRangeFields);
182
+ const KeySpanSchema = Schema.Struct({
183
+ ...barRangeFields,
184
+ tonic: Schema.String,
185
+ pitchClass: Schema.Int,
186
+ mode: ModeSchema,
187
+ correlation: Schema.Finite
188
+ });
189
+ const pitchClassOf = (midi) => (midi % OCTAVE + OCTAVE) % OCTAVE;
190
+ const addWeight = (window) => (weights, note) => {
191
+ const share = overlapOf(note)(window);
192
+ const pitchClass = pitchClassOf(note.midi);
193
+ return pipe(weights, Array.map((weight, index) => {
194
+ if (index === pitchClass) return weight + share;
195
+ return weight;
196
+ }));
197
+ };
198
+ const histogramOf = (window) => (notes) => Array.reduce(notes, Array.makeBy(OCTAVE, () => NONE$1), addWeight(window));
199
+ const add = (sum, value) => sum + value;
200
+ const sumOf = (values) => Array.reduce(values, NONE$1, add);
201
+ const meanOf = (values) => sumOf(values) / values.length;
202
+ const spreadOf = (values) => {
203
+ const center = meanOf(values);
204
+ const squares = pipe(values, Array.map((value) => (value - center) ** SQUARE));
205
+ return Math.sqrt(sumOf(squares));
206
+ };
207
+ const correlationOf = (profile) => (histogram) => {
208
+ const histogramMean = meanOf(histogram);
209
+ const profileMean = meanOf(profile);
210
+ const covariance = sumOf(pipe(Array.zip(histogram, profile), Array.map(([weight, expected]) => (weight - histogramMean) * (expected - profileMean))));
211
+ const scale = spreadOf(histogram) * spreadOf(profile);
212
+ if (scale === NONE$1) return NONE$1;
213
+ return covariance / scale;
214
+ };
215
+ const rotated = (tonic) => (profile) => {
216
+ const weights = Record.values(profile);
217
+ return Array.makeBy(OCTAVE, (index) => weights[(index - tonic + OCTAVE) % OCTAVE] ?? NONE$1);
218
+ };
219
+ const candidatesAt = (histogram) => (tonic) => [{
220
+ tonic: MAJOR_TONICS[tonic] ?? UNKNOWN,
221
+ pitchClass: tonic,
222
+ mode: "major",
223
+ correlation: correlationOf(rotated(tonic)(MAJOR_PROFILE))(histogram)
224
+ }, {
225
+ tonic: MINOR_TONICS[tonic] ?? UNKNOWN,
226
+ pitchClass: tonic,
227
+ mode: "minor",
228
+ correlation: correlationOf(rotated(tonic)(MINOR_PROFILE))(histogram)
229
+ }];
230
+ const byCorrelation = Order.flip(Order.mapInput(Order.Number, (candidate) => candidate.correlation));
231
+ const edgeOf = (song) => (index, end) => pipe(song.bars, Array.findFirst((bar) => bar.index === index), Option.match({
232
+ onNone: () => NONE$1,
233
+ onSome: (bar) => bar.start + Number(end) * bar.length
234
+ }));
235
+ const keyIn = (song) => (range) => {
236
+ const edge = edgeOf(song);
237
+ const histogram = histogramOf({
238
+ start: edge(range.fromBar, false),
239
+ end: edge(range.toBar, true)
240
+ })(soundingsOf(song));
241
+ if (pipe(histogram, Array.every((weight) => weight === NONE$1))) return Option.none();
242
+ const candidates = pipe(Array.range(NONE$1, 11), Array.flatMap(candidatesAt(histogram)));
243
+ return pipe(Array.sort(candidates, byCorrelation), Array.head, Option.map((best) => ({
244
+ fromBar: range.fromBar,
245
+ toBar: range.toBar,
246
+ tonic: best.tonic,
247
+ pitchClass: best.pitchClass,
248
+ mode: best.mode,
249
+ correlation: Math.round(best.correlation * ROUND) / ROUND
250
+ })));
251
+ };
252
+ // src/features/analyze-song/model/repeats.ts
253
+ const FIRST$1 = 1;
254
+ const SECOND = 2;
255
+ const fingerprintOf = (song) => (bar) => {
256
+ const notes = pipe(song.notes, Array.filter((note) => note.bar === bar), Array.map((note) => `${note.track}:${String(note.offset)}:${String(note.midi)}:${String(note.length)}`));
257
+ const hits = pipe(song.hits, Array.filter((hit) => hit.bar === bar), Array.map((hit) => `${hit.track}:${String(hit.offset)}:${hit.voice}`));
258
+ const slices = pipe(song.slices, Array.filter((slice) => slice.bar === bar), Array.map((slice) => `${slice.track}:${String(slice.offset)}:${slice.sample}:${String(slice.index)}`));
259
+ return pipe(Array.sort([
260
+ ...notes,
261
+ ...hits,
262
+ ...slices
263
+ ], Order.String), Array.join("|"));
264
+ };
265
+ const repeatOf = (prints) => (bar) => {
266
+ const print = prints[bar - FIRST$1] ?? "";
267
+ return print !== "" && print === prints[bar - SECOND];
268
+ };
269
+ const joinRun = (runs, bar) => Option.match(Array.last(runs), {
270
+ onNone: () => [{
271
+ fromBar: bar - FIRST$1,
272
+ toBar: bar
273
+ }],
274
+ onSome: (last) => {
275
+ if (last.toBar !== bar - FIRST$1) return [...runs, {
276
+ fromBar: bar - FIRST$1,
277
+ toBar: bar
278
+ }];
279
+ return [...Array.dropRight(runs, FIRST$1), {
280
+ ...last,
281
+ toBar: bar
282
+ }];
283
+ }
284
+ });
285
+ const repeatsOf = (song) => {
286
+ const bars = song.bars.length;
287
+ const prints = pipe(Array.range(FIRST$1, bars), Array.map(fingerprintOf(song)));
288
+ const repeated = pipe(Array.range(SECOND, bars), Array.filter(repeatOf(prints)));
289
+ return Array.reduce(repeated, [], joinRun);
290
+ };
291
+ // src/features/analyze-song/model/analysis.ts
292
+ const FIRST = 1;
293
+ const NONE = 0;
294
+ const PHRASE_BARS = 4;
295
+ const AnalysisSchema = Schema.Struct({
296
+ bars: Schema.Int,
297
+ key: Schema.OptionFromNullOr(KeySpanSchema),
298
+ keys: Schema.Array(KeySpanSchema),
299
+ chords: Schema.Array(ChordSpanSchema),
300
+ repeats: Schema.Array(BarRangeSchema)
301
+ });
302
+ const phrasesOf = (bars) => Array.makeBy(Math.ceil(bars / PHRASE_BARS), (phrase) => ({
303
+ fromBar: phrase * PHRASE_BARS + FIRST,
304
+ toBar: Math.min(bars, (phrase + FIRST) * PHRASE_BARS)
305
+ }));
306
+ const analyze = (song) => {
307
+ const bars = song.bars.length;
308
+ if (bars === NONE) return {
309
+ bars,
310
+ key: Option.none(),
311
+ keys: [],
312
+ chords: [],
313
+ repeats: []
314
+ };
315
+ return {
316
+ bars,
317
+ key: keyIn(song)({
318
+ fromBar: FIRST,
319
+ toBar: bars
320
+ }),
321
+ keys: pipe(phrasesOf(bars), Array.map(keyIn(song)), Array.getSomes),
322
+ chords: chordsOf(song),
323
+ repeats: repeatsOf(song)
324
+ };
325
+ };
326
+ export { AnalysisSchema, BarRangeSchema, ChordSpanSchema, KeySpanSchema, analyze, chordsOf, keyIn, overlapOf, positionOf, soundingsOf };
327
+
328
+ //# sourceMappingURL=analysis.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analysis.mjs","names":["NONE","FIRST","pitchClassOf","TonalNote","Str","Arr","FIRST","UNKNOWN","OCTAVE","Arr","NONE","Arr","FIRST","Arr","Arr"],"sources":["../src/features/analyze-song/model/sounding.ts","../src/features/analyze-song/model/chords.ts","../src/features/analyze-song/model/keys.ts","../src/features/analyze-song/model/repeats.ts","../src/features/analyze-song/model/analysis.ts"],"sourcesContent":["import { Array as Arr, Option, String as Str, pipe } from \"effect\";\nimport { Note as TonalNote } from \"tonal\";\n\nimport type { Note, Role, Song } from \"#/entities/song/index.ts\";\nimport { fractionOf } from \"#/shared/lib/ticks.ts\";\n\nconst NONE = 0;\nconst FIRST = 1;\n\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n\nexport interface Sounding extends Span {\n readonly track: string;\n readonly line: number;\n readonly column: number;\n readonly bar: number;\n readonly role: Option.Option<Role>;\n readonly midi: number;\n readonly spelling: string;\n readonly pitchClass: string;\n}\n\nconst CENTS = /[+-]\\d+c$/u;\n\nconst pitchClassOf = (note: Note): string => {\n const written = TonalNote.pitchClass(Str.replace(CENTS, \"\")(note.spelling));\n if (Str.isNonEmpty(written)) {\n return written;\n }\n return TonalNote.pitchClass(TonalNote.fromMidi(note.midi));\n};\n\nexport const overlapOf =\n (left: Span) =>\n (right: Span): number =>\n Math.max(NONE, Math.min(left.end, right.end) - Math.max(left.start, right.start));\n\nexport const soundingsOf = (song: Song): readonly Sounding[] => {\n const audible = pipe(\n song.tracks,\n Arr.filter((track) => !track.mixer.muted),\n );\n return pipe(\n song.notes,\n Arr.flatMap((note) =>\n pipe(\n audible,\n Arr.findFirst((track) => track.name === note.track),\n Option.map((track) => ({\n track: note.track,\n line: note.sourceLine,\n column: note.sourceColumn,\n bar: note.bar,\n role: track.role,\n midi: note.midi,\n spelling: note.spelling,\n pitchClass: pitchClassOf(note),\n start: note.start,\n end: note.start + Math.round(note.length * note.gate),\n })),\n Option.toArray,\n ),\n ),\n );\n};\n\nexport const positionOf =\n (song: Song) =>\n (tick: number): { readonly bar: number; readonly offset: string } =>\n pipe(\n song.bars,\n Arr.findLast((bar) => bar.start <= tick),\n Option.match({\n onNone: () => ({ bar: FIRST, offset: fractionOf(tick) }),\n onSome: (bar) => ({ bar: bar.index, offset: fractionOf(tick - bar.start) }),\n }),\n );\n","import { Array as Arr, Option, Order, Schema, pipe } from \"effect\";\nimport { Chord } from \"tonal\";\n\nimport type { Song } from \"#/entities/song/index.ts\";\nimport { TICKS_PER_WHOLE } from \"#/shared/lib/ticks.ts\";\n\nimport { overlapOf, positionOf, soundingsOf } from \"./sounding.ts\";\nimport type { Sounding, Span } from \"./sounding.ts\";\n\nconst FIRST = 1;\nconst HELD_SHARE = 0.25;\nconst UNKNOWN = \"?\";\n\nconst PositionSchema = Schema.Struct({ bar: Schema.Int, offset: Schema.String });\n\nexport const ChordSpanSchema = Schema.Struct({\n from: PositionSchema,\n to: PositionSchema,\n start: Schema.Int,\n end: Schema.Int,\n symbol: Schema.String,\n notes: Schema.Array(Schema.String),\n});\n\nexport type ChordSpan = typeof ChordSpanSchema.Type;\n\ninterface BeatChord extends Span {\n readonly symbol: string;\n readonly notes: readonly string[];\n}\n\nconst heldIn =\n (window: Span) =>\n (note: Sounding): boolean =>\n overlapOf(note)(window) >= (window.end - window.start) * HELD_SHARE;\n\nconst isHarmonic = (note: Sounding): boolean =>\n Option.exists(note.role, (role) => role === \"bass\" || role === \"harmony\");\n\nconst OCTAVE = 12;\n\nconst UNISON = 0;\n\nconst samePitchClass = (left: number, right: number): boolean => (left - right) % OCTAVE === UNISON;\n\nconst byMidi = Order.mapInput(Order.Number, (note: Sounding) => note.midi);\n\nconst harmonicOrAll = (held: readonly Sounding[]): readonly Sounding[] => {\n const harmonic = pipe(held, Arr.filter(isHarmonic));\n if (Arr.isReadonlyArrayNonEmpty(harmonic)) {\n return harmonic;\n }\n return held;\n};\n\nconst chordNotesIn =\n (notes: readonly Sounding[]) =>\n (window: Span): readonly string[] =>\n pipe(\n notes,\n Arr.filter(heldIn(window)),\n harmonicOrAll,\n (held) => Arr.sort(held, byMidi),\n Arr.dedupeWith((left, right) => samePitchClass(left.midi, right.midi)),\n Arr.map((note) => note.pitchClass),\n );\n\nconst spells =\n (notes: readonly string[]) =>\n (symbol: string): boolean => {\n const spelled = Chord.get(symbol).notes;\n return (\n spelled.length === notes.length &&\n pipe(\n spelled,\n Arr.every((note) => Arr.contains(notes, note)),\n )\n );\n };\n\nconst symbolOf = (notes: readonly string[]): string => {\n const candidates = Chord.detect(Arr.copy(notes));\n return pipe(\n candidates,\n Arr.findFirst(spells(notes)),\n Option.orElse(() => Arr.head(candidates)),\n Option.getOrElse(() => UNKNOWN),\n );\n};\n\nconst beatWindowsOf = (song: Song): readonly Span[] =>\n pipe(\n song.bars,\n Arr.flatMap((bar) => {\n const beat = TICKS_PER_WHOLE / bar.meter.denominator;\n return Arr.makeBy(bar.meter.numerator, (index) => ({\n start: bar.start + index * beat,\n end: bar.start + (index + FIRST) * beat,\n }));\n }),\n );\n\nconst extend = (spans: readonly BeatChord[], beat: BeatChord): readonly BeatChord[] =>\n Option.match(Arr.last(spans), {\n onNone: () => [beat],\n onSome: (last) => {\n if (last.symbol !== beat.symbol || last.end !== beat.start) {\n return [...spans, beat];\n }\n return [...Arr.dropRight(spans, FIRST), { ...last, end: beat.end }];\n },\n });\n\nconst beatChordOf =\n (notes: readonly Sounding[]) =>\n (window: Span): Option.Option<BeatChord> => {\n const held = chordNotesIn(notes)(window);\n if (!Arr.isReadonlyArrayNonEmpty(held)) {\n return Option.none();\n }\n return Option.some({ ...window, notes: held, symbol: symbolOf(held) });\n };\n\nexport const chordsOf = (song: Song): readonly ChordSpan[] => {\n const notes = soundingsOf(song);\n const beats = pipe(beatWindowsOf(song), Arr.map(beatChordOf(notes)), Arr.getSomes);\n const at = positionOf(song);\n return pipe(\n Arr.reduce(beats, [] as readonly BeatChord[], extend),\n Arr.map((span) => ({\n from: at(span.start),\n to: at(span.end),\n start: span.start,\n end: span.end,\n symbol: span.symbol,\n notes: span.notes,\n })),\n );\n};\n","import { Array as Arr, Option, Order, Record, Schema, pipe } from \"effect\";\n\nimport type { Song } from \"#/entities/song/index.ts\";\n\nimport { overlapOf, soundingsOf } from \"./sounding.ts\";\nimport type { Sounding, Span } from \"./sounding.ts\";\n\nconst FIRST = 1;\nconst NONE = 0;\nconst OCTAVE = 12;\nconst SQUARE = 2;\nconst ROUND = 1000;\nconst UNKNOWN = \"?\";\n\nconst MAJOR_PROFILE = {\n tonic: 6.35,\n minorSecond: 2.23,\n majorSecond: 3.48,\n minorThird: 2.33,\n majorThird: 4.38,\n fourth: 4.09,\n tritone: 2.52,\n fifth: 5.19,\n minorSixth: 2.39,\n majorSixth: 3.66,\n minorSeventh: 2.29,\n majorSeventh: 2.88,\n};\n\nconst MINOR_PROFILE = {\n tonic: 6.33,\n minorSecond: 2.68,\n majorSecond: 3.52,\n minorThird: 5.38,\n majorThird: 2.6,\n fourth: 3.53,\n tritone: 2.54,\n fifth: 4.75,\n minorSixth: 3.98,\n majorSixth: 2.69,\n minorSeventh: 3.34,\n majorSeventh: 3.17,\n};\n\nconst MAJOR_TONICS = [\"C\", \"Db\", \"D\", \"Eb\", \"E\", \"F\", \"F#\", \"G\", \"Ab\", \"A\", \"Bb\", \"B\"];\nconst MINOR_TONICS = [\"C\", \"C#\", \"D\", \"Eb\", \"E\", \"F\", \"F#\", \"G\", \"G#\", \"A\", \"Bb\", \"B\"];\n\nconst ModeSchema = Schema.Literals([\"major\", \"minor\"]);\n\ntype Mode = typeof ModeSchema.Type;\n\nconst barRangeFields = { fromBar: Schema.Int, toBar: Schema.Int };\n\nexport const BarRangeSchema = Schema.Struct(barRangeFields);\n\nexport type BarRange = typeof BarRangeSchema.Type;\n\nexport const KeySpanSchema = Schema.Struct({\n ...barRangeFields,\n tonic: Schema.String,\n pitchClass: Schema.Int,\n mode: ModeSchema,\n correlation: Schema.Finite,\n});\n\nexport type KeySpan = typeof KeySpanSchema.Type;\n\ninterface Candidate {\n readonly tonic: string;\n readonly pitchClass: number;\n readonly mode: Mode;\n readonly correlation: number;\n}\n\nconst pitchClassOf = (midi: number): number => ((midi % OCTAVE) + OCTAVE) % OCTAVE;\n\nconst addWeight =\n (window: Span) =>\n (weights: readonly number[], note: Sounding): readonly number[] => {\n const share = overlapOf(note)(window);\n const pitchClass = pitchClassOf(note.midi);\n return pipe(\n weights,\n Arr.map((weight, index) => {\n if (index === pitchClass) {\n return weight + share;\n }\n return weight;\n }),\n );\n };\n\nconst histogramOf =\n (window: Span) =>\n (notes: readonly Sounding[]): readonly number[] =>\n Arr.reduce(\n notes,\n Arr.makeBy(OCTAVE, () => NONE),\n addWeight(window),\n );\n\nconst add = (sum: number, value: number): number => sum + value;\n\nconst sumOf = (values: readonly number[]): number => Arr.reduce(values, NONE, add);\n\nconst meanOf = (values: readonly number[]): number => sumOf(values) / values.length;\n\nconst spreadOf = (values: readonly number[]): number => {\n const center = meanOf(values);\n const squares = pipe(\n values,\n Arr.map((value) => (value - center) ** SQUARE),\n );\n return Math.sqrt(sumOf(squares));\n};\n\nconst correlationOf =\n (profile: readonly number[]) =>\n (histogram: readonly number[]): number => {\n const histogramMean = meanOf(histogram);\n const profileMean = meanOf(profile);\n const covariance = sumOf(\n pipe(\n Arr.zip(histogram, profile),\n Arr.map(([weight, expected]) => (weight - histogramMean) * (expected - profileMean)),\n ),\n );\n const scale = spreadOf(histogram) * spreadOf(profile);\n if (scale === NONE) {\n return NONE;\n }\n return covariance / scale;\n };\n\nconst rotated =\n (tonic: number) =>\n (profile: Readonly<Record<string, number>>): readonly number[] => {\n const weights = Record.values(profile);\n return Arr.makeBy(OCTAVE, (index) => weights[(index - tonic + OCTAVE) % OCTAVE] ?? NONE);\n };\n\nconst candidatesAt =\n (histogram: readonly number[]) =>\n (tonic: number): readonly Candidate[] => [\n {\n tonic: MAJOR_TONICS[tonic] ?? UNKNOWN,\n pitchClass: tonic,\n mode: \"major\",\n correlation: correlationOf(rotated(tonic)(MAJOR_PROFILE))(histogram),\n },\n {\n tonic: MINOR_TONICS[tonic] ?? UNKNOWN,\n pitchClass: tonic,\n mode: \"minor\",\n correlation: correlationOf(rotated(tonic)(MINOR_PROFILE))(histogram),\n },\n ];\n\nconst byCorrelation = Order.flip(\n Order.mapInput(Order.Number, (candidate: Candidate) => candidate.correlation),\n);\n\nconst edgeOf =\n (song: Song) =>\n (index: number, end: boolean): number =>\n pipe(\n song.bars,\n Arr.findFirst((bar) => bar.index === index),\n Option.match({\n onNone: () => NONE,\n onSome: (bar) => bar.start + Number(end) * bar.length,\n }),\n );\n\nexport const keyIn =\n (song: Song) =>\n (range: BarRange): Option.Option<KeySpan> => {\n const edge = edgeOf(song);\n const histogram = histogramOf({\n start: edge(range.fromBar, false),\n end: edge(range.toBar, true),\n })(soundingsOf(song));\n const silent = pipe(\n histogram,\n Arr.every((weight) => weight === NONE),\n );\n if (silent) {\n return Option.none();\n }\n const candidates = pipe(Arr.range(NONE, OCTAVE - FIRST), Arr.flatMap(candidatesAt(histogram)));\n return pipe(\n Arr.sort(candidates, byCorrelation),\n Arr.head,\n Option.map((best) => ({\n fromBar: range.fromBar,\n toBar: range.toBar,\n tonic: best.tonic,\n pitchClass: best.pitchClass,\n mode: best.mode,\n correlation: Math.round(best.correlation * ROUND) / ROUND,\n })),\n );\n };\n","import { Array as Arr, Option, Order, pipe } from \"effect\";\n\nimport type { Song } from \"#/entities/song/index.ts\";\n\nimport type { BarRange } from \"./keys.ts\";\n\nconst FIRST = 1;\nconst SECOND = 2;\n\nconst fingerprintOf =\n (song: Song) =>\n (bar: number): string => {\n const notes = pipe(\n song.notes,\n Arr.filter((note) => note.bar === bar),\n Arr.map(\n (note) =>\n `${note.track}:${String(note.offset)}:${String(note.midi)}:${String(note.length)}`,\n ),\n );\n const hits = pipe(\n song.hits,\n Arr.filter((hit) => hit.bar === bar),\n Arr.map((hit) => `${hit.track}:${String(hit.offset)}:${hit.voice}`),\n );\n const slices = pipe(\n song.slices,\n Arr.filter((slice) => slice.bar === bar),\n Arr.map(\n (slice) => `${slice.track}:${String(slice.offset)}:${slice.sample}:${String(slice.index)}`,\n ),\n );\n return pipe(Arr.sort([...notes, ...hits, ...slices], Order.String), Arr.join(\"|\"));\n };\n\nconst repeatOf =\n (prints: readonly string[]) =>\n (bar: number): boolean => {\n const print = prints[bar - FIRST] ?? \"\";\n return print !== \"\" && print === prints[bar - SECOND];\n };\n\nconst joinRun = (runs: readonly BarRange[], bar: number): readonly BarRange[] =>\n Option.match(Arr.last(runs), {\n onNone: () => [{ fromBar: bar - FIRST, toBar: bar }],\n onSome: (last) => {\n if (last.toBar !== bar - FIRST) {\n return [...runs, { fromBar: bar - FIRST, toBar: bar }];\n }\n return [...Arr.dropRight(runs, FIRST), { ...last, toBar: bar }];\n },\n });\n\nexport const repeatsOf = (song: Song): readonly BarRange[] => {\n const bars = song.bars.length;\n const prints = pipe(Arr.range(FIRST, bars), Arr.map(fingerprintOf(song)));\n const repeated = pipe(Arr.range(SECOND, bars), Arr.filter(repeatOf(prints)));\n return Arr.reduce(repeated, [] as readonly BarRange[], joinRun);\n};\n","import { Array as Arr, Option, Schema, pipe } from \"effect\";\n\nimport type { Song } from \"#/entities/song/index.ts\";\n\nimport { ChordSpanSchema, chordsOf } from \"./chords.ts\";\nimport { BarRangeSchema, KeySpanSchema, keyIn } from \"./keys.ts\";\nimport type { BarRange } from \"./keys.ts\";\nimport { repeatsOf } from \"./repeats.ts\";\n\nconst FIRST = 1;\nconst NONE = 0;\nconst PHRASE_BARS = 4;\n\nexport const AnalysisSchema = Schema.Struct({\n bars: Schema.Int,\n key: Schema.OptionFromNullOr(KeySpanSchema),\n keys: Schema.Array(KeySpanSchema),\n chords: Schema.Array(ChordSpanSchema),\n repeats: Schema.Array(BarRangeSchema),\n});\n\nexport type Analysis = typeof AnalysisSchema.Type;\n\nconst phrasesOf = (bars: number): readonly BarRange[] =>\n Arr.makeBy(Math.ceil(bars / PHRASE_BARS), (phrase) => ({\n fromBar: phrase * PHRASE_BARS + FIRST,\n toBar: Math.min(bars, (phrase + FIRST) * PHRASE_BARS),\n }));\n\nexport const analyze = (song: Song): Analysis => {\n const bars = song.bars.length;\n if (bars === NONE) {\n return { bars, key: Option.none(), keys: [], chords: [], repeats: [] };\n }\n return {\n bars,\n key: keyIn(song)({ fromBar: FIRST, toBar: bars }),\n keys: pipe(phrasesOf(bars), Arr.map(keyIn(song)), Arr.getSomes),\n chords: chordsOf(song),\n repeats: repeatsOf(song),\n };\n};\n"],"mappings":";;;;AAMA,MAAMA,SAAO;AACb,MAAMC,UAAQ;AAkBd,MAAM,QAAQ;AAEd,MAAMC,kBAAgB,SAAuB;CAC3C,MAAM,UAAUC,KAAU,WAAWC,SAAI,QAAQ,OAAO,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC;CAC1E,IAAIA,SAAI,WAAW,OAAO,GACxB,OAAO;CAET,OAAOD,KAAU,WAAWA,KAAU,SAAS,KAAK,IAAI,CAAC;AAC3D;AAEA,MAAa,aACV,UACA,UACC,KAAK,IAAIH,QAAM,KAAK,IAAI,KAAK,KAAK,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK,OAAO,MAAM,KAAK,CAAC;AAEpF,MAAa,eAAe,SAAoC;CAC9D,MAAM,UAAU,KACd,KAAK,QACLK,MAAI,QAAQ,UAAU,CAAC,MAAM,MAAM,KAAK,CAC1C;CACA,OAAO,KACL,KAAK,OACLA,MAAI,SAAS,SACX,KACE,SACAA,MAAI,WAAW,UAAU,MAAM,SAAS,KAAK,KAAK,GAClD,OAAO,KAAK,WAAW;EACrB,OAAO,KAAK;EACZ,MAAM,KAAK;EACX,QAAQ,KAAK;EACb,KAAK,KAAK;EACV,MAAM,MAAM;EACZ,MAAM,KAAK;EACX,UAAU,KAAK;EACf,YAAYH,eAAa,IAAI;EA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B;AACF"}
@@ -0,0 +1,18 @@
1
+ import { t as Written } from "./index-Cup9xTad.mjs";
2
+ import { Effect, Schema } from "effect";
3
+ declare const UnreadableAls_base: Schema.Class<UnreadableAls, Schema.TaggedStruct<"UnreadableAls", {
4
+ readonly message: Schema.String;
5
+ }>, import("effect/Cause").YieldableError & {
6
+ readonly brand: unique symbol;
7
+ }>;
8
+ export declare class UnreadableAls extends UnreadableAls_base {}
9
+ interface LiveSetFile {
10
+ readonly bytes: Uint8Array;
11
+ readonly title: string;
12
+ }
13
+ interface Fumx extends Written {
14
+ readonly offGrid: number;
15
+ }
16
+ export declare const alsToFumx: (input: LiveSetFile) => Effect.Effect<Fumx, UnreadableAls, never>;
17
+ export type { Fumx, LiveSetFile };
18
+ //# sourceMappingURL=convert-als.d.mts.map