o
    OZŽh–#  ã                   @   sÆ   U d Z ddlmZ ddlZddlZddlZdZdd„ Zdd„ Z	d	d
„ Z
ddd„Zdd„ Zej ¡ Zej ej e¡¡d Zej ed¡Zdadag Zee ed< dZdZdd„ Zedkraeƒ  dS dS )a{   pygame.examples.music_drop_fade
Fade in and play music from a list while observing several events

Adds music files to a playlist whenever played by one of the following methods
Music files passed from the commandline are played
Music files and filenames are played when drag and dropped onto the pygame window
Polls the clipboard and plays music files if it finds one there

Keyboard Controls:
* Press space or enter to pause music playback
* Press up or down to change the music volume
* Press left or right to seek 5 seconds into the track
* Press escape to quit
* Press any other button to skip to the next music file in the list
é    )ÚListNg{®Gáz”?c                 C   sÀ   |   d¡d  ¡ tvrt| › dƒ tdtƒ dS tj | ¡r%t | ¡ n2tj tj 	t
| ¡¡r;t tj 	t
| ¡¡ ntj tj 	t| ¡¡rQt tj 	t| ¡¡ ntdƒ dS t| › dƒ dS )	at  
    This function will check if filename exists and is a music file
    If it is the file will be added to a list of music files(even if already there)
    Type checking is by the extension of the file, not by its contents
    We can only discover if the file is valid when we mixer.music.load() it later

    It looks in the file directory and its data subdirectory
    Ú.é   z not added to file listz$only these files types are allowed: Fzfile not foundz added to file listT)Ú
rpartitionÚlowerÚmusic_file_typesÚprintÚosÚpathÚexistsÚmusic_file_listÚappendÚjoinÚmain_dirÚdata_dir)Úfilename© r   úN/var/www/auris/lib/python3.10/site-packages/pygame/examples/music_drop_fade.pyÚadd_file   s   	
r   c              
   C   sÔ   t | ƒrhztjj td ¡ W n( tjy7 } zt|ƒ | tv r,t | ¡ t| › dƒ W Y d}~dS d}~ww tjjj	dd tjj 
t¡ |  d¡d  ¡ tv rYtdƒ d	antd
ƒ datjj t¡ dS dS )a  
    This function will call add_file and play it if successful
    The music will fade in during the first 4 seconds
    set_endevent is used to post a MUSIC_DONE event when the song finishes
    The main loop will call play_next() when the MUSIC_DONE event is received
    éÿÿÿÿú removed from file listNé   ©Zfade_msr   r   zfile supports seekingr   zfile does not support seeking)r   ÚpgÚmixerÚmusicÚloadr   Úerrorr   ÚremoveÚplayÚ
set_volumeÚvolumer   r   Úmusic_can_seekÚstarting_posÚset_endeventÚ
MUSIC_DONE)r   Úer   r   r   Ú	play_file3   s(   	
€ûîr'   c               
   C   sÖ   t tƒdkr>t d¡} z	tjj | ¡ W n tjy2 } zt|ƒ t| › dƒ W Y d}~nd}~ww t 	| ¡ td| ƒ ntd } tjjj
dd tjj t¡ tjj t¡ |  d¡d	  ¡ tv rgdadS d
adS )zÊ
    This function will play the next song in music_file_list
    It uses pop(0) to get the next song and then appends it to the end of the list
    The song will fade in during the first 4 seconds
    é   r   r   Nzstarting next song: r   r   r   r   r   )Úlenr   Úpopr   r   r   r   r   r   r   r   r    r!   r$   r%   r   r   r"   r#   )Znxtr&   r   r   r   Ú	play_nextQ   s$   
€þ
r+   c                 C   sL   t j ¡ }t | dd¡}|| ¡ 7 }| ¡ | ¡  d }| |||f¡ |S )z¹
    Draws a line of text onto the display surface
    The text will be centered horizontally at the given y position
    The text's height is added to y and returned to the caller
    r(   )éÿ   r,   r,   r   )r   ÚdisplayZget_surfaceÚfontÚrenderZ
