-
Notifications
You must be signed in to change notification settings - Fork 1
/
Export.pde
579 lines (494 loc) · 18.1 KB
/
Export.pde
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
ArrayList <Footage> agendaLib;
ArrayList <Footage> creditLib;
ArrayList <Footage> otherLib;
Footage blankFootage;
int idCounter;
int idCounterSeq;
// Variables for export settings
String expCreditsPath;
String expCreditsLeft;
String expCreditsRight;
int expCreditsMax;
int expCreditsMin;
String expAgendasPath;
String expAgendasLeft;
String expAgendasRight;
int expAgendasMax;
int expAgendasMin;
ArrayList <AnimConfig> expAnims;
long premiereFrame = 8475667200L; // Weird-ass Premiere unit. This is how long a single frame is when specificing Workspace In/Out. FML.
void export(String _path) {
loadConfig();
println("Exporting to " + _path);
idCounter = 1;
idCounterSeq = 1;
buildAnimLib();
blankFootage = new Footage();
blankFootage.path = "";
blankFootage.name = "BLANK";
blankFootage.value = 0;
blankFootage.side = LEFTPLAYER;
blankFootage.duration = 18000;
blankFootage.clipitemid = "clipitem-" + idCounter;
blankFootage.fileid = "file-" + idCounter;
blankFootage.masterclipid = "masterclip-" + idCounter;
idCounter++;
otherLib.add(blankFootage);
buildAgendaLib();
buildCreditLib();
XML _xml;
_xml = new XML("xmeml");
_xml.setString("version", "4");
XML _xmlProject = _xml.addChild("project");
_xmlProject.addChild("name").setContent("Test Export");
XML _xmlChildren = _xmlProject.addChild("children");
_xmlChildren.addChild(exportLib(agendaLib, "Lockwell - Agendas"));
_xmlChildren.addChild(exportLib(creditLib, "Lockwell - Credits"));
_xmlChildren.addChild(exportLib(otherLib, "Lockwell - Other"));
// Actually export Timeline
if (videoCon == null) {
println("No videoCon!");
} else {
_xmlChildren.addChild(exportTimeline(videoCon, videoCon.file));
}
saveXML(_xml, _path);
println("Export done");
}
void exportMult(String _path) {
loadConfig();
println("Exporting list to " + _path);
idCounter = 1;
idCounterSeq = 1;
buildAnimLib();
blankFootage = new Footage();
blankFootage.path = "";
blankFootage.name = "BLANK";
blankFootage.value = 0;
blankFootage.side = LEFTPLAYER;
blankFootage.duration = 18000;
blankFootage.clipitemid = "clipitem-" + idCounter;
blankFootage.fileid = "file-" + idCounter;
blankFootage.masterclipid = "masterclip-" + idCounter;
idCounter++;
otherLib.add(blankFootage);
buildAgendaLib();
buildCreditLib();
XML _xml;
_xml = new XML("xmeml");
_xml.setString("version", "4");
XML _xmlProject = _xml.addChild("project");
_xmlProject.addChild("name").setContent("Test Export");
XML _xmlChildren = _xmlProject.addChild("children");
_xmlChildren.addChild(exportLib(agendaLib, "Lockwell - Agendas"));
_xmlChildren.addChild(exportLib(creditLib, "Lockwell - Credits"));
_xmlChildren.addChild(exportLib(otherLib, "Lockwell - Other"));
// Actually export Timelines
VideoContainer tempVCon;
for (int i = 0; i < exportList.length; i++) {
// Derive Video Data filename from Movie Path
String vDataPath = exportList[i].substring(0, exportList[i].lastIndexOf('.')) + ".lockwell";
// Check if XML for Video Data already exists
if (!fileExists(vDataPath)) {
println(vDataPath + " does not exist");
} else {
tempVCon = new VideoContainer(); //<>//
loadVData(vDataPath, tempVCon);
_xmlChildren.addChild(exportTimeline(tempVCon, exportList[i]));
}
}
saveXML(_xml, _path);
println("Export done");
}
XML exportTimeline(VideoContainer _vCon, String _name) {
int aniCount = 1;
ArrayList <Keyframe> _aniLeftOvers = null;
XML _ret;
_ret = new XML("sequence");
_ret.setString("id", "sequence-" + idCounterSeq);
idCounterSeq++;
long frames = int(_vCon.duration * 29.97);
_ret.setString("MZ.WorkOutPoint", String.format("%d",premiereFrame * frames));
_ret.setString("MZ.WorkInPoint", "0");
_ret.addChild("name").setContent(_name);
_ret.addChild("duration").setContent("0");
_ret.addChild(rateXML());
XML _media = _ret.addChild("media");
XML _video = _media.addChild("video");
_video.addChild("format").addChild(sticsXML());
XML _track;
_track = _video.addChild("track");
_track.setString("MZ.TrackName", "Video");
_track.addChild("enabled").setContent("TRUE");
_track.addChild("locked").setContent("FALSE");
if (gapTracks > 0) {
for (int i = 0; i < gapTracks; i++) {
_track = _video.addChild("track");
_track.setString("MZ.TrackName", "Gap Track " + (i+1));
_track.addChild("enabled").setContent("TRUE");
_track.addChild("locked").setContent("FALSE");
}
}
_track = _video.addChild("track");
_track.setString("MZ.TrackName", "Credits R");
_track.addChild("enabled").setContent("TRUE");
_track.addChild("locked").setContent("FALSE");
keyframesToClips(_track, _vCon, RIGHTPLAYER, KFCREDITS, null);
_track = _video.addChild("track");
_track.setString("MZ.TrackName", "Credits L");
_track.addChild("enabled").setContent("TRUE");
_track.addChild("locked").setContent("FALSE");
keyframesToClips(_track, _vCon, LEFTPLAYER, KFCREDITS, null);
_track = _video.addChild("track");
_track.setString("MZ.TrackName", "Agendas R");
_track.addChild("enabled").setContent("TRUE");
_track.addChild("locked").setContent("FALSE");
keyframesToClips(_track, _vCon, RIGHTPLAYER, KFAGENDAS, null);
_track = _video.addChild("track");
_track.setString("MZ.TrackName", "Agendas L");
_track.addChild("enabled").setContent("TRUE");
_track.addChild("locked").setContent("FALSE");
keyframesToClips(_track, _vCon, LEFTPLAYER, KFAGENDAS, null);
// Export animations
do {
_track = _video.addChild("track");
_track.setString("MZ.TrackName", "Anims " + aniCount);
_track.addChild("enabled").setContent("TRUE");
_track.addChild("locked").setContent("FALSE");
_aniLeftOvers = keyframesToClips(_track, _vCon, BOTHPLAYERS, KFANIMS, _aniLeftOvers);
aniCount = aniCount + 1;
} while (_aniLeftOvers.size() > 0);
_track = _video.addChild("track");
_track.setString("MZ.TrackName", "Notes");
_track.addChild("enabled").setContent("TRUE");
_track.addChild("locked").setContent("FALSE");
keyframesToClips(_track, _vCon, LEFTPLAYER, KFCOMMENTS, null);
XML _audio = _media.addChild("audio");
XML _audioFormat = _audio.addChild("format");
XML _audioFormatChar = _audioFormat.addChild("samplecharacteristics");
_audioFormatChar.addChild("depth").setContent("16");
_audioFormatChar.addChild("samplerate").setContent("48000");
return _ret;
}
ArrayList <Keyframe> keyframesToClips(XML _track, VideoContainer _vCon, int _sideFilter, int _typeFilter, ArrayList <Keyframe> _lastLeftOvers) {
// Outputs keyframes of a specific type to an XML parent
// Returns leftover keyframes if one track wasn't enough
// The latter is used for animations
// Warning. This has grown to be a bit of Spaghetti Code.
Keyframe _tempF1 = null;
Keyframe _tempF2 = null;
Keyframe _tempF3 = null;
int frameIn;
int frameOut;
int frameIn2;
int frameOut2;
int frameLength;
Boolean overlap = false;
Footage _footage;
ArrayList <Keyframe> _kf ;
ArrayList <Footage> _lib;
ArrayList <Keyframe> _filtered;
ArrayList <Keyframe> _leftOvers = new ArrayList <Keyframe>();
if (_lastLeftOvers != null) {
_kf = _lastLeftOvers;
_filtered = _lastLeftOvers;
} else {
_kf = _vCon.keyframes;
// Get a filtered Arraylist
_filtered = filterKeyframes(_kf, _sideFilter, _typeFilter);
// Sort by time
sortByTime(_filtered);
}
if (_typeFilter == KFAGENDAS) {
_lib = agendaLib;
} else if (_typeFilter == KFCREDITS) {
_lib = creditLib;
} else if (_typeFilter == KFCOMMENTS) {
_lib = null;
} else if (_typeFilter == KFANIMS) {
_lib = otherLib;
} else {
println("Can't keyframesToClips. Unknown type Filter " + _typeFilter);
return null;
}
if (_filtered != null) {
// Add an empty terminator keyframe to calulate length of the last segment
Keyframe _tkf = new Keyframe();
_tkf.time = _vCon.duration;
_tkf.type = _typeFilter;
_tkf.side = _sideFilter;
_tkf.value = 0;
_filtered.add(_tkf);
for (int i = 0; i < _filtered.size()-1; i++) {
overlap = false;
_tempF1 = _filtered.get(i);
_tempF2 = _filtered.get(i+1);
frameIn = int(_tempF1.time * 29.97);
frameOut = int(_tempF2.time * 29.97);
if (_typeFilter == KFCOMMENTS) {
frameOut = int((_tempF1.time+1.0f) * 29.97);
} else if (_typeFilter == KFANIMS) {
frameOut = frameIn + round(_tempF1.duration * 29.97);
}
if (frameIn != frameOut) {
frameLength = frameOut - frameIn;
_footage = null;
if (_typeFilter == KFCOMMENTS) {
_footage = blankFootage;
} else if (_typeFilter == KFANIMS) {
// If Animation, check if it overlaps with a previous animation
if (i > 0) {
for (int j = 0; j < i; j++) {
_tempF3 = _filtered.get(j);
frameIn2 = int(_tempF3.time * 29.97);
frameOut2 = frameIn2 + int(_tempF3.duration * 29.97);
if ((frameIn2 < frameIn && frameOut2 > frameIn) || (frameIn2 >= frameIn && frameIn2 < frameOut)) {
// Current animation is overlapping with a previous one.
// Put this into the leftover ArrayList
_leftOvers.add(_tempF1);
overlap = true;
break;
}
}
}
// Now find the clip associated with the keyframe
if (!overlap) {
for (int j = 0; j < _lib.size() && _footage == null; j++) {
_footage = _lib.get(j);
if (_footage.stringValue.equals(_tempF1.stringValue) == false) {
_footage = null;
}
}
if (_footage != null) {
frameOut = frameIn + _footage.duration;
frameLength = _footage.duration;
}
}
} else {
for (int j = 0; j < _lib.size() && _footage == null; j++) {
_footage = _lib.get(j);
if (_footage.value != _tempF1.value || _footage.side != _tempF1.side) {
_footage = null;
}
}
}
if (_footage == null && !overlap) {
println("Problems in keyframesToClips. Can't find value " + _tempF1.value + " for type " + _typeFilter + " for side " + _tempF1.side);
} else if (!overlap) {
XML _clipItem = _track.addChild("clipitem");
_clipItem.addChild("masterclipid").setContent(_footage.masterclipid);
if (_typeFilter == KFCOMMENTS) {
_clipItem.addChild("name").setContent(_tempF1.stringValue);
_clipItem.addChild("enabled").setContent("TRUE");
} else {
_clipItem.addChild("name").setContent(_footage.name);
_clipItem.addChild("enabled").setContent("TRUE");
}
_clipItem.addChild("start").setContent("" + frameIn);
_clipItem.addChild("end").setContent("" + frameOut);
if (_typeFilter != KFCOMMENTS && _typeFilter != KFANIMS) {
_clipItem.addChild("in").setContent("120");
_clipItem.addChild("out").setContent("" + (120 + frameLength));
} else {
_clipItem.addChild("in").setContent("0");
_clipItem.addChild("out").setContent("" + frameLength);
_clipItem.addChild("duration").setContent("" + frameLength);
}
_clipItem.addChild("alphatype").setContent("straight");
_clipItem.addChild("file").setString("id", _footage.fileid);
// Add transform filter if clip is supposed to appear at a certain postion
if (_tempF1.x != 0.0 || _tempF1.y != 0.0) {
_clipItem.addChild(filterXML(_tempF1.x, _tempF1.y));
}
}
}
}
}
return _leftOvers;
}
XML exportLib(ArrayList <Footage> _lib, String _name) {
XML _ret;
_ret = new XML("bin");
_ret.addChild("name").setContent(_name);
XML _children = _ret.addChild("children");
for (int i=0; i < _lib.size(); i++) {
Footage _tempF = _lib.get(i);
XML _tempX = _children.addChild("clip");
// clip ID
// frameblend
// uuid
_tempX.setString("id", _tempF.masterclipid);
_tempX.setString("frameBlend", "FALSE");
_tempX.addChild("masterclipid").setContent(_tempF.masterclipid);
_tempX.addChild("ismasterclip").setContent("TRUE");
_tempX.addChild("duration").setIntContent(_tempF.duration);
_tempX.addChild(rateXML());
_tempX.addChild("name").setContent(_tempF.name);
XML _tempM = _tempX.addChild("media");
XML _video = _tempM.addChild("video");
XML _track = _video.addChild("track");
XML _clip = _track.addChild("clipitem");
_clip.setString("id", _tempF.clipitemid);
_clip.setString("frameBlend", "FALSE");
_clip.addChild("masterclipid").setContent(_tempF.masterclipid);
_clip.addChild("name").setContent(_tempF.name);
XML _file = _clip.addChild("file");
_file.setString("id", _tempF.fileid);
_file.addChild("name").setContent(_tempF.name);
if (_tempF.path != "") {
_file.addChild("pathurl").setContent(_tempF.path);
} else {
_file.addChild("mediaSource").setContent("Slug");
}
_file.addChild(rateXML());
XML _media2 = _file.addChild("media");
XML _video2 = _media2.addChild("video");
_video2.addChild("duration").setIntContent(_tempF.duration);
_video2.addChild(sticsXML());
}
return _ret;
}
XML filterXML(float _x, float _y) {
XML _ret = new XML("filter");
XML _effect = _ret.addChild("effect");
_effect.addChild("name").setContent("Basic Motion");
_effect.addChild("effectid").setContent("basic");
_effect.addChild("effectcategory").setContent("motion");
_effect.addChild("effecttype").setContent("motion");
_effect.addChild("mediatype").setContent("video");
XML _param = _effect.addChild("parameter");
_param.setString("authoringApp", "PremierePro");
_param.addChild("parameterid").setContent("center");
_param.addChild("name").setContent("Center");
XML _val = _param.addChild("value");
_val.addChild("horiz").setFloatContent(_x);
_val.addChild("vert").setFloatContent(_y);
return _ret;
}
XML rateXML() {
XML _ret = new XML("rate");
_ret.addChild("timebase").setContent("30");
_ret.addChild("ntsc").setContent("TRUE");
return _ret;
}
XML sticsXML() {
XML _stics = new XML("samplecharacteristics");
_stics.addChild(rateXML());
_stics.addChild("width").setContent("1920");
_stics.addChild("height").setContent("1080");
_stics.addChild("anamorphic").setContent("FALSE");
_stics.addChild("pixelaspectratio").setContent("square");
_stics.addChild("fielddominance").setContent("none");
_stics.addChild("colordepth").setContent("24");
return _stics;
}
void buildAgendaLib() {
String agendaPath = expAgendasPath;
String fileTemplateL = expAgendasLeft;
String fileTemplateR = expAgendasRight;
int min = expAgendasMin;
int max = expAgendasMax;
agendaLib = new ArrayList<Footage>();
for (int i=min; i <= max; i++) {
String fleL = fillInNumbers(fileTemplateL, i);
String fleR = fillInNumbers(fileTemplateR, i);
Footage tempFL = new Footage();
tempFL.path = agendaPath + fleL;
tempFL.name = fleL;
tempFL.value = i;
tempFL.side = LEFTPLAYER;
tempFL.duration = 18000;
tempFL.clipitemid = "clipitem-" + idCounter;
tempFL.fileid = "file-" + idCounter;
tempFL.masterclipid = "masterclip-" + idCounter;
idCounter++;
Footage tempFR = tempFL.clone();
tempFR.path = agendaPath + fleR;
tempFR.name = fleR;
tempFR.side = RIGHTPLAYER;
tempFR.clipitemid = "clipitem-" + idCounter;
tempFR.fileid = "file-" + idCounter;
tempFR.masterclipid = "masterclip-" + idCounter;
idCounter++;
agendaLib.add(tempFL);
agendaLib.add(tempFR);
}
//println("Generated " + agendaLib.size() + " AgendaLib entries.");
}
void buildCreditLib() {
String creditPath = expCreditsPath;
String fileTemplateL = expCreditsLeft;
String fileTemplateR = expCreditsRight;
int min = expCreditsMin;
int max = expCreditsMax;
creditLib = new ArrayList<Footage>();
for (int i=min; i <= max; i++) {
String fleL = fillInNumbers(fileTemplateL, i);
String fleR = fillInNumbers(fileTemplateR, i);
Footage tempFL = new Footage();
tempFL.path = creditPath + fleL;
tempFL.name = fleL;
tempFL.value = i;
tempFL.side = LEFTPLAYER;
tempFL.duration = 18000;
tempFL.clipitemid = "clipitem-" + idCounter;
tempFL.fileid = "file-" + idCounter;
tempFL.masterclipid = "masterclip-" + idCounter;
idCounter++;
Footage tempFR = tempFL.clone();
tempFR.path = creditPath + fleR;
tempFR.name = fleR;
tempFR.side = RIGHTPLAYER;
tempFR.clipitemid = "clipitem-" + idCounter;
tempFR.fileid = "file-" + idCounter;
tempFR.masterclipid = "masterclip-" + idCounter;
idCounter++;
creditLib.add(tempFL);
creditLib.add(tempFR);
}
//println("Generated " + creditLib.size() + " CreditLib entries.");
}
void buildAnimLib() {
otherLib = new ArrayList <Footage>();
if (expAnims != null) {
for (int i=0; i < expAnims.size(); i++) {
AnimConfig _tAnimCfg = expAnims.get(i);
Footage tempFL = new Footage();
tempFL.path = _tAnimCfg.path + _tAnimCfg.file;
tempFL.name = _tAnimCfg.file;
tempFL.stringValue = _tAnimCfg.name;
tempFL.duration = _tAnimCfg.length;
tempFL.side = LEFTPLAYER;
tempFL.clipitemid = "clipitem-" + idCounter;
tempFL.fileid = "file-" + idCounter;
tempFL.masterclipid = "masterclip-" + idCounter;
idCounter++;
otherLib.add(tempFL);
}
}
println("Generated " + otherLib.size() + " OtherLib entries.");
}
String fillInNumbers(String _s, int _n) {
String ret = _s;
String dblN = String.format("%1$02d", _n);
String snlN = "" + _n;
ret = ret.replaceAll("##", dblN);
ret = ret.replaceAll("#", snlN);
return ret;
}
void fileSelectedExport(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
export(selection.getAbsolutePath());
}
frame.requestFocus();
}
void fileSelectedExportM(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
exportMult(selection.getAbsolutePath());
switchToLoad();
}
frame.requestFocus();
}