Table Of Contents

Previous topic

music21.meter

Next topic

music21.node

This Page

music21.note

Classes and functions for creating and manipulating notes, ties, and durations. Pitch-specific functions are in music21.pitch, but obviously are of great importance here too.

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

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

Note class for notes (not rests or unpitched elements) that can be represented by one or more notational units 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. A ComplexNote will eventually be smart enough that if given a duration in quarters it will try to figure out a way to express itself as best it can if it needs to be represented on page. It does not know this now.

inherits from: NotRest, GeneralNote, Music21Object

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

Attributes inherited from NotRest: stemDirection

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

Attributes inherited from Music21Object: id, groups

Note properties

nameWithOctave
Return or set the pitch name with octave from the music21.pitch.Pitch object. See music21.pitch.Pitch.nameWithOctave.
pitchClass
Return or set the pitch class from the music21.pitch.Pitch object. See music21.pitch.Pitch.pitchClass.
accidental
Return or set the music21.pitch.Accidental object from the music21.pitch.Pitch object.
diatonicNoteNum
Return the diatonic note number from the music21.pitch.Pitch object. See music21.pitch.Pitch.diatonicNoteNum.
freq440
Return or set the freq440 value from the music21.pitch.Pitch object. See music21.pitch.Pitch.freq440.
frequency
Return or set the frequency from the music21.pitch.Pitch object. See music21.pitch.Pitch.frequency.
lily
The name of the note as it would appear in Lilypond format.
midi
Return or set the numerical MIDI pitch representation from the music21.pitch.Pitch object. See music21.pitch.Pitch.midi.
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
name
No documentation.
octave
Return or set the octave value from the music21.pitch.Pitch object. See music21.pitch.Pitch.octave.
pitchClassString
Return or set the pitch class string from the music21.pitch.Pitch object. See music21.pitch.Pitch.pitchClassString.
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 music21.pitch.Pitch object. See music21.pitch.Pitch.step.

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

Properties inherited from Music21Object: duration, offset, parent, priority

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.

>>> a = 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 NotRest: splitNoteAtPoint()

