Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | 1x 3x 3x 3x 3x 3x 1x 2x 14x 1x 1x 224x 1792x 1x 1x 1x | import { Step, Solvable } from "./step.js";
import { modelNotes } from "../model/constraints3.js";
import { INSTRUMENTS } from "../model/instruments.js";
import { noteNames, timeGrid } from "../model/theory.js";
/**
* Step 3: per-voice pitch assignment. Builds a MiniZinc CSP over note variables
* note_s_t with domain {-2 (hold), -1 (rest), 0..127 (MIDI)}.
* @implements {Step}
*/
export class Step3Notes extends Solvable(Step) {
/**
* @override
* @return {Object[]} Step 3 UI descriptors: voices, per-voice config, counterpoint controls.
*/
schema() {
return SCHEMA;
}
/**
* @override
* Build note-grid model, solve, return solver note-grid + time-grid metadata +
* key/mode/time-signature pass-through on success, or {textOutput} on UNSAT.
* The pass-through fields (numerator, denominator, key, mode) make the result
* a self-contained part record for downstream MIDI generation.
* @param {Object} parameters - Form values plus chords and tempo; see {@link Step3Notes#schema}.
* @param {function(model: string): Promise<Object|null>} solver
* Pre-bound solver callback returning the MZN note-grid solution or null.
* @return {Promise<Object>}
* On success: {textOutput, solution, numSubBeats, subdivision, numerator, denominator, key, mode}.
* On UNSAT: {textOutput} only.
*/
async solve(parameters, solver) {
const { voice, voices, numerator, chords } = parameters;
const bars = chords.length > 0 ? chords.length : parameters.bars;
const time = timeGrid(voice, voices, numerator, bars);
const solution = await solver(modelNotes(parameters, time));
if (!solution) {
return { textOutput: "No solution found for music grid." };
}
return {
textOutput: "Music grid solution found.",
solution,
numSubBeats: time.numSubBeats,
subdivision: time.subdivision,
numerator: parameters.numerator,
denominator: parameters.denominator,
key: parameters.key,
mode: parameters.mode,
};
}
}
/** @private */
const SCHEMA = [
{
name: "voices",
type: "stepper",
label: "Number of Voices",
tooltip: "Number of simultaneous melodic lines",
default: 2,
min: 1,
max: 4,
},
{
name: "voice",
type: "nested",
label: "Voice",
tooltip: "Configure pitch range, instrument & options per voice",
firstColumn: { type: "color", key: "color" },
counter: "voices",
defaults: [
{
color: "#0000ff",
min_pitch: 60,
max_pitch: 84,
instrument: 0,
chord_tones: "scale",
duration: "eighth",
allow_repetitions: true,
},
{
color: "#00ff00",
min_pitch: 52,
max_pitch: 76,
instrument: 0,
chord_tones: "chord",
duration: "quarter",
allow_repetitions: true,
},
{
color: "#ff0000",
min_pitch: 45,
max_pitch: 69,
instrument: 0,
chord_tones: "chord",
duration: "half",
allow_repetitions: true,
},
{
color: "#888888",
min_pitch: 36,
max_pitch: 60,
instrument: 0,
chord_tones: "chord",
duration: "whole",
allow_repetitions: false,
},
],
template: [
{
name: "duration",
type: "select",
label: "Duration",
tooltip: "How many notes per beat",
default: "quarter",
options: ["whole", "half", "quarter", "eighth", "triplet", "sixteenth"],
labels: ["Whole", "Half", "Quarter", "Eighth", "Triplet", "Sixteenth"],
},
{
name: "min_pitch",
type: "int",
label: "Min Pitch",
tooltip: "Lowest allowed note for this voice",
default: 48,
min: 24,
max: 96,
step: 1,
format: (v) =>
`${noteNames()[v % 12]}<sub>${Math.floor(v / 12) - 1}</sub>`,
},
{
name: "max_pitch",
type: "int",
label: "Max Pitch",
tooltip: "Highest allowed note for this voice",
default: 72,
min: 24,
max: 96,
step: 1,
format: (v) =>
`${noteNames()[v % 12]}<sub>${Math.floor(v / 12) - 1}</sub>`,
},
{
name: "instrument",
type: "select",
label: "Instrument",
tooltip: "MIDI instrument (General MIDI)",
default: 0,
groups: Object.entries(INSTRUMENTS).map(([label, names], g) => ({
label,
options: names.map((name, i) => ({
value: Object.values(INSTRUMENTS).slice(0, g).flat().length + i,
label: name,
})),
})),
},
{
name: "voice_options",
type: "checkboxes",
label: "Options",
tooltip: "Per voice",
items: [
{
name: "chord_tones",
label: "Chord/Scale Tones",
tooltip: "[ ]: atonal, [-]: scale tones, [v]: chord tones",
default: "chord",
tristate: true,
},
{
name: "allow_repetitions",
label: "Allow Repetitions",
tooltip:
"Allow consecutive notes of the same pitch (disables M9 for this voice)",
default: true,
ariaInvalid: "false",
},
],
},
],
},
{
name: "seed_pct",
type: "int",
label: "Variety",
tooltip: "% of notes randomly pre-assigned for melodic diversity",
default: 25,
min: 0,
max: 50,
step: 5,
format: (v) => `${v}%`,
},
{
name: "dissonance",
type: "float",
label: "Dissonance",
tooltip: "0 = prefer consonance, 0.5 = neutral, 1 = prefer dissonance",
default: 0.5,
min: 0,
max: 1,
step: 0.1,
},
{
name: "max_interval",
type: "int",
label: "Max Interval",
tooltip: "Max jump between consecutive notes (in semitones)",
default: 6,
min: 0,
max: 12,
step: 1,
format: (v) => `${v} <abbr title="Semitones">st</abbr>`,
},
{
name: "rest_pct",
type: "int",
label: "Max Holds/Rests",
tooltip:
"Max % of beats that can be holds or rests per voice (0 = disable holds/rests entirely)",
default: 25,
min: 0,
max: 50,
step: 5,
format: (v) => `${v}%`,
},
{
name: "constraints",
type: "checkboxes",
label: "Counterpoint",
tooltip: "Voice interdependency",
ariaInvalid: "true",
items: [
{
name: "forbid_unisons",
label: "Forbid Unisons",
tooltip: "Prevent two voices from playing the same pitch",
default: true,
},
{
name: "forbid_parallels",
label: "Forbid Parallels",
tooltip: "Prevent parallel 5ths and octaves between voices",
default: true,
},
],
},
];
|