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.
Clef¶
- class music21.clef.Clef(**keywords)¶
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
Equality
Two Clefs are equal if their class is the same, their sign is the same, their line is the same and their octaveChange is the same.
>>> c1 = clef.PercussionClef() >>> c2 = clef.NoClef() >>> c1 == c2 False >>> c3 = clef.TrebleClef() >>> c4 = clef.TrebleClef() >>> c3 == c4 True >>> c4.octaveChange = -1 >>> c3 == c4 False
Note that these are not equal:
>>> clef.TrebleClef() == clef.GClef(line=2) False
Clef
bases
Clef
read-only properties
- Clef.name¶
Returns the “name” of the clef, from the class name
>>> tc = clef.TrebleClef() >>> tc.name 'treble'
>>> tc = clef.Treble8vbClef() >>> tc.name 'treble8vb'
>>> tc = clef.MezzoSopranoClef() >>> tc.name 'mezzoSoprano'
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
Clef
read/write properties
- Clef.octaveChange¶
The number of octaves that the clef “transposes”, generally 0.
>>> tc = clef.TrebleClef() >>> tc.octaveChange 0 >>> clef.Treble8vbClef().octaveChange -1
Read/write properties inherited from Music21Object
:
Clef
methods
- Clef.getStemDirectionForPitches(pitches: Pitch | Sequence[Pitch], *, firstLastOnly: bool = True, extremePitchOnly: bool = False) str ¶
Return a string representing the stem direction for a single
Pitch
object or a list/tuple/Stream of pitches.>>> P = pitch.Pitch >>> bc = clef.BassClef() >>> bc.getStemDirectionForPitches(P('C3')) 'up'
For two pitches, the most extreme pitch determines the direction:
>>> pitchList = [P('C3'), P('B3')] >>> bc.getStemDirectionForPitches(pitchList) 'down'
If firstLastOnly is True (as by default) then only the first and last pitches are examined, as in a beam group. Here we have C3, B3, C3, so despite the B in bass clef being much farther from the center line than either of the Cs, it is stem up:
>>> pitchList.append(P('C3')) >>> bc.getStemDirectionForPitches(pitchList) 'up'
If firstLastOnly is False, then each of the pitches has a weight on the process
>>> bc.getStemDirectionForPitches(pitchList, firstLastOnly=False) 'down'
If extremePitchOnly is True, then whatever pitch is farthest from the center line determines the direction, regardless of order. (default False).
>>> bc.getStemDirectionForPitches(pitchList, extremePitchOnly=True) 'down' >>> pitchList.insert(1, P('C2')) >>> bc.getStemDirectionForPitches(pitchList, extremePitchOnly=True) 'up'
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
Clef
instance variables
- Clef.line¶
The line, counting from the bottom up, that the clef resides on.
>>> clef.AltoClef().line 3 >>> clef.TenorClef().line 4
May be None:
>>> print(clef.NoClef().line) None
- Clef.sign¶
The sign of the clef, generally, ‘C’, ‘G’, ‘F’, ‘percussion’, ‘none’ or None.
>>> alto = clef.AltoClef() >>> alto.sign 'C' >>> percussion = clef.PercussionClef() >>> percussion.sign 'percussion'
Note the difference here:
>>> clef.Clef().sign is None True >>> clef.NoClef().sign 'none'
Instance variables inherited from Music21Object
:
TrebleClef¶
- class music21.clef.TrebleClef(**keywords)¶
The most common clef of all, a treble clef.
>>> a = clef.TrebleClef() >>> a.sign 'G' >>> a.line 2 >>> a.lowestLine 31 >>> note.Note('E4').pitch.diatonicNoteNum 31
TrebleClef
bases
TrebleClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
TrebleClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
TrebleClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
TrebleClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
BassClef¶
- class music21.clef.BassClef(**keywords)¶
A standard Bass Clef
>>> a = clef.BassClef() >>> a.sign 'F'
BassClef
bases
BassClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
BassClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
BassClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
BassClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
AltoClef¶
- class music21.clef.AltoClef(**keywords)¶
A C AltoClef, common for violas.
>>> a = clef.AltoClef() >>> a.sign 'C' >>> a.line 3
AltoClef
bases
AltoClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
AltoClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
AltoClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
AltoClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
Bass8vaClef¶
- class music21.clef.Bass8vaClef(**keywords)¶
A rarely used Bass Clef an octave higher.
>>> a = clef.Bass8vaClef() >>> a.sign 'F'
Bass8vaClef
bases
Bass8vaClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
Bass8vaClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
Bass8vaClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
Bass8vaClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
Bass8vbClef¶
- class music21.clef.Bass8vbClef(**keywords)¶
A bass clef configured to be an octave lower.
>>> a = clef.Bass8vbClef() >>> a.sign 'F' >>> a.octaveChange -1
Bass8vbClef
bases
Bass8vbClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
Bass8vbClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
Bass8vbClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
Bass8vbClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
CBaritoneClef¶
- class music21.clef.CBaritoneClef(**keywords)¶
A Baritone C clef (as opposed to an F Baritone Clef)
>>> a = clef.CBaritoneClef() >>> a.sign 'C' >>> a.line 5
CBaritoneClef
bases
CBaritoneClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
CBaritoneClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
CBaritoneClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
CBaritoneClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
CClef¶
- class music21.clef.CClef(**keywords)¶
A generic C Clef, with no line set
>>> a = clef.CClef() >>> a.sign 'C'
CClef
bases
CClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
CClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
CClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
CClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
FBaritoneClef¶
- class music21.clef.FBaritoneClef(**keywords)¶
an F Baritone Clef
>>> a = clef.FBaritoneClef() >>> a.sign 'F' >>> a.line 3 >>> b = clef.CBaritoneClef() >>> a.lowestLine == b.lowestLine True >>> a.sign == b.sign False
FBaritoneClef
bases
FBaritoneClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
FBaritoneClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
FBaritoneClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
FBaritoneClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
FClef¶
- class music21.clef.FClef(**keywords)¶
A generic F-Clef, like a Bass clef
>>> a = clef.FClef() >>> a.sign 'F'
FClef
bases
FClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
FClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
FClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
FClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
FrenchViolinClef¶
- class music21.clef.FrenchViolinClef(**keywords)¶
A G Clef that appears in many old French Violin scores, appearing on the lowest line, and thus higher than a treble clef.
>>> a = clef.FrenchViolinClef() >>> a.sign 'G' >>> a.line 1
FrenchViolinClef
bases
FrenchViolinClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
FrenchViolinClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
FrenchViolinClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
FrenchViolinClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
GClef¶
- class music21.clef.GClef(**keywords)¶
A generic G Clef
>>> a = clef.GClef() >>> a.sign 'G'
If not defined, the lowestLine is set as a Treble Clef (E4 = 31)
>>> a.lowestLine 31
GClef
bases
GClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
GClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
GClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
GClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
GSopranoClef¶
- class music21.clef.GSopranoClef(**keywords)¶
A G clef on the middle line, formerly occasionally used for soprano parts.
>>> a = clef.GSopranoClef() >>> a.sign 'G' >>> a.line 3
GSopranoClef
bases
GSopranoClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
GSopranoClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
GSopranoClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
GSopranoClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
JianpuClef¶
- class music21.clef.JianpuClef(**keywords)¶
Jianpu notation does not use a clef, but musicxml marks it with a specialized “jianpu” sign.
>>> jc = clef.JianpuClef() >>> jc.sign 'jianpu'
JianpuClef
bases
JianpuClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
JianpuClef
read/write properties
Read/write properties inherited from Clef
:
Read/write properties inherited from Music21Object
:
JianpuClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
JianpuClef
instance variables
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
MezzoSopranoClef¶
- class music21.clef.MezzoSopranoClef(**keywords)¶
A C clef with C on the second line. Perhaps the rarest of the C clefs
>>> a = clef.MezzoSopranoClef() >>> a.sign 'C' >>> a.line 2
MezzoSopranoClef
bases
MezzoSopranoClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
MezzoSopranoClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
MezzoSopranoClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
MezzoSopranoClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
NoClef¶
- class music21.clef.NoClef(**keywords)¶
represents the absence of a Clef.
>>> nc = clef.NoClef() >>> nc.sign 'none'
Note that the sign is the string ‘none’ not the None object
>>> nc.sign is None False
NoClef
bases
NoClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
NoClef
read/write properties
Read/write properties inherited from Clef
:
Read/write properties inherited from Music21Object
:
NoClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
NoClef
instance variables
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
PercussionClef¶
- class music21.clef.PercussionClef(**keywords)¶
represents a Percussion clef.
>>> pc = clef.PercussionClef() >>> pc.sign 'percussion' >>> pc.line is None True
Percussion clefs should not, technically have a “lowestLine,” 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
Changed in v7.3: setting octaveChange no longer affects lowestLine
PercussionClef
bases
PercussionClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
PercussionClef
read/write properties
Read/write properties inherited from Clef
:
Read/write properties inherited from Music21Object
:
PercussionClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
PercussionClef
instance variables
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
PitchClef¶
- class music21.clef.PitchClef(**keywords)¶
Superclass for all other clef subclasses that use pitches.
PitchClef
bases
PitchClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
PitchClef
read/write properties
- PitchClef.octaveChange¶
The number of octaves that the clef “transposes”, generally 0.
>>> tc = clef.TrebleClef() >>> tc.octaveChange 0 >>> clef.Treble8vbClef().octaveChange -1
Changing octaveChange changes lowestLine (but not vice-versa)
>>> tc.lowestLine 31 >>> tc.octaveChange = 1 >>> tc.lowestLine 38 >>> tc.octaveChange = -1 >>> tc.lowestLine 24
Read/write properties inherited from Music21Object
:
PitchClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
PitchClef
instance variables
- PitchClef.lowestLine¶
The diatonicNoteNumber of the lowest line of the clef. (Can be None)
>>> clef.TrebleClef().lowestLine 31
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
SopranoClef¶
- class music21.clef.SopranoClef(**keywords)¶
A soprano clef, with C on the lowest line (found in Bach often)
>>> a = clef.SopranoClef() >>> a.sign 'C' >>> a.line 1
SopranoClef
bases
SopranoClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
SopranoClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
SopranoClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
SopranoClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
SubBassClef¶
- class music21.clef.SubBassClef(**keywords)¶
An F clef on the top line.
>>> a = clef.SubBassClef() >>> a.sign 'F'
SubBassClef
bases
SubBassClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
SubBassClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
SubBassClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
SubBassClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
TabClef¶
- class music21.clef.TabClef(**keywords)¶
represents a Tablature clef.
>>> a = clef.TabClef() >>> a.sign 'TAB'
TabClef
bases
TabClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
TabClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
TabClef
methods
- TabClef.getStemDirectionForPitches(pitchList: Pitch | Iterable[Pitch], *, firstLastOnly: bool = True, extremePitchOnly: bool = False) str ¶
Overridden to simply return ‘down’ for guitar tabs.
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
TabClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
TenorClef¶
- class music21.clef.TenorClef(**keywords)¶
A C Tenor Clef, often used in bassoon and cello parts and orchestral trombone parts.
>>> a = clef.TenorClef() >>> a.sign 'C' >>> a.line 4
TenorClef
bases
TenorClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
TenorClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
TenorClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
TenorClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
Treble8vaClef¶
- class music21.clef.Treble8vaClef(**keywords)¶
A treble clef an octave up (such as for piccolos)
>>> a = clef.Treble8vaClef() >>> a.sign 'G' >>> a.octaveChange 1
Treble8vaClef
bases
Treble8vaClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
Treble8vaClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
Treble8vaClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
Treble8vaClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
Treble8vbClef¶
- class music21.clef.Treble8vbClef(**keywords)¶
A vocal tenor treble clef. Also for guitars.
>>> a = clef.Treble8vbClef() >>> a.sign 'G' >>> a.octaveChange -1
Treble8vbClef
bases
Treble8vbClef
read-only properties
Read-only properties inherited from Clef
:
Read-only properties inherited from Music21Object
:
Read-only properties inherited from ProtoM21Object
:
Treble8vbClef
read/write properties
Read/write properties inherited from PitchClef
:
Read/write properties inherited from Music21Object
:
Treble8vbClef
methods
Methods inherited from Clef
:
Methods inherited from Music21Object
:
Methods inherited from ProtoM21Object
:
Treble8vbClef
instance variables
Instance variables inherited from PitchClef
:
Instance variables inherited from Clef
:
Instance variables inherited from Music21Object
:
Functions¶
- music21.clef.bestClef(streamObj: stream.Stream, allowTreble8vb=False, recurse=False) PitchClef ¶
Returns the clef that is the best fit for notes and chords found in this Stream.
>>> import random >>> a = stream.Stream() >>> for x in range(30): ... n = note.Note() ... n.pitch.midi = random.randint(70, 81) ... a.insert(n) >>> b = clef.bestClef(a) >>> b <music21.clef.TrebleClef> >>> b.line 2 >>> b.sign 'G'
>>> c = stream.Stream() >>> for x in range(10): ... n = note.Note() ... n.pitch.midi = random.randint(45, 54) ... c.insert(n) >>> d = clef.bestClef(c) >>> d <music21.clef.BassClef> >>> d.line 4 >>> d.sign 'F'
This does not automatically get a flat representation of the Stream.
There are a lot more high notes in a (30) than low notes in c (10), but it will not matter here, because the pitches in a will not be found:
>>> c.insert(0, a) >>> clef.bestClef(c) <music21.clef.BassClef>
But with recursion, it will matter:
>>> clef.bestClef(c, recurse=True) <music21.clef.TrebleClef>
Notes around middle C can get Treble8vb if the setting is allowed:
>>> clef.bestClef(stream.Stream([note.Note('D4')])) <music21.clef.TrebleClef> >>> clef.bestClef(stream.Stream([note.Note('D4')]), allowTreble8vb=True) <music21.clef.Treble8vbClef>
Streams of extremely high notes or extremely low notes can get Treble8va or Bass8vb clefs:
>>> clef.bestClef(stream.Stream([note.Note('D7')])) <music21.clef.Treble8vaClef> >>> clef.bestClef(stream.Stream([note.Note('C0')])) <music21.clef.Bass8vbClef>
- music21.clef.clefFromString(clefString, octaveShift=0) Clef ¶
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>
Invalid line numbers raise an exception:
>>> invalidClef = clef.clefFromString('F6') Traceback (most recent call last): music21.clef.ClefException: line number (second character) must be 1-5; do not use this function for clefs on special staves such as 'F6'
Can find any clef in the module
>>> clef.clefFromString('Treble') <music21.clef.TrebleClef> >>> clef.clefFromString('trebleclef') <music21.clef.TrebleClef> >>> clef.clefFromString('treble8vb') <music21.clef.Treble8vbClef>