Table Of Contents

Previous topic

music21.musicxml.translate

Next topic

music21.pitch

music21.note

Classes and functions for creating and manipulating notes, ties, and durations. The Pitch object is stored within, and used to configure, Note objects.

music21.note.noteFromDiatonicNumber(number)
music21.note.sendNoteInfo(music21noteObject)
Debugging method to print information about a music21 note called by trecento.trecentoCadence, among other places

Note

Inherits from: NotRest, GeneralNote, Music21Object, JSONSerializer

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 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.
beams
A Beams object.
pitch
A Pitch object.

Attributes inherited from NotRest: stemDirection

Attributes inherited from GeneralNote: isChord, expressions, editorial, tie, lyrics, articulations

Attributes inherited from Music21Object: classSortOrder, hideObjectOnPrint, id, groups

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.
freq440
Return or set the freq440 value from the Pitch object. See freq440.
frequency
Return or set the frequency from the Pitch object. See frequency.
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'
microtone
Return or set the microtone value from the Pitch object. See microtone.
midi
Return or set the numerical MIDI pitch representation from the Pitch object. See midi.
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=None>, <MidiEvent NOTE_ON, t=None, track=None, channel=1, pitch=60, velocity=90>, <MidiEvent DeltaTime, t=1024, track=None, channel=None>, <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.
name
Return or set the pitch name from the Pitch object. See name.
octave
Return or set the octave value from the Pitch object. See octave.
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.
step
Return or set the pitch step from the Pitch object. See step.

Properties inherited from GeneralNote: quarterLength, color, lily, lyric, musicxml

Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, measureNumber, offset, priority

Properties inherited from JSONSerializer: json

Note methods

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(), hasLyrics()

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), searchParentByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

Rest

Inherits from: GeneralNote, Music21Object, JSONSerializer

class music21.note.Rest(*arguments, **keywords)

General rest class

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, hideObjectOnPrint, id, groups

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, lily, lyric, musicxml

Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, measureNumber, offset, priority

Properties inherited from JSONSerializer: json

Rest methods

Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), compactNoteInfo(), hasLyrics()

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), searchParentByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

EighthNote

Inherits from: Note, NotRest, GeneralNote, Music21Object, JSONSerializer

class music21.note.EighthNote(*arguments, **keywords)

GeneralNote

Inherits from: Music21Object, JSONSerializer

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 music21.duration.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.
lyrics
A list of Lyric objects.

Attributes without Documentation: expressions, articulations

Attributes inherited from Music21Object: classSortOrder, hideObjectOnPrint, id, groups

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.
lily

read-only property that returns a LilyString of the lilypond representation of a note (or via subclassing, rest or chord)

>>> from music21 import *
>>> n1 = note.Note("C#5")
>>> n1.tie = tie.Tie('start')
>>> n1.articulations = [articulations.Accent()]  ## DOES NOTHING RIGHT NOW
>>> n1.quarterLength = 1.25
>>> n1.lily
cis''4~ cis''16~
>>> r1 = note.Rest()
>>> r1.duration.type = "half"
>>> r1.lily
r2
>>> r2 = note.Rest()
>>> r2.quarterLength = 1.25
>>> r2.lily
r4 r16
>>> c1 = chord.Chord(["C#2", "E4", "D#5"])
>>> c1.quarterLength = 2.5   # BUG: 2.333333333 doesnt work yet
>>> c1.lily
<cis, e' dis''>2~ <cis, e' dis''>8
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, measureNumber, offset, priority

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
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'
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
>>> 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)
hasLyrics()
Return True if this object has any lyrics defined

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), searchParentByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

HalfNote

Inherits from: Note, NotRest, GeneralNote, Music21Object, JSONSerializer

class music21.note.HalfNote(*arguments, **keywords)

Lyric

class music21.note.Lyric(text=None, number=1, syllabic=None, applyRaw=False)

Lyric attributes

Attributes without Documentation: text, syllabic, number

Lyric properties

mx

Returns an mxLyric

>>> from music21 import *
>>> a = note.Lyric()
>>> a.text = 'hello'
>>> mxLyric = a.mx
>>> mxLyric.get('text')
'hello'

NotRest

Inherits from: GeneralNote, Music21Object, JSONSerializer

class music21.note.NotRest(*arguments, **keywords)

Parent class for objects that are not rests; or, an object with a stem that can be tied.

NotRest attributes

Attributes without Documentation: stemDirection

Attributes inherited from GeneralNote: editorial, isChord, expressions, tie, lyrics, articulations

Attributes inherited from Music21Object: classSortOrder, hideObjectOnPrint, id, groups

NotRest properties

Properties inherited from GeneralNote: quarterLength, color, lily, lyric, musicxml

Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, measureNumber, offset, priority

Properties inherited from JSONSerializer: json

NotRest methods

Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), compactNoteInfo(), hasLyrics()

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), searchParentByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

QuarterNote

Inherits from: Note, NotRest, GeneralNote, Music21Object, JSONSerializer

class music21.note.QuarterNote(*arguments, **keywords)

Unpitched

Inherits from: GeneralNote, Music21Object, JSONSerializer

class music21.note.Unpitched(*arguments, **keywords)

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, hideObjectOnPrint, id, groups

Unpitched properties

Properties inherited from GeneralNote: quarterLength, color, lily, lyric, musicxml

Properties inherited from Music21Object: duration, activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, measureNumber, offset, priority

Properties inherited from JSONSerializer: json

Unpitched methods

Methods inherited from GeneralNote: addLyric(), augmentOrDiminish(), compactNoteInfo(), hasLyrics()

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), searchParentByAttr(), setContextAttr(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

WholeNote

Inherits from: Note, NotRest, GeneralNote, Music21Object, JSONSerializer

class music21.note.WholeNote(*arguments, **keywords)