From 13a65b88f2f8b8cde4fd819b28062be826f3d639 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sat, 15 Mar 2008 14:53:17 +0000 Subject: [PATCH] implemented save- and load-functionality for FX-mixer git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@790 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 12 +++ configure.in | 4 +- include/effect_chain.h | 2 +- include/effect_rack_view.h | 2 + include/fx_mixer.h | 4 + src/core/effect_chain.cpp | 6 +- src/core/fx_mixer.cpp | 141 ++++++++++++++++++++++--------- src/core/song.cpp | 46 +++++++--- src/tracks/instrument_track.cpp | 3 +- src/widgets/effect_rack_view.cpp | 41 ++------- 10 files changed, 163 insertions(+), 98 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a0333eb8..9c76dff3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-03-15 Tobias Doerffel + + * include/fx_mixer.h: + * include/effect_rack_view.h: + * include/effect_chain.h: + * src/widgets/effect_rack_view.cpp: + * src/tracks/instrument_track.cpp: + * src/core/effect_chain.cpp: + * src/core/song.cpp: + * src/core/fx_mixer.cpp: + implemented save- and load-functionality for FX-mixer + 2008-03-14 Tobias Doerffel * include/engine.h: diff --git a/configure.in b/configure.in index 44f939eca..1059d632c 100644 --- a/configure.in +++ b/configure.in @@ -2,8 +2,8 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.50) -AC_INIT(lmms, 0.4.0-svn20080307, lmms-devel/at/lists/dot/sf/dot/net) -AM_INIT_AUTOMAKE(lmms, 0.4.0-svn20080307) +AC_INIT(lmms, 0.4.0-svn20080315, lmms-devel/at/lists/dot/sf/dot/net) +AM_INIT_AUTOMAKE(lmms, 0.4.0-svn20080315) AM_CONFIG_HEADER(config.h) diff --git a/include/effect_chain.h b/include/effect_chain.h index eab2de62a..00e560e68 100644 --- a/include/effect_chain.h +++ b/include/effect_chain.h @@ -52,7 +52,7 @@ public: void startRunning( void ); bool isRunning( void ); - void deleteAllPlugins( void ); + void clear( void ); private: diff --git a/include/effect_rack_view.h b/include/effect_rack_view.h index 434ea598c..ebdcdfdc1 100644 --- a/include/effect_rack_view.h +++ b/include/effect_rack_view.h @@ -46,6 +46,8 @@ public: effectRackView( effectChain * _model, QWidget * _parent ); virtual ~effectRackView(); + void clear( void ); + public slots: void moveUp( effectView * _view ); diff --git a/include/fx_mixer.h b/include/fx_mixer.h index a536b34ef..3c3765991 100644 --- a/include/fx_mixer.h +++ b/include/fx_mixer.h @@ -60,6 +60,8 @@ public: const surroundSampleFrame * masterMix( void ); + void clear( void ); + virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent ); virtual void loadSettings( const QDomElement & _this ); @@ -92,6 +94,8 @@ public: } void setCurrentFxLine( fxLine * _line ); + void clear( void ); + private slots: void updateFaders( void ); diff --git a/src/core/effect_chain.cpp b/src/core/effect_chain.cpp index a3fabf06c..0ddb236eb 100644 --- a/src/core/effect_chain.cpp +++ b/src/core/effect_chain.cpp @@ -45,7 +45,7 @@ effectChain::effectChain( track * _track ) : effectChain::~effectChain() { - deleteAllPlugins(); + clear(); } @@ -69,7 +69,7 @@ void effectChain::saveSettings( QDomDocument & _doc, QDomElement & _this ) void effectChain::loadSettings( const QDomElement & _this ) { - deleteAllPlugins(); + clear(); m_enabledModel.setValue( _this.attribute( "enabled" ).toInt() ); @@ -236,7 +236,7 @@ bool effectChain::isRunning( void ) -void effectChain::deleteAllPlugins( void ) +void effectChain::clear( void ) { for( int i = 0; i < m_effects.count(); ++i ) { diff --git a/src/core/fx_mixer.cpp b/src/core/fx_mixer.cpp index 061f81338..7a68eb4f2 100644 --- a/src/core/fx_mixer.cpp +++ b/src/core/fx_mixer.cpp @@ -54,6 +54,7 @@ struct fxChannel m_muteModel( FALSE, _parent ), m_soloModel( FALSE, _parent ), m_volumeModel( 1.0, 0.0, 2.0, 0.01, _parent ), + m_name(), m_lock() { engine::getMixer()->clearAudioBuffer( m_buffer, @@ -68,6 +69,7 @@ struct fxChannel boolModel m_muteModel; boolModel m_soloModel; floatModel m_volumeModel; + QString m_name; QMutex m_lock; } ; @@ -81,6 +83,8 @@ fxMixer::fxMixer() : { m_fxChannels[i] = new fxChannel( this ); } + // reset name etc. + clear(); } @@ -113,9 +117,15 @@ void fxMixer::processChannel( fx_ch_t _ch ) const fpp_t f = engine::getMixer()->framesPerPeriod(); m_fxChannels[_ch]->m_fxChain.startRunning(); m_fxChannels[_ch]->m_fxChain.processAudioBuffer( - m_fxChannels[_ch]->m_buffer, f ); - m_fxChannels[_ch]->m_peakLeft = engine::getMixer()->peakValueLeft( m_fxChannels[_ch]->m_buffer, f ) * m_fxChannels[_ch]->m_volumeModel.value(); - m_fxChannels[_ch]->m_peakRight = engine::getMixer()->peakValueRight( m_fxChannels[_ch]->m_buffer, f ) * m_fxChannels[_ch]->m_volumeModel.value(); + m_fxChannels[_ch]->m_buffer, f ); + m_fxChannels[_ch]->m_peakLeft = + engine::getMixer()->peakValueLeft( + m_fxChannels[_ch]->m_buffer, f ) * + m_fxChannels[_ch]->m_volumeModel.value(); + m_fxChannels[_ch]->m_peakRight = + engine::getMixer()->peakValueRight( + m_fxChannels[_ch]->m_buffer, f ) * + m_fxChannels[_ch]->m_volumeModel.value(); } else { @@ -144,11 +154,12 @@ const surroundSampleFrame * fxMixer::masterMix( void ) if( m_fxChannels[i]->m_used ) { surroundSampleFrame * _buf = m_fxChannels[i]->m_buffer; + const float v = m_fxChannels[i]->m_volumeModel.value(); for( f_cnt_t f = 0; f < engine::getMixer()->framesPerPeriod(); ++f ) { - buf[f][0] += _buf[f][0]*m_fxChannels[i]->m_volumeModel.value(); - buf[f][1] += _buf[f][1]*m_fxChannels[i]->m_volumeModel.value(); + buf[f][0] += _buf[f][0] * v; + buf[f][1] += _buf[f][1] * v; } engine::getMixer()->clearAudioBuffer( _buf, engine::getMixer()->framesPerPeriod() ); @@ -156,10 +167,11 @@ const surroundSampleFrame * fxMixer::masterMix( void ) } } processChannel( 0 ); + const float v = m_fxChannels[0]->m_volumeModel.value(); for( f_cnt_t f = 0; f < engine::getMixer()->framesPerPeriod(); ++f ) { - buf[f][0] *= m_fxChannels[0]->m_volumeModel.value(); - buf[f][1] *= m_fxChannels[0]->m_volumeModel.value(); + buf[f][0] *= v; + buf[f][1] *= v; } m_fxChannels[0]->m_peakLeft *= engine::getMixer()->masterGain(); m_fxChannels[0]->m_peakRight *= engine::getMixer()->masterGain(); @@ -169,11 +181,33 @@ const surroundSampleFrame * fxMixer::masterMix( void ) +void fxMixer::clear() +{ + for( int i = 0; i <= NUM_FX_CHANNELS; ++i ) + { + m_fxChannels[i]->m_fxChain.clear(); + m_fxChannels[i]->m_volumeModel.setValue( 1.0f ); + m_fxChannels[i]->m_name = ( i == 0 ) ? + tr( "Master" ) : tr( "FX %1" ).arg( i ); + + } +} + + + + void fxMixer::saveSettings( QDomDocument & _doc, QDomElement & _this ) { -/* m_chordsEnabledModel.saveSettings( _doc, _this, "chord-enabled" ); - m_chordsModel.saveSettings( _doc, _this, "chord" ); - m_chordRangeModel.saveSettings( _doc, _this, "chordrange" );*/ + for( int i = 0; i <= NUM_FX_CHANNELS; ++i ) + { + QDomElement fxch = _doc.createElement( + QString( "fxchannel%1" ).arg( i ) ); + _this.appendChild( fxch ); + m_fxChannels[i]->m_fxChain.saveState( _doc, fxch ); + m_fxChannels[i]->m_volumeModel.saveSettings( _doc, fxch, + "volume" ); + fxch.setAttribute( "name", m_fxChannels[i]->m_name ); + } } @@ -181,27 +215,34 @@ void fxMixer::saveSettings( QDomDocument & _doc, QDomElement & _this ) void fxMixer::loadSettings( const QDomElement & _this ) { -/* m_chordsEnabledModel.loadSettings( _this, "chord-enabled" ); - m_chordsModel.loadSettings( _this, "chord" ); - m_chordRangeModel.loadSettings( _this, "chordrange" );*/ + clear(); + for( int i = 0; i <= NUM_FX_CHANNELS; ++i ) + { + QDomElement fxch = _this.firstChildElement( + QString( "fxchannel%1" ).arg( i ) ); + m_fxChannels[i]->m_fxChain.restoreState( + fxch.firstChildElement( + m_fxChannels[i]->m_fxChain.nodeName() ) ); + m_fxChannels[i]->m_volumeModel.loadSettings( fxch, "volume" ); + m_fxChannels[i]->m_name = fxch.attribute( "name" ); + } + + emit dataChanged(); } class fxLine : public QWidget { public: - fxLine( QWidget * _parent, fxMixerView * _mv ) : + fxLine( QWidget * _parent, fxMixerView * _mv, QString & _name ) : QWidget( _parent ), - m_mv( _mv ) + m_mv( _mv ), + m_name( _name ) { setFixedSize( 32, 200 ); setAttribute( Qt::WA_OpaquePaintEvent, TRUE ); } - virtual void setName( const QString & _name ) - { - m_name = _name; - } virtual void paintEvent( QPaintEvent * ) { QPainter p( this ); @@ -244,12 +285,11 @@ public: m_name = new_name; update(); } - } private: fxMixerView * m_mv; - QString m_name; + QString & m_name; } ; @@ -260,19 +300,22 @@ fxMixerView::fxMixerView() : QWidget(), modelView( NULL ) { + engine::getMainWindow()->workspace()->addSubWindow( this ); + fxMixer * m = engine::getFxMixer(); QPalette pal = palette(); pal.setColor( QPalette::Background, QColor( 72, 76, 88 ) ); setPalette( pal ); setAutoFillBackground( TRUE ); + setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum ); // setFixedHeight( 250+216 ); setWindowTitle( tr( "FX-Mixer" ) ); // setWindowIcon( embed::getIconPixmap( "fxmixer" ) ); - engine::getMainWindow()->workspace()->addSubWindow( this ); + parentWidget()->setAttribute( Qt::WA_DeleteOnClose, FALSE ); - QVBoxLayout * ml = new QVBoxLayout( this ); + QVBoxLayout * ml = new QVBoxLayout; ml->setMargin( 0 ); ml->setSpacing( 0 ); @@ -283,11 +326,6 @@ fxMixerView::fxMixerView() : a->setFixedHeight( 216 ); ml->addWidget( a ); - m_fxRackArea = new QWidget( this ); - m_fxRackArea->setFixedHeight( 250 ); - ml->addWidget( m_fxRackArea ); - ml->addStretch(); - QWidget * base = new QWidget; QHBoxLayout * bl = new QHBoxLayout( base ); bl->setSpacing( 0 ); @@ -300,22 +338,25 @@ fxMixerView::fxMixerView() : base->setPalette( pal ); base->setAutoFillBackground( TRUE ); + + m_fxRackArea = new QWidget; + ml->addWidget( m_fxRackArea ); + setLayout( ml ); + + QHBoxLayout * fxl = new QHBoxLayout; + fxl->setSpacing( 0 ); + fxl->setMargin( 0 ); + + bl->addSpacing( 6 ); + for( int i = 0; i < NUM_FX_CHANNELS+1; ++i ) { fxChannelView * cv = &m_fxChannelViews[i]; - cv->m_fxLine = new fxLine( base, this ); + cv->m_fxLine = new fxLine( base, this, + m->m_fxChannels[i]->m_name ); bl->addWidget( cv->m_fxLine ); - if( i == 0 ) - { - bl->addSpacing( 10 ); - cv->m_fxLine->setName( tr( "Master" ).arg( i ) ); - } - else - { - bl->addSpacing( 1 ); - cv->m_fxLine->setName( tr( "FX %1" ).arg( i ) ); - } + bl->addSpacing( i == 0 ? 10 : 1 ); lcdSpinBox * l = new lcdSpinBox( 2, cv->m_fxLine ); l->model()->setRange( i, i ); l->model()->setValue( i ); @@ -324,16 +365,21 @@ fxMixerView::fxMixerView() : cv->m_fxLine ); cv->m_fader->move( 15-cv->m_fader->width()/2, 80 ); cv->m_rackView = new effectRackView( - &m->m_fxChannels[i]->m_fxChain, m_fxRackArea ); - cv->m_rackView->setFixedSize( 250, 250 ); + &m->m_fxChannels[i]->m_fxChain, NULL ); + fxl->addWidget( cv->m_rackView ); } + fxl->addStretch(); + + m_fxRackArea->setLayout( fxl ); - show(); setCurrentFxLine( m_fxChannelViews[0].m_fxLine ); QTimer * t = new QTimer( this ); connect( t, SIGNAL( timeout() ), this, SLOT( updateFaders() ) ); t->start( 50 ); + + // we want to receive dataChanged-signals in order to update + setModel( m ); } @@ -366,6 +412,17 @@ void fxMixerView::setCurrentFxLine( fxLine * _line ) +void fxMixerView::clear( void ) +{ + for( int i = 0; i <= NUM_FX_CHANNELS; ++i ) + { + m_fxChannelViews[i].m_rackView->clear(); + } +} + + + + void fxMixerView::updateFaders( void ) { fxMixer * m = engine::getFxMixer(); diff --git a/src/core/song.cpp b/src/core/song.cpp index 08bddab33..b776b350e 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -50,6 +50,7 @@ #include "embed.h" #include "envelope_and_lfo_parameters.h" #include "export_project_dialog.h" +#include "fx_mixer.h" #include "import_filter.h" #include "instrument_track.h" #include "main_window.h" @@ -687,10 +688,16 @@ void song::clearProject( void ) { engine::getSongEditor()->clearAllTracks(); } + if( engine::getFxMixerView() ) + { + engine::getFxMixerView()->clear(); + } QCoreApplication::sendPostedEvents(); engine::getBBTrackContainer()->clearAllTracks(); clearAllTracks(); + engine::getFxMixer()->clear(); + if( engine::getAutomationEditor() ) { engine::getAutomationEditor()->setCurrentPattern( NULL ); @@ -833,29 +840,39 @@ void FASTCALL song::loadProject( const QString & _file_name ) else if( engine::hasGUI() ) { if( node.nodeName() == - engine::getPianoRoll()->nodeName() ) + engine::getFxMixer()->nodeName() ) + { + engine::getFxMixer()->restoreState( + node.toElement() ); + } + else if( node.nodeName() == + engine::getPianoRoll()->nodeName() ) { engine::getPianoRoll()->restoreState( - node.toElement() ); + node.toElement() ); } else if( node.nodeName() == - engine::getAutomationEditor()->nodeName() ) + engine::getAutomationEditor()-> + nodeName() ) { - engine::getAutomationEditor()->restoreState( - node.toElement() ); - } - else if( node.nodeName() == - engine::getProjectNotes()->nodeName() ) - { - ( (journallingObject *)( engine:: - getProjectNotes() ) )-> + engine::getAutomationEditor()-> restoreState( node.toElement() ); } else if( node.nodeName() == - m_playPos[Mode_PlaySong].m_timeLine->nodeName() ) + engine::getProjectNotes()-> + nodeName() ) { - m_playPos[Mode_PlaySong].m_timeLine->restoreState( - node.toElement() ); + ( (journallingObject *)( engine:: + getProjectNotes() ) )-> + restoreState( node.toElement() ); + } + else if( node.nodeName() == + m_playPos[Mode_PlaySong]. + m_timeLine->nodeName() ) + { + m_playPos[Mode_PlaySong]. + m_timeLine->restoreState( + node.toElement() ); } } } @@ -884,6 +901,7 @@ bool song::saveProject( void ) ( (journallingObject *)( this ) )->saveState( mmp, mmp.content() ); + engine::getFxMixer()->saveState( mmp, mmp.content() ); engine::getPianoRoll()->saveState( mmp, mmp.content() ); engine::getAutomationEditor()->saveState( mmp, mmp.content() ); ( (journallingObject *)( engine::getProjectNotes() ) )->saveState( mmp, diff --git a/src/tracks/instrument_track.cpp b/src/tracks/instrument_track.cpp index e94b3cb3d..5935bff47 100644 --- a/src/tracks/instrument_track.cpp +++ b/src/tracks/instrument_track.cpp @@ -727,7 +727,8 @@ void instrumentTrack::loadTrackSpecificSettings( const QDomElement & _this ) m_baseNoteModel.loadSettings( _this, "basenote" ); } - m_audioPort.getEffects()->deleteAllPlugins(); + // clear effect-chain just in case we load an old preset without FX-data + m_audioPort.getEffects()->clear(); QDomNode node = _this.firstChild(); while( !node.isNull() ) diff --git a/src/widgets/effect_rack_view.cpp b/src/widgets/effect_rack_view.cpp index 392493863..4f1364ce9 100644 --- a/src/widgets/effect_rack_view.cpp +++ b/src/widgets/effect_rack_view.cpp @@ -42,11 +42,7 @@ effectRackView::effectRackView( effectChain * _model, QWidget * _parent ) : QWidget( _parent ), modelView( NULL ) { - setFixedSize( 230, 184 ); - -/* m_mainLayout = new QVBoxLayout( this ); - m_mainLayout->setMargin( 0 ); - m_mainLayout->setSpacing( 0 );*/ + setFixedSize( 250, 250 ); m_effectsGroupBox = new groupBox( tr( "EFFECTS CHAIN" ), this ); m_effectsGroupBox->setGeometry( 2, 2, 242, 244 ); @@ -63,12 +59,9 @@ effectRackView::effectRackView( effectChain * _model, QWidget * _parent ) : connect( m_addButton, SIGNAL( clicked( void ) ), this, SLOT( addEffect( void ) ) ); - //m_mainLayout->addWidget( m_scrollArea ); - QWidget * w = new QWidget; m_scrollArea->setWidget( w ); - w->show(); - + m_lastY = 0; setModel( _model ); @@ -78,14 +71,14 @@ effectRackView::effectRackView( effectChain * _model, QWidget * _parent ) : effectRackView::~effectRackView() { - //deleteAllPlugins(); + clear(); } -/* -void effectRackView::deleteAllPlugins( void ) + +void effectRackView::clear( void ) { for( QVector::iterator it = m_effectViews.begin(); it != m_effectViews.end(); ++it ) @@ -94,7 +87,7 @@ void effectRackView::deleteAllPlugins( void ) } m_effectViews.clear(); } -*/ + @@ -134,28 +127,6 @@ void effectRackView::moveDown( effectView * _view ) moveUp( *( qFind( m_effectViews.begin(), m_effectViews.end(), _view ) + 1 ) ); } -/* - fxChain()->moveDown( _view->getEffect() ); - if( _view != m_effectViews.last() ) - { - int i = 0; - for( QVector::iterator it = - m_effectViews.begin(); - it != m_effectViews.end(); it++, i++ ) - { - if( *it == _view ) - { - break; - } - } - - effectView * temp = m_effectViews.at( i + 1 ); - - m_effectViews[i + 1] = _view; - m_effectViews[i] = temp; - - redraw(); - }*/ }