startmacro
!
! Test sourceaudio.
!
! Author:  L. Tursky
!
switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE
switch NODRAIN     nodrain  GET DEF=FALSE SDEF=TRUE
if interAct then
  pipe init

    set s:instructions "This test must be run on a computer with a microphone. &
                      Enter a filename for your audio recording in the prompt. &
                      Click on the Record Button to begin capturing audio. &
                      Click on the Stop Button to stop the recording process. &
                      Once the audio is recorded, play it back by clicking the &
                      play button. If you hear your file correctly, press the PASS button."
    panel/msgid=MAIN/setup/controls=gc

    gcontrol text idtext "Instructions" "^instructions" 24 9 /title
    gcontrol prompt filename "FileName" "MyAudioFile"
    gcontrol button rec "Capture Audio" "Record,Stop,Play" /tleft
    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    set gc.main.itemColors {PASS=GREEN,FAIL=RED}
 
  pipe off

endif

endmacro

!******************************************************************************!
procedure processMessage m:msg

!say "msg.name ^msg.name, data ^msg.data"

if msg.name eqs "MAIN" then
  assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
  pipe stop
elseif msg.name eqs "FILENAME"
  say "Filename for recording is ^gc.FILENAME.value"
elseif msg.name eqs "REC"
  if msg.data eqs "RECORD"
    sourceaudio/bg/nodrain=^nodrain "^gc.FILENAME.value"
  elseif msg.data eqs "STOP"
    invoke ,, reg.SOURCEAUDIO.setState("FINISH")
  elseif msg.data eqs "PLAY"
    sinkaudio "^gc.FILENAME.value"
  endif
else
  ! do nothing
  say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid dats: ^msg.data"
endif

return

!******************************************************************************!