/*
WAVEAO.C

Active object to record and playback sound
*/

#include <record.g>

#define WAVEAO_REQUEST_RECORD 0
#define WAVEAO_REQUEST_PLAY 1

GLREF_D PR_APPMAN * const w_am;

#pragma METHOD_CALL

METHOD VOID waveao_ao_init(PR_WAVEAO *self,PR_ROOT *hdone,UINT done_record,UINT done_play)
    {
    self->active.priority=PRIORITY_ACTIVE_VOICE;
    p_send3(w_am,O_AM_ADD_TASK,self);
    self->waveao.hdone=hdone;
    self->waveao.done_record=done_record;
    self->waveao.done_play=done_play;
    }

METHOD INT waveao_ao_run(PR_WAVEAO *self)
    {
    if (self->active.stat==E_FILE_CANCEL)
        self->active.stat=0;
    p_send3(self->waveao.hdone,(self->waveao.request==WAVEAO_REQUEST_RECORD)?
        self->waveao.done_record:self->waveao.done_play,self->active.stat);
    return(RUN_ACTIVE_USED);
    }

METHOD VOID waveao_ao_cancel(PR_WAVEAO *self)
    {
    p_playsoundcancel(); /* entirely equivalent to p_recordsoundcancel */
    p_supersend2(self,O_AO_CANCEL);
    }

METHOD VOID waveao_wv_play(PR_WAVEAO *self,TEXT *name,UINT volume)
    {
    if (!self->active.isactive)
        {
        p_playsounda(name,0,volume,&self->active.stat);
        self->active.isactive=TRUE;
        self->waveao.request=WAVEAO_REQUEST_PLAY;
        }
    }

METHOD VOID waveao_wv_record(PR_WAVEAO *self,TEXT *name,UINT len)
    {
    if (!self->active.isactive)
        {
        p_recordsounda(name,len,&self->active.stat);
        self->active.isactive=TRUE;
        self->waveao.request=WAVEAO_REQUEST_RECORD;
        }
    }

METHOD VOID waveao_wv_stop(PR_WAVEAO *self)
    {
    p_playsoundcancel(); /* entirely equivalent to p_recordsoundcancel */
    }

