Skip to content

Latest commit

 

History

History
175 lines (145 loc) · 9.8 KB

ARCHITECTURE.md

File metadata and controls

175 lines (145 loc) · 9.8 KB

FieldAssist crate architecture

FieldAssist is a Cargo workspace. Library crates form a DAG from leaf utilities up to the desktop application. Sibling crates in the same layer do not depend on each other; traits live in the crate that consumes data, and higher layers supply adapters.

Product behavior is described in docs/spec/ (application, workflows, analysis, processing). This file covers only crate boundaries and composition patterns. The shared Lua surface is documented in scripting/.

Crate DAG

field-core              (file URLs, ProgressHandle, CompositionId `comp:`)
    ├── field-variables (scoped string vars, compose, `${…}` interpolate)
    ├── field-audio-model
    │       (MediaId `media:`, MediaDescriptor, MediaPool, MediaStore, pager;
    │        MediaVariableStore for probe + enrich_media — depends on field-variables)
    │       ├── field-audio-process
    │       └── field-composition ← also field-audio-io, field-core, field-variables
    ├── field-audio-io  (also field-variables for source.* probe / TagMap)
    ├── field-session   (depends on field-core + field-audio-model serde + field-variables;
    │                    DocumentId `doc:`, SessionId `session:`; no
    │                    field-composition edge)
    └── field-audio-playback     (device list for field.audio_devices)

field-features          (feature flag registry; no gpui)
field-settings          (settings.json schema + I/O; no gpui)

field-audio-monitor     (Faust listen DSP; lock-free ParamStore)
field-ui-components     (gpui widgets + host traits / DTOs; field-variables
                         for `${…}` template completion)

field-scripting         (mlua host; depends on field-settings; NO gpui)
    ├── field-batch     (CLI: REPL + script + shebang)
    ├── field-play      (CLI: composition → default device + monitor;
    │                    init.lua + detect_layout)
    └── FieldAssist     (GPUI app; Settings UI; also monitor, ui-components,
                         playback, field-features, field-settings)
Crate Level Responsibility
field-core leaf File URLs, ProgressHandle, prefixed CompositionId
field-variables leaf Scoped string variables, compose (last-wins), ${…} interpolate, variables.json I/O
field-features leaf Feature flag IDs, defaults, and in-memory registry
field-settings leaf Shared settings.json schema and load/save (no GPUI)
field-audio-model leaf PcmBuffer, regions, markers, MediaId / descriptors, MediaPool / MediaStore, BlockPager / BlockSource
field-audio-io leaf Probe/decode/encode above Symphonia and format encoders; source metadata → variables; tagged encode
field-audio-process mid Offline peaks, resampling; future analysis/ops (SPEC-analysis.md)
field-audio-monitor mid Monitor chain Faust DSP, UI schema, lock-free params
field-audio-playback mid Realtime device I/O, transport, playhead
field-ui-components mid Reusable GPUI chrome; host-owned tab titles; data traits; Variables table; ${…} template completion
field-composition high .facomp I/O (v10), EDL, clip tree; re-exports CompositionId
field-session high .fasession I/O (v3) and membership; media|composition targets
field-scripting high Shared Lua 5.4 host (field.* + thin app); ScriptBackend / HeadlessWorld (README)
field-batch app Headless REPL / script runner / Unix shebang over field-scripting
field-play app Headless composition playback; init.lua + detect_layout for monitor chain
FieldAssist app Document editor, GPUI host bridge, docks, playback, Settings UI; embeds workflows

field-scripting sits at the same layer as the app hosts: it may depend on both field-session and field-composition. Its ScriptBackend trait lets each host supply session/document/media storage. FieldAssist keeps GPUI-only script bridges (access, theme, toolbar rendering) and binds host-only app fields (name, theme, command, chrome flags). Settings schema lives in field-settings; FieldAssist owns the Settings window only.

