
    rh                      % S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  \R&                  (       a  SSKJr  \R*                  r\R,                  r\R.                  r\
R0                  " S5      r0 rS\S'   / SQrS rS7S jrS rS8S jr S9S jr!S r"S:S jr#S r$S r%SSS. S;S jjr&S r'S9S<S  jjr(S=S! jr)S" r*S#S$.   S>S% jjr+S9S& jr,S' r-S( r.     S?S) jr/S@S* jr0S:S+ jr1S, r2SAS- jr3SBS. jr4S/ r5S8SCS0 jjr6SDSES1 jjr7 " S2 S3\Rp                  5      r9 " S4 S5\Rt                  5      r;\<S6:X  a  SSKr\Rz                  " \;5        gg)Fu\  
Basic tools for working with Braille in `music21`.  Most users will not need to
use these.  Simply call `.show('braille')` or `.show('braille.ascii')`

>>> soprano = corpus.parse('bwv66.6').parts[0]
>>> #_DOCS_SHOW soprano.show('braille.ascii')
>>> print(converter.toData(soprano, 'braille.ascii'))  # _DOCS_HIDE
                     %%%.C
    #J .DJ [W?<L$ ?W[<L? IJ\]<L[ WW]$ [W?<L?
      "[W?[ \]R<L Q]]@C ]G%F]<L<K

Normally this would open up in a new window.  But to store the data, use
`converter.toData(..., 'braille')`.  Here we show this in Unicode braille
(the default for format braille)

>>> data = converter.toData(soprano, 'braille')
>>> print(data)
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠩⠩⠩⠨⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠼⠚⠀⠨⠙⠚⠀⠪⠺⠹⠣⠇⠫⠀⠹⠺⠪⠣⠇⠹⠀⠊⠚⠳⠻⠣⠇⠪⠀⠺⠺⠻⠫⠀⠪⠺⠹⠣⠇⠹
    ⠀⠀⠐⠪⠺⠹⠪⠀⠳⠻⠗⠣⠇⠀⠟⠻⠻⠈⠉⠀⠻⠛⠩⠋⠻⠣⠇⠣⠅

Any :class:`~music21.base.Music21Object` which cannot be transcribed in
:mod:`~music21.braille.basic` returns a braille literary question mark
and outputs a warning to the console, rather than raising an exception.
This is so that a transcription of a :class:`~music21.stream.Stream` in
:class:`~music21.braille.translate` is completed as thoroughly as possible.
    )annotationsN)articulations)clef)duration)environment)exceptions21)expressions)interval)note)lookup)stringTools)tempozbasic.pyzdict[str, bool]
