Add support for upgrading to standard output
Useful for me to initially import LMMS presets for use in lmms-lv2.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* mmp.h - class for reading and writing multimedia-project-files
|
||||
*
|
||||
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
* Copyright (c) 2012-2013 Paul Giblock <p/at/pgiblock.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -27,6 +28,7 @@
|
||||
#define _MMP_H
|
||||
|
||||
#include <QtXml/QDomDocument>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "export.h"
|
||||
#include "lmms_basics.h"
|
||||
@@ -59,6 +61,7 @@ public:
|
||||
|
||||
QString nameWithExtension( const QString & _fn ) const;
|
||||
|
||||
void write( QTextStream & _strm );
|
||||
bool writeFile( const QString & _fn );
|
||||
|
||||
inline QDomElement & content()
|
||||
|
||||
@@ -168,7 +168,8 @@ int main( int argc, char * * argv )
|
||||
"-x, --oversampling <value> specify oversampling\n"
|
||||
" possible values: 1, 2, 4, 8\n"
|
||||
" default: 2\n"
|
||||
"-u, --upgrade <in> <out> upgrade file <in> and save as <out>\n"
|
||||
"-u, --upgrade <in> [out] upgrade file <in> and save as <out>\n"
|
||||
" standard out is used if no output file is specifed\n"
|
||||
"-d, --dump <in> dump XML of compressed file <in>\n"
|
||||
"-v, --version show version information and exit.\n"
|
||||
"-h, --help show this usage information and exit.\n\n",
|
||||
@@ -179,9 +180,15 @@ int main( int argc, char * * argv )
|
||||
QString( argv[i] ) == "-u" ) )
|
||||
{
|
||||
multimediaProject mmp( QString( argv[i + 1] ) );
|
||||
if (argc > i+1)
|
||||
if (argc > i+2)
|
||||
{
|
||||
mmp.writeFile(argv[i + 2]);
|
||||
mmp.writeFile( argv[i + 2] );
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream ts( stdout );
|
||||
mmp.write( ts );
|
||||
fflush( stdout );
|
||||
}
|
||||
return( EXIT_SUCCESS );
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ QString multimediaProject::nameWithExtension( const QString & _fn ) const
|
||||
|
||||
|
||||
|
||||
bool multimediaProject::writeFile( const QString & _fn )
|
||||
void multimediaProject::write( QTextStream & _strm )
|
||||
{
|
||||
if( type() == SongProject || type() == SongProjectTemplate
|
||||
|| type() == InstrumentTrackSettings )
|
||||
@@ -173,7 +173,14 @@ bool multimediaProject::writeFile( const QString & _fn )
|
||||
cleanMetaNodes( documentElement() );
|
||||
}
|
||||
|
||||
save(_strm, 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool multimediaProject::writeFile( const QString & _fn )
|
||||
{
|
||||
QString fn = nameWithExtension( _fn );
|
||||
QFile outfile( fn );
|
||||
if( !outfile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
|
||||
@@ -191,14 +198,18 @@ bool multimediaProject::writeFile( const QString & _fn )
|
||||
).arg( fn ) );
|
||||
return false;
|
||||
}
|
||||
QString xml = toString( 2 );
|
||||
|
||||
if( fn.section( '.', -1 ) == "mmpz" )
|
||||
{
|
||||
QString xml;
|
||||
QTextStream ts( &xml );
|
||||
write( ts );
|
||||
outfile.write( qCompress( xml.toUtf8() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream( &outfile ) << xml;
|
||||
QTextStream ts( &outfile );
|
||||
write( ts );
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user