added sequencer class, fixed mistakes

This commit is contained in:
redlock 2011-03-11 11:51:45 +01:00
parent 2b5f567ea3
commit afe1fc46a8
2 changed files with 54 additions and 5 deletions

View File

@ -139,14 +139,14 @@ function b()
end
-- fill the screen with translucent black
function clear(alpha)
function clear_black(alpha)
love.graphics.setColor(0,0,0,alpha)
love.graphics.rectangle("fill", 0,0,800,600)
end
-- shorter clear
function cls(alpha)
clear(alpha)
clear_black(alpha)
end
-- one time clear
@ -329,7 +329,7 @@ function sin()
end
-- updates all objects in the _object table
function update_objects()
function update_objects(dt)
for i,v in ipairs(_internal_object_table) do
v:update(dt)
end

View File

@ -234,7 +234,9 @@ end
Image = Class(function(self, file, x, y, color, size, orientation)
self.image = love.graphics.newImage(file)
-- put positions, size, orientation...
self.size = size or 1
self.color = color or {255,255,255,255}
self.r = 0
-- call constructor of Drawable
Drawable.construct(self,x,y,color)
end)
@ -243,7 +245,7 @@ Image:inherit(Drawable)
-- #draw the image
function Image:draw()
love.graphics.setColor(unpack(self.color))
love.graphics.draw(self.image, self.position.x, self.position.y)
love.graphics.draw(self.image, self.position.x, self.position.y,self.r,self.size,self.size)
end
--[[
@ -272,6 +274,53 @@ function Point:draw()
end
--[[
Sequencer
--]]
Sequencer = Class(function(self,bpm, timeSig, phraseLength)
self.timer = 0
self.frame = 0
self.beat = 1
self.bar = 1
self.phrase = 1
self.bpm = bpm or 120
self.timeSignature = timeSig or 8
self.phraseLength = phraseLength or 4
self.newBeat = function() end
self.newBar = function() end
self.newPhrase = function() end
Object.construct(self)
end)
Sequencer:inherit(Object)
function Sequencer:update(dt)
self.timer = self.timer + dt
self.frame = self.frame + 1
local _fps = 30
local fpm = 30 * _fps
--print(math.floor(fpm))
if self.frame%(math.floor(fpm)/self.bpm) == 0 then
self.beat = self.beat + 1
self.newBeat()
if self.beat%self.timeSignature == 0 then
self.bar = self.bar + 1
self.newBar()
if self.bar%self.phraseLength == 0 then
self.phrase = self.phrase + 1
self.newPhrase()
end
end
end
end
-- EXAMPLE:
-- (put in love.load):
-- coco = Circle(300,300)