Trait-at-leaf composition

  • BlockSource (field-audio-model): pager asks for file ranges; field-audio-io::SymphoniaBlockSource implements it; composition wires the two.
  • PlaybackDataProvider (field-audio-playback): engine pulls interleaved PCM; the app implements it for Composition / buffers.
  • MonitorProcess (field-audio-playback): engine runs listen DSP without depending on Faust; field-assist adapts MonitorHost → MonitorProcess.
  • WaveformDataProvider + WaveformEditor (field-ui-components): paint/read and selection/drag overlays; BufferDocument implements both. UI types use LaneScope / PaintRegion / u64 edit ids; the app maps ChannelScope / Region / EditId at the trait boundary.
  • List-panel data traits (RegionsData, MarkersData, EditsData): snapshot + fingerprint for observe-and-skip; selection/navigation via callbacks so panels never name WaveformDisplay or model id newtypes.
  • Monitor host surface (MonitorSnapshot / ParamUiNode + callbacks): Faust JSON and MonitorChain stay in the app (monitor_schema adapter); the UI panel is Faust-free.
  • FormatEncoder (field-audio-io): encode planar PCM; render orchestration stays above I/O.

field-ui-components host contract

FieldAssist imports field_ui_components at call sites. Do not re-export UI crate types through the application.

  • Tab titles are host-owned (dock_titles in FieldAssist). Pass title slices to tool_dock_min_size and into panel constructors.
  • Transport and SessionStatusBar take play state / FileStatus DTOs and host-supplied actions or callbacks.
  • Widgets that remain app-shaped (explorer, workspace shell, render sheet, workflow bar, Faust→ParamUiNode and EditOp→card mappers) stay in FieldAssist.

Sample layout (dasp)

Shared sample type is f32 (dasp::sample::Sample).

  • Planar storage in the model, pager, Faust compute, and waveform reads
  • Interleaved frames at the device callback and PlaybackDataProvider::read_interleaved

Do not force pull-based dasp::signal::Signal through random-access DAW paths.

dasp::ring_buffer::{Fixed, Bounded} are useful for single-owner DSP (delays, etc.). They are not used for the playback prefetch↔callback boundary: push/pop need &mut self, so sharing them across threads would require a mutex. field-audio-playback uses an atomic SPSC PrefetchRing instead.

Realtime playback path

The CPAL output callback must stay realtime-safe. Quality gates (also in crates/field-audio-playback/AGENTS.md):

  1. Zero heap allocation on the callback
  2. Zero blocking lock contention on the callback
  3. No decode / filesystem I/O on the callback

PlaybackEngine runs a dedicated fa-prefetch thread that may allocate, lock the composition pager, and decode FLAC/etc. It pushes pre-monitor device-rate interleaved source frames into the SPSC ring, using bandlimited FFT sample-rate conversion when the source rate differs from the device rate (matched rates copy bit-exactly). The CPAL callback pops those frames, runs monitor DSP (Faust) or Direct channel mapping, and writes the device buffer so live parameters track the audible playhead (not ring depth). Composition read_interleaved uses planar pager fills (one lock per request) on that prefetch thread. Direct bypasses Faust only — rate conversion still applies whenever source and device rates differ.

Linux uses CPAL’s ALSA host. Output buffer size is chosen at stream open from settings.json audio.buffer_size_frames (preferred listed frame sizes; not guaranteed), or by negotiating from the device default when unset — prefer about twice that default within CPAL’s supported range, then other in-range catalog sizes, then platform Default. Negotiated results are not written back to settings. Thread priority is CPAL’s realtime-dbus feature on eligible workers (direct ALSA hardware, WASAPI); CoreAudio already runs its callback as real-time. Buffer negotiation and scheduling stay off the callback.

Binaries

  • field-batch: headless Lua (field.*) — REPL with no args, script file + app.args, Unix shebang (#!/usr/bin/env field-batch). Loads settings.json (scripting apply), then user init.lua else the shared embedded default. Does not auto-load Add/Replace/Review (those stay FieldAssist-embedded).
  • field-play: field-composition + field-audio-playback + field-audio-monitor + field-scripting — plays a composition on the preferred / default device (no session). Loads settings.json (scripting + preferred output), then user init.lua else the shared embedded default, runs detect_layout once after open, then uses the composition's monitoring chain when set (otherwise Direct).
  • FieldAssist: desktop app (crates/field-assist). Applies settings from Rust before init; loads embedded workflows plus user resolver_*.lua / workflow_*.lua along the scripting Search Path (Settings → Scripting).
cargo run -p field-batch -- --eval 'return app.name'
cargo run -p field-batch -- script.lua arg1
cargo run -p field-play -- path/to/project.facomp
cargo run -p field-play -- path/to/take.wav

Docs

Every library crate uses #![deny(missing_docs)], a crate-level overview with a short example, and docs on public items. Generate with:

cargo doc --workspace --no-deps --open