@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.
- package/README.md +33 -1
- package/dist/als-to-fumx.mjs +525 -0
- package/dist/als-to-fumx.mjs.map +1 -0
- package/dist/analysis.d.mts +95 -0
- package/dist/analysis.mjs +328 -0
- package/dist/analysis.mjs.map +1 -0
- package/dist/convert-als.d.mts +18 -0
- package/dist/convert-als.mjs +512 -0
- package/dist/convert-als.mjs.map +1 -0
- package/dist/convert-midi.d.mts +2 -75
- package/dist/convert-midi.mjs +5 -650
- package/dist/convert-midi.mjs.map +1 -1
- package/dist/fumx-language-server.mjs +1 -1
- package/dist/fumx-language-server.mjs.map +1 -1
- package/dist/fumx-module-CqxUe07y.mjs +12485 -0
- package/dist/fumx-module-CqxUe07y.mjs.map +1 -0
- package/dist/fumx-module-CtXvLKU1.mjs +2632 -0
- package/dist/fumx-module-CtXvLKU1.mjs.map +1 -0
- package/dist/grammar-86_uhiTo.mjs +9836 -0
- package/dist/grammar-86_uhiTo.mjs.map +1 -0
- package/dist/index-Cup9xTad.d.mts +105 -0
- package/dist/index-DPt8MZ6e.d.mts +796 -0
- package/dist/index-JXjnMHXw.d.mts +1350 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +4 -0
- package/dist/language.d.mts +13 -0
- package/dist/language.mjs +3 -0
- package/dist/mapper.mjs +1 -1
- package/dist/midi-to-fumx.mjs +12 -854
- package/dist/midi-to-fumx.mjs.map +1 -1
- package/dist/read-song-BzqX5MuZ.mjs +122 -0
- package/dist/read-song-BzqX5MuZ.mjs.map +1 -0
- package/dist/read-song-CzMPm8u8.mjs +123 -0
- package/dist/read-song-CzMPm8u8.mjs.map +1 -0
- package/dist/round-trip-Cz8iQlpW.mjs +946 -0
- package/dist/round-trip-Cz8iQlpW.mjs.map +1 -0
- package/dist/run-main-Bf32CgzU.mjs +26 -0
- package/dist/run-main-Bf32CgzU.mjs.map +1 -0
- package/dist/song-3Zm9g84K.d.mts +1478 -0
- package/dist/song-CYFBSTbH.mjs +387 -0
- package/dist/song-CYFBSTbH.mjs.map +1 -0
- package/dist/song-report.mjs +327 -4
- package/dist/song-report.mjs.map +1 -1
- package/dist/ticks-CXehHP2w.mjs +27 -0
- package/dist/ticks-CXehHP2w.mjs.map +1 -0
- package/dist/{transform-C24h3upp.mjs → transform-BoSDqqPW.mjs} +4 -3
- package/dist/transform-BoSDqqPW.mjs.map +1 -0
- package/dist/vite.mjs +4 -3
- package/dist/vite.mjs.map +1 -1
- package/dist/write-CuDbIkpM.mjs +747 -0
- package/dist/write-CuDbIkpM.mjs.map +1 -0
- package/package.json +49 -12
- package/skills/read-fumx/SKILL.md +85 -0
- package/skills/use-fumx-tools/SKILL.md +1 -2
- package/dist/app-CdpGdiWq.mjs +0 -190
- package/dist/app-CdpGdiWq.mjs.map +0 -1
- package/dist/transform-C24h3upp.mjs.map +0 -1
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import { a as microsecondsOf, i as sortedNotes, r as sortedByTick, t as writeFumx } from "./write-CuDbIkpM.mjs";
|
|
2
|
+
import { t as MIXER_PARAMETERS } from "./song-CYFBSTbH.mjs";
|
|
3
|
+
import { t as TICKS_PER_WHOLE } from "./ticks-CXehHP2w.mjs";
|
|
4
|
+
import { Array, Boolean, Effect, Option, Order, Record, Schema, pipe } from "effect";
|
|
5
|
+
import { XMLParser } from "fast-xml-parser";
|
|
6
|
+
import { decodeTimeSignatureId } from "ableton-als";
|
|
7
|
+
// src/features/convert-als/model/live-set.ts
|
|
8
|
+
const taggedError = Schema.TaggedError;
|
|
9
|
+
var UnreadableAls = class extends taggedError()("UnreadableAls", { message: Schema.String }, { identifier: "UnreadableAls" }) {};
|
|
10
|
+
const REPEATED = /* @__PURE__ */ new Set([
|
|
11
|
+
"MidiTrack",
|
|
12
|
+
"AudioTrack",
|
|
13
|
+
"GroupTrack",
|
|
14
|
+
"ReturnTrack",
|
|
15
|
+
"MidiClip",
|
|
16
|
+
"AudioClip",
|
|
17
|
+
"KeyTrack",
|
|
18
|
+
"MidiNoteEvent",
|
|
19
|
+
"Locator",
|
|
20
|
+
"AutomationEnvelope",
|
|
21
|
+
"FloatEvent",
|
|
22
|
+
"EnumEvent",
|
|
23
|
+
"BoolEvent",
|
|
24
|
+
"TrackSendHolder"
|
|
25
|
+
]);
|
|
26
|
+
const ATTRIBUTES = "@";
|
|
27
|
+
const parser = new XMLParser({
|
|
28
|
+
ignoreAttributes: false,
|
|
29
|
+
attributeNamePrefix: "",
|
|
30
|
+
attributesGroupName: ATTRIBUTES,
|
|
31
|
+
parseTagValue: false,
|
|
32
|
+
parseAttributeValue: false,
|
|
33
|
+
jPath: false,
|
|
34
|
+
isArray: (name) => REPEATED.has(name)
|
|
35
|
+
});
|
|
36
|
+
const Num = Schema.Struct({ Value: Schema.FiniteFromString });
|
|
37
|
+
const Text = Schema.Struct({ Value: Schema.String });
|
|
38
|
+
const Flag = Schema.Struct({ Value: Schema.Literals(["true", "false"]) });
|
|
39
|
+
const EventSchema = Schema.Struct({
|
|
40
|
+
Time: Schema.FiniteFromString,
|
|
41
|
+
Value: Schema.String
|
|
42
|
+
});
|
|
43
|
+
const EventsSchema = Schema.Struct({
|
|
44
|
+
FloatEvent: EventSchema.pipe(Schema.Array, Schema.optionalKey),
|
|
45
|
+
EnumEvent: EventSchema.pipe(Schema.Array, Schema.optionalKey),
|
|
46
|
+
BoolEvent: EventSchema.pipe(Schema.Array, Schema.optionalKey)
|
|
47
|
+
});
|
|
48
|
+
const EnvelopeSchema = Schema.Struct({
|
|
49
|
+
EnvelopeTarget: Schema.Struct({ PointeeId: Num }),
|
|
50
|
+
Automation: Schema.Struct({ Events: EventsSchema })
|
|
51
|
+
});
|
|
52
|
+
const EnvelopeListSchema = Schema.Struct({ AutomationEnvelope: EnvelopeSchema.pipe(Schema.Array, Schema.optionalKey) });
|
|
53
|
+
const EnvelopesSchema = Schema.Struct({ Envelopes: EnvelopeListSchema });
|
|
54
|
+
const TargetSchema = Schema.Struct({ Id: Schema.FiniteFromString });
|
|
55
|
+
const ParameterSchema = Schema.Struct({
|
|
56
|
+
Manual: Schema.optionalKey(Num),
|
|
57
|
+
AutomationTarget: Schema.optionalKey(TargetSchema),
|
|
58
|
+
ArrangerAutomation: Schema.optionalKey(Schema.Struct({ Events: EventsSchema }))
|
|
59
|
+
});
|
|
60
|
+
const NoteSchema = Schema.Struct({
|
|
61
|
+
Time: Schema.FiniteFromString,
|
|
62
|
+
Duration: Schema.FiniteFromString,
|
|
63
|
+
Velocity: Schema.FiniteFromString,
|
|
64
|
+
OffVelocity: Schema.optionalKey(Schema.FiniteFromString),
|
|
65
|
+
IsEnabled: Schema.optionalKey(Schema.Literals(["true", "false"])),
|
|
66
|
+
Probability: Schema.optionalKey(Schema.FiniteFromString),
|
|
67
|
+
VelocityDeviation: Schema.optionalKey(Schema.FiniteFromString)
|
|
68
|
+
});
|
|
69
|
+
const NoteListSchema = Schema.Struct({ MidiNoteEvent: NoteSchema.pipe(Schema.Array, Schema.optionalKey) });
|
|
70
|
+
const KeyTrackSchema = Schema.Struct({
|
|
71
|
+
Notes: NoteListSchema,
|
|
72
|
+
MidiKey: Num
|
|
73
|
+
});
|
|
74
|
+
const LoopSchema = Schema.Struct({
|
|
75
|
+
LoopStart: Num,
|
|
76
|
+
LoopEnd: Num,
|
|
77
|
+
StartRelative: Num,
|
|
78
|
+
LoopOn: Flag
|
|
79
|
+
});
|
|
80
|
+
const KeyTracksSchema = Schema.Struct({ KeyTrack: KeyTrackSchema.pipe(Schema.Array, Schema.optionalKey) });
|
|
81
|
+
const ClipSchema = Schema.Struct({
|
|
82
|
+
CurrentStart: Num,
|
|
83
|
+
CurrentEnd: Num,
|
|
84
|
+
Loop: LoopSchema,
|
|
85
|
+
Disabled: Schema.optionalKey(Flag),
|
|
86
|
+
Notes: Schema.Struct({ KeyTracks: KeyTracksSchema })
|
|
87
|
+
});
|
|
88
|
+
const NameSchema = Schema.Struct({
|
|
89
|
+
EffectiveName: Schema.optionalKey(Text),
|
|
90
|
+
UserName: Schema.optionalKey(Text)
|
|
91
|
+
});
|
|
92
|
+
const DrumsSchema = Schema.Struct({ DrumGroupDevice: Schema.optionalKey(Schema.Unknown) });
|
|
93
|
+
const DevicesSchema = Schema.Struct({ Devices: Schema.optionalKey(DrumsSchema) });
|
|
94
|
+
const ClipEventsSchema = Schema.Struct({ MidiClip: ClipSchema.pipe(Schema.Array, Schema.optionalKey) });
|
|
95
|
+
const ArrangementSchema = Schema.Struct({ ArrangerAutomation: Schema.Struct({ Events: ClipEventsSchema }) });
|
|
96
|
+
const SendHolderSchema = Schema.Struct({ Send: ParameterSchema });
|
|
97
|
+
const SendsSchema = Schema.Struct({ TrackSendHolder: SendHolderSchema.pipe(Schema.Array, Schema.optionalKey) });
|
|
98
|
+
const SpeakerSchema = Schema.Struct({ Manual: Schema.optionalKey(Flag) });
|
|
99
|
+
const TrackMixerSchema = Schema.Struct({
|
|
100
|
+
Volume: ParameterSchema,
|
|
101
|
+
Pan: ParameterSchema,
|
|
102
|
+
Speaker: Schema.optionalKey(SpeakerSchema),
|
|
103
|
+
Sends: Schema.optionalKey(SendsSchema)
|
|
104
|
+
});
|
|
105
|
+
const TrackChainSchema = Schema.Struct({
|
|
106
|
+
DeviceChain: Schema.optionalKey(DevicesSchema),
|
|
107
|
+
Mixer: Schema.optionalKey(TrackMixerSchema),
|
|
108
|
+
MainSequencer: Schema.Struct({ ClipTimeable: ArrangementSchema })
|
|
109
|
+
});
|
|
110
|
+
const MidiTrackSchema = Schema.Struct({
|
|
111
|
+
Id: Schema.String,
|
|
112
|
+
Name: NameSchema,
|
|
113
|
+
AutomationEnvelopes: Schema.optionalKey(EnvelopesSchema),
|
|
114
|
+
DeviceChain: TrackChainSchema
|
|
115
|
+
});
|
|
116
|
+
const ReturnTrackSchema = Schema.Struct({
|
|
117
|
+
Name: NameSchema,
|
|
118
|
+
DeviceChain: Schema.Struct({ Mixer: Schema.optionalKey(TrackMixerSchema) })
|
|
119
|
+
});
|
|
120
|
+
const MixerSchema = Schema.Struct({
|
|
121
|
+
Tempo: ParameterSchema,
|
|
122
|
+
TimeSignature: ParameterSchema
|
|
123
|
+
});
|
|
124
|
+
const MasterSchema = Schema.Struct({
|
|
125
|
+
AutomationEnvelopes: Schema.optionalKey(EnvelopesSchema),
|
|
126
|
+
DeviceChain: Schema.optionalKey(Schema.Struct({ Mixer: MixerSchema })),
|
|
127
|
+
MasterChain: Schema.optionalKey(Schema.Struct({ Mixer: MixerSchema }))
|
|
128
|
+
});
|
|
129
|
+
const LocatorSchema = Schema.Struct({
|
|
130
|
+
Time: Num,
|
|
131
|
+
Name: Text
|
|
132
|
+
});
|
|
133
|
+
const TracksSchema = Schema.Struct({
|
|
134
|
+
MidiTrack: MidiTrackSchema.pipe(Schema.Array, Schema.optionalKey),
|
|
135
|
+
ReturnTrack: ReturnTrackSchema.pipe(Schema.Array, Schema.optionalKey)
|
|
136
|
+
});
|
|
137
|
+
const LocatorListSchema = Schema.Struct({ Locator: LocatorSchema.pipe(Schema.Array, Schema.optionalKey) });
|
|
138
|
+
const LiveSetSchema = Schema.Struct({
|
|
139
|
+
Tracks: TracksSchema,
|
|
140
|
+
MasterTrack: Schema.optionalKey(MasterSchema),
|
|
141
|
+
MainTrack: Schema.optionalKey(MasterSchema),
|
|
142
|
+
Locators: Schema.optionalKey(Schema.Struct({ Locators: LocatorListSchema }))
|
|
143
|
+
});
|
|
144
|
+
const DocumentSchema = Schema.Struct({ Ableton: Schema.Struct({
|
|
145
|
+
MajorVersion: Schema.String,
|
|
146
|
+
MinorVersion: Schema.String,
|
|
147
|
+
Creator: Schema.optionalKey(Schema.String),
|
|
148
|
+
LiveSet: LiveSetSchema
|
|
149
|
+
}) });
|
|
150
|
+
const decodeDocument = Schema.decodeUnknownEffect(DocumentSchema);
|
|
151
|
+
const isElement = Schema.is(Schema.Record(Schema.String, Schema.Unknown));
|
|
152
|
+
const isAttributes = Schema.is(Schema.Record(Schema.String, Schema.String));
|
|
153
|
+
const flattened = (node) => {
|
|
154
|
+
if (node === "") return {};
|
|
155
|
+
if (Array.isArray(node)) return pipe(node, Array.map((child) => flattened(child)));
|
|
156
|
+
if (isElement(node)) {
|
|
157
|
+
const { [ATTRIBUTES]: attributes, ...children } = node;
|
|
158
|
+
const own = pipe(Option.liftPredicate(attributes, isAttributes), Option.getOrElse(() => ({})));
|
|
159
|
+
return {
|
|
160
|
+
...pipe(children, Record.map((child) => flattened(child))),
|
|
161
|
+
...own
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return node;
|
|
165
|
+
};
|
|
166
|
+
const gunzip = (bytes) => Effect.tryPromise({
|
|
167
|
+
try: () => new Response(new Blob([Uint8Array.from(bytes)]).stream().pipeThrough(new DecompressionStream("gzip"))).text(),
|
|
168
|
+
catch: (cause) => UnreadableAls.make({ message: `Not a gzipped Live Set: ${String(cause)}` })
|
|
169
|
+
});
|
|
170
|
+
const readAlsDocument = Effect.fn("readAlsDocument")(function* read(bytes) {
|
|
171
|
+
const xml = yield* gunzip(bytes);
|
|
172
|
+
const parsed = yield* Effect.try({
|
|
173
|
+
try: () => flattened(parser.parse(xml)),
|
|
174
|
+
catch: (cause) => UnreadableAls.make({ message: `Not XML: ${String(cause)}` })
|
|
175
|
+
});
|
|
176
|
+
return yield* decodeDocument(parsed).pipe(Effect.mapError((issue) => UnreadableAls.make({ message: `Not a Live Set this converter reads: ${String(issue)}` })));
|
|
177
|
+
});
|
|
178
|
+
// src/features/convert-als/model/clips.ts
|
|
179
|
+
const NONE$2 = 0;
|
|
180
|
+
const DEFAULT_RELEASE = 64;
|
|
181
|
+
const modulo = (value, size) => (value % size + size) % size;
|
|
182
|
+
const passesOf = (clip) => {
|
|
183
|
+
const start = clip.CurrentStart.Value;
|
|
184
|
+
const length = clip.CurrentEnd.Value - start;
|
|
185
|
+
const loopStart = clip.Loop.LoopStart.Value;
|
|
186
|
+
const loopLength = clip.Loop.LoopEnd.Value - loopStart;
|
|
187
|
+
if (clip.Loop.LoopOn.Value === "false" || loopLength <= NONE$2) return [{
|
|
188
|
+
at: start,
|
|
189
|
+
from: loopStart,
|
|
190
|
+
to: loopStart + length
|
|
191
|
+
}];
|
|
192
|
+
const first = loopStart + modulo(clip.Loop.StartRelative.Value, loopLength);
|
|
193
|
+
const walk = (elapsed, from, passes) => {
|
|
194
|
+
if (elapsed >= length) return passes;
|
|
195
|
+
const span = Math.min(clip.Loop.LoopEnd.Value - from, length - elapsed);
|
|
196
|
+
return walk(elapsed + span, loopStart, [...passes, {
|
|
197
|
+
at: start + elapsed,
|
|
198
|
+
from,
|
|
199
|
+
to: from + span
|
|
200
|
+
}]);
|
|
201
|
+
};
|
|
202
|
+
return walk(NONE$2, first, []);
|
|
203
|
+
};
|
|
204
|
+
const releaseOf = (offVelocity) => pipe(Option.fromUndefinedOr(offVelocity), Option.filter((off) => off !== NONE$2), Option.match({
|
|
205
|
+
onNone: () => DEFAULT_RELEASE,
|
|
206
|
+
onSome: Math.round
|
|
207
|
+
}));
|
|
208
|
+
const sourceNotesOf = (clip) => pipe(clip.Notes.KeyTracks.KeyTrack ?? [], Array.flatMap((keyTrack) => pipe(keyTrack.Notes.MidiNoteEvent ?? [], Array.filter((note) => note.IsEnabled !== "false"), Array.map((note) => ({
|
|
209
|
+
time: note.Time,
|
|
210
|
+
end: note.Time + note.Duration,
|
|
211
|
+
midi: keyTrack.MidiKey.Value,
|
|
212
|
+
velocity: Math.round(note.Velocity),
|
|
213
|
+
release: releaseOf(note.OffVelocity)
|
|
214
|
+
})))));
|
|
215
|
+
const inPass = (notes) => (pass) => pipe(notes, Array.filter((note) => note.time >= pass.from && note.time < pass.to), Array.map((note) => ({
|
|
216
|
+
beat: pass.at + note.time - pass.from,
|
|
217
|
+
length: Math.min(note.end, pass.to) - note.time,
|
|
218
|
+
midi: note.midi,
|
|
219
|
+
velocity: note.velocity,
|
|
220
|
+
release: note.release
|
|
221
|
+
})));
|
|
222
|
+
const byStartThenPitch = Order.combine(Order.mapInput(Order.Number, (note) => note.beat), Order.mapInput(Order.Number, (note) => note.midi));
|
|
223
|
+
const isDisabled = (clip) => Option.exists(Option.fromUndefinedOr(clip.Disabled), (flag) => flag.Value === "true");
|
|
224
|
+
const notesOfClip = (clip) => {
|
|
225
|
+
if (isDisabled(clip)) return [];
|
|
226
|
+
const notes = sourceNotesOf(clip);
|
|
227
|
+
return pipe(passesOf(clip), Array.flatMap(inPass(notes)), Array.sortBy(byStartThenPitch));
|
|
228
|
+
};
|
|
229
|
+
const masterOf = (liveSet) => Option.orElse(Option.fromUndefinedOr(liveSet.MasterTrack), () => Option.fromUndefinedOr(liveSet.MainTrack));
|
|
230
|
+
const mixerOf = (master) => pipe(Option.fromUndefinedOr(master.DeviceChain), Option.orElse(() => Option.fromUndefinedOr(master.MasterChain)), Option.map((chain) => chain.Mixer));
|
|
231
|
+
const eventsOf = (events) => [
|
|
232
|
+
...events.FloatEvent ?? [],
|
|
233
|
+
...events.EnumEvent ?? [],
|
|
234
|
+
...events.BoolEvent ?? []
|
|
235
|
+
];
|
|
236
|
+
const automationEnvelopesOf = (owner) => pipe(Option.fromUndefinedOr(owner.AutomationEnvelopes), Option.flatMap((envelopes) => Option.fromUndefinedOr(envelopes.Envelopes.AutomationEnvelope)), Option.getOrElse(() => []));
|
|
237
|
+
const byTime = Order.mapInput(Order.Number, (event) => event.Time);
|
|
238
|
+
const envelopeOf = (owner) => (parameter) => {
|
|
239
|
+
const inline = pipe(Option.fromUndefinedOr(parameter.ArrangerAutomation), Option.map((automation) => automation.Events));
|
|
240
|
+
const pointed = pipe(Option.fromUndefinedOr(parameter.AutomationTarget), Option.flatMap((target) => pipe(automationEnvelopesOf(owner), Array.findFirst((envelope) => envelope.EnvelopeTarget.PointeeId.Value === target.Id))), Option.map((envelope) => envelope.Automation.Events));
|
|
241
|
+
return pipe(Option.orElse(pointed, () => inline), Option.map(eventsOf), Option.getOrElse(() => []), Array.sortBy(byTime));
|
|
242
|
+
};
|
|
243
|
+
const SINGLE = 1;
|
|
244
|
+
const NEXT$2 = 1;
|
|
245
|
+
const automationOf = (select) => (liveSet) => pipe(masterOf(liveSet), Option.flatMap((master) => pipe(mixerOf(master), Option.map((mixer) => {
|
|
246
|
+
const parameter = select(mixer);
|
|
247
|
+
return {
|
|
248
|
+
events: envelopeOf(master)(parameter),
|
|
249
|
+
manual: pipe(Option.fromUndefinedOr(parameter.Manual), Option.map((manual) => manual.Value))
|
|
250
|
+
};
|
|
251
|
+
}))));
|
|
252
|
+
const tempoAutomationOf = automationOf((mixer) => mixer.Tempo);
|
|
253
|
+
const pointsOf$1 = (events) => pipe(events, Array.map((event) => ({
|
|
254
|
+
beat: event.Time,
|
|
255
|
+
value: Number(event.Value)
|
|
256
|
+
})));
|
|
257
|
+
const tempoFrom = (resolve) => (liveSet) => pipe(tempoAutomationOf(liveSet), Option.map(resolve), Option.getOrElse(() => []));
|
|
258
|
+
const tempoEnvelopeOf = tempoFrom(({ events }) => pointsOf$1(events));
|
|
259
|
+
const manualPointsOf = tempoFrom(({ manual }) => pipe(manual, Option.map((value) => [{
|
|
260
|
+
beat: 0,
|
|
261
|
+
value
|
|
262
|
+
}]), Option.getOrElse(() => [])));
|
|
263
|
+
const tempoPointsOf = (liveSet) => {
|
|
264
|
+
const envelope = tempoEnvelopeOf(liveSet);
|
|
265
|
+
const manual = manualPointsOf(liveSet);
|
|
266
|
+
if (envelope.length > SINGLE || !Array.isReadonlyArrayNonEmpty(manual)) return envelope;
|
|
267
|
+
return manual;
|
|
268
|
+
};
|
|
269
|
+
const valueAt = (from, to) => (beat) => {
|
|
270
|
+
if (to.beat === from.beat) return to.value;
|
|
271
|
+
return from.value + (to.value - from.value) * (beat - from.beat) / (to.beat - from.beat);
|
|
272
|
+
};
|
|
273
|
+
const segmentOf = (from, next) => {
|
|
274
|
+
const start = Math.max(from.beat, 0);
|
|
275
|
+
return Option.match(next, {
|
|
276
|
+
onNone: () => ({
|
|
277
|
+
beat: start,
|
|
278
|
+
bpm: from.value,
|
|
279
|
+
target: Option.none()
|
|
280
|
+
}),
|
|
281
|
+
onSome: (to) => {
|
|
282
|
+
const bpm = valueAt(from, to)(start);
|
|
283
|
+
if (to.beat <= start || to.value === bpm) return {
|
|
284
|
+
beat: start,
|
|
285
|
+
bpm,
|
|
286
|
+
target: Option.none()
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
beat: start,
|
|
290
|
+
bpm,
|
|
291
|
+
target: Option.some(to.value)
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
const keptWith = (kept, segment) => {
|
|
297
|
+
const earlier = pipe(Array.last(kept), Option.filter((last) => last.beat === segment.beat), Option.match({
|
|
298
|
+
onNone: () => kept,
|
|
299
|
+
onSome: () => Array.dropRight(kept, SINGLE)
|
|
300
|
+
}));
|
|
301
|
+
if (pipe(Array.last(earlier), Option.exists((last) => Option.isNone(last.target) && Option.isNone(segment.target) && last.bpm === segment.bpm))) return earlier;
|
|
302
|
+
return [...earlier, segment];
|
|
303
|
+
};
|
|
304
|
+
const withoutRepeats = (segments) => {
|
|
305
|
+
let kept = [];
|
|
306
|
+
for (const segment of segments) kept = keptWith(kept, segment);
|
|
307
|
+
return kept;
|
|
308
|
+
};
|
|
309
|
+
const tempoSegmentsOf = (points) => pipe(points, Array.map((point, index) => ({
|
|
310
|
+
point,
|
|
311
|
+
next: Array.get(points, index + NEXT$2)
|
|
312
|
+
})), Array.filter(({ next }) => Option.match(next, {
|
|
313
|
+
onNone: () => true,
|
|
314
|
+
onSome: (to) => to.beat > 0
|
|
315
|
+
})), Array.map(({ point, next }) => segmentOf(point, next)), withoutRepeats);
|
|
316
|
+
const meterOfId = (beat, id) => pipe(Option.fromNullishOr(decodeTimeSignatureId(id)), Option.map((signature) => ({
|
|
317
|
+
beat: Math.max(beat, 0),
|
|
318
|
+
numerator: signature.num,
|
|
319
|
+
denominator: signature.den
|
|
320
|
+
})));
|
|
321
|
+
const metersOf = (liveSet) => pipe(automationOf((mixer) => mixer.TimeSignature)(liveSet), Option.map(({ events, manual }) => {
|
|
322
|
+
if (events.length > SINGLE || Option.isNone(manual)) return pipe(events, Array.map((event) => meterOfId(event.Time, Number(event.Value))), Array.getSomes, Array.reverse, Array.dedupeAdjacentWith((later, earlier) => later.beat === earlier.beat), Array.reverse);
|
|
323
|
+
return Option.toArray(meterOfId(0, manual.value));
|
|
324
|
+
}), Option.getOrElse(() => []));
|
|
325
|
+
const byBeat = Order.mapInput(Order.Number, (locator) => locator.beat);
|
|
326
|
+
const locatorsOf = (liveSet) => pipe(Option.fromUndefinedOr(liveSet.Locators), Option.flatMap((locators) => Option.fromUndefinedOr(locators.Locators.Locator)), Option.getOrElse(() => []), Array.map((locator) => ({
|
|
327
|
+
beat: locator.Time.Value,
|
|
328
|
+
name: locator.Name.Value
|
|
329
|
+
})), Array.sortBy(byBeat));
|
|
330
|
+
// src/features/convert-als/model/ticks.ts
|
|
331
|
+
const TICKS_PER_BEAT = TICKS_PER_WHOLE / 4;
|
|
332
|
+
const tickOf = (beat) => {
|
|
333
|
+
const exact = beat * TICKS_PER_BEAT;
|
|
334
|
+
return {
|
|
335
|
+
tick: Math.round(exact),
|
|
336
|
+
exact: Number.isInteger(exact)
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
// src/features/convert-als/model/mix.ts
|
|
340
|
+
const DECIBELS_PER_DECADE = 20;
|
|
341
|
+
const SILENT_DECIBELS = -70;
|
|
342
|
+
const AUDIBLE_SEND = .001;
|
|
343
|
+
const NONE$1 = 0;
|
|
344
|
+
const NEXT$1 = 1;
|
|
345
|
+
const SILENT = 10 ** (SILENT_DECIBELS / DECIBELS_PER_DECADE);
|
|
346
|
+
const decibelsOf = (gain) => DECIBELS_PER_DECADE * Math.log10(Math.max(gain, SILENT));
|
|
347
|
+
const [VOLUME, PAN] = MIXER_PARAMETERS;
|
|
348
|
+
const VALUES = {
|
|
349
|
+
volume: decibelsOf,
|
|
350
|
+
pan: (pan) => pan
|
|
351
|
+
};
|
|
352
|
+
const RESTING = {
|
|
353
|
+
volume: NONE$1,
|
|
354
|
+
pan: NONE$1
|
|
355
|
+
};
|
|
356
|
+
const pointsOf = ({ owner, parameter }) => (control) => pipe(envelopeOf(owner)(control), Array.map((event) => ({
|
|
357
|
+
tick: tickOf(Math.max(event.Time, 0)).tick,
|
|
358
|
+
value: VALUES[parameter](Number(event.Value))
|
|
359
|
+
})), Array.filter((point) => Number.isFinite(point.value)));
|
|
360
|
+
const startOf = (owned) => (control) => pipe(pointsOf(owned)(control), Array.head, Option.map((point) => point.value), Option.orElse(() => pipe(Option.fromUndefinedOr(control.Manual), Option.map((manual) => VALUES[owned.parameter](manual.Value)))), Option.getOrElse(() => RESTING[owned.parameter]));
|
|
361
|
+
const levelOf = (owner) => (mixer) => ({
|
|
362
|
+
decibels: startOf({
|
|
363
|
+
owner,
|
|
364
|
+
parameter: VOLUME
|
|
365
|
+
})(mixer.Volume),
|
|
366
|
+
pan: startOf({
|
|
367
|
+
owner,
|
|
368
|
+
parameter: PAN
|
|
369
|
+
})(mixer.Pan),
|
|
370
|
+
muted: pipe(Option.fromUndefinedOr(mixer.Speaker), Option.flatMap((speaker) => Option.fromUndefinedOr(speaker.Manual)), Option.exists((manual) => manual.Value === "false"))
|
|
371
|
+
});
|
|
372
|
+
const sendsOf = (mixer) => pipe(Option.fromUndefinedOr(mixer.Sends), Option.flatMap((sends) => Option.fromUndefinedOr(sends.TrackSendHolder)), Option.getOrElse(() => []), Array.map((holder, bus) => ({
|
|
373
|
+
bus,
|
|
374
|
+
amount: pipe(Option.fromUndefinedOr(holder.Send.Manual), Option.match({
|
|
375
|
+
onNone: () => NONE$1,
|
|
376
|
+
onSome: (manual) => manual.Value
|
|
377
|
+
}))
|
|
378
|
+
})), Array.filter((send) => send.amount > AUDIBLE_SEND));
|
|
379
|
+
const envelopesOf = (owner) => (mixer) => pipe([{
|
|
380
|
+
parameter: "volume",
|
|
381
|
+
control: mixer.Volume
|
|
382
|
+
}, {
|
|
383
|
+
parameter: "pan",
|
|
384
|
+
control: mixer.Pan
|
|
385
|
+
}], Array.map(({ parameter, control }) => ({
|
|
386
|
+
parameter,
|
|
387
|
+
points: pointsOf({
|
|
388
|
+
owner,
|
|
389
|
+
parameter
|
|
390
|
+
})(control)
|
|
391
|
+
})), Array.filter((envelope) => envelope.points.length > NEXT$1));
|
|
392
|
+
const trackMixOf = (track) => pipe(Option.fromUndefinedOr(track.DeviceChain.Mixer), Option.map((mixer) => ({
|
|
393
|
+
level: levelOf(track)(mixer),
|
|
394
|
+
sends: sendsOf(mixer),
|
|
395
|
+
envelopes: envelopesOf(track)(mixer)
|
|
396
|
+
})));
|
|
397
|
+
const NO_ENVELOPES = {};
|
|
398
|
+
const busOf = (nameOf) => (track) => ({
|
|
399
|
+
name: nameOf(track.Name),
|
|
400
|
+
level: pipe(Option.fromUndefinedOr(track.DeviceChain.Mixer), Option.match({
|
|
401
|
+
onNone: () => ({
|
|
402
|
+
decibels: NONE$1,
|
|
403
|
+
pan: NONE$1,
|
|
404
|
+
muted: false
|
|
405
|
+
}),
|
|
406
|
+
onSome: levelOf(NO_ENVELOPES)
|
|
407
|
+
}))
|
|
408
|
+
});
|
|
409
|
+
const mixOf = (nameOf) => (liveSet) => ({
|
|
410
|
+
tracks: new Map(pipe(liveSet.Tracks.MidiTrack ?? [], Array.flatMap((track, index) => pipe(trackMixOf(track), Option.map((mix) => [index, mix]), Option.toArray)))),
|
|
411
|
+
buses: pipe(liveSet.Tracks.ReturnTrack ?? [], Array.map(busOf(nameOf)))
|
|
412
|
+
});
|
|
413
|
+
// src/features/convert-als/model/timeline.ts
|
|
414
|
+
const MELODIC_CHANNEL = 0;
|
|
415
|
+
const DRUM_CHANNEL = 9;
|
|
416
|
+
const NONE = 0;
|
|
417
|
+
const NEXT = 1;
|
|
418
|
+
const nameOf = (label) => pipe([label.EffectiveName, label.UserName], Array.map(Option.fromUndefinedOr), Array.getSomes, Array.map((name) => name.Value), Array.findFirst((name) => name !== ""));
|
|
419
|
+
const isDrumRack = (track) => pipe(Option.fromUndefinedOr(track.DeviceChain.DeviceChain), Option.flatMap((chain) => Option.fromUndefinedOr(chain.Devices)), Option.flatMap((devices) => Option.fromUndefinedOr(devices.DrumGroupDevice)), Option.isSome);
|
|
420
|
+
const trackNotesOf = (track) => {
|
|
421
|
+
const played = pipe(track.DeviceChain.MainSequencer.ClipTimeable.ArrangerAutomation.Events.MidiClip ?? [], Array.flatMap(notesOfClip));
|
|
422
|
+
const placed = pipe(played, Array.map((note) => ({
|
|
423
|
+
note,
|
|
424
|
+
start: tickOf(note.beat),
|
|
425
|
+
end: tickOf(note.beat + note.length)
|
|
426
|
+
})));
|
|
427
|
+
return {
|
|
428
|
+
notes: sortedNotes(pipe(placed, Array.map(({ note, start, end }) => ({
|
|
429
|
+
tick: start.tick,
|
|
430
|
+
end: end.tick,
|
|
431
|
+
midi: note.midi,
|
|
432
|
+
velocity: note.velocity,
|
|
433
|
+
release: note.release
|
|
434
|
+
})))),
|
|
435
|
+
offGrid: Array.countBy(placed, ({ start, end }) => !start.exact || !end.exact)
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
const partOf = (track, index) => {
|
|
439
|
+
const read = trackNotesOf(track);
|
|
440
|
+
return {
|
|
441
|
+
part: {
|
|
442
|
+
track: index,
|
|
443
|
+
channel: Boolean.match(isDrumRack(track), {
|
|
444
|
+
onFalse: () => MELODIC_CHANNEL,
|
|
445
|
+
onTrue: () => DRUM_CHANNEL
|
|
446
|
+
}),
|
|
447
|
+
name: nameOf(track.Name),
|
|
448
|
+
program: Option.none(),
|
|
449
|
+
notes: read.notes,
|
|
450
|
+
controls: [],
|
|
451
|
+
lyrics: []
|
|
452
|
+
},
|
|
453
|
+
offGrid: read.offGrid
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
const temposOf = (liveSet) => pipe(tempoSegmentsOf(tempoPointsOf(liveSet)), Array.map((segment) => ({
|
|
457
|
+
tick: tickOf(segment.beat).tick,
|
|
458
|
+
microseconds: microsecondsOf(segment.bpm),
|
|
459
|
+
target: pipe(segment.target, Option.map(microsecondsOf))
|
|
460
|
+
})));
|
|
461
|
+
const lastOf = (ticks) => Array.reduce(ticks, NONE, (latest, tick) => Math.max(latest, tick));
|
|
462
|
+
const timelineOf = (liveSet) => {
|
|
463
|
+
const reads = pipe(liveSet.Tracks.MidiTrack ?? [], Array.map(partOf), Array.filter((read) => Array.isReadonlyArrayNonEmpty(read.part.notes)));
|
|
464
|
+
const parts = pipe(reads, Array.map((read) => read.part));
|
|
465
|
+
const markers = sortedByTick(pipe(locatorsOf(liveSet), Array.map((locator) => ({
|
|
466
|
+
tick: tickOf(locator.beat).tick,
|
|
467
|
+
text: locator.name
|
|
468
|
+
}))));
|
|
469
|
+
const tempos = temposOf(liveSet);
|
|
470
|
+
const meters = pipe(metersOf(liveSet), Array.map((meter) => ({
|
|
471
|
+
tick: tickOf(meter.beat).tick,
|
|
472
|
+
numerator: meter.numerator,
|
|
473
|
+
denominator: meter.denominator
|
|
474
|
+
})));
|
|
475
|
+
const noteEnds = pipe(parts, Array.flatMap((part) => part.notes), Array.map((note) => note.end));
|
|
476
|
+
const pointEnds = pipe([
|
|
477
|
+
...markers,
|
|
478
|
+
...tempos,
|
|
479
|
+
...meters
|
|
480
|
+
], Array.map((point) => point.tick + NEXT));
|
|
481
|
+
return {
|
|
482
|
+
title: Option.none(),
|
|
483
|
+
end: lastOf([...noteEnds, ...pointEnds]),
|
|
484
|
+
offGrid: Array.reduce(reads, NONE, (sum, read) => sum + read.offGrid),
|
|
485
|
+
tempos,
|
|
486
|
+
meters,
|
|
487
|
+
markers,
|
|
488
|
+
parts,
|
|
489
|
+
mix: mixOf(nameOf)(liveSet)
|
|
490
|
+
};
|
|
491
|
+
};
|
|
492
|
+
// src/features/convert-als/model/convert.ts
|
|
493
|
+
const alsToFumx = Effect.fn("alsToFumx")(function* convert(input) {
|
|
494
|
+
const document = yield* readAlsDocument(input.bytes);
|
|
495
|
+
const timeline = yield* Effect.sync(() => timelineOf(document.Ableton.LiveSet)).pipe(Effect.withSpan("timelineOf"));
|
|
496
|
+
const written = yield* Effect.sync(() => writeFumx({
|
|
497
|
+
timeline,
|
|
498
|
+
title: input.title
|
|
499
|
+
})).pipe(Effect.withSpan("writeFumx"));
|
|
500
|
+
yield* Effect.annotateCurrentSpan({
|
|
501
|
+
creator: document.Ableton.Creator ?? "",
|
|
502
|
+
parts: written.plan.parts.length,
|
|
503
|
+
bars: written.bars.length
|
|
504
|
+
});
|
|
505
|
+
return {
|
|
506
|
+
...written,
|
|
507
|
+
offGrid: timeline.offGrid
|
|
508
|
+
};
|
|
509
|
+
});
|
|
510
|
+
export { UnreadableAls, alsToFumx };
|
|
511
|
+
|
|
512
|
+
//# sourceMappingURL=convert-als.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-als.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"],"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"],"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,2BAAW,IAAI,IAAI;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,aAAa;AAEnB,MAAM,SAAS,IAAI,UAAU;CAC3B,kBAAkB;CAClB,qBAAqB;CACrB,qBAAqB;CACrB,eAAe;CACf,qBAAqB;CACrB,OAAO;CACP,UAAU,SAA0B,SAAS,IAAI,IAAI;AACvD,CAAC;AAED,MAAM,MAAM,OAAO,OAAO,EAAE,OAAO,OAAO,iBAAiB,CAAC;AAC5D,MAAM,OAAO,OAAO,OAAO,EAAE,OAAO,OAAO,OAAO,CAAC;AACnD,MAAM,OAAO,OAAO,OAAO,EAAE,OAAO,OAAO,SAAS,CAAC,QAAQ,OAAO,CAAC,EAAE,CAAC;AAExE,MAAM,cAAc,OAAO,OAAO;CAAE,MAAM,OAAO;CAAkB,OAAO,OAAO;AAAO,CAAC;AAIzF,MAAM,eAAe,OAAO,OAAO;CACjC,YAAY,YAAY,KAAK,OAAO,OAAO,OAAO,WAAW;CAC7D,WAAW,YAAY,KAAK,OAAO,OAAO,OAAO,WAAW;CAC5D,WAAW,YAAY,K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