formalized valuehint as a class

This commit is contained in:
itsmattkc
2021-09-21 20:13:14 -07:00
parent 677277c16d
commit dc7f7a6dda
8 changed files with 62 additions and 31 deletions
+2 -2
View File
@@ -33,8 +33,8 @@ void XMLConnectNodes(const XMLNodeData &xml_node_data, MultiUndoCommand *command
Node *out = xml_node_data.node_ptrs.value(con.output_node);
if (out) {
Node::ValueHint hint;
hint.tag = con.output_param;
// Use output param as hint tag since we grandfathered those in
Node::ValueHint hint(con.output_param);
if (command) {
command->add_child(new NodeEdgeAddCommand(out, con.input));
+1 -1
View File
@@ -51,7 +51,7 @@ ClipBlock::ClipBlock() :
IgnoreHashingFrom(kReverseInput);
PrependInput(kBufferIn, NodeValue::kNone, InputFlags(kInputFlagNotKeyframable));
SetValueHintForInput(kBufferIn, {NodeValue::kBuffer, -1, QString()});
SetValueHintForInput(kBufferIn, ValueHint(NodeValue::kBuffer));
}
Node *ClipBlock::copy() const
+11 -16
View File
@@ -1015,12 +1015,7 @@ int Node::InputArraySize(const QString &id) const
void Node::Hash(const Node *node, const ValueHint &hint, QCryptographicHash &hash, const NodeGlobals &globals, const VideoParams &video_params)
{
if (!hint.type.isEmpty()) {
hash.addData(reinterpret_cast<const char*>(hint.type.constData()), sizeof(NodeValue::Type) * hint.type.size());
}
hash.addData(reinterpret_cast<const char*>(&hint.index), sizeof(hint.index));
hash.addData(hint.tag.toUtf8());
hint.Hash(hash);
node->Hash(hash, globals, video_params);
}
@@ -2468,11 +2463,11 @@ void NodeRemovePositionFromAllContextsCommand::undo()
void Node::ValueHint::Hash(QCryptographicHash &hash) const
{
// Add value hint
foreach (NodeValue::Type t, type) {
hash.addData(reinterpret_cast<const char*>(&t), sizeof(t));
if (!types().isEmpty()) {
hash.addData(reinterpret_cast<const char*>(types().constData()), sizeof(NodeValue::Type) * types().size());
}
hash.addData(reinterpret_cast<const char *>(&index), sizeof(index));
hash.addData(tag.toUtf8());
hash.addData(reinterpret_cast<const char*>(&index()), sizeof(index()));
hash.addData(tag().toUtf8());
}
void Node::ValueHint::Load(QXmlStreamReader *reader)
@@ -2481,15 +2476,15 @@ void Node::ValueHint::Load(QXmlStreamReader *reader)
if (reader->name() == QStringLiteral("types")) {
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("type")) {
type.append(static_cast<NodeValue::Type>(reader->readElementText().toInt()));
type_.append(static_cast<NodeValue::Type>(reader->readElementText().toInt()));
} else {
reader->skipCurrentElement();
}
}
} else if (reader->name() == QStringLiteral("index")) {
index = reader->readElementText().toInt();
index_ = reader->readElementText().toInt();
} else if (reader->name() == QStringLiteral("tag")) {
tag = reader->readElementText();
tag_ = reader->readElementText();
} else {
reader->skipCurrentElement();
}
@@ -2500,15 +2495,15 @@ void Node::ValueHint::Save(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("types"));
for (auto it=type.cbegin(); it!=type.cend(); it++) {
for (auto it=type_.cbegin(); it!=type_.cend(); it++) {
writer->writeTextElement(QStringLiteral("type"), QString::number(*it));
}
writer->writeEndElement(); // types
writer->writeTextElement(QStringLiteral("index"), QString::number(index));
writer->writeTextElement(QStringLiteral("index"), QString::number(index_));
writer->writeTextElement(QStringLiteral("tag"), tag);
writer->writeTextElement(QStringLiteral("tag"), tag_);
}
}
+40 -4
View File
@@ -462,15 +462,51 @@ public:
int InputArraySize(const QString& id) const;
struct ValueHint {
QVector<NodeValue::Type> type;
int index = -1;
QString tag;
class ValueHint {
public:
explicit ValueHint(const QVector<NodeValue::Type> &types = QVector<NodeValue::Type>(), int index = -1, const QString &tag = QString()) :
type_(types),
index_(index),
tag_(tag)
{
}
explicit ValueHint(const QVector<NodeValue::Type> &types, const QString &tag) :
type_(types),
index_(-1),
tag_(tag)
{
}
explicit ValueHint(int index) :
index_(index)
{
}
explicit ValueHint(const QString &tag) :
index_(-1),
tag_(tag)
{
}
void Hash(QCryptographicHash &hash) const;
void Load(QXmlStreamReader *reader);
void Save(QXmlStreamWriter *writer) const;
const QVector<NodeValue::Type> &types() const { return type_; }
const int &index() const { return index_; }
const QString& tag() const { return tag_; }
void set_type(const QVector<NodeValue::Type> &type) { type_ = type; }
void set_index(const int &index) { index_ = index; }
void set_tag(const QString &tag) { tag_ = tag; }
private:
QVector<NodeValue::Type> type_;
int index_;
QString tag_;
};
static void Hash(const Node *node, const ValueHint &hint, QCryptographicHash& hash, const NodeGlobals &globals, const VideoParams& video_params);
+4 -4
View File
@@ -106,18 +106,18 @@ NodeValue NodeTraverser::GenerateRowValueElement(const Node::ValueHint &hint, No
int NodeTraverser::GenerateRowValueElementIndex(const Node::ValueHint &hint, NodeValue::Type preferred_type, const NodeValueTable *table)
{
QVector<NodeValue::Type> types = hint.type;
QVector<NodeValue::Type> types = hint.types();
if (types.isEmpty()) {
types.append(preferred_type);
}
if (hint.index == -1) {
if (hint.index() == -1) {
// Get most recent value with this type and tag
return table->GetValueIndex(types, hint.tag);
return table->GetValueIndex(types, hint.tag());
} else {
// Try to find value at this index
int index = table->Count() - 1 - hint.index;
int index = table->Count() - 1 - hint.index();
int diff = 0;
while (index + diff < table->Count() && index - diff >= 0) {
+1 -1
View File
@@ -49,7 +49,7 @@ PreCacheTask::PreCacheTask(Footage *footage, int index, Sequence* sequence)
Node::CopyInputs(footage, footage_, false);
Node::ConnectEdge(footage_, NodeInput(viewer(), ViewerOutput::kTextureInput));
viewer()->SetValueHintForInput(ViewerOutput::kTextureInput, {{NodeValue::kTexture}, -1, Track::Reference(Track::kVideo, index).ToString()});
viewer()->SetValueHintForInput(ViewerOutput::kTextureInput, Node::ValueHint({NodeValue::kTexture}, Track::Reference(Track::kVideo, index).ToString()));
SetTitle(tr("Pre-caching %1:%2").arg(footage_->filename(), QString::number(index)));
}
+1 -1
View File
@@ -38,7 +38,7 @@ void NodeValueTree::SetNode(const NodeInput &input, const rational &time)
const NodeValue &value = table.at(i);
QTreeWidgetItem *item = new QTreeWidgetItem(this);
Node::ValueHint hint = {{value.type()}, table.Count()-1-i, value.tag()};
Node::ValueHint hint({value.type()}, table.Count()-1-i, value.tag());
QRadioButton *radio = new QRadioButton(this);
radio->setProperty("input", QVariant::fromValue(input));
+2 -2
View File
@@ -405,7 +405,7 @@ void ImportTool::DropGhosts(bool insert)
TransformDistortNode* transform = new TransformDistortNode();
command->add_child(new NodeAddCommand(dst_graph, transform));
command->add_child(new NodeSetValueHintCommand(transform, TransformDistortNode::kTextureInput, -1, {{NodeValue::kTexture}, -1, footage_stream.output}));
command->add_child(new NodeSetValueHintCommand(transform, TransformDistortNode::kTextureInput, -1, Node::ValueHint({NodeValue::kTexture}, footage_stream.output)));
command->add_child(new NodeEdgeAddCommand(footage_stream.footage, NodeInput(transform, TransformDistortNode::kTextureInput)));
command->add_child(new NodeEdgeAddCommand(transform, NodeInput(clip, ClipBlock::kBufferIn)));
@@ -417,7 +417,7 @@ void ImportTool::DropGhosts(bool insert)
VolumeNode* volume_node = new VolumeNode();
command->add_child(new NodeAddCommand(dst_graph, volume_node));
command->add_child(new NodeSetValueHintCommand(volume_node, VolumeNode::kSamplesInput, -1, {{NodeValue::kSamples}, -1, footage_stream.output}));
command->add_child(new NodeSetValueHintCommand(volume_node, VolumeNode::kSamplesInput, -1, Node::ValueHint({NodeValue::kSamples}, footage_stream.output)));
command->add_child(new NodeEdgeAddCommand(footage_stream.footage, NodeInput(volume_node, VolumeNode::kSamplesInput)));
command->add_child(new NodeEdgeAddCommand(volume_node, NodeInput(clip, ClipBlock::kBufferIn)));