-
Notifications
You must be signed in to change notification settings - Fork 3
Note selectors
David Anderson edited this page Jul 21, 2026
·
10 revisions
Many of the nuance functions let you select sets of notes
using "selector" functions:
boolean-valued functions taking a Note argument.
Selectors have the type
type Selector = Callable[[Note], bool] | NoneSelectors 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 pitch -
n.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.tagsselects eighth notes that are topmost
(i.e. the highest sounding note at their start time).
Given a Score ns,
you could then change the performance duration of these notes
to .3 seconds by calling
ns.adjust_dur_abs(.3, top_eighths)For brevity, selectors can be specified as lambda functions:
ns.adjust_dur_abs(
.3,
lambda n: n.dur == 1/8 and 'top' in n.tags
)