Previous topic

music21.roman

Next topic

music21.romanText.clercqTemperley

Table Of Contents

Table Of Contents

This Page

music21.romanText

Objects for processing roman numeral analysis text files, as defined and demonstrated by Dmitri Tymoczko.

RTAnalyticKey

class music21.romanText.RTAnalyticKey(src=u'', container=None)

RTAnalyticKey bases

RTAnalyticKey methods

Methods inherited from RTKeyTypeAtom:

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTAtom

class music21.romanText.RTAtom(src=u'', container=None)

In RomanText, definitions of chords, phrases boundaries, open/close parenthesis, beat indicators, etc. appear within measures (RTMeasure objects). These individual elements will be called Atoms, as they are data that is not tagged.

Each atom store a reference to its container (normally an RTMeasure).

>>> chordIV = romanText.RTAtom('IV')
>>> beat4 = romanText.RTAtom('b4')

However, see RTChord, RTBeat, etc. which are subclasses of RTAtom specifically for storing chords, beats, etc.

RTAtom bases

RTAtom methods

RTAtom.isAtom()

Methods inherited from RTToken:

RTBeat

class music21.romanText.RTBeat(src=u'', container=None)

An RTAtom subclass that defines a beat definition. Also contains a reference to the container.

>>> beatFour = romanText.RTBeat('b4')

RTBeat bases

RTBeat methods

RTBeat.getOffset(timeSignature)

Given a time signature, return the offset position specified by this beat.

>>> rtb = romanText.RTBeat('b1.5')
>>> rtb.getOffset(meter.TimeSignature('3/4'))
0.5
>>> rtb.getOffset(meter.TimeSignature('6/8'))
0.75
>>> rtb.getOffset(meter.TimeSignature('2/2'))
1.0
>>> rtb = romanText.RTBeat('b2')
>>> rtb.getOffset(meter.TimeSignature('3/4'))
1.0
>>> rtb.getOffset(meter.TimeSignature('6/8'))
1.5
>>> rtb = romanText.RTBeat('b1.66')
>>> rtb.getOffset(meter.TimeSignature('6/8'))
1.0
>>> rtc = romanText.RTBeat('b1.66.5')
>>> rtc.getOffset(meter.TimeSignature('6/8'))
1.25

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTChord

class music21.romanText.RTChord(src=u'', container=None)

An RTAtom subclass that defines a chord. Also contains a reference to the container.

>>> chordIV = romanText.RTChord('IV')

RTChord bases

RTChord methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTCloseParens

class music21.romanText.RTCloseParens(src=u')', container=None)

RTCloseParens bases

RTCloseParens methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTEllisonStart

class music21.romanText.RTEllisonStart(src=u'|*', container=None)

RTEllisonStart bases

RTEllisonStart methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTEllisonStop

class music21.romanText.RTEllisonStop(src=u'|*', container=None)

RTEllisonStop bases

RTEllisonStop methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTFile

class music21.romanText.RTFile

Roman Text File access.

RTFile methods

RTFile.close()
RTFile.open(filename)

Open a file for reading, trying a variety of codecs and then trying them again with an ignore if it is not possible.

RTFile.openFileLike(fileLike)

Assign a file-like object, such as those provided by StringIO, as an open file object.

RTFile.read()

Read a file. Note that this calls readstring, which processes all tokens.

If number is given, a work number will be extracted if possible.

RTFile.readstr(strSrc)

Read a string and process all Tokens. Returns a ABCHandler instance.

RTHandler

class music21.romanText.RTHandler

RTHandler read/write properties

RTHandler.tokens

Get or set tokens for this Handler.

RTHandler methods

RTHandler.definesMovement()

Return True if this handler has 1 or more movement.

>>> rth = romanText.RTHandler()
>>> rth.process('Movement: 1 \n \n m1')
>>> rth.definesMovements()
False
>>> rth.definesMovement()
True
RTHandler.definesMovements(countRequired=2)

Return True if more than one movement is defined in a RT file.

