<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, November 05, 2005, 8:53 PM -->
<!-- MuClient version 3.68 -->

<!-- Plugin "audio" generated by Plugin Wizard -->

<muclient>
<plugin
   name="audio"
   author="Tyler Spivey"
   id="0263096b1c20b6dccbd104bd"
   language="VBscript"
   purpose="uses comaudio."
   date_written="2005-11-05 20:53:14"
   requires="3.68"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.vbs"/>

<!--  Script  -->

<script>
<![CDATA[
dim CAService
dim AudioDevice
Dim sounds(32)
dim volume

sub onPluginInstall
dim i

Set CAService = CreateObject("COMAudio.Service")
Set AudioDevice = CAService.OpenDevice("", "")
for i= 1 to 32
set sounds(i) = nothing
next
volume = 1.0
end sub

sub onPluginPlaySound (file)
dim slot
dim i

if file = "" then
'stop all sounds.
for i = 1 to ubound(sounds)-1
if sounds(i) is nothing then
else
sounds(i).Stop
end if
next

else
'find an empty slot.
slot = findSlot()

'do we have a slot?
if slot then
on error resume next
set sounds(slot) = AudioDevice.OpenSound(file,False)
if err then
world.note "unexpected error: "&err
end if
sounds(slot).volume = volume
sounds(slot).play
else
world.note("no more slots. sound not played.")
end if 'slot check
end if 'file check

end sub

function findSlot ()
'can't use a for loop to set the return value - vbscript
'is a peace of crap that should die.
dim i, found, slot
i=1

while i < ubound(sounds) and found = 0
'is this empty?
if sounds(i) is nothing then
'its empty
found = 1
slot = i 'return the value
else 'contains a sound
if sounds(i).Playing = 0 then
'yup, found a stopped sound
found = 1
slot = i
end if
end if
i = i + 1
wend

findSlot = slot
end function
sub volumeSet(name, line, wc)
volume = wc(1)/100
world.note "volume is now "&volume
end sub

]]>
</script>
<aliases>
  <alias
   script="volumeSet"
   match="^\s*volume +(\d+)\s*$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  </alias>
</aliases>

</muclient>

