diff --git a/app/audio/audiomanager.cpp b/app/audio/audiomanager.cpp index fc0dc886d..47b3e84a8 100644 --- a/app/audio/audiomanager.cpp +++ b/app/audio/audiomanager.cpp @@ -73,7 +73,7 @@ int InputCallback(const void *input, void *output, unsigned long frameCount, con FFmpegEncoder *f = static_cast(userData); AudioParams our_params = f->params().audio_params(); - our_params.set_format(AudioParams::GetPackedEquivalent(f->params().audio_params().format())); + our_params.set_format(f->params().audio_params().format().to_packed_equivalent()); f->WriteAudioData(our_params, reinterpret_cast(&input), frameCount); @@ -119,27 +119,27 @@ void AudioManager::ClearBufferedOutput() output_buffer_->clear(); } -PaSampleFormat AudioManager::GetPortAudioSampleFormat(AudioParams::Format fmt) +PaSampleFormat AudioManager::GetPortAudioSampleFormat(SampleFormat fmt) { switch (fmt) { - case AudioParams::kFormatUnsigned8Packed: - case AudioParams::kFormatUnsigned8Planar: + case SampleFormat::U8: + case SampleFormat::U8P: return paUInt8; - case AudioParams::kFormatSigned16Packed: - case AudioParams::kFormatSigned16Planar: + case SampleFormat::S16: + case SampleFormat::S16P: return paInt16; - case AudioParams::kFormatSigned32Packed: - case AudioParams::kFormatSigned32Planar: + case SampleFormat::S32: + case SampleFormat::S32P: return paInt32; - case AudioParams::kFormatFloat32Packed: - case AudioParams::kFormatFloat32Planar: + case SampleFormat::F32: + case SampleFormat::F32P: return paFloat32; - case AudioParams::kFormatSigned64Packed: - case AudioParams::kFormatSigned64Planar: - case AudioParams::kFormatFloat64Packed: - case AudioParams::kFormatFloat64Planar: - case AudioParams::kFormatInvalid: - case AudioParams::kFormatCount: + case SampleFormat::S64: + case SampleFormat::S64P: + case SampleFormat::F64: + case SampleFormat::F64P: + case SampleFormat::INVALID: + case SampleFormat::COUNT: break; } diff --git a/app/audio/audiomanager.h b/app/audio/audiomanager.h index 3c35e0593..7f47d979c 100644 --- a/app/audio/audiomanager.h +++ b/app/audio/audiomanager.h @@ -30,7 +30,6 @@ #include "audio/audioprocessor.h" #include "common/define.h" #include "codec/ffmpeg/ffmpegencoder.h" -#include "render/audioparams.h" #include "render/audioplaybackcache.h" #include "render/previewaudiodevice.h" @@ -94,7 +93,7 @@ private: virtual ~AudioManager() override; - static PaSampleFormat GetPortAudioSampleFormat(AudioParams::Format fmt); + static PaSampleFormat GetPortAudioSampleFormat(SampleFormat fmt); void CloseOutputStream(); diff --git a/app/audio/audioprocessor.cpp b/app/audio/audioprocessor.cpp index 7d451cd44..cddf5aed9 100644 --- a/app/audio/audioprocessor.cpp +++ b/app/audio/audioprocessor.cpp @@ -90,13 +90,13 @@ bool AudioProcessor::Open(const AudioParams &from, const AudioParams &to, double double speed_log = log(tempo) / log(base); // This is the number of how many 0.5 or 2.0 tempos we need to daisychain - int whole = qFloor(speed_log); + int whole = std::floor(speed_log); // Set speed_log to the remainder speed_log -= whole; for (int i=0;i<=whole;i++) { - double filter_tempo = (i == whole) ? qPow(base, speed_log) : base; + double filter_tempo = (i == whole) ? std::pow(base, speed_log) : base; if (qFuzzyCompare(filter_tempo, 1.0)) { // This filter would do nothing @@ -117,7 +117,7 @@ bool AudioProcessor::Open(const AudioParams &from, const AudioParams &to, double // Create conversion filter if (from.sample_rate() != to.sample_rate() || from.channel_layout() != to.channel_layout() || from.format() != to.format() - || (to.FormatIsPlanar() && create_tempo)) { // Tempo processor automatically converts to packed, + || (to.format().is_planar() && create_tempo)) { // Tempo processor automatically converts to packed, // so if the desired output is planar, it'll need // to be converted snprintf(filter_args, 200, "sample_fmts=%s:sample_rates=%d:channel_layouts=0x%" PRIx64, @@ -238,7 +238,7 @@ int AudioProcessor::Convert(float **in, int nb_in_samples, AudioProcessor::Buffe if (output) { int nb_channels = to_.channel_count(); - if (to_.FormatIsPacked()) { + if (to_.format().is_packed()) { nb_channels = 1; } @@ -261,7 +261,7 @@ int AudioProcessor::Convert(float **in, int nb_in_samples, AudioProcessor::Buffe } int nb_bytes = out_frame_->nb_samples * to_.bytes_per_sample_per_channel(); - if (to_.FormatIsPacked()) { + if (to_.format().is_packed()) { nb_bytes *= to_.channel_count(); } diff --git a/app/audio/audioprocessor.h b/app/audio/audioprocessor.h index d67b612cf..a92e7627f 100644 --- a/app/audio/audioprocessor.h +++ b/app/audio/audioprocessor.h @@ -22,16 +22,19 @@ #define AUDIOPROCESSOR_H #include +#include +#include extern "C" { #include } #include "common/define.h" -#include "render/audioparams.h" namespace olive { +using namespace core; + class AudioProcessor { public: diff --git a/app/audio/audiovisualwaveform.cpp b/app/audio/audiovisualwaveform.cpp index f6f0e4db4..fbe4d6120 100644 --- a/app/audio/audiovisualwaveform.cpp +++ b/app/audio/audiovisualwaveform.cpp @@ -24,7 +24,6 @@ #include #include "config/config.h" -#include "common/cpuoptimize.h" namespace olive { @@ -459,8 +458,8 @@ void AudioVisualWaveform::DrawWaveform(QPainter *painter, const QRect& rect, con break; } - next_sample_index = qMin(arr.size(), - start_sample_index + qFloor(rate_dbl * static_cast(i - rect.x() + 1) / scale) * samples.channel_count()); + next_sample_index = std::min(arr.size(), + size_t(start_sample_index + std::floor(rate_dbl * static_cast(i - rect.x() + 1) / scale) * samples.channel_count())); if (summary_index != sample_index) { summary = AudioVisualWaveform::ReSumSamples(&arr.at(sample_index), @@ -480,7 +479,7 @@ size_t AudioVisualWaveform::time_to_samples(const rational &time, double sample_ size_t AudioVisualWaveform::time_to_samples(const double &time, double sample_rate) const { - return qFloor(time * sample_rate) * channels_; + return std::floor(time * sample_rate) * channels_; } std::map::const_iterator AudioVisualWaveform::GetMipmapForScale(double scale) const diff --git a/app/audio/audiovisualwaveform.h b/app/audio/audiovisualwaveform.h index 8f34961a1..a75e46a2d 100644 --- a/app/audio/audiovisualwaveform.h +++ b/app/audio/audiovisualwaveform.h @@ -21,13 +21,14 @@ #ifndef SUMSAMPLES_H #define SUMSAMPLES_H +#include #include #include -#include "codec/samplebuffer.h" - namespace olive { +using namespace core; + /** * @brief A buffer of data used to store a visual representation of audio * diff --git a/app/codec/CMakeLists.txt b/app/codec/CMakeLists.txt index 21733e110..608d82a08 100644 --- a/app/codec/CMakeLists.txt +++ b/app/codec/CMakeLists.txt @@ -33,7 +33,5 @@ set(OLIVE_SOURCES codec/frame.h codec/planarfiledevice.cpp codec/planarfiledevice.h - codec/samplebuffer.cpp - codec/samplebuffer.h PARENT_SCOPE ) diff --git a/app/codec/decoder.h b/app/codec/decoder.h index b67d22d75..de258296d 100644 --- a/app/codec/decoder.h +++ b/app/codec/decoder.h @@ -31,7 +31,6 @@ extern "C" { #include #include -#include "codec/samplebuffer.h" #include "node/block/block.h" #include "node/project/footage/footagedescription.h" #include "render/cancelatom.h" diff --git a/app/codec/encoder.cpp b/app/codec/encoder.cpp index afa14bb3f..810cdcd1b 100644 --- a/app/codec/encoder.cpp +++ b/app/codec/encoder.cpp @@ -257,7 +257,7 @@ void EncodingParams::Save(QXmlStreamWriter *writer) const writer->writeTextElement(QStringLiteral("codec"), QString::number(audio_codec_)); writer->writeTextElement(QStringLiteral("samplerate"), QString::number(audio_params_.sample_rate())); writer->writeTextElement(QStringLiteral("channellayout"), QString::number(audio_params_.channel_layout())); - writer->writeTextElement(QStringLiteral("format"), QString::number(audio_params_.format())); + writer->writeTextElement(QStringLiteral("format"), QString::fromStdString(audio_params_.format().to_string())); writer->writeTextElement(QStringLiteral("bitrate"), QString::number(audio_bit_rate_)); } @@ -337,9 +337,9 @@ QStringList Encoder::GetPixelFormatsForCodec(ExportCodec::Codec c) const return QStringList(); } -std::vector Encoder::GetSampleFormatsForCodec(ExportCodec::Codec c) const +std::vector Encoder::GetSampleFormatsForCodec(ExportCodec::Codec c) const { - return std::vector(); + return std::vector(); } QMatrix4x4 EncodingParams::GenerateMatrix(EncodingParams::VideoScalingMethod method, @@ -471,7 +471,7 @@ bool EncodingParams::LoadV1(QXmlStreamReader *reader) } else if (reader->name() == QStringLiteral("channellayout")) { audio_params_.set_channel_layout(reader->readElementText().toULongLong()); } else if (reader->name() == QStringLiteral("format")) { - audio_params_.set_format(static_cast(reader->readElementText().toInt())); + audio_params_.set_format(SampleFormat::from_string(reader->readElementText().toStdString())); } else if (reader->name() == QStringLiteral("bitrate")) { audio_bit_rate_ = reader->readElementText().toLongLong(); } else { diff --git a/app/codec/encoder.h b/app/codec/encoder.h index 3e952441b..65702a36f 100644 --- a/app/codec/encoder.h +++ b/app/codec/encoder.h @@ -29,9 +29,7 @@ #include "codec/exportcodec.h" #include "codec/exportformat.h" #include "codec/frame.h" -#include "codec/samplebuffer.h" #include "node/block/subtitle/subtitle.h" -#include "render/audioparams.h" #include "render/colortransform.h" #include "render/subtitleparams.h" #include "render/videoparams.h" @@ -204,7 +202,7 @@ public: static Encoder *CreateFromParams(const EncodingParams ¶ms); virtual QStringList GetPixelFormatsForCodec(ExportCodec::Codec c) const; - virtual std::vector GetSampleFormatsForCodec(ExportCodec::Codec c) const; + virtual std::vector GetSampleFormatsForCodec(ExportCodec::Codec c) const; const EncodingParams& params() const; diff --git a/app/codec/exportformat.cpp b/app/codec/exportformat.cpp index 9b6997d78..6e91ff77e 100644 --- a/app/codec/exportformat.cpp +++ b/app/codec/exportformat.cpp @@ -218,9 +218,9 @@ QStringList ExportFormat::GetPixelFormatsForCodec(ExportFormat::Format f, Export return list; } -std::vector ExportFormat::GetSampleFormatsForCodec(Format format, ExportCodec::Codec c) +std::vector ExportFormat::GetSampleFormatsForCodec(Format format, ExportCodec::Codec c) { - std::vector f; + std::vector f; Encoder *e = Encoder::CreateFromFormat(format, EncodingParams()); if (e) { diff --git a/app/codec/exportformat.h b/app/codec/exportformat.h index 0fbf1d203..1ede4ab49 100644 --- a/app/codec/exportformat.h +++ b/app/codec/exportformat.h @@ -26,7 +26,6 @@ #include "common/define.h" #include "exportcodec.h" -#include "render/audioparams.h" namespace olive { @@ -62,7 +61,7 @@ public: static QList GetSubtitleCodecs(ExportFormat::Format f); static QStringList GetPixelFormatsForCodec(Format f, ExportCodec::Codec c); - static std::vector GetSampleFormatsForCodec(Format f, ExportCodec::Codec c); + static std::vector GetSampleFormatsForCodec(Format f, ExportCodec::Codec c); }; diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index 8106cb0a1..30db4ec5d 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -468,7 +468,7 @@ FootageDescription FFmpegDecoder::Probe(const QString &filename, CancelAtom *can stream.set_stream_index(i); stream.set_channel_layout(channel_layout); stream.set_sample_rate(avstream->codecpar->sample_rate); - stream.set_format(AudioParams::kInternalFormat); + stream.set_format(FFmpegUtils::GetNativeSampleFormat(static_cast(avstream->codecpar->format))); stream.set_time_base(avstream->time_base); stream.set_duration(avstream->duration); desc.AddAudioStream(stream); diff --git a/app/codec/ffmpeg/ffmpegencoder.cpp b/app/codec/ffmpeg/ffmpegencoder.cpp index c3be3c534..d5360390d 100644 --- a/app/codec/ffmpeg/ffmpegencoder.cpp +++ b/app/codec/ffmpeg/ffmpegencoder.cpp @@ -52,7 +52,7 @@ QStringList FFmpegEncoder::GetPixelFormatsForCodec(ExportCodec::Codec c) const { QStringList pix_fmts; - const AVCodec* codec_info = GetEncoder(c, AudioParams::kFormatInvalid); + const AVCodec* codec_info = GetEncoder(c, SampleFormat::INVALID); if (codec_info) { for (int i=0; codec_info->pix_fmts[i]!=-1; i++) { @@ -69,29 +69,29 @@ QStringList FFmpegEncoder::GetPixelFormatsForCodec(ExportCodec::Codec c) const return pix_fmts; } -std::vector FFmpegEncoder::GetSampleFormatsForCodec(ExportCodec::Codec c) const +std::vector FFmpegEncoder::GetSampleFormatsForCodec(ExportCodec::Codec c) const { - std::vector f; + std::vector f; if (c == ExportCodec::kCodecPCM) { // FFmpeg lists these as separate codecs so we need custom functionality here // We list signed 16 first because ExportDialog will always use the first element by default - // (because first element is the "default" in FFmpeg) + // (because first element is the "default" in tFFmpeg) f = { - AudioParams::kFormatSigned16Packed, - AudioParams::kFormatUnsigned8Packed, - AudioParams::kFormatSigned32Packed, - AudioParams::kFormatSigned64Packed, - AudioParams::kFormatFloat32Packed, - AudioParams::kFormatFloat64Packed + SampleFormat::S16, + SampleFormat::U8, + SampleFormat::S32, + SampleFormat::S64, + SampleFormat::F32, + SampleFormat::F64 }; } else { - const AVCodec* codec_info = GetEncoder(c, AudioParams::kFormatInvalid); + const AVCodec* codec_info = GetEncoder(c, SampleFormat::INVALID); if (codec_info && codec_info->sample_fmts) { for (int i=0; codec_info->sample_fmts[i]!=-1; i++) { - AudioParams::Format this_format = FFmpegUtils::GetNativeSampleFormat(static_cast(codec_info->sample_fmts[i])); - if (this_format != AudioParams::kFormatInvalid) { + SampleFormat this_format = FFmpegUtils::GetNativeSampleFormat(static_cast(codec_info->sample_fmts[i])); + if (this_format != SampleFormat::INVALID) { f.push_back(this_format); } } @@ -881,7 +881,7 @@ bool FFmpegEncoder::InitializeResampleContext(const AudioParams &audio) return true; } -const AVCodec *FFmpegEncoder::GetEncoder(ExportCodec::Codec c, AudioParams::Format aformat) +const AVCodec *FFmpegEncoder::GetEncoder(ExportCodec::Codec c, SampleFormat aformat) { switch (c) { case ExportCodec::kCodecH264: @@ -912,26 +912,26 @@ const AVCodec *FFmpegEncoder::GetEncoder(ExportCodec::Codec c, AudioParams::Form return avcodec_find_encoder(AV_CODEC_ID_AAC); case ExportCodec::kCodecPCM: switch (aformat) { - case AudioParams::kFormatInvalid: - case AudioParams::kFormatCount: - case AudioParams::kFormatUnsigned8Planar: - case AudioParams::kFormatSigned16Planar: - case AudioParams::kFormatSigned32Planar: - case AudioParams::kFormatSigned64Planar: - case AudioParams::kFormatFloat32Planar: - case AudioParams::kFormatFloat64Planar: + case SampleFormat::INVALID: + case SampleFormat::COUNT: + case SampleFormat::U8P: + case SampleFormat::S16P: + case SampleFormat::S32P: + case SampleFormat::S64P: + case SampleFormat::F32P: + case SampleFormat::F64P: break; - case AudioParams::kFormatUnsigned8Packed: + case SampleFormat::U8: return avcodec_find_encoder(AV_CODEC_ID_PCM_U8); - case AudioParams::kFormatSigned16Packed: + case SampleFormat::S16: return avcodec_find_encoder(AV_CODEC_ID_PCM_S16LE); - case AudioParams::kFormatSigned32Packed: + case SampleFormat::S32: return avcodec_find_encoder(AV_CODEC_ID_PCM_S32LE); - case AudioParams::kFormatSigned64Packed: + case SampleFormat::S64: return avcodec_find_encoder(AV_CODEC_ID_PCM_S64LE); - case AudioParams::kFormatFloat32Packed: + case SampleFormat::F32: return avcodec_find_encoder(AV_CODEC_ID_PCM_F32LE); - case AudioParams::kFormatFloat64Packed: + case SampleFormat::F64: return avcodec_find_encoder(AV_CODEC_ID_PCM_F64LE); } break; diff --git a/app/codec/ffmpeg/ffmpegencoder.h b/app/codec/ffmpeg/ffmpegencoder.h index 18ee18923..3c1ec49ed 100644 --- a/app/codec/ffmpeg/ffmpegencoder.h +++ b/app/codec/ffmpeg/ffmpegencoder.h @@ -41,7 +41,7 @@ public: virtual QStringList GetPixelFormatsForCodec(ExportCodec::Codec c) const override; - virtual std::vector GetSampleFormatsForCodec(ExportCodec::Codec c) const override; + virtual std::vector GetSampleFormatsForCodec(ExportCodec::Codec c) const override; virtual bool Open() override; @@ -82,7 +82,7 @@ private: bool InitializeResampleContext(const AudioParams &audio); - static const AVCodec *GetEncoder(ExportCodec::Codec c, AudioParams::Format aformat); + static const AVCodec *GetEncoder(ExportCodec::Codec c, SampleFormat aformat); AVFormatContext* fmt_ctx_; diff --git a/app/codec/planarfiledevice.h b/app/codec/planarfiledevice.h index 00da3a454..feaf2c647 100644 --- a/app/codec/planarfiledevice.h +++ b/app/codec/planarfiledevice.h @@ -21,14 +21,14 @@ #ifndef PLANARFILEDEVICE_H #define PLANARFILEDEVICE_H +#include #include #include -#include "codec/samplebuffer.h" -#include "common/define.h" - namespace olive { +using namespace core; + class PlanarFileDevice : public QObject { Q_OBJECT diff --git a/app/codec/samplebuffer.cpp b/app/codec/samplebuffer.cpp deleted file mode 100644 index f67c95e90..000000000 --- a/app/codec/samplebuffer.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 . - -***/ - -#include "samplebuffer.h" - -#include - -#include "common/cpuoptimize.h" - -namespace olive { - -SampleBuffer::SampleBuffer() : - sample_count_per_channel_(0) -{ -} - -SampleBuffer::SampleBuffer(const AudioParams &audio_params, const rational &length) : - audio_params_(audio_params) -{ - sample_count_per_channel_ = audio_params_.time_to_samples(length); - allocate(); -} - -SampleBuffer::SampleBuffer(const AudioParams &audio_params, size_t samples_per_channel) : - audio_params_(audio_params), - sample_count_per_channel_(samples_per_channel) -{ - allocate(); -} - -const AudioParams &SampleBuffer::audio_params() const -{ - return audio_params_; -} - -void SampleBuffer::set_audio_params(const AudioParams ¶ms) -{ - if (is_allocated()) { - qWarning() << "Tried to set parameters on allocated sample buffer"; - return; - } - - audio_params_ = params; -} - -void SampleBuffer::set_sample_count(const size_t &sample_count) -{ - if (is_allocated()) { - qWarning() << "Tried to set sample count on allocated sample buffer"; - return; - } - - sample_count_per_channel_ = sample_count; -} - -void SampleBuffer::allocate() -{ - if (!audio_params_.is_valid()) { - qWarning() << "Tried to allocate sample buffer with invalid audio parameters"; - return; - } - - if (!sample_count_per_channel_) { - qWarning() << "Tried to allocate sample buffer with zero sample count"; - return; - } - - if (is_allocated()) { - qWarning() << "Tried to allocate already allocated sample buffer"; - return; - } - - data_.resize(audio_params_.channel_count()); - for (int i=0; i(sample_count_per_channel_) / speed); - - std::vector< std::vector > output_data; - - output_data.resize(audio_params_.channel_count()); - for (int i=0; i(i) * speed); - - for (int j=0;j(data_[i].data()) + start_byte, 0, end_byte - start_byte); - } -} - -void SampleBuffer::set(int channel, const float *data, size_t sample_offset, size_t sample_length) -{ - if (!is_allocated()) { - qWarning() << "Tried to fill an unallocated sample buffer"; - return; - } - - memcpy(&data_[channel].data()[sample_offset], data, sizeof(float) * sample_length); -} - -void SampleBuffer::clamp_channel(int channel) -{ - const float min = -1.0f; - const float max = 1.0f; - - float *cdat = data_[channel].data(); - size_t unopt_start = 0; - -#if defined(Q_PROCESSOR_X86) || defined(Q_PROCESSOR_ARM) - __m128 min_sse = _mm_load1_ps(&min); - __m128 max_sse = _mm_load1_ps(&max); - - unopt_start = (sample_count_per_channel_ / 4) * 4; - for (size_t j=0; j. - -***/ - -#ifndef SAMPLEBUFFER_H -#define SAMPLEBUFFER_H - -#include - -#include "render/audioparams.h" - -namespace olive { - -/** - * @brief A buffer of audio samples - * - * Audio samples in this structure are always stored in PLANAR (separated by channel). This is done to simplify audio - * rendering code. This replaces the old system of using QByteArrays (containing packed audio) and while SampleBuffer - * replaces many of those in the rendering/processing side of things, QByteArrays are currently still in use for - * playback, including reading to and from the cache. - */ -class SampleBuffer -{ -public: - SampleBuffer(); - SampleBuffer(const AudioParams& audio_params, const rational& length); - SampleBuffer(const AudioParams& audio_params, size_t samples_per_channel); - - const AudioParams& audio_params() const; - void set_audio_params(const AudioParams& params); - - const size_t &sample_count() const { return sample_count_per_channel_; } - void set_sample_count(const size_t &sample_count); - void set_sample_count(const rational &length) - { - set_sample_count(audio_params_.time_to_samples(length)); - } - - float* data(int channel) - { - return data_[channel].data(); - } - - const float* data(int channel) const - { - return data_.at(channel).data(); - } - - std::vector to_raw_ptrs() - { - std::vector r(data_.size()); - for (size_t i=0; i > data_; - -}; - -} - -Q_DECLARE_METATYPE(olive::SampleBuffer) - -#endif // SAMPLEBUFFER_H diff --git a/app/common/CMakeLists.txt b/app/common/CMakeLists.txt index b503de134..68155d78a 100644 --- a/app/common/CMakeLists.txt +++ b/app/common/CMakeLists.txt @@ -16,11 +16,8 @@ set(OLIVE_SOURCES ${OLIVE_SOURCES} - common/bezier.cpp - common/bezier.h common/cancelableobject.h common/channellayout.h - common/clamp.h common/commandlineparser.cpp common/commandlineparser.h common/crashpadinterface.cpp diff --git a/app/common/bezier.cpp b/app/common/bezier.cpp deleted file mode 100644 index 0636df355..000000000 --- a/app/common/bezier.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 . - -***/ - -#include "bezier.h" - -#include - -#include "common/clamp.h" - -namespace olive { - -Bezier::Bezier() : - x_(0), - y_(0), - cp1_x_(0), - cp1_y_(0), - cp2_x_(0), - cp2_y_(0) -{ -} - -Bezier::Bezier(double x, double y) : - x_(x), - y_(y), - cp1_x_(0), - cp1_y_(0), - cp2_x_(0), - cp2_y_(0) -{ -} - -Bezier::Bezier(double x, double y, double cp1_x, double cp1_y, double cp2_x, double cp2_y) : - x_(x), - y_(y), - cp1_x_(cp1_x), - cp1_y_(cp1_y), - cp2_x_(cp2_x), - cp2_y_(cp2_y) -{ -} - -double Bezier::QuadraticXtoT(double x, double a, double b, double c) -{ - // Clamp to prevent infinite loop - x = clamp(x, a, c); - - return CalculateTFromX(false, x, a, b, c, 0); -} - -double Bezier::QuadraticTtoY(double a, double b, double c, double t) -{ - return qPow(1.0 - t, 2)*a + 2*(1.0 - t)*t*b + qPow(t, 2)*c; -} - -double Bezier::CubicXtoT(double x, double a, double b, double c, double d) -{ - // Clamp to prevent infinite loop - x = clamp(x, a, d); - - return CalculateTFromX(true, x, a, b, c, d); -} - -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; -} - -double Bezier::CalculateTFromX(bool cubic, double x, double a, double b, double c, double d) -{ - double bottom = 0.0; - double top = 1.0; - - while (true) { - if (bottom == top) { - return bottom; - } - - double mid = (bottom + top) * 0.5; - double test = cubic ? CubicTtoY(a, b, c, d, mid) : QuadraticTtoY(a, b, c, mid); - - if (qAbs(test - x) < 0.000001) { - return mid; - } else if (x > test) { - bottom = mid; - } else { - top = mid; - } - } - - return qSNaN(); -} - -} diff --git a/app/common/bezier.h b/app/common/bezier.h deleted file mode 100644 index 52b984a04..000000000 --- a/app/common/bezier.h +++ /dev/null @@ -1,103 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 . - -***/ - -#ifndef BEZIER_H -#define BEZIER_H - -#include -#include - -#include "common/define.h" - -namespace olive { - -class Bezier -{ -public: - Bezier(); - Bezier(double x, double y); - Bezier(double x, double y, double cp1_x, double cp1_y, double cp2_x, double cp2_y); - - const double &x() const {return x_; } - const double &y() const {return y_; } - const double &cp1_x() const { return cp1_x_; } - const double &cp1_y() const { return cp1_y_; } - const double &cp2_x() const { return cp2_x_; } - const double &cp2_y() const { return cp2_y_; } - - QPointF ToPointF() const - { - return QPointF(x_, y_); - } - - QPointF ControlPoint1ToPointF() const - { - return QPointF(cp1_x_, cp1_y_); - } - - QPointF ControlPoint2ToPointF() const - { - return QPointF(cp2_x_, cp2_y_); - } - - void set_x(const double &x) { x_ = x; } - void set_y(const double &y) { y_ = y; } - void set_cp1_x(const double &cp1_x) { cp1_x_ = cp1_x; } - void set_cp1_y(const double &cp1_y) { cp1_y_ = cp1_y; } - void set_cp2_x(const double &cp2_x) { cp2_x_ = cp2_x; } - void set_cp2_y(const double &cp2_y) { cp2_y_ = cp2_y; } - - static double QuadraticXtoT(double x, double a, double b, double c); - - static double QuadraticTtoY(double a, double b, double c, double t); - - static double QuadraticXtoY(double x, const QPointF &a, const QPointF &b, const QPointF &c) - { - return QuadraticTtoY(a.y(), b.y(), c.y(), QuadraticXtoT(x, a.x(), b.x(), c.x())); - } - - static double CubicXtoT(double x, double a, double b, double c, double d); - - static double CubicTtoY(double a, double b, double c, double d, double t); - - static double CubicXtoY(double x, const QPointF &a, const QPointF &b, const QPointF &c, const QPointF &d) - { - return CubicTtoY(a.y(), b.y(), c.y(), d.y(), CubicXtoT(x, a.x(), b.x(), c.x(), d.x())); - } - -private: - static double CalculateTFromX(bool cubic, double x, double a, double b, double c, double d); - - double x_; - double y_; - - double cp1_x_; - double cp1_y_; - - double cp2_x_; - double cp2_y_; - -}; - -} - -Q_DECLARE_METATYPE(olive::Bezier) - -#endif // BEZIER_H diff --git a/app/common/clamp.h b/app/common/clamp.h deleted file mode 100644 index 9f8cf78d2..000000000 --- a/app/common/clamp.h +++ /dev/null @@ -1,47 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 . - -***/ - -#ifndef CLAMP_H -#define CLAMP_H - -template -/** - * @brief Clamp a value between a minimum and a maximum value - * - * Similar to using min() and max() functions, but performs both at once. If value is less than minimum, this returns - * minimum. If it is more than maximum, this returns maximum. Otherwise it returns value as-is. - * - * @return - * - * Will always return a value between minimum and maximum (inclusive). - */ -T clamp(T value, T minimum, T maximum) { - if (value < minimum) { - return minimum; - } - - if (value > maximum) { - return maximum; - } - - return value; -} - -#endif // CLAMP_H diff --git a/app/common/ffmpegutils.cpp b/app/common/ffmpegutils.cpp index 3ded0bbc9..81ae18b4f 100644 --- a/app/common/ffmpegutils.cpp +++ b/app/common/ffmpegutils.cpp @@ -41,70 +41,70 @@ AVPixelFormat FFmpegUtils::GetCompatiblePixelFormat(const AVPixelFormat &pix_fmt nullptr); } -AudioParams::Format FFmpegUtils::GetNativeSampleFormat(const AVSampleFormat &smp_fmt) +SampleFormat FFmpegUtils::GetNativeSampleFormat(const AVSampleFormat &smp_fmt) { switch (smp_fmt) { case AV_SAMPLE_FMT_U8: - return AudioParams::kFormatUnsigned8Packed; + return SampleFormat::U8; case AV_SAMPLE_FMT_S16: - return AudioParams::kFormatSigned16Packed; + return SampleFormat::S16; case AV_SAMPLE_FMT_S32: - return AudioParams::kFormatSigned32Packed; + return SampleFormat::S32; case AV_SAMPLE_FMT_S64: - return AudioParams::kFormatSigned64Packed; + return SampleFormat::S64; case AV_SAMPLE_FMT_FLT: - return AudioParams::kFormatFloat32Packed; + return SampleFormat::F32; case AV_SAMPLE_FMT_DBL: - return AudioParams::kFormatFloat64Packed; + return SampleFormat::F64; case AV_SAMPLE_FMT_U8P : - return AudioParams::kFormatUnsigned8Planar; + return SampleFormat::U8P; case AV_SAMPLE_FMT_S16P: - return AudioParams::kFormatSigned16Planar; + return SampleFormat::S16P; case AV_SAMPLE_FMT_S32P: - return AudioParams::kFormatSigned32Planar; + return SampleFormat::S32P; case AV_SAMPLE_FMT_S64P: - return AudioParams::kFormatSigned64Planar; + return SampleFormat::S64P; case AV_SAMPLE_FMT_FLTP: - return AudioParams::kFormatFloat32Planar; + return SampleFormat::F32P; case AV_SAMPLE_FMT_DBLP: - return AudioParams::kFormatFloat64Planar; + return SampleFormat::F64P; case AV_SAMPLE_FMT_NONE: case AV_SAMPLE_FMT_NB: break; } - return AudioParams::kFormatInvalid; + return SampleFormat::INVALID; } -AVSampleFormat FFmpegUtils::GetFFmpegSampleFormat(const AudioParams::Format &smp_fmt) +AVSampleFormat FFmpegUtils::GetFFmpegSampleFormat(const SampleFormat &smp_fmt) { switch (smp_fmt) { - case AudioParams::kFormatUnsigned8Packed: + case SampleFormat::U8: return AV_SAMPLE_FMT_U8; - case AudioParams::kFormatSigned16Packed: + case SampleFormat::S16: return AV_SAMPLE_FMT_S16; - case AudioParams::kFormatSigned32Packed: + case SampleFormat::S32: return AV_SAMPLE_FMT_S32; - case AudioParams::kFormatSigned64Packed: + case SampleFormat::S64: return AV_SAMPLE_FMT_S64; - case AudioParams::kFormatFloat32Packed: + case SampleFormat::F32: return AV_SAMPLE_FMT_FLT; - case AudioParams::kFormatFloat64Packed: + case SampleFormat::F64: return AV_SAMPLE_FMT_DBL; - case AudioParams::kFormatUnsigned8Planar: + case SampleFormat::U8P: return AV_SAMPLE_FMT_U8P; - case AudioParams::kFormatSigned16Planar: + case SampleFormat::S16P: return AV_SAMPLE_FMT_S16P; - case AudioParams::kFormatSigned32Planar: + case SampleFormat::S32P: return AV_SAMPLE_FMT_S32P; - case AudioParams::kFormatSigned64Planar: + case SampleFormat::S64P: return AV_SAMPLE_FMT_S64P; - case AudioParams::kFormatFloat32Planar: + case SampleFormat::F32P: return AV_SAMPLE_FMT_FLTP; - case AudioParams::kFormatFloat64Planar: + case SampleFormat::F64P: return AV_SAMPLE_FMT_DBLP; - case AudioParams::kFormatInvalid: - case AudioParams::kFormatCount: + case SampleFormat::INVALID: + case SampleFormat::COUNT: break; } @@ -159,7 +159,7 @@ AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const PixelFormat &pix_fmt, int case PixelFormat::F16: case PixelFormat::F32: case PixelFormat::INVALID: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: break; } } else if (channel_layout == VideoParams::kRGBAChannelCount) { @@ -171,7 +171,7 @@ AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const PixelFormat &pix_fmt, int case PixelFormat::F16: case PixelFormat::F32: case PixelFormat::INVALID: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: break; } } @@ -189,7 +189,7 @@ PixelFormat FFmpegUtils::GetCompatiblePixelFormat(const PixelFormat &pix_fmt) case PixelFormat::F32: return PixelFormat::U16; case PixelFormat::INVALID: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: break; } diff --git a/app/common/ffmpegutils.h b/app/common/ffmpegutils.h index 2f0813524..89252fd53 100644 --- a/app/common/ffmpegutils.h +++ b/app/common/ffmpegutils.h @@ -27,11 +27,14 @@ extern "C" { #include } -#include "render/audioparams.h" +#include + #include "render/videoparams.h" namespace olive { +using namespace core; + class FFmpegUtils { public: /** @@ -52,12 +55,12 @@ public: /** * @brief Returns a native sample format type for a given AVSampleFormat */ - static AudioParams::Format GetNativeSampleFormat(const AVSampleFormat& smp_fmt); + static SampleFormat 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); + static AVSampleFormat GetFFmpegSampleFormat(const SampleFormat &smp_fmt); /** * @brief Returns an SWS_CS_* macro from an AVColorSpace enum member diff --git a/app/common/ocioutils.cpp b/app/common/ocioutils.cpp index 7b5414436..fc7cda122 100644 --- a/app/common/ocioutils.cpp +++ b/app/common/ocioutils.cpp @@ -37,7 +37,7 @@ OCIO::BitDepth OCIOUtils::GetOCIOBitDepthFromPixelFormat(PixelFormat format) return OCIO::BIT_DEPTH_F32; break; case PixelFormat::INVALID: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: break; } diff --git a/app/common/oiioutils.h b/app/common/oiioutils.h index e606531df..633758fe0 100644 --- a/app/common/oiioutils.h +++ b/app/common/oiioutils.h @@ -43,7 +43,7 @@ public: case PixelFormat::F32: return OIIO::TypeDesc::FLOAT; case PixelFormat::INVALID: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: break; } diff --git a/app/common/qtutils.cpp b/app/common/qtutils.cpp index 12935e350..495c95047 100644 --- a/app/common/qtutils.cpp +++ b/app/common/qtutils.cpp @@ -22,8 +22,6 @@ #include -#include "common/clamp.h" - namespace olive { int QtUtils::QFontMetricsWidth(QFontMetrics fm, const QString& s) { @@ -179,10 +177,10 @@ QColor QtUtils::toQColor(const core::Color &i) QColor c; // QColor only supports values from 0.0 to 1.0 and are only used for UI representations - c.setRedF(clamp(i.red(), 0.0f, 1.0f)); - c.setGreenF(clamp(i.green(), 0.0f, 1.0f)); - c.setBlueF(clamp(i.blue(), 0.0f, 1.0f)); - c.setAlphaF(clamp(i.alpha(), 0.0f, 1.0f)); + c.setRedF(std::clamp(i.red(), 0.0f, 1.0f)); + c.setGreenF(std::clamp(i.green(), 0.0f, 1.0f)); + c.setBlueF(std::clamp(i.blue(), 0.0f, 1.0f)); + c.setAlphaF(std::clamp(i.alpha(), 0.0f, 1.0f)); return c; } diff --git a/app/common/qtutils.h b/app/common/qtutils.h index cd6c0fcd4..851078aed 100644 --- a/app/common/qtutils.h +++ b/app/common/qtutils.h @@ -89,5 +89,8 @@ uint qHash(const core::TimeRange& r, uint seed = 0); Q_DECLARE_METATYPE(olive::core::rational); Q_DECLARE_METATYPE(olive::core::Color); Q_DECLARE_METATYPE(olive::core::TimeRange); +Q_DECLARE_METATYPE(olive::core::Bezier); +Q_DECLARE_METATYPE(olive::core::AudioParams); +Q_DECLARE_METATYPE(olive::core::SampleBuffer); #endif // QTVERSIONABSTRACTION_H diff --git a/app/config/config.cpp b/app/config/config.cpp index 51d97eb2b..336b1eeb4 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -138,13 +138,13 @@ void Config::SetDefaults() SetEntryInternal(QStringLiteral("AudioOutputSampleRate"), NodeValue::kInt, 48000); SetEntryInternal(QStringLiteral("AudioOutputChannelLayout"), NodeValue::kInt, AV_CH_LAYOUT_STEREO); - SetEntryInternal(QStringLiteral("AudioOutputSampleFormat"), NodeValue::kInt, AudioParams::kFormatSigned16Packed); + SetEntryInternal(QStringLiteral("AudioOutputSampleFormat"), NodeValue::kText, QString::fromStdString(SampleFormat(SampleFormat::S16).to_string())); SetEntryInternal(QStringLiteral("AudioRecordingFormat"), NodeValue::kInt, ExportFormat::kFormatWAV); SetEntryInternal(QStringLiteral("AudioRecordingCodec"), NodeValue::kInt, ExportCodec::kCodecPCM); SetEntryInternal(QStringLiteral("AudioRecordingSampleRate"), NodeValue::kInt, 48000); SetEntryInternal(QStringLiteral("AudioRecordingChannelLayout"), NodeValue::kInt, AV_CH_LAYOUT_STEREO); - SetEntryInternal(QStringLiteral("AudioRecordingSampleFormat"), NodeValue::kInt, AudioParams::kFormatSigned16Packed); + SetEntryInternal(QStringLiteral("AudioRecordingSampleFormat"), NodeValue::kText, QString::fromStdString(SampleFormat(SampleFormat::S16).to_string())); SetEntryInternal(QStringLiteral("AudioRecordingBitRate"), NodeValue::kInt, 320); SetEntryInternal(QStringLiteral("DiskCacheBehind"), NodeValue::kRational, QVariant::fromValue(rational(0))); diff --git a/app/dialog/preferences/tabs/preferencesaudiotab.cpp b/app/dialog/preferences/tabs/preferencesaudiotab.cpp index b498e53ae..211f070cb 100644 --- a/app/dialog/preferences/tabs/preferencesaudiotab.cpp +++ b/app/dialog/preferences/tabs/preferencesaudiotab.cpp @@ -100,7 +100,7 @@ PreferencesAudioTab::PreferencesAudioTab() output_fmt_combo_ = new SampleFormatComboBox(); output_fmt_combo_->SetPackedFormats(); - output_fmt_combo_->SetSampleFormat(static_cast(OLIVE_CONFIG("AudioOutputSampleFormat").toInt())); + output_fmt_combo_->SetSampleFormat(SampleFormat::from_string(OLIVE_CONFIG("AudioOutputSampleFormat").toString().toStdString())); output_param_layout->addWidget(output_fmt_combo_, output_row, 1); } } @@ -142,7 +142,7 @@ PreferencesAudioTab::PreferencesAudioTab() record_options_->sample_rate_combobox()->SetSampleRate(OLIVE_CONFIG("AudioRecordingSampleRate").toInt()); record_options_->channel_layout_combobox()->SetChannelLayout(OLIVE_CONFIG("AudioRecordingChannelLayout").toULongLong()); record_options_->bit_rate_slider()->SetValue(OLIVE_CONFIG("AudioRecordingBitRate").toInt()); - record_options_->sample_format_combobox()->SetSampleFormat(static_cast(OLIVE_CONFIG("AudioRecordingSampleFormat").toInt())); + record_options_->sample_format_combobox()->SetSampleFormat(SampleFormat::from_string(OLIVE_CONFIG("AudioRecordingSampleFormat").toString().toStdString())); recording_layout->addWidget(record_options_); connect(record_format_combo_, &ExportFormatComboBox::FormatChanged, record_options_, &ExportAudioTab::SetFormat); @@ -182,14 +182,14 @@ void PreferencesAudioTab::Accept(MultiUndoCommand *command) OLIVE_CONFIG("AudioOutputSampleRate") = output_rate_combo_->GetSampleRate(); OLIVE_CONFIG("AudioOutputChannelLayout") = QVariant::fromValue(output_ch_layout_combo_->GetChannelLayout()); - OLIVE_CONFIG("AudioOutputSampleFormat") = output_fmt_combo_->GetSampleFormat(); + OLIVE_CONFIG("AudioOutputSampleFormat") = QString::fromStdString(output_fmt_combo_->GetSampleFormat().to_string()); OLIVE_CONFIG("AudioRecordingFormat") = record_format_combo_->GetFormat(); OLIVE_CONFIG("AudioRecordingCodec") = record_options_->GetCodec(); OLIVE_CONFIG("AudioRecordingSampleRate") = record_options_->sample_rate_combobox()->GetSampleRate(); OLIVE_CONFIG("AudioRecordingChannelLayout") = QVariant::fromValue(record_options_->channel_layout_combobox()->GetChannelLayout()); OLIVE_CONFIG("AudioRecordingBitRate") = QVariant::fromValue(record_options_->bit_rate_slider()->GetValue()); - OLIVE_CONFIG("AudioRecordingSampleFormat") = record_options_->sample_format_combobox()->GetSampleFormat(); + OLIVE_CONFIG("AudioRecordingSampleFormat") = QString::fromStdString(record_options_->sample_format_combobox()->GetSampleFormat().to_string()); emit AudioManager::instance()->OutputParamsChanged(); } diff --git a/app/dialog/sequence/sequence.cpp b/app/dialog/sequence/sequence.cpp index 18b509311..dd8a65c7c 100644 --- a/app/dialog/sequence/sequence.cpp +++ b/app/dialog/sequence/sequence.cpp @@ -140,7 +140,7 @@ void SequenceDialog::accept() AudioParams audio_params = AudioParams(parameter_tab_->GetSelectedAudioSampleRate(), parameter_tab_->GetSelectedAudioChannelLayout(), - AudioParams::kInternalFormat); + Sequence::kDefaultSampleFormat); if (make_undoable_) { diff --git a/app/dialog/sequence/sequencedialogpresettab.cpp b/app/dialog/sequence/sequencedialogpresettab.cpp index e3a572936..b027066c1 100644 --- a/app/dialog/sequence/sequencedialogpresettab.cpp +++ b/app/dialog/sequence/sequencedialogpresettab.cpp @@ -31,7 +31,6 @@ #include "common/filefunctions.h" #include "config/config.h" -#include "render/audioparams.h" #include "render/videoparams.h" #include "ui/icons/icons.h" #include "widget/menu/menu.h" diff --git a/app/node/block/transition/transition.cpp b/app/node/block/transition/transition.cpp index 1b05f3ba7..327f3fc1c 100644 --- a/app/node/block/transition/transition.cpp +++ b/app/node/block/transition/transition.cpp @@ -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; } diff --git a/app/node/distort/transform/transformdistortnode.cpp b/app/node/distort/transform/transformdistortnode.cpp index 26e1e3577..bc2769a8f 100644 --- a/app/node/distort/transform/transformdistortnode.cpp +++ b/app/node/distort/transform/transformdistortnode.cpp @@ -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; diff --git a/app/node/generator/polygon/polygon.cpp b/app/node/generator/polygon/polygon.cpp index 4f71f3336..e05c3da14 100644 --- a/app/node/generator/polygon/polygon.cpp +++ b/app/node/generator/polygon/polygon.cpp @@ -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; iSetPoint(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 -#include "common/bezier.h" #include "node/generator/shape/generatorwithmerge.h" #include "node/gizmo/line.h" #include "node/gizmo/path.h" diff --git a/app/node/generator/text/textv2.cpp b/app/node/generator/text/textv2.cpp index 5689b342a..f4165afa1 100644 --- a/app/node/generator/text/textv2.cpp +++ b/app/node/generator/text/textv2.cpp @@ -20,12 +20,11 @@ #include "textv2.h" +#include #include #include #include -#include "common/cpuoptimize.h" - namespace olive { #define super ShapeNodeBase diff --git a/app/node/globals.h b/app/node/globals.h index 73ff8c00d..85540e504 100644 --- a/app/node/globals.h +++ b/app/node/globals.h @@ -23,7 +23,6 @@ #include -#include "render/audioparams.h" #include "render/loopmode.h" #include "render/videoparams.h" diff --git a/app/node/inputimmediate.cpp b/app/node/inputimmediate.cpp index 9484428aa..7821b7bc8 100644 --- a/app/node/inputimmediate.cpp +++ b/app/node/inputimmediate.cpp @@ -20,7 +20,6 @@ #include "inputimmediate.h" -#include "common/bezier.h" #include "common/lerp.h" #include "common/tohex.h" diff --git a/app/node/math/math/mathbase.cpp b/app/node/math/math/mathbase.cpp index 1c6c979e2..af8ded1e3 100644 --- a/app/node/math/math/mathbase.cpp +++ b/app/node/math/math/mathbase.cpp @@ -23,7 +23,6 @@ #include #include -#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; diff --git a/app/node/math/trigonometry/trigonometry.cpp b/app/node/math/trigonometry/trigonometry.cpp index b82c9f36f..eb8557157 100644 --- a/app/node/math/trigonometry/trigonometry.cpp +++ b/app/node/math/trigonometry/trigonometry.cpp @@ -83,22 +83,22 @@ void TrigonometryNode::Value(const NodeValueRow &value, const NodeGlobals &globa switch (static_cast(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); diff --git a/app/node/node.cpp b/app/node/node.cpp index 2ebef9b30..d514c5d73 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -25,7 +25,6 @@ #include #include -#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 diff --git a/app/node/node.h b/app/node/node.h index 108a137cf..24d13bdd8 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -29,14 +29,12 @@ #include #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" diff --git a/app/node/output/viewer/viewer.cpp b/app/node/output/viewer/viewer.cpp index 2bc405bb8..b7c8c47e1 100644 --- a/app/node/output/viewer/viewer.cpp +++ b/app/node/output/viewer/viewer.cpp @@ -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 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)); } } } diff --git a/app/node/output/viewer/viewer.h b/app/node/output/viewer/viewer.h index e7802472d..70d40dd2a 100644 --- a/app/node/output/viewer/viewer.h +++ b/app/node/output/viewer/viewer.h @@ -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&); diff --git a/app/node/project/footage/footage.cpp b/app/node/project/footage/footage.cpp index f99ea8bc5..4a316c751 100644 --- a/app/node/project/footage/footage.cpp +++ b/app/node/project/footage/footage.cpp @@ -25,7 +25,6 @@ #include #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 diff --git a/app/node/project/footage/footage.h b/app/node/project/footage/footage.h index 1c6e24dc4..794e5062d 100644 --- a/app/node/project/footage/footage.h +++ b/app/node/project/footage/footage.h @@ -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" diff --git a/app/node/project/footage/footagedescription.cpp b/app/node/project/footage/footagedescription.cpp index 742372586..cc878d1c9 100644 --- a/app/node/project/footage/footagedescription.cpp +++ b/app/node/project/footage/footagedescription.cpp @@ -25,6 +25,7 @@ #include #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 } diff --git a/app/node/project/footage/footagedescription.h b/app/node/project/footage/footagedescription.h index 42e6a07be..588c06c2b 100644 --- a/app/node/project/footage/footagedescription.h +++ b/app/node/project/footage/footagedescription.h @@ -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" diff --git a/app/node/project/serializer/CMakeLists.txt b/app/node/project/serializer/CMakeLists.txt index 829e559bb..4eca1cb5f 100644 --- a/app/node/project/serializer/CMakeLists.txt +++ b/app/node/project/serializer/CMakeLists.txt @@ -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 ) diff --git a/app/node/project/serializer/serializer.h b/app/node/project/serializer/serializer.h index 3847ba062..1377b325d 100644 --- a/app/node/project/serializer/serializer.h +++ b/app/node/project/serializer/serializer.h @@ -21,10 +21,11 @@ #ifndef PROJECTSERIALIZER_H #define PROJECTSERIALIZER_H -#include +#include #include "common/define.h" #include "node/project/project.h" +#include "typeserializer.h" namespace olive { diff --git a/app/node/project/serializer/serializer210528.cpp b/app/node/project/serializer/serializer210528.cpp index f79eb5c2c..419b2c890 100644 --- a/app/node/project/serializer/serializer210528.cpp +++ b/app/node/project/serializer/serializer210528.cpp @@ -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(); diff --git a/app/node/project/serializer/serializer210907.cpp b/app/node/project/serializer/serializer210907.cpp index ad180f9e0..8f7250bc2 100644 --- a/app/node/project/serializer/serializer210907.cpp +++ b/app/node/project/serializer/serializer210907.cpp @@ -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(); diff --git a/app/node/project/serializer/serializer211228.cpp b/app/node/project/serializer/serializer211228.cpp index a4a114a83..918b8c552 100644 --- a/app/node/project/serializer/serializer211228.cpp +++ b/app/node/project/serializer/serializer211228.cpp @@ -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(); diff --git a/app/node/project/serializer/serializer220403.cpp b/app/node/project/serializer/serializer220403.cpp index 41daded68..f863f1ae9 100644 --- a/app/node/project/serializer/serializer220403.cpp +++ b/app/node/project/serializer/serializer220403.cpp @@ -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().Save(writer); } else if (data_type == NodeValue::kAudioParams) { - v.value().Save(writer); + TypeSerializer::SaveAudioParams(writer, v.value()); } else { writer->writeCharacters(NodeValue::ValueToString(data_type, v, true)); } diff --git a/app/node/project/serializer/typeserializer.cpp b/app/node/project/serializer/typeserializer.cpp new file mode 100644 index 000000000..003613597 --- /dev/null +++ b/app/node/project/serializer/typeserializer.cpp @@ -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 . + +***/ + +#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())); +} + +} diff --git a/app/common/cpuoptimize.h b/app/node/project/serializer/typeserializer.h similarity index 58% rename from app/common/cpuoptimize.h rename to app/node/project/serializer/typeserializer.h index d683ceb5b..c1b2bd505 100644 --- a/app/common/cpuoptimize.h +++ b/app/node/project/serializer/typeserializer.h @@ -1,7 +1,7 @@ /*** Olive - Non-Linear Video Editor - Copyright (C) 2022 Olive Team + 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 @@ -18,13 +18,29 @@ ***/ -#ifndef CPUOPTIMIZE_H -#define CPUOPTIMIZE_H +#ifndef TYPESERIALIZER_H +#define TYPESERIALIZER_H -#if defined(Q_PROCESSOR_X86) -#include -#elif defined(Q_PROCESSOR_ARM) -#include -#endif +#include +#include +#include -#endif // CPUOPTIMIZE_H +#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 diff --git a/app/node/value.cpp b/app/node/value.cpp index 6d40d621b..763bd96e5 100644 --- a/app/node/value.cpp +++ b/app/node/value.cpp @@ -26,9 +26,7 @@ #include #include -#include "common/bezier.h" #include "common/tohex.h" -#include "render/audioparams.h" #include "render/subtitleparams.h" #include "render/videoparams.h" diff --git a/app/node/value.h b/app/node/value.h index 11223e62b..2e033849f 100644 --- a/app/node/value.h +++ b/app/node/value.h @@ -26,8 +26,6 @@ #include #include -#include "codec/samplebuffer.h" -#include "common/bezier.h" #include "common/qtutils.h" #include "node/splitvalue.h" #include "render/texture.h" diff --git a/app/render/CMakeLists.txt b/app/render/CMakeLists.txt index fcbc45750..7b632d89f 100644 --- a/app/render/CMakeLists.txt +++ b/app/render/CMakeLists.txt @@ -20,8 +20,6 @@ add_subdirectory(opengl) set(OLIVE_SOURCES ${OLIVE_SOURCES} - render/audioparams.cpp - render/audioparams.h render/audioplaybackcache.cpp render/audioplaybackcache.h render/audiowaveformcache.cpp diff --git a/app/render/audioparams.cpp b/app/render/audioparams.cpp deleted file mode 100644 index 63d1b52e5..000000000 --- a/app/render/audioparams.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 . - -***/ - -#include "audioparams.h" - -extern "C" { -#include -} - -#include - -#include "common/xmlutils.h" - -namespace olive { - -const QVector AudioParams::kSupportedSampleRates = { - 8000, // 8000 Hz - 11025, // 11025 Hz - 16000, // 16000 Hz - 22050, // 22050 Hz - 24000, // 24000 Hz - 32000, // 32000 Hz - 44100, // 44100 Hz - 48000, // 48000 Hz - 88200, // 88200 Hz - 96000 // 96000 Hz -}; - -const QVector AudioParams::kSupportedChannelLayouts = { - AV_CH_LAYOUT_MONO, - AV_CH_LAYOUT_STEREO, - AV_CH_LAYOUT_2_1, - AV_CH_LAYOUT_5POINT1, - AV_CH_LAYOUT_7POINT1 -}; - -const AudioParams::Format AudioParams::kInternalFormat = AudioParams::kFormatFloat32Planar; - -bool AudioParams::operator==(const AudioParams &other) const -{ - return (format() == other.format() - && sample_rate() == other.sample_rate() - && time_base() == other.time_base() - && channel_layout() == other.channel_layout()); -} - -bool AudioParams::operator!=(const AudioParams &other) const -{ - return !(*this == other); -} - -qint64 AudioParams::time_to_bytes(const double &time) const -{ - return time_to_bytes_per_channel(time) * channel_count(); -} - -qint64 AudioParams::time_to_bytes(const rational &time) const -{ - return time_to_bytes(time.toDouble()); -} - -qint64 AudioParams::time_to_bytes_per_channel(const double &time) const -{ - Q_ASSERT(is_valid()); - - return qint64(time_to_samples(time)) * bytes_per_sample_per_channel(); -} - -qint64 AudioParams::time_to_bytes_per_channel(const rational &time) const -{ - return time_to_bytes_per_channel(time.toDouble()); -} - -qint64 AudioParams::time_to_samples(const double &time) const -{ - Q_ASSERT(is_valid()); - - // NOTE: Not sure if we should round or ceil, but I've gotten better results with ceil. - // Specifically, we seem to occasionally get straggler ranges that never cache with round. - return qCeil(double(sample_rate()) * time); -} - -qint64 AudioParams::time_to_samples(const rational &time) const -{ - return time_to_samples(time.toDouble()); -} - -qint64 AudioParams::samples_to_bytes(const qint64 &samples) const -{ - Q_ASSERT(is_valid()); - - return samples_to_bytes_per_channel(samples) * channel_count(); -} - -qint64 AudioParams::samples_to_bytes_per_channel(const qint64 &samples) const -{ - Q_ASSERT(is_valid()); - - return samples * bytes_per_sample_per_channel(); -} - -rational AudioParams::samples_to_time(const qint64 &samples) const -{ - return sample_rate_as_time_base() * samples; -} - -qint64 AudioParams::bytes_to_samples(const qint64 &bytes) const -{ - Q_ASSERT(is_valid()); - - return bytes / (channel_count() * bytes_per_sample_per_channel()); -} - -rational AudioParams::bytes_to_time(const qint64 &bytes) const -{ - Q_ASSERT(is_valid()); - - return samples_to_time(bytes_to_samples(bytes)); -} - -rational AudioParams::bytes_per_channel_to_time(const qint64 &bytes) const -{ - Q_ASSERT(is_valid()); - - return samples_to_time(bytes_to_samples(bytes * channel_count())); -} - -int AudioParams::channel_count() const -{ - return channel_count_; -} - -int AudioParams::bytes_per_sample_per_channel() const -{ - switch (format_) { - case kFormatUnsigned8Packed: - case kFormatUnsigned8Planar: - return 1; - case kFormatSigned16Packed: - case kFormatSigned16Planar: - return 2; - case kFormatSigned32Packed: - case kFormatSigned32Planar: - case kFormatFloat32Packed: - case kFormatFloat32Planar: - return 4; - case kFormatSigned64Packed: - case kFormatSigned64Planar: - case kFormatFloat64Packed: - case kFormatFloat64Planar: - return 8; - case kFormatInvalid: - case kFormatCount: - break; - } - - return 0; -} - -int AudioParams::bits_per_sample() const -{ - return bytes_per_sample_per_channel() * 8; -} - -bool AudioParams::is_valid() const -{ - return (!time_base().isNull() - && channel_layout() > 0 - && format_ > kFormatInvalid - && format_ < kFormatCount); -} - -void AudioParams::Load(QXmlStreamReader *reader) -{ - while (XMLReadNextStartElement(reader)) { - if (reader->name() == QStringLiteral("samplerate")) { - set_sample_rate(reader->readElementText().toInt()); - } else if (reader->name() == QStringLiteral("channellayout")) { - set_channel_layout(reader->readElementText().toULongLong()); - } else if (reader->name() == QStringLiteral("format")) { - set_format(static_cast(reader->readElementText().toInt())); - } else if (reader->name() == QStringLiteral("enabled")) { - set_enabled(reader->readElementText().toInt()); - } else if (reader->name() == QStringLiteral("streamindex")) { - set_stream_index(reader->readElementText().toInt()); - } else if (reader->name() == QStringLiteral("duration")) { - set_duration(reader->readElementText().toLongLong()); - } else if (reader->name() == QStringLiteral("timebase")) { - set_time_base(rational::fromString(reader->readElementText().toStdString())); - } else { - reader->skipCurrentElement(); - } - } -} - -void AudioParams::Save(QXmlStreamWriter *writer) const -{ - writer->writeTextElement(QStringLiteral("samplerate"), QString::number(sample_rate_)); - writer->writeTextElement(QStringLiteral("channellayout"), QString::number(channel_layout_)); - writer->writeTextElement(QStringLiteral("format"), QString::number(format_)); - writer->writeTextElement(QStringLiteral("enabled"), QString::number(enabled_)); - writer->writeTextElement(QStringLiteral("streamindex"), QString::number(stream_index_)); - writer->writeTextElement(QStringLiteral("duration"), QString::number(duration_)); - writer->writeTextElement(QStringLiteral("timebase"), QString::fromStdString(timebase_.toString())); -} - -QString AudioParams::SampleRateToString(const int &sample_rate) -{ - return QCoreApplication::translate("AudioParams", "%1 Hz").arg(sample_rate); -} - -QString AudioParams::ChannelLayoutToString(const uint64_t &layout) -{ - switch (layout) { - case AV_CH_LAYOUT_MONO: - return QCoreApplication::translate("AudioParams", "Mono"); - case AV_CH_LAYOUT_STEREO: - return QCoreApplication::translate("AudioParams", "Stereo"); - case AV_CH_LAYOUT_2_1: - return QCoreApplication::translate("AudioParams", "2.1"); - case AV_CH_LAYOUT_5POINT1: - return QCoreApplication::translate("AudioParams", "5.1"); - case AV_CH_LAYOUT_7POINT1: - return QCoreApplication::translate("AudioParams", "7.1"); - default: - return QCoreApplication::translate("AudioParams", "Unknown (0x%1)").arg(layout, 1, 16); - } -} - -QString AudioParams::FormatToString(const Format &f) -{ - switch (f) { - case kFormatUnsigned8Packed: - return QCoreApplication::translate("AudioParams", "Unsigned 8-bit (Packed)"); - case kFormatSigned16Packed: - return QCoreApplication::translate("AudioParams", "Signed 16-bit (Packed)"); - case kFormatSigned32Packed: - return QCoreApplication::translate("AudioParams", "Signed 32-bit (Packed)"); - case kFormatSigned64Packed: - return QCoreApplication::translate("AudioParams", "Signed 64-bit (Packed)"); - case kFormatFloat32Packed: - return QCoreApplication::translate("AudioParams", "Float 32-bit (Packed)"); - case kFormatFloat64Packed: - return QCoreApplication::translate("AudioParams", "Float 64-bit (Packed)"); - case kFormatUnsigned8Planar: - return QCoreApplication::translate("AudioParams", "Unsigned 8-bit (Planar)"); - case kFormatSigned16Planar: - return QCoreApplication::translate("AudioParams", "Signed 16-bit (Planar)"); - case kFormatSigned32Planar: - return QCoreApplication::translate("AudioParams", "Signed 32-bit (Planar)"); - case kFormatSigned64Planar: - return QCoreApplication::translate("AudioParams", "Signed 64-bit (Planar)"); - case kFormatFloat32Planar: - return QCoreApplication::translate("AudioParams", "Float 32-bit (Planar)"); - case kFormatFloat64Planar: - return QCoreApplication::translate("AudioParams", "Float 64-bit (Planar)"); - - case kFormatInvalid: - case kFormatCount: - break; - } - - return QCoreApplication::translate("AudioParams", "Unknown (0x%1)").arg(f, 1, 16); -} - -AudioParams::Format AudioParams::GetPackedEquivalent(Format fmt) -{ - switch (fmt) { - - // For packed input, just return input - case kFormatUnsigned8Packed: - case kFormatSigned16Packed: - case kFormatSigned32Packed: - case kFormatSigned64Packed: - case kFormatFloat32Packed: - case kFormatFloat64Packed: - return fmt; - - // Convert to packed - case kFormatUnsigned8Planar: - return kFormatUnsigned8Packed; - case kFormatSigned16Planar: - return kFormatSigned16Packed; - case kFormatSigned32Planar: - return kFormatSigned32Packed; - case kFormatSigned64Planar: - return kFormatSigned64Packed; - case kFormatFloat32Planar: - return kFormatFloat32Packed; - case kFormatFloat64Planar: - return kFormatFloat64Packed; - - case kFormatInvalid: - case kFormatCount: - break; - } - - return kFormatInvalid; -} - -AudioParams::Format AudioParams::GetPlanarEquivalent(Format fmt) -{ - switch (fmt) { - - // Convert to planar - case kFormatUnsigned8Packed: - return kFormatUnsigned8Planar; - case kFormatSigned16Packed: - return kFormatSigned16Planar; - case kFormatSigned32Packed: - return kFormatSigned32Planar; - case kFormatSigned64Packed: - return kFormatSigned64Planar; - case kFormatFloat32Packed: - return kFormatFloat32Planar; - case kFormatFloat64Packed: - return kFormatFloat64Planar; - - // For planar input, just return input - case kFormatUnsigned8Planar: - case kFormatSigned16Planar: - case kFormatSigned32Planar: - case kFormatSigned64Planar: - case kFormatFloat32Planar: - case kFormatFloat64Planar: - return fmt; - - case kFormatInvalid: - case kFormatCount: - break; - } - - return kFormatInvalid; -} - -void AudioParams::calculate_channel_count() -{ - channel_count_ = av_get_channel_layout_nb_channels(channel_layout()); -} - -} diff --git a/app/render/audioparams.h b/app/render/audioparams.h deleted file mode 100644 index edbcc50a9..000000000 --- a/app/render/audioparams.h +++ /dev/null @@ -1,282 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 . - -***/ - -#ifndef AUDIOPARAMS_H -#define AUDIOPARAMS_H - -extern "C" { -#include -} - -#include -#include -#include -#include - -namespace olive { - -using namespace core; - -class AudioParams { -public: - // Only append to this list (never insert) because indexes are used in serialized files - enum Format { - /// Invalid - kFormatInvalid = -1, - - /// 8-bit unsigned integer - kFormatUnsigned8Planar, - - /// 16-bit signed integer - kFormatSigned16Planar, - - /// 32-bit signed integer - kFormatSigned32Planar, - - /// 64-bit signed integer - kFormatSigned64Planar, - - /// 32-bit float - kFormatFloat32Planar, - - /// 64-bit float - kFormatFloat64Planar, - - /// 8-bit unsigned integer - kFormatUnsigned8Packed, - - /// 16-bit signed integer - kFormatSigned16Packed, - - /// 32-bit signed integer - kFormatSigned32Packed, - - /// 64-bit signed integer - kFormatSigned64Packed, - - /// 32-bit float - kFormatFloat32Packed, - - /// 64-bit float - kFormatFloat64Packed, - - /// Total format count - kFormatCount, - - kPlanarStart = kFormatUnsigned8Planar, - kPackedStart = kFormatUnsigned8Packed, - kPlanarEnd = kPackedStart, - kPackedEnd = kFormatCount - }; - - static const Format kInternalFormat; - - AudioParams() : - sample_rate_(0), - channel_layout_(0), - format_(kFormatInvalid) - { - set_default_footage_parameters(); - - // Cache channel count - calculate_channel_count(); - } - - AudioParams(const int& sample_rate, const uint64_t& channel_layout, const Format& format) : - sample_rate_(sample_rate), - channel_layout_(channel_layout), - format_(format) - { - set_default_footage_parameters(); - timebase_ = sample_rate_as_time_base(); - - // Cache channel count - calculate_channel_count(); - } - - int sample_rate() const - { - return sample_rate_; - } - - void set_sample_rate(int sample_rate) - { - sample_rate_ = sample_rate; - } - - uint64_t channel_layout() const - { - return channel_layout_; - } - - void set_channel_layout(uint64_t channel_layout) - { - channel_layout_ = channel_layout; - calculate_channel_count(); - } - - rational time_base() const - { - return timebase_; - } - - void set_time_base(const rational& timebase) - { - timebase_ = timebase; - } - - rational sample_rate_as_time_base() const - { - return rational(1, sample_rate()); - } - - Format format() const - { - return format_; - } - - void set_format(Format format) - { - format_ = format; - } - - bool enabled() const - { - return enabled_; - } - - void set_enabled(bool e) - { - enabled_ = e; - } - - int stream_index() const - { - return stream_index_; - } - - void set_stream_index(int s) - { - stream_index_ = s; - } - - int64_t duration() const - { - return duration_; - } - - void set_duration(int64_t duration) - { - duration_ = duration; - } - - static bool FormatIsPacked(Format f) - { - return f >= kPackedStart && f < kPackedEnd; - } - - bool FormatIsPacked() const - { - return FormatIsPacked(format_); - } - - static bool FormatIsPlanar(Format f) - { - return f >= kPlanarStart && f < kPlanarEnd; - } - - bool FormatIsPlanar() const - { - return FormatIsPlanar(format_); - } - - qint64 time_to_bytes(const double& time) const; - qint64 time_to_bytes(const rational& time) const; - qint64 time_to_bytes_per_channel(const double& time) const; - qint64 time_to_bytes_per_channel(const rational& time) const; - qint64 time_to_samples(const double& time) const; - qint64 time_to_samples(const rational& time) const; - qint64 samples_to_bytes(const qint64& samples) const; - qint64 samples_to_bytes_per_channel(const qint64& samples) const; - rational samples_to_time(const qint64& samples) const; - qint64 bytes_to_samples(const qint64 &bytes) const; - rational bytes_to_time(const qint64 &bytes) const; - rational bytes_per_channel_to_time(const qint64 &bytes) const; - int channel_count() const; - int bytes_per_sample_per_channel() const; - int bits_per_sample() const; - bool is_valid() const; - - void Load(QXmlStreamReader* reader); - - void Save(QXmlStreamWriter* writer) const; - - bool operator==(const AudioParams& other) const; - bool operator!=(const AudioParams& other) const; - - static const QVector kSupportedChannelLayouts; - static const QVector kSupportedSampleRates; - - /** - * @brief Convert integer sample rate to a user-friendly string - */ - static QString SampleRateToString(const int &sample_rate); - - /** - * @brief Convert channel layout to a user-friendly string - */ - static QString ChannelLayoutToString(const uint64_t &layout); - - static QString FormatToString(const Format &f); - - static AudioParams::Format GetPackedEquivalent(AudioParams::Format fmt); - static AudioParams::Format GetPlanarEquivalent(AudioParams::Format fmt); - -private: - void set_default_footage_parameters() - { - enabled_ = true; - stream_index_ = 0; - duration_ = 0; - } - - void calculate_channel_count(); - - int sample_rate_; - - uint64_t channel_layout_; - - int channel_count_; - - Format format_; - - // Footage-specific - int enabled_; // Switching this to int fixes GCC 11 stringop-overflow issue, I guess a byte-alignment issue? - int stream_index_; - int64_t duration_; - rational timebase_; - -}; - -} - -Q_DECLARE_METATYPE(olive::AudioParams) - -#endif // AUDIOPARAMS_H diff --git a/app/render/audioplaybackcache.cpp b/app/render/audioplaybackcache.cpp index 6113a6fd9..f212f1e33 100644 --- a/app/render/audioplaybackcache.cpp +++ b/app/render/audioplaybackcache.cpp @@ -68,28 +68,28 @@ void AudioPlaybackCache::WriteSilence(const TimeRange &range) bool AudioPlaybackCache::WritePartOfSampleBuffer(const SampleBuffer &samples, const rational &write_start, const rational &buffer_start, const rational &length) { - qint64 length_in_bytes = params_.time_to_bytes_per_channel(length); + int64_t length_in_bytes = params_.time_to_bytes_per_channel(length); - qint64 start_cache_offset = params_.time_to_bytes_per_channel(write_start); - qint64 end_cache_offset = start_cache_offset + length_in_bytes; + int64_t start_cache_offset = params_.time_to_bytes_per_channel(write_start); + int64_t end_cache_offset = start_cache_offset + length_in_bytes; - qint64 start_buffer_offset = params_.time_to_bytes_per_channel(buffer_start); - qint64 end_buffer_offset = std::min(start_buffer_offset + length_in_bytes, params_.samples_to_bytes_per_channel(samples.sample_count())); + int64_t start_buffer_offset = params_.time_to_bytes_per_channel(buffer_start); + int64_t end_buffer_offset = std::min(start_buffer_offset + length_in_bytes, params_.samples_to_bytes_per_channel(samples.sample_count())); - qint64 current_cache_offset = start_cache_offset; - qint64 current_buffer_offset = start_buffer_offset; + int64_t current_cache_offset = start_cache_offset; + int64_t current_buffer_offset = start_buffer_offset; bool success = true; while (current_cache_offset != end_cache_offset) { - qint64 segment = current_cache_offset / kDefaultSegmentSizePerChannel; - qint64 segment_start = segment * kDefaultSegmentSizePerChannel; - qint64 segment_end = segment_start + kDefaultSegmentSizePerChannel; + int64_t segment = current_cache_offset / kDefaultSegmentSizePerChannel; + int64_t segment_start = segment * kDefaultSegmentSizePerChannel; + int64_t segment_end = segment_start + kDefaultSegmentSizePerChannel; - qint64 offset_in_segment = current_cache_offset - segment_start; - qint64 write_len = segment_end - offset_in_segment; - qint64 max_buffer_len = end_buffer_offset - current_buffer_offset; - qint64 zero_len = 0; + int64_t offset_in_segment = current_cache_offset - segment_start; + int64_t write_len = segment_end - offset_in_segment; + int64_t max_buffer_len = end_buffer_offset - current_buffer_offset; + int64_t zero_len = 0; if (write_len > max_buffer_len) { zero_len = write_len - max_buffer_len; diff --git a/app/render/audioplaybackcache.h b/app/render/audioplaybackcache.h index 5297a3acd..2e6c39996 100644 --- a/app/render/audioplaybackcache.h +++ b/app/render/audioplaybackcache.h @@ -22,7 +22,6 @@ #define AUDIOPLAYBACKCACHE_H #include "audio/audiovisualwaveform.h" -#include "codec/samplebuffer.h" #include "render/playbackcache.h" namespace olive { diff --git a/app/render/framehashcache.cpp b/app/render/framehashcache.cpp index 69bb38991..bbec015f5 100644 --- a/app/render/framehashcache.cpp +++ b/app/render/framehashcache.cpp @@ -406,7 +406,7 @@ bool FrameHashCache::SaveCacheFrame(const QString &filename, const FramePtr fram break; case PixelFormat::F16: case PixelFormat::F32: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: case PixelFormat::INVALID: break; } diff --git a/app/render/job/samplejob.h b/app/render/job/samplejob.h index 8cf37e542..8d13baf89 100644 --- a/app/render/job/samplejob.h +++ b/app/render/job/samplejob.h @@ -22,7 +22,6 @@ #define SAMPLEJOB_H #include "acceleratedjob.h" -#include "codec/samplebuffer.h" namespace olive { diff --git a/app/render/opengl/openglrenderer.cpp b/app/render/opengl/openglrenderer.cpp index 9237c9e36..decdfe709 100644 --- a/app/render/opengl/openglrenderer.cpp +++ b/app/render/opengl/openglrenderer.cpp @@ -725,7 +725,7 @@ GLint OpenGLRenderer::GetInternalFormat(PixelFormat format, int channel_layout) } break; case PixelFormat::INVALID: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: break; } @@ -745,7 +745,7 @@ GLenum OpenGLRenderer::GetPixelType(PixelFormat format) return GL_FLOAT; case PixelFormat::INVALID: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: break; } diff --git a/app/render/previewautocacher.h b/app/render/previewautocacher.h index 4aabca518..d0627c6b6 100644 --- a/app/render/previewautocacher.h +++ b/app/render/previewautocacher.h @@ -30,7 +30,6 @@ #include "node/node.h" #include "node/output/viewer/viewer.h" #include "node/project/project.h" -#include "render/audioparams.h" #include "render/projectcopier.h" #include "render/renderjobtracker.h" #include "render/rendermanager.h" diff --git a/app/render/renderticket.h b/app/render/renderticket.h index 77a246c58..ee948166d 100644 --- a/app/render/renderticket.h +++ b/app/render/renderticket.h @@ -26,7 +26,6 @@ #include #include "codec/frame.h" -#include "codec/samplebuffer.h" #include "common/cancelableobject.h" #include "node/output/viewer/viewer.h" diff --git a/app/render/videoparams.cpp b/app/render/videoparams.cpp index 0eb4edd7c..742e01227 100644 --- a/app/render/videoparams.cpp +++ b/app/render/videoparams.cpp @@ -182,7 +182,7 @@ int VideoParams::GetBytesPerChannel(PixelFormat format) { switch (format) { case PixelFormat::INVALID: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: break; case PixelFormat::U8: return 1; @@ -222,7 +222,7 @@ QString VideoParams::GetFormatName(PixelFormat format) case PixelFormat::F32: return QCoreApplication::translate("VideoParams", "Full-Float (32-bit)"); case PixelFormat::INVALID: - case PixelFormat::FORMAT_COUNT: + case PixelFormat::COUNT: break; } @@ -287,7 +287,7 @@ bool VideoParams::is_valid() const return (width() > 0 && height() > 0 && !pixel_aspect_ratio_.isNull() - && format_ > PixelFormat::INVALID && format_ < PixelFormat::FORMAT_COUNT + && format_ > PixelFormat::INVALID && format_ < PixelFormat::COUNT && channel_count_ > 0); } diff --git a/app/task/conform/conform.h b/app/task/conform/conform.h index 9467c9748..30e35fc8f 100644 --- a/app/task/conform/conform.h +++ b/app/task/conform/conform.h @@ -23,7 +23,6 @@ #include "codec/decoder.h" #include "node/project/footage/footage.h" -#include "render/audioparams.h" #include "task/task.h" namespace olive { diff --git a/app/ui/CMakeLists.txt b/app/ui/CMakeLists.txt index 1aad55a4a..0cf894b7f 100644 --- a/app/ui/CMakeLists.txt +++ b/app/ui/CMakeLists.txt @@ -28,5 +28,7 @@ set(OLIVE_SOURCES ${OLIVE_SOURCES} ui/colorcoding.cpp ui/colorcoding.h + ui/humanstrings.cpp + ui/humanstrings.h PARENT_SCOPE ) diff --git a/app/ui/humanstrings.cpp b/app/ui/humanstrings.cpp new file mode 100644 index 000000000..6a52a9ccb --- /dev/null +++ b/app/ui/humanstrings.cpp @@ -0,0 +1,66 @@ +#include "humanstrings.h" + +#include + +namespace olive { + +QString HumanStrings::SampleRateToString(const int &sample_rate) +{ + return QCoreApplication::translate("AudioParams", "%1 Hz").arg(sample_rate); +} + +QString HumanStrings::ChannelLayoutToString(const uint64_t &layout) +{ + switch (layout) { + case AV_CH_LAYOUT_MONO: + return QCoreApplication::translate("AudioParams", "Mono"); + case AV_CH_LAYOUT_STEREO: + return QCoreApplication::translate("AudioParams", "Stereo"); + case AV_CH_LAYOUT_2_1: + return QCoreApplication::translate("AudioParams", "2.1"); + case AV_CH_LAYOUT_5POINT1: + return QCoreApplication::translate("AudioParams", "5.1"); + case AV_CH_LAYOUT_7POINT1: + return QCoreApplication::translate("AudioParams", "7.1"); + default: + return QCoreApplication::translate("AudioParams", "Unknown (0x%1)").arg(layout, 1, 16); + } +} + +QString HumanStrings::FormatToString(const SampleFormat &f) +{ + switch (f) { + case SampleFormat::U8: + return QCoreApplication::translate("AudioParams", "Unsigned 8-bit (Packed)"); + case SampleFormat::S16: + return QCoreApplication::translate("AudioParams", "Signed 16-bit (Packed)"); + case SampleFormat::S32: + return QCoreApplication::translate("AudioParams", "Signed 32-bit (Packed)"); + case SampleFormat::S64: + return QCoreApplication::translate("AudioParams", "Signed 64-bit (Packed)"); + case SampleFormat::F32: + return QCoreApplication::translate("AudioParams", "Float 32-bit (Packed)"); + case SampleFormat::F64: + return QCoreApplication::translate("AudioParams", "Float 64-bit (Packed)"); + case SampleFormat::U8P: + return QCoreApplication::translate("AudioParams", "Unsigned 8-bit (Planar)"); + case SampleFormat::S16P: + return QCoreApplication::translate("AudioParams", "Signed 16-bit (Planar)"); + case SampleFormat::S32P: + return QCoreApplication::translate("AudioParams", "Signed 32-bit (Planar)"); + case SampleFormat::S64P: + return QCoreApplication::translate("AudioParams", "Signed 64-bit (Planar)"); + case SampleFormat::F32P: + return QCoreApplication::translate("AudioParams", "Float 32-bit (Planar)"); + case SampleFormat::F64P: + return QCoreApplication::translate("AudioParams", "Float 64-bit (Planar)"); + + case SampleFormat::INVALID: + case SampleFormat::COUNT: + break; + } + + return QCoreApplication::translate("AudioParams", "Unknown (0x%1)").arg(f, 1, 16); +} + +} diff --git a/app/ui/humanstrings.h b/app/ui/humanstrings.h new file mode 100644 index 000000000..6c94fb292 --- /dev/null +++ b/app/ui/humanstrings.h @@ -0,0 +1,27 @@ +#ifndef HUMANSTRINGS_H +#define HUMANSTRINGS_H + +#include +#include + +namespace olive { + +using namespace core; + +class HumanStrings : public QObject +{ + Q_OBJECT +public: + HumanStrings() = default; + + static QString SampleRateToString(const int &sample_rate); + + static QString ChannelLayoutToString(const uint64_t &layout); + + static QString FormatToString(const SampleFormat &f); + +}; + +} + +#endif // HUMANSTRINGS_H diff --git a/app/widget/audiomonitor/audiomonitor.h b/app/widget/audiomonitor/audiomonitor.h index aaa5e6a5a..fbecb551d 100644 --- a/app/widget/audiomonitor/audiomonitor.h +++ b/app/widget/audiomonitor/audiomonitor.h @@ -27,7 +27,6 @@ #include "audio/audiovisualwaveform.h" #include "common/define.h" -#include "render/audioparams.h" #include "render/audiowaveformcache.h" namespace olive { diff --git a/app/widget/bezier/bezierwidget.h b/app/widget/bezier/bezierwidget.h index 0faa721dc..e16d0601d 100644 --- a/app/widget/bezier/bezierwidget.h +++ b/app/widget/bezier/bezierwidget.h @@ -21,14 +21,16 @@ #ifndef BEZIERWIDGET_H #define BEZIERWIDGET_H +#include #include #include -#include "common/bezier.h" #include "widget/slider/floatslider.h" namespace olive { +using namespace core; + class BezierWidget : public QWidget { Q_OBJECT diff --git a/app/widget/colorwheel/colorgradientwidget.cpp b/app/widget/colorwheel/colorgradientwidget.cpp index 5972565de..e4cec9e7c 100644 --- a/app/widget/colorwheel/colorgradientwidget.cpp +++ b/app/widget/colorwheel/colorgradientwidget.cpp @@ -22,7 +22,6 @@ #include -#include "common/clamp.h" #include "common/lerp.h" #include "node/node.h" @@ -76,7 +75,7 @@ void ColorGradientWidget::paintEvent(QPaintEvent *e) p.setPen(QPen(GetUISelectorColor(), qMax(1, selector_radius / 2))); p.setBrush(Qt::NoBrush); - float clamped_val = clamp(val_, 0.0f, 1.0f); + float clamped_val = std::clamp(val_, 0.0f, 1.0f); if (orientation_ == Qt::Horizontal) { p.drawRect(qRound(width() * (1.0 - clamped_val)) - selector_radius, 0, selector_radius * 2, height() - 1); @@ -99,7 +98,7 @@ void ColorGradientWidget::SelectedColorChangedEvent(const Color &c, bool externa Color ColorGradientWidget::LerpColor(const Color &a, const Color &b, int i, int max) { - float t = clamp(static_cast(i) / static_cast(max), 0.0f, 1.0f); + float t = std::clamp(static_cast(i) / static_cast(max), 0.0f, 1.0f); return Color(lerp(a.red(), b.red(), t), lerp(a.green(), b.green(), t), diff --git a/app/widget/colorwheel/colorwheelwidget.cpp b/app/widget/colorwheel/colorwheelwidget.cpp index 78b19e85a..78d591978 100644 --- a/app/widget/colorwheel/colorwheelwidget.cpp +++ b/app/widget/colorwheel/colorwheelwidget.cpp @@ -23,7 +23,6 @@ #include #include -#include "common/clamp.h" #include "node/node.h" namespace olive { @@ -121,7 +120,7 @@ void ColorWheelWidget::SelectedColorChangedEvent(const Color &c, bool external) { if (external) { force_redraw_ = true; - val_ = clamp(c.value(), 0.0f, 1.0f); + val_ = std::clamp(c.value(), 0.0f, 1.0f); } } diff --git a/app/widget/nodeview/nodeviewedge.cpp b/app/widget/nodeview/nodeviewedge.cpp index 775596377..fd182fb8f 100644 --- a/app/widget/nodeview/nodeviewedge.cpp +++ b/app/widget/nodeview/nodeviewedge.cpp @@ -25,7 +25,6 @@ #include #include -#include "common/bezier.h" #include "common/lerp.h" #include "nodeview.h" #include "nodeviewitem.h" @@ -183,7 +182,7 @@ void NodeViewEdge::UpdateCurve() QPainterPath path; path.moveTo(start); - double angle = qAtan2(end.y() - start.y(), end.x() - start.x()); + double angle = std::atan2(end.y() - start.y(), end.x() - start.x()); if (curved_) { @@ -220,7 +219,7 @@ void NodeViewEdge::UpdateCurve() path.cubicTo(cp1, cp2, end); if (!qFuzzyCompare(start.x(), end.x())) { - double continue_x = end.x() - qCos(angle); + double continue_x = end.x() - std::cos(angle); double x1 = start.x(); double x2 = cp1.x(); @@ -241,7 +240,7 @@ void NodeViewEdge::UpdateCurve() double t = Bezier::CubicXtoT(continue_x, x1, x2, x3, x4); double y = Bezier::CubicTtoY(y1, y2, y3, y4, t); - angle = qAtan2(end.y() - y, end.x() - continue_x); + angle = std::atan2(end.y() - y, end.x() - continue_x); } } else { diff --git a/app/widget/slider/base/sliderladder.cpp b/app/widget/slider/base/sliderladder.cpp index 0ad993039..589f85662 100644 --- a/app/widget/slider/base/sliderladder.cpp +++ b/app/widget/slider/base/sliderladder.cpp @@ -31,7 +31,6 @@ #include #endif -#include "common/clamp.h" #include "common/lerp.h" #include "common/qtutils.h" #include "config/config.h" diff --git a/app/widget/standardcombos/channellayoutcombobox.h b/app/widget/standardcombos/channellayoutcombobox.h index 58a468bdd..0cdf7a503 100644 --- a/app/widget/standardcombos/channellayoutcombobox.h +++ b/app/widget/standardcombos/channellayoutcombobox.h @@ -21,12 +21,15 @@ #ifndef CHANNELLAYOUTCOMBOBOX_H #define CHANNELLAYOUTCOMBOBOX_H +#include #include -#include "render/audioparams.h" +#include "ui/humanstrings.h" namespace olive { +using namespace core; + class ChannelLayoutComboBox : public QComboBox { Q_OBJECT @@ -35,7 +38,7 @@ public: QComboBox(parent) { foreach (const uint64_t& ch_layout, AudioParams::kSupportedChannelLayouts) { - this->addItem(AudioParams::ChannelLayoutToString(ch_layout), + this->addItem(HumanStrings::ChannelLayoutToString(ch_layout), QVariant::fromValue(ch_layout)); } } diff --git a/app/widget/standardcombos/pixelformatcombobox.h b/app/widget/standardcombos/pixelformatcombobox.h index 46fc31312..387a6db43 100644 --- a/app/widget/standardcombos/pixelformatcombobox.h +++ b/app/widget/standardcombos/pixelformatcombobox.h @@ -35,7 +35,7 @@ public: QComboBox(parent) { // Set up preview formats - for (int i=0;i(i); if (!float_only || pix_fmt.is_float()) { diff --git a/app/widget/standardcombos/sampleformatcombobox.h b/app/widget/standardcombos/sampleformatcombobox.h index 046ad9d34..2c991bc34 100644 --- a/app/widget/standardcombos/sampleformatcombobox.h +++ b/app/widget/standardcombos/sampleformatcombobox.h @@ -21,12 +21,15 @@ #ifndef SAMPLEFORMATCOMBOBOX_H #define SAMPLEFORMATCOMBOBOX_H +#include #include -#include "render/audioparams.h" +#include "ui/humanstrings.h" namespace olive { +using namespace core; + class SampleFormatComboBox : public QComboBox { Q_OBJECT @@ -39,16 +42,16 @@ public: void SetAttemptToRestoreFormat(bool e) { attempt_to_restore_format_ = e; } - void SetAvailableFormats(const std::vector &formats) + void SetAvailableFormats(const std::vector &formats) { - AudioParams::Format tmp = AudioParams::kFormatInvalid; + SampleFormat tmp = SampleFormat::INVALID; if (attempt_to_restore_format_) { tmp = GetSampleFormat(); } clear(); - foreach (const AudioParams::Format &of, formats) { + foreach (const SampleFormat &of, formats) { AddFormatItem(of); } @@ -59,15 +62,15 @@ public: void SetPackedFormats() { - AudioParams::Format tmp = AudioParams::kFormatInvalid; + SampleFormat tmp = SampleFormat::INVALID; if (attempt_to_restore_format_) { tmp = GetSampleFormat(); } clear(); - for (int i=AudioParams::kPackedStart; i(i)); + for (int i=SampleFormat::PACKED_START; i(i)); } if (attempt_to_restore_format_) { @@ -75,12 +78,12 @@ public: } } - AudioParams::Format GetSampleFormat() const + SampleFormat GetSampleFormat() const { - return static_cast(this->currentData().toInt()); + return static_cast(this->currentData().toInt()); } - void SetSampleFormat(AudioParams::Format fmt) + void SetSampleFormat(SampleFormat fmt) { for (int i=0; icount(); i++) { if (this->itemData(i).toInt() == fmt) { @@ -91,9 +94,9 @@ public: } private: - void AddFormatItem(AudioParams::Format f) + void AddFormatItem(SampleFormat f) { - this->addItem(AudioParams::FormatToString(f), f); + this->addItem(HumanStrings::FormatToString(f), static_cast(f)); } bool attempt_to_restore_format_; diff --git a/app/widget/standardcombos/sampleratecombobox.h b/app/widget/standardcombos/sampleratecombobox.h index 653cc0c87..dabb86f38 100644 --- a/app/widget/standardcombos/sampleratecombobox.h +++ b/app/widget/standardcombos/sampleratecombobox.h @@ -21,12 +21,15 @@ #ifndef SAMPLERATECOMBOBOX_H #define SAMPLERATECOMBOBOX_H +#include #include -#include "render/audioparams.h" +#include "ui/humanstrings.h" namespace olive { +using namespace core; + class SampleRateComboBox : public QComboBox { Q_OBJECT @@ -35,7 +38,7 @@ public: QComboBox(parent) { foreach (int sr, AudioParams::kSupportedSampleRates) { - this->addItem(AudioParams::SampleRateToString(sr), sr); + this->addItem(HumanStrings::SampleRateToString(sr), sr); } } diff --git a/app/widget/timebased/timebasedwidget.cpp b/app/widget/timebased/timebasedwidget.cpp index 15145f999..d9b0d7ef5 100644 --- a/app/widget/timebased/timebasedwidget.cpp +++ b/app/widget/timebased/timebasedwidget.cpp @@ -153,7 +153,7 @@ void TimeBasedWidget::UpdateMaximumScroll() rational length = (viewer_node_) ? viewer_node_->GetLength() : 0; if (auto_max_scrollbar_) { - scrollbar_->setMaximum(qMax(0, qCeil(TimeToScene(length)) - width())); + scrollbar_->setMaximum(std::max(0, int(std::ceil(TimeToScene(length)) - width()))); } foreach (TimeBasedView* base, timeline_views_) { diff --git a/app/widget/timebased/timescaledobject.cpp b/app/widget/timebased/timescaledobject.cpp index 1102f31ed..f0bc6c22f 100644 --- a/app/widget/timebased/timescaledobject.cpp +++ b/app/widget/timebased/timescaledobject.cpp @@ -24,7 +24,6 @@ #include #include "audio/audiovisualwaveform.h" -#include "common/clamp.h" namespace olive { @@ -124,7 +123,7 @@ void TimeScaledObject::SetScale(const double& scale) { Q_ASSERT(scale > 0); - scale_ = clamp(scale, min_scale_, max_scale_); + scale_ = std::clamp(scale, min_scale_, max_scale_); ScaleChangedEvent(scale_); } diff --git a/app/widget/timelinewidget/tool/pointer.cpp b/app/widget/timelinewidget/tool/pointer.cpp index eca7470a6..0cd3ddfd0 100644 --- a/app/widget/timelinewidget/tool/pointer.cpp +++ b/app/widget/timelinewidget/tool/pointer.cpp @@ -23,7 +23,6 @@ #include #include -#include "common/clamp.h" #include "common/qtutils.h" #include "common/range.h" #include "config/config.h" @@ -948,7 +947,7 @@ rational PointerTool::ValidateInTrimming(rational movement) // Clamp adjusted value between the earliest and latest values rational adjusted = ghost->GetIn() + movement; - rational clamped = clamp(adjusted, earliest_in, latest_in); + rational clamped = std::clamp(adjusted, earliest_in, latest_in); if (clamped != adjusted) { movement = clamped - ghost->GetIn(); @@ -985,7 +984,7 @@ rational PointerTool::ValidateOutTrimming(rational movement) // Clamp adjusted value between the earliest and latest values rational adjusted = ghost->GetOut() + movement; - rational clamped = clamp(adjusted, earliest_out, latest_out); + rational clamped = std::clamp(adjusted, earliest_out, latest_out); if (clamped != adjusted) { movement = clamped - ghost->GetOut(); diff --git a/app/widget/timeruler/timeruler.cpp b/app/widget/timeruler/timeruler.cpp index 1fa74f9d3..87cc879bb 100644 --- a/app/widget/timeruler/timeruler.cpp +++ b/app/widget/timeruler/timeruler.cpp @@ -198,7 +198,7 @@ void TimeRuler::drawForeground(QPainter *p, const QRectF &rect) double screen_pt = static_cast(i); if (long_interval > -1) { - int this_long_unit = qFloor(screen_pt/long_interval); + int this_long_unit = std::floor(screen_pt/long_interval); if (this_long_unit != last_long_unit) { int line_y = long_y; @@ -241,7 +241,7 @@ void TimeRuler::drawForeground(QPainter *p, const QRectF &rect) } if (short_interval > -1) { - int this_short_unit = qFloor(screen_pt/short_interval); + int this_short_unit = std::floor(screen_pt/short_interval); if (this_short_unit != last_short_unit) { p->drawLine(i, short_y, i, line_bottom); last_short_unit = this_short_unit; diff --git a/app/widget/viewer/audiowaveformview.cpp b/app/widget/viewer/audiowaveformview.cpp index 8ad081e6f..639eed5dd 100644 --- a/app/widget/viewer/audiowaveformview.cpp +++ b/app/widget/viewer/audiowaveformview.cpp @@ -24,7 +24,6 @@ #include #include -#include "common/clamp.h" #include "config/config.h" #include "timeline/timelinecommon.h" diff --git a/app/widget/viewer/audiowaveformview.h b/app/widget/viewer/audiowaveformview.h index 73162a06a..ade710e1e 100644 --- a/app/widget/viewer/audiowaveformview.h +++ b/app/widget/viewer/audiowaveformview.h @@ -24,7 +24,6 @@ #include #include -#include "render/audioparams.h" #include "render/audioplaybackcache.h" #include "widget/timeruler/seekablewidget.h" diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index 0c8e91b33..e267cff41 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -32,7 +32,6 @@ #include #include "audio/audiomanager.h" -#include "common/clamp.h" #include "common/ratiodialog.h" #include "config/config.h" #include "core.h" @@ -512,7 +511,7 @@ void ViewerWidget::UpdateAudioProcessor() AudioParams ap = GetConnectedNode()->GetAudioParams(); AudioParams packed(OLIVE_CONFIG("AudioOutputSampleRate").toInt(), OLIVE_CONFIG("AudioOutputChannelLayout").toULongLong(), - static_cast(OLIVE_CONFIG("AudioOutputSampleFormat").toInt())); + SampleFormat::from_string(OLIVE_CONFIG("AudioOutputSampleFormat").toString().toStdString())); audio_processor_.Open(ap, packed, (playback_speed_ == 0) ? 1 : std::abs(playback_speed_)); } @@ -728,7 +727,7 @@ void ViewerWidget::QueueNextAudioBuffer() rational queue_end = audio_playback_queue_time_ + (kAudioPlaybackInterval * playback_speed_); // Clamp queue end by zero and the audio length - queue_end = clamp(queue_end, rational(0), GetConnectedNode()->GetAudioLength()); + queue_end = std::clamp(queue_end, rational(0), GetConnectedNode()->GetAudioLength()); if ((playback_speed_ > 0 && queue_end <= audio_playback_queue_time_) || (playback_speed_ < 0 && queue_end >= audio_playback_queue_time_)) { // This will queue nothing, so stop the loop here @@ -1558,7 +1557,9 @@ void ViewerWidget::Play(bool in_to_out_only) ExportFormat::GetExtension(static_cast(OLIVE_CONFIG("AudioRecordingFormat").toInt()))) ); - AudioParams ap(OLIVE_CONFIG("AudioRecordingSampleRate").toInt(), OLIVE_CONFIG("AudioRecordingChannelLayout").toULongLong(), static_cast(OLIVE_CONFIG("AudioRecordingSampleFormat").toInt())); + AudioParams ap(OLIVE_CONFIG("AudioRecordingSampleRate").toInt(), + OLIVE_CONFIG("AudioRecordingChannelLayout").toULongLong(), + SampleFormat::from_string(OLIVE_CONFIG("AudioRecordingSampleFormat").toString().toStdString())); EncodingParams encode_param; encode_param.EnableAudio(ap, static_cast(OLIVE_CONFIG("AudioRecordingCodec").toInt())); diff --git a/cmake/FindOlive.cmake b/cmake/FindOlive.cmake index 20b34f5f4..01b57204a 100644 --- a/cmake/FindOlive.cmake +++ b/cmake/FindOlive.cmake @@ -29,15 +29,19 @@ foreach (COMPONENT ${LIBOLIVE_COMPONENTS}) HINTS "${LIBOLIVE_LOCATION}" "$ENV{LIBOLIVE_LOCATION}" + "${LIBOLIVE_ROOT}" + "$ENV{LIBOLIVE_ROOT}" PATH_SUFFIXES include/ ) find_library(LIBOLIVE_${UPPER_COMPONENT}_LIBRARY - olivecore + olive${LOWER_COMPONENT} HINTS "${LIBOLIVE_LOCATION}" "$ENV{LIBOLIVE_LOCATION}" + "${LIBOLIVE_ROOT}" + "$ENV{LIBOLIVE_ROOT}" PATH_SUFFIXES lib/ )