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>
164 lines
5.6 KiB
TypeScript
164 lines
5.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { buildAsset } from '../../src/core/commands/assetCommands';
|
||
import { createEmptyProject } from '../../src/core/model/Project';
|
||
import { createSceneObject } from '../../src/core/model/SceneObject';
|
||
import { coerceValue, defaultsFor, schemaFor } from '../../src/core/properties/PropertySchema';
|
||
import {
|
||
deviatesFromAsset,
|
||
deviatesFromTemplate,
|
||
inheritedValue,
|
||
isModified,
|
||
resolveAssetProps,
|
||
resolveSceneObjectProps,
|
||
} from '../../src/core/properties/resolve';
|
||
|
||
describe('PropertySchema', () => {
|
||
it('has no position on any asset type', () => {
|
||
for (const type of ['scene', 'camera', 'sprite'] as const) {
|
||
const keys = schemaFor(type).map((d) => d.key);
|
||
expect(keys).not.toContain('x');
|
||
expect(keys).not.toContain('y');
|
||
expect(keys).not.toContain('position');
|
||
}
|
||
});
|
||
|
||
it('provides defaults for every key', () => {
|
||
expect(defaultsFor('sprite')).toEqual({
|
||
enabled: true,
|
||
keepOnSceneLoad: false,
|
||
scale: 1,
|
||
rotation: 0,
|
||
mirrorX: false,
|
||
mirrorY: false,
|
||
sortWithParent: false,
|
||
renderLayer: -1,
|
||
width: 100,
|
||
height: 100,
|
||
color: 0xffffff,
|
||
texture: '',
|
||
videoClock: 'free',
|
||
videoTime: 0,
|
||
videoVolume: 1,
|
||
videoBus: '',
|
||
shader: '',
|
||
});
|
||
});
|
||
|
||
it('coerces values against the definition', () => {
|
||
const width = schemaFor('sprite').find((d) => d.key === 'width')!;
|
||
expect(coerceValue(width, -5)).toBe(1);
|
||
expect(coerceValue(width, '42')).toBe(42);
|
||
expect(coerceValue(width, 'abc')).toBe(100);
|
||
const color = schemaFor('sprite').find((d) => d.key === 'color')!;
|
||
expect(coerceValue(color, '#ff0000')).toBe(0xff0000);
|
||
expect(coerceValue(color, 0x1ffffff)).toBe(0xffffff);
|
||
});
|
||
});
|
||
|
||
describe('resolve', () => {
|
||
const project = createEmptyProject('p', 'P');
|
||
it('fills asset props with defaults and ignores unknown keys', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
sprite.props = { width: 50, bogus: 1 };
|
||
expect(resolveAssetProps(project, sprite)).toEqual({
|
||
enabled: true,
|
||
keepOnSceneLoad: false,
|
||
scale: 1,
|
||
rotation: 0,
|
||
mirrorX: false,
|
||
mirrorY: false,
|
||
sortWithParent: false,
|
||
renderLayer: -1,
|
||
width: 50,
|
||
height: 100,
|
||
color: 0xffffff,
|
||
texture: '',
|
||
videoClock: 'free',
|
||
videoTime: 0,
|
||
videoVolume: 1,
|
||
videoBus: '',
|
||
shader: '',
|
||
});
|
||
});
|
||
|
||
it('applies sparse overrides on top of asset values', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
sprite.props.color = 0x00ff00;
|
||
const object = createSceneObject('o1', sprite.id, { x: 10, y: 20 });
|
||
expect(resolveSceneObjectProps(project, sprite, object)).toEqual({
|
||
enabled: true,
|
||
keepOnSceneLoad: false,
|
||
scale: 1,
|
||
rotation: 0,
|
||
mirrorX: false,
|
||
mirrorY: false,
|
||
sortWithParent: true,
|
||
renderLayer: -1,
|
||
width: 100,
|
||
height: 100,
|
||
color: 0x00ff00,
|
||
texture: '',
|
||
videoClock: 'free',
|
||
videoTime: 0,
|
||
videoVolume: 1,
|
||
videoBus: '',
|
||
shader: '',
|
||
});
|
||
|
||
object.overrides.color = 0x0000ff;
|
||
expect(resolveSceneObjectProps(project, sprite, object).color).toBe(0x0000ff);
|
||
expect(inheritedValue(project, sprite, 'color')).toBe(0x00ff00);
|
||
});
|
||
|
||
it('detects asset values that differ from the schema default', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
expect(isModified(project, sprite, 'width')).toBe(false); // explicit default counts as unmodified
|
||
sprite.props.width = 250;
|
||
expect(isModified(project, sprite, 'width')).toBe(true);
|
||
delete sprite.props.height; // missing → resolved from default → unmodified
|
||
expect(isModified(project, sprite, 'height')).toBe(false);
|
||
expect(isModified(project, sprite, 'bogus')).toBe(false);
|
||
});
|
||
|
||
it('ignores an override that carries the asset value – nothing to reset or apply', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
sprite.props.width = 250;
|
||
const object = createSceneObject('o1', sprite.id, { x: 0, y: 0 });
|
||
expect(deviatesFromAsset(project, object, sprite, 'width')).toBe(false); // no override at all
|
||
|
||
object.overrides.width = 250; // same value as the asset → not a deviation
|
||
expect(deviatesFromAsset(project, object, sprite, 'width')).toBe(false);
|
||
|
||
object.overrides.width = 300;
|
||
expect(deviatesFromAsset(project, object, sprite, 'width')).toBe(true);
|
||
|
||
// The asset moving to the object's value settles the difference again.
|
||
sprite.props.width = 300;
|
||
expect(deviatesFromAsset(project, object, sprite, 'width')).toBe(false);
|
||
});
|
||
|
||
it('compares an instance against its template as overrides, not as values', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
const template = createSceneObject('t1', sprite.id, { x: 0, y: 0 });
|
||
const object = createSceneObject('o1', sprite.id, { x: 0, y: 0 });
|
||
expect(deviatesFromTemplate(object, template, 'width')).toBe(false); // neither overrides
|
||
|
||
template.overrides.width = 140;
|
||
expect(deviatesFromTemplate(object, template, 'width')).toBe(true);
|
||
|
||
object.overrides.width = 140;
|
||
expect(deviatesFromTemplate(object, template, 'width')).toBe(false);
|
||
|
||
object.overrides.width = 77;
|
||
expect(deviatesFromTemplate(object, template, 'width')).toBe(true);
|
||
});
|
||
|
||
it('keeps position on the scene object only', () => {
|
||
const sprite = buildAsset('sprite', 'Box');
|
||
const object = createSceneObject('o1', sprite.id, { x: 10, y: 20 });
|
||
expect(object.position).toEqual({ x: 10, y: 20, z: 0 });
|
||
expect('position' in sprite).toBe(false);
|
||
expect(resolveSceneObjectProps(project, sprite, object)).not.toHaveProperty('x');
|
||
});
|
||
});
|