Note selectors - davidpanderson/Numula GitHub Wiki
Many of the nuance functions let you select a set of notes using a "selector" function:
a boolean-valued function taking a Note
argument.
Selectors have the type
type Selector = Callable[[Note], bool] | None
Selectors can refer to any of the Note
attributes, including:
n.time
,n.dur
: the note's start time and duration in score units.n.pitch
: the note's pitchn.tags
: the list of tags associated with the note. Two tags are automatically assigned: "top" means the note has the highest pitch of the notes sounding at its start time, and "bottom" means it has the lowest pitch.n.measure_offset
: the time (in score units) from the last measure boundary to the note's start time.n.nchord
: the number of notes with the same start time as this one.n.chord_pos
: of these notes, this one's pitch order (0 = lowest).
For example, the function
def top_eighths(note):
return note.dur == 1/8 and 'top' in note.tags
selects eighth notes that are topmost
(i.e. the highest sounding note at their start time).
Given a Score
ns
,
you could change the performed duration of these notes to .3 seconds by calling
ns.perf_dur_abs(.3, top_eighths)
For brevity, you can selectors as lambda functions:
ns.perf_dur_abs(.3, lambda n: n.dur == 1/8 and 'top' in n.tags)