a
    V$c'"                     @   s(  d dl Z d dlZd dlmZ dd Zdd Zdd ZdCddZdDddZdd Z	dEddZ
dd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd Zd1Zd2Zd3d4 Zd	ad5d6 ZdFd7d8Z d9d: Z!d;d< Z"d=d> Z#d?d@ Z$dAdB Z%dS )G    N)dumpsc                 G   s   t d| t| dS )'
    Calls a method on `function`.
    renpyAudio.{}.apply(null, {});N)
emscripten
run_scriptformatr   functionargs r   renpy/audio\webaudio.pycall   s    r   c                 G   s   t d| t|S r   r   )r   run_script_intr   r   r   r   r   r   call_int#   s    r   c                 G   s   t d| t|}|S r   )r   run_script_stringr   r   )r	   r
   rvr   r   r   call_str+   s    r   F      ?c	           	      C   sH   z
|j }W n ty   Y dS 0 td|  td| ||||||||
 dS )a  
    Plays `file` on `channel`. This clears the playing and queued samples and
    replaces them with this file.

    `name`
        A python object giving a readable name for the file.

    `paused`
        If True, playback is paused rather than started.

    `fadein`
        The time it should take the fade the music in, in seconds.

    `tight`
        If true, the file is played in tight mode. This means that fadeouts
        can span between this file and the file queued after it.

    `start`
        A time in the file to start playing.

    `end`
        A time in the file to end playing.    `

    `relative_volume`
        A number between 0 and 1 that controls the relative volume of this file
    Nstopqueuename	Exceptionr   )	channelfiler   pausedfadeintightstartendrelative_volumer   r   r   play5   s    

r"   c                 C   s>   z
|j }W n ty   Y dS 0 td| ||d|||||
 dS )z
    Queues `file` on `channel` to play when the current file ends. If no file is
    playing, plays it.

    The other arguments are as for play.
    Nr   Fr   )r   r   r   r   r   r   r    r!   r   r   r   r   Z   s
    
r   c                 C   s   t d|  dS )zJ
    Immediately stops `channel`, and unqueues any queued audio file.
    r   Nr   r   r   r   r   r   j   s    r   c                 C   s   t d| | dS )z
    Dequeues the queued sound file.

    `even_tight`
        If true, a queued sound file that is tight is not dequeued. If false,
        a file marked as tight is dequeued.
    dequeueNr#   )r   
even_tightr   r   r   r%   r   s    	r%   c                 C   s   t d| S )z
    Returns the queue depth of the channel. 0 if no file is playing, 1 if
    a files is playing but there is no queued file, and 2 if a file is playing
    and one is queued.
    zrenpyAudio.queue_depth({}))r   r   r   r$   r   r   r   queue_depth~   s    r'   c                 C   s   t d| }|r|S dS )zh
    Returns the `name`  argument of the playing sound. This was passed into
    `play` or `queue`.
    playing_nameN)r   r   r   r   r   r   r(      s    
r(   c                 C   s   t d|  dS )z
    Pauses `channel`.
    pauseNr#   r$   r   r   r   r*      s    r*   c                 C   s   t d|  dS )z
    Unpauses `channel`.
    unpauseNr#   r$   r   r   r   r+      s    r+   c                   C   s   t d dS )z0
    Unpauses all channels that are paused.
    ZunpauseAllAtStartNr#   r   r   r   r   unpause_all_at_start   s    r,   c                 C   s   t d| | dS )z3
    Fades out `channel` over `delay` seconds.
    fadeoutNr#   )r   delayr   r   r   r-      s    r-   c                 C   s   t | dkS )z[
    Returns true if `channel` is currently playing something, and false
    otherwise
    r   )r'   r$   r   r   r   busy   s    r/   c                 C   s"   t d| }|dkr|d S dS dS )z
    Returns the position of the audio file playing in `channel`. Returns None
    if not file is is playing or it is not known.
    get_posr        @@Nr   r)   r   r   r   r0      s    
r0   c                 C   s"   t d| }|dkr|d S dS dS )z|
    Returns the duration of the audio file playing in `channel`, or None if no
    file is playing or it is not known.
    get_durationr   r1   Nr2   r)   r   r   r   r3      s    
r3   c                 C   s   t d| | dS )z
    Sets the primary volume for `channel` to `volume`, a number between
    0 and 1. This volume control is perceptual, taking into account the
    logarithmic nature of human hearing.
    
set_volumeNr#   )r   volumer   r   r   r4      s    r4   c                 C   s   t d| || dS )a  
    Sets the pan for channel.

    `pan`
        A number between -1 and 1 that control the placement of the audio.
        If this is -1, then all audio is sent to the left channel.
        If it's 0, then the two channels are equally balanced. If it's 1,
        then all audio is sent to the right ear.

    `delay`
        The amount of time it takes for the panning to occur.
    set_panNr#   )r   panr.   r   r   r   r6      s    r6   c                 C   s   t d| || dS )a  
    Sets the secondary volume for channel. This is linear, and is multiplied
    with the primary volume and scale factors derived from pan to find the
    actual multiplier used on the samples.

    `delay`
        The time it takes for the change in volume to happen.
    set_secondary_volumeNr#   )r   r5   r.   r   r   r   r8      s    
r8   c                 C   s
   t d| S )z<
    Gets the primary volume associated with `channel`.
    
get_volumer2   r$   r   r   r   r9     s    r9   c                 C   s   dS )z`
    Returns true if the video playing on `channel` has a frame ready for
    presentation.
    Fr   r$   r   r   r   video_ready  s    r:   c                 C   s   dS )z
    Returns the frame of video playing on `channel`. This should be returned
    as an SDL surface with 2px of padding on all sides.
    Nr   r$   r   r   r   
