Update of /cvsroot/audacity/audacity-src/src
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv4717

Modified Files:
        WaveClip.h WaveTrack.cpp WaveTrack.h 
Log Message:
Fix inconsistent entries in merge point cache when merge points were very close 
to each other

Index: WaveTrack.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/WaveTrack.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- WaveTrack.h 26 Jan 2007 11:06:15 -0000      1.46
+++ WaveTrack.h 26 Mar 2007 12:51:42 -0000      1.47
@@ -249,6 +249,10 @@
 
    // Get number of clips in this WaveTrack
    int GetNumClips() const;
+   
+   // Add all wave clips to the given array 'clips' and sort the array by
+   // clip start time. The array is emptied prior to adding the clips.
+   void FillSortedClipArray(WaveClipArray& clips);
 
    // Before calling 'Offset' on a clip, use this function to see if the
    // offsetting is allowed with respect to the other clips in this track.

Index: WaveTrack.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/WaveTrack.cpp,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- WaveTrack.cpp       24 Mar 2007 23:51:46 -0000      1.97
+++ WaveTrack.cpp       26 Mar 2007 12:51:42 -0000      1.98
@@ -29,6 +29,7 @@
 
 #include <wx/defs.h>
 #include <wx/intl.h>
+#include <wx/debug.h>
 
 #include <math.h>
 
@@ -1493,27 +1494,29 @@
 
 void WaveTrack::UpdateLocationsCache()
 {
-   WaveClipList::Node *it, *jt;
+   unsigned int i;
+   WaveClipArray clips;
+   
+   FillSortedClipArray(clips);
    
    mDisplayNumLocations = 0;
-
-   for (it=GetClipIterator(); it; it=it->GetNext())
+   
+   // Count number of display locations
+   for (i = 0; i < clips.GetCount(); i++)
    {
-      WaveClip* clip = it->GetData();
+      WaveClip* clip = clips.Item(i);
       
       mDisplayNumLocations += clip->GetCutLines()->GetCount();
-      
-      for (jt=GetClipIterator(); jt; jt=jt->GetNext())
-      {
-         WaveClip* clip2 = jt->GetData();
-         if (clip != clip2 && fabs(clip->GetEndTime()-clip2->GetStartTime()) < 
WAVETRACK_MERGE_POINT_TOLERANCE)
-            mDisplayNumLocations++;
-      }
+
+      if (i > 0 && fabs(clips.Item(i - 1)->GetEndTime() -
+                  clip->GetStartTime()) < WAVETRACK_MERGE_POINT_TOLERANCE)
+         mDisplayNumLocations++;
    }
 
    if (mDisplayNumLocations == 0)
       return;
 
+   // Alloc necessary number of display locations
    if (mDisplayNumLocations > mDisplayNumLocationsAllocated)
    {
       // Only realloc, if we need more space than before. Otherwise
@@ -1524,32 +1527,42 @@
       mDisplayNumLocationsAllocated = mDisplayNumLocations;
    }
 
+   // Add all display locations to cache
    int curpos = 0;
-
-   for (it=GetClipIterator(); it; it=it->GetNext())
+   
+   for (i = 0; i < clips.GetCount(); i++)
    {
-      WaveClip* clip = it->GetData();
+      WaveClip* clip = clips.Item(i);
+
       WaveClipList* cutlines = clip->GetCutLines();
-      for (jt = cutlines->GetFirst(); jt; jt=jt->GetNext())
+      for (WaveClipList::Node* it = cutlines->GetFirst(); it;
+           it = it->GetNext())
       {
+         // Add cut line expander point
          mDisplayLocations[curpos].typ = locationCutLine;
-         mDisplayLocations[curpos].pos = jt->GetData()->GetOffset() + 
it->GetData()->GetOffset();
+         mDisplayLocations[curpos].pos =
+            clip->GetOffset() + it->GetData()->GetOffset();
          curpos++;
       }
-
-      for (jt=GetClipIterator(); jt; jt=jt->GetNext())
+      
+      if (i > 0)
       {
-         WaveClip* clip2 = jt->GetData();
-         if (clip != clip2 && fabs(clip->GetEndTime()-clip2->GetStartTime()) < 
WAVETRACK_MERGE_POINT_TOLERANCE)
+         WaveClip* previousClip = clips.Item(i - 1);
+         
+         if (fabs(previousClip->GetEndTime() - clip->GetStartTime())
+                                          < WAVETRACK_MERGE_POINT_TOLERANCE)
          {
+            // Add merge point
             mDisplayLocations[curpos].typ = locationMergePoint;
-            mDisplayLocations[curpos].pos = clip->GetEndTime();
-            mDisplayLocations[curpos].clipidx1 = mClips.IndexOf(clip);
-            mDisplayLocations[curpos].clipidx2 = mClips.IndexOf(clip2);
+            mDisplayLocations[curpos].pos = clips.Item(i-1)->GetEndTime();
+            mDisplayLocations[curpos].clipidx1 = mClips.IndexOf(previousClip);
+            mDisplayLocations[curpos].clipidx2 = mClips.IndexOf(clip);
             curpos++;
          }
       }
    }
+   
+   wxASSERT(curpos == mDisplayNumLocations);
 }
 
 // Expand cut line (that is, re-insert audio, then delete audio saved in cut 
line)
@@ -1656,6 +1669,21 @@
    return true;
 }
 
+static int SortClipArrayCmpFunc(WaveClip** clip1, WaveClip** clip2)
+{
+   return (int)((*clip1)->GetStartTime() - (*clip2)->GetStartTime());
+}
+
+void WaveTrack::FillSortedClipArray(WaveClipArray& clips)
+{
+   clips.Empty();
+   
+   for (WaveClipList::Node *it=GetClipIterator(); it; it=it->GetNext())
+      clips.Add(it->GetData());
+   
+   clips.Sort(SortClipArrayCmpFunc);
+}
+
 // Indentation settings for Vim and Emacs and unique identifier for Arch, a
 // version control system. Please do not modify past this point.
 //

Index: WaveClip.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/WaveClip.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- WaveClip.h  29 Jan 2007 00:48:25 -0000      1.18
+++ WaveClip.h  26 Mar 2007 12:51:42 -0000      1.19
@@ -50,6 +50,7 @@
 };
 
 WX_DECLARE_LIST(WaveClip, WaveClipList);
+WX_DEFINE_ARRAY_PTR(WaveClip*, WaveClipArray);
 
 class WaveClip: public XMLTagHandler
 {


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to