Merge branch 'master' into otio_improvments

This commit is contained in:
ThomasWilshaw
2020-12-04 16:08:38 +00:00
committed by GitHub
898 changed files with 93869 additions and 12307 deletions
+21 -14
View File
@@ -1,5 +1,5 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
# Copyright (C) 2020 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,43 +16,50 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
common/bezier.h
common/bezier.cpp
common/bezier.h
common/cancelableobject.h
common/channellayout.h
common/clamp.h
common/commandlineparser.h
common/commandlineparser.cpp
common/crashpadinterface.h
common/commandlineparser.h
common/crashpadinterface.cpp
common/crashpadinterface.h
common/crashpadutils.h
common/debug.h
common/debug.cpp
common/debug.h
common/define.h
common/filefunctions.h
common/ffmpegutils.cpp
common/ffmpegutils.h
common/filefunctions.cpp
common/flipmodifiers.h
common/filefunctions.h
common/flipmodifiers.cpp
common/flipmodifiers.h
common/functiontimer.h
common/lerp.h
common/memorypool.h
common/memorypool.cpp
common/otioutils.h
common/qtutils.h
common/memorypool.h
common/ocioutils.cpp
common/ocioutils.h
common/oiioutils.cpp
common/oiioutils.h
common/qtutils.cpp
common/qtutils.h
common/range.h
common/ratiodialog.h
common/ratiodialog.cpp
common/ratiodialog.h
common/rational.h
common/rational.cpp
common/threadedobject.h
common/threadsafemap.h
common/threadedobject.cpp
common/timecodefunctions.h
common/threadedobject.h
common/timecodefunctions.cpp
common/timerange.h
common/timecodefunctions.h
common/timerange.cpp
common/timerange.h
common/tohex.h
common/xmlutils.h
common/xmlutils.cpp
common/xmlutils.h
PARENT_SCOPE
)
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
class AutoScroll {
public:
@@ -34,6 +34,6 @@ public:
};
};
OLIVE_NAMESPACE_EXIT
}
#endif // AUTOSCROLL_H
+10 -5
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,7 +22,9 @@
#include <QtMath>
OLIVE_NAMESPACE_ENTER
#include "common/clamp.h"
namespace olive {
double Bezier::QuadraticXtoT(double x, double a, double b, double c)
{
@@ -36,7 +38,10 @@ double Bezier::QuadraticTtoY(double a, double b, double c, double t)
double Bezier::CubicXtoT(double x_target, double a, double b, double c, double d)
{
double tolerance = 0.0001;
const double tolerance = 0.0001;
// Clamp to prevent deadlocks
x_target = clamp(x_target, a, d);
double lower = 0.0;
double upper = 1.0;
@@ -51,7 +56,7 @@ double Bezier::CubicXtoT(double x_target, double a, double b, double c, double d
upper = percent;
}
percent = (upper + lower) / 2.0;
percent = (upper + lower) * 0.5;
x = CubicTtoY(a, b, c, d, percent);
}
@@ -63,4 +68,4 @@ double Bezier::CubicTtoY(double a, double b, double c, double d, double t)
return qPow(1.0 - t, 3)*a + 3*qPow(1.0 - t, 2)*t*b + 3*(1.0 - t)*qPow(t, 2)*c + qPow(t, 3)*d;
}
OLIVE_NAMESPACE_EXIT
}
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
class Bezier
{
@@ -37,6 +37,6 @@ public:
static double CubicTtoY(double a, double b, double c, double d, double t);
};
OLIVE_NAMESPACE_EXIT
}
#endif // BEZIER_H
+11 -5
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
class CancelableObject {
public:
@@ -34,19 +34,25 @@ public:
{
}
void Cancel() {
void Cancel()
{
cancelled_ = true;
CancelEvent();
}
const QAtomicInt& IsCancelled() const {
const QAtomicInt& IsCancelled() const
{
return cancelled_;
}
protected:
virtual void CancelEvent(){}
private:
QAtomicInt cancelled_;
};
OLIVE_NAMESPACE_EXIT
}
#endif // CANCELABLEOBJECT_H
+1 -1
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
+1 -1
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
+14 -4
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -34,11 +34,11 @@ CommandLineParser::~CommandLineParser()
}
}
const CommandLineParser::Option *CommandLineParser::AddOption(const QStringList &strings, const QString &description)
const CommandLineParser::Option *CommandLineParser::AddOption(const QStringList &strings, const QString &description, bool takes_arg, const QString &arg_placeholder)
{
Option* o = new Option();
options_.append({strings, description, o});
options_.append({strings, description, o, takes_arg, arg_placeholder});
return o;
}
@@ -72,6 +72,12 @@ void CommandLineParser::Process(int argc, char **argv)
if (!s.compare(arg_basename, Qt::CaseInsensitive)) {
// Flag discovered!
o.option->Set();
if (o.takes_arg && i+1 < argc) {
o.option->SetSetting(argv[i+1]);
i++;
}
matched_known = true;
goto found_flag;
}
@@ -147,7 +153,11 @@ void CommandLineParser::PrintHelp(const char* filename)
all_args.append(this_arg);
}
printf(" %s\n", all_args.toUtf8().constData());
if (o.arg_placeholder.isEmpty()) {
printf(" %s\n", all_args.toUtf8().constData());
} else {
printf(" %s <%s>\n", all_args.toUtf8().constData(), o.arg_placeholder.toUtf8().constData());
}
printf(" %s\n\n", o.description.toUtf8().constData());
}
+25 -23
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,7 +33,27 @@ public:
DISABLE_COPY_MOVE(CommandLineParser)
class Option {
class PositionalArgument
{
public:
PositionalArgument() = default;
const QString& GetSetting() const
{
return setting_;
}
void SetSetting(const QString& s)
{
setting_ = s;
}
private:
QString setting_;
};
class Option : public PositionalArgument {
public:
Option()
{
@@ -55,29 +75,9 @@ public:
};
class PositionalArgument
{
public:
PositionalArgument() = default;
const QString& GetSetting() const
{
return setting_;
}
void SetSetting(const QString& s)
{
setting_ = s;
}
private:
QString setting_;
};
CommandLineParser() = default;
const Option* AddOption(const QStringList& strings, const QString& description);
const Option* AddOption(const QStringList& strings, const QString& description, bool takes_arg = false, const QString& arg_placeholder = QString());
const PositionalArgument* AddPositionalArgument(const QString& name, const QString& description, bool required = false);
@@ -90,6 +90,8 @@ private:
QStringList args;
QString description;
Option* option;
bool takes_arg;
QString arg_placeholder;
};
struct KnownPositionalArgument {
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@ crashpad::CrashpadClient *client;
QString GenerateReportPath()
{
return QDir(OLIVE_NAMESPACE::FileFunctions::GetTempFilePath()).filePath(QStringLiteral("reports"));
return QDir(olive::FileFunctions::GetTempFilePath()).filePath(QStringLiteral("reports"));
}
base::FilePath GenerateReportPathForCrashpad()
@@ -90,7 +90,7 @@ bool InitializeCrashpad()
base::FilePath reports_dir = GenerateReportPathForCrashpad();
base::FilePath metrics_dir(QSTRING_TO_BASE_STRING(QDir(OLIVE_NAMESPACE::FileFunctions::GetTempFilePath()).filePath(QStringLiteral("metrics"))));
base::FilePath metrics_dir(QSTRING_TO_BASE_STRING(QDir(olive::FileFunctions::GetTempFilePath()).filePath(QStringLiteral("metrics"))));
// Metadata that will be posted to the server with the crash report map
std::map<std::string, std::string> annotations;
+1 -1
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
+1 -1
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
#include "debug.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
void DebugHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
@@ -54,4 +54,4 @@ void DebugHandler(QtMsgType type, const QMessageLogContext &context, const QStri
#endif
}
OLIVE_NAMESPACE_EXIT
}
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,10 +25,10 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
void DebugHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
OLIVE_NAMESPACE_EXIT
}
#endif // DEBUG_H
+6 -16
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,17 +21,7 @@
#ifndef OLIVECOMMONDEFINE_H
#define OLIVECOMMONDEFINE_H
#define OLIVE_NAMESPACE olive
#define OLIVE_NAMESPACE_ENTER namespace OLIVE_NAMESPACE {
#define OLIVE_NAMESPACE_EXIT }
OLIVE_NAMESPACE_ENTER
const int kHSVChannels = 3;
const int kRGBChannels = 3;
const int kRGBAChannels = 4;
namespace olive {
/// The minimum size an icon in ProjectExplorer can be
const int kProjectIconSizeMinimum = 16;
@@ -44,14 +34,14 @@ const int kProjectIconSizeDefault = 64;
const int kBytesInGigabyte = 1073741824;
OLIVE_NAMESPACE_EXIT
}
#define MACRO_NAME_AS_STR(s) #s
#define MACRO_VAL_AS_STR(s) MACRO_NAME_AS_STR(s)
#define OLIVE_NS_CONST_ARG(x, y) QArgument<const OLIVE_NAMESPACE::x>("const " MACRO_VAL_AS_STR(OLIVE_NAMESPACE) "::" #x, y)
#define OLIVE_NS_ARG(x, y) QArgument<OLIVE_NAMESPACE::x>(MACRO_VAL_AS_STR(OLIVE_NAMESPACE) "::" #x, y)
#define OLIVE_NS_RETURN_ARG(x, y) QReturnArgument<OLIVE_NAMESPACE::x>(MACRO_VAL_AS_STR(OLIVE_NAMESPACE) "::" #x, y)
#define OLIVE_NS_CONST_ARG(x, y) QArgument<const olive::x>("const " MACRO_VAL_AS_STR(olive) "::" #x, y)
#define OLIVE_NS_ARG(x, y) QArgument<olive::x>(MACRO_VAL_AS_STR(olive) "::" #x, y)
#define OLIVE_NS_RETURN_ARG(x, y) QReturnArgument<olive::x>(MACRO_VAL_AS_STR(olive) "::" #x, y)
/**
* Copy/move deleters. Similar to Q_DISABLE_COPY_MOVE, et al. but those functions are not present in Qt < 5.13 so we
+141
View File
@@ -0,0 +1,141 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 Olive Team
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "common/ffmpegutils.h"
namespace olive {
AVPixelFormat FFmpegUtils::GetCompatiblePixelFormat(const AVPixelFormat &pix_fmt)
{
AVPixelFormat possible_pix_fmts[] = {
AV_PIX_FMT_RGB24,
AV_PIX_FMT_RGBA,
AV_PIX_FMT_RGB48,
AV_PIX_FMT_RGBA64,
AV_PIX_FMT_NONE
};
return avcodec_find_best_pix_fmt_of_list(possible_pix_fmts,
pix_fmt,
1,
nullptr);
}
AudioParams::Format FFmpegUtils::GetNativeSampleFormat(const AVSampleFormat &smp_fmt)
{
switch (smp_fmt) {
case AV_SAMPLE_FMT_U8:
return AudioParams::kFormatUnsigned8;
case AV_SAMPLE_FMT_S16:
return AudioParams::kFormatSigned16;
case AV_SAMPLE_FMT_S32:
return AudioParams::kFormatSigned32;
case AV_SAMPLE_FMT_S64:
return AudioParams::kFormatSigned64;
case AV_SAMPLE_FMT_FLT:
return AudioParams::kFormatFloat32;
case AV_SAMPLE_FMT_DBL:
return AudioParams::kFormatFloat64;
case AV_SAMPLE_FMT_U8P :
case AV_SAMPLE_FMT_S16P:
case AV_SAMPLE_FMT_S32P:
case AV_SAMPLE_FMT_S64P:
case AV_SAMPLE_FMT_FLTP:
case AV_SAMPLE_FMT_DBLP:
case AV_SAMPLE_FMT_NONE:
case AV_SAMPLE_FMT_NB:
break;
}
return AudioParams::kFormatInvalid;
}
AVSampleFormat FFmpegUtils::GetFFmpegSampleFormat(const AudioParams::Format &smp_fmt)
{
switch (smp_fmt) {
case AudioParams::kFormatUnsigned8:
return AV_SAMPLE_FMT_U8;
case AudioParams::kFormatSigned16:
return AV_SAMPLE_FMT_S16;
case AudioParams::kFormatSigned32:
return AV_SAMPLE_FMT_S32;
case AudioParams::kFormatSigned64:
return AV_SAMPLE_FMT_S64;
case AudioParams::kFormatFloat32:
return AV_SAMPLE_FMT_FLT;
case AudioParams::kFormatFloat64:
return AV_SAMPLE_FMT_DBL;
case AudioParams::kFormatInvalid:
case AudioParams::kFormatCount:
break;
}
return AV_SAMPLE_FMT_NONE;
}
AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const VideoParams::Format &pix_fmt, int channel_layout)
{
if (channel_layout == VideoParams::kRGBChannelCount) {
switch (pix_fmt) {
case VideoParams::kFormatUnsigned8:
return AV_PIX_FMT_RGB24;
case VideoParams::kFormatUnsigned16:
return AV_PIX_FMT_RGB48;
case VideoParams::kFormatFloat16:
case VideoParams::kFormatFloat32:
case VideoParams::kFormatInvalid:
case VideoParams::kFormatCount:
break;
}
} else if (channel_layout == VideoParams::kRGBAChannelCount) {
switch (pix_fmt) {
case VideoParams::kFormatUnsigned8:
return AV_PIX_FMT_RGBA;
case VideoParams::kFormatUnsigned16:
return AV_PIX_FMT_RGBA64;
case VideoParams::kFormatFloat16:
case VideoParams::kFormatFloat32:
case VideoParams::kFormatInvalid:
case VideoParams::kFormatCount:
break;
}
}
return AV_PIX_FMT_NONE;
}
VideoParams::Format FFmpegUtils::GetCompatiblePixelFormat(const VideoParams::Format &pix_fmt)
{
switch (pix_fmt) {
case VideoParams::kFormatUnsigned8:
return VideoParams::kFormatUnsigned8;
case VideoParams::kFormatUnsigned16:
case VideoParams::kFormatFloat16:
case VideoParams::kFormatFloat32:
return VideoParams::kFormatUnsigned16;
case VideoParams::kFormatInvalid:
case VideoParams::kFormatCount:
break;
}
return VideoParams::kFormatInvalid;
}
}
+63
View File
@@ -0,0 +1,63 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 Olive Team
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef FFMPEGABSTRACTION_H
#define FFMPEGABSTRACTION_H
extern "C" {
#include <libavformat/avformat.h>
}
#include "render/audioparams.h"
#include "render/videoparams.h"
namespace olive {
class FFmpegUtils {
public:
/**
* @brief Returns an AVPixelFormat that can be used to convert a frame to a data type Olive supports with minimal data loss
*/
static AVPixelFormat GetCompatiblePixelFormat(const AVPixelFormat& pix_fmt);
/**
* @brief Returns a native pixel format that can be used to convert from a native frame to an AVFrame with minimal data loss
*/
static VideoParams::Format GetCompatiblePixelFormat(const VideoParams::Format& pix_fmt);
/**
* @brief Returns an FFmpeg pixel format for a given native pixel format
*/
static AVPixelFormat GetFFmpegPixelFormat(const VideoParams::Format& pix_fmt, int channel_layout);
/**
* @brief Returns a native sample format type for a given AVSampleFormat
*/
static AudioParams::Format GetNativeSampleFormat(const AVSampleFormat& smp_fmt);
/**
* @brief Returns an FFmpeg sample format type for a given native type
*/
static AVSampleFormat GetFFmpegSampleFormat(const AudioParams::Format &smp_fmt);
};
}
#endif // FFMPEGABSTRACTION_H
+57 -4
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#include "config/config.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
QString FileFunctions::GetUniqueFileIdentifier(const QString &filename)
{
@@ -75,7 +75,7 @@ QString FileFunctions::GetTempFilePath()
{
QString temp_path = QDir(QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation))
.filePath(QCoreApplication::organizationName()))
.filePath(QCoreApplication::applicationName());
.filePath(QCoreApplication::applicationName());
// Ensure it exists
QDir(temp_path).mkpath(".");
@@ -187,4 +187,57 @@ QString FileFunctions::EnsureFilenameExtension(QString fn, const QString &extens
return fn;
}
OLIVE_NAMESPACE_EXIT
QString FileFunctions::ReadFileAsString(const QString &filename)
{
QFile f(filename);
QString file_data;
if (f.open(QFile::ReadOnly | QFile::Text)) {
QTextStream text_stream(&f);
file_data = text_stream.readAll();
f.close();
}
return file_data;
}
QString FileFunctions::GetSafeTemporaryFilename(const QString &original)
{
int counter = 0;
QFileInfo original_info(original);
QString basename = original_info.baseName();
QString complete_suffix = original_info.completeSuffix();
// If we have a complete suffix, make sure there's a period in it
if (!complete_suffix.isEmpty()) {
complete_suffix.prepend('.');
}
QString temp_abs_path;
do {
temp_abs_path = original_info.dir().filePath(
QStringLiteral("%1.tmp%2%3").arg(basename,
QString::number(counter),
complete_suffix));
counter++;
} while (QFileInfo::exists(temp_abs_path));
return temp_abs_path;
}
bool FileFunctions::RenameFileAllowOverwrite(const QString &from, const QString &to)
{
if (QFileInfo::exists(to) && !QFile::remove(to)) {
qCritical() << "Couldn't remove existing file" << to << "for overwrite";
return false;
}
// By this point, we can assume `to` either never existed or has now been deleted
if (!QFile::rename(from, to)) {
qCritical() << "Failed to rename file" << from << "to" << to;
return false;
}
return true;
}
}
+22 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
/**
* @brief A collection of static file and directory functions
@@ -65,10 +65,29 @@ public:
*/
static QString EnsureFilenameExtension(QString fn, const QString& extension);
static QString ReadFileAsString(const QString& filename);
/**
* @brief Returns a temporary filename that can be used while writing rather than the original
*
* If overwriting a file, it's safest to write to a new file first and then only replace it at
* the end so that if the program crashes or the user cancels the save half way through, the
* original file is still intact.
*
* This function returns a slight variant of the filename provided that's guaranteed to not exist
* and therefore won't overwrite anything important.
*/
static QString GetSafeTemporaryFilename(const QString& original);
/**
* @brief Renames a file from `from` to `to`, deleting `to` if such a file already exists first
*/
static bool RenameFileAllowOverwrite(const QString& from, const QString& to);
};
OLIVE_NAMESPACE_EXIT
}
#endif // FILEFUNCTIONS_H
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
#include "flipmodifiers.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
Qt::KeyboardModifiers FlipControlAndShiftModifiers(Qt::KeyboardModifiers e) {
if (e & Qt::ControlModifier & Qt::ShiftModifier) {
@@ -38,4 +38,4 @@ Qt::KeyboardModifiers FlipControlAndShiftModifiers(Qt::KeyboardModifiers e) {
return e;
}
OLIVE_NAMESPACE_EXIT
}
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,10 +25,10 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
Qt::KeyboardModifiers FlipControlAndShiftModifiers(Qt::KeyboardModifiers e);
OLIVE_NAMESPACE_EXIT
}
#endif // FLIPMODIFIERS_H
+1 -1
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
+1 -1
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
+2 -2
View File
@@ -1,6 +1,6 @@
#include "memorypool.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
size_t memory_pool_consumption = 0;
QMutex memory_pool_consumption_lock;
@@ -11,4 +11,4 @@ bool MemoryPoolLimitReached()
return (memory_pool_consumption >= 2147483648);
}
OLIVE_NAMESPACE_EXIT
}
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -30,7 +30,7 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
extern size_t memory_pool_consumption;
extern QMutex memory_pool_consumption_lock;
@@ -397,6 +397,6 @@ private:
};
OLIVE_NAMESPACE_EXIT
}
#endif // MEMORYPOOL_H
+47
View File
@@ -0,0 +1,47 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 Olive Team
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "ocioutils.h"
namespace olive {
OCIO::BitDepth OCIOUtils::GetOCIOBitDepthFromPixelFormat(VideoParams::Format format)
{
switch (format) {
case VideoParams::kFormatUnsigned8:
return OCIO::BIT_DEPTH_UINT8;
case VideoParams::kFormatUnsigned16:
return OCIO::BIT_DEPTH_UINT16;
break;
case VideoParams::kFormatFloat16:
return OCIO::BIT_DEPTH_F16;
break;
case VideoParams::kFormatFloat32:
return OCIO::BIT_DEPTH_F32;
break;
case VideoParams::kFormatInvalid:
case VideoParams::kFormatCount:
break;
}
return OCIO::BIT_DEPTH_UNKNOWN;
}
}
+39
View File
@@ -0,0 +1,39 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 Olive Team
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OCIOUTILS_H
#define OCIOUTILS_H
#include <OpenColorIO/OpenColorIO.h>
namespace OCIO = OCIO_NAMESPACE;
#include "render/videoparams.h"
namespace olive {
class OCIOUtils
{
public:
static OCIO::BitDepth GetOCIOBitDepthFromPixelFormat(VideoParams::Format format);
};
}
#endif // OCIOUTILS_H
+81
View File
@@ -0,0 +1,81 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 Olive Team
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "oiioutils.h"
namespace olive {
void OIIOUtils::FrameToBuffer(const Frame* frame, OIIO::ImageBuf *buf)
{
buf->set_pixels(OIIO::ROI(),
buf->spec().format,
frame->const_data(),
OIIO::AutoStride,
frame->linesize_bytes());
}
void OIIOUtils::BufferToFrame(OIIO::ImageBuf *buf, Frame* frame)
{
buf->get_pixels(OIIO::ROI(),
buf->spec().format,
frame->data(),
OIIO::AutoStride,
frame->linesize_bytes());
}
rational OIIOUtils::GetPixelAspectRatioFromOIIO(const OIIO::ImageSpec &spec)
{
return rational::fromDouble(spec.get_float_attribute("PixelAspectRatio", 1));
}
VideoParams::Format OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::BASETYPE type)
{
switch (type) {
case OIIO::TypeDesc::UNKNOWN:
case OIIO::TypeDesc::NONE:
break;
case OIIO::TypeDesc::INT8:
case OIIO::TypeDesc::INT16:
case OIIO::TypeDesc::INT32:
case OIIO::TypeDesc::UINT32:
case OIIO::TypeDesc::INT64:
case OIIO::TypeDesc::UINT64:
case OIIO::TypeDesc::STRING:
case OIIO::TypeDesc::PTR:
case OIIO::TypeDesc::LASTBASE:
case OIIO::TypeDesc::DOUBLE:
qDebug() << "Tried to use unknown OIIO base type";
break;
case OIIO::TypeDesc::UINT8:
return VideoParams::kFormatUnsigned8;
case OIIO::TypeDesc::UINT16:
return VideoParams::kFormatUnsigned16;
case OIIO::TypeDesc::HALF:
return VideoParams::kFormatFloat16;
case OIIO::TypeDesc::FLOAT:
return VideoParams::kFormatFloat32;
}
return VideoParams::kFormatInvalid;
}
}
+65
View File
@@ -0,0 +1,65 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 Olive Team
This program 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 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef OIIOUTILS_H
#define OIIOUTILS_H
#include <OpenImageIO/imagebuf.h>
#include <OpenImageIO/typedesc.h>
#include "codec/frame.h"
#include "render/videoparams.h"
namespace olive {
class OIIOUtils {
public:
static OIIO::TypeDesc::BASETYPE GetOIIOBaseTypeFromFormat(VideoParams::Format format)
{
switch (format) {
case VideoParams::kFormatUnsigned8:
return OIIO::TypeDesc::UINT8;
case VideoParams::kFormatUnsigned16:
return OIIO::TypeDesc::UINT16;
case VideoParams::kFormatFloat16:
return OIIO::TypeDesc::HALF;
case VideoParams::kFormatFloat32:
return OIIO::TypeDesc::FLOAT;
case VideoParams::kFormatInvalid:
case VideoParams::kFormatCount:
break;
}
return OIIO::TypeDesc::UNKNOWN;
}
static void FrameToBuffer(const Frame *frame, OIIO::ImageBuf* buf);
static void BufferToFrame(OIIO::ImageBuf* buf, Frame* frame);
static VideoParams::Format GetFormatFromOIIOBasetype(OIIO::TypeDesc::BASETYPE type);
static rational GetPixelAspectRatioFromOIIO(const OIIO::ImageSpec& spec);
};
}
#endif // OIIOUTILS_H
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
uint32_t ceil_to_power_of_2(uint32_t v)
{
@@ -51,6 +51,6 @@ uint32_t floor_to_power_of_2(uint32_t x)
return x - (x >> 1);
}
OLIVE_NAMESPACE_EXIT
}
#endif // POWER_H
+12 -4
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,9 +20,9 @@
#include "qtutils.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
int QFontMetricsWidth(QFontMetrics fm, const QString& s) {
int QtUtils::QFontMetricsWidth(QFontMetrics fm, const QString& s) {
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return fm.width(s);
#else
@@ -30,4 +30,12 @@ int QFontMetricsWidth(QFontMetrics fm, const QString& s) {
#endif
}
OLIVE_NAMESPACE_EXIT
QFrame *QtUtils::CreateHorizontalLine()
{
QFrame* horizontal_line = new QFrame();
horizontal_line->setFrameShape(QFrame::HLine);
horizontal_line->setFrameShadow(QFrame::Sunken);
return horizontal_line;
}
}
+18 -11
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,20 +28,27 @@
*/
#include <QFontMetrics>
#include <QFrame>
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
/**
* @brief Retrieves the width of a string according to certain QFontMetrics
*
* QFontMetrics::width() has been deprecatd in favor of QFontMetrics::horizontalAdvance(), but the
* latter was only introduced in 5.11+. This function wraps the latter for 5.11+ and the former for
* earlier.
*/
int QFontMetricsWidth(QFontMetrics fm, const QString& s);
class QtUtils {
public:
/**
* @brief Retrieves the width of a string according to certain QFontMetrics
*
* QFontMetrics::width() has been deprecatd in favor of QFontMetrics::horizontalAdvance(), but the
* latter was only introduced in 5.11+. This function wraps the latter for 5.11+ and the former for
* earlier.
*/
static int QFontMetricsWidth(QFontMetrics fm, const QString& s);
OLIVE_NAMESPACE_EXIT
static QFrame* CreateHorizontalLine();
};
}
#endif // QTVERSIONABSTRACTION_H
+1 -1
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
#include <QCoreApplication>
#include <QMessageBox>
OLIVE_NAMESPACE_ENTER
namespace olive {
double GetFloatRatioFromUser(QWidget* parent,
const QString& title,
@@ -88,4 +88,4 @@ double GetFloatRatioFromUser(QWidget* parent,
}
}
OLIVE_NAMESPACE_EXIT
}
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,12 +25,12 @@
#include "common/rational.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
double GetFloatRatioFromUser(QWidget* parent,
const QString& title,
bool* ok_in);
OLIVE_NAMESPACE_EXIT
}
#endif // RATIODIALOG_H
+3 -3
View File
@@ -3,7 +3,7 @@
#include "rational.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
rational rational::fromDouble(const double &flt)
{
@@ -393,9 +393,9 @@ uint qHash(const rational &r, uint seed)
return ::qHash(r.toDouble(), seed);
}
OLIVE_NAMESPACE_EXIT
}
QDebug operator<<(QDebug debug, const OLIVE_NAMESPACE::rational &r)
QDebug operator<<(QDebug debug, const olive::rational &r)
{
return debug.space() << r.toDouble();
/*
+4 -4
View File
@@ -20,7 +20,7 @@ extern "C" {
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
typedef int64_t intType;
/*
@@ -141,10 +141,10 @@ private:
uint qHash(const rational& r, uint seed);
OLIVE_NAMESPACE_EXIT
}
QDebug operator<<(QDebug debug, const OLIVE_NAMESPACE::rational& r);
QDebug operator<<(QDebug debug, const olive::rational& r);
Q_DECLARE_METATYPE(OLIVE_NAMESPACE::rational)
Q_DECLARE_METATYPE(olive::rational)
#endif // RATIONAL_H
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
#include "threadedobject.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
void ThreadedObject::LockDeletes()
{
@@ -54,4 +54,4 @@ bool ThreadedObject::TryLockMutex(int timeout)
return threadobj_main_lock_.tryLock(timeout);
}
OLIVE_NAMESPACE_EXIT
}
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
class ThreadedObject
{
@@ -45,6 +45,6 @@ private:
QAtomicInt threadobj_delete_lock_;
};
OLIVE_NAMESPACE_EXIT
}
#endif // THREADEDOBJECT_H
+27
View File
@@ -0,0 +1,27 @@
#ifndef THREADSAFEMAP_H
#define THREADSAFEMAP_H
#include <QMap>
#include <QMutex>
template <typename K, typename V>
class ThreadSafeMap
{
public:
ThreadSafeMap() = default;
void insert(K key, V value)
{
mutex_.lock();
map_.insert(key, value);
mutex_.unlock();
}
private:
QMutex mutex_;
QMap<K, V> map_;
};
#endif // THREADSAFEMAP_H
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
#include "config/config.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
QString padded(int64_t arg, int padding) {
return QStringLiteral("%1").arg(arg, padding, 10, QChar('0'));
@@ -289,4 +289,4 @@ int64_t Timecode::rescale_timestamp_ceil(const int64_t &ts, const rational &sour
return qCeil(static_cast<double>(ts) * source.toDouble() / dest.toDouble());
}
OLIVE_NAMESPACE_EXIT
}
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
#include "common/rational.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
/**
* @brief Functions for converting times/timecodes/timestamps
@@ -72,6 +72,6 @@ public:
};
OLIVE_NAMESPACE_EXIT
}
#endif // TIMECODEFUNCTIONS_H
+77 -29
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,9 +20,10 @@
#include "timerange.h"
#include <QtMath>
#include <utility>
OLIVE_NAMESPACE_ENTER
namespace olive {
TimeRange::TimeRange(const rational &in, const rational &out) :
in_(in),
@@ -77,11 +78,11 @@ bool TimeRange::operator!=(const TimeRange &r) const
bool TimeRange::OverlapsWith(const TimeRange &a, bool in_inclusive, bool out_inclusive) const
{
bool overlaps_in = (in_inclusive) ? (a.out() < in()) : (a.out() <= in());
bool doesnt_overlap_in = (in_inclusive) ? (a.out() < in()) : (a.out() <= in());
bool overlaps_out = (out_inclusive) ? (a.in() > out()) : (a.in() >= out());
bool doesnt_overlap_out = (out_inclusive) ? (a.in() > out()) : (a.in() >= out());
return !(overlaps_in || overlaps_out);
return !doesnt_overlap_in && !doesnt_overlap_out;
}
TimeRange TimeRange::Combined(const TimeRange &a) const
@@ -148,6 +149,21 @@ const TimeRange &TimeRange::operator-=(const rational &rhs)
return *this;
}
std::list<TimeRange> TimeRange::Split(const int &chunk_size) const
{
std::list<TimeRange> split_ranges;
int start_time = qFloor(this->in().toDouble() / static_cast<double>(chunk_size)) * chunk_size;
int end_time = qCeil(this->out().toDouble() / static_cast<double>(chunk_size)) * chunk_size;
for (int i=start_time; i<end_time; i+=chunk_size) {
split_ranges.push_back(TimeRange(qMax(this->in(), rational(i)),
qMin(this->out(), rational(i + chunk_size))));
}
return split_ranges;
}
void TimeRange::normalize()
{
// If `out` is earlier than `in`, swap them
@@ -160,43 +176,45 @@ void TimeRange::normalize()
length_ = out_ - in_;
}
void TimeRangeList::InsertTimeRange(TimeRange range_to_add)
void TimeRangeList::insert(TimeRange range_to_add)
{
// See if list contains this range
if (ContainsTimeRange(range_to_add)) {
if (contains(range_to_add)) {
return;
}
// Does not contain range, so we'll almost certainly be adding it in some way
for (int i=0;i<size();i++) {
const TimeRange& compare = at(i);
const TimeRange& compare = array_.at(i);
if (compare.OverlapsWith(range_to_add)) {
range_to_add = TimeRange::Combine(range_to_add, compare);
removeAt(i);
array_.removeAt(i);
i--;
}
}
append(range_to_add);
array_.append(range_to_add);
}
void TimeRangeList::RemoveTimeRange(const TimeRange &remove)
void TimeRangeList::remove(const TimeRange &remove)
{
int sz = this->size();
for (int i=0;i<sz;i++) {
TimeRange& compare = (*this)[i];
TimeRange& compare = array_[i];
if (remove.Contains(compare)) {
// This element is entirely encompassed in this range, remove it
this->removeAt(i);
array_.removeAt(i);
i--;
sz--;
} else if (compare.Contains(remove, false, false)) {
// The remove range is within this element, only choice is to split the element into two
this->append(TimeRange(remove.out(), compare.out()));
TimeRange new_range(remove.out(), compare.out());
compare.set_out(remove.in());
insert(new_range);
break;
} else if (compare.in() < remove.in() && compare.out() > remove.in()) {
// This element's out point overlaps the range's in, we'll trim it
compare.set_out(remove.in());
@@ -207,10 +225,10 @@ void TimeRangeList::RemoveTimeRange(const TimeRange &remove)
}
}
bool TimeRangeList::ContainsTimeRange(const TimeRange &range, bool in_inclusive, bool out_inclusive) const
bool TimeRangeList::contains(const TimeRange &range, bool in_inclusive, bool out_inclusive) const
{
for (int i=0;i<size();i++) {
if (at(i).Contains(range, in_inclusive, out_inclusive)) {
if (array_.at(i).Contains(range, in_inclusive, out_inclusive)) {
return true;
}
}
@@ -218,12 +236,45 @@ bool TimeRangeList::ContainsTimeRange(const TimeRange &range, bool in_inclusive,
return false;
}
void TimeRangeList::shift(const rational &diff)
{
for (int i=0; i<array_.size(); i++) {
array_[i] += diff;
}
}
void TimeRangeList::trim_in(const rational &diff)
{
// Re-do list since we want to handle overlaps
TimeRangeList temp = *this;
clear();
foreach (TimeRange r, temp) {
r.set_in(r.in() + diff);
insert(r);
}
}
void TimeRangeList::trim_out(const rational &diff)
{
// Re-do list since we want to handle overlaps
TimeRangeList temp = *this;
clear();
foreach (TimeRange r, temp) {
r.set_out(r.out() + diff);
insert(r);
}
}
TimeRangeList TimeRangeList::Intersects(const TimeRange &range) const
{
TimeRangeList intersect_list;
for (int i=0;i<size();i++) {
const TimeRange& compare = at(i);
const TimeRange& compare = array_.at(i);
if (compare.out() <= range.in() || compare.in() >= range.out()) {
// No intersect
@@ -233,31 +284,28 @@ TimeRangeList TimeRangeList::Intersects(const TimeRange &range) const
TimeRange cropped(qMax(range.in(), compare.in()),
qMin(range.out(), compare.out()));
intersect_list.append(cropped);
intersect_list.insert(cropped);
}
}
return intersect_list;
}
void TimeRangeList::PrintTimeList()
{
qDebug() << "TimeRangeList now contains:";
for (int i=0;i<size();i++) {
qDebug() << " " << at(i);
}
}
uint qHash(const TimeRange &r, uint seed)
{
return qHash(r.in(), seed) ^ qHash(r.out(), seed);
}
OLIVE_NAMESPACE_EXIT
}
QDebug operator<<(QDebug debug, const OLIVE_NAMESPACE::TimeRange &r)
QDebug operator<<(QDebug debug, const olive::TimeRange &r)
{
debug.nospace() << r.in().toDouble() << " - " << r.out().toDouble();
return debug.space();
}
QDebug operator<<(QDebug debug, const olive::TimeRangeList &r)
{
debug << r.internal_array();
return debug.space();
}
+62 -11
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
#include "rational.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
class TimeRange {
public:
@@ -56,6 +56,8 @@ public:
const TimeRange& operator+=(const rational &rhs);
const TimeRange& operator-=(const rational &rhs);
std::list<TimeRange> Split(const int &chunk_size) const;
private:
void normalize();
@@ -65,34 +67,83 @@ private:
};
class TimeRangeList : public QList<TimeRange> {
class TimeRangeList {
public:
TimeRangeList() = default;
TimeRangeList(std::initializer_list<TimeRange> r) :
QList<TimeRange>(r)
array_(r)
{
}
void InsertTimeRange(TimeRange range_to_add);
void insert(TimeRange range_to_add);
void RemoveTimeRange(const TimeRange& remove);
void remove(const TimeRange& remove);
bool ContainsTimeRange(const TimeRange& range, bool in_inclusive = true, bool out_inclusive = true) const;
bool contains(const TimeRange& range, bool in_inclusive = true, bool out_inclusive = true) const;
bool isEmpty() const
{
return array_.isEmpty();
}
void clear()
{
array_.clear();
}
int size() const
{
return array_.size();
}
void shift(const rational& diff);
void trim_in(const rational& diff);
void trim_out(const rational& diff);
TimeRangeList Intersects(const TimeRange& range) const;
using const_iterator = QVector<TimeRange>::const_iterator;
const_iterator begin() const
{
return array_.constBegin();
}
const_iterator end() const
{
return array_.constEnd();
}
const TimeRange& first() const
{
return array_.first();
}
const TimeRange& last() const
{
return array_.last();
}
const QVector<TimeRange>& internal_array() const
{
return array_;
}
private:
void PrintTimeList();
QVector<TimeRange> array_;
};
uint qHash(const TimeRange& r, uint seed);
OLIVE_NAMESPACE_EXIT
}
QDebug operator<<(QDebug debug, const OLIVE_NAMESPACE::TimeRange& r);
QDebug operator<<(QDebug debug, const olive::TimeRange& r);
QDebug operator<<(QDebug debug, const olive::TimeRangeList& r);
Q_DECLARE_METATYPE(OLIVE_NAMESPACE::TimeRange)
Q_DECLARE_METATYPE(olive::TimeRange)
#endif // TIMERANGE_H
+2 -2
View File
@@ -5,12 +5,12 @@
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
inline QString ToHex(quint64 t) {
return QStringLiteral("%1").arg(t, 0, 16);
}
OLIVE_NAMESPACE_EXIT
}
#endif // TOHEX_H
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
#include "node/factory.h"
#include "widget/nodeview/nodeviewundo.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
void XMLConnectNodes(const XMLNodeData &xml_node_data, QUndoCommand *command)
{
@@ -64,4 +64,4 @@ void XMLLinkBlocks(const XMLNodeData &xml_node_data)
}
}
OLIVE_NAMESPACE_EXIT
}
+3 -3
View File
@@ -1,7 +1,7 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
#include "project/item/footage/stream.h"
OLIVE_NAMESPACE_ENTER
namespace olive {
class Block;
class Node;
@@ -71,6 +71,6 @@ bool XMLReadNextStartElement(QXmlStreamReader* reader);
void XMLLinkBlocks(const XMLNodeData& xml_node_data);
OLIVE_NAMESPACE_EXIT
}
#endif // XMLREADLOOP_H