Parses the de Clercq-Temperley popular music flavor of RomanText. The Clercq-Temperley file format and additional rock corpus analysis information may be located at


class music21.romanText.clercqTemperley.CTSong(textFile, **keywords)

This parser is an object-oriented approach to parsing clercqTemperley text files into music.

Create a CTSong object one of two ways: 1) by passing in the string, with newline characters (\n) at the end of each line 2) by passing in the text file as a string, and have python open the file and read the text

>>> exampleClercqTemperley = '''
... % Brown-Eyed Girl
... VP: I \| IV \| I \| V \|
... In: $VP\*2
... Vr: $VP\*4 IV \| V \| I \| vi \| IV \| V \| I \| V \|  % Second part of verse could be called chorus
... Ch: V \| \| $VP\*2 I \|\*4 
... Ch2: V \| \| $VP\*3     % Fadeout
... S: [G] $In $Vr $Vr $Ch $VP $Vr $Ch2
... '''
>>> s = romanText.clercqTemperley.CTSong('C:/Brown-Eyed_Girl.txt')

When you call the .toScore() method on the newly created CTSong object, the code extracts meaningful properties (such as title, text, comments, year, rules, home time Signature, and home Key Signature) from the textfile and makes these accessible as below.

The toScore() method has two optional labeling parameters, labelRomanNumerals and labelSubsectionsOnScore. Both are set to True by default. Thus, the created score will have labels (on the chord’s lyric) for each roman numeral as well as for each section in the song (LHS). In case of a recursive definition (a rule contains a reference to another rule), both labels are printed, with the deepest reference on the smallest lyric line.

>>> s.toScore().show()
>>> s.title
'Brown-Eyed Girl'
>>> s.homeTimeSig
<music21.meter.TimeSignature 4/4>
>>> s.homeKeySig
<music21.key.Key of G major>
>>> s.comments
[['Vr:', 'Second part of verse could be called chorus'], ['Ch2:', 'Fadeout']]

Year is not defined as part of the Clercq-Temperley format, but it will be helpful to have it as a property. So let’s assign a year to this song:

>>> s.year = 1967
>>> s.year

Upon calling toScore(), CTRule objects are also created. CTRule objects are the individual rules that make up the song object. For example,

>>> s.rules
OrderedDict([('VP', <music21.CTRule.CTRule text="VP: I | IV | I | V |">), 
             ('In', <music21.CTRule.CTRule text="In: $VP*2">), 
             ('Vr', <music21.CTRule.CTRule text="Vr: $VP*4 IV | V | I | vi | IV | V | I | V |  % Second part of verse could be called chorus">), 
             ('Ch', <music21.CTRule.CTRule text="Ch: V | | $VP*2 I |*4">), 
             ('Ch2', <music21.CTRule.CTRule text="Ch2: V | | $VP*3     % Fadeout">), 
             ('S', <music21.CTRule.CTRule text="S: [G] $In $Vr $Vr $Ch $VP $Vr $Ch2">)])

The parser extracts meaningful properties to each rule, such as sectionName, home time signature of that rule, home key of that rule, and of course the individual stream from the song corresponding to the rule.

The following examples display the instantiated properties of the second rule (list indexes start at one) as created above.

>>> rule = s.rules['In']
>>> rule.text
'In: $VP*2'
>>> rule.sectionName

With this object-oriented approach to parsing the clercq-temperley text file format, we now have the ability to analyze a large corpus (200 files) of popular music using the full suite of harmonic tools of music21. We can not only analyze each song as a whole, as presented in Clercq and Temperley’s research, but we can also analyze each individual section (or rule) of a song. This may provide interesting insight into popular music beyond our current understanding.

Examples used throughout this class utilize the following Clercq-Temperley text file

>>> BlitzkriegBopCT = '''
... % Blitzkrieg Bop
... In: $BP\*3 I IV \| I \| $BP\*3 I IV \| I \| R \|\*4 I \|\*4
... Vr: $BP\*3 I IV \| I \|
... Br: IV \| \| I \| IV I \| IV \| \| ii \| IV V \|
... Co: R \|\*4 I \|\*4
... S: [A] $In $Vr $Vr $Br $Vr $Vr $Br $Vr $Vr $Co
... '''

CTSong read-only properties


Get the comments list of all CTRule objects.

comments are stored as a list of comments, each comment on a line as a list. If the comment is on a rule line, the list contains both the line’s LHS (like In:) and the comment if the comment is on a line of its own, only the comment is appended as a list of length one.

The title is not a comment. The title is stored under self.title

textString = ‘’‘
%Simple Gifts
% A wonderful shaker melody
Vr: I | I | %incomplete verse
S: [A] $Vr % Not quite finished!’‘’
>>> s = romanText.clercqTemperley.CTSong(romanText.clercqTemperley.textString)
>>> s.comments
[['A wonderful shaker melody'], ['Vr:', 'incomplete verse'], ['S:', 'Not quite finished!']]

gets the initial, or ‘home’, key signature by looking at the musictext and locating the key signature at the start of the S: rule.

>>> s = romanText.clercqTemperley.CTSong(romanText.clercqTemperley.textString)
>>> s.homeKeySig
<music21.key.Key of A major>

gets the initial, or ‘home’, time signature in a song by looking at the ‘S’ substring and returning the provided time signature. If not present, returns a default music21 time signature of 4/4

