motion.rs

crates/veilvoice-video/src/motion.rs

veilvoice-video · 1162 lines · read the source here · or on GitHub

The moving picture an export draws, and the templates it starts from.

Roadmap item 175. The Browser's video used to be a black frame with the sound under it, which is enough for somewhere that only takes video and is nothing anybody would choose to watch. This is the picture a recording tool draws: a wave that answers the sound as it plays, moving across the frame, in colours chosen to look right in motion.

The whole look is a setting

Motion is every part of it:

  • the lettering: the built-in face, heavier, or none at all (Face);
  • the colours: the background and the wave, each a flat colour or a gradient (Fill);
  • the shape: bars from a baseline, bars mirrored about the middle, or a line (Style);
  • how strongly the wave answers the sound (Motion::response);
  • how many seconds of it are on screen at once (Motion::window_secs);
  • how quickly it settles after a loud moment (Motion::settle_secs).

Templates, so nobody has to open the advanced half

templates is one for every theme the application already has, built from that theme's own colours, and several more chosen because they look right moving rather than because they match a panel. The default is the application's default theme, and its settings are the ones that looked best at sixty frames a second: high enough quality and smooth enough that the defaults are the answer for most people.

Why a timeline of levels rather than the samples

Drawing a frame from the samples means reading every sample on screen, for every frame: six seconds of 48 kHz audio is nearly three hundred thousand samples, sixty times a second. So the recording is reduced once, to a level every five milliseconds with the settling already applied (levels), and a frame reads a few hundred of those. The smoothing is computed in time order along the whole recording, which is what makes it a property of the sound rather than of the frame rate: the same recording settles the same way at twenty-four frames a second and at sixty.

The same picture on every machine

As for everything crate::raster draws: no system fonts and no dependency, so two people exporting one recording with one template get the same frames.

In plain words

This draws the video: a wave that moves with the voice, in a colour scheme you pick from a list or make yourself. The defaults are chosen so that most people never need to change anything.

WHAT THIS FILE CONTAINS

1162 lines defining 27 functions (18 public), 9 types and 8 constants. Everything below is read out of the source, so it cannot disagree with the code.

The types it owns.

  • enum Face line 65 · How the title and the times are lettered.
  • enum Direction line 91 · Which way a gradient runs.
  • enum Fill line 117 · A colour, or two with a gradient between them.
  • enum Style line 160 · The shape the wave is drawn as.
  • struct Motion line 193 · The whole look of a video.
  • struct Template line 249 · A named starting point.
  • struct Levels line 448 · How loud the recording is, about every five milliseconds, already settled.
  • struct Layout line 527 · Where everything on a frame goes.
  • struct Renderer line 573 · Draws the frames of one export.

What happens when it runs. These are the ways in: public, and nothing else in this file calls them, so they are what an outside caller reaches first.

  • Face::label line 80 · What this is called where it is chosen.
  • Direction::label line 106 · What this is called where it is chosen.
  • Fill::middle line 153 · The colour a thumbnail or a picker shows for this fill: its middle.
    reaches at, mix
  • Style::label line 175 · What this is called where it is chosen.
  • Motion::checked line 225 · Refuse settings outside the ranges the controls offer.
  • template line 435 · The template with this identifier.
    reaches templates, from_palette
  • Levels::duration_secs line 464 · How long the recording is.
  • Levels::peak line 472 · The loudest settled level between two moments, from 0.0 to 1.0.
  • levels line 491 · Reduce a recording to the timeline a picture is drawn from.
  • Renderer::new line 588 · A renderer for levels at size, fps frames a second, with title lettered at the top unless the face is Face::None.
    reaches layout, letter
  • Renderer::frames line 643 · How many frames the video has: the length times the rate, rounded up so the last partial frame is still shown.
  • Renderer::undrawable line 649 · Text that came out as boxes, so a front end can say so before the render rather than after.
  • Renderer::frame_bytes line 654 · The size of one frame in bytes, as rgb24.
  • Renderer::frame line 659 · Draw frame index into out, which is resized to fit.
    reaches still, draw_foot, draw_wave, clock, letter, mix, paint
  • thumbnail line 825 · A picture of a whole recording, for a list of them.

