various: moved more to core lib

This commit is contained in:
itsmattkc
2023-01-19 16:01:31 -08:00
parent dd9c52ab59
commit c1c6893713
92 changed files with 448 additions and 1558 deletions
+3 -4
View File
@@ -20,7 +20,6 @@
#include "transition.h"
#include "common/clamp.h"
#include "node/block/clip/clip.h"
#include "node/output/track/track.h"
#include "widget/slider/rationalslider.h"
@@ -126,7 +125,7 @@ double TransitionBlock::GetOutProgress(const double &time) const
return 0;
}
return clamp(1.0 - (GetInternalTransitionTime(time) / out_offset().toDouble()), 0.0, 1.0);
return std::clamp(1.0 - (GetInternalTransitionTime(time) / out_offset().toDouble()), 0.0, 1.0);
}
double TransitionBlock::GetInProgress(const double &time) const
@@ -135,7 +134,7 @@ double TransitionBlock::GetInProgress(const double &time) const
return 0;
}
return clamp((GetInternalTransitionTime(time) - out_offset().toDouble()) / in_offset().toDouble(), 0.0, 1.0);
return std::clamp((GetInternalTransitionTime(time) - out_offset().toDouble()) / in_offset().toDouble(), 0.0, 1.0);
}
double TransitionBlock::GetInternalTransitionTime(const double &time) const
@@ -245,7 +244,7 @@ double TransitionBlock::TransformCurve(double linear) const
linear *= linear;
break;
case kLogarithmic:
linear = qSqrt(linear);
linear = std::sqrt(linear);
break;
}
@@ -179,9 +179,9 @@ void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x, dou
} else if (gizmo == rotation_gizmo_) {
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() + gizmo->GetGlobals().nonsquare_resolution()/2).toPointF();
gizmo_start_angle_ = qAtan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
gizmo_start_angle_ = std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
gizmo_last_angle_ = gizmo_start_angle_;
gizmo_last_alt_angle_ = qAtan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
gizmo_last_alt_angle_ = std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
gizmo_rotate_wrap_ = 0;
gizmo_rotate_last_dir_ = kDirectionNone;
@@ -216,8 +216,8 @@ void TransformDistortNode::GizmoDragMove(double x, double y, const Qt::KeyboardM
} else if (gizmo == rotation_gizmo_) {
double raw_angle = qAtan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
double alt_angle = qAtan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
double raw_angle = std::atan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
double alt_angle = std::atan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
double current_angle = raw_angle;
+17 -14
View File
@@ -173,7 +173,7 @@ void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row, const NodeG
res = globals.square_resolution();
}
QPointF half_res = res.toPointF()/2;
Imath::V2d half_res(res.x()/2, res.y()/2);
auto points = row[kPointsInput].toArray();
@@ -205,20 +205,20 @@ void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row, const NodeG
for (int i=0; i<pts_sz; i++) {
const Bezier &pt = points.at(i).toBezier();
QPointF main = pt.ToPointF() + half_res;
QPointF cp1 = main + pt.ControlPoint1ToPointF();
QPointF cp2 = main + pt.ControlPoint2ToPointF();
Imath::V2d main = pt.to_vec() + half_res;
Imath::V2d cp1 = main + pt.control_point_1_to_vec();
Imath::V2d cp2 = main + pt.control_point_2_to_vec();
gizmo_position_handles_[i]->SetPoint(main);
gizmo_position_handles_[i]->SetPoint(QPointF(main.x, main.y));
gizmo_bezier_handles_[i*2]->SetPoint(cp1);
gizmo_bezier_lines_[i*2]->SetLine(QLineF(main, cp1));
gizmo_bezier_handles_[i*2+1]->SetPoint(cp2);
gizmo_bezier_lines_[i*2+1]->SetLine(QLineF(main, cp2));
gizmo_bezier_handles_[i*2]->SetPoint(QPointF(cp1.x, cp1.y));
gizmo_bezier_lines_[i*2]->SetLine(QLineF(QPointF(main.x, main.y), QPointF(cp1.x, cp1.y)));
gizmo_bezier_handles_[i*2+1]->SetPoint(QPointF(cp2.x, cp2.y));
gizmo_bezier_lines_[i*2+1]->SetLine(QLineF(QPointF(main.x, main.y), QPointF(cp2.x, cp2.y)));
}
}
poly_gizmo_->SetPath(GeneratePath(points, pts_sz).translated(half_res));
poly_gizmo_->SetPath(GeneratePath(points, pts_sz).translated(QPointF(half_res.x, half_res.y)));
}
ShaderCode PolygonGenerator::GetShaderCode(const ShaderRequest &request) const
@@ -246,9 +246,11 @@ void PolygonGenerator::GizmoDragMove(double x, double y, const Qt::KeyboardModif
void PolygonGenerator::AddPointToPath(QPainterPath *path, const Bezier &before, const Bezier &after)
{
path->cubicTo(before.ToPointF() + before.ControlPoint2ToPointF(),
after.ToPointF() + after.ControlPoint1ToPointF(),
after.ToPointF());
Imath::V2d a = before.to_vec() + before.control_point_2_to_vec();
Imath::V2d b = after.to_vec() + after.control_point_1_to_vec();
Imath::V2d c = after.to_vec();
path->cubicTo(QPointF(a.x, a.y), QPointF(b.x, b.y), QPointF(c.x, c.y));
}
QPainterPath PolygonGenerator::GeneratePath(const NodeValueArray &points, int size)
@@ -257,7 +259,8 @@ QPainterPath PolygonGenerator::GeneratePath(const NodeValueArray &points, int si
if (!points.empty()) {
const Bezier &first_pt = points.at(0).toBezier();
path.moveTo(first_pt.ToPointF());
Imath::V2d v = first_pt.to_vec();
path.moveTo(QPointF(v.x, v.y));
for (int i=1; i<size; i++) {
AddPointToPath(&path, points.at(i-1).toBezier(), points.at(i).toBezier());
-1
View File
@@ -23,7 +23,6 @@
#include <QPainterPath>
#include "common/bezier.h"
#include "node/generator/shape/generatorwithmerge.h"
#include "node/gizmo/line.h"
#include "node/gizmo/path.h"
+1 -2
View File
@@ -20,12 +20,11 @@
#include "textv2.h"
#include <olive/core/core.h>
#include <QAbstractTextDocumentLayout>
#include <QDateTime>
#include <QTextDocument>
#include "common/cpuoptimize.h"
namespace olive {
#define super ShapeNodeBase
-1
View File
@@ -23,7 +23,6 @@
#include <QVector2D>
#include "render/audioparams.h"
#include "render/loopmode.h"
#include "render/videoparams.h"
-1
View File
@@ -20,7 +20,6 @@
#include "inputimmediate.h"
#include "common/bezier.h"
#include "common/lerp.h"
#include "common/tohex.h"
+1 -2
View File
@@ -23,7 +23,6 @@
#include <QMatrix4x4>
#include <QVector2D>
#include "common/cpuoptimize.h"
#include "common/tohex.h"
#include "node/distort/transform/transformdistortnode.h"
@@ -595,7 +594,7 @@ T MathNodeBase::PerformAll(Operation operation, T a, U b)
case kOpDivide:
return a / b;
case kOpPower:
return qPow(a, b);
return std::pow(a, b);
}
return a;
+6 -6
View File
@@ -83,22 +83,22 @@ void TrigonometryNode::Value(const NodeValueRow &value, const NodeGlobals &globa
switch (static_cast<Operation>(GetStandardValue(kMethodIn).toInt())) {
case kOpSine:
x = qSin(x);
x = std::sin(x);
break;
case kOpCosine:
x = qCos(x);
x = std::cos(x);
break;
case kOpTangent:
x = qTan(x);
x = std::tan(x);
break;
case kOpArcSine:
x = qAsin(x);
x = std::asin(x);
break;
case kOpArcCosine:
x = qAcos(x);
x = std::acos(x);
break;
case kOpArcTangent:
x = qAtan(x);
x = std::atan(x);
break;
case kOpHypSine:
x = std::sinh(x);
+11 -14
View File
@@ -25,7 +25,6 @@
#include <QDebug>
#include <QFile>
#include "common/bezier.h"
#include "common/lerp.h"
#include "core.h"
#include "config/config.h"
@@ -484,31 +483,29 @@ QVariant Node::GetSplitValueAtTimeOnTrack(const QString &input, const rational &
// Perform a cubic bezier with two control points
interpolated = Bezier::CubicXtoY(time.toDouble(),
QPointF(before->time().toDouble(), before_val),
QPointF(before->time().toDouble() + before->valid_bezier_control_out().x(), before_val + before->valid_bezier_control_out().y()),
QPointF(after->time().toDouble() + after->valid_bezier_control_in().x(), after_val + after->valid_bezier_control_in().y()),
QPointF(after->time().toDouble(), after_val));
Imath::V2d(before->time().toDouble(), before_val),
Imath::V2d(before->time().toDouble() + before->valid_bezier_control_out().x(), before_val + before->valid_bezier_control_out().y()),
Imath::V2d(after->time().toDouble() + after->valid_bezier_control_in().x(), after_val + after->valid_bezier_control_in().y()),
Imath::V2d(after->time().toDouble(), after_val));
} else if (before->type() == NodeKeyframe::kBezier || after->type() == NodeKeyframe::kBezier) {
// Perform a quadratic bezier with only one control point
QPointF control_point;
Imath::V2d control_point;
if (before->type() == NodeKeyframe::kBezier) {
control_point = before->valid_bezier_control_out();
control_point.setX(control_point.x() + before->time().toDouble());
control_point.setY(control_point.y() + before_val);
control_point.x = (before->valid_bezier_control_out().x() + before->time().toDouble());
control_point.y = (before->valid_bezier_control_out().y() + before_val);
} else {
control_point = after->valid_bezier_control_in();
control_point.setX(control_point.x() + after->time().toDouble());
control_point.setY(control_point.y() + after_val);
control_point.x = (after->valid_bezier_control_in().x() + after->time().toDouble());
control_point.y = (after->valid_bezier_control_in().y() + after_val);
}
// Interpolate value using quadratic beziers
interpolated = Bezier::QuadraticXtoY(time.toDouble(),
QPointF(before->time().toDouble(), before_val),
Imath::V2d(before->time().toDouble(), before_val),
control_point,
QPointF(after->time().toDouble(), after_val));
Imath::V2d(after->time().toDouble(), after_val));
} else {
// To have arrived here, the keyframes must both be linear
-2
View File
@@ -29,14 +29,12 @@
#include <QXmlStreamWriter>
#include "codec/frame.h"
#include "codec/samplebuffer.h"
#include "common/xmlutils.h"
#include "node/gizmo/draggable.h"
#include "node/globals.h"
#include "node/keyframe.h"
#include "node/inputimmediate.h"
#include "node/param.h"
#include "render/audioparams.h"
#include "render/audioplaybackcache.h"
#include "render/audiowaveformcache.h"
#include "render/framehashcache.h"
+6 -4
View File
@@ -32,6 +32,8 @@ const QString ViewerOutput::kSubtitleParamsInput = QStringLiteral("subtitle_para
const QString ViewerOutput::kTextureInput = QStringLiteral("tex_in");
const QString ViewerOutput::kSamplesInput = QStringLiteral("samples_in");
const SampleFormat ViewerOutput::kDefaultSampleFormat = SampleFormat::F32P;
#define super Node
ViewerOutput::ViewerOutput(bool create_buffer_inputs, bool create_default_streams) :
@@ -213,9 +215,9 @@ void ViewerOutput::set_default_parameters()
VideoParams::generate_auto_divider(width, height)
));
SetAudioParams(AudioParams(
OLIVE_CONFIG("DefaultSequenceAudioFrequency").toInt(),
OLIVE_CONFIG("DefaultSequenceAudioLayout").toULongLong(),
AudioParams::kInternalFormat
OLIVE_CONFIG("DefaultSequenceAudioFrequency").toInt(),
OLIVE_CONFIG("DefaultSequenceAudioLayout").toULongLong(),
kDefaultSampleFormat
));
}
@@ -518,7 +520,7 @@ void ViewerOutput::set_parameters_from_footage(const QVector<ViewerOutput *> foo
if (!audio_streams.isEmpty()) {
const AudioParams& s = audio_streams.first();
SetAudioParams(AudioParams(s.sample_rate(), s.channel_layout(), AudioParams::kInternalFormat));
SetAudioParams(AudioParams(s.sample_rate(), s.channel_layout(), kDefaultSampleFormat));
}
}
}
+2 -1
View File
@@ -24,7 +24,6 @@
#include "codec/encoder.h"
#include "node/node.h"
#include "node/output/track/track.h"
#include "render/audioparams.h"
#include "render/audioplaybackcache.h"
#include "render/framehashcache.h"
#include "render/subtitleparams.h"
@@ -200,6 +199,8 @@ public:
static const QString kTextureInput;
static const QString kSamplesInput;
static const SampleFormat kDefaultSampleFormat;
signals:
void FrameRateChanged(const rational&);
+1 -2
View File
@@ -25,7 +25,6 @@
#include <QStandardPaths>
#include "codec/decoder.h"
#include "common/clamp.h"
#include "common/filefunctions.h"
#include "common/qtutils.h"
#include "common/xmlutils.h"
@@ -352,7 +351,7 @@ rational Footage::AdjustTimeByLoopMode(rational time, LoopMode loop_mode, const
break;
case LoopMode::kLoopModeClamp:
// Clamp footage time to length
time = clamp(time, rational(0), length - timebase);
time = std::clamp(time, rational(0), length - timebase);
break;
case LoopMode::kLoopModeLoop:
// Loop footage time around job length
-1
View File
@@ -28,7 +28,6 @@
#include "codec/decoder.h"
#include "footagedescription.h"
#include "node/output/viewer/viewer.h"
#include "render/audioparams.h"
#include "render/cancelatom.h"
#include "render/videoparams.h"
@@ -25,6 +25,7 @@
#include <QXmlStreamWriter>
#include "common/xmlutils.h"
#include "node/project/serializer/typeserializer.h"
namespace olive {
@@ -74,8 +75,7 @@ bool FootageDescription::Load(const QString &filename)
vp.Load(&reader);
AddVideoStream(vp);
} else if (reader.name() == QStringLiteral("audio")) {
AudioParams ap;
ap.Load(&reader);
AudioParams ap = TypeSerializer::LoadAudioParams(&reader);
AddAudioStream(ap);
} else if (reader.name() == QStringLiteral("subtitle")) {
SubtitleParams sp;
@@ -136,7 +136,7 @@ bool FootageDescription::Save(const QString &filename) const
foreach (const AudioParams& ap, audio_streams_) {
writer.writeStartElement(QStringLiteral("audio"));
ap.Save(&writer);
TypeSerializer::SaveAudioParams(&writer, ap);
writer.writeEndElement(); // audio
}
@@ -22,7 +22,6 @@
#define FOOTAGEDESCRIPTION_H
#include "node/output/track/track.h"
#include "render/audioparams.h"
#include "render/subtitleparams.h"
#include "render/videoparams.h"
@@ -29,5 +29,9 @@ set(OLIVE_SOURCES
node/project/serializer/serializer211228.h
node/project/serializer/serializer220403.cpp
node/project/serializer/serializer220403.h
node/project/serializer/typeserializer.cpp
node/project/serializer/typeserializer.h
PARENT_SCOPE
)
+2 -1
View File
@@ -21,10 +21,11 @@
#ifndef PROJECTSERIALIZER_H
#define PROJECTSERIALIZER_H
#include <QIODevice>
#include <vector>
#include "common/define.h"
#include "node/project/project.h"
#include "typeserializer.h"
namespace olive {
@@ -328,8 +328,7 @@ void ProjectSerializer210528::LoadImmediate(QXmlStreamReader *reader, Node *node
vp.Load(reader);
value_on_track = QVariant::fromValue(vp);
} else if (data_type == NodeValue::kAudioParams) {
AudioParams ap;
ap.Load(reader);
AudioParams ap = TypeSerializer::LoadAudioParams(reader);
value_on_track = QVariant::fromValue(ap);
} else {
QString value_text = reader->readElementText();
@@ -325,8 +325,7 @@ void ProjectSerializer210907::LoadImmediate(QXmlStreamReader *reader, Node *node
vp.Load(reader);
value_on_track = QVariant::fromValue(vp);
} else if (data_type == NodeValue::kAudioParams) {
AudioParams ap;
ap.Load(reader);
AudioParams ap = TypeSerializer::LoadAudioParams(reader);
value_on_track = QVariant::fromValue(ap);
} else {
QString value_text = reader->readElementText();
@@ -375,8 +375,7 @@ void ProjectSerializer211228::LoadImmediate(QXmlStreamReader *reader, Node *node
vp.Load(reader);
value_on_track = QVariant::fromValue(vp);
} else if (data_type == NodeValue::kAudioParams) {
AudioParams ap;
ap.Load(reader);
AudioParams ap = TypeSerializer::LoadAudioParams(reader);
value_on_track = QVariant::fromValue(ap);
} else {
QString value_text = reader->readElementText();
@@ -774,8 +774,7 @@ void ProjectSerializer220403::LoadImmediate(QXmlStreamReader *reader, Node *node
vp.Load(reader);
value_on_track = QVariant::fromValue(vp);
} else if (data_type == NodeValue::kAudioParams) {
AudioParams ap;
ap.Load(reader);
AudioParams ap = TypeSerializer::LoadAudioParams(reader);
value_on_track = QVariant::fromValue(ap);
} else {
QString value_text = reader->readElementText();
@@ -857,7 +856,7 @@ void ProjectSerializer220403::SaveImmediate(QXmlStreamWriter *writer, Node *node
if (data_type == NodeValue::kVideoParams) {
v.value<VideoParams>().Save(writer);
} else if (data_type == NodeValue::kAudioParams) {
v.value<AudioParams>().Save(writer);
TypeSerializer::SaveAudioParams(writer, v.value<AudioParams>());
} else {
writer->writeCharacters(NodeValue::ValueToString(data_type, v, true));
}
@@ -0,0 +1,63 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2023 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 "typeserializer.h"
namespace olive {
AudioParams TypeSerializer::LoadAudioParams(QXmlStreamReader *reader)
{
AudioParams a;
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("samplerate")) {
a.set_sample_rate(reader->readElementText().toInt());
} else if (reader->name() == QStringLiteral("channellayout")) {
a.set_channel_layout(reader->readElementText().toULongLong());
} else if (reader->name() == QStringLiteral("format")) {
a.set_format(SampleFormat::from_string(reader->readElementText().toStdString()));
} else if (reader->name() == QStringLiteral("enabled")) {
a.set_enabled(reader->readElementText().toInt());
} else if (reader->name() == QStringLiteral("streamindex")) {
a.set_stream_index(reader->readElementText().toInt());
} else if (reader->name() == QStringLiteral("duration")) {
a.set_duration(reader->readElementText().toLongLong());
} else if (reader->name() == QStringLiteral("timebase")) {
a.set_time_base(rational::fromString(reader->readElementText().toStdString()));
} else {
reader->skipCurrentElement();
}
}
return a;
}
void TypeSerializer::SaveAudioParams(QXmlStreamWriter *writer, const AudioParams &a)
{
writer->writeTextElement(QStringLiteral("samplerate"), QString::number(a.sample_rate()));
writer->writeTextElement(QStringLiteral("channellayout"), QString::number(a.channel_layout()));
writer->writeTextElement(QStringLiteral("format"), QString::fromStdString(a.format().to_string()));
writer->writeTextElement(QStringLiteral("enabled"), QString::number(a.enabled()));
writer->writeTextElement(QStringLiteral("streamindex"), QString::number(a.stream_index()));
writer->writeTextElement(QStringLiteral("duration"), QString::number(a.duration()));
writer->writeTextElement(QStringLiteral("timebase"), QString::fromStdString(a.time_base().toString()));
}
}
@@ -0,0 +1,46 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2023 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 TYPESERIALIZER_H
#define TYPESERIALIZER_H
#include <olive/core/core.h>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "common/xmlutils.h"
namespace olive {
using namespace core;
class TypeSerializer
{
public:
TypeSerializer() = default;
static AudioParams LoadAudioParams(QXmlStreamReader *reader);
static void SaveAudioParams(QXmlStreamWriter *writer, const AudioParams &a);
};
}
#endif // TYPESERIALIZER_H
-2
View File
@@ -26,9 +26,7 @@
#include <QVector3D>
#include <QVector4D>
#include "common/bezier.h"
#include "common/tohex.h"
#include "render/audioparams.h"
#include "render/subtitleparams.h"
#include "render/videoparams.h"
-2
View File
@@ -26,8 +26,6 @@
#include <QVariant>
#include <QVector>
#include "codec/samplebuffer.h"
#include "common/bezier.h"
#include "common/qtutils.h"
#include "node/splitvalue.h"
#include "render/texture.h"