music21.note¶
Classes and functions for creating Notes, Rests, and Lyrics.
The Pitch
object is stored within,
and used to configure, Note
objects.
Note¶
-
class
music21.note.
Note
(*arguments, **keywords)¶ One of the most important music21 classes, a Note stores a single note (that is, not a rest or an unpitched element) that can be represented by one or more notational units – so for instance a C quarter-note and a D# eighth-tied-to-32nd are both a single Note object.
A Note knows both its total duration and how to express itself as a set of tied notes of different lengths. For instance, a note of 2.5 quarters in length could be half tied to eighth or dotted quarter tied to quarter.
The first argument to the Note is the pitch name (with or without octave, see the introduction to
music21.pitch.Pitch
). Further arguments can be specified as keywords (such as type, dots, etc.) and are passed to the underlyingmusic21.duration.Duration
element.Two notes are considered equal if their most important attributes (such as pitch, duration, articulations, and ornaments) are equal. Attributes that might change based on the wider context of a note (such as offset, beams, stem direction) are not compared. This test presently does not look at lyrics in establishing equality. It may in the future.
Note
bases
Note
read-only properties
-
Note.
diatonicNoteNum
¶ Return the diatonic note number from the
Pitch
object. SeediatonicNoteNum
.Probably will be deprecated soon...
-
Note.
fullName
¶ Return the most complete representation of this Note, providing duration and pitch information.
>>> n = note.Note('A-', quarterLength=1.5) >>> n.fullName 'A-flat Dotted Quarter Note'
>>> n = note.Note('E~3', quarterLength=2) >>> n.fullName 'E-half-sharp in octave 3 Half Note'
>>> n = note.Note('D', quarterLength=.25) >>> n.microtone = 25 >>> n.fullName 'D (+25c) 16th Note'
Read-only properties inherited from Music21Object
:
Note
read/write properties
-
Note.
accidental
¶ Return or set the
Accidental
object from thePitch
object.DEPRECATED May 2014: use n.pitch.accidental instead
-
Note.
frequency
¶ Return or set the frequency from the
Pitch
object.See
frequency
.DEPRECATED May 2014: use n.pitch.frequency instead
-
Note.
microtone
¶ Return or set the microtone value from the
Pitch
object.See
microtone
.DEPRECATED May 2014: use n.pitch.microtone instead
-
Note.
midi
¶ Return or set the numerical MIDI pitch representation from the
Pitch
object.See
midi
.DEPRECATED May 2014: use n.pitch.midi instead
-
Note.
nameWithOctave
¶ Return or set the pitch name with octave from the
Pitch
object. See Pitch‘s attributenameWithOctave
.
-
Note.
pitchClass
¶ Return or set the pitch class from the
Pitch
object. Seemusic21.pitch.Pitch.pitchClass
.DEPRECATED May 2014: use n.pitch.pitchClass instead
-
Note.
pitchClassString
¶ Return or set the pitch class string from the
Pitch
object.See
pitchClassString
.DEPRECATED May 2014: use n.pitch.pitchClassString instead
-
Note.
pitches
¶ Return the
Pitch
object in a list. This property is designed to provide an interface analogous to that found onChord
.>>> n = note.Note('g#') >>> n.nameWithOctave 'G#' >>> n.pitches [<music21.pitch.Pitch G#>] >>> n.pitches = [pitch.Pitch('c2'), pitch.Pitch('g2')] >>> n.nameWithOctave 'C2' >>> n.pitches [<music21.pitch.Pitch C2>]
-
Note.
ps
¶ Return or set the numerical pitch space representation from the
music21.pitch.Pitch
object.DEPRECATED May 2014: use n.pitch.ps instead
Read/write properties inherited from NotRest
:
Read/write properties inherited from GeneralNote
:
Read/write properties inherited from Music21Object
:
Note
methods
-
Note.
transpose
(value, inPlace=False)¶ Transpose the Note by the user-provided value. If the value is an integer, the transposition is treated in half steps.
If the value is a string, any Interval string specification can be provided.
>>> a = note.Note('g4') >>> b = a.transpose('m3') >>> b <music21.note.Note B-> >>> aInterval = interval.Interval(-6) >>> b = a.transpose(aInterval) >>> b <music21.note.Note C#>
>>> c = b.transpose(interval.GenericInterval(2)) >>> c <music21.note.Note D#>
>>> a.transpose(aInterval, inPlace=True) >>> a <music21.note.Note C#>
Methods inherited from GeneralNote
:
Methods inherited from Music21Object
:
Note
instance variables
-
Note.
isNote
¶ Boolean read-only value describing if this Note is a Note (True).
-
Note.
isRest
¶ Boolean read-only value describing if this Note is a Rest (False).
-
Note.
pitch
¶ A
Pitch
object containing all the information about the note’s pitch. Many .pitch properties and methods are also made Note properties also
Instance variables inherited from NotRest
:
Instance variables inherited from GeneralNote
:
Instance variables inherited from Music21Object
:
Rest¶
-
class
music21.note.
Rest
(*arguments, **keywords)¶ Rests are represented in music21 as GeneralNote objects that do not have a pitch object attached to them. By default they have length 1.0 (Quarter Rest)
Calling
notes
on a Stream does not get rests. However, the propertynotesAndRests
of Streams gets rests as well.>>> r = note.Rest() >>> r.isRest True >>> r.isNote False >>> r.duration.quarterLength = 2.0 >>> r.duration.type 'half'
All Rests have the name property ‘rest’:
>>> r.name 'rest'
Rest
bases
Rest
read-only properties
-
Rest.
fullName
¶ Return the most complete representation of this Rest, providing duration information.
>>> r = note.Rest(quarterLength=1.5) >>> r.fullName 'Dotted Quarter Rest'
>>> note.Rest(type='whole').fullName 'Whole Rest'
Read-only properties inherited from Music21Object
:
Rest
read/write properties
Read/write properties inherited from GeneralNote
:
Read/write properties inherited from Music21Object
:
Rest
methods
Methods inherited from GeneralNote
:
Methods inherited from Music21Object
:
Rest
instance variables
-
Rest.
fullMeasure
¶ does this rest last a full measure (thus display as whole, center, etc.) Options are False, True, “always”, “auto” (default)
False means do not set as full measure, no matter what.
True keeps the set duration, but will always display as a full measure rest.
“always” means the duration will (EVENTUALLY, not yet!) update automatically to match the time signature context; and is True. Does not work yet – functions as True. # TODO: get it to work.
“auto” is the default, where if the rest value happens to match the current time signature context, then display it as a whole note, centered, etc. otherwise will display normally.
See examples in
music21.musicxml.m21ToXml.MeasureExporter.restToXml()
-
Rest.
isNote
¶ Boolean read-only value describing if this Rest is a Note (False).
-
Rest.
isRest
¶ Boolean read-only value describing if this Rest is a Rest (True, obviously).
-
Rest.
name
¶ returns “rest” always. It is here so that you can get x.name on all .notesAndRests objects
-
Rest.
stepShift
¶ number of lines/spaces to shift the note upwards or downwards for display.
Instance variables inherited from GeneralNote
:
Instance variables inherited from Music21Object
:
SpacerRest¶
-
class
music21.note.
SpacerRest
(*arguments, **keywords)¶ This is exactly the same as a rest, but it is a SpacerRest. This object should only be used for making hidden space in a score in lilypond.
This may become deprecated at some point...
SpacerRest
bases
SpacerRest
read-only properties
Read-only properties inherited from Rest
:
Read-only properties inherited from Music21Object
:
SpacerRest
read/write properties
Read/write properties inherited from GeneralNote
:
Read/write properties inherited from Music21Object
:
SpacerRest
methods
Methods inherited from GeneralNote
:
Methods inherited from Music21Object
:
SpacerRest
instance variables
Instance variables inherited from Rest
:
Instance variables inherited from GeneralNote
:
Instance variables inherited from Music21Object
:
Unpitched¶
-
class
music21.note.
Unpitched
¶ A General class of unpitched objects which appear at different places on the staff. Examples: percussion notation.
The Unpitched object does not currently do anything and should not be used.
Unpitched
bases
Unpitched
read-only properties
Read-only properties inherited from Music21Object
:
Unpitched
read/write properties
-
Unpitched.
storedInstrument
¶
Read/write properties inherited from NotRest
:
Read/write properties inherited from GeneralNote
:
Read/write properties inherited from Music21Object
:
Unpitched
methods
-
Unpitched.
displayPitch
()¶ returns a pitch object that is the same as the displayStep and displayOctave
Methods inherited from GeneralNote
:
Methods inherited from Music21Object
:
Unpitched
instance variables
Instance variables inherited from NotRest
:
Instance variables inherited from GeneralNote
:
Instance variables inherited from Music21Object
:
NotRest¶
-
class
music21.note.
NotRest
(*arguments, **keywords)¶ Parent class for Note-like objects that are not rests; that is to say they have a stem, can be tied, and volume is important. Basically, that’s a Note or Unpitched object for now.
NotRest
bases
NotRest
read-only properties
Read-only properties inherited from Music21Object
:
NotRest
read/write properties
-
NotRest.
notehead
¶ Get or set the notehead type of this NotRest object. Valid notehead type names are found in note.noteheadTypeNames (see below):
>>> note.noteheadTypeNames ['arrow down', 'arrow up', 'back slashed', 'circle dot', 'circle-x', 'cluster', 'cross', 'diamond', 'do', 'fa', 'inverted triangle', 'la', 'left triangle', 'mi', 'none', 'normal', 're', 'rectangle', 'slash', 'slashed', 'so', 'square', 'ti', 'triangle', 'x'] >>> n = note.Note() >>> n.notehead = 'diamond' >>> n.notehead 'diamond'
>>> n.notehead = 'junk' Traceback (most recent call last): NotRestException: not a valid notehead type name: 'junk'
-
NotRest.
noteheadFill
¶ Get or set the note head fill status of this NotRest. Valid note head fill values are True, False, or None (meaning default).
>>> n = note.Note() >>> n.noteheadFill = 'no' >>> n.noteheadFill False >>> n.noteheadFill = 'filled' >>> n.noteheadFill True
>>> n.noteheadFill = 'junk' Traceback (most recent call last): NotRestException: not a valid notehead fill value: junk
-
NotRest.
noteheadParenthesis
¶ Get or set the note head parentheses for this Note/Unpitched/Chord object.
>>> n = note.Note() >>> n.noteheadParenthesis False >>> n.noteheadParenthesis = True >>> n.noteheadParenthesis True
‘yes’ or 1 equate to True; ‘no’ or 0 to False
>>> n.noteheadParenthesis = 'no' >>> n.noteheadParenthesis False
Anything else raises an exception:
>>> n.noteheadParenthesis = 'blah' Traceback (most recent call last): NotRestException: notehead parentheses must be True or False, not 'blah'
-
NotRest.
stemDirection
¶ Get or set the stem direction of this NotRest object. Valid stem direction names are found in note.stemDirectionNames (see below).
>>> note.stemDirectionNames ['double', 'down', 'noStem', 'none', 'unspecified', 'up'] >>> n = note.Note() >>> n.stemDirection = 'noStem' >>> n.stemDirection 'noStem' >>> n.stemDirection = 'junk' Traceback (most recent call last): NotRestException: not a valid stem direction name: junk
-
NotRest.
volume
¶ Get and set the
Volume
object of this object. Volume objects are created on demand.>>> n1 = note.Note() >>> n1.volume.velocity = 120 >>> n2 = note.Note() >>> n2.volume = 80 # can directly set a velocity value >>> s = stream.Stream() >>> s.append([n1, n2]) >>> [n.volume.velocity for n in s.notes] [120, 80]
Read/write properties inherited from GeneralNote
:
Read/write properties inherited from Music21Object
:
NotRest
methods
Methods inherited from GeneralNote
:
Methods inherited from Music21Object
:
NotRest
instance variables
-
NotRest.
beams
¶ A
music21.beam.Beams
object.
-
NotRest.
isChord
¶ Boolean read-only value describing if this GeneralNote object is a Chord. Is True
-
NotRest.
isNote
¶ Boolean read-only value describing if this GeneralNote object is a Note. Is False
-
NotRest.
isRest
¶ Boolean read-only value describing if this GeneralNote object is a Rest. Is False >>> c = chord.Chord() >>> c.isRest False
Instance variables inherited from GeneralNote
:
Instance variables inherited from Music21Object
:
GeneralNote¶
-
class
music21.note.
GeneralNote
(*arguments, **keywords)¶ A GeneralNote object is the base class object for the
Note
,Rest
,Chord
, and related objects.Keywords can be passed to a GeneralNote which are then passed to the underlying
Duration
. These keywords might be listed like type=‘16th’, dots=2 etc. to create a double-dotted sixteenth note.In almost every circumstance, you should create note.Note() or note.Rest() or note.Chord() objects directly, and not use this underlying structure.
>>> gn = note.GeneralNote(type = '16th', dots = 2) >>> gn.quarterLength 0.4375
GeneralNote
bases
GeneralNote
read-only properties
Read-only properties inherited from Music21Object
:
GeneralNote
read/write properties
-
GeneralNote.
color
¶ Return the Note color.
>>> a = note.GeneralNote() >>> a.duration.type = 'whole' >>> a.color is None True >>> a.color = '#235409' >>> a.color '#235409' >>> a.editorial.color '#235409'
-
GeneralNote.
editorial
¶ a
NoteEditorial
object that stores editorial information (comments, harmonic information, ficta) and certain display information (color, hidden-state).Created automatically as needed:
>>> n = note.Note("C4") >>> n.editorial <music21.editorial.NoteEditorial object at 0x...> >>> n.editorial.ficta = pitch.Accidental('sharp') >>> n.editorial.ficta <accidental sharp>
-
GeneralNote.
lyric
¶ The lyric property can be used to get and set a lyric for this Note, Chord, or Rest. This is a simplified version of the more general
addLyric()
method.>>> a = note.Note('A4') >>> a.lyrics [] >>> a.lyric = 'hel-' >>> a.lyric 'hel' >>> a.lyrics [<music21.note.Lyric number=1 syllabic=begin text="hel">]
Eliminate Lyrics by setting a.lyric to None
>>> a.lyric = None >>> a.lyric >>> a.lyrics []
TODO: should check data here should split n separated lyrics into different lyrics
presently only creates one lyric, and destroys any existing lyrics
Read/write properties inherited from Music21Object
:
GeneralNote
methods
-
GeneralNote.
addLyric
(text, lyricNumber=None, applyRaw=False, lyricIdentifier=None)¶ Adds a lyric, or an additional lyric, to a Note, Chord, or Rest’s lyric list. If lyricNumber is not None, a specific line of lyric text can be set. The lyricIdentifier can also be set.
>>> n1 = note.Note() >>> n1.addLyric("hello") >>> n1.lyrics[0].text 'hello' >>> n1.lyrics[0].number 1
An added option gives the lyric number, not the list position
>>> n1.addLyric("bye", 3) >>> n1.lyrics[1].text 'bye' >>> n1.lyrics[1].number 3 >>> for lyr in n1.lyrics: print(lyr.text) hello bye
Replace an existing lyric by specifying the same number:
>>> n1.addLyric("ciao", 3) >>> n1.lyrics[1].text 'ciao' >>> n1.lyrics[1].number 3
Giving a lyric with a hyphen at either end will set whether it is part of a multisyllable word:
>>> n1.addLyric("good-") >>> n1.lyrics[2].text 'good' >>> n1.lyrics[2].syllabic 'begin'
This feature can be overridden by specifying “applyRaw = True”:
>>> n1.addLyric("-5", applyRaw = True) >>> n1.lyrics[3].text '-5' >>> n1.lyrics[3].syllabic 'single'
-
GeneralNote.
augmentOrDiminish
(scalar, inPlace=True)¶ Given a scalar greater than zero, return a Note with a scaled Duration. If inPlace is True, this is done in-place and the method returns None. If inPlace is False, this returns a modified deepcopy.
>>> n = note.Note('g#') >>> n.quarterLength = 3 >>> n.augmentOrDiminish(2) >>> n.quarterLength 6.0
>>> c = chord.Chord(['g#','A#','d']) >>> n.quarterLength = 2 >>> n.augmentOrDiminish(.25) >>> n.quarterLength 0.5
>>> n = note.Note('g#') >>> n.augmentOrDiminish(-1) Traceback (most recent call last): NoteException: scalar must be greater than zero
-
GeneralNote.
getGrace
(appogiatura=False, inPlace=False)¶ Return a grace version of this GeneralNote
>>> n = note.Note('G4', quarterLength=2) >>> n.duration.quarterLength 2.0 >>> n.duration.isGrace False >>> n.duration <music21.duration.Duration 2.0> >>> n.duration.type 'half' >>> n.duration.components (DurationTuple(type='half', dots=0, quarterLength=2.0),)
>>> ng = n.getGrace() >>> ng.duration.quarterLength 0.0 >>> ng.duration.isGrace True >>> ng.duration <music21.duration.GraceDuration unlinked type:zero quarterLength:0.0> >>> ng.duration.type 'zero' >>> ng.duration.components (DurationTuple(type='half', dots=0, quarterLength=0.0),)
Appogiaturas are still a work in progress...
>>> ng2 = n.getGrace(appogiatura=True) >>> ng2.duration <music21.duration.AppogiaturaDuration unlinked type:zero quarterLength:0.0> >>> ng2.duration.slash False
Set inPlace to True to change the duration element on the Note. This can have negative consequences if the Note is in a stream.
>>> r = note.Rest(quarterLength = .5) >>> r.getGrace(inPlace=True) >>> r.duration <music21.duration.GraceDuration unlinked type:zero quarterLength:0.0>
-
GeneralNote.
hasLyrics
()¶ Return True if this object has any lyrics defined
TODO: Delete: just do:
if self.lyrics
...
-
GeneralNote.
insertLyric
(text, index=0, applyRaw=False, identifier=None)¶ Inserts a lyric into the Note, Chord, or Rest’s lyric list in front of the index specified (0 by default), using index + 1 as the inserted lyric’s line number. shifts line numbers of all following lyrics in list
>>> n1 = note.Note() >>> n1.addLyric("second") >>> n1.lyrics [<music21.note.Lyric number=1 syllabic=single text="second">] >>> n1.insertLyric("first", 0) >>> n1.lyrics [<music21.note.Lyric number=1 syllabic=single text="first">, <music21.note.Lyric number=2 syllabic=single text="second">]
Methods inherited from Music21Object
:
GeneralNote
instance variables
-
GeneralNote.
articulations
¶ a list of articulations such as
Staccato
, etc.) that are stored on this Note.
-
GeneralNote.
expressions
¶ a list of expressions (such as
Fermata
, etc.) that are stored on this Note.
-
GeneralNote.
isChord
¶ Boolean read-only value describing if this object is a Chord.
-
GeneralNote.
tie
¶ either None or a
Tie
object.
Instance variables inherited from Music21Object
:
Lyric¶
-
class
music21.note.
Lyric
(text=None, number=1, **kwargs)¶ An object representing a single Lyric as part of a note’s .lyrics property.
The note.lyric property is a simple way of specifying a single lyric, but Lyric objects are needed for working with multiple lyrics.
>>> l = note.Lyric(text="hello") >>> l <music21.note.Lyric number=1 syllabic=single text="hello">
Music21 processes leading and following hyphens intelligently...
>>> l2 = note.Lyric(text='hel-') >>> l2 <music21.note.Lyric number=1 syllabic=begin text="hel">
...unless applyRaw is set to True
>>> l3 = note.Lyric(number=3, text='hel-', applyRaw=True) >>> l3 <music21.note.Lyric number=3 syllabic=single text="hel-">
Lyrics have four properties: text, number, identifier, syllabic (single, begin, middle, end)
>>> l3.text 'hel-'
>>> l3.number 3
>>> l3.syllabic 'single'
Note musicXML only supports one ‘identifier’ attribute which is called ‘number’ but which can be a number or a descriptive identifier like ‘part2verse1.’ To preserve lyric ordering, music21 stores a number and a descriptive identifier separately. The descriptive identifier is by default the same as the number, but in cases where a string identifier is present, it will be different.
Lyric
bases
Lyric
read-only properties
-
Lyric.
rawText
¶ returns the text of the syllable with ‘-‘ etc.
>>> l = note.Lyric("hel-") >>> l.text 'hel' >>> l.rawText 'hel-'
Lyric
read/write properties
-
Lyric.
identifier
¶ By default, this is the same as self.number. However, if there is a descriptive identifier like ‘part2verse1’, it is stored here and will be different from self.number. When converting to musicXML, this property will be stored in the lyric ‘number’ attribute which can store a number or a descriptive identifier but not both.
>>> l = note.Lyric() >>> l.number = 12 >>> l.identifier 12
>>> l.identifier = 'Rainbow' >>> l.identifier 'Rainbow'
-
Lyric.
number
¶ This stores the number of the lyric (which determines the order lyrics appear in the score if there are multiple lyrics). Unlike the musicXML lyric number attribute, this value must always be a number; lyric order is always stored in this form. Descriptive identifiers like ‘part2verse1’ which can be found in the musicXML lyric number attribute should be stored in self.identifier.
Lyric
methods
-
Lyric.
setTextAndSyllabic
(rawText, applyRaw=False)¶ Given a setting for rawText and applyRaw, sets the syllabic type for a lyric based on the rawText:
>>> l = note.Lyric() >>> l.setTextAndSyllabic('hel-') >>> l.text 'hel' >>> l.syllabic 'begin'