>>> rth = romanText.RTHandler()
>>> rth.process('Movement: 1 \n Movement: 2 \n \n m1')
>>> rth.definesMovements()
True
>>> rth.process('Movement: 1 \n m1')
>>> rth.definesMovements()
False
RTHandler.process(src)

Given an entire specification as a single source string, strSrc. This is usually provided in a file.

RTHandler.splitAtHeader(lines)

Divide string into header and non-header; this is done before tokenization.

>>> rth = romanText.RTHandler()
>>> rth.splitAtHeader(['Title: s', 'Time Signature:', '', 'm1 g: i'])
(['Title: s', 'Time Signature:', ''], ['m1 g: i'])
RTHandler.splitByMovement(duplicateHeader=True)

If we have movements defined, return a list of RTHandler objects, representing header information and each movement, in order.

>>> rth = romanText.RTHandler()
>>> rth.process('Title: Test \n Movement: 1 \n m1 \n Movement: 2 \n m1')
>>> post = rth.splitByMovement(False)
>>> len(post)
3
>>> len(post[0])
1
>>> post[0].__class__
<class 'music21.romanText.RTHandler'>
>>> len(post[1]), len(post[2])
(2, 2)
>>> post = rth.splitByMovement(duplicateHeader=True)
>>> len(post)
2
>>> len(post[0]), len(post[1])
(3, 3)
RTHandler.tokenize(src)

Walk the RT string, creating RT objects along the way.

RTHandler.tokenizeAtoms(line, container=None)

Given a line of data stored in measure consisting only of Atoms, tokenize and return a list.

>>> rth = romanText.RTHandler()
>>> str(rth.tokenizeAtoms('IV b3 ii7 b4 ii'))
"[<RTChord 'IV'>, <RTBeat 'b3'>, <RTChord 'ii7'>, <RTBeat 'b4'>, <RTChord 'ii'>]"
>>> str(rth.tokenizeAtoms('V7 b2 V13 b3 V7 iio6/5[no5]'))
"[<RTChord 'V7'>, <RTBeat 'b2'>, <RTChord 'V13'>, <RTBeat 'b3'>, <RTChord 'V7'>, <RTChord 'iio6/5[no5]'>]"
>>> tokenList = rth.tokenizeAtoms('I b2 I b2.25 V/ii b2.5 bVII b2.75 V g: IV')
>>> str(tokenList)
"[<RTChord 'I'>, <RTBeat 'b2'>, <RTChord 'I'>, <RTBeat 'b2.25'>, <RTChord 'V/ii'>, <RTBeat 'b2.5'>, <RTChord 'bVII'>, <RTBeat 'b2.75'>, <RTChord 'V'>, <RTAnalyticKey 'g:'>, <RTChord 'IV'>]"
>>> tokenList[9].getKey()
<music21.key.Key of g minor>
>>> str(rth.tokenizeAtoms('= m3'))
'[]'
>>> tokenList = rth.tokenizeAtoms('g;: ||: V b2 ?(Bb: VII7 b3 III b4 ?)Bb: i :||')
>>> str(tokenList)
"[<RTKey 'g;:'>, <RTRepeatStart '||:'>, <RTChord 'V'>, <RTBeat 'b2'>, <RTOptionalKeyOpen '?(Bb:'>, <RTChord 'VII7'>, <RTBeat 'b3'>, <RTChord 'III'>, <RTBeat 'b4'>, <RTOptionalKeyClose '?)Bb:'>, <RTChord 'i'>, <RTRepeatStop ':||'>]"
RTHandler.tokenizeBody(lines)

In the body, we may have measure, time signature, or note declarations, as well as possible other tagged definitions.

RTHandler.tokenizeHeader(lines)

In the header, we only have RTTagged tokens. We can this process these all as the same class.

RTKey

class music21.romanText.RTKey(src=u'', container=None)

RTKey bases

RTKey methods

Methods inherited from RTKeyTypeAtom:

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTKeySignature

class music21.romanText.RTKeySignature(src=u'', container=None)

RTKeySignature bases

RTKeySignature methods

RTKeySignature.getKeySignature()

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTKeyTypeAtom

