@r_masseater/song-format 0.2.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 (33) hide show
  1. package/dist/als-to-fumx.mjs +525 -0
  2. package/dist/als-to-fumx.mjs.map +1 -0
  3. package/dist/convert-als.mjs +30 -22
  4. package/dist/convert-als.mjs.map +1 -1
  5. package/dist/convert-midi.mjs +1 -1
  6. package/dist/fumx-language-server.mjs +1 -1
  7. package/dist/{fumx-module-CmHFC-eI.mjs → fumx-module-CqxUe07y.mjs} +38 -66
  8. package/dist/{fumx-module-CmHFC-eI.mjs.map → fumx-module-CqxUe07y.mjs.map} +1 -1
  9. package/dist/{fumx-module-DJQrnEVm.mjs → fumx-module-CtXvLKU1.mjs} +38 -66
  10. package/dist/fumx-module-CtXvLKU1.mjs.map +1 -0
  11. package/dist/index.mjs +1 -1
  12. package/dist/language.mjs +1 -1
  13. package/dist/mapper.mjs +1 -1
  14. package/dist/midi-to-fumx.mjs +10 -947
  15. package/dist/midi-to-fumx.mjs.map +1 -1
  16. package/dist/{read-song-CSIhaAEB.mjs → read-song-BzqX5MuZ.mjs} +2 -2
  17. package/dist/{read-song-CSIhaAEB.mjs.map → read-song-BzqX5MuZ.mjs.map} +1 -1
  18. package/dist/{read-song-CNrfcHrY.mjs → read-song-CzMPm8u8.mjs} +2 -2
  19. package/dist/{read-song-CNrfcHrY.mjs.map → read-song-CzMPm8u8.mjs.map} +1 -1
  20. package/dist/round-trip-Cz8iQlpW.mjs +946 -0
  21. package/dist/round-trip-Cz8iQlpW.mjs.map +1 -0
  22. package/dist/song-report.mjs +2 -2
  23. package/dist/transform-BoSDqqPW.mjs +109 -0
  24. package/dist/transform-BoSDqqPW.mjs.map +1 -0
  25. package/dist/vite.mjs +2 -2
  26. package/dist/{write-CS-ZjoQB.mjs → write-CuDbIkpM.mjs} +4 -3
  27. package/dist/{write-CS-ZjoQB.mjs.map → write-CuDbIkpM.mjs.map} +1 -1
  28. package/package.json +6 -11
  29. package/skills/read-fumx/SKILL.md +0 -1
  30. package/skills/use-fumx-tools/SKILL.md +0 -1
  31. package/dist/fumx-module-DJQrnEVm.mjs.map +0 -1
  32. package/dist/transform-DQm5wTlA.mjs +0 -489
  33. package/dist/transform-DQm5wTlA.mjs.map +0 -1
@@ -1,916 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { t as runMain } from "./run-main-Bf32CgzU.mjs";
3
- import { c as fractionOf, d as FumxGrammar, f as FumxTerminals, s as TICKS_PER_WHOLE } from "./fumx-module-CmHFC-eI.mjs";
4
- import { t as readSong } from "./read-song-CSIhaAEB.mjs";
5
- import { AstUtils, GrammarAST } from "langium";
6
- import { Array, Console, Effect, FileSystem, Match, Option, Order, Path, Predicate, Record, Schema, String as String$1, pipe } from "effect";
7
- import { Midi } from "tonal";
8
- import { Argument, Command, Flag } from "effect/cli";
2
+ import { a as sortedNotes, i as sortedByTick, n as writeFumx, r as NO_MIX, s as convertMain, t as roundTrip } from "./round-trip-Cz8iQlpW.mjs";
3
+ import { s as TICKS_PER_WHOLE } from "./fumx-module-CqxUe07y.mjs";
4
+ import { Array, Effect, Match, Option, Order, Predicate, Record, Schema, pipe } from "effect";
9
5
  import { parseMidi } from "midi-file";
