Start refactoring main()
This commit is contained in:
@@ -167,27 +167,29 @@ int main( int argc, char * * argv )
|
||||
|
||||
disable_denormals();
|
||||
|
||||
bool core_only = false;
|
||||
bool coreOnly = false;
|
||||
bool fullscreen = true;
|
||||
bool exit_after_import = false;
|
||||
bool allow_root = false;
|
||||
bool render_loop = false;
|
||||
QString file_to_load, file_to_save, file_to_import, render_out, profilerOutputFile;
|
||||
bool exitAfterImport = false;
|
||||
bool allowRoot = false;
|
||||
bool renderLoop = false;
|
||||
QString fileToLoad, fileToImport, renderOut, profilerOutputFile;
|
||||
|
||||
// first of two command-line parsing stages
|
||||
for( int i = 1; i < argc; ++i )
|
||||
{
|
||||
if( argc > i && ( ( QString( argv[i] ) == "--render" ||
|
||||
QString( argv[i] ) == "-r" ) ||
|
||||
( QString( argv[i] ) == "--help" ||
|
||||
QString( argv[i] ) == "-h" ) ) )
|
||||
QString arg = argv[i];
|
||||
|
||||
if( arg == "--help" || arg == "-h" ||
|
||||
arg == "--version" || arg == "-v" ||
|
||||
arg == "--render" || arg == "-r" )
|
||||
{
|
||||
core_only = true;
|
||||
coreOnly = true;
|
||||
}
|
||||
else if( argc > i && ( QString( argv[i] ) == "--allowroot" ) )
|
||||
else if( arg == "--allowroot" )
|
||||
{
|
||||
allow_root = true;
|
||||
allowRoot = true;
|
||||
}
|
||||
else if( argc > i && QString( argv[i] ) == "-geometry" )
|
||||
else if( arg == "-geometry" )
|
||||
{
|
||||
// option -geometry is filtered by Qt later,
|
||||
// so we need to check its presence now to
|
||||
@@ -198,14 +200,14 @@ int main( int argc, char * * argv )
|
||||
}
|
||||
|
||||
#ifndef LMMS_BUILD_WIN32
|
||||
if ( ( getuid() == 0 || geteuid() == 0 ) && !allow_root )
|
||||
if ( ( getuid() == 0 || geteuid() == 0 ) && !allowRoot )
|
||||
{
|
||||
printf("LMMS cannot be run as root.\nUse \"--allowroot\" to override.\n\n");
|
||||
return(EXIT_FAILURE);
|
||||
printf( "LMMS cannot be run as root.\nUse \"--allowroot\" to override.\n\n" );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
QCoreApplication * app = core_only ?
|
||||
QCoreApplication * app = coreOnly ?
|
||||
new QCoreApplication( argc, argv ) :
|
||||
new QApplication( argc, argv ) ;
|
||||
|
||||
@@ -214,26 +216,25 @@ int main( int argc, char * * argv )
|
||||
ProjectRenderer::Depth_16Bit );
|
||||
ProjectRenderer::ExportFileFormats eff = ProjectRenderer::WaveFile;
|
||||
|
||||
|
||||
// second of two command-line parsing stages
|
||||
for( int i = 1; i < argc; ++i )
|
||||
{
|
||||
if( QString( argv[i] ) == "--version" ||
|
||||
QString( argv[i] ) == "-v" )
|
||||
QString arg = argv[i];
|
||||
|
||||
if( arg == "--version" || arg == "-v" )
|
||||
{
|
||||
printVersion(argv[0]);
|
||||
return( EXIT_SUCCESS );
|
||||
printVersion( argv[0] );
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if( argc > i && ( QString( argv[i] ) == "--help" ||
|
||||
QString( argv[i] ) == "-h" ) )
|
||||
else if( argc > i && ( arg == "--help" || arg == "-h" ) )
|
||||
{
|
||||
printHelp();
|
||||
return( EXIT_SUCCESS );
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if( argc > i+1 && ( QString( argv[i] ) == "--upgrade" ||
|
||||
QString( argv[i] ) == "-u" ) )
|
||||
else if( argc > i+1 && ( arg == "--upgrade" || arg == "-u" ) )
|
||||
{
|
||||
DataFile dataFile( QString::fromLocal8Bit( argv[i + 1] ) );
|
||||
if (argc > i+2)
|
||||
if( argc > i+2 )
|
||||
{
|
||||
dataFile.writeFile( QString::fromLocal8Bit( argv[i + 2] ) );
|
||||
}
|
||||
@@ -243,51 +244,48 @@ int main( int argc, char * * argv )
|
||||
dataFile.write( ts );
|
||||
fflush( stdout );
|
||||
}
|
||||
return( EXIT_SUCCESS );
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if( argc > i && QString( argv[i] ) == "--allowroot" )
|
||||
else if( argc > i && arg == "--allowroot" )
|
||||
{
|
||||
// Ignore, processed earlier
|
||||
#ifdef LMMS_BUILD_WIN32
|
||||
if ( allow_root )
|
||||
if( allowRoot )
|
||||
{
|
||||
printf( "\nOption \"--allowroot\" will be ignored on this platform.\n\n" );
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
else if( argc > i && ( QString( argv[i] ) == "--dump" ||
|
||||
QString( argv[i] ) == "-d" ) )
|
||||
else if( argc > i && ( arg == "--dump" || arg == "-d" ) )
|
||||
{
|
||||
QFile f( QString::fromLocal8Bit( argv[i + 1] ) );
|
||||
f.open( QIODevice::ReadOnly );
|
||||
QString d = qUncompress( f.readAll() );
|
||||
printf( "%s\n", d.toUtf8().constData() );
|
||||
return( EXIT_SUCCESS );
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if( argc > i && ( QString( argv[i] ) == "--render" ||
|
||||
QString( argv[i] ) == "-r" ) )
|
||||
else if( argc > i && ( arg == "--render" || arg == "-r" ) )
|
||||
{
|
||||
file_to_load = QString::fromLocal8Bit( argv[i + 1] );
|
||||
render_out = baseName( file_to_load ) + ".";
|
||||
fileToLoad = QString::fromLocal8Bit( argv[i + 1] );
|
||||
renderOut = baseName( fileToLoad ) + ".";
|
||||
++i;
|
||||
}
|
||||
else if( argc > i && ( QString( argv[i] ) == "--loop-mode" ||
|
||||
QString( argv[i] ) == "-l" ) )
|
||||
else if( argc > i && ( arg == "--loop-mode" || arg == "-l" ) )
|
||||
{
|
||||
render_loop = true;
|
||||
renderLoop = true;
|
||||
}
|
||||
else if( argc > i && ( QString( argv[i] ) == "--output" ||
|
||||
QString( argv[i] ) == "-o" ) )
|
||||
else if( argc > i && ( arg == "--output" || arg == "-o" ) )
|
||||
{
|
||||
render_out = baseName( QString::fromLocal8Bit( argv[i + 1] ) ) + ".";
|
||||
renderOut = baseName( QString::fromLocal8Bit( argv[i + 1] ) ) + ".";
|
||||
++i;
|
||||
}
|
||||
else if( argc > i &&
|
||||
( QString( argv[i] ) == "--format" ||
|
||||
QString( argv[i] ) == "-f" ) )
|
||||
else if( argc > i && ( arg == "--format" || arg == "-f" ) )
|
||||
{
|
||||
const QString ext = QString( argv[i + 1] );
|
||||
|
||||
if( ext == "wav" )
|
||||
{
|
||||
eff = ProjectRenderer::WaveFile;
|
||||
@@ -302,13 +300,11 @@ int main( int argc, char * * argv )
|
||||
{
|
||||
printf( "\nInvalid output format %s.\n\n"
|
||||
"Try \"%s --help\" for more information.\n\n", argv[i + 1], argv[0] );
|
||||
return( EXIT_FAILURE );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
else if( argc > i &&
|
||||
( QString( argv[i] ) == "--samplerate" ||
|
||||
QString( argv[i] ) == "-s" ) )
|
||||
else if( argc > i && ( arg == "--samplerate" || arg == "-s" ) )
|
||||
{
|
||||
sample_rate_t sr = QString( argv[i + 1] ).toUInt();
|
||||
if( sr >= 44100 && sr <= 192000 )
|
||||
@@ -319,15 +315,14 @@ int main( int argc, char * * argv )
|
||||
{
|
||||
printf( "\nInvalid samplerate %s.\n\n"
|
||||
"Try \"%s --help\" for more information.\n\n", argv[i + 1], argv[0] );
|
||||
return( EXIT_FAILURE );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
else if( argc > i &&
|
||||
( QString( argv[i] ) == "--bitrate" ||
|
||||
QString( argv[i] ) == "-b" ) )
|
||||
else if( argc > i && ( arg == "--bitrate" || arg == "-b" ) )
|
||||
{
|
||||
int br = QString( argv[i + 1] ).toUInt();
|
||||
|
||||
if( br >= 64 && br <= 384 )
|
||||
{
|
||||
os.bitrate = br;
|
||||
@@ -336,21 +331,18 @@ int main( int argc, char * * argv )
|
||||
{
|
||||
printf( "\nInvalid bitrate %s.\n\n"
|
||||
"Try \"%s --help\" for more information.\n\n", argv[i + 1], argv[0] );
|
||||
return( EXIT_FAILURE );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
else if ( argc > i &&
|
||||
( QString( argv[i] ) =="--float" ||
|
||||
QString( argv[i] ) == "-a" ) )
|
||||
else if( argc > i && ( arg =="--float" || arg == "-a" ) )
|
||||
{
|
||||
os.depth = ProjectRenderer::Depth_32Bit;
|
||||
}
|
||||
else if( argc > i &&
|
||||
( QString( argv[i] ) == "--interpolation" ||
|
||||
QString( argv[i] ) == "-i" ) )
|
||||
else if( argc > i && ( arg == "--interpolation" || arg == "-i" ) )
|
||||
{
|
||||
const QString ip = QString( argv[i + 1] );
|
||||
|
||||
if( ip == "linear" )
|
||||
{
|
||||
qs.interpolation = Mixer::qualitySettings::Interpolation_Linear;
|
||||
@@ -371,15 +363,14 @@ int main( int argc, char * * argv )
|
||||
{
|
||||
printf( "\nInvalid interpolation method %s.\n\n"
|
||||
"Try \"%s --help\" for more information.\n\n", argv[i + 1], argv[0] );
|
||||
return( EXIT_FAILURE );
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
else if( argc > i &&
|
||||
( QString( argv[i] ) == "--oversampling" ||
|
||||
QString( argv[i] ) == "-x" ) )
|
||||
else if( argc > i && ( arg == "--oversampling" || arg == "-x" ) )
|
||||
{
|
||||
int o = QString( argv[i + 1] ).toUInt();
|
||||
|
||||
switch( o )
|
||||
{
|
||||
case 1:
|
||||
@@ -401,18 +392,17 @@ int main( int argc, char * * argv )
|
||||
}
|
||||
++i;
|
||||
}
|
||||
else if( argc > i &&
|
||||
( QString( argv[i] ) == "--import" ) )
|
||||
else if( argc > i && ( arg == "--import" ) )
|
||||
{
|
||||
file_to_import = QString::fromLocal8Bit( argv[i+1] );
|
||||
fileToImport = QString::fromLocal8Bit( argv[i + 1] );
|
||||
++i;
|
||||
// exit after import? (only for debugging)
|
||||
if( argc > i && QString( argv[i+1] ) == "-e" )
|
||||
if( argc > i && QString( argv[i + 1] ) == "-e" )
|
||||
{
|
||||
exit_after_import = true;
|
||||
exitAfterImport = true;
|
||||
}
|
||||
}
|
||||
else if( argc > i && ( QString( argv[i] ) == "--profile" || QString( argv[i] ) == "-p" ) )
|
||||
else if( argc > i && ( arg == "--profile" || arg == "-p" ) )
|
||||
{
|
||||
profilerOutputFile = QString::fromLocal8Bit( argv[i+1] );
|
||||
++i;
|
||||
@@ -425,7 +415,7 @@ int main( int argc, char * * argv )
|
||||
"Try \"%s --help\" for more information.\n\n", argv[i], argv[0] );
|
||||
return( EXIT_FAILURE );
|
||||
}
|
||||
file_to_load = QString::fromLocal8Bit( argv[i] );
|
||||
fileToLoad = QString::fromLocal8Bit( argv[i] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,7 +465,39 @@ int main( int argc, char * * argv )
|
||||
}
|
||||
#endif
|
||||
|
||||
if( render_out.isEmpty() )
|
||||
// if we have an output file for rendering, just render the song
|
||||
// without starting the GUI
|
||||
if( !renderOut.isEmpty() )
|
||||
{
|
||||
Engine::init( true );
|
||||
|
||||
printf( "loading project...\n" );
|
||||
Engine::getSong()->loadProject( fileToLoad );
|
||||
printf( "done\n" );
|
||||
|
||||
Engine::getSong()->setExportLoop( renderLoop );
|
||||
|
||||
// create renderer
|
||||
QString extension = ( eff == ProjectRenderer::WaveFile ) ? "wav" : "ogg";
|
||||
ProjectRenderer * r = new ProjectRenderer( qs, os, eff, renderOut + extension );
|
||||
QCoreApplication::instance()->connect( r,
|
||||
SIGNAL( finished() ), SLOT( quit() ) );
|
||||
|
||||
// timer for progress-updates
|
||||
QTimer * t = new QTimer( r );
|
||||
r->connect( t, SIGNAL( timeout() ),
|
||||
SLOT( updateConsoleProgress() ) );
|
||||
t->start( 200 );
|
||||
|
||||
if( profilerOutputFile.isEmpty() == false )
|
||||
{
|
||||
Engine::mixer()->profiler().setOutputFile( profilerOutputFile );
|
||||
}
|
||||
|
||||
// start now!
|
||||
r->startProcessing();
|
||||
}
|
||||
else // otherwise, start the GUI
|
||||
{
|
||||
new GuiApplication();
|
||||
|
||||
@@ -492,32 +514,33 @@ int main( int argc, char * * argv )
|
||||
"Do you want to recover the project of this session?" ),
|
||||
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes )
|
||||
{
|
||||
file_to_load = recoveryFile;
|
||||
fileToLoad = recoveryFile;
|
||||
}
|
||||
|
||||
// we try to load given file
|
||||
if( !file_to_load.isEmpty() )
|
||||
if( !fileToLoad.isEmpty() )
|
||||
{
|
||||
gui->mainWindow()->show();
|
||||
if( fullscreen )
|
||||
{
|
||||
gui->mainWindow()->showMaximized();
|
||||
}
|
||||
if( file_to_load == recoveryFile )
|
||||
|
||||
if( fileToLoad == recoveryFile )
|
||||
{
|
||||
Engine::getSong()->createNewProjectFromTemplate( file_to_load );
|
||||
Engine::getSong()->createNewProjectFromTemplate( fileToLoad );
|
||||
}
|
||||
else
|
||||
{
|
||||
Engine::getSong()->loadProject( file_to_load );
|
||||
Engine::getSong()->loadProject( fileToLoad );
|
||||
}
|
||||
}
|
||||
else if( !file_to_import.isEmpty() )
|
||||
else if( !fileToImport.isEmpty() )
|
||||
{
|
||||
ImportFilter::import( file_to_import, Engine::getSong() );
|
||||
if( exit_after_import )
|
||||
ImportFilter::import( fileToImport, Engine::getSong() );
|
||||
if( exitAfterImport )
|
||||
{
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
gui->mainWindow()->show();
|
||||
@@ -538,38 +561,6 @@ int main( int argc, char * * argv )
|
||||
gui->mainWindow()->showMaximized();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// we're going to render our song
|
||||
Engine::init( true );
|
||||
|
||||
printf( "loading project...\n" );
|
||||
Engine::getSong()->loadProject( file_to_load );
|
||||
printf( "done\n" );
|
||||
|
||||
Engine::getSong()->setExportLoop(render_loop);
|
||||
|
||||
// create renderer
|
||||
QString extension = ( eff == ProjectRenderer::WaveFile ) ? "wav" : "ogg";
|
||||
ProjectRenderer * r = new ProjectRenderer( qs, os, eff, render_out + extension );
|
||||
QCoreApplication::instance()->connect( r,
|
||||
SIGNAL( finished() ), SLOT( quit() ) );
|
||||
|
||||
// timer for progress-updates
|
||||
QTimer * t = new QTimer( r );
|
||||
r->connect( t, SIGNAL( timeout() ),
|
||||
SLOT( updateConsoleProgress() ) );
|
||||
t->start( 200 );
|
||||
|
||||
if( profilerOutputFile.isEmpty() == false )
|
||||
{
|
||||
Engine::mixer()->profiler().setOutputFile( profilerOutputFile );
|
||||
}
|
||||
|
||||
// start now!
|
||||
r->startProcessing();
|
||||
}
|
||||
|
||||
const int ret = app->exec();
|
||||
@@ -578,5 +569,5 @@ int main( int argc, char * * argv )
|
||||
// cleanup memory managers
|
||||
MemoryManager::cleanup();
|
||||
|
||||
return( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user