o
    OZŽh_  ã                   @   sp   d Z ddlZddlZddlZG dd„ dƒZdd„ Zdd„ Zed	kr6e	ej
ƒd
kr-eƒ  dS eej
d ƒ dS dS )a   pygame.examples.playmus

A simple music player.

   Use pygame.mixer.music to play an audio file.

A window is created to handle keyboard events for playback commands.


Keyboard Controls
-----------------

space - play/pause toggle
r     - rewind
f     - fade out
q     - stop

é    Nc                   @   sF   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	ddd„Z
dS )ÚWindowz§The application's Pygame window

    A Window instance manages the creation of and drawing to a
    window. It is a singleton class. Only one instance can exist.

    Nc                 O   s<   t jdurt jS t | ¡}tj ¡  tj d¡|_|t _|S )zReturn an open Pygame windowN)iX  i  )	r   ÚinstanceÚobjectÚ__new__ÚpgÚdisplayÚinitÚset_modeÚscreen)ÚclsÚargsÚkwdsÚself© r   úF/var/www/auris/lib/python3.10/site-packages/pygame/examples/playmus.pyr   $   s   


zWindow.__new__c                 C   s˜   t j |¡ d| _d| _| j | j¡ t j ¡  tj	 
¡  tj	 d d¡| _d| j_t| j ¡ d ƒ| _t| j ¡ d ƒ| _| j| j | _|  dd¡ d S )N)éþ   éç   é   éÿ   )é   é   é    r   é   Tg      ø?zÜ
Press 'q' or 'ESCAPE' or close this window to quit
Press 'SPACE' to play / pause
Press 'r' to rewind to the beginning (restart)
Press 'f' to fade music out over 5 seconds

Window will quit automatically when music ends
r   )r   r   Zset_captionÚ
text_colorÚbackground_colorr
   ÚfillÚflipÚpygameZfreetyper   ZFontÚfontÚoriginÚintZget_sized_ascenderÚascenderZget_sized_descenderZ	descenderÚline_heightÚwrite_lines)r   Útitler   r   r   Ú__init__/   s   

úzWindow.__init__c                 C   s   | S ©Nr   ©r   r   r   r   Ú	__enter__F   s   zWindow.__enter__c                 C   s   |   ¡  dS )NF)Úclose)r   Úexc_typeÚexc_valÚexc_tbr   r   r   Ú__exit__I   s   zWindow.__exit__c                 C   s   t j ¡  d t_d S r&   )r   r   Úquitr   r   r'   r   r   r   r)   M   s   

zWindow.closer   c           
      C   s˜   | j  ¡ \}}| j}|| }|dk r|| }t| d¡|ƒD ]&\}}|| | j }	| j  | jd|| ||f¡ | j 	| j d|	f|| j
¡ qtj ¡  d S )Nr   Ú
é   )r
   Úget_sizer"   Ú	enumerateÚsplitr!   r   r   r   Z	render_tor   r   r   r   )
r   ÚtextÚlineÚwÚhr"   ÚnlinesÚiZ	text_lineÚyr   r   r   r#   Q   s   ÿzWindow.write_lines)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r%   r(   r-   r)   r#   r   r   r   r   r      s    r   c                   C   s   t dƒ t dƒ d S )NzUsage: python playmus.py <file>z/       python -m pygame.examples.playmus <file>)Úprintr   r   r   r   Úshow_usage_messageb   s   r@   c              	   C   sü  t | ƒì}| dd¡ tjjdd zÐd}tjj | ¡ tj tj	d¡ tjj 
¡  | dd¡ tjj ¡ s8|rÔtj ¡ }|jtjkr¾|j}|tjkrk|r\tjj ¡  d}| dd¡ nptjj ¡  d}| d	d¡ na|tjkrš| d
d…  ¡ dv rƒd}tjj ¡  nd}tjj 
¡  |r™tjj ¡  | |d¡ n2|tjkr­| dd¡ tjj d¡ n|tjtjfv r½d}tjj ¡  n|jtjkrÌd}tjj ¡  tjj ¡ s8|s8tj tj	d¡ W tj ¡  ntj ¡  w W d  ƒ n1 sów   Y  t ¡  dS )z&Play an audio file with pg.mixer.musiczLoading ...éÿÿÿÿiD¬  )Z	frequencyFiô  zPlaying ...
TzPaused ...
éýÿÿÿN)ZoggZmp3ÚmodzRewound.z
Restarted.zFading out ...
iˆ  r   )r   r#   r   Zmixerr   ZmusicÚloadÚtimeZ	set_timerZ	USEREVENTZplayZget_busyÚeventÚwaitÚtypeZKEYDOWNÚkeyZK_SPACEZunpauseÚpauseZK_rÚlowerÚrewindZK_fZfadeoutZK_qZK_ESCAPEÚstopZQUITr.   )Ú	file_pathÚwinÚpausedÚerI   Ústatusr   r   r   Úmaing   s\   



€
€ß#Î3rS   Ú__main__é   é   )r>   Úsysr   r   Zpygame.freetyper   r@   rS   r;   ÚlenÚargvr   r   r   r   Ú<module>   s   H9
û