summaryrefslogtreecommitdiff
path: root/noteblock.lua
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2021-12-23 20:46:24 -0600
committercheapie <no-email-for-you@example.com>2021-12-23 20:46:24 -0600
commit144c61533cdd2293aaf1b3b7cfeec8b7ca0df04f (patch)
tree2013bda171ea6554207ad3489be7a6c460c720bb /noteblock.lua
parent47a32ff26ed8945f28dc16ff51148b788b5f7580 (diff)
downloaddigistuff-144c61533cdd2293aaf1b3b7cfeec8b7ca0df04f.tar
digistuff-144c61533cdd2293aaf1b3b7cfeec8b7ca0df04f.tar.gz
digistuff-144c61533cdd2293aaf1b3b7cfeec8b7ca0df04f.tar.bz2
digistuff-144c61533cdd2293aaf1b3b7cfeec8b7ca0df04f.tar.xz
digistuff-144c61533cdd2293aaf1b3b7cfeec8b7ca0df04f.zip
Add support for fading and cutting noteblock sounds
Also add a 1kHz sine wave sample, intended for use with this
Diffstat (limited to 'noteblock.lua')
-rw-r--r--noteblock.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/noteblock.lua b/noteblock.lua
index 58bb747..ef14224 100644
--- a/noteblock.lua
+++ b/noteblock.lua
@@ -73,7 +73,18 @@ minetest.register_node("digistuff:noteblock", {
if type(msg.pitch) == "number" then
pitch = math.max(0.05,math.min(10,msg.pitch))
end
- if sound then minetest.sound_play({name = sound,gain = volume,},{pos = pos,pitch = pitch,},true) end
+ if sound then
+ if type(msg.cut) == "number" and msg.cut >= 0 then
+ msg.cut = math.min(msg.cut,10)
+ local handle = minetest.sound_play({name = sound,gain = volume,},{pos = pos,pitch = pitch,},false)
+ minetest.after(msg.cut,minetest.sound_stop,handle)
+ elseif type(msg.fadestep) == "number" and type(msg.fadegain) == "number" and msg.fadegain >= 0 and type(msg.fadestart) == "number" and msg.fadestart >= 0 then
+ local handle = minetest.sound_play({name = sound,gain = volume,},{pos = pos,pitch = pitch,},false)
+ minetest.after(msg.fadestart,minetest.sound_fade,handle,msg.fadestep,msg.fadegain)
+ else
+ minetest.sound_play({name = sound,gain = volume,},{pos = pos,pitch = pitch,},true)
+ end
+ end
end
end
},