void DSPasteKeysCommand::setKeyValueFromKnob(const KnobIPtr& knob, double keyTime, KeyFrame* key) { KnobDoubleBasePtr isDouble = toKnobDoubleBase(knob); KnobBoolBasePtr isBool = toKnobBoolBase(knob); KnobIntBasePtr isInt = toKnobIntBase(knob); KnobStringBasePtr isString = toKnobStringBase(knob); if (isDouble) { key->setValue( isDouble->getValueAtTime(keyTime) ); } else if (isBool) { key->setValue( isBool->getValueAtTime(keyTime) ); } else if (isInt) { key->setValue( isInt->getValueAtTime(keyTime) ); } else if (isString) { std::string v = isString->getValueAtTime(keyTime); double keyFrameValue = 0.; AnimatingKnobStringHelperPtr isStringAnimatedKnob = boost::dynamic_pointer_cast<AnimatingKnobStringHelper>(isString); assert(isStringAnimatedKnob); if (isStringAnimatedKnob) { isStringAnimatedKnob->stringToKeyFrameValue(keyTime, ViewIdx(0), v, &keyFrameValue); } key->setValue(keyFrameValue); } }
void NodeAnimPrivate::computeTimeOffsetRange() { NodeGuiPtr nodeUI = nodeGui.lock(); NodePtr node = nodeUI->getNode(); if (!node) { return; } // Retrieve nearest reader useful values { AnimationModulePtr isAnimModel = toAnimationModule(model.lock()); NodeAnimPtr nearestReader = isAnimModel->getNearestReaderInternal(node); if (nearestReader) { // Retrieve the time offset values KnobIntBasePtr timeOffsetKnob = toKnobIntBase(node->getKnobByName(kReaderParamNameTimeOffset)); assert(timeOffsetKnob); int timeOffsetValue = timeOffsetKnob->getValue(); frameRange = nearestReader->getFrameRange(); frameRange.min += timeOffsetValue; frameRange.max += timeOffsetValue; } } } // computeTimeOffsetRange
void moveFrameRange(const NodePtr& node, double dt) { KnobIntBasePtr frameRangeKnob = toKnobIntBase( node->getKnobByName(kFrameRangeParamNameFrameRange) ); assert(frameRangeKnob); frameRangeKnob->setValues(frameRangeKnob->getValue() + dt, frameRangeKnob->getValue(1) + dt, ViewSpec::all(), eValueChangedReasonNatronGuiEdited); }
void moveTimeOffset(const NodePtr& node, double dt) { KnobIntBasePtr timeOffsetKnob = toKnobIntBase( node->getKnobByName(kTimeOffsetParamNameTimeOffset) ); assert(timeOffsetKnob); KnobHelper::ValueChangedReturnCodeEnum s = timeOffsetKnob->setValue(timeOffsetKnob->getValue() + dt, ViewSpec::all(), 0, eValueChangedReasonNatronGuiEdited, 0); Q_UNUSED(s); }
NATRON_NAMESPACE_ANONYMOUS_ENTER /** * @brief Move the node 'reader' on project timeline, by offsetting its * starting time by 'dt'. */ void moveReader(const NodePtr &reader, double dt) { KnobIntBasePtr startingTimeKnob = toKnobIntBase( reader->getKnobByName(kReaderParamNameStartingTime) ); assert(startingTimeKnob); KnobHelper::ValueChangedReturnCodeEnum s = startingTimeKnob->setValue(startingTimeKnob->getValue() + dt, ViewSpec::all(), 0, eValueChangedReasonNatronGuiEdited, 0); Q_UNUSED(s); }
void NodeAnimPrivate::computeFRRange() { NodeGuiPtr nodeUI = nodeGui.lock(); NodePtr node = nodeUI->getNode(); if (!node) { return; } KnobIntBasePtr frameRangeKnob = toKnobIntBase(node->getKnobByName(kFrameRangeParamNameFrameRange)); assert(frameRangeKnob); frameRange.min = frameRangeKnob->getValue(DimIdx(0)); frameRange.max = frameRangeKnob->getValue(DimIdx(1)); }
static ValueChangedReturnCodeEnum setOldValueForDimView(const KnobIntBasePtr& isInt, const KnobBoolBasePtr& isBool, const KnobDoubleBasePtr& isDouble, const KnobStringBasePtr& isString, ValueChangedReasonEnum reason, bool setKeyFrame, double time, bool hasChanged, ValueChangedReturnCodeEnum retCode, DimIdx dim, ViewIdx view_i, const PerDimViewVariantMap& oldValues) { ValueChangedReturnCodeEnum ret = eValueChangedReturnCodeNothingChanged; DimensionViewPair key = {dim, view_i}; PerDimViewVariantMap::const_iterator foundDimView = oldValues.find(key); if (foundDimView == oldValues.end()) { return ret; } const Variant& v = foundDimView->second; if (setKeyFrame && retCode != eValueChangedReturnCodeKeyframeAdded) { if (isInt) { ret = isInt->setValueAtTime(time, v.toInt(), view_i, dim, reason, 0, hasChanged); } else if (isBool) { ret = isBool->setValueAtTime(time, v.toBool(), view_i, dim, reason, 0, hasChanged); } else if (isDouble) { ret = isDouble->setValueAtTime(time, v.toDouble(), view_i, dim, reason, 0, hasChanged); } else if (isString) { ret = isString->setValueAtTime(time, v.toString().toStdString(), view_i, dim, reason, 0, hasChanged); } } else { if (isInt) { ret = isInt->setValue(v.toInt(), view_i, dim, reason, 0, hasChanged); } else if (isBool) { ret = isBool->setValue(v.toBool(), view_i, dim, reason, 0, hasChanged); } else if (isDouble) { ret = isDouble->setValue(v.toDouble(), view_i, dim, reason, 0, hasChanged); } else if (isString) { ret = isString->setValue(v.toString().toStdString(), view_i, dim, reason, 0, hasChanged); } } return ret; }
void MultipleKnobEditsUndoCommand::redo() { // The first time, everything is handled within setValue/setValueAtTime already if (!firstRedoCalled) { firstRedoCalled = true; return; } assert( !knobs.empty() ); KnobHolderPtr holder = knobs.begin()->first.lock()->getHolder(); // Make sure we get a single evaluation if (holder) { holder->beginChanges(); } for (ParamsMap::iterator it = knobs.begin(); it != knobs.end(); ++it) { KnobIPtr knob = it->first.lock(); if (!knob) { continue; } if (it->second.empty()) { continue; } // All knobs must belong to the same node! assert(knob->getHolder() == holder); KnobIntBasePtr isInt = toKnobIntBase(knob); KnobBoolBasePtr isBool = toKnobBoolBase(knob); KnobDoubleBasePtr isDouble = toKnobDoubleBase(knob); KnobStringBasePtr isString = toKnobStringBase(knob); bool hasChanged = false; std::list<ValueToSet>::iterator next = it->second.begin(); ++next; if (it->second.size() > 1) { // block knobChanged handler for this knob until the last change so we don't clutter the main-thread with useless action calls knob->blockValueChanges(); } for (std::list<ValueToSet>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) { if (next == it->second.end() && it->second.size() > 1) { // Re-enable knobChanged for the last change on this knob knob->unblockValueChanges(); } if (it2->setKeyFrame) { if (isInt) { it2->setValueRetCode = isInt->setValueAtTime(it2->time, it2->newValue.toInt(), it2->view, it2->dimension, it2->reason, 0, hasChanged); } else if (isBool) { it2->setValueRetCode = isBool->setValueAtTime(it2->time, it2->newValue.toBool(), it2->view, it2->dimension, it2->reason, 0, hasChanged); } else if (isDouble) { it2->setValueRetCode = isDouble->setValueAtTime(it2->time, it2->newValue.toDouble(), it2->view, it2->dimension, it2->reason, 0, hasChanged); } else if (isString) { it2->setValueRetCode = isString->setValueAtTime(it2->time, it2->newValue.toString().toStdString(), it2->view, it2->dimension, it2->reason, 0, hasChanged); } else { assert(false); } } else { if (isInt) { it2->setValueRetCode = isInt->setValue(it2->newValue.toInt(), it2->view, it2->dimension, it2->reason, 0, hasChanged); } else if (isBool) { it2->setValueRetCode = isBool->setValue(it2->newValue.toBool(), it2->view, it2->dimension, it2->reason, 0, hasChanged); } else if (isDouble) { it2->setValueRetCode = isDouble->setValue(it2->newValue.toDouble(), it2->view, it2->dimension, it2->reason, 0, hasChanged); } else if (isString) { it2->setValueRetCode = isString->setValue(it2->newValue.toString().toStdString(), it2->view, it2->dimension, it2->reason, 0, hasChanged); } else { assert(false); } } hasChanged |= it2->setValueRetCode != eValueChangedReturnCodeNothingChanged; if (next != it->second.end()) { ++next; } } } if (holder) { holder->endChanges(); } } // redo