Skip to content

Commit

Permalink
Make active a final property and add a signal and virtual slot, subcl…
Browse files Browse the repository at this point in the history
…asses can override the slot
  • Loading branch information
rectalogic committed Nov 22, 2023
1 parent dcb9214 commit 9e59243
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/mediafx/audio_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
class QUrl;
struct Interval;

void AudioClip::setActive(bool active)
void AudioClip::onActiveChanged(bool active)
{
Clip::setActive(active);
Clip::onActiveChanged(active);
// XXX
}

Expand Down
2 changes: 1 addition & 1 deletion src/mediafx/audio_clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AudioClip : public Clip {
: Clip(parent) {};

protected:
void setActive(bool active) override;
void onActiveChanged(bool active) override;

void loadMedia(const QUrl&) override;
bool renderClip(const Interval& globalTime) override;
Expand Down
27 changes: 21 additions & 6 deletions src/mediafx/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@
#include "interval.h"
#include "mediafx.h"
#include "session.h"
#include <QObject>
#include <QQmlInfo>
#include <QUrl>

Clip::Clip(QObject* parent)
: QObject(parent)
, m_clipStart(-1)
, m_clipEnd(-1)
, m_currentGlobalTime(-1, -1)
, m_nextClipTime(0, -1)
{
connect(this, &Clip::activeChanged, this, &Clip::onActiveChanged);
}

void Clip::setSource(const QUrl& url)
{
if (!m_source.isEmpty()) {
Expand Down Expand Up @@ -101,12 +112,16 @@ void Clip::stop()

void Clip::setActive(bool active)
{
m_active = active && !m_stopped;
auto mediaFX = MediaFX::singletonInstance();
if (active) {
mediaFX->registerClip(this);
} else {
mediaFX->unregisterClip(this);
active = active && !m_stopped;
if (m_active != active) {
m_active = active;
auto mediaFX = MediaFX::singletonInstance();
if (active) {
mediaFX->registerClip(this);
} else {
mediaFX->unregisterClip(this);
}
emit onActiveChanged(active);
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/mediafx/clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,22 @@ class Clip : public QObject, public QQmlParserStatus {
// Times are qint64 milliseconds, but stored internally as microseconds to match QVideoFrame times
Q_PROPERTY(int clipStart READ clipStart WRITE setClipStart NOTIFY clipStartChanged FINAL)
Q_PROPERTY(int clipEnd READ clipEnd WRITE setClipEnd NOTIFY clipEndChanged FINAL)
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged FINAL)
QML_ELEMENT
QML_UNCREATABLE("Clip is an abstract base class.")

signals:
void clipStartChanged();
void clipEndChanged();
void activeChanged(bool);

protected slots:
virtual void onActiveChanged(bool active) {};

public:
using QObject::QObject;

explicit Clip(QObject* parent = nullptr)
: QObject(parent)
, m_clipStart(-1)
, m_clipEnd(-1)
, m_currentGlobalTime(-1, -1)
, m_nextClipTime(0, -1)
{
}
explicit Clip(QObject* parent = nullptr);

QUrl source() const { return m_source; };
void setSource(const QUrl&);
Expand All @@ -59,6 +57,9 @@ class Clip : public QObject, public QQmlParserStatus {
qint64 clipEnd() const { return m_clipEnd / 1000; };
void setClipEnd(qint64 millis);

void setActive(bool active);
bool active() const { return m_active; };

bool render(const Interval& globalTime);

void classBegin() override;
Expand All @@ -75,9 +76,6 @@ class Clip : public QObject, public QQmlParserStatus {

Interval nextClipTime() const { return m_nextClipTime; };

virtual void setActive(bool active);
bool active() const { return m_active; };

virtual void loadMedia(const QUrl&) = 0;

virtual bool renderClip(const Interval& globalTime) = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/mediafx/video_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ bool VideoClip::prepareNextVideoFrame()
return false;
}

void VideoClip::setActive(bool bactive)
void VideoClip::onActiveChanged(bool active)
{
VisualClip::setActive(bactive);
VisualClip::onActiveChanged(active);
if (isComponentComplete()) {
if (active()) {
if (active) {
play();
} else {
mediaPlayer.pause();
Expand Down
2 changes: 1 addition & 1 deletion src/mediafx/video_clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class VideoClip : public VisualClip {

bool prepareNextVideoFrame() override;

void setActive(bool active) override;
void onActiveChanged(bool active) override;

void stop() override;

Expand Down

0 comments on commit 9e59243

Please sign in to comment.