Skip to content

Commit

Permalink
node: merge various metadata functions into one
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattkc committed Feb 20, 2023
1 parent b8ee27e commit 2c4347e
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 105 deletions.
4 changes: 2 additions & 2 deletions app/dialog/footagerelink/footagerelinkdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ FootageRelinkDialog::FootageRelinkDialog(const QVector<Footage *> &footage, QWid
connect(item_browse_btn, &QPushButton::clicked, this, &FootageRelinkDialog::BrowseForFootage);
item_actions_layout->addWidget(item_browse_btn);

item->setIcon(0, f->icon());
item->setIcon(0, f->data(Node::ICON).value<QIcon>());
item->setText(0, f->GetLabel());
item->setText(1, f->filename());

Expand All @@ -89,7 +89,7 @@ void FootageRelinkDialog::UpdateFootageItem(int index)
{
Footage* f = footage_.at(index);
QTreeWidgetItem* item = table_->topLevelItem(index);
item->setIcon(0, f->icon());
item->setIcon(0, f->data(Node::ICON).value<QIcon>());
item->setText(1, f->filename());
}

Expand Down
10 changes: 7 additions & 3 deletions app/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ void Node::Retranslate()
SetInputName(kEnabledInput, tr("Enabled"));
}

QIcon Node::icon() const
QVariant Node::data(const DataType &d) const
{
// Just a meaningless default icon to be used where necessary
return icon::New;
if (d == ICON) {
// Just a meaningless default icon to be used where necessary
return icon::New;
}

return QVariant();
}

bool Node::SetNodePositionInContext(Node *node, const QPointF &pos)
Expand Down
16 changes: 9 additions & 7 deletions app/node/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,16 @@ class Node : public QObject
*/
virtual void Retranslate();

virtual QIcon icon() const;

virtual QString duration() const {return QString();}

virtual qint64 creation_time() const {return 0;}
virtual qint64 mod_time() const {return 0;}
enum DataType
{
ICON,
DURATION,
CREATED_TIME,
MODIFIED_TIME,
FREQUENCY_RATE
};

virtual QString rate() const {return QString();}
virtual QVariant data(const DataType &d) const;

const QVector<QString>& inputs() const
{
Expand Down
93 changes: 49 additions & 44 deletions app/node/output/viewer/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,56 +87,61 @@ QString ViewerOutput::Description() const
return tr("Interface between a Viewer panel and the node system.");
}

