Skip to content

Commit c788bb4

Browse files
committed
working pattern record
1 parent e4dd35c commit c788bb4

3 files changed

Lines changed: 75 additions & 33 deletions

File tree

animator.lua

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ local animator = include('lib/animator')
2626
local ui = include('lib/ui')
2727
local GRID = include('lib/Grid')
2828
local g = grid.connect()
29-
local pattern_time = require 'pattern_time'
3029
engine.name = 'MollyThePoly'
3130

3231
function init()
@@ -53,14 +52,6 @@ function init()
5352
end
5453
animator.noteOffMetro.event = animator.allNotesOff
5554
animator.clock:start()
56-
animator.pattern = pattern_time.new()
57-
animator.pattern.process = function(e)
58-
if e.delta then
59-
enc(e.n, e.delta)
60-
else
61-
animator.grid:handleBottomRowSelect(e.x, e.y)
62-
end
63-
end
6455
animator.redraw()
6556
end
6657

@@ -93,8 +84,6 @@ function key(n, z)
9384
end
9485

9586
function enc(n, delta)
96-
local e = {n = n, delta = delta}
97-
animator.pattern:watch(e)
9887
if n == 2 then
9988
animator.moveSequencers('y', delta, constants.CANVAS_HEIGHT)
10089
animator.redraw()

lib/Grid.lua

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local pattern_time = require 'pattern_time'
12
local constants = include('animator/lib/constants')
23
local helpers = include('animator/lib/helpers')
34
local GRID_LENGTH = constants.GRID_LENGTH
@@ -6,8 +7,9 @@ local CANVAS_HEIGHT = constants.CANVAS_HEIGHT
67
local NAV_ROW = constants.GRID_NAV_ROW
78
local GRID_LEVELS = constants.GRID_LEVELS
89
local SNAPSHOT_NUM = 8
10+
local PATTERN_NUM = 4
911
local g = grid.connect()
10-
local CLEAR_POSITION = SNAPSHOT_NUM + 1
12+
local CLEAR_POSITION = 15
1113
local TOGGLE_VIEW_POSITION = constants.CANVAS_LENGTH
1214
local DIV_START = GRID_LENGTH - 8
1315
local INTERSECT_START = 2
@@ -23,12 +25,21 @@ function GRID.new(animator)
2325
animator = animator,
2426
view = 1,
2527
selected = 1,
28+
patterns = {},
2629
}
2730
setmetatable(g, GRID)
2831
setmetatable(g, {__index = GRID})
2932

3033
g.viewKeyHandlers = {g.mainKeyHandler, g.optionsKeyHandler}
3134
g.viewRedraws = {g.redrawMain, g.redrawOptions}
35+
36+
for i=1,PATTERN_NUM do
37+
g.patterns[i] = pattern_time.new()
38+
g.patterns[i].process = function(e)
39+
g:handleBottomRowSelect(e.x, e.y)
40+
end
41+
end
42+
3243
return g
3344
end
3445

@@ -40,7 +51,7 @@ end
4051
function GRID:redrawMain()
4152
g:all(0)
4253
drawSteps(self.animator.stepLevels)
43-
redrawBottomRow(self.snapshot)
54+
self:redrawBottomRow()
4455
g:refresh()
4556
end
4657

@@ -75,17 +86,7 @@ function GRID:optionsKeyHandler(x, y, z)
7586
end
7687
end
7788

78-
function GRID:mainKeyDown(x, y, held)
79-
if y == NAV_ROW and x == 13 then
80-
return self.animator.pattern:rec_start();
81-
end
82-
if y == NAV_ROW and x == 14 then
83-
return self.animator.pattern:rec_stop();
84-
end
85-
if y == NAV_ROW and x == 15 then
86-
return self.animator.pattern:start();
87-
end
88-
89+
function GRID:mainKeyDown(x, y)
8990
if y <= CANVAS_HEIGHT then
9091
self:handleSequence(x, y)
9192
elseif y == NAV_ROW then
@@ -111,12 +112,48 @@ end
111112

