
    3jY                       d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ej                  rddlmZ  G d d	ej                        Z G d
 dej                        Z G d de
      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d dej2                        Z G d dej6                        Zed k(  rddlZ ej<                  e       yy)!z
The style module represents information about the style of a Note, Accidental,
etc. such that precise positioning information, layout, size, etc. can be specified.
    )annotationsN)common)exceptions21)ProtoM21Object	editorialc                      e Zd Zy)TextFormatExceptionN__name__
__module____qualname__     :/DATA/.local/lib/python3.12/site-packages/music21/style.pyr
   r
          r   r
   c                  H    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZy)	Enclosure	rectanglesquareovalcirclebrackettrianglediamondpentagonhexagonheptagonoctagonnonagondecagonzinverted-bracketnoneN)r   r   r   	RECTANGLESQUAREOVALCIRCLEBRACKETTRIANGLEDIAMONDPENTAGONHEXAGONHEPTAGONOCTAGONNONAGONDECAGONINVERTED_BRACKETNO_ENCLOSUREr   r   r   r   r       sN    IFDFGHGHGHGGG)Lr   r   c                      e Zd ZU dZdddZded<   ddZedd       Zej                  dd	       Zd
 Z
d Z ee
ed      Zy)Stylea  
    A style object is a lightweight object that
    keeps track of information about the look of an object.

    >>> st = style.Style()
    >>> st.units
    'tenths'
    >>> st.absoluteX is None
    True

    >>> st.absoluteX = 20.4
    >>> st.absoluteX
    20.4

    z
            If set to `True`, the Music21Object will not print upon output
            (only used in MusicXML output at this point and
            in Lilypond output for notes, chords, and rests).
            z
            What distances are measured in.  The default "tenths" is a concept
            borrowed from MusicXML which refers to 1/10th of the distance between
            two staff lines.  It is currently also the only supported unit.
            )hideObjectOnPrintunitsdict[str, str]	_DOC_ATTRc                    d | _         d | _        d | _        d | _        d | _        d | _        d | _        d | _        d| _        d| _	        d | _
        d | _        y )NtenthsF)size	relativeX	relativeY	absoluteX
_absoluteY
_enclosurefontRepresentationcolorr5   r4   
dashLengthspaceLengthselfs    r   __init__zStyle.__init__O   s_    	)-)-)- +/ +/ #'#
"
',*.+/r   c                    | j                   S )a  
        Get or set the enclosure as a style.Enclosure enum (or
        None, which means the enclosure is left unspecified).

        Valid names are:

        * "rectangle"/style.Enclosure.RECTANGLE,
        * "square"/style.Enclosure.SQUARE,
        * "oval"/style.Enclosure.OVAL,
        * "circle"/style.Enclosure.CIRCLE,
        * "bracket"/style.Enclosure.BRACKET,
        * "inverted-bracket"/style.Enclosure.INVERTED_BRACKET (output in musicxml 4 only)
        * "none"/style.Enclosure.NO_ENCLOSURE
        * None (i.e. enclosure is unspecified)

        or the following other shapes with their ALLCAPS Enclosure equivalents:

        triangle, diamond, pentagon, hexagon, heptagon, octagon,
        nonagon, or decagon.

        >>> tst = style.TextStyle()
        >>> tst.enclosure = None
        >>> tst.enclosure = style.Enclosure.RECTANGLE
        >>> tst.enclosure
        <Enclosure.RECTANGLE>

        Setting as a string is still supported, but is converted to
        an enum.

        >>> tst.enclosure = 'octagon'
        >>> tst.enclosure
        <Enclosure.OCTAGON>

        Setting an invalid enclosure raises a TextFormatException

        >>> tst.enclosure = 'parabola'
        Traceback (most recent call last):
        music21.style.TextFormatException:
            Not a supported enclosure: 'parabola'

        OMIT_FROM_DOCS

        Similarly for non-strings:

        >>> tst.enclosure = 4
        Traceback (most recent call last):
        music21.style.TextFormatException:
            Not a supported enclosure: 4

        * Changed in v9.7: We now differentiate between no enclosure
          (Enclosure.NO_ENCLOSURE) and unspecified enclosure (None).
        )r?   rD   s    r   	enclosurezStyle.enclosurej   s    l r   c                   ||| _         y t        |t              r|| _         y t        |t              r"	 t        |j	                               }|| _         y t        d|      # t
        $ r}t        d|      |d }~ww xY w)NzNot a supported enclosure: )r?   
