Topyly¶
Introduction¶
This moodule produde hte functionality to convert musical data into LilyPond format, also including exporting to MIDI and graphical format. It also provides some tools for playing with FluidSynth.
_Map Class¶
_Map is a class that provides methods for mapping musical data from python to LilyPond format.
It’s the base class for the next classes.
- _Map.__init__(note: int | list | list[list] = 60, dur: int | list | list[list] = None, vel: int | list = None, exp: str | list = None, key: str = None) None¶
- Parameters:
note (int or list(int or list 2D)) – list of pitches
dur (int or list(int or list 2D)) – list of duration
vel (int or list) – list of velocities
exp (str or list(string)) – list of expressions
key – key signature (string) per mapping note (es. ‘d’, ‘ef’, ‘g’, ecc.)
_Print Class¶
_Printis a class that save these files:lilypond file (.ly)
MIDI file (.mid)
graphic file (.pdf or .png)
- _Print.__init__(filename: str = 'score', format: str = 'pdf', version: str = '2.24.4') None¶
- Parameters:
filename (str) – filename (without extension), default is “score”
format (str) – graphic format for output (pdf, png), default is “pdf”
version (str) – version of lilypond to use, default is “2.24.4”
- _Print.print_out¶
Print the lilypond output string to the console.-
- _Print.make_file¶
Save the lilypond output string to a .ly file and compile it to generate the specified .format and MIDI files.
Staff Class¶
Staff is a rappresentation of a musical staff for lilypond. It can be used to create a musical score with the given musical data.
- Staff.__init__(note: int | list[int] = 60, dur: int | list[int] = None, vel: int | list[int] = None, exp=None, key: str = None, t_sig: str = None, clef: str = None, i_name: str = None, i_short: str = None, i_midi: str = None, filename: str = 'score', format: str = 'pdf', version: str = '2.24.3')¶
- Parameters:
note (int or list(int or list 2D)) – list of pitches
dur (int or list(int or list 2D)) – list of duration
vel (int or list) – list of velocities
exp (str or list(string)) – list of expressions
key (str) – key signature
t_sig (str) – time signature
clef (str) – clef
i_name (str) – instrument name for score
i_short (str) – short instrument name for score
i_midi (str) – MIDI instrument name for score
filename (str) – filename (without extension), default is “score”
format (str) – graphic format for output (pdf, png), default is “pdf
version (str) – version of lilypond to use, default is “2.24.3
- Staff.out¶
Return the lilypond output string for the staff.
- Staff.play(bpm=60, beat=4, chan=0, instrID=0, audioDev: str = 'coreaudio', sf2_abs_path: str = None)¶
Converte durate in durate assolute Esegue una sequenza
- Parameters:
pitch – int = nota singola list = sequenza monofonica list2D = sequenza polifonica o singolo accordo tuple = sequenza di più voci
vel – int = nota singola list = sequenza tuple = sequenza di più voci
dur – int = nota singola list = sequenza tuple = sequenza di più voci
bpm – int = tempo metronomico
beat – = valore del beat (1,2,4,8,16,32)
Score Class¶
Score rapresentes a musical score for lilypond. It can be used to create a musical score with the given musical data.
- Score.__init__(staff: str = "\n\t\t{c' d' e' f'}", staff_size: int = None, indent: int = None, s_indent: int = None, title: str = None, composer: str = None, size: str = 'a4landscape', margins: tuple = (10, 10, 10, 10), filename: str = 'score', format: str = 'pdf', version: str = '2.24.3') None¶
Constructor for Score class.
- Parameters:
staff (str or tuple of str in lilypond format) – tuple of Staff outputs or single Staff output, default is a simple staff with c’ d’ e’ f’
staff_size (int or None) – staff size in mm, default is None (standard size)
indent (int or None) – indent in mm, default is None (no indent)
s_indent (int or None) – short indent in mm, default is None (no short indent)
title (str or None) – title of the score, default is None (no title)
composer (str or None) – composer of the score, default is None (no composer)
size (str or tuple(int, int)) – page size, default is “a4landscape”. Can be a predefined size string or a tuple of two ints for custom width/height in mm
margins (tuple(int, int, int, int)) – page margins as a tuple (top, bottom, left, right) in mm, default is (10, 10, 10, 10)
filename (str) – filename (without extension), default is “score”
format (str) – graphic format for output (pdf, png), default is “pdf”
version (str) – version of lilypond to use, default is “2.24.3”
- Score.sei_libero()¶
Nasconde indicazione di tempo e linee di battuta.
Functions¶
- musicnpy.topyly.tonalita(key: str = None) str¶
Return alteration of key signature.
- Parameters:
key (str or None) – tonalità (es. ‘d’, ‘ef’, ‘a’, ‘bf’)
- Returns:
‘diesis’ or ‘bemoli’
- Return type:
str
- musicnpy.topyly.mapPitch(a: list | int, key=None) list[str]¶
Convert int midi pitches in lylipond pitch symbols.
- Parameters:
a (list[int] or int) – list of pitches
- Returns:
list of lilypond pitch symbols
- Return type:
list[str]
- musicnpy.topyly.mapDur(a: list | int) list[str]¶
convert durations in lilypond duration symbols.
- Parameters:
a (list[int] or int) – list of durations
- Returns:
list of lilypond duration symbols
- Return type:
list[str]
- musicnpy.topyly.mapVel(a: list[int]) list[str]¶
Convert list of velocities in lilypond dynamic symbols.
- Parameters:
a (list[int] or int) – list of velocities
- Returns:
list of lilypond dynamic symbols
- Return type:
list[str]
- musicnpy.topyly.mapExp(a: list[str]) list[str]¶
convert list of expressions in lilypond expression symbols.
- Parameters:
a (list[str] or str) – list of expressions
- Returns:
list of lilypond expression symbols
- Return type:
list[str]
- musicnpy.topyly.nDim(a: list) int¶
Return list dimension
- Parameters:
a (list) – list
- Returns:
dimension of the list
- Return type:
int
- musicnpy.topyly.l_mod(lista: list, target: int) list¶
Generate a list of n elements (target) by repeating the input list and applying modulo.
- Parameters:
lista (list) – input list (1D, 2D or 3D)
target (int) – desired length of the output list
- Returns:
list of length target
- Return type:
list
- musicnpy.topyly.l_zero(lista: list, target: int) list¶
Generate a list of n elements (target) by repeating the input list and applying zero padding.
- Parameters:
lista (list) – input list (1D, 2D or 3D)
target (int) – desired length of the output list
- Returns:
list of length target
- Return type:
list
- musicnpy.topyly.dflt(a=None, offset=0)¶
Genera array di default e aggiunge uno zeropad se argomento è: • a = None • a = int • a = lista • offset = se a –> None questo è il valore che aggiunge
- musicnpy.topyly.selmode(lista, max)¶
Genera liste di diversa lunghezza in base al modo specificato lista = [60, ‘zero’] max = target size
- musicnpy.topyly.getmaxsize(note, dur, vel, exp)¶
Trova il size della lista più lunga
- musicnpy.topyly.dur2sec(dur=4, bpm=60, beat=4)¶
Converte valori espressi in notazione lilypond in valori assoluti in secondi
- Parameters:
dur – int or list
beat – beat value (1,2,4,8,16,32)
bpm – bpm value
- musicnpy.topyly.note(pitch=60, dur=4, vel=64, track=0)¶
Definisce una nota midi. Se pitch è un int esegue una sola nota, altrimenti un accordo.
- Parameters:
pitch – midinote 0-127
vel – midi velocity 0-127
dur – Duration in seconds
track – midi channel default = channel 0
- musicnpy.topyly.voice(pitch=60, dur=4, vel=64, track=0)¶
Definisce una sequenza a una voce (track) anche polifonica.
- Parameters:
pitch – list o list2D (accordi)
vel – int or list
dur – int or list
track – default = channel 0
- musicnpy.topyly.voices(pitch=60, dur=4, vel=4, chan=0)¶
Defininisce più voci. Corrisponde a Staff. Mette automaticamente ogni voce in una track (midi channel) diversa.
- Parameters:
pitch – tuple di liste
vel – tuple di liste
dur – tuple di liste