Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
Phase 0 Research: Professional C++20 DSP Architecture Overhaul & Plugin Scanner Separation
Feature: 030-dsp-architecture-overhaul | Date: 2026-10-19
1. Idiomatic .h / .cpp Separation vs. Monolithic Header-Only Devices
Decision
Split all non-template classes across dsp/primitives/, devices/ (25 effects, 16 instruments, 6 MIDI effects, 4 rack classes), engine/, audio_io/, media/, and pluginhost/ into concise declaration headers (.h) and implementation translation units (.cpp). Keep only small inline math/SIMD functions (FastMath.h, Simd.h, SimdAudio.h, AudioSpan.h, RtAttributes.h, ScopedNoDenormals.h, Hadamard.h, Random.h) and class templates (SpscRingBuffer, SnapshotHistory, PolyVoiceManager) in headers.
Rationale
- Currently,
Engine_Devices.cpp,Engine_Render.cpp,RackCore.h, andBuiltinDevices.h#includedozens of 500–1,800 line header-only devices. Modifying a single line inChamber.horVoltSynth.htriggers massive recompilation of core engine translation units. - In idiomatic C++ (and as demonstrated throughout
zrythm/src/dsp/), separating interface (.h) from implementation (.cpp):- Reduces header size from ~1,000 lines to ~60–120 lines per device.
- Hides internal helper functions, lookup tables, and parameter metadata inside anonymous namespaces in
.cppfiles. - Enables
BuiltinDevices.cppandDeviceFactory.cppto be the only translation units that include all device headers, whileEngine_Render.cpponly needsDevice.h,Instrument.h, andMidiDevice.h! - Allows Ninja to compile all 50+ device
.cppfiles in parallel across all CPU cores.
Alternatives Considered
- Keeping header-only devices in subdirectories: Rejected by user requirement ("try to split things into more .cpp and .h files the way C++ is normally written") and because header-only architecture scales poorly in build times and symbol isolation.
2. Plugin Scanner Separation (nota_pluginscanner vs. nota_pluginhost vs. nota_engine)
Decision
Divide pluginhost/ into three distinct layers:
pluginhost/bridge/: Pure C++ headers (PluginHostBridge.h,PluginCatalogBridge.h) with zero JUCE types.pluginhost/scanner/(nota_pluginscannerstatic library +nota-scanworkerexecutable):PluginCatalog.h/PluginCatalog.cpp: Thread-safe registry owningplugins.xmlandscanpaths.txt, guarded bystd::shared_mutexso background scans (Task.Runin C#) and UI thread reads (nota_pluginhost_plugin_desc,nota_pluginhost_index_of_id) never race.OutOfProcessScanner.h/OutOfProcessScanner.cpp: Managesnota-scanworkerchild process execution, timeout enforcement, sentinel slicing (<<<NOTA_PLUGINS_BEGIN>>>..<<<NOTA_PLUGINS_END>>>), and batch/coordinator scanning inspired by Zrythm'sOutOfProcessPluginScanner.abi_pluginscanner.cpp: Implements thenota_pluginhost_scan*andnota_pluginhost_plugin_*C ABI functions.worker/PluginScannerWorker.h/.cpp+worker/main.cpp: The out-of-process scanner executable (nota-scanworker).
pluginhost/hosting/(nota_pluginhoststatic library):PluginHost.h/.cpp,NotaPlayHead.h/.cpp,PluginEditorWindow.h/.cpp,PluginInstrument.h/.cpp,PluginEffect.h/.cpp.- Queries
PluginCatalogBridgeto obtain plugin descriptions by index/ID and instantiatesjuce::AudioPluginInstanceon the main thread.
Rationale
- Completely decouples plugin scanning and catalog management from
nota::Engine. - Fixes the latent thread-safety bug where
PluginScan.cscallsnota_pluginhost_scanon a .NET worker thread while the UI thread readscatalog(). - Preserves 100% of
include/nota/nota_engine.hC ABI by linkingnota_pluginscannerandnota_pluginhostintonota_enginewithWHOLE_ARCHIVE.
3. Zrythm DSP Patterns Adopted in Nota
Decision
Adopt the following proven C++ patterns from Zrythm (zrythm/src/dsp/ and zrythm/src/utils/), adapted to Nota's JUCE-free engine rules:
- Compiler Real-Time Safety Annotations (
RtAttributes.h):- Use
[[clang::nonblocking]](NOTA_RT_SAFE) and[[gnu::hot]](NOTA_HOT) on all audio-thread entry points and callees, enabling Clang's RealtimeSanitizer (-fsanitize=realtime).
- Use
- Explicit Processor Preparation Lifecycle:
- Allocate all buffers strictly during
setSampleRate(sr, maxBlock)/prepare()on the message thread. - Fix
Engine::computeBlockMidi()soblockMidi_andblockExpr_are pre-allocated when theGraphis published on the message thread, never resized on the audio thread.
- Allocate all buffers strictly during
std::span-Based Buffer Views (AudioSpan.h) & Vectorized Float Ranges (Simd.h,SimdAudio.h):- Provide
StereoSpanandConstStereoSpanwrappingstd::span<float>alongside pointer overloads. - Provide vectorized
deinterleaveStereo,interleaveStereo,scaleStereoMeter,addStereoScaledMeterMap,processMasterBus,isSilent, andpeakAndSumSquares.
- Provide
- Cache-Aligned Fork-Join Parallel Executor (
AudioThreadPool.h/.cpp):- Inspired by
zrythm::dsp::graph::ForkJoinExecutor:- Align job slots (
alignas(64)) to prevent false sharing across CPU cores. - Maintain per-worker scratch buffers (
workerScratch_[workerId]) instead of allocating a 128 KBscratchBufon everyTrackinstance. - Ensure every worker thread sets
ScopedNoDenormals(FTZ/DAZ) in its worker loop!
- Align job slots (
- Inspired by
- Reusable Polyphonic Voice Management (
PolyVoiceManager.h/SynthVoice.h):- Inspired by
zrythm::dsp::PolyVoiceManagerandSynthVoice, adapted to fixed-capacity non-allocating storage for Nota's built-in instruments.
- Inspired by
4. Consolidation of DSP Optimization Patches (0001 & 0002)
Decision
Incorporate all optimizations from 0001-feat-Comprehensive-real-time-DSP-performance-optimiz.patch and 0002-feat-Polyphonic-synth-FastMath-SIMD-audio-vectorizat.patch directly into the new modular .h/.cpp architecture, and extend them to the remaining unoptimized devices and instruments:
FastMath.h:exp2f,log2f,dbToLin,linToDb,tanh,tanhPrecise,tanhRatio,sin,cos,tanPrewarp.Simd.h&SimdAudio.h: NEON and SSE/AVX/FMA vectorization, 16-sample early-exitisSilent, single-passpeakAndSumSquares,StereoMeterAccumulator,processMasterBuswith branchless NaN/Inf suppression (squashNonFinite), anddot16for 4x True-Peak FIR limiting.SilenceDetector: Dual-threshold hysteresis ($-80\text{ dBFS}$ attack / $-90.5\text{ dBFS}$ release) withlastMaxPeakcaching to avoid redundant buffer scans.- UI Telemetry Decimation: Batch ring-buffer write index updates (
ringW_) to once per audio block across all analyzers and scopes (Eq,DynamicEq,Compressor,Ceiling,Prism,OperatorSynth,Chorus,Flanger,Phaser,AutoFilter,Vintage,Lens).