class music21.romanText.RTKeyTypeAtom(src=u'', container=None)

RTKeyTypeAtoms contain utility functions for all Key-type tokensi, i.e. RTKey, RTAnalyticKey, but not KeySignature.

RTKeyTypeAtom bases

RTKeyTypeAtom methods

RTKeyTypeAtom.getKey()

This returns a Key, not a KeySignature object

RTKeyTypeAtom.getKeySignature()

Get a KeySignature object.

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTMeasure

class music21.romanText.RTMeasure(src=u'')

In RomanText, measures are given one per line and always start with ‘m’.

For instance:

m4 i b3 v b4 VI m5 b2 g: IV b4 V m6 i m7 D: V

Measure ranges can be used and copied, such as:

m8-m9=m4-m5

RTMeasure objects can also define variant readings for a measure:

m1 ii m1var1 ii b2 ii6 b3 IV

Variants are not part of the tag, but are read into an attribute.

Endings are indicated by a single letter after the measure number, such as “a” for first ending.

>>> rtm = romanText.RTMeasure('m15a V6 b1.5 V6/5 b2 I b3 viio6')
>>> rtm.data
'V6 b1.5 V6/5 b2 I b3 viio6'
>>> rtm.number
[15]
>>> rtm.repeatLetter
['a']

RTMeasure bases

RTMeasure methods

RTMeasure.getCopyTarget()

If this measure defines a copy operation, return two lists defining the measures to copy; the second list has the repeat data.

>>> rtm = romanText.RTMeasure('m35-36 = m29-30')
>>> rtm.number
[35, 36]
>>> rtm.getCopyTarget()
([29, 30], ['', ''])
>>> rtm = romanText.RTMeasure('m4 = m1')
>>> rtm.number
[4]
>>> rtm.getCopyTarget()
([1], [''])
RTMeasure.isMeasure()

Methods inherited from RTToken:

RTNoChord

class music21.romanText.RTNoChord(src=u'', container=None)

An RTAtom subclass that defines absence of a chord. Also contains a reference to the container.

>>> chordNC = romanText.RTNoChord('NC')
>>> chordNC
<RTNoChord 'NC'>

RTNoChord bases

RTNoChord methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTOpenParens

class music21.romanText.RTOpenParens(src=u'(', container=None)

RTOpenParens bases

RTOpenParens methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTOptionalKeyClose

class music21.romanText.RTOptionalKeyClose(src=u'', container=None)

RTOptionalKeyClose bases

RTOptionalKeyClose methods

RTOptionalKeyClose.getKey()

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTOptionalKeyOpen

class music21.romanText.RTOptionalKeyOpen(src=u'', container=None)

RTOptionalKeyOpen bases

RTOptionalKeyOpen methods

RTOptionalKeyOpen.getKey()

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTPhraseBoundary

class music21.romanText.RTPhraseBoundary(src=u'||', container=None)

RTPhraseBoundary bases

RTPhraseBoundary methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTPhraseMarker

class music21.romanText.RTPhraseMarker(src=u'', container=None)

RTPhraseMarker bases

RTPhraseMarker methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTRepeat

class music21.romanText.RTRepeat(src=u'', container=None)

RTRepeat bases

RTRepeat methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTRepeatStart

class music21.romanText.RTRepeatStart(src=u'||:', container=None)

RTRepeatStart bases

RTRepeatStart methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTRepeatStop

class music21.romanText.RTRepeatStop(src=u':||', container=None)

RTRepeatStop bases

RTRepeatStop methods

Methods inherited from RTAtom:

Methods inherited from RTToken:

RTTagged

class music21.romanText.RTTagged(src=u'')

In romanText, some data elements are tags, that is a tag name, a colon, optional whitespace, and data. In non-RTTagged elements, there is just data.

All tagged tokens are subclasses of this class. Examples are:

Title: Die Jahrzeiten Composer: Fanny Mendelssohn
>>> rttag = romanText.RTTagged('Title: Die Jahrzeiten')
>>> rttag.tag
'Title'
>>> rttag.data
'Die Jahrzeiten'
>>> rttag.isTitle()
True
>>> rttag.isComposer()
False

