A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(music): scales of five notes, for a piece or for one instrument in it - pentatonic and the five Chinese modes count their degrees to five, so a line cannot touch the two notes they leave out, and an instrument's own scale writes a five-note tune over chords that have all seven
yhhd2e640ee659a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0ac499bd4..665233b97 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -26,7 +26,7 @@ published separately; it ships inside the editor.- **A far field of flowers shows its colour.** A mesh plant kept in a far version grows across the ground to stand for those left out. A flat flower grown that way is a disc facing the sky: from an eye a few metres up it is seen edge on, and a meadow that is all flowers at your feet was plain green a field away. `Foliage.farTilt` tips the top of each far plant over by so many degrees (the last tenth of its height: the flower, not its stem), each plant its own way round, so half the field shows its face. 0, the default, leaves a far plant as it was.- **A layer with a grain is read without repeat and without hexagons.** Near the eye a terrain layer is read in hexagonal cells, each shifted and turned at random, so no tile shows. A layer with a direction to it (sand in ripples, rock in beds) turned cell by cell has its normal map lit cell by cell, and the ground showed a mosaic of light and dark hexagons a metre wide. `u_antiTileTurn` on the Terrain and Terrain Layers materials is how far round a cell may be turned: 1, the default, is any way as before; 0 shifts the cell and does not turn it, which is the setting for a layer with a grain.- **Music with an introduction, and a source that fades.** Background music looped from its first sample to its last, so a piece could not open with something heard once; and an `AudioSource` in a scene started and stopped at full volume, the fades being `playBGM`'s alone. A looping voice now takes `loopStart`, seconds into the clip that it comes back to at its end: `playBGM(url, { loopStart })` and `AudioSource.loopStart` play the file from its top once and round from there after. It is exact to the sample where the clip is decoded, on the web and on the native host; where a clip is played from its compressed file (a long clip streamed on the web, a mini-game) the player is sent back when it ends, which can be heard as a breath. `AudioSource.fadeIn` and `fadeOut` are seconds: raising `playing` brings it up from nothing, lowering it lets it down before the voice is stopped, and raising it again on the way out turns it round where it is. A piece made with `music_write` marks its first parts as an introduction with `intro`, and the reply gives the `loopStart` to play it with.-- **An AI can make background music.** A sound effect is layers; a piece of music is notes, and writing it as layers would be writing every note as a wave. A piece is now an `.esmusic`: instruments, each the layers of a sound written at the A of 440 Hz and struck at the pitch of every note; patterns of a few bars, each track a line of steps (`1 - - . 5, - 3'`, `[1 3 5]`, `x` for a drum) written as degrees of the key, so a line cannot leave it; chords that a bass or a pad follows, written once and moving with them; and the order the patterns come in, with instruments left out of a part so a piece builds. It makes a `.wav` that runs into itself, what rings past its end added to its start, and with `stems` a file for each instrument that add up to the whole, for music that grows with the game. A loop that joins without a click can still be heard to join, where a full last bar runs into a thin first one: the reply says what the last bar and the first hold and warns when they differ. A piece with `loop: false` has an end: it rings out past its last bar, and `fadeIn` and `fadeOut` bring it up and down; a loop has no fade written into it, since the game fades one with `playBGM` and `stopBGM`. Right notes at one loudness, each begun from nothing, are a machine reading a score, so a line can be played: `dynamics` on a pattern give each bar the loudness it begins on and move evenly between them, a crescendo and a diminuendo; `legato` on an instrument brings a note that runs straight on from the last in under it, from past the attack of its recording, as a bow that does not leave the string; and `pedal` holds every note of a piano to the end of its bar. A piece is mixed: an instrument's `lowcut` and `highcut` take off what it has no need of, and `master` holds the loud moments down with `compress` and tilts the whole with `low` and `high`, done to the sum and to each stem alike so they still add up. And `rubato` lets each pattern begin held back, move on and ease off, every instrument together. Whoever writes it cannot hear it, so `music_write`, `music_edit` and `music_read` answer with a picture of the notes, every one a bar in its instrument's colour, and with what can be said of them unheard: two lines crowding one octave, notes outside the key, how loud each instrument is beside the whole. Instruments of layers are made sounds, which suit electronic, retro and ambient music. A piano or strings that pass for real ones are recordings: an instrument may instead have `samples`, a recording in the project for each of a few notes, and every note of the piece is played from the recording nearest it, faster to be higher and slower to be lower; what dies of itself ends with its recording, and what is held goes round the steady middle of it with `loop`. A recording made in stereo comes out of a SoundFont as one file with both its sides, and each zone's level and filter come with it as the sample's `gain` and `cutoff`, so a piano's hundred and eighty zones stay its seventeen recordings. Each recording is listened to: one whose pitch is not the note it is called, or a whole library an octave out because it counts its octaves from another C, is a warning that names the note to set, since nothing in the notes would show an instrument out of tune. A sample marked `dynamic: "soft"` or `"loud"` plays the steps marked `?` or `!`, since a piano struck hard is brighter and not only louder; several samples of one note take turns, so a note repeated is not one recording repeated; and `tune` takes out how sharp a recording is. A SoundFont (`.sf2`) put in a project is a bank of such instruments: `soundfont_read` lists what is in it and takes one out as `.wav` files and the samples that play them, each with its note, range, tuning and loop, after which the SoundFont is not needed. The engine ships no recordings of its own: they are the project's.+- **An AI can make background music.** A sound effect is layers; a piece of music is notes, and writing it as layers would be writing every note as a wave. A piece is now an `.esmusic`: instruments, each the layers of a sound written at the A of 440 Hz and struck at the pitch of every note; patterns of a few bars, each track a line of steps (`1 - - . 5, - 3'`, `[1 3 5]`, `x` for a drum) written as degrees of the key, so a line cannot leave it; chords that a bass or a pad follows, written once and moving with them; and the order the patterns come in, with instruments left out of a part so a piece builds. It makes a `.wav` that runs into itself, what rings past its end added to its start, and with `stems` a file for each instrument that add up to the whole, for music that grows with the game. A loop that joins without a click can still be heard to join, where a full last bar runs into a thin first one: the reply says what the last bar and the first hold and warns when they differ. A piece with `loop: false` has an end: it rings out past its last bar, and `fadeIn` and `fadeOut` bring it up and down; a loop has no fade written into it, since the game fades one with `playBGM` and `stopBGM`. There are scales of five notes, `pentatonic`, `pentatonicMinor` and the Chinese modes `gong`, `shang`, `jue`, `zhi` and `yu`, whose degrees count to five so that a line cannot touch the two notes they leave out; and an instrument may have a `scale` of its own, which is how such a tune is made: five notes in the flute over chords that have all seven. Right notes at one loudness, each begun from nothing, are a machine reading a score, so a line can be played: `dynamics` on a pattern give each bar the loudness it begins on and move evenly between them, a crescendo and a diminuendo; `legato` on an instrument brings a note that runs straight on from the last in under it, from past the attack of its recording, as a bow that does not leave the string; and `pedal` holds every note of a piano to the end of its bar. A piece is mixed: an instrument's `lowcut` and `highcut` take off what it has no need of, and `master` holds the loud moments down with `compress` and tilts the whole with `low` and `high`, done to the sum and to each stem alike so they still add up. And `rubato` lets each pattern begin held back, move on and ease off, every instrument together. Whoever writes it cannot hear it, so `music_write`, `music_edit` and `music_read` answer with a picture of the notes, every one a bar in its instrument's colour, and with what can be said of them unheard: two lines crowding one octave, notes outside the key, how loud each instrument is beside the whole. Instruments of layers are made sounds, which suit electronic, retro and ambient music. A piano or strings that pass for real ones are recordings: an instrument may instead have `samples`, a recording in the project for each of a few notes, and every note of the piece is played from the recording nearest it, faster to be higher and slower to be lower; what dies of itself ends with its recording, and what is held goes round the steady middle of it with `loop`. A recording made in stereo comes out of a SoundFont as one file with both its sides, and each zone's level and filter come with it as the sample's `gain` and `cutoff`, so a piano's hundred and eighty zones stay its seventeen recordings. Each recording is listened to: one whose pitch is not the note it is called, or a whole library an octave out because it counts its octaves from another C, is a warning that names the note to set, since nothing in the notes would show an instrument out of tune. A sample marked `dynamic: "soft"` or `"loud"` plays the steps marked `?` or `!`, since a piano struck hard is brighter and not only louder; several samples of one note take turns, so a note repeated is not one recording repeated; and `tune` takes out how sharp a recording is. A SoundFont (`.sf2`) put in a project is a bank of such instruments: `soundfont_read` lists what is in it and takes one out as `.wav` files and the samples that play them, each with its note, range, tuning and loop, after which the SoundFont is not needed. The engine ships no recordings of its own: they are the project's.- **An AI can make a sound effect.** The engine played recordings and nothing here made one: a game built by an agent had pictures and models of its own and no sounds. A sound is now layers, as a picture is: `sound_write` takes a source of tones (sine, triangle, saw, square), noise (white, pink, brown) and `modes`, the tones a struck thing rings with, each placed in time and shaped by a level, a decay, filters whose corner can move, a second tone bending it, drive, pan and repeats, with an echo and a room over the whole, and writes an `.essound` and the `.wav` a scene plays. Whoever writes one cannot hear it, so the reply is a picture: the wave on top and pitch against time under it, a thump a blot low on the left, a hiss a haze across the top, a falling tone a falling line, with the level and the share of the energy that is low, middle and high. `sound_edit` changes a number and makes it again; `loop` runs the end into the start for an engine or a wind. A gunshot, footsteps, breaking glass, a pickup, an explosion, an engine loop and a laser are 150 to 500 bytes of source each and are made in under a tenth of a second. The same source is the same file on every machine. The first sounds made this way were listened to and did not pass: one noise through one filter with one decay is heard at once as a machine. So a layer can now be what a real sound is made of: noise cut to a `band` and brought back to full level, several of which die at different rates behind an `impulse`; a `tail` that lets part of a decay linger; `scatter`, which strikes a layer hundreds of times at random in time, pitch, loudness and side, for glass, gravel and rain; `repeat` with `faster`, for a thing bouncing to rest; a `peak` filter for the note a body adds; and `reverb` as a place, `room` or `open`, made by laying the sound over what that place answers to a click, with distinct first echoes and a wash whose top dies before its bottom. A layer can also be a recording in the project (`source: "sample"`), played at a speed and shaped as any other layer is, for the one sound that will not come out of waves and noise. The tool text gives the method and the numbers for a shot, glass, a step and an explosion; the step is a shoe on a floor, measured against a recording: a blow on something that rings briefly, heel then ball of the foot, a scrape, nothing under 110 Hz, and a room round it. A `group` is several layers struck together as one event, so four footsteps are one step with `repeat` (787 bytes of source where it was 24 layers), each striking with its own grit. `variants` makes up to eight files that are the same sound and not the same samples, their pitch, loudness, decay and timing off by `vary`, with a sound event beside them that plays one after another without repeating: a game that plays one file for every shot is heard as a machine however good the file. And `reference` names a recording to be like, which is drawn above the made sound in every reply, the same way and to one scale of time, and measured the same way; `sound_read` reads a recording on its own.- **An AI can draw a surface: a picture that repeats, with what the light does on it.** `image_write` drew one picture, and a picture laid beside itself shows its edges; nor is a wall only its colour. `tile: true` on an image source makes it repeat: a shape, a line or a brush stroke that leaves one edge comes in at the opposite one, a shadow and a blur go round with it, and a noise fill meets itself. `material: { relief, height, roughness, metal }` makes it a surface: each of height, roughness and metal is layers drawn as a grey picture of their own (light is high, rough, metal), or the colour's own lightness stands in for the relief, and a normal map, a map of roughness and metal and an `.esmaterial` are written beside the picture. The reply shows the picture laid beside itself two by two, where a join would run through the middle, and the same under a low light, and gives the fields to put on a mesh. A brick wall, a plank floor and a riveted plate, 256 pixels each, drew in under a third of a second apiece and tiled three across in the engine with no join. A `filter` still stops at the edges, and a noise turned or stretched by `transform` does not come round.- **A model is written once for all its like parts, and a leaf can be a picture.** A model's source was a flat list of steps with plain numbers: a plant of ten fronds wrote out a frond ten times, and every leaf was a thin solid in one colour. Three things change that. `params` names numbers and points, and a value written `"=length * 0.4"` is a sum over them, with points that add and scale, angles in degrees, and makers for what shapes keep asking for: `polar` for a point round the upright axis, `arc` for a line that bends from one lean to another, `part` for a share of a line. `{ op: "repeat", over: [rows], steps: [...] }` runs its steps once for each row, the row's fields being names inside it, and `let` names a value for the steps after it; what is saved and edited is the source as written, so one edit to a name changes every part. The `strip` step carries a band with no thickness along a path, shaped by `widths`, folded by `cup`, with a picture laid along it from root to tip. `material.texture` names that picture, and with `alpha: "cutout"` its alpha is the outline: a leaf with veins and a torn edge, drawn once. `loft` takes an `up` for the way its section stands. The palm that was 386 steps is six steps written in two models of 2.9 and 2.4 KB, and 9,150 triangles where it was 26,814. Drawn in the engine it cost a little more GPU than the solid one all the same (about 1.1 ms against 0.8 for the frame at 1024 by 1024 on an RTX 3060): cut-out leaves draw both sides and test every pixel.diff --git a/desktop b/desktopindex d037d5529..8e9710277 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit d037d5529235e1259b453bb4bd48cc635894b301+Subproject commit 8e9710277775e668caa8ee056985fb43a3be3fbddiff --git a/pipeline/src/music/musicRender.ts b/pipeline/src/music/musicRender.tsindex b0e79acf7..89163fedb 100644--- a/pipeline/src/music/musicRender.ts+++ b/pipeline/src/music/musicRender.ts@@ -113,7 +113,7 @@ export function compileMusic(source: MusicSource): CompiledMusic {if (typeof part !== 'string' && (part.without?.includes(track) || (part.only && !part.only.includes(track)))) continue;const instrument = source.instruments[track]!;if (instrument.follow && !pattern.chords) say(`"${track}" follows the chords, and pattern "${name}" has none: it plays every bar on chord 1`);- const steps = parseTrack(line, pattern.bars, stepsToBar, `pattern "${name}", track "${track}"`);+ const steps = parseTrack(line, pattern.bars, stepsToBar, `pattern "${name}", track "${track}"`, SCALES[instrument.scale ?? source.scale ?? 'minor'].length);// Time that gives: late at the start of the phrase, made up through its middle, late again toward its end,// and back where it was on the last bar line, so the pattern is as long as it was written.const phrase = pattern.bars * barSeconds;@@ -155,11 +155,15 @@ export function compileMusic(source: MusicSource): CompiledMusic {const slurred = !!instrument.legato && s.notes.length === 1 && before !== null && before.end === i && s.loud <= 1;if (slurred) before!.event.tied = true;const chord = instrument.follow && pattern.chords ? pattern.chords[Math.floor(i / stepsToBar) % pattern.chords.length]! : 1;- // A root on 5, 6 or 7 is taken below the tonic, so the chords lie round it and a bass does not climb away.- const drop = chord >= 5 ? -7 : 0;+ // A root in the upper part of the scale (5, 6 or 7 of seven; 4 or 5 of five) is taken below the tonic, so the+ // chords lie round it and a bass does not climb away.+ // The instrument's own scale where it has one: the same tonic, other notes.+ const own = instrument.scale ? SCALES[instrument.scale] : scale;+ const size = own.length;+ const drop = chord > size / 2 + 1 ? -size : 0;for (const n of s.notes) {- const index = n.degree - 1 + chord - 1 + drop + 7;- const midi = 60 + tonic + scale[index % 7]! + 12 * (Math.floor(index / 7) - 1 + n.octave + (instrument.octave ?? 0)) + n.alter;+ const index = n.degree - 1 + chord - 1 + drop + size;+ const midi = 60 + tonic + own[index % size]! + 12 * (Math.floor(index / size) - 1 + n.octave + (instrument.octave ?? 0)) + n.alter;events.push({ instrument: track, at: when, seconds: written, midi, loud, part: p, outside: n.alter !== 0, mark, hard, ...sounds, ...(slurred ? { slur: true } : {}) });}before = s.notes.length === 1 ? { end: i + held, event: events.at(-1)! } : null;diff --git a/pipeline/src/music/musicSource.ts b/pipeline/src/music/musicSource.tsindex a05656b84..636123c82 100644--- a/pipeline/src/music/musicSource.ts+++ b/pipeline/src/music/musicSource.ts@@ -19,8 +19,20 @@ export const MUSIC_SOURCE_EXT = '.esmusic';export const MUSIC_SOURCE_VERSION = 1;export const MAX_MUSIC_SECONDS = 240;-/** Semitones above the tonic of each of a scale's seven degrees. */+/**+ * Semitones above the tonic of each of a scale's degrees. Most have seven. The five-note scales have five, and a line+ * written in one of them cannot touch the two notes it leaves out, which is the whole of their sound: `pentatonic`+ * and `pentatonicMinor` by their Western names, and the five Chinese modes, each the same five notes begun from+ * another of them, gong (do), shang (re), jue (mi), zhi (sol) and yu (la).+ */export const SCALES = {+ pentatonic: [0, 2, 4, 7, 9],+ pentatonicMinor: [0, 3, 5, 7, 10],+ gong: [0, 2, 4, 7, 9],+ shang: [0, 2, 5, 7, 10],+ jue: [0, 3, 5, 8, 10],+ zhi: [0, 2, 5, 7, 9],+ yu: [0, 3, 5, 7, 10],major: [0, 2, 4, 5, 7, 9, 11],minor: [0, 2, 3, 5, 7, 8, 10],dorian: [0, 2, 3, 5, 7, 9, 10],@@ -75,6 +87,13 @@ export interface MusicInstrument {octave?: number;/** Its degrees count from the root of the bar's chord: 1 is the root, 3 the third, 5 the fifth, whatever the chord. A bass or a pad that follows is written once and moves with the chords. */follow?: boolean;+ /**+ * A scale of its own, on the piece's tonic, that its line is written in: a tune in the five notes of `yu` over a+ * piece in `minor`, whose chords and bass have all seven. That is how the style is made, a tune that cannot+ * touch the two notes the harmony under it is free to use. Not for an instrument that follows the chords, whose+ * degrees are counted from them.+ */+ scale?: ScaleName;/** Seconds a held note takes to die after it is let go. Default 0.08. */release?: number;/**@@ -223,7 +242,7 @@ function noteOf(text: string): StepNote | null {}/** A track's line as steps, bar by bar. Throws saying which bar is wrong and why. */-export function parseTrack(text: string, bars: number, stepsToBar: number, where: string): Step[] {+export function parseTrack(text: string, bars: number, stepsToBar: number, where: string, degrees = 7): Step[] {const out: Step[] = [];const written = text.split('|').map((b) => b.trim());if (written.at(-1) === '') written.pop();@@ -244,6 +263,8 @@ export function parseTrack(text: string, bars: number, stepsToBar: number, whereif (notes.length === 0 || notes.length > 6 || notes.some((n) => n === null)) {throw new Error(`${where}, bar ${b + 1}: "${token.replace(/\+/g, ' ')}" is not a step. A step is . (silence), - (hold), x (a drum), a degree 1..7 with ' or , for octaves and # or b before it, or [1 3 5] for up to six at once`);}+ const past = (notes as StepNote[]).find((n) => n.degree > degrees);+ if (past) throw new Error(`${where}, bar ${b + 1}: degree ${past.degree} is not in this scale, which has ${degrees} notes: its degrees are 1..${degrees}, and the next octave begins again at 1'`);out.push({ kind: 'notes', loud: loudOf(mark), notes: notes as StepNote[] });}}@@ -252,7 +273,7 @@ export function parseTrack(text: string, bars: number, stepsToBar: number, where}const SOURCE_FIELDS = ['version', 'tempo', 'beats', 'key', 'scale', 'swing', 'humanize', 'seed', 'instruments', 'patterns', 'song', 'loop', 'intro', 'fadeIn', 'fadeOut', 'stems', 'reverb', 'rubato', 'master', 'gain', 'rate'];-const INSTRUMENT_FIELDS = ['layers', 'samples', 'attack', 'gain', 'pan', 'octave', 'follow', 'release', 'reverb', 'legato', 'pedal', 'lowcut', 'highcut'];+const INSTRUMENT_FIELDS = ['layers', 'samples', 'attack', 'gain', 'pan', 'octave', 'follow', 'release', 'reverb', 'legato', 'pedal', 'lowcut', 'highcut', 'scale'];const RECORDING = /\.(wav|ogg|mp3|flac|m4a|aac|webm)$/i;function checkSamples(samples: unknown, where: string): void {@@ -339,11 +360,16 @@ export function validateMusicSource(raw: unknown): MusicSource {if (value.reverb !== undefined && !between(value.reverb, 0, 1)) throw new Error(`${where}: reverb must be 0..1`);if (value.legato !== undefined && typeof value.legato !== 'boolean' && !between(value.legato, 0.01, 0.5)) throw new Error(`${where}: legato must be true, or the seconds one note takes to come in under the last, 0.01..0.5`);if (value.pedal !== undefined && typeof value.pedal !== 'boolean') throw new Error(`${where}: pedal must be true or false`);+ if (value.scale !== undefined) {+ if (!(typeof value.scale === 'string' && value.scale in SCALES)) throw new Error(`${where}: scale must be one of ${Object.keys(SCALES).join(', ')}`);+ if (value.follow) throw new Error(`${where}: an instrument that follows the chords counts its degrees from them, in the piece's scale; a scale of its own is for a line that does not follow`);+ }if (value.lowcut !== undefined && !between(value.lowcut, 20, 2000)) throw new Error(`${where}: lowcut must be Hz, 20..2000`);if (value.highcut !== undefined && !between(value.highcut, 500, 20000)) throw new Error(`${where}: highcut must be Hz, 500..20000`);}const beats = (s.beats as number | undefined) ?? 4;+ const degrees = SCALES[(s.scale as ScaleName | undefined) ?? 'minor'].length;if (!isObj(s.patterns) || Object.keys(s.patterns).length === 0) throw new Error('patterns must be { name: { bars, tracks: { instrument: "steps" } } }, at least one');for (const [name, value] of Object.entries(s.patterns)) {const where = `pattern "${name}"`;@@ -353,8 +379,8 @@ export function validateMusicSource(raw: unknown): MusicSource {if (!(Number.isInteger(value.bars) && between(value.bars, 1, 32))) throw new Error(`${where}: bars must be a whole number, 1..32`);if (value.div !== undefined && !(Number.isInteger(value.div) && between(value.div, 1, 8))) throw new Error(`${where}: div must be whole steps to a beat, 1..8`);if (value.chords !== undefined) {- if (!Array.isArray(value.chords) || value.chords.length === 0 || value.chords.length > (value.bars as number) || value.chords.some((c) => !(Number.isInteger(c) && c >= 1 && c <= 7))) {- throw new Error(`${where}: chords must be the degree of each bar's root, 1..7, no more of them than bars`);+ if (!Array.isArray(value.chords) || value.chords.length === 0 || value.chords.length > (value.bars as number) || value.chords.some((c) => !(Number.isInteger(c) && c >= 1 && c <= degrees))) {+ throw new Error(`${where}: chords must be the degree of each bar's root, 1..${degrees}, no more of them than bars`);}}if (value.dynamics !== undefined) {@@ -370,7 +396,7 @@ export function validateMusicSource(raw: unknown): MusicSource {for (const [track, line] of Object.entries(value.tracks)) {if (!(track in s.instruments)) throw new Error(`${where} has a track for "${track}", which is not an instrument; the instruments are ${Object.keys(s.instruments).join(', ')}`);if (typeof line !== 'string') throw new Error(`${where}, track "${track}" must be a line of steps`);- parseTrack(line, value.bars as number, beats * ((value.div as number | undefined) ?? 4), `${where}, track "${track}"`);+ parseTrack(line, value.bars as number, beats * ((value.div as number | undefined) ?? 4), `${where}, track "${track}"`, SCALES[((s.instruments as Record<string, MusicInstrument>)[track]!.scale ?? (s.scale as ScaleName | undefined) ?? 'minor')].length);}}diff --git a/pipeline/tests/music.test.ts b/pipeline/tests/music.test.tsindex 25138dfde..bed788401 100644--- a/pipeline/tests/music.test.ts+++ b/pipeline/tests/music.test.ts@@ -714,3 +714,56 @@ describe('the whole, mixed and breathing', () => {expect(bad({}, { highcut: 100 })).toThrow(/highcut must be Hz, 500\.\.20000/);});});++describe('scales of five notes', () => {+ const five = (scale: string, line: string, more: Record<string, unknown> = {}, pattern: Record<string, unknown> = {}) => compileMusic(validateMusicSource({+ tempo: 120, key: 'A', scale, humanize: 0, instruments: { tone, low: { ...tone, follow: true } }, patterns: { a: { bars: 1, tracks: { tone: line }, ...pattern } }, song: ['a'], ...more,+ })).events.map((e) => noteName(e.midi!));+ const run = "1 2 3 4 5 1' 2' 5, . . . . . . . .";++ it('count their degrees to five, and begin the next octave again at 1', () => {+ // La do re mi sol: the five notes of the minor that a wuxia tune is made of.+ expect(five('yu', run)).toEqual(['A4', 'C5', 'D5', 'E5', 'G5', 'A5', 'C6', 'G4']);+ expect(five('pentatonicMinor', run)).toEqual(five('yu', run));+ // Do re mi sol la.+ expect(five('gong', run, { key: 'C' })).toEqual(['C4', 'D4', 'E4', 'G4', 'A4', 'C5', 'D5', 'A3']);+ expect(five('pentatonic', run, { key: 'C' })).toEqual(five('gong', run, { key: 'C' }));+ // The other three modes are the same five notes begun from re, mi and sol.+ expect(five('shang', '1 2 3 4 5 . . . . . . . . . . .', { key: 'D' })).toEqual(['D4', 'E4', 'G4', 'A4', 'C5']);+ expect(five('jue', '1 2 3 4 5 . . . . . . . . . . .', { key: 'E' })).toEqual(['E4', 'G4', 'A4', 'C5', 'D5']);+ expect(five('zhi', '1 2 3 4 5 . . . . . . . . . . .', { key: 'G' })).toEqual(['G4', 'A4', 'C5', 'D5', 'E5']);+ });++ it('cannot be written out of: a sixth degree is refused, and says why', () => {+ expect(() => five('yu', '1 2 6 . . . . . . . . . . . . .')).toThrow(/pattern "a", track "tone", bar 1: degree 6 is not in this scale, which has 5 notes: its degrees are 1\.\.5, and the next octave begins again at 1'/);+ expect(() => five('yu', '[1 3 7] . . . . . . . . . . . . . . .')).toThrow(/degree 7 is not in this scale/);+ // The same line is fine in a scale of seven.+ expect(five('minor', '1 2 6 . . . . . . . . . . . . .')).toEqual(['A4', 'B4', 'F5']);+ expect(() => five('yu', run, {}, { chords: [6] })).toThrow(/chords must be the degree of each bar's root, 1\.\.5/);+ });++ it('lets one instrument write in five notes over a piece that has seven', () => {+ const source = (tune: string) => validateMusicSource({+ tempo: 120, key: 'A', scale: 'minor', humanize: 0, instruments: { flute: { ...tone, scale: 'yu' }, low: { ...tone, follow: true } },+ patterns: { a: { bars: 1, chords: [6], tracks: { flute: tune, low: '[1 3 5] . . . . . . . . . . . . . . .' } } }, song: ['a'],+ });+ const e = compileMusic(source("1 2 3 4 5 1' . . . . . . . . . ."));+ // The flute counts five; the chord under it is F, which the flute could not play.+ expect(e.events.filter((x) => x.instrument === 'flute').map((x) => noteName(x.midi!))).toEqual(['A4', 'C5', 'D5', 'E5', 'G5', 'A5']);+ expect(e.events.filter((x) => x.instrument === 'low').map((x) => noteName(x.midi!))).toEqual(['F4', 'A4', 'C5']);+ expect(() => source('6 . . . . . . . . . . . . . . .')).toThrow(/track "flute", bar 1: degree 6 is not in this scale, which has 5 notes/);+ expect(() => validateMusicSource({ tempo: 120, key: 'A', instruments: { low: { ...tone, follow: true, scale: 'yu' } }, patterns: { a: { bars: 1, tracks: { low: REST } } }, song: ['a'] })).toThrow(/a scale of its own is for a line that does not follow/);+ });++ it('builds what follows a chord from the five notes, with roots on 4 and 5 below the tonic', () => {+ const follow = (chord: number): string[] => compileMusic(validateMusicSource({+ tempo: 120, key: 'A', scale: 'yu', humanize: 0, instruments: { low: { ...tone, follow: true } },+ patterns: { a: { bars: 1, chords: [chord], tracks: { low: '[1 3 5] . . . . . . . . . . . . . . .' } } }, song: ['a'],+ })).events.map((e) => noteName(e.midi!));+ // Every other note of the five from the root: fourths and fifths, the open sound of the style.+ expect(follow(1)).toEqual(['A4', 'D5', 'G5']);+ expect(follow(3)).toEqual(['D5', 'G5', 'C6']);+ expect(follow(4)).toEqual(['E4', 'A4', 'D5']);+ expect(follow(5)).toEqual(['G4', 'C5', 'E5']);+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex f407145d8..6cf7e27dc 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -4648,6 +4648,10 @@ export const NOTED = {{"note": "An AI can make background music."},"fix(music): an instrument only struck as a drum is not told its recording is the wrong note - the pitch found in a drum is not a note it can be out of":{"note": "An AI can make background music."},+ "feat(music): scales of five notes, for a piece or for one instrument in it - pentatonic and the five Chinese modes count their degrees to five, so a line cannot touch the two notes they leave out, and an instrument's own scale writes a five-note tune over chords that have all seven":+ {"note": "An AI can make background music."},+ "feat(music): the tool text says the five-note scales and how a tune in one sits over a piece in seven":+ {"note": "An AI can make background music."},"feat(sky): a sky of your own shades the ground under its clouds - defineSkyEffect takes groundShadow and a second function, skyShadow(world, sun), what is left of the light at a world position, and the sky pass multiplies every surface it finds by it, as Sky Atmosphere does with its own clouds":{"note": "A sky of your own shades the ground under its clouds."},"fix(terrain): a colour map and an occlusion map lie the way the heightmap does - Terrain.colorMap, Terrain.occlusionMap and Foliage.colorMap were sampled with their rows turned over, so a picture painted to match a heightmap, a splatmap or a density map came out mirrored north to south under them; an image over an area now has its first row along the least z whoever reads it":