isinstancer   strlower
ValueErrorr
   )rE   value	enc_valueves       r   rH   zStyle.enclosure   s    =#DOy)#DOs#[%ekkm4	 (DO &(CE9&MNN  [),Gy*QRXZZ[s   A# #	B ,A;;B c                    | j                   S N)r>   rD   s    r   _getAbsoluteYzStyle._getAbsoluteY   s    r   c                    |d | _         y |dk(  rd| _         y |dk(  rd| _         y 	 t        j                  |      | _         y # t        $ r}t	        d|      |d }~ww xY w)Nabove
   belowiz$Not a supported absoluteY position: )r>   r   numToIntOrFloatrM   r
   rE   rN   rP   s      r   _setAbsoluteYzStyle._setAbsoluteY   sm    ="DOg DOg!DO"("8"8"? ):5)Ds   A 	A
AAa\  
        Get or set the vertical position, where 0
        is the top line of the staff and units
        are whatever is defined in `.units`, generally "tenths", meaning
        1/10th of a staff space.

        Other legal positions are 'above' and 'below' which
        are synonyms for 10 and -70 respectively (for 5-line
        staves; other staves are not yet implemented)
        This behavior may change in music21 v8 or after.

        >>> te = style.Style()
        >>> te.absoluteY = 10
        >>> te.absoluteY
        10

        >>> te.absoluteY = 'below'
        >>> te.absoluteY
        -70

        Setting an invalid position raises a TextFormatException

        >>> te.absoluteY = 'hello'
        Traceback (most recent call last):
        music21.style.TextFormatException:
            Not a supported absoluteY position: 'hello'
        docNreturnNone)r^   zEnclosure | None)rN   zEnclosure | str | None)r   r   r   __doc__r7   __annotations__rF   propertyrH   setterrS   rZ   	absoluteYr   r   r   r3   r3   2   su     
!I~ 06 5 5n O O  &Ir   r3   c                  <     e Zd ZU dZddddZded<   d	 fdZ xZS )
	NoteStylez
    A Style object that also includes stem and accidental style information.

    Beam style is stored on the Beams object.  Lyric style is stored on the Lyric
    object.
    a  
            An optional style.Style object describing what the stem looks like.

            >>> n = note.Note()
            >>> n.style.stemStyle is None
            True

            Note that stemStyle is not created automatically.  Users must
            instantiate a :class:`~music21.style.Style` object.

            >>> n.style.stemStyle = style.Style()
            >>> n.style.stemStyle.color = 'red'
            a  
            An optional style.Style object describing what the accidental looks like.

            >>> n = note.Note()
            >>> n.style.accidentalStyle is None
            True

            Note that accidentalStyle is not created automatically.  Users must
            instantiate a :class:`~music21.style.Style` object.

            >>> n.style.accidentalStyle = style.Style()
            >>> n.style.accidentalStyle.relativeX = -2.0

            Note: do not use .hideObjectOnPrint in accidentalStyle to hide the
            accidental.  Set the displayType on the Accidental itself.

            This object may eventually move to Note.pitch.accidental.style.
            a	  
            An optional string representing the size of the note as a type of note.

            Valid values are None (=normal), `'cue'`, `'grace'`, `'graceCue'`, and `'large'`
            (taken from MusicXML, with "graceCue" replacing "grace-cue").
            )	stemStyleaccidentalStylenoteSizer6   r7   c                L    t         |           d | _        d | _        d | _        y rR   )superrF   rg   rh   ri   rE   	__class__s    r   rF   zNoteStyle.__init__  s$    %)+/"&r   r]   )r   r   r   r`   r7   ra   rF   __classcell__rm   s   @r   rf   rf      s1    $A&!I~ &P' 'r   rf   c                  p    e Zd ZdZ fdZd Zd Z eeed      Zd Z	d Z
 ee	e
d	      Zedd
       Zej                  dd       Zedd       Zej                  dd       Zd Zd Z eeed      Zd Zd Z eeed      Zd Zd Z eeed      Zed        Zej                  d        Z xZS )	TextStylez
    A Style object that also includes text formatting.

    >>> ts = style.TextStyle()
    >>> ts.classes
    ('TextStyle', 'Style', 'ProtoM21Object', 'object')
    c                    t         |           d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _	        d | _
        d | _        d | _        d | _        d | _        y rR   )rk   rF   _fontFamily	_fontSize
