Skip to main content

sva_engine/
lib.rs

1// Concern: resolves a graph into instances a caller can ask about, and keeps their buffers | Non-concern: parsing (sva-ast), CLI framing (sva-cli) | IO: (&Graph, root) -> Instances, Traced
2
3mod arguments;
4mod bindings;
5mod cache;
6mod cast;
7mod error;
8mod index;
9pub mod instantiate;
10mod loops;
11mod lower;
12mod meaning;
13pub mod overload;
14pub mod query;
15mod recent;
16mod refs;
17pub mod render;
18mod schedule;
19mod steps;
20mod threads;
21mod time;
22mod trace;
23mod typing;
24mod vocabulary;
25
26pub use arguments::{Argument, Arguments, Called, Chosen};
27pub use bindings::Binding;
28pub use cache::log::cache_log;
29pub use cache::{
30    Backend, Boot, BootPhase, CacheStats, Call, CallStats, Counters, Cut, DEFAULT_CACHE_BYTES,
31    DEFAULT_MARK_EVERY, DEFAULT_STORE_BYTES, EngineStats, FETCH_READS, Gauge, Hash, INDEX_NAME,
32    Kind, Lookup, Nothing, Opening, Outcome, PayloadKind, Persisted, Phase, Progress, STORE_FORMAT,
33    Store, StoreBoot, Stored, Tally, Tier, Typed, Worked,
34};
35pub use cast::Cast;
36pub use error::{BindingFault, Diagnostic, EngineError, Located, REGISTRY};
37pub use meaning::{Meaning, meaning};
38pub use query::{
39    Answer, Arg, Ask, Atom, DEFAULT_BEATING_WINDOW_SECS, DEFAULT_BUFFER_SECS, DEFAULT_CELL_SECS,
40    DEFAULT_FLOOR_DB, DEFAULT_FRAME_SECS, DEFAULT_LEDGER_DEPTH, DEFAULT_LOUDNESS_WINDOW_SECS,
41    DEFAULT_MAX_PAIRS, DEFAULT_MAX_PEAKS, DEFAULT_MODULATION_WINDOW_SECS,
42    DEFAULT_NOVELTY_WINDOW_SECS, DEFAULT_OVERSAMPLE, DEFAULT_PARTIALS_FLOOR_DB,
43    DEFAULT_PARTIALS_FRAME_SECS, DEFAULT_PARTIALS_HOP_SECS, DEFAULT_PARTIALS_TRACKS,
44    DEFAULT_PARTIALS_WINDOW_SECS, DEFAULT_PATTERN_FRAME_SECS, DEFAULT_PERIODICITY_WINDOW_SECS,
45    DEFAULT_SMOOTH_SECS, DEFAULT_SPL_DB, Given, Harmonic, Output, READINGS, Reading, Reads,
46    Representation,
47};
48pub use refs::{identity, nodes_in, spectral_sum_of};
49pub use render::until::{Cmp, Term};
50pub use render::{
51    Abandon, Built, Change, Changed, Counts, Handle, Hear, LATEST, NOTES, Never, Out, Placed,
52    Range, Render, RenderConfig, STREAMED, Session, Stream, StreamConfig, Until, Work, answer,
53    answer_buffer, atoms_of, change, ends, fetch, plan, render, render_called, render_in,
54    render_over, supports,
55};
56pub use schedule::{Order, Schedule, schedule_from};
57pub use sva_formula::{C64, Codomain, Held, Line, NodeId, SpectralSum, Ty, Var};
58pub use sva_samples::measure::{
59    bands, beating, harmony, loudness_pattern, modulation, partials, periodicity, pitch, score,
60    self_similarity, sharpness, sliding, spectrum,
61};
62pub use sva_samples::resample;
63pub use sva_samples::{
64    Alias, AliasBand, BAND_COUNT, BandCrest, BandTrack, Bands, Buffer, Crest,
65    CuttingBelowSilenceThreshold, Detail, EnvelopeFrame, Extent, FormantFrame, Frames, Label,
66    LedgerEntry, Loudness, LoudnessFrame, MAX_PINNED_FRAME, Note, PEAK_NOTE, PSYCHOACOUSTIC_V1,
67    PitchFrame, Profile, Resampled, Rule, Score, SignalKind, Source, Spectrum, StereoFrame,
68    StereoImage, fitted_frame, measure_alias, pinned_frame,
69};
70pub use threads::default_threads;
71pub use trace::{Traced, Up, trace};
72pub use typing::{Typing, Value, When};
73pub use vocabulary::{MAX_WIDTH, named_may_move, recognized_named, shape, shape_name};
74
75use sva_ast::Graph;
76
77pub const DEFAULT_SAMPLE_RATE: u32 = 44_100;
78
79/// One inference, so a lint and a render refuse identically.
80pub fn check_structure(graph: &Graph, root: &str) -> Result<(), EngineError> {
81    types(graph, root).map(|_| ())
82}
83
84/// One `Ty` per node, across refs, over the instances `root` reaches.
85pub fn types(graph: &Graph, root: &str) -> Result<Typing, EngineError> {
86    types_at(graph, root, DEFAULT_SAMPLE_RATE)
87}
88
89/// At `rate`, whose step each `sp` is.
90pub fn types_at(graph: &Graph, root: &str, rate: u32) -> Result<Typing, EngineError> {
91    let instances = instantiate::instantiate(graph, root, rate)?;
92    // A root names the instance its own defaults resolved to, as `render` asks for.
93    let held = instances.instance_of(root)?;
94    let order = schedule::schedule_from(&instances, std::slice::from_ref(&held))?;
95    typing::infer_all(&instances, &order)
96}