How mctop4ik/midiwavconverter works
Purpose and Entry Point
Zetni is a C++ music-rendering/synthesis tool. It converts text-based song definitions into audio using patterns, instruments, effects, sampled WAV assets, and WAV output. The executable entry point is src/zetni_main.cc; build composition is defined by CMakeLists.txt.
Input-to-Output Pipeline
The orchestration layer in src/zetni-pipeline.cc connects parsing, synthesis, and file output. Music source files such as examples/badapple.txt and examples/interstellar.txt are parsed into an internal music representation, rendered by the engine, then serialized as waveform data through src/zetni-wavefile.cc.
Key contracts are exposed in includes/zetni/zetni-pipeline.h, includes/zetni/zetni-music-file.h, and includes/zetni/zetni-wavefile.h.
Syntax and Music Parsing
src/zetni-syntax-analyzator.cc performs syntax-level analysis before semantic music parsing. src/zetni-parser.cc handles the broader source format, while src/zetni-pattern-parser.cc creates pattern-specific structures.
The resulting pattern model is implemented in src/zetni-pattern.cc and declared by includes/zetni/zetni-pattern.h. This separates textual notation concerns from playback/rendering behavior.
Pattern Execution
Patterns are executable sequences of instructions. Two central instruction types are:
• Instrument playback: src/pattern-instructions/zetni-instrument-play-pattern-instruction.cc
• Pattern invocation/composition: src/pattern-instructions/zetni-call-another-pattern-instruction.cc
Their interfaces in includes/zetni/interfaces/zetni-pattern-instruction-interface.h and related headers allow the engine to schedule notes and reuse named patterns without coupling the parser directly to concrete instruction implementations.
Rendering Engine and Envelope Control
src/zetni-engine.cc is the primary audio-rendering boundary: it consumes parsed music/pattern data, invokes instruments, applies effects, and produces sample streams. src/zetni-adsr.cc supplies ADSR envelope behavior for note amplitude shaping.
Core abstractions are defined in includes/zetni/interfaces/zetni-engine-interface.h, includes/zetni/zetni-engine.h, and includes/zetni/zetni-adsr.h.
Instrument Layer
Concrete sound sources include procedural oscillators and a sample-based instrument:
src/instruments/zetni-instruments-sine.cc, src/instruments/zetni-instruments-square.cc, and src/instruments/zetni-instruments-sampler.cc.
The sampler reads repository WAV assets such as samples/piano.wav and samples/kick.wav; WAV decoding is handled by src/zetni-wavefile.cc. Common instrument dispatch/registration is centralized in src/zetni-instruments.cc behind includes/zetni/interfaces/zetni-instrument-interface.h.
Effects and External Dependencies
Effects are modular post- or per-signal transformations, with gain, echo, and tremolo implementations in src/effects/zetni-effect-gain.cc, src/effects/zetni-effect-echo.cc, and src/effects/zetni-effect-tremolo.cc. src/zetni-effects.cc manages effect selection/application through includes/zetni/interfaces/zetni-effect-interface.h.
The repository shows no network services, databases, or cloud infrastructure. Runtime dependencies are local filesystem access to song definitions and WAV samples/output; CMake is the build-system integration point.
Main entry points: zetni-engine.cc Rendering Engine · zetni-pipeline.cc Render Pipeline · zetni-wavefile.cc WAV Reader/Writer · zetni-pattern.cc Pattern Model
Components 19
Music Inputs
- Song Definitions
examples/badapple.txt - WAV Sample Assets
samples/piano.wav
Parsing & Patterns
- Syntax Analysis
src/zetni-syntax-analyzator.cc - Music Parser
src/zetni-parser.cc - Pattern Parser
src/zetni-pattern-parser.cc - Pattern Model · Executable pattern sequences and instructions.
src/zetni-pattern.cc - Instrument Play
src/pattern-instructions/zetni-instrument-play-pattern-instruction.cc - Pattern Call
src/pattern-instructions/zetni-call-another-pattern-instruction.cc
Audio Rendering
- Rendering Engine · Schedules patterns and produces audio samples.
src/zetni-engine.cc - ADSR Envelope
src/zetni-adsr.cc - Instrument Registry
src/zetni-instruments.cc - Oscillators & Sampler · Sine, square, and WAV-sample sound sources.
src/instruments/zetni-instruments-sampler.cc - Effects Manager
src/zetni-effects.cc - Gain, Echo & Tremolo
src/effects/zetni-effect-gain.cc
Other components
- CMake Build
CMakeLists.txt - CLI Entry Point
src/zetni_main.cc - Render Pipeline · Coordinates parsing, rendering, and WAV output.
src/zetni-pipeline.cc - WAV Reader/Writer · Decodes sampled WAV files and serializes rendered output.
src/zetni-wavefile.cc - WAV Output
Connections 21
- CMake Build → CLI Entry Point: builds
- CLI Entry Point → Render Pipeline: starts
- Song Definitions → Render Pipeline: source input
- Render Pipeline → Syntax Analysis: analyzes
- Syntax Analysis → Music Parser: validated text
- Music Parser → Pattern Parser: parses patterns
- Pattern Parser → Pattern Model: builds
- Instrument Play → Pattern Model: instruction type
- Pattern Call → Pattern Model: instruction type
- Render Pipeline → Rendering Engine: renders
- Pattern Model → Rendering Engine: scheduled patterns
- Rendering Engine → ADSR Envelope: shapes notes
- Rendering Engine → Instrument Registry: invokes
- Instrument Registry → Oscillators & Sampler: selects
- WAV Sample Assets → WAV Reader/Writer: sample data
- WAV Reader/Writer → Oscillators & Sampler: decoded WAV
- Rendering Engine → Effects Manager: applies
- Effects Manager → Gain, Echo & Tremolo: selects
- Rendering Engine → WAV Reader/Writer: sample stream
- Render Pipeline → WAV Reader/Writer: writes through
- WAV Reader/Writer → WAV Output: serializes