read_video  s    r;         c                 C   s   dS )zS
    Sets a flag that determines if this channel will attempt to decode video.
    Nr   )r   videor   r   r   	set_video'  s    r?   c                  C   s&   t stjd } t|  da dS )z=
    Loads the javascript required for webaudio to work.
    z	_audio.jsTN)loadedrenpyloaderloadreadr   r   )Zjsr   r   r   load_script1  s    
rE   c                 C   s
   t   dS )a  
    Initializes the audio system with the given parameters. The parameter are
    just informational - the audio system should be able to play all supported
    files.

    `freq`
        The sample frequency to play back at.

    `stereo`
        Should we play in stereo (generally true).

    `samples`
        The length of the sample buffer.

    `status`
        If true, the sound system will print errors out to the console.
    `
    T)rE   )freqstereosamplesstatus
equal_monor   r   r   init?  s    rK   c                   C   s   dS )z*
    De-initializes the audio system.
    Nr   r   r   r   r   quitX  s    rL   c                   C   s   dS )z)
    Called periodically (at 20 Hz).
    Nr   r   r   r   r   periodic^  s    rM   c                   C   s   dS )z9
    Called to advance time at the start of a frame.
    Nr   r   r   r   r   advance_timed  s    rN   c                 C   s   dS )z
    Called to provide sample surfaces to the display system. The surfaces
    returned by read_video should be in the same format as these.
    Nr   )rgbrgbar   r   r   sample_surfacesj  s    rQ   c                 C   s   t   td| S )zw
    Webaudio-specific. Returns 1 if the audio system can play all the mime
    types in the list, 0 if it cannot.
    can_play_types)rE   r   )typesr   r   r   rR   s  s    rR   )Fr   Fr   r   r   )r   Fr   r   r   )F)FF)&rA   r   jsonr   r   r   r   r"   r   r   r%   r'   r(   r*   r+   r,   r-   r/   r0   r3   r4   r6   r8   r9   r:   r;   NO_VIDEONODROP_VIDEO
DROP_VIDEOr?   r@   rE   rK   rL   rM   rN   rQ   rR   r   r   r   r   <module>   sH   

%


	
	

	