~ubuntu-branches/ubuntu/dapper/lmms/dapper

« back to all changes in this revision

Viewing changes to src/core/export_project_dialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ragwitz
  • Date: 2005-12-22 16:22:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051222162250-key3p7x0212jy6dn
Tags: 0.1.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * export_project_dialog.cpp - implementation of dialog for exporting project
3
3
 *
4
 
 * Linux MultiMedia Studio
5
 
 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox@users.sourceforge.net>
 
4
 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
5
 * 
 
6
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
6
7
 *
7
8
 * This program is free software; you can redistribute it and/or
8
9
 * modify it under the terms of the GNU General Public
31
32
#include <QProgressBar>
32
33
#include <QComboBox>
33
34
#include <QCheckBox>
34
 
#include <QTimer>
35
35
#include <QLabel>
36
36
#include <QPushButton>
37
37
#include <QCloseEvent>
 
38
#include <QApplication>
38
39
 
39
40
#else
40
41
 
43
44
#include <qprogressbar.h>
44
45
#include <qcombobox.h>
45
46
#include <qcheckbox.h>
46
 
#include <qtimer.h>
47
47
#include <qlabel.h>
48
48
#include <qpushbutton.h>
 
49
#include <qapplication.h>
49
50
 
50
51
#endif
51
52
 
52
53
 
53
54
#include "export_project_dialog.h"
54
55
#include "song_editor.h"
 
56
#include "lmms_main_win.h"
55
57
#include "embed.h"
56
58
 
57
59
#include "audio_file_wave.h"
58
60
#include "audio_file_ogg.h"
59
61
 
60
62
 
 
63
extern QString file_to_render;
 
64
 
 
65
 
