Skip to content

Instantly share code, notes, and snippets.

@Bradshaw
Created November 11, 2012 14:59
Show Gist options
  • Save Bradshaw/4055142 to your computer and use it in GitHub Desktop.
Save Bradshaw/4055142 to your computer and use it in GitHub Desktop.
local sounder_table = {}
sounder = {}
function sounder.play(name, pitch, volume)
if not sounder_table[name] then
print("This is new")
sounder_table[name] = {}
table.insert(sounder_table[name],love.audio.newSource(name))
else
local free = false
for i,v in ipairs(sounder_table[name]) do
if v:isStopped() then
print("Found freedom")
free = true
end
end
if not free then
print("Did not find freedom")
table.insert(sounder_table[name],love.audio.newSource(name))
end
end
local playme
for i,v in ipairs(sounder_table[name]) do
if v:isStopped() then
print(i.." is a candidate")
playme = i
end
end
if pitch then
sounder_table[name][playme]:setPitch(pitch)
end
if volume then
sounder_table[name][playme]:setVolume(volume)
end
print("Playing "..playme)
sounder_table[name][playme]:play()
end
function sounder.pitch(name, pitch, all)
if sounder_table[name] then
for i,v in ipairs(sounder_table[name]) do
if all or v:playing() then
v:setPitch(pitch)
end
end
end
end
function sounder.volume(name, volume, all)
if sounder_table[name] then
for i,v in ipairs(sounder_table[name]) do
if all or v:playing() then
v:setVolume(volume)
end
end
end
end
function sounder.stop(name)
if sounder_table[name] then
for i,v in ipairs(sounder_table[name]) do
v:stop()
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment