From 239e4fb4bdc69d9a795d584cbf89c3e6efb1b26d Mon Sep 17 00:00:00 2001 From: Paul Giblock Date: Sun, 8 Jun 2008 12:59:42 +0000 Subject: [PATCH] Improve graph and bitinvader git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1105 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 7 ++- include/graph.h | 21 ++++++++- plugins/bit_invader/bit_invader.cpp | 3 +- src/gui/widgets/graph.cpp | 71 +++++++++++++++++++++-------- 4 files changed, 81 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4bbdb2389..2bb64be32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,9 @@ 2008-06-08 Paul Giblock + * src/gui/widgets/graph.h: * src/gui/widgets/graph.cpp: - Fix graph widget + - Fix graph widget "scrolling" + - Add styles so it can be drawn un-interpolated * include/mv_base.h: * src/core/mv_base.cpp: @@ -34,6 +36,9 @@ * src/gui/controller_connection_dialog.cpp: improve interface slightly + * plugins/bit_invader/bit_invader.cpp: + change graph style mode when toggling interpolation + 2008-06-08 Tobias Doerffel * plugins/ladspa_effect/tap/tap_deesser.c: diff --git a/include/graph.h b/include/graph.h index 8f0544a03..aa8cd6369 100644 --- a/include/graph.h +++ b/include/graph.h @@ -41,7 +41,14 @@ class EXPORT graph : public QWidget, public modelView { Q_OBJECT public: - graph( QWidget * _parent ); + enum graphStyle + { + NearestStyle, + LinearStyle, + NumGraphStyles + }; + + graph( QWidget * _parent, graphStyle _style = graph::LinearStyle ); virtual ~graph(); void setForeground( const QPixmap & _pixmap ); @@ -51,6 +58,17 @@ public: return castModel(); } + inline graphStyle getGraphStyle( void ) + { + return m_graphStyle; + } + + inline void setGraphStyle( graphStyle _s ) + { + m_graphStyle = _s; + update(); + } + protected: virtual void paintEvent( QPaintEvent * _pe ); @@ -73,6 +91,7 @@ private: QPixmap m_foreground; graphModel * m_graphModel; + graphStyle m_graphStyle; bool m_mouseDown; int m_lastCursorX; diff --git a/plugins/bit_invader/bit_invader.cpp b/plugins/bit_invader/bit_invader.cpp index 1a8c1dce5..609948f27 100644 --- a/plugins/bit_invader/bit_invader.cpp +++ b/plugins/bit_invader/bit_invader.cpp @@ -330,7 +330,7 @@ bitInvaderView::bitInvaderView( instrument * _instrument, m_sampleLengthKnob->move( 10, 120 ); m_sampleLengthKnob->setHintText( tr( "Sample Length" ) + " ", "" ); - m_graph = new graph( this ); + m_graph = new graph( this, graph::NearestStyle ); m_graph->move(53,118); // 55,120 - 2px border m_graph->setAutoFillBackground( TRUE ); @@ -536,6 +536,7 @@ void bitInvaderView::smoothClicked( void ) void bitInvaderView::interpolationToggled( bool value ) { + m_graph->setGraphStyle( value ? graph::LinearStyle : graph::NearestStyle); engine::getSong()->setModified(); } diff --git a/src/gui/widgets/graph.cpp b/src/gui/widgets/graph.cpp index 6adba3d77..ddfa97fdf 100644 --- a/src/gui/widgets/graph.cpp +++ b/src/gui/widgets/graph.cpp @@ -39,10 +39,11 @@ using namespace std; -graph::graph( QWidget * _parent ) : +graph::graph( QWidget * _parent, graphStyle _style ) : QWidget( _parent ), /* TODO: size, background? */ - modelView( new graphModel( -1.0, 1.0, 128, NULL, NULL, TRUE ) ) + modelView( new graphModel( -1.0, 1.0, 128, NULL, NULL, TRUE ) ), + m_graphStyle( _style ) { m_mouseDown = false; @@ -227,30 +228,64 @@ void graph::paintEvent( QPaintEvent * ) // Max index, more useful below length--; - p.setRenderHints( QPainter::Antialiasing, TRUE ); - for( int i=0; i < length; i++ ) + + switch( m_graphStyle ) { - // Needs to be rewritten - p.drawLine(2+static_cast(i*xscale), - 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ), - 2+static_cast((i+1)*xscale), - 2+static_cast( ( (*samps)[i+1] - maxVal ) * yscale ) - ); + case graph::LinearStyle: + p.setRenderHints( QPainter::Antialiasing, TRUE ); + + for( int i=0; i < length; i++ ) + { + // Needs to be rewritten + p.drawLine(2+static_cast(i*xscale), + 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ), + 2+static_cast((i+1)*xscale), + 2+static_cast( ( (*samps)[i+1] - maxVal ) * yscale ) + ); + } + + // Draw last segment flat + p.drawLine(2+static_cast(length*xscale), + 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ), + width()-2, + 2+static_cast( ( (*samps)[0] - maxVal ) * yscale ) ); + + p.setRenderHints( QPainter::Antialiasing, FALSE ); + break; + + + case graph::NearestStyle: + printf("GAY MODE\n"); + for( int i=0; i < length; i++ ) + { + p.drawLine(2+static_cast(i*xscale), + 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ), + 2+static_cast((i+1)*xscale), + 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ) + ); + p.drawLine(2+static_cast((i+1)*xscale), + 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ), + 2+static_cast((i+1)*xscale), + 2+static_cast( ( (*samps)[i+1] - maxVal ) * yscale ) + ); + } + + p.drawLine(2+static_cast(length*xscale), + 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ), + width()-2, + 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ) ); + break; + + default: + break; } - // Draw last segment flat - p.drawLine(2+static_cast(length*xscale), - 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ), - width()-2, - 2+static_cast( ( (*samps)[0] - maxVal ) * yscale ) ); - - p.setRenderHints( QPainter::Antialiasing, FALSE ); // draw Pointer if( m_mouseDown ) { QPoint cursor = mapFromGlobal( QCursor::pos() ); - p.setPen( QColor( 0xAA, 0xFF, 0x00 ) ); + p.setPen( QColor( 0xAA, 0xFF, 0x00, 0x70 ) ); p.drawLine( 2, cursor.y(), width()-2, cursor.y() ); p.drawLine( cursor.x(), 2, cursor.x(), height()-2 ); }