Utilities
Pitch parsing, duration values, and font size management.
Pitch utilities
These functions convert between pitch string notation and internal step values used for vertical positioning on the staff.
Decompose a scientific pitch string into (step, accidental, octave).
from pylute import parse_pitch
parse_pitch("C4") # ("C", "", 4)
parse_pitch("F#4") # ("F", "#", 4)
parse_pitch("Bb3") # ("B", "b", 3)
parse_pitch("Eb5") # ("E", "b", 5)
Convert a pitch string to a staff step integer used for vertical note positioning. Step 0 = bottom staff line, step 1 = first space, step 4 = top line. Steps below 0 or above 8 produce ledger lines.
from pylute import pitch_to_step
pitch_to_step("E4", "treble") # 0 (bottom line in treble clef)
pitch_to_step("G4", "treble") # 1 (first space)
pitch_to_step("B4", "treble") # 2 (second line)
pitch_to_step("G2", "bass") # 0 (bottom line in bass clef)
Convert a key name to a signed accidental count. Negative = flats, positive = sharps. Integers pass through unchanged.
from pylute import parse_key
parse_key("C") # 0
parse_key("G") # 1
parse_key("Bb") # -2
parse_key("F#") # 6
parse_key(-3) # -3 (pass-through)
Durations
The VALUES dictionary maps duration type strings to their fractional beat value, where 1.0 = one whole note. A 4/4 bar has capacity 1.0; a 3/4 bar has capacity 0.75.
| Duration type | Beat value | Fills a 4/4 bar |
|---|---|---|
| whole | 1.0 | Exactly |
| half | 0.5 | 2 per bar |
| quarter | 0.25 | 4 per bar |
| eighth | 0.125 | 8 per bar |
| sixteenth | 0.0625 | 16 per bar |
| dotted_half | 0.75 | 1 per 3/4 bar |
| dotted_quarter | 0.375 | — |
| dotted_eighth | 0.1875 | — |
from pylute import VALUES, get_value
get_value("quarter") # 0.25
get_value("dotted_half") # 0.75
# You can also access the dict directly:
VALUES["eighth"] # 0.125
Font management
PyLute uses the Bravura SMuFL music font for all glyphs. Font size is global and controls the visual scale of all notation elements.
| Function | Description |
|---|---|
| get_font_size() → int | Current global font size in points. Default: 70. |
| set_font_size(size: int) → None | Set the global font size. Clamped to a minimum of 28. Affects the rendered size of all glyphs and staff spacing. Call before creating any Score. |
| get_font() → pygame.freetype.Font | Returns the cached Bravura font instance at the current size. |
| make_font(size: int) → pygame.freetype.Font | Create a new font instance at a specific size, independent of the global setting. |
from pylute.font import set_font_size, get_font_size
# Smaller notation (good for dense scores or small windows)
set_font_size(50)
print(get_font_size()) # 50
# Back to default
set_font_size(70)