various: moved more to core lib

This commit is contained in:
itsmattkc
2023-01-19 16:01:31 -08:00
parent dd9c52ab59
commit c1c6893713
92 changed files with 448 additions and 1558 deletions
-1
View File
@@ -27,7 +27,6 @@
#include "audio/audiovisualwaveform.h"
#include "common/define.h"
#include "render/audioparams.h"
#include "render/audiowaveformcache.h"
namespace olive {
+3 -1
View File
@@ -21,14 +21,16 @@
#ifndef BEZIERWIDGET_H
#define BEZIERWIDGET_H
#include <olive/core/core.h>
#include <QCheckBox>
#include <QWidget>
#include "common/bezier.h"
#include "widget/slider/floatslider.h"
namespace olive {
using namespace core;
class BezierWidget : public QWidget
{
Q_OBJECT
@@ -22,7 +22,6 @@
#include <QPainter>
#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<float>(i) / static_cast<float>(max), 0.0f, 1.0f);
float t = std::clamp(static_cast<float>(i) / static_cast<float>(max), 0.0f, 1.0f);
return Color(lerp(a.red(), b.red(), t),
lerp(a.green(), b.green(), t),
+1 -2
View File
@@ -23,7 +23,6 @@
#include <QPainter>
#include <QtMath>
#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);
}
}
+3 -4
View File
@@ -25,7 +25,6 @@
#include <QGraphicsSceneMouseEvent>
#include <QStyleOptionGraphicsItem>
#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 {
-1
View File
@@ -31,7 +31,6 @@
#include <ApplicationServices/ApplicationServices.h>
#endif
#include "common/clamp.h"
#include "common/lerp.h"
#include "common/qtutils.h"
#include "config/config.h"
@@ -21,12 +21,15 @@
#ifndef CHANNELLAYOUTCOMBOBOX_H
#define CHANNELLAYOUTCOMBOBOX_H
#include <olive/core/core.h>
#include <QComboBox>
#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));
}
}
@@ -35,7 +35,7 @@ public:
QComboBox(parent)
{
// Set up preview formats
for (int i=0;i<PixelFormat::FORMAT_COUNT;i++) {
for (int i=0;i<PixelFormat::COUNT;i++) {
PixelFormat pix_fmt = static_cast<PixelFormat::Format>(i);
if (!float_only || pix_fmt.is_float()) {
@@ -21,12 +21,15 @@
#ifndef SAMPLEFORMATCOMBOBOX_H
#define SAMPLEFORMATCOMBOBOX_H
#include <olive/core/core.h>
#include <QComboBox>
#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<AudioParams::Format> &formats)
void SetAvailableFormats(const std::vector<SampleFormat> &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<AudioParams::kPackedEnd; i++) {
AddFormatItem(static_cast<AudioParams::Format>(i));
for (int i=SampleFormat::PACKED_START; i<SampleFormat::PACKED_END; i++) {
AddFormatItem(static_cast<SampleFormat::Format>(i));
}
if (attempt_to_restore_format_) {
@@ -75,12 +78,12 @@ public:
}
}
AudioParams::Format GetSampleFormat() const
SampleFormat GetSampleFormat() const
{
return static_cast<AudioParams::Format>(this->currentData().toInt());
return static_cast<SampleFormat::Format>(this->currentData().toInt());
}
void SetSampleFormat(AudioParams::Format fmt)
void SetSampleFormat(SampleFormat fmt)
{
for (int i=0; i<this->count(); 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<SampleFormat::Format>(f));
}
bool attempt_to_restore_format_;
@@ -21,12 +21,15 @@
#ifndef SAMPLERATECOMBOBOX_H
#define SAMPLERATECOMBOBOX_H
#include <olive/core/core.h>
#include <QComboBox>
#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);
}
}
+1 -1
View File
@@ -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_) {
+1 -2
View File
@@ -24,7 +24,6 @@
#include <QtMath>
#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_);
}
+2 -3
View File
@@ -23,7 +23,6 @@
#include <QDebug>
#include <QToolTip>
#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();
+2 -2
View File
@@ -198,7 +198,7 @@ void TimeRuler::drawForeground(QPainter *p, const QRectF &rect)
double screen_pt = static_cast<double>(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;
-1
View File
@@ -24,7 +24,6 @@
#include <QPainter>
#include <QtMath>
#include "common/clamp.h"
#include "config/config.h"
#include "timeline/timelinecommon.h"
-1
View File
@@ -24,7 +24,6 @@
#include <QtConcurrent/QtConcurrent>
#include <QWidget>
#include "render/audioparams.h"
#include "render/audioplaybackcache.h"
#include "widget/timeruler/seekablewidget.h"
+5 -4
View File
@@ -32,7 +32,6 @@
#include <QVBoxLayout>
#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<AudioParams::Format>(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<ExportFormat::Format>(OLIVE_CONFIG("AudioRecordingFormat").toInt())))
);
AudioParams ap(OLIVE_CONFIG("AudioRecordingSampleRate").toInt(), OLIVE_CONFIG("AudioRecordingChannelLayout").toULongLong(), static_cast<AudioParams::Format>(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<ExportCodec::Codec>(OLIVE_CONFIG("AudioRecordingCodec").toInt()));