112113
function GRID:handleBottomRowSelect(x, y)
113114
local animator = self.animator
115+
local isClearHeld = self.held and self.held.y == NAV_ROW and self.held.x == CLEAR_POSITION
116+
117+
local function stopOtherPattern(current, patterns)
118+
for i=1,PATTERN_NUM do
119+
local otherPat = patterns[i]
120+
if i ~= current and (otherPat.rec == 1 or otherPat.play == 1) then
121+
otherPat:rec_stop()
122+
otherPat:stop()
123+
end
124+
end
125+
end
126+
114127
if x >= 1 and x <= SNAPSHOT_NUM then
115128
local e = {x=x, y=y}
116-
local isClearHeld = self.held and self.held.y == NAV_ROW and self.held.x == CLEAR_POSITION
117129
animator.handleSelectSnapshot(x, isClearHeld)
118130
self.snapshot = x
119-
self.animator.pattern:watch(e)
131+
132+
for i=1,PATTERN_NUM do
133+
self.patterns[i]:watch(e)
134+
end
135+
136+
animator.redraw()
137+
elseif x >= 10 and x <= 13 then
138+
local i = x - 9
139+
local pattern = self.patterns[i]
140+
if isClearHeld then
141+
pattern:rec_stop()
142+
pattern:stop()
143+
pattern:clear();
144+
elseif pattern.rec == 1 then
145+
pattern:rec_stop()
146+
pattern:stop()
147+
pattern:start();
148+
elseif pattern.count == 0 then
149+
stopOtherPattern(i, self.patterns)
150+
pattern:rec_start()
151+
elseif pattern.play == 1 then
152+
pattern:stop()
153+
else
154+
stopOtherPattern(i, self.patterns)
155+
pattern:start()
156+
end
120157
animator.redraw()
121158
elseif x == CLEAR_POSITION then
122159
self:setHeld(x, y)
@@ -213,6 +250,21 @@ function GRID:drawOptions(selected)
213250
end
214251
end
215252

253+
function GRID:redrawBottomRow()
254+
for i=1,SNAPSHOT_NUM do
255+
if self.snapshot == i then
256+
g:led(i, NAV_ROW, GRID_LEVELS.HIGH)
257+
elseif self.animator.snapshots[i] ~= nil then
258+
g:led(i, NAV_ROW, GRID_LEVELS.LOW_MED)
259+
else
260+
g:led(i, NAV_ROW, GRID_LEVELS.DIM)
261+
end
262+
end
263+
drawPatterns(self.patterns);
264+
g:led(CLEAR_POSITION, NAV_ROW, GRID_LEVELS.DIM)
265+
drawToggleViewPad()
266+
end
267+
216268
function drawSteps(levels)
217269
local findXY = helpers.findXY
218270
for pos,level in pairs(levels) do
@@ -221,13 +273,14 @@ function drawSteps(levels)
221273
end
222274
end
223275

224-
function redrawBottomRow(snapshot)
225-
for i=1,SNAPSHOT_NUM do
226-
g:led(i, NAV_ROW, snapshot == i and GRID_LEVELS.HIGH or GRID_LEVELS.LOW_MED)
276+
function drawPatterns(patterns)
277+
for i=1,PATTERN_NUM do
278+
local x = i+9
279+
if patterns[i].rec == 1 then g:led(x, NAV_ROW, GRID_LEVELS.HIGH)
280+
elseif patterns[i].play == 1 then g:led(x, NAV_ROW, GRID_LEVELS.MED)
281+
elseif patterns[i].count > 0 then g:led(x, NAV_ROW, GRID_LEVELS.LOW_MED)
282+
else g:led(x, NAV_ROW, GRID_LEVELS.DIM) end
227283
end
228-
229-
g:led(CLEAR_POSITION, NAV_ROW, GRID_LEVELS.DIM)
230-
drawToggleViewPad()
231284
end
232285

233286
function getNewLineSteps(a, b)

lib/constants.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ local constants = {
2222
CANVAS_LENGTH = GRID_LENGTH,
2323
GRID_NAV_ROW = 8,
2424
LFO_NUM = 2,
25-
GRID_LEVELS = {DIM = 2, LOW_MED = 4, MED = 8, HIGH = 14 },
25+
GRID_LEVELS = {DIM = 2, LOW_MED = 5, MED = 9, HIGH = 15},
2626
INTERSECT_OP_NONE = NONE,
2727
INTERSECT_OP_OCTAVE = OCTAVE,
2828
INTERSECT_OP_MUTE = MUTE,

0 commit comments

Comments
 (0)