diff --git a/include/Graph.h b/include/Graph.h index 38e92a4b4..18a02df6e 100644 --- a/include/Graph.h +++ b/include/Graph.h @@ -165,6 +165,7 @@ public slots: void normalize(); void invert(); void shiftPhase( int _deg ); + void clearInvisible(); signals: void lengthChanged(); diff --git a/plugins/bit_invader/bit_invader.cpp b/plugins/bit_invader/bit_invader.cpp index 983df5ec2..4e7945a40 100644 --- a/plugins/bit_invader/bit_invader.cpp +++ b/plugins/bit_invader/bit_invader.cpp @@ -472,6 +472,7 @@ void bitInvaderView::modelChanged() void bitInvaderView::sinWaveClicked() { + m_graph->model()->clearInvisible(); m_graph->model()->setWaveToSine(); Engine::getSong()->setModified(); } @@ -481,6 +482,7 @@ void bitInvaderView::sinWaveClicked() void bitInvaderView::triangleWaveClicked() { + m_graph->model()->clearInvisible(); m_graph->model()->setWaveToTriangle(); Engine::getSong()->setModified(); } @@ -490,6 +492,7 @@ void bitInvaderView::triangleWaveClicked() void bitInvaderView::sawWaveClicked() { + m_graph->model()->clearInvisible(); m_graph->model()->setWaveToSaw(); Engine::getSong()->setModified(); } @@ -499,6 +502,7 @@ void bitInvaderView::sawWaveClicked() void bitInvaderView::sqrWaveClicked() { + m_graph->model()->clearInvisible(); m_graph->model()->setWaveToSquare(); Engine::getSong()->setModified(); } @@ -508,6 +512,7 @@ void bitInvaderView::sqrWaveClicked() void bitInvaderView::noiseWaveClicked() { + m_graph->model()->clearInvisible(); m_graph->model()->setWaveToNoise(); Engine::getSong()->setModified(); } @@ -518,35 +523,12 @@ void bitInvaderView::noiseWaveClicked() void bitInvaderView::usrWaveClicked() { QString fileName = m_graph->model()->setWaveToUser(); - ToolTip::add( m_usrWaveBtn, fileName ); - Engine::getSong()->setModified(); - /* - m_graph->model()->setWaveToNoise(); - Engine::getSong()->setModified(); - // zero sample_shape - for (int i = 0; i < sample_length; i++) + if (!fileName.isEmpty()) { - sample_shape[i] = 0; + ToolTip::add(m_usrWaveBtn, fileName); + m_graph->model()->clearInvisible(); + Engine::getSong()->setModified(); } - - // load user shape - sampleBuffer buffer; - QString af = buffer.openAudioFile(); - if ( af != "" ) - { - buffer.setAudioFile( af ); - - // copy buffer data - sample_length = min( sample_length, static_cast( - buffer.frames() ) ); - for ( int i = 0; i < sample_length; i++ ) - { - sample_shape[i] = (float)*buffer.data()[i]; - } - } - - sampleChanged(); - */ } diff --git a/src/gui/widgets/Graph.cpp b/src/gui/widgets/Graph.cpp index 44c37165e..458160c41 100644 --- a/src/gui/widgets/Graph.cpp +++ b/src/gui/widgets/Graph.cpp @@ -692,7 +692,15 @@ void graphModel::shiftPhase( int _deg ) emit samplesChanged( 0, length()-1 ); } - +// Clear any part of the graph that isn't displayed +void graphModel::clearInvisible() +{ + const int graph_length = length(); + const int full_graph_length = m_samples.size(); + for( int i = graph_length; i < full_graph_length; i++ ) + m_samples[i] = 0; + emit samplesChanged( graph_length, full_graph_length - 1 ); +} void graphModel::drawSampleAt( int x, float val ) {