@r_masseater/i68 0.0.0 → 0.2.0
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/LICENSE +87 -0
- package/README.md +134 -1
- package/dist/app-J9_4mtbE.mjs +7 -0
- package/dist/app-J9_4mtbE.mjs.map +1 -0
- package/dist/cli-CzV_7HHU.mjs +15 -0
- package/dist/cli-CzV_7HHU.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +9 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/habits.d.mts +72 -0
- package/dist/habits.mjs +98 -0
- package/dist/habits.mjs.map +1 -0
- package/dist/index-5D8Rm7JG.d.mts +48 -0
- package/dist/index-DB7buWb9.d.mts +49 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +3 -0
- package/dist/mix-facts-CvX18d2q.mjs +6997 -0
- package/dist/mix-facts-CvX18d2q.mjs.map +1 -0
- package/dist/presets.d.mts +36 -0
- package/dist/presets.mjs +802 -0
- package/dist/presets.mjs.map +1 -0
- package/dist/section-C9JQ1-aJ.mjs +388 -0
- package/dist/section-C9JQ1-aJ.mjs.map +1 -0
- package/dist/style-rules-gR1Cixel.d.mts +132 -0
- package/dist/vite.d.mts +7 -0
- package/dist/vite.mjs +1 -0
- package/package.json +87 -7
- package/skills/lint-songs/SKILL.md +51 -0
- package/skills/use-i68-presets/SKILL.md +57 -0
package/dist/presets.mjs
ADDED
|
@@ -0,0 +1,802 @@
|
|
|
1
|
+
import { n as defineRule, t as definePlugin } from "./app-J9_4mtbE.mjs";
|
|
2
|
+
import { A as tracksOf, C as neighborsOf, D as sortByPitch, E as reporterOf, O as soundingAt, S as lowest, T as overlappingPairs, _ as pitchClassOf, a as StyleRulesSchema, b as highest, c as mixKeyOf, d as bach_chorales_default, f as progressionOf, g as nameOf, h as midiOf, i as HABIT_KINDS, k as topLineOf, m as keysOf, n as placeIn, p as keyAt, r as trackKeyOf, s as subjectKeyOf, t as mixFactsOf, u as longestContext, v as MELODIC, w as onsetsOf, x as isPitched, y as hasRole } from "./mix-facts-CvX18d2q.mjs";
|
|
3
|
+
import { Array, Match, Number, Option, Order, Predicate, Record, String as String$1, pipe } from "effect";
|
|
4
|
+
import { TICKS_PER_WHOLE } from "@r_masseater/song-format";
|
|
5
|
+
import { Chord } from "tonal";
|
|
6
|
+
// src/app/presets/shared/lib/options.ts
|
|
7
|
+
const numberOption = ({ key, fallback }) => (options) => pipe(Option.fromNullishOr(options[key]), Option.filter(Predicate.isNumber), Option.getOrElse(() => fallback));
|
|
8
|
+
// src/app/presets/features/check-harmony/model/chord-above-melody.ts
|
|
9
|
+
const UNISON$1 = 0;
|
|
10
|
+
const within = numberOption({
|
|
11
|
+
key: "within",
|
|
12
|
+
fallback: UNISON$1
|
|
13
|
+
});
|
|
14
|
+
const isMelody = hasRole(["melody"]);
|
|
15
|
+
const isHarmony = hasRole(["harmony"]);
|
|
16
|
+
const placementOf = (distance, room) => {
|
|
17
|
+
if (distance < UNISON$1) return Option.some("above");
|
|
18
|
+
if (distance > UNISON$1 && distance <= room) return Option.some("just below");
|
|
19
|
+
return Option.none();
|
|
20
|
+
};
|
|
21
|
+
const checkPair$2 = (report, room) => (pair) => {
|
|
22
|
+
const parts = Option.all({
|
|
23
|
+
melody: pipe(pair, Array.findFirst(isMelody)),
|
|
24
|
+
chord: pipe(pair, Array.findFirst(isHarmony))
|
|
25
|
+
});
|
|
26
|
+
for (const { melody, chord } of Option.toArray(parts)) for (const where of Option.toArray(placementOf(melody.midi - chord.midi, room))) report(`${String(chord.line)}:${String(chord.column)}:${String(chord.bar)}`, {
|
|
27
|
+
line: chord.line,
|
|
28
|
+
column: chord.column,
|
|
29
|
+
message: `${chord.spelling} in ${chord.track} sits ${where} the melody note ${melody.spelling}`,
|
|
30
|
+
detail: "Keep the chord below the melody with some room between them"
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const isPart = (sounding) => isMelody(sounding) || isHarmony(sounding);
|
|
34
|
+
const chordAboveMelody = defineRule({
|
|
35
|
+
meta: { description: "Chord parts stay below the lead melody" },
|
|
36
|
+
check: (context) => {
|
|
37
|
+
const check = checkPair$2(reporterOf(context), within(context.options));
|
|
38
|
+
for (const pair of overlappingPairs(pipe(context.soundings, Array.filter(isPart)))) check(pair);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
// src/app/presets/features/check-harmony/model/crowded-low-mids.ts
|
|
42
|
+
const SIXTEENTH = TICKS_PER_WHOLE / 16;
|
|
43
|
+
const LOW_MID_FLOOR = 45;
|
|
44
|
+
const BASS_FLOOR = 40;
|
|
45
|
+
const LOW_MID_CEILING = 59;
|
|
46
|
+
const maxNotes = numberOption({
|
|
47
|
+
key: "max",
|
|
48
|
+
fallback: 3
|
|
49
|
+
});
|
|
50
|
+
const floorOf = (sounding) => {
|
|
51
|
+
if (hasRole(["bass"])(sounding)) return BASS_FLOOR;
|
|
52
|
+
return LOW_MID_FLOOR;
|
|
53
|
+
};
|
|
54
|
+
const inLowMids = (sounding) => isPitched(sounding) && sounding.midi <= LOW_MID_CEILING && sounding.midi >= floorOf(sounding);
|
|
55
|
+
const stepsOf$1 = (bar) => Array.makeBy(Math.ceil(bar.length / SIXTEENTH), (index) => bar.start + index * SIXTEENTH);
|
|
56
|
+
const crowdAt = (low) => (tick) => pipe(soundingAt(low)(tick), Array.dedupeWith((left, right) => left.track === right.track && left.midi === right.midi));
|
|
57
|
+
const spellingsOf = (notes) => pipe(notes, Array.map((note) => note.spelling), Array.join(", "));
|
|
58
|
+
const checkBar = (report, low, max) => (bar) => {
|
|
59
|
+
const crowded = pipe(stepsOf$1(bar), Array.map(crowdAt(low)), Array.findFirst((notes) => notes.length > max));
|
|
60
|
+
for (const notes of Option.toArray(crowded)) for (const first of Option.toArray(Array.head(notes))) report(String(bar.index), {
|
|
61
|
+
line: first.line,
|
|
62
|
+
column: first.column,
|
|
63
|
+
message: `${String(notes.length)} notes crowd the low mids in bar ${String(bar.index)}: ${spellingsOf(notes)}`,
|
|
64
|
+
detail: "Thin the chord or move notes out of A2-B3"
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
const crowdedLowMids = defineRule({
|
|
68
|
+
meta: { description: "Few notes pile up between A2 and B3 at once" },
|
|
69
|
+
check: (context) => {
|
|
70
|
+
const low = pipe(context.soundings, Array.filter(inLowMids));
|
|
71
|
+
const check = checkBar(reporterOf(context), low, maxNotes(context.options));
|
|
72
|
+
for (const bar of context.song.bars) check(bar);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
// src/app/presets/features/check-harmony/model/low-interval-limit.ts
|
|
76
|
+
const LIMITS = {
|
|
77
|
+
"1": 52,
|
|
78
|
+
"2": 51,
|
|
79
|
+
"3": 48,
|
|
80
|
+
"4": 46,
|
|
81
|
+
"5": 46,
|
|
82
|
+
"6": 46,
|
|
83
|
+
"7": 34,
|
|
84
|
+
"8": 43,
|
|
85
|
+
"9": 41,
|
|
86
|
+
"10": 41,
|
|
87
|
+
"11": 41,
|
|
88
|
+
"13": 40,
|
|
89
|
+
"14": 39
|
|
90
|
+
};
|
|
91
|
+
const checkPair$1 = (report) => (pair) => {
|
|
92
|
+
const [first, second] = pair;
|
|
93
|
+
const low = Math.min(first.midi, second.midi);
|
|
94
|
+
const gap = Math.abs(first.midi - second.midi);
|
|
95
|
+
const limits = pipe(LIMITS, Record.get(String(gap)), Option.toArray);
|
|
96
|
+
for (const limit of limits) if (low < limit) report(`${String(second.line)}:${String(low)}:${String(gap)}`, {
|
|
97
|
+
line: second.line,
|
|
98
|
+
column: second.column,
|
|
99
|
+
message: `${String(gap)} semitones between ${first.spelling} (${first.track}) and ${second.spelling} (${second.track}) is below its limit ${nameOf(limit)}`,
|
|
100
|
+
detail: "Widen the interval or move the upper note up an octave"
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
const lowIntervalLimit = defineRule({
|
|
104
|
+
meta: { description: "Close intervals stay above the pitch where they turn muddy" },
|
|
105
|
+
check: (context) => {
|
|
106
|
+
const check = checkPair$1(reporterOf(context));
|
|
107
|
+
for (const pair of overlappingPairs(pipe(context.soundings, Array.filter(isPitched)))) check(pair);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
// src/app/presets/features/check-harmony/model/semitone-clash.ts
|
|
111
|
+
const MINOR_SECOND = 1;
|
|
112
|
+
const MINOR_NINTH = 13;
|
|
113
|
+
const CLUSTER_FLOOR = 59;
|
|
114
|
+
const MAJOR_THIRD$1 = 4;
|
|
115
|
+
const MINOR_SEVENTH = 10;
|
|
116
|
+
const isBass = hasRole(["bass"]);
|
|
117
|
+
const dominantOver = (soundings) => (bottom, top) => {
|
|
118
|
+
if (!isBass(bottom) && !isBass(top)) return false;
|
|
119
|
+
if (!isBass(bottom) || top.midi - bottom.midi !== MINOR_NINTH) return true;
|
|
120
|
+
const classes = pipe(soundingAt(soundings)(top.start), Array.map((other) => pitchClassOf(other.midi - bottom.midi)));
|
|
121
|
+
return Array.contains(classes, MAJOR_THIRD$1) && Array.contains(classes, MINOR_SEVENTH);
|
|
122
|
+
};
|
|
123
|
+
const nameOfGap = (gap) => Match.value(gap).pipe(Match.when(MINOR_SECOND, () => Option.some("minor 2nd")), Match.when(MINOR_NINTH, () => Option.some("minor 9th")), Match.orElse(() => Option.none()));
|
|
124
|
+
const isCluster = (low, high) => low.track === high.track && high.midi - low.midi === MINOR_SECOND && low.midi >= CLUSTER_FLOOR;
|
|
125
|
+
const checkPair = (report, excused) => (pair) => {
|
|
126
|
+
const [low, high] = sortByPitch(pair);
|
|
127
|
+
const [, later] = pair;
|
|
128
|
+
for (const [bottom, top] of Option.toArray(Option.all([Option.fromNullishOr(low), Option.fromNullishOr(high)]))) for (const name of Option.toArray(nameOfGap(top.midi - bottom.midi))) if (!isCluster(bottom, top) && !excused(bottom, top)) report(`${String(later.line)}:${String(bottom.midi)}:${String(top.midi)}`, {
|
|
129
|
+
line: later.line,
|
|
130
|
+
column: later.column,
|
|
131
|
+
message: `${top.spelling} (${top.track}) and ${bottom.spelling} (${bottom.track}) clash a ${name} apart`,
|
|
132
|
+
detail: "Move one of the two notes to a chord note"
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
const semitoneClash = defineRule({
|
|
136
|
+
meta: { description: "Parts do not sound a minor 2nd or minor 9th apart, except the flat 9th of a dominant over its bass" },
|
|
137
|
+
check: (context) => {
|
|
138
|
+
const pitched = pipe(context.soundings, Array.filter(isPitched));
|
|
139
|
+
const check = checkPair(reporterOf(context), dominantOver(pitched));
|
|
140
|
+
for (const pair of overlappingPairs(pitched)) check(pair);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
// src/app/presets/features/check-harmony/model/voice-jump.ts
|
|
144
|
+
const MAJOR_THIRD = 4;
|
|
145
|
+
const MIN_VOICES = 3;
|
|
146
|
+
const NEARBY = 1.5 * TICKS_PER_WHOLE;
|
|
147
|
+
const maxMove = numberOption({
|
|
148
|
+
key: "max",
|
|
149
|
+
fallback: MAJOR_THIRD
|
|
150
|
+
});
|
|
151
|
+
const chordOf = (onset) => ({
|
|
152
|
+
first: Array.headNonEmpty(onset),
|
|
153
|
+
pitches: pipe(onset, Array.map((sounding) => sounding.midi), Array.dedupe)
|
|
154
|
+
});
|
|
155
|
+
const nearestMove = (from) => (pitch) => Math.min(...pipe(from, Array.map((other) => Math.abs(pitch - other))));
|
|
156
|
+
const checkChange = (report, max) => ([previous, next]) => {
|
|
157
|
+
const leaps = pipe(next.pitches, Array.map(nearestMove(previous.pitches)), Array.filter((move) => move > max));
|
|
158
|
+
if (next.first.start - previous.first.start <= NEARBY && Array.isReadonlyArrayNonEmpty(leaps)) report(`${String(next.first.line)}:${String(next.first.start)}`, {
|
|
159
|
+
line: next.first.line,
|
|
160
|
+
column: next.first.column,
|
|
161
|
+
message: `${String(leaps.length)} voices of ${next.first.track} leap more than ${String(max)} semitones into the next chord`,
|
|
162
|
+
detail: "Keep shared notes and move each voice to the closest note"
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
const chordsOf = (track) => pipe(onsetsOf(track), Array.map(chordOf), Array.filter((chord) => chord.pitches.length >= MIN_VOICES));
|
|
166
|
+
const voiceJump = defineRule({
|
|
167
|
+
meta: { description: "Chord voices move to the nearest note of the next chord" },
|
|
168
|
+
check: (context) => {
|
|
169
|
+
const check = checkChange(reporterOf(context), maxMove(context.options));
|
|
170
|
+
const harmony = pipe(context.soundings, Array.filter(hasRole(["harmony"])));
|
|
171
|
+
for (const track of tracksOf(harmony)) for (const change of neighborsOf(chordsOf(track))) check(change);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
// src/app/presets/features/check-harmony/model/preset.ts
|
|
175
|
+
const harmonyPlugin = definePlugin({ rules: {
|
|
176
|
+
"semitone-clash": semitoneClash,
|
|
177
|
+
"low-interval-limit": lowIntervalLimit,
|
|
178
|
+
"crowded-low-mids": crowdedLowMids,
|
|
179
|
+
"chord-above-melody": chordAboveMelody,
|
|
180
|
+
"voice-jump": voiceJump
|
|
181
|
+
} });
|
|
182
|
+
const harmony = () => ({
|
|
183
|
+
plugins: { harmony: harmonyPlugin },
|
|
184
|
+
rules: {
|
|
185
|
+
"harmony/semitone-clash": "warn",
|
|
186
|
+
"harmony/low-interval-limit": "warn",
|
|
187
|
+
"harmony/crowded-low-mids": "warn",
|
|
188
|
+
"harmony/chord-above-melody": "warn",
|
|
189
|
+
"harmony/voice-jump": "warn"
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
// src/app/presets/shared/lib/time.ts
|
|
193
|
+
const NONE = 0;
|
|
194
|
+
const segmentsIn = (bar) => Array.match(bar.tempoSteps, {
|
|
195
|
+
onEmpty: () => [{
|
|
196
|
+
start: bar.start,
|
|
197
|
+
end: bar.start + bar.length,
|
|
198
|
+
bpm: bar.tempo.bpm
|
|
199
|
+
}],
|
|
200
|
+
onNonEmpty: (steps) => pipe(steps, Array.map((step) => ({
|
|
201
|
+
start: bar.start + step.offset,
|
|
202
|
+
end: bar.start + step.offset + step.length,
|
|
203
|
+
bpm: step.bpm
|
|
204
|
+
})))
|
|
205
|
+
});
|
|
206
|
+
const secondsPerTick = (bpm) => 240 / (bpm * TICKS_PER_WHOLE);
|
|
207
|
+
const clockOf = (song) => {
|
|
208
|
+
const segments = pipe(song.bars, Array.flatMap(segmentsIn));
|
|
209
|
+
return (tick) => {
|
|
210
|
+
let seconds = NONE;
|
|
211
|
+
for (const segment of segments) if (segment.start < tick) seconds += (Math.min(tick, segment.end) - segment.start) * secondsPerTick(segment.bpm);
|
|
212
|
+
return seconds;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
// src/app/presets/features/check-pop/model/breath.ts
|
|
216
|
+
const DEFAULT_SECONDS = 8;
|
|
217
|
+
const DEFAULT_REST = .15;
|
|
218
|
+
const DIGITS = 1;
|
|
219
|
+
const LAST = 1;
|
|
220
|
+
const maxSeconds = numberOption({
|
|
221
|
+
key: "seconds",
|
|
222
|
+
fallback: DEFAULT_SECONDS
|
|
223
|
+
});
|
|
224
|
+
const minRest = numberOption({
|
|
225
|
+
key: "rest",
|
|
226
|
+
fallback: DEFAULT_REST
|
|
227
|
+
});
|
|
228
|
+
const phrasesOf = (clock, rest) => (line) => Array.reduce(line, Array.empty(), (phrases, note) => pipe(Array.last(phrases), Option.filter((phrase) => clock(note.start) - clock(Array.lastNonEmpty(phrase).end) < rest), Option.match({
|
|
229
|
+
onNone: () => Array.append(phrases, Array.of(note)),
|
|
230
|
+
onSome: (phrase) => Array.append(Array.dropRight(phrases, LAST), Array.append(phrase, note))
|
|
231
|
+
})));
|
|
232
|
+
const endOf = (phrase) => pipe(phrase, Array.map((sounding) => sounding.end), (ends) => Math.max(...ends));
|
|
233
|
+
const checkPhrase = (report, clock, max) => (phrase) => {
|
|
234
|
+
const first = Array.headNonEmpty(phrase);
|
|
235
|
+
const seconds = clock(endOf(phrase)) - clock(first.start);
|
|
236
|
+
if (seconds > max) report(`${String(first.line)}:${String(first.start)}`, {
|
|
237
|
+
line: first.line,
|
|
238
|
+
column: first.column,
|
|
239
|
+
message: `${first.track} sings for ${seconds.toFixed(DIGITS)} seconds without a rest`,
|
|
240
|
+
detail: "Put a short rest in the phrase"
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
const breath = defineRule({
|
|
244
|
+
meta: { description: "A sung line leaves room to breathe" },
|
|
245
|
+
check: (context) => {
|
|
246
|
+
const clock = clockOf(context.song);
|
|
247
|
+
const check = checkPhrase(reporterOf(context), clock, maxSeconds(context.options));
|
|
248
|
+
const split = phrasesOf(clock, minRest(context.options));
|
|
249
|
+
const melodic = pipe(context.soundings, Array.filter(hasRole(MELODIC)));
|
|
250
|
+
for (const track of tracksOf(melodic)) for (const phrase of split(topLineOf(track))) check(phrase);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
// src/app/presets/features/check-pop/model/melody-leap.ts
|
|
254
|
+
const maxLeap = numberOption({
|
|
255
|
+
key: "max",
|
|
256
|
+
fallback: 12
|
|
257
|
+
});
|
|
258
|
+
const checkStep$1 = (report, max) => ([previous, next]) => {
|
|
259
|
+
const leap = Math.abs(next.midi - previous.midi);
|
|
260
|
+
if (leap > max && next.start - previous.end < TICKS_PER_WHOLE) report(`${String(next.line)}:${String(next.start)}`, {
|
|
261
|
+
line: next.line,
|
|
262
|
+
column: next.column,
|
|
263
|
+
message: `${next.track} leaps ${String(leap)} semitones from ${previous.spelling} to ${next.spelling}`,
|
|
264
|
+
detail: "Make the jump smaller, or step back the other way right after it"
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
const melodyLeap = defineRule({
|
|
268
|
+
meta: { description: "A melody does not jump further than an octave from one note to the next" },
|
|
269
|
+
check: (context) => {
|
|
270
|
+
const check = checkStep$1(reporterOf(context), maxLeap(context.options));
|
|
271
|
+
const melodic = pipe(context.soundings, Array.filter(hasRole(MELODIC)));
|
|
272
|
+
for (const track of tracksOf(melodic)) for (const step of neighborsOf(topLineOf(track))) check(step);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
// src/app/presets/shared/lib/chords.ts
|
|
276
|
+
const COMMON = [
|
|
277
|
+
"M",
|
|
278
|
+
"m",
|
|
279
|
+
"dim",
|
|
280
|
+
"aug",
|
|
281
|
+
"7",
|
|
282
|
+
"maj7",
|
|
283
|
+
"m7",
|
|
284
|
+
"m7b5",
|
|
285
|
+
"dim7",
|
|
286
|
+
"sus4",
|
|
287
|
+
"sus2",
|
|
288
|
+
"6",
|
|
289
|
+
"m6",
|
|
290
|
+
"Madd9",
|
|
291
|
+
"madd9",
|
|
292
|
+
"9",
|
|
293
|
+
"maj9",
|
|
294
|
+
"m9",
|
|
295
|
+
"7sus4",
|
|
296
|
+
"m/ma7",
|
|
297
|
+
"6add9",
|
|
298
|
+
"m69",
|
|
299
|
+
"5"
|
|
300
|
+
];
|
|
301
|
+
const DYAD = 2;
|
|
302
|
+
const isCommonName = (name) => pipe(Array.head(Chord.get(name).aliases), Option.exists((alias) => Array.contains(COMMON, alias)));
|
|
303
|
+
const isCommonChord = (pitchClasses) => {
|
|
304
|
+
const names = Array.dedupe(pitchClasses);
|
|
305
|
+
if (names.length < DYAD) return true;
|
|
306
|
+
return pipe(Chord.detect(names), Array.some(isCommonName));
|
|
307
|
+
};
|
|
308
|
+
// src/app/presets/features/check-pop/model/out-of-key.ts
|
|
309
|
+
const ORNAMENT = TICKS_PER_WHOLE / 8;
|
|
310
|
+
const HALF_STEP = 1;
|
|
311
|
+
const WHOLE_STEP = 2;
|
|
312
|
+
const MAJOR_STEPS = {
|
|
313
|
+
tonic: 0,
|
|
314
|
+
second: 2,
|
|
315
|
+
third: 4,
|
|
316
|
+
fourth: 5,
|
|
317
|
+
fifth: 7,
|
|
318
|
+
sixth: 9,
|
|
319
|
+
seventh: 11
|
|
320
|
+
};
|
|
321
|
+
const MINOR_STEPS = {
|
|
322
|
+
tonic: 0,
|
|
323
|
+
second: 2,
|
|
324
|
+
flatThird: 3,
|
|
325
|
+
fourth: 5,
|
|
326
|
+
fifth: 7,
|
|
327
|
+
flatSixth: 8,
|
|
328
|
+
raisedSixth: 9,
|
|
329
|
+
flatSeventh: 10,
|
|
330
|
+
leadingTone: 11
|
|
331
|
+
};
|
|
332
|
+
const MAJOR = Record.values(MAJOR_STEPS);
|
|
333
|
+
const MINOR = Record.values(MINOR_STEPS);
|
|
334
|
+
const stepsOf = (key) => {
|
|
335
|
+
if (key.mode === "major") return MAJOR;
|
|
336
|
+
return MINOR;
|
|
337
|
+
};
|
|
338
|
+
const inScale = (key) => (midi) => Array.contains(stepsOf(key), pitchClassOf(midi - key.pitchClass));
|
|
339
|
+
const inChordOf = (soundings) => {
|
|
340
|
+
const harmony = pipe(soundings, Array.filter(hasRole(["bass", "harmony"])));
|
|
341
|
+
return (sounding) => {
|
|
342
|
+
const under = soundingAt(harmony)(sounding.start);
|
|
343
|
+
const shared = pipe(under, Array.some((other) => other.track !== sounding.track && pitchClassOf(other.midi) === pitchClassOf(sounding.midi)));
|
|
344
|
+
const voicesChord = hasRole(["bass", "harmony"])(sounding) && isCommonChord(pipe(under, Array.map((other) => other.pitchClass)));
|
|
345
|
+
return shared || voicesChord;
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
const isStep = (from, to) => {
|
|
349
|
+
const distance = Math.abs(to.midi - from.midi);
|
|
350
|
+
return distance >= HALF_STEP && distance <= WHOLE_STEP;
|
|
351
|
+
};
|
|
352
|
+
const neighboursOf = (track) => (sounding) => {
|
|
353
|
+
const before = pipe(track, Array.findLast((other) => other.end === sounding.start));
|
|
354
|
+
const after = pipe(track, Array.findFirst((other) => other.start === sounding.end));
|
|
355
|
+
return Option.all([before, after]);
|
|
356
|
+
};
|
|
357
|
+
const isOrnament = (fits, track) => (sounding) => sounding.end - sounding.start <= ORNAMENT && pipe(neighboursOf(track)(sounding), Option.exists(([before, after]) => isStep(before, sounding) && isStep(sounding, after) && fits(before) && fits(after)));
|
|
358
|
+
const fitsOf = (keys, inChord) => (sounding) => inChord(sounding) || pipe(keyAt(keys)(sounding.bar), Option.match({
|
|
359
|
+
onNone: () => true,
|
|
360
|
+
onSome: (key) => inScale(key)(sounding.midi)
|
|
361
|
+
}));
|
|
362
|
+
const trackOf = (tracks) => (sounding) => pipe(tracks, Array.findFirst((candidate) => pipe(candidate, Array.some((other) => other.track === sounding.track))), Option.getOrElse(() => []));
|
|
363
|
+
const checkNote$2 = ({ report, keys, fits, tracks }) => (sounding) => {
|
|
364
|
+
const track = trackOf(tracks)(sounding);
|
|
365
|
+
for (const key of Option.toArray(keyAt(keys)(sounding.bar))) if (!fits(sounding) && !isOrnament(fits, track)(sounding)) report(`${String(sounding.line)}:${String(sounding.column)}`, {
|
|
366
|
+
line: sounding.line,
|
|
367
|
+
column: sounding.column,
|
|
368
|
+
message: `${sounding.spelling} in ${sounding.track} is outside ${key.tonic} ${key.mode} and the chord under it`,
|
|
369
|
+
detail: "Move it a semitone, or ignore the line if the borrowed note is intended"
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
const outOfKey = defineRule({
|
|
373
|
+
meta: { description: "Notes stay in the key the notes around them imply" },
|
|
374
|
+
check: (context) => {
|
|
375
|
+
const keys = keysOf(context.song);
|
|
376
|
+
const pitched = pipe(context.soundings, Array.filter(isPitched));
|
|
377
|
+
const fits = fitsOf(keys, inChordOf(context.soundings));
|
|
378
|
+
const check = checkNote$2({
|
|
379
|
+
report: reporterOf(context),
|
|
380
|
+
keys,
|
|
381
|
+
fits,
|
|
382
|
+
tracks: tracksOf(pitched)
|
|
383
|
+
});
|
|
384
|
+
for (const sounding of pitched) check(sounding);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
// src/app/presets/features/check-pop/model/part-range.ts
|
|
388
|
+
const DEFAULT_RANGES = {
|
|
389
|
+
melody: ["C3", "C6"],
|
|
390
|
+
countermelody: ["C3", "C6"],
|
|
391
|
+
bass: ["E1", "C4"]
|
|
392
|
+
};
|
|
393
|
+
const RANGE_LENGTH = 2;
|
|
394
|
+
const isRange = (value) => Array.isArray(value) && value.length === RANGE_LENGTH && pipe(value, Array.every(Predicate.isString));
|
|
395
|
+
const boundsOf = ([low, high]) => Option.all({
|
|
396
|
+
low: midiOf(low),
|
|
397
|
+
high: midiOf(high),
|
|
398
|
+
name: Option.some(`${low}-${high}`)
|
|
399
|
+
});
|
|
400
|
+
const configured = (options) => pipe(Option.fromNullishOr(options["ranges"]), Option.filter(Predicate.isObject), Option.map((value) => ({
|
|
401
|
+
...DEFAULT_RANGES,
|
|
402
|
+
...value
|
|
403
|
+
})), Option.getOrElse(() => DEFAULT_RANGES));
|
|
404
|
+
const rangesOf = (options) => pipe(configured(options), Record.toEntries, Array.flatMap(([name, value]) => pipe(Option.liftPredicate(value, isRange), Option.flatMap(boundsOf), Option.map((bounds) => [name, bounds]), Option.toArray)), Record.fromEntries);
|
|
405
|
+
const boundsFor = (ranges) => (sounding) => pipe(ranges, Record.get(sounding.track), Option.orElse(() => pipe(sounding.role, Option.flatMap((role) => pipe(ranges, Record.get(role))))));
|
|
406
|
+
const checkNote$1 = (report) => (sounding, bounds) => {
|
|
407
|
+
if (sounding.midi < bounds.low || sounding.midi > bounds.high) report(`${String(sounding.line)}:${String(sounding.column)}`, {
|
|
408
|
+
line: sounding.line,
|
|
409
|
+
column: sounding.column,
|
|
410
|
+
message: `${sounding.spelling} in ${sounding.track} is outside ${bounds.name}`,
|
|
411
|
+
detail: "Move the phrase an octave, or set the range of this track"
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
const partRange = defineRule({
|
|
415
|
+
meta: { description: "Each part stays inside the range its singer or instrument can play" },
|
|
416
|
+
check: (context) => {
|
|
417
|
+
const check = checkNote$1(reporterOf(context));
|
|
418
|
+
const lookup = boundsFor(rangesOf(context.options));
|
|
419
|
+
for (const sounding of context.soundings) for (const bounds of Option.toArray(lookup(sounding))) check(sounding, bounds);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
// src/app/presets/features/check-pop/model/preset.ts
|
|
423
|
+
const popPlugin = definePlugin({ rules: {
|
|
424
|
+
"out-of-key": outOfKey,
|
|
425
|
+
"part-range": partRange,
|
|
426
|
+
"melody-leap": melodyLeap,
|
|
427
|
+
breath
|
|
428
|
+
} });
|
|
429
|
+
const warnWith = (key) => (value) => pipe(Option.fromNullishOr(value), Option.match({
|
|
430
|
+
onNone: () => "warn",
|
|
431
|
+
onSome: (given) => ["warn", { [key]: given }]
|
|
432
|
+
}));
|
|
433
|
+
const pop = (options = {}) => ({
|
|
434
|
+
plugins: { pop: popPlugin },
|
|
435
|
+
rules: {
|
|
436
|
+
"pop/out-of-key": "warn",
|
|
437
|
+
"pop/part-range": warnWith("ranges")(options.ranges),
|
|
438
|
+
"pop/melody-leap": warnWith("max")(options.maxLeap),
|
|
439
|
+
"pop/breath": warnWith("seconds")(options.breathSeconds)
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
// src/app/presets/features/check-classical/model/outer-voices.ts
|
|
443
|
+
const pickAt = (soundings, pick) => (tick) => pipe(soundingAt(soundings)(tick), Array.match({
|
|
444
|
+
onEmpty: () => Option.none(),
|
|
445
|
+
onNonEmpty: (found) => Option.some(pick(found))
|
|
446
|
+
}));
|
|
447
|
+
const outerVoicesOf = (soundings) => {
|
|
448
|
+
const melodic = pipe(soundings, Array.filter(hasRole(MELODIC)));
|
|
449
|
+
const low = pipe(soundings, Array.filter(hasRole(["bass"])));
|
|
450
|
+
const topAt = pickAt(melodic, highest);
|
|
451
|
+
const bottomAt = pickAt(low, lowest);
|
|
452
|
+
const ticks = pipe([...melodic, ...low], Array.map((sounding) => sounding.start), Array.dedupe, (all) => Array.sort(all, Order.Number));
|
|
453
|
+
const pairAt = (tick) => pipe(Option.all({
|
|
454
|
+
melody: topAt(tick),
|
|
455
|
+
bass: bottomAt(tick)
|
|
456
|
+
}), Option.map(({ melody, bass }) => ({
|
|
457
|
+
tick,
|
|
458
|
+
melody,
|
|
459
|
+
bass
|
|
460
|
+
})));
|
|
461
|
+
return pipe(ticks, Array.map(pairAt), Array.getSomes);
|
|
462
|
+
};
|
|
463
|
+
// src/app/presets/features/check-classical/model/parallel-perfects.ts
|
|
464
|
+
const UNISON = 0;
|
|
465
|
+
const FIFTH = 7;
|
|
466
|
+
const STILL = 0;
|
|
467
|
+
const perfectName = (interval) => Match.value(interval).pipe(Match.when(UNISON, () => Option.some("octaves")), Match.when(FIFTH, () => Option.some("fifths")), Match.orElse(() => Option.none()));
|
|
468
|
+
const intervalOf = (pair) => pitchClassOf(pair.melody.midi - pair.bass.midi);
|
|
469
|
+
const movesTogether = (previous, next) => {
|
|
470
|
+
const melody = Math.sign(next.melody.midi - previous.melody.midi);
|
|
471
|
+
return melody !== STILL && melody === Math.sign(next.bass.midi - previous.bass.midi);
|
|
472
|
+
};
|
|
473
|
+
const checkMove = (report) => ([previous, next]) => {
|
|
474
|
+
const name = perfectName(intervalOf(next));
|
|
475
|
+
if (Option.isSome(name) && intervalOf(previous) === intervalOf(next) && movesTogether(previous, next)) report(`${String(next.melody.line)}:${String(next.tick)}`, {
|
|
476
|
+
line: next.melody.line,
|
|
477
|
+
column: next.melody.column,
|
|
478
|
+
message: `Parallel ${name.value}: ${previous.melody.spelling}/${previous.bass.spelling} to ${next.melody.spelling}/${next.bass.spelling} between ${next.melody.track} and ${next.bass.track}`,
|
|
479
|
+
detail: "Move the melody or the bass the other way"
|
|
480
|
+
});
|
|
481
|
+
};
|
|
482
|
+
const parallelPerfects = defineRule({
|
|
483
|
+
meta: { description: "Melody and bass do not move in parallel fifths or octaves" },
|
|
484
|
+
check: (context) => {
|
|
485
|
+
const check = checkMove(reporterOf(context));
|
|
486
|
+
for (const move of neighborsOf(outerVoicesOf(context.soundings))) check(move);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
// src/app/presets/features/check-classical/model/unresolved-dissonance.ts
|
|
490
|
+
const DISSONANT = Record.values({
|
|
491
|
+
minorSecond: 1,
|
|
492
|
+
majorSecond: 2,
|
|
493
|
+
fourth: 5,
|
|
494
|
+
tritone: 6,
|
|
495
|
+
minorSeventh: 10,
|
|
496
|
+
majorSeventh: 11
|
|
497
|
+
});
|
|
498
|
+
const STEP_DOWN = Record.values({
|
|
499
|
+
halfStep: -1,
|
|
500
|
+
wholeStep: -2
|
|
501
|
+
});
|
|
502
|
+
const HALVES = 2;
|
|
503
|
+
const ON_BEAT = 0;
|
|
504
|
+
const strongLength = (length, numerator) => {
|
|
505
|
+
if (numerator % HALVES === ON_BEAT) return length / HALVES;
|
|
506
|
+
return length;
|
|
507
|
+
};
|
|
508
|
+
const isStrongBeat = (song) => (sounding) => pipe(song.bars, Array.findFirst((bar) => bar.index === sounding.bar), Option.exists((bar) => (sounding.start - bar.start) % strongLength(bar.length, bar.meter.numerator) === ON_BEAT));
|
|
509
|
+
const bassOf = (soundings) => {
|
|
510
|
+
const pairs = outerVoicesOf(soundings);
|
|
511
|
+
return (tick) => pipe(pairs, Array.findFirst((pair) => pair.tick === tick), Option.map((pair) => pair.bass));
|
|
512
|
+
};
|
|
513
|
+
const checkNote = (report, strong, bassAt) => ([note, next]) => {
|
|
514
|
+
const dissonant = Option.exists(bassAt(note.start), (bass) => Array.contains(DISSONANT, pitchClassOf(note.midi - bass.midi)));
|
|
515
|
+
const resolved = Option.exists(next, (found) => Array.contains(STEP_DOWN, found.midi - note.midi));
|
|
516
|
+
if (strong(note) && dissonant && !resolved) report(`${String(note.line)}:${String(note.start)}`, {
|
|
517
|
+
line: note.line,
|
|
518
|
+
column: note.column,
|
|
519
|
+
message: `${note.spelling} in ${note.track} is dissonant against the bass and does not step down`,
|
|
520
|
+
detail: "Move the next note down a step"
|
|
521
|
+
});
|
|
522
|
+
};
|
|
523
|
+
const withNext = (line) => [...pipe(neighborsOf(line), Array.map(([note, next]) => [note, Option.some(next)])), ...pipe(Array.last(line), Option.map((note) => [note, Option.none()]), Option.toArray)];
|
|
524
|
+
const unresolvedDissonance = defineRule({
|
|
525
|
+
meta: { description: "A dissonant melody note on a strong beat steps down to resolve" },
|
|
526
|
+
check: (context) => {
|
|
527
|
+
const check = checkNote(reporterOf(context), isStrongBeat(context.song), bassOf(context.soundings));
|
|
528
|
+
const melodic = pipe(context.soundings, Array.filter(hasRole(MELODIC)));
|
|
529
|
+
for (const track of tracksOf(melodic)) for (const entry of withNext(topLineOf(track))) check(entry);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
// src/app/presets/features/check-classical/model/preset.ts
|
|
533
|
+
const classicalPlugin = definePlugin({ rules: {
|
|
534
|
+
"parallel-perfects": parallelPerfects,
|
|
535
|
+
"unresolved-dissonance": unresolvedDissonance
|
|
536
|
+
} });
|
|
537
|
+
const classical = () => ({
|
|
538
|
+
plugins: { classical: classicalPlugin },
|
|
539
|
+
rules: {
|
|
540
|
+
"classical/parallel-perfects": "warn",
|
|
541
|
+
"classical/unresolved-dissonance": "warn"
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
// src/app/presets/features/check-progressions/model/named.ts
|
|
545
|
+
const PROGRESSIONS = [
|
|
546
|
+
{
|
|
547
|
+
name: "丸サ進行 (Just the Two of Us)",
|
|
548
|
+
degrees: [
|
|
549
|
+
"IVM7",
|
|
550
|
+
"III7",
|
|
551
|
+
"VIm7"
|
|
552
|
+
]
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
name: "王道進行",
|
|
556
|
+
degrees: [
|
|
557
|
+
"IV",
|
|
558
|
+
"V",
|
|
559
|
+
"IIIm",
|
|
560
|
+
"VIm"
|
|
561
|
+
]
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
name: "小室進行",
|
|
565
|
+
degrees: [
|
|
566
|
+
"VIm",
|
|
567
|
+
"IV",
|
|
568
|
+
"V",
|
|
569
|
+
"I"
|
|
570
|
+
]
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
name: "カノン進行",
|
|
574
|
+
degrees: [
|
|
575
|
+
"I",
|
|
576
|
+
"V",
|
|
577
|
+
"VIm",
|
|
578
|
+
"IIIm",
|
|
579
|
+
"IV",
|
|
580
|
+
"I",
|
|
581
|
+
"IV",
|
|
582
|
+
"V"
|
|
583
|
+
]
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
name: "ii–V–I",
|
|
587
|
+
degrees: [
|
|
588
|
+
"IIm",
|
|
589
|
+
"V",
|
|
590
|
+
"I"
|
|
591
|
+
]
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
name: "Andalusian cadence",
|
|
595
|
+
degrees: [
|
|
596
|
+
"VIm",
|
|
597
|
+
"V",
|
|
598
|
+
"IV",
|
|
599
|
+
"III"
|
|
600
|
+
]
|
|
601
|
+
}
|
|
602
|
+
];
|
|
603
|
+
const START = 0;
|
|
604
|
+
const FAMILIES = [
|
|
605
|
+
["M7", ""],
|
|
606
|
+
["m7b5", "dim"],
|
|
607
|
+
["m7", "m"],
|
|
608
|
+
["dim7", "dim"],
|
|
609
|
+
["7", ""]
|
|
610
|
+
];
|
|
611
|
+
const familyOf = (token) => pipe(FAMILIES, Array.findFirst(([suffix]) => String$1.endsWith(suffix)(token)), Option.match({
|
|
612
|
+
onNone: () => token,
|
|
613
|
+
onSome: ([suffix, triad]) => `${String$1.slice(START, token.length - suffix.length)(token)}${triad}`
|
|
614
|
+
}));
|
|
615
|
+
const matches = (steps, degrees) => (start) => pipe(degrees, Array.every((degree, offset) => pipe(Array.get(steps, start + offset), Option.exists((step) => familyOf(step.token) === familyOf(degree)))));
|
|
616
|
+
const namedProgression = defineRule({
|
|
617
|
+
meta: { description: "Names the well-known chord progressions a song uses" },
|
|
618
|
+
check: (context) => {
|
|
619
|
+
const steps = progressionOf(context.soundings)(context.song);
|
|
620
|
+
const report = reporterOf(context);
|
|
621
|
+
for (const progression of PROGRESSIONS) {
|
|
622
|
+
const starts = pipe(Array.makeBy(steps.length, (index) => index), Array.filter(matches(steps, progression.degrees)));
|
|
623
|
+
for (const step of pipe(starts, Array.flatMap((start) => Option.toArray(Array.get(steps, start))))) report(`${progression.name}:${String(step.line)}:${String(step.bar)}`, {
|
|
624
|
+
line: step.line,
|
|
625
|
+
column: step.column,
|
|
626
|
+
message: `${progression.name} (${Array.join(progression.degrees, "–")}) starts in bar ${String(step.bar)}`
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
// src/app/presets/features/check-progressions/model/preset.ts
|
|
632
|
+
const progressionsPlugin = definePlugin({ rules: { named: namedProgression } });
|
|
633
|
+
const progressions = () => ({
|
|
634
|
+
plugins: { progressions: progressionsPlugin },
|
|
635
|
+
rules: { "progressions/named": "warn" }
|
|
636
|
+
});
|
|
637
|
+
// src/app/presets/features/check-style/model/rare-transition.ts
|
|
638
|
+
const DEFAULT_SHARE = .03;
|
|
639
|
+
const DEFAULT_SEEN = 8;
|
|
640
|
+
const PERCENT = 100;
|
|
641
|
+
const SUGGESTIONS = 3;
|
|
642
|
+
const FIRST$1 = 1;
|
|
643
|
+
const NEVER = 0;
|
|
644
|
+
const minShare = numberOption({
|
|
645
|
+
key: "share",
|
|
646
|
+
fallback: DEFAULT_SHARE
|
|
647
|
+
});
|
|
648
|
+
const minSeen = numberOption({
|
|
649
|
+
key: "seen",
|
|
650
|
+
fallback: DEFAULT_SEEN
|
|
651
|
+
});
|
|
652
|
+
const percentOf = (count, total) => `${String(Math.round(count / total * PERCENT))}%`;
|
|
653
|
+
const suggestionsOf = (context) => pipe(Record.toEntries(context.next), Array.sortWith(([, count]) => -count, Number.Order), Array.take(SUGGESTIONS), Array.map(([token, count]) => `${token} (${percentOf(count, context.total)})`), Array.join(", "));
|
|
654
|
+
const checkStep = (report, table, { share, seen }) => (steps, index) => {
|
|
655
|
+
const before = Array.take(steps, index);
|
|
656
|
+
for (const step of Option.toArray(Array.get(steps, index))) for (const context of Option.toArray(longestContext({
|
|
657
|
+
table,
|
|
658
|
+
seen
|
|
659
|
+
})(before))) {
|
|
660
|
+
const count = Option.getOrElse(Record.get(context.next, step.token), () => NEVER);
|
|
661
|
+
if (count / context.total < share) report(`${String(step.line)}:${step.token}:${String(index)}`, {
|
|
662
|
+
line: step.line,
|
|
663
|
+
column: step.column,
|
|
664
|
+
message: `${context.words} → ${step.token} is rare in ${table.name} (${percentOf(count, context.total)})`,
|
|
665
|
+
detail: `${table.name} usually goes to ${suggestionsOf(context)}`
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
const rareTransitionOf = (table) => defineRule({
|
|
670
|
+
meta: { description: `Chord changes follow what ${table.name} usually does next` },
|
|
671
|
+
check: (context) => {
|
|
672
|
+
const steps = progressionOf(context.soundings)(context.song);
|
|
673
|
+
const check = checkStep(reporterOf(context), table, {
|
|
674
|
+
share: minShare(context.options),
|
|
675
|
+
seen: minSeen(context.options)
|
|
676
|
+
});
|
|
677
|
+
const indices = Array.makeBy(steps.length, (at) => at);
|
|
678
|
+
for (const index of Array.drop(indices, FIRST$1)) check(steps, index);
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
// src/app/presets/features/check-style/model/preset.ts
|
|
682
|
+
const bachPlugin = definePlugin({ rules: { "rare-transition": rareTransitionOf(bach_chorales_default) } });
|
|
683
|
+
const bach = () => ({
|
|
684
|
+
plugins: { bach: bachPlugin },
|
|
685
|
+
rules: { "bach/rare-transition": "warn" }
|
|
686
|
+
});
|
|
687
|
+
const stylePluginOf = (table) => definePlugin({ rules: { "rare-transition": rareTransitionOf(table) } });
|
|
688
|
+
// src/app/presets/features/check-habits/model/occasions.ts
|
|
689
|
+
const FIRST = 1;
|
|
690
|
+
const follows = (before, context) => {
|
|
691
|
+
const words = String$1.split(" ")(context);
|
|
692
|
+
return before.length >= words.length && pipe(Array.takeRight(before, words.length), Array.map((step) => step.token), Array.join(" ")) === context;
|
|
693
|
+
};
|
|
694
|
+
const chordOccasions = (context) => (chord) => {
|
|
695
|
+
const steps = progressionOf(context.soundings)(context.song);
|
|
696
|
+
return pipe(Array.makeBy(steps.length, (index) => index), Array.drop(FIRST), Array.filter((index) => follows(Array.take(steps, index), chord.context)), Array.map((index) => {
|
|
697
|
+
const step = Array.getUnsafe(steps, index);
|
|
698
|
+
return {
|
|
699
|
+
id: String(index),
|
|
700
|
+
line: step.line,
|
|
701
|
+
column: step.column,
|
|
702
|
+
holds: step.token === chord.next
|
|
703
|
+
};
|
|
704
|
+
}));
|
|
705
|
+
};
|
|
706
|
+
const sectionStartsOf = (context) => pipe(context.song.bars, Array.drop(FIRST), Array.filter((bar) => Option.isSome(bar.section) || Option.isSome(bar.mark)), Array.map((bar) => bar.index));
|
|
707
|
+
const occasionAt = (place, holds) => ({
|
|
708
|
+
id: String(place.bar),
|
|
709
|
+
line: place.line,
|
|
710
|
+
column: place.column,
|
|
711
|
+
holds
|
|
712
|
+
});
|
|
713
|
+
const has = (facts, habit) => (bar) => pipe(facts, Array.some((fact) => mixKeyOf(fact.habit) === mixKeyOf(habit) && Option.match(bar, {
|
|
714
|
+
onNone: () => true,
|
|
715
|
+
onSome: (at) => fact.place.bar === at
|
|
716
|
+
})));
|
|
717
|
+
const mixOccasions = (context) => (habit) => {
|
|
718
|
+
const facts = mixFactsOf(context.soundings)(context.song);
|
|
719
|
+
const place = placeIn(context.soundings);
|
|
720
|
+
const tracks = pipe(context.song.tracks, Array.filter((track) => trackKeyOf(track.name) === habit.track));
|
|
721
|
+
if (habit.type !== "move") return pipe(tracks, Array.map((track) => occasionAt(place({
|
|
722
|
+
track: track.name,
|
|
723
|
+
bar: FIRST
|
|
724
|
+
}), has(facts, habit)(Option.none()))));
|
|
725
|
+
return pipe(tracks, Array.flatMap((track) => pipe(sectionStartsOf(context), Array.map((bar) => occasionAt(place({
|
|
726
|
+
track: track.name,
|
|
727
|
+
bar
|
|
728
|
+
}), has(facts, habit)(Option.some(bar)))))));
|
|
729
|
+
};
|
|
730
|
+
const occasionsOf = (context) => (subject) => {
|
|
731
|
+
if (subject.type === "chord") return chordOccasions(context)(subject);
|
|
732
|
+
return mixOccasions(context)(subject);
|
|
733
|
+
};
|
|
734
|
+
// src/app/presets/features/check-habits/model/habit-rule.ts
|
|
735
|
+
const WORDINGS = {
|
|
736
|
+
keep: {
|
|
737
|
+
description: (name) => `Songs keep the habits of ${name}`,
|
|
738
|
+
reportsWhen: false,
|
|
739
|
+
message: (name, key) => `${name} keeps ${key} here`
|
|
740
|
+
},
|
|
741
|
+
fix: {
|
|
742
|
+
description: (name) => `Songs avoid the habits ${name} is fixing`,
|
|
743
|
+
reportsWhen: true,
|
|
744
|
+
message: (name, key) => `${key} is a habit ${name} is fixing`
|
|
745
|
+
},
|
|
746
|
+
suggest: {
|
|
747
|
+
description: (name) => `Habits that would fit ${name}`,
|
|
748
|
+
reportsWhen: false,
|
|
749
|
+
message: (name, key) => `${key} would fit ${name} here`
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
const detailOf = (habit) => pipe(Option.fromNullishOr(habit.reason), Option.match({
|
|
753
|
+
onNone: () => habit.aim,
|
|
754
|
+
onSome: (reason) => `${habit.aim}: ${reason}`
|
|
755
|
+
}));
|
|
756
|
+
const habitRuleOf = ({ rules, kind }) => {
|
|
757
|
+
const wording = WORDINGS[kind];
|
|
758
|
+
const habits = pipe(rules.habits, Array.filter((habit) => habit.kind === kind));
|
|
759
|
+
return defineRule({
|
|
760
|
+
meta: { description: wording.description(rules.name) },
|
|
761
|
+
check: (context) => {
|
|
762
|
+
const report = reporterOf(context);
|
|
763
|
+
for (const habit of habits) {
|
|
764
|
+
const key = subjectKeyOf(habit.habit);
|
|
765
|
+
for (const occasion of occasionsOf(context)(habit.habit)) if (occasion.holds === wording.reportsWhen) report(`${key}:${occasion.id}`, {
|
|
766
|
+
line: occasion.line,
|
|
767
|
+
column: occasion.column,
|
|
768
|
+
message: wording.message(rules.name, key),
|
|
769
|
+
detail: detailOf(habit)
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
// src/app/presets/features/check-habits/model/preset.ts
|
|
776
|
+
const styleRulesPluginOf = (rules) => definePlugin({ rules: {
|
|
777
|
+
keep: habitRuleOf({
|
|
778
|
+
rules,
|
|
779
|
+
kind: "keep"
|
|
780
|
+
}),
|
|
781
|
+
fix: habitRuleOf({
|
|
782
|
+
rules,
|
|
783
|
+
kind: "fix"
|
|
784
|
+
}),
|
|
785
|
+
suggest: habitRuleOf({
|
|
786
|
+
rules,
|
|
787
|
+
kind: "suggest"
|
|
788
|
+
})
|
|
789
|
+
} });
|
|
790
|
+
const styleRules = ({ plugin, rules }) => ({
|
|
791
|
+
plugins: { [plugin]: styleRulesPluginOf(rules) },
|
|
792
|
+
rules: {
|
|
793
|
+
[`${plugin}/keep`]: "warn",
|
|
794
|
+
[`${plugin}/fix`]: "error",
|
|
795
|
+
[`${plugin}/suggest`]: "warn"
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
// src/app/presets.ts
|
|
799
|
+
const recommended = (options = {}) => ({ extends: [pop(options), harmony()] });
|
|
800
|
+
export { DEFAULT_RANGES, HABIT_KINDS, PROGRESSIONS, StyleRulesSchema, bach, bachPlugin, classical, classicalPlugin, harmony, harmonyPlugin, mixKeyOf, pop, popPlugin, progressions, progressionsPlugin, recommended, stylePluginOf, styleRules, styleRulesPluginOf, subjectKeyOf };
|
|
801
|
+
|
|
802
|
+
//# sourceMappingURL=presets.mjs.map
|