From 3c17eda4e328b4ba4ba59ad0ec29e483b659479f Mon Sep 17 00:00:00 2001 From: Marc Oliver Orth Date: Wed, 28 Jun 2023 18:28:19 +0200 Subject: [PATCH] - --- Examples/monster-tale.txt | 2 ++ Modules/Music.lua | 25 +++++-------------------- main.lua | 28 ++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Examples/monster-tale.txt b/Examples/monster-tale.txt index e46563d..51c598a 100644 --- a/Examples/monster-tale.txt +++ b/Examples/monster-tale.txt @@ -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 diff --git a/Modules/Music.lua b/Modules/Music.lua index 232f007..07e722d 100644 --- a/Modules/Music.lua +++ b/Modules/Music.lua @@ -55,9 +55,6 @@ Music = { int = 32 / 0x7f * 8 -- intensity 0 .. 127 -> 0.0 .. 8.0 } }, - wavetables = { - noise = {} - }, audio = { source = nil, sound_data = nil @@ -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 @@ -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 @@ -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 @@ -674,8 +663,4 @@ function Music:parse_mml(mml) --> bool until end_of_line end - - self:render_audio() - - return success end diff --git a/main.lua b/main.lua index be70c2f..c680533 100644 --- a/main.lua +++ b/main.lua @@ -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 @@ -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() @@ -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