§
    ƒØjÍ^  ã                  óH  — d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 ej        Z G d„ dej        ¦  «        Z G d	„ d
e¦  «        Z G d„ dej        ¦  «        Z G d„ dej        ¦  «        Z G d„ dej        ¦  «        Zedk    rd dlZ ej        e¦  «         dS dS )é    )ÚannotationsN)Úexceptions21)Úprebase)Úlookup)ÚnumberToBrailleÚ	yieldDotsc                  óž   — e Zd ZdZdd„Zdd„Zed„ ¦   «         Zej        d	„ ¦   «         Zd
„ Z	d„ Z
d„ Zdd„Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ ZdS )ÚBrailleTextuå  
    Object that handles all the formatting associated with braille music notation on multiple lines.

    >>> bt = braille.text.BrailleText(lineLength=10, showHand='right')
    >>> bt
    <music21.braille.text.BrailleText 1 line, 0 headings, 10 cols>
    >>> bt.lineLength
    10
    >>> bt.allLines
    [<music21.braille.text.BrailleTextLine 'â €â €â €â €â €â €â €â €â €â €'>]
    >>> bt.rightHandSymbol
    True
    >>> bt.leftHandSymbol
    False
    >>> bt.allHeadings
    []
    é(   Nc                óž   — || _         d | _        g | _        |                      ¦   «          d | _        d| _        d| _        g | _        || _        d S )NF)	Ú
lineLengthÚcurrentLineÚallLinesÚmakeNewLineÚ	_showHandÚrightHandSymbolÚleftHandSymbolÚallHeadingsÚshowHand)Úselfr   r   s      ú‰/Users/tedpeters/Documents/Projects/Claude Projects/Misc Tools/notename-sheets/.venv/lib/python3.11/site-packages/music21/braille/text.pyÚ__init__zBrailleText.__init__(   sT   € Ø$ˆŒØˆÔØˆŒØ×ÒÑÔÐàˆŒØ$ˆÔØ#ˆÔØˆÔà ˆŒˆˆó    ÚreturnÚstrc                ó²   — t          | j        ¦  «        }|› d�|dk    rdndz   }t          | j        ¦  «        }|› d�|dk    rdndz   }|› d|› d| j        › d�S )Nz lineé   ÚsÚ z headingz, z cols)Úlenr   r   r   )r   Úline_lenÚline_strÚheading_lenÚheading_strs        r   Ú_reprInternalzBrailleText._reprInternal5   s‚   € Ý�t”}Ñ%Ô%ˆØÐ%Ð%Ð%°¸A²°¨¨À2ÑFˆÝ˜$Ô*Ñ+Ô+ˆØ$Ð.Ð.Ð.¸ÈÒ9IÐ9I°#°#ÈrÑRˆàÐCÐC˜kÐCÐC¨T¬_ÐCÐCÐCÐCr   c                ó   — | j         S ©N)r   ©r   s    r   r   zBrailleText.showHand=   s
   € àŒ~Ðr   c                ód   — |dk    r	d| _         d S |dk    r	d| _        d S |�t          d¦  «        ‚d S )NÚrightTÚleftzIllegal hand sign request.)r   r   ÚBrailleTextException)r   ÚnewHands     r   r   zBrailleText.showHandA   sQ   € à�gÒÐØ#'ˆDÔ Ð Ð Ø˜ÒÐØ"&ˆDÔÐÐØÐ Ý&Ð'CÑDÔDÐDð !Ð r   c                ób  — | j         j        dk    r|                      ¦   «          t          | j        ¦  «        dz
  }|}| j         }|                     ¦   «         D ]9}d|_        |                     |d¬¦  «         |                      ¦   «          |dz  }Œ:| j                             ||f¦  «         dS )uW  
        adds a heading to the BrailleText.  Heading can be a single or multiple line
        Unicode string representing a heading.

        These headings are not stored in allHeadings, but instead in .allLines,
        what .allHeadings stores is the index of the start of a heading section
        and the index of the end of a heading section.

        (since each BrailleTextLine knows whether it is a heading or not, storing
        the index of headings might be overkill)

        >>> bt = braille.text.BrailleText(lineLength=10)
        >>> headingText = braille.basic.timeSigToBraille(meter.TimeSignature('4/8'))
        >>> bt.addHeading(headingText)
        >>> len(bt.allLines)
        2
        >>> bt.allLines[0].isHeading
        True
        >>> print(str(bt.allLines[0]))
        â ¼â ™â ¦
        >>> bt.allHeadings
        [(0, 1)]
        >>> bt.addMeasureNumber(7)
        >>> headingText = braille.basic.timeSigToBraille(meter.TimeSignature('3/4'))
        >>> bt.addHeading(headingText)
        >>> len(bt.allLines)
        4
        >>> bt.allHeadings
        [(0, 1), (2, 3)]
        r   r   TF©ÚaddSpaceN)	r   ÚtextLocationr   r    r   Ú
