diff --git a/app/dialog/export/codec/imagesection.cpp b/app/dialog/export/codec/imagesection.cpp index caf7a0ef0..cf38fd698 100644 --- a/app/dialog/export/codec/imagesection.cpp +++ b/app/dialog/export/codec/imagesection.cpp @@ -43,9 +43,10 @@ ImageSection::ImageSection(QWidget* parent) : layout->addWidget(new QLabel(tr("Frame to Export:")), row, 0); - frame_slider_ = new TimeSlider(); + frame_slider_ = new RationalSlider(); frame_slider_->SetMinimum(0); frame_slider_->SetValue(0); + frame_slider_->SetDisplayType(RationalSlider::kTime); layout->addWidget(frame_slider_, row, 1); } diff --git a/app/dialog/export/codec/imagesection.h b/app/dialog/export/codec/imagesection.h index 933678e17..6e116b466 100644 --- a/app/dialog/export/codec/imagesection.h +++ b/app/dialog/export/codec/imagesection.h @@ -24,7 +24,7 @@ #include #include "codecsection.h" -#include "widget/slider/timeslider.h" +#include "widget/slider/rationalslider.h" namespace olive { @@ -44,12 +44,12 @@ public: frame_slider_->SetTimebase(r); } - int64_t GetTimestamp() const + rational GetTime() const { return frame_slider_->GetValue(); } - void SetTimestamp(int64_t t) + void SetTime(const rational &t) { frame_slider_->SetValue(t); } @@ -57,7 +57,7 @@ public: private: QCheckBox* image_sequence_checkbox_; - TimeSlider* frame_slider_; + RationalSlider* frame_slider_; private slots: void ImageSequenceCheckBoxToggled(bool e); diff --git a/app/dialog/export/export.cpp b/app/dialog/export/export.cpp index 16e0bb8ae..acf3de5ce 100644 --- a/app/dialog/export/export.cpp +++ b/app/dialog/export/export.cpp @@ -167,7 +167,7 @@ ExportDialog::ExportDialog(ViewerOutput *viewer_node, QWidget *parent) : preview_layout->addWidget(new QLabel(tr("Preview"))); preview_viewer_ = new ViewerWidget(); preview_viewer_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - connect(preview_viewer_, &ViewerWidget::TimeChanged, video_tab_, &ExportVideoTab::SetTimestamp); + connect(preview_viewer_, &ViewerWidget::TimeChanged, video_tab_, &ExportVideoTab::SetTime); preview_layout->addWidget(preview_viewer_); splitter->addWidget(preview_area); @@ -527,7 +527,7 @@ ExportParams ExportDialog::GenerateParams() const if (ExportCodec::IsCodecAStillImage(video_tab_->GetSelectedCodec()) && !video_tab_->IsImageSequenceSet()) { // Exporting as image without exporting image sequence, only export one frame - rational export_time = Timecode::timestamp_to_time(video_tab_->GetStillImageTime(), GetSelectedTimebase()); + rational export_time = video_tab_->GetStillImageTime(); params.set_custom_range(TimeRange(export_time, export_time)); } else if (range_combobox_->currentIndex() == kRangeInToOut) { // Assume if this combobox is enabled, workarea is enabled - a check that we make in this dialog's constructor diff --git a/app/dialog/export/exportvideotab.cpp b/app/dialog/export/exportvideotab.cpp index 9c5b98b57..7aa6844fe 100644 --- a/app/dialog/export/exportvideotab.cpp +++ b/app/dialog/export/exportvideotab.cpp @@ -252,12 +252,12 @@ void ExportVideoTab::VideoCodecChanged() qDebug() << "Set default pix fmt" << pix_fmt_; } -void ExportVideoTab::SetTimestamp(int64_t timestamp) +void ExportVideoTab::SetTime(const rational &time) { for (int i=0; icount(); i++) { ImageSection* img = dynamic_cast(codec_stack_->widget(i)); if (img) { - img->SetTimestamp(timestamp); + img->SetTime(time); } } } diff --git a/app/dialog/export/exportvideotab.h b/app/dialog/export/exportvideotab.h index 45b2d50bb..ce74d5a0a 100644 --- a/app/dialog/export/exportvideotab.h +++ b/app/dialog/export/exportvideotab.h @@ -45,9 +45,9 @@ public: bool IsImageSequenceSet() const; - int64_t GetStillImageTime() const + rational GetStillImageTime() const { - return image_section_->GetTimestamp(); + return image_section_->GetTime(); } ExportCodec::Codec GetSelectedCodec() const @@ -138,7 +138,7 @@ public: public slots: void VideoCodecChanged(); - void SetTimestamp(int64_t timestamp); + void SetTime(const rational &time); signals: void ColorSpaceChanged(const QString& colorspace); diff --git a/app/dialog/keyframeproperties/keyframeproperties.cpp b/app/dialog/keyframeproperties/keyframeproperties.cpp index 6a518d52f..9637c486f 100644 --- a/app/dialog/keyframeproperties/keyframeproperties.cpp +++ b/app/dialog/keyframeproperties/keyframeproperties.cpp @@ -43,7 +43,8 @@ KeyframePropertiesDialog::KeyframePropertiesDialog(const QVector layout->addWidget(new QLabel("Time:"), row, 0); - time_slider_ = new TimeSlider(); + time_slider_ = new RationalSlider(); + time_slider_->SetDisplayType(RationalSlider::kTime); time_slider_->SetTimebase(timebase_); layout->addWidget(time_slider_, row, 1); @@ -146,7 +147,7 @@ KeyframePropertiesDialog::KeyframePropertiesDialog(const QVector } if (all_same_time) { - time_slider_->SetValue(Timecode::time_to_timestamp(keys_.first()->time(), timebase_)); + time_slider_->SetValue(keys_.first()->time()); } else { time_slider_->SetTristate(); } @@ -196,7 +197,7 @@ void KeyframePropertiesDialog::accept() { MultiUndoCommand* command = new MultiUndoCommand(); - rational new_time = Timecode::timestamp_to_time(time_slider_->GetValue(), timebase_); + rational new_time = time_slider_->GetValue(); int new_type = type_select_->currentData().toInt(); foreach (NodeKeyframe* key, keys_) { diff --git a/app/dialog/keyframeproperties/keyframeproperties.h b/app/dialog/keyframeproperties/keyframeproperties.h index 708d3b988..835845943 100644 --- a/app/dialog/keyframeproperties/keyframeproperties.h +++ b/app/dialog/keyframeproperties/keyframeproperties.h @@ -27,7 +27,7 @@ #include "node/keyframe.h" #include "widget/slider/floatslider.h" -#include "widget/slider/timeslider.h" +#include "widget/slider/rationalslider.h" namespace olive { @@ -47,7 +47,7 @@ private: rational timebase_; - TimeSlider* time_slider_; + RationalSlider* time_slider_; QComboBox* type_select_; diff --git a/app/panel/timebased/timebased.cpp b/app/panel/timebased/timebased.cpp index c897add29..44cc51281 100644 --- a/app/panel/timebased/timebased.cpp +++ b/app/panel/timebased/timebased.cpp @@ -74,9 +74,9 @@ void TimeBasedPanel::SetTimebase(const rational &timebase) widget_->SetTimebase(timebase); } -void TimeBasedPanel::SetTimestamp(const int64_t ×tamp) +void TimeBasedPanel::SetTime(const rational &time) { - widget_->SetTimestamp(timestamp); + widget_->SetTime(time); } void TimeBasedPanel::GoToPrevCut() diff --git a/app/panel/timebased/timebased.h b/app/panel/timebased/timebased.h index 9559d1f9f..b85657e4d 100644 --- a/app/panel/timebased/timebased.h +++ b/app/panel/timebased/timebased.h @@ -101,10 +101,10 @@ public: public slots: void SetTimebase(const rational& timebase); - virtual void SetTimestamp(const int64_t& timestamp); + void SetTime(const rational &time); signals: - void TimeChanged(const int64_t& time); + void TimeChanged(const rational& time); void TimebaseChanged(const rational& timebase); diff --git a/app/widget/curvewidget/curvewidget.cpp b/app/widget/curvewidget/curvewidget.cpp index 7b124934e..4de5787ef 100644 --- a/app/widget/curvewidget/curvewidget.cpp +++ b/app/widget/curvewidget/curvewidget.cpp @@ -59,7 +59,7 @@ CurveWidget::CurveWidget(QWidget *parent) : QHBoxLayout* top_controls = new QHBoxLayout(); key_control_ = new NodeParamViewKeyframeControl(false); - connect(key_control_, &NodeParamViewKeyframeControl::RequestSetTime, this, &CurveWidget::KeyControlRequestedTimeChanged); + connect(key_control_, &NodeParamViewKeyframeControl::RequestSetTime, this, &CurveWidget::SetTimeAndSignal); top_controls->addWidget(key_control_); top_controls->addStretch(); @@ -156,12 +156,12 @@ void CurveWidget::SetNodes(const QVector &nodes) nodes_ = nodes; } -void CurveWidget::TimeChangedEvent(const int64_t ×tamp) +void CurveWidget::TimeChangedEvent(const rational &time) { - TimeBasedWidget::TimeChangedEvent(timestamp); + TimeBasedWidget::TimeChangedEvent(time); - view_->SetTime(timestamp); - UpdateBridgeTime(timestamp); + view_->SetTime(time); + UpdateBridgeTime(time); } void CurveWidget::TimebaseChangedEvent(const rational &timebase) @@ -211,9 +211,8 @@ void CurveWidget::SetKeyframeButtonCheckedFromType(NodeKeyframe::Type type) hold_button_->setChecked(type == NodeKeyframe::kHold); } -void CurveWidget::UpdateBridgeTime(const int64_t ×tamp) +void CurveWidget::UpdateBridgeTime(const rational &time) { - rational time = Timecode::timestamp_to_time(timestamp, view_->timebase()); key_control_->SetTime(time); } @@ -355,11 +354,6 @@ void CurveWidget::KeyframeTypeButtonTriggered(bool checked) Core::instance()->undo_stack()->push(command); } -void CurveWidget::KeyControlRequestedTimeChanged(const rational &time) -{ - SetTimeAndSignal(Timecode::time_to_timestamp(time, view_->timebase())); -} - void CurveWidget::NodeEnabledChanged(Node* n, bool e) { ConnectNode(n, e); diff --git a/app/widget/curvewidget/curvewidget.h b/app/widget/curvewidget/curvewidget.h index 5e8daf8f2..7b9e01021 100644 --- a/app/widget/curvewidget/curvewidget.h +++ b/app/widget/curvewidget/curvewidget.h @@ -61,7 +61,7 @@ public slots: void SetNodes(const QVector &nodes); protected: - virtual void TimeChangedEvent(const int64_t &) override; + virtual void TimeChangedEvent(const rational &) override; virtual void TimebaseChangedEvent(const rational &) override; virtual void ScaleChangedEvent(const double &) override; @@ -76,7 +76,7 @@ private: void SetKeyframeButtonCheckedFromType(NodeKeyframe::Type type); - void UpdateBridgeTime(const int64_t& timestamp); + void UpdateBridgeTime(const rational &time); void ConnectNode(Node* node, bool connect); @@ -103,8 +103,6 @@ private slots: void KeyframeTypeButtonTriggered(bool checked); - void KeyControlRequestedTimeChanged(const rational& time); - void NodeEnabledChanged(Node* n, bool e); void InputEnabledChanged(const NodeKeyframeTrackReference &ref, bool e); diff --git a/app/widget/nodeparamview/nodeparamview.cpp b/app/widget/nodeparamview/nodeparamview.cpp index b85fbc69d..a97c76b3a 100644 --- a/app/widget/nodeparamview/nodeparamview.cpp +++ b/app/widget/nodeparamview/nodeparamview.cpp @@ -92,7 +92,7 @@ NodeParamView::NodeParamView(QWidget *parent) : // Connect ruler and keyframe view together connect(ruler(), &TimeRuler::TimeChanged, keyframe_view_, &KeyframeView::SetTime); connect(keyframe_view_, &KeyframeView::TimeChanged, ruler(), &TimeRuler::SetTime); - connect(keyframe_view_, &KeyframeView::TimeChanged, this, &NodeParamView::SetTimestamp); + connect(keyframe_view_, &KeyframeView::TimeChanged, this, &NodeParamView::SetTime); connect(keyframe_view_, &KeyframeView::Dragged, this, &NodeParamView::KeyframeViewDragged); // Connect keyframe view scaling to this @@ -155,7 +155,7 @@ void NodeParamView::SelectNodes(const QVector &nodes) } if (items_.size() > original_node_count ) { - UpdateItemTime(GetTimestamp()); + UpdateItemTime(GetTime()); // Re-arrange keyframes QueueKeyframePositionUpdate(); @@ -220,16 +220,16 @@ void NodeParamView::TimebaseChangedEvent(const rational &timebase) item->SetTimebase(timebase); } - UpdateItemTime(GetTimestamp()); + UpdateItemTime(GetTime()); } -void NodeParamView::TimeChangedEvent(const int64_t ×tamp) +void NodeParamView::TimeChangedEvent(const rational &time) { - super::TimeChangedEvent(timestamp); + super::TimeChangedEvent(time); - keyframe_view_->SetTime(timestamp); + keyframe_view_->SetTime(time); - UpdateItemTime(timestamp); + UpdateItemTime(time); } void NodeParamView::ConnectedNodeChangeEvent(ViewerOutput *n) @@ -252,10 +252,8 @@ void NodeParamView::DeleteSelected() keyframe_view_->DeleteSelected(); } -void NodeParamView::UpdateItemTime(const int64_t ×tamp) +void NodeParamView::UpdateItemTime(const rational &time) { - rational time = Timecode::timestamp_to_time(timestamp, timebase()); - foreach (NodeParamViewItem* item, items_) { item->SetTime(time); } @@ -306,7 +304,7 @@ void NodeParamView::AddNode(Node *n) connect(n, &Node::KeyframeAdded, keyframe_view_, &KeyframeView::AddKeyframe); connect(n, &Node::KeyframeRemoved, keyframe_view_, &KeyframeView::RemoveKeyframe); - connect(item, &NodeParamViewItem::RequestSetTime, this, &NodeParamView::ItemRequestedTimeChanged); + connect(item, &NodeParamViewItem::RequestSetTime, this, &NodeParamView::SetTimeAndSignal); connect(item, &NodeParamViewItem::RequestSelectNode, this, &NodeParamView::RequestSelectNode); connect(item, &NodeParamViewItem::dockLocationChanged, this, &NodeParamView::QueueKeyframePositionUpdate); connect(item, &NodeParamViewItem::dockLocationChanged, this, &NodeParamView::SignalNodeOrder); @@ -358,11 +356,6 @@ void NodeParamView::RemoveNode(Node *n) } } -void NodeParamView::ItemRequestedTimeChanged(const rational &time) -{ - SetTimeAndSignal(Timecode::time_to_timestamp(time, keyframe_view_->timebase())); -} - void NodeParamView::UpdateGlobalScrollBar() { int height_offscreen = param_widget_container_->height() - ruler()->height() + scrollbar()->height(); diff --git a/app/widget/nodeparamview/nodeparamview.h b/app/widget/nodeparamview/nodeparamview.h index 3e8f7edc4..1718f445e 100644 --- a/app/widget/nodeparamview/nodeparamview.h +++ b/app/widget/nodeparamview/nodeparamview.h @@ -94,12 +94,12 @@ protected: virtual void ScaleChangedEvent(const double &) override; virtual void TimebaseChangedEvent(const rational&) override; - virtual void TimeChangedEvent(const int64_t &) override; + virtual void TimeChangedEvent(const rational &time) override; virtual void ConnectedNodeChangeEvent(ViewerOutput* n) override; private: - void UpdateItemTime(const int64_t ×tamp); + void UpdateItemTime(const rational &time); void QueueKeyframePositionUpdate(); @@ -132,8 +132,6 @@ private: Node* focused_node_; private slots: - void ItemRequestedTimeChanged(const rational& time); - void UpdateGlobalScrollBar(); void PinNode(bool pin); diff --git a/app/widget/nodetableview/nodetablewidget.h b/app/widget/nodetableview/nodetablewidget.h index 558a3f2c1..13d800799 100644 --- a/app/widget/nodetableview/nodetablewidget.h +++ b/app/widget/nodetableview/nodetablewidget.h @@ -42,17 +42,12 @@ public: } protected: - virtual void TimeChangedEvent(const int64_t&) override + virtual void TimeChangedEvent(const rational &time) override { - UpdateView(); + view_->SetTime(time); } private: - void UpdateView() - { - view_->SetTime(GetTime()); - } - NodeTableView* view_; }; diff --git a/app/widget/playbackcontrols/playbackcontrols.cpp b/app/widget/playbackcontrols/playbackcontrols.cpp index 6fd514207..80bae6381 100644 --- a/app/widget/playbackcontrols/playbackcontrols.cpp +++ b/app/widget/playbackcontrols/playbackcontrols.cpp @@ -53,8 +53,9 @@ PlaybackControls::PlaybackControls(QWidget *parent) : lower_left_layout->setSpacing(0); lower_left_layout->setMargin(0); - cur_tc_lbl_ = new TimeSlider(); - connect(cur_tc_lbl_, &TimeSlider::ValueChanged, this, &PlaybackControls::TimeChanged); + cur_tc_lbl_ = new RationalSlider(); + cur_tc_lbl_->SetDisplayType(RationalSlider::kTime); + connect(cur_tc_lbl_, &RationalSlider::ValueChanged, this, &PlaybackControls::TimeChanged); lower_left_layout->addWidget(cur_tc_lbl_); lower_left_layout->addStretch(); @@ -179,12 +180,12 @@ void PlaybackControls::SetAudioVideoDragButtonsVisible(bool e) audio_drag_btn_->setVisible(e); } -void PlaybackControls::SetTime(const int64_t &r) +void PlaybackControls::SetTime(const rational &r) { cur_tc_lbl_->SetValue(r); } -void PlaybackControls::SetEndTime(const int64_t &r) +void PlaybackControls::SetEndTime(const rational &r) { if (time_base_.isNull()) { return; @@ -192,9 +193,9 @@ void PlaybackControls::SetEndTime(const int64_t &r) end_time_ = r; - end_tc_lbl_->setText(Timecode::timestamp_to_timecode(end_time_, - time_base_, - Core::instance()->GetTimecodeDisplay())); + end_tc_lbl_->setText(Timecode::time_to_timecode(end_time_, + time_base_, + Core::instance()->GetTimecodeDisplay())); } void PlaybackControls::ShowPauseButton() diff --git a/app/widget/playbackcontrols/playbackcontrols.h b/app/widget/playbackcontrols/playbackcontrols.h index 7a76560e1..b1d283f56 100644 --- a/app/widget/playbackcontrols/playbackcontrols.h +++ b/app/widget/playbackcontrols/playbackcontrols.h @@ -28,7 +28,7 @@ #include "common/rational.h" #include "dragbutton.h" -#include "widget/slider/timeslider.h" +#include "widget/slider/rationalslider.h" namespace olive { @@ -53,9 +53,9 @@ public: void SetAudioVideoDragButtonsVisible(bool e); public slots: - void SetTime(const int64_t &r); + void SetTime(const rational &r); - void SetEndTime(const int64_t &r); + void SetEndTime(const rational &r); void ShowPauseButton(); @@ -100,7 +100,7 @@ signals: void VideoPressed(); - void TimeChanged(const int64_t& t); + void TimeChanged(const rational& t); protected: virtual void changeEvent(QEvent *) override; @@ -111,10 +111,10 @@ private: QWidget* lower_left_container_; QWidget* lower_right_container_; - TimeSlider* cur_tc_lbl_; + RationalSlider* cur_tc_lbl_; QLabel* end_tc_lbl_; - int64_t end_time_; + rational end_time_; rational time_base_; diff --git a/app/widget/timebased/timebasedview.cpp b/app/widget/timebased/timebasedview.cpp index d0053dd17..0156771ab 100644 --- a/app/widget/timebased/timebasedview.cpp +++ b/app/widget/timebased/timebasedview.cpp @@ -33,7 +33,6 @@ const double TimeBasedView::kMaximumScale = 8192; TimeBasedView::TimeBasedView(QWidget *parent) : HandMovableView(parent), - playhead_(0), playhead_scene_left_(-1), playhead_scene_right_(-1), dragging_playhead_(false), @@ -150,7 +149,7 @@ void TimeBasedView::SetYScale(const double &y_scale) } } -void TimeBasedView::SetTime(const int64_t time) +void TimeBasedView::SetTime(const rational &time) { playhead_ = time; @@ -194,11 +193,6 @@ void TimeBasedView::drawForeground(QPainter *painter, const QRectF &rect) } } -rational TimeBasedView::GetPlayheadTime() const -{ - return Timecode::timestamp_to_time(playhead_, timebase()); -} - bool TimeBasedView::PlayheadPress(QMouseEvent *event) { QPointF scene_pos = mapToScene(event->pos()); @@ -217,23 +211,16 @@ bool TimeBasedView::PlayheadMove(QMouseEvent *event) } QPointF scene_pos = mapToScene(event->pos()); - rational mouse_time = SceneToTime(scene_pos.x()); - - int64_t target_ts = qMax(static_cast(0), Timecode::time_to_timestamp(mouse_time, timebase())); + rational mouse_time = qMax(rational(0), SceneToTime(scene_pos.x())); if (Core::instance()->snapping() && snap_service_) { - rational target_time = Timecode::timestamp_to_time(target_ts, timebase()); rational movement; - snap_service_->SnapPoint({target_time}, &movement, SnapService::kSnapAll & ~SnapService::kSnapToPlayhead); - - if (!movement.isNull()) { - target_ts = Timecode::time_to_timestamp(target_time + movement, timebase()); - } + snap_service_->SnapPoint({mouse_time}, &movement, SnapService::kSnapAll & ~SnapService::kSnapToPlayhead); } - SetTime(target_ts); - emit TimeChanged(target_ts); + SetTime(mouse_time); + emit TimeChanged(mouse_time); return true; } @@ -255,7 +242,7 @@ bool TimeBasedView::PlayheadRelease(QMouseEvent*) qreal TimeBasedView::GetPlayheadX() { - return TimeToScene(Timecode::timestamp_to_time(playhead_, timebase())); + return TimeToScene(playhead_); } void TimeBasedView::SetEndTime(const rational &length) diff --git a/app/widget/timebased/timebasedview.h b/app/widget/timebased/timebasedview.h index 55a6ec6d8..d7a6f4b49 100644 --- a/app/widget/timebased/timebasedview.h +++ b/app/widget/timebased/timebasedview.h @@ -56,12 +56,12 @@ public: } public slots: - void SetTime(const int64_t time); + void SetTime(const rational &time); void SetEndTime(const rational& length); signals: - void TimeChanged(const int64_t& time); + void TimeChanged(const rational& time); void ScaleChanged(double scale); @@ -78,7 +78,10 @@ protected: virtual void ZoomIntoCursorPosition(QWheelEvent *event, double multiplier, const QPointF &cursor_pos) override; - rational GetPlayheadTime() const; + const rational &GetPlayheadTime() const + { + return playhead_; + } bool PlayheadPress(QMouseEvent* event); bool PlayheadMove(QMouseEvent* event); @@ -105,7 +108,7 @@ protected slots: private: qreal GetPlayheadX(); - int64_t playhead_; + rational playhead_; double playhead_scene_left_; double playhead_scene_right_; diff --git a/app/widget/timebased/timebasedwidget.cpp b/app/widget/timebased/timebasedwidget.cpp index 86befc724..2b3691884 100644 --- a/app/widget/timebased/timebasedwidget.cpp +++ b/app/widget/timebased/timebasedwidget.cpp @@ -57,12 +57,7 @@ void TimeBasedWidget::SetScaleAndCenterOnPlayhead(const double &scale) QTimer::singleShot(0, this, &TimeBasedWidget::CenterScrollOnPlayhead); } -rational TimeBasedWidget::GetTime() const -{ - return Timecode::timestamp_to_time(ruler()->GetTime(), timebase()); -} - -const int64_t &TimeBasedWidget::GetTimestamp() const +const rational &TimeBasedWidget::GetTime() const { return ruler_->GetTime(); } @@ -273,8 +268,7 @@ void TimeBasedWidget::resizeEvent(QResizeEvent *event) void TimeBasedWidget::ConnectTimelineView(TimeBasedView *base, bool connect_time_change_event) { if (connect_time_change_event) { - connect(base, &TimeBasedView::TimeChanged, this, &TimeBasedWidget::SetTimestamp); - connect(base, &TimeBasedView::TimeChanged, this, &TimeBasedWidget::TimeChanged); + connect(base, &TimeBasedView::TimeChanged, this, &TimeBasedWidget::SetTimeAndSignal); } timeline_views_.append(base); @@ -286,7 +280,7 @@ void TimeBasedWidget::PassWheelEventsToScrollBar(QObject *object) object->installEventFilter(this); } -void TimeBasedWidget::SetTimestamp(int64_t timestamp) +void TimeBasedWidget::SetTime(const rational &time) { if (UserIsDraggingPlayhead()) { // If the user is dragging the playhead, we will simply nudge over and not use autoscroll rules. @@ -306,9 +300,9 @@ void TimeBasedWidget::SetTimestamp(int64_t timestamp) } } - ruler_->SetTime(timestamp); + ruler_->SetTime(time); - TimeChangedEvent(timestamp); + TimeChangedEvent(time); } void TimeBasedWidget::SetTimebase(const rational &timebase) @@ -341,20 +335,18 @@ void TimeBasedWidget::GoToPrevCut() return; } - if (GetTimestamp() == 0) { + if (GetTime().isNull()) { return; } - int64_t closest_cut = 0; + rational closest_cut = 0; foreach (Track* track, sequence->GetTracks()) { - int64_t this_track_closest_cut = 0; + rational this_track_closest_cut = 0; foreach (Block* block, track->Blocks()) { - int64_t block_out_ts = Timecode::time_to_timestamp(block->out(), timebase()); - - if (block_out_ts < GetTimestamp()) { - this_track_closest_cut = block_out_ts; + if (block->out() < GetTime()) { + this_track_closest_cut = block->out(); } else { break; } @@ -375,20 +367,18 @@ void TimeBasedWidget::GoToNextCut() return; } - int64_t closest_cut = INT64_MAX; + rational closest_cut = RATIONAL_MAX; foreach (Track* track, sequence->GetTracks()) { - int64_t this_track_closest_cut = Timecode::time_to_timestamp(track->track_length(), timebase()); + rational this_track_closest_cut = track->track_length(); - if (this_track_closest_cut <= GetTimestamp()) { - this_track_closest_cut = INT64_MAX; + if (this_track_closest_cut <= GetTime()) { + this_track_closest_cut = RATIONAL_MAX; } foreach (Block* block, track->Blocks()) { - int64_t block_in_ts = Timecode::time_to_timestamp(block->in(), timebase()); - - if (block_in_ts > GetTimestamp()) { - this_track_closest_cut = block_in_ts; + if (block->in() > GetTime()) { + this_track_closest_cut = block->in(); break; } } @@ -396,7 +386,7 @@ void TimeBasedWidget::GoToNextCut() closest_cut = qMin(closest_cut, this_track_closest_cut); } - if (closest_cut < INT64_MAX) { + if (closest_cut < RATIONAL_MAX) { SetTimeAndSignal(closest_cut); } } @@ -411,33 +401,43 @@ void TimeBasedWidget::GoToStart() void TimeBasedWidget::PrevFrame() { if (viewer_node_) { - SetTimeAndSignal(qMax(static_cast(0), ruler()->GetTime() - 1)); + rational proposed_time = Timecode::snap_time_to_timebase(GetTime() - timebase(), timebase(), Timecode::kCeil); + if (proposed_time == GetTime()) { + // Catch rounding error, assume this time is snapped and just subtract a timebase + proposed_time -= timebase(); + } + SetTimeAndSignal(qMax(rational(0), proposed_time)); } } void TimeBasedWidget::NextFrame() { if (viewer_node_) { - SetTimeAndSignal(ruler()->GetTime() + 1); + rational proposed_time = Timecode::snap_time_to_timebase(GetTime() + timebase(), timebase(), Timecode::kFloor); + if (proposed_time == GetTime()) { + // Catch rounding error, assume this time is snapped and just add a timebase + proposed_time += timebase(); + } + SetTimeAndSignal(proposed_time); } } void TimeBasedWidget::GoToEnd() { if (viewer_node_) { - SetTimeAndSignal(Timecode::time_to_timestamp(viewer_node_->GetLength(), timebase())); + SetTimeAndSignal(viewer_node_->GetLength()); } } -void TimeBasedWidget::SetTimeAndSignal(const int64_t &t) +void TimeBasedWidget::SetTimeAndSignal(const rational &t) { - SetTimestamp(t); + SetTime(t); emit TimeChanged(t); } void TimeBasedWidget::CenterScrollOnPlayhead() { - scrollbar_->setValue(qRound(TimeToScene(Timecode::timestamp_to_time(ruler_->GetTime(), timebase()))) - scrollbar_->width()/2); + scrollbar_->setValue(qRound(TimeToScene(ruler_->GetTime())) - scrollbar_->width()/2); } void TimeBasedWidget::SetAutoSetTimebase(bool e) @@ -639,7 +639,7 @@ void TimeBasedWidget::GoToIn() { if (GetConnectedNode()) { if (GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { - SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->in(), timebase())); + SetTimeAndSignal(GetConnectedNode()->GetTimelinePoints()->workarea()->in()); } else { GoToStart(); } @@ -650,7 +650,7 @@ void TimeBasedWidget::GoToOut() { if (GetConnectedNode()) { if (GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { - SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->out(), timebase())); + SetTimeAndSignal(GetConnectedNode()->GetTimelinePoints()->workarea()->out()); } else { GoToEnd(); } diff --git a/app/widget/timebased/timebasedwidget.h b/app/widget/timebased/timebasedwidget.h index e0cc79b41..2e479d84b 100644 --- a/app/widget/timebased/timebasedwidget.h +++ b/app/widget/timebased/timebasedwidget.h @@ -38,9 +38,7 @@ class TimeBasedWidget : public TimelineScaledWidget public: TimeBasedWidget(bool ruler_text_visible = true, bool ruler_cache_status_visible = false, QWidget* parent = nullptr); - rational GetTime() const; - - const int64_t& GetTimestamp() const; + const rational &GetTime() const; void ZoomIn(); @@ -57,7 +55,7 @@ public: virtual bool eventFilter(QObject* object, QEvent* event) override; public slots: - void SetTimestamp(int64_t timestamp); + void SetTime(const rational &time); void SetTimebase(const rational& timebase); @@ -94,14 +92,14 @@ public slots: void GoToOut(); protected slots: - void SetTimeAndSignal(const int64_t& t); + void SetTimeAndSignal(const rational& t); protected: ResizableTimelineScrollBar* scrollbar() const; virtual void TimebaseChangedEvent(const rational&) override; - virtual void TimeChangedEvent(const int64_t&){} + virtual void TimeChangedEvent(const rational&){} virtual void ScaleChangedEvent(const double &) override; @@ -134,7 +132,7 @@ protected slots: static void PageScrollInternal(QScrollBar* bar, int maximum, int screen_position, bool whole_page_scroll); signals: - void TimeChanged(const int64_t&); + void TimeChanged(const rational&); void TimebaseChanged(const rational&); diff --git a/app/widget/timebased/timescaledobject.cpp b/app/widget/timebased/timescaledobject.cpp index bdb162979..3d74ed026 100644 --- a/app/widget/timebased/timescaledobject.cpp +++ b/app/widget/timebased/timescaledobject.cpp @@ -72,12 +72,12 @@ rational TimeScaledObject::SceneToTime(const double &x, const double &x_scale, c return rational(rounded_x_mvmt * timebase.numerator(), timebase.denominator()); } -double TimeScaledObject::TimeToScene(const rational &time) +double TimeScaledObject::TimeToScene(const rational &time) const { return time.toDouble() * scale_; } -rational TimeScaledObject::SceneToTime(const double &x, bool round) +rational TimeScaledObject::SceneToTime(const double &x, bool round) const { return SceneToTime(x, scale_, timebase_, round); } diff --git a/app/widget/timebased/timescaledobject.h b/app/widget/timebased/timescaledobject.h index 60dd5eea5..c9e86eeb2 100644 --- a/app/widget/timebased/timescaledobject.h +++ b/app/widget/timebased/timescaledobject.h @@ -51,8 +51,8 @@ public: static double CalculateScaleFromDimensions(double viewport_sz, double content_sz); static double CalculatePaddingFromDimensionScale(double viewport_sz); - double TimeToScene(const rational& time); - rational SceneToTime(const double &x, bool round = false); + double TimeToScene(const rational& time) const; + rational SceneToTime(const double &x, bool round = false) const; protected: virtual void TimebaseChangedEvent(const rational&){} diff --git a/app/widget/timelinewidget/timelinewidget.cpp b/app/widget/timelinewidget/timelinewidget.cpp index 5174a4e8c..c9f0a1c7e 100644 --- a/app/widget/timelinewidget/timelinewidget.cpp +++ b/app/widget/timelinewidget/timelinewidget.cpp @@ -71,10 +71,11 @@ TimelineWidget::TimelineWidget(QWidget *parent) : QHBoxLayout* ruler_and_time_layout = new QHBoxLayout(); vert_layout->addLayout(ruler_and_time_layout); - timecode_label_ = new TimeSlider(); + timecode_label_ = new RationalSlider(); timecode_label_->SetAlignment(Qt::AlignCenter); + timecode_label_->SetDisplayType(RationalSlider::kTime); timecode_label_->setVisible(false); - connect(timecode_label_, &TimeSlider::ValueChanged, this, &TimelineWidget::SetTimeAndSignal); + connect(timecode_label_, &RationalSlider::ValueChanged, this, &TimelineWidget::SetTimeAndSignal); ruler_and_time_layout->addWidget(timecode_label_); ruler_and_time_layout->addWidget(ruler()); @@ -136,7 +137,7 @@ TimelineWidget::TimelineWidget(QWidget *parent) : connect(view->horizontalScrollBar(), &QScrollBar::valueChanged, ruler(), &TimeRuler::SetScroll); connect(view, &TimelineView::ScaleChanged, this, &TimelineWidget::SetScale); - connect(view, &TimelineView::TimeChanged, this, &TimelineWidget::ViewTimestampChanged); + connect(view, &TimelineView::TimeChanged, this, &TimelineWidget::SetTimeAndSignal); connect(view, &TimelineView::customContextMenuRequested, this, &TimelineWidget::ShowContextMenu); connect(scrollbar(), &QScrollBar::valueChanged, view->horizontalScrollBar(), &QScrollBar::setValue); connect(view->horizontalScrollBar(), &QScrollBar::valueChanged, scrollbar(), &QScrollBar::setValue); @@ -222,13 +223,13 @@ void TimelineWidget::resizeEvent(QResizeEvent *event) UpdateTimecodeWidthFromSplitters(views_.first()->splitter()); } -void TimelineWidget::TimeChangedEvent(const int64_t& timestamp) +void TimelineWidget::TimeChangedEvent(const rational &time) { - super::TimeChangedEvent(timestamp); + super::TimeChangedEvent(time); - SetViewTimestamp(timestamp); + SetViewTime(time); - timecode_label_->SetValue(timestamp); + timecode_label_->SetValue(time); } void TimelineWidget::ScaleChangedEvent(const double &scale) @@ -400,7 +401,7 @@ void TimelineWidget::SplitAtPlayhead() return; } - rational playhead_time = Timecode::timestamp_to_time(GetTimestamp(), timebase()); + const rational &playhead_time = GetTime(); QVector selected_blocks = GetSelectedBlocks(); @@ -693,8 +694,7 @@ void TimelineWidget::DeleteInToOut(bool ripple) false)); if (ripple) { - SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->in(), - timebase())); + SetTimeAndSignal(GetConnectedNode()->GetTimelinePoints()->workarea()->in()); } Core::instance()->undo_stack()->push(command); @@ -1085,39 +1085,16 @@ void TimelineWidget::SetUseAudioTimeUnits(bool use) // Update timebases UpdateViewTimebases(); - - // Force update of the viewer timestamps - SetViewTimestamp(GetTimestamp()); } -void TimelineWidget::SetViewTimestamp(const int64_t &ts) +void TimelineWidget::SetViewTime(const rational &time) { for (int i=0;iview()->SetTime(Timecode::rescale_timestamp(ts, - timebase(), - GetConnectedNode()->GetAudioParams().sample_rate_as_time_base())); - } else { - view->view()->SetTime(ts); - } + view->view()->SetTime(time); } } -void TimelineWidget::ViewTimestampChanged(int64_t ts) -{ - if (GetConnectedNode() && use_audio_time_units_ && sender() == views_.at(Track::kAudio)) { - ts = Timecode::rescale_timestamp(ts, - GetConnectedNode()->GetAudioParams().sample_rate_as_time_base(), - timebase()); - } - - // Update all other views - SetTimestamp(ts); - emit TimeChanged(ts); -} - void TimelineWidget::ToolChanged() { HideSnaps(); @@ -1441,9 +1418,9 @@ void TimelineWidget::RippleTo(Timeline::MovementMode mode) // If we rippled, ump to where new cut is if applicable if (mode == Timeline::kTrimIn) { - SetTimeAndSignal(Timecode::time_to_timestamp(closest_point_to_playhead, timebase())); + SetTimeAndSignal(closest_point_to_playhead); } else if (mode == Timeline::kTrimOut && closest_point_to_playhead == GetTime()) { - SetTimeAndSignal(Timecode::time_to_timestamp(playhead_time, timebase())); + SetTimeAndSignal(playhead_time); } } diff --git a/app/widget/timelinewidget/timelinewidget.h b/app/widget/timelinewidget/timelinewidget.h index 50052c413..ed1d33d92 100644 --- a/app/widget/timelinewidget/timelinewidget.h +++ b/app/widget/timelinewidget/timelinewidget.h @@ -31,7 +31,7 @@ #include "node/output/viewer/viewer.h" #include "timeline/timelinecommon.h" #include "timelineandtrackview.h" -#include "widget/slider/timeslider.h" +#include "widget/slider/rationalslider.h" #include "widget/snapservice/snapservice.h" #include "widget/timebased/timebasedwidget.h" #include "widget/timelinewidget/timelinewidgetselections.h" @@ -254,7 +254,7 @@ protected: virtual void resizeEvent(QResizeEvent *event) override; virtual void TimebaseChangedEvent(const rational &) override; - virtual void TimeChangedEvent(const int64_t &) override; + virtual void TimeChangedEvent(const rational &time) override; virtual void ScaleChangedEvent(const double &) override; virtual void ConnectNodeEvent(ViewerOutput* n) override; @@ -305,7 +305,7 @@ private: QVector views_; - TimeSlider* timecode_label_; + RationalSlider* timecode_label_; QVector selected_blocks_; @@ -357,9 +357,7 @@ private slots: void SetUseAudioTimeUnits(bool use); - void SetViewTimestamp(const int64_t& ts); - - void ViewTimestampChanged(int64_t ts); + void SetViewTime(const rational &time); void ToolChanged(); diff --git a/app/widget/timelinewidget/tool/import.cpp b/app/widget/timelinewidget/tool/import.cpp index ff9ee2629..163078e38 100644 --- a/app/widget/timelinewidget/tool/import.cpp +++ b/app/widget/timelinewidget/tool/import.cpp @@ -131,10 +131,9 @@ void ImportTool::DragMove(TimelineViewMouseEvent *event) // Generate tooltip (showing earliest in point of imported clip) rational tooltip_timebase = parent()->GetTimebaseForTrackType(event->GetTrack().type()); - int64_t earliest_timestamp = Timecode::time_to_timestamp(earliest_ghost, tooltip_timebase); - QString tooltip_text = Timecode::timestamp_to_timecode(earliest_timestamp, - tooltip_timebase, - Core::instance()->GetTimecodeDisplay()); + QString tooltip_text = Timecode::time_to_timecode(earliest_ghost, + tooltip_timebase, + Core::instance()->GetTimecodeDisplay()); // Force tooltip to update (otherwise the tooltip won't move as written in the documentation, and could get in the way // of the cursor) diff --git a/app/widget/timelinewidget/tool/pointer.cpp b/app/widget/timelinewidget/tool/pointer.cpp index 95b4b61db..f2f03cf69 100644 --- a/app/widget/timelinewidget/tool/pointer.cpp +++ b/app/widget/timelinewidget/tool/pointer.cpp @@ -506,10 +506,10 @@ void PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos) rational tooltip_timebase = parent()->GetTimebaseForTrackType(drag_start_.GetTrack().type()); QToolTip::hideText(); QToolTip::showText(QCursor::pos(), - Timecode::timestamp_to_timecode(Timecode::time_to_timestamp(time_movement, tooltip_timebase), - tooltip_timebase, - Core::instance()->GetTimecodeDisplay(), - true), + Timecode::time_to_timecode(time_movement, + tooltip_timebase, + Core::instance()->GetTimecodeDisplay(), + true), parent()); } @@ -672,10 +672,10 @@ void PointerTool::FinishDrag(TimelineViewMouseEvent *event) QHash >::const_iterator i; for (i=slide_info.constBegin(); i!=slide_info.constEnd(); i++) { command->add_child(new TrackSlideCommand(parent()->GetTrackFromReference(i.key()), - i.value(), - in_adjacents.value(i.key()), - out_adjacents.value(i.key()), - movement)); + i.value(), + in_adjacents.value(i.key()), + out_adjacents.value(i.key()), + movement)); } // Adjust selections diff --git a/app/widget/timelinewidget/tool/slip.cpp b/app/widget/timelinewidget/tool/slip.cpp index e7f66881f..ad116afbb 100644 --- a/app/widget/timelinewidget/tool/slip.cpp +++ b/app/widget/timelinewidget/tool/slip.cpp @@ -58,10 +58,10 @@ void SlipTool::ProcessDrag(const TimelineCoordinate &mouse_pos) rational tooltip_timebase = parent()->GetTimebaseForTrackType(drag_start_.GetTrack().type()); QToolTip::hideText(); QToolTip::showText(QCursor::pos(), - Timecode::timestamp_to_timecode(Timecode::time_to_timestamp(time_movement, tooltip_timebase), - tooltip_timebase, - Core::instance()->GetTimecodeDisplay(), - true), + Timecode::time_to_timecode(time_movement, + tooltip_timebase, + Core::instance()->GetTimecodeDisplay(), + true), parent()); } diff --git a/app/widget/timelinewidget/view/timelineview.cpp b/app/widget/timelinewidget/view/timelineview.cpp index e07c981f6..2bf55bf68 100644 --- a/app/widget/timelinewidget/view/timelineview.cpp +++ b/app/widget/timelinewidget/view/timelineview.cpp @@ -661,12 +661,6 @@ Block *TimelineView::GetItemAtScenePos(const rational &time, int track_index) co return nullptr; } -void TimelineView::UserSetTime(const int64_t &time) -{ - SetTime(time); - emit TimeChanged(time); -} - void TimelineView::TrackListChanged() { UpdateSceneRect(); diff --git a/app/widget/timelinewidget/view/timelineview.h b/app/widget/timelinewidget/view/timelineview.h index 7c5d9fb88..5a9f01282 100644 --- a/app/widget/timelinewidget/view/timelineview.h +++ b/app/widget/timelinewidget/view/timelineview.h @@ -126,8 +126,6 @@ private: int GetHeightOfAllTracks() const; - void UserSetTime(const int64_t& time); - void UpdatePlayheadRect(); QHash* selections_; diff --git a/app/widget/timeruler/seekablewidget.cpp b/app/widget/timeruler/seekablewidget.cpp index 1b763f067..b410557d3 100644 --- a/app/widget/timeruler/seekablewidget.cpp +++ b/app/widget/timeruler/seekablewidget.cpp @@ -31,7 +31,6 @@ namespace olive { SeekableWidget::SeekableWidget(QWidget* parent) : TimelineScaledWidget(parent), - time_(0), timeline_points_(nullptr), scroll_(0), snap_service_(nullptr), @@ -73,11 +72,6 @@ void SeekableWidget::SetSnapService(SnapService *service) snap_service_ = service; } -const int64_t &SeekableWidget::GetTime() const -{ - return time_; -} - const int &SeekableWidget::GetScroll() const { return scroll_; @@ -119,7 +113,7 @@ TimelinePoints *SeekableWidget::timeline_points() const return timeline_points_; } -void SeekableWidget::SetTime(const int64_t &r) +void SeekableWidget::SetTime(const rational &r) { time_ = r; @@ -133,29 +127,14 @@ void SeekableWidget::SetScroll(int s) update(); } -double SeekableWidget::ScreenToUnitFloat(int screen) const -{ - return (screen + scroll_) / GetScale() / timebase_dbl(); -} - -int64_t SeekableWidget::ScreenToUnit(int screen) const -{ - return qFloor(ScreenToUnitFloat(screen)); -} - -int64_t SeekableWidget::ScreenToUnitRounded(int screen) const -{ - return qRound64(ScreenToUnitFloat(screen)); -} - -int SeekableWidget::UnitToScreen(int64_t unit) const -{ - return qFloor(static_cast(unit) * GetScale() * timebase_dbl()) - scroll_; -} - int SeekableWidget::TimeToScreen(const rational &time) const { - return qFloor(time.toDouble() * GetScale()) - scroll_; + return qFloor(TimeToScene(time)) - scroll_; +} + +rational SeekableWidget::ScreenToTime(int x) const +{ + return qMax(rational(0), SceneToTime(x + scroll_)); } void SeekableWidget::SeekToScreenPoint(int screen) @@ -164,26 +143,20 @@ void SeekableWidget::SeekToScreenPoint(int screen) return; } - int64_t timestamp = qMax(static_cast(0), ScreenToUnitRounded(screen)); + rational playhead_time = ScreenToTime(screen); if (Core::instance()->snapping() && snap_service_) { - rational playhead_time = Timecode::timestamp_to_time(timestamp, timebase()); rational movement; snap_service_->SnapPoint({playhead_time}, &movement, SnapService::kSnapAll & ~SnapService::kSnapToPlayhead); - - if (!movement.isNull()) { - timestamp = Timecode::time_to_timestamp(playhead_time + movement, - timebase()); - } } - if (timestamp != GetTime()) { - SetTime(timestamp); + if (playhead_time != GetTime()) { + SetTime(playhead_time); - emit TimeChanged(timestamp); + emit TimeChanged(playhead_time); } } diff --git a/app/widget/timeruler/seekablewidget.h b/app/widget/timeruler/seekablewidget.h index 7881e7e9f..8cccaf64b 100644 --- a/app/widget/timeruler/seekablewidget.h +++ b/app/widget/timeruler/seekablewidget.h @@ -34,7 +34,10 @@ class SeekableWidget : public TimelineScaledWidget public: SeekableWidget(QWidget *parent = nullptr); - const int64_t& GetTime() const; + const rational& GetTime() const + { + return time_; + } const int& GetScroll() const; @@ -48,7 +51,7 @@ public: } public slots: - void SetTime(const int64_t &r); + void SetTime(const rational &r); void SetScroll(int s); @@ -65,14 +68,8 @@ protected: TimelinePoints* timeline_points() const; - double ScreenToUnitFloat(int screen) const; - - int64_t ScreenToUnit(int screen) const; - int64_t ScreenToUnitRounded(int screen) const; - - int UnitToScreen(int64_t unit) const; - int TimeToScreen(const rational& time) const; + rational ScreenToTime(int x) const; void DrawPlayhead(QPainter* p, int x, int y); @@ -88,10 +85,10 @@ signals: /** * @brief Signal emitted whenever the time changes on this ruler, either by user or programmatically */ - void TimeChanged(int64_t); + void TimeChanged(const rational &time); private: - int64_t time_; + rational time_; TimelinePoints* timeline_points_; diff --git a/app/widget/timeruler/timeruler.cpp b/app/widget/timeruler/timeruler.cpp index ccadef51b..db887fe7e 100644 --- a/app/widget/timeruler/timeruler.cpp +++ b/app/widget/timeruler/timeruler.cpp @@ -208,7 +208,7 @@ void TimeRuler::paintEvent(QPaintEvent *) if (text_visible_) { QRect text_rect; Qt::Alignment text_align; - QString timecode_str = Timecode::timestamp_to_timecode(ScreenToUnit(i), timebase(), Core::instance()->GetTimecodeDisplay()); + QString timecode_str = Timecode::time_to_timecode(ScreenToTime(i), timebase(), Core::instance()->GetTimecodeDisplay()); int timecode_width = QtUtils::QFontMetricsWidth(fm, timecode_str); int timecode_left; @@ -287,7 +287,7 @@ void TimeRuler::paintEvent(QPaintEvent *) } // Draw the playhead if it's on screen at the moment - int playhead_pos = UnitToScreen(GetTime()); + int playhead_pos = TimeToScreen(GetTime()); p.setPen(Qt::NoPen); p.setBrush(PLAYHEAD_COLOR); DrawPlayhead(&p, playhead_pos, line_bottom); diff --git a/app/widget/viewer/audiowaveformview.cpp b/app/widget/viewer/audiowaveformview.cpp index a632da463..fdc52edc4 100644 --- a/app/widget/viewer/audiowaveformview.cpp +++ b/app/widget/viewer/audiowaveformview.cpp @@ -100,7 +100,7 @@ void AudioWaveformView::paintEvent(QPaintEvent *event) // Draw playhead p.setPen(PLAYHEAD_COLOR); - int playhead_x = UnitToScreen(GetTime()); + int playhead_x = TimeToScreen(GetTime()); p.drawLine(playhead_x, 0, playhead_x, height()); } diff --git a/app/widget/viewer/footageviewer.cpp b/app/widget/viewer/footageviewer.cpp index 983db9e0f..2a2926f85 100644 --- a/app/widget/viewer/footageviewer.cpp +++ b/app/widget/viewer/footageviewer.cpp @@ -44,14 +44,14 @@ void FootageViewerWidget::ConnectNodeEvent(ViewerOutput *n) { super::ConnectNodeEvent(n); - SetTimestamp(cached_timestamps_.value(n, 0)); + SetTime(cached_timestamps_.value(n, 0)); } void FootageViewerWidget::DisconnectNodeEvent(ViewerOutput *n) { // Cache timestamp in case this footage is opened again later - cached_timestamps_.insert(n, GetTimestamp()); - SetTimestamp(0); + cached_timestamps_.insert(n, GetTime()); + SetTime(0); super::DisconnectNodeEvent(n); } diff --git a/app/widget/viewer/footageviewer.h b/app/widget/viewer/footageviewer.h index ce765c6ff..fdc8a62ea 100644 --- a/app/widget/viewer/footageviewer.h +++ b/app/widget/viewer/footageviewer.h @@ -40,7 +40,7 @@ protected: private: void StartFootageDragInternal(bool enable_video, bool enable_audio); - QHash cached_timestamps_; + QHash cached_timestamps_; private slots: void StartFootageDrag(); diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index 697ad204b..e85b72d3a 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -121,7 +121,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) : SetScale(48.0); // Ensures that seeking on the waveform view updates the time as expected - connect(waveform_view_, &AudioWaveformView::TimeChanged, this, &ViewerWidget::TimeChangedFromWaveform); + connect(waveform_view_, &AudioWaveformView::TimeChanged, this, &ViewerWidget::SetTimeAndSignal); connect(waveform_view_, &AudioWaveformView::customContextMenuRequested, this, &ViewerWidget::ShowContextMenu); connect(&playback_backup_timer_, &QTimer::timeout, this, &ViewerWidget::PlaybackTimerUpdate); @@ -144,30 +144,16 @@ ViewerWidget::~ViewerWidget() } } -void ViewerWidget::TimeChangedEvent(const int64_t &i) +void ViewerWidget::TimeChangedEvent(const rational &time) { if (!time_changed_from_timer_) { PauseInternal(); } - controls_->SetTime(i); - - { - // Update waveform time - qint64 waveform_time; - - if (waveform_view_->timebase() != this->timebase()) { - waveform_time = Timecode::rescale_timestamp(i, this->timebase(), waveform_view_->timebase()); - } else { - waveform_time = i; - } - - waveform_view_->SetTime(waveform_time); - } - - if (GetConnectedNode() && last_time_ != i) { - rational time_set = Timecode::timestamp_to_time(i, timebase()); + controls_->SetTime(time); + waveform_view_->SetTime(time); + if (GetConnectedNode() && last_time_ != time) { if (!IsPlaying()) { UpdateTextureFromNode(); @@ -178,13 +164,13 @@ void ViewerWidget::TimeChangedEvent(const int64_t &i) display_widget_->ResetFPSTimer(); } - display_widget_->SetTime(time_set); + display_widget_->SetTime(time); } // Send time to auto-cacher UpdateAutoCacher(); - last_time_ = i; + last_time_ = time; } void ViewerWidget::ConnectNodeEvent(ViewerOutput *n) @@ -573,14 +559,14 @@ void ViewerWidget::PlayInternal(int speed, bool in_to_out_only) if (speed > 0) { SetTimeAndSignal(0); } else { - SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedNode()->GetLength(), timebase())); + SetTimeAndSignal(GetConnectedNode()->GetLength()); } } playback_speed_ = speed; play_in_to_out_only_ = in_to_out_only; - playback_queue_next_frame_ = ruler()->GetTime(); + playback_queue_next_frame_ = GetTimestamp(); controls_->ShowPauseButton(); @@ -752,7 +738,7 @@ RenderTicketPtr ViewerWidget::GetFrame(const rational &t, bool prioritize) void ViewerWidget::FinishPlayPreprocess() { - int64_t playback_start_time = ruler()->GetTime(); + int64_t playback_start_time = GetTimestamp(); StartAudioOutput(); @@ -1062,7 +1048,7 @@ void ViewerWidget::Play(bool in_to_out_only) if (GetConnectedNode() && GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { // Jump to in point - SetTimeAndSignal(Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->in(), timebase())); + SetTimeAndSignal(GetConnectedNode()->GetTimelinePoints()->workarea()->in()); } else { in_to_out_only = false; } @@ -1148,21 +1134,21 @@ void ViewerWidget::TimebaseChangedEvent(const rational &timebase) void ViewerWidget::PlaybackTimerUpdate() { - int64_t current_time = playback_timer_.GetTimestampNow(); + rational current_time = Timecode::timestamp_to_time(playback_timer_.GetTimestampNow(), timebase()); - int64_t min_time, max_time; + rational min_time, max_time; if (play_in_to_out_only_ && GetConnectedNode()->GetTimelinePoints()->workarea()->enabled()) { // If "play in to out" is enabled or we're looping AND we have a workarea, only play the workarea - min_time = Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->in(), timebase()); - max_time = Timecode::time_to_timestamp(GetConnectedNode()->GetTimelinePoints()->workarea()->out(), timebase()); + min_time = GetConnectedNode()->GetTimelinePoints()->workarea()->in(); + max_time = GetConnectedNode()->GetTimelinePoints()->workarea()->out(); } else { // Otherwise set the bounds to the range of the sequence min_time = 0; - max_time = Timecode::time_to_timestamp(GetConnectedNode()->GetLength(), timebase()); + max_time = GetConnectedNode()->GetLength(); } @@ -1170,7 +1156,7 @@ void ViewerWidget::PlaybackTimerUpdate() || (playback_speed_ > 0 && current_time >= max_time)) { // Determine which timestamp we tripped - int64_t tripped_time; + rational tripped_time; if (current_time <= min_time) { tripped_time = min_time; @@ -1181,7 +1167,7 @@ void ViewerWidget::PlaybackTimerUpdate() if (Config::Current()[QStringLiteral("Loop")].toBool()) { // If we're looping, jump to the other side of the workarea and continue - int64_t opposing_time = (tripped_time == min_time) ? max_time : min_time; + rational opposing_time = (tripped_time == min_time) ? max_time : min_time; // Cache the current speed int current_speed = playback_speed_; @@ -1211,8 +1197,7 @@ void ViewerWidget::PlaybackTimerUpdate() UpdateTextureFromNode(); } else if (!windows_.empty()) { // We still run the queue if windows are visible even if our own display widget isn't visible - rational t = GetTime(); - while (!playback_queue_.empty() && playback_queue_.front().timestamp != t) { + while (!playback_queue_.empty() && playback_queue_.front().timestamp != GetTime()) { PopOldestFrameFromPlaybackQueue(); } } @@ -1239,7 +1224,7 @@ void ViewerWidget::SetViewerPixelAspect(const rational &ratio) void ViewerWidget::LengthChangedSlot(const rational &length) { if (last_length_ != length) { - controls_->SetEndTime(Timecode::time_to_timestamp(length, timebase())); + controls_->SetEndTime(length); UpdateMinimumScale(); if (length < last_length_ && GetTime() >= length) { @@ -1296,16 +1281,6 @@ void ViewerWidget::ManualSwitchToWaveform(bool e) } } -void ViewerWidget::TimeChangedFromWaveform(qint64 t) -{ - if (waveform_view_->timebase() != this->timebase()) { - // Transform time to our timebase - t = Timecode::rescale_timestamp(t, waveform_view_->timebase(), this->timebase()); - } - - SetTimeAndSignal(t); -} - void ViewerWidget::ViewerShiftedRange(const rational &from, const rational &to) { if (GetTime() >= qMin(from, to)) { diff --git a/app/widget/viewer/viewer.h b/app/widget/viewer/viewer.h index 402164ee3..a7d7154ae 100644 --- a/app/widget/viewer/viewer.h +++ b/app/widget/viewer/viewer.h @@ -149,7 +149,7 @@ signals: protected: virtual void TimebaseChangedEvent(const rational &) override; - virtual void TimeChangedEvent(const int64_t &) override; + virtual void TimeChangedEvent(const rational &time) override; virtual void ConnectNodeEvent(ViewerOutput *) override; virtual void DisconnectNodeEvent(ViewerOutput *) override; @@ -167,6 +167,11 @@ protected: } private: + int64_t GetTimestamp() const + { + return Timecode::time_to_timestamp(GetTime(), timebase(), Timecode::kFloor); + } + void UpdateTimeInternal(int64_t i); void PlayInternal(int speed, bool in_to_out_only); @@ -215,7 +220,7 @@ private: QAtomicInt playback_speed_; - int64_t last_time_; + rational last_time_; bool color_menu_enabled_; @@ -294,8 +299,6 @@ private slots: void ManualSwitchToWaveform(bool e); - void TimeChangedFromWaveform(qint64 t); - void DragEntered(QDragEnterEvent* event); void Dropped(QDropEvent* event); diff --git a/app/window/mainwindow/mainwindow.cpp b/app/window/mainwindow/mainwindow.cpp index 7f49a1e89..fec8e5453 100644 --- a/app/window/mainwindow/mainwindow.cpp +++ b/app/window/mainwindow/mainwindow.cpp @@ -102,15 +102,15 @@ MainWindow::MainWindow(QWidget *parent) : connect(param_panel_, &ParamPanel::FocusedNodeChanged, sequence_viewer_panel_, &ViewerPanel::SetGizmos); // Connect time signals together - connect(sequence_viewer_panel_, &SequenceViewerPanel::TimeChanged, param_panel_, &ParamPanel::SetTimestamp); - connect(sequence_viewer_panel_, &SequenceViewerPanel::TimeChanged, table_panel_, &NodeTablePanel::SetTimestamp); - connect(sequence_viewer_panel_, &SequenceViewerPanel::TimeChanged, curve_panel_, &NodeTablePanel::SetTimestamp); - connect(param_panel_, &ParamPanel::TimeChanged, sequence_viewer_panel_, &SequenceViewerPanel::SetTimestamp); - connect(param_panel_, &ParamPanel::TimeChanged, table_panel_, &NodeTablePanel::SetTimestamp); - connect(param_panel_, &ParamPanel::TimeChanged, curve_panel_, &NodeTablePanel::SetTimestamp); - connect(curve_panel_, &ParamPanel::TimeChanged, sequence_viewer_panel_, &SequenceViewerPanel::SetTimestamp); - connect(curve_panel_, &ParamPanel::TimeChanged, table_panel_, &NodeTablePanel::SetTimestamp); - connect(curve_panel_, &ParamPanel::TimeChanged, param_panel_, &NodeTablePanel::SetTimestamp); + connect(sequence_viewer_panel_, &SequenceViewerPanel::TimeChanged, param_panel_, &ParamPanel::SetTime); + connect(sequence_viewer_panel_, &SequenceViewerPanel::TimeChanged, table_panel_, &NodeTablePanel::SetTime); + connect(sequence_viewer_panel_, &SequenceViewerPanel::TimeChanged, curve_panel_, &NodeTablePanel::SetTime); + connect(param_panel_, &ParamPanel::TimeChanged, sequence_viewer_panel_, &SequenceViewerPanel::SetTime); + connect(param_panel_, &ParamPanel::TimeChanged, table_panel_, &NodeTablePanel::SetTime); + connect(param_panel_, &ParamPanel::TimeChanged, curve_panel_, &NodeTablePanel::SetTime); + connect(curve_panel_, &ParamPanel::TimeChanged, sequence_viewer_panel_, &SequenceViewerPanel::SetTime); + connect(curve_panel_, &ParamPanel::TimeChanged, table_panel_, &NodeTablePanel::SetTime); + connect(curve_panel_, &ParamPanel::TimeChanged, param_panel_, &NodeTablePanel::SetTime); // Connect node order signals connect(param_panel_, &ParamPanel::NodeOrderChanged, curve_panel_, &CurvePanel::SetNodes); @@ -564,14 +564,14 @@ TimelinePanel* MainWindow::AppendTimelinePanel() TimelinePanel* panel = AppendPanelInternal(timeline_panels_); connect(panel, &PanelWidget::CloseRequested, this, &MainWindow::TimelineCloseRequested); - connect(panel, &TimelinePanel::TimeChanged, curve_panel_, &ParamPanel::SetTimestamp); - connect(panel, &TimelinePanel::TimeChanged, param_panel_, &ParamPanel::SetTimestamp); - connect(panel, &TimelinePanel::TimeChanged, table_panel_, &NodeTablePanel::SetTimestamp); - connect(panel, &TimelinePanel::TimeChanged, sequence_viewer_panel_, &SequenceViewerPanel::SetTimestamp); + connect(panel, &TimelinePanel::TimeChanged, curve_panel_, &ParamPanel::SetTime); + connect(panel, &TimelinePanel::TimeChanged, param_panel_, &ParamPanel::SetTime); + connect(panel, &TimelinePanel::TimeChanged, table_panel_, &NodeTablePanel::SetTime); + connect(panel, &TimelinePanel::TimeChanged, sequence_viewer_panel_, &SequenceViewerPanel::SetTime); connect(panel, &TimelinePanel::BlockSelectionChanged, this, &MainWindow::TimelinePanelSelectionChanged); - connect(param_panel_, &ParamPanel::TimeChanged, panel, &TimelinePanel::SetTimestamp); - connect(curve_panel_, &ParamPanel::TimeChanged, panel, &TimelinePanel::SetTimestamp); - connect(sequence_viewer_panel_, &SequenceViewerPanel::TimeChanged, panel, &TimelinePanel::SetTimestamp); + connect(param_panel_, &ParamPanel::TimeChanged, panel, &TimelinePanel::SetTime); + connect(curve_panel_, &ParamPanel::TimeChanged, panel, &TimelinePanel::SetTime); + connect(sequence_viewer_panel_, &SequenceViewerPanel::TimeChanged, panel, &TimelinePanel::SetTime); sequence_viewer_panel_->ConnectTimeBasedPanel(panel);