Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 84a16dda authored by Jason Wood's avatar Jason Wood

Minor optimisation of scenelist generation - populating scenelists is now done...

Minor optimisation of scenelist generation - populating scenelists is now done on a vector that is passed into the method, which avoids a copy.

svn path=/trunk/kdenlive/; revision=305
parent 9b762c12
......@@ -158,12 +158,10 @@ QDomDocument DocClipAVFile::sceneToXML(const GenTime &startTime, const GenTime &
return sceneList;
}
QValueVector<GenTime> DocClipAVFile::sceneTimes()
void DocClipAVFile::populateSceneTimes(QValueVector<GenTime> &toPopulate)
{
QValueVector<GenTime> list;
list.append(trackStart());
list.append(trackEnd());
return list;
toPopulate.append(trackStart());
toPopulate.append(trackEnd());
}
// virtual
......
......@@ -56,8 +56,8 @@ public:
virtual int framesPerSecond() const;
/** Returns a scene list generated from this clip. */
virtual QDomDocument generateSceneList();
// Returns a list of times that this clip must break upon.
virtual QValueVector<GenTime> sceneTimes();
// Appends scene times for this clip to the passed vector.
virtual void populateSceneTimes(QValueVector<GenTime> &toPopulate);
// Returns an XML document that describes part of the current scene.
virtual QDomDocument sceneToXML(const GenTime &startTime, const GenTime &endTime);
......
......@@ -108,8 +108,8 @@ public:
* where it returns true. */
virtual bool isProjectClip() { return false; }
// Returns a list of times that this clip must break upon.
virtual QValueVector<GenTime> sceneTimes() = 0;
// Appends scene times for this clip to the passed vector.
virtual void populateSceneTimes(QValueVector<GenTime> &toPopulate) = 0;
// Returns an XML document that describes part of the current scene.
virtual QDomDocument sceneToXML(const GenTime &startTime, const GenTime &endTime) = 0;
......
......@@ -257,11 +257,15 @@ QDomDocument DocClipProject::generateSceneList()
QDomDocument sceneList;
sceneList.appendChild(sceneList.createElement("scenelist"));
QValueVector<GenTime> unsortedTimes = sceneTimes();
QValueVector<GenTime> unsortedTimes;
populateSceneTimes(unsortedTimes);
// sort times and remove duplicates.
qHeapSort(unsortedTimes);
QValueVector<GenTime> times;
// Will reserve much more than we need, but should speed up the process somewhat...
times.reserve(unsortedTimes.size());
QValueVector<GenTime>::Iterator itt = unsortedTimes.begin();
while(itt != unsortedTimes.end()) {
......@@ -336,22 +340,22 @@ DocClipProject * DocClipProject::createClip(KdenliveDoc *doc, const QDomElement
return project;
}
QValueVector<GenTime> DocClipProject::sceneTimes()
void DocClipProject::populateSceneTimes(QValueVector<GenTime> &toPopulate)
{
QValueVector<GenTime> list;
GenTime time;
for(uint count=0; count<numTracks(); count++) {
DocTrackClipIterator itt(*(m_tracks.at(count)));
while(itt.current()) {
QValueVector<GenTime> newTimes = itt.current()->sceneTimes();
QValueVector<GenTime> newTimes;
itt.current()->populateSceneTimes(newTimes);
QValueVector<GenTime>::Iterator newItt = newTimes.begin();
while(newItt != newTimes.end()) {
time = (*newItt) + trackStart() - cropStartTime();
if((time >= trackStart()) && (time <= trackEnd())) {
list.append(time);
toPopulate.append(time);
}
++newItt;
......@@ -360,10 +364,8 @@ QValueVector<GenTime> DocClipProject::sceneTimes()
}
}
list.append(trackStart());
list.append(trackEnd());
return list;
toPopulate.append(trackStart());
toPopulate.append(trackEnd());
}
// Returns an XML document that describes part of the current scene.
......@@ -432,3 +434,32 @@ QPtrList<DocClipBase> DocClipProject::referencedClips(AVFile *file)
return list;
}
bool DocClipProject::hasSelectedClips()
{
bool result = false;
for(uint count=0; count<numTracks(); ++count) {
if(m_tracks.at(count)->hasSelectedClips()) {
result = true;
break;
}
}
return result;
}
DocClipBase *DocClipProject::selectedClip()
{
DocClipBase *pResult;
DocTrackBase *srcTrack;
for(uint track=0; track<numTracks(); track++) {
srcTrack = m_tracks.at(track);
if(srcTrack->hasSelectedClips()) {
pResult = srcTrack->firstClip(true).current();
}
}
return pResult;
}
......@@ -73,14 +73,22 @@ public:
/** Creates a clip from the passed QDomElement. This only pertains to those details
* specific to DocClipProject.*/
static DocClipProject * createClip(KdenliveDoc *doc, const QDomElement element);
// Returns a list of times that this clip must break upon.
virtual QValueVector<GenTime> sceneTimes();
// Appends scene times for this clip to the passed vector.
virtual void populateSceneTimes(QValueVector<GenTime> &toPopulate);
// Returns an XML document that describes part of the current scene.
virtual QDomDocument sceneToXML(const GenTime &startTime, const GenTime &endTime);
/** Returns true if the clip in some way includes he specified AVFile. */
virtual bool containsAVFile(AVFile *file);
QPtrList<DocClipBase> referencedClips(AVFile *file);
/** Returns true if at least one clip in the project clip is currently selected, false otherwise. */
bool hasSelectedClips();
/** Returns a clip that is currently selected. Only one clip is returned!
* This function is intended for times when you need a "master" clip. but have no preferred
* choice. */
DocClipBase *selectedClip();
signals:
/** This signal is emitted whenever tracks are added to or removed from the project. */
void trackListChanged();
......
......@@ -291,14 +291,21 @@ void DocTrackBase::resizeClipTrackStart(DocClipBase *clip, GenTime newStart)
kdWarning() << "Clip cannot be resized to length < 1 frame, fixing..." << endl;
newStart = clip->cropDuration() - GenTime(1, m_doc->framesPerSecond());
}
// Check that we are not trying to overlap the previous clip.
DocTrackClipIterator itt(*this);
DocClipBase *previousClip = 0;
#warning - the following code does not work for large increments - small clips might be overlapped.
#warning - Replace with code that looks at the clip directly before the clip we are working with.
DocClipBase *test;
test = getClipAt(clip->trackStart() + newStart);
while(itt.current() && (itt.current()!=clip)) {
previousClip = itt.current();
++itt;
}
if((test) && (test != clip)) {
newStart = test->trackStart() + test->cropDuration() - clip->trackStart();
if(previousClip && (itt.current() == clip)) {
if(previousClip->trackEnd() > newStart + clip->trackStart()) {
newStart = previousClip->trackEnd() - clip->trackStart();
}
}
clip->setTrackStart(clip->trackStart() + newStart);
......@@ -324,14 +331,25 @@ void DocTrackBase::resizeClipTrackEnd(DocClipBase *clip, GenTime newEnd)
newEnd = clip->trackStart() + GenTime(1, m_doc->framesPerSecond());
}
#warning - the following code does not work for large increments - small clips might be overlapped.
#warning - Replace with code that looks at the clip directly after the clip we are working with.
DocClipBase *test;
// Check that we are not overlapping the next clip on the track.
DocTrackClipIterator itt(*this);
DocClipBase *nextClip=0;
while(itt.current() && (itt.current() != clip)) {
++itt;
}
test = getClipAt(newEnd);
if(itt.current()) {
++itt;
nextClip = itt.current();
} else {
kdError() << "Trying to resize clip that does not exist on specified track!!!" << endl;
}
if((test) && (test != clip)) {
newEnd = test->trackStart();
if(nextClip && (nextClip != clip)) {
if(nextClip->trackStart() < newEnd) {
newEnd = nextClip->trackStart();
}
}
clip->setTrackEnd(newEnd);
......
......@@ -37,27 +37,28 @@ class DocTrackBase : public QObject
public:
DocTrackBase(KdenliveDoc *doc);
virtual ~DocTrackBase();
/** Returns true if the specified clip can be added to this track, false otherwise.
*
* This method needs to be implemented by inheriting classes to define
* which types of clip they support. */
virtual bool canAddClip(DocClipBase *clip) = 0;
/** Adds a clip to the track. Returns true if successful, false if it fails for some reason.
* This method calls canAddClip() to determine whether or not the clip can be added to this
* particular track. */
bool addClip(DocClipBase *clip, bool selected);
/** Returns the clip type as a string. This is a bit of a hack to give the
* KMMTimeLine a way to determine which class it should associate
* with each type of clip. */
virtual const QString &clipType() = 0;
/** Returns an iterator to the clip after the last clip(chronologically) which overlaps the
start/end value range specified.
/** Returns true if the specified clip can be added to this track, false otherwise.
*
* This method needs to be implemented by inheriting classes to define
* which types of clip they support. */
virtual bool canAddClip(DocClipBase *clip) = 0;
/** Adds a clip to the track. Returns true if successful, false if it fails for some reason.
* This method calls canAddClip() to determine whether or not the clip can be added to this
* particular track. */
bool addClip(DocClipBase *clip, bool selected);
/** Returns the clip type as a string. This is a bit of a hack to give the
* KMMTimeLine a way to determine which class it should associate
* with each type of clip. */
virtual const QString &clipType() = 0;
/** Returns an iterator to the clip after the last clip(chronologically) which overlaps the
start/end value range specified.
This allows you to write standard iterator for loops over a specific range of the track.
You must choose which list of tracks you are interested in - the selected or unselected. */
QPtrListIterator<DocClipBase> endClip(GenTime startValue, GenTime endValue, bool selected);
/** Returns an iterator to the first clip (chronologically) which overlaps the start/end value range specified.
You must choose which list of tracks you are interested in - the selected or unselected. */
This allows you to write standard iterator for loops over a specific range of the track.
You must choose which list of tracks you are interested in - the selected or unselected. */
QPtrListIterator<DocClipBase> endClip(GenTime startValue, GenTime endValue, bool selected);
/** Returns an iterator to the first clip (chronologically) which overlaps the start/end
* value range specified.
* You must choose which list of tracks you are interested in - the selected or unselected. */
QPtrListIterator<DocClipBase> firstClip(GenTime startValue, GenTime endValue, bool selected);
/** Returns the clip which resides at the current value, or 0 if non exists */
DocClipBase *getClipAt(GenTime value);
......
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