]> Shamusworld >> Repos - wozmaker/blobdiff - src/waveformwidget.cpp
Collapse redundant code down to a callable function in waveformwidget.
[wozmaker] / src / waveformwidget.cpp
index 5368a8bcc5d3bf2d110b4e17f96911ad3c2f70d3..c00bc778371be1cc34e11569e3123402878c10f9 100644 (file)
@@ -279,17 +279,7 @@ void WaveformWidget::paintEvent(QPaintEvent * event)
                {
                        for(uint32_t i=0; i<trackBytes; i++)
                        {
-#if 0
-                               uint32_t timeToNext = Global::stream[j]->data[offset + i];
-
-                               while (Global::stream[j]->data[offset + i] == 0xFF)
-                               {
-                                       i++;
-                                       timeToNext += Global::stream[j]->data[offset + i];
-                               }
-#else
                                uint32_t timeToNext = Global::wave[j][offset + i];
-#endif
 
 //                             if (i > 0)
        //                              x += timeToNext / 2;
@@ -299,16 +289,11 @@ void WaveformWidget::paintEvent(QPaintEvent * event)
                                {
                                        if (x >= drawXPos)
                                        {
-                                               painter.setPen(bluePen);
-
-                                               if (x >= ((estSplice / 2) /* * ratio[wfNum]*/))
-                                                       painter.setPen(Qt::magenta);
+                                               if (x < (estSplice / 2))
+                                                       DrawPulse(&painter, &bluePen, lastx, x, y);
+                                               else
+                                                       DrawPulse(&painter, Qt::magenta, lastx, x, y);
 
-                                               painter.drawLine(lastx, y, x, y);
-                                               painter.drawLine(x, y, x + 4.0, y);
-                                               painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0);
-                                               painter.drawLine(x + 4.0, y - 17.0, x + 8.0, y - 17.0);
-                                               painter.drawLine(x + 8.0, y - 17.0, x + 8.0, y);
                                                lastx = x + 8.0;
                                        }
 
@@ -402,12 +387,7 @@ x positions are 16 pix apart, ideally.  So to get the # of bits, we need to divi
                        {
                                if (Global::stream[j]->data[i / 8] & Global::bit[i % 8])
                                {
-                                       painter.setPen(Qt::cyan);
-                                       painter.drawLine(lastx, y, x, y);
-                                       painter.drawLine(x, y, x + 4, y);
-                                       painter.drawLine(x + 4, y, x + 4, y - 17);
-                                       painter.drawLine(x + 4, y - 17, x + 8, y - 17);
-                                       painter.drawLine(x + 8, y - 17, x + 8, y);
+                                       DrawPulse(&painter, Qt::cyan, lastx, x, y);
                                        lastx = x + 8.0;
                                }
 
@@ -430,32 +410,20 @@ x positions are 16 pix apart, ideally.  So to get the # of bits, we need to divi
        uint32_t byte = 1;
        uint32_t bytePos = x;
        uint32_t bitCount = 1;
-       float hgt = 17.0f * 1.0f;
-
-       painter.setPen(greenPen);
-       painter.drawLine(lastx, y, x, y);
-       painter.drawLine(x, y, x + 4.0, y);
-       painter.drawLine(x + 4.0, y, x + 4.0, y - hgt);
-       painter.drawLine(x + 4.0, y - hgt, x + 8.0, y - hgt);
-       painter.drawLine(x + 8.0, y - hgt, x + 8.0, y);
+
+       DrawPulse(&painter, &greenPen, lastx, x, y);
        lastx = x + 8.0;
 
        for(uint32_t i=0; i<Global::swLen; i++)
        {
                uint32_t timeToNext = Global::synthWave[i];
-               hgt = 17.0 * Global::swAmplitude[i];
                x += (double)timeToNext / 2.0;
 
                if ((timeToNext > 0) || (i == 0))
                {
                        if (x >= drawXPos)
                        {
-                               painter.setPen(greenPen);
-                               painter.drawLine(lastx, y, x, y);
-                               painter.drawLine(x, y, x + 4.0, y);
-                               painter.drawLine(x + 4.0, y, x + 4.0, y - hgt);
-                               painter.drawLine(x + 4.0, y - hgt, x + 8.0, y - hgt);
-                               painter.drawLine(x + 8.0, y - hgt, x + 8.0, y);
+                               DrawPulse(&painter, &greenPen, lastx, x, y, Global::swAmplitude[i]);
                                lastx = x + 8.0;
                        }
 
@@ -535,12 +503,7 @@ x positions are 16 pix apart, ideally.  So to get the # of bits, we need to divi
        x = 0;
        lastx = 0;
 
-       painter.setPen(orangePen);
-       painter.drawLine(lastx, y, x, y);
-       painter.drawLine(x, y, x + 4.0, y);
-       painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0f);
-       painter.drawLine(x + 4.0, y - 17.0f, x + 8.0, y - 17.0f);
-       painter.drawLine(x + 8.0, y - 17.0f, x + 8.0, y);
+       DrawPulse(&painter, &orangePen, lastx, x, y);
        lastx = x + 8.0;
 
        for(uint32_t i=0; i<Global::synWaveLen[Global::trackNum]; i++)
@@ -550,12 +513,7 @@ x positions are 16 pix apart, ideally.  So to get the # of bits, we need to divi
 
                if (x >= drawXPos)
                {
-                       painter.setPen(orangePen);
-                       painter.drawLine(lastx, y, x, y);
-                       painter.drawLine(x, y, x + 4.0, y);
-                       painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0f);
-                       painter.drawLine(x + 4.0, y - 17.0f, x + 8.0, y - 17.0f);
-                       painter.drawLine(x + 8.0, y - 17.0f, x + 8.0, y);
+                       DrawPulse(&painter, &orangePen, lastx, x, y);
                        lastx = x + 8.0;
                }
 
@@ -576,12 +534,7 @@ x positions are 16 pix apart, ideally.  So to get the # of bits, we need to divi
        x = 0;
        lastx = 0;
 
-       painter.setPen(orangePen);
-       painter.drawLine(lastx, y, x, y);
-       painter.drawLine(x, y, x + 4.0, y);
-       painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0f);
-       painter.drawLine(x + 4.0, y - 17.0f, x + 8.0, y - 17.0f);
-       painter.drawLine(x + 8.0, y - 17.0f, x + 8.0, y);
+       DrawPulse(&painter, &orangePen, lastx, x, y);
        lastx = x + 8.0;
 
        for(uint32_t i=Global::waveSync; i<Global::synWaveLen[Global::trackNum]; i++)
@@ -591,12 +544,7 @@ x positions are 16 pix apart, ideally.  So to get the # of bits, we need to divi
 
                if (x >= drawXPos)
                {
-                       painter.setPen(orangePen);
-                       painter.drawLine(lastx, y, x, y);
-                       painter.drawLine(x, y, x + 4.0, y);
-                       painter.drawLine(x + 4.0, y, x + 4.0, y - 17.0f);
-                       painter.drawLine(x + 4.0, y - 17.0f, x + 8.0, y - 17.0f);
-                       painter.drawLine(x + 8.0, y - 17.0f, x + 8.0, y);
+                       DrawPulse(&painter, &orangePen, lastx, x, y);
                        lastx = x + 8.0;
                }
 
@@ -615,6 +563,25 @@ x positions are 16 pix apart, ideally.  So to get the # of bits, we need to divi
 }
 
 
+void WaveformWidget::DrawPulse(QPainter * painter, QPen * pen, float lastx, float x, float y, float height/*= 1.0*/)
+{
+       float yHeight = y - (17.0 * height);
+       painter->setPen(*pen);
+       painter->drawLine(lastx, y, x, y);
+       painter->drawLine(x, y, x + 4.0, y);
+       painter->drawLine(x + 4.0, y, x + 4.0, yHeight);
+       painter->drawLine(x + 4.0, yHeight, x + 8.0, yHeight);
+       painter->drawLine(x + 8.0, yHeight, x + 8.0, y);
+}
+
+
+void WaveformWidget::DrawPulse(QPainter * painter, Qt::GlobalColor color, float lastx, float x, float y, float height/*= 1.0*/)
+{
+       QPen pen(color);
+       DrawPulse(painter, &pen, lastx, x, y, height);
+}
+
+
 void WaveformWidget::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)