beamStatus)beginLongBracketSlurendLongBracketSlurbeginLongDoubleSlurendLongDoubleSlur	shortSlur	beamStartbeamContinuec                *    [         R                  U R                     nSU R                   SU 3/U R                  l        U$ ! [
         aE    [        R                  SU  S35        SU R                   S3/U R                  l        [        S   s $ f = f)u/  
Takes in a :class:`~music21.bar.Barline` and returns its representation
as a braille string in UTF-8 unicode.

.. note:: Only dashed, double barlines, and final barlines can be transcribed.

>>> from music21.braille.basic import barlineToBraille
>>> doubleBarline = bar.Barline('double')
>>> print(barlineToBraille(doubleBarline))
⠣⠅⠄
>>> finalBarline = bar.Barline('final')
>>> print(barlineToBraille(finalBarline))
⠣⠅

Heavy gives an "unusual barline" symbol

>>> heavyBarline = bar.Barline('heavy')
>>> print(barlineToBraille(heavyBarline))
⠇
zBarline  " cannot be transcribed to braille. Nonebasic_exception)	r   barlinestype	editorialbrailleEnglishKeyErrorenvironRuleswarnsymbols)music21BarlinebrailleBarlines     O/home/james-whalen/.local/lib/python3.13/site-packages/music21/braille/basic.pybarlineToBrailler'   T   s    **)<)<=~**+1^,<=3?  / *H^$44VWX5=n>Q>Q=RRW3X2Y  /())*s   A A ABBTc                   / U R                   l        [        U R                  5      nSnU(       a  UR	                  5         OSn/ nUS   n[
        R                  " UU R                  S9n[        UUS9nU[        S   :X  aJ  [        R                  SU  S35        U R                   R                  R                  U  S	35        [        S   $ UR                  U5        S
R                  UR                   R                  S/ 5      5      n	U R                   R                  R                  U SU	 35        [        S[!        U5      5       GH  n
X:   n [#        UUU R                   R                  5        [(        R*                  " Xk5      R,                  nUS:  a  US-
  S-  S-   nU
S:X  aR  [/        U5      nUR                  U5        U R                   R                  R                  SUR0                   SU 35        OX:S-
     n[(        R*                  " UU5      R,                  nUS:  aQ  [/        U5      nUR                  U5        U R                   R                  R                  SUR0                   SU 35        OWUS:X  aQ  [/        U5      nUR                  U5        U R                   R                  R                  SUR0                   SU 35        US:X  a  SnUR                  [2        R4                  U   5        U R                   R                  R                  SU S[2        R4                  U    35        GM     SR                  U5      $ ! [$         a.    [        R                  SUR&                   S3SU  S3-   5         GNf = f)um	  
Takes in a :class:`~music21.chord.Chord` and returns its representation
as a braille string in UTF-8 unicode.


In braille, only one pitch of a chord is brailled, with the rest represented
as numeric intervals from that one pitch. If descending is True, the highest
(sounding) pitch is brailled, and intervals are labeled in descending order;
if descending is False, the lowest (sounding) pitch is brailled, and the
intervals are labeled in ascending order. Convention dictates that chords
found in the treble clef are brailled descending, and those found in the bass
clef are brailled ascending.


If showOctave is True, the octave of the brailled pitch is shown. Other
octave marks are shown in context relative to the brailled pitch.

>>> from music21.braille.basic import chordToBraille
>>> gMajorTriadA = chord.Chord(['G4', 'B4', 'D5', 'G5'], quarterLength=4.0)
>>> print(chordToBraille(gMajorTriadA, descending=True))
⠨⠷⠼⠴⠤
>>> gMajorTriadB = chord.Chord(['G2', 'B2', 'D3', 'G3'], quarterLength=4.0)
>>> print(chordToBraille(gMajorTriadB, descending=False))
⠘⠷⠬⠔⠤
>>> gMajorTriadRightHand = chord.Chord(['D4', 'B4', 'G5'], quarterLength=4.0)
>>> print(chordToBraille(gMajorTriadRightHand, descending=True))
⠨⠷⠴⠼
>>> gMajorTriadLeftHand = chord.Chord(['G2', 'D3', 'B3'], quarterLength=4.0)
>>> print(chordToBraille(gMajorTriadLeftHand, descending=False))
⠘⠷⠔⠬
>>> cMajorTriadRightHand = chord.Chord(['C4', 'E5'], quarterLength=4.0)
>>> print(chordToBraille(cMajorTriadRightHand, descending=True))
⠨⠯⠐⠬
>>> cMajorTriadLeftHand = chord.Chord(['C2', 'E3'], quarterLength=4.0)
>>> print(chordToBraille(cMajorTriadLeftHand, descending=False))
⠘⠽⠸⠬
>>> cMajorSeventhRightHand = chord.Chord(['C6', 'E5', 'B4'], quarterLength=4.0)
>>> print(chordToBraille(cMajorSeventhRightHand, descending=True))
⠰⠽⠴⠌
>>> cMajorSeventhLeftHand = chord.Chord(['G2', 'E3', 'E4'], quarterLength=4.0)
>>> print(chordToBraille(cMajorSeventhLeftHand, descending=False))
⠘⠷⠴⠐⠴

>>> chordWithoutAccidentals = chord.Chord(['C4', 'E4', 'F4'], quarterLength=4.0)
>>> print(chordToBraille(chordWithoutAccidentals, descending=True))
⠐⠿⠌⠼

>>> chordWithAccidentals = chord.Chord(['C4', 'E-4', 'F#4'], quarterLength=4.0)
>>> chordWithAccidentals.pitches[0].accidental = 'natural'
>>> print(chordToBraille(chordWithAccidentals, descending=True))
⠩⠐⠿⠣⠌⠡⠼

Descending	Ascendingr   quarterLength)music21Note
showOctaver   zChord r   r   
r   z Chord:
   Accidental z of zchord       Octave r   z	Interval  )r   r   sortedpitchesreverser   Noter,   noteToBrailler#   r!   r"   appendjoingetrangelenhandlePitchWithAccidentalr    
accidentalr
   notesToGeneric
undirectedpitchToOctaveoctaver   	intervals)music21Chord
descendingr.   
allPitches	direction
chordTrans	basePitchinitNotebrailleNoteenglishJoinedcurrentPitchIndexcurrentPitchintervalDistancebrailleOctavepreviousPitchrelativeIntervalDists                   r&   chordToBraillerV   t   sz   j -/L),,-JI	J1Iyy"00H  K g/00F<.0RST--44~U5KL())k"IIh00445ErJKM))00+Y}o. #1c*o6!4
	%&&55 $229KVVa 01 49A= A% -l ;!!-0&&55<<l112!M?CE !+q+@ A'/'>'>}?K(MMWZ %'1,$1,$?M%%m4 **99@@!,"5"5!6aG "),7Mm,""1188,--.a?Aq  &**+;<=--44()6+;+;<L+M*NO	
O 7T 77:E  	l556d;<.(JKL	s   !M4NNc                   [        U S5      (       a  U R                  nOU nU[        R                  ;   a  [        R                  U   $ US:  a  [        R                  S   SU-
  -  $ US:  a  [        R                  S   US-
  -  $ g)u  
takes a pitch object and returns the brailling for the octave.

Can also be given an int specifying the octave.

Expands the definition given in Degarmo Ch 7 to allow even less commonly used octaves such
as -1, and > 8 by tripling, etc. the number of octave marks.

>>> pitchToOctave = braille.basic.pitchToOctave
>>> print(pitchToOctave(pitch.Pitch('C4')))
⠐
>>> print(pitchToOctave(pitch.Pitch('B-4')))
⠐
>>> print(pitchToOctave(4))
⠐
>>> print(pitchToOctave(3))
⠸
>>> print(pitchToOctave(2))
⠘
>>> print(pitchToOctave(1))
⠈
>>> print(pitchToOctave(0))
⠈⠈
>>> print(pitchToOctave(-1))
⠈⠈⠈
>>> print(pitchToOctave(5))
⠨
>>> print(pitchToOctave(6))
⠰
>>> print(pitchToOctave(7))
⠠
>>> print(pitchToOctave(8))
⠠⠠
>>> print(pitchToOctave(9))
⠠⠠⠠
rE   r0      r3      N)hasattrrE   r   octaves)music21PitchOrIntrE   s     r&   rD   rD      s    L  (++"))"~~f%%	!~~a AJ//	!~~a FQJ// 
    c                   SSSSSSSSS	S
SS.n[        U [        R                  5      (       a  SU  3/U R                  l        g[
        R                  nUS   n XCU R                     U R                     -  n X R                  R                     SU 3-   /U R                  l        [        U [        R                  [        R                  45      (       a8  XCS   U   -  nU(       a%  U R                  R                  R                  S5        U$ XCS   S   -  nU$ ! [         a    SU  3/U R                  l         Nf = f! [         a:    [        R!                  SU  S35        U  S3/U R                  l        ["        S   s $ f = f)u  
Takes in a :class:`~music21.clef.Clef` and returns its representation
as a braille string in UTF-8 unicode.

Only :class:`~music21.clef.GClef`, :class:`~music21.clef.CClef`,
:class:`~music21.clef.FClef`, :class:`~music21.clef.NoClef` and
their subclasses (such as :class:`~music21.clef.TrebleClef`,
:class:`~music21.clef.BassClef`) can be transcribed.

If keyboardHandSwitched is True, the suffix of the brailled clef changes from dots
1-2-3 to dots 1-3. In scores of keyboard instruments, this change indicates
that the playing hand differs from which implied by the clef. (E.g. A G clef
in the left-hand part of a piano score needs the change of suffix.) Note
that changeSuffix works only for G and F clefs.

>>> from music21.braille.basic import clefToBraille
>>> trebleClef = clef.TrebleClef()
>>> print(clefToBraille(trebleClef))
⠜⠌⠇
>>> print(clefToBraille(trebleClef, keyboardHandSwitched=True))
⠜⠌⠅
>>> bassClef = clef.BassClef()
>>> print(clefToBraille(bassClef))
⠜⠼⠇
>>> print(clefToBraille(bassClef, keyboardHandSwitched=True))
⠜⠼⠅

>>> altoClef = clef.AltoClef()
>>> print(clefToBraille(altoClef))
⠜⠬⠇
>>> tenorClef = clef.TenorClef()
>>> print(clefToBraille(tenorClef))
⠜⠬⠐⠇
>>> noClef = clef.NoClef()
>>> clefToBraille(noClef) == ''
True
>>> sopranoClef = clef.SopranoClef()
>>> print(f'{sopranoClef.sign}, {sopranoClef.line}, {clefToBraille(sopranoClef)}')
C, 1, ⠜⠬⠈⠇
zFrench ViolinTreblez	G-sopranoSopranozMezzo-sopranoAltoTenorz
C-baritonez
F-baritoneBasszSub-bass)FrenchViolinClef
TrebleClefGSopranoClefSopranoClefMezzoSopranoClefAltoClef	TenorClefCBaritoneClefFBaritoneClefBassClefSubBassClefzNo Clef r5   prefixz Clef zUnnamed Clef suffixz Keyboard hand switchedFzClef r   r   r   )
isinstancer   NoClefr   r   r   clefssignline	__class____name__r    re   rm   r;   r!   r"   r#   )music21ClefkeyboardHandSwitched	clefNamesrs   brailleClefs        r&   clefToBrailler|   %  s   T ,# +%%!I +t{{++2:;-0H/I,LLE/K*[--.{/?/?@@	S0099:vk]=SST !!0
 kDOOT]]#CDD?+?@@K#%%44;;<UV  ?511K  	S6CK=4Q3RK!!0	S  *E+.PQR3>-u0E/F,())*s>   D? 9.D 'A&D? D? D<9D? ;D<<D? ?AFFc                x   / n/ U R                   l        U(       aG  UR                  [        S   5        U R                   R                  R                  S[        S    35         [	        U R
                  SS9nU R                   R                  R                  SU R
                   S
U 35        UR                  U5        SR                  U5      $ ! [         aa  n[        R                  SU  SU 35        U R                   R                  R                  SU R
                   S35        [        S   s S	nA$ S	nAff = f)u  
Takes in a :class:`~music21.dynamics.Dynamic` and returns its
:attr:`~music21.dynamics.Dynamic.value` as a braille string in
UTF-8 unicode.


If precedeByWordSign is True, the value is preceded by a word
sign (⠜).


>>> from music21.braille.basic import dynamicToBraille
>>> print(dynamicToBraille(dynamics.Dynamic('f')))
⠜⠋
>>> print(dynamicToBraille(dynamics.Dynamic('pp')))
⠜⠏⠏
wordzWord: TisTextExpressionzDynamic : r   r   Nr   r5   )
r   r   r;   r#   wordToBraillevalueBrailleBasicExceptionr!   r"   r<   )music21DynamicprecedeByWordSigndynamicTransbrailleDynamicwordExceptions        r&   dynamicToBrailler   u  s   " L.0N+GFO,  //66?P7QR*&~';';dS ++22
>''(.)9:<'77<   ! *H^$4B}oFG  //66.BVBVAWW\7]^())*s   #C 
D9AD4.D94D9c                ,   / U R                   l        U R                  5       R                  5       n U Vs/ s H  n[	        U5      PM     nn[        S   R                  U5      nU R                   R                  R                  SU R                  5        SU 35        U$ s  snf ! [
         ae  n[        R                  SU  SU 35        U R                   R                  R                  SU R                  5        S35        [        S   s SnA$ SnAff = f)ud  
Takes in a :class:`~music21.instrument.Instrument` and returns its "best name"
as a braille string in UTF-8 unicode.

>>> from music21.braille.basic import instrumentToBraille
>>> print(instrumentToBraille(instrument.Bassoon()))
⠠⠃⠁⠎⠎⠕⠕⠝
>>> print(instrumentToBraille(instrument.BassClarinet()))
⠠⠃⠁⠎⠎⠀⠉⠇⠁⠗⠊⠝⠑⠞
zInstrument r   r   r   Nspacer   )r   r   bestNamesplitr   r   r!   r"   r;   r#   r<   )music21InstrumentallWordsr~   transr   brailleInsts         r&   instrumentToBrailler     s
    24. ))+113H*19:t$: '"''.K..55
'00231[MBD ;  *K(9':"]OLM##2299+4467u=	?())	*s/   B$ B
B$ B$ $
D.ADDDc                   [         R                  n/ U R                  l        U R                  n [         R
                  U   nUS:  a,  U R                  R                  R                  SU SU 35        O4U R                  R                  R                  S[        U5       SU 35        Uc  U$ UR                  n[        U5      n[        U5      n/ n US:X  d  US:X  d
  XV-  X7-  :w  aB  UR                  X&   5        U R                  R                  R                  SSU S	X&    35        O`Xg:  a[  UR                  U[        XS-
  5         5        U[        XS-
  5         n	U R                  R                  R                  SSU S	U	 35        UR                  U5        S
R                  U5      $ ! [         aN    [        R                  SU  S35        U R                  R                  R                  SU  S35        [        S   s $ f = f! [         aF    [        R                  SU S35        U R                  R                  R                  U S35        Us $ f = f)u  
Takes in a :class:`~music21.key.KeySignature` and returns its representation
in braille as a string in UTF-8 unicode.

>>> from music21.braille.basic import keySigToBraille
>>> print(keySigToBraille(key.KeySignature(4)))
⠼⠙⠩

If given an old key signature, then its cancellation will be applied before
and in relation to the new key signature.

>>> print(keySigToBraille(key.KeySignature(0), outgoingKeySig = key.KeySignature(-3)))
⠡⠡⠡
zIncoming Key Signature r   zKey Signature z sharps Noner   r   z
 sharp(s) z	 flat(s) z
 naturals r5   zOutgoing Key Signature z naturals=None)r   naturalsr   r   sharpskeySignaturesr    r!   r"   r;   r#   absinsertr<   )
music21KeySignatureoutgoingKeySigr   incomingSharps
ks_brailleoutgoingSharpsabsOutgoingabsIncomingr   naturalsPrints
             r&   keySigToBrailler     st    H35!!0(//N	*)).9
 %%44;;^,JzlC	
 	%%44;;S01:,G	
 #**Nn%Kn%KEa!Q&"0n6RSLL./))88??  0
8;P:QRT 'LL#n&E"FGH$S)H%IJM))88??  0
=/J 	Z wwu~U  *%&9%::\]	
 	%%44;;01>	
 ())*X  %n%55WX	Z%%44;;~>Nn<]^	s&   F, CH ,AHHAIIc                   U R                   c  g/ U R                  l         / n[        R                  " SU R
                  R                  S9n[        USS9nUR                  U5        SR                  UR                  R                  S/ 5      5      nU R                  R                  R                  S	U 35        UR                  [        S
   5        U R                  R                  R                  S[        S
    35        [        U R                   5      nUR                  U5        U R                  R                  R                  SU R                    SU 35        SR                  U5      $ ! [         aV  n[        R                  SU  SU 35        U R                  R                  R                  U  S35        [        S   s SnA$ SnAff = f)ub  
Takes in a :class:`~music21.tempo.MetronomeMark` and returns it as a
braille string in UTF-8 unicode.
The format is (note C with duration of metronome's referent)(metronome symbol)(number/bpm).

>>> from music21.braille.basic import metronomeMarkToBraille
>>> mm1 = tempo.MetronomeMark(number=80, referent=note.Note(type='half'))
>>> print(metronomeMarkToBraille(mm1))
⠝⠶⠼⠓⠚
>>> mm2 = tempo.MetronomeMark(number=135, referent=note.Note(quarterLength=0.5))
>>> print(metronomeMarkToBraille(mm2))
⠙⠶⠼⠁⠉⠑

>>> mm3 = tempo.MetronomeMark(numberSounding=80)
>>> metronomeMarkToBraille(mm3)
''
Nr5   C4r+   F)r.   r   r   zMetronome Note 	metronomezMetronome symbol zMetronome number zMetronome Mark r   r   r   )numberr   r   r   r9   referentr,   r:   r;   r<   r=   r#   numberToBrailler   r!   r"   )music21MetronomeMark
metroTrans	metroNoterN   rO   brailleNumbernumberExceptions          r&   metronomeMarkToBrailler     s   $ ""*46""1*
IId2F2O2O2]2]^	#I%@+&!4!4!8!89I2!NO&&55<<m_-	
 	'+./&&55<< 456	
 ((<(C(CD-(&&55<< 4 ; ;<Am_M	
 wwz""  *O,@+AOCTUV&&55<<@T?UUZ=[\())*s   EE- -
G7AGGGc              #    #    S n[        U S5      (       a  [        U R                  US9 H  nUR                  [        R
                  ;   a  [        R
                  UR                     nO>UR                  [        R                  ;   a  [        R                  UR                     nOM}  SU R                  ;   a5  U R                  R                  R                  SUR                   SU 35        Uv   M     gg7f)u7  
Generator that yields braille before note articulations from a given note.
Might yield nothing.

"When a staccato or staccatissimo is shown with any of the other
[before note expressions], it is brailled first."

"The up-bow and down-bow marks for bowed string instruments are brailled before any other
signs from Column A and before an ornament." (BMTM, 114)

Beyond that, we yield in alphabetical order, which happens to satisfy this:
"When an accent is shown with a tenuto, the accent is brailled first." (BMTM, 113)

For reference:

>>> brailleArt = braille.lookup.beforeNoteExpr
>>> print(brailleArt['tenuto'])
⠸⠦
>>> print(brailleArt['staccato'])
⠦
>>> print(brailleArt['accent'])
⠨⠦

>>> brailleBowings = braille.lookup.bowingSymbols
>>> print(brailleBowings['down bow'])
⠣⠃
>>> print(brailleBowings['up bow'])
⠣⠄

>>> n = note.Note()
>>> n.articulations.append(articulations.DownBow())
>>> n.articulations.append(articulations.Tenuto())
>>> n.articulations.append(articulations.Staccato())
>>> n.articulations.append(articulations.Accent())
>>> n.articulations.append(articulations.Scoop())  # example unsupported articulation

This will yield in order: DownBow, Staccato, Accent, Tenuto.

>>> for brailleArt in braille.basic.yieldBrailleArticulations(n):
...     print(brailleArt)
⠣⠃
⠦
⠨⠦
⠸⠦

c                    [        U [        R                  5      n[        U [        R                  5      nU(       + U(       + U R                  4$ N)rq   r   BowingStaccatoname)inner_articulationisBowing
isStaccatos      r&   _brailleArticulationsSortKey?yieldBrailleArticulations.<locals>._brailleArticulationsSortKeyZ  s@    0-2F2FG 2M4J4JK
*n.@.E.EFFr]   r   )keyr   zArticulation r   N)
rZ   r6   r   r   r   bowingSymbolsbeforeNoteExprr   r   r;   )noteElr   art
brailleArts       r&   yieldBrailleArticulationsr   *  s     `G v''&..4PQCxx6///#11#((;
V222#22388<
6#3#33  //66sxxjPQR\Q]7^_ R (s   C5C7)r.   upperFirstInFingeringc               L   / U R                   l        [         H  n [        X5      [        U'   M     / n[        S   (       aH  UR                  [        S   5        U R                   R                  R                  S[        S    35        OU[        S   (       aG  UR                  [        S   5        U R                   R                  R                  S[        S    35        [        S   (       aU  [        S   (       aG  UR                  [        S	   5        U R                   R                  R                  S
[        S	    35        U R                  R                  nU(       Ga;  [        S   (       Ga  US   R                  S:X  a,  US   R                  S:w  a  UR                  [        S   5        OUS   R                  S:X  aG  UR                  [        S   5        U R                   R                  R                  S[        S    35        [        S   nU[        US   R                  SSS9-  nU[        S   -  nUR                  U5        U R                   R                  R                  US   R                   SUS    35        O[        S   (       a	  S[        S'   [        U 5       H  nUR                  U5        M      [        U R                   UU R                   R                  5        U(       a[  [+        U R                   5      nUR                  U5        U R                   R                  R                  SU R,                   SU 35         [.        R0                  U R                   R2                     n	[5        U R                  [        R6                  5      (       aO  U	S    n
UR                  U
5        U R                   R                  R                  U R2                   SS  S!U
 35        GO* [        S   (       a:  U	S    n
U R                   R                  R                  U R2                   S"U
 35        OcXR                  R8                     n
U R                   R                  R                  U R2                   SU R                  R8                   SU
 35        UR                  U
5        [;        U R                  R<                  5       HJ  nUR                  [        S   5        U R                   R                  R                  S#[        S    35        ML     [?        XU5        [A        X5        [        S%   (       aG  UR                  [        S&   5        U R                   R                  R                  S'[        S&    35        [        S   (       a  [        S   (       d  [        S(   (       aH  UR                  [        S)   5        U R                   R                  R                  S
[        S)    35        OU[        S   (       aG  UR                  [        S	   5        U R                   R                  R                  S
[        S	    35        U RB                  ba  U RB                  R8                  S*:w  aG  UR                  [        S+   5        U R                   R                  R                  S,[        S+    35        S-RE                  U5      $ ! [
         a    S[        U'    GM  f = f! ["         a7    [$        R'                  SU R                   R(                   SU  S3S-   5         GN9f = f! ["         a}    [$        R'                  SU R                   R2                  < SU  S3S-   5        U R                   R                  R                  SU R                   R2                   S35        [        S   s $ f = f! ["         ah    [$        R'                  S$U R                   SU  S3S-   5        U R                   R                  R                  S$U R                   S35        [        S   s $ f = f).u  
Given a :class:`~music21.note.Note`, returns the appropriate braille
characters as a string in UTF-8 unicode.


The format for note display in braille is the accidental (if necessary)
+ octave (if necessary) + pitch name with length.


If the note has an :class:`~music21.pitch.Accidental`, the accidental is always
displayed unless its :attr:`~music21.pitch.Accidental.displayStatus` is set to
False. The octave of the note is only displayed if showOctave is set to True.


>>> from music21.braille.basic import noteToBraille
>>> C4 = note.Note('C4')
>>> print(noteToBraille(C4))
⠐⠹
>>> C4.quarterLength = 2.0
>>> print(noteToBraille(C4))
⠐⠝
>>> Ds4 = note.Note('D#4')
>>> print(noteToBraille(Ds4))
⠩⠐⠱
>>> print(noteToBraille(Ds4, showOctave=False))
⠩⠱
>>> Ds4.pitch.accidental.displayStatus=False
>>> print(noteToBraille(Ds4))
⠐⠱
>>> A2 = note.Note('A2')
>>> A2.quarterLength = 3.0
>>> print(noteToBraille(A2))
⠘⠎⠄


>>> B = note.Note('B4')
>>> f = expressions.Fermata()
>>> B.expressions.append(f)
>>> print(noteToBraille(B))
⠐⠺⠣⠇
>>> for x in B.editorial.brailleEnglish:
...     print(x)
Octave 4 ⠐
B quarter ⠺
Note-fermata: Shape normal: ⠣⠇

>>> f.shape = 'square'
>>> print(noteToBraille(B))
⠐⠺⠰⠣⠇
>>> for x in B.editorial.brailleEnglish:
...     print(x)
Octave 4 ⠐
B quarter ⠺
Note-fermata: Shape square: ⠰⠣⠇


>>> C4 = note.Note('C4')
>>> print(noteToBraille(C4))
⠐⠹
>>> C4.duration.appendTuplet(duration.Tuplet(3, 2))  # triplet
>>> print(noteToBraille(C4))
⠐⠹
>>> C4.beamStart = True
>>> print(noteToBraille(C4))
⠆⠐⠹
>>> for x in C4.editorial.brailleEnglish:
...     print(x)
Triplet ⠆
Octave 4 ⠐
C quarter ⠹

>>> C4 = note.Note('C4')
>>> C4.duration.appendTuplet(duration.Tuplet(7, 4))  # septuplet
>>> C4.beamStart = True
>>> print(noteToBraille(C4))
⠸⠶⠄⠐⠹
>>> for x in C4.editorial.brailleEnglish:
...     print(x)
Septuplet ⠸⠶⠄
Octave 4 ⠐
C quarter ⠹
Fr   opening_bracket_slurzOpening bracket slur r   opening_double_slurzOpening double slur r   closing_bracket_slurzClosing bracket slur r   r   Tripletnonetripletztranscriber-added_signztranscriber-added tuplet_prefixTwithNumberSignlowerdotr   r   r1   	 of note !cannot be transcribed to braille.r4   zName r   r   eighthz Gracenote--not supported z beam Dot z	Duration r   opening_single_slurzOpening single slur r   closing_double_slurstoptiezTie r5   )#r   r   TEMPORARY_ATTRIBUTESgetattrr   AttributeErrorr;   r#   r   tupletsfullNametupletActualShowr   numberNotesActualr   r@   pitchr    r!   r"   rA   rD   rE   r   pitchNameToNotessteprq   GraceDurationr   r>   dotshandleArticulationshandleExpressionsr   r<   )r-   r.   r   keyword	noteTrans
allTupletstupletTransbrailleArticulationrS   notesInStepnameWithDurationunused_counter_dots               r&   r:   r:   m  sX   x ,.K('	(")+"?Jw ( I
 ()!789,,33#G,B$C#DE	G	)	*!678,,33"7+@#A"BC	E&'J7M,N!789,,33#G,B$C#DE	G
 %%--Jk""!}%%2z!}7U7UY_7_  !34a=11V;$$W-E%FG))88??,W5M-N,OPR%o6z!}/N/N@E7; = = wu~-  -!!0077a=))*!IbM?; ').J~&
  9E,-  F


!!!00	
 %k&7&78',,33gk>P>P=QQRS`Ra4bc*--k.?.?.D.DE +&&(>(>??&x0)*,,33 (+EFVEWX	
	..)#.x#8 %%44;;"''(/?.@AC $//C/C/H/H#I %%44;;"''(+*>*>*C*C)DAFVEWX -.&+K,@,@,E,E&F"  0%%44;;d75>BR<ST 'G 0EFk- +!678,,33"7+@#A"BC	E+,<R1S)*W%:;<!!0077'0E(F'GHJ,-W%;<=!!0077'0F(G'HIK
 "{';';v'E(,,33d75>:J4KL779]  	("'Jw	(v  
+++667yQO12	

"  *K%%**-Y{m1E12	3 	,,33eK<M<M<R<R;SSX4YZ())*>  	.K001;-qI567 !!0077)KDXDXCYY^8_`,--	.sJ   [?+[# '\' -D)^1 [ [ #=\$#\$'B^.-^.1A/`#"`#c                   U R                   nUb  UR                  SLa  UR                  S:X  a.  [        S   nUR	                  U5        UR	                  SU 35        UR	                  [
        R                  UR                     5        UR	                  SUR                   S[
        R                  UR                      35        UR                  S:X  a/  [        S   nUR	                  U5        UR	                  SU 35        g g g g )NFparentheseszbraille-music-parenthesiszParenthesis r1   r   )rA   displayStatusdisplayStyler#   r;   r   accidentalsr   )music21Pitch
pitchTransr   accpss        r&   r@   r@   _  s    

!
!C
3,,E9},45Bb!!!L"56&,,SXX67CHH:Qv7I7I#((7S6TUV},45Bb!!!L"56 - :r]   c                     U R                    H:  nSUR                  ;   d  M  [        UR                  US9nUR	                  U5        M<     g ! [
         a6    [        R                  SU R                  R                   SU  S3S-   5         g f = f)N	Fingering)r   z
Fingering r   r   r   )
r   classestranscribeNoteFingeringfingerNumberr;   r   r!   r"   r   	fingering)r-   r   r   r   transcribedFingerings        r&   r   r   o  s    
3,,Cckk)'>$$*?(A$   !56 - ! 3..889;-qQ12	33s   A )A =BBc           	        U R                    H  n[        U[         R                  5      (       d  M$   [        R                  S   UR
                     nUR                  U5        U R                  R                  R                  SUR
                   SU 35        M     g! [         a     [        R                  SU SU  S35         M  f = f)z4
Transcribe the expressions for a note.GeneralNote.
shapezNote-fermata: Shape r   zFermata r   z cannot be transcribed.N)r	   rq   Fermatar   fermatasr   r;   r   r   r    r!   r"   )r-   r   exprfermataBrailles       r&   r   r     s     ''dK//00b!'!9$**!E  0%%44;;*4::,b8HIK (  b!!HTF)K=H_"`abs   A&B&CCc                "   / U R                   l        / nU R                  R                  nU R                  R                  nU R
                  SL a  SnSn [        R                  U   nUR                  U5        U R                   R                  R                  SU S	U 35        [        U5       HJ  nUR                  [        S
   5        U R                   R                  R                  S[        S
    35        ML     [        X5        SR                  U5      $ ! [         al    [        R                  SU R                   S35        U R                   R                  R                  SU R                  R                   S35        [        S   s $ f = f)uY  
Given a :class:`~music21.note.Rest`, returns the appropriate braille
characters as a string in UTF-8 unicode.


Currently, only supports single rests with or without dots.
Complex rests are not supported.

>>> from music21.braille.basic import restToBraille
>>> dottedQuarter = note.Rest(quarterLength=1.5)
>>> print(restToBraille(dottedQuarter))
⠧⠄
>>> whole = note.Rest(quarterLength=4.0)
>>> print(restToBraille(whole))
⠍

This would give a warning and gives the basic_exception symbol:

quarterPlusSixteenth = note.Rest(quarterLength=1.25)
print(restToBraille(quarterPlusSixteenth))
⠜⠦
Twholer   zRest of duration r   zRest r   r   r   r   r   r5   )r   r   r   r   r   fullMeasurer   restsr    r!   r"   r;   r#   r>   r   r<   )music21Rest	restTransrestTyperestDots
simpleRestr   s         r&   restToBrailler    sl   . ,.K(I##((H##((H$&*\\(+
 Z ((//%z:,0OP#Ho(,,33d75>:J4KL . k-779  * 4 455WX	Z,,33eK<P<P<U<U;VV[4\]())	*s   D A3FF(   maxLineLengthc          	        / nX R                   l        U R                  R                  S5      n/ nU H  nUR                  5       n/ nU H  n [	        U5      n	SnU H  nUS:X  a  SnM  U[        U5      -  nM     U[        U	5      -   S	-   US
-
  :  a  UR                  S5        UR                  U	5        UR                  [        S   5        M     UR                  SR                  USS 5      5        M     [        S   S-   nUR                  U5      [        S   -   nU R                   R                  R                  SU R                   SU 35        U$ ! [
         ae  n
[        R                  SU  SU
 35        U R                   R                  R                  SU R                   S35        [        S   s Sn
A
s  s  $ Sn
A
ff = f)u  
Takes in a :class:`~music21.tempo.TempoText` and returns its representation in braille
as a string in UTF-8 unicode. The tempo text is returned uncentered, and is split around
the comma, each split returned on a separate line. The literary period required at the end
of every tempo text expression in braille is also included.

>>> from music21.braille.basic import tempoTextToBraille
>>> print(tempoTextToBraille(tempo.TempoText('Lento assai, cantante e tranquillo')))
⠠⠇⠑⠝⠞⠕⠀⠁⠎⠎⠁⠊⠂
⠉⠁⠝⠞⠁⠝⠞⠑⠀⠑⠀⠞⠗⠁⠝⠟⠥⠊⠇⠇⠕⠲
>>> print(tempoTextToBraille(tempo.TempoText('Andante molto grazioso')))
⠠⠁⠝⠙⠁⠝⠞⠑⠀⠍⠕⠇⠞⠕⠀⠛⠗⠁⠵⠊⠕⠎⠕⠲

>>> print(tempoTextToBraille(tempo.TempoText('Andante molto grazioso ma cantabile')))
⠠⠁⠝⠙⠁⠝⠞⠑⠀⠍⠕⠇⠞⠕⠀⠛⠗⠁⠵⠊⠕⠎⠕⠀⠍⠁⠀
⠉⠁⠝⠞⠁⠃⠊⠇⠑⠲

>>> print(tempoTextToBraille(tempo.TempoText('Andante molto grazioso ma cantabile'),
...                          maxLineLength=20))
⠠⠁⠝⠙⠁⠝⠞⠑⠀
⠍⠕⠇⠞⠕⠀
⠛⠗⠁⠵⠊⠕⠎⠕⠀⠍⠁⠀
⠉⠁⠝⠞⠁⠃⠊⠇⠑⠲
,zTempo Text r   r   r   Nr   r/   r0   rY   r   r5   r   .r   )r   r   textr   r   r   r!   r"   r;   r#   r?   r<   alphabet)music21TempoTextr  newBrailleEnglish
allPhrasesbraillePhrasessamplePhraser   phraseTrans
sampleWordbrailleWordr   total_widthphrasejoinerbrailleUnicodeTexts                  r&   tempoTextToBrailler!    s   < $&0A-!&&,,S1JN"%%'!#"J2+J7 K%T>"#K3v;.K	 & S--1]Q5FG""4({+ww/0+ #, 	bggk!B&7893 #6 c]T!F^4x}D--44
&++,A.@-AB 7 ) 2!!K0@/AM?"ST **99@@!"2"7"7!8> 01112s   E
G AG 6G Gc                   / U R                   l        U R                  nU[        R                  ;   a@  [        R                  U   nU R                   R                  R                  SU SU 35        U$ UR                  5       n/ n U H  nUR                  [        USS95        M     [        S	   R                  U5      nU R                   R                  R                  SU SU 35        U(       a<  [        S
   U-   nU R                   R                  R                  SS[        S
    35        [        U5      S:  a;  U[        S
   -   nU R                   R                  R                  S[        S
    35        U$ ! [         aW  n[        R                  SU  SU 35        U R                   R                  R                  SU S35        [        S   s SnA$ SnAff = f)uo  
Takes in a :class:`~music21.expressions.TextExpression` and returns its
representation in UTF-8 unicode.

From the lookup table:

>>> from music21.braille.basic import textExpressionToBraille
>>> print(textExpressionToBraille(expressions.TextExpression('cresc.')))
⠜⠉⠗⠄

Single word expression has word symbol (⠜) only at beginning:

>>> print(textExpressionToBraille(expressions.TextExpression('dolce')))
⠜⠙⠕⠇⠉⠑

Multiple word expression has word symbol at beginning and end.

>>> print(textExpressionToBraille(expressions.TextExpression('dim. e rall.')))
⠜⠙⠊⠍⠄⠀⠑⠀⠗⠁⠇⠇⠄⠜
zText Expression r   Tr   r   r   r   Nr   r~   r   zWord r0   )r   r   contentr   textExpressionsr;   r   r   r   r!   r"   r#   r<   r   r?   )	music21TextExpressionr   teWordssimpleReturnallExprtextExpressionTransr  r   brailleTextExprs	            r&   textExpressionToBrailler+    s   * 68##2#++G&(((--g6''66==wiq7	9 mmoG*D&&}TD'QR  g&++,?@O##2299
7)1_$568 !&/O;''66==a5QWHYAZ[
7|a)GFO;''66==gfoEV>WX# ! *,-B,C2m_UV''66==@PQXPYY^>_`())*s   "E9 9
GAGGGc                   / U R                   l        U R                  S;   aJ  [        U R                     nU R                   R                  R	                  SU R                   SU 35        U$  [        U R                  5      [        U R                  SSS9/nSR                  U5      nU R                   R                  R	                  SU R                   SU R                   S3U -   5        U$ ! [        [        4 aT  n[        R                  SU  S	35        U R                   R                  R	                  U  S
35        [        S   s SnA$ SnAff = f)u  
Takes in a :class:`~music21.meter.TimeSignature` and returns its
representation in braille as a string in UTF-8 unicode.

>>> from music21.braille.basic import timeSigToBraille
>>> print(timeSigToBraille(meter.TimeSignature('4/4')))
⠼⠙⠲
>>> print(timeSigToBraille(meter.TimeSignature('3/4')))
⠼⠉⠲
>>> print(timeSigToBraille(meter.TimeSignature('12/8')))
⠼⠁⠃⠦
>>> print(timeSigToBraille(meter.TimeSignature('c')))
⠨⠉
)commoncutzTime Signature r   FTr   r5   /r   r   r   N)r   r   symbolr#   r;   r   	numeratordenominatorr<   r   r    r!   r"   )m21TimeSignature
brailleSigtimeSigTransunused_errors       r&   timeSigToBrailler7  @  s_    13-"33-445
""1188.556a
|D	F*'(8(B(BC'(8(D(D7<.245 WW\*
""1188.889;K;W;W:XXYZ	
 !8, *.//QR	T""1188<L;MU9ST())	*s    -B C. .E>A	EEEc                   U c  g[         R                  " X5      nUR                  R                  S:  nUR                  R                  S;   nU R                  UR                  :H  nSnU(       d  U(       a	  U(       d  SnU$ )a  
Determines whether a currentNote carries an octave designation
in relation to a previous Note.

Rules:

* If currentNote is found within a second or third
  of previousNote, currentNote does not
  carry an octave designation.

* If currentNote is found a sixth or
  more away from previousNote, currentNote does carry
  an octave designation.

* If currentNote is found within a fourth or fifth
  of previousNote, currentNote carries
  an octave designation if and only if currentNote and
  previousNote are not found in the
  same octave.

Of course, these rules cease to apply in quite a few cases,
which are not directly reflected
in the results of this function:

1) If a braille measure goes to a new line, the first note in the measure carries an
   octave designation regardless of what the previous note was.


2) If a braille measure contains a new key or time signature, the first note carries
   an octave designation regardless of what the previous note was.


3) If a new key or time signature occurs in the middle of a measure, or if a double bar
   line is encountered, both of which would necessitate a music hyphen, the next note after
   those cases needs an octave marking.

If any special case happens, previousNote can be set to None and the function will return
True.

>>> from music21.braille.basic import showOctaveWithNote
>>> showOctaveWithNote(note.Note('C4'), note.Note('E4'))
False
>>> showOctaveWithNote(note.Note('C4'), note.Note('F4'))
False
>>> showOctaveWithNote(note.Note('C4'), note.Note('F3'))
True
>>> showOctaveWithNote(note.Note('C4'), note.Note('A4'))
True

If previousNote is None, it is always True

>>> showOctaveWithNote(None, note.Note('A4'))
True
TrY   )      F)r
   IntervalgenericrC   rE   )previousNotecurrentNoteiisSixthOrGreaterisFourthOrFifthsameOctaveAsPreviousdoShowOctaves          r&   showOctaveWithNoterD  l  sv    n ,4Ayy++q0ii**f4O'..+2D2DDLO4Hr]   c                   U c  Uc  Uc  Uc  [        S5      eSnUb	  [        X$S9nU c  Uc  Uc  UR                  5       n/ nU H  nUR                  U5        M     [	        U5      US-
  ::  a*  SR                  U5      nUR                  U[        S   5      $ [        [	        U5      5       H   n	Xy   R                  U[        S   5      Xy'   M"     SR                  U5      $ / n
Ub  [        U5      nU
R                  U5         [        X5      nUb  U
R                  [        S   5        U
R                  U5        SR                  U
5      nUc  UR                  U[        S   5      $ UR                  5       n/ nU H  nUR                  U5        M     UR                  U5        [	        U5      S:  a*  US	   (       d   USS n[	        U5      S:  a  US	   (       d  M   [	        U5      S:  a*  US
   (       d   USS
 n[	        U5      S:  a  US
   (       d  M   [	        U5      [	        U5      -   S-   US-
  ::  a1  [        S   R                  U5      nUR                  U[        S   5      $ [        [	        U5      5       H   n	Xy   R                  U[        S   5      Xy'   M"     SR                  U5      $ ! [          a    Uc  Uc  [        S5      e GNf = f)u  
Takes in a :class:`~music21.key.KeySignature`, :class:`~music21.meter.TimeSignature`,
:class:`~music21.tempo.TempoText`, and
:class:`~music21.tempo.MetronomeMark` and returns its representation in braille as a
string in UTF-8 unicode. The contents
are always centered on a line, whose width is 40 by default.

In most cases, the format is (tempo text)(space)(metronome mark)(space)(key/time signature),
centered, although all of
these need not be included. If all the contents do not fit on one line with at
least 3 blank characters on each side, then
the tempo text goes on the first line (and additional lines if necessary),
and the metronome mark + key and time signature
goes on the last line.

If the resulting heading is of length zero, a BrailleBasicException is raised.

>>> from music21.braille.basic import transcribeHeading
>>> print(transcribeHeading(
...         key.KeySignature(5),
...         meter.TimeSignature('3/8'),
...         tempo.TempoText('Allegretto'),
...         tempo.MetronomeMark(number=135, referent=note.Note(type='eighth'))))
⠀⠀⠀⠀⠀⠀⠀⠠⠁⠇⠇⠑⠛⠗⠑⠞⠞⠕⠲⠀⠙⠶⠼⠁⠉⠑⠀⠼⠑⠩⠼⠉⠦⠀⠀⠀⠀⠀⠀⠀
>>> print(transcribeHeading(
...          key.KeySignature(-2),
...          meter.TimeSignature('common'),
...          tempo.TempoText('Lento assai, cantante e tranquillo'),
...          None))
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠇⠑⠝⠞⠕⠀⠁⠎⠎⠁⠊⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠝⠞⠁⠝⠞⠑⠀⠑⠀⠞⠗⠁⠝⠟⠥⠊⠇⠇⠕⠲⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠣⠣⠨⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
>>> print(transcribeHeading(
...          key.KeySignature(-2),
...          meter.TimeSignature('common'),
...          tempo.TempoText('Lento assai, cantante e tranquillo'),
...          None,
...          maxLineLength=10))
⠀⠠⠇⠑⠝⠞⠕⠀⠀⠀
⠀⠀⠁⠎⠎⠁⠊⠂⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠉⠁⠝⠞⠁⠝⠞⠑⠀⠀
⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀
⠞⠗⠁⠝⠟⠥⠊⠇⠇⠕⠲
⠀⠀⠀⠣⠣⠨⠉⠀⠀⠀

NzNo heading can be made.r  rY   r5   r   r/   r0   r   r   )r   r!  
splitlinesr;   r?   r<   centerr#   r>   r   transcribeSignatures)r   music21TimeSignaturer  r   r  tempoTextTranstempoTextLinesheadingTranstempoText_lineheading_line_index
otherTransmetronomeMarkTranskeyAndTimeSigotherTransStrtempo_text_lineheadingTrans_strs                   r&   transcribeHeadingrU    s   n 	#$, ($,#$=>>N#+,<Z#$,$,'224,N/ -~=1#4577<0L&&}gg6FGG&+C,=&>"3?3S3Z3Z!G$40 '?
 99\**J'34HI,-C,-@W+gg./-(
 GGJ'M##M773CDD'224-O0  .M*,!#LO'+L ,!#LOO ,!#L,<',L ,!#L,<,< ~]!33a7MA<MN&w/44\B#**='':JKK&+C,=&>"3?3S3Z3Z!G$40 '?
 99\**= ! C',<,D'(ABBCs   7J0 0KKc                   [         R                  n[        U [        5      (       a  [	        U 5      n [        U 5      S:X  a   X    $ / nU R                  S5      n[        U5      S:X  a  SnO)[        U5      S:X  a  U R                  S5      nSnO[        eU(       d  UR                  5         [        [        U5      5       H  nXF   R                  S5      n [        U5      S:X  aF  UR                  X'S	      5        UR                  [        S
   5        UR                  X'S      5        Ml  [        U5      S:X  a  US	   nSn	 X(   n	UR                  U	5        M  M     SR                  U5      $ ! [         a    [        SU  35      ef = f! [         a0  n
U(       d  U
eUS	:X  a  [        S   n	 Sn
A
Nk[        S   n	 Sn
A
NySn
A
ff = f! [         a    [        SU  35      ef = f)uo  
Takes in a note fingering and returns its correct transcription to braille.

>>> from music21.braille.basic import transcribeNoteFingering
>>> print(transcribeNoteFingering('4'))
⠂

A change of fingering:

>>> print(transcribeNoteFingering('2-1'))
⠃⠉⠁

A choice of fingering, both on either the top or bottom of the staff:

>>> print(transcribeNoteFingering('5|4', upperFirstInFingering=True))
⠅⠂
>>> print(transcribeNoteFingering('5|4', upperFirstInFingering=False))
⠂⠅

A choice of fingering, one on top and one below the staff:

>>> print(transcribeNoteFingering('2,1', upperFirstInFingering=True))
⠃⠁
>>> print(transcribeNoteFingering('2,1', upperFirstInFingering=False))
⠁⠃

A choice of fingering, first set missing fingermark:

>>> print(transcribeNoteFingering('2,x'))
⠃⠄

A choice of fingering, second set missing fingermark:

>>> print(transcribeNoteFingering('x,2'))
⠠⠃

Missing fingermarks change with upperFirstInFingering

>>> print(transcribeNoteFingering('x,4', upperFirstInFingering=True))
⠠⠂
>>> print(transcribeNoteFingering('x,4', upperFirstInFingering=False))
⠂⠄
>>> print(transcribeNoteFingering('4,x', upperFirstInFingering=True))
⠂⠄
>>> print(transcribeNoteFingering('4,x', upperFirstInFingering=False))
⠠⠂


A change of fingering and a choice of fingering combined (thanks to Bo-cheng Jhan
for the patch):

>>> print(transcribeNoteFingering('1-2|3-4'))
⠁⠉⠃⠇⠉⠂

Incorrect fingerings raise a BrailleBasicException:

>>> transcribeNoteFingering('6')
Traceback (most recent call last):
music21.braille.basic.BrailleBasicException: Cannot translate note fingering: 6
r0   z!Cannot translate note fingering: r  rX   T|F-r   finger_changer5   first_set_missing_fingermarksecond_set_missing_fingermarkN)r   fingerMarksrq   intstrr?   r    r   r   r8   r>   r;   r#   r<   )sampleNoteFingeringr   r\  r   choiceallowAbsencer?  change
changeMarkfingerMarkToAppendes              r&   r   r   /  s   z $$K%s++!"56
1$	c33 E &&s+F
6{a	V	$**3/ 3v;%	c6{a[34W_56[34V!#AY
%'"
V)4)@& /0 "  2 775>Q  	c'*KL_K`(abb	c6   V' Av-45S-T*-45T-U*V  	c'*KL_K`(abb	csU   E- AG*GF	G-F	
GF>+G0	F>9G>GGGc                    Uc  U b  U R                   S:X  a  Uc  g/ nU b  UR                  [        XS95        Ub  UR                  [        U5      5        SR	                  U5      $ )u	  
Takes in a :class:`~music21.key.KeySignature` and
:class:`~music21.meter.TimeSignature` and returns its representation
in braille as a string in UTF-8 unicode. If given an old key signature,
then its cancellation will be applied before
and in relation to the new key signature.

Raises a BrailleBasicException if the resulting key and time signature is
empty, which happens if the time signature
is None and (a) the key signature is None or (b) the key signature has
zero sharps and there is no previous key signature.

>>> from music21.braille.basic import transcribeSignatures
>>> print(transcribeSignatures(key.KeySignature(5), meter.TimeSignature('3/8'), None))
⠼⠑⠩⠼⠉⠦
>>> print(transcribeSignatures(key.KeySignature(0), None, key.KeySignature(-3)))
⠡⠡⠡
r   r5   )r   )r   r;   r   r7  r<   )r   rI  r   r   s       r&   rH  rH    sj    & 	$$,(//149OE&_%8XY'%&:;<775>r]   c                    U R                  5       n/ nU HF  n/ nU H  nUR                  [        U   5        M     UR                  SR                  U5      5        MH     SR                  U5      $ )aM  
translates a braille UTF-8 unicode string into braille ASCII,
which is the format compatible with most braille embossers.

.. note:: The function works by corresponding braille symbols to ASCII symbols.
    The table which corresponds to said values can be found
    `here <https://en.wikipedia.org/wiki/Braille_ASCII#Braille_ASCII_values>`_.
    Because of the way in which the braille symbols translate, the resulting
    ASCII string will look to a non-reader as gibberish. Also, the eighth-note notes
    in braille music are one-off their corresponding letters
    in both ASCII and written braille.
    The written D is really a C eighth-note, the written E is really a
    D eighth note, etc.

>>> from music21.braille.basic import brailleUnicodeToBrailleAscii, noteToBraille
>>> brailleUnicodeToBrailleAscii('\u2800')
' '
>>> Cs8 = note.Note('C#4', quarterLength=0.5)
>>> Cs8_braille = noteToBraille(Cs8)
>>> brailleUnicodeToBrailleAscii(Cs8_braille)
'%"D'
>>> Eb8 = note.Note('E-4', quarterLength=0.5)
>>> Eb8_braille = noteToBraille(Eb8)
>>> brailleUnicodeToBrailleAscii(Eb8_braille)
'<"F'
r5   r/   )rF  r;   ascii_charsr<   )brailleUnicodebrailleLines
asciiLines
sampleLineallCharschars         r&   brailleUnicodeToBrailleAsciiro    si    6 ",,.LJ"
DOOK-. "''(+,	 # 99Z  r]   c                &   0 n[          H  nX![         U   '   M     U R                  5       n/ nU HO  n/ nU H$  nUR                  XR                  5          5        M&     UR                  SR	                  U5      5        MQ     SR	                  U5      $ )u4  
translates a braille ASCII string to braille UTF-8 unicode, which
can then be displayed on-screen in braille on compatible systems.

.. note:: The function works by corresponding ASCII symbols to braille
    symbols in a very direct fashion. It is not a translator from plain
    text to braille, because ASCII symbols may not correspond to their
    equivalents in braille. For example, a literal period is a 4 in
    braille ASCII. Also, all letters are translated into their lowercase
    equivalents, and any capital letters are indicated by preceding them
    with a comma.

>>> t1 = braille.basic.brailleAsciiToBrailleUnicode(',ANDANTE ,MAESTOSO4')
>>> t1
'⠠⠁⠝⠙⠁⠝⠞⠑⠀⠠⠍⠁⠑⠎⠞⠕⠎⠕⠲'
>>> t2 = braille.basic.tempoTextToBraille(tempo.TempoText('Andante Maestoso'))
>>> t1 == t2
True
r5   r/   )rh  rF  r;   upperr<   )brailleAsciibraille_charsr   rk  rj  rl  rm  rn  s           r&   brailleAsciiToBrailleUnicodert    s    ( M*-k#&'  ((*JL 
DOOM**,78 BGGH-.	 ! 99\""r]   c                ,   U U 3U U 3U U 3U U 3S.nU R                  5       n/ nU H  n/ n/ n/ n	U HR  n
[        R                  U
   u  pnUR                  X;   5        UR                  X<   5        U	R                  X=   5        MT     UR                  SR	                  U5      5        UR                  SR	                  U5      5        UR                  SR	                  U	5      5        UR                  S5        M     SR	                  USS 5      $ )u   
translates a braille unicode string into symbols (unicode) -- for debugging.

>>> print(braille.basic.brailleUnicodeToSymbols('⠜'))
·o
·o
o·
)00011011z  r5   r/   r   r   )rF  r   binary_dotsr;   r<   )ri  filledSymbolemptySymbolsymbolTransrj  binaryLinesrl  binaryLine1binaryLine2binaryLine3rn  dots14dots25dots36s                 r&   brailleUnicodeToSymbolsr    s(    (=6'=7(>+7(>,8:K
 ",,.LK"
D'-'9'9$'?$VV{23{23{23	 
 	499[12499[12499[122 # 99[2&''r]   c              #  f   #    [         R                  U     H  nUS;   d  M  [        S   v   M     g7f)u  
Generator that yields symbol['dot'] characters for each row of a
braille character that where the left dot is filled.  These
are used in many places in Braille Music Code.

>>> B = braille.lookup.brailleDotDict
>>> gen = braille.basic.yieldDots(B[1])
>>> gen
<generator object yieldDots at 0x10aee5f68>
>>> for dot in gen:
...     print(dot)
⠄
>>> gen = braille.basic.yieldDots(B[1235])
>>> for dot in gen:
...     print(dot)
⠄
⠄
⠄
)rx  ry  r   N)r   rz  r#   )brailleCharacterr   s     r&   	yieldDotsr  /  s/     ( ""#34<%.  5s   11c           	     $  ^ / mSU4S jjnU(       a  U  Hq  nUR                  5       (       a  U" UR                  5       5        M0  US:X  a  TR                  [        S   5        MP  US:X  a  U" S5        U" S5        Mh   U" U5        Ms     S
R                  T5      $ SnU  GH  n UR                  5       (       a"  U(       d  TR                  [        S   5        SnO6UR                  5       (       a!  U(       a  TR                  [        S   5        SnUR                  5       (       a0  TR                  [        S   5        U" UR                  5       5        M  UR                  5       (       a-  TR                  [        R                  [        U5         5        M  US:X  a  U" S5        U" S5        GM  U" U5        GM     S
R                  T5      $ ! [         a    [        SU SU  S3S	-   5      ef = f! [         a    [        SU SU  S35      ef = f)u|  
Transcribes a word to UTF-8 braille.

>>> from music21.braille.basic import wordToBraille
>>> print(wordToBraille('Andante'))
⠠⠁⠝⠙⠁⠝⠞⠑

Try the German for violin.

>>> print(wordToBraille('Geige'))
⠠⠛⠑⠊⠛⠑

Tests number symbol at beginning, punctuation in number
and switch back to letters.

>>> print(wordToBraille('25.4cm'))
⠼⠃⠑⠲⠙⠰⠉⠍
c                   > U [         ;   a  TR                  [         U    5        g [        R                  " U 5      nX:X  a  [	        SU -   5      eTR                  [         S   5        TR                  [         U   5        g )NzCannot translate ^)r  r;   r   stripAccentsr    )inner_letterl2	wordTranss     r&   
add_letter!wordToBraille.<locals>.add_lettera  si    8#Xl34)),7B!2\ABBXc]+Xb\*r]   r  r      ßszCharacter 'z' in Text Expression 'z' r   r5   Fr   Tletter_sign	uppercasez' in word '#' cannot be transcribed to braille.)r  r^  )isupperr   r;   r#   r    r   r<   isdigitisalphar   numbersUpperr]  )r  r   r  letterlastCharWasNumberr  s        @r&   r   r   K  s   ( I+  F~~6<<>*3  0433?v& ! wwy!!	~~(9  !23$(!!!&7  !78$)!~~  !566<<>*!!  !4!4S[!AB4336"% 2 779C   ?/%fX-CJ<rR=>? ??8  	'fX[<_` 	s,   >G$B0G2A G2G21G2 G/2Hc           	     V   / nU(       a  UR                  [        S   5        U(       a  [        R                  nO[        R                  n[        U 5       H!  n UR                  U[        U5         5        M#     SR                  U5      $ ! [         a    [        SU SU  S35      ef = f)u  
Transcribes a number to UTF-8 braille. By default, the result number
occupies the upper two thirds of braille cells with a leading number sign.
If withNumberSign is set to False, the leading number sign will be removed.
If lower is set to True, the position will be changed from the upper (1245
dots) to the lower (2356 dots).

>>> from music21.braille.basic import numberToBraille
>>> print(numberToBraille(12))
⠼⠁⠃
>>> print(numberToBraille(7))
⠼⠛
>>> print(numberToBraille(37))
⠼⠉⠛
r   zDigit 'z' in number 'r  r5   )
r;   r#   r   numbersLowerr  r^  r]  
ValueErrorr   r<   )sampleNumberr   r   numberTransnumbersdigits         r&   r   r     s      K78,-%%%%\"	ws5z23 # 77;	  	'%l^;^_ 	s   BB(c                      \ rS rSrSrg)r   i   Nrw   
__module____qualname____firstlineno____static_attributes__r  r]   r&   r   r         r]   r   c                      \ rS rSrSrg)Testi  r  Nr  r  r]   r&   r  r    r  r]   r  __main__)TT)F)Tr   )r-   z	note.Note)r   	list[str])r-   znote.GeneralNoter   r  )r  ztempo.TempoTextreturnr^  )NNNNr  )1T)rr  r^  r  r^  )o   ·)r  r^  r  r^  )TF)r  r]  r  r^  )>__doc__
__future__r   typingtunittestmusic21r   r   r   r   r   r	   r
   r   music21.brailler   music21.commonr   TYPE_CHECKINGr   r  rh  r#   Environmentr!   r   __annotations__r   r'   rV   rD   r|   r   r   r   r   r   r:   r@   r   r   r  r!  r+  r7  rD  rU  r   rH  ro  rt  r  r  r   r   Music21Exceptionr   TestCaser  rw   mainTestr  r]   r&   <module>r     s  : #   !         " &?? ??  
..&&z2 
O  ( *@{|00fM*`!!H6DN,*^@L 	ood7 3 b".h C%C 		CL6r&*XAJ |+~l^H$!N!#H(D!8M` F	L99 		8 	 zT r]   