_fontStyle_fontWeight_letterSpacing
lineHeighttextDirectiontextRotationlanguagetextDecoration_justify_alignHorizontal_alignVerticalrl   s    r   rF   zTextStyle.__init__#  sq    "! " $"r   c                    | j                   S rR   )r   rD   s    r   _getAlignVerticalzTextStyle._getAlignVertical6      """r   c                6    |dv r|| _         y t        d|      )N)NtopmiddlebottombaselinezInvalid vertical align: )r   r
   rE   rN   s     r   _setAlignVerticalzTextStyle._setAlignVertical9  s&    AA"'D%(@	&JKKr   a  
        Get or set the vertical align. Valid values are top, middle, bottom, baseline
        or None

        >>> te = style.TextStyle()
        >>> te.alignVertical = 'top'
        >>> te.alignVertical
        'top'

        Invalid vertical aligns raise a TextFormatException:

        >>> te.alignVertical = 'hello'
        Traceback (most recent call last):
        music21.style.TextFormatException:
            Invalid vertical align: 'hello'
        r[   c                    | j                   S rR   )r~   rD   s    r   _getAlignHorizontalzTextStyle._getAlignHorizontalS  s    $$$r   c                6    |dv r|| _         y t        d|      )N)NleftrightcenterzInvalid horizontal align: )r~   r
   r   s     r   _setAlignHorizontalzTextStyle._setAlignHorizontalV  s&    55$)D!%(B5)&LMMr   a  
        Get or set the horizontal alignment.  Valid values are left, right, center,
        or None

        >>> te = style.TextStyle()
        >>> te.alignHorizontal = 'right'
        >>> te.alignHorizontal
        'right'

        Invalid horizontal aligns raise a TextFormatException:

        >>> te.alignHorizontal = 'hello'
        Traceback (most recent call last):
        music21.style.TextFormatException:
            Invalid horizontal align: 'hello'
        c                    | j                   S )a  
        Get or set the justification.  Valid values are left,
        center, right, full (not supported by MusicXML), and None

        >>> tst = style.TextStyle()
        >>> tst.justify = 'center'
        >>> tst.justify
        'center'

        Invalid values raise a TextFormatException

        >>> tst.justify = 'hello'
        Traceback (most recent call last):
        music21.style.TextFormatException:
            Not a supported justification: 'hello'
        )r}   rD   s    r   justifyzTextStyle.justifyp  s    $ }}r   c                    |d | _         y |j                         dvrt        d|      |j                         | _         y )N)r   r   r   fullzNot a supported justification: )r}   rL   r
   r   s     r   r   zTextStyle.justify  s=    = DM{{}$GG),KE9*UVV!KKMDMr   c                    | j                   S )a  
        Get or set the style, as normal, italic, bold, and bolditalic.
        None is currently an acceptable value which should be "normal".

        >>> tst = style.TextStyle()
        >>> tst.fontStyle = 'bold'
        >>> tst.fontStyle
        'bold'

        Invalid values raise a TextFormatException

        >>> tst.fontStyle = 'hello'
        Traceback (most recent call last):
        music21.style.TextFormatException:
            Not a supported fontStyle: 'hello'
        )ru   rD   s    r   	fontStylezTextStyle.fontStyle  s    $ r   c                    |d | _         y |j                         dvrt        d|      |j                         | _         y )N)italicnormalbold
bolditaliczNot a supported fontStyle: )ru   rL   r
   r   s     r   r   zTextStyle.fontStyle  s=    ="DO{{}$NN),Gy*QRR#kkmDOr   c                    | j                   S rR   )rv   rD   s    r   
_getWeightzTextStyle._getWeight  s    r   c                    |d | _         y |j                         dvrt        d|       |j                         | _         y )N)r   r   zNot a supported fontWeight: )rv   rL   r
   r   s     r   
