Files
feuerwerk/tests/core/texture-commands.test.ts
adminandClaude Opus 5.5 4d0a696327 Keep composition sound in step and give compositions a bus of their own
A composition's sound ran on the audio clock while its picture ran on
the frames. A frame counts at most 0.1 s, so after a hitch the sound
stayed ahead of the picture until the next stop. Songs in a trailer
drifted off the cut. The items of a composition also had no bus of
their own, and a video sprite could not pick where its sound goes.

- CompositionSound.follow compares the audio clock with the picture
  each frame. More than 40 ms apart, it starts the sound again where
  the picture is. This holds in the tab and in a run.
- A time scale other than 1 now restarts the sound again and again.
  It stays in time but comes in pieces.
- The sprite of a video item shows "Driven (by composition)" as a
  fixed Video clock row. Video time is hidden there, because the
  composition sets it every frame.
- Every composition has a bus in the mix and a node in the master
  routing. A new one goes to the master unless other compositions are
  linked elsewhere, apart from where the sounds go.
- Audio items pick From asset, To composition, Master or a bus. New
  items start with To composition. Items saved before keep From asset,
  so music already sent through a bus does not bypass it.
- Video sprites have a new row Video bus: From asset by default, the
  master or a bus. In a composition the default is the composition's
  bus, also for video sprites inside a container item.
- The chosen bus is part of the key of the video player, so a sprite
  with another bus gets a player of its own.

Found along the way:

- Six tests with full lists of sprite defaults expected the old rows
  and now list Video bus too.

Tests:
- tsc, eslint, Prettier clean
- Unit: 971 green in the 28 files touched
- npm run check on melektaus-atx: green, 309 files, 4804 tests
- e2e 68 (melektaus-atx): 13 checks green, 68i new. The sound item
  and the video item go into mix:cp68-cut, which goes to the master.
- e2e 69 (melektaus-atx): ALL PASSED, 23 checks, 69q and 69r new.
  After a hitch of 500 ms the sound restarted twice and then lay
  0.5 to 5 ms off the playhead.
- Counter-checks in unit tests: without the comparison the hitch test
  fails, without the bus in the preload the run test fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 10:31:16 +02:00

102 lines
4.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import { CreateAssetCommand, CreateTextureCommand } from '../../src/core/commands/assetCommands';
import { CommandError } from '../../src/core/commands/Command';
import { findAsset } from '../../src/core/model/Project';
import { spriteFromTexture } from '../../src/core/properties/aspect';
import { makeProject } from '../helpers';
const FILE = `${'b'.repeat(64)}.webp`;
describe('CreateTextureCommand', () => {
it('adds a texture asset carrying the uploaded image, and removes it again', () => {
const { project, stack } = makeProject();
const command = new CreateTextureCommand('Hero', { file: FILE, width: 64, height: 32 });
stack.execute(command);
const asset = findAsset(project, command.asset.id);
expect(asset).toMatchObject({ type: 'texture', name: 'Hero', file: FILE, width: 64, height: 32 });
// The schema default comes along, so the new texture is a complete asset – nothing to fill in later.
expect(asset?.props).toEqual({ filter: 'linear', sliceScale: 1 });
stack.undo();
expect(project.assets).toHaveLength(0);
stack.redo();
expect(findAsset(project, command.asset.id)?.name).toBe('Hero');
});
it('keeps the caller’s name even though the upload result carries one of its own', () => {
const { project, stack } = makeProject();
// What `TextureStore.upload` actually answers: the file's original name and its byte count
// ride along. Copied wholesale they would land in the asset and rename it behind the caller.
const upload = { file: FILE, name: 'hero-idle.png', width: 64, height: 32, bytes: 900 };
const command = new CreateTextureCommand('Hero', upload);
stack.execute(command);
const asset = findAsset(project, command.asset.id);
expect(asset?.name).toBe('Hero');
expect(asset).not.toHaveProperty('bytes');
});
it('rejects a file name the server cannot have produced – in execute, not in the constructor', () => {
const { project, stack } = makeProject();
const command = new CreateTextureCommand('Hero', { file: '../secrets.png', width: 1, height: 1 });
expect(() => stack.execute(command)).toThrow(CommandError);
expect(project.assets).toHaveLength(0);
});
it('keeps two assets for the same file apart', () => {
const { project, stack } = makeProject();
stack.execute(new CreateTextureCommand('Hero', { file: FILE, width: 8, height: 8 }));
stack.execute(new CreateTextureCommand('Hero copy', { file: FILE, width: 8, height: 8 }));
expect(project.assets.map((a) => a.id)).toHaveLength(2);
expect(new Set(project.assets.map((a) => a.id)).size).toBe(2);
});
});
describe('CreateAssetCommand with starting props', () => {
it('creates a sprite wearing the texture at its pixel size, and removes it again', () => {
const { project, stack } = makeProject();
const texture = new CreateTextureCommand('Hero', { file: FILE, width: 64, height: 32 });
stack.execute(texture);
const sprite = new CreateAssetCommand('sprite', 'Hero 2', spriteFromTexture(project, texture.asset.id));
stack.execute(sprite);
expect(findAsset(project, sprite.asset.id)?.props).toEqual({
enabled: true,
keepOnSceneLoad: false,
scale: 1,
rotation: 0,
mirrorX: false,
mirrorY: false,
sortWithParent: true,
renderLayer: -1,
width: 64,
height: 32,
color: 0xffffff,
texture: texture.asset.id,
videoClock: 'free',
videoTime: 0,
videoVolume: 1,
videoBus: '',
shader: '',
});
stack.undo();
expect(findAsset(project, sprite.asset.id)).toBeUndefined();
stack.redo();
expect(findAsset(project, sprite.asset.id)?.props.texture).toBe(texture.asset.id);
});
it('passes each value through the schema', () => {
const { project, stack } = makeProject();
const sprite = new CreateAssetCommand('sprite', 'Tiny', { width: -5 });
stack.execute(sprite);
expect(findAsset(project, sprite.asset.id)?.props.width).toBe(1);
});
it('rejects a property the type does not have, leaving the project untouched', () => {
const { project, stack } = makeProject();
expect(() => stack.execute(new CreateAssetCommand('sprite', 'Odd', { zoom: 2 }))).toThrow(CommandError);
expect(project.assets).toHaveLength(0);
});
});