WHAT CALLS WHAT

Face::label line 80 Direction::label line 106 Fill::at line 133 Fill::middle line 153 Style::label line 175 Motion::default line 215 Motion::checked line 225 from_palette line 260 templates line 417 template line 435 Levels::duration_secs line 464 Levels::peak line 472 layout line 541 Renderer::new line 588 Renderer::frame line 659 Renderer::still line 666 Renderer::draw_wave line 675 Renderer::draw_foot line 731 Renderer::paint line 770 letter line 796 clock line 860 mix line 871 entry: a way in: public, and nothing in this file calls it api: public, and also used inside this file helper: private to this file dashed: a call that goes back up, or across a wrapped rank The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one. 22 of 25 functions are drawn; the diagram is bounded at 22 so it stays readable.

The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one. 22 of 25 functions are drawn; the diagram is bounded at 22 so it stays readable.

The same graph as Mermaid source
%%{init: {"theme":"base","themeVariables":{"background":"#1a1b26","primaryColor":"#1f2335","primaryTextColor":"#c0caf5","primaryBorderColor":"#7aa2f7","secondaryColor":"#16161e","tertiaryColor":"#16161e","lineColor":"#737aa2","textColor":"#c0caf5","mainBkg":"#1f2335","nodeBorder":"#7aa2f7","clusterBkg":"#16161e","clusterBorder":"#2f3549","fontFamily":"ui-monospace, SFMono-Regular, Consolas, monospace","fontSize":"14px"}}}%%
flowchart TD
    n_label(["Face::label<br/>line 80"])
    n_label(["Direction::label<br/>line 106"])
    n_at["Fill::at<br/>line 133"]
    n_middle(["Fill::middle<br/>line 153"])
    n_label(["Style::label<br/>line 175"])
    n_default["Motion::default<br/>line 215"]
    n_checked(["Motion::checked<br/>line 225"])
    n_from_palette["from_palette<br/>line 260"]
    n_templates["templates<br/>line 417"]
    n_template(["template<br/>line 435"])
    n_duration_secs(["Levels::duration_secs<br/>line 464"])
    n_peak(["Levels::peak<br/>line 472"])
    n_layout["layout<br/>line 541"]
    n_new(["Renderer::new<br/>line 588"])
    n_frame(["Renderer::frame<br/>line 659"])
    n_still["Renderer::still<br/>line 666"]
    n_draw_wave["Renderer::draw_wave<br/>line 675"]
    n_draw_foot["Renderer::draw_foot<br/>line 731"]
    n_paint["Renderer::paint<br/>line 770"]
    n_letter["letter<br/>line 796"]
    n_clock["clock<br/>line 860"]
    n_mix["mix<br/>line 871"]
    n_at --> n_mix
    n_default --> n_from_palette
    n_draw_foot --> n_clock
    n_draw_foot --> n_letter
    n_draw_foot --> n_mix
    n_draw_foot --> n_paint
    n_draw_wave --> n_paint
    n_frame --> n_still
    n_middle --> n_at
    n_new --> n_layout
    n_new --> n_letter
    n_paint --> n_mix
    n_still --> n_draw_foot
    n_still --> n_draw_wave
    n_template --> n_templates
    n_templates --> n_from_palette
    click n_label href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L80" "open the source"
    click n_label href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L106" "open the source"
    click n_at href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L133" "open the source"
    click n_middle href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L153" "open the source"
    click n_label href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L175" "open the source"
    click n_default href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L215" "open the source"
    click n_checked href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L225" "open the source"
    click n_from_palette href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L260" "open the source"
    click n_templates href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L417" "open the source"
    click n_template href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L435" "open the source"
    click n_duration_secs href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L464" "open the source"
    click n_peak href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L472" "open the source"
    click n_layout href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L541" "open the source"
    click n_new href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L588" "open the source"
    click n_frame href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L659" "open the source"
    click n_still href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L666" "open the source"
    click n_draw_wave href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L675" "open the source"
    click n_draw_foot href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L731" "open the source"
    click n_paint href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L770" "open the source"
    click n_letter href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L796" "open the source"
    click n_clock href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L860" "open the source"
    click n_mix href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-video/src/motion.rs#L871" "open the source"
    classDef entry fill:#1f2335,stroke:#7aa2f7,color:#c0caf5
    class n_label,n_label,n_middle,n_label,n_checked,n_template,n_duration_secs,n_peak,n_new,n_frame entry
    classDef api fill:#1f2335,stroke:#7dcfff,color:#c0caf5
    class n_at,n_templates,n_still api
    classDef helper fill:#1f2335,stroke:#bb9af7,color:#c0caf5
    class n_default,n_from_palette,n_layout,n_draw_wave,n_draw_foot,n_paint,n_letter,n_clock,n_mix helper
    subgraph chart_key ["Key"]
        direction LR
        key_entry["entry: a way in: public, and nothing in this file calls it"]
        key_api["api: public, and also used inside this file"]
        key_helper["helper: private to this file"]
    end
    class key_entry entry
    class key_api api
    class key_helper helper

