-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimecodeBPMconvert.lua
executable file
·246 lines (165 loc) · 7.1 KB
/
TimecodeBPMconvert.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
local pluginName = select(1,...);
local componentName = select(2,...);
local signalTable = select(3,...);
local my_handle = select(4,...);
----------------------------------------------------------------------------------------------------------------
local PlugTitle = "Timecode BPM convert"
local messageDescription = "USE WITH CAUTION, TAKE BACKUPS.\n\n"..
"This tool will convert all the events on all your tracks in your timecode.\n\n"..
"The tool automagically convert BPM to the correct rate and moves all the data on the timeline\n\n"..
"It will create a new timecode object so you wont loose the source timeline"
-- Almost never tested.
-- No support is given.
-- Github: https://github.com/kinglevel
-- Instagram: @kinglevel
-- Please commit or post updates for the community
--[[
/mMNh-
NM33My
-ydds`
/.
ho
+yy/ `Md +yy/
.N33N` +MM. -N33N`
-+o/ hMMo o++-
d: `MMMm oy
-:. yNo` +MMMM- yM+ .:-`
d33N: /MMh. dMMMMs -dMM. :N33d
+ddd: `MMMm: .MMMMMN /NMMd :hdd+
``hh+. hMMMN+ +MMMMMM: `sMMMMo -ody `
-NMNh+. +MMMMMy`d_SUM_My.hMMMMM- -odNMm`
/MMMMNh+:MMMMMMmMMMMMMMNmMMMMMN-odNMMMN-
oMMMMMMNMMMMMMMMMMMMMMMMMMMMMMNMMMMMM/
hMMMMMMMMM---LEDvard---MMMMMMMMMMMMo
`mMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh
.NMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMm`
:mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm-
`://////////////////////////////.
-+ymMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNho/.
"Vision will blind. Severance ties. Median am I. True are all lies"
███╗ ███╗███████╗███████╗██╗ ██╗██╗ ██╗ ██████╗ ██████╗ █████╗ ██╗ ██╗
████╗ ████║██╔════╝██╔════╝██║ ██║██║ ██║██╔════╝ ██╔════╝ ██╔══██╗██║ ██║
██╔████╔██║█████╗ ███████╗███████║██║ ██║██║ ███╗██║ ███╗███████║███████║
██║╚██╔╝██║██╔══╝ ╚════██║██╔══██║██║ ██║██║ ██║██║ ██║██╔══██║██╔══██║
██║ ╚═╝ ██║███████╗███████║██║ ██║╚██████╔╝╚██████╔╝╚██████╔╝██║ ██║██║ ██║
╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
README: https://github.com/kinglevel/TimecodeBPMConvert
]]--
-- Confirm
local function ConfirmBox(displayHandle, message)
if Confirm(PlugTitle, message) then
return true
else
return false
end
end
-- Main window for user options
local function BPMsettings(displayHandle)
local options = {
title=PlugTitle,
backColor="Global.Focus",
icon="invert",
message=messageDescription,
display= nil,
commands={
{value=0, name="Abort"},
{value=1, name="Convert"}
},
inputs={
{name="Timecode Source", value="", blackFilter="", whiteFilter="0123456789"},
{name="Timecode Destination", value="", blackFilter="", whiteFilter="0123456789"},
{name="BPM Destination", value="", blackFilter="", whiteFilter="0123456789"},
{name="BPM Original", value="", blackFilter="", whiteFilter="0123456789"}
}
}
-- spawn main window
local userinput = MessageBox(options)
local confirm = userinput.result
-- Abort
if confirm == 0 then
Printf("Aborted by user")
return false
end
-- Push parameters
if confirm == 1 then
--get all variables from the user
local BPMoriginal = userinput.inputs["BPM Original"]
local BPMdestination = userinput.inputs["BPM Destination"]
local Timecode = userinput.inputs["Timecode Source"]
local TimecodeDst = userinput.inputs["Timecode Destination"]
--Proceed if all the needed data is present
if tonumber(BPMoriginal) ~= nil and tonumber(BPMdestination) ~= nil and tonumber(Timecode) ~= nil then
speedfactor = BPMdestination / BPMoriginal
return speedfactor, Timecode, TimecodeDst
else
Printf("Missing data")
return false
end
return false
end
end
local function EventTypes(o, maxDepth)
--Modified GMA3helper:tree
--Made for seeeing classes easier
local function printDirectory(dir, prefix, depth)
local i = 1;
if maxDepth then
if (depth > maxDepth) then return; end
end
while dir[i] do
local content = dir[i]
Printf(prefix..'|---'..content.index..': '..content.name..': '..content:GetClass())
printDirectory(content,prefix..'| ', depth+1) -- use recursion
i = i + 1;
end
end
printDirectory(o,'',1)
end
local function BPMConvert(obj, rate)
--Modified GMA3helper:tree
local function printDirectory(dir, prefix, depth)
local i = 1;
while dir[i] do
local content = dir[i]
--Get all the intresting event classes
if content:GetClass() == "FaderEvent" or content:GetClass() == "CmdEvent" then
--Get the Times
local time = content:Get("TIME")
--Set the Times
content:Set("TIME", time * rate)
end
printDirectory(content,prefix..'| ', depth+1) -- use recursion
i = i + 1;
end
end
printDirectory(obj,'',1)
end
local function Convert(displayHandle)
--Get all settings from the user
local speedfactor, timecodeSrc, timecodeDst = BPMsettings(displayHandle)
--Confirm the settings
local confirm = ConfirmBox(displayHandle, "Do you really want to convert all events on\n"..
"Timecode: \n" ..
timecodeSrc .. " --- " .. DataPool().Timecodes[tonumber(timecodeSrc)].name ..
"\nRate: \n" ..
speedfactor)
if confirm == true then
--Make backup
Cmd("ClearAll")
local X = Cmd("Copy timecode " .. timecodeSrc .. " at timecode " .. timecodeDst)
--If backup is ok and nothing in the way
if X == "OK" then
--Get timecode object
local song = DataPool().Timecodes[tonumber(timecodeDst)]
--Rate
local rate = tonumber(speedfactor)
--Magic like Harry Potter
BPMConvert(song, rate)
Cmd("Select timecode " .. timecodeDst)
end
end
end
local function main(displayHandle)
Convert(displayHandle)
end
return main