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
+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