10
- // src/app/convert-command.ts
11
- const INDENT$1 = 2;
12
- const taggedError$2 = Schema.TaggedError;
13
- var Mismatch = class extends taggedError$2()("Mismatch", { message: Schema.String }, { identifier: "Mismatch" }) {};
14
- const encodeSummary = Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown, { space: INDENT$1 }));
15
- const convertMain = (spec) => {
16
- const convertFile = Effect.fn("convertFile")(function* convertFile(file, out) {
17
- const fileSystem = yield* FileSystem.FileSystem;
18
- const path = yield* Path.Path;
19
- const input = path.resolve(file);
20
- const parsed = path.parse(input);
21
- const target = Option.match(out, {
22
- onNone: () => path.join(parsed.dir, `${parsed.name}.fumx`),
23
- onSome: (given) => path.resolve(given)
24
- });
25
- const bytes = yield* fileSystem.readFile(input);
26
- const converted = yield* spec.convert({
27
- bytes,
28
- title: parsed.name,
29
- path: target
30
- });
31
- yield* fileSystem.writeFileString(target, converted.text);
32
- return {
33
- output: target,
34
- comparison: converted.comparison,
35
- adjustments: converted.adjustments
36
- };
37
- });
38
- const command = Command.make(spec.name, {
39
- file: Argument.String("file").pipe(Argument.withDescription(spec.input)),
40
- out: Flag.String("out").pipe(Flag.withDescription(`Where to write the .fumx file; defaults to the ${spec.source}'s name with .fumx`), Flag.optional)
41
- }, ({ file, out }) => convertFile(file, out).pipe(Effect.tap((summary) => Effect.flatMap(encodeSummary(summary), Console.log)), Effect.filterOrFail((summary) => summary.comparison.matches, () => Mismatch.make({ message: `The written .fumx does not reproduce every event of the ${spec.source}` })), Effect.asVoid));
42
- runMain(spec.name)(Command.run(command, { version: "0.0.0" }));
43
- };
44
- // src/entities/timeline/model/general-midi.ts
45
- const PROGRAMS = [
46
- "acoustic-grand-piano",
47
- "bright-acoustic-piano",
48
- "electric-grand-piano",
49
- "honky-tonk-piano",
50
- "electric-piano-1",
51
- "electric-piano-2",
52
- "harpsichord",
53
- "clavinet",
54
- "celesta",
55
- "glockenspiel",
56
- "music-box",
57
- "vibraphone",
58
- "marimba",
59
- "xylophone",
60
- "tubular-bells",
61
- "dulcimer",
62
- "drawbar-organ",
63
- "percussive-organ",
64
- "rock-organ",
65
- "church-organ",
66
- "reed-organ",
67
- "accordion",
68
- "harmonica",
69
- "tango-accordion",
70
- "acoustic-guitar-nylon",
71
- "acoustic-guitar-steel",
72
- "electric-guitar-jazz",
73
- "electric-guitar-clean",
74
- "electric-guitar-muted",
75
- "overdriven-guitar",
76
- "distortion-guitar",
77
- "guitar-harmonics",
78
- "acoustic-bass",
79
- "electric-bass-finger",
80
- "electric-bass-pick",
81
- "fretless-bass",
82
- "slap-bass-1",
83
- "slap-bass-2",
84
- "synth-bass-1",
85
- "synth-bass-2",
86
- "violin",
87
- "viola",
88
- "cello",
89
- "contrabass",
90
- "tremolo-strings",
91
- "pizzicato-strings",
92
- "orchestral-harp",
93
- "timpani",
94
- "string-ensemble-1",
95
- "string-ensemble-2",
96
- "synth-strings-1",
97
- "synth-strings-2",
98
- "choir-aahs",
99
- "voice-oohs",
100
- "synth-voice",
101
- "orchestra-hit",
102
- "trumpet",
103
- "trombone",
104
- "tuba",
105
- "muted-trumpet",
106
- "french-horn",
107
- "brass-section",
108
- "synth-brass-1",
109
- "synth-brass-2",
110
- "soprano-sax",
111
- "alto-sax",
112
- "tenor-sax",
113
- "baritone-sax",
114
- "oboe",
115
- "english-horn",
116
- "bassoon",
117
- "clarinet",
118
- "piccolo",
119
- "flute",
120
- "recorder",
121
- "pan-flute",
122
- "blown-bottle",
123
- "shakuhachi",
124
- "whistle",
125
- "ocarina",
126
- "lead-1-square",
127
- "lead-2-sawtooth",
128
- "lead-3-calliope",
129
- "lead-4-chiff",
130
- "lead-5-charang",
131
- "lead-6-voice",
132
- "lead-7-fifths",
133
- "lead-8-bass-and-lead",
134
- "pad-1-new-age",
135
- "pad-2-warm",
136
- "pad-3-polysynth",
137
- "pad-4-choir",
138
- "pad-5-bowed",
139
- "pad-6-metallic",
140
- "pad-7-halo",
141
- "pad-8-sweep",
142
- "fx-1-rain",
143
- "fx-2-soundtrack",
144
- "fx-3-crystal",
145
- "fx-4-atmosphere",
146
- "fx-5-brightness",
147
- "fx-6-goblins",
148
- "fx-7-echoes",
149
- "fx-8-sci-fi",
150
- "sitar",
151
- "banjo",
152
- "shamisen",
153
- "koto",
154
- "kalimba",
155
- "bagpipe",
156
- "fiddle",
157
- "shanai",
158
- "tinkle-bell",
159
- "agogo",
160
- "steel-drums",
161
- "woodblock",
162
- "taiko-drum",
163
- "melodic-tom",
164
- "synth-drum",
165
- "reverse-cymbal",
166
- "guitar-fret-noise",
167
- "breath-noise",
168
- "seashore",
169
- "bird-tweet",
170
- "telephone-ring",
171
- "helicopter",
172
- "applause",
173
- "gunshot"
174
- ];
175
- const DRUMS = [
176
- "acoustic-bass-drum",
177
- "bass-drum-1",
178
- "side-stick",
179
- "acoustic-snare",
180
- "hand-clap",
181
- "electric-snare",
182
- "low-floor-tom",
183
- "closed-hi-hat",
184
- "high-floor-tom",
185
- "pedal-hi-hat",
186
- "low-tom",
187
- "open-hi-hat",
188
- "low-mid-tom",
189
- "hi-mid-tom",
190
- "crash-cymbal-1",
191
- "high-tom",
192
- "ride-cymbal-1",
193
- "chinese-cymbal",
194
- "ride-bell",
195
- "tambourine",
196
- "splash-cymbal",
197
- "cowbell",
198
- "crash-cymbal-2",
199
- "vibraslap",
200
- "ride-cymbal-2",
201
- "hi-bongo",
202
- "low-bongo",
203
- "mute-hi-conga",
204
- "open-hi-conga",
205
- "low-conga",
206
- "high-timbale",
207
- "low-timbale",
208
- "high-agogo",
209
- "low-agogo",
210
- "cabasa",
211
- "maracas",
212
- "short-whistle",
213
- "long-whistle",
214
- "short-guiro",
215
- "long-guiro",
216
- "claves",
217
- "hi-wood-block",
218
- "low-wood-block",
219
- "mute-cuica",
220
- "open-cuica",
221
- "mute-triangle",
222
- "open-triangle"
223
- ];
224
- // src/entities/timeline/model/groups.ts
225
- const NONE$7 = 0;
226
- const NEXT$7 = 1;
227
- const isDrumPart = (part) => part.channel === 9;
228
- const chordKeyOf = (note) => `${String(note.tick)}:${String(note.end)}:${String(note.velocity)}:${String(note.release)}`;
229
- const groupOf = (notes) => pipe(Array.head(notes), Option.map((first) => ({
230
- start: first.tick,
231
- end: first.end,
232
- midis: pipe(notes, Array.map((note) => note.midi)),
233
- velocity: first.velocity,
234
- release: first.release,
235
- lyric: Option.none()
236
- })));
237
- const stackedOf = (chord) => pipe(chord, Array.map((note, index) => ({
238
- note,
239
- layer: pipe(Array.take(chord, index), Array.countBy((earlier) => earlier.midi === note.midi))
240
- })), Array.groupBy(({ layer }) => String(layer)), Record.values, Array.map((layer) => pipe(layer, Array.map(({ note }) => note))));
241
- const chordsOf = (part) => {
242
- if (isDrumPart(part)) return pipe(part.notes, Array.map((note) => [note]));
243
- return pipe(part.notes, Array.groupBy(chordKeyOf), Record.values, Array.flatMap(stackedOf));
244
- };
245
- const byStartThenLonger = Order.combine(Order.mapInput(Order.Number, (group) => group.start), Order.mapInput(Order.flip(Order.Number), (group) => group.end));
246
- const withLyrics = (part) => (groups) => pipe(groups, Array.map((group, index) => {
247
- const leads = pipe(Array.get(groups, index - NEXT$7), Option.match({
248
- onNone: () => true,
249
- onSome: (previous) => previous.start !== group.start
250
- }));
251
- const lyric = pipe(Array.findFirst(part.lyrics, (candidate) => candidate.tick === group.start), Option.filter(() => leads), Option.map((found) => found.text));
252
- return {
253
- ...group,
254
- lyric
255
- };
256
- }));
257
- const groupsOf = (part) => {
258
- const groups = pipe(chordsOf(part), Array.map(groupOf), Array.getSomes);
259
- return withLyrics(part)(Array.sort(groups, byStartThenLonger));
260
- };
261
- const endOfLine = (line) => Option.match(Array.last(line), {
262
- onNone: () => NONE$7,
263
- onSome: (group) => group.end
264
- });
265
- const placeGroup = (lines, group) => Option.match(Array.findFirstIndex(lines, (line) => endOfLine(line) <= group.start), {
266
- onNone: () => [...lines, [group]],
267
- onSome: (index) => pipe(lines, Array.map((line, position) => {
268
- if (position === index) return [...line, group];
269
- return line;
270
- }))
271
- });
272
- const linesOf = (groups) => Array.reduce(groups, [], placeGroup);
273
- // src/entities/timeline/model/names.ts
274
- const FIRST_SUFFIX = 2;
275
- const keywordsIn = (node) => new Set(AstUtils.streamAst(node).filter((child) => GrammarAST.isKeyword(child)).map((keyword) => keyword.value));
276
- const grammar = FumxGrammar();
277
- const allowedKeywords = pipe(grammar.rules, Array.findFirst((rule) => rule.name === "Name"), Option.match({
278
- onNone: () => /* @__PURE__ */ new Set(),
279
- onSome: keywordsIn
280
- }));
281
- const allKeywords = Array.fromIterable(keywordsIn(grammar));
282
- const reserved = new Set(pipe(allKeywords, Array.filter((keyword) => !allowedKeywords.has(keyword))));
283
- const otherTerminals = pipe(Record.toEntries(FumxTerminals), Array.filter(([name]) => name !== "ID"), Array.map(([, pattern]) => new RegExp(`^(?:${pattern.source})$`, "u")));
284
- const identifier = new RegExp(`^(?:${FumxTerminals.ID.source})$`, "u");
285
- const isUsable = (name) => identifier.test(name) && !reserved.has(name) && !pipe(otherTerminals, Array.some((pattern) => pattern.test(name)));
286
- const slugOf = (text) => pipe(text, String$1.normalize("NFKD"), String$1.toLowerCase, String$1.replaceAll(/[^a-z0-9]+/gu, "-"), String$1.replaceAll(/^[-0-9]+|-+$/gu, ""));
287
- const nameFrom = (candidates) => pipe(candidates, Array.map(slugOf), Array.findFirst(isUsable), Option.getOrElse(() => "part"));
288
- const uniqueAmong = (taken) => (name) => pipe(Array.range(FIRST_SUFFIX, taken.size + FIRST_SUFFIX), Array.map((suffix) => `${name}-${String(suffix)}`), Array.prepend(name), Array.findFirst((candidate) => isUsable(candidate) && !taken.has(candidate)), Option.getOrElse(() => `${name}-${String(taken.size)}`));
289
- // src/entities/timeline/model/plan.ts
290
- const NONE$6 = 0;
291
- const NEXT$6 = 1;
292
- const SHARED = 1;
293
- const DEFAULT_PROGRAM = 0;
294
- const drumNameOf = (midi) => Option.getOrElse(Array.get(DRUMS, midi - 35), () => `note-${String(midi)}`);
295
- const programNameOf = (program) => Option.getOrElse(Array.get(PROGRAMS, program), () => `program-${String(program)}`);
296
- const controllerKeyOf = ({ controller }) => {
297
- if (controller.kind === "cc") return `cc ${String(controller.number)}`;
298
- if (controller.kind === "pressure") return Option.match(controller.midi, {
299
- onNone: () => "pressure",
300
- onSome: (midi) => `pressure ${String(midi)}`
301
- });
302
- return controller.kind;
303
- };
304
- const isLastAtTick = (controls) => (index) => pipe(Option.all([Array.get(controls, index), Array.get(controls, index + NEXT$6)]), Option.match({
305
- onNone: () => true,
306
- onSome: ([control, next]) => next.tick !== control.tick || controllerKeyOf(next) !== controllerKeyOf(control)
307
- }));
308
- const byControllerThenTick = Order.combine(Order.mapInput(Order.String, controllerKeyOf), Order.mapInput(Order.Number, (control) => control.tick));
309
- const controlsOf$1 = (part) => {
310
- const drumProgram = pipe(part.program, Option.filter(() => isDrumPart(part)), Option.map((value) => ({
311
- tick: NONE$6,
312
- controller: { kind: "program" },
313
- value
314
- })), Option.toArray);
315
- const sorted = Array.sort([...drumProgram, ...part.controls], byControllerThenTick);
316
- return pipe(sorted, Array.filter((_control, index) => isLastAtTick(sorted)(index)));
317
- };
318
- const programOf = (part) => Option.getOrElse(part.program, () => DEFAULT_PROGRAM);
319
- const labelOf = (part) => Option.getOrElse(part.name, () => "");
320
- const instrumentsOf = (parts) => new Map(pipe(parts, Array.filter((part) => !isDrumPart(part)), Array.map(programOf), Array.dedupe, Array.map((program) => [program, nameFrom([programNameOf(program)])])));
321
- const drumVoicesOf = (parts) => {
322
- const midis = pipe(parts, Array.filter(isDrumPart), Array.flatMap((part) => part.notes), Array.map((note) => note.midi), Array.dedupe);
323
- return new Map(pipe(Array.sort(midis, Order.Number), Array.map((midi) => [midi, drumNameOf(midi)])));
324
- };
325
- const channelledOf = (shared) => (part) => {
326
- const label = labelOf(part);
327
- if (shared.has(label)) return `${label} ch${String(part.channel + NEXT$6)}`;
328
- return label;
329
- };
330
- const fallbackOf = (part) => {
331
- if (isDrumPart(part)) return "drums";
332
- return programNameOf(programOf(part));
333
- };
334
- const candidatesOf = (shared) => (part) => [
335
- channelledOf(shared)(part),
336
- fallbackOf(part),
337
- `track ${String(part.track)}`
338
- ];
339
- const sharedLabelsOf = (parts) => new Set(pipe(parts, Array.groupBy(labelOf), Record.filter((same) => same.length > SHARED), Record.keys));
340
- const sourceOf = (instruments) => (part) => {
341
- if (isDrumPart(part)) return { kind: "kit" };
342
- const program = programOf(part);
343
- return {
344
- kind: "instrument",
345
- instrument: instruments.get(program) ?? "",
346
- program
347
- };
348
- };
349
- const namesOf = (planned) => new Set(pipe(planned, Array.map((done) => done.name)));
350
- const UNMIXED = {
351
- level: {
352
- decibels: NONE$6,
353
- pan: NONE$6,
354
- muted: false
355
- },
356
- sends: [],
357
- envelopes: []
358
- };
359
- const NO_PARTS = [];
360
- const nextPart = (naming) => (planned, part) => {
361
- const name = uniqueAmong(namesOf(planned))(nameFrom(naming.candidates(part)));
362
- return Array.append(planned, {
363
- part,
364
- name,
365
- source: sourceOf(naming.instruments)(part),
366
- lines: linesOf(groupsOf(part)),
367
- controls: controlsOf$1(part),
368
- mix: naming.mixes.get(part.track) ?? UNMIXED
369
- });
370
- };
371
- const busesOf = ({ taken, buses }) => {
372
- const used = new Set(taken);
373
- const named = [];
374
- for (const [index, bus] of buses.entries()) {
375
- const name = uniqueAmong(used)(nameFrom([...Option.toArray(bus.name), `bus ${String(index + NEXT$6)}`]));
376
- used.add(name);
377
- named.push({
378
- name,
379
- level: bus.level
380
- });
381
- }
382
- return named;
383
- };
384
- const planOf = (timeline) => {
385
- const instruments = instrumentsOf(timeline.parts);
386
- const candidates = candidatesOf(sharedLabelsOf(timeline.parts));
387
- const parts = Array.reduce(timeline.parts, NO_PARTS, nextPart({
388
- instruments,
389
- candidates,
390
- mixes: timeline.mix.tracks
391
- }));
392
- return {
393
- parts,
394
- buses: busesOf({
395
- taken: namesOf(parts),
396
- buses: timeline.mix.buses
397
- }),
398
- instruments,
399
- drumVoices: drumVoicesOf(timeline.parts)
400
- };
401
- };
402
- // src/entities/timeline/model/tempo-units.ts
403
- const MICROSECONDS_PER_MINUTE = 6e7;
404
- const bpmOf = (microseconds) => MICROSECONDS_PER_MINUTE / microseconds;
405
- const microsecondsOf = (bpm) => Math.round(MICROSECONDS_PER_MINUTE / bpm);
406
- // src/entities/timeline/model/compare.ts
407
- const NONE$5 = 0;
408
- const NEXT$5 = 1;
409
- const UNKNOWN = -1;
410
- const FULL$2 = 127;
411
- const DEFAULT_RELEASE$2 = 64;
412
- const DECIMALS$1 = 9;
413
- const SHOWN = 20;
414
- const countsOf = (keys) => pipe(keys, Array.groupBy((key) => key), Record.map((same) => same.length));
415
- const surplusOf = (over) => (under) => pipe(Record.toEntries(over), Array.flatMap(([key, count]) => {
416
- const left = count - Option.getOrElse(Record.get(under, key), () => NONE$5);
417
- if (left > NONE$5) return Array.makeBy(left, () => key);
418
- return [];
419
- }), Array.take(SHOWN));
420
- const tallyOf = (expected, actual) => {
421
- const wanted = countsOf(expected);
422
- const found = countsOf(actual);
423
- return {
424
- expected: expected.length,
425
- actual: actual.length,
426
- missing: surplusOf(wanted)(found),
427
- extra: surplusOf(found)(wanted)
428
- };
429
- };
430
- const byteOf = (share) => Math.round(share * FULL$2);
431
- const releaseOf$1 = (release) => Option.match(release, {
432
- onNone: () => DEFAULT_RELEASE$2,
433
- onSome: byteOf
434
- });
435
- const keyOf = (parts) => pipe(parts, Array.map(String), Array.join(" "));
436
- const expectedNotesOf = (plan) => pipe(plan.parts, Array.flatMap((planned) => pipe(planned.part.notes, Array.map((note) => keyOf([
437
- planned.name,
438
- note.tick,
439
- note.end - note.tick,
440
- note.midi,
441
- note.velocity,
442
- note.release
443
- ])))));
444
- const actualNotesOf = ({ plan, song }) => {
445
- const voices = new Map(pipe(Array.fromIterable(plan.drumVoices), Array.map(([midi, name]) => [name, midi])));
446
- const notes = pipe(song.notes, Array.map((note) => keyOf([
447
- note.track,
448
- note.start,
449
- note.length,
450
- note.midi,
451
- byteOf(note.velocity),
452
- releaseOf$1(note.releaseVelocity)
453
- ])));
454
- const hits = pipe(song.hits, Array.map((hit) => keyOf([
455
- hit.track,
456
- hit.start,
457
- hit.length,
458
- voices.get(hit.voice) ?? UNKNOWN,
459
- byteOf(hit.velocity),
460
- releaseOf$1(hit.releaseVelocity)
461
- ])));
462
- return [...notes, ...hits];
463
- };
464
- const rounded = (value) => String(Number(value.toFixed(DECIMALS$1)));
465
- const expectedControlsOf = (plan) => pipe(plan.parts, Array.flatMap((planned) => pipe(planned.controls, Array.map((control) => keyOf([
466
- planned.name,
467
- controllerKeyOf(control),
468
- control.tick,
469
- rounded(control.value)
470
- ])))));
471
- const actualControlsOf = (song) => pipe(song.controls, Array.map((control) => keyOf([
472
- control.track,
473
- controllerKeyOf({ controller: control.controller }),
474
- control.start,
475
- rounded(control.value)
476
- ])));
477
- const FLAT = "-";
478
- const isFlatRepeat = (point, previous) => Option.isNone(point.target) && Option.isNone(previous.target) && previous.microseconds === point.microseconds;
479
- const changesOf = (points) => pipe(points, Array.filter((point, index) => pipe(Array.get(points, index - NEXT$5), Option.match({
480
- onNone: () => true,
481
- onSome: (previous) => !isFlatRepeat(point, previous)
482
- }))), Array.map(({ tick, microseconds, target }) => keyOf([
483
- tick,
484
- microseconds,
485
- Option.getOrElse(target, () => FLAT)
486
- ])));
487
- const expectedTempoOf = (bars) => changesOf(pipe(bars, Array.flatMap((bar) => pipe(bar.tempo, Array.map((step) => ({
488
- tick: bar.start + step.offset,
489
- microseconds: step.microseconds,
490
- target: step.target
491
- }))))));
492
- const barPointsOf = (bar) => {
493
- if (Array.isReadonlyArrayNonEmpty(bar.tempoSteps)) return pipe(bar.tempoSteps, Array.map((step) => ({
494
- tick: bar.start + step.offset,
495
- microseconds: microsecondsOf(step.bpm),
496
- target: pipe(step.target, Option.map(microsecondsOf))
497
- })));
498
- return [{
499
- tick: bar.start,
500
- microseconds: microsecondsOf(bar.tempo.bpm),
501
- target: Option.none()
502
- }];
503
- };
504
- const actualTempoOf = (song) => changesOf(pipe(song.bars, Array.flatMap(barPointsOf)));
505
- const expectedLyricsOf = (plan) => pipe(plan.parts, Array.flatMap((planned) => pipe(planned.lines, Array.flatten, Array.flatMap((group) => pipe(group.lyric, Option.map((text) => keyOf([
506
- planned.name,
507
- group.start,
508
- text
509
- ])), Option.toArray)))));
510
- const syllableKeyOf = (note) => pipe(note.lyric, Option.flatMap((lyric) => {
511
- if (lyric.kind === "syllable") return Option.some(keyOf([
512
- note.track,
513
- note.start,
514
- lyric.text
515
- ]));
516
- return Option.none();
517
- }));
518
- const actualLyricsOf = (song) => pipe(song.notes, Array.map(syllableKeyOf), Array.getSomes, Array.dedupe);
519
- const expectedMarksOf = (bars) => pipe(bars, Array.filter((bar) => Array.isReadonlyArrayNonEmpty(bar.marks)), Array.map((bar) => keyOf([bar.start, Array.join(bar.marks, " / ")])));
520
- const actualMarksOf = (song) => pipe(song.bars, Array.map((bar) => pipe(bar.mark, Option.map((mark) => keyOf([bar.start, mark])))), Array.getSomes);
521
- const isClean = (tally) => !Array.isReadonlyArrayNonEmpty(tally.missing) && !Array.isReadonlyArrayNonEmpty(tally.extra);
522
- const compareWithSong = ({ plan, bars, song }) => {
523
- const tallies = {
524
- notes: tallyOf(expectedNotesOf(plan), actualNotesOf({
525
- plan,
526
- song
527
- })),
528
- controls: tallyOf(expectedControlsOf(plan), actualControlsOf(song)),
529
- tempo: tallyOf(expectedTempoOf(bars), actualTempoOf(song)),
530
- lyrics: tallyOf(expectedLyricsOf(plan), actualLyricsOf(song)),
531
- marks: tallyOf(expectedMarksOf(bars), actualMarksOf(song))
532
- };
533
- return {
534
- ...tallies,
535
- matches: pipe(Record.values(tallies), Array.every(isClean))
536
- };
537
- };
538
- // src/entities/timeline/model/events.ts
539
- const NO_MIX = {
540
- tracks: /* @__PURE__ */ new Map(),
541
- buses: []
542
- };
543
- const byTick = Order.mapInput(Order.Number, (timed) => timed.tick);
544
- const sortedByTick = (items) => Array.sort(items, byTick);
545
- const byTickThenPitch = Order.combine(Order.mapInput(Order.Number, (note) => note.tick), Order.mapInput(Order.Number, (note) => note.midi));
546
- const sortedNotes = (notes) => Array.sort(notes, byTickThenPitch);
547
- // src/entities/timeline/model/cells.ts
548
- const NONE$4 = 0;
549
- const FULL$1 = 127;
550
- const SHARE_DECIMALS = 3;
551
- const SEMITONE_DECIMALS = 12;
552
- const LAST = 1;
553
- const durationText = (length) => {
554
- if (length === NONE$4) return "0/1";
555
- return fractionOf(length);
556
- };
557
- const restCell = (length) => ({
558
- head: "rest",
559
- attributes: [],
560
- length
561
- });
562
- const restsOf = (length) => {
563
- if (length > NONE$4) return [restCell(length)];
564
- return [];
565
- };
566
- const isRest = (cell) => cell.head === "rest";
567
- const mergeRests = (merged, cell) => pipe(Array.last(merged), Option.filter((previous) => isRest(previous) && isRest(cell)), Option.match({
568
- onNone: () => [...merged, cell],
569
- onSome: (previous) => [...Array.dropRight(merged, LAST), restCell(previous.length + cell.length)]
570
- }));
571
- const NO_CELLS = [];
572
- const cellText = (cell) => Array.join([
573
- cell.head,
574
- durationText(cell.length),
575
- ...cell.attributes
576
- ], " ");
577
- const cellsText = (cells) => pipe(Array.reduce(cells, NO_CELLS, mergeRests), Array.map(cellText), Array.join(", "));
578
- const quoted = (text) => `"${pipe(text, String$1.replaceAll("\\", String.raw`\\`), String$1.replaceAll("\"", String.raw`\"`), String$1.replaceAll("\n", String.raw`\n`), String$1.replaceAll("\r", String.raw`\r`), String$1.replaceAll(" ", String.raw`\t`))}"`;
579
- const shareText = (value) => String(Number((value / FULL$1).toFixed(SHARE_DECIMALS)));
580
- const semitoneText = (value) => {
581
- const text = String(Number(value.toFixed(SEMITONE_DECIMALS)));
582
- if (value > NONE$4) return `+${text}st`;
583
- return `${text}st`;
584
- };
585
- const pitchText = (midi) => Midi.midiToNoteName(midi, { sharps: true });
586
- // src/entities/timeline/model/layout.ts
587
- const NONE$3 = 0;
588
- const NEXT$4 = 1;
589
- const QUARTER = 4;
590
- const DEFAULT_METER = {
591
- numerator: QUARTER,
592
- denominator: QUARTER
593
- };
594
- const DEFAULT_MICROSECONDS = 5e5;
595
- const MAX_DECIMALS = 9;
596
- const endOfSpan = (span) => span.start + span.length;
597
- const latestAt = (tick) => (items) => pipe(items, Array.filter((item) => item.tick <= tick), Array.last);
598
- const lengthOf = (signature) => TICKS_PER_WHOLE * signature.numerator / signature.denominator;
599
- const meterText = (signature) => (length) => {
600
- const beats = length * signature.denominator / TICKS_PER_WHOLE;
601
- if (Number.isInteger(beats)) return `${String(beats)}/${String(signature.denominator)}`;
602
- return fractionOf(length);
603
- };
604
- const rampAt = (tempos) => (tick) => pipe(latestAt(tick)(tempos), Option.flatMap((start) => pipe(start.target, Option.flatMap((target) => pipe(Array.findFirst(tempos, (tempo) => tempo.tick > start.tick), Option.map((next) => ({
605
- start,
606
- end: next.tick,
607
- target
608
- })))))));
609
- const interpolated = (ramp) => (tick) => {
610
- const from = bpmOf(ramp.start.microseconds);
611
- const to = bpmOf(ramp.target);
612
- const share = (tick - ramp.start.tick) / (ramp.end - ramp.start.tick);
613
- return microsecondsOf(from + (to - from) * share);
614
- };
615
- const rampedAt = (tempos) => (tick, at) => pipe(rampAt(tempos)(tick), Option.map((ramp) => interpolated(ramp)(at)));
616
- const steadyAt = (tempos) => (tick) => pipe(latestAt(tick)(tempos), Option.match({
617
- onNone: () => DEFAULT_MICROSECONDS,
618
- onSome: (tempo) => tempo.microseconds
619
- }));
620
- const tempoAt = (tempos) => (tick) => Option.getOrElse(rampedAt(tempos)(tick, tick), () => steadyAt(tempos)(tick));
621
- const tempoStepsOf = (tempos) => (bar) => {
622
- const end = endOfSpan(bar);
623
- const points = [bar.start, ...pipe(tempos, Array.filter((tempo) => tempo.tick > bar.start && tempo.tick < end), Array.map((tempo) => tempo.tick), Array.dedupe)];
624
- return pipe(points, Array.map((tick, index) => {
625
- const stepEnd = Option.getOrElse(Array.get(points, index + NEXT$4), () => end);
626
- return {
627
- offset: tick - bar.start,
628
- length: stepEnd - tick,
629
- microseconds: tempoAt(tempos)(tick),
630
- target: rampedAt(tempos)(tick, stepEnd)
631
- };
632
- }));
633
- };
634
- const marksOf = (markers) => (bar) => pipe(markers, Array.filter((marker) => marker.tick >= bar.start && marker.tick < endOfSpan(bar)), Array.map((marker) => marker.text));
635
- const spanAt = (meters) => (start) => {
636
- const signature = Option.getOrElse(latestAt(start)(meters), () => DEFAULT_METER);
637
- const full = start + lengthOf(signature);
638
- return {
639
- start,
640
- length: pipe(Array.findFirst(meters, (meter) => meter.tick > start), Option.match({
641
- onNone: () => full,
642
- onSome: (meter) => Math.min(meter.tick, full)
643
- })) - start,
644
- signature
645
- };
646
- };
647
- const barsOf = (timeline) => Array.unfold({
648
- start: NONE$3,
649
- first: true
650
- }, (cursor) => {
651
- if (!cursor.first && cursor.start >= timeline.end) return Option.none();
652
- const span = spanAt(timeline.meters)(cursor.start);
653
- const bar = {
654
- start: span.start,
655
- length: span.length,
656
- meter: meterText(span.signature)(span.length),
657
- tempo: tempoStepsOf(timeline.tempos)(span),
658
- marks: marksOf(timeline.markers)(span)
659
- };
660
- return Option.some([bar, {
661
- start: endOfSpan(span),
662
- first: false
663
- }]);
664
- });
665
- const bpmText = (microseconds) => {
666
- const exact = bpmOf(microseconds);
667
- return `${pipe(Array.range(NONE$3, MAX_DECIMALS), Array.map((decimals) => String(Number(exact.toFixed(decimals)))), Array.findFirst((candidate) => microsecondsOf(Number(candidate)) === microseconds), Option.getOrElse(() => String(exact)))}bpm`;
668
- };
669
- // src/entities/timeline/model/control-lines.ts
670
- const NEXT$3 = 1;
671
- const valueText = (control) => {
672
- if (control.controller.kind === "bend") return semitoneText(control.value);
673
- return String(control.value);
674
- };
675
- const headOf$1 = (planned) => ({ controller }) => {
676
- if (controller.kind === "pressure") return Option.match(controller.midi, {
677
- onNone: () => `${planned.name}.pressure`,
678
- onSome: (midi) => `${planned.name}.pressure ${pitchText(midi)}`
679
- });
680
- return `${planned.name}.${controllerKeyOf({ controller })}`;
681
- };
682
- const cellsOf$1 = (bar) => (controls) => {
683
- const lead = pipe(Array.head(controls), Option.map((first) => first.tick - bar.start), Option.toArray, Array.flatMap(restsOf));
684
- const steps = pipe(controls, Array.map((control, index) => ({
685
- head: valueText(control),
686
- attributes: [],
687
- length: pipe(Array.get(controls, index + NEXT$3), Option.match({
688
- onNone: () => endOfSpan(bar),
689
- onSome: (next) => next.tick
690
- })) - control.tick
691
- })));
692
- return [...lead, ...steps];
693
- };
694
- const controlLinesOf = (bar) => (planned) => pipe(planned.controls, Array.filter((control) => control.tick >= bar.start && control.tick < endOfSpan(bar)), Array.groupBy((control) => controllerKeyOf(control)), Record.values, Array.map((controls) => pipe(Array.head(controls), Option.map((first) => `${headOf$1(planned)(first)}: ${cellsText(cellsOf$1(bar)(controls))}`))), Array.getSomes);
695
- // src/entities/timeline/model/mix-lines.ts
696
- const DECIMALS = 1;
697
- const PERCENT = 100;
698
- const NONE$2 = 0;
699
- const NEXT$2 = 1;
700
- const amountText = (value, unit) => {
701
- const text = Number(value.toFixed(DECIMALS));
702
- if (text > NONE$2) return `+${String(text)}${unit}`;
703
- return `${String(text)}${unit}`;
704
- };
705
- const UNITS = {
706
- volume: (decibels) => amountText(decibels, "dB"),
707
- pan: (pan) => amountText(pan * PERCENT, "%")
708
- };
709
- const levelWords = (level) => [
710
- ...pipe(Option.some(level.decibels), Option.filter((decibels) => UNITS.volume(decibels) !== UNITS.volume(NONE$2)), Option.map((decibels) => `volume ${UNITS.volume(decibels)}`), Option.toArray),
711
- ...pipe(Option.some(level.pan), Option.filter((pan) => UNITS.pan(pan) !== UNITS.pan(NONE$2)), Option.map((pan) => `pan ${UNITS.pan(pan)}`), Option.toArray),
712
- ...pipe(Option.some("mute"), Option.filter(() => level.muted), Option.toArray)
713
- ];
714
- const trackMixWords = ({ mix, buses }) => [...levelWords(mix.level), ...pipe(mix.sends, Array.filter((send) => send.amount > NONE$2), Array.flatMap((send) => pipe(Array.get(buses, send.bus), Option.map((bus) => `send ${bus.name} ${amountText(send.amount * PERCENT, "%")}`), Option.toArray)))];
715
- const busLineOf = (bus) => Array.join([
716
- "bus",
717
- bus.name,
718
- ...levelWords(bus.level)
719
- ], " ");
720
- const valueAt = (points) => (tick) => {
721
- const before = pipe(points, Array.filter((point) => point.tick <= tick), Array.last);
722
- const after = pipe(points, Array.findFirst((point) => point.tick > tick));
723
- return Option.match(before, {
724
- onNone: () => Option.match(after, {
725
- onNone: () => NONE$2,
726
- onSome: (point) => point.value
727
- }),
728
- onSome: (left) => Option.match(after, {
729
- onNone: () => left.value,
730
- onSome: (right) => left.value + (right.value - left.value) * (tick - left.tick) / (right.tick - left.tick)
731
- })
732
- });
733
- };
734
- const rampOf = (bar, name) => (envelope) => {
735
- const at = valueAt(envelope.points);
736
- const unit = UNITS[envelope.parameter];
737
- const from = unit(at(bar.start));
738
- const to = unit(at(endOfSpan(bar)));
739
- return pipe(Option.some(`automate ${name}.${envelope.parameter} ${from} -> ${to} over 1bar`), Option.filter(() => from !== to));
740
- };
741
- const automationLinesOf = (bar) => (planned) => pipe(planned.mix.envelopes, Array.filter((envelope) => Array.length(envelope.points) > NEXT$2), Array.map(rampOf(bar, planned.name)), Array.getSomes);
742
- // src/entities/timeline/model/voice-lines.ts
743
- const FULL = 127;
744
- const DEFAULT_RELEASE$1 = 64;
745
- const SINGLE$1 = 1;
746
- const touches = (bar) => (group) => {
747
- if (group.end === group.start) return group.start >= bar.start && group.start < endOfSpan(bar);
748
- return group.start < endOfSpan(bar) && group.end > bar.start;
749
- };
750
- const segmentOf = (bar) => (group) => ({
751
- group,
752
- start: Math.max(group.start, bar.start),
753
- end: Math.min(group.end, endOfSpan(bar))
754
- });
755
- const pitchesText = (midis) => {
756
- if (midis.length === SINGLE$1) return Array.join(pipe(midis, Array.map(pitchText)), "");
757
- return `[${Array.join(pipe(midis, Array.map(pitchText)), " ")}]`;
758
- };
759
- const headOf = (voices) => (group) => Option.match(voices, {
760
- onNone: () => pitchesText(group.midis),
761
- onSome: (map) => pipe(Array.head(group.midis), Option.flatMap((midi) => Option.fromNullishOr(map.get(midi))), Option.getOrElse(() => ""))
762
- });
763
- const when = (condition, text) => {
764
- if (condition) return [text];
765
- return [];
766
- };
767
- const attributesOf = ({ group, start, end }) => {
768
- const last = end === group.end;
769
- return [
770
- ...when(group.velocity !== FULL, `vel ${shareText(group.velocity)}`),
771
- ...when(last && group.release !== DEFAULT_RELEASE$1, `off ${shareText(group.release)}`),
772
- ...when(!last, "tie"),
773
- ...pipe(group.lyric, Option.filter(() => start === group.start), Option.map((text) => `lyric ${quoted(text)}`), Option.toArray)
774
- ];
775
- };
776
- const cellsOf = (segments, bar, head) => {
777
- const placed = Array.reduce(segments, {
778
- cells: [],
779
- cursor: bar.start
780
- }, ({ cells, cursor }, segment) => ({
781
- cells: [
782
- ...cells,
783
- ...restsOf(segment.start - cursor),
784
- {
785
- head: head(segment.group),
786
- attributes: attributesOf(segment),
787
- length: segment.end - segment.start
788
- }
789
- ],
790
- cursor: segment.end
791
- }));
792
- return [...placed.cells, ...restsOf(endOfSpan(bar) - placed.cursor)];
793
- };
794
- const lineTextOf = (planned, voices, bar) => (line) => {
795
- const segments = pipe(line, Array.filter(touches(bar)), Array.map(segmentOf(bar)));
796
- return pipe(Array.head(segments), Option.map((first) => ({
797
- text: `${planned.name}: ${cellsText(cellsOf(segments, bar, headOf(voices)))}`,
798
- continues: first.start > first.group.start
799
- })));
800
- };
801
- const continuedFirst = Order.mapInput(Order.Boolean, (voice) => !voice.continues);
802
- const voiceLinesOf = ({ plan, bar }) => (planned) => {
803
- const voices = pipe(Option.some(plan.drumVoices), Option.filter(() => planned.source.kind === "kit"));
804
- const texts = pipe(planned.lines, Array.map(lineTextOf(planned, voices, bar)), Array.getSomes);
805
- return pipe(Array.sort(texts, continuedFirst), Array.map((voice) => voice.text));
806
- };
807
- // src/entities/timeline/model/write.ts
808
- const SINGLE = 1;
809
- const INDENT = " ";
810
- const START = {
811
- meter: Option.none(),
812
- microseconds: Option.none()
813
- };
814
- const isRamp = (step) => Option.isSome(step.target);
815
- const stepText = (step) => {
816
- const ramp = Option.match(step.target, {
817
- onNone: () => "",
818
- onSome: (target) => ` -> ${bpmText(target)}`
819
- });
820
- return `${bpmText(step.microseconds)}${ramp} ${fractionOf(step.length)}`;
821
- };
822
- const tempoLineOf = (bar) => {
823
- if (bar.tempo.length <= SINGLE && !pipe(bar.tempo, Array.some(isRamp))) return Option.none();
824
- const steps = pipe(bar.tempo, Array.map(stepText));
825
- return Option.some(`tempo: ${Array.join(steps, ", ")}`);
826
- };
827
- const differs = (previous) => (current) => Option.match(previous, {
828
- onNone: () => true,
829
- onSome: (value) => value !== current
830
- });
831
- const headerTempoOf = (previous) => (bar) => pipe(Array.head(bar.tempo), Option.filter(() => bar.tempo.length === SINGLE && !pipe(bar.tempo, Array.some(isRamp))), Option.map((step) => step.microseconds), Option.filter(differs(previous.microseconds)), Option.map((microseconds) => `tempo ${bpmText(microseconds)}`), Option.toArray);
832
- const barHeadOf = (previous) => (bar) => {
833
- const meter = pipe(Option.some(bar.meter), Option.filter(differs(previous.meter)), Option.map((current) => `meter ${current}`), Option.toArray);
834
- const mark = pipe(Option.some(bar.marks), Option.filter(Array.isReadonlyArrayNonEmpty), Option.map((marks) => `mark ${quoted(Array.join(marks, " / "))}`), Option.toArray);
835
- return Array.join([
836
- "bar",
837
- ...meter,
838
- ...headerTempoOf(previous)(bar),
839
- ...mark,
840
- "{"
841
- ], " ");
842
- };
843
- const barBodyOf = (plan) => (bar) => [...Option.toArray(tempoLineOf(bar)), ...pipe(plan.parts, Array.flatMap((planned) => [
844
- ...voiceLinesOf({
845
- plan,
846
- bar
847
- })(planned),
848
- ...controlLinesOf(bar)(planned),
849
- ...automationLinesOf(bar)(planned)
850
- ]))];
851
- const afterBar = (bar) => ({
852
- meter: Option.some(bar.meter),
853
- microseconds: pipe(Array.last(bar.tempo), Option.map((step) => Option.getOrElse(step.target, () => step.microseconds)))
854
- });
855
- const walkStep = (plan) => ({ lines, previous }, bar) => ({
856
- lines: [
857
- ...lines,
858
- "",
859
- barHeadOf(previous)(bar),
860
- ...pipe(barBodyOf(plan)(bar), Array.map((line) => `${INDENT}${line}`)),
861
- "}"
862
- ],
863
- previous: afterBar(bar)
864
- });
865
- const instrumentLinesOf = (plan) => pipe(Array.fromIterable(plan.instruments), Array.map(([program, name]) => `instrument ${name} plugin gm program ${String(program)}`));
866
- const kitLinesOf = (plan) => {
867
- if (plan.drumVoices.size < SINGLE) return [];
868
- return [
869
- "kit gm-drums {",
870
- ...pipe(Array.fromIterable(plan.drumVoices.values()), Array.map((name) => `${INDENT}${name} ${quoted(`gm-drums/${name}.flac`)}`)),
871
- "}"
872
- ];
873
- };
874
- const sourceWordsOf = (planned) => {
875
- if (planned.source.kind === "kit") return ["kit gm-drums role drums"];
876
- return [`instrument ${planned.source.instrument}`];
877
- };
878
- const trackLineOf = (plan) => (planned) => Array.join([
879
- "track",
880
- planned.name,
881
- ...sourceWordsOf(planned),
882
- ...trackMixWords({
883
- mix: planned.mix,
884
- buses: plan.buses
885
- })
886
- ], " ");
887
- const headerOf = ({ plan, title }) => [
888
- `song ${quoted(title)}`,
889
- "",
890
- "plugin gm from \"./gm.ts\" { program: number = 0 }",
891
- "",
892
- ...instrumentLinesOf(plan),
893
- ...kitLinesOf(plan),
894
- "",
895
- ...pipe(plan.buses, Array.map(busLineOf)),
896
- ...pipe(plan.parts, Array.map(trackLineOf(plan)))
897
- ];
898
- const writeFumx = ({ timeline, title }) => {
899
- const plan = planOf(timeline);
900
- const bars = barsOf(timeline);
901
- const walked = Array.reduce(bars, {
902
- lines: headerOf({
903
- plan,
904
- title
905
- }),
906
- previous: START
907
- }, walkStep(plan));
908
- return {
909
- text: `${Array.join(walked.lines, "\n")}\n`,
910
- plan,
911
- bars
912
- };
913
- };
914
6
  // src/features/convert-midi/model/channel.ts
915
7
  const NONE$1 = 0;
916
8
  const NEXT$1 = 1;
@@ -1155,8 +247,8 @@ const timelineOf = (midi) => {
1155
247
  };
1156
248
  };
1157
249
  // src/features/convert-midi/model/convert.ts
1158
- const taggedError$1 = Schema.TaggedError;
1159
- var UnreadableMidi = class extends taggedError$1()("UnreadableMidi", { message: Schema.String }, { identifier: "UnreadableMidi" }) {};
250
+ const taggedError = Schema.TaggedError;
251
+ var UnreadableMidi = class extends taggedError()("UnreadableMidi", { message: Schema.String }, { identifier: "UnreadableMidi" }) {};
1160
252
  const midiToFumx = Effect.fn("midiToFumx")(function* convert(input) {
1161
253
  const midi = yield* Effect.try({
1162
254
  try: () => parseMidi(input.bytes),
@@ -1177,46 +269,17 @@ const midiToFumx = Effect.fn("midiToFumx")(function* convert(input) {
1177
269
  offGrid: timeline.offGrid
1178
270
  };
1179
271
  });
1180
- // src/app/round-trip.ts
1181
- const taggedError = Schema.TaggedError;
1182
- var InvalidOutput = class extends taggedError()("InvalidOutput", {
1183
- message: Schema.String,
1184
- text: Schema.String
1185
- }, { identifier: "InvalidOutput" }) {};
1186
- const issueText = (issue) => `${String(issue.line)}:${String(issue.column)} ${issue.message}`;
1187
- const roundTrip = Effect.fn("roundTrip")(function* check(path, fumx) {
1188
- const read = yield* readSong({
1189
- path,
1190
- read: () => Effect.succeed(fumx.text)
1191
- }).pipe(Effect.withSpan("readSong"));
1192
- if (read.status === "invalid") return yield* InvalidOutput.make({
1193
- message: pipe(read.issues, Array.map(issueText), Array.join("\n")),
1194
- text: fumx.text
1195
- });
1196
- const comparison = compareWithSong({
1197
- plan: fumx.plan,
1198
- bars: fumx.bars,
1199
- song: read.song
1200
- });
1201
- yield* Effect.annotateCurrentSpan({
1202
- matches: comparison.matches,
1203
- notes: comparison.notes.expected
1204
- });
1205
- return {
1206
- text: fumx.text,
1207
- comparison,
1208
- adjustments: { offGrid: fumx.offGrid }
1209
- };
272
+ // src/app/midi-to-fumx.ts
273
+ const convertMidiFile = Effect.fn("convertMidiFile")(function* convert(source) {
274
+ const fumx = yield* midiToFumx(source);
275
+ return yield* roundTrip(source.path, fumx);
1210
276
  });
1211
277
  // bin/midi-to-fumx.ts
1212
278
  convertMain({
1213
279
  name: "midi-to-fumx",
1214
280
  input: "A Standard MIDI File (.mid)",
1215
281
  source: "MIDI file",
1216
- convert: Effect.fn("convertMidiFile")(function* convert(source) {
1217
- const fumx = yield* midiToFumx(source);
1218
- return yield* roundTrip(source.path, fumx);
1219
- })
282
+ convert: convertMidiFile
1220
283
  });
1221
284
  export {};
1222
285