1# 2# Copyright (c) 2012 Ashok P. Nadkarni 3# All rights reserved. 4# 5# See the file LICENSE for license 6 7# Generate sound for the specified duration 8proc twapi::beep {args} { 9 array set opts [parseargs args { 10 {frequency.int 1000} 11 {duration.int 100} 12 {type.arg} 13 }] 14 15 if {[info exists opts(type)]} { 16 switch -exact -- $opts(type) { 17 ok {MessageBeep 0} 18 hand {MessageBeep 0x10} 19 question {MessageBeep 0x20} 20 exclaimation {MessageBeep 0x30} 21 exclamation {MessageBeep 0x30} 22 asterisk {MessageBeep 0x40} 23 default {error "Unknown sound type '$opts(type)'"} 24 } 25 return 26 } 27 Beep $opts(frequency) $opts(duration) 28 return 29} 30 31# Play the specified sound 32proc twapi::play_sound {name args} { 33 array set opts [parseargs args { 34 alias 35 async 36 loop 37 nodefault 38 wait 39 nostop 40 }] 41 42 if {$opts(alias)} { 43 set flags 0x00010000; #SND_ALIAS 44 } else { 45 set flags 0x00020000; #SND_FILENAME 46 } 47 if {$opts(loop)} { 48 # Note LOOP requires ASYNC 49 setbits flags 0x9; #SND_LOOP | SND_ASYNC 50 } else { 51 if {$opts(async)} { 52 setbits flags 0x0001; #SND_ASYNC 53 } else { 54 setbits flags 0x0000; #SND_SYNC 55 } 56 } 57 58 if {$opts(nodefault)} { 59 setbits flags 0x0002; #SND_NODEFAULT 60 } 61 62 if {! $opts(wait)} { 63 setbits flags 0x00002000; #SND_NOWAIT 64 } 65 66 if {$opts(nostop)} { 67 setbits flags 0x0010; #SND_NOSTOP 68 } 69 70 return [PlaySound $name 0 $flags] 71} 72 73proc twapi::stop_sound {} { 74 PlaySound "" 0 0x0040; #SND_PURGE 75} 76