61
66
fileEncodeDevice fileEncodeDevices[] =
62
67
{
63
68
 
128
133
        QDialog( _parent ),
129
134
        m_fileName( _file_name ),
130
135
        m_hourglassLbl( NULL ),
131
 
        m_exportProgressBar( NULL ),
132
 
        m_deleteFile( FALSE ),
133
 
        m_oldProgressVal( -1 )
 
136
        m_deleteFile( FALSE )
134
137
{
135
138
#ifdef QT4
136
139
        m_fileType = getFileTypeFromExtension( "." +
311
314
        {
312
315
                if( fileEncodeDevices[idx].m_fileType == m_fileType )
313
316
                {
314
 
                        bool success_ful = FALSE;
315
 
                        audioDevice * dev = fileEncodeDevices[idx].m_getDevInst(
 
317
                        break;
 
318
                }
 
319
                ++idx;
 
320
        }
 
321
 
 
322
        if( fileEncodeDevices[idx].m_fileType == NULL_FILE )
 
323
        {
 
324
                return;
 
325
        }
 
326
 
 
327
        bool success_ful = FALSE;
 
328
        audioFileDevice * dev = fileEncodeDevices[idx].m_getDevInst(
316
329
                                                        DEFAULT_SAMPLE_RATE,
317
330
                                                        DEFAULT_CHANNELS,
318
331
                                                        success_ful,
322
335
                                        m_kbpsCombo->currentText().toInt() - 64,
323
336
                                        m_kbpsCombo->currentText().toInt() + 64
324
337
                                );
325
 
                        if( success_ful == FALSE )
326
 
                        {
327
 
                                QMessageBox::information( this,
 
338
        if( success_ful == FALSE )
 
339
        {
 
340
                QMessageBox::information( this,
328
341
                                        tr( "Export failed" ),
329
342
                                        tr( "The project-export failed, "
330
343
                                                "because the output-file/-"
333
346
                                                "access to the selected "
334
347
                                                "file/device!" ),
335
348
                                                        QMessageBox::Ok );
336
 
                                return;
337
 
                        }
338
 
                        mixer::inst()->pause();
339
 
                        mixer::inst()->setAudioDevice( dev,
340
 
                                                        m_hqmCb->isChecked() );
341
 
                        songEditor::inst()->startExport();
342
 
                        mixer::inst()->play();
343
 
                        break;
344
 
                }
345
 
                ++idx;
346
 
        }
347
 
 
348
 
        if( fileEncodeDevices[idx].m_fileType == NULL_FILE )
349
 
        {
350
349
                return;
351
350
        }
352
351
 
 
352
 
353
353
        setWindowTitle( tr( "Exporting project to %1" ).arg(
354
354
                                        QFileInfo( m_fileName ).fileName() ) );
355
355
 
378
378
 
379
379
        m_cancelBtn->move( CANCEL_X_WHILE_EXPORT, CANCEL_Y_WHILE_EXPORT );
380
380
 
381
 
        m_progressBarUpdateTimer = new QTimer( this );
382
 
        connect( m_progressBarUpdateTimer, SIGNAL( timeout() ), this,
383
 
                                                SLOT( redrawProgressBar() ) );
384
 
        m_progressBarUpdateTimer->start( 100 );
385
 
 
 
381
 
 
382
 
 
383
        mixer::inst()->setAudioDevice( dev, m_hqmCb->isChecked() );
 
384
        songEditor::inst()->startExport();
 
385
 
 
386
 
 
387
        songEditor::playPos & pp = songEditor::inst()->getPlayPos(
 
388
                                                        songEditor::PLAY_SONG );
 
389
 
 
390
        while( songEditor::inst()->exportDone() == FALSE &&
 
391
                                songEditor::inst()->exporting() == TRUE )
 
392
        {
 
393
                dev->processNextBuffer();
 
394
                int pval = pp * 100 /
 
395
                        ( ( songEditor::inst()->lengthInTacts() + 1 ) * 64 );
 
396
#ifdef QT4
 
397
                m_exportProgressBar->setValue( pval );
 
398
#else
 
399
                m_exportProgressBar->setProgress( pval );
 
400
#endif
 
401
                // update lmms-main-win-caption
 
402
                lmmsMainWin::inst()->setWindowTitle( tr( "Rendering:" ) + " " +
 
403
                                                QString::number( pval ) + "%" );
 
404
                // process paint-events etc.
 
405
                qApp->processEvents();
 
406
        }
 
407
 
 
408
        // if m_deleteFile == TRUE, user aborted export and finalization-
 
409
        // routines were already called, so we only need to call them if
 
410
        // export went through without any problems
 
411
        if( m_deleteFile == FALSE )
 
412
        {
 
413
                finishProjectExport();
 
414
        }
386
415
}
387
416
 
388
417
 
397
426
                abortProjectExport();
398
427
                return;
399
428
        }
 
429
}
 
430
 
 
431
 
 
432
 
 
433
 
 
434
// called whenever there's a reason for aborting song-export (like user-input)
 
435
void exportProjectDialog::abortProjectExport( void )
 
436
{
 
437
        m_deleteFile = TRUE;
 
438
 
 
439
        finishProjectExport();
 
440
}
 
441
 
 
442
 
 
443
 
 
444
 
 
445
void exportProjectDialog::finishProjectExport( void )
 
446
{
 
447
        mixer::inst()->restoreAudioDevice();
400
448
 
401
449
        // if the user aborted export-process, the file has to be deleted
402
450
        if( m_deleteFile )
407
455
        // restore window-title
408
456
        lmmsMainWin::inst()->resetWindowTitle(); 
409
457
 
 
458
        songEditor::inst()->stopExport();
 
459
 
 
460
        // if we rendered file from command line, quit after export
 
461
        if( file_to_render != "" )
 
462
        {
 
463
                // qApp->quit(); - doesn't work for some reason...
 
464
                exit( 0 );
 
465
        }
 
466
 
410
467
        // let's close us...
411
468
        accept();
412
 
 
413
 
}
414
 
 
415
 
 
416
 
 
417
 
 
418
 
// called whenever there's a reason for aborting song-export (like user-input)
419
 
void exportProjectDialog::abortProjectExport( void )
420
 
{
421
 
        mixer::inst()->pause();
422
 
        m_deleteFile = TRUE;
423
 
 
424
 
        finishProjectExport();
425
 
}
426
 
 
427
 
 
428
 
 
429
 
 
430
 
void exportProjectDialog::finishProjectExport( void )
431
 
{
432
 
        m_progressBarUpdateTimer->stop();
433
 
        delete m_progressBarUpdateTimer;
434
 
 
435
 
        mixer::inst()->restoreAudioDevice();
436
 
        songEditor::inst()->stopExport();
437
 
 
438
 
        mixer::inst()->play();
439
 
 
440
 
        // this method does the final cleanup...
441
 
        cancelBtnClicked();
442
 
}
443
 
 
444
 
 
445
 
 
446
 
 
447
 
void exportProjectDialog::redrawProgressBar( void )
448
 
{
449
 
        if( m_progressVal != m_oldProgressVal )
450
 
        {
451
 
#ifdef QT4
452
 
                m_exportProgressBar->setValue( m_progressVal );
453
 
#else
454
 
                m_exportProgressBar->setProgress( m_progressVal );
455
 
#endif
456
 
                // update lmms-main-win-caption
457
 
                lmmsMainWin::inst()->setWindowTitle( tr( "Rendering:" ) + " " +
458
 
                                QString::number( m_progressVal ) + "%" );
459
 
                m_oldProgressVal = m_progressVal;
460
 
        }
461
 
 
462
 
        if( songEditor::inst()->exportDone() == TRUE ||
463
 
                                songEditor::inst()->exporting() == FALSE )
464
 
        {
465
 
                finishProjectExport();
466
 
        }
467
 
 
468
 
}
469
 
 
470
 
 
471
 
 
472
 
 
473
 
void exportProjectDialog::updateProgressBar( int _new_val )
474
 
{
475
 
        m_progressVal = _new_val;
476
 
}
 
469
}
 
470
 
477
471
 
478
472
 
479
473