Skip to content

Commit

Permalink
Replace current time and playback signals with a time scrub signal
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Apr 8, 2024
1 parent f879375 commit f952e10
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 78 deletions.
7 changes: 7 additions & 0 deletions lib/tlPlayQtApp/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,13 @@ namespace tl
{
_p->timelineActions->actions()["FrameView"]->setChecked(value);
});
/*connect(
p.timelineWidget,
&qtwidget::TimelineWidget::timeScrubbed,
[this](const otime::RationalTime& value)
{
std::cout << "Time scrubbed: " << value << std::endl;
});*/

connect(
p.currentTimeSpinBox,
Expand Down
16 changes: 4 additions & 12 deletions lib/tlQtWidget/TimelineWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ namespace tl

std::shared_ptr<observer::ValueObserver<bool> > editableObserver;
std::shared_ptr<observer::ValueObserver<bool> > frameViewObserver;
std::shared_ptr<observer::ValueObserver<timeline::Playback> > playbackObserver;
std::shared_ptr<observer::ValueObserver<otime::RationalTime> > currentTimeObserver;
std::shared_ptr<observer::ValueObserver<otime::RationalTime> > timeScrubObserver;
};

TimelineWidget::TimelineWidget(
Expand Down Expand Up @@ -211,18 +210,11 @@ namespace tl
Q_EMIT frameViewChanged(value);
});

p.playbackObserver = observer::ValueObserver<timeline::Playback>::create(
p.timelineWidget->observePlayback(),
[this](timeline::Playback value)
{
Q_EMIT playbackChanged(value);
});

p.currentTimeObserver = observer::ValueObserver<otime::RationalTime>::create(
p.timelineWidget->observeCurrentTime(),
p.timeScrubObserver = observer::ValueObserver<otime::RationalTime>::create(
p.timelineWidget->observeTimeScrub(),
[this](const otime::RationalTime& value)
{
Q_EMIT currentTimeChanged(value);
Q_EMIT timeScrubbed(value);
});

p.timer.reset(new QTimer);
Expand Down
13 changes: 2 additions & 11 deletions lib/tlQtWidget/TimelineWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,9 @@ namespace tl
//! Get the mouse wheel scale.
float mouseWheelScale() const;

//! Get the playback mode.
timeline::Playback playback();

//! Get whether to stop playback when scrubbing.
bool hasStopOnScrub() const;

//! Get the current time.
const otime::RationalTime& currentTime() const;

//! Get the frame markers.
const std::vector<int>& frameMarkers() const;

Expand Down Expand Up @@ -103,11 +97,8 @@ namespace tl
//! This signal is emitted when the frame view is changed.
void frameViewChanged(bool);

//! This signal is emitted when the playback mode is changed.
void playbackChanged(tl::timeline::Playback);

//! This signal is emitted when the current time is changed.
void currentTimeChanged(const tl::otime::RationalTime&);
//! This signal is emitted when the time is scrubbed.
void timeScrubbed(const tl::otime::RationalTime&);

protected:
void initializeGL() override;
Expand Down
17 changes: 15 additions & 2 deletions lib/tlTimelineUI/TimelineItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace tl

p.player = player;

p.timeScrub = observer::Value<otime::RationalTime>::create(time::invalidTime);

p.thumbnailGenerator = ui::ThumbnailGenerator::create(context, window);

const auto otioTimeline = p.player->getTimeline()->getTimeline();
Expand Down Expand Up @@ -195,6 +197,11 @@ namespace tl
_p->stopOnScrub = value;
}

std::shared_ptr<observer::IValue<otime::RationalTime> > TimelineItem::observeTimeScrub() const
{
return _p->timeScrub;
}

