Previous topic

music21.braille.examples

Next topic

music21.braille.text

Table Of Contents

Table Of Contents

This Page

music21.braille.segment

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.

Functions

music21.braille.segment.addGroupingAttributes(allSegments, **partKeywords)

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.

music21.braille.segment.addSegmentAttributes(allSegments, **partKeywords)

Modifies the attributes of a BrailleSegment by passing partKeywords as an argument.

music21.braille.segment.compareNoteGroupings(noteGroupingA, noteGroupingB)

Takes in two note groupings, noteGroupingA and noteGroupingB. Returns True if both groupings have identical contents. False otherwise.

music21.braille.segment.extractBrailleElements(music21Measure)

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("2/4 c16 c c c d d d d")
>>> 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)
<music21.meter.TimeSignature 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>
music21.braille.segment.findSegments(music21Part, **partKeywords)

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 = braille.segment.findSegments(example, segmentBreaks = [(8, 3.0)])
>>> allSegments[0]
---begin segment---
<music21.braille.segment BrailleSegment>
Measure 0, Signature Grouping 1:
<music21.key.KeySignature of 3 flats>
<music21.meter.TimeSignature 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---
music21.braille.segment.fixArticulations(allSegments)

Goes through each BrailleSegment and modifies the list of articulations of a Note if appropriate. In particular, two rules are applied:

  • Doubling rule => If four or more of the same Articulation are found in a row, the first instance of the articulation is doubled and the rest are omitted.
  • Staccato, Tenuto rule => “If two repeated notes appear to be tied, but either is marked staccato or tenuto, they are treated as slurred instead of tied.” (BMTM, 112)
music21.braille.segment.getRawSegments(music21Part, segmentBreaks=[])

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("3/4 c4 c c e e e g g g c'2.")
>>> 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 3/4>
    {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:
<music21.meter.TimeSignature 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:
<music21.meter.TimeSignature 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---
music21.braille.segment.prepareBeamedNotes(music21Measure)

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("2/4 c16 c c c d d d d")
>>> 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
music21.braille.segment.prepareSlurredNotes(music21Part, slurLongPhraseWithBrackets=True, showShortSlursAndTiesTogether=False, showLongSlursAndTiesTogether=False)

Takes in a Part and three keywords:

  • slurLongPhraseWithBrackets
  • showShortSlursAndTiesTogether
  • showLongSlursAndTiesTogether

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("3/4 c4 d e")
>>> 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("3/4 c8 d e f g a")
>>> 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>
music21.braille.segment.setAffinityCode(music21Object)

Takes in a Music21Object, and does two things:

  • Modifies the classSortOrder attribute of the object to fit the slightly modified ordering of objects in braille music.
  • Adds an affinity code to the object. This code indicates which surrounding objects the object should be grouped with.

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.

>>> n1 = note.Note("D5")
>>> braille.segment.setAffinityCode(n1)
>>> n1.affinityCode
9
>>> n1.classSortOrder
10
>>> c1 = clef.TrebleClef()
>>> braille.segment.setAffinityCode(c1)
>>> c1.affinityCode
9
>>> c1.classSortOrder
7
music21.braille.segment.splitMeasure(music21Measure, value=2, beatDivisionOffset=0, useTimeSignature=None)

Takes a Measure, divides it in two parts, and returns a Part containing the two halves. The parameters are as follows:

  • value => the number of partitions to split a time signature into. The first half will contain all elements found within the offsets of the first partition, while the last half will contain all other elements.
  • beatDivisionOffset => Adjusts the end offset of the first partition by a certain amount of beats to the left.
  • useTimeSignature => In the event that the Measure comes from the middle of a Part and thus does not define an explicit TimeSignature. If not provided, a TimeSignature is retrieved by using bestTimeSignature().
music21.braille.segment.splitNoteGrouping(noteGrouping, value=2, beatDivisionOffset=0)

Almost identical to splitMeasure(), but functions on a BrailleElementGrouping instead.

BrailleElementGrouping

class music21.braille.segment.BrailleElementGrouping

BrailleElementGrouping instance variables

BrailleElementGrouping.descendingChords

True if a Chord should be spelled from highest to lowest pitch in braille, False if the opposite is the case.

BrailleElementGrouping.keySignature

The last KeySignature preceding the grouping.

BrailleElementGrouping.numRepeats

The number of times this grouping is repeated.

BrailleElementGrouping.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.

BrailleElementGrouping.timeSignature

The last TimeSignature preceding the grouping.

BrailleElementGrouping.upperFirstInNoteFingering

No documentation.

BrailleElementGrouping.withHyphen

If True, this grouping will end with a music hyphen.

BrailleGrandSegment

class music21.braille.segment.BrailleGrandSegment(rightSegment, leftSegment)

BrailleGrandSegment methods

BrailleGrandSegment.combineGroupingKeys(rightSegment, leftSegment)
BrailleGrandSegment.extractHeading(brailleKeyboard)
BrailleGrandSegment.extractLongExpressionGrouping(brailleKeyboard)
BrailleGrandSegment.extractNoteGrouping(brailleKeyboard)
BrailleGrandSegment.extractSignatureGrouping(brailleKeyboard)
BrailleGrandSegment.extractTempoTextGrouping(brailleKeyboard)
BrailleGrandSegment.transcribe()

BrailleSegment

class music21.braille.segment.BrailleSegment

BrailleSegment methods

BrailleSegment.addDummyRests(brailleText)
BrailleSegment.addMeasureNumber(brailleText)

Takes in a braille text instance and adds a measure number

BrailleSegment.consolidate()
BrailleSegment.extractHeading(brailleText)

Extract a KeySignature, TempoText and MetronomeMark and add an appropriate braille heading to the brailleText object inputted.

BrailleSegment.extractInaccordGrouping(brailleText)
BrailleSegment.extractLongExpressionGrouping(brailleText)
BrailleSegment.extractNoteGrouping(brailleText)
BrailleSegment.extractSignatureGrouping(brailleText)
BrailleSegment.extractTempoTextGrouping(brailleText)
BrailleSegment.transcribe()

Heading (if applicable) Measure Number Rest of Note Groupings

BrailleSegment instance variables

BrailleSegment.cancelOutgoingKeySig

If True, the previous key signature should be cancelled immediately before a new key signature is encountered.

BrailleSegment.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.

BrailleSegment.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.

BrailleSegment.maxLineLength

The maximum amount of braille characters that should be present in a line. The standard is 40 characters.

BrailleSegment.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.

BrailleSegment.showFirstMeasureNumber

If True, then a measure number is shown following the heading (if applicable) and preceding the music.

BrailleSegment.showHand

If set to “right” or “left”, shows the corresponding hand sign at the beginning of the first line.

BrailleSegment.showHeading

If True, then a braille heading is displayed. See transcribeHeading() for more details on headings.

BrailleSegment.suppressOctaveMarks

If True, then all octave marks are suppressed. Designed for test purposes, as octave marks were not presented until Chapter 7 of BMTM.