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


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
>>> nonStandard1 = clef.clefFromString("F1")
>>> nonStandard1
>>> nonStandard1.line
>>> nonStandard2 = clef.clefFromString("D4")
>>> nonStandard2
>>> nonStandard2.sign
>>> nonStandard2.line
>>> tc8vb = clef.clefFromString("G2", -1)
>>> tc8vb

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

>>> tabClef = clef.clefFromString("TAB")
>>> tabClef

Case does not matter.

>>> tc8vb = clef.clefFromString("g2", -1)
>>> tc8vb
>>> percussionClef = clef.clefFromString('Percussion')
>>> percussionClef
>>> noClef = clef.clefFromString('None')
>>> noClef


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
>>> tc.sign
>>> tc.line

Most clefs also have a “lowest note” function which represents the diatonicNoteNum of the note. (Where C4,C#4,C##4,C-4 etc. = 29, all types of D4 = 30, etc.)

>>> tc.lowestLine

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: