Classes and functions for creating and manipulating notes, ties, and durations.
The Pitch object is stored within, and used to configure, Note objects.
Debugging method to print information about a music21 note called by trecento.trecentoCadence, among other places
Inherits from: NotRest, GeneralNote, Music21Object, JSONSerializer
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 object is a Note.
- isRest¶
Boolean read-only value describing if this is a Rest.
- isUnpitched¶
Boolean read-only value describing if this is Unpitched.
Attributes inherited from GeneralNote: isChord, lyrics, expressions, tie, articulations, editorial
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, id, groups, hideObjectOnPrint
Note properties
- nameWithOctave¶
Return or set the pitch name with octave from the Pitch object. See nameWithOctave.
- pitchClass¶
Return or set the pitch class from the music21.pitch.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 'E3-half-sharp Half Note'>>> n = note.Note('D', quarterLength=.25) >>> n.microtone = 25 >>> n.fullName 'D (+25c) 16th Note'
- midiEvents¶
Get or set this chord as a list of music21.midi.base.MidiEvent objects.
>>> from music21 import * >>> n = note.Note() >>> n.midiEvents [<MidiEvent DeltaTime, t=0, track=None, channel=1>, <MidiEvent NOTE_ON, t=None, track=None, channel=1, pitch=60, velocity=90>, <MidiEvent DeltaTime, t=1024, track=None, channel=1>, <MidiEvent NOTE_OFF, t=None, track=None, channel=1, pitch=60, velocity=0>]
- midiFile¶
Return a complete music21.midi.base.MidiFile object based on the Note.
The music21.midi.base.MidiFile object can be used to write a MIDI file of this Note with default parameters using the music21.midi.base.MidiFile.write() method, given a file path. The file must be opened in ‘wb’ mode.
>>> from music21 import * >>> n = note.Note() >>> mf = n.midiFile >>> mf.open('/Volumes/xdisc/_scratch/midi.mid', 'wb') >>> mf.write() >>> mf.close()
- mx¶
No documentation.
- pitchClassString¶
Return or set the pitch class string from the Pitch object. See pitchClassString.
- pitchNames¶
Return a list of Pitch names from name. This property is designed to provide an interface analogous to that found on Chord.
>>> from music21 import * >>> n = note.Note('g#') >>> n.name 'G#' >>> n.pitchNames ['G#'] >>> n.pitchNames = [pitch.Pitch('c2'), pitch.Pitch('g2')] >>> n.name 'C' >>> n.pitchNames ['C']
- 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 [G#] >>> n.pitches = [pitch.Pitch('c2'), pitch.Pitch('g2')] >>> n.nameWithOctave 'C2' >>> n.pitches [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, noteheadParen, stemDirection, volume
Properties inherited from GeneralNote: quarterLength, color, lyric, musicxml
Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
Note methods
- jsonAttributes()¶
Define all attributes of this object that should be JSON serialized for storage and re-instantiation.
- setAccidental(accidental)¶
This method is obsolete: use the accidental property instead.
- 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(), compactNoteInfo(), getGrace(), hasLyrics(), insertLyric()
Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), searchActiveSiteByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: GeneralNote, Music21Object, JSONSerializer
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 stream.notes does not get rests. However, the property stream.notesAndRests 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 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: isUnpitched, name
Attributes inherited from GeneralNote: editorial, isChord, expressions, tie, lyrics, articulations
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, 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'
- mx¶
Returns a List of mxNotes Attributes of notes are merged from different locations: first from the duration objects, then from the pitch objects. Finally, GeneralNote attributes are added
Properties inherited from GeneralNote: quarterLength, color, lyric, musicxml
Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
Rest methods
Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), compactNoteInfo(), getGrace(), hasLyrics(), insertLyric(), jsonAttributes()
Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), searchActiveSiteByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Note, NotRest, GeneralNote, Music21Object, JSONSerializer
Inherits from: Music21Object, JSONSerializer
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 without Documentation: expressions, articulations
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, 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.GeneralNote() >>> a.lyric = 'test' >>> a.lyric 'test'
- musicxml¶
Return a complete musicxml representation.
Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
GeneralNote methods
- addLyric(text, lyricNumber=None, applyRaw=False)¶
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.
>>> 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
- compactNoteInfo()¶
A debugging info tool, returning information about a note E- E 4 flat 16th 0.166666666667 & is a tuplet (in fact STOPS the tuplet)
- 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)¶
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">]
- jsonAttributes()¶
Define all attributes of this object that should be JSON serialized for storage and re-instantiation. Attributes that name basic Python objects or JSONSerializer subclasses, or dictionaries or lists that contain Python objects or JSONSerializer subclasses, can be provided.
>>> from music21 import * >>> gn = note.GeneralNote() >>> gn.jsonAttributes() ['_activeSite', '_activeSiteId', '_definedContexts', '_duration', '_idLastDeepCopyOf', '_overriddenLily', '_priority', 'lyrics', 'expressions', 'articulations', 'editorial', 'tie']Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), searchActiveSiteByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Note, NotRest, GeneralNote, Music21Object, JSONSerializer
Inherits from: JSONSerializer
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 three properties: text, number, syllabic (single, begin, middle, end)
>>> l3.text
'hel-'
>>> l3.number
3
>>> l3.syllabic
'single'
Lyric attributes
Attributes without Documentation: text, syllabic, number
Lyric properties
Properties inherited from JSONSerializer: json
Lyric methods
- jsonAttributes()¶
Define all attributes of this object that should be JSON serialized for storage and re-instantiation. Attributes that name basic Python objects or JSONSerializer subclasses, or dictionaries or lists that contain Python objects or JSONSerializer subclasses, can be provided.
>>> from music21 import * >>> l = note.Lyric() >>> l.jsonAttributes() ['text', 'syllabic', 'number']Methods inherited from JSONSerializer: jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: GeneralNote, Music21Object, JSONSerializer
Parent class for objects that are not rests; or, an object with a stem that can be tied.
NotRest attributes
Attributes inherited from GeneralNote: editorial, isChord, expressions, tie, lyrics, articulations
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, groups, id
NotRest properties
- notehead¶
Get or set the notehead 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
- noteheadParen¶
Get or set the note head fill status fo this NotRest.
- 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, musicxml
Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
NotRest methods
- jsonAttributes()¶
Define all attributes of this object that should be JSON serialized for storage and re-instantiation. Attributes that name basic Python objects or JSONSerializer subclasses, or dictionaries or lists that contain Python objects or JSONSerializer subclasses, can be provided.
Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), compactNoteInfo(), getGrace(), hasLyrics(), insertLyric()
Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), searchActiveSiteByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Note, NotRest, GeneralNote, Music21Object, JSONSerializer
Inherits from: GeneralNote, Music21Object, JSONSerializer
General class of unpitched objects which appear at different places on the staff. Examples: percussion notation
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, expressions, tie, lyrics, articulations
Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, hideObjectOnPrint, groups, id
Unpitched properties
Properties inherited from GeneralNote: quarterLength, color, lyric, musicxml
Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
Unpitched methods
Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), compactNoteInfo(), getGrace(), hasLyrics(), insertLyric(), jsonAttributes()
Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), searchActiveSiteByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Note, NotRest, GeneralNote, Music21Object, JSONSerializer