mirror of
https://github.com/minetest-mods/mesecons.git
synced 2025-06-30 06:40:22 +02:00
Add pitch variations for most noteblock sounds (#535)
This commit is contained in:
@ -20,6 +20,7 @@ minetest.register_node("mesecons_noteblock:noteblock", {
|
||||
mesecon.noteblock_play(pos, node.param2)
|
||||
end
|
||||
}},
|
||||
place_param2 = 11, -- initialize at C note
|
||||
on_blast = mesecon.on_blastnode,
|
||||
})
|
||||
|
||||
@ -45,7 +46,7 @@ local soundnames = {
|
||||
"mesecons_noteblock_a",
|
||||
"mesecons_noteblock_asharp",
|
||||
"mesecons_noteblock_b",
|
||||
"mesecons_noteblock_c"
|
||||
"mesecons_noteblock_c" -- << noteblock is initialized here
|
||||
}
|
||||
|
||||
local node_sounds = {}
|
||||
@ -74,6 +75,9 @@ mesecon.noteblock_play = function(pos, param2)
|
||||
pos.y = pos.y-1
|
||||
local nodeunder = minetest.get_node(pos).name
|
||||
local soundname = node_sounds[nodeunder]
|
||||
local use_pitch = true
|
||||
local pitch
|
||||
-- Special sounds
|
||||
if not soundname then
|
||||
for k,v in pairs(node_sounds_group) do
|
||||
local g = minetest.get_item_group(nodeunder, k)
|
||||
@ -83,6 +87,7 @@ mesecon.noteblock_play = function(pos, param2)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Piano
|
||||
if not soundname then
|
||||
soundname = soundnames[param2]
|
||||
if not soundname then
|
||||
@ -92,6 +97,17 @@ mesecon.noteblock_play = function(pos, param2)
|
||||
if nodeunder == steelblock_nodename then
|
||||
soundname = soundname.. 2
|
||||
end
|
||||
use_pitch = false
|
||||
end
|
||||
-- Disable pitch for fire and explode because they'd sound too odd
|
||||
if soundname == "fire_fire" or soundname == "tnt_explode" then
|
||||
use_pitch = false
|
||||
end
|
||||
if use_pitch then
|
||||
-- Calculate pitch
|
||||
-- Adding 1 to param2 because param2=11 is *lowest* pitch sound
|
||||
local val = (param2+1)%12
|
||||
pitch = 2^((val-6)/12)
|
||||
end
|
||||
pos.y = pos.y+1
|
||||
if soundname == "fire_fire" then
|
||||
@ -99,6 +115,6 @@ mesecon.noteblock_play = function(pos, param2)
|
||||
local handle = minetest.sound_play(soundname, {pos = pos, loop = true})
|
||||
minetest.after(3.0, minetest.sound_fade, handle, -1.5, 0.0)
|
||||
else
|
||||
minetest.sound_play(soundname, {pos = pos}, true)
|
||||
minetest.sound_play(soundname, {pos = pos, pitch = pitch}, true)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user