-
Notifications
You must be signed in to change notification settings - Fork 558
/
Copy pathPremiere.jsx
2996 lines (2692 loc) · 105 KB
/
Premiere.jsx
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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*************************************************************************
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2020 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it. If you have received this file from a source other than Adobe,
* then your use, modification, or distribution of it requires the prior
* written permission of Adobe.
**************************************************************************/
// time display types
var TIMEDISPLAY_24Timecode = 100;
var TIMEDISPLAY_25Timecode = 101;
var TIMEDISPLAY_2997DropTimecode = 102;
var TIMEDISPLAY_2997NonDropTimecode = 103;
var TIMEDISPLAY_30Timecode = 104;
var TIMEDISPLAY_50Timecode = 105;
var TIMEDISPLAY_5994DropTimecode = 106;
var TIMEDISPLAY_5994NonDropTimecode = 107;
var TIMEDISPLAY_60Timecode = 108;
var TIMEDISPLAY_Frames = 109;
var TIMEDISPLAY_23976Timecode = 110;
var TIMEDISPLAY_16mmFeetFrames = 111;
var TIMEDISPLAY_35mmFeetFrames = 112;
var TIMEDISPLAY_48Timecode = 113;
var TIMEDISPLAY_AudioSamplesTimecode = 200;
var TIMEDISPLAY_AudioMsTimecode = 201;
var KF_Interp_Mode_Linear = 0;
var KF_Interp_Mode_Hold = 4;
var KF_Interp_Mode_Bezier = 5;
var KF_Interp_Mode_Time = 6;
// field type constants
var FIELDTYPE_Progressive = 0;
var FIELDTYPE_UpperFirst = 1;
var FIELDTYPE_LowerFirst = 2;
// audio channel types
var AUDIOCHANNELTYPE_Mono = 0;
var AUDIOCHANNELTYPE_Stereo = 1;
var AUDIOCHANNELTYPE_51 = 2;
var AUDIOCHANNELTYPE_Multichannel = 3;
var AUDIOCHANNELTYPE_4Channel = 4;
var AUDIOCHANNELTYPE_8Channel = 5;
// vr projection type
var VRPROJECTIONTYPE_None = 0;
var VRPROJECTIONTYPE_Equirectangular = 1;
// vr stereoscopic type
var VRSTEREOSCOPICTYPE_Monoscopic = 0;
var VRSTEREOSCOPICTYPE_OverUnder = 1;
var VRSTEREOSCOPICTYPE_SideBySide = 2;
// constants used when clearing cache
var MediaType_VIDEO = "228CDA18-3625-4d2d-951E-348879E4ED93"; // Magical constants from Premiere Pro's internal automation.
var MediaType_AUDIO = "80B8E3D5-6DCA-4195-AEFB-CB5F407AB009";
var MediaType_ANY = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
var MediaType_Audio = 0; // Constants for working with setting value.
var MediaType_Video = 1;
var Colorspace_601 = 0;
var Colorspace_709 = 1;
var Colorspace_2020 = 2;
var Colorspace_2100HLG = 3;
var BitPrecision_8bit = 0;
var BitPrecision_10bit = 1;
var BitPrecision_Float = 2;
var BitPrecision_HDR = 3;
var NOT_SET = "-400000";
$._PPP_={
getVersionInfo : function () {
return 'PPro ' + app.version + 'x' + app.build;
},
getUserName : function () {
var userName = "User name not found.";
var homeDir = new File('~/');
if (homeDir) {
userName = homeDir.displayName;
homeDir.close();
}
return userName;
},
keepPanelLoaded : function () {
app.setExtensionPersistent("com.adobe.PProPanel", 0); // 0, while testing (to enable rapid reload); 1 for "Never unload me, even when not visible."
},
updateAllProjectItems : function () {
var numItems = app.project.rootItem.children.numItems;
for (var i = 0; i < numItems; i++) {
var currentItem = app.project.rootItem.children[i];
if (currentItem) {
currentItem.refreshMedia();
}
}
},
getSep : function () {
if (Folder.fs === 'Macintosh') {
return '/';
} else {
return '\\';
}
},
saveProject : function () {
app.project.save();
},
exportCurrentFrameAsPNG : function (presetPath) {
var seq = app.project.activeSequence;
if (seq) {
var currentSeqSettings = app.project.activeSequence.getSettings();
if (currentSeqSettings){
var currentTime = seq.getPlayerPosition();
if (currentTime){
var oldInPoint = seq.getInPointAsTime();
var oldOutPoint = seq.getOutPointAsTime();
var offsetTime = currentTime.seconds + 0.033; // Todo: Add fancy timecode math, to get one frame, given current sequence timebase
seq.setInPoint(currentTime.seconds);
seq.setOutPoint(offsetTime);
// Create a file name, based on timecode of frame.
var timeAsText = currentTime.getFormatted(currentSeqSettings.videoFrameRate, app.project.activeSequence.videoDisplayFormat);
var removeThese = /:|;/ig; // Why? Because Windows chokes on colons in file names.
var tidyTime = timeAsText.replace(removeThese, '_');
var outputPathInToOut = new File("~/Desktop/output/in_to_out");
var outputFileNameInToOut = outputPathInToOut.fsName + $._PPP_.getSep() + seq.name + '___' + tidyTime + '___' + ".png";
var removeUponCompletion = 1;
var startQueueImmediately = false;
var jobID_InToOut = app.encoder.encodeSequence( seq,
outputFileNameInToOut,
presetPath,
app.encoder.ENCODE_IN_TO_OUT,
removeUponCompletion,
startQueueImmediately);
// put in and out points back where we found them.
seq.setInPoint(oldInPoint.seconds);
seq.setOutPoint(oldOutPoint.seconds);
}
}
}
},
renameProjectItem : function () {
var item = app.project.rootItem.children[0]; // assumes the zero-th item in the project is footage.
if (item) {
item.name = item.name + ", updated by PProPanel.";
} else {
$._PPP_.updateEventPanel("No project items found.");
}
},
getActiveSequenceName : function () {
if (app.project.activeSequence) {
return app.project.activeSequence.name;
} else {
return "No active sequence.";
}
},
projectPanelSelectionChanged : function (eventObj) { // Note: This message is also triggered when the user opens or creates a new project.
var message = "";
var projectItems = eventObj;
if (projectItems) {
if (projectItems.length) {
var remainingArgs = projectItems.length;
var view = eventObj.viewID;
message = remainingArgs + " items selected: ";
for (var i = 0; i < projectItems.length; i++) { // Concatenate selected project item names, into message.
message += projectItems[i].name;
remainingArgs--;
if (remainingArgs > 1) {
message += ', ';
}
if (remainingArgs === 1) {
message += ", and ";
}
if (remainingArgs === 0) {
message += ".";
}
}
} else {
message = 'No items selected.';
}
}
$._PPP_.updateEventPanel(message);
},
registerProjectPanelSelectionChangedFxn : function () {
app.bind("onSourceClipSelectedInProjectPanel", $._PPP_.projectPanelSelectionChanged);
},
registerItemsAddedToProjectFxn : function () {
app.bind("onItemsAddedToProjectSuccess", $._PPP_.onItemsAddedToProject);
},
saveCurrentProjectLayout : function () {
var currentProjPanelDisplay = app.project.getProjectPanelMetadata();
if (currentProjPanelDisplay) {
var outFileName = app.project.name + '_Previous_Project_Panel_Display_Settings.xml';
var actualProjectPath = new File(app.project.path);
var projDir = actualProjectPath.parent;
if (actualProjectPath) {
var completeOutputPath = projDir + $._PPP_.getSep() + outFileName;
var outFile = new File(completeOutputPath);
if (outFile) {
outFile.encoding = "UTF8";
outFile.open("w", "TEXT", "????");
outFile.write(currentProjPanelDisplay);
$._PPP_.updateEventPanel("Saved layout to next to the project.");
outFile.close();
}
actualProjectPath.close();
}
} else {
$._PPP_.updateEventPanel("Could not retrieve current project layout.");
}
},
setProjectPanelMeta : function () {
var filterString = "";
if (Folder.fs === 'Windows') {
filterString = "XML files:*.xml";
}
var runningOnWindows = (Folder.fs === 'Windows');
if (runningOnWindows){
var fileToOpen = File.openDialog( "Choose Project panel layout to open.",
filterString,
false);
} else {
var fileToOpen = File.openDialog( "Choose Project panel layout to open.",
checkMacFileType,
false);
}
if (fileToOpen) {
if (fileToOpen.fsName.indexOf('.xml')) { // We should really be more careful, but hey, it says it's XML!
fileToOpen.encoding = "UTF8";
fileToOpen.open("r", "TEXT", "????");
var fileContents = fileToOpen.read();
if (fileContents) {
app.project.setProjectPanelMetadata(fileContents);
$._PPP_.updateEventPanel("Updated layout from .xml file.");
}
}
} else {
$._PPP_.updateEventPanel("No valid layout file chosen.");
}
},
exportSequenceAsPrProj : function () {
var activeSequence = app.project.activeSequence;
if (activeSequence) {
var startTimeOffset = activeSequence.zeroPoint;
var prProjExtension = '.prproj';
var outputName = activeSequence.name;
var outFolder = Folder.selectDialog();
if (outFolder) {
var completeOutputPath = outFolder.fsName +
$._PPP_.getSep() +
outputName +
prProjExtension;
app.project.activeSequence.exportAsProject(completeOutputPath);
$._PPP_.updateEventPanel("Exported " + app.project.activeSequence.name + " to " + completeOutputPath + ".");
} else {
$._PPP_.updateEventPanel("Could not find or create output folder.");
}
// Here's how to import N sequences from a project.
//
// var seqIDsToBeImported = new Array;
// seqIDsToBeImported[0] = ID1;
// ...
// seqIDsToBeImported[N] = IDN;
//
//app.project.importSequences(pathToPrProj, seqIDsToBeImported);
} else {
$._PPP_.updateEventPanel("No active sequence.");
}
},
createSequenceMarkers : function () {
var activeSequence = app.project.activeSequence;
if (activeSequence) {
var markers = activeSequence.markers;
if (markers) {
var numMarkers = markers.numMarkers;
if (numMarkers > 0) {
var marker_index = 1;
for (var current_marker = markers.getFirstMarker(); current_marker !== undefined; current_marker = markers.getNextMarker(current_marker)) {
if (current_marker.name !== "") {
$._PPP_.updateEventPanel('Marker ' + marker_index + ' name = ' + current_marker.name + '.');
} else {
$._PPP_.updateEventPanel('Marker ' + marker_index + ' has no name.');
}
$._PPP_.updateEventPanel('Marker ' + marker_index + ' GUID = ' + current_marker.guid + '.');
if (current_marker.end.seconds > 0) {
$._PPP_.updateEventPanel('Marker ' + marker_index + ' duration = ' + (current_marker.end.seconds - current_marker.start.seconds) + ' seconds.');
} else {
$._PPP_.updateEventPanel('Marker ' + marker_index + ' has no duration.');
}
$._PPP_.updateEventPanel('Marker ' + marker_index + ' starts at ' + current_marker.start.seconds + ' seconds.');
marker_index = marker_index + 1;
}
}
}
var newCommentMarker = markers.createMarker(12.345);
newCommentMarker.name = 'Marker created by PProPanel.';
newCommentMarker.comments = 'Here are some comments, inserted by PProPanel.';
newCommentMarker.end = (newCommentMarker.seconds + 5.0);
var newWebMarker = markers.createMarker(14.345);
newWebMarker.name = 'Web marker created by PProPanel.';
newWebMarker.comments = 'Here are some comments, inserted by PProPanel.';
newWebMarker.end = (newWebMarker.seconds + 3.0);
newWebMarker.setTypeAsWebLink("http://www.adobe.com", "frame target");
} else {
$._PPP_.updateEventPanel("No active sequence.");
}
},
exportFCPXML : function () {
if (app.project.activeSequence) {
var projPath = new File(app.project.path);
var parentDir = projPath.parent;
var outputName = app.project.activeSequence.name;
var xmlExtension = '.xml';
var outputPath = Folder.selectDialog("Choose the output directory");
if (outputPath) {
var completeOutputPath = outputPath.fsName + $._PPP_.getSep() + outputName + xmlExtension;
app.project.activeSequence.exportAsFinalCutProXML(completeOutputPath, 1); // 1 == suppress UI
var info = "Exported FCP XML for " +
app.project.activeSequence.name +
" to " +
completeOutputPath +
".";
$._PPP_.updateEventPanel(info);
} else {
$._PPP_.updateEventPanel("No output path chosen.");
}
} else {
$._PPP_.updateEventPanel("No active sequence.");
}
},
openInSource : function () {
var filterString = "";
if (Folder.fs === 'Windows') {
filterString = "All files:*.*";
}
var fileToOpen = File.openDialog("Choose file to open.", filterString, false);
if (fileToOpen) {
// It's often desirable to preview media in the source monitor, without forcing the
// generation of audio peak files. Here's how to do so.
var property = 'BE.Prefs.Audio.AutoPeakGeneration';
var initialValue = app.properties.getProperty(property);
var propValue = false;
var persistent = 1;
var allowToCreate = true;
if (initialValue === 'true') {
app.properties.setProperty('BE.Prefs.Audio.AutoPeakGeneration', propValue, persistent, allowToCreate);
}
app.sourceMonitor.openFilePath(fileToOpen.fsName);
if (initialValue === 'true') {
app.properties.setProperty(property, initialValue, persistent, allowToCreate);
}
app.sourceMonitor.play(1.0); // playback speed as float, 1.0 = normal speed forward
var position = app.sourceMonitor.getPosition();
$._PPP_.updateEventPanel("Current Source monitor position: " + position.seconds + " seconds.");
/* Example code for controlling scrubbing in Source monitor.
app.enableQE();
qe.source.player.startScrubbing();
qe.source.player.scrubTo('00;00;00;11');
qe.source.player.endScrubbing();
qe.source.player.step();
qe.source.player.play(playbackSpeed) // playbackSpeed must be between -4.0 and 4.0
*/
fileToOpen.close();
} else {
$._PPP_.updateEventPanel("No file chosen.");
}
},
searchForBinWithName : function (nameToFind) {
// deep-search a folder by name in project
var deepSearchBin = function (inFolder) {
if (inFolder && inFolder.name === nameToFind && inFolder.type === 2) {
return inFolder;
} else {
for (var i = 0; i < inFolder.children.numItems; i++) {
if (inFolder.children[i] && inFolder.children[i].type === 2) {
var foundBin = deepSearchBin(inFolder.children[i]);
if (foundBin) {
return foundBin;
}
}
}
}
};
return deepSearchBin(app.project.rootItem);
},
importFiles : function () {
var filterString = "";
if (Folder.fs === 'Windows') {
filterString = "All files:*.*";
}
if (app.project) {
var fileOrFilesToImport = File.openDialog( "Choose files to import", // title
filterString, // filter available files?
true); // allow multiple?
if (fileOrFilesToImport) {
// We have an array of File objects; importFiles() takes an array of paths.
var importThese = [];
if (importThese) {
for (var i = 0; i < fileOrFilesToImport.length; i++) {
importThese[i] = fileOrFilesToImport[i].fsName;
}
var suppressWarnings = true;
var importAsStills = false;
app.project.importFiles(importThese,
suppressWarnings,
app.project.getInsertionBin(),
importAsStills);
}
} else {
$._PPP_.updateEventPanel("No files to import.");
}
}
},
muteFun : function () {
if (app.project.activeSequence) {
for (var i = 0; i < app.project.activeSequence.audioTracks.numTracks; i++) {
var currentTrack = app.project.activeSequence.audioTracks[i];
if (Math.random() > 0.5) {
var muteState = 0;
if (currentTrack.isMuted()) {
muteState = 1;
}
currentTrack.setMute(muteState);
}
}
} else {
$._PPP_.updateEventPanel("No active sequence.");
}
},
disableImportWorkspaceWithProjects : function () {
var prefToModify = 'FE.Prefs.ImportWorkspace';
var propertyExists = app.properties.doesPropertyExist(prefToModify);
var propertyIsReadOnly = app.properties.isPropertyReadOnly(prefToModify);
var propertyValue = app.properties.getProperty(prefToModify);
app.properties.setProperty(prefToModify, "0", 1, false);
var safetyCheck = app.properties.getProperty(prefToModify);
if (safetyCheck != propertyValue) {
$._PPP_.updateEventPanel("Changed \'Import Workspaces with Projects\' from " + propertyValue + " to " + safetyCheck + ".");
}
},
setWorkspace : function() {
var desiredWSName = prompt('Which workspace would you like?', 'Editing', 'Which workspace?');
var workspaces = app.getWorkspaces();
var foundIt = false;
if (workspaces) {
$._PPP_.updateEventPanel(workspaces.length + " workspaces found.");
for (var i = 0; ((i < workspaces.length) && (foundIt === false)); i++) {
var currentWS = workspaces[i];
if (currentWS === desiredWSName) {
app.setWorkspace(currentWS);
foundIt = true;
$._PPP_.updateEventPanel("Workspace set to " + currentWS + ".");
}
}
if (foundIt === false) {
$._PPP_.updateEventPanel("Workspace named " + desiredWSName + " was not found.");
}
}
},
turnOffStartDialog : function () {
var prefToModify = 'MZ.Prefs.ShowQuickstartDialog';
var propertyExists = app.properties.doesPropertyExist(prefToModify);
var propertyIsReadOnly = app.properties.isPropertyReadOnly(prefToModify);
var originalValue = app.properties.getProperty(prefToModify);
app.properties.setProperty(prefToModify, "0", 1, true); // optional 4th param:0 = non-persistent, 1 = persistent (default)
var safetyCheck = app.properties.getProperty(prefToModify);
if (safetyCheck != originalValue) {
$._PPP_.updateEventPanel("Start dialog now OFF. Enjoy!");
} else {
$._PPP_.updateEventPanel("Start dialog was already OFF.");
}
},
replaceMedia : function () {
// Note: This method of changing paths for projectItems is from the time
// before PPro supported full-res AND proxy paths for each projectItem.
// This can still be used, and will change the hi-res projectItem path, but
// if your panel supports proxy workflows, it should rely instead upon
// projectItem.setProxyPath() instead.
var firstProjectItem = app.project.rootItem.children[0];
if (firstProjectItem) {
if (firstProjectItem.canChangeMediaPath()) {
// setScaleToFrameSize() ensures that for all clips created from this footage,
// auto scale to frame size will be ON, regardless of the current user preference.
// This is important for proxy workflows, to avoid mis-scaling upon replacement.
// Addendum: This setting will be in effect the NEXT time the projectItem is added to a
// sequence; it will not affect or reinterpret clips from this projectItem, already in
// sequences.
firstProjectItem.setScaleToFrameSize();
var filterString = "";
if (Folder.fs === 'Windows') {
filterString = "All files:*.*";
}
var replacementMedia = File.openDialog( "Choose new media file, for " +
firstProjectItem.name,
filterString, // file filter
false); // allow multiple?
if (replacementMedia) {
var suppressWarnings = true;
firstProjectItem.name = replacementMedia.name + ", formerly known as " + firstProjectItem.name;
firstProjectItem.changeMediaPath(replacementMedia.fsName, suppressWarnings);
replacementMedia.close();
}
} else {
$._PPP_.updateEventPanel("Couldn't change path of " + firstProjectItem.name + ".");
}
} else {
$._PPP_.updateEventPanel("No project items found.");
}
},
openProject : function () {
var filterString = "";
if (Folder.fs === 'Windows') {
filterString = "Premiere Pro project files:*.prproj";
}
var projToOpen = File.openDialog( "Choose project:",
filterString,
false);
if ((projToOpen) && projToOpen.exists) {
app.openDocument( projToOpen.fsName, // Path to project
false, // suppress 'Convert Project' dialogs?
false, // suppress 'Locate Files' dialogs?
false, // suppress warning dialogs?
false); // prevent document from getting added to MRU list?
projToOpen.close();
}
},
exportFramesForMarkers : function () {
var activeSequence = app.project.activeSequence;
if (activeSequence) {
var markers = activeSequence.markers;
var markerCount = markers.numMarkers;
if (markerCount) {
var firstMarker = markers.getFirstMarker();
if (firstMarker){
var previousMarker;
activeSequence.setPlayerPosition(firstMarker.start.ticks);
$._PPP_.exportCurrentFrameAsPNG();
var currentMarker;
for (var i = 0; i < markerCount; i++) {
if (i === 0) {
currentMarker = markers.getNextMarker(firstMarker);
} else {
currentMarker = markers.getNextMarker(previousMarker);
}
if (currentMarker) {
activeSequence.setPlayerPosition(currentMarker.start.ticks);
previousMarker = currentMarker;
$._PPP_.exportCurrentFrameAsPNG();
}
}
}
} else {
$._PPP_.updateEventPanel("No markers applied to " + activeSequence.name + ".");
}
} else {
$._PPP_.updateEventPanel("No active sequence.");
}
},
createSequence : function (name) {
var someID = "xyz123";
var seqName = prompt('Name of sequence?', '<<<default>>>', 'Sequence Naming Prompt');
app.project.createNewSequence(seqName, someID);
},
createSequenceFromPreset : function (presetPath) {
app.enableQE();
var seqName = prompt('Name of sequence?', '<<<default>>>', 'Sequence Naming Prompt');
if (seqName) {
qe.project.newSequence(seqName, presetPath);
}
},
transcode : function (outputPresetPath) {
app.encoder.bind('onEncoderJobComplete', $._PPP_.onEncoderJobComplete);
app.encoder.bind('onEncoderJobError', $._PPP_.onEncoderJobError);
app.encoder.bind('onEncoderJobProgress', $._PPP_.onEncoderJobProgress);
app.encoder.bind('onEncoderJobQueued', $._PPP_.onEncoderJobQueued);
app.encoder.bind('onEncoderJobCanceled', $._PPP_.onEncoderJobCanceled);
var projRoot = app.project.rootItem.children;
if (projRoot.numItems) {
var firstProjectItem = app.project.rootItem.children[0];
if (firstProjectItem) {
app.encoder.launchEncoder(); // This can take a while; let's get the ball rolling.
var fileOutputPath = Folder.selectDialog("Choose the output directory");
if (fileOutputPath) {
var regExp = new RegExp('[.]');
var outputName = firstProjectItem.name.search(regExp);
if (outputName == -1) {
outputName = firstProjectItem.name.length;
}
var outFileName = firstProjectItem.name.substr(0, outputName);
outFileName = outFileName.replace('/', '-');
var completeOutputPath = fileOutputPath.fsName + $._PPP_.getSep() + outFileName + '.mxf';
var removeFromQueue = 1;
var rangeToEncode = app.encoder.ENCODE_IN_TO_OUT;
app.encoder.encodeProjectItem( firstProjectItem,
completeOutputPath,
outputPresetPath,
rangeToEncode,
removeFromQueue);
app.encoder.startBatch();
}
} else {
$._PPP_.updateEventPanel("No project items found.");
}
} else {
$._PPP_.updateEventPanel("Project is empty.");
}
},
transcodeExternal : function (outputPresetPath) {
app.encoder.launchEncoder();
var filterString = "";
if (Folder.fs === 'Windows') {
filterString = "All files:*.*";
}
var fileToTranscode = File.openDialog("Choose file to open.",
filterString,
false);
if (fileToTranscode) {
var fileOutputPath = Folder.selectDialog("Choose the output directory");
if (fileOutputPath) {
var srcInPoint = new Time();
srcInPoint.seconds = 1.0; // encode start time at 1s (optional--if omitted, encode entire file)
var srcOutPoint = new Time();
srcOutPoint.seconds = 3.0; // encode stop time at 3s (optional--if omitted, encode entire file)
var removeFromQueue = 0;
var result = app.encoder.encodeFile(fileToTranscode.fsName,
fileOutputPath.fsName,
outputPresetPath,
removeFromQueue,
srcInPoint,
srcOutPoint);
}
}
},
render : function (outputPresetPath) {
app.enableQE();
var activeSequence = qe.project.getActiveSequence(); // we use a QE DOM function, to determine the output extension.
if (activeSequence) {
var ameInstalled = false;
var ameStatus = BridgeTalk.getStatus("ame");
if (ameStatus == "ISNOTINSTALLED") {
$._PPP_.updateEventPanel("AME is not installed.");
} else {
if (ameStatus == 'ISNOTRUNNING') {
app.encoder.launchEncoder(); // This can take a while; let's get the ball rolling.
}
var seqInPointAsTime = app.project.activeSequence.getInPointAsTime();
var seqOutPointAsTime = app.project.activeSequence.getOutPointAsTime();
var useLast = false;
var outputPath = app.encoder.lastExportMediaFolder();
if (outputPath) {
useLast = confirm("Use most recent output folder", false, "Use most recent?");
} else {
if (useLast === false) {
var outFolder = Folder.selectDialog("Choose the output directory");
if (outFolder) {
outputPath = outFolder.fsName;
}
}
}
var outPreset = new File(outputPresetPath);
if (outPreset.exists === true) {
var outputFormatExtension = activeSequence.getExportFileExtension(outPreset.fsName);
if (outputFormatExtension) {
var outputFilename = activeSequence.name + '.' + outputFormatExtension;
var fullPathToFile = outputPath +
activeSequence.name +
"." +
outputFormatExtension;
var outFileTest = new File(fullPathToFile);
if (outFileTest.exists) {
var destroyExisting = confirm("A file with that name already exists; overwrite?", false, "Are you sure...?");
if (destroyExisting) {
outFileTest.remove();
outFileTest.close();
}
}
app.encoder.bind('onEncoderJobComplete', $._PPP_.onEncoderJobComplete);
app.encoder.bind('onEncoderJobError', $._PPP_.onEncoderJobError);
app.encoder.bind('onEncoderJobProgress', $._PPP_.onEncoderJobProgress);
app.encoder.bind('onEncoderJobQueued', $._PPP_.onEncoderJobQueued);
app.encoder.bind('onEncoderJobCanceled', $._PPP_.onEncoderJobCanceled);
app.encoder.setSidecarXMPEnabled(0); // use these 0 or 1 settings to disable some/all metadata creation.
app.encoder.setEmbeddedXMPEnabled(0);
/*
For reference, here's how to export from within PPro (blocking further user interaction).
var seq = app.project.activeSequence;
if (seq) {
seq.exportAsMediaDirect(fullPathToFile,
outPreset.fsName,
app.encoder.ENCODE_WORKAREA);
Bonus: Here's how to compute a sequence's duration, in ticks. 254016000000 ticks/second.
var sequenceDuration = app.project.activeSequence.end - app.project.activeSequence.zeroPoint;
}
*/
var removeFromQueueUponSuccess = 1;
var jobID = app.encoder.encodeSequence( app.project.activeSequence,
fullPathToFile,
outPreset.fsName,
app.encoder.ENCODE_WORKAREA,
removeFromQueueUponSuccess);
$._PPP_.updateEventPanel('jobID = ' + jobID);
outPreset.close();
}
} else {
$._PPP_.updateEventPanel("Could not find output preset.");
}
}
} else {
$._PPP_.updateEventPanel("No active sequence.");
}
},
saveProjectCopy : function () {
var sessionCounter = 1;
var originalPath = app.project.path;
var outputPath = Folder.selectDialog("Choose the output directory");
if (outputPath) {
var absPath = outputPath.fsName;
var outputName = String(app.project.name);
var array = outputName.split('.', 2);
outputName = array[0] + sessionCounter + '.' + array[1];
sessionCounter++;
var fullOutPath = absPath + $._PPP_.getSep() + outputName;
app.project.saveAs(fullOutPath);
for (var a = 0; a < app.projects.numProjects; a++) {
var currentProject = app.projects[a];
if (currentProject.path === fullOutPath) {
// Why do this first? So we don't frighten the user by making PPro's front-most window disappear. :)
app.openDocument(originalPath, true, true, true, true);
currentProject.closeDocument();
}
}
} else {
$._PPP_.updateEventPanel("No output path chosen.");
}
},
mungeXMP : function () {
var projectItem = app.project.rootItem.children[0]; // assumes first item is footage.
if (projectItem) {
if (ExternalObject.AdobeXMPScript === undefined) {
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
}
if (ExternalObject.AdobeXMPScript !== undefined) {
var xmpBlob = projectItem.getXMPMetadata();
var xmp = new XMPMeta(xmpBlob);
var oldSceneVal = "";
var oldDMCreatorVal = "";
if (xmp.doesPropertyExist(XMPConst.NS_DM, "scene") === true) {
var myScene = xmp.getProperty(XMPConst.NS_DM, "scene");
oldSceneVal = myScene.value;
}
if (xmp.doesPropertyExist(XMPConst.NS_DM, "creator") === true) {
var myCreator = xmp.getProperty(XMPConst.NS_DM, "creator");
oldDMCreatorVal = myCreator.value;
}
// Regardless of whether there WAS scene or creator data, set scene and creator data.
xmp.setProperty(XMPConst.NS_DM, "scene", oldSceneVal + " Added by PProPanel sample!");
xmp.setProperty(XMPConst.NS_DM, "creator", oldDMCreatorVal + " Added by PProPanel sample!");
// That was the NS_DM creator; here's the NS_DC creator.
var creatorProp = "creator";
var containsDMCreatorValue = xmp.doesPropertyExist(XMPConst.NS_DC, creatorProp);
var numCreatorValuesPresent = xmp.countArrayItems(XMPConst.NS_DC, creatorProp);
var CreatorsSeparatedBy4PoundSigns = "";
if (numCreatorValuesPresent > 0) {
// If there are existing entries, append
for (var z = 0; z < numCreatorValuesPresent; z++) {
CreatorsSeparatedBy4PoundSigns = CreatorsSeparatedBy4PoundSigns + xmp.getArrayItem(XMPConst.NS_DC, creatorProp, z + 1);
CreatorsSeparatedBy4PoundSigns = CreatorsSeparatedBy4PoundSigns + "####";
}
$._PPP_.updateEventPanel(CreatorsSeparatedBy4PoundSigns);
if (confirm("Replace previous?", false, "Replace existing Creator?")) {
xmp.deleteProperty(XMPConst.NS_DC, "creator");
}
xmp.appendArrayItem(XMPConst.NS_DC, // If no values exist, appendArrayItem will create a value.
creatorProp,
numCreatorValuesPresent + " creator values were already present.",
null,
XMPConst.ARRAY_IS_ORDERED);
} else {
// If this is the first entry, write something else.
xmp.appendArrayItem(XMPConst.NS_DC,
creatorProp,
"PProPanel wrote the first value into NS_DC creator field.",
null,
XMPConst.ARRAY_IS_ORDERED);
}
var xmpAsString = xmp.serialize(); // either way, serialize and write XMP.
projectItem.setXMPMetadata(xmpAsString);
}
} else {
$._PPP_.updateEventPanel("Project item required.");
}
},
getProductionByName : function (nameToGet) {
var production;
var allProductions = app.anywhere.listProductions();
for (var i = 0; i < allProductions.numProductions; i++) {
var currentProduction = allProductions[i];
if (currentProduction.name === nameToGet) {
production = currentProduction;
}
}
return production;
},
pokeAnywhere : function () {
var token = app.anywhere.getAuthenticationToken();
var productionList = app.anywhere.listProductions();
if (app.anywhere.isProductionOpen()) {
var sessionURL = app.anywhere.getCurrentEditingSessionURL();
var selectionURL = app.anywhere.getCurrentEditingSessionSelectionURL();
var activeSequenceURL = app.anywhere.getCurrentEditingSessionActiveSequenceURL();
var theOneIAskedFor = $._PPP_.getProductionByName("test");
if (theOneIAskedFor) {
var out = theOneIAskedFor.name + ", " + theOneIAskedFor.description;
$._PPP_.updateEventPanel("Found: " + out); // todo: put useful code here.
}
} else {
$._PPP_.updateEventPanel("No Production open.");
}
},
dumpOMF : function () {
var activeSequence = app.project.activeSequence;
if (activeSequence) {
var outputPath = Folder.selectDialog("Choose the output directory");
if (outputPath) {
var absPath = outputPath.fsName;
var outputName = String(activeSequence.name) + '.omf';
var fullOutPathWithName = absPath + $._PPP_.getSep() + outputName;
app.project.exportOMF( app.project.activeSequence, // sequence
fullOutPathWithName, // output file path
'OMFTitle', // OMF title
48000, // sample rate (48000 or 96000)
16, // bits per sample (16 or 24)
1, // audio encapsulated flag (1:yes or 0:no)
0, // audio file format (0:AIFF or 1:WAV)
0, // trim audio files (0:no or 1:yes)
0, // handle frames (if trim is 1, handle frames from 0 to 1000)
0); // include pan flag (0:no or 1:yes)
}
} else {
$._PPP_.updateEventPanel("No active sequence.");
}
},
addClipMarkers : function () {
if (app.project.rootItem.children.numItems > 0) {
var projectItem = app.project.rootItem.children[0]; // assumes first item is footage.
if (projectItem) {
if (projectItem.type == ProjectItemType.CLIP || projectItem.type == ProjectItemType.FILE) {
var markers = projectItem.getMarkers();
if (markers) {
var numMarkers = markers.numMarkers;
var newMarker = markers.createMarker(12.345);
var guid = newMarker.guid;
newMarker.name = 'Marker created by PProPanel.';
newMarker.comments = 'Here are some comments, inserted by PProPanel.';
newMarker.end = (newMarker.start.seconds + 5.0);
//default marker type == comment. To change marker type, call one of these:
// newMarker.setTypeAsChapter();
// newMarker.setTypeAsWebLink();
// newMarker.setTypeAsSegmentation();
// newMarker.setTypeAsComment();
}
} else {
$._PPP_.updateEventPanel("Can only add markers to footage items.");
}
} else {
$._PPP_.updateEventPanel("Could not find first projectItem.");
}
} else {
$._PPP_.updateEventPanel("Project is empty.");
}
},
modifyProjectMetadata : function () {
var kPProPrivateProjectMetadataURI = "http://ns.adobe.com/premierePrivateProjectMetaData/1.0/";
var nameField = "Column.Intrinsic.Name";
var tapeName = "Column.Intrinsic.TapeName";
var logNote = "Column.Intrinsic.LogNote";
var newField = "ExampleFieldName";
var desc = "Column.PropertyText.Description";
if (app.isDocumentOpen()) {
var projectItem = app.project.rootItem.children[0]; // just grabs first projectItem.