From 736a252b53d01081529507fc7ab4bcb44db13fff Mon Sep 17 00:00:00 2001 From: Paul Giblock Date: Sun, 25 May 2008 05:29:00 +0000 Subject: [PATCH] Load and save controllers to project git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1016 0778d3d1-df1d-0410-868b-ea421aaaa00d --- src/core/song.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/core/song.cpp b/src/core/song.cpp index 35eb0186c..884233d07 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -729,6 +729,13 @@ void song::clearProject( void ) engine::getProjectNotes()->clear(); } + /* + while( !m_controllers.empty() ) + { + delete m_controllers.last(); + } + */ + engine::getProjectJournal()->clearInvalidJournallingObjects(); engine::getProjectJournal()->clearJournal(); @@ -853,6 +860,10 @@ void FASTCALL song::loadProject( const QString & _file_name ) ( (journallingObject *)( this ) )-> restoreState( node.toElement() ); } + else if( node.nodeName() == "controllers" ) + { + restoreControllerStates( node.toElement() ); + } else if( engine::hasGUI() ) { if( node.nodeName() == @@ -924,6 +935,8 @@ bool song::saveProject( void ) mmp.content() ); m_playPos[Mode_PlaySong].m_timeLine->saveState( mmp, mmp.content() ); + saveControllerStates( mmp, mmp.content() ); + m_fileName = mmp.nameWithExtension( m_fileName ); if( mmp.writeFile( m_fileName ) == TRUE ) { @@ -980,6 +993,35 @@ void song::importProject( void ) } + + +void song::saveControllerStates( QDomDocument & _doc, QDomElement & _this ) +{ + // save settings of controllers + QDomElement controllersNode =_doc.createElement( "controllers" ); + _this.appendChild( controllersNode ); + for( int i = 0; i < m_controllers.size(); ++i ) + { + m_controllers[i]->saveState( _doc, controllersNode ); + } +} + + + + +void song::restoreControllerStates( const QDomElement & _this ) +{ + QDomNode node = _this.firstChild(); + while( !node.isNull() ) { + addController( controller::create( node.toElement(), this ) ); + + node = node.nextSibling(); + } +} + + + + #warning TODO: move somewhere else static inline QString baseName( const QString & _file ) { @@ -1077,6 +1119,20 @@ void song::addController( controller * _c ) } +void song::removeController( controller * _controller ) +{ + int index = m_controllers.indexOf( _controller ); + if( index != -1 ) + { + m_controllers.remove( index ); + + if( engine::getSong() ) + { + engine::getSong()->setModified(); + } + } +} + #include "song.moc"