changeset 400:f44a89a25c97

Fix waveform display from going over buffer limit.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 19 Oct 2012 15:56:59 +0300
parents 525f7af644c4
children 2fdf440ea66a
files edmain.cpp edmain.h edwaveform.cpp edwaveform.h
diffstat 4 files changed, 26 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/edmain.cpp	Fri Oct 19 10:04:57 2012 +0300
+++ b/edmain.cpp	Fri Oct 19 15:56:59 2012 +0300
@@ -250,19 +250,12 @@
 }
 
 
-// Return audio track duration in milliseconds
-int DemoEditor::getAudioTrackDuration()
+int DemoEditor::getTimelineDuration()
 {
     return timelineAudioTrack->getDuration();
 }
 
 
-int DemoEditor::getTimelineDuration()
-{
-    return getAudioTrackDuration();
-}
-
-
 void DemoEditor::updateTimelineView()
 {
     demoView->setEngineData(&engine);    
@@ -283,7 +276,7 @@
     timelineView->setOffset(currViewOffset);
     timelineView->setScale(currViewScale);
 
-    timelineScrollBar->setRange(0, getTimelineDuration() - timelineAudioTrack->getScaledWidth());
+    timelineScrollBar->setRange(0, getTimelineDuration());
     timelineScrollBar->setValue(currViewOffset);
 }
 
@@ -403,6 +396,10 @@
         delete currTimeline;
         currTimeline = tmp;
 
+        timelineView->setTimeline(currTimeline);
+        updateTimelineView();
+        updateMenuStates();
+
         update();
         historyReset();
         changed = false;
--- a/edmain.h	Fri Oct 19 10:04:57 2012 +0300
+++ b/edmain.h	Fri Oct 19 15:56:59 2012 +0300
@@ -100,8 +100,6 @@
     int reopenResources();
     int loadResources();
     bool initializeVideo();
-
-    int getAudioTrackDuration();
     int getTimelineDuration();    
 
     void createNewFile();
--- a/edwaveform.cpp	Fri Oct 19 10:04:57 2012 +0300
+++ b/edwaveform.cpp	Fri Oct 19 15:56:59 2012 +0300
@@ -13,6 +13,7 @@
     scale     = 1.0f;
     time      = offs = 0;
     duration  = 0;
+    sduration = 0;
 
     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
 }
@@ -28,9 +29,18 @@
 
     int bps = getBps();
     if (bps != 0)
-        duration = ((float) (size / bps) / (float) freq) * 1000.0f;
+    {
+        // Duration in milliseconds
+        duration  = ((float) (size / bps) / (float) freq) * 1000.0f;
+        
+        // Duration in samples
+        sduration = msize / bps;
+    }
     else
-        duration = 0;
+    {
+        duration  = 0;
+        sduration = 0;
+    }
 
     update();
 }
@@ -123,7 +133,7 @@
 void QWaveTrackDisplay::paintEvent(QPaintEvent *)
 {
     QColor waveColor(0, 150, 0);
-    QColor waveCenterLine(0, 0, 0);
+    QColor waveCenterLine(100, 100, 100);
     QColor markerColor(255,255,255);
     QColor bgColor(0, 0, 0);//255, 255, 255);
 
@@ -170,7 +180,9 @@
             qint16 *buf = (qint16 *) data;
             for (int xc = 0; xc < width(); xc++)
             {
-                int value = buf[(int) (((offs + xc) * mscale)) * channels] + voffs;
+                int moffs = (int) (((offs + xc) * mscale));
+                if (moffs >= sduration) break;
+                int value = buf[moffs * channels] + voffs;
                 painter.drawLine(prevX, prevY, xc, value);
                 prevY = value;
                 prevX = xc;
@@ -182,7 +194,9 @@
             qint8 *buf = (qint8 *) data;
             for (int xc = 0; xc < width(); xc++)
             {
-                int value = buf[((int) ((offs + xc) * mscale)) * channels] + voffs;
+                int moffs = (int) (((offs + xc) * mscale));
+                if (moffs >= sduration) break;
+                int value = buf[moffs * channels] + voffs;
                 painter.drawLine(prevX, prevY, xc, value);
                 prevY = value;
                 prevX = xc;
--- a/edwaveform.h	Fri Oct 19 10:04:57 2012 +0300
+++ b/edwaveform.h	Fri Oct 19 15:56:59 2012 +0300
@@ -55,7 +55,7 @@
     float scale;
     float time, offs, duration; // in milliseconds
 
-    int size, channels, format, freq;
+    int size, channels, format, freq, sduration;
     void *data;
 };