RTTagged bases

RTTagged methods

RTTagged.isAnalyst()

True if tag represents a analyst, otherwise False.

>>> tag = romanText.RTTagged('Analyst: This is an analyst.')
>>> tag.isAnalyst()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isAnalyst()
False
RTTagged.isComposer()

True is the tag represents a composer.

>>> rth = romanText.RTTagged('Composer: Claudio Monteverdi')
>>> rth.isComposer()
True
>>> rth.isTitle()
False
>>> rth.isWork()
False
>>> rth.data 
'Claudio Monteverdi'
RTTagged.isForm()

True if tag represents a form, otherwise False.

>>> tag = romanText.RTTagged('Form: This is a form.')
>>> tag.isForm()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isForm()
False
RTTagged.isKeySignature()

True if tag represents a key signature, otherwise False.

>>> tag = romanText.RTTagged('KeySignature: This is a key signature.')
>>> tag.isKeySignature()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isKeySignature()
False

KeySignatures are a type of tagged data found outside of measures, such as “Key Signature: Bb,” meaning one flat.

Note: this is not the same as a key definition found inside of a Measure. These are represented by RTKey objects, defined below, and are not RTTagged objects, but RTAtom subclasses.

RTTagged.isMovement()

True if tag represents a movement, otherwise False.

>>> tag = romanText.RTTagged('Movement: This is a movement.')
>>> tag.isMovement()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isMovement()
False
RTTagged.isNote()

True if tag represents a note, otherwise False.

>>> tag = romanText.RTTagged('Note: This is a note.')
>>> tag.isNote()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isNote()
False
RTTagged.isPedal()

True if tag represents a pedal, otherwise False.

>>> tag = romanText.RTTagged('Pedal: This is a pedal.')
>>> tag.isPedal()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isPedal()
False
RTTagged.isPiece()

True if tag represents a piece, otherwise False.

>>> tag = romanText.RTTagged('Piece: This is a piece.')
>>> tag.isPiece()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isPiece()
False
RTTagged.isProofreader()

True if tag represents a proofreader, otherwise False.

>>> tag = romanText.RTTagged('Proofreader: This is a proofreader.')
>>> tag.isProofreader()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isProofreader()
False
RTTagged.isTimeSignature()

True if tag represents a time signature, otherwise False.

>>> tag = romanText.RTTagged('TimeSignature: This is a time signature.')
>>> tag.isTimeSignature()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isTimeSignature()
False

TimeSignature header data can be found intermingled with measures.

RTTagged.isTitle()

True if tag represents a title, otherwise False.

>>> tag = romanText.RTTagged('Title: This is a title.')
>>> tag.isTitle()
True
>>> tag = romanText.RTTagged('Nothing: Nothing at all.')
>>> tag.isTitle()
False
RTTagged.isWork()

True if tag represents a work, otherwise False.

The “work” is not defined as a header tag, but is used to represent all tags, often placed after Composer, for the work or pieces designation.

>>> rth = romanText.RTTagged('Madrigal: 4.12')
>>> rth.isTitle()
False
>>> rth.isWork()
True
>>> rth.tag
'Madrigal'
>>> rth.data 
'4.12'

Methods inherited from RTToken:

RTToken

class music21.romanText.RTToken(src=u'')

Stores each linear, logical entity of a RomanText.

A multi-pass parsing procedure is likely necessary, as RomanText permits variety of groupings and markings.

>>> rtt = romanText.RTToken('||:')
>>> rtt
<RTToken '||:'>

RTToken methods

RTToken.isAnalyst()
RTToken.isAtom()

Atoms are any untagged data; generally only found inside of a measure definition.

RTToken.isComposer()
RTToken.isForm()

Occasionally found in header.

RTToken.isKeySignature()
RTToken.isMeasure()
RTToken.isMovement()
RTToken.isNote()
RTToken.isPedal()
RTToken.isPiece()
RTToken.isProofreader()
RTToken.isTimeSignature()
RTToken.isTitle()
RTToken.isWork()