initial release
This commit is contained in:
402
cosmic rage/worlds/plugins/LuaAudio.xml
Normal file
402
cosmic rage/worlds/plugins/LuaAudio.xml
Normal file
@@ -0,0 +1,402 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!DOCTYPE muclient>
|
||||
<!-- Saved on Tuesday, December 09, 2008, 2:04 PM -->
|
||||
<!-- MuClient version 4.37 -->
|
||||
|
||||
<!-- Plugin "LuaAudio" generated by Plugin Wizard -->
|
||||
|
||||
<muclient>
|
||||
<plugin
|
||||
name="LuaAudio"
|
||||
author="Tyler Spivey"
|
||||
id="aedf0cb0be5bf045860d54b7"
|
||||
language="Lua"
|
||||
purpose="Test audio plugin for lua"
|
||||
save_state="y"
|
||||
date_written="2008-12-09 14:02:34"
|
||||
requires="4.37"
|
||||
version="1.0"
|
||||
>
|
||||
|
||||
</plugin>
|
||||
|
||||
|
||||
<!-- Get our standard constants -->
|
||||
|
||||
<include name="constants.lua"/>
|
||||
<aliases>
|
||||
<alias
|
||||
match="sound_toggle"
|
||||
enabled="y"
|
||||
send_to="12"
|
||||
sequence="100"
|
||||
>
|
||||
<send>
|
||||
if (sounds==0) then
|
||||
sounds=1
|
||||
Note("Sounds on.")
|
||||
audio.volume(vol,0)
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/on.ogg")
|
||||
return
|
||||
else
|
||||
sounds=0
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/off.ogg")
|
||||
Note("Sounds off.")
|
||||
vol=audio.getVolume()
|
||||
DoAfterSpecial(0.3, 'Sound("volume=0")', 12)
|
||||
return
|
||||
end
|
||||
</send>
|
||||
</alias>
|
||||
<alias
|
||||
match="volume_down"
|
||||
enabled="y"
|
||||
send_to="12"
|
||||
sequence="100"
|
||||
>
|
||||
<send>
|
||||
if (sounds==0) then
|
||||
Execute("tts_interrupt You're not supposed to use this function while sounds are off you weird person.")
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/error2.ogg")
|
||||
return
|
||||
end
|
||||
if (volume_changed==1) then
|
||||
if (vol==0) then
|
||||
Note("It's muted you noob.")
|
||||
else
|
||||
vol=vol-5
|
||||
SetVariable("vol", vol)
|
||||
SaveState()
|
||||
Sound("volume="..vol.."")
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/down.ogg")
|
||||
end --volume changed 0
|
||||
else
|
||||
volume_changed=1
|
||||
if (GetVariable("vol") == nil) then
|
||||
vol=100
|
||||
vol=vol-5
|
||||
SetVariable("vol", vol)
|
||||
SaveState()
|
||||
Sound("volume="..vol.."")
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/down.ogg")
|
||||
else --if it is not nil
|
||||
vol=tonumber(GetVariable("vol"))
|
||||
if (vol==0) then
|
||||
Note("It's muted you noob.")
|
||||
else
|
||||
vol=vol-5
|
||||
SetVariable("vol", vol)
|
||||
SaveState()
|
||||
Sound("volume="..vol.."")
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/up.ogg")
|
||||
end --not 0
|
||||
end --not nil
|
||||
end --changed not changed
|
||||
</send>
|
||||
</alias>
|
||||
<alias
|
||||
match="vol"
|
||||
enabled="y"
|
||||
send_to="12"
|
||||
sequence="100"
|
||||
>
|
||||
<send>
|
||||
Note(vol)
|
||||
Note(GetVariable("vol"))
|
||||
Note(sounds)
|
||||
</send>
|
||||
</alias>
|
||||
<alias
|
||||
match="volume_up"
|
||||
enabled="y"
|
||||
send_to="12"
|
||||
sequence="100"
|
||||
>
|
||||
<send>
|
||||
if (sounds==0) then
|
||||
Execute("tts_interrupt You're not supposed to use this function while sounds are off you weird person.")
|
||||
return
|
||||
end
|
||||
if (volume_changed==1) then
|
||||
if (vol>=100) then
|
||||
Note("Volume range can't be greater than 100.")
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/error.ogg")
|
||||
else
|
||||
vol=vol+5
|
||||
SetVariable("vol", vol)
|
||||
SaveState()
|
||||
Sound("volume="..vol.."")
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/up.ogg")
|
||||
end --volume changed 100
|
||||
else
|
||||
volume_changed=1
|
||||
if (GetVariable("vol") == nil) then
|
||||
vol=100
|
||||
SetVariable("vol", 100)
|
||||
Note("Volume range can't be greater than 100.")
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/error.ogg")
|
||||
SaveState()
|
||||
else --if it is not nil
|
||||
vol=tonumber(GetVariable("vol"))
|
||||
if (vol>=100) then
|
||||
Note("Volume range can't be greater than 100.")
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/error.ogg")
|
||||
else
|
||||
vol=vol+5
|
||||
SetVariable("vol", vol)
|
||||
SaveState()
|
||||
Sound("volume="..vol.."")
|
||||
Sound(GetInfo(67).."/sounds/luaaudio/up.ogg")
|
||||
end --not 100
|
||||
end --not nil
|
||||
end --changed not changed
|
||||
</send>
|
||||
</alias>
|
||||
<alias
|
||||
match="sound_close"
|
||||
enabled="y"
|
||||
send_to="12"
|
||||
sequence="100"
|
||||
>
|
||||
<send>audio.free()
|
||||
</send>
|
||||
</alias>
|
||||
</aliases>
|
||||
<script>
|
||||
<![CDATA[
|
||||
local ppi=require "ppi"
|
||||
|
||||
|
||||
|
||||
|
||||
function sfreq(freqing)
|
||||
freq=split(freqing, "=")
|
||||
val=freq[1]
|
||||
file=freq[2]
|
||||
Sound("freq="..val)
|
||||
Sound(file)
|
||||
end
|
||||
|
||||
local function isPlaying(id)
|
||||
return audio.isPlaying(id)
|
||||
end
|
||||
|
||||
local function getVolume(id)
|
||||
return audio.getVolume(id)
|
||||
end -- local function getVolume(id)
|
||||
|
||||
function SoundPan(panning)
|
||||
pan=split(panning, "=")
|
||||
current=tonumber(pan[1])
|
||||
max=tonumber(pan[2])
|
||||
file=pan[3]
|
||||
Sound("pan="..(current*200/max)-100)
|
||||
Sound(file)
|
||||
Sound("pan=0")
|
||||
end -- function SoundPan(panning)
|
||||
|
||||
function split(str, pat)
|
||||
local t = {}
|
||||
local fpat = "(.-)" .. pat
|
||||
local last_end = 1
|
||||
local s, e, cap = str:find(fpat, 1)
|
||||
while s do
|
||||
if s ~= 1 or cap ~= "" then
|
||||
table.insert(t,cap)
|
||||
end
|
||||
last_end = e+1
|
||||
s, e, cap = str:find(fpat, last_end)
|
||||
end
|
||||
if last_end <= #str then
|
||||
cap = str:sub(last_end)
|
||||
table.insert(t, cap)
|
||||
end
|
||||
return t
|
||||
end -- function split(str, pat)
|
||||
|
||||
-- mapping of loops to ids
|
||||
loops = {}
|
||||
|
||||
|
||||
function OnPluginPlaySound(file)
|
||||
if file == "" then
|
||||
audio.stop(0)
|
||||
return
|
||||
end -- if
|
||||
|
||||
if file:find("=") then
|
||||
t = split(file, "=")
|
||||
if t[1] == "pan" then
|
||||
audio.pan(tonumber(t[2]))
|
||||
elseif t[1] == "volume" then
|
||||
audio.volume(tonumber(t[2]))
|
||||
elseif t[1] == "freq" then
|
||||
audio.freq(tonumber(t[2]))
|
||||
elseif t[1] == "loop" then
|
||||
file = t[2]
|
||||
local id = audio.play(file, 1)
|
||||
|
||||
if id ~= 0 then
|
||||
loops[file] = id
|
||||
end -- If
|
||||
|
||||
elseif t[1] == "stop" then
|
||||
if t[2] == "all" then
|
||||
for k,v in pairs(loops) do
|
||||
audio.stop(v)
|
||||
end
|
||||
elseif loops[t[2]] then
|
||||
audio.stop(loops[t[2]])
|
||||
loops[t[2]] = nil
|
||||
end
|
||||
end -- if t1
|
||||
else -- doesn't contain =
|
||||
id=audio.play(file,0)
|
||||
end -- if contains =
|
||||
end -- function OnPluginPlaySound(file)
|
||||
|
||||
function setPan(x, id)
|
||||
if x and id then
|
||||
audio.pan(x, id)
|
||||
else
|
||||
|
||||
end -- if
|
||||
end -- function setPan(x,id)
|
||||
|
||||
function setPitch(x, id)
|
||||
if x and id then
|
||||
audio.pitch(x,id)
|
||||
else
|
||||
|
||||
end -- if
|
||||
end -- function setPitch(x,id)
|
||||
|
||||
function setVol(x, id)
|
||||
if x and id then
|
||||
audio.volume(x, id)
|
||||
else
|
||||
|
||||
end -- if
|
||||
end -- function setVol(x,id)
|
||||
|
||||
--
|
||||
-- Slides volume up or down aka fading. x refers to the desired volume, id the playout id, and time is in ms.
|
||||
function slideVol(x, id, time)
|
||||
if x and id and time then
|
||||
audio.slideVol(x, id, time)
|
||||
else
|
||||
|
||||
end -- if
|
||||
end -- function slideVol(x,id,time)
|
||||
|
||||
function fadeout(id, _time)
|
||||
if id then
|
||||
audio.fadeout(id, _time)
|
||||
else
|
||||
end -- if
|
||||
end -- function fadeout(id,time)
|
||||
|
||||
function slidePan(x, id, _time)
|
||||
if x and id then
|
||||
audio.slidePan(x, id, _time)
|
||||
else
|
||||
end -- if
|
||||
end -- function slidePan(x, id, time)
|
||||
|
||||
local function slidePitch(x, id, _time)
|
||||
if x and id then
|
||||
audio.slidePitch(x, id, _time)
|
||||
else
|
||||
|
||||
end -- if
|
||||
end
|
||||
|
||||
local function stop(id)
|
||||
if id then
|
||||
audio.stop(id)
|
||||
end -- if
|
||||
end
|
||||
|
||||
local function playDelay(file, time, pan, vol)
|
||||
return audio.playDelay(file, time, pan, vol)
|
||||
end -- local function playDelay(file, time, pan, vol)
|
||||
|
||||
local function playDelayLooped(file,time,pan,vol)
|
||||
id=audio.playDelayLooped(file,time,pan,vol)
|
||||
return id
|
||||
end -- local function playDelayLooped(file,time,pan,vol)
|
||||
|
||||
local function playLooped(file)
|
||||
id=audio.play(file,1)
|
||||
--Note(id)
|
||||
--if id==0 then
|
||||
--Sound(GetInfo(67).."/sounds/luaaudio/error.ogg")
|
||||
--end
|
||||
return id
|
||||
end -- local function playLooped(file)
|
||||
|
||||
local function play(file, loop, pan, vol)
|
||||
id=audio.play(file, loop, pan, vol)
|
||||
|
||||
--if vol not nil and greater than 100 then cap at 100
|
||||
if vol ~= nil then
|
||||
if vol > 100 then
|
||||
vol=100
|
||||
end -- if
|
||||
end -- if
|
||||
|
||||
return id
|
||||
end -- local function play(file,loop,pan,vol)
|
||||
|
||||
--------------------------------------------------------
|
||||
-- startup/shutdown
|
||||
--------------------------------------------------------
|
||||
|
||||
function OnPluginInstall ()
|
||||
assert(package.loadlib("audio.dll", "luaopen_audio"))()
|
||||
|
||||
if not (GetVariable("vol")==nil) then
|
||||
vol=tonumber(GetVariable("vol"))
|
||||
Sound("volume="..vol.."")
|
||||
else
|
||||
vol=100
|
||||
Sound("volume=100")
|
||||
SetVariable("vol", "100")
|
||||
SaveState()
|
||||
end -- if
|
||||
end -- function OnPluginInstall ()
|
||||
|
||||
function OnPluginClose()
|
||||
if #GetWorldList()==1 then
|
||||
audio.free()
|
||||
end -- if
|
||||
end -- function OnPluginClose()
|
||||
|
||||
--------------------------------------------------------
|
||||
-- external interfaces
|
||||
--------------------------------------------------------
|
||||
|
||||
ppi.Expose("init",OnPluginInstall)
|
||||
ppi.Expose("unload",OnPluginClose)
|
||||
ppi.Expose("setPitch",setPitch)
|
||||
ppi.Expose("slidePitch",slidePitch)
|
||||
|
||||
ppi.Expose("isPlaying",isPlaying)
|
||||
ppi.Expose("getVolume",getVolume)
|
||||
|
||||
ppi.Expose("stop",stop)
|
||||
ppi.Expose("setPan",setPan)
|
||||
ppi.Expose("play",play)
|
||||
ppi.Expose("playDelay",playDelay)
|
||||
ppi.Expose("playDelayLooped",playDelayLooped)
|
||||
ppi.Expose("setVol",setVol)
|
||||
ppi.Expose("slideVol",slideVol)
|
||||
ppi.Expose("fadeout",fadeout)
|
||||
ppi.Expose("slidePan",slidePan)
|
||||
ppi.Expose("playLooped",playLooped)
|
||||
|
||||
--set keybindings
|
||||
Accelerator("ctrl+f12", "sound_toggle")
|
||||
]]>
|
||||
</script>
|
||||
</muclient>
|
||||
Reference in New Issue
Block a user