diff --git a/include/mmp.h b/include/mmp.h index a226d8189..82818a8f3 100644 --- a/include/mmp.h +++ b/include/mmp.h @@ -1,7 +1,7 @@ /* * mmp.h - class for reading and writing multimedia-project-files * - * Copyright (c) 2004-2008 Tobias Doerffel + * Copyright (c) 2004-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -52,9 +52,8 @@ public: } ; - multimediaProject( const QString & _in_file_name, - bool _is_filename = TRUE, - bool _upgrade = TRUE ); + multimediaProject( const QString & _fileName ); + multimediaProject( const QByteArray & _data ); multimediaProject( ProjectTypes _project_type ); virtual ~multimediaProject(); @@ -76,8 +75,6 @@ public: return( m_type ); } - static ProjectTypes typeOfFile( const QString & _fn ); - private: static ProjectTypes type( const QString & _type_name ); @@ -87,6 +84,8 @@ private: void upgrade( void ); + void loadData( const QByteArray & _data, const QString & _sourceFile ); + struct EXPORT typeDescStruct { diff --git a/plugins/audio_file_processor/audio_file_processor.cpp b/plugins/audio_file_processor/audio_file_processor.cpp index 1e787979a..72388f594 100644 --- a/plugins/audio_file_processor/audio_file_processor.cpp +++ b/plugins/audio_file_processor/audio_file_processor.cpp @@ -1,7 +1,7 @@ /* * audio_file_processor.cpp - instrument for using audio-files * - * Copyright (c) 2004-2008 Tobias Doerffel + * Copyright (c) 2004-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -424,7 +424,7 @@ void audioFileProcessorView::dropEvent( QDropEvent * _de ) } else if( type == QString( "tco_%1" ).arg( track::SampleTrack ) ) { - multimediaProject mmp( value, FALSE ); + multimediaProject mmp( value.toUtf8() ); castModel()->setAudioFile( mmp.content(). firstChild().toElement().attribute( "src" ) ); _de->accept(); diff --git a/src/core/mmp.cpp b/src/core/mmp.cpp index b9d5fc123..2d23eeccb 100644 --- a/src/core/mmp.cpp +++ b/src/core/mmp.cpp @@ -1,9 +1,7 @@ -#ifndef SINGLE_SOURCE_COMPILE - /* * mmp.cpp - implementation of class multimediaProject * - * Copyright (c) 2004-2008 Tobias Doerffel + * Copyright (c) 2004-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -29,6 +27,7 @@ #include +#include #include #include #include @@ -84,85 +83,43 @@ multimediaProject::multimediaProject( ProjectTypes _project_type ) : -multimediaProject::multimediaProject( const QString & _in_file_name, - bool _is_filename, - bool _upgrade ) : +multimediaProject::multimediaProject( const QString & _fileName ) : QDomDocument(), m_content(), m_head() { - QFile in_file( _in_file_name ); - if( _is_filename == TRUE ) + QFile inFile( _fileName ); + if( !inFile.open( QIODevice::ReadOnly ) ) { - if( !in_file.open( QIODevice::ReadOnly ) ) - { - QMessageBox::critical( NULL, - songEditor::tr( "Could not open file" ), - songEditor::tr( "Could not open " - "file %1. You probably " - "have no rights to " - "read this file.\n" - "Please make sure you " - "have at least read-" - "access to the file " - "and try again." - ).arg( _in_file_name ) ); + QMessageBox::critical( NULL, + songEditor::tr( "Could not open file" ), + songEditor::tr( "Could not open file %1. You probably " + "have no permissions to read this " + "file.\n Please make sure to have at " + "least read permissions to the file " + "and try again." ).arg( _fileName ) ); return; - } } - QString error_msg; - int line; - int col; - if( _is_filename == TRUE ) + + if( _fileName.section( '.', -1 ) == "mmpz" ) { - bool error = FALSE; - if( _in_file_name.section( '.', -1 ) == "mmpz" ) - { - QString data = qUncompress( in_file.readAll() ); - error = !setContent( data, &error_msg, &line, &col ); - } - else - { - error = !setContent( &in_file, &error_msg, &line, - &col ); - } - if( error ) - { - printf( "at line %d column %d: %s\n", line, col, - error_msg.toAscii().constData() ); - QMessageBox::critical( NULL, songEditor::tr( "Error in " - "multimedia-project" ), - songEditor::tr( "The multimedia-" - "project %1 seems to contain errors. LMMS " - "will try its best to recover as much " - "data as possible data from this file." - ).arg( _in_file_name ) ); - return; - } - in_file.close(); + loadData( qUncompress( inFile.readAll() ), _fileName ); } else { - if( !setContent( _in_file_name, &error_msg, &line, &col ) ) - { - printf( "multimediaProject: error parsing XML-data " - "directly given to constructor!\n" ); - return; - } + loadData( inFile.readAll(), _fileName ); } +} - QDomElement root = documentElement(); - m_type = type( root.attribute( "type" ) ); - m_head = root.elementsByTagName( "head" ).item( 0 ).toElement(); - if( _upgrade && root.hasAttribute( "creatorversion" ) && - root.attribute( "creatorversion" ) != LMMS_VERSION ) - { - upgrade(); - } - m_content = root.elementsByTagName( typeName( m_type ) ). - item( 0 ).toElement(); + +multimediaProject::multimediaProject( const QByteArray & _data ) : + QDomDocument(), + m_content(), + m_head() +{ + loadData( _data, "" ); } @@ -187,26 +144,26 @@ QString multimediaProject::nameWithExtension( const QString & _fn ) const if( configManager::inst()->value( "app", "nommpz" ).toInt() == 0 ) { - return( _fn + ".mmpz" ); + return _fn + ".mmpz"; } - return( _fn + ".mmp" ); + return _fn + ".mmp"; } break; case SongProjectTemplate: if( _fn.section( '.',-1 ) != "mpt" ) { - return( _fn + ".mpt" ); + return _fn + ".mpt"; } break; case InstrumentTrackSettings: if( _fn.section( '.', -1 ) != "xpf" ) { - return( _fn + ".xpf" ); + return _fn + ".xpf"; } break; default: ; } - return( _fn ); + return _fn; } @@ -236,7 +193,7 @@ bool multimediaProject::writeFile( const QString & _fn ) "the file and try " "again." ).arg( fn ) ); - return( FALSE ); + return false; } QString xml = "\n" + toString( 2 ); if( fn.section( '.', -1 ) == "mmpz" ) @@ -249,17 +206,7 @@ bool multimediaProject::writeFile( const QString & _fn ) } outfile.close(); - return( TRUE ); -} - - - - -multimediaProject::ProjectTypes multimediaProject::typeOfFile( - const QString & _fn ) -{ - multimediaProject m( _fn, TRUE, FALSE ); - return( m.type() ); + return true; } @@ -272,15 +219,14 @@ multimediaProject::ProjectTypes multimediaProject::type( { if( s_types[i].m_name == _type_name ) { - return( static_cast( - i ) ); + return static_cast( i ); } } if( _type_name == "channelsettings" ) { - return( multimediaProject::InstrumentTrackSettings ); + return multimediaProject::InstrumentTrackSettings; } - return( UnknownType ); + return UnknownType; } @@ -290,9 +236,9 @@ QString multimediaProject::typeName( ProjectTypes _project_type ) { if( _project_type >= UnknownType && _project_type < NumProjectTypes ) { - return( s_types[_project_type].m_name ); + return s_types[_project_type].m_name; } - return( s_types[UnknownType].m_name ); + return s_types[UnknownType].m_name; } @@ -463,7 +409,7 @@ void multimediaProject::upgrade( void ) } else if( !el.hasAttribute( "chord-enabled" ) ) { - el.setAttribute( "chord-enabled", TRUE ); + el.setAttribute( "chord-enabled", true ); el.setAttribute( "arp-enabled", el.attribute( "arpdir" ).toInt() != 0 ); } @@ -735,4 +681,32 @@ void multimediaProject::upgrade( void ) -#endif +void multimediaProject::loadData( const QByteArray & _data, + const QString & _sourceFile ) +{ + QString errorMsg; + int line, col; + if( !setContent( _data, &errorMsg, &line, &col ) ) + { + qWarning() << "at line" << line << "column" << errorMsg; + QMessageBox::critical( NULL, songEditor::tr( "Error in file" ), + songEditor::tr( "The file %1 seems to contain errors " + "and therefore can't be loaded." ). + arg( _sourceFile ) ); + return; + } + + QDomElement root = documentElement(); + m_type = type( root.attribute( "type" ) ); + m_head = root.elementsByTagName( "head" ).item( 0 ).toElement(); + + if( root.hasAttribute( "creatorversion" ) && + root.attribute( "creatorversion" ) != LMMS_VERSION ) + { + upgrade(); + } + + m_content = root.elementsByTagName( typeName( m_type ) ). + item( 0 ).toElement(); +} + diff --git a/src/core/track.cpp b/src/core/track.cpp index ccc1daff7..fb62a5982 100644 --- a/src/core/track.cpp +++ b/src/core/track.cpp @@ -488,7 +488,7 @@ void trackContentObjectView::dropEvent( QDropEvent * _de ) { // value contains our XML-data so simply create a // multimediaProject which does the rest for us... - multimediaProject mmp( value, false ); + multimediaProject mmp( value.toUtf8() ); // at least save position before getting to moved to somewhere // the user doesn't expect... midiTime pos = m_tco->startPosition(); @@ -1084,7 +1084,7 @@ void trackContentWidget::dropEvent( QDropEvent * _de ) // value contains our XML-data so simply create a // multimediaProject which does the rest for us... - multimediaProject mmp( value, false ); + multimediaProject mmp( value.toUtf8() ); // at least save position before getting moved to somewhere // the user doesn't expect... tco->restoreState( mmp.content().firstChild().toElement() ); @@ -1242,7 +1242,8 @@ void trackContentWidget::undoStep( journalEntry & _je ) trackContentObject * tco = getTrack()->createTCO( midiTime( 0 ) ); multimediaProject mmp( - _je.data().toMap()["state"].toString(), false ); + _je.data().toMap()["state"]. + toString().toUtf8() ); tco->restoreState( mmp.content().firstChild().toElement() ); break; @@ -2277,7 +2278,7 @@ void trackView::dropEvent( QDropEvent * _de ) { // value contains our XML-data so simply create a // multimediaProject which does the rest for us... - multimediaProject mmp( value, false ); + multimediaProject mmp( value.toUtf8() ); engine::getMixer()->lock(); m_track->restoreState( mmp.content().firstChild().toElement() ); engine::getMixer()->unlock(); diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp index a23ed5654..468891bec 100644 --- a/src/gui/piano_roll.cpp +++ b/src/gui/piano_roll.cpp @@ -3376,7 +3376,7 @@ void pianoRoll::pasteNotes( void ) if( !value.isEmpty() ) { - multimediaProject mmp( value, false ); + multimediaProject mmp( value.toUtf8() ); QDomNodeList list = mmp.elementsByTagName( note::classNodeName() ); diff --git a/src/gui/track_container_view.cpp b/src/gui/track_container_view.cpp index 4e4e00c4d..7a55b48be 100644 --- a/src/gui/track_container_view.cpp +++ b/src/gui/track_container_view.cpp @@ -326,7 +326,7 @@ void trackContainerView::undoStep( journalEntry & _je ) case RemoveTrack: { multimediaProject mmp( - _je.data().toMap()["state"].toString(), false ); + _je.data().toMap()["state"].toString().utf8() ); track::create( mmp.content().firstChild().toElement(), m_tc ); break; @@ -414,7 +414,7 @@ void trackContainerView::dropEvent( QDropEvent * _de ) } else if( type.left( 6 ) == "track_" ) { - multimediaProject mmp( value, false ); + multimediaProject mmp( value.toUtf8() ); track::create( mmp.content().firstChild().toElement(), m_tc ); _de->accept(); } diff --git a/src/gui/widgets/envelope_and_lfo_view.cpp b/src/gui/widgets/envelope_and_lfo_view.cpp index afdd89079..5a7bc4253 100644 --- a/src/gui/widgets/envelope_and_lfo_view.cpp +++ b/src/gui/widgets/envelope_and_lfo_view.cpp @@ -398,7 +398,7 @@ void envelopeAndLFOView::dropEvent( QDropEvent * _de ) } else if( type == QString( "tco_%1" ).arg( track::SampleTrack ) ) { - multimediaProject mmp( value, FALSE ); + multimediaProject mmp( value.toUtf8() ); m_params->m_userWave.setAudioFile( mmp.content().firstChild().toElement(). attribute( "src" ) );