splitlinesÚ	isHeadingÚappendr   )r   ÚheadingÚ
indexStartÚ
indexFinalÚbrailleCurrentLineÚheadingLines         r   Ú
addHeadingzBrailleText.addHeadingJ   sÅ   € ð> ÔÔ(¨AÒ-Ð-Ø×ÒÑÔÐÝ˜œÑ'Ô'¨!Ñ+ˆ
Øˆ
à!Ô-ÐØ"×-Ò-Ñ/Ô/ð 	ð 	ˆKØ+/ÐÔ(Ø×%Ò% k¸EÐ%ÑBÔBÐBØ×ÒÑÔÐØ˜!‰OˆJˆJØÔ×Ò ¨ZÐ 8Ñ9Ô9Ð9Ð9Ð9r   c                óv   — |                      t          d         ¦  «        D ]}|                      |¦  «         ŒdS )zƒ
        Adds an expression long enough that it is split at
        each space symbol such that line wrapping could occur.
        ÚspaceN)ÚsplitÚsymbolsÚappendOrInsertCurrent)r   ÚlongExprÚbrailleExprs      r   ÚaddLongExpressionzBrailleText.addLongExpressionv   sE   € ð
 $Ÿ>š>­'°'Ô*:Ñ;Ô;ð 	4ð 	4ˆKØ×&Ò& {Ñ3Ô3Ð3Ð3ð	4ð 	4r   c                óæ   — |                       ¦   «          | j        s| j        r3|                      |¦  «         | j                             |d¬¦  «         dS | j                             d|¦  «         dS )u  
        Adds a NoteGrouping to a new line, prefacing that new line
        with the appropriate spaces or keyboard symbols and dots.

        >>> bt = braille.text.BrailleText(10)
        >>> bt.currentLine.append('hi', addSpace=False)
        >>> print(str(bt))
        hi
        >>> c = braille.lookup.pitchNameToNotes['C']['quarter']  # dots 1456
        >>> bt.addToNewLine(c + c + c)
        >>> print(str(bt))
        hi
        â €â €â ¹â ¹â ¹

        It is done differently if there are hand symbols involved:

        >>> bt = braille.text.BrailleText(10)
        >>> bt.showHand = 'right'
        >>> bt.currentLine.append('hi', addSpace=False)
        >>> bt.addToNewLine(c + c + c)
        >>> print(str(bt))
        hi
        â ¨â œâ „â ¹â ¹â ¹

        Fr/   é   N)r   r   r   Ú!optionalAddKeyboardSymbolsAndDotsr   r4   Úinsert)r   ÚbrailleNoteGroupings     r   ÚaddToNewLinezBrailleText.addToNewLine~   sƒ   € ð4 	×ÒÑÔÐØÔð 	< 4Ô#6ð 	<Ø×2Ò2Ð3FÑGÔGÐGØÔ×#Ò#Ð$7À%Ð#ÑHÔHÐHÐHÐHàÔ×#Ò# AÐ':Ñ;Ô;Ð;Ð;Ð;r   Tc                óØ   — | j                              ||¬¦  «        r| j                              ||¬¦  «         dS |                      ¦   «          | j                              d|¦  «         dS )u1  
        append expression to the current line if it is possible,
        or make a new line and insert it there:

        >>> bt = braille.text.BrailleText(lineLength=10)
        >>> bt.appendOrInsertCurrent('hello', addSpace=False)
        >>> print(str(bt))
        hello
        >>> bt.appendOrInsertCurrent(braille.lookup.symbols['space'] + 'hi')
        >>> print(str(bt))
        helloâ €â €hi
        >>> bt.appendOrInsertCurrent(braille.lookup.symbols['space'] + 'there')
        >>> print(str(bt))
        helloâ €â €hi
        â €â €â €there
        r/   rD   N)r   Ú	canAppendr4   r   rF   )r   rA   r0   s      r   r?   z!BrailleText.appendOrInsertCurrentŸ   su   € ð" Ô×%Ò% k¸HÐ%ÑEÔEð 	4ØÔ×#Ò# K¸(Ð#ÑCÔCÐCÐCÐCà×ÒÑÔÐØÔ×#Ò# A {Ñ3Ô3Ð3Ð3Ð3r   c                óv  — |                       |¦  «        }	 | j                             ||¬¦  «         nù# t          $ rì |                      ¦   «          | j        s| j        r¬| j        r'| j                             dt          d         ¦  «         n-| j        r&| j                             dt          d         ¦  «         t          |d         ¦  «        D ]}| j                             |d¬¦  «         Œ| j                             |d¬¦  «         n| j                             d|¦  «         Y nw xY wd| j        _
        d S )Nr/   rD   Úrh_keyboardÚlh_keyboardr   FT)rE   r   r4   r,   r   r   r   rF   r>   r   ÚcontainsNoteGrouping)r   Úinaccordr0   Údots       r   ÚaddInaccordzBrailleText.addInaccord¶   s[  € Ø×9Ò9¸(ÑCÔCˆð	5ØÔ×#Ò# H°xÐ#Ñ@Ô@Ð@Ð@øÝ#ð 	5ð 	5ð 	5Ø×ÒÑÔÐØÔ#ð 	5 tÔ':ð 	5ØÔ'ð GØÔ$×+Ò+¨A­w°}Ô/EÑFÔFÐFÐFØÔ(ð GØÔ$×+Ò+¨A­w°}Ô/EÑFÔFÐFÝ$ X¨a¤[Ñ1Ô1ð Að A�CØÔ$×+Ò+¨C¸%Ð+Ñ@Ô@Ð@Ð@ØÔ ×'Ò'¨¸5Ð'ÑAÔAÐAÐAàÔ ×'Ò'¨¨8Ñ4Ô4Ð4øøð	5øøøð 15ˆÔÔ-Ð-Ð-s   —4 ´C3D*Ä)D*c                óÎ   — t          |t          ¦  «        rt          |¦  «        }| j        j        dk    r|                      ¦   «          | j                             |d¬¦  «         dS )u   
        Add a measure number (either a braille number or an int).

        >>> bt = braille.text.BrailleText(lineLength=10)
        >>> bt
        <music21.braille.text.BrailleText 1 line, 0 headings, 10 cols>
        >>> bt.allLines
        [<music21.braille.text.BrailleTextLine 'â €â €â €â €â €â €â €â €â €â €'>]
        >>> bt.addMeasureNumber(4)
        >>> print(str(bt.allLines[0]))
        â ¼â ™
        >>> bt.currentLine.textLocation
        2

        If there are already lines, then add a new one:

        >>> bt.addMeasureNumber(5)
        >>> bt.allLines
        [<music21.braille.text.BrailleTextLine 'â ¼â ™â €â €â €â €â €â €â €â €'>,
         <music21.braille.text.BrailleTextLine 'â ¼â ‘â €â €â €â €â €â €â €â €'>]
        >>> print(str(bt.allLines[-1]))
        â ¼â ‘
        r   Fr/   N)Ú
isinstanceÚintr   r   r1   r   r4   )r   ÚmeasureNumbers     r   ÚaddMeasureNumberzBrailleText.addMeasureNumberÈ   sh   € õ0 �m¥SÑ)Ô)ð 	;Ý+¨MÑ:Ô:ˆMàÔÔ(¨AÒ-Ð-Ø×ÒÑÔÐØÔ×Ò ¸ÐÑ>Ô>Ð>Ð>Ð>r   c                ó°  — d}| j         j        sµ| j        s| j        r§| j         j        dk    rd}| j        r(| j                              t          d         |¬¦  «         n.| j        r'| j                              t          d         |¬¦  «         |r4t          |d         ¦  «        D ]}| j                              |d¬¦  «         Œd}| j         j        dk    rd}|S )zØ
        Adds symbols for rh_keyboard or lh_keyboard depending on what
        is appropriate

        returns a boolean indicating whether a space needs to be added
        before the next symbol is needed.
        Tr   FrL   r/   rM   )r   rN   r   r   r1   r4   r>   r   )r   ÚnoteGroupingr0   rP   s       r   rE   z-BrailleText.optionalAddKeyboardSymbolsAndDotsç   s  € ð ˆØÔ Ô5ð 	ØÔ)ð	Ø-1Ô-@ð	àÔÔ,°Ò1Ð1Ø �ØÔ#ð SØÔ ×'Ò'­°Ô(>ÈÐ'ÑRÔRÐRÐRØÔ$ð SØÔ ×'Ò'­°Ô(>ÈÐ'ÑRÔRÐRØð AÝ$ \°!¤_Ñ5Ô5ð Að A�CØÔ$×+Ò+¨C¸%Ð+Ñ@Ô@Ð@Ð@ØˆHàÔÔ(¨AÒ-Ð-ØˆHàˆr   c                ó\   — d}| j         j        dk    rd}|                      ||¬¦  «         dS )u  
        Appends signatures to the current location if there is space, otherwise appends to
        a new line:

        >>> bt = braille.text.BrailleText(lineLength=5)
        >>> bt.addSignatures(braille.basic.timeSigToBraille(meter.TimeSignature('4/8')))
        >>> print(str(bt.currentLine))
        â ¼â ™â ¦
        >>> bt.addSignatures(braille.basic.timeSigToBraille(meter.TimeSignature('3/4')))
        >>> print(str(bt.currentLine))
        â €â €â ¼â ‰â ²
        >>> len(bt.allLines)
        2
        Tr   Fr/   N)r   r1   r?   )r   Ú
