Commit bd4e528a authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Adding correct boundaries to clip resizing.

Fixes issue #107
parent 4cb79555
......@@ -133,18 +133,19 @@ namespace Action
class ResizeClip : public Generic
{
public:
ResizeClip( Clip* clip, qint64 newBegin, qint64 newEnd ) : Generic( Resize ),
m_clip( clip ), m_newBegin( newBegin ), m_newEnd( newEnd )
ResizeClip( Clip* clip, qint64 newBegin, qint64 newEnd, bool resizeForSplit ) : Generic( Resize ),
m_clip( clip ), m_newBegin( newBegin ), m_newEnd( newEnd ), m_resizeForSplit( resizeForSplit )
{
}
void execute()
{
m_clip->setBoundaries( m_newBegin, m_newEnd );
m_clip->setBoundaries( m_newBegin, m_newEnd, m_resizeForSplit );
}
protected:
Clip* m_clip;
qint64 m_newBegin;
qint64 m_newEnd;
bool m_resizeForSplit;
};
class Pause : public Workflow
......
......@@ -100,15 +100,12 @@ void AbstractGraphicsMediaItem::resize( qint64 size, From from )
{
Q_ASSERT( clip() );
if ( size > clip()->getParent()->getNbFrames() || size < 1 )
if ( size > clip()->getMaxEnd() || size < 1 )
return;
qint64 realBegin = startPos() - clip()->getBegin();
qint64 realEnd = realBegin + clip()->getParent()->getNbFrames();
if ( from == BEGINNING )
{
if ( realBegin + clip()->getBegin() + size > realEnd )
if ( clip()->getBegin() + size > clip()->getMaxEnd() )
return ;
tracksView()->getRenderer()->resizeClip( clip(), clip()->getBegin(), clip()->getBegin() + size, 0, //This parameter is unused in this case
trackNumber(), MainWorkflow::VideoTrack );
......@@ -116,14 +113,14 @@ void AbstractGraphicsMediaItem::resize( qint64 size, From from )
else
{
qint64 newBegin = qMax( clip()->getEnd() - size, (qint64)0 );
if ( realBegin > newBegin + startPos() )
if ( clip()->getMaxBegin() > newBegin )
return ;
qint64 oldLength = clip()->getLength();
if ( ( clip()->getEnd() - size ) < 0 )
{
qWarning( "Warning: resizing a region with a size below 0" );
size += clip()->getEnd() - size;
}
// if ( ( clip()->getEnd() - size ) < 0 )
// {
// qWarning( "Warning: resizing a region with a size below 0" );
// size += clip()->getEnd() - size;
// }
m_resizeExpected = true;
tracksView()->getRenderer()->resizeClip( clip(), qMax( clip()->getEnd() - size, (qint64)0 ), clip()->getEnd(),
startPos() + ( oldLength - size ), trackNumber(), MainWorkflow::VideoTrack );
......
......@@ -31,25 +31,43 @@
const int Clip::DefaultFPS = 30;
Clip::Clip( Media* parent ) : m_parent( parent ), m_begin( 0 ), m_end( parent->getNbFrames() )
Clip::Clip( Media* parent ) :
m_parent( parent ),
m_begin( 0 ),
m_end( parent->getNbFrames() ),
m_maxBegin( 0 ),
m_maxEnd( parent->getNbFrames() )
{
m_Uuid = QUuid::createUuid();
computeLength();
}
Clip::Clip( Clip* creator, qint64 begin, qint64 end ) : m_parent( creator->getParent() ), m_begin( begin ), m_end( end )
Clip::Clip( Clip* creator, qint64 begin, qint64 end ) :
m_parent( creator->getParent() ),
m_begin( begin ),
m_end( end ),
m_maxBegin( begin ),
m_maxEnd( end )
{
m_Uuid = QUuid::createUuid();
computeLength();
}
Clip::Clip( Media* parent, qint64 begin, qint64 end /*= -1*/ ) : m_parent( parent ), m_begin( begin ), m_end( end )
Clip::Clip( Media* parent, qint64 begin, qint64 end /*= -1*/ ) :
m_parent( parent ),
m_begin( begin ),
m_end( end ),
m_maxBegin( begin ),
m_maxEnd( end )
{
//FIXME: WTF ?
Q_ASSERT( parent->getInputType() == Media::File || ( begin == 0 && end == m_parent->getNbFrames() ) );
if ( parent->getInputType() == Media::File && end < 0 )
{
m_end = parent->getNbFrames();
m_maxEnd = m_end;
}
m_Uuid = QUuid::createUuid();
computeLength();
}
......@@ -61,14 +79,18 @@ Clip::Clip( Clip* clip ) :
m_length( clip->m_length ),
m_lengthSeconds( clip->m_lengthSeconds ),
m_metaTags( clip->m_metaTags ),
m_notes( clip->m_notes )
m_notes( clip->m_notes ),
m_maxBegin( clip->m_begin ),
m_maxEnd( clip->m_end )
{
m_Uuid = QUuid::createUuid();
}
Clip::Clip( const QUuid& uuid, qint64 begin, qint64 end ) :
m_begin( begin),
m_end( end )
m_end( end ),
m_maxBegin( begin ),
m_maxEnd( end )
{
Q_UNUSED( end );
Media* media = Library::getInstance()->getMedia( uuid );
......@@ -166,27 +188,46 @@ const QUuid& Clip::getUuid() const
return m_Uuid;
}
void Clip::setBegin( qint64 begin )
void Clip::setBegin( qint64 begin, bool updateMax /*= false*/ )
{
Q_ASSERT( begin >= .0f );
if ( begin == m_begin ) return;
m_begin = begin;
if ( updateMax == true )
m_maxBegin = begin;
computeLength();
}
void Clip::setEnd( qint64 end )
void Clip::setEnd( qint64 end, bool updateMax /*= false*/ )
{
if ( end == m_end ) return;
m_end = end;
if ( updateMax == true )
m_maxEnd = end;
computeLength();
}
void Clip::setBoundaries( qint64 newBegin, qint64 newEnd )
void Clip::setBoundaries( qint64 newBegin, qint64 newEnd, bool updateMax /*= false*/ )
{
Q_ASSERT( newBegin < newEnd );
if ( newBegin == m_begin && m_end == newEnd )
return ;
m_begin = newBegin;
m_end = newEnd;
if ( updateMax == true )
{
m_maxBegin = newBegin;
m_maxEnd = newEnd;
}
computeLength();
}
qint64 Clip::getMaxBegin() const
{
return m_maxBegin;
}
qint64 Clip::getMaxEnd() const
{
return m_maxEnd;
}
......@@ -52,9 +52,9 @@ class Clip : public QObject
qint64 getBegin() const;
qint64 getEnd() const;
void setBegin( qint64 begin );
void setEnd( qint64 end );
void setBoundaries( qint64 newBegin, qint64 newEnd );
void setBegin( qint64 begin, bool updateMax = false );
void setEnd( qint64 end, bool updateMax = false );
void setBoundaries( qint64 newBegin, qint64 newEnd, bool updateMax = false );
/**
\return Returns the clip length in frame.
......@@ -87,6 +87,9 @@ class Clip : public QObject
const QString& getNotes() const;
void setNotes( const QString& notes );
qint64 getMaxBegin() const;
qint64 getMaxEnd() const;
private:
void computeLength();
......@@ -119,6 +122,18 @@ class Clip : public QObject
QStringList m_metaTags;
QString m_notes;
/**
* This is used for the resize. The clip won't be abble to be resized beyond this value.
* ie this clip won't start before m_maxBegin.
*/
qint64 m_maxBegin;
/**
* This is used for the resize. The clip won't be abble to be resized beyond this value
* ie this clip won't end before m_maxEnd.
*/
qint64 m_maxEnd;
signals:
void lengthUpdated();
};
......
......@@ -278,16 +278,16 @@ Clip* WorkflowRenderer::split( Clip* toSplit, Clip* newClip, uint32_t trac
//thus potentially breaking the synchrone way of doing this
Action::Generic* act = new Action::AddClip( m_mainWorkflow, trackId, trackType, newClip, newClipPos );
//resizing it
Action::Generic* act2 = new Action::ResizeClip( toSplit, toSplit->getBegin(), newClipBegin );
Action::Generic* act2 = new Action::ResizeClip( toSplit, toSplit->getBegin(), newClipBegin, true );
//Push the actions onto the action stack
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
m_actions.push( act2 );
m_actions.addAction( act2 );
}
else
{
toSplit->setEnd( newClipBegin );
toSplit->setEnd( newClipBegin, true );
m_mainWorkflow->addClip( newClip, trackId, newClipPos, trackType );
}
return newClip;
......@@ -300,7 +300,7 @@ void WorkflowRenderer::unsplit( Clip* origin, Clip* splitted, uint32_t trackI
//removing clip
Action::Generic* act = new Action::RemoveClip( m_mainWorkflow, trackId, trackType, splitted->getUuid() );
//resizing it
Action::Generic* act2 = new Action::ResizeClip( origin, splitted->getBegin(), oldEnd );
Action::Generic* act2 = new Action::ResizeClip( origin, splitted->getBegin(), oldEnd, true );
//Push the actions onto the action stack
QMutexLocker lock( m_actionsMutex );
m_actions.addAction( act );
......@@ -309,7 +309,7 @@ void WorkflowRenderer::unsplit( Clip* origin, Clip* splitted, uint32_t trackI
else
{
m_mainWorkflow->removeClip( splitted->getUuid(), trackId, trackType );
origin->setEnd( oldEnd );
origin->setEnd( oldEnd, true );
}
}
......
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