How za-warka/itmoloops works
Purpose and Executables
ITMO Loops is a cross-platform C++ DSL renderer: it converts a textual music score into 44.1 kHz, 16-bit WAV audio. CMake defines the build, while CLI entry points are in bin/main.cpp and bin/nmain.cpp; executable wiring is in bin/CMakeLists.txt.
Compilation-to-Audio Pipeline
The main control flow is source file → preprocessing → tokenization/parsing → score model → audio generation → WAV export. The parser produces a time-oriented composition model rather than directly emitting samples, separating DSL interpretation from rendering. Key stages are src/preprocessor/preprocessor.cpp, src/lexer/lexer.cpp, and src/parser/parser.cpp.
Source Preparation and DSL Front End
Preprocessing handles source-file-level transformation and likely inclusion/text normalization boundaries before lexical analysis. The lexer exposes token abstractions consumed by the parser; parser failures are represented in the domain model. Core paths: src/preprocessor/source_file.cpp, src/lexer/token.hpp, src/model/parser_error.hpp.
Musical Score Model
The parsed representation organizes notes, reusable patterns, pattern invocations, and the aggregate score. This is the boundary between declarative composition semantics and sample-level synthesis. src/model/score.hpp, src/model/pattern.hpp, and src/model/note.hpp define this central intermediate model.
Instruments and Voice Synthesis
Instrument is the polymorphic synthesis abstraction. Concrete oscillators generate procedural waveforms, while Sampler reads/playbacks source audio with resampling, looping, and AR envelopes; Noise adds non-tonal synthesis. Runtime-selected instruments are created through a factory, allowing parser-facing names to remain decoupled from implementations. Paths: src/model/instrument.hpp, src/model/factories/instrument_factory.cpp, src/model/instruments/sampler.cpp.
DSP Effects Chain
Effects share a common abstraction and are instantiated through an effect factory. The renderer applies configured effects sequentially to synthesized signal data, supporting gain, echo, filtering, distortion/bit reduction, and modulation. Paths: src/model/effect.hpp, src/model/factories/effect_factory.cpp, src/model/effects/echo.cpp.
Rendering and Audio I/O
The sound generator traverses the score, schedules/mixes polyphonic voices, resolves note frequencies via the note table, and produces PCM samples. WAV input supports sampled instruments; WAV output writes the final binary container. Bundled WAV assets under samples/ are runtime content dependencies for sampler-based scores. Paths: src/generator/sound_generator.cpp, src/utils/note_table.cpp, src/wav/wav_reader.cpp, src/wav/wav_writer.cpp.
Runtime and Delivery Boundaries
The project is a native C++17/20 CMake application with no indicated server, database, or cloud dependencies. Inputs are DSL text plus optional local WAV samples; output is a local WAV file. Example compositions are under examples/, and CI/CD is defined in .github/workflows/cicd.yml.
Main entry points: score.hpp Score model · sound_generator.cpp Sound generator · parser.cpp Parser · instrument_factory.cpp Instrument factory
Components 24
DSL Front End
- DSL score source
- Source file handling
src/preprocessor/source_file.cpp - Preprocessor · Normalizes source-level content before lexing.
src/preprocessor/preprocessor.cpp - Lexer
src/lexer/lexer.cpp - Token abstraction
src/lexer/token.hpp - Parser
src/parser/parser.cpp - Parser errors
src/model/parser_error.hpp
Score & Synthesis
- Score model · Time-oriented boundary between DSL semantics and sample rendering.
src/model/score.hpp - Patterns and notes
src/model/pattern.hpp - Instrument abstraction
src/model/instrument.hpp - Instrument factory
src/model/factories/instrument_factory.cpp - Sampler instrument · Reads WAV sources with resampling, looping, and envelopes.
src/model/instruments/sampler.cpp - Effect abstraction
src/model/effect.hpp - Effect factory
src/model/factories/effect_factory.cpp - Echo effect
src/model/effects/echo.cpp
Audio Rendering & I/O
- Sound generator · Schedules and mixes polyphonic voices into PCM samples.
src/generator/sound_generator.cpp - Note table
src/utils/note_table.cpp - WAV reader
src/wav/wav_reader.cpp - Bundled samples
- WAV writer
src/wav/wav_writer.cpp - Output WAV · 44.1 kHz, 16-bit PCM output.
Other components
- Main CLI
bin/main.cpp - Alternate CLI
bin/nmain.cpp - Executable build wiring
bin/CMakeLists.txt
Connections 26
- Executable build wiring → Main CLI: builds
- Executable build wiring → Alternate CLI: builds
- Main CLI → DSL score source: reads
- Alternate CLI → DSL score source: reads
- DSL score source → Source file handling: loads
- Source file handling → Preprocessor: prepares
- Preprocessor → Lexer: transformed text
- Lexer → Token abstraction: emits
- Token abstraction → Parser: consumed by
- Parser → Parser errors: reports failures
- Parser → Score model: builds
- Patterns and notes → Score model: defines contents
- Score model → Instrument factory: selects instruments
- Instrument factory → Instrument abstraction: creates
- Instrument factory → Sampler instrument: selects
- Bundled samples → WAV reader: source audio
- WAV reader → Sampler instrument: decoded samples
- Score model → Effect factory: configures effects
- Effect factory → Effect abstraction: creates
- Effect factory → Echo effect: selects
- Score model → Sound generator: renders
- Instrument abstraction → Sound generator: synthesizes voices
- Effect abstraction → Sound generator: sequential processing
- Note table → Sound generator: note frequencies
- Sound generator → WAV writer: PCM samples
- WAV writer → Output WAV: writes