signaturesr0   s      r   ÚaddSignatureszBrailleText.addSignatures  s>   € ð ˆØÔÔ(¨AÒ-Ð-ØˆHà×"Ò" :¸Ð"ÑAÔAÐAÐAÐAr   c                óv   — t          | j        ¦  «        | _        | j                             | j        ¦  «         dS )a  
        Add a newline to the BrailleText

        >>> bt = braille.text.BrailleText(lineLength=10)
        >>> len(bt.allLines)
        1
        >>> bt.makeNewLine()
        >>> len(bt.allLines)
        2
        >>> bt.makeNewLine()
        >>> len(bt.allLines)
        3
        N)ÚBrailleTextLiner   r   r   r4   r(   s    r   r   zBrailleText.makeNewLine  s5   € õ +¨4¬?Ñ;Ô;ˆÔØŒ×Ò˜TÔ-Ñ.Ô.Ð.Ð.Ð.r   c                ó  — | j         D �]\  }}d}t          |t          | j        ¦  «        ¦  «        D ]8}| j        |         j        r n#| j        |         j        }t          ||¦  «        }Œ9t          ||¦  «        D ]�}| j        |         }t          |¦  «        }|                     t          d         ¦  «        }|t          |¦  «        k    r>| 
                    |t          d         ¦  «        }|                     d|¦  «         ||_        Œ��ŒdS )u'  
        Recenter each of the headings so that they exactly align
        with the text beneath them.

        Demonstration with non braille text:

        >>> heading1 = 'hello'
        >>> body1 = 'anyoneHome?' + braille.lookup.symbols['space'] + 'yup!'
        >>> bt = braille.text.BrailleText(lineLength=12)
        >>> bt.addHeading(heading1)
        >>> bt.addLongExpression(body1)
        >>> bt.allHeadings
        [(0, 1)]
        >>> bt.recenterHeadings()
        >>> print(str(bt))
        â €â €â €helloâ €â €â €â €
        â €anyoneHome?
        â €â €yup!

        Each heading is aligned with its own text

        >>> heading2 = 'buh'
        >>> body2 = 'short' + braille.lookup.symbols['space'] + 'court'
        >>> bt.addHeading(heading2)
        >>> bt.addLongExpression(body2)
        >>> bt.allHeadings
        [(0, 1), (3, 4)]
        >>> bt.recenterHeadings()
        >>> print(str(bt))
        â €â €â €helloâ €â €â €â €
        â €anyoneHome?
        â €â €yup!
        â €â €â €â €buhâ €â €â €â €â €
        â €shortâ €court
        r   r<   N)r   Úranger    r   r3   r1   Úmaxr   Ústripr>   ÚcenterrF   )	r   r6   r7   ÚmaxLineLengthÚir   ÚjÚbrailleTextLineÚlineStrToCenters	            r   ÚrecenterHeadingszBrailleText.recenterHeadings(  s(  € ðH )-Ô(8ð 	Añ 	AÑ$ˆZ˜ØˆMÝ˜:¥s¨4¬=Ñ'9Ô'9Ñ:Ô:ð ?ð ?�Ø”= Ô#Ô-ð Ø�EØ!œ]¨1Ô-Ô:�
Ý # M°:Ñ >Ô >��Ý˜: zÑ2Ô2ð Að A�Ø"&¤-°Ô"2�Ý"% oÑ"6Ô"6�Ø"1×"7Ò"7½ÀÔ8HÑ"IÔ"I�Ø ¥3 Ñ#7Ô#7Ò7Ð7Ø&5×&<Ò&<¸]ÍGÐT[ÔL\Ñ&]Ô&]�OØ#×*Ò*¨1¨oÑ>Ô>Ð>Ø3@�OÔ0øñAð	Að 	Ar   c                ór   — |                       ¦   «          d                     d„ | j        D ¦   «         ¦  «        S )Nú
c                ó,   — g | ]}t          |¦  «        ‘ŒS © )r   )Ú.0Úlines     r   ú
<listcomp>z'BrailleText.__str__.<locals>.<listcomp>^  s   € Ð>Ð>Ð>¨�#˜d™)œ)Ð>Ð>Ð>r   )rh   Újoinr   r(   s    r   Ú__str__zBrailleText.__str__\  s7   € Ø×ÒÑÔÐØ�yŠyÐ>Ð>°´Ð>Ñ>Ô>Ñ?Ô?Ð?r   )r   N©r   r   ©Tr'   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   Úpropertyr   Úsetterr:   rB   rH   r?   rQ   rV   rE   r[   r   rh   rq   rl   r   r   r
   r
      sB  € € € € € ðð ð"!ð !ð !ð !ðDð Dð Dð Dð ðð ñ „Xðð „_ðEð Eñ „_ðEð*:ð *:ð *:ðX4ð 4ð 4ð<ð <ð <ðB4ð 4ð 4ð 4ð.5ð 5ð 5ð$?ð ?ð ?ð>ð ð ð ð6Bð Bð Bð*/ð /ð /ð"2Að 2Að 2Aðh@ð @ð @ð @ð @r   r
   c                  ó0   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zˆ xZS )ÚBrailleKeyboardzD
    A subclass of BrailleText that handles both hands at once.
    r   c                óv   •— t          ¦   «                              |¬¦  «         d | _        d | _        d| _        d S )N)r   r   )Úsuperr   ÚrightHandLineÚleftHandLineÚhighestMeasureNumberLength)r   r   Ú	__class__s     €r   r   zBrailleKeyboard.__init__f  s<   ø€ Ý‰Œ×Ò JÐÑ/Ô/Ð/Ø!ˆÔØ ˆÔØ*+ˆÔ'Ð'Ð'r   c                ó   — | j         j        dk    r| j         | _        n8t          | j        ¦  «        | _        | j                             | j        ¦  «         t          | j        ¦  «        | _        | j                             | j        ¦  «         d S )Nr   )r   r1   r~   r]   r   r   r4   r   r(   s    r   ÚmakeNewLineszBrailleKeyboard.makeNewLiness  s}   € ØÔÔ(¨AÒ-Ð-Ø!%Ô!1ˆDÔÐå!0°´Ñ!AÔ!AˆDÔØŒM× Ò  Ô!3Ñ4Ô4Ð4å+¨D¬OÑ<Ô<ˆÔØŒ×Ò˜TÔ.Ñ/Ô/Ð/Ð/Ð/r   c                ó`  — | j         €| j        €|                      ¦   «          | j         j        dk    rF| j                              | j        t          |¦  «        z
  |¦  «         | j         j        | j        _        d}| j         j        du r¼d}| j                              t          d         d¬¦  «         | j                             t          d         d¬¦  «         |r4t          |d         ¦  «        D ]}| j                              |d¬¦  «         Œ|r4t          |d         ¦  «        D ]}| j                             |d¬¦  «         Œ| j                              ||¬¦  «        r¢| j                             ||¬¦  «        r†|r| j                             ||¬¦  «         |r| j                              ||¬¦  «         | j         j        | j        j        k    r| j         j        | j        _        �n«| j        j        | j         _        �n“|                      ¦   «          | j                              | j        t          |¦  «        z
  |¦  «         | j         j        | j        _        | j                              t          d         d¬¦  «         | j                             t          d         d¬¦  «         |rPt          |d         ¦  «        D ]}| j                              |d¬¦  «         Œ| j                              |d¬¦  «         |rPt          |d         ¦  «        D ]}| j                             |d¬¦  «         Œ| j                             |d¬¦  «         | j         j        | j        j        k    r| j         j        | j        _        n| j        j        | j         _        d| j         _        d| j        _        d S )Nr   TFrL   r/   rM   )r~   r   rƒ   r1   rF   r€   r    rN   r4   r>   r   rJ   )r   rU   ÚnoteGroupingRÚnoteGroupingLr0   rP   s         r   ÚaddNoteGroupingsz BrailleKeyboard.addNoteGroupings}  sØ  € ØÔÐ%¨$Ô*;Ð*CØ×ÒÑÔÐØÔÔ*¨aÒ/Ð/ØÔ×%Ò% dÔ&EÍÈMÑHZÔHZÑ&ZØ&3ñ5ô 5ð 5à-1Ô-?Ô-LˆDÔÔ*ØˆØÔÔ2°eÐ;Ð;ØˆHØÔ×%Ò%¥g¨mÔ&<ÀtÐ%ÑLÔLÐLØÔ×$Ò$¥W¨]Ô%;ÀdÐ$ÑKÔKÐKØð CÝ$ ]°1Ô%5Ñ6Ô6ð Cð C�CØÔ&×-Ò-¨c¸EÐ-ÑBÔBÐBÐBØð BÝ$ ]°1Ô%5Ñ6Ô6ð Bð B�CØÔ%×,Ò,¨S¸5Ð,ÑAÔAÐAÐAØÔ×(Ò(¨ÀÐ(ÑJÔJð 	QØÔ%×/Ò/°ÈÐ/ÑQÔQð	Qàð KØÔ!×(Ò(¨ÀÐ(ÑJÔJÐJØð LØÔ"×)Ò)¨-À(Ð)ÑKÔKÐKØÔ!Ô.°Ô1BÔ1OÒOÐOØ15Ô1CÔ1P�Ô!Ô.Ñ.à26Ô2CÔ2P�Ô"Ô/Ñ/à×ÒÑÔÐØÔ×%Ò% dÔ&EÍÈMÑHZÔHZÑ&ZØ&3ñ5ô 5ð 5à-1Ô-?Ô-LˆDÔÔ*ØÔ×%Ò%¥g¨mÔ&<ÀtÐ%ÑLÔLÐLØÔ×$Ò$¥W¨]Ô%;ÀdÐ$ÑKÔKÐKØð IÝ$ ]°1Ô%5Ñ6Ô6ð Cð C�CØÔ&×-Ò-¨c¸EÐ-ÑBÔBÐBÐBØÔ"×)Ò)¨-À%Ð)ÑHÔHÐHàð HÝ$ ]°1Ô%5Ñ6Ô6ð Bð B�CØÔ%×,Ò,¨S¸5Ð,ÑAÔAÐAÐAØÔ!×(Ò(¨ÀÐ(ÑGÔGÐGØÔ!Ô.°Ô1BÔ1OÒOÐOØ15Ô1CÔ1P�Ô!Ô.Ð.à26Ô2CÔ2P�Ô"Ô/Ø26ˆÔÔ/Ø15ˆÔÔ.Ð.Ð.r   ©r   )rt   ru   rv   rw   r   rƒ   r‡   Ú__classcell__)r�   s   @r   r{   r{   a  se   ø€ € € € € ðð ð,ð ,ð ,ð ,ð ,ð ,ð0ð 0ð 0ð16ð 16ð 16ð 16ð 16ð 16ð 16r   r{   c                  óL   — e Zd ZdZddd„Zdd„Zdd
„Zd„ Zdd„Zd„ Z	d„ Z
d„ ZdS )r]   uT  
    An object representing a single line of braille text:

    The initial value is the length of the line:

    >>> btl = braille.text.BrailleTextLine(40)
    >>> btl
    <music21.braille.text.BrailleTextLine 'â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €'>
    >>> btl.isHeading
    False
    >>> btl.containsNoteGrouping
    False
    >>> btl.lineLength
    40
    >>> btl.textLocation
    0
    >>> btl.highestUsedLocation
    0
    >>> btl.allChars == 40 * [braille.lookup.symbols['space']]
    True

    >>> btl.append(braille.lookup.symbols['tie'])
    >>> btl
    <music21.braille.text.BrailleTextLine 'â €â ˆâ ‰â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €â €'>
    >>> print(str(btl))
    â €â ˆâ ‰
    r   r   rT   c                ó‚   — d| _         d| _        || _        | j        t          d         gz  | _        d| _        d| _        d S )NFr<   r   )r3   rN   r   r>   ÚallCharsr1   ÚhighestUsedLocation)r   r   s     r   r   zBrailleTextLine.__init__Í  sD   € ØˆŒØ$)ˆÔ!Ø$ˆŒØœ­7°7Ô+;Ð*<Ñ<ˆŒØˆÔØ#$ˆÔ Ð Ð r   r   r   c                óP   — t          d                     | j        ¦  «        ¦  «        S )Nr   )Úreprrp   rŒ   r(   s    r   r%   zBrailleTextLine._reprInternalÕ  s   € Ý�B—H’H˜Tœ]Ñ+Ô+Ñ,Ô,Ð,r   Tc                ó"  — |                       ||¦  «        st          d¦  «        ‚|r*t          d         | j        | j        <   | xj        dz  c_        t          |¦  «        D ]!}|| j        | j        <   | xj        dz  c_        Œ"| j        | _        dS )u  
        Appends text (with optional space at the beginning) or raises an
        exception if it cannot be appended.

        >>> btl = braille.text.BrailleTextLine(6)
        >>> btl.append(braille.lookup.symbols['tie'], addSpace=False)
        >>> print(str(btl))
        â ˆâ ‰
        >>> btl.textLocation
        2
        >>> btl.highestUsedLocation
        2

        Default is to add a space:

        >>> btl.append(braille.lookup.symbols['tie'])
        >>> print(str(btl))
        â ˆâ ‰â €â ˆâ ‰

        Out of room:

        >>> btl.append(braille.lookup.symbols['tie'])
        Traceback (most recent call last):
        music21.braille.text.BrailleTextException: Text does not fit at end of braille text line.

        Text is appended at `textLocation`, overwriting other text that might be there.

        >>> btl.textLocation = btl.highestUsedLocation = 0
        >>> btl.append('hi', addSpace=False)
        >>> btl.textLocation = btl.highestUsedLocation = 5
        >>> print(str(btl))
        hiâ €â ˆâ ‰
        z.Text does not fit at end of braille text line.r<   r   N)rJ   r,   r>   rŒ   r1   Úlistr�   )r   Útextr0   Úchars       r   r4   zBrailleTextLine.appendØ  s§   € ðD �~Š~˜d HÑ-Ô-ð 	YÝ&Ð'WÑXÔXÐXØð 	#Ý/6°wÔ/?ˆDŒM˜$Ô+Ñ,ØÐÔ Ñ"ÐÔÝ˜‘J”Jð 	#ð 	#ˆDØ/3ˆDŒM˜$Ô+Ñ,ØÐÔ Ñ"ÐÔÐØ#'Ô#4ˆÔ Ð Ð r   c                óþ   — |                       ||¦  «        st          d¦  «        ‚t          ||¬¦  «        D ]\  }}|| j        |<   Œ|t	          |¦  «        z   | _        t          | j        | j        ¦  «        | _        dS )u)  
        Inserts text at a certain location, updating textLocation and possibly
        highestUsedLocation:

        >>> btl = braille.text.BrailleTextLine(6)
        >>> btl.insert(2, braille.lookup.symbols['tie'])
        >>> print(str(btl))
        â €â €â ˆâ ‰
        >>> btl.textLocation
        4
        >>> btl.highestUsedLocation
        4

        >>> btl.insert(0, braille.lookup.symbols['tie'])

        It looks like we have deleted the previous tie:

        >>> print(str(btl))
        â ˆâ ‰

        But that's because only characters up to .textLocation are printed
        (this may change later)

        >>> btl.textLocation
        2
        >>> btl.highestUsedLocation
        4

        Let's change textLocation and now see:

        >>> btl.textLocation = btl.highestUsedLocation
        >>> print(str(btl))
        â ˆâ ‰â ˆâ ‰

        Inserting beyond the end creates an error:

        >>> btl.insert(5, braille.lookup.symbols['tie'])
        Traceback (most recent call last):
        music21.braille.text.BrailleTextException: Text cannot be inserted at specified location.

        Unlike list inserts, this insert overwrites the previous text:

        >>> btl.insert(0, 'hi')
        >>> btl.textLocation = btl.highestUsedLocation
        >>> print(str(btl))
        hiâ ˆâ ‰
        z.Text cannot be inserted at specified location.)ÚstartN)Ú	canInsertr,   Ú	enumeraterŒ   r    r1   r`   r�   )r   r1   r’   rd   r“   s        r   rF   zBrailleTextLine.insert  s‹   € ð` �~Š~˜l¨DÑ1Ô1ð 	YÝ&Ð'WÑXÔXÐXÝ  ¨\Ð:Ñ:Ô:ð 	$ð 	$‰GˆAˆtØ#ˆDŒM˜!ÑÐØ(­3¨t©9¬9Ñ4ˆÔÝ#& tÔ'?ÀÔARÑ#SÔ#SˆÔ Ð Ð r   c                ó†   — t          | j        | j        ¦  «        }|rdnd}|t          |¦  «        z   |z   | j        k    rdS dS )a<  
        Returns True if there is enough space in this line to append the text, or False
        if not:

        >>> btl = braille.text.BrailleTextLine(10)
        >>> btl.canAppend('1234567890', addSpace=False)
        True
        >>> btl.canAppend('12345678901', addSpace=False)
        False
        >>> btl.canAppend('1234567890', addSpace=True)
        False
        >>> btl.textLocation
        0
        >>> btl.textLocation = 5
        >>> btl.canAppend('12345', addSpace=False)
        True
        >>> btl.canAppend('123456', addSpace=False)
        False

        If highestUsedLocation > textLocation, highestUsedLocation is used instead:

        >>> btl.highestUsedLocation = 7
        >>> btl.canAppend('123', addSpace=False)
        True
        >>> btl.canAppend('1234', addSpace=False)
        False
        r   r   FT)r`   r�   r1   r    r   )r   r’   r0   ÚsearchLocationÚaddSpaceAmounts        r   rJ   zBrailleTextLine.canAppend;  sN   € õ8 ˜TÔ5°tÔ7HÑIÔIˆØ&Ð-˜˜¨AˆØ�S ™YœYÑ&¨Ñ7¸4¼?ÒJÐJØ�5à�4r   c                ó@   — |t          |¦  «        z   | j        k    rdS dS )a  
        Returns True if there is enough space starting at textLocation to append
        the text. False otherwise:

        >>> btl = braille.text.BrailleTextLine(10)
        >>> btl.canInsert(4, '123456')
        True
        >>> btl.canInsert(5, '123456')
        False
        FT)r    r   )r   r1   r’   s      r   r–   zBrailleTextLine.canInsert^  s&   € ð �#˜d™)œ)Ñ# d¤oÒ5Ð5Ø�5à�4r   c                ó´   — | j         dz
  }|dk     rdS | j        |         }|t          d         k    r't          d         | j        |<   | xj         dz  c_         dS dS )u:  
        Occasionally a line ends with a hyphen because
        the last appender thought it would be helpful, such as
        to put more characters into a line.  But in case it
        is not, then this method will change that last character
        to a space and set textLocation back one character,
        so it is not printed.

        >>> bt = braille.text.BrailleTextLine(10)
        >>> bt.append('hi', addSpace=False)
        >>> bt.append(braille.lookup.symbols['music_hyphen'], addSpace=False)
        >>> print(str(bt))
        hiâ �
        >>> bt.textLocation
        3
        >>> print(bt.allChars[2])
        â �
        >>> bt.lastHyphenToSpace()
        >>> print(str(bt))
        hi
        >>> bt.allChars[2] == braille.lookup.symbols['space']
        True
        >>> bt.textLocation
        2
        r   r   NÚmusic_hyphenr<   )r1   rŒ   r>   )r   ÚprevLocÚprevChars      r   ÚlastHyphenToSpacez!BrailleTextLine.lastHyphenToSpacen  sn   € ð4 Ô# aÑ'ˆØ�QŠ;ˆ;ØˆFØ”= Ô)ˆØ•w˜~Ô.Ò.Ð.Ý%,¨WÔ%5ˆDŒM˜'Ñ"ØÐÔ Ñ"ÐÔÐÐð /Ð.r   c                óP   — d                      | j        d| j        …         ¦  «        S )Nr   r   )rp   rŒ   r1   r(   s    r   rq   zBrailleTextLine.__str__�  s#   € Ø�wŠw�t”} Q tÔ'8Ð%8Ô9Ñ:Ô:Ð:r   Nrˆ   )r   rT   rr   rs   )rt   ru   rv   rw   r   r%   r4   rF   rJ   r–   r    rq   rl   r   r   r]   r]   ±  s¶   € € € € € ðð ð6%ð %ð %ð %ð %ð-ð -ð -ð -ð*5ð *5ð *5ð *5ðX5Tð 5Tð 5Tðn!ð !ð !ð !ðFð ð ð  #ð  #ð  #ðD;ð ;ð ;ð ;ð ;r   r]   c                  ó   — e Zd ZdS )r,   N©rt   ru   rv   rl   r   r   r,   r,   –  ó   € € € € € Ø€Dr   r,   c                  ó   — e Zd ZdS )ÚTestNr£   rl   r   r   r¦   r¦   œ  r¤   r   r¦   Ú__main__)Ú
__future__r   ÚunittestÚmusic21r   r   Úmusic21.brailler   Úmusic21.braille.basicr   r   r>   ÚProtoM21Objectr
   r{   r]   ÚMusic21Exceptionr,   ÚTestCaser¦   rt   ÚmainTestrl   r   r   ú<module>r±      s¯  ðð #Ð "Ð "Ð "Ð "Ð "à €€€à  Ð  Ð  Ð  Ð  Ð  Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ø <Ð <Ð <Ð <Ð <Ð <Ð <Ð <à
Œ.€ðH@ð H@ð H@ð H@ð H@�'Ô(ñ H@ô H@ð H@ðV
M6ð M6ð M6ð M6ð M6�kñ M6ô M6ð M6ð``;ð `;ð `;ð `;ð `;�gÔ,ñ `;ô `;ð `;ðJ	ð 	ð 	ð 	ð 	˜<Ô8ñ 	ô 	ð 	ð	ð 	ð 	ð 	ð 	ˆ8Ôñ 	ô 	ð 	ð ˆzÒÐØ€N€N€NØ€GÔ�TÑÔÐÐÐð Ðr   