Architectural Design Decisions
The engineering principles and architectural trade-offs that govern Cadence. Detailed wire formats, bounds, and DSP formulas live in Specifications.
1. Retained Material Graph as Saved Truth
- Musical definitions outlive clips: Persisted
Project(version = 1) documents store independent patterns, retained derivations, parts, placements, sections, unified Eurorack Modular Rack instruments, mixer topology, modulations, ducks, and macros — never flattened MIDI clips or baked audio. Changing one chord or motif propagates live to every derived layer unless explicitly forked or frozen. - Equal status for literal, derived, and
:minimaterial: All 22PatternKindvariants compose inside one bounded DAG (MAX_DEPTH = 32), share pure stateless evaluation (det_hashSplitMix64 + fractional sub-stepoffset ∈ [0.0, 1.0)), and edit through the same decks and Ex commands. Fork preserves dependency links; freeze captures a bounded literal snapshot;'(From here) scopes an edit to a bar boundary without breaking earlier sections. - Compiled scores are private execution artifacts:
ScoreWindowis an internal flat buffer optimized for O(1) zero-allocation real-time playback and offline rendering, never a persistence or compatibility format.
2. Zero-Legacy Pre-Release Discipline
- Clean replacement over shims: Cadence carries zero schema migration converters, backwards-compatibility aliases, or dead-code fallbacks. When a domain model, parameter curve, or UI contract is wrong, it is replaced cleanly and every caller, test, and showcase example is updated together.
- Strict deserialization: Domain structs enforce
#[serde(deny_unknown_fields)]so typos or stale fields fail loudly at load time instead of silently dropping musical data.
3. Pure cadence-core::dsp Single Point of Truth (SPOT)
- One math implementation for audio and visuals: Every filter transfer function (
Svf,AcidLadder,TptOnePoleLpf, complex parallel dry/wet mix), 4-band EQ response, multi-modeDrivewaveshaper,Halfband2x2× oversampling filter, sample-rate-invariantNoiseGen/PinkFilter/ModalResonator,LoFiProcessor,ModularEnv(Adsr/HoldDecay+ pre-delay + multi-burst), 7-voice PolyBLEP/FM oscillator math,SamplerVoice, soft-knee dynamics gain computer, RT60 tail curve, quadrature LFO, pan law, fader power taper,-60 dBdecay coefficient (decay_coeff_60db_ms), and dB formatter lives once incrates/core/src/dsp/with zero I/O and zero heap allocation. - Structural impossibility of drift: Both
cadence-engine(real-time DSP) andcadence-app::view(GPU curves and readouts) callcadence_core::dsp::*directly, andcrates/app/src/view/live_params.rsmirrors the exact 3-tier Macro/Modulation precedence ofcrates/core/src/material/compile.rs.
4. Unclipped 32-Bit Float Headroom & Console Gain Staging
- No hidden Master soft-clipping: Internal channels, groups, returns, and Master inserts run in uncolored 32-bit float with zero hidden
tanhor limiter behind Master. Clamping to[-1.0, 1.0]happens strictly at the final CPAL hardware DAC conversion and PCM WAV export boundaries. - Clear
hotvs.clippedmetering: Internal float buses exceeding0 dBFSlatch informationalhot(recoverable headroom via faders or a Master Limiter);clippedlatches strictly on non-finite samples anywhere or Master post-fader output> 1.0. - Independent gain factors &
+6 dBheadroom: Channel trim (0.0..=2.0,CHANNEL_GAIN_UNITY_NORM = 0.75console power taper), directModulationTarget::ChannelGain(ChannelGainScale), and event-triggered sidechainDuckenvelopes multiply independently (gain * scale * duck). Mono sources use constant-power panning (pan_mono_equal_power); stereo mixer buses use unity-normalized equal-power balance (pan_stereo_balance) so centered buses pass at exact[1.0, 1.0]unity.
5. Unified Eurorack Modular Rack & Compile-Time Mixer Invariance
- One orthogonal instrument architecture (
RackPatch): Instead of maintaining siloed, non-interoperable instrument engines, everyInstrumentInstanceowns one unified Eurorack ModularRack(Rack → Zones → Modules [Panel] + Patchbay) composed from 11 orthogonal modules (Vco,Sampler,Noise,Env,Lfo,Filter,Vca/RingMod,Drive,LoFi,Resonator,Out), bipolar attenuverter cables, and deterministicz-11-sample feedback compilation. A 1-zone subtractive or 2× through-zero FM synth, a plucked physical-modeling string/bar/plate instrument, a single-sample player, a hybrid analog+sample 32-zone drum kit with 8 choke groups, and a feedback-patched modular voice all run through one zero-allocModularVoiceengine and one orthogonal parameter space (InstrumentParam::{Rack, Zone, Module, Cable}). - Structural Rack & mixer invariance: Every Rack zone enforces
1..=24modules (MAX_RESONATORS_PER_ZONE = 4) with exactly one mandatoryOutmodule (AddRackModule/RemoveRackModuleboth protectOut), validated port compatibility, and atomic pruning of stalepanel_pins,modulations,parameter_links, andmacro.bindingson zone/module/cable removal. On the console side, aChannel’sChannelKind(Audio,Group,Return) and anEffectDevice’sEffectKindare immutable for the lifetime of their ID via typed mixer/effect edits (CreateChannel,UpdateChannelMeta,AddEffect,RemoveEffect,MoveEffect,UpdateEffect).
6. Pure Zero-IO Controller (cadence-app + HostIo)
- Strict crate separation:
cadence-appdepends solely onanyhow,cadence-core,cadence-formats(feature-gatedrbs),serde, andserde_json— no audio backend, no MIDI backend, no windowing, and no directstd::fs/std::envaccess. All host I/O flows throughHostIo(CoreHostIoon disk,MemoryHostIoin pure tests). - One controller, every surface: Interactive keyboard input, hardware MIDI,
--key-script,--script,--stdio, and live GUI--ctlUnix socket requests all converge ontoApp::apply(Action)and one unifiedHostRequestprotocol (src/host/protocol.rs).
7. Keyboard-First Native GPU Decks, Modeless Grammar & Hermetic Typography
- GPU presentation over
FrameView:cadence-appprojects immutable semanticFrameViewsnapshots;cadence-guirenders them on nativewgpu+glyphonthrough a single painter-orderedDisplayListwith balanced scissor clipping, selective phosphor bloom, sharedcable_graph.rsmulti-column Bezier rendering (powering both the Project Signal Graph and Eurorack Instrument Patchbay with ASCII"z-1"feedback badges), embedded cross-platform app icons (icon.rs), and zero hardcoded RGBA values outsidecrates/gui/src/theme.rs(Cadence Dark,Midnight Neon,Studio Light). - Hermetic 2-face embedded typography:
GpuRendererbuilds a self-containedFontSystembacked exclusively by bundledJetBrains MonoRegular (400) and Bold (700) with zero OS font scanning or proportional fallback, and disables programming ligatures (calt/liga/clig/dlig) so keyboard hints like-/=,!=,->, and</>always shape into literal monospace glyphs across platforms. - Modeless 4-tier keyboard grammar & screen-axis alignment:
h/j/k/l(andH/J/K/L) strictly navigate and switch tabs across every deck — zero accidental mutations.Alt+h/j/k/l(Alt+H/J/K/Lcoarse) directly sculpt and reorder items along their visual screen axis with coalesced single-gesture undo, paired with one-hand,/.(</>coarse) scalar adjustments andAlt+Backspacereset.- Six deck layout alignments keep every control list, Rack
Zonesstrip, BankPartsrow, Mixer vertical slot stack, Macros horizontal dial strip, andAudio | MIDIDevices inspector strictly aligned 1:1 with the visual axes. - Only genuine input modes remain:
Insert(ion Pattern Notes), modalJam(gj/Ctrl+Shift+j), exactValueInput(Enter), and live-validatedMiniEditor(EnteronMini).
- Discoverable modals over blind Ex typing:
- Fuzzy Action Palette (
:/Ctrl+Shift+p): Replaces blind GUI Ex mode with fuzzy search over actions, decks, layouts, 8 quick-add FX, themes, and dynamic project objects — while preserving a live top-slot▶ Run command:passthrough so power users,--key-script, andcadence ctl cmdwork without friction. - First-class sound & song dialogs: Unified 6-category Instrument Preset Browser (
P) (All/Synth/Sampler/Drums/Kit/Modular+ 4 bareRackTemplatedefaults) with live non-destructive preview from a fullProjectsnapshot (zero undo trace onEsc, single transaction onEnter), Song Properties (gP/Ctrl+Shift+i) spanning all 13NAMED_SCALES, dedicated live-validated Mini-Notation Editor,Samplersample assignment viaB/Samplerow (auto-insertingSampler -> Out.Inand applying RIFFsmpl/instmetadata), unifiedAudio | MIDIDevices deck (gd/Ctrl+d), and universal/search.
- Fuzzy Action Palette (
- Derived layout state & MIDI symmetry: Workspace, focus, and deck-gating queries compute purely from
Layoutwith zero duplicate shadow fields. Data-driven MIDI profiles (generic,standard_cc,minilab3_daw) map hardware encoders, pads, and OLED/RGB feedback onto the same session actions.
8. Single-Clock Live Performance, 24-Bit Recording & Crash-Safe Takes
- Performing over the arrangement: One monotonic transport clock (
Timeline) drives both song playback and live performance. Launching a part overrides only its lane (claiming any shared instrument) while every other lane continues playing the arrangement; releasing restores the arrangement and keeping writes the override back into it. - Quantized boundaries & human feel: Section jumps land at pass end so loop cycles stay exact; launches, releases, and live song edits land on configurable
Boundarysteps withlate_tolerance_stepscatching just-late presses;StagedChangebatches multiple moves onto one downbeat. - Live 24-bit audio recording into the material graph: Hardware audio input (
ta/tA/ti/:rec) streams lock-free through SPSC capture and monitor rings, converts cleanly across mismatched hardware sample rates, writes a portable 24-bit WAV, and commits aSamplerRack + Part + Placement atomically onto the undo stack. - Live flags outside undo: Lane and channel mute/solo (
LiveFlags) are saved as left, never enter undo history, and never bump song revisions. - Explicitly armed Takes as performance scores: Take recording defaults to OFF (
trtoggles arming live; Chrome displaysTAKE ARM/● REC TAKE (N)/● TAKE CAPPED;Auto-Record Takesin Settingsg,restores opt-in always-on capture) so routine playback never litters session folders. When armed, an off-thread.take.jsonljournal (TAKE_VERSION = 1) captures landed changes (never raw audio) alongside the startingv1project, survives hard crashes up to the last flushed event, supportsvVisual range marking andXconfirmation-guarded discard ingt, renders bit-identically offline (--take --render), and auto-forks definitions edited mid-take when kept into the arrangement.
9. Self-Contained Palette & 100% MIT External Assets
- Native studio completeness: One unified Eurorack Modular Rack (11 orthogonal modules with 7-voice unison, 2× through-zero FM, 4-pole
AcidLowPass, multi-burstModularEnv,LoFiProcessor, 32-mode physicalModalResonator, RIFFsmpl/instSamplermodule, and 32-zone/8-choke-group kits) plus 8 zero-allocation effects (Eq, rhythmicFilter,Compressor, lookahead PDCLimiter, 3-mode 2×-oversampledDrive,Chorus, dual-modeDelay, Hadamard FDNReverb) and nestedGroup → Groupbus routing deliver finished club/ambient mixes in one binary without external plugin dependencies. - Externalized data, portable projects: Zero instrument presets or filter grooves are compiled into the binary (only 4 bare neutral
RackTemplatedefaults live in code) —v1InstrumentPresets inpresets/(6kits including baked and live-synthTR-808/TR-909/EDM Kit,46single-voice drum presets,11synth presets), the 24-groove clean-room MIT factory bank inpresets/filter_grooves.json(extensible up to 128 slots via user banks, browsable live viaP, forkable into editable patterns viaf, and exportable back topresets/filter_grooves.json), and--render-kit-generated MITfactory-samples/load dynamically and degrade gracefully to neutral defaults when absent. Persisted projects reject absolute sample paths, ensuring every project and portable bundle opens reproducibly on any machine.