_setWeightzTextStyle._setWeight  s?    =#D{{}$66),H*PQQ${{}Dr   z
        Get or set the weight, as normal, or bold.

        >>> tst = style.TextStyle()
        >>> tst.fontWeight = 'bold'
        >>> tst.fontWeight
        'bold'
        c                    | j                   S rR   )rt   rD   s    r   _getSizezTextStyle._getSize  s    ~~r   c                ~    |	 t        j                  |      }|| _        y || _        y # t        $ r
 Y || _        y w xY wrR   )r   rX   rM   rt   r   s     r   _setSizezTextStyle._setSize  sG    ..u5   s   ) 	<<z
        Get or set the size.  Best, an int or float, but also a css font size

        >>> tst = style.TextStyle()
        >>> tst.fontSize = 20
        >>> tst.fontSize
        20
        c                    | j                   S rR   )rw   rD   s    r   _getLetterSpacingzTextStyle._getLetterSpacing  r   r   c                    |dk7  r|	 t        |      }|| _        y || _        y # t        $ r}t        d|      |d }~ww xY w)Nr   zNot a supported letterSpacing: )floatrM   r
   rw   rY   s      r   _setLetterSpacingzTextStyle._setLetterSpacing  sZ    H!2e $e  )5eY?s   $ 	A<Az
         Get or set the letter spacing.

        >>> tst = style.TextStyle()
        >>> tst.letterSpacing = 20
        >>> tst.letterSpacing
        20.0
        >>> tst.letterSpacing = 'normal'
        c                @    | j                   g | _         | j                   S )aH  
        Returns a list of font family names associated with
        the style, or sets the font family name list.

        If a single string is passed then it is converted to
        a list.

        >>> ts = style.TextStyle()
        >>> ff = ts.fontFamily
        >>> ff
        []
        >>> ff.append('Times')
        >>> ts.fontFamily
        ['Times']
        >>> ts.fontFamily.append('Garamond')
        >>> ts.fontFamily
        ['Times', 'Garamond']
        >>> ts.fontFamily = 'Helvetica, sans-serif'
        >>> ts.fontFamily
        ['Helvetica', 'sans-serif']
        )rs   rD   s    r   
fontFamilyzTextStyle.fontFamily  s$    . #!Dr   c                    t        j                  |      r|| _        y |j                  d      D cg c]  }|j	                          c}| _        y c c}w )N,)r   
isIterablers   splitstrip)rE   	newFamilyfs      r   r   zTextStyle.fontFamily  sC    Y'(D3<??33GH3Ga	3GHDHs   A)r^   
str | None)rN   r   )rN   r   r^   r_   )r   r   r   r`   rF   r   r   rb   alignVerticalr   r   alignHorizontalr   rc   r   r   r   
fontWeightr   r   fontSizer   r   letterSpacingr   rn   ro   s   @r   rq   rq     s<   #&#L .."M&%N 22$O(  & ^^* *  & , , - *$	J  	H#
$ .."
M    4 I Ir   rq   c                  "     e Zd ZdZ fdZ xZS )TextStylePlacementz.
    TextStyle plus a placement attribute
    c                0    t         |           d | _        y rR   )rk   rF   	placementrl   s    r   rF   zTextStylePlacement.__init__  s    r   r   r   r   r`   rF   rn   ro   s   @r   r   r     s     r   r   c                  "     e Zd ZdZ fdZ xZS )BezierStylez'
    From the MusicXML Definition.
    c                v    t         |           d | _        d | _        d | _        d | _        d | _        d | _        y rR   )rk   rF   bezierOffsetbezierOffset2bezierXbezierYbezierX2bezierY2rl   s    r   rF   zBezierStyle.__init__&  s:     !r   r   ro   s   @r   r   r   !  s    	 	r   r   c                  "     e Zd ZdZ fdZ xZS )	LineStylez
    from the MusicXML Definition

    Defines lineShape ('straight', 'curved' or None)
    lineType ('solid', 'dashed', 'dotted', 'wavy' or None)
    dashLength (in tenths)
    spaceLength (in tenths)
    c                Z    t         |           d | _        d | _        d | _        d | _        y rR   )rk   rF   	lineShapelineTyperB   rC   rl   s    r   rF   zLineStyle.__init__<  s+    r   r   ro   s   @r   r   r   2  s       r   r   c                  "     e Zd ZdZ fdZ xZS )StreamStylez~
    Includes several elements in the MusicXML <appearance> tag in <defaults>
    along with <music-font> and <word-font>
    c                    t         |           g | _        g | _        g | _        g | _        d | _        d | _        g | _        g | _	        d| _
        d| _        d | _        d | _        y )NT)rk   rF   
lineWidths	noteSizes	distancesotherAppearances	musicFontwordFont
lyricFontslyricLanguagesprintPartNameprintPartAbbreviationmeasureNumberingmeasureNumberStylerl   s    r   rF   zStreamStyle.__init__K  sj     " !%)" !%"&r   r   ro   s   @r   r   r   E  s    
' 'r   r   c                  "     e Zd ZdZ fdZ xZS )	BeamStylez
    Style for beams
    c                0    t         |           d | _        y rR   )rk   rF   fanrl   s    r   rF   zBeamStyle.__init__d  s    r   r   ro   s   @r   r   r   _  s     r   r   c                      e Zd ZdZeZdZddZedd       Z	edd       Z
