2014-10-28 15:55:42 +00:00
|
|
|
#/usr/bin/env love
|
|
|
|
-- love .
|
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
local sfxr = require("sfxr")
|
2020-06-05 07:07:47 +00:00
|
|
|
local lf = require('loveframes/loveframes')
|
2014-05-26 14:41:44 +00:00
|
|
|
|
|
|
|
-- Global stuff
|
|
|
|
local source
|
|
|
|
local sound
|
|
|
|
local sounddata
|
|
|
|
|
|
|
|
local seed
|
|
|
|
local playbutton
|
|
|
|
local playing = false
|
|
|
|
|
|
|
|
local wavecanvas
|
|
|
|
local statistics = {
|
|
|
|
generation = 0,
|
|
|
|
transfer = 0,
|
|
|
|
waveview = 0,
|
|
|
|
duration = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
-- This will hold all sliders and the wave form box
|
|
|
|
local guiparams = {}
|
|
|
|
-- The parameter list is built from this
|
2014-11-12 23:40:11 +00:00
|
|
|
-- {{"Text", "table name", {{"Text", "table paramter", min, max}, ...}}, ...}
|
2014-05-26 14:41:44 +00:00
|
|
|
local guicategories = {
|
|
|
|
{
|
|
|
|
"Envelope",
|
|
|
|
"envelope",
|
|
|
|
{
|
|
|
|
{"Attack Time", "attack", 0, 1},
|
|
|
|
{"Sustain Time", "sustain", 0, 1},
|
|
|
|
{"Sustain Punch", "punch", 0, 1},
|
|
|
|
{"Decay Time", "decay", 0, 1}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Frequency",
|
|
|
|
"frequency",
|
|
|
|
{
|
|
|
|
{"Start", "start", 0, 1},
|
|
|
|
{"Minimum", "min", 0, 1},
|
|
|
|
{"Slide", "slide", -1, 1},
|
|
|
|
{"Delta Slide", "dslide", -1, 1}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Vibrato",
|
|
|
|
"vibrato",
|
|
|
|
{
|
|
|
|
{"Depth", "depth", 0, 1},
|
|
|
|
{"Speed", "speed", 0, 1}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Change",
|
|
|
|
"change",
|
|
|
|
{
|
|
|
|
{"Amount", "amount", -1, 1},
|
|
|
|
{"Speed", "speed", 0, 1}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Square Duty",
|
|
|
|
"duty",
|
|
|
|
{
|
|
|
|
{"Ratio", "ratio", 0, 1},
|
|
|
|
{"Sweep", "sweep", -1, 1}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Phaser",
|
|
|
|
"phaser",
|
|
|
|
{
|
|
|
|
{"Offset", "offset", -1, 1},
|
|
|
|
{"Sweep", "sweep", -1, 1}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Low Pass",
|
|
|
|
"lowpass",
|
|
|
|
{
|
|
|
|
{"Cutoff", "cutoff", 0, 1},
|
|
|
|
{"Sweep", "sweep", -1, 1},
|
|
|
|
{"Resonance", "resonance", 0, 1}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"High Pass",
|
|
|
|
"highpass",
|
|
|
|
{
|
|
|
|
{"Cutoff", "cutoff", 0, 1},
|
|
|
|
{"Sweep", "sweep", -1, 1}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Easy lookup of wave forms
|
|
|
|
local waveFormList = {
|
|
|
|
["Square"] = 0,
|
|
|
|
["Sawtooth"] = 1,
|
|
|
|
["Sine"] = 2,
|
|
|
|
["Noise"] = 3,
|
2014-11-12 23:40:11 +00:00
|
|
|
[0] = "Square",
|
|
|
|
[1] = "Sawtooth",
|
|
|
|
[2] = "Sine",
|
|
|
|
[3] = "Noise"
|
2014-05-26 14:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function stopSound()
|
|
|
|
playbutton:SetText("Play")
|
|
|
|
if source then
|
|
|
|
source:stop()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function playSound()
|
|
|
|
-- Stop the currently playing source
|
|
|
|
if source then
|
|
|
|
source:stop()
|
|
|
|
end
|
2014-08-26 13:55:58 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
local t = love.timer.getTime()
|
|
|
|
local tab = sound:generateTable(sfxr.FREQ_44100, sfxr.BITS_FLOAT)
|
|
|
|
t = love.timer.getTime() - t
|
|
|
|
statistics.generation = math.floor(t * 10000) / 10
|
|
|
|
|
|
|
|
if #tab == 0 then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
sounddata = love.sound.newSoundData(#tab, 44100, 16, 1)
|
|
|
|
statistics.duration = math.floor(sounddata:getDuration() * 10000) / 10
|
|
|
|
|
|
|
|
-- Stuff for the wave view
|
|
|
|
local waveview = {}
|
|
|
|
local j = 0
|
|
|
|
local max = -1
|
|
|
|
local min = 1
|
|
|
|
local avg = 0.5
|
|
|
|
|
|
|
|
local t = love.timer.getTime()
|
|
|
|
for i = 0, #tab - 1 do
|
|
|
|
|
|
|
|
local v = tab[i + 1]
|
|
|
|
-- Copy the sample over to the SoundData
|
|
|
|
sounddata:setSample(i, v)
|
|
|
|
|
|
|
|
-- Add the minimal and maximal sample to the wave view
|
|
|
|
-- every 256 samples. This is how Audacity does it, actually.
|
|
|
|
j = j + 1
|
|
|
|
min = math.min(v, min)
|
|
|
|
max = math.max(v, max)
|
|
|
|
if j >= 256 then
|
|
|
|
waveview[#waveview + 1] = min
|
|
|
|
waveview[#waveview + 1] = max
|
|
|
|
j = 0
|
|
|
|
min, max = 1, -1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
t = love.timer.getTime() - t
|
|
|
|
statistics.transfer = math.floor(t * 10000) / 10
|
|
|
|
|
|
|
|
updateWaveCanvas(waveview)
|
|
|
|
updateStatistics()
|
|
|
|
|
|
|
|
if sounddata then
|
|
|
|
source = love.audio.newSource(sounddata)
|
|
|
|
source:play()
|
2014-06-20 13:03:24 +00:00
|
|
|
playbutton:SetText("Stop Playing")
|
2014-05-26 14:41:44 +00:00
|
|
|
playing = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function createSeedBox()
|
2014-10-28 15:55:42 +00:00
|
|
|
local f = lf.Create("form"):SetName("Random Seed")
|
2014-05-26 14:41:44 +00:00
|
|
|
|
|
|
|
seed = lf.Create("numberbox")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetValue(math.floor(love.timer.getTime()))
|
|
|
|
:SetMax(math.huge)
|
|
|
|
:SetMin(-math.huge)
|
|
|
|
:SetWidth(100)
|
2014-05-26 14:41:44 +00:00
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
f:AddItem(seed):SetPos(5, 240)
|
2014-05-26 14:41:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function createPresetGenerators()
|
|
|
|
local f = lf.Create("form")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetName("Preset Generators")
|
2014-05-26 14:41:44 +00:00
|
|
|
local generators = {
|
|
|
|
{"Pickup/Coin", sound.randomPickup},
|
|
|
|
{"Laser/Shoot", sound.randomLaser},
|
|
|
|
{"Explosion", sound.randomExplosion},
|
|
|
|
{"Powerup", sound.randomPowerup},
|
|
|
|
{"Hit/Hurt", sound.randomHit},
|
|
|
|
{"Jump", sound.randomJump},
|
|
|
|
{"Blip/Select", sound.randomBlip}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, v in ipairs(generators) do
|
|
|
|
local b = lf.Create("button")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetText(v[1])
|
|
|
|
:SetWidth(100)
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(b)
|
|
|
|
|
|
|
|
b.OnClick = function(self)
|
|
|
|
v[2](sound, seed:GetValue())
|
|
|
|
seed:SetValue(seed:GetValue() + 1)
|
|
|
|
updateParameters()
|
|
|
|
playSound()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
f:SetPos(5, 5):SetWidth(110)
|
2014-05-26 14:41:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function createRandomizers()
|
2014-10-28 15:55:42 +00:00
|
|
|
local f = lf.Create("form"):SetName("Randomizers")
|
2014-05-26 14:41:44 +00:00
|
|
|
|
|
|
|
local b = lf.Create("button")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetText("Mutate")
|
|
|
|
:SetWidth(100)
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(b)
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
b.OnClick = function(self)
|
|
|
|
sound:mutate()
|
|
|
|
updateParameters()
|
|
|
|
playSound()
|
|
|
|
end
|
|
|
|
|
|
|
|
local b = lf.Create("button")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetText("Randomize")
|
|
|
|
:SetWidth(100)
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(b)
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
b.OnClick = function(self)
|
|
|
|
sound:randomize(seed:GetValue())
|
|
|
|
updateParameters()
|
|
|
|
seed:SetValue(seed:GetValue() + 1)
|
|
|
|
playSound()
|
|
|
|
end
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
f:SetPos(5, 515):SetSize(110, 80)
|
2014-05-26 14:41:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function createParameters()
|
2014-10-28 15:55:42 +00:00
|
|
|
local f = lf.Create("form"):SetName("Parameters")
|
2014-05-26 14:41:44 +00:00
|
|
|
|
|
|
|
local l = lf.Create("list")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetSpacing(5)
|
|
|
|
:SetPadding(5)
|
|
|
|
:SetSize(340, 565)
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(l)
|
|
|
|
|
|
|
|
|
|
|
|
-- Waveforms
|
|
|
|
l:AddItem(lf.Create("text"):SetPos(0, pheight):SetText("Wave Form"))
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
local m = lf.Create("multichoice")
|
2014-11-12 23:40:11 +00:00
|
|
|
for i = 0, #waveFormList do
|
|
|
|
m:AddChoice(waveFormList[i])
|
|
|
|
end
|
|
|
|
m:SetChoice("Square")
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
m.OnChoiceSelected = function(o, c)
|
|
|
|
sound.wavetype = waveFormList[c]
|
|
|
|
end
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
l:AddItem(m)
|
|
|
|
guiparams.waveform = m
|
|
|
|
|
|
|
|
|
|
|
|
-- Repeat speed
|
2014-10-28 15:55:42 +00:00
|
|
|
local t = lf.Create("text")
|
|
|
|
:SetText("Repeat Speed 0")
|
|
|
|
:SetPos(0, pheight)
|
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
local s = lf.Create("slider")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetWidth(120)
|
|
|
|
:SetMinMax(0, 1)
|
|
|
|
:SetValue(sound.repeatspeed)
|
|
|
|
|
2014-08-26 18:09:21 +00:00
|
|
|
s.OnValueChanged = function(o)
|
|
|
|
local v = o:GetValue()
|
|
|
|
if v <= 0.02 and v >= -0.02 and v ~= 0 then
|
|
|
|
o:SetValue(0)
|
2014-05-26 14:41:44 +00:00
|
|
|
sound.repeatspeed = 0
|
2014-08-26 18:09:21 +00:00
|
|
|
t:SetText("Repeat Speed 0")
|
2014-05-26 14:41:44 +00:00
|
|
|
else
|
|
|
|
sound.repeatspeed = v
|
|
|
|
t:SetText("Repeat Speed " .. tostring(math.floor(v * 100) / 100))
|
|
|
|
end
|
|
|
|
end
|
2014-10-28 15:55:42 +00:00
|
|
|
|
|
|
|
l:AddItem(t):AddItem(s)
|
2014-05-26 14:41:44 +00:00
|
|
|
guiparams.repeatspeed = {s, t}
|
|
|
|
|
|
|
|
|
|
|
|
for i1, v1 in ipairs(guicategories) do
|
2014-10-28 15:55:42 +00:00
|
|
|
local c = lf.Create("collapsiblecategory"):SetText(v1[1])
|
2014-05-26 14:41:44 +00:00
|
|
|
l:AddItem(c)
|
|
|
|
|
|
|
|
local p = lf.Create("panel")
|
|
|
|
local pheight = 0
|
|
|
|
p.Draw = function() end
|
|
|
|
c:SetObject(p)
|
|
|
|
|
|
|
|
guiparams[v1[2]] = {}
|
|
|
|
|
|
|
|
for i2, v2 in ipairs(v1[3]) do
|
2014-10-28 15:55:42 +00:00
|
|
|
lf.Create("text", p)
|
|
|
|
:SetText(v2[1])
|
|
|
|
:SetPos(0, pheight)
|
|
|
|
|
|
|
|
local t = lf.Create("text", p)
|
|
|
|
:SetText("0")
|
|
|
|
:SetPos(95, pheight)
|
2014-05-26 14:41:44 +00:00
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
local s = lf.Create("slider", p)
|
|
|
|
:SetPos(130, pheight - 3)
|
|
|
|
:SetWidth(170)
|
|
|
|
:SetMinMax(v2[3], v2[4])
|
|
|
|
:SetValue(sound[v1[2]][v2[2]])
|
2014-05-26 14:41:44 +00:00
|
|
|
|
2014-08-26 18:09:21 +00:00
|
|
|
s.OnValueChanged = function(o)
|
|
|
|
local v = o:GetValue()
|
|
|
|
if v <= 0.02 and v >= -0.02 and v ~= 0 then
|
|
|
|
o:SetValue(0)
|
2014-05-26 14:41:44 +00:00
|
|
|
sound[v1[2]][v2[2]] = 0
|
2014-08-26 18:09:21 +00:00
|
|
|
t:SetText("0")
|
2014-05-26 14:41:44 +00:00
|
|
|
else
|
|
|
|
sound[v1[2]][v2[2]] = v
|
|
|
|
t:SetText(math.floor(v * 100) / 100)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
guiparams[v1[2]][v2[2]] = {s, t}
|
|
|
|
pheight = pheight + 30
|
|
|
|
end
|
|
|
|
|
|
|
|
p:SetHeight(pheight - 10)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
f:SetPos(125, 5):SetSize(350, 590)
|
2014-05-26 14:41:44 +00:00
|
|
|
end
|
|
|
|
|
2014-06-20 12:48:38 +00:00
|
|
|
function createActionButtons()
|
2014-10-28 15:55:42 +00:00
|
|
|
local f = lf.Create("form"):SetName("Actions")
|
2014-05-26 14:41:44 +00:00
|
|
|
|
|
|
|
local b = lf.Create("button")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetText("Generate and Play")
|
|
|
|
:SetWidth(140)
|
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
b.OnClick = function(o)
|
|
|
|
if not playing then
|
|
|
|
playSound()
|
|
|
|
else
|
|
|
|
stopSound()
|
|
|
|
end
|
|
|
|
end
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
playbutton = b
|
|
|
|
f:AddItem(b)
|
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
|
2014-07-28 16:40:04 +00:00
|
|
|
local fr = lf.Create("frame")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetName("File Picker")
|
|
|
|
:SetSize(400, 300)
|
|
|
|
:Center()
|
|
|
|
:SetVisible(false)
|
|
|
|
:SetModal(false)
|
2016-03-01 23:37:06 +00:00
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
local frl = lf.Create("columnlist", fr)
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetPos(5, 30)
|
|
|
|
:SetSize(390, 235)
|
|
|
|
:AddColumn("Name")
|
2014-08-27 21:10:58 +00:00
|
|
|
|
|
|
|
local frt = lf.Create("textinput", fr)
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetPos(5, 270)
|
|
|
|
:SetWidth(300)
|
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
local frb = lf.Create("button", fr)
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetPos(315, 270)
|
2014-08-27 21:10:58 +00:00
|
|
|
|
|
|
|
frl.OnRowSelected = function(p, row, data)
|
|
|
|
frt:SetText(data[1])
|
|
|
|
end
|
|
|
|
|
2014-07-28 16:40:04 +00:00
|
|
|
fr.OnClose = function(o)
|
2014-08-27 21:10:58 +00:00
|
|
|
frl:Clear()
|
2014-07-28 16:40:04 +00:00
|
|
|
fr:SetVisible(false):SetModal(false)
|
|
|
|
return false
|
|
|
|
end
|
2014-08-27 21:10:58 +00:00
|
|
|
|
2014-11-12 23:40:11 +00:00
|
|
|
local function saveHandler(type, cb)
|
2014-08-27 21:10:58 +00:00
|
|
|
return function()
|
|
|
|
fr:SetName("Save to ." .. type)
|
|
|
|
frt:SetText("sound." .. type)
|
|
|
|
frb:SetText("Save")
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
love.filesystem.getDirectoryItems("sounds", function(name)
|
|
|
|
if name:find(type, #type-#name+1, true) then
|
|
|
|
frl:AddRow(name)
|
|
|
|
end
|
|
|
|
end)
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
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)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
frt.OnEnter = frb.OnClick
|
2014-10-28 15:55:42 +00:00
|
|
|
fr:SetVisible(true)
|
|
|
|
:SetModal(true)
|
|
|
|
:Center()
|
2014-08-27 21:10:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-12 23:40:11 +00:00
|
|
|
local function loadHandler(type, cb)
|
2014-08-27 21:10:58 +00:00
|
|
|
return function()
|
|
|
|
fr:SetName("Load from ." .. type)
|
|
|
|
frt:SetText("sound." .. type)
|
|
|
|
frb:SetText("Load")
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
love.filesystem.getDirectoryItems("sounds", function(name)
|
|
|
|
if name:find(type, #type-#name+1, true) then
|
|
|
|
frl:AddRow(name)
|
|
|
|
end
|
|
|
|
end)
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
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
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
frt.OnEnter = frb.OnClick
|
2014-10-28 15:55:42 +00:00
|
|
|
fr:SetVisible(true)
|
|
|
|
:SetModal(true)
|
|
|
|
:Center()
|
2014-08-27 21:10:58 +00:00
|
|
|
end
|
2014-07-28 16:40:04 +00:00
|
|
|
end
|
2014-08-27 21:10:58 +00:00
|
|
|
|
2014-07-28 16:40:04 +00:00
|
|
|
|
2014-06-20 13:03:24 +00:00
|
|
|
local sb = lf.Create("button")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetText("Save Lua")
|
|
|
|
:SetWidth(67)
|
2014-11-12 23:40:11 +00:00
|
|
|
sb.OnClick = saveHandler("lua", function(f) sound:save(f, true) end)
|
2014-06-20 13:03:24 +00:00
|
|
|
f:AddItem(sb)
|
2014-06-20 12:48:38 +00:00
|
|
|
|
2014-06-20 13:03:24 +00:00
|
|
|
local lb = lf.Create("button")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetText("Load Lua")
|
|
|
|
:SetWidth(67)
|
2016-01-02 13:54:57 +00:00
|
|
|
lb.OnClick = loadHandler("lua", function(f) sound:load(f) end)
|
2014-06-20 13:03:24 +00:00
|
|
|
f:AddItem(lb)
|
2014-06-20 12:48:38 +00:00
|
|
|
|
2014-08-20 18:16:38 +00:00
|
|
|
local bsb = lf.Create("button")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetText("Save binary")
|
|
|
|
:SetWidth(67)
|
2014-11-12 23:40:11 +00:00
|
|
|
bsb.OnClick = saveHandler("sfs", function(f) sound:saveBinary(f) end)
|
2014-08-20 18:16:38 +00:00
|
|
|
f:AddItem(bsb)
|
|
|
|
|
|
|
|
local blb = lf.Create("button")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetText("Load binary")
|
|
|
|
:SetWidth(67)
|
2014-11-12 23:40:11 +00:00
|
|
|
blb.OnClick = loadHandler("sfs", function(f) sound:loadBinary(f) end)
|
2014-08-20 18:16:38 +00:00
|
|
|
f:AddItem(blb)
|
|
|
|
|
2014-06-20 13:03:24 +00:00
|
|
|
local eb = lf.Create("button")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetText("Export WAV")
|
|
|
|
:SetWidth(140)
|
2014-11-12 23:40:11 +00:00
|
|
|
eb.OnClick = saveHandler("wav", function(f) sound:exportWAV(f) end)
|
2014-06-20 13:03:24 +00:00
|
|
|
f:AddItem(eb)
|
2014-06-20 12:48:38 +00:00
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
f:SetPos(485, 455):SetSize(150, 140)
|
2014-06-20 13:03:24 +00:00
|
|
|
|
|
|
|
lb:SetPos(78, 47)
|
2014-08-20 18:16:38 +00:00
|
|
|
bsb:SetY(77)
|
|
|
|
blb:SetPos(78, 77)
|
|
|
|
eb:SetY(107)
|
2014-05-26 14:41:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function createOther()
|
|
|
|
local f = lf.Create("form")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetName("Wave View")
|
|
|
|
:SetPos(485, 5)
|
|
|
|
:SetSize(150, 170)
|
|
|
|
|
2014-08-27 21:10:58 +00:00
|
|
|
local draw = function(o)
|
|
|
|
if source then
|
2020-06-05 07:00:08 +00:00
|
|
|
love.graphics.setColor(1, 1, 1)
|
2014-08-27 21:10:58 +00:00
|
|
|
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
|
2020-06-05 07:00:08 +00:00
|
|
|
love.graphics.setColor(1, 0.6, 0)
|
2014-08-27 21:10:58 +00:00
|
|
|
love.graphics.line(x, 25, x, 165)
|
|
|
|
end
|
|
|
|
|
2020-06-05 07:07:47 +00:00
|
|
|
lf.GetActiveSkin().form(o)
|
2014-08-27 21:10:58 +00:00
|
|
|
end
|
|
|
|
f.Draw = draw
|
2014-05-26 14:41:44 +00:00
|
|
|
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
local f = lf.Create("form"):SetName("Volume")
|
2014-05-26 14:41:44 +00:00
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
local t = lf.Create("text"):SetText("Master 0.5")
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(t)
|
2014-10-28 15:55:42 +00:00
|
|
|
|
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
local s = lf.Create("slider")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetMinMax(0, 1)
|
|
|
|
:SetSize(135, 20)
|
|
|
|
|
2014-08-26 18:09:21 +00:00
|
|
|
s.OnValueChanged = function(o)
|
|
|
|
local v = o:GetValue()
|
|
|
|
if v <= 0.52 and v >= 0.48 and v ~= 0.5 then
|
|
|
|
o:SetValue(0.5)
|
2014-05-26 14:41:44 +00:00
|
|
|
v = 0.5
|
|
|
|
end
|
|
|
|
sound.volume.master = v
|
|
|
|
t:SetText("Master " .. tostring(math.floor(v * 100) / 100))
|
|
|
|
end
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
s:SetValue(sound.volume.master)
|
|
|
|
f:AddItem(s)
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
|
|
|
|
local t = lf.Create("text"):SetText("Sound 0.5")
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(t)
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
local s = lf.Create("slider")
|
2014-10-28 15:55:42 +00:00
|
|
|
:SetMinMax(0, 1)
|
|
|
|
:SetSize(135, 20)
|
|
|
|
|
2014-08-26 18:09:21 +00:00
|
|
|
s.OnValueChanged = function(o)
|
|
|
|
local v = o:GetValue()
|
|
|
|
if v <= 0.52 and v >= 0.48 and v ~= 0.5 then
|
|
|
|
o:SetValue(0.5)
|
2014-05-26 14:41:44 +00:00
|
|
|
v = 0.5
|
|
|
|
end
|
|
|
|
sound.volume.sound = v
|
|
|
|
t:SetText("Sound " .. tostring(math.floor(v * 100) / 100))
|
|
|
|
end
|
2014-10-28 15:55:42 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
s:SetValue(sound.volume.sound)
|
|
|
|
f:AddItem(s)
|
|
|
|
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
f:SetPos(485, 340):SetWidth(150)
|
2014-05-26 14:41:44 +00:00
|
|
|
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
local f = lf.Create("form"):SetName("Times / Duration")
|
|
|
|
|
|
|
|
local t = lf.Create("text"):SetText("Generation: 0ms")
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(t)
|
|
|
|
statistics.generationtext = t
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
local t = lf.Create("text"):SetText("Transfer: 0ms")
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(t)
|
|
|
|
statistics.transfertext = t
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
local t = lf.Create("text"):SetText("Wave View: 0ms")
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(t)
|
|
|
|
statistics.waveviewtext = t
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
local t = lf.Create("text"):SetText("Duration: 0ms")
|
2014-05-26 14:41:44 +00:00
|
|
|
f:AddItem(t)
|
|
|
|
statistics.durationtext = t
|
|
|
|
|
2014-10-28 15:55:42 +00:00
|
|
|
f:SetPos(485, 185):SetWidth(150)
|
2014-05-26 14:41:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function updateParameters()
|
|
|
|
-- Iterate through the list of parameters and update all of them
|
|
|
|
for i1, v1 in ipairs(guicategories) do
|
|
|
|
for i2, v2 in ipairs(v1[3]) do
|
|
|
|
local v = sound[v1[2]][v2[2]]
|
|
|
|
local s, t = unpack(guiparams[v1[2]][v2[2]])
|
|
|
|
s:SetValue(v)
|
|
|
|
t:SetText(math.floor(v * 100) / 100)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local s, t = unpack(guiparams.repeatspeed)
|
|
|
|
local v = sound.repeatspeed
|
|
|
|
|
|
|
|
s:SetValue(v)
|
|
|
|
t:SetText("Repeat Speed " .. tostring(math.floor(v * 100) / 100))
|
|
|
|
|
2020-06-05 07:04:24 +00:00
|
|
|
guiparams.waveform:SetChoice(waveFormList[sound.waveform])
|
2014-05-26 14:41:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function updateWaveCanvas(waveview)
|
|
|
|
local t = love.timer.getTime()
|
|
|
|
love.graphics.setCanvas(wavecanvas)
|
2020-06-05 07:07:47 +00:00
|
|
|
love.graphics.clear(unpack(lf.GetActiveSkin().controls.frame_body_color))
|
2020-06-05 07:00:08 +00:00
|
|
|
love.graphics.setColor(1, 1, 1)
|
2014-05-26 14:41:44 +00:00
|
|
|
love.graphics.setLineStyle("rough")
|
|
|
|
|
|
|
|
-- Iterate through the passed table and draw all lines to the canvas
|
|
|
|
local step = 125 / #waveview
|
|
|
|
local last = 70
|
|
|
|
for i, v in ipairs(waveview) do
|
|
|
|
local x = (i * step)
|
2014-08-21 12:27:31 +00:00
|
|
|
local y = (-v + 1) * 70
|
2014-05-26 14:41:44 +00:00
|
|
|
|
|
|
|
love.graphics.line(x - step, last, x, y)
|
|
|
|
last = y
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Draw the zero line
|
2020-06-05 07:00:08 +00:00
|
|
|
love.graphics.setColor(1, 0.314, 0.2, 0.784)
|
2014-05-26 14:41:44 +00:00
|
|
|
love.graphics.line(0, 70, 125, 70)
|
|
|
|
|
|
|
|
love.graphics.setCanvas()
|
|
|
|
t = love.timer.getTime() - t
|
|
|
|
statistics.waveview = math.floor(t * 10000) / 10
|
|
|
|
end
|
|
|
|
|
|
|
|
function updateStatistics()
|
|
|
|
statistics.durationtext:SetText("Duration: " .. statistics.duration .. " ms")
|
|
|
|
statistics.transfertext:SetText("Transfer: " .. statistics.transfer .. " ms")
|
|
|
|
statistics.waveviewtext:SetText("Wave View: " .. statistics.waveview .. " ms")
|
|
|
|
statistics.generationtext:SetText("Generation: " .. statistics.generation .. " ms")
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.load()
|
2020-06-05 07:07:47 +00:00
|
|
|
lf.SetActiveSkin("Orange")
|
2016-03-01 23:37:06 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
love.graphics.setBackgroundColor(200, 200, 200)
|
|
|
|
|
2020-06-05 07:45:04 +00:00
|
|
|
local pathinfo = love.filesystem.getInfo("sounds")
|
|
|
|
if pathinfo == nil then
|
2014-08-27 21:10:58 +00:00
|
|
|
love.filesystem.createDirectory("sounds")
|
2020-06-05 07:45:04 +00:00
|
|
|
pathinfo = love.filesystem.getInfo("sounds")
|
2014-08-27 21:10:58 +00:00
|
|
|
end
|
2020-06-05 07:45:04 +00:00
|
|
|
assert(pathinfo.type == 'directory', '"sounds" exists in ' ..
|
|
|
|
love.filesystem.getRealDirectory('sounds') .. ' but is not a directory')
|
2014-08-27 21:10:58 +00:00
|
|
|
|
2014-05-26 14:41:44 +00:00
|
|
|
sound = sfxr.newSound()
|
|
|
|
|
|
|
|
createSeedBox()
|
|
|
|
createPresetGenerators()
|
|
|
|
createRandomizers()
|
|
|
|
createParameters()
|
2014-06-20 12:48:38 +00:00
|
|
|
createActionButtons()
|
2014-05-26 14:41:44 +00:00
|
|
|
createOther()
|
|
|
|
|
|
|
|
wavecanvas = love.graphics.newCanvas(125, 140)
|
|
|
|
|
|
|
|
love.mousepressed = lf.mousepressed
|
|
|
|
love.mousereleased = lf.mousereleased
|
|
|
|
love.keyreleased = lf.keyreleased
|
|
|
|
love.textinput = lf.textinput
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.update(dt)
|
|
|
|
lf.update(dt)
|
|
|
|
if source then
|
|
|
|
if playing and not source:isPlaying() then
|
|
|
|
playing = false
|
2014-06-20 13:03:24 +00:00
|
|
|
playbutton:SetText("Generate and Play")
|
2014-05-26 14:41:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.draw()
|
|
|
|
lf.draw()
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.keypressed(key)
|
2014-08-27 21:10:58 +00:00
|
|
|
if key == " " then
|
2014-05-26 14:41:44 +00:00
|
|
|
playSound()
|
|
|
|
elseif key == "escape" then
|
|
|
|
love.event.push("quit")
|
|
|
|
end
|
|
|
|
lf.keypressed(key)
|
|
|
|
end
|