This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Music theory Anki flashcard deck generator that uses LilyPond to create music notation images. The generated images are used to create Anki decks for learning music theory fundamentals.
- LilyPond 2.24+ (install via
brew install lilypondon macOS) - Anki (for importing the final decks)
./scripts/build.shThis compiles all LilyPond (.ly) files to PNG images at 400 DPI resolution with auto-sized pages.
- The build script (
scripts/build.sh) scanssrc/for.lyfiles - LilyPond compiles each file to PNG using
--png -dresolution=400 - Files use
ly:one-line-auto-height-breakingwith tuned spacing to auto-size pages - Output organized in
images/mirroring the source structure
src/
├── key-signatures/
│ ├── treble-major/ # Treble clef major key signature .ly files
│ ├── treble-minor/ # Treble clef minor key signature .ly files
│ ├── bass-major/ # Bass clef major key signature .ly files
│ └── bass-minor/ # Bass clef minor key signature .ly files
└── note-reading/
├── treble/ # Treble clef note reading .ly files
└── bass/ # Bass clef note reading .ly files
images/ # Mirrors src/ structure exactly
├── key-signatures/
│ ├── treble-major/
│ ├── treble-minor/
│ ├── bass-major/
│ └── bass-minor/
└── note-reading/
├── treble/
└── bass/
csv/ # CSV files for Anki import
All .ly files follow a consistent pattern:
Key Signatures: Use \key <note> \major or \key <note> \minor with \omit Staff.TimeSignature and \omit Staff.BarLine, displaying only the staff and key signature. Layout is controlled via:
page-breaking = #ly:one-line-auto-height-breaking- Auto-sizes page to content- Margins: 3mm top/bottom, 2mm left/right
top-system-spacingandtop-markup-spacing- Tuned to prevent clef cutoff\override Score.SpacingSpanner.spacing-increment = #1.5- Fine-grained horizontal spacings\breve- Invisible spacer (2 whole notes duration)- Produces consistent 416px wide images with balanced margins
Note Reading: Display a single note on the staff with defined paper width (line-width = 3\cm).
Common settings across all files:
- Version: "2.24.0"
- Paper:
indent = 0, auto-sized with specific margins - Header:
tagline = ##f(removes LilyPond footer)
Spacing Philosophy: All key signature images maintain uniform 416px width (optimized for phone screens) so students can't use staff length as a clue. The auto-height breaking eliminates the need for post-processing cropping. See README.md Technical Notes for details.
The build script has two main compilation functions:
-
compile_key_signatures <subdir>: Compiles key signature files fromsrc/key-signatures/<subdir>toimages/key-signatures/<subdir>. Called four times for treble-major, treble-minor, bass-major, and bass-minor. -
compile_notes <clef>: Compiles note reading files fromsrc/note-reading/<clef>toimages/note-reading/<clef>.
Both functions suppress LilyPond stderr output (2>/dev/null) for cleaner build logs and automatically count files before processing.
- Create
.lyfile insrc/key-signatures/{treble|bass}-{major|minor}/ - Name using pattern:
{note}-{major|minor}.ly(e.g.,g-sharp-minor.ly) - Use standard key signature template with appropriate
\keydirective - Run
./scripts/build.shto generate image in matchingimages/key-signatures/subdirectory
- Create
.lyfile insrc/note-reading/{treble|bass}/ - Name after the note (e.g.,
c4.lyfor middle C) - Use standard note reading template with the specific note
- Run
./scripts/build.shto generate image
- Key signature files: Use lowercase with hyphens (e.g.,
c-sharp-major.ly,a-flat-minor.ly) - Note reading files: Use note name + octave (e.g.,
c4.ly,g5.ly) - Images automatically match source filename (e.g.,
c-sharp-major.ly→c-sharp-major.png)
Lesson notes are stored in Obsidian at:
/Users/ana/Documents/Obsidian Vault/Learning/Piano/Lessons/
Each lesson file (e.g., 2025-09-04.md) contains vocabulary tables, concept explanations, and practice notes.
All flashcard CSVs use three columns:
Front,Back,Tags
"Question text with <b>bold</b> for key terms","Answer text","lesson::001 type::vocabulary topic::intervals"- Use HTML
<b>tags for emphasis (Anki renders these) - Escape quotes by doubling them:
""example"" - All cards import into a single "Music Theory" deck; tags enable filtered study
Every card gets three tags:
| Tag Type | Values | Purpose |
|---|---|---|
lesson:: |
001, 002, 003, 004, ... |
Filter by lesson |
type:: |
vocabulary, concept |
Card type |
topic:: |
See list below | Subject area |
Topic tags:
basics- sharps, flats, enharmonicintervals- half steps, interval names, qualities, inversionsscales- patterns, scale types, degreestriads- formulas, chord typeskeys- relative/parallel keys, key signatures, circle of fifthsexpression- consonance, dissonance, modulationmotion- parallel, contrary, obliqueacoustics- frequency ratiosnotation- clef reading, mnemonicshistory- periods, composers, terms
Vocabulary terms (from lesson vocabulary tables):
- Create TWO separate cards per term:
- Term → Definition:
"What is a <b>sharp</b>?"→"A symbol that raises a note by one half step" - Definition → Term:
"Which symbol raises a note by one half step?"→"A sharp (♯)"
- Term → Definition:
- Tag with
type::vocabulary
Concept cards (from lesson content):
- Single-sided cards testing understanding
- Examples: scale patterns, interval half-step counts, triad formulas, historical facts
- Tag with
type::concept
csv/music-theory-lesson-001.csv
csv/music-theory-lesson-002.csv
...
- File → Import → select CSV
- Choose/create "Music Theory" deck (or appropriate sub-deck)
- Map: Field 1 = Front, Field 2 = Back, Field 3 = Tags
- Note type: "Basic" (single-sided cards)
- Imports are additive—new cards add to existing deck
The "Music Theory" deck uses sub-decks for organization:
Music Theory/
├── Lessons/
│ ├── Lesson_001 # Music Theory Foundations
│ ├── Lesson_002 # Intervals, Acoustics & Reading
│ ├── Lesson_003 # Minor Scale Types & Voice Motion
│ └── Lesson_004 # Music History Overview
└── Mnemonics # Memory aids for keys, clefs, etc.
When importing CSVs, select the appropriate sub-deck (e.g., Music Theory::Lessons::Lesson_001).
The csv/mnemonics.csv file uses a simplified tagging schema:
type::mnemonic(instead of vocabulary/concept)topic::keysortopic::notation- No
lesson::tag (mnemonics span all lessons)
Always export from the parent "Music Theory" deck to create a single .apkg package:
- Right-click "Music Theory" deck in Anki
- Select Export
- Choose "Anki Deck Package (.apkg)"
- Uncheck "Include scheduling information" (for sharing)
- Save as
Music Theory.apkgin the base directory
This preserves the sub-deck hierarchy and all tags. Do NOT export sub-decks individually.
Users can create filtered decks using tag queries:
| To study... | Search query |
|---|---|
| All mnemonics | tag:type::mnemonic |
| Lesson 1 only | tag:lesson::001 |
| All intervals | tag:topic::intervals |
| Vocabulary only | tag:type::vocabulary |