-
Notifications
You must be signed in to change notification settings - Fork 0
/
playmode.lua
executable file
·169 lines (121 loc) · 4.02 KB
/
playmode.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
--dft setting
framerate=8
cycles=60/framerate
local function playFrom (param)
drawFunc=drawPlayback
updateFunc=updatePlayback
npress=false
cyclecount=0
--we use it to throttle longer frames
elapsedTc=0
pbIdx=param
end
function playFromFirst()
playFrom(1)
end
function toPlayback()
playFrom(currentIdx)
end
local function rendertouicanvas()
love.graphics.setCanvas(ui)
love.graphics.clear(0.5,0.5,0.5,0.5)
love.graphics.setColor(1.,1.,1.,1.0)
love.graphics.rectangle('fill',offsetcvs.x,offsetcvs.y,conf.cvsw*applicativezoom,conf.cvsh*applicativezoom)
--we blit optional BG
local key = 'f'..pbIdx
if mybg[key]~=nil then
love.graphics.draw(frames[mybg[key]].pic,offsetcvs.x,offsetcvs.y)
end
--TO TEST display color frame
lprevidx=pbIdx-1
if lprevidx>0 and frames[lprevidx].cf==true then
love.graphics.draw(frames[lprevidx].pic,offsetcvs.x,offsetcvs.y)
end
love.graphics.draw(frames[pbIdx].pic,offsetcvs.x,offsetcvs.y)
msgToCvs()
love.graphics.setCanvas()
end
function drawPlayback()
-- love.graphics.draw(buttonsPic)
rendertouicanvas()
--this is the background image of our paint
love.graphics.clear(1.,1.,1.,0.0)--
love.graphics.setColor(1.0,1.0,1.0,1.0)
love.graphics.draw(ui,0,0,0,scrsx,scrsy)
end
--data structure where we put a current repetition marker
currentRepetition=nil
-- contains the source repetition structure, including a transient data for the numer of run
--= {trigger=3,target=1,repetition=4, iteration= 1 -- 3 more to go, then we cancel }
function updatePlayback()
cyclecount=cyclecount+1
if cyclecount>cycles then
cyclecount=0
elapsedTc=elapsedTc+1
print('elapsed tc '..elapsedTc)
if elapsedTc>=frames[pbIdx].tc then
--TODO check if next frame is a trigger, let a marker to say once finished,
-- you go to loop
pbIdx=pbIdx+1
--only work for one tc 0
if (frames[pbIdx].tc<1 and pbIdx<maxframe)then
print('skipping 0tc frame')
pbIdx=pbIdx+1
end
--TODO should be mutualized with export
--if we are already in a repetition, we do not look
-- (overlap forbidden )
if currentRepetition~=nil then
print('in a repetition , we do not look for more')
--if we are in a repetition and new frame number is higher than trigger,
if pbIdx>currentRepetition.trigger then
--either we jump back ( still valid )
if currentRepetition.iteration<currentRepetition.repetition then
pbIdx=currentRepetition.target
currentRepetition.iteration=currentRepetition.iteration+1
else
--or we cancel repetition ( it is other )
currentRepetition.iteration=nil
currentRepetition=nil
end
end
else
--we look for apotential new one
local pot =repetitions[pbIdx]
if pot~=nil then
print(' repetition pointer on frame '..pbIdx)
print(' repetitions for new idx,tgt: '..pot.target )
--TODO setup
currentRepetition=pot
currentRepetition.iteration=0 --we jump on frame end
else
print('no repetition for frame '..pbIdx)
end
end
elapsedTc=0
print('next frame')
--we trigger sound if new frame has one
if frames[pbIdx].sound~=nil then
print('playing sound for frame '..pbIdx)
love.audio.play(frames[pbIdx].sound)
end
end
end
if pbIdx>=maxframe then
pbIdx=1
toPaintMode()
return
end
if npress==true and npy>(conf.cvsh-256) then
-- if npx<brshLineWidth then
-- brshradius=npy/uih * brshMaxRad
-- mybrush=love.graphics.newImage(roundBrushWithAlpha( brshradius,0.0,0.0,0.0))
-- mybrush:setFilter('nearest','nearest')
-- else
currentIdx=pbIdx
initCanvases(currentIdx)
resetUndo()
toPaintMode()
-- end
end
end