o
    tVg_                     @   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 )WindowzThe 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   K/home/ubuntu/.local/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   set_caption
text_colorbackground_colorr
   fillflippygamefreetyper   Fontfontoriginintget_sized_ascenderascenderget_sized_descender	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!   	render_tor   r   r   r   )
r   textlinewhr(   nlinesi	text_lineyr   r   r   r)   Q   s   zWindow.write_lines)r   )__name__
__module____qualname____doc__r   r   r+   r.   r3   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   rH   c              	   C   s  t | }|dd tjjdd zd}tjj|  tjtj	d tjj
  |dd tjj s8|rt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 rd}tjj  nd}tjj
  |rtjj  ||d n2|tjkr|dd tjjd n|tjtjfv rd}tjj  n|jtjkrd}tjj  tjj s8|s8tjtj	d W tj  ntj  w W d   n1 sw   Y  t  dS )z&Play an audio file with pg.mixer.musiczLoading ...iD  )	frequencyFi  zPlaying ...
TzPaused ...
N)oggmp3modzRewound.z
Restarted.zFading out ...
i  r   )r   r)   r   mixerr   musicloadtime	set_timer	USEREVENTplayget_busyeventwaittypeKEYDOWNkeyK_SPACEunpausepauseK_rlowerrewindK_ffadeoutK_qK_ESCAPEstopQUITr4   )	file_pathwinpauseder[   statusr   r   r   maing   s\   




#3rm   __main__      )rF   sysr   r   pygame.freetyper   rH   rm   rC   lenargvr   r   r   r   <module>   s   H9
