
    ̺i                         S SK r SSKJrJrJr  SSKJr  SSKJr  SSK	J
r
JrJr  SSKJrJr   " S S	5      r " S
 S\5      r " S S\5      rS rS rSS jrg)    N   )
check_datacheck_msgdictcheck_value)decode_message)encode_message)REALTIME_TYPESSPEC_BY_TYPEmake_msgdict)msg2strstr2msgc                       \ rS rSrSrSrS rS rS rSS jr	S r
\S	 5       rS
 rS r\S 5       rSS jrS rS rS rSrg)BaseMessage   z!Abstract base class for messages.Fc                     [         eNNotImplementedErrorselfs    U/var/www/piano.thomer.com/venv/lib/python3.13/site-packages/mido/messages/messages.pycopyBaseMessage.copy       !!    c                     [         er   r   r   s    r   bytesBaseMessage.bytes   r   r   c                 4    [        U R                  5       5      $ )z\Encode message and return as a bytearray.

This can be used to write the message to a file.
)	bytearrayr   r   s    r   binBaseMessage.bin   s    
 &&r   c                 N    UR                  S U R                  5        5       5      $ )zcEncode message and return as a string of hex numbers,

Each number is separated by the string sep.
c              3   (   #    U  H  oS  v   M
     g7f)02XN ).0bytes     r   	<genexpr>"BaseMessage.hex.<locals>.<genexpr>$   s     ?,$*,s   )joinr   )r   seps     r   hexBaseMessage.hex   s    
 xx?$**,???r   c                 l    [        U 5      R                  5       nUS   S:X  a  [        US   5      US'   U$ )zReturns a dictionary containing the attributes of the message.

Example: {'type': 'sysex', 'data': [1, 2], 'time': 0}

Sysex data will be returned as a list.
typesysexdata)varsr   list)r   r2   s     r   dictBaseMessage.dict&   s7     Dz <7"V-DLr   c                     U " S0 UD6$ )zgCreate a message from a dictionary.

