-
-
Save justmat/74532deb405ce7ce85438b12b5f49bd0 to your computer and use it in GitHub Desktop.
pattern time study
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- pattern_time study | |
pattern_time = require 'pattern_time' -- use the pattern_time lib in this script | |
function init() | |
grid_pattern = pattern_time.new() -- establish a pattern recorder | |
grid_pattern.process = grid_pattern_execute -- assign the function to be executed when the pattern plays back | |
grid_redraw() | |
end | |
g = grid.connect() -- hardware: grid connect | |
g.key = function(x,y,z) -- hardware: grid event (eg 'what happens when a button is pressed') | |
if z == 1 and y == 8 and x == 1 then -- the bottom left key is the pattern control key, if i press it... | |
if grid_pattern.rec == 1 then -- if we're recording... | |
grid_pattern:rec_stop() -- stop recording | |
grid_pattern:start() -- start playing | |
elseif grid_pattern.count == 0 then -- otherwise, if there are no events recorded.. | |
grid_pattern:rec_start() -- start recording | |
elseif grid_pattern.play == 1 then -- if we're playing... | |
grid_pattern:stop() -- stop playing | |
else -- if by this point, we're not playing... | |
grid_pattern:start() -- start playing | |
end | |
elseif z == 1 and y == 8 and x == 2 then -- the key to the right of the pattern control key... | |
grid_pattern:rec_stop() -- stops recording | |
grid_pattern:stop() -- stops playback | |
grid_pattern:clear() -- clears the pattern | |
g:all(0) -- clear the grid | |
end | |
if z == 1 and y ~= 8 then -- if we press any key above the bottom row... | |
record_this = {} -- create a table called "record_this" to put our events! | |
record_this.x = x -- here's an event, the key's x position | |
record_this.y = y -- here's another event, the key's y position | |
grid_pattern:watch(record_this) -- tell the pattern recorder to watch these events + commit them to memory | |
g:all(0) | |
g:led(x,y,z*15) | |
end | |
grid_redraw() | |
g:refresh() | |
end | |
function grid_pattern_execute(recorded) -- when the pattern plays back, do the following with each entry we recorded in 31-35 | |
g:all(0) | |
g:led(recorded.x,recorded.y,15) -- remember "record_this.x" and "record_this.y"? here, we're using that data and doing something with it! | |
grid_redraw() | |
g:refresh() | |
end | |
function grid_redraw() | |
if grid_pattern.rec == 1 then -- if we're recording... | |
g:led(1,8,10) -- medium-high brightness | |
elseif grid_pattern.play == 1 then -- if we're playing... | |
g:led(1,8,15) -- highest brightness | |
elseif grid_pattern.play == 0 and grid_pattern.count > 0 then -- if we're not playing, but the pattern isn't empty... | |
g:led(1,8,5) -- lower brightness | |
else -- otherwise, if we're not recording/playing and the pattern is empty... | |
g:led(1,8,3) -- lowest brightness | |
end | |
g:refresh() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment