alpha2-model 0.10.0

Versioned project and timeline model for alpha2.
Documentation
//! The codes of the project document: load refusals, model errors and lint issues.

use alpha2_diagnose::{Code, Severity};

use crate::{LintIssue, ModelError};

macro_rules! codes {
    ($table:ident, $severity:expr, $level:literal, $($constant:ident = $name:literal, $summary:literal;)*) => {
        $(
            #[doc = concat!("`", $name, "`.")]
            pub static $constant: Code = Code {
                name: $name,
                severity: $severity,
                level: $level,
                summary: $summary,
            };
        )*
        /// Every code of this group.
        pub static $table: &[&Code] = &[$(&$constant),*];
    };
}

macro_rules! variant_codes {
    (
        $enum:ident, $code_of:ident, $table:ident, $variants:ident, $severity:expr,
        $level:literal, $($variant:ident: $constant:ident = $name:literal, $summary:literal;)*
    ) => {
        $(
            #[doc = concat!("`", $name, "`.")]
            pub static $constant: Code = Code {
                name: $name,
                severity: $severity,
                level: $level,
                summary: $summary,
            };
        )*
        /// Every code of this group, one per variant.
        pub static $table: &[&Code] = &[$(&$constant),*];

        pub(crate) const fn $code_of(value: &$enum) -> &'static Code {
            match value {
                $($enum::$variant { .. } => &$constant,)*
            }
        }

        #[cfg(test)]
        pub(crate) static $variants: &[(&str, &Code)] =
            &[$((stringify!($variant), &$constant)),*];
    };
}

codes! {
    LOAD, Severity::Error, 1,
    LOAD_TOO_LARGE = "load.too_large", "The document is larger than the engine reads.";
    LOAD_UNSUPPORTED_VERSION = "load.unsupported_version",
        "The document is of a schema version this build does not read.";
    LOAD_REFUSED = "load.refused", "The engine's parser refuses the document at this place.";
}

