forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Knob.h
2900 lines (2294 loc) · 111 KB
/
Knob.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 Engine_Knob_h
#define Engine_Knob_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 <set>
#include <map>
#if !defined(Q_MOC_RUN) && !defined(SBK_RUN)
#include <boost/enable_shared_from_this.hpp>
#include <boost/scoped_ptr.hpp>
#endif
#include <QtCore/QReadWriteLock>
#include <QtCore/QMutex>
#include <QtCore/QString>
#include <QtCore/QCoreApplication>
#include "Engine/Variant.h"
#include "Engine/AppManager.h" // for AppManager::createKnob
#include "Engine/OverlaySupport.h"
#include "Engine/ViewIdx.h"
#include "Engine/EngineFwd.h"
#define NATRON_USER_MANAGED_KNOBS_PAGE_LABEL "User"
#define NATRON_USER_MANAGED_KNOBS_PAGE "userNatron"
NATRON_NAMESPACE_ENTER
class KnobSignalSlotHandler
: public QObject
{
Q_OBJECT
KnobIWPtr k;
public:
KnobSignalSlotHandler(const KnobIPtr &knob);
KnobIPtr getKnob() const
{
return k.lock();
}
void s_animationLevelChanged(ViewSpec view,
int dim)
{
Q_EMIT animationLevelChanged(view, dim);
}
void s_valueChanged(ViewSpec view,
int dimension,
int reason)
{
Q_EMIT valueChanged(view, dimension, reason);
}
void s_secretChanged()
{
Q_EMIT secretChanged();
}
void s_viewerContextSecretChanged()
{
Q_EMIT viewerContextSecretChanged();
}
void s_enabledChanged()
{
Q_EMIT enabledChanged();
}
void s_keyFrameSet(double time,
ViewSpec view,
int dimension,
int reason,
bool added)
{
Q_EMIT keyFrameSet(time, view, dimension, reason, added);
}
void s_keyFrameRemoved(double time,
ViewSpec view,
int dimension,
int reason)
{
Q_EMIT keyFrameRemoved(time, view, dimension, reason);
}
void s_multipleKeyFramesSet(const std::list<double>& keys,
ViewSpec view,
int dimension,
int reason)
{
Q_EMIT multipleKeyFramesSet(keys, view, dimension, reason);
}
void s_multipleKeyFramesRemoved(const std::list<double>& keys,
ViewSpec view,
int dimension,
int reason)
{
Q_EMIT multipleKeyFramesRemoved(keys, view, dimension, reason);
}
void s_animationAboutToBeRemoved(ViewSpec view,
int dimension)
{
Q_EMIT animationAboutToBeRemoved(view, dimension);
}
void s_animationRemoved(ViewSpec view,
int dimension)
{
Q_EMIT animationRemoved(view, dimension);
}
void s_knobSlaved(int dim,
bool slaved)
{
Q_EMIT knobSlaved(dim, slaved);
}
void s_setValueWithUndoStack(const Variant& v,
ViewSpec view,
int dim)
{
Q_EMIT setValueWithUndoStack(v, view, dim);
}
void s_appendParamEditChange(ValueChangedReasonEnum reason,
Variant v,
ViewSpec view,
int dim,
double time,
bool createNewCommand,
bool setKeyFrame)
{
Q_EMIT appendParamEditChange( (int)reason, v, view, dim, time, createNewCommand, setKeyFrame );
}
void s_setDirty(bool b)
{
Q_EMIT dirty(b);
}
void s_setFrozen(bool f)
{
Q_EMIT frozenChanged(f);
}
void s_keyFrameMoved(ViewSpec view,
int dimension,
double oldTime,
double newTime)
{
Q_EMIT keyFrameMoved(view, dimension, oldTime, newTime);
}
void s_redrawGuiCurve(CurveChangeReason reason,
ViewSpec view,
int dimension)
{
Q_EMIT redrawGuiCurve( (int)reason, view, dimension );
}
void s_minMaxChanged(double mini,
double maxi,
int index)
{
Q_EMIT minMaxChanged(mini, maxi, index);
}
void s_displayMinMaxChanged(double mini,
double maxi,
int index)
{
Q_EMIT displayMinMaxChanged(mini, maxi, index);
}
void s_helpChanged()
{
Q_EMIT helpChanged();
}
void s_expressionChanged(int dimension)
{
Q_EMIT expressionChanged(dimension);
}
void s_derivativeMoved(double time,
ViewSpec view,
int dimension)
{
Q_EMIT derivativeMoved(time, view, dimension);
}
void s_keyFrameInterpolationChanged(double time,
ViewSpec view,
int dimension)
{
Q_EMIT keyFrameInterpolationChanged(time, view, dimension);
}
void s_hasModificationsChanged()
{
Q_EMIT hasModificationsChanged();
}
void s_labelChanged()
{
Q_EMIT labelChanged();
}
void s_inViewerContextLabelChanged()
{
Q_EMIT inViewerContextLabelChanged();
}
void s_evaluateOnChangeChanged(bool value)
{
Q_EMIT evaluateOnChangeChanged(value);
}
void s_dimensionNameChanged(int dimension)
{
Q_EMIT dimensionNameChanged(dimension);
}
public Q_SLOTS:
/**
* @brief Calls KnobI::onAnimationRemoved
**/
void onAnimationRemoved(ViewSpec view, int dimension);
void onMasterKeyFrameSet(double time, ViewSpec view, int dimension, int reason, bool added);
void onMasterKeyFrameRemoved(double time, ViewSpec view, int dimension, int reason);
void onMasterKeyFrameMoved(ViewSpec view, int dimension, double oldTime, double newTime);
void onMasterAnimationRemoved(ViewSpec view, int dimension);
Q_SIGNALS:
void evaluateOnChangeChanged(bool value);
///emitted whenever setAnimationLevel is called. It is meant to notify
///openfx params whether it is auto-keying or not.
void animationLevelChanged(ViewSpec view, int dimension);
///Emitted when the value is changed with a reason different than eValueChangedReasonUserEdited
///This can happen as the result of a setValue() call from the plug-in or by
///a slaved knob whose master's value changed. The reason is passed in parameter.
void valueChanged(ViewSpec view, int dimension, int reason);
///Emitted when the secret state of the knob changed
void secretChanged();
///Emitted when the secret state of the knob changed in the viewer context
void viewerContextSecretChanged();
///Emitted when a dimension enabled state changed
void enabledChanged();
///This is called to notify the gui that the knob shouldn't be editable.
///Basically this is used when rendering with a Writer or for Trackers while tracking is active.
void frozenChanged(bool frozen);
///Emitted whenever a keyframe is set with a reason different of eValueChangedReasonUserEdited
///@param added True if this is the first time that the keyframe was set
void keyFrameSet(double time, ViewSpec view, int dimension, int reason, bool added);
void multipleKeyFramesSet(std::list<double>, ViewSpec view, int dimension, int reason);
void multipleKeyFramesRemoved(std::list<double>, ViewSpec view, int dimension, int reason);
///Emitted whenever a keyframe is removed with a reason different of eValueChangedReasonUserEdited
void keyFrameRemoved(double time, ViewSpec view, int dimension, int reason);
void keyFrameMoved( ViewSpec view, int dimension, double oldTime, double newTime);
void derivativeMoved(double time, ViewSpec view, int dimension);
void keyFrameInterpolationChanged(double time, ViewSpec view, int dimension);
/// Emitted when the gui curve has been cloned
void redrawGuiCurve(int reason, ViewSpec view, int dimension);
///Emitted whenever all keyframes of a dimension are about removed with a reason different of eValueChangedReasonUserEdited
void animationAboutToBeRemoved(ViewSpec view, int dimension);
///Emitted whenever all keyframes of a dimension are effectively removed
void animationRemoved(ViewSpec view, int dimension);
///Emitted whenever a knob is slaved via the slaveTo function with a reason of eValueChangedReasonPluginEdited.
void knobSlaved(int dimension, bool slaved);
///Emitted whenever the GUI should set the value using the undo stack. This is
///only to address the problem of interacts that should use the undo/redo stack.
void setValueWithUndoStack(Variant v, ViewSpec view, int dim);
///Same as setValueWithUndoStack except that the value change will be compressed
///in a multiple edit undo/redo action
void appendParamEditChange(int reason, Variant v, ViewSpec view, int dim, double time, bool createNewCommand, bool setKeyFrame);
///Emitted whenever the knob is dirty, @see KnobI::setDirty(bool)
void dirty(bool);
void minMaxChanged(double mini, double maxi, int index);
void displayMinMaxChanged(double mini, double maxi, int index);
void helpChanged();
void expressionChanged(int dimension);
void hasModificationsChanged();
void labelChanged();
void inViewerContextLabelChanged();
void dimensionNameChanged(int dimension);
};
struct KnobChange
{
KnobIPtr knob;
ValueChangedReasonEnum reason, originalReason;
bool originatedFromMainThread;
bool refreshGui;
double time;
ViewSpec view;
std::set<int> dimensionChanged;
bool valueChangeBlocked;
};
typedef std::list<KnobChange> KnobChanges;
class KnobI
: public OverlaySupport
, public boost::enable_shared_from_this<KnobI>
{
friend class KnobHolder;
public:
// TODO: enable_shared_from_this
// constructors should be privatized in any class that derives from boost::enable_shared_from_this<>
KnobI()
{
}
public:
// dtor
virtual ~KnobI()
{
}
protected:
/**
* @brief Deletes this knob permanently
**/
virtual void deleteKnob() = 0;
public:
struct ListenerDim
{
bool isExpr;
bool isListening;
int targetDim;
ListenerDim()
: isExpr(false), isListening(false), targetDim(-1) {}
};
typedef std::map<KnobIWPtr, std::vector<ListenerDim> > ListenerDimsMap;
/**
* @brief Do not call this. It is called right away after the constructor by the factory
* to initialize curves and values. This is separated from the constructor as we need RTTI
* for Curve.
**/
virtual void populate() = 0;
virtual void setKnobGuiPointer(const boost::shared_ptr<KnobGuiI>& ptr) = 0;
virtual boost::shared_ptr<KnobGuiI> getKnobGuiPointer() const = 0;
virtual bool getAllDimensionVisible() const = 0;
static bool areTypesCompatibleForSlave(KnobI* lhs, KnobI* rhs);
/**
* @brief Returns the knob was created by a plugin or added automatically by Natron (e.g like mask knobs)
**/
virtual bool isDeclaredByPlugin() const = 0;
/**
* @brief Must flag that the knob was dynamically created to warn the gui it should handle it correctly
**/
virtual void setDynamicallyCreated() = 0;
virtual bool isDynamicallyCreated() const = 0;
/**
* @brief A user knob is a knob created by the user by the gui
**/
virtual void setAsUserKnob(bool b) = 0;
virtual bool isUserKnob() const = 0;
/**
* @brief Must return the type name of the knob. This name will be used by the KnobFactory
* to create an instance of this knob.
**/
virtual const std::string & typeName() const = 0;
/**
* @brief Must return true if this knob can animate (i.e: if we can set different values depending on the time)
* Some parameters cannot animate, for example a file selector.
**/
virtual bool canAnimate() const = 0;
/**
* @brief Returns true if the knob has had modifications
**/
virtual bool hasModifications() const = 0;
virtual bool hasModifications(int dimension) const = 0;
virtual bool hasModificationsForSerialization() const = 0;
virtual void computeHasModifications() = 0;
virtual void checkAnimationLevel(ViewSpec view, int dimension) = 0;
/**
* @brief If the parameter is multidimensional, this is the label that will be displayed for a dimension.
**/
virtual std::string getDimensionName(int dimension) const = 0;
virtual void setDimensionName(int dim, const std::string & name) = 0;
/**
* @brief When set to true the evaluate (render) action will not be called
* when issuing value changes. Internally it maintains a counter, when it reaches 0 the evaluation is unblocked.
**/
virtual void beginChanges() = 0;
/**
* @brief To be called to reactivate evaluation. Internally it maintains a counter, when it reaches 0 the evaluation is unblocked.
**/
virtual void endChanges() = 0;
virtual void blockValueChanges() = 0;
virtual void unblockValueChanges() = 0;
virtual bool isValueChangesBlocked() const = 0;
virtual void blockListenersNotification() = 0;
virtual void unblockListenersNotification() = 0;
virtual bool isListenersNotificationBlocked() const = 0;
/**
* @brief Called by setValue to refresh the GUI, call the instanceChanged action on the plugin and
* evaluate the new value (cause a render).
* @returns true if the knobChanged handler was called once for this knob
**/
virtual bool evaluateValueChange(int dimension, double time, ViewSpec view, ValueChangedReasonEnum reason) = 0;
/**
* @brief Copies all the values, animations and extra data the other knob might have
* to this knob. This function calls cloneExtraData.
* The evaluateValueChange function will not be called as a result of the clone.
* However a valueChanged signal will be emitted by the KnobSignalSlotHandler if there's any.
*
* @param dimension If -1 all dimensions will be cloned, otherwise you can clone only a specific dimension
*
* WARNING: This knob and 'other' MUST have the same dimension as well as the same type.
**/
virtual void clone(KnobI* other, int dimension = -1, int otherDimension = -1) = 0;
virtual void clone(const KnobIPtr & other,
int dimension = -1,
int otherDimension = -1)
{
clone( other.get(), dimension, otherDimension );
}
/**
* @brief Performs the same as clone but also refresh any gui it has.
**/
virtual void cloneAndUpdateGui(KnobI* other, int dimension = -1, int otherDimension = -1) = 0;
virtual void cloneDefaultValues(KnobI* other) = 0;
/**
* @brief Same as clone but returns whether the knob state changed as the result of the clone operation
**/
virtual bool cloneAndCheckIfChanged(KnobI* other, int dimension = -1, int otherDimension = -1) = 0;
/**
* @brief Same as clone(const KnobIPtr& ) except that the given offset is applied
* on the keyframes time and only the keyframes within the given range are copied.
* If the range is NULL everything will be copied.
*
* Note that unlike the other version of clone, this version is more relaxed and accept parameters
* with different dimensions, but only the intersection of the dimension of the 2 parameters will be copied.
* The restriction on types still apply.
**/
virtual void clone(KnobI* other, double offset, const RangeD* range, int dimension = -1, int otherDimension = -1) = 0;
virtual void clone(const KnobIPtr & other,
double offset,
const RangeD* range,
int dimension = -1,
int otherDimension = -1)
{
clone(other.get(), offset, range, dimension, otherDimension);
}
/**
* @brief Must return the curve used by the GUI of the parameter
**/
virtual boost::shared_ptr<Curve> getGuiCurve(ViewSpec view, int dimension, bool byPassMaster = false) const = 0;
virtual double random(double min, double max, double time, unsigned int seed = 0) const = 0;
virtual double random(double min = 0., double max = 1.) const = 0;
virtual int randomInt(int min, int max, double time, unsigned int seed = 0) const = 0;
virtual int randomInt(int min, int max) const = 0;
/**
* @brief Evaluates the curve at the given dimension and at the given time. This returns the value of the curve directly.
* If the knob is holding a string, it will return the index.
**/
virtual double getRawCurveValueAt(double time, ViewSpec view, int dimension) = 0;
/**
* @brief Same as getRawCurveValueAt, but first check if an expression is present. The expression should return a PoD.
**/
virtual double getValueAtWithExpression(double time, ViewSpec view, int dimension) = 0;
protected:
/**
* @brief Removes all the keyframes in the given dimension.
**/
virtual void removeAnimationWithReason(ViewSpec view, int dimension, ValueChangedReasonEnum reason) = 0;
public:
/**
* @brief Removes the keyframe at the given time and dimension if it matches any.
**/
virtual void deleteValueAtTime(CurveChangeReason curveChangeReason, double time, ViewSpec view, int dimension, bool copyCurveValueAtTimeToInternalValue) = 0;
virtual void deleteValuesAtTime(CurveChangeReason curveChangeReason, const std::list<double>& times, ViewSpec view, int dimension, bool copyCurveValueAtTimeToInternalValue) = 0;
/**
* @brief Moves a keyframe by a given delta and emits the signal keyframeMoved
**/
virtual bool moveValueAtTime(CurveChangeReason reason, double time, ViewSpec view, int dimension, double dt, double dv, KeyFrame* newKey) = 0;
virtual bool moveValuesAtTime(CurveChangeReason reason, ViewSpec view, int dimension, double dt, double dv, std::vector<KeyFrame>* keyframes) = 0;
/**
* @brief Transforms a keyframe by a given matrix. The matrix must not contain any skew or rotation.
**/
virtual bool transformValueAtTime(CurveChangeReason curveChangeReason, double time, ViewSpec view, int dimension, const Transform::Matrix3x3& matrix, KeyFrame* newKey) = 0;
virtual bool transformValuesAtTime(CurveChangeReason curveChangeReason, ViewSpec view, int dimension, const Transform::Matrix3x3& matrix, std::vector<KeyFrame>* keyframes) = 0;
/**
* @brief Copies all the animation of *curve* into the animation curve at the given dimension.
**/
virtual void cloneCurve(ViewSpec view, int dimension, const Curve& curve) = 0;
/**
* @brief Changes the interpolation type for the given keyframe
**/
virtual bool setInterpolationAtTime(CurveChangeReason reason, ViewSpec view, int dimension, double time, KeyframeTypeEnum interpolation, KeyFrame* newKey) = 0;
/**
* @brief Set the left/right derivatives of the control point at the given time.
**/
virtual bool moveDerivativesAtTime(CurveChangeReason reason, ViewSpec view, int dimension, double time, double left, double right) = 0;
virtual bool moveDerivativeAtTime(CurveChangeReason reason, ViewSpec view, int dimension, double time, double derivative, bool isLeft) = 0;
/**
* @brief Removes animation before the given time and dimension. If the reason is different than eValueChangedReasonUserEdited
* a signal will be emitted
**/
virtual void deleteAnimationBeforeTime(double time, ViewSpec view, int dimension, ValueChangedReasonEnum reason) = 0;
/**
* @brief Removes animation before the given time and dimension. If the reason is different than eValueChangedReasonUserEdited
* a signal will be emitted
**/
virtual void deleteAnimationAfterTime(double time, ViewSpec view, int dimension, ValueChangedReasonEnum reason) = 0;
/**
* @brief Calls removeAnimation with a reason of eValueChangedReasonNatronInternalEdited.
**/
void removeAnimation(ViewSpec view, int dimension);
/**
* @brief Calls deleteValueAtTime with a reason of eValueChangedReasonUserEdited
**/
virtual void onKeyFrameRemoved(double time, ViewSpec view, int dimension, bool copyCurveValueAtTimeToInternalValue) = 0;
/**
* @brief Calls removeAnimation with a reason of eValueChangedReasonUserEdited
**/
void onAnimationRemoved(ViewSpec view, int dimension);
/**
* @brief Set an expression on the knob. If this expression is invalid, this function throws an excecption with the error from the
* Python interpreter.
* @param hasRetVariable If true the expression is expected to be multi-line and have its return value set to the variable "ret", otherwise
* the expression is expected to be single-line.
* @param force If set to true, this function will not check if the expression is valid nor will it attempt to compile/evaluate it, it will
* just store it. This flag is used for serialisation, you should always pass false
**/
protected:
virtual void setExpressionInternal(int dimension, const std::string& expression, bool hasRetVariable, bool clearResults, bool failIfInvalid) = 0;
public:
void restoreExpression(int dimension,
const std::string& expression,
bool hasRetVariable)
{
setExpressionInternal(dimension, expression, hasRetVariable, false, false);
}
void setExpression(int dimension,
const std::string& expression,
bool hasRetVariable,
bool failIfInvalid)
{
setExpressionInternal(dimension, expression, hasRetVariable, true, failIfInvalid);
}
/**
* @brief Tries to re-apply invalid expressions, returns true if they are all valid
**/
virtual bool checkInvalidExpressions() = 0;
virtual bool isExpressionValid(int dimension, std::string* error) const = 0;
virtual void setExpressionInvalid(int dimension, bool valid, const std::string& error) = 0;
/**
* @brief For each dimension, try to find in the expression, if set, the node name "oldName" and replace
* it by "newName"
**/
virtual void replaceNodeNameInExpression(int dimension,
const std::string& oldName,
const std::string& newName) = 0;
virtual void clearExpressionsResults(int dimension) = 0;
virtual void clearExpression(int dimension, bool clearResults) = 0;
virtual std::string getExpression(int dimension) const = 0;
/**
* @brief Checks that the given expr for the given dimension will produce a correct behaviour.
* On success this function returns correctly, otherwise an exception is thrown with the error.
* This function also declares some extra python variables via the declareCurrentKnobVariable_Python function.
* The new expression is returned.
* @param resultAsString[out] The result of the execution of the expression will be written to the string.
* @returns A new string containing the modified expression with the 'ret' variable declared if it wasn't already declared
* by the user.
**/
virtual std::string validateExpression(const std::string& expression, int dimension, bool hasRetVariable,
std::string* resultAsString) = 0;
protected:
virtual void refreshListenersAfterValueChange(ViewSpec view, ValueChangedReasonEnum reason, int dimension) = 0;
public:
/**
* @brief Returns whether the expr at the given dimension uses the ret variable to assign to the return value or not
**/
virtual bool isExpressionUsingRetVariable(int dimension = 0) const = 0;
/**
* @brief Returns in dependencies a list of all the knobs used in the expression at the given dimension
* @returns True on success, false if no expression is set.
**/
virtual bool getExpressionDependencies(int dimension, std::list<std::pair<KnobIWPtr, int> >& dependencies) const = 0;
/**
* @brief Calls setValueAtTime with a reason of eValueChangedReasonUserEdited.
**/
virtual bool onKeyFrameSet(double time, ViewSpec view, int dimension) = 0;
virtual bool onKeyFrameSet(double time, ViewSpec view, const KeyFrame& key, int dimension) = 0;
virtual bool setKeyFrame(const KeyFrame& key, ViewSpec view, int dimension, ValueChangedReasonEnum reason) = 0;
/**
* @brief Called when the current time of the timeline changes.
* It must get the value at the given time and notify the gui it must
* update the value displayed.
**/
virtual void onTimeChanged(bool isPlayback, double time) = 0;
/**
* @brief Compute the derivative at time as a double
**/
virtual double getDerivativeAtTime(double time, ViewSpec view, int dimension = 0) = 0;
/**
* @brief Compute the integral of dimension from time1 to time2 as a double
**/
virtual double getIntegrateFromTimeToTime(double time1, double time2, ViewSpec view, int dimension = 0) = 0;
/**
* @brief Places in time the keyframe time at the given index.
* If it exists the function returns true, false otherwise.
**/
virtual bool getKeyFrameTime(ViewSpec view, int index, int dimension, double* time) const = 0;
/**
* @brief Convenience function, does the same as getKeyFrameWithIndex but returns the last
* keyframe.
**/
virtual bool getLastKeyFrameTime(ViewSpec view, int dimension, double* time) const = 0;
/**
* @brief Convenience function, does the same as getKeyFrameWithIndex but returns the first
* keyframe.
**/
virtual bool getFirstKeyFrameTime(ViewSpec view, int dimension, double* time) const = 0;
/**
* @brief Returns the count of keyframes in the given dimension.
**/
virtual int getKeyFramesCount(ViewSpec view, int dimension) const = 0;
/**
* @brief Returns the nearest keyframe time if it was found.
* Returns true if it succeeded, false otherwise.
**/
virtual bool getNearestKeyFrameTime(ViewSpec view, int dimension, double time, double* nearestTime) const = 0;
/**
* @brief Returns the keyframe index if there's any keyframe in the curve
* at the given dimension and the given time. -1 otherwise.
**/
virtual int getKeyFrameIndex(ViewSpec view, int dimension, double time) const = 0;
/**
* @brief Returns a pointer to the curve in the given dimension.
* It cannot be a null pointer.
**/
virtual boost::shared_ptr<Curve> getCurve(ViewSpec view, int dimension, bool byPassMaster = false) const = 0;
/**
* @brief Returns true if the dimension is animated with keyframes.
**/
virtual bool isAnimated( int dimension, ViewSpec view = ViewSpec::current() ) const = 0;
/**
* @brief Returns true if at least 1 dimension is animated. MT-Safe
**/
virtual bool hasAnimation() const = 0;
/**
* @brief Returns a const ref to the curves held by this knob. This is MT-safe as they're
* never deleted (except on program exit).
**/
virtual const std::vector<boost::shared_ptr<Curve> > & getCurves() const = 0;
/**
* @brief Activates or deactivates the animation for this parameter. On the GUI side that means
* the user can never interact with the animation curves nor can he/she set any keyframe.
**/
virtual void setAnimationEnabled(bool val) = 0;
/**
* @brief Returns true if the animation is enabled for this knob. A return value of
* true doesn't necessarily means that the knob is animated at all.
**/
virtual bool isAnimationEnabled() const = 0;
/**
* @brief Get the knob label, that is the label next to the knob on the user interface.
* This function is MT-safe as it the label can only be changed by the main thread.
**/
virtual std::string getLabel() const = 0;
virtual void setLabel(const std::string& label) = 0;
void setLabel(const QString & label)
{
setLabel( label.toStdString() );
}
/**
* @brief Set an icon instead of the text label for this knob
* @param modeOff If true, this icon will be used when the parameter is an unchecked state (only relevant for
* buttons/booleans parameters), otherwise the icon will be used when the parameter is in a checked state
**/
virtual void setIconLabel(const std::string& iconFilePath, bool checked = false) = 0;
virtual const std::string& getIconLabel(bool checked = false) const = 0;
/**
* @brief Returns a pointer to the holder owning the knob.
**/
virtual KnobHolder* getHolder() const = 0;
virtual void setHolder(KnobHolder* holder) = 0;
/**
* @brief Get the knob dimension. MT-safe as it is static and never changes.
**/
virtual int getDimension() const = 0;
/**
* @brief Any GUI representing this parameter should represent the next parameter on the same line as this parameter.
**/
virtual void setAddNewLine(bool newLine) = 0;
virtual void setAddSeparator(bool addSep) = 0;
/**
* @brief Any GUI representing this parameter should represent the next parameter on the same line as this parameter.
**/
virtual bool isNewLineActivated() const = 0;
virtual bool isSeparatorActivated() const = 0;
/**
* @brief GUI-related
**/
virtual void setSpacingBetweenItems(int spacing) = 0;
virtual int getSpacingBetweenitems() const = 0;
/**
* @brief Set the label of the knob on the viewer
**/
virtual std::string getInViewerContextLabel() const = 0;
virtual void setInViewerContextLabel(const QString& label) = 0;
/**
* @brief Determines whether this knob can be assigned a shortcut or not via the shortcut editor.
* If true, Natron will look for a shortcut in the shortcuts database with an ID matching the name of this
* parameter. To set default values for shortcuts, implement EffectInstance::getPluginShortcuts(...)
**/
virtual void setInViewerContextCanHaveShortcut(bool haveShortcut) = 0;
virtual bool getInViewerContextHasShortcut() const = 0;
/**
* @brief Returns whether this type of knob can be instantiated in the viewer UI
**/
virtual bool supportsInViewerContext() const
{
return false;
}
/**
* @brief Set how much space (in pixels) to leave between the current parameter and the next parameter in horizontal layouts.
**/
virtual void setInViewerContextItemSpacing(int spacing) = 0;
virtual int getInViewerContextItemSpacing() const = 0;
/**
* @brief Set whether the knob should have a vertical separator after or not in the viewer
**/
virtual void setInViewerContextAddSeparator(bool addSeparator) = 0;
virtual bool getInViewerContextAddSeparator() const = 0;
/**
* @brief Set whether the viewer UI should create a new line after this parameter or not
**/
virtual void setInViewerContextNewLineActivated(bool activated) = 0;
virtual bool getInViewerContextNewLineActivated() const = 0;
/**
* @brief Set whether the knob should have its viewer GUI secret or not
**/
virtual void setInViewerContextSecret(bool secret) = 0;
virtual bool getInViewerContextSecret() const = 0;
/**
* @brief Enables/disables user interaction with the given dimension.
**/
virtual void setEnabled(int dimension, bool b) = 0;
virtual void setDefaultEnabled(int dimension, bool b) = 0;
/**
* @brief Is the dimension enabled ?
**/
virtual bool isEnabled(int dimension) const = 0;
virtual bool isDefaultEnabled(int dimension) const = 0;
/**
* @brief Convenience function, same as calling setEnabled(int,bool) for all dimensions.
**/
virtual void setAllDimensionsEnabled(bool b) = 0;
virtual void setDefaultAllDimensionsEnabled(bool b) = 0;
/**
* @brief Set the knob visible/invisible on the GUI representing it.
**/
virtual void setSecret(bool b) = 0;
virtual void setSecretByDefault(bool b) = 0;
/**
* @brief Is the knob visible to the user ?
**/
virtual bool getIsSecret() const = 0;
virtual bool getDefaultIsSecret() const = 0;
/**
* @brief Returns true if a knob is secret because it is either itself secret or one of its parent, recursively
**/
virtual bool getIsSecretRecursive() const = 0;
/**
* @biref This is called to notify the gui that the knob shouldn't be editable.
* Basically this is used when rendering with a Writer or for Trackers while tracking is active.
**/
virtual void setIsFrozen(bool frozen) = 0;
virtual bool evaluateValueChangeOnTimeChange() const { return false; }
/**
* @brief When dirty, the knob is actually representing several elements that do not hold the same value.
* For example for the roto node, a knob actually represent the value of the opacity of the selected curve.
* If they're multiple curves selected,then the value of the knob is dirty
* since we have no means to know the specifics values for each curve.
* This is purely a GUI stuff and should only be called when the GUI is created. This is here just for means to
* notify the GUI.
**/
virtual void setDirty(bool d) = 0;
/**
* @brief Call this to change the knob name. The name is not the text label displayed on
* the GUI but what Natron uses internally to identify knobs from each other. By default the
* name is the same as the getLabel(i.e: the text label).
*/
virtual void setName(const std::string & name, bool throwExceptions = false) = 0;
/**
* @brief Returns the knob name. By default the
* name is the same as the getLabel(i.e: the text label).
*/
virtual const std::string & getName() const = 0;
/**
* @brief Returns the name passed to setName(). This might be different than getName() if
* the name passed to setName() was not python compliant.
**/
virtual const std::string & getOriginalName() const = 0;
/**
* @brief Set the given knob as the parent of this knob.
* @param knob It must be a tab or group knob.
*/
virtual void setParentKnob(KnobIPtr knob) = 0;
virtual void resetParent() = 0;
/**
* @brief Returns a pointer to the parent knob if any.
*/
virtual KnobIPtr getParentKnob() const = 0;
/**
* @brief Returns the hierarchy level of this knob.
* By default it is 0, however a knob with a parent will
* have a hierarchy level of 1, etc...
**/
virtual int determineHierarchySize() const = 0;
/**
* @brief If a knob is evaluating on change, that means
* every time a value changes, the knob will call the
* evaluate function on the KnobHolder holding it.
* By default this is set to true.
**/
virtual void setEvaluateOnChange(bool b) = 0;
/**
* @brief Does the knob evaluates on change ?
**/