From 515d459d363d91aceb5c5129eb81f12ccbdeec60 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 11 Apr 2021 19:38:29 +1000 Subject: [PATCH] nodeparamview: make keyframes on every key track by default Fixes #1437 --- app/node/inputdragger.cpp | 23 +++++++++++++---- app/node/inputdragger.h | 5 ++-- .../nodeparamviewwidgetbridge.cpp | 25 +++++++++++++------ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/app/node/inputdragger.cpp b/app/node/inputdragger.cpp index 0d835fc77..ebf00874d 100644 --- a/app/node/inputdragger.cpp +++ b/app/node/inputdragger.cpp @@ -36,7 +36,7 @@ bool NodeInputDragger::IsStarted() const return input_.IsValid(); } -void NodeInputDragger::Start(const NodeKeyframeTrackReference &input, const rational &time) +void NodeInputDragger::Start(const NodeKeyframeTrackReference &input, const rational &time, bool create_key_on_all_tracks) { Q_ASSERT(!IsStarted()); @@ -52,9 +52,8 @@ void NodeInputDragger::Start(const NodeKeyframeTrackReference &input, const rati // Determine whether we are creating a keyframe or not if (input_.input().IsKeyframing()) { dragging_key_ = node->GetKeyframeAtTimeOnTrack(input_, time); - drag_created_key_ = !dragging_key_; - if (drag_created_key_) { + if (!dragging_key_) { dragging_key_ = new NodeKeyframe(time, start_value_, node->GetBestKeyframeTypeForTimeOnTrack(input_, time), @@ -62,6 +61,19 @@ void NodeInputDragger::Start(const NodeKeyframeTrackReference &input, const rati input_.input().element(), input_.input().input(), node); + created_keys_.append(dragging_key_); + + if (create_key_on_all_tracks) { + int nb_tracks = NodeValue::get_number_of_keyframe_tracks(input.input().node()->GetInputDataType(input.input().input())); + for (int i=0; iGetSplitValueAtTimeOnTrack(this_ref, time), + node->GetBestKeyframeTypeForTimeOnTrack(this_ref, time), + i, input.input().element(), input.input().input(), node)); + } + } + } } } } @@ -112,9 +124,9 @@ void NodeInputDragger::End() MultiUndoCommand* command = new MultiUndoCommand(); if (input_.input().node()->IsInputKeyframing(input_.input())) { - if (drag_created_key_) { + for (int i=0; iadd_child(new NodeParamInsertKeyframeCommand(input_.input().node(), dragging_key_)); + command->add_child(new NodeParamInsertKeyframeCommand(input_.input().node(), created_keys_.at(i))); } // We just set a keyframe's value @@ -129,6 +141,7 @@ void NodeInputDragger::End() Core::instance()->undo_stack()->push(command); input_.Reset(); + created_keys_.clear(); } } diff --git a/app/node/inputdragger.h b/app/node/inputdragger.h index 8743e7aff..bf74068da 100644 --- a/app/node/inputdragger.h +++ b/app/node/inputdragger.h @@ -34,7 +34,7 @@ public: bool IsStarted() const; - void Start(const NodeKeyframeTrackReference& input, const rational& time); + void Start(const NodeKeyframeTrackReference& input, const rational& time, bool create_key_on_all_tracks = true); void Drag(QVariant value); @@ -50,8 +50,7 @@ private: QVariant end_value_; NodeKeyframe* dragging_key_; - - bool drag_created_key_; + QVector created_keys_; }; diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp index a6b1240b7..17411ace1 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp @@ -207,14 +207,25 @@ void NodeParamViewWidgetBridge::SetInputValueInternal(const QVariant &value, int command->add_child(new NodeParamSetKeyframeValueCommand(existing_key, value)); } else { // No existing key, create a new one - NodeKeyframe* new_key = new NodeKeyframe(node_time, - value, - input_.node()->GetBestKeyframeTypeForTimeOnTrack(NodeKeyframeTrackReference(input_, track), node_time), - track, - input_.element(), - input_.input()); + int nb_tracks = NodeValue::get_number_of_keyframe_tracks(input_.node()->GetInputDataType(input_.input())); + for (int i=0; iadd_child(new NodeParamInsertKeyframeCommand(input_.node(), new_key)); + if (i == track) { + track_value = value; + } else { + track_value = input_.node()->GetValueAtTime(input_.input(), node_time, input_.element()); + } + + NodeKeyframe* new_key = new NodeKeyframe(node_time, + track_value, + input_.node()->GetBestKeyframeTypeForTimeOnTrack(NodeKeyframeTrackReference(input_, i), node_time), + i, + input_.element(), + input_.input()); + + command->add_child(new NodeParamInsertKeyframeCommand(input_.node(), new_key)); + } } } else { command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(input_, track), value));