Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2o committed Jun 28, 2023
1 parent aa8c25c commit 3c17eda
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Examples/monster-tale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ D @v01 o2 l2 @env1 v96
a > e < f > c < g1 > c1 <
a e f c l4 g < b > c d e2 b2
r1

E
25 changes: 5 additions & 20 deletions Modules/Music.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ Music = {
int = 32 / 0x7f * 8 -- intensity 0 .. 127 -> 0.0 .. 8.0
}
},
wavetables = {
noise = {}
},
audio = {
source = nil,
sound_data = nil
Expand Down Expand Up @@ -128,13 +125,9 @@ function Music:NOISE(sample_rate, frequency) --> function()

return function(i)
i = i % npoints + 1
local n = 0
if npoints >= #self.wavetables.noise then
n = math.floor((#self.wavetables.noise / npoints) * i)
else
n = math.floor((npoints / #self.wavetables.noise) * i)
end
return i < (npoints - 1) and self.wavetables.noise[n] or 0
--local n = math.floor((#self.wavetables.noise / npoints) * i)
--return i < (npoints - 1) and self.wavetables.noise[n] or 0
return i < (npoints - 1) and math.random(-2.0, 2.0) or 0
end
end

Expand All @@ -156,10 +149,7 @@ function Music:init()
self.tracks.data.E = {}
self.tracks.info.E = {}

for i = 1, 64 do
self.wavetables.noise[i] = math.random(-1.0, 1.0)
end

math.randomseed(os.time())
end
function Music:is_ready() --> bool
if self.audio.source then
Expand Down Expand Up @@ -516,8 +506,7 @@ end

-- THE PARSER

function Music:parse_mml(mml) --> bool
local success = true
function Music:parse_mml(mml)
math.randomseed(os.time())

self.mml = mml
Expand Down Expand Up @@ -674,8 +663,4 @@ function Music:parse_mml(mml) --> bool
until end_of_line

end

self:render_audio()

return success
end
28 changes: 26 additions & 2 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
]]

VERSION = "0.5.0"
VERSION = "0.6.0"

--[[
0.6.0
- basic error handling when dropping malformed mml files
0.5.0
- simple gui added
- noise synth bug fix
Expand Down Expand Up @@ -294,6 +297,20 @@ function love.quit()
end

function love.filedropped(file)
Music:pause()
Gui.buttons["play_pause"].is_active = false
Gui.buttons["play_pause"].toggled = false
Gui.buttons["export"].is_active = false
t_ui.title_text.text = ""
t_ui.composer_text.text = ""
t_ui.programmer_text.text = ""
t_ui.copyright_text.text = ""
t_ui["voice_A_text"].color = "text_empty"
t_ui["voice_B_text"].color = "text_empty"
t_ui["voice_C_text"].color = "text_empty"
t_ui["voice_D_text"].color = "text_empty"
t_ui["voice_E_text"].color = "text_empty"

if file then
file:open("r")
--file_content = file:read()
Expand All @@ -307,8 +324,15 @@ function love.filedropped(file)

Music:init()

local success = Music:parse_mml(content)
local success = false
if pcall(function () Music:parse_mml(content) end) then
success = true
else
-- error
local error = love.window.showMessageBox("Error", "Malformed mml", "info", true)
end
if success then
Music:render_audio()
t_ui.title_text.text = Music.meta.title
t_ui.composer_text.text = Music.meta.composer
t_ui.programmer_text.text = Music.meta.programmer
Expand Down

0 comments on commit 3c17eda

Please sign in to comment.