Inner classes and methods for transcribing musical segments into braille.
This module was made in consultation with the manual “Introduction to Braille Music Transcription, Second Edition” by Mary Turner De Garmo, 2005. It is available from the Library of Congress here, and will henceforth be referred to as BMTM.
Modifies the attributes of all BrailleElementGrouping instances in a list of BrailleSegment instances. The necessary information is retrieved both by passing in partKeywords as an argument and by taking into account the linear progression of the groupings and segments.
Modifies the attributes of a BrailleSegment by passing partKeywords as an argument.
Takes in two note groupings, noteGroupingA and noteGroupingB. Returns True if both groupings have identical contents. False otherwise.
Takes in a Measure and returns a BrailleElementGrouping of correctly ordered Music21Object instances which can be directly transcribed to braille.
>>> from music21.braille import segment
>>> from music21 import spanner
>>> from music21 import tinyNotation
>>> tn = tinyNotation.TinyNotationStream("c16 c c c d d d d", "2/4")
>>> tn = tn.makeNotation(cautionaryNotImmediateRepeat=False)
>>> measure = tn[0]
>>> measure.append(spanner.Slur(measure.notes[0],measure.notes[-1]))
>>> measure.show("text")
{0.0} <music21.clef.TrebleClef>
{0.0} <music21.meter.TimeSignature 2/4>
{0.0} <music21.note.Note C>
{0.25} <music21.note.Note C>
{0.5} <music21.note.Note C>
{0.75} <music21.note.Note C>
{1.0} <music21.note.Note D>
{1.25} <music21.note.Note D>
{1.5} <music21.note.Note D>
{1.75} <music21.note.Note D>
{2.0} <music21.spanner.Slur <music21.note.Note C><music21.note.Note D>>
{2.0} <music21.bar.Barline style=final>
Spanners are dealt with in prepareSlurredNotes(), so they are not returned by this method, as seen below.
>>> segment.extractBrailleElements(measure)
2/4
<music21.clef.TrebleClef>
<music21.note.Note C>
<music21.note.Note C>
<music21.note.Note C>
<music21.note.Note C>
<music21.note.Note D>
<music21.note.Note D>
<music21.note.Note D>
<music21.note.Note D>
<music21.bar.Barline style=final>
Takes in a Part or TinyNotationStream and a list of partKeywords. Returns a list of BrailleSegment instances.
Five methods get called in the generation of segments:
>>> from music21.braille import test
>>> example = test.example11_2()
>>> allSegments = findSegments(example, segmentBreaks = [(8, 3.0)])
>>> allSegments[0]
---begin segment---
<music21.braille.segment BrailleSegment>
Measure 0, Signature Grouping 1:
sharps -3, mode None
4/4
===
Measure 0, Note Grouping 1:
<music21.clef.TrebleClef>
<music21.note.Note B->
===
Measure 1, Note Grouping 1:
<music21.note.Note G>
<music21.note.Note E->
<music21.note.Note D>
<music21.note.Note E->
===
Measure 2, Note Grouping 1:
<music21.note.Note G>
<music21.note.Note F>
<music21.note.Note E->
===
Measure 3, Note Grouping 1:
<music21.note.Note A->
<music21.note.Note G>
<music21.note.Note C>
<music21.note.Note C>
===
Measure 4, Note Grouping 1:
<music21.note.Note B->
<music21.note.Note B->
===
Measure 5, Note Grouping 1:
<music21.note.Note E->
<music21.note.Note B->
<music21.note.Note A->
<music21.note.Note G>
===
Measure 6, Note Grouping 1:
<music21.note.Note G>
<music21.note.Note F>
<music21.note.Note C>
===
Measure 7, Note Grouping 1:
<music21.note.Note C>
<music21.note.Note F>
<music21.note.Note A->
<music21.note.Note D>
===
Measure 8, Note Grouping 1:
<music21.note.Note E->
** Music Hyphen **
===
---end segment---
>>> allSegments[1]
---begin segment---
<music21.braille.segment BrailleSegment>
Measure 8, Note Grouping 1:
<music21.note.Note G>
===
Measure 9, Note Grouping 1:
<music21.note.Note G>
<music21.note.Note F>
<music21.note.Note F>
<music21.note.Note F>
===
Measure 10, Note Grouping 1:
<music21.note.Note A->
<music21.note.Note G>
<music21.note.Note B->
===
Measure 11, Note Grouping 1:
<music21.note.Note B->
<music21.note.Note A>
<music21.note.Note A>
<music21.note.Note C>
===
Measure 12, Note Grouping 1:
<music21.note.Note B->
<music21.note.Note B->
===
Measure 13, Note Grouping 1:
<music21.note.Note E->
<music21.note.Note B->
<music21.note.Note A->
<music21.note.Note G>
===
Measure 14, Note Grouping 1:
<music21.note.Note G>
<music21.note.Note F>
<music21.note.Note C>
===
Measure 15, Note Grouping 1:
<music21.note.Note C>
<music21.note.Rest rest>
<music21.note.Note F>
<music21.note.Rest rest>
===
Measure 16, Note Grouping 1:
<music21.note.Note A->
<music21.note.Note D>
===
Measure 17, Note Grouping 1:
<music21.note.Note E->
<music21.bar.Barline style=final>
===
---end segment---
Goes through each BrailleSegment and modifies the list of articulations of a Note if appropriate. In particular, two rules are applied:
Takes in a Part and a segmentBreaks list which contains (measureNumber, offsetStart) tuples. These tuples determine how the Part is divided up into segments (i.e. instances of BrailleSegment). This method assumes that the Part is already divided up into measures (see Measure). An acceptable input is shown below.
Two methods are called on each measure during the creation of segments:
>>> from music21 import tinyNotation
>>> tn = tinyNotation.TinyNotationStream("c4 c c e e e g g g c'2.","3/4")
>>> tn = tn.makeNotation(cautionaryNotImmediateRepeat=False)
>>> tn.show("text")
{0.0} <music21.stream.Measure 1 offset=0.0>
{0.0} <music21.meter.TimeSignature 3/4>
{0.0} <music21.clef.TrebleClef>
{0.0} <music21.note.Note C>
{1.0} <music21.note.Note C>
{2.0} <music21.note.Note C>
{3.0} <music21.stream.Measure 2 offset=3.0>
{0.0} <music21.note.Note E>
{1.0} <music21.note.Note E>
{2.0} <music21.note.Note E>
{6.0} <music21.stream.Measure 3 offset=6.0>
{0.0} <music21.note.Note G>
{1.0} <music21.note.Note G>
{2.0} <music21.note.Note G>
{9.0} <music21.stream.Measure 4 offset=9.0>
{0.0} <music21.note.Note C>
{3.0} <music21.bar.Barline style=final>
By default, there is no break anywhere within the Part, and a segmentList of size 1 is returned.
>>> import copy
>>> from music21.braille import segment
>>> tnA = copy.deepcopy(tn)
>>> segment.getRawSegments(tnA)[0]
---begin segment---
<music21.braille.segment BrailleSegment>
Measure 1, Signature Grouping 1:
3/4
===
Measure 1, Note Grouping 1:
<music21.clef.TrebleClef>
<music21.note.Note C>
<music21.note.Note C>
<music21.note.Note C>
===
Measure 2, Note Grouping 1:
<music21.note.Note E>
<music21.note.Note E>
<music21.note.Note E>
===
Measure 3, Note Grouping 1:
<music21.note.Note G>
<music21.note.Note G>
<music21.note.Note G>
===
Measure 4, Note Grouping 1:
<music21.note.Note C>
<music21.bar.Barline style=final>
===
---end segment---
Now, a segment break occurs at measure 2, offset 1.0 within that measure. The two segments are shown below.
>>> tnB = copy.deepcopy(tn)
>>> allSegments = segment.getRawSegments(tnB, segmentBreaks=[(2,1.0)])
>>> allSegments[0]
---begin segment---
<music21.braille.segment BrailleSegment>
Measure 1, Signature Grouping 1:
3/4
===
Measure 1, Note Grouping 1:
<music21.clef.TrebleClef>
<music21.note.Note C>
<music21.note.Note C>
<music21.note.Note C>
===
Measure 2, Note Grouping 1:
<music21.note.Note E>
===
---end segment---
>>> allSegments[1]
---begin segment---
<music21.braille.segment BrailleSegment>
Measure 2, Note Grouping 1:
<music21.note.Note E>
<music21.note.Note E>
===
Measure 3, Note Grouping 1:
<music21.note.Note G>
<music21.note.Note G>
<music21.note.Note G>
===
Measure 4, Note Grouping 1:
<music21.note.Note C>
<music21.bar.Barline style=final>
===
---end segment---
Takes in a Measure and labels beamed notes of smaller value than an 8th with beamStart and beamContinue keywords in accordance with beaming rules in braille music.
A more in-depth explanation of beaming in braille can be found in Chapter 15 of Introduction to Braille Music Transcription, Second Edition, by Mary Turner De Garmo.
>>> from music21.braille import segment
>>> from music21 import tinyNotation
>>> tn = tinyNotation.TinyNotationStream("c16 c c c d d d d", "2/4")
>>> tn = tn.makeNotation(cautionaryNotImmediateRepeat=False)
>>> tn.show("text")
{0.0} <music21.stream.Measure 1 offset=0.0>
{0.0} <music21.clef.TrebleClef>
{0.0} <music21.meter.TimeSignature 2/4>
{0.0} <music21.note.Note C>
{0.25} <music21.note.Note C>
{0.5} <music21.note.Note C>
{0.75} <music21.note.Note C>
{1.0} <music21.note.Note D>
{1.25} <music21.note.Note D>
{1.5} <music21.note.Note D>
{1.75} <music21.note.Note D>
{2.0} <music21.bar.Barline style=final>
>>> measure = tn[0]
>>> segment.prepareBeamedNotes(measure)
>>> measure.notes[0].beamStart
True
>>> measure.notes[1].beamContinue
True
>>> measure.notes[2].beamContinue
True
>>> measure.notes[3].beamContinue
True
Takes in a Part and three keywords:
For any slurs present in the Part, the appropriate notes are labeled with attributes indicating where to put the symbols that represent slurring in braille. For purposes of slurring in braille, there is a distinction between short and long phrases. In a short phrase, a slur covers up to four notes. A short slur symbol should follow each note except the last.
>>> import copy
>>> from music21.braille import segment
>>> from music21 import spanner
>>> from music21 import tinyNotation
>>> short = tinyNotation.TinyNotationStream("c4 d e","3/4")
>>> s1 = spanner.Slur(short.notes[0],short.notes[-1])
>>> short.append(s1)
>>> short.show("text")
{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.spanner.Slur <music21.note.Note C><music21.note.Note E>>
>>> shortA = copy.deepcopy(short)
>>> segment.prepareSlurredNotes(shortA)
>>> shortA.notes[0].shortSlur
True
>>> shortA.notes[1].shortSlur
True
In a long phrase, a slur covers more than four notes. There are two options for slurring long phrases. The first is by using the bracket slur. By default, slurLongPhraseWithBrackets is True. The opening bracket sign is put before the first note, and the closing bracket sign is put before the last note.
>>> long = tinyNotation.TinyNotationStream("c8 d e f g a","3/4")
>>> s2 = spanner.Slur(long.notes[0],long.notes[-1])
>>> long.append(s2)
>>> long.show("text")
{0.0} <music21.meter.TimeSignature 3/4>
{0.0} <music21.note.Note C>
{0.5} <music21.note.Note D>
{1.0} <music21.note.Note E>
{1.5} <music21.note.Note F>
{2.0} <music21.note.Note G>
{2.5} <music21.note.Note A>
{3.0} <music21.spanner.Slur <music21.note.Note C><music21.note.Note A>>
>>> longA = copy.deepcopy(long)
>>> segment.prepareSlurredNotes(longA)
>>> longA.notes[0].beginLongBracketSlur
True
>>> longA.notes[-1].endLongBracketSlur
True
The other way is by using the double slur, setting slurLongPhraseWithBrackets to False. The opening sign of the double slur is put after the first note (i.e. before the second note) and the closing sign is put before the last note (i.e. before the second to last note).
>>> longB = copy.deepcopy(long)
>>> segment.prepareSlurredNotes(longB, slurLongPhraseWithBrackets=False)
>>> longB.notes[1].beginLongDoubleSlur
True
>>> longB.notes[-2].endLongDoubleSlur
True
In the event that slurs and ties are shown together in print, the slur is redundant. Examples are shown for slurring a short phrase; the process is identical for slurring a long phrase.
Below, a tie has been added between the first two notes of the short phrase defined above. If showShortSlursAndTiesTogether is set to its default value of False, then the slur on either side of the phrase is reduced by the amount that ties are present, as shown below.
>>> from music21 import tie
>>> short.notes[0].tie = tie.Tie("start")
>>> shortB = copy.deepcopy(short)
>>> segment.prepareSlurredNotes(shortB)
>>> shortB.notes[0].shortSlur
Traceback (most recent call last):
AttributeError: 'Note' object has no attribute 'shortSlur'
>>> shortB.notes[0].tie
<music21.tie.Tie start>
>>> shortB.notes[1].shortSlur
True
If showShortSlursAndTiesTogether is set to True, then the slurs and ties are shown together (i.e. the note has both a shortSlur and a tie).
>>> shortC = copy.deepcopy(short)
>>> segment.prepareSlurredNotes(shortC, showShortSlursAndTiesTogether=True)
>>> shortC.notes[0].shortSlur
True
>>> shortC.notes[0].tie
<music21.tie.Tie start>
Takes in a Music21Object, and does two things:
A BrailleSegmentException is raised if an affinity code cannot be assigned to the object.
As seen in the following example, the affinity code of a Note and a TrebleClef are the same, because they should be grouped together. However, the classSortOrder indicates that the TrebleClef should come first in the braille.
>>> from music21.braille import segment
>>> from music21 import note
>>> from music21 import clef
>>> n1 = note.Note("D5")
>>> setAffinityCode(n1)
>>> n1.affinityCode
9
>>> n1.classSortOrder
10
>>> c1 = clef.TrebleClef()
>>> setAffinityCode(c1)
>>> c1.affinityCode
9
>>> c1.classSortOrder
7
Takes a Measure, divides it in two parts, and returns a Part containing the two halves. The parameters are as follows:
Almost identical to splitMeasure(), but functions on a BrailleElementGrouping instead.
Inherits from: list
Intended to be a list of objects which should be displayed without a space in braille.
>>> from music21.braille import segment
>>> from music21 import note
>>> bg = segment.BrailleElementGrouping()
>>> bg.append(note.Note("C4"))
>>> bg.append(note.Note("D4"))
>>> bg.append(note.Rest())
>>> bg.append(note.Note("F4"))
>>> bg
<music21.note.Note C>
<music21.note.Note D>
<music21.note.Rest rest>
<music21.note.Note F>
BrailleElementGrouping attributes
- numRepeats¶
The number of times this grouping is repeated.
- withHyphen¶
If True, this grouping will end with a music hyphen.
- keySignature¶
The last KeySignature preceding the grouping.
- showClefSigns¶
If true, clef signs are shown in braille. Representation of music in braille is not dependent upon clefs and staves, so the clef signs would be displayed for referential or historical purposes.
- timeSignature¶
The last TimeSignature preceding the grouping.
- descendingChords¶
True if a Chord should be spelled from highest to lowest pitch in braille, False if the opposite is the case.
Attributes without Documentation: upperFirstInNoteFingering
BrailleElementGrouping methods
Methods inherited from list: append(), count(), extend(), index(), insert(), pop(), remove(), reverse(), sort()
Inherits from: defaultdict, dict
A segment is “a group of measures occupying more than one braille line.” Music is divided into segments so as to “present the music to the reader in a meaningful manner and to give him convenient reference points to use in memorization” (BMTM, 71).
BrailleSegment attributes
- cancelOutgoingKeySig¶
If True, the previous key signature should be cancelled immediately before a new key signature is encountered.
- endHyphen¶
If True, then the last BrailleElementGrouping of this segment will be followed by a music hyphen. The last grouping is incomplete, because a segment break occured in the middle of a measure.
- dummyRestLength¶
For a given positive integer n, adds n “dummy rests” near the beginning of a segment. Designed for test purposes, as they are used to demonstrate measure division at the end of braille lines.
- measureNumberWithDot¶
If True, then the initial measure number of this segment should be followed by a dot. This segment is starting in the middle of a measure.
- showHeading¶
If True, then a braille heading is displayed. See transcribeHeading() for more details on headings.
- showFirstMeasureNumber¶
If True, then a measure number is shown following the heading (if applicable) and preceding the music.
- showHand¶
If set to “right” or “left”, shows the corresponding hand sign at the beginning of the first line.
- suppressOctaveMarks¶
If True, then all octave marks are suppressed. Designed for test purposes, as octave marks were not presented until Chapter 7 of BMTM.
- maxLineLength¶
The maximum amount of braille characters that should be present in a line. The standard is 40 characters.
Attributes inherited from defaultdict: default_factory
BrailleSegment methods
- addDummyRests(brailleText)¶
No documentation.
- addMeasureNumber(brailleText)¶
Takes in a braille text instance and adds a measure number
- consolidate()¶
- extractHeading(brailleText)¶
Extract a KeySignature, TempoText and MetronomeMark and add an appropriate braille heading to the brailleText object inputted.
>>> from music21.braille import segment >>> from music21 import key >>> from music21 import meter >>> from music21 import tempo
- extractInaccordGrouping(brailleText)¶
No documentation.
- extractLongExpressionGrouping(brailleText)¶
No documentation.
- extractNoteGrouping(brailleText)¶
No documentation.
- extractSignatureGrouping(brailleText)¶
No documentation.
- extractTempoTextGrouping(brailleText)¶
No documentation.
- transcribe()¶
Heading (if applicable) Measure Number Rest of Note Groupings
Methods inherited from defaultdict: copy()
Methods inherited from dict: clear(), fromkeys(), get(), has_key(), items(), iteritems(), iterkeys(), itervalues(), keys(), pop(), popitem(), setdefault(), update(), values(), viewitems(), viewkeys(), viewvalues()