variant_codes! {
    ModelError, model_error_code, MODEL, MODEL_VARIANTS, Severity::Error, 1,
    UnsupportedSchemaVersion: MODEL_UNSUPPORTED_SCHEMA_VERSION = "model.unsupported_schema_version",
        "This build cannot interpret the document version.";
    TooManyDataSets: MODEL_TOO_MANY_DATA_SETS = "model.too_many_data_sets",
        "The project has more than `MAX_DATA_SETS` data sets.";
    DuplicateDataSetId: MODEL_DUPLICATE_DATA_SET_ID = "model.duplicate_data_set_id",
        "Two data sets share one ID.";
    InvalidDataSet: MODEL_INVALID_DATA_SET = "model.invalid_data_set",
        "A data set breaks a rule of its kind.";
    InvalidDataBinding: MODEL_INVALID_DATA_BINDING = "model.invalid_data_binding",
        "A data binding, correction or caption words reference is unusable where it sits.";
    EmptyIdentifier: MODEL_EMPTY_IDENTIFIER = "model.empty_identifier",
        "At least one ID was empty.";
    DuplicateSourceId: MODEL_DUPLICATE_SOURCE_ID = "model.duplicate_source_id",
        "Two sources share one ID.";
    DuplicateEffectResourceId: MODEL_DUPLICATE_EFFECT_RESOURCE_ID = "model.duplicate_effect_resource_id",
        "Two effect resources share one ID.";
    DuplicateTrackId: MODEL_DUPLICATE_TRACK_ID = "model.duplicate_track_id",
        "Two tracks share one ID.";
    DuplicateClipId: MODEL_DUPLICATE_CLIP_ID = "model.duplicate_clip_id",
        "Two clips share one ID.";
    EmptyLocator: MODEL_EMPTY_LOCATOR = "model.empty_locator",
        "A source locator was empty.";
    AudioOnImage: MODEL_AUDIO_ON_IMAGE = "model.audio_on_image",
        "A still image source says it has audio, which no image holds.";
    InvalidProvider: MODEL_INVALID_PROVIDER = "model.invalid_provider",
        "A source's provider does not fit it (wrong source kind, audio, or incoherent settings), or a generated source has one.";
    InvalidFingerprint: MODEL_INVALID_FINGERPRINT = "model.invalid_fingerprint",
        "A source's fingerprint is malformed, or a generated source has one.";
    ContradictoryColor: MODEL_CONTRADICTORY_COLOR = "model.contradictory_color",
        "A source declares a color whose dynamic range contradicts its transfer (HDR is exactly a PQ or HLG transfer).";
    InvalidGenerator: MODEL_INVALID_GENERATOR = "model.invalid_generator",
        "A generated source has no valid generator, or has a locator, color metadata or audio; or another source has a generator.";
    InvalidShape: MODEL_INVALID_SHAPE = "model.invalid_shape",
        "A shapes content tree or mask outline breaks a limit, has a value out of range, or has keyframes that cannot interpolate.";
    InvalidLayout: MODEL_INVALID_LAYOUT = "model.invalid_layout",
        "A layout tree breaks a limit or structure rule, has a value out of range, or has keyframes that cannot interpolate.";
    InvalidTextRunStyle: MODEL_INVALID_TEXT_RUN_STYLE = "model.invalid_text_run_style",
        "A text generator's run has a style out of range once applied, or the runs draw in more than `MAX_TEXT_FONT_SELECTIONS` font selections from this run on.";
    EmptyEffectResourceLocator: MODEL_EMPTY_EFFECT_RESOURCE_LOCATOR = "model.empty_effect_resource_locator",
        "An effect resource locator was empty.";
    UnknownEffectResource: MODEL_UNKNOWN_EFFECT_RESOURCE = "model.unknown_effect_resource",
        "A clip effect references an absent effect resource.";
    EmptyClipRange: MODEL_EMPTY_CLIP_RANGE = "model.empty_clip_range",
        "A clip has an empty source or timeline range.";
    NegativeClipRange: MODEL_NEGATIVE_CLIP_RANGE = "model.negative_clip_range",
        "A clip starts before the project or source timeline origin.";
    OverlappingClips: MODEL_OVERLAPPING_CLIPS = "model.overlapping_clips",
        "Two clips overlap without one transition covering their intersection.";
    UnknownClipSource: MODEL_UNKNOWN_CLIP_SOURCE = "model.unknown_clip_source",
        "A clip refers to an absent source.";
    IncompatibleClipSource: MODEL_INCOMPATIBLE_CLIP_SOURCE = "model.incompatible_clip_source",
        "A source cannot be placed on the selected track kind.";
    InvalidVisualProperties: MODEL_INVALID_VISUAL_PROPERTIES = "model.invalid_visual_properties",
        "A visual clip has non-finite values, invalid opacity, or unordered keyframes.";
    InvalidAudioProperties: MODEL_INVALID_AUDIO_PROPERTIES = "model.invalid_audio_properties",
        "A clip has an invalid gain, pan, fade, or audio effect parameter.";
    InvalidTrackAudio: MODEL_INVALID_TRACK_AUDIO = "model.invalid_track_audio",
        "A track bus has an invalid gain, pan or effect parameter, or too many sends.";
    InvalidMasterAudio: MODEL_INVALID_MASTER_AUDIO = "model.invalid_master_audio",
        "The project master bus has an invalid gain, effect, or limiter parameter.";
    InvalidAudioBus: MODEL_INVALID_AUDIO_BUS = "model.invalid_audio_bus",
        "A bus has an invalid gain, pan or effect parameter, or too many sends.";
    InvalidAudioSend: MODEL_INVALID_AUDIO_SEND = "model.invalid_audio_send",
        "A send has an invalid gain.";
    UnknownAudioBus: MODEL_UNKNOWN_AUDIO_BUS = "model.unknown_audio_bus",
        "An output or send names a bus the project does not have.";
    DuplicateAudioBus: MODEL_DUPLICATE_AUDIO_BUS = "model.duplicate_audio_bus",
        "Two buses share an id.";
    AudioRoutingCycle: MODEL_AUDIO_ROUTING_CYCLE = "model.audio_routing_cycle",
        "Outputs, sends and effect keys lead from a track or bus back to itself.";
    TooManyAudioBuses: MODEL_TOO_MANY_AUDIO_BUSES = "model.too_many_audio_buses",
        "The project holds more buses than `MAX_AUDIO_BUSES`.";
    UnknownAudioSidechain: MODEL_UNKNOWN_AUDIO_SIDECHAIN = "model.unknown_audio_sidechain",
        "An effect's `sidechain` names a track or bus the project does not have.";
    UnknownComposition: MODEL_UNKNOWN_COMPOSITION = "model.unknown_composition",
        "A clip names an absent composition.";
    InvalidClipComposition: MODEL_INVALID_CLIP_COMPOSITION = "model.invalid_clip_composition",
        "A clip's composition has a non-positive scale, reaches a composition time past `MAX_SERIALIZED_TICKS` before the clip ends, or is on an audio clip.";
    DuplicateCompositionId: MODEL_DUPLICATE_COMPOSITION_ID = "model.duplicate_composition_id",
        "Two compositions share one ID.";
    InvalidNodeId: MODEL_INVALID_NODE_ID = "model.invalid_node_id",
        "A node ID contains `/`, which is reserved for joining the IDs of inlined group and media nodes.";
    DuplicateNodeId: MODEL_DUPLICATE_NODE_ID = "model.duplicate_node_id",
        "Two nodes of one composition share an ID.";
    TooManyCompositionNodes: MODEL_TOO_MANY_COMPOSITION_NODES = "model.too_many_composition_nodes",
        "A composition has more nodes than the renderer will schedule.";
    InvalidNode: MODEL_INVALID_NODE = "model.invalid_node",
        "A node has an invalid setting: effect identity, version, parameter or value; transform, progress, opacity or mask out of range; too many merge layers or masks; or a bypass on a node without inputs.";
    UnknownNodeInput: MODEL_UNKNOWN_NODE_INPUT = "model.unknown_node_input",
        "A node input names a node its composition does not have.";
    CompositionCycle: MODEL_COMPOSITION_CYCLE = "model.composition_cycle",
        "A node depends on its own output.";
    UnknownCompositionOutput: MODEL_UNKNOWN_COMPOSITION_OUTPUT = "model.unknown_composition_output",
        "A composition's output names a node it does not have.";
    InvalidNodeSource: MODEL_INVALID_NODE_SOURCE = "model.invalid_node_source",
        "A media node names an absent source or one that is not visual.";
    InvalidCompositionPorts: MODEL_INVALID_COMPOSITION_PORTS = "model.invalid_composition_ports",
        "A composition's group inputs are unnamed, repeated or too many, or a control names no effect setting of its nodes or repeats one.";
    UnknownGroupComposition: MODEL_UNKNOWN_GROUP_COMPOSITION = "model.unknown_group_composition",
        "A group node names an absent composition.";
    InvalidTimeOffset: MODEL_INVALID_TIME_OFFSET = "model.invalid_time_offset",
        "A time offset node reads what has no other time.";
    CompositionUsesItself: MODEL_COMPOSITION_USES_ITSELF = "model.composition_uses_itself",
        "A composition uses itself through group nodes or composition sources.";
    CompositionNestedTooDeep: MODEL_COMPOSITION_NESTED_TOO_DEEP = "model.composition_nested_too_deep",
        "Compositions nest, through group nodes, composition sources or time offset nodes, more than `MAX_COMPOSITION_DEPTH` deep.";
    TooManyInlinedNodes: MODEL_TOO_MANY_INLINED_NODES = "model.too_many_inlined_nodes",
        "The compositions draw more than `MAX_INLINED_NODES` nodes, counting each group node and composition-source media node as the nodes it draws and each time offset node as the nodes it draws again.";
    FrameDrawsTooManyNodes: MODEL_FRAME_DRAWS_TOO_MANY_NODES = "model.frame_draws_too_many_nodes",
        "The clips at one instant draw more than `MAX_FRAME_INLINED_NODES` composition nodes together.";
    InvalidCompositionSource: MODEL_INVALID_COMPOSITION_SOURCE = "model.invalid_composition_source",
        "A composition source names an absent composition, or has what only a host-supplied source has.";
    InvalidAdjustmentSource: MODEL_INVALID_ADJUSTMENT_SOURCE = "model.invalid_adjustment_source",
        "An adjustment source has more than an ID and its kind: a locator, generator, composition, color, fingerprint, provider or audio.";
    InvalidAdjustmentTransition: MODEL_INVALID_ADJUSTMENT_TRANSITION = "model.invalid_adjustment_transition",
        "A transition from or to an adjustment clip is not `alpha2.transition.fade`.";
    InvalidEffect: MODEL_INVALID_EFFECT = "model.invalid_effect",
        "An effect, transition or generator under `BUILTIN_EFFECT_PREFIX` that does not match its built-in definition.";
    UnknownNodeResource: MODEL_UNKNOWN_NODE_RESOURCE = "model.unknown_node_resource",
        "A node's effect references an absent effect resource.";
    UnknownSourceResource: MODEL_UNKNOWN_SOURCE_RESOURCE = "model.unknown_source_resource",
        "A generated source's effect generator references an absent effect resource.";
    InvalidClipMask: MODEL_INVALID_CLIP_MASK = "model.invalid_clip_mask",
        "A clip has more than `MAX_CLIP_MASKS` masks, a mask with a negative or non-finite value, or masks on an audio track.";
    InvalidCaptions: MODEL_INVALID_CAPTIONS = "model.invalid_captions",
        "A caption track has no captions, has clips or transitions, or has invalid cues or style; or another track has captions.";
    UnknownCaptionStyle: MODEL_UNKNOWN_CAPTION_STYLE = "model.unknown_caption_style",
        "A caption cue names a style its track does not have.";
    InvalidCaptionCueStyle: MODEL_INVALID_CAPTION_CUE_STYLE = "model.invalid_caption_cue_style",
        "A caption cue's style (its track's with the cue's patch applied), or the style of one of its runs over it, is out of range, or its runs draw in more than `MAX_TEXT_FONT_SELECTIONS` font selections.";
    InvalidTimeMap: MODEL_INVALID_TIME_MAP = "model.invalid_time_map",
        "A clip's time map cannot be played: a freeze outside the source range, or a curve with unusable keyframes.";
    TooManyLoopPasses: MODEL_TOO_MANY_LOOP_PASSES = "model.too_many_loop_passes",
        "A looping clip makes more than `MAX_LOOP_PASSES` passes.";
    InvalidMatte: MODEL_INVALID_MATTE = "model.invalid_matte",
        "A clip's matte names no visual clip, itself, a clip with its own matte, an adjustment clip, or a clip in a transition; or an audio or adjustment clip has a matte.";
    InvalidFrameInterpolation: MODEL_INVALID_FRAME_INTERPOLATION = "model.invalid_frame_interpolation",
        "A clip outside a video track sets a frame interpolation.";
    InvalidClipTransition: MODEL_INVALID_CLIP_TRANSITION = "model.invalid_clip_transition",
        "A transition is not contained in two distinct visual clips on its track.";
    TransitionCycle: MODEL_TRANSITION_CYCLE = "model.transition_cycle",
        "Transitions active at one instant lead from clip to clip in a circle, leaving no clip to show.";
    DuplicateTransition: MODEL_DUPLICATE_TRANSITION = "model.duplicate_transition",
        "Two clips have more than one transition between them, in either direction.";
    TooManyDerivedCues: MODEL_TOO_MANY_DERIVED_CUES = "model.too_many_derived_cues",
        "A caption track derives more than `MAX_DERIVED_CUES` cues from its words, or maps more than `MAX_DATA_WORDS` words through its clips.";
    UnwritableTime: MODEL_UNWRITABLE_TIME = "model.unwritable_time",
        "A time lies past `MAX_SERIALIZED_TICKS` either way, which no document holds.";
    TooManyEffectResources: MODEL_TOO_MANY_EFFECT_RESOURCES = "model.too_many_effect_resources",
        "The project has more than `MAX_EFFECT_RESOURCES` effect resources.";
    TooManyCompositions: MODEL_TOO_MANY_COMPOSITIONS = "model.too_many_compositions",
        "The project contains too many compositions.";
    TooManySources: MODEL_TOO_MANY_SOURCES = "model.too_many_sources",
        "The source table exceeds the bounded project resource budget.";
    TooManyTracks: MODEL_TOO_MANY_TRACKS = "model.too_many_tracks",
        "The timeline contains too many tracks.";
    TooManyClips: MODEL_TOO_MANY_CLIPS = "model.too_many_clips",
        "The timeline contains too many clips in total.";
    TooManyAudioEffects: MODEL_TOO_MANY_AUDIO_EFFECTS = "model.too_many_audio_effects",
        "More audio effects hold state at once than `MAX_AUDIO_EFFECTS`.";
    TooMuchAudioDelay: MODEL_TOO_MUCH_AUDIO_DELAY = "model.too_much_audio_delay",
        "The audio effects hold more than `MAX_AUDIO_DELAY_MS` of delay at once.";
    TooManyClipsOnTrack: MODEL_TOO_MANY_CLIPS_ON_TRACK = "model.too_many_clips_on_track",
        "One track contains too many clips.";
    TooManyCaptionCues: MODEL_TOO_MANY_CAPTION_CUES = "model.too_many_caption_cues",
        "A caption track holds more than `MAX_CLIPS_PER_TRACK` cues.";
    TooManyTransitions: MODEL_TOO_MANY_TRANSITIONS = "model.too_many_transitions",
        "One track contains too many transitions.";
    ZeroCanvasDimension: MODEL_ZERO_CANVAS_DIMENSION = "model.zero_canvas_dimension",
        "Width or height was zero.";
    CanvasDimensionTooLarge: MODEL_CANVAS_DIMENSION_TOO_LARGE = "model.canvas_dimension_too_large",
        "A canvas edge exceeds the portable GPU-independent limit.";
    CanvasPixelBudgetExceeded: MODEL_CANVAS_PIXEL_BUDGET_EXCEEDED = "model.canvas_pixel_budget_exceeded",
        "The canvas area exceeds the bounded pixel budget.";
    InvalidBackground: MODEL_INVALID_BACKGROUND = "model.invalid_background",
        "A background component is non-finite or outside `0..=1`.";
    InvalidColorPipeline: MODEL_INVALID_COLOR_PIPELINE = "model.invalid_color_pipeline",
        "The color pipeline's HDR peak is outside `HDR_PEAK_NITS_RANGE`.";
    InvalidShutter: MODEL_INVALID_SHUTTER = "model.invalid_shutter",
        "A field of the project's shutter is out of range.";
    UnsupportedSampleRate: MODEL_UNSUPPORTED_SAMPLE_RATE = "model.unsupported_sample_rate",
        "The project sample rate is outside the supported DSP interval.";
}