void TimelineItem::setFrameMarkers(const std::vector<int>& value)
{
TLRENDER_P();
Expand Down Expand Up @@ -419,8 +426,12 @@ namespace tl
switch (p.mouse.mode)
{
case Private::MouseMode::CurrentTime:
p.player->seek(_posToTime(event.pos.x));
{
const otime::RationalTime time = _posToTime(event.pos.x);
p.player->seek(time);
p.timeScrub->setIfChanged(time);
break;
}
case Private::MouseMode::Item:
{
if (!p.mouse.items.empty())
Expand Down Expand Up @@ -516,7 +527,9 @@ namespace tl
{
p.player->setPlayback(timeline::Playback::Stop);
}
p.player->seek(_posToTime(event.pos.x));
const otime::RationalTime time = _posToTime(event.pos.x);
p.player->seek(time);
p.timeScrub->setIfChanged(time);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/tlTimelineUI/TimelineItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ namespace tl
//! Set whether playback stops when scrubbing.
void setStopOnScrub(bool);

//! Observe time scrubbing.
std::shared_ptr<observer::IValue<otime::RationalTime> > observeTimeScrub() const;

//! Set the frame markers.
void setFrameMarkers(const std::vector<int>&);

Expand Down
1 change: 1 addition & 0 deletions lib/tlTimelineUI/TimelineItemPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace tl
timeline::PlayerCacheInfo cacheInfo;
bool editable = false;
bool stopOnScrub = true;
std::shared_ptr<observer::Value<otime::RationalTime> > timeScrub;
std::vector<int> frameMarkers;
int minimumHeight = 0;
std::shared_ptr<ui::ThumbnailGenerator> thumbnailGenerator;
Expand Down
55 changes: 13 additions & 42 deletions lib/tlTimelineUI/TimelineWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ namespace tl
std::function<void(bool)> frameViewCallback;
ui::KeyModifier scrollKeyModifier = ui::KeyModifier::Control;
float mouseWheelScale = 1.1F;
std::shared_ptr<observer::Value<timeline::Playback> > playback;
std::shared_ptr<observer::Value<bool> > stopOnScrub;
std::shared_ptr<observer::Value<otime::RationalTime> > currentTime;
std::shared_ptr<observer::Value<otime::RationalTime> > timeScrub;
std::vector<int> frameMarkers;
std::shared_ptr<observer::Value<ItemOptions> > itemOptions;
double scale = 500.0;
Expand All @@ -49,8 +48,7 @@ namespace tl
MouseData mouse;

std::shared_ptr<observer::ValueObserver<bool> > timelineObserver;
std::shared_ptr<observer::ValueObserver<timeline::Playback> > playbackObserver;
std::shared_ptr<observer::ValueObserver<otime::RationalTime> > currentTimeObserver;
std::shared_ptr<observer::ValueObserver<otime::RationalTime> > timeScrubObserver;
};

void TimelineWidget::_init(
Expand All @@ -69,9 +67,8 @@ namespace tl

p.editable = observer::Value<bool>::create(false);
p.frameView = observer::Value<bool>::create(true);
p.playback = observer::Value<timeline::Playback>::create(timeline::Playback::Stop);
p.stopOnScrub = observer::Value<bool>::create(true);
p.currentTime = observer::Value<otime::RationalTime>::create(time::invalidTime);
p.timeScrub = observer::Value<otime::RationalTime>::create(time::invalidTime);
p.itemOptions = observer::Value<ItemOptions>::create();

p.window = gl::GLFWWindow::create(
Expand Down Expand Up @@ -115,8 +112,6 @@ namespace tl
p.itemData->thumbnails.clear();
p.itemData->waveforms.clear();
p.timelineObserver.reset();
p.playbackObserver.reset();
p.currentTimeObserver.reset();
p.scrollWidget->setWidget(nullptr);
p.timelineItem.reset();

Expand All @@ -131,27 +126,10 @@ namespace tl
{
_timelineUpdate();
});

p.playbackObserver = observer::ValueObserver<timeline::Playback>::create(
p.player->observePlayback(),
[this](timeline::Playback value)
{
_p->playback->setIfChanged(value);
});

p.currentTimeObserver = observer::ValueObserver<otime::RationalTime>::create(
p.player->observeCurrentTime(),
[this](const otime::RationalTime& value)
{
_p->currentTime->setIfChanged(value);
});
}
else
{
_timelineUpdate();

_p->playback->setIfChanged(timeline::Playback::Stop);
_p->currentTime->setIfChanged(time::invalidTime);
}
}

Expand Down Expand Up @@ -263,16 +241,6 @@ namespace tl
p.mouseWheelScale = value;
}

timeline::Playback TimelineWidget::getPlayback() const
{
return _p->playback->get();
}

std::shared_ptr<observer::IValue<timeline::Playback> > TimelineWidget::observePlayback() const
{
return _p->playback;
}

bool TimelineWidget::hasStopOnScrub() const
{
return _p->stopOnScrub->get();
Expand All @@ -295,14 +263,9 @@ namespace tl
}
}

const otime::RationalTime& TimelineWidget::getCurrentTime() const
std::shared_ptr<observer::IValue<otime::RationalTime> > TimelineWidget::observeTimeScrub() const
{
return _p->currentTime->get();
}

std::shared_ptr<observer::IValue<otime::RationalTime> > TimelineWidget::observeCurrentTime() const
{
return _p->currentTime;
return _p->timeScrub;
}

const std::vector<int>& TimelineWidget::getFrameMarkers() const
Expand Down Expand Up @@ -562,6 +525,7 @@ namespace tl

const math::Vector2i scrollPos = p.scrollWidget->getScrollPos();

p.timeScrubObserver.reset();
p.scrollWidget->setWidget(nullptr);
p.timelineItem.reset();

Expand All @@ -585,6 +549,13 @@ namespace tl
p.timelineItem->setFrameMarkers(p.frameMarkers);
p.scrollWidget->setScrollPos(scrollPos);
p.scrollWidget->setWidget(p.timelineItem);

p.timeScrubObserver = observer::ValueObserver<otime::RationalTime>::create(
p.timelineItem->observeTimeScrub(),
[this](const otime::RationalTime& value)
{
_p->timeScrub->setIfChanged(value);
});
}
}
}
Expand Down
13 changes: 2 additions & 11 deletions lib/tlTimelineUI/TimelineWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ namespace tl
//! Set the mouse wheel scale.
void setMouseWheelScale(float);

//! Get the playback mode.
timeline::Playback getPlayback() const;

//! Observe the playback mode.
std::shared_ptr<observer::IValue<timeline::Playback> > observePlayback() const;

//! Get whether to stop playback when scrubbing.
bool hasStopOnScrub() const;

Expand All @@ -100,11 +94,8 @@ namespace tl
//! Set whether to stop playback when scrubbing.
void setStopOnScrub(bool);

//! Get the current time.
const otime::RationalTime& getCurrentTime() const;

//! Observe the current time.
std::shared_ptr<observer::IValue<otime::RationalTime> > observeCurrentTime() const;
//! Observe time scrubbing.
std::shared_ptr<observer::IValue<otime::RationalTime> > observeTimeScrub() const;

//! Get the frame markers.
const std::vector<int>& getFrameMarkers() const;
Expand Down

0 comments on commit f952e10

Please sign in to comment.