forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadNode.cpp
1456 lines (1233 loc) · 48.7 KB
/
ReadNode.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 "ReadNode.h"
#include <sstream> // stringstream
#include "Global/QtCompat.h"
#if !defined(SBK_RUN) && !defined(Q_MOC_RUN)
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_OFF
#include <boost/algorithm/string/predicate.hpp> // iequals
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_ON
#endif
#if !defined(Q_MOC_RUN) && !defined(SBK_RUN)
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_OFF
GCC_DIAG_OFF(unused-parameter)
// /opt/local/include/boost/serialization/smart_cast.hpp:254:25: warning: unused parameter 'u' [-Wunused-parameter]
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
// /usr/local/include/boost/serialization/shared_ptr.hpp:112:5: warning: unused typedef 'boost_static_assert_typedef_112' [-Wunused-local-typedef]
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/version.hpp>
GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_ON
GCC_DIAG_ON(unused-parameter)
#endif
CLANG_DIAG_OFF(deprecated)
CLANG_DIAG_OFF(uninitialized)
#include <QtCore/QCoreApplication>
#include <QtCore/QProcess>
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)
#include "Engine/AppInstance.h"
#include "Engine/AppManager.h"
#include "Engine/Node.h"
#include "Engine/CreateNodeArgs.h"
#include "Engine/KnobTypes.h"
#include "Engine/KnobFile.h"
#include "Engine/Project.h"
#include "Engine/NodeSerialization.h"
#include "Engine/KnobSerialization.h" // createDefaultValueForParam
#include "Engine/Plugin.h"
#include "Engine/Settings.h"
//The plug-in that is instantiated whenever this node is created and doesn't point to any valid or known extension
#define READ_NODE_DEFAULT_READER PLUGINID_OFX_READOIIO
#define kPluginSelectorParamEntryDefault "Default"
NATRON_NAMESPACE_ENTER
//Generic Reader
#define kParamFilename kOfxImageEffectFileParamName
#define kParamProxy kOfxImageEffectProxyParamName
#define kParamProxyThreshold "proxyThreshold"
#define kParamOriginalProxyScale "originalProxyScale"
#define kParamCustomProxyScale "customProxyScale"
#define kParamOnMissingFrame "onMissingFrame"
#define kParamFrameMode "frameMode"
#define kParamTimeOffset "timeOffset"
#define kParamStartingTime "startingTime"
#define kParamOriginalFrameRange kReaderParamNameOriginalFrameRange
#define kParamFirstFrame "firstFrame"
#define kParamLastFrame "lastFrame"
#define kParamBefore "before"
#define kParamAfter "after"
#define kParamTimeDomainUserEdited "timeDomainUserEdited"
#define kParamFilePremult "filePremult"
#define kParamOutputPremult "outputPremult"
#define kParamOutputComponents "outputComponents"
#define kParamInputSpaceLabel "File Colorspace"
#define kParamFrameRate "frameRate"
#define kParamCustomFps "customFps"
#define kParamInputSpaceSet "ocioInputSpaceSet"
#define kParamExistingInstance "ParamExistingInstance"
//Generic OCIO
#define kOCIOParamConfigFile "ocioConfigFile"
#define kOCIOParamInputSpace "ocioInputSpace"
#define kOCIOParamOutputSpace "ocioOutputSpace"
#define kOCIOParamInputSpaceChoice "ocioInputSpaceIndex"
#define kOCIOParamOutputSpaceChoice "ocioOutputSpaceIndex"
#define kOCIOHelpButton "ocioHelp"
#define kOCIOHelpLooksButton "ocioHelpLooks"
#define kOCIOHelpDisplaysButton "ocioHelpDisplays"
#define kOCIOParamContext "Context"
/*
These are names of knobs that are defined in GenericReader and that should stay on the interface
no matter what the internal Reader is.
*/
struct GenericKnob
{
// The script-name of the knob.
const char* scriptName;
// Whether the value should be saved when changing filename.
bool mustKeepValue;
};
static GenericKnob genericReaderKnobNames[] =
{
{kParamFilename, false},
{kParamProxy, false},
{kParamProxyThreshold, false},
{kParamOriginalProxyScale, false},
{kParamCustomProxyScale, false},
{kParamOnMissingFrame, true},
{kParamFrameMode, true},
{kParamTimeOffset, false},
{kParamStartingTime, false},
{kParamOriginalFrameRange, false},
{kParamFirstFrame, false},
{kParamLastFrame, false},
{kParamBefore, true},
{kParamAfter, true},
{kParamTimeDomainUserEdited, false},
{kParamFilePremult, true}, // keep: don't change useful params behind the user's back
{kParamOutputPremult, true}, // keep: don't change useful params behind the user's back
{kParamOutputComponents, true}, // keep: don't change useful params behind the user's back
{kParamInputSpaceLabel, false},
{kParamFrameRate, true}, // keep: don't change useful params behind the user's back
{kParamCustomFps, true}, // if custom fps was checked, don't uncheck it
{kParamInputSpaceSet, true},
{kParamExistingInstance, true}, // don't automatically set parameters when changing the filename, see GenericReaderPlugin::inputFileChanged()
{kOCIOParamConfigFile, true},
{kNatronReadNodeOCIOParamInputSpace, false},
{kOCIOParamInputSpace, false}, // input colorspace must not be kept (depends on file format)
{kOCIOParamOutputSpace, true}, // output colorspace must be kept
{kOCIOParamInputSpaceChoice, false},
{kOCIOParamOutputSpaceChoice, true},
{kOCIOHelpButton, false},
{kOCIOHelpLooksButton, false},
{kOCIOHelpDisplaysButton, false},
{kOCIOParamContext, false},
{0, false}
};
static bool
isGenericKnob(const std::string& knobName,
bool *mustSerialize)
{
int i = 0;
while (genericReaderKnobNames[i].scriptName) {
if (genericReaderKnobNames[i].scriptName == knobName) {
*mustSerialize = genericReaderKnobNames[i].mustKeepValue;
return true;
}
++i;
}
return false;
}
bool
ReadNode::isBundledReader(const std::string& pluginID,
bool wasProjectCreatedWithLowerCaseIDs)
{
if (wasProjectCreatedWithLowerCaseIDs) {
// Natron 1.x has plugin ids stored in lowercase
return ( boost::iequals(pluginID, PLUGINID_OFX_READOIIO) ||
boost::iequals(pluginID, PLUGINID_OFX_READFFMPEG) ||
boost::iequals(pluginID, PLUGINID_OFX_READPFM) ||
boost::iequals(pluginID, PLUGINID_OFX_READPSD) ||
boost::iequals(pluginID, PLUGINID_OFX_READKRITA) ||
boost::iequals(pluginID, PLUGINID_OFX_READSVG) ||
boost::iequals(pluginID, PLUGINID_OFX_READMISC) ||
boost::iequals(pluginID, PLUGINID_OFX_READORA) ||
boost::iequals(pluginID, PLUGINID_OFX_READCDR) ||
boost::iequals(pluginID, PLUGINID_OFX_READPNG) ||
boost::iequals(pluginID, PLUGINID_OFX_READPDF) ||
boost::iequals(pluginID, PLUGINID_OFX_READBRAW) );
}
return (pluginID == PLUGINID_OFX_READOIIO ||
pluginID == PLUGINID_OFX_READFFMPEG ||
pluginID == PLUGINID_OFX_READPFM ||
pluginID == PLUGINID_OFX_READPSD ||
pluginID == PLUGINID_OFX_READKRITA ||
pluginID == PLUGINID_OFX_READSVG ||
pluginID == PLUGINID_OFX_READMISC ||
pluginID == PLUGINID_OFX_READORA ||
pluginID == PLUGINID_OFX_READCDR ||
pluginID == PLUGINID_OFX_READPNG ||
pluginID == PLUGINID_OFX_READPDF ||
pluginID == PLUGINID_OFX_READBRAW);
}
bool
ReadNode::isBundledReader(const std::string& pluginID)
{
return isBundledReader( pluginID, getApp()->wasProjectCreatedWithLowerCaseIDs() );
}
struct ReadNodePrivate
{
Q_DECLARE_TR_FUNCTIONS(ReadNode)
public:
ReadNode* _publicInterface;
QMutex embeddedPluginMutex;
NodePtr embeddedPlugin;
std::list<KnobSerializationPtr> genericKnobsSerialization;
KnobFileWPtr inputFileKnob;
//Thiese are knobs owned by the ReadNode and not the Reader
KnobChoiceWPtr pluginSelectorKnob;
KnobStringWPtr pluginIDStringKnob;
KnobSeparatorWPtr separatorKnob;
KnobButtonWPtr fileInfosKnob;
std::list<KnobIWPtr> readNodeKnobs;
//MT only
int creatingReadNode;
// Plugin-ID of the last read node created.
// If this is different, we do not load serialized knobs
std::string lastPluginIDCreated;
bool wasCreatedAsHiddenNode;
ReadNodePrivate(ReadNode* publicInterface)
: _publicInterface(publicInterface)
, embeddedPluginMutex()
, embeddedPlugin()
, genericKnobsSerialization()
, inputFileKnob()
, pluginSelectorKnob()
, pluginIDStringKnob()
, separatorKnob()
, fileInfosKnob()
, readNodeKnobs()
, creatingReadNode(0)
, lastPluginIDCreated()
, wasCreatedAsHiddenNode(false)
{
}
void placeReadNodeKnobsInPage();
void createReadNode(bool throwErrors,
const std::string& filename,
const NodeSerializationPtr& serialization );
void destroyReadNode();
void cloneGenericKnobs();
void refreshPluginSelectorKnob();
void refreshFileInfoVisibility(const std::string& pluginID);
void createDefaultReadNode();
bool checkDecoderCreated(double time, ViewIdx view);
static QString getFFProbeBinaryPath()
{
QString appPath = QCoreApplication::applicationDirPath();
appPath += QLatin1Char('/');
appPath += QString::fromUtf8("ffprobe");
#ifdef __NATRON_WIN32__
appPath += QString::fromUtf8(".exe");
#endif
return appPath;
}
};
class SetCreatingReaderRAIIFlag
{
ReadNodePrivate* _p;
public:
SetCreatingReaderRAIIFlag(ReadNodePrivate* p)
: _p(p)
{
++p->creatingReadNode;
}
~SetCreatingReaderRAIIFlag()
{
--_p->creatingReadNode;
}
};
ReadNode::ReadNode(NodePtr n)
: EffectInstance(n)
, _imp( new ReadNodePrivate(this) )
{
setSupportsRenderScaleMaybe(eSupportsNo);
}
ReadNode::~ReadNode()
{
}
NodePtr
ReadNode::getEmbeddedReader() const
{
QMutexLocker k(&_imp->embeddedPluginMutex);
return _imp->embeddedPlugin;
}
void
ReadNode::setEmbeddedReader(const NodePtr& node)
{
QMutexLocker k(&_imp->embeddedPluginMutex);
_imp->embeddedPlugin = node;
}
void
ReadNodePrivate::placeReadNodeKnobsInPage()
{
KnobIPtr pageKnob = _publicInterface->getKnobByName("Controls");
KnobPage* isPage = dynamic_cast<KnobPage*>( pageKnob.get() );
if (!isPage) {
return;
}
for (std::list<KnobIWPtr>::iterator it = readNodeKnobs.begin(); it != readNodeKnobs.end(); ++it) {
KnobIPtr knob = it->lock();
knob->setParentKnob( KnobIPtr() );
isPage->removeKnob( knob.get() );
}
KnobsVec children = isPage->getChildren();
int index = -1;
for (std::size_t i = 0; i < children.size(); ++i) {
if (children[i]->getName() == kParamCustomFps) {
index = i;
break;
}
}
if (index != -1) {
++index;
for (std::list<KnobIWPtr>::iterator it = readNodeKnobs.begin(); it != readNodeKnobs.end(); ++it) {
KnobIPtr knob = it->lock();
isPage->insertKnob(index, knob);
++index;
}
}
children = isPage->getChildren();
// Find the separatorKnob in the page and if the next parameter is also a separator, hide it
int foundSep = -1;
for (std::size_t i = 0; i < children.size(); ++i) {
if (children[i]== separatorKnob.lock()) {
foundSep = i;
break;
}
}
if (foundSep != -1) {
++foundSep;
if (foundSep < (int)children.size()) {
bool isSecret = children[foundSep]->getIsSecret();
while (isSecret && foundSep < (int)children.size()) {
++foundSep;
isSecret = children[foundSep]->getIsSecret();
}
if (foundSep < (int)children.size()) {
separatorKnob.lock()->setSecret(dynamic_cast<KnobSeparator*>(children[foundSep].get()));
} else {
separatorKnob.lock()->setSecret(true);
}
} else {
separatorKnob.lock()->setSecret(true);
}
}
}
void
ReadNodePrivate::cloneGenericKnobs()
{
const KnobsVec& knobs = _publicInterface->getKnobs();
for (std::list<KnobSerializationPtr>::iterator it = genericKnobsSerialization.begin(); it != genericKnobsSerialization.end(); ++it) {
KnobIPtr serializedKnob = (*it)->getKnob();
for (KnobsVec::const_iterator it2 = knobs.begin(); it2 != knobs.end(); ++it2) {
if ( (*it2)->getName() == serializedKnob->getName() ) {
KnobChoice* isChoice = dynamic_cast<KnobChoice*>( (*it2).get() );
KnobChoice* choiceSerialized = dynamic_cast<KnobChoice*>( serializedKnob.get() );;
if (isChoice && choiceSerialized) {
const ChoiceExtraData* choiceData = dynamic_cast<const ChoiceExtraData*>( (*it)->getExtraData() );
assert(choiceData);
if (choiceData) {
std::string optionID = choiceData->_choiceString;
// first, try to get the id the easy way ( see choiceMatch() )
int id = isChoice->choiceRestorationId(choiceSerialized, optionID);
#pragma message WARN("TODO: choice id filters")
//if (id < 0) {
// // no luck, try the filters
// filterKnobChoiceOptionCompat(getPluginID(), serialization.getPluginMajorVersion(), serialization.getPluginMinorVersion(), projectInfos.vMajor, projectInfos.vMinor, projectInfos.vRev, serializedName, &optionID);
// id = isChoice->choiceRestorationId(choiceSerialized, optionID);
//}
isChoice->choiceRestoration(choiceSerialized, optionID, id);
}
} else {
(*it2)->clone( serializedKnob.get() );
}
//(*it2)->setSecret( serializedKnob->getIsSecret() );
/*if ( (*it2)->getDimension() == serializedKnob->getDimension() ) {
for (int i = 0; i < (*it2)->getDimension(); ++i) {
(*it2)->setEnabled( i, serializedKnob->isEnabled(i) );
}
}*/
break;
}
}
}
}
void
ReadNodePrivate::destroyReadNode()
{
assert( QThread::currentThread() == qApp->thread() );
if (!embeddedPlugin) {
return;
}
KnobsVec knobs = _publicInterface->getKnobs();
genericKnobsSerialization.clear();
std::string serializationString;
try {
std::ostringstream ss;
{ // see http://boost.2283326.n4.nabble.com/the-boost-xml-serialization-to-a-stringstream-does-not-have-an-end-tag-td2580772.html
// xml_oarchive must be destroyed before obtaining ss.str(), or the </boost_serialization> tag is missing,
// which throws an exception in boost 1.66.0, due to the following change:
// https://fossies.org/diffs/boost/1_65_1_vs_1_66_0/libs/serialization/src/basic_xml_grammar.ipp-diff.html
// see also https://svn.boost.org/trac10/ticket/13400
// see also https://svn.boost.org/trac10/ticket/13354
boost::archive::xml_oarchive oArchive(ss);
std::list<KnobSerializationPtr> serialized;
for (KnobsVec::iterator it = knobs.begin(); it != knobs.end(); ++it) {
// The internal node still holds a shared ptr to the knob.
// Since we want to keep some knobs around, ensure they do not get deleted in the destructor of the embedded node
embeddedPlugin->getEffectInstance()->removeKnobFromList(it->get());
if ( !(*it)->isDeclaredByPlugin() ) {
continue;
}
//If it is a knob of this ReadNode, do not destroy it
bool isReadNodeKnob = false;
for (std::list<KnobIWPtr>::iterator it2 = readNodeKnobs.begin(); it2 != readNodeKnobs.end(); ++it2) {
if (it2->lock() == *it) {
isReadNodeKnob = true;
break;
}
}
if (isReadNodeKnob) {
continue;
}
//Keep pages around they will be re-used
KnobPage* isPage = dynamic_cast<KnobPage*>( it->get() );
if (isPage) {
continue;
}
//This is a knob of the Reader plug-in
//Serialize generic knobs and keep them around until we create a new Reader plug-in
bool mustSerializeKnob;
bool isGeneric = isGenericKnob( (*it)->getName(), &mustSerializeKnob );
if (!isGeneric || mustSerializeKnob) {
/* if (!isGeneric && !(*it)->getDefaultIsSecret()) {
// Don't save the secret state otherwise some knobs could be invisible when cloning the serialization even if we change format
(*it)->setSecret(false);
}*/
KnobSerializationPtr s = boost::make_shared<KnobSerialization>(*it);
serialized.push_back(s);
}
if (!isGeneric) {
try {
_publicInterface->deleteKnob(it->get(), false);
} catch (...) {
}
}
}
int n = (int)serialized.size();
oArchive << boost::serialization::make_nvp("numItems", n);
for (std::list<KnobSerializationPtr>::const_iterator it = serialized.begin(); it!= serialized.end(); ++it) {
oArchive << boost::serialization::make_nvp("item", **it);
}
}
serializationString = ss.str();
} catch (...) {
assert(false);
}
try {
std::stringstream ss(serializationString);
boost::archive::xml_iarchive iArchive(ss);
int n ;
iArchive >> boost::serialization::make_nvp("numItems", n);
for (int i = 0; i < n; ++i) {
KnobSerializationPtr s = boost::make_shared<KnobSerialization>();
iArchive >> boost::serialization::make_nvp("item", *s);
genericKnobsSerialization.push_back(s);
}
} catch (const std::exception& e) {
qDebug() << e.what();
assert(false);
} catch (...) {
assert(false);
}
//This will remove the GUI of non generic parameters
_publicInterface->recreateKnobs(true);
#pragma message WARN("TODO: if Gui, refresh pluginID, version, help tooltip in DockablePanel to reflect embedded node change")
QMutexLocker k(&embeddedPluginMutex);
if (embeddedPlugin) {
embeddedPlugin->destroyNode(true, false);
}
embeddedPlugin.reset();
} // ReadNodePrivate::destroyReadNode
void
ReadNodePrivate::createDefaultReadNode()
{
CreateNodeArgs args(READ_NODE_DEFAULT_READER, NodeCollectionPtr() );
args.setProperty(kCreateNodeArgsPropNoNodeGUI, true);
args.setProperty(kCreateNodeArgsPropSilent, true);
args.setProperty(kCreateNodeArgsPropOutOfProject, true);
args.setProperty<std::string>(kCreateNodeArgsPropNodeInitialName, "defaultReadNodeReader");
args.setProperty<NodePtr>(kCreateNodeArgsPropMetaNodeContainer, _publicInterface->getNode());
args.setProperty<bool>(kCreateNodeArgsPropAllowNonUserCreatablePlugins, true);
// This will avoid throwing errors when creating the reader
args.addParamDefaultValue<bool>("ParamExistingInstance", true);
NodePtr node = _publicInterface->getApp()->createNode(args);
if (!node) {
QString error = tr("The IO.ofx.bundle OpenFX plug-in is required to use this node, make sure it is installed.");
throw std::runtime_error( error.toStdString() );
}
{
QMutexLocker k(&embeddedPluginMutex);
embeddedPlugin = node;
}
//We need to explcitly refresh the Python knobs since we attached the embedded node knobs into this node.
_publicInterface->getNode()->declarePythonFields();
//Destroy it to keep the default parameters
destroyReadNode();
separatorKnob.lock()->setSecret(true);
}
bool
ReadNodePrivate::checkDecoderCreated(double time,
ViewIdx view)
{
KnobFilePtr fileKnob = inputFileKnob.lock();
assert(fileKnob);
std::string pattern = fileKnob->getFileName(std::floor(time + 0.5), view);
if ( pattern.empty() ) {
_publicInterface->setPersistentMessage( eMessageTypeError, tr("Filename empty").toStdString() );
return false;
}
if (!_publicInterface->getEmbeddedReader()) {
QString s = tr("Decoder was not created for %1, check that the file exists and its format is supported.").arg( QString::fromUtf8( pattern.c_str() ) );
_publicInterface->setPersistentMessage( eMessageTypeError, s.toStdString() );
return false;
}
return true;
}
static std::string
getFileNameFromSerialization(const std::list<KnobSerializationPtr>& serializations)
{
std::string filePattern;
for (std::list<KnobSerializationPtr>::const_iterator it = serializations.begin(); it != serializations.end(); ++it) {
if ( (*it)->getKnob()->getName() == kOfxImageEffectFileParamName ) {
KnobStringBase* isString = dynamic_cast<KnobStringBase*>( (*it)->getKnob().get() );
assert(isString);
if (isString) {
filePattern = isString->getValue();
}
break;
}
}
return filePattern;
}
void
ReadNodePrivate::createReadNode(bool throwErrors,
const std::string& filename,
const NodeSerializationPtr& serialization)
{
if (creatingReadNode) {
return;
}
SetCreatingReaderRAIIFlag creatingNode__(this);
QString qpattern = QString::fromUtf8( filename.c_str() );
std::string ext = QtCompat::removeFileExtension(qpattern).toLower().toStdString();
std::string readerPluginID;
KnobStringPtr pluginIDKnob = pluginIDStringKnob.lock();
readerPluginID = pluginIDKnob->getValue();
if ( readerPluginID.empty() ) {
KnobChoicePtr pluginChoiceKnob = pluginSelectorKnob.lock();
int pluginChoice_i = pluginChoiceKnob->getValue();
if (pluginChoice_i == 0) {
//Use default
readerPluginID = appPTR->getReaderPluginIDForFileType(ext);
} else {
std::vector<ChoiceOption> entries = pluginChoiceKnob->getEntries_mt_safe();
if ( (pluginChoice_i >= 0) && ( pluginChoice_i < (int)entries.size() ) ) {
readerPluginID = entries[pluginChoice_i].id;
}
}
}
// If the plug-in is the same, do not create a new decoder.
if (embeddedPlugin && embeddedPlugin->getPluginID() == readerPluginID) {
KnobFilePtr fileKnob = inputFileKnob.lock();
assert(fileKnob);
if (fileKnob) {
// Make sure instance changed action is called on the decoder and not caught in our knobChanged handler.
embeddedPlugin->getEffectInstance()->onKnobValueChanged_public(fileKnob.get(), eValueChangedReasonNatronInternalEdited, _publicInterface->getCurrentTime(), ViewSpec(0), true);
}
return;
}
//Destroy any previous reader
//This will store the serialization of the generic knobs
destroyReadNode();
bool defaultFallback = false;
if (readerPluginID.empty()) {
if (throwErrors) {
QString message = tr("Could not find a decoder to read %1 file format")
.arg( QString::fromUtf8( ext.c_str() ) );
throw std::runtime_error( message.toStdString() );
}
defaultFallback = true;
}
if ( !defaultFallback && !ReadNode::isBundledReader(readerPluginID, _publicInterface->getApp()->wasProjectCreatedWithLowerCaseIDs()) ) {
if (throwErrors) {
QString message = tr("%1 is not a bundled reader, please create it from the Image->Readers menu or with the tab menu in the Nodegraph")
.arg( QString::fromUtf8( readerPluginID.c_str() ) );
throw std::runtime_error( message.toStdString() );
}
defaultFallback = true;
}
NodePtr node;
//Find the appropriate reader
if (readerPluginID.empty() && !serialization) {
//Couldn't find any reader
if ( !ext.empty() ) {
QString message = tr("No plugin capable of decoding %1 was found.")
.arg( QString::fromUtf8( ext.c_str() ) );
//Dialogs::errorDialog(tr("Read").toStdString(), message.toStdString(), false);
if (throwErrors) {
throw std::runtime_error( message.toStdString() );
}
}
defaultFallback = true;
} else {
if ( readerPluginID.empty() ) {
readerPluginID = READ_NODE_DEFAULT_READER;
}
CreateNodeArgs args(readerPluginID, NodeCollectionPtr() );
args.setProperty(kCreateNodeArgsPropNoNodeGUI, true);
args.setProperty(kCreateNodeArgsPropOutOfProject, true);
args.setProperty<std::string>(kCreateNodeArgsPropNodeInitialName, "internalDecoderNode");
args.setProperty<NodePtr>(kCreateNodeArgsPropMetaNodeContainer, _publicInterface->getNode());
args.setProperty<NodeSerializationPtr>(kCreateNodeArgsPropNodeSerialization, serialization);
args.setProperty<bool>(kCreateNodeArgsPropAllowNonUserCreatablePlugins, true);
if (serialization || wasCreatedAsHiddenNode) {
args.setProperty<bool>(kCreateNodeArgsPropSilent, true);
args.setProperty<bool>(kCreateNodeArgsPropAllowNonUserCreatablePlugins, true); // also load deprecated plugins
}
node = _publicInterface->getApp()->createNode(args);
// Set the filename value
if (node) {
KnobFilePtr fileKnob = boost::dynamic_pointer_cast<KnobFile>(node->getKnobByName(kOfxImageEffectFileParamName));
if (fileKnob) {
fileKnob->setValue(filename);
}
}
{
QMutexLocker k(&embeddedPluginMutex);
embeddedPlugin = node;
}
if (pluginIDKnob) {
pluginIDKnob->setValue(readerPluginID);
}
placeReadNodeKnobsInPage();
//We need to explcitly refresh the Python knobs since we attached the embedded node knobs into this node.
_publicInterface->getNode()->declarePythonFields();
}
if (!node) {
defaultFallback = true;
}
if (defaultFallback) {
createDefaultReadNode();
}
// Clone the old values of the generic knobs if we created the same decoder than before
if (lastPluginIDCreated == readerPluginID) {
cloneGenericKnobs();
}
lastPluginIDCreated = readerPluginID;
NodePtr thisNode = _publicInterface->getNode();
//Refresh accepted bitdepths on the node
thisNode->refreshAcceptedBitDepths();
//Refresh accepted components
thisNode->initializeInputs();
//This will refresh the GUI with this Reader specific parameters
_publicInterface->recreateKnobs(true);
#pragma message WARN("TODO: if Gui, refresh pluginID, version, help tooltip in DockablePanel to reflect embedded node change")
KnobIPtr knob = node ? node->getKnobByName(kOfxImageEffectFileParamName) : _publicInterface->getKnobByName(kOfxImageEffectFileParamName);
if (knob) {
inputFileKnob = boost::dynamic_pointer_cast<KnobFile>(knob);
}
} // ReadNodePrivate::createReadNode
void
ReadNodePrivate::refreshFileInfoVisibility(const std::string& pluginID)
{
KnobButtonPtr fileInfos = fileInfosKnob.lock();
KnobIPtr hasMetadataKnob = _publicInterface->getKnobByName("showMetadata");
bool hasFfprobe = false;
if (!hasMetadataKnob) {
QString ffprobePath = getFFProbeBinaryPath();
hasFfprobe = QFile::exists(ffprobePath);
} else {
hasMetadataKnob->setSecret(true);
}
if ( hasMetadataKnob || ( ReadNode::isVideoReader(pluginID) && hasFfprobe ) ) {
fileInfos->setSecret(false);
} else {
fileInfos->setSecret(true);
}
}
void
ReadNodePrivate::refreshPluginSelectorKnob()
{
KnobFilePtr fileKnob = inputFileKnob.lock();
assert(fileKnob);
std::string filePattern = fileKnob->getValue();
std::vector<ChoiceOption> entries, help;
entries.push_back(ChoiceOption(kPluginSelectorParamEntryDefault, "", ReadNode::tr("Use the default plug-in chosen from the Preferences to read this file format").toStdString()));
QString qpattern = QString::fromUtf8( filePattern.c_str() );
std::string ext = QtCompat::removeFileExtension(qpattern).toLower().toStdString();
std::string pluginID;
if ( !ext.empty() ) {
pluginID = appPTR->getReaderPluginIDForFileType(ext);
IOPluginSetForFormat readersForFormat;
appPTR->getReadersForFormat(ext, &readersForFormat);
// Reverse it so that we sort them by decreasing score order
for (IOPluginSetForFormat::reverse_iterator it = readersForFormat.rbegin(); it != readersForFormat.rend(); ++it) {
Plugin* plugin = appPTR->getPluginBinary(QString::fromUtf8( it->pluginID.c_str() ), -1, -1, false);
std::stringstream ss;
ss << "Use " << plugin->getPluginLabel().toStdString() << " version ";
ss << plugin->getMajorVersion() << "." << plugin->getMinorVersion();
ss << " to read this file format";
entries.push_back( ChoiceOption(plugin->getPluginID().toStdString(), "", ss.str()));
}
}
KnobChoicePtr pluginChoice = pluginSelectorKnob.lock();
pluginChoice->populateChoices(entries);
pluginChoice->blockValueChanges();
pluginChoice->resetToDefaultValue(0);
pluginChoice->unblockValueChanges();
if (entries.size() <= 2) {
pluginChoice->setSecret(true);
} else {
pluginChoice->setSecret(false);
}
KnobStringPtr pluginIDKnob = pluginIDStringKnob.lock();
pluginIDKnob->blockValueChanges();
pluginIDKnob->setValue(pluginID);
pluginIDKnob->unblockValueChanges();
refreshFileInfoVisibility(pluginID);
} // ReadNodePrivate::refreshPluginSelectorKnob
bool
ReadNode::isReader() const
{
return true;
}
// static
bool
ReadNode::isVideoReader(const std::string& pluginID)
{
return (pluginID == PLUGINID_OFX_READFFMPEG);
}
bool
ReadNode::isVideoReader() const
{
NodePtr p = getEmbeddedReader();
return p ? isVideoReader( p->getPluginID() ) : false;
}
bool
ReadNode::isGenerator() const
{
return true;
}
bool
ReadNode::isOutput() const
{
return false;
}
bool
ReadNode::isMultiPlanar() const
{
NodePtr p = getEmbeddedReader();
return p ? p->getEffectInstance()->isMultiPlanar() : EffectInstance::isMultiPlanar();
}
bool
ReadNode::isViewAware() const
{
NodePtr p = getEmbeddedReader();
return p ? p->getEffectInstance()->isViewAware() : EffectInstance::isViewAware();
}
bool
ReadNode::supportsTiles() const
{
NodePtr p = getEmbeddedReader();
return p ? p->getEffectInstance()->supportsTiles() : EffectInstance::supportsTiles();
}
bool
ReadNode::supportsMultiResolution() const
{
NodePtr p = getEmbeddedReader();
return p ? p->getEffectInstance()->supportsMultiResolution() : EffectInstance::supportsMultiResolution();
}
bool
ReadNode::supportsMultipleClipDepths() const
{
NodePtr p = getEmbeddedReader();
return p ? p->getEffectInstance()->supportsMultipleClipDepths() : EffectInstance::supportsMultipleClipDepths();
}
RenderSafetyEnum
ReadNode::renderThreadSafety() const
{
NodePtr p = getEmbeddedReader();
return p ? p->getEffectInstance()->renderThreadSafety() : eRenderSafetyFullySafe;
}
bool
ReadNode::getCanTransform() const
{
return false;
}
SequentialPreferenceEnum
ReadNode::getSequentialPreference() const
{
NodePtr p = getEmbeddedReader();
return p ? p->getEffectInstance()->getSequentialPreference() : EffectInstance::getSequentialPreference();
}
EffectInstance::ViewInvarianceLevel
ReadNode::isViewInvariant() const
{
NodePtr p = getEmbeddedReader();
return p ? p->getEffectInstance()->isViewInvariant() : EffectInstance::isViewInvariant();
}
EffectInstance::PassThroughEnum
ReadNode::isPassThroughForNonRenderedPlanes() const
{
NodePtr p = getEmbeddedReader();
return p ? p->getEffectInstance()->isPassThroughForNonRenderedPlanes() : EffectInstance::isPassThroughForNonRenderedPlanes();
}
bool
ReadNode::getCreateChannelSelectorKnob() const
{
return false;
}
bool
ReadNode::isHostChannelSelectorSupported(bool* /*defaultR*/,
bool* /*defaultG*/,
bool* /*defaultB*/,
bool* /*defaultA*/) const
{
return false;
}
int
ReadNode::getMajorVersion() const
{ return 1; }
int