Fix broken waveforms

This commit is contained in:
Mathias Buhr 2017-04-23 21:35:23 +02:00 committed by Harry van Haaren
parent d3de3f0a0a
commit 40d23e1b0d

View file

@ -45,7 +45,6 @@ public:
h = _h; h = _h;
highlight = false; highlight = false;
newWaveform = false;
waveformCr = 0; waveformCr = 0;
waveformSurf = 0; waveformSurf = 0;
@ -66,12 +65,11 @@ public:
bool highlight; bool highlight;
int x, y, w, h; int x, y, w, h;
cairo_t* waveformCr; cairo_t* waveformCr = nullptr;
cairo_surface_t* waveformSurf; cairo_surface_t* waveformSurf = nullptr;
bool newWaveform; bool newWaveform = false;
long dataSize;
std::vector<float> data; std::vector<float> data;
void setData( const std::vector<float>& newdata ) void setData( const std::vector<float>& newdata )
@ -80,7 +78,6 @@ public:
data = newdata; data = newdata;
newWaveform = true; newWaveform = true;
damage(FL_DAMAGE_ALL); damage(FL_DAMAGE_ALL);
} }
@ -133,7 +130,7 @@ public:
cairo_set_dash ( waveformCr, dashes, 0, 0.0); cairo_set_dash ( waveformCr, dashes, 0, 0.0);
if ( !data.empty() ) { if ( data.empty() ) {
// draw X // draw X
cairo_move_to( cr, 0 , 0 ); cairo_move_to( cr, 0 , 0 );
cairo_line_to( cr, 0 + w, 0 + h ); cairo_line_to( cr, 0 + w, 0 + h );
@ -156,7 +153,7 @@ public:
float currentSample = 0.f; float currentSample = 0.f;
// find how many samples per pixel // find how many samples per pixel
int samplesPerPix = int(dataSize / float(w)); const auto samplesPerPix = int(data.size() / float(w));
//cout << "width = " << w << " sampsPerPx " << samplesPerPix << endl; //cout << "width = " << w << " sampsPerPx " << samplesPerPix << endl;
// loop over each pixel value we need // loop over each pixel value we need
@ -237,12 +234,10 @@ public:
// FIXME: needs to be resampled, not clipped at end // FIXME: needs to be resampled, not clipped at end
// delete old data, and resize it // delete old data, and resize it
data.resize(w); data.resize(w);
newWaveform = true; newWaveform = true;
redraw(); redraw();
} }