forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.h
1607 lines (1135 loc) · 51.9 KB
/
Node.h
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 ***** */
#ifndef NATRON_ENGINE_NODE_H
#define NATRON_ENGINE_NODE_H
// ***** 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 "Global/Macros.h"
#include <vector>
#include <string>
#include <map>
#include <list>
#include <bitset>
CLANG_DIAG_OFF(deprecated)
#include <QtCore/QMetaType>
#include <QtCore/QObject>
CLANG_DIAG_ON(deprecated)
#include <QtCore/QMutex>
#if !defined(Q_MOC_RUN) && !defined(SBK_RUN)
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#endif
#include "Engine/AppManager.h"
#include "Global/KeySymbols.h"
#include "Engine/ImagePlaneDesc.h"
#include "Engine/CacheEntryHolder.h"
#include "Engine/ViewIdx.h"
#include "Engine/EngineFwd.h"
#include "Engine/Markdown.h"
#define NATRON_PARAMETER_PAGE_NAME_EXTRA "Node"
#define NATRON_PARAMETER_PAGE_NAME_INFO "Info"
#define kDisableNodeKnobName "disableNode"
#define kLifeTimeNodeKnobName "nodeLifeTime"
#define kEnableLifeTimeNodeKnobName "enableNodeLifeTime"
#define kUserLabelKnobName "userTextArea"
#define kEnableMaskKnobName "enableMask"
#define kEnableInputKnobName "enableInput"
#define kMaskChannelKnobName "maskChannel"
#define kInputChannelKnobName "inputChannel"
#define kEnablePreviewKnobName "enablePreview"
#define kOutputChannelsKnobName "channels"
#define kNodeParamProcessAllLayers "processAllPlanes"
#define kNodeParamProcessAllLayersLabel "All Planes"
#define kNodeParamProcessAllLayersHint "When checked all planes in input will be processed and output to the same plane as in input. It is useful for example to apply a Transform effect on all planes."
#define kOfxMaskInvertParamName "maskInvert"
#define kOfxMixParamName "mix"
#define kReadOIIOAvailableViewsKnobName "availableViews"
#define kWriteOIIOParamViewsSelector "viewsSelector"
NATRON_NAMESPACE_ENTER
class Node
: public QObject
, public boost::enable_shared_from_this<Node>
, public CacheEntryHolder
{
GCC_DIAG_SUGGEST_OVERRIDE_OFF
Q_OBJECT
GCC_DIAG_SUGGEST_OVERRIDE_ON
public:
struct Implementation;
public:
// TODO: enable_shared_from_this
// constructors should be privatized in any class that derives from boost::enable_shared_from_this<>
Node(const AppInstancePtr& app,
const NodeCollectionPtr& group,
Plugin* plugin);
public:
virtual ~Node();
NodeCollectionPtr getGroup() const;
/**
* @brief Returns true if this node is a "user" node. For internal invisible node, this would return false.
* If this function returns false, the node will not be serialized.
**/
bool isPartOfProject() const;
const Plugin* getPlugin() const;
/**
* @brief Used internally when instantiating a Python template, we first make a group and then pass a pointer
* to the real plugin.
**/
void switchInternalPlugin(Plugin* plugin);
void setPrecompNode(const PrecompNodePtr& precomp);
PrecompNodePtr isPartOfPrecomp() const;
/**
* @brief Creates the EffectInstance that will be embedded into this node and set it up.
* This function also loads all parameters. Node connections will not be setup in this method.
**/
void load(const CreateNodeArgs& args);
void initNodeScriptName(const NodeSerialization* serialization, const QString& fixedName);
///called by load() and OfxEffectInstance, do not call this!
void loadKnobs(const NodeSerialization & serialization, bool updateKnobGui = false);
void loadKnob(const KnobIPtr & knob,
const NodeSerialization & serialization,
bool updateKnobGui = false);
///Set values for Knobs given their serialization
void setValuesFromSerialization(const CreateNodeArgs& args);
///to be called once all nodes have been loaded from the project or right away after the load() function.
///this is so the child of a multi-instance can retrieve the pointer to it's main instance
void fetchParentMultiInstancePointer();
///If the node can have a roto context, create it
void createRotoContextConditionnally();
void createTrackerContextConditionnally();
///function called by EffectInstance to create a knob
template <class K>
boost::shared_ptr<K> createKnob(const std::string &description,
int dimension = 1,
bool declaredByPlugin = true)
{
return appPTR->getKnobFactory().createKnob<K>(getEffectInstance(), description, dimension, declaredByPlugin);
}
///This cannot be done in loadKnobs as to call this all the nodes in the project must have
///been loaded first.
void storeKnobsLinks(const NodeSerialization & serialization,
const std::map<std::string, std::string>& oldNewScriptNamesMapping);
// Once all nodes are created, we can restore the links that were previously saved by storeKnobsLinks()
void restoreKnobsLinks(const NodesList & allNodes,
const std::map<std::string, std::string>& oldNewScriptNamesMapping,
bool throwOnFailure);
void restoreUserKnobs(const NodeSerialization& serialization);
void setPagesOrder(const std::list<std::string>& pages);
std::list<std::string> getPagesOrder() const;
bool isNodeCreated() const;
bool isGLFinishRequiredBeforeRender() const;
void refreshAcceptedBitDepths();
/**
* @brief Quits any processing on going on this node, this call is non blocking
**/
void quitAnyProcessing_non_blocking();
void quitAnyProcessing_blocking(bool allowThreadsToRestart);
/**
* @brief Returns true if all processing threads controlled by this node have quit
**/
bool areAllProcessingThreadsQuit() const;
/* @brief Similar to quitAnyProcessing except that the threads aren't destroyed
* This is called when a node is deleted by the user
*/
void abortAnyProcessing_non_blocking();
void abortAnyProcessing_blocking();
/*Never call this yourself. This is needed by OfxEffectInstance so the pointer to the live instance
* is set earlier.
*/
void setEffect(const EffectInstancePtr& liveInstance);
EffectInstancePtr getEffectInstance() const;
/**
* @brief Returns true if the node is a multi-instance node, that is, holding several other nodes.
* e.g: the Tracker node.
**/
bool isMultiInstance() const;
NodePtr getParentMultiInstance() const;
///Accessed by the serialization thread, but mt safe since never changed
std::string getParentMultiInstanceName() const;
void getChildrenMultiInstance(NodesList* children) const;
/**
* @brief Returns the hash value of the node, or 0 if it has never been computed.
**/
U64 getHashValue() const;
virtual std::string getCacheID() const OVERRIDE FINAL;
/**
* @brief Forwarded to the live effect instance
**/
void beginEditKnobs();
/**
* @brief Forwarded to the live effect instance
**/
const std::vector<KnobIPtr> & getKnobs() const;
/**
* @brief When frozen is true all the knobs of this effect read-only so the user can't interact with it.
* @brief This function will be called on all input nodes as well
**/
void setKnobsFrozen(bool frozen);
/*Returns in viewers the list of all the viewers connected to this node*/
void hasViewersConnected(std::list<ViewerInstance* >* viewers) const;
void hasOutputNodesConnected(std::list<OutputEffectInstance* >* writers) const;
private:
void hasViewersConnectedInternal(std::list<ViewerInstance* >* viewers,
std::list<const Node*>* markedNodes) const;
void hasOutputNodesConnectedInternal(std::list<OutputEffectInstance* >* writers,
std::list<const Node*>* markedNodes) const;
public:
/**
* @brief Forwarded to the live effect instance
**/
int getMajorVersion() const;
/**
* @brief Forwarded to the live effect instance
**/
int getMinorVersion() const;
/**
* @brief Forwarded to the live effect instance
**/
bool isInputNode() const;
/**
* @brief Forwarded to the live effect instance
**/
bool isOutputNode() const;
/**
* @brief Forwarded to the live effect instance
**/
bool isOpenFXNode() const;
/**
* @brief Returns true if the node is either a roto node
**/
bool isRotoNode() const;
/**
* @brief Returns true if this node is a tracker
**/
bool isTrackerNodePlugin() const;
bool isPointTrackerNode() const;
/**
* @brief Returns true if this node is a backdrop
**/
bool isBackdropNode() const;
/**
* @brief Returns true if the node is a rotopaint node
**/
bool isRotoPaintingNode() const;
ViewerInstance* isEffectViewer() const;
NodeGroup* isEffectGroup() const;
/**
* @brief Returns a pointer to the rotoscoping context if the node is in the paint context, otherwise NULL.
**/
RotoContextPtr getRotoContext() const;
TrackerContextPtr getTrackerContext() const;
U64 getRotoAge() const;
/**
* @brief Forwarded to the live effect instance
**/
int getNInputs() const;
/**
* @brief Returns true if the given input supports the given components. If inputNb equals -1
* then this function will check whether the effect can produce the given components.
**/
bool isSupportedComponent(int inputNb, const ImagePlaneDesc& comp) const;
/**
* @brief Returns the most appropriate components that can be supported by the inputNb.
* If inputNb equals -1 then this function will check the output components.
**/
ImagePlaneDesc findClosestSupportedComponents(int inputNb, const ImagePlaneDesc& comp) const;
static ImagePlaneDesc findClosestInList(const ImagePlaneDesc& comp,
const std::list<ImagePlaneDesc> &components,
bool multiPlanar);
ImageBitDepthEnum getBestSupportedBitDepth() const;
bool isSupportedBitDepth(ImageBitDepthEnum depth) const;
ImageBitDepthEnum getClosestSupportedBitDepth(ImageBitDepthEnum depth);
/**
* @brief Returns the components and index of the channel to use to produce the mask.
* None = -1
* R = 0
* G = 1
* B = 2
* A = 3
**/
int getMaskChannel(int inputNb, const std::list<ImagePlaneDesc>& availableLayers, ImagePlaneDesc* comps) const;
int isMaskChannelKnob(const KnobI* knob) const;
/**
* @brief Returns whether masking is enabled or not
**/
bool isMaskEnabled(int inputNb) const;
/**
* @brief Returns a pointer to the input Node at index 'index'
* or NULL if it couldn't find such node.
* MT-safe
* This function uses thread-local storage because several render thread can be rendering concurrently
* and we want the rendering of a frame to have a "snap-shot" of the tree throughout the rendering of the
* frame.
*
* DO NOT CALL THIS ON THE SERIALIZATION THREAD, INSTEAD PREFER USING getInputNames()
**/
NodePtr getInput(int index) const;
/**
* @brief Returns the input as seen on the gui. This is not necessarily the same as the value returned by getInput.
**/
NodePtr getGuiInput(int index) const;
/**
* @brief Same as getInput except that it doesn't do group redirections for Inputs/Outputs
**/
NodePtr getRealInput(int index) const;
NodePtr getRealGuiInput(int index) const;
private:
NodePtr getInputInternal(bool useGuiInput, bool useGroupRedirections, int index) const;
public:
/**
* @brief Returns the input index of the node if it is an input of this node, -1 otherwise.
**/
int getInputIndex(const Node* node) const;
/**
* @brief Returns true if the node is currently executing the onInputChanged handler.
**/
bool duringInputChangedAction() const;
/**
*@brief Returns the inputs of the node as the Gui just set them.
* The vector might be different from what getInputs_other_thread() could return.
* This can only be called by the main thread.
**/
const std::vector<NodeWPtr> & getInputs() const WARN_UNUSED_RETURN;
const std::vector<NodeWPtr> & getGuiInputs() const WARN_UNUSED_RETURN;
std::vector<NodeWPtr> getInputs_copy() const WARN_UNUSED_RETURN;
/**
* @brief Returns the input index of the node n if it exists,
* -1 otherwise.
**/
int inputIndex(const NodePtr& n) const;
const std::vector<std::string> & getInputLabels() const;
std::string getInputLabel(int inputNb) const;
std::string getInputHint(int inputNb) const;
void setInputLabel(int inputNb, const std::string& label);
void setInputHint(int inputNb, const std::string& hint);
bool isInputVisible(int inputNb) const;
void setInputVisible(int inputNb, bool visible);
int getInputNumberFromLabel(const std::string& inputLabel) const;
bool isInputOnlyAlpha(int inputNb) const;
bool isInputConnected(int inputNb) const;
bool hasOutputConnected() const;
bool hasInputConnected() const;
bool hasOverlay() const;
bool hasMandatoryInputDisconnected() const;
bool hasAllInputsConnected() const;
/**
* @brief This is used by the auto-connection algorithm.
* When connecting nodes together this function helps determine
* on which input it should connect a new node.
* It returns the first non optional empty input or the first optional
* empty input if they are all optionals, or -1 if nothing matches the 2 first conditions..
* if all inputs are connected.
**/
virtual int getPreferredInputForConnection() const;
virtual int getPreferredInput() const;
NodePtr getPreferredInputNode() const;
void setRenderThreadSafety(RenderSafetyEnum safety);
RenderSafetyEnum getCurrentRenderThreadSafety() const;
void revertToPluginThreadSafety();
void setCurrentOpenGLRenderSupport(PluginOpenGLRenderSupport support);
PluginOpenGLRenderSupport getCurrentOpenGLRenderSupport() const;
void setCurrentSequentialRenderSupport(SequentialPreferenceEnum support);
SequentialPreferenceEnum getCurrentSequentialRenderSupport() const;
void setCurrentCanTransform(bool support);
bool getCurrentCanTransform() const;
void setCurrentSupportTiles(bool support);
bool getCurrentSupportTiles() const;
void refreshDynamicProperties();
bool isRenderScaleSupportEnabledForPlugin() const;
bool isMultiThreadingSupportEnabledForPlugin() const;
//////////////////////ROTO-PAINT related functionalities//////////////////////
//////////////////////////////////////////////////////////////////////////////
void prepareForNextPaintStrokeRender();
//Used by nodes below the rotopaint tree to optimize the RoI
void setLastPaintStrokeDataNoRotopaint();
void invalidateLastPaintStrokeDataNoRotopaint();
void getPaintStrokeRoD(double time, RectD* bbox) const;
RectD getPaintStrokeRoD_duringPainting() const;
bool isLastPaintStrokeBitmapCleared() const;
void clearLastPaintStrokeRoD();
void getLastPaintStrokePoints(double time,
unsigned int mipmapLevel,
std::list<std::list<std::pair<Point, double> > >* strokes,
int* strokeIndex) const;
ImagePtr getOrRenderLastStrokeImage(unsigned int mipMapLevel,
double par,
const ImagePlaneDesc& components,
ImageBitDepthEnum depth) const;
void setWhileCreatingPaintStroke(bool creating);
bool isDuringPaintStrokeCreation() const;
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
void setProcessChannelsValues(bool doR, bool doG, bool doB, bool doA);
private:
int getPreferredInputInternal(bool connected) const;
public:
/**
* @brief Returns in 'outputs' a map of all nodes connected to this node
* where the value of the map is the input index from which these outputs
* are connected to this node.
**/
void getOutputsConnectedToThisNode(std::map<NodePtr, int>* outputs);
const NodesWList & getOutputs() const;
const NodesWList & getGuiOutputs() const;
void getOutputs_mt_safe(NodesWList& outputs) const;
/**
* @brief Same as above but enters into subgroups
**/
void getOutputsWithGroupRedirection(NodesList& outputs) const;
/**
* @brief Each input name is appended to the vector, in the same order
* as they are in the internal inputs vector. Disconnected inputs are
* represented as empty strings.
**/
void getInputNames(std::map<std::string, std::string> & inputNames) const;
enum CanConnectInputReturnValue
{
eCanConnectInput_ok = 0,
eCanConnectInput_indexOutOfRange,
eCanConnectInput_inputAlreadyConnected,
eCanConnectInput_givenNodeNotConnectable,
eCanConnectInput_groupHasNoOutput,
eCanConnectInput_graphCycles,
eCanConnectInput_differentPars,
eCanConnectInput_differentFPS,
eCanConnectInput_multiResNotSupported,
};
/**
* @brief Returns true if a connection is possible for the given input number of the current node
* to the given input.
**/
Node::CanConnectInputReturnValue canConnectInput(const NodePtr& input, int inputNumber) const;
/** @brief Adds the node parent to the input inputNumber of the
* node. Returns true if it succeeded, false otherwise.
* When returning false, this means an input was already
* connected for this inputNumber. It should be removed
* beforehand.
*/
virtual bool connectInput(const NodePtr& input, int inputNumber);
bool connectInputBase(const NodePtr& input,
int inputNumber)
{
return Node::connectInput(input, inputNumber);
}
/** @brief Removes the node connected to the input inputNumber of the
* node. Returns the inputNumber if it could remove it, otherwise returns
-1.
*/
virtual int disconnectInput(int inputNumber);
/** @brief Removes the node input of the
* node inputs. Returns the inputNumber if it could remove it, otherwise returns
-1.*/
virtual int disconnectInput(Node* input);
/**
* @brief Same as:
disconnectInput(inputNumber);
connectInput(input,inputNumber);
* Except that it is atomic
**/
bool replaceInput(const NodePtr& input, int inputNumber);
void setNodeGuiPointer(const NodeGuiIPtr& gui);
NodeGuiIPtr getNodeGui() const;
bool isSettingsPanelVisible() const;
bool isSettingsPanelMinimized() const;
void onOpenGLEnabledKnobChangedOnProject(bool activated);
private:
bool replaceInputInternal(const NodePtr& input, int inputNumber, bool useGuiValues);
int disconnectInputInternal(Node* input, bool useGuiInputs);
bool isSettingsPanelVisibleInternal(std::set<const Node*>& recursionList) const;
public:
bool isUserSelected() const;
bool shouldCacheOutput(bool isFrameVaryingOrAnimated, double time, ViewIdx view, int visitsCount) const;
/**
* @brief If the session is a GUI session, then this function sets the position of the node on the nodegraph.
**/
void setPosition(double x, double y);
void getPosition(double *x, double *y) const;
void setSize(double w, double h);
void getSize(double* w, double* h) const;
/**
* @brief Get the colour of the node as it appears on the nodegraph.
**/
bool getColor(double* r, double *g, double* b) const;
void setColor(double r, double g, double b);
std::string getKnobChangedCallback() const;
std::string getInputChangedCallback() const;
/**
* @brief This is used exclusively by nodes in the underlying graph of the implementation of the RotoPaint.
* Do not use that anywhere else.
**/
void attachRotoItem(const RotoDrawableItemPtr& stroke);
RotoDrawableItemPtr getAttachedRotoItem() const;
//This flag is used for the Roto plug-in and for the Merge inside the rotopaint tree
//so that if the input of the roto node is RGB, it gets converted with alpha = 0, otherwise the user
//won't be able to paint the alpha channel
bool usesAlpha0ToConvertFromRGBToRGBA() const;
void setUseAlpha0ToConvertFromRGBToRGBA(bool use);
protected:
void runInputChangedCallback(int index);
private:
/**
* @brief Adds an output to this node.
**/
void connectOutput(bool useGuiValues, const NodePtr& output);
/** @brief Removes the node output of the
* node outputs. Returns the outputNumber if it could remove it,
otherwise returns -1.*/
int disconnectOutput(bool useGuiValues, const Node* output);
public:
/**
* @brief Switches the 2 first inputs that are not a mask, if and only if they have compatible components/bitdepths
**/
void switchInput0And1();
/*============================*/
/**
* @brief Forwarded to the live effect instance
**/
std::string getPluginID() const;
/**
* @brief Forwarded to the live effect instance
**/
std::string getPluginLabel() const;
/**
* @brief Returns the path to where the resources are stored for this plug-in
**/
std::string getPluginResourcesPath() const;
void getPluginGrouping(std::list<std::string>* grouping) const;
/**
* @brief Forwarded to the live effect instance
**/
std::string getPluginDescription() const;
/**
* @brief Returns the absolute file-path to the plug-in icon.
**/
std::string getPluginIconFilePath() const;
// These functions are gone in Natron 2.2
std::string getPyPlugID() const;
std::string getPyPlugLabel() const;
std::string getPyPlugDescription() const;
void getPyPlugGrouping(std::list<std::string>* grouping) const;
std::string getPyPlugIconFilePath() const;
int getPyPlugMajorVersion() const;
/*============================*/
AppInstancePtr getApp() const;
/* @brief Make this node inactive. It will appear
as if it was removed from the graph editor
but the object still lives to allow
undo/redo operations.
@param outputsToDisconnect A list of the outputs whose inputs must be disconnected
@param disconnectAll If set to true the parameter outputsToDisconnect is ignored and all outputs' inputs are disconnected
@param reconnect If set to true Natron will attempt to re-connect disconnected output to an input of this node
@param hideGui When true, the node gui will be notified so it gets hidden
*/
void deactivate(const std::list<NodePtr> & outputsToDisconnect = std::list<NodePtr>(),
bool disconnectAll = true,
bool reconnect = true,
bool hideGui = true,
bool triggerRender = true,
bool unslaveKnobs = true);
/* @brief Make this node active. It will appear
again on the node graph.
WARNING: this function can only be called
after a call to deactivate() has been made.
*
* @param outputsToRestore Only the outputs specified that were previously connected to the node prior to the call to
* deactivate() will be reconnected as output to this node.
* @param restoreAll If true, the parameter outputsToRestore will be ignored.
*/
void activate(const std::list<NodePtr> & outputsToRestore = std::list<NodePtr>(),
bool restoreAll = true,
bool triggerRender = true);
/**
* @brief Calls deactivate() and then remove the node from the project. The object will be destroyed
* when the caller releases the reference to this Node
* @param autoReconnect If set to true, outputs connected to this node will try to connect to the input of this node automatically.
**/
void destroyNode(bool blockingDestroy, bool autoReconnect);
private:
void doDestroyNodeInternalEnd(bool autoReconnect);
public:
/**
* @brief Forwarded to the live effect instance
**/
KnobIPtr getKnobByName(const std::string & name) const;
/*@brief The derived class should query this to abort any long process
in the engine function.*/
bool aborted() const;
bool makePreviewByDefault() const;
void togglePreview();
bool isPreviewEnabled() const;
/**
* @brief Makes a small 8bits preview image of size width x height of format ARGB32.
* Pre-condition:
* - buf has been allocated for the correct amount of memory needed to fill the buffer.
* Post-condition:
* - buf must not be freed or overflown.
* It will serve as a preview on the node's graphical user interface.
* This function is called directly by the GUI to display the preview.
* In order to notify the GUI that you want to refresh the preview, just
* call refreshPreviewImage(time).
*
* The width and height might be modified by the function, so their value can
* be queried at the end of the function
**/
bool makePreviewImage(SequenceTime time, int *width, int *height, unsigned int* buf);
/**
* @brief Returns true if the node is currently rendering a preview image.
**/
bool isRenderingPreview() const;
/**
* @brief Returns true if the node is active for use in the graph editor. MT-safe
**/
bool isActivated() const;
/**
* @brief Use this function to post a transient message to the user. It will be displayed using
* a dialog. The message can be of 4 types...
* INFORMATION_MESSAGE : you just want to inform the user about something.
* eMessageTypeWarning : you want to inform the user that something important happened.
* eMessageTypeError : you want to inform the user an error occurred.
* eMessageTypeQuestion : you want to ask the user about something.
* The function will return true always except for a message of type eMessageTypeQuestion, in which
* case the function may return false if the user pressed the 'No' button.
* @param content The message you want to pass.
**/
bool message(MessageTypeEnum type, const std::string & content) const;
/**
* @brief Use this function to post a persistent message to the user. It will be displayed on the
* node's graphical interface and on any connected viewer. The message can be of 3 types...
* INFORMATION_MESSAGE : you just want to inform the user about something.
* eMessageTypeWarning : you want to inform the user that something important happened.
* eMessageTypeError : you want to inform the user an error occurred.
* @param content The message you want to pass.
**/
void setPersistentMessage(MessageTypeEnum type, const std::string & content);
/**
* @brief Clears any message posted previously by setPersistentMessage.
* This function will also be called on all inputs
**/
void clearPersistentMessage(bool recurse);
private:
void clearPersistentMessageRecursive(std::list<Node*>& markedNodes);
void clearPersistentMessageInternal();
public:
void purgeAllInstancesCaches();
bool notifyInputNIsRendering(int inputNb);
void notifyInputNIsFinishedRendering(int inputNb);
bool notifyRenderingStarted();
void notifyRenderingEnded();
int getIsInputNRenderingCounter(int inputNb) const;
int getIsNodeRenderingCounter() const;
/**
* @brief forwarded to the live instance
**/
void setOutputFilesForWriter(const std::string & pattern);
///called by EffectInstance
void registerPluginMemory(size_t nBytes);
///called by EffectInstance
void unregisterPluginMemory(size_t nBytes);
//see eRenderSafetyInstanceSafe in EffectInstance::renderRoI
//only 1 clone can render at any time
QMutex & getRenderInstancesSharedMutex();
void refreshPreviewsRecursivelyDownstream(double time);
void refreshPreviewsRecursivelyUpstream(double time);
void incrementKnobsAge();
void incrementKnobsAge_internal();
public:
U64 getKnobsAge() const;
void onAllKnobsSlaved(bool isSlave, KnobHolder* master);
void onKnobSlaved(const KnobIPtr& slave, const KnobIPtr& master, int dimension, bool isSlave);
NodePtr getMasterNode() const;
#ifdef NATRON_ENABLE_IO_META_NODES
//When creating a Reader or Writer node, this is a pointer to the "bundle" node that the user actually see.
NodePtr getIOContainer() const;
#endif
/**
* @brief Attempts to lock an image for render. If it successfully obtained the lock,
* the thread can continue and render normally. If another thread is currently
* rendering that image, this function will wait until the image is available for render again.
* This is used internally by EffectInstance::renderRoI
**/
void lock(const ImagePtr& entry);
bool tryLock(const ImagePtr& entry);
void unlock(const ImagePtr& entry);
/**
* @brief DO NOT EVER USE THIS FUNCTION. This is provided for compatibility with plug-ins that
* do not respect the OpenFX specification.
**/
ImagePtr getImageBeingRendered(double time, unsigned int mipMapLevel, ViewIdx view);
void beginInputEdition();
void endInputEdition(bool triggerRender);
void onInputChanged(int inputNb, bool isInputA = true);
bool onEffectKnobValueChanged(KnobI* what, ValueChangedReasonEnum reason);
bool isNodeDisabled() const;
void setNodeDisabled(bool disabled);
KnobBoolPtr getDisabledKnob() const;
bool isLifetimeActivated(int *firstFrame, int *lastFrame) const;
std::string getNodeExtraLabel() const;
/**
* @brief Show keyframe markers on the timeline. The signal to refresh the timeline's gui
* will be emitted only if emitSignal is set to true.
* Calling this function without calling hideKeyframesFromTimeline() has no effect.
**/
void showKeyframesOnTimeline(bool emitSignal);
/**
* @brief Hide keyframe markers on the timeline. The signal to refresh the timeline's gui
* will be emitted only if emitSignal is set to true.
* Calling this function without calling showKeyframesOnTimeline() has no effect.
**/
void hideKeyframesFromTimeline(bool emitSignal);
bool areKeyframesVisibleOnTimeline() const;
/**
* @brief The given label is appended in the node's label but will not be editable
* by the user from the settings panel.
* If a custom data tag is found, it will replace any custom data.
**/
void replaceCustomDataInlabel(const QString & data);
private:
void restoreSublabel();
public:
/**
* @brief Returns whether this node or one of its inputs (recursively) is marked as
* eSequentialPreferenceOnlySequential
*
* @param nodeName If the return value is true, this will be set to the name of the node
* which is sequential.
*
**/
bool hasSequentialOnlyNodeUpstream(std::string & nodeName) const;
/**
* @brief Updates the sub label knob: e.g for the Merge node it corresponds to the
* operation name currently used and visible on the node
**/
void updateEffectLabelKnob(const QString & name);
/**
* @brief Returns true if an effect should be able to connect this node.
**/
bool canOthersConnectToThisNode() const;
/**
* @brief Clears any pointer referring to the last rendered image
**/
void clearLastRenderedImage();
struct KnobLink
{
///The knob being slaved
KnobIWPtr slave;
KnobIWPtr master;
///The master node to which the knob is slaved to
NodeWPtr masterNode;
///The dimension being slaved, -1 if irrelevant
int dimension;
};
void getKnobsLinks(std::list<KnobLink> & links) const;