Initial commit.

master
James Stevenson 2017-11-23 12:39:02 -05:00
commit 745dd67051
33 changed files with 431 additions and 0 deletions

3
README Normal file
View File

@ -0,0 +1,3 @@
Games Sounds `gen_music' (C) 2017 James Stevenson
GPL3+
Glyph textures by kilbith from X-Decor.

16
dark.txt Normal file
View File

@ -0,0 +1,16 @@
gen_music_phit,walkie_blip,xdecor_enchanting,default_chest_open,catching_breath
1
1
2
0
1
1
2
0
3
4
0
5
0
1
5

22
example1.txt Normal file
View File

@ -0,0 +1,22 @@
gen_music_phit,default_dig_metal,item_smoke
1
0
0
0
0
3
2
2
3
2
2
0
0
3
2
2
3
2
2
0
0

17
example2.txt Normal file
View File

@ -0,0 +1,17 @@
default_dig_dig_immediate,default_dig_oddly_breakable_by_hand,default_dig_metal,default_place_node_hard,default_place_node,default_place_node_metal,default_tool_breaks,default_item_smoke
2
8
0
1
7
0
6
1
5
1
0
4
1
3
1
0

10
example3.txt Normal file
View File

@ -0,0 +1,10 @@
default_dig_oddly_breakable_by_hand
1
1
0
1
0
0
1
0
1

11
example4.txt Normal file
View File

@ -0,0 +1,11 @@
default_dig_metal,default_dig_snappy,default_punch
3
3
0
1
3
2
3
1
1
0

1
extra_sounds.txt Normal file
View File

@ -0,0 +1 @@
walkie_blip

334
init.lua Normal file
View File

@ -0,0 +1,334 @@
-- Game Sounds `gen_music'
-- By James Stevenson (C) 2017
-- GPL3+
gen_music = {}
gen_music.songs = {}
local mod_name = minetest.get_current_modname()
local mod_path = minetest.get_modpath(mod_name)
local function load_songs()
local input = io.open(mod_path .. "/songs.txt", "r")
if not input then
return
end
local songs = {}
local fn = input:read("*l")
while fn do
songs[#songs + 1] = fn
fn = input:read("*l")
end
for i = 1, #songs do
local song_name = songs[i]
local song = io.open(mod_path .. "/" .. song_name, "r")
if not song then
print(song_name .. " not found.")
else
print("Loading " .. song_name)
local ins = song:read("*l"):split()
local seq = {}
local seql = song:read("*l")
while seql do
seq[#seq + 1] = tonumber(seql)
seql = song:read("*l")
end
gen_music.songs[song_name] = {
ins = ins,
seq = seq,
}
end
end
end
load_songs()
--print(dump(gen_music))
local sounds = {}
for _, nodes in pairs(minetest.registered_nodes) do
for elem, val in pairs(nodes) do
if elem == "sounds" then
for _, spec in pairs(val) do
if not sounds[spec.name] and
spec.name ~= "" then
if not spec.gain then
spec.gain = 0.5
end
sounds[#sounds + 1] = spec
end
end
end
end
end
--[[
-- mobs_redo entities.
for _, def in pairs(minetest.registered_entities) do
for prop, val in pairs(def) do
if prop == "sounds" then
for sound_type, sound in pairs(val) do
if type(sound) == "string" then
if not sounds[sound] and
sounds[sound] ~= "" then
sounds[#sounds + 1] = {name = sound, gain = 0.5}
end
end
end
end
end
end
--]]
local extra_sounds = {
"tnt_ignite",
"tnt_explode",
"tnt_gunpower_burning",
"fire_flint_and_steel",
"fire_extinguish_flame",
"fire_fire",
"default_punch",
"default_dig_oddly_breakable_by_hand",
"default_dug_node",
"player_damage",
"doors_door_open",
"doors_door_close",
"default_chest_open",
"default_chest_close",
}
for i = 1, #extra_sounds do
local n = extra_sounds[i]
if not sounds[n] then
sounds[#sounds + 1] = {name = extra_sounds[i], gain = 0.5}
end
end
-- Sound Traveller
local ps = function(pos)
if math.random() < 0.8 then
return
end
local s = -1
if math.random() > 0.5 then
s = 1
end
minetest.add_particle({
pos = {
x = math.random() * s + pos.x,
y = math.random() * s + pos.y,
z = math.random() * s + pos.z
},
velocity = {
x = math.random() * s,
y = math.random() * s,
z = math.random() * s
},
acceleration = {
x = math.random() * s,
y = math.random() * s,
z = math.random() * s
},
expirationtime = 1,
size = 2,
texture = "xdecor_glyph" .. math.random(1, 18) .. ".png",
})
end
-- if show_sound_traveller
minetest.register_entity("gen_music:sound_traveller", {
visual = "sprite",
visual_size = {x = 0.5, y = 0.5},
collisionbox = {0},
physical = false,
textures = {"empty.png"},--default_mese_crystal.png"},
on_activate = function(self, staticdata, dtime_s)
--self.pos = self.object:get_pos()
end,
on_step = function(self, dtime)
--ps(self.pos)
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
end,
on_death = function(self, killer)
end,
on_rightclick = function(self, clicker)
end,
get_staticdata = function(self)
end,
})
gen_music.gs = function(object, song, loop)
-- TODO Generate random sequence and ensemble based on
-- found sounds, and extra_sounds.txt.
if type(song) == "string" then
song = gen_music.songs[song]
end
--print(dump(song))
if not song then
return
end
local gain = math.random()
if gain > 0.67 then
gain = 0.67
end
local play = minetest.sound_play
local seq = {}
local obj = {}
if math.random() < 0.67 then
minetest.after(math.random(), function()
local p_pos = object:get_pos()
if not p_pos then
return
end
local jitter = function(j, p)
local r = math.random()
local s = j * -1
if r > 0.5 then
s = j * 1
if math.random() > r then
return p + (1 * s)
else
return p - (1 * s)
end
elseif math.random() < r then
return p + (1 * s)
else
return p - (1 * s)
end
end
p_pos.x = jitter(math.random(), p_pos.x)
p_pos.y = jitter(math.random(), p_pos.y)
p_pos.z = jitter(math.random(), p_pos.z)
local function play_variable(ensemble, positional)
-- New object.
local obj_idx = #obj + 1
obj[obj_idx] = minetest.add_entity(p_pos,
"gen_music:sound_traveller", "")
local o_pos = obj[obj_idx]:get_pos()
local d = vector.direction(p_pos, o_pos)
d.x = jitter(math.random(), d.x)
d.y = jitter(math.random(), d.y)
d.z = jitter(math.random(), d.z)
obj[obj_idx]:set_velocity(d)
obj[obj_idx]:set_acceleration(d)
-- New sound attached to new object.
local pitch = math.random()
if math.random() > 0.5 or
pitch > 0.66 then
pitch = pitch - 0.5
end
local idx = #seq + 1
local fade = math.random(1)
local n
if not ensemble then
n = ""
else
n = ensemble[math.random(1, #song)]
end
seq[idx] = play(n, {
gain = gain * 0.1,
pitch = pitch * 1.33,
fade = fade,
object = obj[obj_idx],
})
--print("Starting " .. seq[idx])
if fade == 1 then
minetest.sound_fade(seq[idx], 0.1, gain)
end
end
local score = song.seq
for i = 1, #score do
local e = score[i]
if e == "0" then
minetest.after(math.random(), function()
play_variable()
end)
else
local g = song.ins[e]
if g then
minetest.after(math.random(), function()
play_variable{g}
end)
end
end
end
-- `Mese Music' by jas
--[[
if math.random() < 0.33 then
play_variable({"phit", "phit", "phit", "phit"})
minetest.after(math.random(), function()
play_variable({"phit", "phit", "walkie_blip", "xdecor_enchanting", "mobs_spell"}, true)
end)
end
if math.random() > 0.33 then
minetest.after(math.random(), function()
play_variable({"walkie_blip", "walkie_blip", "phit"}, true)
end)
end
if math.random() > 0.5 then
minetest.after(math.random(), function()
play_variable({"xdecor_enchanting", "phit", "walkie_blip"}, false)
end)
end
--]]
minetest.after(math.random(), function()
for k, v in pairs(obj) do
v:remove()
end
end)
end)
end
minetest.after(math.random(), function()
for idx = 1, #seq do
minetest.after(math.random(), function()
--print("Stopping " .. seq[idx])
minetest.sound_fade(seq[idx], -0.1, 0.0)
minetest.after(math.random(), function()
minetest.sound_stop(seq[idx])
end)
end)
end
if loop then
if object:is_player() then
local l = object:get_attribute("loop")
if not l or l == "" then
return
end
l = tonumber(l)
object:set_attribute("loop", l - 1)
if l == 0 then
object:set_attribute("loop", nil)
end
minetest.after(math.random() + math.random(), function()
gen_music.gs(object, song, loop)
end)
end
end
end)
end
minetest.register_chatcommand("gs", {
func = function(name, param)
param = param:split(" ")
local player = minetest.get_player_by_name(name)
if param[1] == "load" then
--[[ -- TODO Mod security.
if param[2] then
local h = io.open(mod_path .. "/songs.txt", "a+")
h:write(param[2])
end
--]]
load_songs()
end
if param[1] == "stop" then
player:set_attribute("loop", nil)
return true, "This may take a moment."
end
local lc = param[2] or 3
player:set_attribute("loop", tonumber(lc))
gen_music.gs(minetest.get_player_by_name(name),
param[1], true)
end,
})

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = gen_music

9
song1.txt Normal file
View File

@ -0,0 +1,9 @@
walkie_blip,phit,xdecor_enchanting,mobs_spell
1 20
1 10
2 10
1 10
3 10
4 30
4 40

7
songs.txt Normal file
View File

@ -0,0 +1,7 @@
mysong1.txt
dark.txt
sombre.txt
example1.txt
example2.txt
example3.txt
example4.txt

BIN
sounds/gen_music_phit.1.ogg Normal file

Binary file not shown.

BIN
sounds/gen_music_phit.2.ogg Normal file

Binary file not shown.

BIN
sounds/gen_music_phit.3.ogg Normal file

Binary file not shown.

BIN
textures/empty.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

BIN
textures/xdecor_glyph1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

BIN
textures/xdecor_glyph10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

BIN
textures/xdecor_glyph11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

BIN
textures/xdecor_glyph12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

BIN
textures/xdecor_glyph13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

BIN
textures/xdecor_glyph14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

BIN
textures/xdecor_glyph15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

BIN
textures/xdecor_glyph16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

BIN
textures/xdecor_glyph17.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

BIN
textures/xdecor_glyph18.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

BIN
textures/xdecor_glyph2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

BIN
textures/xdecor_glyph3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

BIN
textures/xdecor_glyph4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

BIN
textures/xdecor_glyph5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

BIN
textures/xdecor_glyph6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

BIN
textures/xdecor_glyph7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

BIN
textures/xdecor_glyph8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

BIN
textures/xdecor_glyph9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B