More minor cleanups in main.lua

This commit is contained in:
nucular 2014-11-13 00:40:11 +01:00
parent e04f244640
commit 7a542bb531

View File

@ -23,6 +23,7 @@ local statistics = {
-- This will hold all sliders and the wave form box -- This will hold all sliders and the wave form box
local guiparams = {} local guiparams = {}
-- The parameter list is built from this -- The parameter list is built from this
-- {{"Text", "table name", {{"Text", "table paramter", min, max}, ...}}, ...}
local guicategories = { local guicategories = {
{ {
"Envelope", "Envelope",
@ -101,7 +102,10 @@ local waveFormList = {
["Sawtooth"] = 1, ["Sawtooth"] = 1,
["Sine"] = 2, ["Sine"] = 2,
["Noise"] = 3, ["Noise"] = 3,
"Square", "Sawtooth", "Sine", "Noise" [0] = "Square",
[1] = "Sawtooth",
[2] = "Sine",
[3] = "Noise"
} }
@ -255,11 +259,10 @@ function createParameters()
l:AddItem(lf.Create("text"):SetPos(0, pheight):SetText("Wave Form")) l:AddItem(lf.Create("text"):SetPos(0, pheight):SetText("Wave Form"))
local m = lf.Create("multichoice") local m = lf.Create("multichoice")
:AddChoice("Square") for i = 0, #waveFormList do
:AddChoice("Sawtooth") m:AddChoice(waveFormList[i])
:AddChoice("Sine") end
:AddChoice("Noise") m:SetChoice("Square")
:SetChoice("Square")
m.OnChoiceSelected = function(o, c) m.OnChoiceSelected = function(o, c)
sound.wavetype = waveFormList[c] sound.wavetype = waveFormList[c]
@ -392,7 +395,7 @@ function createActionButtons()
return false return false
end end
local function save(type, cb) local function saveHandler(type, cb)
return function() return function()
fr:SetName("Save to ." .. type) fr:SetName("Save to ." .. type)
frt:SetText("sound." .. type) frt:SetText("sound." .. type)
@ -423,7 +426,7 @@ function createActionButtons()
end end
end end
local function load(type, cb) local function loadHandler(type, cb)
return function() return function()
fr:SetName("Load from ." .. type) fr:SetName("Load from ." .. type)
frt:SetText("sound." .. type) frt:SetText("sound." .. type)
@ -458,36 +461,35 @@ function createActionButtons()
local sb = lf.Create("button") local sb = lf.Create("button")
:SetText("Save Lua") :SetText("Save Lua")
:SetWidth(67) :SetWidth(67)
sb.OnClick = save("lua", function(f) sound:save(f, true) end) sb.OnClick = saveHandler("lua", function(f) sound:save(f, true) end)
f:AddItem(sb) f:AddItem(sb)
local lb = lf.Create("button") local lb = lf.Create("button")
:SetText("Load Lua") :SetText("Load Lua")
:SetWidth(67) :SetWidth(67)
sb.OnClick = load("lua", function(f) sound:load(f) end) sb.OnClick = loadHandler("lua", function(f) sound:load(f) end)
f:AddItem(lb) f:AddItem(lb)
local bsb = lf.Create("button") local bsb = lf.Create("button")
:SetText("Save binary") :SetText("Save binary")
:SetWidth(67) :SetWidth(67)
bsb.OnClick = save("sfs", function(f) sound:saveBinary(f) end) bsb.OnClick = saveHandler("sfs", function(f) sound:saveBinary(f) end)
f:AddItem(bsb) f:AddItem(bsb)
local blb = lf.Create("button") local blb = lf.Create("button")
:SetText("Load binary") :SetText("Load binary")
:SetWidth(67) :SetWidth(67)
blb.OnClick = load("sfs", function(f) sound:loadBinary(f) end) blb.OnClick = loadHandler("sfs", function(f) sound:loadBinary(f) end)
f:AddItem(blb) f:AddItem(blb)
local eb = lf.Create("button") local eb = lf.Create("button")
:SetText("Export WAV") :SetText("Export WAV")
:SetWidth(140) :SetWidth(140)
eb.OnClick = save("wav", function(f) sound:exportWAV(f) end) eb.OnClick = saveHandler("wav", function(f) sound:exportWAV(f) end)
f:AddItem(eb) f:AddItem(eb)
f:SetPos(485, 455):SetSize(150, 140) f:SetPos(485, 455):SetSize(150, 140)
-- well ugh
lb:SetPos(78, 47) lb:SetPos(78, 47)
bsb:SetY(77) bsb:SetY(77)
blb:SetPos(78, 77) blb:SetPos(78, 77)
@ -604,7 +606,7 @@ function updateParameters()
s:SetValue(v) s:SetValue(v)
t:SetText("Repeat Speed " .. tostring(math.floor(v * 100) / 100)) t:SetText("Repeat Speed " .. tostring(math.floor(v * 100) / 100))
guiparams.waveform:SetChoice(waveFormList[sound.wavetype + 1]) guiparams.waveform:SetChoice(waveFormList[sound.wavetype])
end end
function updateWaveCanvas(waveview) function updateWaveCanvas(waveview)