variant_codes! {
    LintIssue, lint_issue_code, LINT, LINT_VARIANTS, Severity::Warning, 2,
    UnreachedKeyframe: LINT_UNREACHED_KEYFRAME = "lint.unreached_keyframe",
        "A keyframe that no shown time depends on.";
    HiddenClip: LINT_HIDDEN_CLIP = "lint.hidden_clip",
        "A clip wholly covered for its whole time by an opaque full-frame clip on a later track.";
    ShortTransition: LINT_SHORT_TRANSITION = "lint.short_transition",
        "A transition no project frame shows as a mix.";
    OffFrameBoundary: LINT_OFF_FRAME_BOUNDARY = "lint.off_frame_boundary",
        "A boundary that is not where a project frame starts, so the change shows at the next frame.";
    UnusedSource: LINT_UNUSED_SOURCE = "lint.unused_source",
        "A source no render reads.";
    HdrSource: LINT_HDR_SOURCE = "lint.hdr_source",
        "A high-dynamic-range source in a project whose color pipeline refuses HDR, so rendering it fails.";
    EmptySubpath: LINT_EMPTY_SUBPATH = "lint.empty_subpath",
        "A path's subpath without vertices, which draws nothing.";
    PaintWithoutGeometry: LINT_PAINT_WITHOUT_GEOMETRY = "lint.paint_without_geometry",
        "A fill or stroke with no geometry before it in its group, which paints nothing.";
    UnusedCaptionStyle: LINT_UNUSED_CAPTION_STYLE = "lint.unused_caption_style",
        "A caption style no cue names and no cue's speaker matches.";
    StaleData: LINT_STALE_DATA = "lint.stale_data",
        "A source-anchored data set made from other media than its source holds now.";
    ManyShiftedReads: LINT_MANY_SHIFTED_READS = "lint.many_shifted_reads",
        "A clip whose composition reads one host-supplied video at more than four other times.";
    EmptyTextAnimator: LINT_EMPTY_TEXT_ANIMATOR = "lint.empty_text_animator",
        "A text animator that sets no property, which changes nothing.";
    MotionBlurWithoutMotion: LINT_MOTION_BLUR_WITHOUT_MOTION = "lint.motion_blur_without_motion",
        "A clip or transform node marked for motion blur that does not move.";
    SubFrameClip: LINT_SUB_FRAME_CLIP = "lint.sub_frame_clip",
        "A clip on the timeline for less than one project frame.";
    HighlightWithoutTimedRuns: LINT_HIGHLIGHT_WITHOUT_TIMED_RUNS = "lint.highlight_without_timed_runs",
        "A highlight over a text with no timed run, which draws nothing.";
}