From 69a9304751cfdf784696212fcf4834eba584c584 Mon Sep 17 00:00:00 2001 From: cheapie Date: Tue, 28 Apr 2020 21:28:26 -0500 Subject: Miscellaneous touchscreen and noteblock work * Noteblock sound list updated * Noteblocks now support pitch control * Touchscreens can now optionally use the "real coordinates" system --- noteblock.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'noteblock.lua') diff --git a/noteblock.lua b/noteblock.lua index 665c201..5bd0883 100644 --- a/noteblock.lua +++ b/noteblock.lua @@ -1,5 +1,5 @@ if not minetest.get_modpath("mesecons_noteblock") then - minetest.log("error","mesecons_noteblock is not installed - digilines noteblock will not be available!") + minetest.log("warning","mesecons_noteblock is not installed - digilines noteblock will not be available!") return end @@ -51,12 +51,23 @@ minetest.register_node("digistuff:noteblock", { if sound then minetest.sound_play(sound,{pos=pos}) end elseif type(msg) == "table" then if type(msg.sound) ~= "string" then return end + for _,i in ipairs({"pitch","speed","volume","gain",}) do + if type(msg[i]) == "string" then + msg[i] = tonumber(msg[i]) + end + end local sound = validnbsounds[msg.sound] + if not msg.volume then msg.volume = msg.gain end local volume = 1 if type(msg.volume) == "number" then volume = math.max(0,math.min(1,msg.volume)) end - if sound then minetest.sound_play({name=sound,gain=volume},{pos=pos}) end + if not msg.pitch then msg.pitch = msg.speed end + local pitch = 1 + 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 end end }, -- cgit v1.2.3