From 6cf2d8380888ebedd3bdc2b10a6b02958c065877 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 12 Aug 2009 07:14:44 -0700 Subject: [PATCH] made CLI rendering smoother Suppressed a message box that would pop up in command line interface causing a crash and made lmms act properly when a rendering plugin fails. Need to figure out how to terminate program in project_renderer line 222. --- include/project_renderer.h | 7 +++++++ src/core/audio/audio_file_device.cpp | 31 ++++++++++++++++++---------- src/core/main.cpp | 1 + src/core/project_renderer.cpp | 9 ++++++++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/include/project_renderer.h b/include/project_renderer.h index ca7aac2a4..f4629c57e 100644 --- a/include/project_renderer.h +++ b/include/project_renderer.h @@ -28,6 +28,7 @@ #include "audio_file_device.h" #include "lmmsconfig.h" +class QTimer; class projectRenderer : public QThread { @@ -83,6 +84,10 @@ public: static ExportFileFormats getFileFormatFromExtension( const QString & _ext ); + void setConsoleUpdateTimer(QTimer * t) + { + m_consoleUpdateTimer = t; + } public slots: void startProcessing( void ); @@ -105,6 +110,8 @@ private: volatile int m_progress; volatile bool m_abort; + QTimer * m_consoleUpdateTimer; + } ; diff --git a/src/core/audio/audio_file_device.cpp b/src/core/audio/audio_file_device.cpp index 2102b5513..c8b2213ab 100644 --- a/src/core/audio/audio_file_device.cpp +++ b/src/core/audio/audio_file_device.cpp @@ -25,9 +25,11 @@ #include +#include #include "audio_file_device.h" #include "export_project_dialog.h" +#include "engine.h" audioFileDevice::audioFileDevice( const sample_rate_t _sample_rate, @@ -51,17 +53,24 @@ audioFileDevice::audioFileDevice( const sample_rate_t _sample_rate, if( m_outputFile.open( QFile::WriteOnly | QFile::Truncate ) == FALSE ) { - QMessageBox::critical( NULL, - exportProjectDialog::tr( "Could not open file" ), - exportProjectDialog::tr( "Could not open file %1 " - "for writing.\nPlease make " - "sure you have write-" - "permission to the file and " - "the directory containing the " - "file and try again!" ).arg( - _file ), - QMessageBox::Ok, - QMessageBox::NoButton ); + QString warningMessage = exportProjectDialog::tr( + "Could not open file %1 " + "for writing.\nPlease make " + "sure you have write-" + "permission to the file and " + "the directory containing the " + "file and try again!" ).arg( _file ); + if( engine::hasGUI() ){ + QMessageBox::critical( NULL, + exportProjectDialog::tr( "Could not open file" ), + warningMessage, + QMessageBox::Ok, + QMessageBox::NoButton ); + } + else + { + qWarning() << warningMessage; + } } } diff --git a/src/core/main.cpp b/src/core/main.cpp index bbc01cdd1..50c85b506 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -499,6 +499,7 @@ int main( int argc, char * * argv ) // timer for progress-updates QTimer * t = new QTimer( r ); + r->setConsoleUpdateTimer(t); r->connect( t, SIGNAL( timeout() ), SLOT( updateConsoleProgress() ) ); t->start( 200 ); diff --git a/src/core/project_renderer.cpp b/src/core/project_renderer.cpp index 69084bb84..a5211c24d 100644 --- a/src/core/project_renderer.cpp +++ b/src/core/project_renderer.cpp @@ -24,6 +24,7 @@ #include +#include #include "project_renderer.h" #include "song.h" @@ -214,6 +215,14 @@ void projectRenderer::updateConsoleProgress( void ) char buf[80]; char prog[cols+1]; + if( m_fileDev == NULL ){ + qWarning("Error occured. Aborting render."); + m_consoleUpdateTimer->stop(); + delete m_consoleUpdateTimer; + // TODO: kill the program. I can't figure out how to do it... + return; + } + for( int i = 0; i < cols; ++i ) { prog[i] = ( i*100/cols <= m_progress ? '-' : ' ' );