music21.clef

This module defines numerous subclasses of Clef, providing object representations for all commonly used clefs. Clef objects are often found within Measure objects.

Functions

music21.clef.clefFromString(clefString, octaveShift=0)

Returns a Clef object given a string like “G2” or “F4” etc.

Does not refer to a violin/guitar string.

>>> tc = clef.clefFromString("G2")
>>> tc
<music21.clef.TrebleClef>
>>> nonStandard1 = clef.clefFromString("F1")
>>> nonStandard1
<music21.clef.FClef>
>>> nonStandard1.line
1
>>> nonStandard2 = clef.clefFromString("D4")
>>> nonStandard2
<music21.clef.PitchClef>
>>> nonStandard2.sign
'D'
>>> nonStandard2.line
4
>>> tc8vb = clef.clefFromString("G2", -1)
>>> tc8vb
<music21.clef.Treble8vbClef>

Three special clefs, Tab, Percussion, and None are also supported.

>>> tabClef = clef.clefFromString("TAB")
>>> tabClef
<music21.clef.TabClef>

Case does not matter.

>>> tc8vb = clef.clefFromString("g2", -1)
>>> tc8vb
<music21.clef.Treble8vbClef>
>>> percussionClef = clef.clefFromString('Percussion')
>>> percussionClef
<music21.clef.PercussionClef>
>>> noClef = clef.clefFromString('None')
>>> noClef
<music21.clef.NoClef>

Clef

class music21.clef.Clef

A Clef is a basic music21 object for representing musical clefs (Treble, Bass, etc.)

Some clefs only represent the graphical element of the clef, such as G clef, which is subclassed by TrebleClef() and FrenchViolinClef().

>>> tc = clef.TrebleClef()
>>> tc
<music21.clef.TrebleClef>
>>> tc.sign
'G'
>>> tc.line
2

Most clefs also have a “lowestLine” function which represents the diatonicNoteNum of the note that would fall on the lowest line if the Clef were put on a five-line staff. (Where C4,C#4,C##4,C-4 etc. = 29, all types of D4 = 30, etc.)

>>> tc.lowestLine
31

Clef bases

Clef read-only properties

Read-only properties inherited from Music21Object:

Clef read/write properties

Read/write properties inherited from Music21Object:

Clef methods

Methods inherited from Music21Object:

Clef instance variables

Instance variables inherited from Music21Object:

PercussionClef

class music21.clef.PercussionClef

represents a Percussion clef.

>>> pc = clef.PercussionClef()
>>> pc.sign
'percussion'
>>> pc.line is None
True

Percussion clefs should not, technically. have a lowest line, but it is a common usage to assume that in pitch-centric contexts to use the pitch numbers from treble clef for percussion clefs. Thus:

>>> pc.lowestLine == clef.TrebleClef().lowestLine
True

PercussionClef bases

PercussionClef read-only properties

Read-only properties inherited from Music21Object:

PercussionClef read/write properties

Read/write properties inherited from Music21Object:

PercussionClef methods

Methods inherited from Music21Object:

PercussionClef instance variables

Instance variables inherited from Music21Object: