an.sound_anchors#

Sound cues timed by the picture (an#317): at: {when: <node>, reaches: {y: px}} and until:.

A record scratch has to land when the last line of a crawl becomes readable. Writing that second into the scene means solving the crawl’s geometry outside an, and every layout change moves the picture away from the sound. Here the cue names the event instead, and resolve_cue_anchors() finds the second when the film is laid out:

  • at: {when: crawl/line_7, reaches: {y: 840}} — the first instant the node’s on-screen centre crosses that frame row (or x column), from the very document the stage renders (compiled_document), through the camera, parallax and a crawl’s tilt (an.stage.timeline.screen_position()), sampled at every film frame and interpolated between the two that straddle it; plus offset;

  • at: {when: musket, event: land} — the instant an item’s hold event happens in the compiled shot (the hold report’s events: grasp, place, contact, release, land, bounce, rest; and a topple’s, an.stage.topple), nth picking the n-th; plus offset. A swap’s clink lands on the frame the sabre reaches the socket, wherever the timing of the reach moves it;

  • at: {when: book/body, changes: state, to: page_l} — the instant of the shot’s nth set (or tween) of that node’s property (to that value, when to is given), read from the shot’s own actions: no stage document is needed, so it works in any shot (an#815); plus offset. A page-turn sound follows the page wherever its set is retimed;

  • until: {cue: scratch, offset: 0.12} — the cue ends at that cue’s start plus offset (its duration is derived).

A cue’s second is where its sound’s sync point goes (sync in its sound.json, an.sounds.set_sync(): a clip whose clink comes 0.78 s after a scrape is placed 0.78 s early), so an anchored hit sounds on its frame.

It runs on the in-memory settled copy of the scene (as the measured shot lengths do, an.measurements): scene.md keeps the anchor, never the second. Each resolved cue is reported as an info finding — “scratch at 33.03 s (crawl/line_7 reached y=840)” — which the render report records. An anchor that cannot be resolved (no such node, never reached, a shot no stage draws) refuses before any browser launches.

Functions

anchor_in_document(doc, anchor, *, shot_id, ...)

Shot-local seconds of anchor (an event, an authored change of shot, or a crossing), before its offset.

change_in_shot(shot, anchor, *, where[, ...])

Shot-local seconds of anchor's authored change: the start of the nth set or tween of shot whose target is anchor.when and property anchor.changes (and whose value, a set's value or a tween's to_value, is anchor.to when given), in time order.

crossing_in_document(doc, anchor, *, ...)

Shot-local seconds at which anchor.when's centre first reaches anchor.reaches, in a compiled stage document.

event_in_document(doc, anchor, *, shot_id, where)

Shot-local seconds of anchor's hold event (the nth event of item when) in a compiled stage document.

resolve_cue_anchors(scene, ctx, renderers, ...)

scene (a copy) with every anchored at resolved to seconds and every until to a duration.

Exceptions

SoundAnchorError

A cue's anchor cannot be resolved: the message says which and why.

exception an.sound_anchors.SoundAnchorError[source]#

Bases: ValueError

A cue’s anchor cannot be resolved: the message says which and why.

an.sound_anchors.anchor_in_document(doc, anchor, *, shot_id, fps, duration, where, shot=None, mall=None)[source]#

Shot-local seconds of anchor (an event, an authored change of shot, or a crossing), before its offset.

Return type:

float

an.sound_anchors.change_in_shot(shot, anchor, *, where, play_extent=None)[source]#

Shot-local seconds of anchor’s authored change: the start of the nth set or tween of shot whose target is anchor.when and property anchor.changes (and whose value, a set’s value or a tween’s to_value, is anchor.to when given), in time order. play_extent is the compile’s (an.stage.compile.play_extent_of()), so a set after a natural-length play in a sequence is timed where the picture has it.

>>> from an.ir.schema import SetAction, Shot
>>> shot = Shot(id="s", actions=[
...     SetAction(target="book/body", property="state", value="page_l", at=1.5),
...     SetAction(target="book/body", property="state", value="page_r", at=3.0),
... ])
>>> change_in_shot(shot, CueAnchor(when="book/body", changes="state", to="page_r"), where="x")
3.0
>>> change_in_shot(shot, CueAnchor(when="book/body", changes="state", nth=2), where="x")
3.0
Return type:

float

an.sound_anchors.crossing_in_document(doc, anchor, *, shot_id, fps, duration, where)[source]#

Shot-local seconds at which anchor.when’s centre first reaches anchor.reaches, in a compiled stage document.

Return type:

float

an.sound_anchors.event_in_document(doc, anchor, *, shot_id, where)[source]#

Shot-local seconds of anchor’s hold event (the nth event of item when) in a compiled stage document.

Return type:

float

an.sound_anchors.resolve_cue_anchors(scene, ctx, renderers, *, film_starts)[source]#

scene (a copy) with every anchored at resolved to seconds and every until to a duration.

ctx: the render context the shots are compiled under renderers: each shot’s renderer, in timeline order film_starts: each shot’s start in film time (a meta.sounds anchor’s

shot-local second is moved there)

Return type:

tuple[SceneIR, list[Finding]]