-
Notifications
You must be signed in to change notification settings - Fork 0
/
timecode.lua
executable file
·169 lines (125 loc) · 3.93 KB
/
timecode.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
local clockQuad = {x=64, y=64, w=64, h=64}
realCQuad=love.graphics.newQuad(clockQuad.x,clockQuad.y,clockQuad.w,clockQuad.h,buttonsPic:getWidth(),buttonsPic:getHeight())
local exitQuad = {x=4*64, y=64, w=64, h=64}
realExitQuad=love.graphics.newQuad(clockQuad.x,clockQuad.y,clockQuad.w,clockQuad.h,buttonsPic:getWidth(),buttonsPic:getHeight())
local applyToRangeQuad = {x=64, y=9*64, w=64, h=64}
function exitTC()
print('exit tc '..frames[currentIdx].tc)
toPaintMode()
end
function applyToRange()
--applying current time code to selected range
if rangeBeginIdx==nil or rangeEndIdx==nil then
print(' nil marker, not possible , cb '..cb.. ' ce ' .. ce)
return
end
if rangeEndIdx<=rangeBeginIdx then
print(' end marker before begin marker, not possible ')
return
end
for i=rangeBeginIdx,rangeEndIdx
do
print('frame '..i..' tc set '..frames[currentIdx].tc)
frames[i].tc=frames[currentIdx].tc
end
toPaintMode()
end
local widgets={}
createTCButtons=function()
widgets={}
wExitTc = createpicbutton(uiw-64*buttonZoom,0,buttonsPic,exitTC,exitQuad,buttonZoom)--0,buttonZoom,buttonZoom
wATRTc = createpicbutton(uiw-64*buttonZoom,64*buttonZoom,buttonsPic,applyToRange,applyToRangeQuad,buttonZoom)
table.insert(widgets,wExitTc)
table.insert(widgets,wATRTc)
end
--utility
function loadTxtCodes()
--TODO load zazanim style tcs ( for interop )
local tcf=love.filesystem.getInfo(conf.prjfld.."timecodes.txt")
if tcf ~= nil then
for sTc in love.filesystem.lines(conf.prjfld.."timecodes.txt")
do
addMsg(sTc)
addMsg(string.byte(sTc,1,3))
addMsg(string.sub(sTc,1,3))
local frmNum=tonumber(string.sub(sTc,1,3))
addMsg(string.sub(sTc,5,7))
local frmTc=tonumber(string.sub(sTc,5,7))
--TODO be careful zazanim has different indexes
if frames[frmNum]~=nil then
frames[frmNum].tc=frmTc
else
print('warning idx out of range '..frmNum)
end
end
end
end
function saveTxtCodes()
-- save zzn txt codes for interop
-- first frame 001:0tc ( 3 chars tc )
timecodestring=""
for i=1,maxframe
do
timecodestring=timecodestring..string.format("%03d",i)..":"..string.format("%03d",frames[i].tc).."\n"
end
love.filesystem.write(conf.prjfld.."timecodes.txt",timecodestring)
end
function toTimeCode()
print ('initial time code '..frames[currentIdx].tc )
addMsg('applicative zoom '..applicativezoom)
addMsg('button zoom '..buttonZoom)
createTCButtons()
uiResize=createTCButtons
drawFunc=timeCodeDraw
updateFunc=timeCodeUpdate
end
local function rendertouicanvas()
love.graphics.setCanvas(ui)
love.graphics.clear(1.0,1.0,1.0,0.0)
renderWidgets(widgets)
-- //should be define
maxcol=(uiw-64*buttonZoom) / ( 64*buttonZoom );
-- maxcol=(uiw-applicativezoom) / ( applicativezoom );
col=0
row=0
for i=1,frames[currentIdx].tc
do
-- love.graphics.draw(buttonsPic,realCQuad,col*64*applicativezoom,row*64*applicativezoom,0,applicativezoom,applicativezoom)
love.graphics.draw(buttonsPic,realCQuad,col*64*buttonZoom,row*64*buttonZoom,0,buttonZoom,buttonZoom)
col=col+1
if col>=(maxcol-1) then
col=0
row=row+1
end
end
msgToCvs()
love.graphics.setCanvas()
end
function timeCodeDraw()
rendertouicanvas()
--this is the background image of our paint
-- love.graphics.clear(1.,1.,1.,1.0)
love.graphics.clear(.5,.5,.5,1.0)
love.graphics.setColor(1.0,1.0,1.0,1.0)
love.graphics.draw(ui,0,0,0,scrsx,scrsy)
end
function timeCodeUpdate()
if npress==true then
print('tc click')
consumed=consumeClick(widgets)
print('consumed '..tostring(consumed))
if consumed==true
then
return
end
--we calculate the timecode
local xtc=math.floor(npx/(64*buttonZoom))
local ytc=math.floor(npy/(64*buttonZoom))
local tmp=(ytc*uiw/(64*buttonZoom -1) )+xtc
math.floor(tmp)
print('updating tc '..tmp)
if tmp<0 then tmp=0 end
frames[currentIdx].tc = tmp
npress=false
end
end