diff --git a/ChangeLog b/ChangeLog index da0e260a9..4a01b2774 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-02-06 Andreas Brandmaier + + * plugins/bitinvader/bitinvader.cpp + * plugins/bitinvader/bitinvader.h + * plugins/bitinvader/graph.cpp + * plugins/bitinvader/graph.h + - code cleanup + - added drag&drop support to wavegraph + - added new BitInvader presets and improved old ones + + 2006-02-05 Tobias Doerffel * include/basic_filters.h: diff --git a/plugins/bit_invader/bit_invader.cpp b/plugins/bit_invader/bit_invader.cpp index b0fdb56d9..d9b3c0646 100644 --- a/plugins/bit_invader/bit_invader.cpp +++ b/plugins/bit_invader/bit_invader.cpp @@ -113,11 +113,7 @@ bSynth::bSynth(float* shape, int length, float _pitch, bool _interpolation, floa sample_step = static_cast( sample_length / ((float)mixer::inst()->sampleRate() / _pitch) ); -/* cout << "Sample length: " << sample_length << endl << - "Sample rate : " << mixer::inst()->sampleRate() << endl << - "Frequency : " << _pitch << endl << - "Sample step : " << sample_step << endl; -*/ + } @@ -194,13 +190,13 @@ bitInvader::bitInvader( channelTrack * _channel_track ) : } - m_pickKnob = new knob( knobDark_28, this, tr( "Samplelength" ) ); - m_pickKnob->setRange( 8, 128, 1 ); - m_pickKnob->setValue( 128, TRUE ); - m_pickKnob->move( 10, 120 ); - m_pickKnob->setHintText( tr( "Sample Length" ) + " ", "" ); + m_sampleLengthKnob = new knob( knobDark_28, this, tr( "Samplelength" ) ); + m_sampleLengthKnob->setRange( 8, 128, 1 ); + m_sampleLengthKnob->setValue( 128, TRUE ); + m_sampleLengthKnob->move( 10, 120 ); + m_sampleLengthKnob->setHintText( tr( "Sample Length" ) + " ", "" ); - connect( m_pickKnob, SIGNAL( valueChanged( float ) ), + connect( m_sampleLengthKnob, SIGNAL( valueChanged( float ) ), this, SLOT ( sampleSizeChanged( float ) ) ); @@ -216,13 +212,14 @@ bitInvader::bitInvader( channelTrack * _channel_track ) : connect( m_normalizeToggle, SIGNAL( toggled( bool ) ), this, SLOT ( normalizeToggle( bool ) ) ); - sample_length = 128; - sample_shape = new float[128]; - emit( sinWaveClicked() ); m_graph = new graph( "", this ); m_graph->move(53,118); // 55,120 - 2px border - m_graph->setSamplePointer( sample_shape, sample_length ); + m_graph->setCursor( QCursor( Qt::CrossCursor ) ); + + toolTip::add( m_graph, tr ( "Draw your own waveform here" + "by dragging your mouse onto this graph" + )); QPixmap p = PLUGIN_NAME::getIconPixmap("wavegraph3") ; @@ -334,6 +331,14 @@ bitInvader::bitInvader( channelTrack * _channel_track ) : #else setErasePixmap( PLUGIN_NAME::getIconPixmap( "artwork" ) ); #endif + + + sample_length = 128; + sample_shape = new float[128]; + m_graph->setSamplePointer( sample_shape, sample_length ); + emit( sinWaveClicked() ); + + } @@ -377,7 +382,7 @@ void bitInvader::sinWaveClicked( void ) void bitInvader::triangleWaveClicked( void ) { // generate a Triangle wave using static oscillator-method - for (int i=0; i < sample_length; i++) + for (int i=0; i < sample_length; i++) { sample_shape[i] = oscillator::triangleSample( i/static_cast(sample_length) ); } @@ -391,22 +396,22 @@ void bitInvader::sawWaveClicked( void ) { // generate a Saw wave using static oscillator-method for (int i=0; i < sample_length; i++) - { + { sample_shape[i] = oscillator::sawSample( i/static_cast(sample_length) ); - } + } - sampleChanged(); + sampleChanged(); } void bitInvader::sqrWaveClicked( void ) { // generate a Sqr wave using static oscillator-method for (int i=0; i < sample_length; i++) - { + { sample_shape[i] = oscillator::squareSample( i/static_cast(sample_length) ); - } + } - sampleChanged(); + sampleChanged(); } @@ -414,11 +419,11 @@ void bitInvader::noiseWaveClicked( void ) { // generate a Noise wave using static oscillator-method for (int i=0; i < sample_length; i++) - { + { sample_shape[i] = oscillator::noiseSample( i/static_cast(sample_length) ); - } + } - sampleChanged(); + sampleChanged(); } @@ -441,7 +446,6 @@ void bitInvader::usrWaveClicked( void ) sample_length = min( sample_length, static_cast(buffer.frames()) ); for ( int i = 0; i < sample_length; i++ ) { -// sample_shape = (float*)buffer.data(); sample_shape[i] = (float)*buffer.data()[i]; } } @@ -602,7 +606,7 @@ void bitInvader::loadSettings( const QDomElement & _this ) sample_length = _this.attribute( "sampleLength" ).toInt() ; // Load knobs (fires change SIGNAL?) - m_pickKnob->setValue( static_cast(sample_length) ); + m_sampleLengthKnob->setValue( static_cast(sample_length) ); // Load sample shape delete[] sample_shape; @@ -693,10 +697,7 @@ void bitInvader::playNote( notePlayHandle * _n ) } _n->m_pluginData = new bSynth( sample_shape, sample_length,freq - , interpolation, factor - //, m_pickKnob->value() - //m_pickupKnob->value() - ); + , interpolation, factor ); } const Uint32 frames = mixer::inst()->framesPerAudioBuffer(); diff --git a/plugins/bit_invader/bit_invader.h b/plugins/bit_invader/bit_invader.h index 0c1543d3d..a79d8ee80 100644 --- a/plugins/bit_invader/bit_invader.h +++ b/plugins/bit_invader/bit_invader.h @@ -108,8 +108,7 @@ protected: */ private: - knob * m_pickKnob; - knob * m_pickupKnob; + knob * m_sampleLengthKnob; pixmapButton * sinWaveBtn; pixmapButton * triangleWaveBtn; diff --git a/plugins/bit_invader/graph.cpp b/plugins/bit_invader/graph.cpp index 20883bf88..4d195a35f 100644 --- a/plugins/bit_invader/graph.cpp +++ b/plugins/bit_invader/graph.cpp @@ -41,7 +41,8 @@ #include "graph.h" - +#include "string_pair_drag.h" +#include "sample_buffer.h" #include #include @@ -53,11 +54,12 @@ graph::graph( const QString & _text, QWidget * _parent) : QWidget( _parent ) { - m_background = NULL; +// m_background = 0; TODO m_mouseDown = false; setFixedSize( 132, 104 ); + setAcceptDrops( TRUE ); #ifndef QT4 setBackgroundMode( NoBackground ); @@ -75,8 +77,6 @@ graph::~graph() void graph::setBackground( const QPixmap &_pixmap ) { m_background = _pixmap; -// setErasePixmap ( m_background ); - } void graph::setSamplePointer( float * _pointer, int _length ) @@ -86,11 +86,32 @@ void graph::setSamplePointer( float * _pointer, int _length ) update(); } +void graph::loadSampleFromFile( const QString filename ) +{ + // zero sample_shape + for (int i = 0; i < sampleLength; i++) + { + samplePointer[i] = 0; + } + + // load user shape + sampleBuffer buffer; + buffer.setAudioFile( filename ); + + // copy buffer data + sampleLength = min( sampleLength, static_cast(buffer.frames()) ); + for ( int i = 0; i < sampleLength; i++ ) + { + samplePointer[i] = (float)*buffer.data()[i]; + } + +} + void graph::mouseMoveEvent ( QMouseEvent * _me ) { - // get position - int x = _me->x(); + // get position + int x = _me->x(); int y = _me->y(); @@ -104,10 +125,6 @@ void graph::mouseMoveEvent ( QMouseEvent * _me ) } else { x = m_lastCursorX; } -// QCursor::setPos( 1, 1 ); - - - changeSampleAt( x, y ); @@ -143,15 +160,15 @@ void graph::changeSampleAt(int _x, int _y) _x -= 2; _y -= 2; - // boundary check - if (_x < 0) { return; } - if (_x > sampleLength) { return; } + // boundary check + if (_x < 0) { return; } + if (_x > sampleLength) { return; } if (_y < 0) { return; } if (_y >= 100) { return; } _y = 100 - _y; // change sample shape - samplePointer[_x] = (_y-50.0)/50.0; + samplePointer[_x] = (_y-50.0)/50.0; emit sampleChanged(); @@ -219,5 +236,26 @@ void graph::paintEvent( QPaintEvent * ) } +void graph::dropEvent( QDropEvent * _de ) +{ + QString type = stringPairDrag::decodeKey( _de ); + QString value = stringPairDrag::decodeValue( _de ); + + if( type == "samplefile" ) + { + loadSampleFromFile( value ); + _de->accept(); + } +} + +void graph::dragEnterEvent( QDragEnterEvent * _dee ) +{ + if( stringPairDrag::processDragEnterEvent( _dee, + QString( "samplefile" ) ) == FALSE ) + { + _dee->ignore(); + } +} + #include "graph.moc" diff --git a/plugins/bit_invader/graph.h b/plugins/bit_invader/graph.h index 7e02d79e1..02b6dcfc4 100644 --- a/plugins/bit_invader/graph.h +++ b/plugins/bit_invader/graph.h @@ -49,20 +49,12 @@ class graph : public QWidget { Q_OBJECT public: -/* enum ledColors - { - YELLOW, GREEN, TOTAL_COLORS - } ; -*/ - graph( const QString & _txt, QWidget * _parent//, - //ledColors _color = YELLOW - ); + graph( const QString & _txt, QWidget * _parent ); virtual ~graph(); - void setSamplePointer( float * pointer, int length ); - void setBackground ( const QPixmap & _pixmap ); + void graph::loadSampleFromFile( QString filename ); signals: void sampleSizeChanged( float f ); @@ -70,6 +62,8 @@ signals: protected: virtual void paintEvent( QPaintEvent * _pe ); + virtual void dropEvent( QDropEvent * _de ); + virtual void dragEnterEvent( QDragEnterEvent * _dee ); virtual void mousePressEvent( QMouseEvent * _me ); virtual void mouseMoveEvent( QMouseEvent * _me ); virtual void mouseReleaseEvent( QMouseEvent * _me ); @@ -86,9 +80,6 @@ private: bool m_mouseDown; int m_lastCursorX; - -//signals: -// void toggled( bool ); } ;