get_heightZ	get_widthZblit)ÚtextÚyÚscreenZsurfÚxr   r   r   Údraw_text_linep   s   
r4   c                 C   sT   t dkr(tjj ¡ d }t | }||  a tjjjt d td|› dt › ƒ dS dS )a@  
    Changes current playback position by amount seconds.
    This only works with OGG and MP3 files.
    music.get_pos() returns how many milliseconds the song has played, not
    the current position in the file. We must track the starting position
    ourselves. music.set_pos() will set the position in seconds.
    r   g     @@)Ústartzjumped from z to N)r#   r   r   r   Zget_posr   r   )ÚamountZ
played_forZold_posr   r   r   Úchange_music_position~   s   
ûr7   Údatag      è?r   )Úmp3ÚoggÚmidÚmodÚitÚxmZwav)r9   r:   r<   r=   r>   c            
      C   sº  d} d}d}t  ¡  t j d¡ t j dd¡at j ¡ }t j ¡  t j 	¡ d t _
t j t j
¡}|d u r6dn| d¡}tjd	d … D ]}t|ƒ qBtd
ƒ tddƒ}td|ƒ}td|ƒ}td|ƒ}td|ƒ}td|ƒ}td|ƒ 	 | rWt j ¡ D ]˜}|jt jkr„d} qy|jt jkrt|jƒ qy|jt jkrœt|jƒ qy|jtkr¥tƒ  qy|jt jkrþ|jt jkr´d} qy|jt jt jfv rÑ|rÈt j j! "¡  d}qyt j j! #¡  d}qy|jt j$krÚt%}qy|jt j&krät% }qy|jt j'krït(dƒ qy|jt j)krút(dƒ qytƒ  qy|jt j*kr|jt j$t j&fv rd}qy|r-t+|7 a+t,t-dt+ƒd	ƒa+t j j! .t+¡ t/dt+ƒ t j t j
¡}|d u r;dn| d¡}	|	|krK|	}t|ƒ t j 0¡  | 1d¡ | stt  2¡  d S )NTFr   )i€  ià  ZArialé   Ú zUTF-8r(   zhouse_lo.oggz/Drop music files or path names onto this windowé   z"Copy file names into the clipboardz"Or feed them from the command linezIf it's music it will play!z*SPACE to pause or UP/DOWN to change volumez)LEFT and RIGHT will skip around the trackz$Other keys will start the next tracké   éûÿÿÿzvolume:é	   )3r   Úinitr-   Úset_moder.   ZSysFontÚtimeZClockZscrapZ	get_typesZ
SCRAP_TEXTÚgetÚdecodeÚsysÚargvr   r'   r4   ÚeventÚtypeZQUITZDROPTEXTr0   ZDROPFILEÚfiler%   r+   ZKEYDOWNÚkeyZK_ESCAPEZK_SPACEZK_RETURNr   r   ZunpauseÚpauseZK_UPÚVOLUME_CHANGE_AMOUNTZK_DOWNZK_RIGHTr7   ZK_LEFTZKEYUPr!   ÚminÚmaxr    r   ÚflipZtickÚquit)
ÚrunningÚpausedZchange_volumeÚclockZ	scrap_getZclippedÚargr1   ZevÚnew_textr   r   r   Úmain›   sˆ   












€



Ì6r[   Ú__main__)r   ) Ú__doc__Útypingr   Zpygamer   r	   rJ   rQ   r   r'   r+   r4   r7   rL   Zcustom_typer%   r
   ÚsplitÚabspathÚ__file__r   r   r   r#   r!   r   ÚstrÚ__annotations__r   r"   r[   Ú__name__r   r   r   r   Ú<module>   s,   

a
ÿ