Commit b8dbba21 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Media: Store Clip as QSharedPointer

parent 069ba8c8
......@@ -141,7 +141,7 @@ Commands::Clip::Add::retranslate()
setText( tr( "Adding clip to track %1" ).arg( m_trackId ) );
}
std::shared_ptr<Clip>
QSharedPointer<::Clip>
Commands::Clip::Add::newClip()
{
return m_clip;
......@@ -307,8 +307,8 @@ Commands::Clip::Split::Split( std::shared_ptr<SequenceWorkflow> const& workflow,
retranslate();
return;
}
m_newClip = std::shared_ptr<::Clip>( m_toSplit->media()->cut( newClipBegin - m_toSplit->begin(),
m_toSplit->end() - m_toSplit->begin() ) );
m_newClip = m_toSplit->media()->cut( newClipBegin - m_toSplit->begin(),
m_toSplit->end() - m_toSplit->begin() );
m_oldEnd = m_toSplit->end();
retranslate();
}
......
......@@ -31,6 +31,8 @@
#endif
#include <QObject>
#include <QUuid>
#include <QSharedPointer>
#include <memory>
class Clip;
......@@ -83,12 +85,12 @@ namespace Commands
virtual void internalUndo();
virtual void retranslate();
std::shared_ptr<::Clip> newClip();
QSharedPointer<::Clip> newClip();
private:
std::shared_ptr<SequenceWorkflow> m_workflow;
QUuid m_uuid;
std::shared_ptr<::Clip> m_clip;
QSharedPointer<::Clip> m_clip;
quint32 m_trackId;
qint64 m_pos;
bool m_isAudioClip;
......@@ -104,7 +106,7 @@ namespace Commands
private:
std::shared_ptr<SequenceWorkflow> m_workflow;
std::shared_ptr<::Clip> m_clip;
QSharedPointer<::Clip> m_clip;
quint32 m_newTrackId;
quint32 m_oldTrackId;
qint64 m_newPos;
......@@ -121,7 +123,7 @@ namespace Commands
private:
std::shared_ptr<SequenceWorkflow> m_workflow;
std::shared_ptr<::Clip> m_clip;
QSharedPointer<::Clip> m_clip;
quint32 m_trackId;
qint64 m_pos;
};
......@@ -144,7 +146,7 @@ namespace Commands
private:
std::shared_ptr<SequenceWorkflow> m_workflow;
std::shared_ptr<::Clip> m_clip;
QSharedPointer<::Clip> m_clip;
qint64 m_newBegin;
qint64 m_oldBegin;
qint64 m_newEnd;
......@@ -163,9 +165,9 @@ namespace Commands
virtual void retranslate();
private:
std::shared_ptr<SequenceWorkflow> m_workflow;
std::shared_ptr<::Clip> m_toSplit;
QSharedPointer<::Clip> m_toSplit;
quint32 m_trackId;
std::shared_ptr<::Clip> m_newClip;
QSharedPointer<::Clip> m_newClip;
qint64 m_newClipPos;
qint64 m_newClipBegin;
qint64 m_oldEnd;
......
......@@ -85,7 +85,7 @@ Library::addMedia( QSharedPointer<Media> media )
if ( m_media.contains( media->id() ) )
return;
m_media[media->id()] = media;
connect( media.data(), &Media::subclipAdded, [this]( Clip* c ) {
connect( media.data(), &Media::subclipAdded, [this]( QSharedPointer<Clip> c ) {
m_clips[c->uuid()] = c;
setCleanState( false );
});
......@@ -108,8 +108,7 @@ Library::media( qint64 mediaId )
return m_media.value( mediaId );
}
Clip*
Library::clip( const QUuid& uuid )
QSharedPointer<Clip> Library::clip( const QUuid& uuid )
{
return m_clips.value( uuid );
......
......@@ -60,7 +60,7 @@ public:
* @return The clip if it exists, or nullptr
* This can be any clip, the given UUID doesn't have to refer to a root clip
*/
Clip* clip( const QUuid& uuid );
QSharedPointer<Clip> clip( const QUuid& uuid );
void clear();
private:
......@@ -75,7 +75,7 @@ private:
* @brief m_clips contains all the clips loaded in the library, without any
* subclip hierarchy
*/
QHash<QUuid, Clip*> m_clips;
QHash<QUuid, QSharedPointer<Clip>> m_clips;
void preSave();
void postLoad();
......
......@@ -116,10 +116,10 @@ Media::id() const
return m_mlMedia->id();
}
Clip*
Media::cut(qint64 begin, qint64 end)
QSharedPointer<Clip>
Media::cut( qint64 begin, qint64 end )
{
auto clip = new Clip( sharedFromThis(), begin, end );
auto clip = QSharedPointer<Clip>( new Clip( sharedFromThis(), begin, end ) );
m_clips[clip->uuid()] = clip;
emit subclipAdded( clip );
return clip;
......@@ -221,18 +221,18 @@ Media::snapshot()
return m_snapshot.isNull() ? *Media::defaultSnapshot : m_snapshot;
}
Clip*
QSharedPointer<Clip>
Media::loadSubclip( const QVariantMap& m )
{
if ( m.contains( "uuid" ) == false || m.contains( "begin" ) == false || m.contains( "end" ) == false )
{
vlmcWarning() << "Invalid clip provided:" << m;
return nullptr;
return {};
}
const auto& uuid = m["uuid"].toUuid();
const auto begin = m["begin"].toLongLong();
const auto end = m["end"].toLongLong();
auto clip = new Clip( sharedFromThis(), begin, end, uuid );
auto clip = QSharedPointer<Clip>( new Clip( sharedFromThis(), begin, end, uuid ) );
//FIXME: This shouldn't be loaded from the library
clip->loadFilters( m );
......
......@@ -99,7 +99,7 @@ public:
* @param end The last frame of the cut
* @return A new Clip, representing the media from [begin] to [end]
*/
Clip* cut( qint64 begin, qint64 end );
QSharedPointer<Clip> cut( qint64 begin, qint64 end );
void removeSubclip( const QUuid& uuid );
QVariant toVariant() const;
......@@ -115,14 +115,14 @@ public:
#endif
private:
Clip* loadSubclip( const QVariantMap& m );
QSharedPointer<Clip> loadSubclip( const QVariantMap& m );
protected:
std::unique_ptr<Backend::IInput> m_input;
medialibrary::MediaPtr m_mlMedia;
medialibrary::FilePtr m_mlFile;
Clip* m_baseClip;
QHash<QUuid, Clip*> m_clips;
QHash<QUuid, QSharedPointer<Clip>> m_clips;
#ifdef HAVE_GUI
static QPixmap* defaultSnapshot;
......@@ -134,7 +134,7 @@ signals:
* \brief This signal should be emitted to tell a new sublip have been added
* \param Clip The newly added subclip
*/
void subclipAdded( Clip* );
void subclipAdded( QSharedPointer<Clip> );
/**
* \brief This signal should be emiteted when a subclip has been removed
* This signal pass a QUuid as the clip may be deleted when the signal reaches its
......
......@@ -64,7 +64,7 @@ SequenceWorkflow::~SequenceWorkflow()
}
bool
SequenceWorkflow::addClip( std::shared_ptr<Clip> const& clip, quint32 trackId, qint32 pos )
SequenceWorkflow::addClip( QSharedPointer<Clip> const& clip, quint32 trackId, qint32 pos )
{
auto ret = trackFromFormats( trackId, clip->formats() )->insertAt( *clip->input(), pos );
if ( ret == false )
......@@ -76,16 +76,13 @@ SequenceWorkflow::addClip( std::shared_ptr<Clip> const& clip, quint32 trackId, q
QString
SequenceWorkflow::addClip( const QUuid& uuid, quint32 trackId, qint32 pos, bool isAudioClip )
{
Clip* clip = Core::instance()->library()->clip( uuid );
if ( clip == nullptr )
auto newClip = Core::instance()->library()->clip( uuid );
if ( newClip == nullptr )
{
vlmcCritical() << "Couldn't find an acceptable parent to be added.";
return QUuid().toString();
}
//FIXME: This will blow up:
auto newClip = std::shared_ptr<Clip>( clip );
if ( isAudioClip == true )
newClip->setFormats( Clip::Audio );
else
......@@ -150,14 +147,14 @@ SequenceWorkflow::resizeClip( const QUuid& uuid, qint64 newBegin, qint64 newEnd,
return ret;
}
std::shared_ptr<Clip>
QSharedPointer<Clip>
SequenceWorkflow::removeClip( const QUuid& uuid )
{
auto it = m_clips.find( uuid );
if ( it == m_clips.end() )
{
vlmcCritical() << "Couldn't find a clip " << uuid;
return std::shared_ptr<Clip>( nullptr );
return {};
}
auto clip = std::get<ClipTupleIndex::Clip>( it.value() );
auto trackId = std::get<ClipTupleIndex::TrackId>( it.value() );
......@@ -266,12 +263,12 @@ SequenceWorkflow::clear()
}
}
std::shared_ptr<Clip>
QSharedPointer<Clip>
SequenceWorkflow::clip( const QUuid& uuid )
{
auto it = m_clips.find( uuid );
if ( it == m_clips.end() )
return std::shared_ptr<Clip>( nullptr );
return {};
return std::get<ClipTupleIndex::Clip>( it.value() );
}
......
......@@ -57,14 +57,14 @@ class SequenceWorkflow : public QObject
~SequenceWorkflow();
// Clip, Track Id, and Position
using ClipTuple = std::tuple<std::shared_ptr<Clip>, quint32, qint64>;
using ClipTuple = std::tuple<QSharedPointer<Clip>, quint32, qint64>;
bool addClip( std::shared_ptr<Clip> const& clip, quint32 trackId, qint32 pos );
bool addClip( QSharedPointer<Clip> const& clip, quint32 trackId, qint32 pos );
QString addClip( const QUuid& uuid, quint32 trackId, qint32 pos, bool isAudioClip );
bool moveClip( const QUuid& uuid, quint32 trackId, qint64 pos );
bool resizeClip( const QUuid& uuid, qint64 newBegin,
qint64 newEnd, qint64 newPos );
std::shared_ptr<Clip> removeClip( const QUuid& uuid );
QSharedPointer<Clip> removeClip( const QUuid& uuid );
bool linkClips( const QUuid& uuidA, const QUuid& uuidB );
bool unlinkClips( const QUuid& uuidA, const QUuid& uuidB );
......@@ -72,7 +72,7 @@ class SequenceWorkflow : public QObject
void loadFromVariant( const QVariant& variant );
void clear();
std::shared_ptr<Clip> clip( const QUuid& uuid );
QSharedPointer<Clip> clip( const QUuid& uuid );
quint32 trackId( const QUuid& uuid );
qint32 position( const QUuid& uuid );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment