From f943df139e52df488eb74c0700d1ad0d7a47d382 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Tue, 30 Jun 2009 01:19:48 +0200 Subject: [PATCH] InstrumentView: added generic DnD support, renamed/splitted files Added generic drag'n'drop support for all instrument views. All resources supported by the according instrument now can be dropped onto instrument view without any extra code in actual instrument. Additionally renamed some files and classes related to InstrumentView class to match new style. Signed-off-by: Tobias Doerffel --- .../{dummy_instrument.h => DummyInstrument.h} | 19 ++- .../{instrument_view.h => InstrumentView.h} | 27 ++-- include/instrument_track.h | 2 +- .../audio_file_processor.cpp | 106 ++++------------ .../audio_file_processor.h | 12 +- plugins/bit_invader/bit_invader.cpp | 2 +- plugins/bit_invader/bit_invader.h | 4 +- plugins/kicker/kicker.cpp | 2 +- plugins/kicker/kicker.h | 4 +- plugins/lb302/lb302.cpp | 2 +- plugins/lb302/lb302.h | 4 +- plugins/lb303/lb303.cpp | 2 +- plugins/lb303/lb303.h | 4 +- plugins/organic/organic.cpp | 2 +- plugins/organic/organic.h | 4 +- plugins/papu/papu_instrument.cpp | 2 +- plugins/papu/papu_instrument.h | 4 +- plugins/patman/patman.cpp | 59 ++------- plugins/patman/patman.h | 12 +- plugins/sf2_player/sf2_player.cpp | 2 +- plugins/sf2_player/sf2_player.h | 4 +- plugins/sid/sid_instrument.cpp | 2 +- plugins/sid/sid_instrument.h | 4 +- plugins/stk/mallets/mallets.cpp | 2 +- plugins/stk/mallets/mallets.h | 4 +- .../triple_oscillator/triple_oscillator.cpp | 2 +- plugins/triple_oscillator/triple_oscillator.h | 4 +- plugins/vestige/vestige.cpp | 62 ++-------- plugins/vestige/vestige.h | 14 +-- plugins/vibed/vibed.cpp | 2 +- plugins/vibed/vibed.h | 4 +- plugins/zynaddsubfx/zynaddsubfx.cpp | 55 +-------- plugins/zynaddsubfx/zynaddsubfx.h | 17 +-- src/core/instrument.cpp | 64 +--------- src/gui/InstrumentView.cpp | 116 ++++++++++++++++++ 35 files changed, 251 insertions(+), 380 deletions(-) rename include/{dummy_instrument.h => DummyInstrument.h} (76%) rename include/{instrument_view.h => InstrumentView.h} (61%) create mode 100644 src/gui/InstrumentView.cpp diff --git a/include/dummy_instrument.h b/include/DummyInstrument.h similarity index 76% rename from include/dummy_instrument.h rename to include/DummyInstrument.h index 068467b5b..46c29479d 100644 --- a/include/dummy_instrument.h +++ b/include/DummyInstrument.h @@ -1,8 +1,8 @@ /* - * dummy_instrument.h - instrument used as fallback if an instrument couldn't - * be loaded + * DummyInstrument.h - instrument used as fallback if an instrument couldn't + * be loaded * - * Copyright (c) 2005-2008 Tobias Doerffel + * Copyright (c) 2005-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -23,23 +23,22 @@ * */ - #ifndef _DUMMY_INSTRUMENT_H #define _DUMMY_INSTRUMENT_H #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" -class dummyInstrument : public instrument +class DummyInstrument : public instrument { public: - dummyInstrument( instrumentTrack * _instrument_track ) : + DummyInstrument( instrumentTrack * _instrument_track ) : instrument( _instrument_track, NULL ) { } - virtual ~dummyInstrument() + virtual ~DummyInstrument() { } @@ -57,12 +56,12 @@ public: virtual QString nodeName( void ) const { - return( "dummyinstrument" ); + return "dummyinstrument"; } virtual pluginView * instantiateView( QWidget * _parent ) { - return( new instrumentView( this, _parent ) ); + return new InstrumentView( this, _parent ); } } ; diff --git a/include/instrument_view.h b/include/InstrumentView.h similarity index 61% rename from include/instrument_view.h rename to include/InstrumentView.h index bdf716432..f916adffc 100644 --- a/include/instrument_view.h +++ b/include/InstrumentView.h @@ -1,7 +1,7 @@ /* - * instrument_view.h - definition of instrumentView-class + * InstrumentView.h - definition of InstrumentView class * - * Copyright (c) 2008 Tobias Doerffel + * Copyright (c) 2008-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -32,25 +32,30 @@ class instrumentTrackWindow; -class EXPORT instrumentView : public pluginView +class EXPORT InstrumentView : public pluginView { public: - instrumentView( instrument * _instrument, QWidget * _parent ); - virtual ~instrumentView(); + InstrumentView( instrument * _instrument, QWidget * _parent ); + virtual ~InstrumentView(); - instrument * model( void ) + instrument * model() { - return( castModel() ); + return castModel(); } - const instrument * model( void ) const + const instrument * model() const { - return( castModel() ); + return castModel(); } - virtual void setModel( ::model * _model, bool = FALSE ); + virtual void setModel( ::model * _model, bool = false ); - instrumentTrackWindow * getInstrumentTrackWindow( void ); + instrumentTrackWindow * getInstrumentTrackWindow(); + + +protected: + virtual void dragEnterEvent( QDragEnterEvent * _dee ); + virtual void dropEvent( QDropEvent * _de ); } ; diff --git a/include/instrument_track.h b/include/instrument_track.h index 72694fa98..21841003c 100644 --- a/include/instrument_track.h +++ b/include/instrument_track.h @@ -394,7 +394,7 @@ private: // test-piano at the bottom of every instrument-settings-window PianoView * m_pianoView; - friend class instrumentView; + friend class InstrumentView; } ; diff --git a/plugins/audio_file_processor/audio_file_processor.cpp b/plugins/audio_file_processor/audio_file_processor.cpp index c91e4911a..abdea6a65 100644 --- a/plugins/audio_file_processor/audio_file_processor.cpp +++ b/plugins/audio_file_processor/audio_file_processor.cpp @@ -79,8 +79,8 @@ audioFileProcessor::audioFileProcessor( instrumentTrack * _instrument_track ) : m_ampModel( 100, 0, 500, 1, this, tr( "Amplify" ) ), m_startPointModel( 0, 0, 1, 0.0000001f, this, tr( "Start of sample") ), m_endPointModel( 1, 0, 1, 0.0000001f, this, tr( "End of sample" ) ), - m_reverseModel( FALSE, this, tr( "Reverse sample" ) ), - m_loopModel( FALSE, this, tr( "Loop") ) + m_reverseModel( false, this, tr( "Reverse sample" ) ), + m_loopModel( false, this, tr( "Loop") ) { connect( &m_reverseModel, SIGNAL( dataChanged() ), this, SLOT( reverseModelChanged() ) ); @@ -115,7 +115,7 @@ void audioFileProcessor::playNote( notePlayHandle * _n, if( m_sampleBuffer.play( _working_buffer, (handleState *)_n->m_pluginData, frames, _n->frequency(), - m_loopModel.value() ) == TRUE ) + m_loopModel.value() ) == true ) { applyRelease( _working_buffer, _n ); getInstrumentTrack()->processAudioBuffer( _working_buffer, @@ -158,7 +158,7 @@ void audioFileProcessor::loadSettings( const QDomElement & _this ) { if( _this.attribute( "src" ) != "" ) { - setAudioFile( _this.attribute( "src" ), FALSE ); + setAudioFile( _this.attribute( "src" ), false ); } else if( _this.attribute( "sampledata" ) != "" ) { @@ -186,9 +186,9 @@ void audioFileProcessor::loadResource( const ResourceItem * _resourceItem ) -QString audioFileProcessor::nodeName( void ) const +QString audioFileProcessor::nodeName() const { - return( audiofileprocessor_plugin_descriptor.name ); + return audiofileprocessor_plugin_descriptor.name; } @@ -200,9 +200,9 @@ Uint32 audioFileProcessor::getBeatLen( notePlayHandle * _n ) const engine::getMixer()->processingSampleRate() / engine::getMixer()->baseSampleRate(); - return( static_cast( floorf( ( m_sampleBuffer.endFrame() - + return static_cast( floorf( ( m_sampleBuffer.endFrame() - m_sampleBuffer.startFrame() ) * - freq_factor ) ) ); + freq_factor ) ); } @@ -210,7 +210,7 @@ Uint32 audioFileProcessor::getBeatLen( notePlayHandle * _n ) const pluginView * audioFileProcessor::instantiateView( QWidget * _parent ) { - return( new audioFileProcessorView( this, _parent ) ); + return new AudioFileProcessorView( this, _parent ); } @@ -238,7 +238,7 @@ void audioFileProcessor::setAudioFile( const QString & _audio_file, -void audioFileProcessor::reverseModelChanged( void ) +void audioFileProcessor::reverseModelChanged() { m_sampleBuffer.setReversed( m_reverseModel.value() ); } @@ -246,7 +246,7 @@ void audioFileProcessor::reverseModelChanged( void ) -void audioFileProcessor::ampModelChanged( void ) +void audioFileProcessor::ampModelChanged() { m_sampleBuffer.setAmplification( m_ampModel.value() / 100.0f ); } @@ -254,7 +254,7 @@ void audioFileProcessor::ampModelChanged( void ) -void audioFileProcessor::loopPointChanged( void ) +void audioFileProcessor::loopPointChanged() { const f_cnt_t f1 = static_cast( m_startPointModel.value() * ( m_sampleBuffer.frames()-1 ) ); @@ -284,12 +284,12 @@ public: -QPixmap * audioFileProcessorView::s_artwork = NULL; +QPixmap * AudioFileProcessorView::s_artwork = NULL; -audioFileProcessorView::audioFileProcessorView( instrument * _instrument, +AudioFileProcessorView::AudioFileProcessorView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { if( s_artwork == NULL ) { @@ -316,7 +316,7 @@ audioFileProcessorView::audioFileProcessorView( instrument * _instrument, "sound like the original sample.") ); m_reverseButton = new pixmapButton( this ); - m_reverseButton->setCheckable( TRUE ); + m_reverseButton->setCheckable( true ); m_reverseButton->move( 184, 124 ); m_reverseButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "reverse_on" ) ); @@ -329,7 +329,7 @@ audioFileProcessorView::audioFileProcessorView( instrument * _instrument, "crash." ) ); m_loopButton = new pixmapButton( this ); - m_loopButton->setCheckable( TRUE ); + m_loopButton->setCheckable( true ); m_loopButton->move( 220, 124 ); m_loopButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap( "loop_on" ) ); @@ -345,7 +345,7 @@ audioFileProcessorView::audioFileProcessorView( instrument * _instrument, "samples." ) ); m_ampKnob = new knob( knobStyled, this ); - m_ampKnob->setVolumeKnob( TRUE ); + m_ampKnob->setVolumeKnob( true ); m_ampKnob->move( 17, 108 ); m_ampKnob->setFixedSize( 37, 47 ); m_ampKnob->setHintText( tr( "Amplify:" )+" ", "%" ); @@ -374,75 +374,19 @@ audioFileProcessorView::audioFileProcessorView( instrument * _instrument, "If you enable looping-mode, this is the point where " "AudioFileProcessor returns if a note is longer than " "the sample between the start and end-points." ) ); - - setAcceptDrops( TRUE ); } -audioFileProcessorView::~audioFileProcessorView() +AudioFileProcessorView::~AudioFileProcessorView() { } -void audioFileProcessorView::dragEnterEvent( QDragEnterEvent * _dee ) -{ - if( _dee->mimeData()->hasFormat( stringPairDrag::mimeType() ) ) - { - QString txt = _dee->mimeData()->data( - stringPairDrag::mimeType() ); - if( txt.section( ':', 0, 0 ) == QString( "tco_%1" ).arg( - track::SampleTrack ) ) - { - _dee->acceptProposedAction(); - } - else if( txt.section( ':', 0, 0 ) == "samplefile" ) - { - _dee->acceptProposedAction(); - } - else - { - _dee->ignore(); - } - } - else - { - _dee->ignore(); - } -} - - - - -void audioFileProcessorView::dropEvent( QDropEvent * _de ) -{ - QString type = stringPairDrag::decodeKey( _de ); - QString value = stringPairDrag::decodeValue( _de ); - if( type == "samplefile" ) - { - castModel()->setAudioFile( value ); - _de->accept(); - return; - } - else if( type == QString( "tco_%1" ).arg( track::SampleTrack ) ) - { - multimediaProject mmp( value.toUtf8() ); - castModel()->setAudioFile( mmp.content(). - firstChild().toElement().attribute( "src" ) ); - _de->accept(); - return; - } - - _de->ignore(); -} - - - - -void audioFileProcessorView::paintEvent( QPaintEvent * ) +void AudioFileProcessorView::paintEvent( QPaintEvent * ) { QPainter p( this ); @@ -497,7 +441,7 @@ void audioFileProcessorView::paintEvent( QPaintEvent * ) -void audioFileProcessorView::sampleUpdated( void ) +void AudioFileProcessorView::sampleUpdated() { m_graph = QPixmap( 245, 75 ); m_graph.fill( Qt::transparent ); @@ -513,7 +457,7 @@ void audioFileProcessorView::sampleUpdated( void ) -void audioFileProcessorView::openAudioFile( void ) +void AudioFileProcessorView::openAudioFile() { QString af = castModel()->m_sampleBuffer. openAudioFile(); @@ -527,7 +471,7 @@ void audioFileProcessorView::openAudioFile( void ) -void audioFileProcessorView::modelChanged( void ) +void AudioFileProcessorView::modelChanged() { audioFileProcessor * a = castModel(); connect( &a->m_sampleBuffer, SIGNAL( sampleUpdated() ), @@ -550,8 +494,8 @@ extern "C" // neccessary for getting instance out of shared lib plugin * PLUGIN_EXPORT lmms_plugin_main( model *, void * _data ) { - return( new audioFileProcessor( - static_cast( _data ) ) ); + return new audioFileProcessor( + static_cast( _data ) ); } diff --git a/plugins/audio_file_processor/audio_file_processor.h b/plugins/audio_file_processor/audio_file_processor.h index 3c001094e..c7ab2507f 100644 --- a/plugins/audio_file_processor/audio_file_processor.h +++ b/plugins/audio_file_processor/audio_file_processor.h @@ -30,7 +30,7 @@ #include #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "sample_buffer.h" #include "knob.h" #include "pixmap_button.h" @@ -88,18 +88,18 @@ private: boolModel m_loopModel; - friend class audioFileProcessorView; + friend class AudioFileProcessorView; } ; -class audioFileProcessorView : public instrumentView +class AudioFileProcessorView : public InstrumentView { Q_OBJECT public: - audioFileProcessorView( instrument * _instrument, QWidget * _parent ); - virtual ~audioFileProcessorView(); + AudioFileProcessorView( instrument * _instrument, QWidget * _parent ); + virtual ~AudioFileProcessorView(); protected slots: @@ -108,8 +108,6 @@ protected slots: protected: - virtual void dragEnterEvent( QDragEnterEvent * _dee ); - virtual void dropEvent( QDropEvent * _de ); virtual void paintEvent( QPaintEvent * ); diff --git a/plugins/bit_invader/bit_invader.cpp b/plugins/bit_invader/bit_invader.cpp index 126f8b3bf..33049bd7d 100644 --- a/plugins/bit_invader/bit_invader.cpp +++ b/plugins/bit_invader/bit_invader.cpp @@ -323,7 +323,7 @@ pluginView * bitInvader::instantiateView( QWidget * _parent ) bitInvaderView::bitInvaderView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { setAutoFillBackground( TRUE ); QPalette pal; diff --git a/plugins/bit_invader/bit_invader.h b/plugins/bit_invader/bit_invader.h index 561347120..24b643125 100644 --- a/plugins/bit_invader/bit_invader.h +++ b/plugins/bit_invader/bit_invader.h @@ -29,7 +29,7 @@ #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "graph.h" #include "knob.h" #include "pixmap_button.h" @@ -109,7 +109,7 @@ private: -class bitInvaderView : public instrumentView +class bitInvaderView : public InstrumentView { Q_OBJECT public: diff --git a/plugins/kicker/kicker.cpp b/plugins/kicker/kicker.cpp index 76426b4c8..031c93ece 100644 --- a/plugins/kicker/kicker.cpp +++ b/plugins/kicker/kicker.cpp @@ -198,7 +198,7 @@ public: kickerInstrumentView::kickerInstrumentView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { m_startFreqKnob = new kickerKnob( this ); m_startFreqKnob->setHintText( tr( "Start frequency:" ) + " ", "Hz" ); diff --git a/plugins/kicker/kicker.h b/plugins/kicker/kicker.h index 6cf1de88d..cb785ca5a 100644 --- a/plugins/kicker/kicker.h +++ b/plugins/kicker/kicker.h @@ -28,7 +28,7 @@ #include #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "knob.h" @@ -73,7 +73,7 @@ private: -class kickerInstrumentView : public instrumentView +class kickerInstrumentView : public InstrumentView { Q_OBJECT public: diff --git a/plugins/lb302/lb302.cpp b/plugins/lb302/lb302.cpp index 91959a55e..693c3261d 100644 --- a/plugins/lb302/lb302.cpp +++ b/plugins/lb302/lb302.cpp @@ -803,7 +803,7 @@ pluginView * lb302Synth::instantiateView( QWidget * _parent ) lb302SynthView::lb302SynthView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { // GUI m_vcfCutKnob = new knob( knobBright_26, this ); diff --git a/plugins/lb302/lb302.h b/plugins/lb302/lb302.h index 289b75b26..ab7dc8c41 100644 --- a/plugins/lb302/lb302.h +++ b/plugins/lb302/lb302.h @@ -34,7 +34,7 @@ #include "effect_lib.h" #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "led_checkbox.h" #include "knob.h" #include "mixer.h" @@ -238,7 +238,7 @@ private: } ; -class lb302SynthView : public instrumentView +class lb302SynthView : public InstrumentView { public: lb302SynthView( instrument * _instrument, diff --git a/plugins/lb303/lb303.cpp b/plugins/lb303/lb303.cpp index 9323773a0..f511974ef 100644 --- a/plugins/lb303/lb303.cpp +++ b/plugins/lb303/lb303.cpp @@ -737,7 +737,7 @@ pluginView * lb303Synth::instantiateView( QWidget * _parent ) lb303SynthView::lb303SynthView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { // GUI m_vcfCutKnob = new knob( knobBright_26, this ); diff --git a/plugins/lb303/lb303.h b/plugins/lb303/lb303.h index 1b215d9d7..37e4dd2b3 100644 --- a/plugins/lb303/lb303.h +++ b/plugins/lb303/lb303.h @@ -34,7 +34,7 @@ #include "effect_lib.h" #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "led_checkbox.h" #include "knob.h" #include "mixer.h" @@ -239,7 +239,7 @@ private: } ; -class lb303SynthView : public instrumentView +class lb303SynthView : public InstrumentView { public: lb303SynthView( instrument * _instrument, diff --git a/plugins/organic/organic.cpp b/plugins/organic/organic.cpp index bfc96832e..d36ae4042 100644 --- a/plugins/organic/organic.cpp +++ b/plugins/organic/organic.cpp @@ -377,7 +377,7 @@ public: organicInstrumentView::organicInstrumentView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { organicInstrument * oi = castModel(); diff --git a/plugins/organic/organic.h b/plugins/organic/organic.h index 23e93a540..edd4cc512 100644 --- a/plugins/organic/organic.h +++ b/plugins/organic/organic.h @@ -28,7 +28,7 @@ #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "oscillator.h" #include "automatable_model.h" @@ -133,7 +133,7 @@ private slots: } ; -class organicInstrumentView : public instrumentView +class organicInstrumentView : public InstrumentView { Q_OBJECT public: diff --git a/plugins/papu/papu_instrument.cpp b/plugins/papu/papu_instrument.cpp index 672b60894..79ba1f9f9 100644 --- a/plugins/papu/papu_instrument.cpp +++ b/plugins/papu/papu_instrument.cpp @@ -445,7 +445,7 @@ public: papuInstrumentView::papuInstrumentView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { setAutoFillBackground( true ); diff --git a/plugins/papu/papu_instrument.h b/plugins/papu/papu_instrument.h index 6e34cfaf6..b2cd96c50 100644 --- a/plugins/papu/papu_instrument.h +++ b/plugins/papu/papu_instrument.h @@ -28,7 +28,7 @@ #include #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "knob.h" #include "graph.h" @@ -106,7 +106,7 @@ private: } ; -class papuInstrumentView : public instrumentView +class papuInstrumentView : public InstrumentView { Q_OBJECT public: diff --git a/plugins/patman/patman.cpp b/plugins/patman/patman.cpp index 616112f8a..d2fa522b9 100644 --- a/plugins/patman/patman.cpp +++ b/plugins/patman/patman.cpp @@ -432,7 +432,7 @@ void patmanInstrument::selectSample( notePlayHandle * _n ) pluginView * patmanInstrument::instantiateView( QWidget * _parent ) { - return new patmanView( this, _parent ); + return new PatmanView( this, _parent ); } @@ -444,8 +444,8 @@ pluginView * patmanInstrument::instantiateView( QWidget * _parent ) -patmanView::patmanView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ), +PatmanView::PatmanView( instrument * _instrument, QWidget * _parent ) : + InstrumentView( _instrument, _parent ), m_pi( NULL ) { setAutoFillBackground( true ); @@ -500,21 +500,19 @@ patmanView::patmanView( instrument * _instrument, QWidget * _parent ) : "frequency." ) ); m_displayFilename = tr( "No file selected" ); - - setAcceptDrops( true ); } -patmanView::~patmanView() +PatmanView::~PatmanView() { } -void patmanView::openFile() +void PatmanView::openFile() { QFileDialog ofd( NULL, tr( "Open patch file" ) ); ofd.setFileMode( QFileDialog::ExistingFiles ); @@ -566,7 +564,7 @@ void patmanView::openFile() -void patmanView::updateFilename() +void PatmanView::updateFilename() { m_displayFilename = ""; Uint16 idx = m_pi->m_patchFile.length(); @@ -593,48 +591,7 @@ void patmanView::updateFilename() -void patmanView::dragEnterEvent( QDragEnterEvent * _dee ) -{ - if( _dee->mimeData()->hasFormat( stringPairDrag::mimeType() ) ) - { - QString txt = _dee->mimeData()->data( - stringPairDrag::mimeType() ); - if( txt.section( ':', 0, 0 ) == "samplefile" ) - { - _dee->acceptProposedAction(); - } - else - { - _dee->ignore(); - } - } - else - { - _dee->ignore(); - } -} - - - - -void patmanView::dropEvent( QDropEvent * _de ) -{ - QString type = stringPairDrag::decodeKey( _de ); - QString value = stringPairDrag::decodeValue( _de ); - if( type == "samplefile" ) - { - m_pi->setFile( value ); - _de->accept(); - return; - } - - _de->ignore(); -} - - - - -void patmanView::paintEvent( QPaintEvent * ) +void PatmanView::paintEvent( QPaintEvent * ) { QPainter p( this ); @@ -647,7 +604,7 @@ void patmanView::paintEvent( QPaintEvent * ) -void patmanView::modelChanged() +void PatmanView::modelChanged() { m_pi = castModel(); m_loopButton->setModel( &m_pi->m_loopedModel ); diff --git a/plugins/patman/patman.h b/plugins/patman/patman.h index ec91fa9d4..87cbc18cd 100644 --- a/plugins/patman/patman.h +++ b/plugins/patman/patman.h @@ -27,7 +27,7 @@ #define _PATMAN_H_ #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "sample_buffer.h" #include "automatable_model.h" @@ -106,7 +106,7 @@ private: void selectSample( notePlayHandle * _n ); - friend class patmanView; + friend class PatmanView; signals: void fileChanged(); @@ -115,12 +115,12 @@ signals: -class patmanView : public instrumentView +class PatmanView : public InstrumentView { Q_OBJECT public: - patmanView( instrument * _instrument, QWidget * _parent ); - virtual ~patmanView(); + PatmanView( instrument * _instrument, QWidget * _parent ); + virtual ~PatmanView(); public slots: @@ -129,8 +129,6 @@ public slots: protected: - virtual void dragEnterEvent( QDragEnterEvent * _dee ); - virtual void dropEvent( QDropEvent * _de ); virtual void paintEvent( QPaintEvent * ); diff --git a/plugins/sf2_player/sf2_player.cpp b/plugins/sf2_player/sf2_player.cpp index 5c7ee4f1a..3f1e5458e 100644 --- a/plugins/sf2_player/sf2_player.cpp +++ b/plugins/sf2_player/sf2_player.cpp @@ -742,7 +742,7 @@ public: sf2InstrumentView::sf2InstrumentView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { // QVBoxLayout * vl = new QVBoxLayout( this ); // QHBoxLayout * hl = new QHBoxLayout(); diff --git a/plugins/sf2_player/sf2_player.h b/plugins/sf2_player/sf2_player.h index bb6743c18..a24f1dea6 100644 --- a/plugins/sf2_player/sf2_player.h +++ b/plugins/sf2_player/sf2_player.h @@ -31,7 +31,7 @@ #include "instrument.h" #include "pixmap_button.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "knob.h" #include "lcd_spinbox.h" #include "led_checkbox.h" @@ -181,7 +181,7 @@ public: -class sf2InstrumentView : public instrumentView +class sf2InstrumentView : public InstrumentView { Q_OBJECT public: diff --git a/plugins/sid/sid_instrument.cpp b/plugins/sid/sid_instrument.cpp index 8bf0890b0..60dd35e24 100644 --- a/plugins/sid/sid_instrument.cpp +++ b/plugins/sid/sid_instrument.cpp @@ -476,7 +476,7 @@ public: sidInstrumentView::sidInstrumentView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { setAutoFillBackground( TRUE ); diff --git a/plugins/sid/sid_instrument.h b/plugins/sid/sid_instrument.h index c1c401247..c82c43011 100644 --- a/plugins/sid/sid_instrument.h +++ b/plugins/sid/sid_instrument.h @@ -29,7 +29,7 @@ #include #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "knob.h" @@ -131,7 +131,7 @@ private: -class sidInstrumentView : public instrumentView +class sidInstrumentView : public InstrumentView { Q_OBJECT public: diff --git a/plugins/stk/mallets/mallets.cpp b/plugins/stk/mallets/mallets.cpp index 434c52e68..ecf59d15e 100644 --- a/plugins/stk/mallets/mallets.cpp +++ b/plugins/stk/mallets/mallets.cpp @@ -307,7 +307,7 @@ pluginView * malletsInstrument::instantiateView( QWidget * _parent ) malletsInstrumentView::malletsInstrumentView( malletsInstrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { m_modalBarWidget = setupModalBarControls( this ); setWidgetBackground( m_modalBarWidget, "artwork" ); diff --git a/plugins/stk/mallets/mallets.h b/plugins/stk/mallets/mallets.h index a969dfb3b..f47591e32 100644 --- a/plugins/stk/mallets/mallets.h +++ b/plugins/stk/mallets/mallets.h @@ -31,7 +31,7 @@ #include "combobox.h" #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "knob.h" #include "note_play_handle.h" #include "led_checkbox.h" @@ -177,7 +177,7 @@ private: } ; -class malletsInstrumentView: public instrumentView +class malletsInstrumentView: public InstrumentView { Q_OBJECT public: diff --git a/plugins/triple_oscillator/triple_oscillator.cpp b/plugins/triple_oscillator/triple_oscillator.cpp index 1d87c9d76..504ac80ef 100644 --- a/plugins/triple_oscillator/triple_oscillator.cpp +++ b/plugins/triple_oscillator/triple_oscillator.cpp @@ -482,7 +482,7 @@ public: tripleOscillatorView::tripleOscillatorView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { setAutoFillBackground( TRUE ); QPalette pal; diff --git a/plugins/triple_oscillator/triple_oscillator.h b/plugins/triple_oscillator/triple_oscillator.h index 45af8e108..89318f62e 100644 --- a/plugins/triple_oscillator/triple_oscillator.h +++ b/plugins/triple_oscillator/triple_oscillator.h @@ -28,7 +28,7 @@ #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "oscillator.h" #include "automatable_model.h" @@ -148,7 +148,7 @@ private: -class tripleOscillatorView : public instrumentView +class tripleOscillatorView : public InstrumentView { Q_OBJECT public: diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index dcdb47bae..51633f307 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -70,7 +70,7 @@ plugin::descriptor vestige_plugin_descriptor = } -QPixmap * vestigeInstrumentView::s_artwork = NULL; +QPixmap * VestigeInstrumentView::s_artwork = NULL; vestigeInstrument::vestigeInstrument( instrumentTrack * _instrument_track ) : @@ -246,7 +246,7 @@ void vestigeInstrument::loadFile( const QString & _file ) pluginView * vestigeInstrument::instantiateView( QWidget * _parent ) { - return new vestigeInstrumentView( this, _parent ); + return new VestigeInstrumentView( this, _parent ); } @@ -257,9 +257,9 @@ pluginView * vestigeInstrument::instantiateView( QWidget * _parent ) -vestigeInstrumentView::vestigeInstrumentView( instrument * _instrument, +VestigeInstrumentView::VestigeInstrumentView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { if( s_artwork == NULL ) { @@ -301,21 +301,19 @@ vestigeInstrumentView::vestigeInstrumentView( instrument * _instrument, note_off_all_btn->setFont( pointSize<8>( note_off_all_btn->font() ) ); connect( note_off_all_btn, SIGNAL( clicked() ), this, SLOT( noteOffAll() ) ); - - setAcceptDrops( true ); } -vestigeInstrumentView::~vestigeInstrumentView() +VestigeInstrumentView::~VestigeInstrumentView() { } -void vestigeInstrumentView::modelChanged() +void VestigeInstrumentView::modelChanged() { m_vi = castModel(); } @@ -323,7 +321,7 @@ void vestigeInstrumentView::modelChanged() -void vestigeInstrumentView::openPlugin() +void VestigeInstrumentView::openPlugin() { QFileDialog ofd( NULL, tr( "Open VST-plugin" ) ); @@ -367,7 +365,7 @@ void vestigeInstrumentView::openPlugin() -void vestigeInstrumentView::toggleGUI() +void VestigeInstrumentView::toggleGUI() { QMutexLocker ml( &m_vi->m_pluginMutex ); if( m_vi->m_plugin == NULL ) @@ -392,7 +390,7 @@ void vestigeInstrumentView::toggleGUI() -void vestigeInstrumentView::noteOffAll() +void VestigeInstrumentView::noteOffAll() { m_vi->m_pluginMutex.lock(); if( m_vi->m_plugin != NULL ) @@ -409,47 +407,7 @@ void vestigeInstrumentView::noteOffAll() -void vestigeInstrumentView::dragEnterEvent( QDragEnterEvent * _dee ) -{ - if( _dee->mimeData()->hasFormat( stringPairDrag::mimeType() ) ) - { - QString txt = _dee->mimeData()->data( - stringPairDrag::mimeType() ); - if( txt.section( ':', 0, 0 ) == "vstplugin" ) - { - _dee->acceptProposedAction(); - } - else - { - _dee->ignore(); - } - } - else - { - _dee->ignore(); - } -} - - - - -void vestigeInstrumentView::dropEvent( QDropEvent * _de ) -{ - QString type = stringPairDrag::decodeKey( _de ); - QString value = stringPairDrag::decodeValue( _de ); - if( type == "vstplugin" ) - { - m_vi->loadFile( value ); - _de->accept(); - return; - } - _de->ignore(); -} - - - - -void vestigeInstrumentView::paintEvent( QPaintEvent * ) +void VestigeInstrumentView::paintEvent( QPaintEvent * ) { QPainter p( this ); diff --git a/plugins/vestige/vestige.h b/plugins/vestige/vestige.h index e5fa7bfa1..7c7b618ec 100644 --- a/plugins/vestige/vestige.h +++ b/plugins/vestige/vestige.h @@ -26,12 +26,10 @@ #ifndef _VESTIGE_H #define _VESTIGE_H - #include - #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "midi.h" #include "note.h" @@ -83,18 +81,18 @@ private: QString m_pluginDLL; - friend class vestigeInstrumentView; + friend class VestigeInstrumentView; } ; -class vestigeInstrumentView : public instrumentView +class VestigeInstrumentView : public InstrumentView { Q_OBJECT public: - vestigeInstrumentView( instrument * _instrument, QWidget * _parent ); - virtual ~vestigeInstrumentView(); + VestigeInstrumentView( instrument * _instrument, QWidget * _parent ); + virtual ~VestigeInstrumentView(); protected slots: @@ -104,8 +102,6 @@ protected slots: protected: - virtual void dragEnterEvent( QDragEnterEvent * _dee ); - virtual void dropEvent( QDropEvent * _de ); virtual void paintEvent( QPaintEvent * _pe ); diff --git a/plugins/vibed/vibed.cpp b/plugins/vibed/vibed.cpp index 793f8befa..ae06e8148 100644 --- a/plugins/vibed/vibed.cpp +++ b/plugins/vibed/vibed.cpp @@ -355,7 +355,7 @@ pluginView * vibed::instantiateView( QWidget * _parent ) vibedView::vibedView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) + InstrumentView( _instrument, _parent ) { setAutoFillBackground( TRUE ); QPalette pal; diff --git a/plugins/vibed/vibed.h b/plugins/vibed/vibed.h index de2e7033a..bc117c133 100644 --- a/plugins/vibed/vibed.h +++ b/plugins/vibed/vibed.h @@ -25,7 +25,7 @@ #define _VIBED_H #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "sample_buffer.h" #include "graph.h" #include "knob.h" @@ -82,7 +82,7 @@ private: -class vibedView : public instrumentView +class vibedView : public InstrumentView { Q_OBJECT public: diff --git a/plugins/zynaddsubfx/zynaddsubfx.cpp b/plugins/zynaddsubfx/zynaddsubfx.cpp index ffb0f136d..c0a812b4a 100644 --- a/plugins/zynaddsubfx/zynaddsubfx.cpp +++ b/plugins/zynaddsubfx/zynaddsubfx.cpp @@ -248,7 +248,7 @@ void zynAddSubFx::initRemotePlugin( void ) pluginView * zynAddSubFx::instantiateView( QWidget * _parent ) { - return new zynAddSubFxView( this, _parent ); + return new ZynAddSubFxView( this, _parent ); } @@ -257,8 +257,8 @@ pluginView * zynAddSubFx::instantiateView( QWidget * _parent ) -zynAddSubFxView::zynAddSubFxView( instrument * _instrument, QWidget * _parent ) : - instrumentView( _instrument, _parent ) +ZynAddSubFxView::ZynAddSubFxView( instrument * _instrument, QWidget * _parent ) : + InstrumentView( _instrument, _parent ) { setAutoFillBackground( true ); QPalette pal; @@ -277,62 +277,19 @@ zynAddSubFxView::zynAddSubFxView( instrument * _instrument, QWidget * _parent ) m_toggleUIButton->setWhatsThis( tr( "Click here to show or hide the graphical user interface " "(GUI) of ZynAddSubFX." ) ); - - setAcceptDrops( true ); } -zynAddSubFxView::~zynAddSubFxView() +ZynAddSubFxView::~ZynAddSubFxView() { } -void zynAddSubFxView::dragEnterEvent( QDragEnterEvent * _dee ) -{ - if( _dee->mimeData()->hasFormat( stringPairDrag::mimeType() ) ) - { - QString txt = _dee->mimeData()->data( - stringPairDrag::mimeType() ); - if( txt.section( ':', 0, 0 ) == "pluginpresetfile" ) - { - _dee->acceptProposedAction(); - } - else - { - _dee->ignore(); - } - } - else - { - _dee->ignore(); - } -} - - - - -void zynAddSubFxView::dropEvent( QDropEvent * _de ) -{ - const QString type = stringPairDrag::decodeKey( _de ); - const QString value = stringPairDrag::decodeValue( _de ); - if( type == "pluginpresetfile" ) - { - // TODO: replace by generic approach - // castModel()->loadFile( value ); - _de->accept(); - return; - } - _de->ignore(); -} - - - - -void zynAddSubFxView::modelChanged( void ) +void ZynAddSubFxView::modelChanged( void ) { toggleUI(); } @@ -340,7 +297,7 @@ void zynAddSubFxView::modelChanged( void ) -void zynAddSubFxView::toggleUI( void ) +void ZynAddSubFxView::toggleUI( void ) { if( m_toggleUIButton->isChecked() ) { diff --git a/plugins/zynaddsubfx/zynaddsubfx.h b/plugins/zynaddsubfx/zynaddsubfx.h index d6a3d8356..e6a272397 100644 --- a/plugins/zynaddsubfx/zynaddsubfx.h +++ b/plugins/zynaddsubfx/zynaddsubfx.h @@ -30,13 +30,13 @@ #include #include "instrument.h" -#include "instrument_view.h" +#include "InstrumentView.h" #include "remote_plugin.h" class QPushButton; -class zynAddSubFxView; +class ZynAddSubFxView; class notePlayHandle; @@ -78,7 +78,7 @@ private: QMutex m_pluginMutex; remotePlugin * m_plugin; - friend class zynAddSubFxView; + friend class ZynAddSubFxView; signals: @@ -88,17 +88,12 @@ signals: -class zynAddSubFxView : public instrumentView +class ZynAddSubFxView : public InstrumentView { Q_OBJECT public: - zynAddSubFxView( instrument * _instrument, QWidget * _parent ); - virtual ~zynAddSubFxView(); - - -protected: - virtual void dragEnterEvent( QDragEnterEvent * _dee ); - virtual void dropEvent( QDropEvent * _de ); + ZynAddSubFxView( instrument * _instrument, QWidget * _parent ); + virtual ~ZynAddSubFxView(); private: diff --git a/src/core/instrument.cpp b/src/core/instrument.cpp index 53c7b191a..80200f757 100644 --- a/src/core/instrument.cpp +++ b/src/core/instrument.cpp @@ -1,9 +1,7 @@ -#ifndef SINGLE_SOURCE_COMPILE - /* * instrument.cpp - base-class for all instrument-plugins (synths, samplers etc) * - * Copyright (c) 2005-2008 Tobias Doerffel + * Copyright (c) 2005-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -26,9 +24,8 @@ #include "instrument.h" -#include "instrument_view.h" #include "instrument_track.h" -#include "dummy_instrument.h" +#include "DummyInstrument.h" #include "note_play_handle.h" #include "embed.h" @@ -66,7 +63,7 @@ void instrument::deleteNotePluginData( notePlayHandle * ) f_cnt_t instrument::beatLen( notePlayHandle * ) const { - return( 0 ); + return 0; } @@ -81,12 +78,12 @@ instrument * instrument::instantiate( const QString & _plugin_name, if( dynamic_cast( p ) != NULL ) { // everything ok, so return pointer - return( dynamic_cast( p ) ); + return dynamic_cast( p ); } // not quite... so delete plugin and return dummy instrument delete p; - return( new dummyInstrument( _instrument_track ) ); + return new DummyInstrument( _instrument_track ); } @@ -94,7 +91,7 @@ instrument * instrument::instantiate( const QString & _plugin_name, bool instrument::isFromTrack( const track * _track ) const { - return( m_instrumentTrack == _track ); + return m_instrumentTrack == _track; } @@ -129,52 +126,3 @@ QString instrument::fullDisplayName( void ) const } - - - - - -instrumentView::instrumentView( instrument * _instrument, QWidget * _parent ) : - pluginView( _instrument, _parent ) -{ - setModel( _instrument ); - setFixedSize( 250, 250 ); - setAttribute( Qt::WA_DeleteOnClose, TRUE ); -} - - - - -instrumentView::~instrumentView() -{ - if( getInstrumentTrackWindow() ) - { - getInstrumentTrackWindow()->m_instrumentView = NULL; - } -} - - - - -void instrumentView::setModel( ::model * _model, bool ) -{ - if( dynamic_cast( _model ) != NULL ) - { - modelView::setModel( _model ); - getInstrumentTrackWindow()->setWindowIcon( - model()->getDescriptor()->logo->pixmap() ); - connect( model(), SIGNAL( destroyed( QObject * ) ), - this, SLOT( close() ) ); - } -} - - - - -instrumentTrackWindow * instrumentView::getInstrumentTrackWindow( void ) -{ - return( dynamic_cast( - parentWidget()->parentWidget() ) ); -} - -#endif diff --git a/src/gui/InstrumentView.cpp b/src/gui/InstrumentView.cpp new file mode 100644 index 000000000..e4126394a --- /dev/null +++ b/src/gui/InstrumentView.cpp @@ -0,0 +1,116 @@ +/* + * InstrumentView.cpp - base-class for views of all instruments + * + * Copyright (c) 2008-2009 Tobias Doerffel + * + * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + + +#include "InstrumentView.h" +#include "embed.h" +#include "instrument.h" +#include "instrument_track.h" +#include "ResourceDB.h" +#include "string_pair_drag.h" +#include "UnifiedResourceProvider.h" + + +InstrumentView::InstrumentView( instrument * _instrument, QWidget * _parent ) : + pluginView( _instrument, _parent ) +{ + setModel( _instrument ); + setFixedSize( 250, 250 ); + setAttribute( Qt::WA_DeleteOnClose, true ); + setAcceptDrops( true ); +} + + + + +InstrumentView::~InstrumentView() +{ + if( getInstrumentTrackWindow() ) + { + getInstrumentTrackWindow()->m_instrumentView = NULL; + } +} + + + + +void InstrumentView::setModel( ::model * _model, bool ) +{ + if( dynamic_cast( _model ) != NULL ) + { + modelView::setModel( _model ); + getInstrumentTrackWindow()->setWindowIcon( + model()->getDescriptor()->logo->pixmap() ); + connect( model(), SIGNAL( destroyed( QObject * ) ), + this, SLOT( close() ) ); + } +} + + + + +instrumentTrackWindow * InstrumentView::getInstrumentTrackWindow( void ) +{ + return dynamic_cast( + parentWidget()->parentWidget() ); +} + + + + +void InstrumentView::dragEnterEvent( QDragEnterEvent * _dee ) +{ + if( stringPairDrag::decodeKey( _dee ) == ResourceItem::mimeKey() ) + { + const ResourceItem * item = + engine::resourceProvider()->database()-> + itemByHash( stringPairDrag::decodeValue( _dee ) ); + if( item && + model()->getDescriptor()->supportsFileType( + item->nameExtension() ) ) + { + _dee->acceptProposedAction(); + } + } +} + + + + +void InstrumentView::dropEvent( QDropEvent * _de ) +{ + if( stringPairDrag::decodeKey( _de ) == ResourceItem::mimeKey() ) + { + const ResourceItem * item = + engine::resourceProvider()->database()-> + itemByHash( stringPairDrag::decodeValue( _de ) ); + model()->loadResource( item ); + _de->accept(); + } +} + + + + +