Play and stop a pattern from a behavior in the game #336
A pattern could only be heard in its tab. Songs come with #334, and only then can #336 play them in a game. Until then a game plays a single pattern, looped or once, through two new nodes. - Play pattern plays the whole pattern through its instrument at its own tempo. The loop on the ruler is only for editing. Inputs are pattern, volume, loop (on by default) and detached. It gives out playback, 0 where there is no instrument or no note. - Stop pattern stops one pattern, every pattern for none, or one playback by its number. Let ring lets notes with an Envelope fall away in their release. - A playing is numbered and owned like a voice. Destroying the object, Stop sound with nothing named and the end of the run stop it. Stop sound with a voice takes a playback too. - Each playing runs on a scheduler of its own (core/music/playbacks). It waits for its files first, and a stop that came earlier wins. - The scheduler has an end for a sequence that does not loop. It stops waking there and is done once its last notes are. - The worker clock moved to viewport/wake.ts, so SoundLibrary can use it without importing music.ts. Tests: - pattern-play.test.ts (new): 8 tests, node catalog +7 cases - e2e 64 (melektaus-atx): ALL PASSED, 23 checks (+3) - Gate (melektaus-atx): CHECK EXIT 0, 248 files, 3854 tests - Counter-checks: no end in the scheduler, and no owner for the playing, each fail 1 test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4ea752feef
commit
2a3b90b017
19 files changed
+745
-28
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import type { NodeDef, PortDef } from '../../NodeRegistry';
|
||||
import { asBoolean, asNumber, asString } from '../../values';
|
||||
import { exec, num, withDefault } from '../shared';
|
||||
|
||||
export const patternPort = (): PortDef => ({
|
||||
key: 'pattern',
|
||||
label: 'pattern',
|
||||
type: 'string',
|
||||
field: { key: 'pattern', label: 'Pattern', kind: 'asset', default: '', assetTypes: ['pattern'] },
|
||||
});
|
||||
|
||||
export const PlayPattern: NodeDef = {
|
||||
type: 'PlayPattern',
|
||||
label: 'Play pattern',
|
||||
category: 'action',
|
||||
description:
|
||||
'Plays a pattern asset through its instrument, at the tempo the pattern has. The whole pattern ' +
|
||||
'is played, from its start to its end: once, or with "loop" round and round until a Stop ' +
|
||||
'pattern ends it – the loop set on its ruler is only for editing. "volume" makes every note of ' +
|
||||
'it quieter. Each play is a playing of its own: firing this twice plays it twice, overlapping. ' +
|
||||
'It belongs to this object like a sound and stops when the object is destroyed, unless ' +
|
||||
'"detached" is on. "playback" is the number of this playing, for Stop pattern; 0 where the ' +
|
||||
'pattern has no instrument or no notes.',
|
||||
inputs: [
|
||||
exec(),
|
||||
patternPort(),
|
||||
withDefault(num('volume'), 1),
|
||||
{
|
||||
key: 'loop',
|
||||
label: 'loop',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
field: { key: 'loop', label: 'Loop', kind: 'boolean', default: true },
|
||||
},
|
||||
{
|
||||
key: 'detached',
|
||||
label: 'detached',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
field: { key: 'detached', label: 'Detached (outlives this object)', kind: 'boolean', default: false },
|
||||
},
|
||||
],
|
||||
outputs: [exec(), num('playback')],
|
||||
params: [],
|
||||
run: (ctx, inputs) => {
|
||||
const pattern = asString(inputs.pattern);
|
||||
const playback = pattern
|
||||
? ctx.playPattern(pattern, asNumber(inputs.volume), asBoolean(inputs.loop), asBoolean(inputs.detached))
|
||||
: 0;
|
||||
return { next: 'exec', outputs: { playback } };
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { asBoolean, asNumber, asString } from '../../values';
|
||||
import { exec, num } from '../shared';
|
||||
import { patternPort } from './PlayPattern';
|
||||
|
||||
export const StopPattern: NodeDef = {
|
||||
type: 'StopPattern',
|
||||
label: 'Stop pattern',
|
||||
category: 'action',
|
||||
description:
|
||||
'Stops every playing of a pattern, however many Play pattern started. With no pattern picked it ' +
|
||||
'stops every pattern, and leaves the sounds alone. With "playback" connected it stops only that ' +
|
||||
'one playing, the number Play pattern handed out, and nothing where it is 0. Its notes fade out ' +
|
||||
'in a few milliseconds; with "let ring" those of an instrument with an Envelope fall away in ' +
|
||||
'its release.',
|
||||
inputs: [
|
||||
exec(),
|
||||
patternPort(),
|
||||
// Not typed in: unconnected it is null, and only then does the pattern decide.
|
||||
{ ...num('playback'), inline: false },
|
||||
{
|
||||
key: 'letRing',
|
||||
label: 'let ring',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
field: { key: 'letRing', label: 'Let ring', kind: 'boolean', default: false },
|
||||
},
|
||||
],
|
||||
outputs: [exec()],
|
||||
params: [],
|
||||
run: (ctx, inputs) => {
|
||||
const letRing = asBoolean(inputs.letRing);
|
||||
if (inputs.playback === null || inputs.playback === undefined)
|
||||
ctx.stopPattern(asString(inputs.pattern), letRing);
|
||||
else {
|
||||
const playback = asNumber(inputs.playback);
|
||||
if (playback > 0) ctx.stopVoice(playback, letRing);
|
||||
}
|
||||
return { next: 'exec' };
|
||||
},
|
||||
};
|
||||
@@ -25,6 +25,8 @@ import { RestartGame } from './action/RestartGame';
|
||||
import { SetPosition } from './action/SetPosition';
|
||||
import { SetSoundFxParameters } from './action/SetSoundFxParameters';
|
||||
import { PlayNote } from './action/PlayNote';
|
||||
import { PlayPattern } from './action/PlayPattern';
|
||||
import { StopPattern } from './action/StopPattern';
|
||||
import { SetZ } from './action/SetZ';
|
||||
import { Spawn } from './action/Spawn';
|
||||
import { StopGame } from './action/StopGame';
|
||||
@@ -308,6 +310,8 @@ export const BUILT_IN_NODES: readonly NodeDef[] = [
|
||||
SoundFxParameters,
|
||||
PlayNote,
|
||||
InstrumentParameterValues,
|
||||
PlayPattern,
|
||||
StopPattern,
|
||||
LoadScene,
|
||||
Log,
|
||||
StopGame,
|
||||
|
||||
Reference in new issue
Block a user