Architecture
Euterpes is five layers, and a test (tests/test_architecture.py) fails the build when an import breaks a rule.
ui/ Qt widgets. The only package that imports PySide6 widgets.
services/ Use cases without Qt: the open document, playback, practice, recording, importing.
adapters/ Hardware and external programs: sound card, MIDI ports, LilyPond, Audiveris, MP3.
dsp/ Signal processing with numpy: synthesiser voices, soundfonts, clicks, pitch tracking.
core/ The domain in pure Python, standard library only: the LilyPond subset, the
score model, timing, engraving layout, practice logic, and the ports.
coreimports only the standard library.dspimports numpy andcore.adaptersimport their third-party library,coreanddsp; never Qt.servicesimportcoreonly. They receive adapters as constructor arguments.uimay import everything. Nothing importsuiexceptapp.py, the composition root, andcli.py, which paints pictures offscreen with the engraver's painter.
Every outside dependency (the clock, the sound card, the MIDI port, the synthesiser, the print engraver, the recognition engines, the MP3 encoder) is a small Protocol in core/ports.py, with a fake in the tests. This is what lets the whole program be tested without hardware.
Three rules shape the code:
- The text is the truth. A score is a
.lyfile. Edits made on the staff are pure functions that return text edits (core/lilypond/note_edits.py,editing.py); the score model is never changed and written back. - Exact time. Written positions and lengths are
Fractions of a whole note. They become float seconds only at the edge. - Ports, not hardware. A port is added together with its first user.
The decisions behind this are the decision records: the stack (ADR 1), the layers (ADR 2), the text as the single source of truth (ADR 3), the two engravers (ADR 4) and the one clock (ADR 5).
The core modules
| Module | Job |
|---|---|
core/pitch.py, duration.py |
Spelled pitches, keys, intervals; durations as exact fractions |
core/model.py |
The score model: events, voices, staves, bars, repeats |
core/lilypond/ |
Lexer, parser, interpreter, writer, text edits, document |
core/bars.py, timing.py |
Cutting time into bars; tempo map, play order |
core/playback.py |
Score to timed sounding notes |
core/metronome.py, transport.py, looping.py |
Clicks and count-in; play, seek, tempo; loop and tempo ramp |
core/engraving/, engraved.py |
The live engraver's layout; LilyPond's engraved result |
core/practice/ |
Expected notes, followers, judging, calibration, weakness statistics, suggestions |
core/recording.py |
Notes played live, turned into a score |
core/importers/, core/exporters/ |
MusicXML, MIDI, LaTeX in; MusicXML out |
core/instruments.py, tuning.py |
Instrument ranges; tuner maths and strings |
core/library.py |
The library's piece metadata |
core/midifile.py |
A minimal Standard MIDI File writer |
The other layers
| Layer | Examples |
|---|---|
dsp/ |
synth.py (built-in voices), sf2.py and soundfont.py (SoundFont 2 files), switching.py, offline.py (render to samples), pitch.py (YIN), click.py |
adapters/ |
audio.py (sound card), midi.py, lilypond.py, omr.py (Audiveris), mp3.py (LAME), updates.py |
services/ |
session.py, player.py, practice.py, progress.py, recorder.py, library.py, importing.py, listening.py |
ui/ |
main_window.py (the wiring; window_parts.py builds its parts, the *_controller.py files hold its features), the pages, staff_editor.py (staff gestures to text edits), score_view.py, theme.py, tutorial.py |
Mutable state lives in a few services; the model in core is frozen (slots dataclasses).