@@ -20,6 +20,7 @@ minetest.register_node("mesecons_noteblock:noteblock", {
2020 mesecon .noteblock_play (pos , node .param2 )
2121 end
2222 }},
23+ place_param2 = 11 , -- initialize at C note
2324 on_blast = mesecon .on_blastnode ,
2425})
2526
@@ -45,7 +46,7 @@ local soundnames = {
4546 " mesecons_noteblock_a" ,
4647 " mesecons_noteblock_asharp" ,
4748 " mesecons_noteblock_b" ,
48- " mesecons_noteblock_c"
49+ " mesecons_noteblock_c" -- << noteblock is initialized here
4950}
5051
5152local node_sounds = {}
@@ -74,6 +75,9 @@ mesecon.noteblock_play = function(pos, param2)
7475 pos .y = pos .y - 1
7576 local nodeunder = minetest .get_node (pos ).name
7677 local soundname = node_sounds [nodeunder ]
78+ local use_pitch = true
79+ local pitch
80+ -- Special sounds
7781 if not soundname then
7882 for k ,v in pairs (node_sounds_group ) do
7983 local g = minetest .get_item_group (nodeunder , k )
@@ -83,6 +87,7 @@ mesecon.noteblock_play = function(pos, param2)
8387 end
8488 end
8589 end
90+ -- Piano
8691 if not soundname then
8792 soundname = soundnames [param2 ]
8893 if not soundname then
@@ -92,13 +97,24 @@ mesecon.noteblock_play = function(pos, param2)
9297 if nodeunder == steelblock_nodename then
9398 soundname = soundname .. 2
9499 end
100+ use_pitch = false
101+ end
102+ -- Disable pitch for fire and explode because they'd sound too odd
103+ if soundname == " fire_fire" or soundname == " tnt_explode" then
104+ use_pitch = false
105+ end
106+ if use_pitch then
107+ -- Calculate pitch
108+ -- Adding 1 to param2 because param2=11 is *lowest* pitch sound
109+ local val = (param2 + 1 )% 12
110+ pitch = 2 ^ ((val - 6 )/ 12 )
95111 end
96112 pos .y = pos .y + 1
97113 if soundname == " fire_fire" then
98114 -- Smoothly fade out fire sound
99115 local handle = minetest .sound_play (soundname , {pos = pos , loop = true })
100116 minetest .after (3.0 , minetest .sound_fade , handle , - 1.5 , 0.0 )
101117 else
102- minetest .sound_play (soundname , {pos = pos }, true )
118+ minetest .sound_play (soundname , {pos = pos , pitch = pitch }, true )
103119 end
104120end
0 commit comments