This site loads no third-party script, so it cannot run Mermaid; the diagram above is the same nodes and edges drawn by the generator instead. GitHub renders the source below directly.

ITEMS

ItemLineDocumentation
Face pub enum65How the title and the times are lettered.
Face::ALL pub const77Every face, in the order they are offered.
Face::label pub fn80What this is called where it is chosen.
Direction pub enum91Which way a gradient runs.
Direction::ALL pub const103Every direction, in the order they are offered.
Direction::label pub fn106What this is called where it is chosen.
Fill pub enum117A colour, or two with a gradient between them.
Fill::at pub fn133The colour at a point, given as a fraction of the width and height.
Fill::middle pub fn153The colour a thumbnail or a picker shows for this fill: its middle.
Style pub enum160The shape the wave is drawn as.
Style::ALL pub const172Every style, in the order they are offered.
Style::label pub fn175What this is called where it is chosen.
RESPONSE_RANGE pub const185The smallest and largest Motion::response.
WINDOW_RANGE pub const187The shortest and longest Motion::window_secs.
SETTLE_RANGE pub const189The shortest and longest Motion::settle_secs.
Motion pub struct193The whole look of a video.
Motion::default fn215
Motion::checked pub fn225Refuse settings outside the ranges the controls offer.
Template pub struct249A named starting point.
from_palette fn260The template a theme makes: its own background, its two accents as the wave, its own text colour.
EXTRAS const283The templates that are not a theme, chosen for how they look moving.
templates pub fn417Every template: one per theme, in the themes' own order, then the extras.
template pub fn435The template with this identifier.
HOP_SECS pub const444Seconds between two entries of a Levels timeline, as asked for.
Levels pub struct448How loud the recording is, about every five milliseconds, already settled.
Levels::duration_secs pub fn464How long the recording is.
Levels::peak pub fn472The loudest settled level between two moments, from 0.0 to 1.0.
levels pub fn491Reduce a recording to the timeline a picture is drawn from.
Layout struct527Where everything on a frame goes.
layout fn541Where the wave, the title and the progress line go on a frame of this size.
Renderer pub struct573Draws the frames of one export.
Renderer::new pub fn588A renderer for levels at size, fps frames a second, with title lettered at the top unless the face is Face::None.
Renderer::frames pub fn643How many frames the video has: the length times the rate, rounded up so the last partial frame is still shown.
Renderer::undrawable pub fn649Text that came out as boxes, so a front end can say so before the render rather than after.
Renderer::frame_bytes pub fn654The size of one frame in bytes, as rgb24.
Renderer::frame pub fn659Draw frame index into out, which is resized to fit.
Renderer::still pub fn666Draw frame index as a canvas, for a still or a test.
Renderer::draw_wave fn675The wave as it stands at at_secs, newest sound at the right.
Renderer::draw_foot fn731The elapsed time, the length, and a progress line under them.
Renderer::paint fn770Fill a rectangle with the wave's colours, with soft edges where it falls between pixels.
letter fn796Letter text centred on centre_x, heavier for Face::Bold.
thumbnail pub fn825A picture of a whole recording, for a list of them.
clock fn860m:ss, or h:mm:ss past an hour.
mix fn871Mix from a towards b by t.