>>> s = romanText.clercqTemperley.CTSong(romanText.clercqTemperley.textString)
>>> s.homeTimeSig
<music21.meter.TimeSignature 4/4>
>>> change = romanText.clercqTemperley.CTSong(romanText.clercqTemperley.changeIsGonnaCome)
>>> change.homeTimeSig
<music21.meter.TimeSignature 12/8>
>>> change.homeTimeSig.beatSequence
<MeterSequence {{1/8+1/8+1/8}+{1/8+1/8+1/8}+{1/8+1/8+1/8}+{1/8+1/8+1/8}}>

Get the rules of a CTSong. the Rules is an OrderedDict of objects of type CTRule. If only a textfile provided, this goes through text file and creates the rule object out of each line containing a LHS including the Song line, which should always be last.

>>> s = romanText.clercqTemperley.CTSong(romanText.clercqTemperley.BlitzkriegBopCT)
>>> len(s.rules)
>>> for rule in s.rules:
...   (rule, s.rules[rule])
('BP', <music21.CTRule.CTRule text="BP: I | IV V | %THIS IS A COMMENT">)
('In', <music21.CTRule.CTRule text="In: $BP*3 I IV | I | $BP*3 I IV | I | R |*4 I |*4">)
('Vr', <music21.CTRule.CTRule text="Vr: $BP*3 I IV | I |">)
('Br', <music21.CTRule.CTRule text="Br: IV | | I | IV I | IV | | ii | IV V |">)
('Co', <music21.CTRule.CTRule text="Co: R |*4 I |*4">)
('S', <music21.CTRule.CTRule text="S: [A] $In $Vr $Vr $Br $Vr $Vr $Br $Vr $Vr $Co">)

Get or set the title of the CTSong. If not specified explicitly but the clercq-Temperley text exists, this attribute searches first few lines of text file for title (a string preceded by a ‘%’) if found, sets title attribute to this string and returns this title)

>>> s = romanText.clercqTemperley.CTSong(romanText.clercqTemperley.textString)
>>> s.title
'Simple Gifts'

CTSong methods


Called when a CTSong is created by passing a string or filename; in the second case, it opens the file and removes all blank lines, and adds in new line characters returns pieceString that CTSong can parse.

CTSong.toScore(labelRomanNumerals=True, labelSubsectionsOnScore=True)

creates Score object out of a from CTSong...also creates CTRule objects in the process, filling their .streamFromCTSong attribute with the corresponding smaller inner stream. Individual attributes of a rule are defined by the entire CTSong, such as meter and time signature, so creation of CTRule objects typically occurs only from this method and directly from the clercqTemperly text.

>>> s = romanText.clercqTemperley.CTSong(romanText.clercqTemperley.BlitzkriegBopCT)
>>> scoreObj = s.toScore()
>>> scoreObj.highestOffset   

CTSong instance variables


the year of the CTSong; not formally defined by the Clercq-Temperley format


class music21.romanText.clercqTemperley.CTRule(text='', parent=None)

CTRule objects correspond to the individual lines defined in a CTSong object. They are typically created by the parser after a CTSong object has been created and the .toScore() method has been called on that object. The usefullness of each CTRule object is that each has a streamFromCTSong() attribute, which is the stream from the entire score that the rule corresponds to.

CTRule read-only properties


Get the comment of a CTRule object.

>>> s = romanText.clercqTemperley.CTRule('In: $BP*3 I IV | I | $BP*3 I IV | I | R |*4 I |*4 % This is a comment')
>>> s.comment
'This is a comment'

Stores the expanded version of the Left hand side (LHS) such as Introduction, Verse, etc. if text present uses LHS to expand)

Currently supported abbreviations:

  • In: Introduction
  • Br: Bridge
  • Vr: Verse
  • Ch: Chorus
  • Fadeout: Fadeout
  • S: Song
>>> s = romanText.clercqTemperley.CTRule('Vr2: $BP*3 I IV | I |')
>>> s.sectionName

CTRule read/write properties


Get the LHS (Left Hand Side) of the CTRule. If not specified explicitly but CTtext present, searches first characters up until ‘:’ for rule and returns string)

>>> s = romanText.clercqTemperley.CTRule('In: $BP*3 I IV | R |*4 I |*4 % This is a comment')
>>> s.LHS

Gets just the music text of the CTRule, excluding the left hand side and comments

>>> s = romanText.clercqTemperley.CTRule('In: $BP*3 I IV | I | $BP*3 I IV | I | R |*4 I |*4 % This is a comment')
>>> s.text
'In: $BP*3 I IV | I | $BP*3 I IV | I | R |*4 I |*4 % This is a comment'
>>> s.musicText
'$BP*3 I IV | I | $BP*3 I IV | I | R |*4 I |*4'

A reference to the CTSong object housing the CTRule if any.

CTRule methods

CTRule.addOptionalTieAndLyrics(rn, lastChord)

Adds ties to chords that are the same. Adds lyrics to chords that change.

CTRule.expand(ts=None, ks=None)

The meat of it all – expand one rule completely and return a list of Measure objects.


changes some CT values into music21 values

>>> s = romanText.clercqTemperley.CTRule()
>>> s.fixupChordAtom('iix')
>>> s.fixupChordAtom('viih7')
>>> s.fixupChordAtom('iia')
CTRule.insertKsTs(m, ts, ks)

insert a new time signature or key signature into measure m, if it’s not already in the stream somewhere.

CTRule.isSame(rn, lastChord)

CTRule instance variables


the full text of the CTRule, including the LHS, chords, and comments