
proc APSSoundHelp {} {
    return "Usage: APSSound\n\[-type <string>\] where <string> is working, alert, or emergency\t\n\[-volume <string>\] from 1 to 100\t\n\[-iterations <string>\]\t\n\[-period <string>\] where <string> is in milliseconds or \"continuous\".\nPlays given sound type in background."
}

proc APSSound {args} {
    set type "working"
    set volume 50
    set iterations 1
    set period 2000
    
    APSStrictParseArguments {type volume iterations period}
    catch "after 0 APSPlaySound $type $volume $iterations $period"
}

proc APSPlaySound {type volume iteration period} {
    global apsSoundPath
    if {$period == "continuous"} {
        set bgFlag ""
    } else {
        set bgFlag "&"
    }
    global tcl_platform
    if {$tcl_platform(os) == "SunOS"} {
        set cmd "exec audioplay -i -v $volume $apsSoundPath/${type}.au $bgFlag"
    } else {
        set cmd "exec play -q -v 1.0 $apsSoundPath/${type}.au $bgFlag"
    }
    catch $cmd
    if {$iteration == 1} {
        return
    } elseif {$period == "continuous"} {
        APSPlaySound $type $volume [incr iteration -1] $period
    } else {
        catch "after $period APSPlaySound $type $volume [incr iteration -1] $period"
    }
    
}
