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

Multitracks timeline o//

parent 921cbf72
......@@ -25,19 +25,30 @@
#include "MainWorkflow.h"
MainWorkflow::MainWorkflow() : m_renderStarted( false )
unsigned char* MainWorkflow::blackOutput = NULL;
MainWorkflow::MainWorkflow( int trackCount ) :
m_trackCount( trackCount ),
m_renderStarted( false )
{
m_tracks = new TrackWorkflow*[NB_TRACKS];
for (unsigned int i = 0; i < NB_TRACKS; ++i)
if ( MainWorkflow::blackOutput == NULL )
{
m_tracks[i] = new TrackWorkflow;
connect( m_tracks[i], SIGNAL( trackEndReached() ), this, SLOT( __endReached() ) );
//TODO: this ain't free !
MainWorkflow::blackOutput = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 3];
memset( MainWorkflow::blackOutput, 0, VIDEOHEIGHT * VIDEOWIDTH * 3 );
}
m_tracks = new Toggleable<TrackWorkflow*>[trackCount];
for (int i = 0; i < trackCount; ++i)
{
m_tracks[i].setPtr( new TrackWorkflow( i ) );
connect( m_tracks[i], SIGNAL( trackEndReached( unsigned int ) ), this, SLOT( trackEndReached(unsigned int) ) );
}
}
void MainWorkflow::addClip( Clip* clip, unsigned int trackId, qint64 start )
{
Q_ASSERT_X( trackId < NB_TRACKS, "MainWorkflow::addClip",
Q_ASSERT_X( trackId < m_trackCount, "MainWorkflow::addClip",
"The specified trackId isn't valid, for it's higher than the number of tracks");
qDebug() << "MainWorkflow: Adding clip" << clip->getUuid() << "to track" << trackId;
......@@ -46,15 +57,36 @@ void MainWorkflow::addClip( Clip* clip, unsigned int trackId, qint64 start )
void MainWorkflow::startRender()
{
qint64 maxLength = 0;
m_renderStarted = true;
m_currentFrame = 0;
emit frameChanged( 0 );
m_length = m_tracks[0]->getLength();
for ( unsigned int i = 0; i < m_trackCount; ++i )
{
if ( m_tracks[i]->getLength() > maxLength )
maxLength = m_tracks[i]->getLength();
}
m_length = maxLength;
}
unsigned char* MainWorkflow::getOutput()
{
unsigned char* ret = m_tracks[0]->getOutput( m_currentFrame );
unsigned char* ret;
for ( unsigned int i = 0; i < m_trackCount; ++i )
{
if ( m_tracks[i].activated() == false )
continue ;
if ( ( ret = m_tracks[i]->getOutput( m_currentFrame ) ) != NULL )
{
qDebug() << "Getting a frame";
break ;
}
}
if ( ret == NULL )
ret = MainWorkflow::blackOutput;
++m_currentFrame;
emit frameChanged( m_currentFrame );
emit positionChanged( (float)m_currentFrame / (float)m_length );
......@@ -76,10 +108,22 @@ qint64 MainWorkflow::getLength() const
return m_length;
}
void MainWorkflow::__endReached()
void MainWorkflow::trackEndReached( unsigned int trackId )
{
m_tracks[trackId].deactivate();
for ( unsigned int i = 0; i < m_trackCount; ++i)
{
if ( m_tracks[i].activated() == true )
return ;
}
emit mainWorkflowEndReached();
m_renderStarted = false;
m_currentFrame = 0;
emit frameChanged( 0 );
}
unsigned int MainWorkflow::getTrackCount() const
{
return m_trackCount;
}
......@@ -26,17 +26,15 @@
#include <QObject>
#include "tools/Toggleable.hpp"
#include "TrackWorkflow.h"
//TODO: THIS HAS TO GO ASAP !!!!!
#define NB_TRACKS 1
class MainWorkflow : public QObject
{
Q_OBJECT
public:
MainWorkflow();
MainWorkflow( int trackCount );
void addClip( Clip* clip, unsigned int trackId, qint64 start );
void startRender();
......@@ -53,18 +51,26 @@ class MainWorkflow : public QObject
* in frames.
*/
qint64 getLength() const;
/**
* This boolean describe is a render has been started
*/
bool m_renderStarted;
* Returns the number of tracks in this workflow
*/
unsigned int getTrackCount() const;
static unsigned char* blackOutput;
private:
TrackWorkflow** m_tracks;
qint64 m_currentFrame;
qint64 m_length;
Toggleable<TrackWorkflow*>* m_tracks;
qint64 m_currentFrame;
qint64 m_length;
unsigned int m_trackCount;
/**
* This boolean describe is a render has been started
*/
bool m_renderStarted;
private slots:
void __endReached();
void trackEndReached( unsigned int trackId );
signals:
/**
......
......@@ -24,17 +24,9 @@
#include "TrackWorkflow.h"
unsigned char* TrackWorkflow::blackOutput = NULL;
TrackWorkflow::TrackWorkflow()
TrackWorkflow::TrackWorkflow( unsigned int trackId ) : m_trackId( trackId )
{
m_mediaPlayer = new LibVLCpp::MediaPlayer();
if ( TrackWorkflow::blackOutput == NULL )
{
//TODO: this ain't free !
TrackWorkflow::blackOutput = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 3];
memset( TrackWorkflow::blackOutput, 0, VIDEOHEIGHT * VIDEOWIDTH * 3 );
}
}
TrackWorkflow::~TrackWorkflow()
......@@ -65,7 +57,7 @@ qint64 TrackWorkflow::getLength() const
unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
qint64 start , bool needRepositioning )
{
unsigned char* ret = TrackWorkflow::blackOutput;
unsigned char* ret = NULL;
cw->getStateLock()->lockForRead();
......@@ -198,7 +190,7 @@ bool TrackWorkflow::checkEnd( qint64 currentFrame ) const
unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
{
unsigned char* ret = TrackWorkflow::blackOutput;
unsigned char* ret = NULL;
QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
static qint64 lastFrame = 0;
......@@ -206,7 +198,7 @@ unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
if ( checkEnd( currentFrame ) == true )
{
emit trackEndReached();
emit trackEndReached( m_trackId );
//We continue, as there can be ClipWorkflow that required to be stopped.
}
needRepositioning = ( abs( currentFrame - lastFrame ) > 1 ) ? true : false;
......
......@@ -43,7 +43,7 @@ class TrackWorkflow : public QObject
Q_OBJECT
public:
TrackWorkflow();
TrackWorkflow( unsigned int trackId );
~TrackWorkflow();
unsigned char* getOutput( qint64 currentFrame );
......@@ -51,7 +51,6 @@ class TrackWorkflow : public QObject
//FIXME: this won't be reliable as soon as we change the fps from the configuration
static const unsigned int nbFrameBeforePreload = 60;
static unsigned char* blackOutput;
private:
void computeLength();
......@@ -62,6 +61,8 @@ class TrackWorkflow : public QObject
bool checkEnd( qint64 currentFrame ) const;
private:
unsigned int m_trackId;
QMap<qint64, ClipWorkflow*> m_clips;
/**
......@@ -79,7 +80,7 @@ class TrackWorkflow : public QObject
void addClip( Clip*, qint64 start );
signals:
void trackEndReached();
void trackEndReached( unsigned int );
};
#endif // TRACKWORKFLOW_H
......@@ -32,7 +32,7 @@ Timeline::Timeline( QWidget *parent ) :
{
m_ui.setupUi( this );
m_mainWorkflow = new MainWorkflow();
m_mainWorkflow = new MainWorkflow( 5 );
m_tracksScene = new TracksScene( this );
m_tracksView = new TracksView( m_tracksScene, m_mainWorkflow, m_ui.tracksFrame );
......
......@@ -38,7 +38,7 @@ TracksView::TracksView( QGraphicsScene* scene, MainWorkflow* mainWorkflow, QWidg
m_tracksHeight = 50;
//TODO should be dynamic
m_tracksCount = 5;
m_tracksCount = mainWorkflow->getTrackCount();
m_fps = 30;
setMouseTracking( true );
......
......@@ -43,7 +43,7 @@ public:
void setDuration( int duration );
int duration() const { return m_projectDuration; }
int tracksHeight() const { return m_tracksHeight; }
int tracksCount() const { return m_tracksCount; }
unsigned int tracksCount() const { return m_tracksCount; }
void setCursorPos( int pos );
int cursorPos();
GraphicsCursorItem* tracksCursor() const { return m_cursorLine; }
......
/*****************************************************************************
* Toggleable.hpp : Represents a generic container for toglleable values
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef TOGGLEABLE_HPP
#define TOGGLEABLE_HPP
#include <QtDebug>
/**
* This class represents a generic toggleable value container.
*/
template <typename T>
class Toggleable
{
public:
Toggleable() : m_ptr( NULL ), m_activated( true )
{
}
void setPtr( T ptr )
{
Q_ASSERT( m_ptr == NULL );
m_ptr = ptr;
}
operator T()
{
return m_ptr;
}
T operator->()
{
if ( m_activated == true )
return m_ptr;
qDebug() << "using operator -> on a disabled value !";
return NULL;
}
bool activated() const
{
return m_activated;
}
bool deactivated() const
{
return !m_activated;
}
void activate()
{
m_activated = true;
}
void deactivate()
{
m_activated = false;
}
private:
T m_ptr;
bool m_activated;
};
#endif // TOGGLEABLE_HPP
......@@ -76,7 +76,8 @@ HEADERS += src/gui/MainWindow.h \
src/Workflow/MainWorkflow.h \
src/gui/PreviewWidget.h \
src/gui/RenderPreviewWidget.h \
src/gui/GenericPreviewWidget.h
src/gui/GenericPreviewWidget.h \
src/tools/Toggleable.hpp
FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/PreviewWidget.ui \
src/gui/ui/Preferences.ui \
......
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