Classes and functions for creating Notes, Rests, and Lyrics.
The Pitch object is stored within, and used to configure, Note objects.
Inherits from: NotRest, GeneralNote, Music21Object
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 underlying music21.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 attributes
- isNote¶
Boolean read-only value describing if this Note is a Note (True).
- isRest¶
Boolean read-only value describing if this Note is a Rest (False).
- isUnpitched¶
Boolean read-only value describing if this Note is Unpitched (False).
- pitch¶
A Pitch object containing all the information about the note’s pitch. Many .pitch properties and methods are also made Note properties also
Attributes inherited from GeneralNote: isChord, lyrics, expressions, tie, articulations, editorial
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, xPosition, id, sites, groups, hideObjectOnPrint
Note properties
- nameWithOctave¶
Return or set the pitch name with octave from the Pitch object. See Pitch‘s attribute nameWithOctave.
- pitchClass¶
Return or set the pitch class from the Pitch object. See music21.pitch.Pitch.pitchClass.
- accidental¶
Return or set the Accidental object from the Pitch object.
- diatonicNoteNum¶
Return the diatonic note number from the Pitch object. See diatonicNoteNum.
- fullName¶
Return the most complete representation of this Note, providing duration and pitch information.
>>> from music21 import * >>> 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'
- pitchClassString¶
Return or set the pitch class string from the Pitch object. See pitchClassString.
- pitches¶
Return the Pitch object in a list. This property is designed to provide an interface analogous to that found on Chord.
>>> from music21 import * >>> 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>]
- ps¶
Return or set the numerical pitch space representation from the music21.pitch.Pitch object. See music21.pitch.Pitch.ps.
Properties inherited from NotRest: notehead, noteheadFill, noteheadParenthesis, stemDirection, volume
Properties inherited from GeneralNote: quarterLength, color, lyric
Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, fullyQualifiedClasses, isGrace, measureNumber, offset, priority, seconds
Note methods
- 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.
>>> from music21 import * >>> 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#> >>> a.transpose(aInterval, inPlace=True) >>> a <music21.note.Note C#>Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), getGrace(), hasLyrics(), insertLyric()
Methods inherited from Music21Object: addContext(), addLocation(), findAttributeInHierarchy(), getAllContextsByClass(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref(), write()
Inherits from: Note, NotRest, GeneralNote, Music21Object
A simple way of creating a whole note (used in testing and docs mostly) Most whole notes are not WholeNote objects
Inherits from: Note, NotRest, GeneralNote, Music21Object
A simple way of creating a half note (used in testing and docs mostly) Most half notes are not HalfNote objects
Inherits from: Note, NotRest, GeneralNote, Music21Object
A simple way of creating a quarter note (used in testing and docs mostly) Most quarter notes are not QuarterNote objects
N.B. the default Note object is a quarter note, so this is only needed for explicitly stating that a note is a quarter note.
Inherits from: Note, NotRest, GeneralNote, Music21Object
A simple way of creating an eighth note (used in testing and docs mostly) Most eighth notes are not EighthNote objects
Inherits from: GeneralNote, Music21Object
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 property notesAndRests of Streams gets rests as well.
>>> from music21 import *
>>> r = note.Rest()
>>> r.isRest
True
>>> r.isNote
False
>>> r.duration.quarterLength = 2.0
>>> r.duration.type
'half'
Rest attributes
- isNote¶
Boolean read-only value describing if this Rest is a Note (False).
- isRest¶
Boolean read-only value describing if this Rest is a Rest (True, obviously).
- isUnpitched¶
Boolean read-only value describing if this Rest is Unpitched (False – only Unpitched objects are True).
- name¶
returns “rest” always. It is here so that you can get x.name on all .notesAndRests objects
Attributes inherited from GeneralNote: editorial, isChord, expressions, tie, lyrics, articulations
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id
Rest properties
- fullName¶
Return the most complete representation of this Rest, providing duration information.
>>> from music21 import * >>> r = note.Rest(quarterLength=1.5) >>> r.fullName 'Dotted Quarter Rest' >>> note.Rest(type='whole').fullName 'Whole Rest'Properties inherited from GeneralNote: quarterLength, color, lyric
Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, fullyQualifiedClasses, isGrace, measureNumber, offset, priority, seconds
Rest methods
Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), getGrace(), hasLyrics(), insertLyric()
Methods inherited from Music21Object: addContext(), addLocation(), findAttributeInHierarchy(), getAllContextsByClass(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref(), write()
Inherits from: Rest, GeneralNote, Music21Object
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.
Inherits from: NotRest, GeneralNote, Music21Object
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 attributes
- isNote¶
Boolean read-only value describing if this GeneralNote object is a Note. Is False
- isRest¶
Boolean read-only value describing if this GeneralNote object is a Rest. Is False
Attributes without Documentation: displayOctave, displayStep, isUnpitched
Attributes inherited from GeneralNote: editorial, isChord, lyrics, expressions, tie, articulations
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, xPosition, id, sites, groups, hideObjectOnPrint
Unpitched properties
- storedInstrument¶
No documentation.
Properties inherited from NotRest: notehead, noteheadFill, noteheadParenthesis, stemDirection, volume
Properties inherited from GeneralNote: quarterLength, color, lyric
Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, fullyQualifiedClasses, isGrace, measureNumber, offset, priority, seconds
Unpitched methods
- displayPitch()¶
returns a pitch object that is the same as the displayStep and displayOctave
Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), getGrace(), hasLyrics(), insertLyric()
Methods inherited from Music21Object: addContext(), addLocation(), findAttributeInHierarchy(), getAllContextsByClass(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref(), write()
Inherits from: GeneralNote, Music21Object
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 attributes
Attributes inherited from GeneralNote: editorial, isChord, lyrics, expressions, tie, articulations
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, xPosition, id, sites, groups, hideObjectOnPrint
NotRest properties
- notehead¶
Get or set the notehead type of this NotRest object. Valid notehead type names are found in note.noteheadTypeNames (see below):
>>> from music21 import * >>> note.noteheadTypeNames ['slash', 'triangle', 'diamond', 'square', 'cross', 'x', 'circle-x', 'inverted triangle', 'arrow down', 'arrow up', 'slashed', 'back slashed', 'normal', 'cluster', 'none', 'do', 're', 'mi', 'fa', 'so', 'la', 'ti', 'circle dot', 'left triangle', 'rectangle'] >>> 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'
- noteheadFill¶
Get or set the note head fill status of this NotRest. Valid note head fill values are yes, no, default, and None.
>>> from music21 import * >>> n = note.Note() >>> n.noteheadFill = 'no' >>> n.noteheadFill 'no'>>> n.noteheadFill = 'junk' Traceback (most recent call last): NotRestException: not a valid notehead fill value: junk
- noteheadParenthesis¶
Get or set the note head parentheses for this Note/Unpitched/Chord object.
- stemDirection¶
Get or set the stem direction of this NotRest object. Valid stem direction names are found in note.stemDirectionNames (see below).
>>> from music21 import * >>> note.stemDirectionNames ['up', 'down', 'noStem', 'double', 'unspecified', 'none'] >>> 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
- volume¶
Get and set the Volume object of this object. Volume objects are created on demand.
>>> from music21 import * >>> 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]Properties inherited from GeneralNote: quarterLength, color, lyric
Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, fullyQualifiedClasses, isGrace, measureNumber, offset, priority, seconds
NotRest methods
Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), getGrace(), hasLyrics(), insertLyric()
Methods inherited from Music21Object: addContext(), addLocation(), findAttributeInHierarchy(), getAllContextsByClass(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref(), write()
Inherits from: Music21Object
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.
>>> from music21 import *
>>> gn = note.GeneralNote(type = '16th', dots = 2)
>>> gn.quarterLength
0.4375
GeneralNote attributes
- editorial¶
a NoteEditorial object that stores editorial information (comments, harmonic information, ficta) and certain display information (color, hidden-state).
- isChord¶
Boolean read-only value describing if this GeneralNote object is a Chord. Is True
- tie¶
either None or a Tie object.
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, xPosition, sites, groups, id
GeneralNote properties
- quarterLength¶
Return the Duration as represented in Quarter Length.
>>> from music21 import * >>> n = note.Note() >>> n.quarterLength = 2.0 >>> n.quarterLength 2.0
- color¶
Return the Note color.
- 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.
>>> from music21 import * >>> 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 []Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, fullyQualifiedClasses, isGrace, measureNumber, offset, priority, seconds
GeneralNote methods
- 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.
>>> from music21 import * >>> n1 = note.Note() >>> n1.addLyric("hello") >>> n1.lyrics[0].text 'hello' >>> n1.lyrics[0].number 1An 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 byeReplace an existing lyric by specifying the same number:
>>> n1.addLyric("ciao", 3) >>> n1.lyrics[1].text 'ciao' >>> n1.lyrics[1].number 3Giving 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'
- 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 deep copy.
>>> from music21 import * >>> 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
- getGrace(appogiatura=False)¶
Return a grace version of this NotRest
>>> from music21 import * >>> n = note.Note('G4', quarterLength=2) >>> n.duration.quarterLength 2.0 >>> n.isGrace False >>> ng = n.getGrace() >>> ng.duration.quarterLength 0.0 >>> ng.isGrace True >>> ng = n.getGrace(appogiatura=True) >>> ng.duration.slash False
- hasLyrics()¶
Return True if this object has any lyrics defined
- 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
>>> from music21 import * >>> 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: addContext(), addLocation(), findAttributeInHierarchy(), getAllContextsByClass(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref(), write()
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.
>>> from music21 import *
>>> 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 attributes
Attributes without Documentation: text, syllabic
Lyric properties
- 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.
- 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.