e
j                  dd       Z
edd       Zedd       Zej                  dd	       Zy
)
StyleMixina(  
    Mixin for any class that wants to support style and editorial, since several
    non-music21 objects, such as Lyrics and Accidentals will support Style.

    Not used by Music21Objects because of the added trouble in copying etc. so
    there is code duplication with base.Music21Object
    _style
_editorialc                     d | _         d | _        y rR   r   rD   s    r   rF   zStyleMixin.__init__v  s     #'48r   c                8    t        | d      sy| j                  duS )aa  
        Returns True if there is a :class:`~music21.style.Style` object
        already associated with this object, False otherwise.

        Calling .style on an object will always create a new
        Style object, so even though a new Style object isn't too expensive
        to create, this property helps to prevent creating new Styles more than
        necessary.

        >>> lObj = note.Lyric('hello')
        >>> lObj.hasStyleInformation
        False
        >>> lObj.style
        <music21.style.TextStylePlacement object at 0x10b0a2080>
        >>> lObj.hasStyleInformation
        True
        r   FN)hasattrr   rD   s    r   hasStyleInformationzStyleMixin.hasStyleInformation|  s     & tX&{{$&&r   c                b    | j                   | j                  } |       | _         | j                   S )a  
        Returns (or Creates and then Returns) the Style object
        associated with this object, or sets a new
        style object.  Different classes might use
        different Style objects because they might have different
        style needs (such as text formatting or bezier positioning)

        Eventually will also query the groups to see if they have
        any styles associated with them.

        >>> acc = pitch.Accidental()
        >>> st = acc.style
        >>> st
        <music21.style.TextStyle object at 0x10ba96208>
        >>> st.absoluteX = 20.0
        >>> st.absoluteX
        20.0
        >>> acc.style = style.TextStyle()
        >>> acc.style.absoluteX is None
        True
        )r   _styleClass)rE   
styleClasss     r   stylezStyleMixin.style  s,    0 ;;))J$,DK{{r   c                    || _         y rR   )r   )rE   newStyles     r   r   zStyleMixin.style  s	    r   c                    | j                   duS )a[  
        Returns True if there is a :class:`~music21.editorial.Editorial` object
        already associated with this object, False otherwise.

        Calling .style on an object will always create a new
        Style object, so even though a new Style object isn't too expensive
        to create, this property helps to prevent creating new Styles more than
        necessary.

        >>> acc = pitch.Accidental('#')
        >>> acc.hasEditorialInformation
        False
        >>> acc.editorial
        <music21.editorial.Editorial {}>
        >>> acc.hasEditorialInformation
        True
        Nr   rD   s    r   hasEditorialInformationz"StyleMixin.hasEditorialInformation  s    & d**r   c                j    ddl m} | j                   |j                         | _        | j                  S )a"  
        a :class:`~music21.editorial.Editorial` object that stores editorial information
        (comments, footnotes, harmonic information, ficta).

        Created automatically as needed:

        >>> acc = pitch.Accidental()
        >>> acc.editorial
        <music21.editorial.Editorial {}>
        >>> acc.editorial.ficta = pitch.Accidental('sharp')
        >>> acc.editorial.ficta
        <music21.pitch.Accidental sharp>
        >>> acc.editorial
        <music21.editorial.Editorial {'ficta': <music21.pitch.Accidental sharp>}>
        r   r   )music21r   r   	Editorial)rE   r   s     r   r   zStyleMixin.editorial  s-    $ 	&??"1i113DOr   c                    || _         y rR   r   )rE   eds     r   r   zStyleMixin.editorial  s	    r   Nr]   )r^   bool)r^   r3   )r   r3   )r^   editorial.Editorial)r   r   )r   r   r   r`   r3   r   	__slots__rF   rb   r   r   rc   r   r   r   r   r   r   r   i  s     K(I9 ' ',  8 \\  + +(  ,  r   r   c                      e Zd Zy)TestNr   r   r   r   r   r     r   r   r   __main__)r`   
__future__r   typingtunittestr   r   r   music21.prebaser   TYPE_CHECKINGr   Music21Exceptionr
   StrEnumr   r3   rf   rq   r   r   r   r   r   SlottedObjectMixinr   TestCaser   r   mainTestr   r   r   <module>r     s    #      * ??!	,77 	 $oN od3' 3'lzI zIz % "   &'% '4 y** yx	8 	 zGT r   