Files
oak-editor/app/widget/timebased/timescaledobject.cpp
T
Mike-Solar 66d761b4b7 R8: finish app/ pure C ABI migration (P3-P9) and make OTIO required
- app/ no longer includes engine C++ headers nor holds engine C++ types:
  engine access goes through the oakengine C ABI plus C++ wrappers
  (oakutil/oaknode.h, oakutil/oakvideo.h) and app-local mirror types
  (tooltypes, trackreferencehandle, timelinecommonapp, keyframetypes,
  subtitleapp, serializedlayoutinfoapp, nodevaluehandle, sliderdisplaytypeapp)
- engine: new C ABI functions for block/track/clip/transition navigation
  and predicates, links, caches, waveform/playback, disk folder,
  sequence_track_list, node_free, footage_is_valid, block_get_track,
  get_brush; loadotio/saveotio ported to the current engine API
- OTIO is now a required dependency: CI and CD build it on every
  platform, FindOpenTimelineIO fixed for OTIO 0.16/0.19 (the old deps
  include requirement silently disabled OTIO everywhere), runtime
  libraries are bundled into packages and copied next to macOS binaries
  (oak_copy_otio_runtime)
- fix ProjectViewModel drag&drop mime read/write size mismatch (segfault)
- unify color label naming (k_olive -> "Oak") in the app-side mirror
- docs: OTIO required, FFmpeg minimum corrected to 6.0 (en/zh)
- gtest suite: 1925 passed, 0 failed
2026-07-31 22:46:52 +08:00

172 lines
3.9 KiB
C++

/***
Olive - Non-Linear Video Editor
Copyright (C) 2022 Olive Team
Modifications Copyright (C) 2025 mikesolar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "timescaledobject.h"
#include <cfloat>
#include <QtMath>
#include "oakengine/node.h"
namespace olive
{
const int TimeScaledObject::k_calculate_dimensions_padding = 10;
TimeScaledObject::TimeScaledObject()
: scale_(1.0)
, min_scale_(0)
, max_scale_(oakengine_audio_waveform_max_sample_rate())
{
}
void TimeScaledObject::set_timebase(const Rational &timebase)
{
timebase_ = timebase;
timebase_dbl_ = timebase_.to_double();
TimebaseChangedEvent(timebase);
}
const Rational &TimeScaledObject::timebase() const
{
return timebase_;
}
const double &TimeScaledObject::timebase_dbl() const
{
return timebase_dbl_;
}
Rational TimeScaledObject::scene_to_time(const double &x, const double &x_scale,
const Rational &timebase, bool round)
{
if (timebase.isNull()) {
return Rational();
}
double unscaled_time = x / x_scale / timebase.to_double();
// Adjust screen point by scale and timebase
qint64 rounded_x_mvmt;
if (round) {
rounded_x_mvmt = qRound64(unscaled_time);
} else if (unscaled_time < 0) {
// "floor" to zero
rounded_x_mvmt = qCeil(unscaled_time);
} else {
rounded_x_mvmt = qFloor(unscaled_time);
}
// Return a time in the timebase
return Rational(rounded_x_mvmt * timebase.numerator(),
timebase.denominator());
}
Rational TimeScaledObject::scene_to_time_no_grid(const double &x,
const double &x_scale)
{
double unscaled_time = x / x_scale;
return Rational::from_double(unscaled_time);
}
double TimeScaledObject::time_to_scene(const Rational &time) const
{
if (timebase_.isNull()) {
return 0.0;
}
return time.to_double() * scale_;
}
Rational TimeScaledObject::scene_to_time(const double &x, bool round) const
{
if (timebase_.isNull()) {
return Rational();
}
return scene_to_time(x, scale_, timebase_, round);
}
Rational TimeScaledObject::scene_to_time_no_grid(const double &x) const
{
if (timebase_.isNull()) {
return Rational::from_double(x / scale_);
}
return scene_to_time_no_grid(x, scale_);
}
void TimeScaledObject::set_maximum_scale(const double &max)
{
max_scale_ = max;
if (get_scale() > max_scale_) {
set_scale(max_scale_);
}
}
void TimeScaledObject::set_minimum_scale(const double &min)
{
min_scale_ = min;
if (get_scale() < min_scale_) {
set_scale(min_scale_);
}
}
const double &TimeScaledObject::get_scale() const
{
return scale_;
}
void TimeScaledObject::set_scale(const double &scale)
{
Q_ASSERT(scale > 0);
scale_ = std::clamp(scale, min_scale_, max_scale_);
ScaleChangedEvent(scale_);
}
void TimeScaledObject::set_scale_from_dimensions(double viewport_width,
double content_width)
{
set_scale(calculate_scale_from_dimensions(viewport_width, content_width));
}
double TimeScaledObject::calculate_scale_from_dimensions(double viewport_sz,
double content_sz)
{
return static_cast<double>(viewport_sz / k_calculate_dimensions_padding *
(k_calculate_dimensions_padding - 1)) /
static_cast<double>(content_sz);
}
double TimeScaledObject::calculate_padding_from_dimension_scale(double viewport_sz)
{
return (viewport_sz / (k_calculate_dimensions_padding * 2));
}
TimelineScaledWidget::TimelineScaledWidget(QWidget *parent)
: QWidget(parent)
{
}
}