music21.tinyNotation¶
tinyNotation is a simple way of specifying single line melodies that uses a notation somewhat similar to Lilypond but with WAY fewer options. It was originally developed to notate trecento (medieval Italian) music, but it is pretty useful for a lot of short examples, so we have made it a generally supported music21 format.
N.B.: TinyNotation is not meant to expand to cover every single case. Instead it is meant to be subclassable to extend to the cases your project needs. See for instance the harmony examples in HarmonyStream and HarmonyNote or the Trecento specific examples in trecento/cadencebook.py
Here are the most important rules:
Note names are: a,b,c,d,e,f,g and r for rest
Flats, sharps, and naturals are notated as #,- (not b), and (if needed) n. If the accidental is above the staff (i.e., editorial), enclose it in parentheses: (#), etc. Make sure that flats in the key signatures are explicitly specified.
Note octaves are specified as follows:
CC to BB = from C below bass clef to second-line B in bass clef C to B = from bass clef C to B below middle C. c to b = from middle C to the middle of treble clef c' to b' = from C in treble clef to B above treble clef
Octaves below and above these are specified by further doublings of letter (CCC) or apostrophes (c’‘) – this is one of the note name standards found in many music theory books.
After the note name, a number may be placed indicating the note length: 1 = whole note, 2 = half, 4 = quarter, 8 = eighth, 16 = sixteenth. etc. If the number is omitted then it is assumed to be the same as the previous note. I.e., c8 B c d is a string of eighth notes.
After the number, a ~ can be placed to show a tie to the next note. A ”.” indicates a dotted note. (If you are entering data via Excel or other spreadsheet, be sure that “capitalize the first letter of sentences” is turned off under “Tools->AutoCorrect,” otherwise the next letter will be capitalized, and the octave will be screwed up.)
For triplets use this notation: trip{c4 d8} indicating that these two notes both have “3s” over them. For 4 in the place of 3, use quad{c16 d e8}. No other tuplets are supported.
Again, see the HarmonyStream
(below) and
trecento.cadencebook examples
to see how to make TinyNotation useful for your own needs.
(Currently, final notes with fermatas (or any very long final note), take 0 for the note length. But expect this to disappear from the TinyNotation specification soon, as it’s too Trecento specific.)
an alpha complete rewrite of tinyNotation.
tinyNotation was one of the first modules of music21 and one of my first attempts to program in Python. and it shows.
this is what the module should have been... from mistakes learned and insights from ABC etc. parsing.
keeping both until this becomes stable.
>>> tnc = tinyNotation.Converter("3/4 E4 r f# g=lastG trip{b-8 a g} c4~ c") >>> stream1 = tnc.parse().stream >>> stream1.show('text') {0.0} <music21.stream.Measure 1 offset=0.0> {0.0} <music21.clef.TrebleClef> {0.0} <music21.meter.TimeSignature 3/4> {0.0} <music21.note.Note E> {1.0} <music21.note.Rest rest> {2.0} <music21.note.Note F#> {3.0} <music21.stream.Measure 2 offset=3.0> {0.0} <music21.note.Note G> {1.0} <music21.note.Note B-> {1.3333} <music21.note.Note A> {1.6667} <music21.note.Note G> {2.0} <music21.note.Note C> {6.0} <music21.stream.Measure 3 offset=6.0> {0.0} <music21.note.Note C> {1.0} <music21.bar.Barline style=final>>>> stream1.flat.getElementById("lastG").step 'G' >>> stream1.flat.notesAndRests[1].isRest True >>> stream1.flat.notesAndRests[0].octave 3 >>> stream1.flat.notes[-2].tie.type 'start' >>> stream1.flat.notes[-1].tie.type 'stop'Changing time signatures are supported:
>>> s1 = converter.parse('tinynotation: 3/4 C4 D E 2/4 F G A B 1/4 c') >>> s1.show('t') {0.0} <music21.stream.Measure 1 offset=0.0> {0.0} <music21.clef.BassClef> {0.0} <music21.meter.TimeSignature 3/4> {0.0} <music21.note.Note C> {1.0} <music21.note.Note D> {2.0} <music21.note.Note E> {3.0} <music21.stream.Measure 2 offset=3.0> {0.0} <music21.meter.TimeSignature 2/4> {0.0} <music21.note.Note F> {1.0} <music21.note.Note G> {5.0} <music21.stream.Measure 3 offset=5.0> {0.0} <music21.note.Note A> {1.0} <music21.note.Note B> {7.0} <music21.stream.Measure 4 offset=7.0> {0.0} <music21.meter.TimeSignature 1/4> {0.0} <music21.note.Note C> {1.0} <music21.bar.Barline style=final>
Converter¶
-
class
music21.tinyNotation.
Converter
(stringRep='', **keywords)¶ Main conversion object for TinyNotation.
Accepts one keyword: makeNotation=False to get “classic” TinyNotation formats.
Converter
methods
-
Converter.
parse
()¶ splitPreTokens, setupRegularExpressions, then run through each preToken, and run postParse.
-
Converter.
parseOne
(i, t)¶ parse a single token at position i, with text t.
Checks for state changes, modifiers, tokens, and end-state brackets.
-
Converter.
postParse
()¶ Call postParse calls on .stream, currently just .makeMeasures.
-
Converter.
setupRegularExpressions
()¶ Regular expressions get compiled for faster usage.
-
Converter.
splitPreTokens
()¶ splits the string into textual tokens.
Right now just splits on spaces, but might be smarter to ignore spaces in quotes, etc. later.
IdModifier¶
-
class
music21.tinyNotation.
IdModifier
(modifierData, modifierString, parent)¶ sets the .id of the m21Obj, called with =
IdModifier
bases
IdModifier
methods
-
IdModifier.
postParse
(m21Obj)¶
Methods inherited from Modifier
:
LyricModifier¶
-
class
music21.tinyNotation.
LyricModifier
(modifierData, modifierString, parent)¶ sets the .lyric of the m21Obj, called with _
LyricModifier
bases
LyricModifier
methods
-
LyricModifier.
postParse
(m21Obj)¶
Methods inherited from Modifier
:
Modifier¶
-
class
music21.tinyNotation.
Modifier
(modifierData, modifierString, parent)¶ a modifier is something that changes the current token, like setting the Id or Lyric.
Modifier
methods
-
Modifier.
postParse
(m21Obj)¶ called after the tokenString has been truend into an m21Obj. m21Obj may be None
-
Modifier.
preParse
(tokenString)¶ called before the tokenString has been turned into an object
NoteOrRestToken¶
-
class
music21.tinyNotation.
NoteOrRestToken
(token='')¶ represents a Note or Rest. Chords are represented by Note objects
NoteOrRestToken
bases
NoteOrRestToken
methods
-
NoteOrRestToken.
applyDuration
(n, t, parent)¶ takes the information in the string t and creates a Duration object for the note or rest n.
-
NoteOrRestToken.
dots
(n, search, pm, t, parent)¶ adds the appropriate number of dots to the right place.
Subclassed in TrecentoNotation where two dots has a different meaning.
-
NoteOrRestToken.
durationType
(n, search, pm, t, parent)¶ The result of a successful search for a duration type: puts a Duration in the right place.
Methods inherited from Token
:
NoteToken¶
-
class
music21.tinyNotation.
NoteToken
(token='')¶ A NoteToken represents a single Note with pitch
NoteToken
bases
NoteToken
methods
-
NoteToken.
editorialAccidental
(n, search, pm, t)¶ indicates that the accidental is in parentheses, so set it up to be stored in ficta.
-
NoteToken.
flats
(n, search, pm, t)¶ called when one or more flats have been found.
-
NoteToken.
getPitch
(n, t)¶
-
NoteToken.
highOctave
(n, search, pm, t)¶ Called when a note of octave 4 or higher is encountered.
-
NoteToken.
lowOctave
(n, search, pm, t)¶ Called when a note of octave 3 or below is encountered.
-
NoteToken.
natural
(n, search, pm, t)¶ called when an explicit natural has been found. All pitches are natural without being specified, so not needed.
-
NoteToken.
parse
(parent)¶ Extract the pitch from the note.
-
NoteToken.
sharps
(n, search, pm, t)¶ called when one or more sharps have been found.
Methods inherited from NoteOrRestToken
:
QuadrupletState¶
-
class
music21.tinyNotation.
QuadrupletState
(parent, stateInfo)¶ a 4:3 tuplet
QuadrupletState
bases
QuadrupletState
methods
Methods inherited from TupletState
:
Methods inherited from State
:
RestToken¶
-
class
music21.tinyNotation.
RestToken
(token='')¶ A token starting with ‘r’, representing a rest.
RestToken
bases
RestToken
methods
-
RestToken.
parse
(parent)¶
Methods inherited from NoteOrRestToken
:
StarModifier¶
-
class
music21.tinyNotation.
StarModifier
(modifierData, modifierString, parent)¶ does nothing, but easily subclassed. Uses ... to make it happen
StarModifier
bases
StarModifier
methods
Methods inherited from Modifier
:
State¶
-
class
music21.tinyNotation.
State
(parent, stateInfo)¶ State tokens apply something to every note found within it.
State
methods
-
State.
affectTokenAfterParse
(m21Obj)¶ called to modify the tokenObj after parsing
tokenObj may be None if another state has deleted it.
-
State.
affectTokenAfterParseBeforeModifiers
(m21Obj)¶ called after the object has been acquired but before modifiers have been applied.
-
State.
affectTokenBeforeParse
(tokenStr)¶ called to modify the string of a token.
-
State.
end
()¶ called just after removing state
-
State.
start
()¶ called when the state is initiated
TieState¶
-
class
music21.tinyNotation.
TieState
(parent, stateInfo)¶ A TieState is an autoexpiring state that applies a tie start to this note and a tie stop to the next note.
TieState
bases
TieState
methods
-
TieState.
end
()¶ end the tie state by applying tie ties to the appropriate notes
Methods inherited from State
:
TimeSignatureToken¶
-
class
music21.tinyNotation.
TimeSignatureToken
(token='')¶ Represents a single time signature, like 1/4
TimeSignatureToken
bases
TimeSignatureToken
methods
-
TimeSignatureToken.
parse
(parent)¶
Token¶
-
class
music21.tinyNotation.
Token
(token='')¶ A single token made from the parser.
Call .parse(parent) to make it work.
Token
methods
-
Token.
parse
(parent)¶ do NOT store parent – probably too slow
TripletState¶
-
class
music21.tinyNotation.
TripletState
(parent, stateInfo)¶ a 3:2 tuplet
TripletState
bases
TripletState
methods
Methods inherited from TupletState
:
Methods inherited from State
:
TupletState¶
-
class
music21.tinyNotation.
TupletState
(parent, stateInfo)¶ a tuplet state applies tuplets to notes while parsing and sets ‘start’ and ‘stop’ on the first and last note when end is called.
TupletState
bases
TupletState
methods
-
TupletState.
affectTokenAfterParse
(n)¶ puts a tuplet on the note
-
TupletState.
end
()¶ end a tuplet by putting start on the first note and stop on the last.
Methods inherited from State
: