diff --git a/include/graph.h b/include/graph.h index 20437996e..3e9a2d2d3 100644 --- a/include/graph.h +++ b/include/graph.h @@ -49,11 +49,15 @@ public: NumGraphStyles }; - graph( QWidget * _parent, graphStyle _style = graph::LinearStyle ); + graph( QWidget * _parent, graphStyle _style = graph::LinearStyle, + int _width = 132, + int _height = 104 + ); virtual ~graph(); void setForeground( const QPixmap & _pixmap ); + void setGraphColor( const QColor ); inline graphModel * model() @@ -65,6 +69,7 @@ public: { return m_graphStyle; } + inline void setGraphStyle( graphStyle _s ) { @@ -88,7 +93,8 @@ protected slots: private: virtual void modelChanged(); - void changeSampleAt(int _x, int _y); + void changeSampleAt( int _x, int _y ); + void drawLineAt( int _x, int _y, int _lastx ); QPixmap m_foreground; diff --git a/plugins/waveshaper/wavegraph.png b/plugins/waveshaper/wavegraph.png new file mode 100644 index 000000000..18d99a81e Binary files /dev/null and b/plugins/waveshaper/wavegraph.png differ diff --git a/plugins/waveshaper/waveshaper.cpp b/plugins/waveshaper/waveshaper.cpp index 16e3ced56..a7c1f037d 100644 --- a/plugins/waveshaper/waveshaper.cpp +++ b/plugins/waveshaper/waveshaper.cpp @@ -96,7 +96,7 @@ bool waveShaperEffect::processAudioBuffer( sampleFrame * _buf, for ( i=0; i <= 1; ++i ) { - lookup = fabsf( s[i] ) * 100.0f; + lookup = fabsf( s[i] ) * 200.0f; posneg = s[i] < 0 ? -1.0f : 1.0f; if ( lookup < 1 ) @@ -105,7 +105,7 @@ bool waveShaperEffect::processAudioBuffer( sampleFrame * _buf, s[i] = frac * m_wsControls.m_wavegraphModel.samples()[0] * posneg; } else - if ( lookup < 100 ) + if ( lookup < 200 ) { frac = lookup - truncf(lookup); s[i] = @@ -115,7 +115,7 @@ bool waveShaperEffect::processAudioBuffer( sampleFrame * _buf, } else { - s[i] *= m_wsControls.m_wavegraphModel.samples()[99]; + s[i] *= m_wsControls.m_wavegraphModel.samples()[199]; } } diff --git a/plugins/waveshaper/waveshaper_control_dialog.cpp b/plugins/waveshaper/waveshaper_control_dialog.cpp index b00dc3cd8..c699b66ca 100644 --- a/plugins/waveshaper/waveshaper_control_dialog.cpp +++ b/plugins/waveshaper/waveshaper_control_dialog.cpp @@ -42,17 +42,32 @@ waveShaperControlDialog::waveShaperControlDialog( pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) ); setPalette( pal ); - setFixedSize( 120, 200 ); + setFixedSize( 222, 300 ); QVBoxLayout * tl = new QVBoxLayout( this ); tl->addSpacing( 30 ); + tl->addStrut( 204 ); - graph * waveGraph = new graph( this, graph::LinearStyle ); + graph * waveGraph = new graph( this, graph::NearestStyle, 204, 204 ); waveGraph -> setModel( &_controls -> m_wavegraphModel ); + + waveGraph -> setAutoFillBackground( true ); - tl -> addWidget( waveGraph ); + pal = QPalette(); + pal.setBrush( backgroundRole(), + PLUGIN_NAME::getIconPixmap("wavegraph") ); + waveGraph->setPalette( pal ); + waveGraph->setGraphColor( QColor( 170, 255, 255 ) ); +// waveGraph -> setMinimumSize( 204, 204); +// waveGraph -> resize( 204, 204); + + waveGraph -> setMaximumSize( 204, 204 ); + + tl -> setSizeConstraint( QLayout::SetNoConstraint ); + tl -> addWidget( waveGraph ); + QHBoxLayout * l = new QHBoxLayout; knob * inputKnob = new knob( knobBright_26, this); diff --git a/plugins/waveshaper/waveshaper_controls.cpp b/plugins/waveshaper/waveshaper_controls.cpp index 6455c9653..40c60a895 100644 --- a/plugins/waveshaper/waveshaper_controls.cpp +++ b/plugins/waveshaper/waveshaper_controls.cpp @@ -37,7 +37,7 @@ waveShaperControls::waveShaperControls( waveShaperEffect * _eff ) : m_effect( _eff ), m_inputModel( 1.0f, 0.0f, 2.0f, 0.01f, this, tr( "Input gain" ) ), m_outputModel( 1.0f, 0.0f, 2.0f, 0.01f, this, tr( "Output gain" ) ), - m_wavegraphModel( 0.0f, 1.0f, 100, this ) + m_wavegraphModel( 0.0f, 1.0f, 200, this ) { connect( &m_inputModel, SIGNAL( dataChanged() ), this, SLOT( changeInput() ) ); @@ -115,13 +115,13 @@ void waveShaperControls::saveSettings( QDomDocument & _doc, void waveShaperControls::setDefaultShape() { - float shp [100] = { }; - for ( int i = 0; i<100; i++) + float shp [200] = { }; + for ( int i = 0; i<200; i++) { - shp[i] = ((float)i + 1.0f) / 100.0f; + shp[i] = ((float)i + 1.0f) / 200.0f; } - m_wavegraphModel.setLength( 100 ); + m_wavegraphModel.setLength( 200 ); m_wavegraphModel.setSamples( (float*)&shp ); } diff --git a/src/gui/widgets/graph.cpp b/src/gui/widgets/graph.cpp index dc0246eb0..9c3877467 100644 --- a/src/gui/widgets/graph.cpp +++ b/src/gui/widgets/graph.cpp @@ -34,7 +34,8 @@ #include "engine.h" -graph::graph( QWidget * _parent, graphStyle _style ) : +graph::graph( QWidget * _parent, graphStyle _style, int _width, + int _height ) : QWidget( _parent ), /* TODO: size, background? */ ModelView( new graphModel( -1.0, 1.0, 128, NULL, true ), this ), @@ -43,7 +44,7 @@ graph::graph( QWidget * _parent, graphStyle _style ) : m_mouseDown = false; m_graphColor = QColor( 0xFF, 0xAA, 0x00 ); - resize( 132, 104 ); + resize( _width, _height ); setAcceptDrops( true ); setCursor( Qt::CrossCursor ); @@ -76,7 +77,7 @@ void graph::setGraphColor( QColor _graphcol ) /* void graph::loadSampleFromFile( const QString & _filename ) { - + int i; // zero sample_shape @@ -84,7 +85,7 @@ void graph::loadSampleFromFile( const QString & _filename ) { samplePointer[i] = 0; } - + // load user shape sampleBuffer buffer( _filename ); @@ -154,25 +155,73 @@ void graph::mousePressEvent( QMouseEvent * _me ) { if( _me->button() == Qt::LeftButton ) { - // toggle mouse state - m_mouseDown = true; + if ( !( _me->modifiers() & Qt::ShiftModifier ) ) + { + // toggle mouse state + m_mouseDown = true; - // get position - int x = _me->x(); - int y = _me->y(); + // get position + int x = _me->x(); + int y = _me->y(); - changeSampleAt( x, y ); + changeSampleAt( x, y ); + + // toggle mouse state + m_mouseDown = true; + setCursor( Qt::BlankCursor ); + m_lastCursorX = x; + } + else + { + //when shift-clicking, draw a line from last position to current + //position + int x = _me->x(); + int y = _me->y(); + + drawLineAt( x, y, m_lastCursorX ); + + setCursor( Qt::BlankCursor ); + m_lastCursorX = x; + } - // toggle mouse state - m_mouseDown = true; - setCursor( Qt::BlankCursor ); - m_lastCursorX = x; } } +void graph::drawLineAt( int _x, int _y, int _lastx ) +{ + float minVal = model()->minValue(); + float maxVal = model()->maxValue(); + if ( width() <= 4 ) + { + return; + } + float xscale = static_cast( model()->length() ) / + ( width()-4 ); -void graph::changeSampleAt(int _x, int _y) + //consider border + _x -= 2; + _y -= 2; + _lastx -= 2; + + float range = minVal - maxVal; + float val = ( _y*range/( height()-4 ) ) + maxVal; + float lastval = model() -> m_samples[ (int)( _lastx * xscale ) ]; + + // calculate line drawing variables + int linelen = qAbs( _x - _lastx ) + 1; + int xstep = _x > _lastx ? -1 : 1; + float ystep = ( lastval - val ) / linelen; + + // draw a line + for ( int i = 0; i < linelen; i++ ) + { + int x = (_x + (i * xstep)); // get x value + model()->setSampleAt( (int)( x * xscale ), val + (i * ystep)); + } +} + +void graph::changeSampleAt( int _x, int _y ) { float minVal = model()->minValue(); float maxVal = model()->maxValue(); @@ -208,7 +257,7 @@ void graph::mouseReleaseEvent( QMouseEvent * _me ) setCursor( Qt::CrossCursor ); update(); } -} +} @@ -237,15 +286,15 @@ void graph::paintEvent( QPaintEvent * ) for( int i=0; i < length; i++ ) { // Needs to be rewritten - p.drawLine(2+static_cast(i*xscale), + p.drawLine(2+static_cast(i*xscale), 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ), - 2+static_cast((i+1)*xscale), + 2+static_cast((i+1)*xscale), 2+static_cast( ( (*samps)[i+1] - maxVal ) * yscale ) ); } // Draw last segment wrapped around - p.drawLine(2+static_cast(length*xscale), + p.drawLine(2+static_cast(length*xscale), 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ), width()-2, 2+static_cast( ( (*samps)[0] - maxVal ) * yscale ) ); @@ -257,19 +306,19 @@ void graph::paintEvent( QPaintEvent * ) case graph::NearestStyle: for( int i=0; i < length; i++ ) { - p.drawLine(2+static_cast(i*xscale), + p.drawLine(2+static_cast(i*xscale), 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ), - 2+static_cast((i+1)*xscale), + 2+static_cast((i+1)*xscale), 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ) ); - p.drawLine(2+static_cast((i+1)*xscale), + p.drawLine(2+static_cast((i+1)*xscale), 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ), - 2+static_cast((i+1)*xscale), + 2+static_cast((i+1)*xscale), 2+static_cast( ( (*samps)[i+1] - maxVal ) * yscale ) ); } - p.drawLine(2+static_cast(length*xscale), + p.drawLine(2+static_cast(length*xscale), 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ), width()-2, 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ) ); @@ -281,7 +330,7 @@ void graph::paintEvent( QPaintEvent * ) // draw Pointer - if( m_mouseDown ) + if( m_mouseDown ) { QPoint cursor = mapFromGlobal( QCursor::pos() ); p.setPen( QColor( 0xAA, 0xFF, 0x00, 0x70 ) ); @@ -369,7 +418,7 @@ void graphModel::setRange( float _min, float _max ) if( !m_samples.isEmpty() ) { - // Trim existing values + // Trim existing values for( int i=0; i < length(); i++ ) { m_samples[i] = fmaxf( _min, fminf( m_samples[i], _max ) ); @@ -512,7 +561,7 @@ void graphModel::smooth() m_samples[0] = ( temp[0] + temp[length()-1] ) * 0.5f; for ( int i=1; i < length(); i++ ) { - m_samples[i] = ( temp[i-1] + temp[i] ) * 0.5f; + m_samples[i] = ( temp[i-1] + temp[i] ) * 0.5f; } emit samplesChanged(0, length()-1); @@ -539,7 +588,7 @@ void graphModel::normalize() if( max != 1.0f ) { emit samplesChanged( 0, length()-1 ); } -} +}