Methods inherited from GeneralNote: addLyric(), compactNoteInfo(), splitAtDurations()

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndParent(), freezeIds(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), purgeLocations(), removeLocation(), searchParentByAttr(), setContextAttr(), show(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Rest

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

General rest class

inherits from: GeneralNote, Music21Object

Rest attributes

isNote
Boolean read-only value describing if this object is a Chord.
isRest
Boolean read-only value describing if this is a Rest.

Attributes without Documentation: isUnpitched, name

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

Attributes inherited from Music21Object: id, groups

Rest properties

lily

The name of the rest as it would appear in Lilypond format.

>>> r1 = Rest()
>>> r1.duration.type = "half"
>>> r1.lily
'r2'
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, offset, parent, priority

Rest methods

Methods inherited from GeneralNote: addLyric(), compactNoteInfo(), splitAtDurations()

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndParent(), freezeIds(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), purgeLocations(), removeLocation(), searchParentByAttr(), setContextAttr(), show(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Beam

class music21.note.Beam(type=None, direction=None)

A Beam is an object representation of one single beam, that is, one horizontal line connecting two notes together (or less commonly a note to a rest). Thus it takes two separate Beam objects to represent the beaming of a 16th note. The Beams object (note the plural) is the object that handles groups of Beam objects; it is defined later on. Here are two ways to define the start of a beam

>>> b1 = music21.note.Beam(type = 'start')
>>> b2 = music21.note.Beam('start')
Here is a partial beam (that is, one that does not
connect to any other note, such as the second beam of
a dotted eighth, sixteenth group)
Two ways of doing the same thing
>>> b3 = music21.note.Beam(type = 'partial', direction = 'left')
>>> b4 = music21.note.Beam('partial', 'left')

Beam attributes

Attributes without Documentation: direction, type, number, independentAngle

Beam properties

mx
>>> a = Beam()
>>> a.type = 'start'
>>> a.number = 1
>>> b = a.mx
>>> b.get('charData')
'begin'
>>> b.get('number')
1
>>> a.type = 'partial'
>>> a.direction = 'left'
>>> b = a.mx
>>> b.get('charData')
'backward hook'

Beams

class music21.note.Beams

The Beams object stores in it attribute beamsList (a list) all the Beam objects defined above. Thus len(note.beams) tells you how many beams the note currently has on it.

Beams attributes

Attributes without Documentation: feathered, beamsList

Beams properties

mx
Returns a list of mxBeam objects

Beams methods

append(type=None, direction=None)
No documentation.
fill(level=None)

A quick way of setting the beams list for a particular duration, for instance, fill(“16th”) will clear the current list of beams in the Beams object and add two beams. fill(2) will do the same (though note that that is an int, not a string). It does not do anything to the direction that the beams are going in. Both “eighth” and “8th” work. Adding more than six beams (i.e. things like 512th notes) raises an error.

>>> a = music21.note.Beams()
>>> a.fill('16th')
>>> len(a)
2
>>> a.fill('32nd')
>>> len(a)
3
>>> a.beamsList[2]
<music21.note.Beam object at 0x...>
getByNumber(number)

Gets an internal beam object by number...

>>> a = Beams()
>>> a.fill('16th')
>>> a.setAll('start')
>>> a.getByNumber(2).type
'start'
getNumbers()

Returns a list of all defined beam numbers; it should normally be a set of consecutive integers, but it might not be.

>>> a = Beams()
>>> a.fill('32nd')
>>> a.getNumbers()
[1, 2, 3]
getTypeByNumber(number)

Get beam type, with direction, by number

>>> a = Beams()
>>> a.fill('16th')
>>> a.setAll('start')
>>> a.setByNumber(2, 'partial-right')
>>> a.getTypeByNumber(2)
'partial-right'
>>> a.getTypeByNumber(1)
'start'
getTypes()

Returns a list of all beam types defined for the current beams

>>> a = Beams()
>>> a.fill('16th')
>>> a.setAll('start')
>>> a.getTypes()
['start', 'start']
setAll(type, direction=None)

setAll is a method of convenience that sets the type of each of the beam objects within the beamsList to the specified type. It also takes an optional “direction” attribute that sets the direction for each beam (otherwise the direction of each beam is set to None) Acceptable directions (start, stop, continue, etc.) are listed under Beam() above.

>>> a = music21.note.Beams()
>>> a.fill('16th')
>>> a.setAll('start')
>>> a.getTypes()
['start', 'start']
setByNumber(number, type, direction=None)

Set an internal beam object by number, or rhythmic symbol level

>>> a = Beams()
>>> a.fill('16th')
>>> a.setAll('start')
>>> a.setByNumber(1, 'continue')
>>> a.beamsList[0].type
'continue'
>>> a.setByNumber(2, 'stop')
>>> a.beamsList[1].type
'stop'
>>> a.setByNumber(2, 'partial-right')
>>> a.beamsList[1].type
'partial'
>>> a.beamsList[1].direction
'right'

EighthNote

class music21.note.EighthNote(*arguments, **keywords)
inherits from: Note, NotRest, GeneralNote, Music21Object

GeneralNote

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

A GeneralNote object is the parent object for the Note, Rest, Chird, and related objects.

inherits from: Music21Object

GeneralNote attributes

editorial

EditorialComments that can be applied to notes

>>> a = NoteEditorial()
>>> a.misc
{}
isChord
Boolean read-only value describing if this object is a Chord.
lyrics
A list of Lyric objects.
tie
A Tie object.

Attributes without Documentation: notations, articulations

Attributes inherited from Music21Object: id, groups

GeneralNote properties

quarterLength

Return quarter length

>>> n = Note()
>>> n.quarterLength = 2.0
>>> n.quarterLength
2.0
color
No documentation.
lyric
returns the first Lyric’s text todo: should return a n separated string of lyrics
musicxml
This must call _getMX to get basic mxNote objects

Properties inherited from Music21Object: duration, offset, parent, priority

GeneralNote methods

addLyric(text, lyricNumber=None)

adds another lyric to the note’s lyric list optionally with a certain lyric number

>>> n1 = Note()
>>> n1.addLyric("hello")
>>> n1.lyrics[0].text
'hello'
>>> n1.lyrics[0].number
1
## note that the option number specified gives the lyric number, not the list position
>>> n1.addLyric("bye", 3)
>>> n1.lyrics[1].text
'bye'
>>> n1.lyrics[1].number
3
## replace existing lyric
>>> n1.addLyric("ciao", 3)
>>> n1.lyrics[1].text
'ciao'
>>> n1.lyrics[1].number
3
compactNoteInfo()
nice debugging info tool – returns information about a note E- E 4 flat 16th 0.166666666667 & is a tuplet (in fact STOPS the tuplet)
splitAtDurations()

Takes a Note and returns a list of notes with only a single duration.DurationUnit in each.

>>> a = Note()
>>> a.duration.clear() # remove defaults
>>> a.duration.addDurationUnit(duration.Duration('half'))
>>> a.duration.quarterLength
2.0
>>> a.duration.addDurationUnit(duration.Duration('whole'))
>>> a.duration.quarterLength
6.0
>>> b = a.splitAtDurations()
>>> b[0].pitch == b[1].pitch
True
>>> b[0].duration.type
'half'
>>> b[1].duration.type
'whole'

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndParent(), freezeIds(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), purgeLocations(), removeLocation(), searchParentByAttr(), setContextAttr(), show(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

HalfNote

class music21.note.HalfNote(*arguments, **keywords)
inherits from: Note, NotRest, GeneralNote, Music21Object

Lyric

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

Lyric attributes

Attributes without Documentation: text, number, syllabic

Lyric properties

mx

Returns an mxLyric

>>> a = Lyric()
>>> a.text = 'hello'
>>> mxLyric = a.mx
>>> mxLyric.get('text')
'hello'

NotRest

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

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

inherits from: GeneralNote, Music21Object

NotRest attributes

Attributes without Documentation: stemDirection

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

Attributes inherited from Music21Object: id, groups

NotRest properties

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

Properties inherited from Music21Object: duration, offset, parent, priority

NotRest methods

splitNoteAtPoint(quarterLength)

Split a Note into two Notes.

>>> a = NotRest()
>>> a.duration.type = 'whole'
>>> b, c = a.splitNoteAtPoint(3)
>>> b.duration.type
'half'
>>> b.duration.dots
1
>>> b.duration.quarterLength
3.0
>>> c.duration.type
'quarter'
>>> c.duration.dots
0
>>> c.duration.quarterLength
1.0

Methods inherited from GeneralNote: addLyric(), compactNoteInfo(), splitAtDurations()

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndParent(), freezeIds(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), purgeLocations(), removeLocation(), searchParentByAttr(), setContextAttr(), show(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

QuarterNote

class music21.note.QuarterNote(*arguments, **keywords)
inherits from: Note, NotRest, GeneralNote, Music21Object

Tie

class music21.note.Tie(tievalue=start)

Object added to notes that are tied to other notes. The type value is generally one of start or stop.

>>> note1 = Note()
>>> note1.tie = Tie("start")
>>> note1.tieStyle = "normal" # or could be dotted or dashed
>>> note1.tie.type
'start'
Differences from MusicXML:
notes do not need to know if they are tied from a
previous note.  i.e., you can tie n1 to n2 just with
a tie start on n1.  However, if you want proper musicXML output
you need a tie stop on n2
one tie with "continue" implies tied from and tied to
optional (to know what notes are next:)
.to = note()   # not implimented yet, b/c of garbage coll.
.from = note()

inherits from: Music21Object

Tie attributes

Attributes without Documentation: type

Attributes inherited from Music21Object: id, groups

Tie properties

mx
No documentation.

Properties inherited from Music21Object: duration, offset, parent, priority

Tie methods

Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndParent(), freezeIds(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), purgeLocations(), removeLocation(), show(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Unpitched

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

General class of unpitched objects which appear at different places on the staff. Examples: percussion notation

inherits from: GeneralNote, Music21Object

Unpitched attributes

isNote
Boolean read-only value describing if this object is a Chord.
isRest
Boolean read-only value describing if this is a Rest.

Attributes without Documentation: displayOctave, displayStep, isUnpitched

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

Attributes inherited from Music21Object: id, groups

Unpitched properties

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

Properties inherited from Music21Object: duration, offset, parent, priority

Unpitched methods

Methods inherited from GeneralNote: addLyric(), compactNoteInfo(), splitAtDurations()

Methods inherited from Music21Object: addContext(), addLocation(), addLocationAndParent(), freezeIds(), getContextAttr(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), purgeLocations(), removeLocation(), searchParentByAttr(), setContextAttr(), show(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

WholeNote

class music21.note.WholeNote(*arguments, **keywords)
inherits from: Note, NotRest, GeneralNote, Music21Object