forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OfxHost.cpp
1739 lines (1503 loc) · 68.5 KB
/
OfxHost.cpp
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
/* ***** BEGIN LICENSE BLOCK *****
* This file is part of Natron <https://natrongithub.github.io/>,
* (C) 2018-2021 The Natron developers
* (C) 2013-2018 INRIA and Alexandre Gauthier-Foichat
*
* Natron is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Natron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Natron. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
* ***** END LICENSE BLOCK ***** */
// ***** BEGIN PYTHON BLOCK *****
// from <https://docs.python.org/3/c-api/intro.html#include-files>:
// "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
#include <Python.h>
// ***** END PYTHON BLOCK *****
#include "OfxHost.h"
#include <cassert>
#include <cstdarg>
#include <memory>
#include <fstream>
#include <new> // std::bad_alloc
#include <stdexcept> // std::exception
#include <cctype> // tolower
#include <algorithm> // transform, min, max
#include <string>
#include <cstring> // for std::memcpy, std::memset, std::strcmp
CLANG_DIAG_OFF(deprecated)
CLANG_DIAG_OFF(uninitialized)
CLANG_DIAG_OFF(deprecated-register) //'register' storage class specifier is deprecated
#include <QtCore/QDateTime>
#include <QtCore/QDir>
#include <QtCore/QMutex>
#include <QtCore/QThreadPool>
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QTemporaryFile>
CLANG_DIAG_ON(deprecated-register)
#ifdef OFX_SUPPORTS_MULTITHREAD
#include <QtCore/QThread>
#include <QtCore/QThreadStorage>
#include <QtConcurrentMap> // QtCore on Qt4, QtConcurrent on Qt5
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_OFF
// /usr/local/include/boost/bind/arg.hpp:37:9: warning: unused typedef 'boost_static_assert_typedef_37' [-Wunused-local-typedef]
#include <boost/bind/bind.hpp>
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_ON
#endif
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)
//ofx
#include <ofxParametricParam.h>
#include <ofxOpenGLRender.h>
#ifdef OFX_EXTENSIONS_NUKE
#include <nuke/fnOfxExtensions.h>
#endif
#include <ofxNatron.h>
//ofx host support
#include <ofxhPluginAPICache.h>
// ofxhPropertySuite.h:565:37: warning: 'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to true [-Wtautological-undefined-compare]
CLANG_DIAG_OFF(unknown-pragmas)
CLANG_DIAG_OFF(tautological-undefined-compare) // appeared in clang 3.5
#include <ofxhImageEffect.h>
CLANG_DIAG_ON(tautological-undefined-compare)
CLANG_DIAG_ON(unknown-pragmas)
#include <ofxhPluginCache.h>
#include <ofxhImageEffectAPI.h>
#include <ofxhHost.h>
#include <ofxhParam.h>
#include <tuttle/ofxReadWrite.h>
#include <ofxhPluginCache.h>
#include <ofxhParametricParam.h> //our version of parametric param suite support
#include "Global/GlobalDefines.h"
#include "Global/FStreamsSupport.h"
#include "Global/QtCompat.h"
#include "Global/KeySymbols.h"
#ifdef DEBUG
#include "Global/FloatingPointExceptions.h"
#endif
#include "Engine/AppInstance.h"
#include "Engine/AppManager.h"
#include "Engine/CreateNodeArgs.h"
#include "Engine/KnobTypes.h"
#include "Engine/LibraryBinary.h"
#include "Engine/MemoryInfo.h" // printAsRAM
#include "Engine/Node.h"
#include "Engine/NodeSerialization.h"
#include "Engine/OfxEffectInstance.h"
#include "Engine/OfxImageEffectInstance.h"
#include "Engine/OutputSchedulerThread.h"
#include "Engine/OfxMemory.h"
#include "Engine/Plugin.h"
#include "Engine/Project.h"
#include "Engine/Settings.h"
#include "Engine/StandardPaths.h"
#include "Engine/TLSHolder.h"
#include "Engine/ThreadPool.h"
using namespace boost::placeholders;
//An effect may not use more than this amount of threads
#define NATRON_MULTI_THREAD_SUITE_MAX_NUM_CPU 4
NATRON_NAMESPACE_ENTER
// to disambiguate with the global-scope ::OfxHost
// see second answer of http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf
static
std::string
string_format(const std::string fmt,
...)
{
int size = ( (int)fmt.size() ) * 2 + 50; // Use a rubric appropriate for your code
std::string str;
va_list ap;
while (1) { // Maximum two passes on a POSIX system...
str.reserve(size);
va_start(ap, fmt);
int n = vsnprintf( (char *)str.data(), size, fmt.c_str(), ap );
va_end(ap);
if ( (n > -1) && (n < size) ) { // Everything worked
str.resize(n);
return str;
}
if (n > -1) { // Needed size returned
size = n + 1; // For null char
} else {
size *= 2; // Guess at a larger size (OS specific)
}
}
return str;
}
struct OfxHostPrivate
{
OFX::Host::ImageEffect::PluginCachePtr imageEffectPluginCache;
boost::shared_ptr<TLSHolder<OfxHost::OfxHostTLSData> > tlsData;
#ifdef MULTI_THREAD_SUITE_USES_THREAD_SAFE_MUTEX_ALLOCATION
std::list<QMutex*> pluginsMutexes;
QMutex* pluginsMutexesLock; //<protects _pluginsMutexes
#endif
std::string loadingPluginID; // ID of the plugin being loaded
int loadingPluginVersionMajor;
int loadingPluginVersionMinor;
OfxHostPrivate()
: imageEffectPluginCache()
, tlsData( new TLSHolder<OfxHost::OfxHostTLSData>() )
#ifdef MULTI_THREAD_SUITE_USES_THREAD_SAFE_MUTEX_ALLOCATION
, pluginsMutexes()
, pluginsMutexesLock(0)
#endif
, loadingPluginID()
, loadingPluginVersionMajor(0)
, loadingPluginVersionMinor(0)
{
}
};
OfxHost::OfxHost()
: _imp( new OfxHostPrivate() )
{
_imp->imageEffectPluginCache = boost::make_shared<OFX::Host::ImageEffect::PluginCache>((OFX::Host::ImageEffect::Host*)this);
}
OfxHost::~OfxHost()
{
//Clean up, to be polite.
OFX::Host::PluginCache::clearPluginCache();
#ifdef MULTI_THREAD_SUITE_USES_THREAD_SAFE_MUTEX_ALLOCATION
delete _imp->pluginsMutexesLock;
#endif
}
OfxHost::OfxHostDataTLSPtr
OfxHost::getTLSData() const
{
return _imp->tlsData->getOrCreateTLSData();
}
void
OfxHost::setOfxHostOSHandle(void* handle)
{
_properties.setPointerProperty(kOfxPropHostOSHandle, handle);
}
void
OfxHost::setProperties()
{
/* Known OpenFX host names:
uk.co.thefoundry.nuke
com.eyeonline.Fusion
com.sonycreativesoftware.vegas
Autodesk Toxik
Assimilator
Dustbuster
DaVinciResolve
DaVinciResolveLite
Mistika
com.apple.shake
Baselight
IRIDAS Framecycler
com.chinadigitalvideo.dx
com.newblue.titlerpro
Ramen
TuttleOfx
fr.inria.Natron
Other possible names:
Nuke
Autodesk Toxik Render Utility
Autodesk Toxik Python Bindings
Toxik
Fusion
film master
film cutter
data conform
nucoda
phoenix
Film Master
Baselight
Scratch
DS OFX Host
Avid DS
Vegas
CDV DX
Resolve
*/
// see hostStuffs in ofxhImageEffect.cpp
_properties.setStringProperty( kOfxPropName, appPTR->getCurrentSettings()->getHostName() );
_properties.setGetHook(kOfxPropName, this);
_properties.setStringProperty(kOfxPropLabel, NATRON_APPLICATION_NAME); // "nuke" //< use this to pass for nuke
_properties.setIntProperty(kOfxPropAPIVersion, 1, 0); //OpenFX API v1.4
_properties.setIntProperty(kOfxPropAPIVersion, 4, 1);
_properties.setIntProperty(kOfxPropVersion, NATRON_VERSION_MAJOR, 0);
_properties.setIntProperty(kOfxPropVersion, NATRON_VERSION_MINOR, 1);
_properties.setIntProperty(kOfxPropVersion, NATRON_VERSION_REVISION, 2);
_properties.setStringProperty(kOfxPropVersionLabel, NATRON_VERSION_STRING);
_properties.setIntProperty( kOfxImageEffectHostPropIsBackground, (int)appPTR->isBackground() );
_properties.setIntProperty(kOfxImageEffectPropSupportsOverlays, 1);
_properties.setIntProperty(kOfxImageEffectPropSupportsMultiResolution, 1);
_properties.setIntProperty(kOfxImageEffectPropSupportsTiles, 1);
_properties.setIntProperty(kOfxImageEffectPropTemporalClipAccess, 1);
_properties.setStringProperty(kOfxImageEffectPropSupportedComponents, kOfxImageComponentRGBA, 0);
_properties.setStringProperty(kOfxImageEffectPropSupportedComponents, kOfxImageComponentAlpha, 1);
if ( appPTR->getCurrentSettings()->areRGBPixelComponentsSupported() ) {
_properties.setStringProperty(kOfxImageEffectPropSupportedComponents, kOfxImageComponentRGB, 2);
}
_properties.setStringProperty(kOfxImageEffectPropSupportedComponents, kFnOfxImageComponentMotionVectors, 3);
_properties.setStringProperty(kOfxImageEffectPropSupportedComponents, kFnOfxImageComponentStereoDisparity, 4);
#ifdef OFX_EXTENSIONS_NATRON
_properties.setStringProperty(kOfxImageEffectPropSupportedComponents, kNatronOfxImageComponentXY, 5);
#endif
_properties.setStringProperty(kOfxImageEffectPropSupportedPixelDepths, kOfxBitDepthFloat, 0);
_properties.setStringProperty(kOfxImageEffectPropSupportedPixelDepths, kOfxBitDepthShort, 1);
_properties.setStringProperty(kOfxImageEffectPropSupportedPixelDepths, kOfxBitDepthByte, 2);
_properties.setStringProperty(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextGenerator, 0 );
_properties.setStringProperty(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextFilter, 1);
_properties.setStringProperty(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextGeneral, 2 );
_properties.setStringProperty(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextTransition, 3 );
///Setting these makes The Foundry Furnace plug-ins fail in the load action
//_properties.setStringProperty(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextReader, 4 );
//_properties.setStringProperty(kOfxImageEffectPropSupportedContexts, kOfxImageEffectContextWriter, 5 );
_properties.setIntProperty(kOfxImageEffectPropSupportsMultipleClipDepths, 1);
_properties.setIntProperty(kOfxImageEffectPropSupportsMultipleClipPARs, 1);
_properties.setIntProperty(kOfxImageEffectPropSetableFrameRate, 1);
_properties.setIntProperty(kOfxImageEffectPropSetableFielding, 0);
_properties.setIntProperty(kOfxParamHostPropSupportsCustomInteract, 1 );
_properties.setIntProperty( kOfxParamHostPropSupportsStringAnimation, KnobString::canAnimateStatic() );
_properties.setIntProperty( kOfxParamHostPropSupportsChoiceAnimation, KnobChoice::canAnimateStatic() );
_properties.setIntProperty( kOfxParamHostPropSupportsBooleanAnimation, KnobBool::canAnimateStatic() );
_properties.setIntProperty( kOfxParamHostPropSupportsCustomAnimation, KnobString::canAnimateStatic() );
_properties.setPointerProperty(kOfxPropHostOSHandle, NULL);
_properties.setIntProperty(kOfxParamHostPropSupportsParametricAnimation, 0);
_properties.setIntProperty(kOfxParamHostPropMaxParameters, -1);
_properties.setIntProperty(kOfxParamHostPropMaxPages, 0);
_properties.setIntProperty(kOfxParamHostPropPageRowColumnCount, 0, 0 );
_properties.setIntProperty(kOfxParamHostPropPageRowColumnCount, 0, 1 );
_properties.setIntProperty(kOfxImageEffectInstancePropSequentialRender, 2); // OFX 1.2
#ifdef OFX_SUPPORTS_OPENGLRENDER
// all host properties should be static and not depend on the settings, or the plugin cache may be wrong
_properties.setStringProperty(kOfxImageEffectPropOpenGLRenderSupported, "true"); // OFX 1.3
//if (appPTR->getCurrentSettings()->isOpenGLRenderingEnabled()) {
// _properties.setStringProperty(kOfxImageEffectPropOpenGLRenderSupported, "true"); // OFX 1.3
//} else {
// _properties.setStringProperty(kOfxImageEffectPropOpenGLRenderSupported, "false"); // OFX 1.3
//}
#endif
_properties.setIntProperty(kOfxImageEffectPropRenderQualityDraft, 1); // OFX 1.4
_properties.setStringProperty(kOfxImageEffectHostPropNativeOrigin, kOfxHostNativeOriginBottomLeft); // OFX 1.4
#ifdef OFX_EXTENSIONS_NUKE
///Plane suite
_properties.setIntProperty(kFnOfxImageEffectPropMultiPlanar, 1);
///Nuke transform suite
_properties.setIntProperty(kFnOfxImageEffectCanTransform, 1);
#endif
#ifdef OFX_EXTENSIONS_NATRON
///Natron extensions
_properties.setIntProperty(kNatronOfxHostIsNatron, 1);
_properties.setIntProperty(kNatronOfxParamHostPropSupportsDynamicChoices, 1);
_properties.setIntProperty(kNatronOfxParamPropChoiceCascading, 1);
_properties.setStringProperty(kNatronOfxImageEffectPropChannelSelector, kOfxImageComponentRGBA);
_properties.setIntProperty(kNatronOfxImageEffectPropHostMasking, 1);
_properties.setIntProperty(kNatronOfxImageEffectPropHostMixing, 1);
_properties.setIntProperty(kNatronOfxPropDescriptionIsMarkdown, 1);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxArrowCursor, 0);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxUpArrowCursor, 1);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxCrossCursor, 2);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxIBeamCursor, 3);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxWaitCursor, 4);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxBusyCursor, 5);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxForbiddenCursor, 6);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxPointingHandCursor, 7);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxWhatsThisCursor, 8);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxSizeVerCursor, 9);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxSizeHorCursor, 10);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxSizeBDiagCursor, 11);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxSizeFDiagCursor, 12);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxSizeAllCursor, 13);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxSplitVCursor, 14);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxSplitHCursor, 15);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxOpenHandCursor, 16);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxClosedHandCursor, 17);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxBlankCursor, 18);
_properties.setStringProperty(kNatronOfxImageEffectPropDefaultCursors, kNatronOfxDefaultCursor, 19);
#endif
} // OfxHost::setProperties
static
Settings::KnownHostNameEnum
getHostNameProxy(const std::string& pluginID,
int pluginVersionMajor,
int pluginVersionMinor)
{
Q_UNUSED(pluginVersionMajor);
Q_UNUSED(pluginVersionMinor);
assert( !pluginID.empty() );
static const std::string neatvideo("com.absoft.neatvideo");
static const std::string hitfilm("com.FXHOME.HitFilm");
static const std::string redgiant("com.redgiantsoftware.Universe_");
static const std::string digitalfilmtools("com.digitalfilmtools.");
static const std::string tiffen("com.tiffen.");
//static const std::string digitalanarchy("com.digitalanarchy.");
if ( !pluginID.compare(0, neatvideo.size(), neatvideo) ) {
// Neat Video plugins work with Nuke, Resolve and Mistika
// https://www.neatvideo.com/download.html
// tested with neat video 4.0.9, maj=4,min=0
return Settings::eKnownHostNameNuke;
} else if ( !pluginID.compare(0, hitfilm.size(), hitfilm) ) {
// HitFilm plugins (work with Vegas, Resolve and TitlerPro,
// Vegas and TitlerPro support more plugins than Resolve
// tested with HitFilm 3.1.0113
// maj=1 or 2 (depends on plugin), min=0
// HitFilm Ignite also supports NewBlue OFX Bridge, Sony Catalyst Edit, The Foundry Nuke
// tested with HitFilm Ignite 1.0.0118
// Clone Stamp from HitFilm Ignite is officially only compatible with Nuke
if ( pluginID == (hitfilm + ".CloneStamp") ) {
return Settings::eKnownHostNameNuke;
}
return Settings::eKnownHostNameVegas;
} else if ( !pluginID.compare(0, redgiant.size(), redgiant) ) {
// Red Giant Universe plugins 1.5 work with Vegas and Resolve
return Settings::eKnownHostNameVegas;
} else if ( !pluginID.compare(0, digitalfilmtools.size(), digitalfilmtools) ||
!pluginID.compare(0, tiffen.size(), tiffen) ) {
// Digital film tools plug-ins work with Nuke, Vegas, Scratch and Resolve
// http://www.digitalfilmtools.com/supported-hosts/ofx-host-plugins.php
return Settings::eKnownHostNameNuke;
//} else if (!pluginID.compare(0, digitalanarchy.size(), digitalanarchy)) {
// // Digital Anarchy plug-ins work with Scratch, Resolve, and any OFX host, but they are tested with Scratch.
// // http://digitalanarchy.com/demos/psd_mac.html
// return Settings::eKnownHostNameScratch;
}
//printf("%s v%d.%d\n", pluginID.c_str(), pluginVersionMajor, pluginVersionMinor);
return Settings::eKnownHostNameNone;
} // getHostNameProxy
const std::string &
OfxHost::getStringProperty(const std::string &name,
int n) const OFX_EXCEPTION_SPEC
{
if ( (name == kOfxPropName) && (n == 0) ) {
// depending on the current plugin ID and version, return a compatible host name.
std::string pluginID;
int pluginVersionMajor = 0;
int pluginVersionMinor = 0;
if ( !_imp->loadingPluginID.empty() ) {
// plugin is not yet created: we are loading or describing it
pluginID = _imp->loadingPluginID;
pluginVersionMajor = _imp->loadingPluginVersionMajor;
pluginVersionMinor = _imp->loadingPluginVersionMinor;
} else {
OfxHostDataTLSPtr tls = _imp->tlsData->getOrCreateTLSData();
if (tls && tls->lastEffectCallingMainEntry) {
pluginID = tls->lastEffectCallingMainEntry->getPlugin()->getIdentifier();
pluginVersionMajor = tls->lastEffectCallingMainEntry->getPlugin()->getVersionMajor();
pluginVersionMinor = tls->lastEffectCallingMainEntry->getPlugin()->getVersionMinor();
}
}
///Proxy known plug-ins that filter hostnames
if ( pluginID.empty() ) {
qDebug() << "OfxHost::getStringProperty(" kOfxPropName "): Error: no plugin ID! (ignoring)";
} else {
Settings::KnownHostNameEnum e = getHostNameProxy(pluginID, pluginVersionMajor, pluginVersionMinor);
if (e != Settings::eKnownHostNameNone) {
const std::string& ret = appPTR->getCurrentSettings()->getKnownHostName(e);
return ret;
}
}
// kOfxPropName was set at host creation, let the value decided by the user
return _properties.getStringPropertyRaw(kOfxPropName);
} else {
throw OFX::Host::Property::Exception(kOfxStatErrValue);
}
}
OFX::Host::ImageEffect::Instance*
OfxHost::newInstance(void*,
OFX::Host::ImageEffect::ImageEffectPlugin* plugin,
OFX::Host::ImageEffect::Descriptor & desc,
const std::string & context)
{
assert(plugin);
return new OfxImageEffectInstance(plugin, desc, context, false);
}
/// Override this to create a descriptor, this makes the 'root' descriptor
OFX::Host::ImageEffect::Descriptor *
OfxHost::makeDescriptor(OFX::Host::ImageEffect::ImageEffectPlugin* plugin)
{
assert(plugin);
OFX::Host::ImageEffect::Descriptor *desc = new OfxImageEffectDescriptor(plugin);
return desc;
}
/// used to construct a context description, rootContext is the main context
OFX::Host::ImageEffect::Descriptor *
OfxHost::makeDescriptor(const OFX::Host::ImageEffect::Descriptor &rootContext,
OFX::Host::ImageEffect::ImageEffectPlugin *plugin)
{
assert(plugin);
OFX::Host::ImageEffect::Descriptor *desc = new OfxImageEffectDescriptor(rootContext, plugin);
return desc;
}
/// used to construct populate the cache
OFX::Host::ImageEffect::Descriptor *
OfxHost::makeDescriptor(const std::string &bundlePath,
OFX::Host::ImageEffect::ImageEffectPlugin *plugin)
{
assert(plugin);
OFX::Host::ImageEffect::Descriptor *desc = new OfxImageEffectDescriptor(bundlePath, plugin);
return desc;
}
/// message
OfxStatus
OfxHost::vmessage(const char* msgtype,
const char* /*id*/,
const char* format,
va_list args)
{
assert(msgtype);
assert(format);
std::string message = string_format(format, args);
std::string type(msgtype);
if (type == kOfxMessageLog) {
appPTR->writeToErrorLog_mt_safe( tr("Plug-in"), QDateTime::currentDateTime(), QString::fromUtf8( message.c_str() ) );
} else if ( (type == kOfxMessageFatal) || (type == kOfxMessageError) ) {
///It seems that the only errors or warning that passes here are exceptions thrown by plug-ins
///(mainly Sapphire) while aborting a render. Instead of spamming the user of meaningless dialogs,
///just write to the log instead.
//Dialogs::errorDialog(NATRON_APPLICATION_NAME, message);
appPTR->writeToErrorLog_mt_safe(tr("Plug-in"), QDateTime::currentDateTime(), QString::fromUtf8( message.c_str() ) );
} else if (type == kOfxMessageWarning) {
///It seems that the only errors or warning that passes here are exceptions thrown by plug-ins
///(mainly Sapphire) while aborting a render. Instead of spamming the user of meaningless dialogs,
///just write to the log instead.
// Dialogs::warningDialog(NATRON_APPLICATION_NAME, message);
appPTR->writeToErrorLog_mt_safe( tr("Plug-in"), QDateTime::currentDateTime(), QString::fromUtf8( message.c_str() ) );
} else if (type == kOfxMessageMessage) {
Dialogs::informationDialog(NATRON_APPLICATION_NAME, message);
} else if (type == kOfxMessageQuestion) {
if (Dialogs::questionDialog(NATRON_APPLICATION_NAME, message, false) == eStandardButtonYes) {
return kOfxStatReplyYes;
} else {
return kOfxStatReplyNo;
}
}
return kOfxStatReplyDefault;
}
OfxStatus
OfxHost::setPersistentMessage(const char* type,
const char* id,
const char* format,
va_list args)
{
vmessage(type, id, format, args);
return kOfxStatOK;
}
/// clearPersistentMessage
OfxStatus
OfxHost::clearPersistentMessage()
{
return kOfxStatOK;
}
static std::string
getContext_internal(const std::set<std::string> & contexts)
{
std::string context;
if (contexts.size() == 0) {
throw std::runtime_error( std::string("Error: Plug-in does not support any context") );
//context = kOfxImageEffectContextGeneral;
//plugin->addContext(kOfxImageEffectContextGeneral);
} else if (contexts.size() == 1) {
context = ( *contexts.begin() );
return context;
} else {
std::set<std::string>::iterator found = contexts.find(kOfxImageEffectContextReader);
bool reader = found != contexts.end();
if (reader) {
context = kOfxImageEffectContextReader;
return context;
}
found = contexts.find(kOfxImageEffectContextWriter);
bool writer = found != contexts.end();
if (writer) {
context = kOfxImageEffectContextWriter;
return context;
}
found = contexts.find(kNatronOfxImageEffectContextTracker);
bool tracker = found != contexts.end();
if (tracker) {
context = kNatronOfxImageEffectContextTracker;
return context;
}
found = contexts.find(kOfxImageEffectContextGeneral);
bool general = found != contexts.end();
if (general) {
context = kOfxImageEffectContextGeneral;
return context;
}
found = contexts.find(kOfxImageEffectContextFilter);
bool filter = found != contexts.end();
if (filter) {
context = kOfxImageEffectContextFilter;
return context;
}
found = contexts.find(kOfxImageEffectContextPaint);
bool paint = found != contexts.end();
if (paint) {
context = kOfxImageEffectContextPaint;
return context;
}
found = contexts.find(kOfxImageEffectContextGenerator);
bool generator = found != contexts.end();
if (generator) {
context = kOfxImageEffectContextGenerator;
return context;
}
found = contexts.find(kOfxImageEffectContextTransition);
bool transition = found != contexts.end();
if (transition) {
context = kOfxImageEffectContextTransition;
return context;
}
}
return context;
} // getContext_internal
OFX::Host::ImageEffect::Descriptor*
OfxHost::getPluginContextAndDescribe(OFX::Host::ImageEffect::ImageEffectPlugin* plugin,
ContextEnum* ctx)
{
_imp->loadingPluginID = plugin->getRawIdentifier();
_imp->loadingPluginVersionMajor = plugin->getVersionMajor();
_imp->loadingPluginVersionMinor = plugin->getVersionMajor();
OFX::Host::PluginHandle *pluginHandle;
// getPluginHandle() must be called before getContexts():
// it calls kOfxActionLoad on the plugin and kOfxActionDescribe, which may set properties (including supported contexts)
try {
pluginHandle = plugin->getPluginHandle();
} catch (...) {
throw std::runtime_error( tr("Error: Description (kOfxActionLoad and kOfxActionDescribe) failed while loading %1.")
.arg( QString::fromUtf8( plugin->getIdentifier().c_str() ) ).toStdString() );
}
if (!pluginHandle) {
throw std::runtime_error( tr("Error: Description (kOfxActionLoad and kOfxActionDescribe) failed while loading %1.")
.arg( QString::fromUtf8( plugin->getIdentifier().c_str() ) ).toStdString() );
}
assert(pluginHandle->getOfxPlugin() && pluginHandle->getOfxPlugin()->mainEntry);
const std::set<std::string> & contexts = plugin->getContexts();
std::string context = getContext_internal(contexts);
if ( context.empty() ) {
throw std::invalid_argument( tr("OpenFX plug-in does not have any valid context.").toStdString() );
}
OFX::Host::PluginHandle* ph = plugin->getPluginHandle();
assert( ph->getOfxPlugin() );
assert(ph->getOfxPlugin()->mainEntry);
Q_UNUSED(ph);
OFX::Host::ImageEffect::Descriptor* desc = NULL;
//This will call kOfxImageEffectActionDescribeInContext
desc = plugin->getContext(context);
if (!desc) {
throw std::runtime_error( tr("Plug-in parameters and inputs description (kOfxImageEffectActionDescribeInContext) failed in context %1.")
.arg( QString::fromUtf8( context.c_str() ) ).toStdString() );
}
//Create the mask clip if needed
if ( desc->isHostMaskingEnabled() ) {
const std::map<std::string, OFX::Host::ImageEffect::ClipDescriptor*>& clips = desc->getClips();
std::map<std::string, OFX::Host::ImageEffect::ClipDescriptor*>::const_iterator found = clips.find("Mask");
if ( found == clips.end() ) {
OFX::Host::ImageEffect::ClipDescriptor* clip = desc->defineClip("Mask");
OFX::Host::Property::Set& props = clip->getProps();
props.setIntProperty(kOfxImageClipPropIsMask, 1);
props.setStringProperty(kOfxImageEffectPropSupportedComponents, kOfxImageComponentAlpha, 0);
if (context == kOfxImageEffectContextGeneral) {
props.setIntProperty(kOfxImageClipPropOptional, 1);
}
props.setIntProperty(kOfxImageEffectPropSupportsTiles, desc->getProps().getIntProperty(kOfxImageEffectPropSupportsTiles) != 0);
props.setIntProperty(kOfxImageEffectPropTemporalClipAccess, 0);
}
}
*ctx = OfxEffectInstance::mapToContextEnum(context);
_imp->loadingPluginID.clear();
return desc;
} // OfxHost::getPluginContextAndDescribe
AbstractOfxEffectInstancePtr
OfxHost::createOfxEffect(NodePtr node,
const CreateNodeArgs& args
#ifndef NATRON_ENABLE_IO_META_NODES
,
bool allowFileDialogs,
bool *hasUsedFileDialog
#endif
)
{
assert(node);
const Plugin* natronPlugin = node->getPlugin();
assert(natronPlugin);
ContextEnum ctx;
OFX::Host::ImageEffect::Descriptor* desc = natronPlugin->getOfxDesc(&ctx);
OFX::Host::ImageEffect::ImageEffectPlugin* plugin = natronPlugin->getOfxPlugin();
assert(plugin && desc && ctx != eContextNone);
AbstractOfxEffectInstancePtr hostSideEffect( new OfxEffectInstance(node) );
NodeSerializationPtr serialization = args.getProperty<NodeSerializationPtr>(kCreateNodeArgsPropNodeSerialization);
std::string fixedName = args.getProperty<std::string>(kCreateNodeArgsPropNodeInitialName);
if ( node && !node->getEffectInstance() ) {
node->setEffect(hostSideEffect);
node->initNodeScriptName(serialization.get(), QString::fromUtf8(fixedName.c_str()));
}
hostSideEffect->createOfxImageEffectInstance(plugin, desc, ctx, serialization.get(), args
#ifndef NATRON_ENABLE_IO_META_NODES
, allowFileDialogs,
hasUsedFileDialog
#endif
);
return hostSideEffect;
}
///Return the xml cache file used before Natron 2 RC2
static QString
getOldCacheFilePath()
{
QString cachePath = appPTR->getDiskCacheLocation() + QLatin1Char('/');
QString oldOfxCache = cachePath + QString::fromUtf8("OFXCache.xml");
return oldOfxCache;
}
static QString
getOFXCacheDirPath()
{
QString cachePath = appPTR->getDiskCacheLocation() + QLatin1Char('/');
QString ofxCachePath = cachePath + QString::fromUtf8("OFXLoadCache");
return ofxCachePath;
}
///Return the xml cache file used after Natron 2 RC2
static QString
getCacheFilePath()
{
QString ofxCachePath = getOFXCacheDirPath() + QLatin1Char('/');
QString ofxCacheFilePath = ofxCachePath + QString::fromUtf8("OFXCache_") +
QString::fromUtf8(NATRON_VERSION_STRING) + QString::fromUtf8("_") +
QString::fromUtf8(NATRON_DEVELOPMENT_STATUS) + QString::fromUtf8("_") +
QString::number(NATRON_BUILD_NUMBER) + QString::fromUtf8(".xml");
return ofxCacheFilePath;
}
static void
getPluginShortcuts(const OFX::Host::ImageEffect::Descriptor& desc, std::list<PluginActionShortcut>* shortcuts)
{
int nDims = desc.getProps().getDimension(kNatronOfxImageEffectPropInViewerContextDefaultShortcuts);
if (nDims == 0) {
return;
}
{
// Check that all props have the same dimension
int nSymDims = desc.getProps().getDimension(kNatronOfxImageEffectPropInViewerContextShortcutSymbol);
int nCtrlDims = desc.getProps().getDimension(kNatronOfxImageEffectPropInViewerContextShortcutHasControlModifier);
int nShiftDims = desc.getProps().getDimension(kNatronOfxImageEffectPropInViewerContextShortcutHasShiftModifier);
int nAltDims = desc.getProps().getDimension(kNatronOfxImageEffectPropInViewerContextShortcutHasAltModifier);
int nMetaDims = desc.getProps().getDimension(kNatronOfxImageEffectPropInViewerContextShortcutHasMetaModifier);
int nKeypadDims = desc.getProps().getDimension(kNatronOfxImageEffectPropInViewerContextShortcutHasKeypadModifier);
if (nSymDims != nDims ||
nCtrlDims != nDims ||
nShiftDims != nDims ||
nAltDims != nDims ||
nMetaDims != nDims ||
nKeypadDims != nDims) {
std::cerr << desc.getPlugin()->getIdentifier() << ": Invalid dimension setup of the NatronOfxImageEffectPropInViewerContextDefaultShortcuts property." << std::endl;
return;
}
}
const std::map<std::string, OFX::Host::Param::Descriptor*> & paramDescriptors = desc.getParams();
for (int i = 0; i < nDims; ++i) {
const std::string& paramName = desc.getProps().getStringProperty(kNatronOfxImageEffectPropInViewerContextDefaultShortcuts, i);
int symbol = desc.getProps().getIntProperty(kNatronOfxImageEffectPropInViewerContextShortcutSymbol, i);
int hasCtrl = desc.getProps().getIntProperty(kNatronOfxImageEffectPropInViewerContextShortcutHasControlModifier, i);
int hasShift = desc.getProps().getIntProperty(kNatronOfxImageEffectPropInViewerContextShortcutHasShiftModifier, i);
int hasAlt = desc.getProps().getIntProperty(kNatronOfxImageEffectPropInViewerContextShortcutHasAltModifier, i);
int hasMeta = desc.getProps().getIntProperty(kNatronOfxImageEffectPropInViewerContextShortcutHasMetaModifier, i);
int hasKeypad = desc.getProps().getIntProperty(kNatronOfxImageEffectPropInViewerContextShortcutHasKeypadModifier, i);
std::map<std::string, OFX::Host::Param::Descriptor*>::const_iterator foundParamDesc = paramDescriptors.find(paramName);
if (foundParamDesc == paramDescriptors.end()) {
// Hmm the plug-in probably wrongly set the kNatronOfxImageEffectPropInViewerContextDefaultShortcuts property
std::cerr << desc.getPlugin()->getIdentifier() << ": " << paramName << " was set to the NatronOfxImageEffectPropInViewerContextDefaultShortcuts property but does not appear to exist in the parameters described." << std::endl;
continue;
}
// The Key enum is a mapping 1:1 of the symbols defined in ofxKeySymbols.h
Key eSymbol = (Key)symbol;
KeyboardModifiers eMods;
if (hasCtrl) {
eMods |= eKeyboardModifierControl;
}
if (hasShift) {
eMods |= eKeyboardModifierShift;
}
if (hasAlt) {
eMods |= eKeyboardModifierAlt;
}
if (hasMeta) {
eMods |= eKeyboardModifierMeta;
}
if (hasKeypad) {
eMods |= eKeyboardModifierKeypad;
}
shortcuts->push_back(PluginActionShortcut(paramName, foundParamDesc->second->getLabel(), eSymbol, eMods));
}
}
static inline
QDebug operator<<(QDebug dbg, const std::list<std::string> &l)
{
for (std::list<std::string>::const_iterator it = l.begin(); it != l.end(); ++it) {
dbg.nospace() << QString::fromUtf8( it->c_str() ) << ' ';
}
return dbg.space();
}
void
OfxHost::loadOFXPlugins(IOPluginsMap* readersMap,
IOPluginsMap* writersMap)
{
qDebug() << "Load OFX Plugins...";
SettingsPtr settings = appPTR->getCurrentSettings();
assert(settings);
bool useStdOFXPluginsLocation = settings->getUseStdOFXPluginsLocation();
if (!useStdOFXPluginsLocation) {
qDebug() << "Load OFX Plugins: do not use std plugins location";
// only set if false, else use the previous value (which is set for example in BaseTest::SetUp())
OFX::Host::PluginCache::useStdOFXPluginsLocation(useStdOFXPluginsLocation);
}
OFX::Host::PluginCache* pluginCache = OFX::Host::PluginCache::getPluginCache();
assert(pluginCache);
/// set the version label in the global cache
pluginCache->setCacheVersion(NATRON_APPLICATION_NAME "OFXCachev1");
/// register the image effect cache with the global plugin cache
_imp->imageEffectPluginCache->registerInCache( *pluginCache );
if (useStdOFXPluginsLocation) {
pluginCache->setPluginHostPath(NATRON_APPLICATION_NAME);
pluginCache->setPluginHostPath("Nuke"); // most Nuke OFX plugins are compatible
}
std::list<std::string> extraPluginsSearchPaths;
settings->getOpenFXPluginsSearchPaths(&extraPluginsSearchPaths);
for (std::list<std::string>::iterator it = extraPluginsSearchPaths.begin(); it != extraPluginsSearchPaths.end(); ++it) {
if ( !(*it).empty() ) {
qDebug() << "Load OFX Plugins: append extra plugins dir" << it->c_str();
pluginCache->addFileToPath(*it);
}
}
// if Natron is /usr/bin/Natron, /usr/bin/../OFX/Natron points to Natron-specific plugins
QDir dir( QCoreApplication::applicationDirPath() );
dir.cdUp();
std::string natronBundledPluginsPath = QString( dir.absolutePath() + QString::fromUtf8("/Plugins/OFX/") + QString::fromUtf8(NATRON_APPLICATION_NAME) ).toStdString();
try {
if ( settings->loadBundledPlugins() ) {
if ( settings->preferBundledPlugins() ) {
qDebug() << "Load OFX Plugins: prepend bundled plugins dir" << natronBundledPluginsPath.c_str();
pluginCache->prependFileToPath(natronBundledPluginsPath);
} else {
qDebug() << "Load OFX Plugins: append bundled plugins dir" << natronBundledPluginsPath.c_str();
pluginCache->addFileToPath(natronBundledPluginsPath);
}
}
} catch (std::logic_error&) {
// ignore
}
// The cache location depends on the OS.
// On OSX, it will be ~/Library/Caches/<organization>/<application>/OFXLoadCache/
//on Linux ~/.cache/<organization>/<application>/OFXLoadCache/
//on windows: C:\Users\<username>\App Data\Local\<organization>\<application>\Caches\OFXLoadCache
QString ofxCacheFilePath = getCacheFilePath();
qDebug() << "Load OFX Plugins: reading cache file" << ofxCacheFilePath;
{
FStreamsSupport::ifstream ifs;
FStreamsSupport::open( &ifs, ofxCacheFilePath.toStdString() );
if (!ifs) {
qDebug() << "Load OFX Plugins: cannot open cache file" << ofxCacheFilePath;
} else {
try {
pluginCache->readCache(ifs);
qDebug() << "Load OFX Plugins: reading cache file... done!";
} catch (const std::exception& e) {
qDebug() << "Load OFX Plugins: reading cache file... failed!";
appPTR->writeToErrorLog_mt_safe( QLatin1String("OpenFX"), QDateTime::currentDateTime(),
tr("Failure to read OpenFX plug-ins cache: %1").arg( QString::fromUtf8( e.what() ) ) );
}
}
}
qDebug() << "Load OFX Plugins: plugin path is" << pluginCache->getPluginPath();
qDebug() << "Load OFX Plugins: scan plugins...";
pluginCache->scanPluginFiles();
qDebug() << "Load OFX Plugins: scan plugins... done!";
_imp->loadingPluginID.clear(); // finished loading plugins
if ( pluginCache->dirty() ) {
// write the cache NOW (it won't change anyway)
qDebug() << "Load OFX Plugins: writing cache file" << ofxCacheFilePath;
/// flush out the current cache
writeOFXCache();
qDebug() << "Load OFX Plugins: writing cache file... done!";
}
/*Filling node name list and plugin grouping*/
typedef std::map<OFX::Host::ImageEffect::MajorPlugin, OFX::Host::ImageEffect::ImageEffectPlugin *> PMap;
const PMap& ofxPlugins =
_imp->imageEffectPluginCache->getPluginsByIDMajor();
for (PMap::const_iterator it = ofxPlugins.begin();
it != ofxPlugins.end(); ++it) {
OFX::Host::ImageEffect::ImageEffectPlugin* p = it->second;
assert(p);
if (p->getContexts().size() == 0) {
continue;
}
assert( p->getBinary() );
if ( !p->getBinary() ) {
continue;
}
std::string openfxId = p->getIdentifier();
const std::string & grouping = p->getDescriptor().getPluginGrouping();
const std::string & bundlePath = p->getBinary()->getBundlePath();
std::string pluginLabel = OfxEffectInstance::makePluginLabel( p->getDescriptor().getShortLabel(),
p->getDescriptor().getLabel(),
p->getDescriptor().getLongLabel() );
QStringList groups = OfxEffectInstance::makePluginGrouping(p->getIdentifier(),
p->getVersionMajor(), p->getVersionMinor(),
pluginLabel, grouping);
for (int i = 0; i < groups.size(); ++i) {
groups[i] = groups[i].trimmed();
}
const std::string resourcesPathStr(bundlePath + "/Contents/Resources/");
QString resourcesPath = QString::fromUtf8( resourcesPathStr.c_str() );
QString iconFileName;
std::string pngIcon;
try {
// kOfxPropIcon is normally only defined for parameter desctriptors
// (see <http://openfx.sourceforge.net/Documentation/1.3/ofxProgrammingReference.html#ParameterProperties>)
// but let's assume it may also be defained on the plugin descriptor.
pngIcon = p->getDescriptor().getProps().getStringProperty(kOfxPropIcon, 1); // dimension 1 is PNG icon
} catch (OFX::Host::Property::Exception) {
}
if ( pngIcon.empty() ) {
// no icon defined by kOfxPropIcon, use the default value
pngIcon = openfxId + ".png";
}
iconFileName.append(resourcesPath);
iconFileName.append( QString::fromUtf8( pngIcon.c_str() ) );
QString groupIconFilename;
if (groups.size() > 0) {
groupIconFilename = resourcesPath;
// the plugin grouping has no descriptor, just try the default filename.
groupIconFilename.append(groups[0]);