@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,747 @@
|
|
|
1
|
+
import { r as FumxTerminals, t as FumxGrammar } from "./grammar-86_uhiTo.mjs";
|
|
2
|
+
import { n as fractionOf, t as TICKS_PER_WHOLE } from "./ticks-CXehHP2w.mjs";
|
|
3
|
+
import { Array, Option, Order, Record, String as String$1, pipe } from "effect";
|
|
4
|
+
import { AstUtils, GrammarAST } from "langium";
|
|
5
|
+
import { Midi } from "tonal";
|
|
6
|
+
// src/entities/timeline/model/general-midi.ts
|
|
7
|
+
const PROGRAMS = [
|
|
8
|
+
"acoustic-grand-piano",
|
|
9
|
+
"bright-acoustic-piano",
|
|
10
|
+
"electric-grand-piano",
|
|
11
|
+
"honky-tonk-piano",
|
|
12
|
+
"electric-piano-1",
|
|
13
|
+
"electric-piano-2",
|
|
14
|
+
"harpsichord",
|
|
15
|
+
"clavinet",
|
|
16
|
+
"celesta",
|
|
17
|
+
"glockenspiel",
|
|
18
|
+
"music-box",
|
|
19
|
+
"vibraphone",
|
|
20
|
+
"marimba",
|
|
21
|
+
"xylophone",
|
|
22
|
+
"tubular-bells",
|
|
23
|
+
"dulcimer",
|
|
24
|
+
"drawbar-organ",
|
|
25
|
+
"percussive-organ",
|
|
26
|
+
"rock-organ",
|
|
27
|
+
"church-organ",
|
|
28
|
+
"reed-organ",
|
|
29
|
+
"accordion",
|
|
30
|
+
"harmonica",
|
|
31
|
+
"tango-accordion",
|
|
32
|
+
"acoustic-guitar-nylon",
|
|
33
|
+
"acoustic-guitar-steel",
|
|
34
|
+
"electric-guitar-jazz",
|
|
35
|
+
"electric-guitar-clean",
|
|
36
|
+
"electric-guitar-muted",
|
|
37
|
+
"overdriven-guitar",
|
|
38
|
+
"distortion-guitar",
|
|
39
|
+
"guitar-harmonics",
|
|
40
|
+
"acoustic-bass",
|
|
41
|
+
"electric-bass-finger",
|
|
42
|
+
"electric-bass-pick",
|
|
43
|
+
"fretless-bass",
|
|
44
|
+
"slap-bass-1",
|
|
45
|
+
"slap-bass-2",
|
|
46
|
+
"synth-bass-1",
|
|
47
|
+
"synth-bass-2",
|
|
48
|
+
"violin",
|
|
49
|
+
"viola",
|
|
50
|
+
"cello",
|
|
51
|
+
"contrabass",
|
|
52
|
+
"tremolo-strings",
|
|
53
|
+
"pizzicato-strings",
|
|
54
|
+
"orchestral-harp",
|
|
55
|
+
"timpani",
|
|
56
|
+
"string-ensemble-1",
|
|
57
|
+
"string-ensemble-2",
|
|
58
|
+
"synth-strings-1",
|
|
59
|
+
"synth-strings-2",
|
|
60
|
+
"choir-aahs",
|
|
61
|
+
"voice-oohs",
|
|
62
|
+
"synth-voice",
|
|
63
|
+
"orchestra-hit",
|
|
64
|
+
"trumpet",
|
|
65
|
+
"trombone",
|
|
66
|
+
"tuba",
|
|
67
|
+
"muted-trumpet",
|
|
68
|
+
"french-horn",
|
|
69
|
+
"brass-section",
|
|
70
|
+
"synth-brass-1",
|
|
71
|
+
"synth-brass-2",
|
|
72
|
+
"soprano-sax",
|
|
73
|
+
"alto-sax",
|
|
74
|
+
"tenor-sax",
|
|
75
|
+
"baritone-sax",
|
|
76
|
+
"oboe",
|
|
77
|
+
"english-horn",
|
|
78
|
+
"bassoon",
|
|
79
|
+
"clarinet",
|
|
80
|
+
"piccolo",
|
|
81
|
+
"flute",
|
|
82
|
+
"recorder",
|
|
83
|
+
"pan-flute",
|
|
84
|
+
"blown-bottle",
|
|
85
|
+
"shakuhachi",
|
|
86
|
+
"whistle",
|
|
87
|
+
"ocarina",
|
|
88
|
+
"lead-1-square",
|
|
89
|
+
"lead-2-sawtooth",
|
|
90
|
+
"lead-3-calliope",
|
|
91
|
+
"lead-4-chiff",
|
|
92
|
+
"lead-5-charang",
|
|
93
|
+
"lead-6-voice",
|
|
94
|
+
"lead-7-fifths",
|
|
95
|
+
"lead-8-bass-and-lead",
|
|
96
|
+
"pad-1-new-age",
|
|
97
|
+
"pad-2-warm",
|
|
98
|
+
"pad-3-polysynth",
|
|
99
|
+
"pad-4-choir",
|
|
100
|
+
"pad-5-bowed",
|
|
101
|
+
"pad-6-metallic",
|
|
102
|
+
"pad-7-halo",
|
|
103
|
+
"pad-8-sweep",
|
|
104
|
+
"fx-1-rain",
|
|
105
|
+
"fx-2-soundtrack",
|
|
106
|
+
"fx-3-crystal",
|
|
107
|
+
"fx-4-atmosphere",
|
|
108
|
+
"fx-5-brightness",
|
|
109
|
+
"fx-6-goblins",
|
|
110
|
+
"fx-7-echoes",
|
|
111
|
+
"fx-8-sci-fi",
|
|
112
|
+
"sitar",
|
|
113
|
+
"banjo",
|
|
114
|
+
"shamisen",
|
|
115
|
+
"koto",
|
|
116
|
+
"kalimba",
|
|
117
|
+
"bagpipe",
|
|
118
|
+
"fiddle",
|
|
119
|
+
"shanai",
|
|
120
|
+
"tinkle-bell",
|
|
121
|
+
"agogo",
|
|
122
|
+
"steel-drums",
|
|
123
|
+
"woodblock",
|
|
124
|
+
"taiko-drum",
|
|
125
|
+
"melodic-tom",
|
|
126
|
+
"synth-drum",
|
|
127
|
+
"reverse-cymbal",
|
|
128
|
+
"guitar-fret-noise",
|
|
129
|
+
"breath-noise",
|
|
130
|
+
"seashore",
|
|
131
|
+
"bird-tweet",
|
|
132
|
+
"telephone-ring",
|
|
133
|
+
"helicopter",
|
|
134
|
+
"applause",
|
|
135
|
+
"gunshot"
|
|
136
|
+
];
|
|
137
|
+
const DRUMS = [
|
|
138
|
+
"acoustic-bass-drum",
|
|
139
|
+
"bass-drum-1",
|
|
140
|
+
"side-stick",
|
|
141
|
+
"acoustic-snare",
|
|
142
|
+
"hand-clap",
|
|
143
|
+
"electric-snare",
|
|
144
|
+
"low-floor-tom",
|
|
145
|
+
"closed-hi-hat",
|
|
146
|
+
"high-floor-tom",
|
|
147
|
+
"pedal-hi-hat",
|
|
148
|
+
"low-tom",
|
|
149
|
+
"open-hi-hat",
|
|
150
|
+
"low-mid-tom",
|
|
151
|
+
"hi-mid-tom",
|
|
152
|
+
"crash-cymbal-1",
|
|
153
|
+
"high-tom",
|
|
154
|
+
"ride-cymbal-1",
|
|
155
|
+
"chinese-cymbal",
|
|
156
|
+
"ride-bell",
|
|
157
|
+
"tambourine",
|
|
158
|
+
"splash-cymbal",
|
|
159
|
+
"cowbell",
|
|
160
|
+
"crash-cymbal-2",
|
|
161
|
+
"vibraslap",
|
|
162
|
+
"ride-cymbal-2",
|
|
163
|
+
"hi-bongo",
|
|
164
|
+
"low-bongo",
|
|
165
|
+
"mute-hi-conga",
|
|
166
|
+
"open-hi-conga",
|
|
167
|
+
"low-conga",
|
|
168
|
+
"high-timbale",
|
|
169
|
+
"low-timbale",
|
|
170
|
+
"high-agogo",
|
|
171
|
+
"low-agogo",
|
|
172
|
+
"cabasa",
|
|
173
|
+
"maracas",
|
|
174
|
+
"short-whistle",
|
|
175
|
+
"long-whistle",
|
|
176
|
+
"short-guiro",
|
|
177
|
+
"long-guiro",
|
|
178
|
+
"claves",
|
|
179
|
+
"hi-wood-block",
|
|
180
|
+
"low-wood-block",
|
|
181
|
+
"mute-cuica",
|
|
182
|
+
"open-cuica",
|
|
183
|
+
"mute-triangle",
|
|
184
|
+
"open-triangle"
|
|
185
|
+
];
|
|
186
|
+
// src/entities/timeline/model/groups.ts
|
|
187
|
+
const NONE$4 = 0;
|
|
188
|
+
const NEXT$4 = 1;
|
|
189
|
+
const isDrumPart = (part) => part.channel === 9;
|
|
190
|
+
const chordKeyOf = (note) => `${String(note.tick)}:${String(note.end)}:${String(note.velocity)}:${String(note.release)}`;
|
|
191
|
+
const groupOf = (notes) => pipe(Array.head(notes), Option.map((first) => ({
|
|
192
|
+
start: first.tick,
|
|
193
|
+
end: first.end,
|
|
194
|
+
midis: pipe(notes, Array.map((note) => note.midi)),
|
|
195
|
+
velocity: first.velocity,
|
|
196
|
+
release: first.release,
|
|
197
|
+
lyric: Option.none()
|
|
198
|
+
})));
|
|
199
|
+
const stackedOf = (chord) => pipe(chord, Array.map((note, index) => ({
|
|
200
|
+
note,
|
|
201
|
+
layer: pipe(Array.take(chord, index), Array.countBy((earlier) => earlier.midi === note.midi))
|
|
202
|
+
})), Array.groupBy(({ layer }) => String(layer)), Record.values, Array.map((layer) => pipe(layer, Array.map(({ note }) => note))));
|
|
203
|
+
const chordsOf = (part) => {
|
|
204
|
+
if (isDrumPart(part)) return pipe(part.notes, Array.map((note) => [note]));
|
|
205
|
+
return pipe(part.notes, Array.groupBy(chordKeyOf), Record.values, Array.flatMap(stackedOf));
|
|
206
|
+
};
|
|
207
|
+
const byStartThenLonger = Order.combine(Order.mapInput(Order.Number, (group) => group.start), Order.mapInput(Order.flip(Order.Number), (group) => group.end));
|
|
208
|
+
const withLyrics = (part) => (groups) => pipe(groups, Array.map((group, index) => {
|
|
209
|
+
const leads = pipe(Array.get(groups, index - NEXT$4), Option.match({
|
|
210
|
+
onNone: () => true,
|
|
211
|
+
onSome: (previous) => previous.start !== group.start
|
|
212
|
+
}));
|
|
213
|
+
const lyric = pipe(Array.findFirst(part.lyrics, (candidate) => candidate.tick === group.start), Option.filter(() => leads), Option.map((found) => found.text));
|
|
214
|
+
return {
|
|
215
|
+
...group,
|
|
216
|
+
lyric
|
|
217
|
+
};
|
|
218
|
+
}));
|
|
219
|
+
const groupsOf = (part) => {
|
|
220
|
+
const groups = pipe(chordsOf(part), Array.map(groupOf), Array.getSomes);
|
|
221
|
+
return withLyrics(part)(Array.sort(groups, byStartThenLonger));
|
|
222
|
+
};
|
|
223
|
+
const endOfLine = (line) => Option.match(Array.last(line), {
|
|
224
|
+
onNone: () => NONE$4,
|
|
225
|
+
onSome: (group) => group.end
|
|
226
|
+
});
|
|
227
|
+
const placeGroup = (lines, group) => Option.match(Array.findFirstIndex(lines, (line) => endOfLine(line) <= group.start), {
|
|
228
|
+
onNone: () => [...lines, [group]],
|
|
229
|
+
onSome: (index) => pipe(lines, Array.map((line, position) => {
|
|
230
|
+
if (position === index) return [...line, group];
|
|
231
|
+
return line;
|
|
232
|
+
}))
|
|
233
|
+
});
|
|
234
|
+
const linesOf = (groups) => Array.reduce(groups, [], placeGroup);
|
|
235
|
+
// src/entities/timeline/model/names.ts
|
|
236
|
+
const FIRST_SUFFIX = 2;
|
|
237
|
+
const keywordsIn = (node) => new Set(AstUtils.streamAst(node).filter((child) => GrammarAST.isKeyword(child)).map((keyword) => keyword.value));
|
|
238
|
+
const grammar = FumxGrammar();
|
|
239
|
+
const allowedKeywords = pipe(grammar.rules, Array.findFirst((rule) => rule.name === "Name"), Option.match({
|
|
240
|
+
onNone: () => /* @__PURE__ */ new Set(),
|
|
241
|
+
onSome: keywordsIn
|
|
242
|
+
}));
|
|
243
|
+
const allKeywords = Array.fromIterable(keywordsIn(grammar));
|
|
244
|
+
const reserved = new Set(pipe(allKeywords, Array.filter((keyword) => !allowedKeywords.has(keyword))));
|
|
245
|
+
const otherTerminals = pipe(Record.toEntries(FumxTerminals), Array.filter(([name]) => name !== "ID"), Array.map(([, pattern]) => new RegExp(`^(?:${pattern.source})$`, "u")));
|
|
246
|
+
const identifier = new RegExp(`^(?:${FumxTerminals.ID.source})$`, "u");
|
|
247
|
+
const isUsable = (name) => identifier.test(name) && !reserved.has(name) && !pipe(otherTerminals, Array.some((pattern) => pattern.test(name)));
|
|
248
|
+
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, ""));
|
|
249
|
+
const nameFrom = (candidates) => pipe(candidates, Array.map(slugOf), Array.findFirst(isUsable), Option.getOrElse(() => "part"));
|
|
250
|
+
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)}`));
|
|
251
|
+
// src/entities/timeline/model/plan.ts
|
|
252
|
+
const NONE$3 = 0;
|
|
253
|
+
const NEXT$3 = 1;
|
|
254
|
+
const SHARED = 1;
|
|
255
|
+
const DEFAULT_PROGRAM = 0;
|
|
256
|
+
const drumNameOf = (midi) => Option.getOrElse(Array.get(DRUMS, midi - 35), () => `note-${String(midi)}`);
|
|
257
|
+
const programNameOf = (program) => Option.getOrElse(Array.get(PROGRAMS, program), () => `program-${String(program)}`);
|
|
258
|
+
const controllerKeyOf = ({ controller }) => {
|
|
259
|
+
if (controller.kind === "cc") return `cc ${String(controller.number)}`;
|
|
260
|
+
if (controller.kind === "pressure") return Option.match(controller.midi, {
|
|
261
|
+
onNone: () => "pressure",
|
|
262
|
+
onSome: (midi) => `pressure ${String(midi)}`
|
|
263
|
+
});
|
|
264
|
+
return controller.kind;
|
|
265
|
+
};
|
|
266
|
+
const isLastAtTick = (controls) => (index) => pipe(Option.all([Array.get(controls, index), Array.get(controls, index + NEXT$3)]), Option.match({
|
|
267
|
+
onNone: () => true,
|
|
268
|
+
onSome: ([control, next]) => next.tick !== control.tick || controllerKeyOf(next) !== controllerKeyOf(control)
|
|
269
|
+
}));
|
|
270
|
+
const byControllerThenTick = Order.combine(Order.mapInput(Order.String, controllerKeyOf), Order.mapInput(Order.Number, (control) => control.tick));
|
|
271
|
+
const controlsOf = (part) => {
|
|
272
|
+
const drumProgram = pipe(part.program, Option.filter(() => isDrumPart(part)), Option.map((value) => ({
|
|
273
|
+
tick: NONE$3,
|
|
274
|
+
controller: { kind: "program" },
|
|
275
|
+
value
|
|
276
|
+
})), Option.toArray);
|
|
277
|
+
const sorted = Array.sort([...drumProgram, ...part.controls], byControllerThenTick);
|
|
278
|
+
return pipe(sorted, Array.filter((_control, index) => isLastAtTick(sorted)(index)));
|
|
279
|
+
};
|
|
280
|
+
const programOf = (part) => Option.getOrElse(part.program, () => DEFAULT_PROGRAM);
|
|
281
|
+
const labelOf = (part) => Option.getOrElse(part.name, () => "");
|
|
282
|
+
const instrumentsOf = (parts) => new Map(pipe(parts, Array.filter((part) => !isDrumPart(part)), Array.map(programOf), Array.dedupe, Array.map((program) => [program, nameFrom([programNameOf(program)])])));
|
|
283
|
+
const drumVoicesOf = (parts) => {
|
|
284
|
+
const midis = pipe(parts, Array.filter(isDrumPart), Array.flatMap((part) => part.notes), Array.map((note) => note.midi), Array.dedupe);
|
|
285
|
+
return new Map(pipe(Array.sort(midis, Order.Number), Array.map((midi) => [midi, drumNameOf(midi)])));
|
|
286
|
+
};
|
|
287
|
+
const channelledOf = (shared) => (part) => {
|
|
288
|
+
const label = labelOf(part);
|
|
289
|
+
if (shared.has(label)) return `${label} ch${String(part.channel + NEXT$3)}`;
|
|
290
|
+
return label;
|
|
291
|
+
};
|
|
292
|
+
const fallbackOf = (part) => {
|
|
293
|
+
if (isDrumPart(part)) return "drums";
|
|
294
|
+
return programNameOf(programOf(part));
|
|
295
|
+
};
|
|
296
|
+
const candidatesOf = (shared) => (part) => [
|
|
297
|
+
channelledOf(shared)(part),
|
|
298
|
+
fallbackOf(part),
|
|
299
|
+
`track ${String(part.track)}`
|
|
300
|
+
];
|
|
301
|
+
const sharedLabelsOf = (parts) => new Set(pipe(parts, Array.groupBy(labelOf), Record.filter((same) => same.length > SHARED), Record.keys));
|
|
302
|
+
const sourceOf = (instruments) => (part) => {
|
|
303
|
+
if (isDrumPart(part)) return { kind: "kit" };
|
|
304
|
+
const program = programOf(part);
|
|
305
|
+
return {
|
|
306
|
+
kind: "instrument",
|
|
307
|
+
instrument: instruments.get(program) ?? "",
|
|
308
|
+
program
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
const namesOf = (planned) => new Set(pipe(planned, Array.map((done) => done.name)));
|
|
312
|
+
const UNMIXED = {
|
|
313
|
+
level: {
|
|
314
|
+
decibels: NONE$3,
|
|
315
|
+
pan: NONE$3,
|
|
316
|
+
muted: false
|
|
317
|
+
},
|
|
318
|
+
sends: [],
|
|
319
|
+
envelopes: []
|
|
320
|
+
};
|
|
321
|
+
const NO_PARTS = [];
|
|
322
|
+
const nextPart = (naming) => (planned, part) => {
|
|
323
|
+
const name = uniqueAmong(namesOf(planned))(nameFrom(naming.candidates(part)));
|
|
324
|
+
return Array.append(planned, {
|
|
325
|
+
part,
|
|
326
|
+
name,
|
|
327
|
+
source: sourceOf(naming.instruments)(part),
|
|
328
|
+
lines: linesOf(groupsOf(part)),
|
|
329
|
+
controls: controlsOf(part),
|
|
330
|
+
mix: naming.mixes.get(part.track) ?? UNMIXED
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
const busesOf = ({ taken, buses }) => {
|
|
334
|
+
const used = new Set(taken);
|
|
335
|
+
const named = [];
|
|
336
|
+
for (const [index, bus] of buses.entries()) {
|
|
337
|
+
const name = uniqueAmong(used)(nameFrom([...Option.toArray(bus.name), `bus ${String(index + NEXT$3)}`]));
|
|
338
|
+
used.add(name);
|
|
339
|
+
named.push({
|
|
340
|
+
name,
|
|
341
|
+
level: bus.level
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return named;
|
|
345
|
+
};
|
|
346
|
+
const planOf = (timeline) => {
|
|
347
|
+
const instruments = instrumentsOf(timeline.parts);
|
|
348
|
+
const candidates = candidatesOf(sharedLabelsOf(timeline.parts));
|
|
349
|
+
const parts = Array.reduce(timeline.parts, NO_PARTS, nextPart({
|
|
350
|
+
instruments,
|
|
351
|
+
candidates,
|
|
352
|
+
mixes: timeline.mix.tracks
|
|
353
|
+
}));
|
|
354
|
+
return {
|
|
355
|
+
parts,
|
|
356
|
+
buses: busesOf({
|
|
357
|
+
taken: namesOf(parts),
|
|
358
|
+
buses: timeline.mix.buses
|
|
359
|
+
}),
|
|
360
|
+
instruments,
|
|
361
|
+
drumVoices: drumVoicesOf(timeline.parts)
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
// src/entities/timeline/model/tempo-units.ts
|
|
365
|
+
const MICROSECONDS_PER_MINUTE = 6e7;
|
|
366
|
+
const bpmOf = (microseconds) => MICROSECONDS_PER_MINUTE / microseconds;
|
|
367
|
+
const microsecondsOf = (bpm) => Math.round(MICROSECONDS_PER_MINUTE / bpm);
|
|
368
|
+
// src/entities/timeline/model/events.ts
|
|
369
|
+
const NO_MIX = {
|
|
370
|
+
tracks: /* @__PURE__ */ new Map(),
|
|
371
|
+
buses: []
|
|
372
|
+
};
|
|
373
|
+
const byTick = Order.mapInput(Order.Number, (timed) => timed.tick);
|
|
374
|
+
const sortedByTick = (items) => Array.sort(items, byTick);
|
|
375
|
+
const byTickThenPitch = Order.combine(Order.mapInput(Order.Number, (note) => note.tick), Order.mapInput(Order.Number, (note) => note.midi));
|
|
376
|
+
const sortedNotes = (notes) => Array.sort(notes, byTickThenPitch);
|
|
377
|
+
// src/entities/timeline/model/cells.ts
|
|
378
|
+
const NONE$2 = 0;
|
|
379
|
+
const FULL$1 = 127;
|
|
380
|
+
const SHARE_DECIMALS = 3;
|
|
381
|
+
const SEMITONE_DECIMALS = 12;
|
|
382
|
+
const LAST = 1;
|
|
383
|
+
const durationText = (length) => {
|
|
384
|
+
if (length === NONE$2) return "0/1";
|
|
385
|
+
return fractionOf(length);
|
|
386
|
+
};
|
|
387
|
+
const restCell = (length) => ({
|
|
388
|
+
head: "rest",
|
|
389
|
+
attributes: [],
|
|
390
|
+
length
|
|
391
|
+
});
|
|
392
|
+
const restsOf = (length) => {
|
|
393
|
+
if (length > NONE$2) return [restCell(length)];
|
|
394
|
+
return [];
|
|
395
|
+
};
|
|
396
|
+
const isRest = (cell) => cell.head === "rest";
|
|
397
|
+
const mergeRests = (merged, cell) => pipe(Array.last(merged), Option.filter((previous) => isRest(previous) && isRest(cell)), Option.match({
|
|
398
|
+
onNone: () => [...merged, cell],
|
|
399
|
+
onSome: (previous) => [...Array.dropRight(merged, LAST), restCell(previous.length + cell.length)]
|
|
400
|
+
}));
|
|
401
|
+
const NO_CELLS = [];
|
|
402
|
+
const cellText = (cell) => Array.join([
|
|
403
|
+
cell.head,
|
|
404
|
+
durationText(cell.length),
|
|
405
|
+
...cell.attributes
|
|
406
|
+
], " ");
|
|
407
|
+
const cellsText = (cells) => pipe(Array.reduce(cells, NO_CELLS, mergeRests), Array.map(cellText), Array.join(", "));
|
|
408
|
+
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`))}"`;
|
|
409
|
+
const shareText = (value) => String(Number((value / FULL$1).toFixed(SHARE_DECIMALS)));
|
|
410
|
+
const semitoneText = (value) => {
|
|
411
|
+
const text = String(Number(value.toFixed(SEMITONE_DECIMALS)));
|
|
412
|
+
if (value > NONE$2) return `+${text}st`;
|
|
413
|
+
return `${text}st`;
|
|
414
|
+
};
|
|
415
|
+
const pitchText = (midi) => Midi.midiToNoteName(midi, { sharps: true });
|
|
416
|
+
// src/entities/timeline/model/layout.ts
|
|
417
|
+
const NONE$1 = 0;
|
|
418
|
+
const NEXT$2 = 1;
|
|
419
|
+
const QUARTER = 4;
|
|
420
|
+
const DEFAULT_METER = {
|
|
421
|
+
numerator: QUARTER,
|
|
422
|
+
denominator: QUARTER
|
|
423
|
+
};
|
|
424
|
+
const DEFAULT_MICROSECONDS = 5e5;
|
|
425
|
+
const MAX_DECIMALS = 9;
|
|
426
|
+
const endOfSpan = (span) => span.start + span.length;
|
|
427
|
+
const latestAt = (tick) => (items) => pipe(items, Array.filter((item) => item.tick <= tick), Array.last);
|
|
428
|
+
const lengthOf = (signature) => TICKS_PER_WHOLE * signature.numerator / signature.denominator;
|
|
429
|
+
const meterText = (signature) => (length) => {
|
|
430
|
+
const beats = length * signature.denominator / TICKS_PER_WHOLE;
|
|
431
|
+
if (Number.isInteger(beats)) return `${String(beats)}/${String(signature.denominator)}`;
|
|
432
|
+
return fractionOf(length);
|
|
433
|
+
};
|
|
434
|
+
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) => ({
|
|
435
|
+
start,
|
|
436
|
+
end: next.tick,
|
|
437
|
+
target
|
|
438
|
+
})))))));
|
|
439
|
+
const interpolated = (ramp) => (tick) => {
|
|
440
|
+
const from = bpmOf(ramp.start.microseconds);
|
|
441
|
+
const to = bpmOf(ramp.target);
|
|
442
|
+
const share = (tick - ramp.start.tick) / (ramp.end - ramp.start.tick);
|
|
443
|
+
return microsecondsOf(from + (to - from) * share);
|
|
444
|
+
};
|
|
445
|
+
const rampedAt = (tempos) => (tick, at) => pipe(rampAt(tempos)(tick), Option.map((ramp) => interpolated(ramp)(at)));
|
|
446
|
+
const steadyAt = (tempos) => (tick) => pipe(latestAt(tick)(tempos), Option.match({
|
|
447
|
+
onNone: () => DEFAULT_MICROSECONDS,
|
|
448
|
+
onSome: (tempo) => tempo.microseconds
|
|
449
|
+
}));
|
|
450
|
+
const tempoAt = (tempos) => (tick) => Option.getOrElse(rampedAt(tempos)(tick, tick), () => steadyAt(tempos)(tick));
|
|
451
|
+
const tempoStepsOf = (tempos) => (bar) => {
|
|
452
|
+
const end = endOfSpan(bar);
|
|
453
|
+
const points = [bar.start, ...pipe(tempos, Array.filter((tempo) => tempo.tick > bar.start && tempo.tick < end), Array.map((tempo) => tempo.tick), Array.dedupe)];
|
|
454
|
+
return pipe(points, Array.map((tick, index) => {
|
|
455
|
+
const stepEnd = Option.getOrElse(Array.get(points, index + NEXT$2), () => end);
|
|
456
|
+
return {
|
|
457
|
+
offset: tick - bar.start,
|
|
458
|
+
length: stepEnd - tick,
|
|
459
|
+
microseconds: tempoAt(tempos)(tick),
|
|
460
|
+
target: rampedAt(tempos)(tick, stepEnd)
|
|
461
|
+
};
|
|
462
|
+
}));
|
|
463
|
+
};
|
|
464
|
+
const marksOf = (markers) => (bar) => pipe(markers, Array.filter((marker) => marker.tick >= bar.start && marker.tick < endOfSpan(bar)), Array.map((marker) => marker.text));
|
|
465
|
+
const spanAt = (meters) => (start) => {
|
|
466
|
+
const signature = Option.getOrElse(latestAt(start)(meters), () => DEFAULT_METER);
|
|
467
|
+
const full = start + lengthOf(signature);
|
|
468
|
+
return {
|
|
469
|
+
start,
|
|
470
|
+
length: pipe(Array.findFirst(meters, (meter) => meter.tick > start), Option.match({
|
|
471
|
+
onNone: () => full,
|
|
472
|
+
onSome: (meter) => Math.min(meter.tick, full)
|
|
473
|
+
})) - start,
|
|
474
|
+
signature
|
|
475
|
+
};
|
|
476
|
+
};
|
|
477
|
+
const barsOf = (timeline) => Array.unfold({
|
|
478
|
+
start: NONE$1,
|
|
479
|
+
first: true
|
|
480
|
+
}, (cursor) => {
|
|
481
|
+
if (!cursor.first && cursor.start >= timeline.end) return Option.none();
|
|
482
|
+
const span = spanAt(timeline.meters)(cursor.start);
|
|
483
|
+
const bar = {
|
|
484
|
+
start: span.start,
|
|
485
|
+
length: span.length,
|
|
486
|
+
meter: meterText(span.signature)(span.length),
|
|
487
|
+
tempo: tempoStepsOf(timeline.tempos)(span),
|
|
488
|
+
marks: marksOf(timeline.markers)(span)
|
|
489
|
+
};
|
|
490
|
+
return Option.some([bar, {
|
|
491
|
+
start: endOfSpan(span),
|
|
492
|
+
first: false
|
|
493
|
+
}]);
|
|
494
|
+
});
|
|
495
|
+
const bpmText = (microseconds) => {
|
|
496
|
+
const exact = bpmOf(microseconds);
|
|
497
|
+
return `${pipe(Array.range(NONE$1, MAX_DECIMALS), Array.map((decimals) => String(Number(exact.toFixed(decimals)))), Array.findFirst((candidate) => microsecondsOf(Number(candidate)) === microseconds), Option.getOrElse(() => String(exact)))}bpm`;
|
|
498
|
+
};
|
|
499
|
+
// src/entities/timeline/model/control-lines.ts
|
|
500
|
+
const NEXT$1 = 1;
|
|
501
|
+
const valueText = (control) => {
|
|
502
|
+
if (control.controller.kind === "bend") return semitoneText(control.value);
|
|
503
|
+
return String(control.value);
|
|
504
|
+
};
|
|
505
|
+
const headOf$1 = (planned) => ({ controller }) => {
|
|
506
|
+
if (controller.kind === "pressure") return Option.match(controller.midi, {
|
|
507
|
+
onNone: () => `${planned.name}.pressure`,
|
|
508
|
+
onSome: (midi) => `${planned.name}.pressure ${pitchText(midi)}`
|
|
509
|
+
});
|
|
510
|
+
return `${planned.name}.${controllerKeyOf({ controller })}`;
|
|
511
|
+
};
|
|
512
|
+
const cellsOf$1 = (bar) => (controls) => {
|
|
513
|
+
const lead = pipe(Array.head(controls), Option.map((first) => first.tick - bar.start), Option.toArray, Array.flatMap(restsOf));
|
|
514
|
+
const steps = pipe(controls, Array.map((control, index) => ({
|
|
515
|
+
head: valueText(control),
|
|
516
|
+
attributes: [],
|
|
517
|
+
length: pipe(Array.get(controls, index + NEXT$1), Option.match({
|
|
518
|
+
onNone: () => endOfSpan(bar),
|
|
519
|
+
onSome: (next) => next.tick
|
|
520
|
+
})) - control.tick
|
|
521
|
+
})));
|
|
522
|
+
return [...lead, ...steps];
|
|
523
|
+
};
|
|
524
|
+
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);
|
|
525
|
+
// src/entities/timeline/model/mix-lines.ts
|
|
526
|
+
const DECIMALS = 1;
|
|
527
|
+
const PERCENT = 100;
|
|
528
|
+
const NONE = 0;
|
|
529
|
+
const NEXT = 1;
|
|
530
|
+
const amountText = (value, unit) => {
|
|
531
|
+
const text = Number(value.toFixed(DECIMALS));
|
|
532
|
+
if (text > NONE) return `+${String(text)}${unit}`;
|
|
533
|
+
return `${String(text)}${unit}`;
|
|
534
|
+
};
|
|
535
|
+
const UNITS = {
|
|
536
|
+
volume: (decibels) => amountText(decibels, "dB"),
|
|
537
|
+
pan: (pan) => amountText(pan * PERCENT, "%")
|
|
538
|
+
};
|
|
539
|
+
const levelWords = (level) => [
|
|
540
|
+
...pipe(Option.some(level.decibels), Option.filter((decibels) => UNITS.volume(decibels) !== UNITS.volume(NONE)), Option.map((decibels) => `volume ${UNITS.volume(decibels)}`), Option.toArray),
|
|
541
|
+
...pipe(Option.some(level.pan), Option.filter((pan) => UNITS.pan(pan) !== UNITS.pan(NONE)), Option.map((pan) => `pan ${UNITS.pan(pan)}`), Option.toArray),
|
|
542
|
+
...pipe(Option.some("mute"), Option.filter(() => level.muted), Option.toArray)
|
|
543
|
+
];
|
|
544
|
+
const trackMixWords = ({ mix, buses }) => [...levelWords(mix.level), ...pipe(mix.sends, Array.filter((send) => send.amount > NONE), Array.flatMap((send) => pipe(Array.get(buses, send.bus), Option.map((bus) => `send ${bus.name} ${amountText(send.amount * PERCENT, "%")}`), Option.toArray)))];
|
|
545
|
+
const busLineOf = (bus) => Array.join([
|
|
546
|
+
"bus",
|
|
547
|
+
bus.name,
|
|
548
|
+
...levelWords(bus.level)
|
|
549
|
+
], " ");
|
|
550
|
+
const valueAt = (points) => (tick) => {
|
|
551
|
+
const before = pipe(points, Array.filter((point) => point.tick <= tick), Array.last);
|
|
552
|
+
const after = pipe(points, Array.findFirst((point) => point.tick > tick));
|
|
553
|
+
return Option.match(before, {
|
|
554
|
+
onNone: () => Option.match(after, {
|
|
555
|
+
onNone: () => NONE,
|
|
556
|
+
onSome: (point) => point.value
|
|
557
|
+
}),
|
|
558
|
+
onSome: (left) => Option.match(after, {
|
|
559
|
+
onNone: () => left.value,
|
|
560
|
+
onSome: (right) => left.value + (right.value - left.value) * (tick - left.tick) / (right.tick - left.tick)
|
|
561
|
+
})
|
|
562
|
+
});
|
|
563
|
+
};
|
|
564
|
+
const rampOf = (bar, name) => (envelope) => {
|
|
565
|
+
const at = valueAt(envelope.points);
|
|
566
|
+
const unit = UNITS[envelope.parameter];
|
|
567
|
+
const from = unit(at(bar.start));
|
|
568
|
+
const to = unit(at(endOfSpan(bar)));
|
|
569
|
+
return pipe(Option.some(`automate ${name}.${envelope.parameter} ${from} -> ${to} over 1bar`), Option.filter(() => from !== to));
|
|
570
|
+
};
|
|
571
|
+
const automationLinesOf = (bar) => (planned) => pipe(planned.mix.envelopes, Array.filter((envelope) => Array.length(envelope.points) > NEXT), Array.map(rampOf(bar, planned.name)), Array.getSomes);
|
|
572
|
+
// src/entities/timeline/model/voice-lines.ts
|
|
573
|
+
const FULL = 127;
|
|
574
|
+
const DEFAULT_RELEASE = 64;
|
|
575
|
+
const SINGLE$1 = 1;
|
|
576
|
+
const touches = (bar) => (group) => {
|
|
577
|
+
if (group.end === group.start) return group.start >= bar.start && group.start < endOfSpan(bar);
|
|
578
|
+
return group.start < endOfSpan(bar) && group.end > bar.start;
|
|
579
|
+
};
|
|
580
|
+
const segmentOf = (bar) => (group) => ({
|
|
581
|
+
group,
|
|
582
|
+
start: Math.max(group.start, bar.start),
|
|
583
|
+
end: Math.min(group.end, endOfSpan(bar))
|
|
584
|
+
});
|
|
585
|
+
const pitchesText = (midis) => {
|
|
586
|
+
if (midis.length === SINGLE$1) return Array.join(pipe(midis, Array.map(pitchText)), "");
|
|
587
|
+
return `[${Array.join(pipe(midis, Array.map(pitchText)), " ")}]`;
|
|
588
|
+
};
|
|
589
|
+
const headOf = (voices) => (group) => Option.match(voices, {
|
|
590
|
+
onNone: () => pitchesText(group.midis),
|
|
591
|
+
onSome: (map) => pipe(Array.head(group.midis), Option.flatMap((midi) => Option.fromNullishOr(map.get(midi))), Option.getOrElse(() => ""))
|
|
592
|
+
});
|
|
593
|
+
const when = (condition, text) => {
|
|
594
|
+
if (condition) return [text];
|
|
595
|
+
return [];
|
|
596
|
+
};
|
|
597
|
+
const attributesOf = ({ group, start, end }) => {
|
|
598
|
+
const last = end === group.end;
|
|
599
|
+
return [
|
|
600
|
+
...when(group.velocity !== FULL, `vel ${shareText(group.velocity)}`),
|
|
601
|
+
...when(last && group.release !== DEFAULT_RELEASE, `off ${shareText(group.release)}`),
|
|
602
|
+
...when(!last, "tie"),
|
|
603
|
+
...pipe(group.lyric, Option.filter(() => start === group.start), Option.map((text) => `lyric ${quoted(text)}`), Option.toArray)
|
|
604
|
+
];
|
|
605
|
+
};
|
|
606
|
+
const cellsOf = (segments, bar, head) => {
|
|
607
|
+
const placed = Array.reduce(segments, {
|
|
608
|
+
cells: [],
|
|
609
|
+
cursor: bar.start
|
|
610
|
+
}, ({ cells, cursor }, segment) => ({
|
|
611
|
+
cells: [
|
|
612
|
+
...cells,
|
|
613
|
+
...restsOf(segment.start - cursor),
|
|
614
|
+
{
|
|
615
|
+
head: head(segment.group),
|
|
616
|
+
attributes: attributesOf(segment),
|
|
617
|
+
length: segment.end - segment.start
|
|
618
|
+
}
|
|
619
|
+
],
|
|
620
|
+
cursor: segment.end
|
|
621
|
+
}));
|
|
622
|
+
return [...placed.cells, ...restsOf(endOfSpan(bar) - placed.cursor)];
|
|
623
|
+
};
|
|
624
|
+
const lineTextOf = (planned, voices, bar) => (line) => {
|
|
625
|
+
const segments = pipe(line, Array.filter(touches(bar)), Array.map(segmentOf(bar)));
|
|
626
|
+
return pipe(Array.head(segments), Option.map((first) => ({
|
|
627
|
+
text: `${planned.name}: ${cellsText(cellsOf(segments, bar, headOf(voices)))}`,
|
|
628
|
+
continues: first.start > first.group.start
|
|
629
|
+
})));
|
|
630
|
+
};
|
|
631
|
+
const continuedFirst = Order.mapInput(Order.Boolean, (voice) => !voice.continues);
|
|
632
|
+
const voiceLinesOf = ({ plan, bar }) => (planned) => {
|
|
633
|
+
const voices = pipe(Option.some(plan.drumVoices), Option.filter(() => planned.source.kind === "kit"));
|
|
634
|
+
const texts = pipe(planned.lines, Array.map(lineTextOf(planned, voices, bar)), Array.getSomes);
|
|
635
|
+
return pipe(Array.sort(texts, continuedFirst), Array.map((voice) => voice.text));
|
|
636
|
+
};
|
|
637
|
+
// src/entities/timeline/model/write.ts
|
|
638
|
+
const SINGLE = 1;
|
|
639
|
+
const INDENT = " ";
|
|
640
|
+
const START = {
|
|
641
|
+
meter: Option.none(),
|
|
642
|
+
microseconds: Option.none()
|
|
643
|
+
};
|
|
644
|
+
const isRamp = (step) => Option.isSome(step.target);
|
|
645
|
+
const stepText = (step) => {
|
|
646
|
+
const ramp = Option.match(step.target, {
|
|
647
|
+
onNone: () => "",
|
|
648
|
+
onSome: (target) => ` -> ${bpmText(target)}`
|
|
649
|
+
});
|
|
650
|
+
return `${bpmText(step.microseconds)}${ramp} ${fractionOf(step.length)}`;
|
|
651
|
+
};
|
|
652
|
+
const isSteady = (bar) => bar.tempo.length <= SINGLE && !pipe(bar.tempo, Array.some(isRamp));
|
|
653
|
+
const tempoLineOf = (bar) => {
|
|
654
|
+
if (isSteady(bar)) return Option.none();
|
|
655
|
+
const steps = pipe(bar.tempo, Array.map(stepText));
|
|
656
|
+
return Option.some(`tempo: ${Array.join(steps, ", ")}`);
|
|
657
|
+
};
|
|
658
|
+
const differs = (previous) => (current) => Option.match(previous, {
|
|
659
|
+
onNone: () => true,
|
|
660
|
+
onSome: (value) => value !== current
|
|
661
|
+
});
|
|
662
|
+
const headerTempoOf = (previous) => (bar) => pipe(Array.head(bar.tempo), Option.filter(() => isSteady(bar)), Option.map((step) => step.microseconds), Option.filter(differs(previous.microseconds)), Option.map((microseconds) => `tempo ${bpmText(microseconds)}`), Option.toArray);
|
|
663
|
+
const barHeadOf = (previous) => (bar) => {
|
|
664
|
+
const meter = pipe(Option.some(bar.meter), Option.filter(differs(previous.meter)), Option.map((current) => `meter ${current}`), Option.toArray);
|
|
665
|
+
const mark = pipe(Option.some(bar.marks), Option.filter(Array.isReadonlyArrayNonEmpty), Option.map((marks) => `mark ${quoted(Array.join(marks, " / "))}`), Option.toArray);
|
|
666
|
+
return Array.join([
|
|
667
|
+
"bar",
|
|
668
|
+
...meter,
|
|
669
|
+
...headerTempoOf(previous)(bar),
|
|
670
|
+
...mark,
|
|
671
|
+
"{"
|
|
672
|
+
], " ");
|
|
673
|
+
};
|
|
674
|
+
const barBodyOf = (plan) => (bar) => [...Option.toArray(tempoLineOf(bar)), ...pipe(plan.parts, Array.flatMap((planned) => [
|
|
675
|
+
...voiceLinesOf({
|
|
676
|
+
plan,
|
|
677
|
+
bar
|
|
678
|
+
})(planned),
|
|
679
|
+
...controlLinesOf(bar)(planned),
|
|
680
|
+
...automationLinesOf(bar)(planned)
|
|
681
|
+
]))];
|
|
682
|
+
const afterBar = (bar) => ({
|
|
683
|
+
meter: Option.some(bar.meter),
|
|
684
|
+
microseconds: pipe(Array.last(bar.tempo), Option.map((step) => Option.getOrElse(step.target, () => step.microseconds)))
|
|
685
|
+
});
|
|
686
|
+
const walkStep = (plan) => ({ lines, previous }, bar) => ({
|
|
687
|
+
lines: [
|
|
688
|
+
...lines,
|
|
689
|
+
"",
|
|
690
|
+
barHeadOf(previous)(bar),
|
|
691
|
+
...pipe(barBodyOf(plan)(bar), Array.map((line) => `${INDENT}${line}`)),
|
|
692
|
+
"}"
|
|
693
|
+
],
|
|
694
|
+
previous: afterBar(bar)
|
|
695
|
+
});
|
|
696
|
+
const instrumentLinesOf = (plan) => pipe(Array.fromIterable(plan.instruments), Array.map(([program, name]) => `instrument ${name} plugin gm program ${String(program)}`));
|
|
697
|
+
const kitLinesOf = (plan) => {
|
|
698
|
+
if (plan.drumVoices.size < SINGLE) return [];
|
|
699
|
+
return [
|
|
700
|
+
"kit gm-drums {",
|
|
701
|
+
...pipe(Array.fromIterable(plan.drumVoices.values()), Array.map((name) => `${INDENT}${name} ${quoted(`gm-drums/${name}.flac`)}`)),
|
|
702
|
+
"}"
|
|
703
|
+
];
|
|
704
|
+
};
|
|
705
|
+
const sourceWordsOf = (planned) => {
|
|
706
|
+
if (planned.source.kind === "kit") return ["kit gm-drums role drums"];
|
|
707
|
+
return [`instrument ${planned.source.instrument}`];
|
|
708
|
+
};
|
|
709
|
+
const trackLineOf = (plan) => (planned) => Array.join([
|
|
710
|
+
"track",
|
|
711
|
+
planned.name,
|
|
712
|
+
...sourceWordsOf(planned),
|
|
713
|
+
...trackMixWords({
|
|
714
|
+
mix: planned.mix,
|
|
715
|
+
buses: plan.buses
|
|
716
|
+
})
|
|
717
|
+
], " ");
|
|
718
|
+
const headerOf = ({ plan, title }) => [
|
|
719
|
+
`song ${quoted(title)}`,
|
|
720
|
+
"",
|
|
721
|
+
"plugin gm from \"./gm.ts\" { program: number = 0 }",
|
|
722
|
+
"",
|
|
723
|
+
...instrumentLinesOf(plan),
|
|
724
|
+
...kitLinesOf(plan),
|
|
725
|
+
"",
|
|
726
|
+
...pipe(plan.buses, Array.map(busLineOf)),
|
|
727
|
+
...pipe(plan.parts, Array.map(trackLineOf(plan)))
|
|
728
|
+
];
|
|
729
|
+
const writeFumx = ({ timeline, title }) => {
|
|
730
|
+
const plan = planOf(timeline);
|
|
731
|
+
const bars = barsOf(timeline);
|
|
732
|
+
const walked = Array.reduce(bars, {
|
|
733
|
+
lines: headerOf({
|
|
734
|
+
plan,
|
|
735
|
+
title
|
|
736
|
+
}),
|
|
737
|
+
previous: START
|
|
738
|
+
}, walkStep(plan));
|
|
739
|
+
return {
|
|
740
|
+
text: `${Array.join(walked.lines, "\n")}\n`,
|
|
741
|
+
plan,
|
|
742
|
+
bars
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
export { microsecondsOf as a, sortedNotes as i, NO_MIX as n, sortedByTick as r, writeFumx as t };
|
|
746
|
+
|
|
747
|
+
//# sourceMappingURL=write-CuDbIkpM.mjs.map
|