mirror of
https://github.com/nucular/sfxrlua.git
synced 2024-12-24 18:44:20 +00:00
Added very simple file picker; Moved wave view into Draw function
This commit is contained in:
parent
24ad42b0ad
commit
69f5b12d72
150
main.lua
150
main.lua
@ -351,79 +351,116 @@ function createActionButtons()
|
|||||||
playbutton = b
|
playbutton = b
|
||||||
f:AddItem(b)
|
f:AddItem(b)
|
||||||
|
|
||||||
|
|
||||||
local fr = lf.Create("frame")
|
local fr = lf.Create("frame")
|
||||||
fr:SetName("Alright")
|
fr:SetName("File Picker")
|
||||||
fr:SetSize(400, 105)
|
fr:SetSize(400, 300)
|
||||||
fr:Center()
|
fr:Center()
|
||||||
fr:SetVisible(false)
|
fr:SetVisible(false)
|
||||||
fr:SetModal(false)
|
fr:SetModal(false)
|
||||||
|
|
||||||
|
local frl = lf.Create("columnlist", fr)
|
||||||
|
frl:SetPos(5, 30)
|
||||||
|
frl:SetSize(390, 235)
|
||||||
|
frl:AddColumn("Name")
|
||||||
|
|
||||||
|
local frt = lf.Create("textinput", fr)
|
||||||
|
frt:SetPos(5, 270)
|
||||||
|
frt:SetWidth(300)
|
||||||
|
local frb = lf.Create("button", fr)
|
||||||
|
frb:SetPos(315, 270)
|
||||||
|
|
||||||
|
frl.OnRowSelected = function(p, row, data)
|
||||||
|
frt:SetText(data[1])
|
||||||
|
end
|
||||||
|
|
||||||
fr.OnClose = function(o)
|
fr.OnClose = function(o)
|
||||||
|
frl:Clear()
|
||||||
fr:SetVisible(false):SetModal(false)
|
fr:SetVisible(false):SetModal(false)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local frb = lf.Create("button", fr)
|
|
||||||
frb:SetText("Okay")
|
local function save(type, cb)
|
||||||
frb:SetPos(5, 70)
|
return function()
|
||||||
|
fr:SetName("Save to ." .. type)
|
||||||
|
frt:SetText("sound." .. type)
|
||||||
|
frb:SetText("Save")
|
||||||
|
love.filesystem.getDirectoryItems("sounds", function(name)
|
||||||
|
if name:find(type, #type-#name+1, true) then
|
||||||
|
frl:AddRow(name)
|
||||||
|
end
|
||||||
|
end)
|
||||||
frb.OnClick = function(o)
|
frb.OnClick = function(o)
|
||||||
|
local name = frt:GetText()
|
||||||
|
if (#name > 0) then
|
||||||
|
local f = love.filesystem.newFile("sounds/" .. name, "w")
|
||||||
|
if f then
|
||||||
|
cb(f)
|
||||||
|
frl:Clear()
|
||||||
fr:SetVisible(false):SetModal(false)
|
fr:SetVisible(false):SetModal(false)
|
||||||
end
|
end
|
||||||
local frt = lf.Create("text", fr)
|
end
|
||||||
frt:SetPos(5, 30)
|
end
|
||||||
|
frt.OnEnter = frb.OnClick
|
||||||
|
fr:SetVisible(true):SetModal(true):Center()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function load(type, cb)
|
||||||
|
return function()
|
||||||
|
fr:SetName("Load from ." .. type)
|
||||||
|
frt:SetText("sound." .. type)
|
||||||
|
frb:SetText("Load")
|
||||||
|
love.filesystem.getDirectoryItems("sounds", function(name)
|
||||||
|
if name:find(type, #type-#name+1, true) then
|
||||||
|
frl:AddRow(name)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
frb.OnClick = function(o)
|
||||||
|
local name = frt:GetText()
|
||||||
|
if (#name > 0) then
|
||||||
|
local f = love.filesystem.newFile("sounds/" .. name, "r")
|
||||||
|
if f then
|
||||||
|
cb(f)
|
||||||
|
frl:Clear()
|
||||||
|
fr:SetVisible(false):SetModal(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
frt.OnEnter = frb.OnClick
|
||||||
|
fr:SetVisible(true):SetModal(true):Center()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local sb = lf.Create("button")
|
local sb = lf.Create("button")
|
||||||
sb:SetText("Save Lua")
|
sb:SetText("Save Lua")
|
||||||
sb:SetWidth(67)
|
sb:SetWidth(67)
|
||||||
sb.OnClick = function(o)
|
sb.OnClick = save("lua", function(f) sound:save(f, true) end)
|
||||||
local p = love.filesystem.getSaveDirectory() .. "/" .. "sound.lua"
|
|
||||||
sound:save(p, true)
|
|
||||||
frt:SetText("Saved to\n" .. p)
|
|
||||||
fr:SetVisible(true):SetModal(true):Center()
|
|
||||||
end
|
|
||||||
f:AddItem(sb)
|
f:AddItem(sb)
|
||||||
|
|
||||||
local lb = lf.Create("button")
|
local lb = lf.Create("button")
|
||||||
lb:SetText("Load Lua")
|
lb:SetText("Load Lua")
|
||||||
lb:SetWidth(67)
|
lb:SetWidth(67)
|
||||||
lb.OnClick = function(o)
|
lb.OnClick = load("lua", function(f) sound:load(f) end)
|
||||||
local p = love.filesystem.getSaveDirectory() .. "/" .. "sound.lua"
|
|
||||||
sound:load(p)
|
|
||||||
updateParameters()
|
|
||||||
frt:SetText("Loaded from\n" .. p)
|
|
||||||
fr:SetVisible(true):SetModal(true):Center()
|
|
||||||
end
|
|
||||||
f:AddItem(lb)
|
f:AddItem(lb)
|
||||||
|
|
||||||
local bsb = lf.Create("button")
|
local bsb = lf.Create("button")
|
||||||
bsb:SetText("Save binary")
|
bsb:SetText("Save binary")
|
||||||
bsb:SetWidth(67)
|
bsb:SetWidth(67)
|
||||||
bsb.OnClick = function(o)
|
bsb.OnClick = save("sfs", function(f) sound:saveBinary(f) end)
|
||||||
local p = love.filesystem.getSaveDirectory() .. "/" .. "sound.sfxr"
|
|
||||||
sound:saveBinary(p)
|
|
||||||
frt:SetText("Saved to\n" .. p)
|
|
||||||
fr:SetVisible(true):SetModal(true):Center()
|
|
||||||
end
|
|
||||||
f:AddItem(bsb)
|
f:AddItem(bsb)
|
||||||
|
|
||||||
local blb = lf.Create("button")
|
local blb = lf.Create("button")
|
||||||
blb:SetText("Load binary")
|
blb:SetText("Load binary")
|
||||||
blb:SetWidth(67)
|
blb:SetWidth(67)
|
||||||
blb.OnClick = function(o)
|
blb.OnClick = load("sfs", function(f) sound:loadBinary(f) end)
|
||||||
local p = love.filesystem.getSaveDirectory() .. "/" .. "sound.sfxr"
|
|
||||||
sound:loadBinary(p)
|
|
||||||
frt:SetText("Loaded from\n" .. p)
|
|
||||||
fr:SetVisible(true):SetModal(true):Center()
|
|
||||||
end
|
|
||||||
f:AddItem(blb)
|
f:AddItem(blb)
|
||||||
|
|
||||||
local eb = lf.Create("button")
|
local eb = lf.Create("button")
|
||||||
eb:SetText("Export WAV")
|
eb:SetText("Export WAV")
|
||||||
eb:SetWidth(140)
|
eb:SetWidth(140)
|
||||||
eb.OnClick = function(o)
|
eb.OnClick = save("wav", function(f) sound:exportWAV(f) end)
|
||||||
local p = love.filesystem.getSaveDirectory() .. "/" .. "sound.wav"
|
|
||||||
sound:exportWAV(p)
|
|
||||||
frt:SetText("Exported WAV to\n" .. p)
|
|
||||||
fr:SetVisible(true):SetModal(true):Center()
|
|
||||||
end
|
|
||||||
f:AddItem(eb)
|
f:AddItem(eb)
|
||||||
|
|
||||||
f:SetPos(485, 455)
|
f:SetPos(485, 455)
|
||||||
@ -441,6 +478,22 @@ function createOther()
|
|||||||
f:SetName("Wave View")
|
f:SetName("Wave View")
|
||||||
f:SetPos(485, 5)
|
f:SetPos(485, 5)
|
||||||
f:SetSize(150, 170)
|
f:SetSize(150, 170)
|
||||||
|
local draw = function(o)
|
||||||
|
if source then
|
||||||
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
love.graphics.draw(wavecanvas, 495, 25)
|
||||||
|
|
||||||
|
-- Draw a fancy position cursor
|
||||||
|
local pos = source:tell("samples")
|
||||||
|
local max = sounddata:getSampleCount()
|
||||||
|
local x = 495 + (pos / max) * 125
|
||||||
|
love.graphics.setColor(255, 153, 0)
|
||||||
|
love.graphics.line(x, 25, x, 165)
|
||||||
|
end
|
||||||
|
|
||||||
|
lf.skins.available["Orange"].DrawForm(o)
|
||||||
|
end
|
||||||
|
f.Draw = draw
|
||||||
|
|
||||||
|
|
||||||
local f = lf.Create("form")
|
local f = lf.Create("form")
|
||||||
@ -560,20 +613,6 @@ function updateWaveCanvas(waveview)
|
|||||||
statistics.waveview = math.floor(t * 10000) / 10
|
statistics.waveview = math.floor(t * 10000) / 10
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawWaveView()
|
|
||||||
if source then
|
|
||||||
love.graphics.setColor(255, 255, 255)
|
|
||||||
love.graphics.draw(wavecanvas, 495, 25)
|
|
||||||
|
|
||||||
-- Draw a fancy position cursor
|
|
||||||
local pos = source:tell("samples")
|
|
||||||
local max = sounddata:getSampleCount()
|
|
||||||
local x = 495 + (pos / max) * 125
|
|
||||||
love.graphics.setColor(255, 153, 0)
|
|
||||||
love.graphics.line(x, 25, x, 165)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function updateStatistics()
|
function updateStatistics()
|
||||||
statistics.durationtext:SetText("Duration: " .. statistics.duration .. " ms")
|
statistics.durationtext:SetText("Duration: " .. statistics.duration .. " ms")
|
||||||
statistics.transfertext:SetText("Transfer: " .. statistics.transfer .. " ms")
|
statistics.transfertext:SetText("Transfer: " .. statistics.transfer .. " ms")
|
||||||
@ -587,6 +626,10 @@ function love.load()
|
|||||||
lf.util.SetActiveSkin("Orange")
|
lf.util.SetActiveSkin("Orange")
|
||||||
love.graphics.setBackgroundColor(200, 200, 200)
|
love.graphics.setBackgroundColor(200, 200, 200)
|
||||||
|
|
||||||
|
if not love.filesystem.isDirectory("sounds") then
|
||||||
|
love.filesystem.createDirectory("sounds")
|
||||||
|
end
|
||||||
|
|
||||||
sound = sfxr.newSound()
|
sound = sfxr.newSound()
|
||||||
|
|
||||||
createSeedBox()
|
createSeedBox()
|
||||||
@ -616,11 +659,10 @@ end
|
|||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
lf.draw()
|
lf.draw()
|
||||||
drawWaveView()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keypressed(key)
|
function love.keypressed(key)
|
||||||
if key == " " or key == "return" then
|
if key == " " then
|
||||||
playSound()
|
playSound()
|
||||||
elseif key == "escape" then
|
elseif key == "escape" then
|
||||||
love.event.push("quit")
|
love.event.push("quit")
|
||||||
|
Loading…
Reference in New Issue
Block a user