@@ -61,6 +61,18 @@ mesecon.noteblock_play = function(pos, param2)
6161 pos .y = pos .y - 1
6262 local nodeunder = minetest .get_node (pos ).name
6363 local soundname = node_sounds [nodeunder ]
64+ local pitch
65+ -- Special sounds
66+ if not soundname then
67+ for k ,v in pairs (node_sounds_group ) do
68+ local g = minetest .get_item_group (nodeunder , k )
69+ if g ~= 0 then
70+ soundname = v
71+ break
72+ end
73+ end
74+ end
75+ -- Piano
6476 if not soundname then
6577 for k ,v in pairs (node_sounds_group ) do
6678 local g = minetest .get_item_group (nodeunder , k )
@@ -79,13 +91,26 @@ mesecon.noteblock_play = function(pos, param2)
7991 if nodeunder == " default:steelblock" then
8092 soundname = soundname .. 2
8193 end
94+ pitch = false
95+ end
96+ -- Disable pitch for fire and explode because they'd sound too odd
97+ if soundname == " fire_fire" or soundname == " tnt_explode" then
98+ pitch = false
99+ end
100+ if pitch == false then
101+ pitch = nil
102+ else
103+ -- Calculate pitch
104+ local val = (param2 + 1 )% 12
105+ -- All semitones from C to B (analog to piano mode)
106+ pitch = 2 ^ ((val - 6 )/ 12 )
82107 end
83108 pos .y = pos .y + 1
84109 if soundname == " fire_fire" then
85110 -- Smoothly fade out fire sound
86111 local handle = minetest .sound_play (soundname , {pos = pos , loop = true })
87112 minetest .after (3.0 , minetest .sound_fade , handle , - 1.5 , 0.0 )
88113 else
89- minetest .sound_play (soundname , {pos = pos }, true )
114+ minetest .sound_play (soundname , {pos = pos , pitch = pitch }, true )
90115 end
91116end
0 commit comments