QString ViewerOutput::duration() const
{
rational using_timebase;
Timecode::Display using_display = Core::instance()->GetTimecodeDisplay();

// Get first enabled streams
VideoParams video = GetFirstEnabledVideoStream();
AudioParams audio = GetFirstEnabledAudioStream();
SubtitleParams sub = GetFirstEnabledSubtitleStream();

if (video.is_valid() && video.video_type() != VideoParams::kVideoTypeStill) {
// Prioritize video
using_timebase = video.frame_rate_as_time_base();
} else if (audio.is_valid()) {
// Use audio as a backup
// If we're showing in a timecode, we prefer showing audio in seconds instead
if (using_display == Timecode::kTimecodeDropFrame
|| using_display == Timecode::kTimecodeNonDropFrame) {
using_display = Timecode::kTimecodeSeconds;
QVariant ViewerOutput::data(const DataType &d) const
{
switch (d) {
case DURATION:
{
rational using_timebase;
Timecode::Display using_display = Core::instance()->GetTimecodeDisplay();

// Get first enabled streams
VideoParams video = GetFirstEnabledVideoStream();
AudioParams audio = GetFirstEnabledAudioStream();
SubtitleParams sub = GetFirstEnabledSubtitleStream();

if (video.is_valid() && video.video_type() != VideoParams::kVideoTypeStill) {
// Prioritize video
using_timebase = video.frame_rate_as_time_base();
} else if (audio.is_valid()) {
// Use audio as a backup
// If we're showing in a timecode, we prefer showing audio in seconds instead
if (using_display == Timecode::kTimecodeDropFrame
|| using_display == Timecode::kTimecodeNonDropFrame) {
using_display = Timecode::kTimecodeSeconds;
}

using_timebase = audio.sample_rate_as_time_base();
} else if (sub.is_valid()) {
using_timebase = OLIVE_CONFIG("DefaultSequenceFrameRate").value<rational>();
}

using_timebase = audio.sample_rate_as_time_base();
} else if (sub.is_valid()) {
using_timebase = OLIVE_CONFIG("DefaultSequenceFrameRate").value<rational>();
if (!using_timebase.isNull()) {
// Return time transformed to timecode
return QString::fromStdString(Timecode::time_to_timecode(GetLength(), using_timebase, using_display));
}
break;
}

if (using_timebase.isNull()) {
// No timebase, return null
return QString();
} else {
// Return time transformed to timecode
return QString::fromStdString(Timecode::time_to_timecode(GetLength(), using_timebase, using_display));
case FREQUENCY_RATE:
{
VideoParams video_stream;

if (HasEnabledVideoStreams()
&& (video_stream = GetFirstEnabledVideoStream()).video_type() != VideoParams::kVideoTypeStill) {
// This is a video editor, prioritize video streams
return tr("%1 FPS").arg(video_stream.frame_rate().toDouble());
} else if (HasEnabledAudioStreams()) {
// No video streams, return audio
AudioParams audio_stream = GetFirstEnabledAudioStream();
return tr("%1 Hz").arg(audio_stream.sample_rate());
}
break;
}
}

QString ViewerOutput::rate() const
{
VideoParams video_stream;

if (HasEnabledVideoStreams()
&& (video_stream = GetFirstEnabledVideoStream()).video_type() != VideoParams::kVideoTypeStill) {
// This is a video editor, prioritize video streams
return tr("%1 FPS").arg(video_stream.frame_rate().toDouble());
} else if (HasEnabledAudioStreams()) {
// No video streams, return audio
AudioParams audio_stream = GetFirstEnabledAudioStream();
return tr("%1 Hz").arg(audio_stream.sample_rate());
default:
break;
}

return QString();
return super::data(d);
}

bool ViewerOutput::HasEnabledVideoStreams() const
Expand Down
3 changes: 1 addition & 2 deletions app/node/output/viewer/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class ViewerOutput : public Node
virtual QVector<CategoryID> Category() const override;
virtual QString Description() const override;

virtual QString duration() const override;
virtual QString rate() const override;
virtual QVariant data(const DataType &d) const override;

void set_default_parameters();

Expand Down
8 changes: 6 additions & 2 deletions app/node/project/folder/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ Folder::Folder()
AddInput(kChildInput, NodeValue::kNone, InputFlags(kInputFlagArray | kInputFlagNotKeyframable));
}

QIcon Folder::icon() const
QVariant Folder::data(const DataType &d) const
{
return icon::Folder;
if (d == ICON) {
return icon::Folder;
}

return super::data(d);
}

void Folder::Retranslate()
Expand Down
2 changes: 1 addition & 1 deletion app/node/project/folder/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Folder : public Node
return tr("Organize several items into a single collection.");
}

virtual QIcon icon() const override;
virtual QVariant data(const DataType &d) const override;

virtual void Retranslate() override;

Expand Down
71 changes: 38 additions & 33 deletions app/node/project/footage/footage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,26 +203,6 @@ const QString &Footage::decoder() const
return decoder_;
}

QIcon Footage::icon() const
{
if (valid_ && GetTotalStreamCount()) {
// Prioritize video > audio > image
VideoParams s = GetFirstEnabledVideoStream();

if (s.is_valid() && s.video_type() != VideoParams::kVideoTypeStill) {
return icon::Video;
} else if (HasEnabledAudioStreams()) {
return icon::Audio;
} else if (s.is_valid() && s.video_type() == VideoParams::kVideoTypeStill) {
return icon::Image;
} else if (HasEnabledSubtitleStreams()) {
return icon::Subtitles;
}
}

return icon::Error;
}

QString Footage::DescribeVideoStream(const VideoParams &params)
{
if (params.video_type() == VideoParams::kVideoTypeStill) {
Expand Down Expand Up @@ -375,26 +355,51 @@ void Footage::LoadFinishedEvent()
}
}

qint64 Footage::creation_time() const
QVariant Footage::data(const DataType &d) const
{
QFileInfo info(filename());
switch (d) {
case CREATED_TIME:
{
QFileInfo info(filename());

if (info.exists()) {
return QtUtils::GetCreationDate(info).toSecsSinceEpoch();
if (info.exists()) {
return QtUtils::GetCreationDate(info).toSecsSinceEpoch();
}
break;
}
case MODIFIED_TIME:
{
QFileInfo info(filename());

return 0;
}

qint64 Footage::mod_time() const
{
QFileInfo info(filename());
if (info.exists()) {
return info.lastModified().toSecsSinceEpoch();
}
break;
}
case ICON:
{
if (valid_ && GetTotalStreamCount()) {
// Prioritize video > audio > image
VideoParams s = GetFirstEnabledVideoStream();

if (s.is_valid() && s.video_type() != VideoParams::kVideoTypeStill) {
return icon::Video;
} else if (HasEnabledAudioStreams()) {
return icon::Audio;
} else if (s.is_valid() && s.video_type() == VideoParams::kVideoTypeStill) {
return icon::Image;
} else if (HasEnabledSubtitleStreams()) {
return icon::Subtitles;
}
}

if (info.exists()) {
return info.lastModified().toSecsSinceEpoch();
return icon::Error;
}
default:
break;
}

return 0;
return super::data(d);
}

void Footage::UpdateTooltip()
Expand Down
5 changes: 1 addition & 4 deletions app/node/project/footage/footage.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ class Footage : public ViewerOutput
*/
const QString& decoder() const;

virtual QIcon icon() const override;

virtual bool IsItem() const override
{
return true;
Expand All @@ -176,8 +174,7 @@ class Footage : public ViewerOutput

virtual void LoadFinishedEvent() override;

virtual qint64 creation_time() const override;
virtual qint64 mod_time() const override;
virtual QVariant data(const DataType &d) const override;

virtual int GetTotalStreamCount() const override { return total_stream_count_; }

Expand Down
8 changes: 6 additions & 2 deletions app/node/project/sequence/sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ void Sequence::add_default_nodes(MultiUndoCommand* command)
}
}

QIcon Sequence::icon() const
QVariant Sequence::data(const DataType &d) const
{
return icon::Sequence;
if (d == ICON) {
return icon::Sequence;
}

return super::data(d);
}

QVector<Track *> Sequence::GetUnlockedTracks() const
Expand Down
2 changes: 1 addition & 1 deletion app/node/project/sequence/sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Sequence : public ViewerOutput

void add_default_nodes(MultiUndoCommand *command = nullptr);

virtual QIcon icon() const override;
virtual QVariant data(const DataType &d) const override;

const QVector<Track *> &GetTracks() const
{
Expand Down
8 changes: 4 additions & 4 deletions app/widget/projectexplorer/projectviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
case kName:
return internal_item->GetLabel();
case kDuration:
return internal_item->duration();
return internal_item->data(Node::DURATION);
case kRate:
return internal_item->rate();
return internal_item->data(Node::FREQUENCY_RATE);
case kLastModified:
case kCreatedTime:
{
qint64 using_time = (column_type == kLastModified) ? internal_item->mod_time() : internal_item->creation_time();
qint64 using_time = (column_type == kLastModified) ? internal_item->data(Node::MODIFIED_TIME).toLongLong() : internal_item->data(Node::CREATED_TIME).toLongLong();

if (using_time == 0) {
// 0 is the null value, return nothing
Expand Down Expand Up @@ -178,7 +178,7 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
case Qt::DecorationRole:
// If this is the first column, return the Item's icon
if (column_type == kName) {
return internal_item->icon();
return internal_item->data(Node::ICON);
}
break;
case Qt::ToolTipRole:
Expand Down

0 comments on commit 2c4347e

Please sign in to comment.