
    3j                        d Z ddlmZ ddlZddlmc 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 ej                   rddlmZ  G d	 d
      Zedk(  rddl
Z
 e
j*                          yy)z
Functions that convert <sound> tag to the many music21
objects that this tag might represent.

Pulled out because xmlToM21 is getting way too big.
    )annotationsN)common)duration)tempo)helpers)MeasureParserc                  P    e Zd ZdZddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZy)SoundTagMixinz
    This Mixin is applied to MeasureParser -- it is moved
    out from there because there is still a lot to write
    here and xmlToM21.py is getting too big.
    c                    t         j                  r"t        | t              rt        | t              sJ | j                  |      }|| j                  z   }| j                  |      }| j                  |d||       y)z
        Convert a <sound> tag to one or more relevant objects
        (presently just MetronomeMark),
        and add it or them to the core and staffReference.
        N)	tTYPE_CHECKING
isinstancer   r
   xmlToOffsetoffsetMeasureNotegetStaffNumbersetSound)selfmxSoundoffsetDirectiontotalOffsetstaffKeys        L/DATA/.local/lib/python3.12/site-packages/music21/musicxml/xmlSoundParser.pyxmlSoundzSoundTagMixin.xmlSound&   sm     ??dM2z$7VVV **73%(>(>>&&w/g!	#    c                    t         j                  r"t        | t              rt        | t              sJ d|j
                  v r| j                  ||||       yy)a/  
        Takes a <sound> tag and creates objects from it.
        Presently only handles <sound tempo='x'> events and inserts them as MetronomeMarks.
        If the <sound> tag is a child of a <direction> tag, the direction information
        is used to set the placement of the MetronomeMark.
        r   N)r   r   r   r   r
   attribsetSoundTempo)r   r   mxDirr   r   s        r   r   zSoundTagMixin.setSound:   sK     ??dM2z$7VVV& gnn$wxE %r   c                H   t         j                  r"t        | t              rt        | t              sJ t        j                  t        |j                  dd                  }|dk(  rt        j                  dd       yt        j                  t        j                  d      d|	      }t        j                   ||       | j#                  ||       | j%                  ||       |*t        j&                  ||d
d
       | j)                  ||       | j+                  |||       y)zQ
        Add a metronome mark from the tempo attribute of a <sound> tag.
        r   r   z 0 qpm tempo tag found, skipping.   )
stacklevelNquarter)type)referentnumbernumberSounding	placement)r   r   r   r   r
   r   numToIntOrFloatfloatgetwarningswarnr   MetronomeMarkr   Durationr   synchronizeIdsToM21setPrintObjectsetPositionsetM21AttributeFromAttributesetEditorialinsertCoreAndRef)r   r   r   r   r   qpmmms          r   r   zSoundTagMixin.setSoundTempo_   s     ??dM2z$7VVV$$U7;;w+B%CD!8MM<K  (*;*;*K(,03# 	##GR0GR("%00E; eR(k8R8r   N)r   
ET.ElementreturnNone)
r   r7   r   zET.Element | Noner   intr   r)   r8   r9   )__name__
__module____qualname____doc__r   r   r    r   r   r
   r
       s}    
#("F"F "F 	"F
 "F 
"FJ99 9 	9
 9 
9r   r
   __main__)r>   
__future__r   typingr   xml.etree.ElementTreeetreeElementTreeETr+   music21r   r   r   music21.musicxmlr   r   music21.musicxml.xmlToM21r   r
   r;   mainTestr?   r   r   <module>rK      s^    #  " "     $??7\9 \9~ zG r   