Only "type" is required. The other will be set to default
values.
r&   r&   )clsr2   s     r   	from_dictBaseMessage.from_dict4   s     {T{r   c                 H    [        [        U R                     S   5      S/-   $ )Nvalue_namestime)r4   r
   r0   r   s    r   _get_value_namesBaseMessage._get_value_names=   s"    L+M:;vhFFr   c           	         [        U R                  5      /nU R                  5        H#  nUR                  U S[	        X5      < 35        M%     SR                  [        U 5      R                  SR                  U5      5      $ )N=z{}({})z, )reprr0   r>   appendgetattrformat__name__r+   )r   itemsnames      r   __repr__BaseMessage.__repr__A   sf    dii!))+DLLD674#6"9:; ,tDz22DIIe4DEEr   c                 (    U R                   [        ;   $ )z1True if the message is a system realtime message.)r0   r	   r   s    r   is_realtimeBaseMessage.is_realtimeG   s     yyN**r   Nc                 J    U R                   S:w  a  gUc  gU R                  U:H  $ )zReturn True if the message is of type 'control_change'.

The optional control argument can be used to test for a specific
control number, for example:

if msg.is_cc(7):
    # Message is control change 7 (channel volume).
control_changeFT)r0   control)r   rP   s     r   is_ccBaseMessage.is_ccL   s+     99((_<<7**r   c                     [        S5      e)Nzattribute cannot be deletedAttributeError)r   rH   s     r   __delattr__BaseMessage.__delattr__\   s    :;;r   c                     [        S5      e)Nzmessage is immutablerT   r   rH   values      r   __setattr__BaseMessage.__setattr___   s    344r   c                     [        U[        5      (       d  [        S[        U5       35      e[	        U 5      [	        U5      :H  $ )Nzcan't compare message to )
isinstancer   	TypeErrorr0   r3   r   others     r   __eq__BaseMessage.__eq__b   s;    %--8eFGG DzT%[((r   r&   ) r   )rF   
__module____qualname____firstlineno____doc__is_metar   r   r!   r-   r5   classmethodr9   r>   rI   propertyrL   rQ   rV   r[   rb   __static_attributes__r&   r   r   r   r      sl    +G""'@  GF + ++ <5)r   r   c                       \ rS rSrSrS rSrg)	SysexDataj   z>Special kind of tuple accepts and converts any sequence in +=.c                 4    [        U5        U [        U5      -   $ r   )r   rn   r`   s     r   __iadd__SysexData.__iadd__l   s    5i&&&r   r&   N)rF   re   rf   rg   rh   rq   rl   r&   r   r   rn   rn   j   s
    H'r   rn   c                   |    \ rS rSrSS jrSS jr\SS j5       r\SS j5       r\S 5       r	S r
S	 rS
 r\rS rSrg)Messageq   c                     [        X5      nUS:X  a  [        US   5      US'   U(       d  [        U5        [        U 5      R	                  U5        g )Nr1   r2   )r   rn   r   r3   update)r   r0   skip_checksargsmsgdicts        r   __init__Message.__init__r   sB    t*7?'8GFO'"T
'"r   c                    U(       dJ  U R                   R                  U R                   5      n[        U5      R                  [        U 5      5        U$ SU;   a  US   U R                  :w  a  [        S5      eSU;   a  [        US   5      US'   [        U 5      R                  5       nUR                  U5        U(       d  [        U5        U R                   " SSU0UD6$ )a"  Return a copy of the message.

Attributes will be overridden by the passed keyword arguments.
Only message specific attributes can be overridden. The message
type can not be changed.

The skip_checks arg can be used to bypass validation of message
attributes and should be used cautiously.
r0   zcopy must be same message typer2   rx   r&   )		__class____new__r3   rw   r0   
ValueErrorr    r   r   )r   rx   	overridesmsgrz   s        r   r   Message.copy|   s     ..((8CIT$Z(JY9V#4		#A=>>Y ))F*; <Ift*//#y!'"~~A+AAAr   c                     U R                  U 5      n[        XS9nSU;   a  [        US   5      US'   [        U5      R	                  U5        U$ )zParse a byte encoded message.

Accepts a byte string or any iterable of integers.

This is the reverse of msg.bytes() or msg.bin().
r=   r2   )r   r   rn   r3   rw   )clr2   r=   r   rz   s        r   
from_bytesMessage.from_bytes   sL     jjn 1W'8GFOS	!
r   Nc                     [         R                  " SSU5      nUb  UR                  US[        U5      -  5      nU R	                  [
        R                  U5      US9$ )z@Parse a hex encoded message.

This is the reverse of msg.hex().
z\srd   r   )resubreplacelenr   r    fromhex)r   textr=   r,   s       r   from_hexMessage.from_hex   sS     vveS$'? <<S3s8^4D}}Y..t44}@@r   c                 $    U " S0 [        U5      D6$ )zBParse a string encoded message.

This is the reverse of str(msg).
r&   )r   )r   r   s     r   from_strMessage.from_str   s     "GDM""r   c                 ~    U R                   S:X  a  S[        U R                  5      -   $ [        U R                      S   $ )Nr1      length)r0   r   r2   r
   r   s    r   __len__Message.__len__   s5    99s499~%%		*844r   c                 *    [        [        U 5      5      $ r   r   r3   r   s    r   __str__Message.__str__   s    tDz""r   c                     US:X  a  [        S5      eU[        U 5      ;  a%  [        SR                  U R                  U5      5      e[	        X5        US:X  a  [        U5      [        U 5      S'   g U[        U 5      U'   g )Nr0   ztype attribute is read onlyz{} message has no attribute {}r2   )rU   r3   rE   r0   r   rn   rY   s      r   _setattrMessage._setattr   sx    6> !>??d#  "006tyy7;1=> > $v~%.u%5T
6"#(T
4 r   c                 *    [        [        U 5      5      $ )z0Encode message and return as a list of integers.)r   r3   r   s    r   r   Message.bytes   s    d4j))r   r&   )F)r   )r   N)rF   re   rf   rg   r{   r   rj   r   r   r   r   r   r   r[   r   rl   r&   r   r   rt   rt   q   sf    #B<   A A" # #5#) K*r   rt   c                 ,    [         R                  U 5      $ )zParse a string of text and return a message.

The string can span multiple lines, but must contain
one full message.

Raises ValueError if the string could not be parsed.
)rt   r   )r   s    r   parse_stringr      s     D!!r   c              #     #    SnU  HA  n UR                  S5      S   R                  5       nU(       a  [        U5      S4v   US-  nMC     g! [         a-  nSR	                  UUR
                  S   S9nSU4v    SnAN<SnAff = f7f)a^  Parse a stream of messages and yield (message, error_message)

stream can be any iterable that generates text strings, where each
string is a string encoded message.

If a string can be parsed, (message, None) is returned. If it
can't be parsed, (None, error_message) is returned. The error
message contains the line number where the error occurred.
r   #r   Nzline {line_number}: {msg})line_numberr   )splitstripr   r   rE   ry   )streamr   line	exceptionerror_messages        r   parse_string_streamr      s      K	&::c?1%++-D"4($.. 	q 
  	&7>>'NN1% ? 'M %%		&s.   B8A
B
B#A?:B?BBc                 (    [        [        U 5      US9$ )zFormat a message and return as a string.

This is equivalent to str(message).

To leave out the time attribute, pass include_time=False.
)include_timer   )r   r   s     r   format_as_stringr     s     49<88r   )T)r   checksr   r   r   decoder   encoder   specsr	   r
   r   stringsr   r   r   tuplern   rt   r   r   r   r&   r   r   <module>r      sV   
 
 : : " " = = %Y) Y)x' 'm*k m*`"09r   