Move GUI dependencies out of Song::exportProjectMidi
Move all GUI dependencies out of Song::exportProjectMidi and move them into the MainWindow. Show the GUI in the new slot method MainWindow::onExportProjectMidi and delegate to Song::exportProjectMidi once the file name has been determined. The file name is given as a parameter to Song::exportProjectMidi which still contains the business logic of exporting the data.
This commit is contained in:
@@ -175,6 +175,9 @@ public slots:
|
||||
|
||||
void autoSave();
|
||||
|
||||
private slots:
|
||||
void onExportProjectMidi();
|
||||
|
||||
protected:
|
||||
virtual void closeEvent( QCloseEvent * _ce );
|
||||
virtual void focusOutEvent( QFocusEvent * _fe );
|
||||
|
||||
@@ -298,6 +298,7 @@ public:
|
||||
return m_timeSigModel;
|
||||
}
|
||||
|
||||
void exportProjectMidi(QString const & exportFileName) const;
|
||||
|
||||
public slots:
|
||||
void playSong();
|
||||
@@ -311,7 +312,6 @@ public slots:
|
||||
void importProject();
|
||||
void exportProject( bool multiExport = false );
|
||||
void exportProjectTracks();
|
||||
void exportProjectMidi();
|
||||
|
||||
void startExport();
|
||||
void stopExport();
|
||||
|
||||
@@ -1388,54 +1388,22 @@ void Song::exportProject( bool multiExport )
|
||||
}
|
||||
|
||||
|
||||
void Song::exportProjectMidi()
|
||||
void Song::exportProjectMidi(QString const & exportFileName) const
|
||||
{
|
||||
FileDialog efd( gui->mainWindow() );
|
||||
// instantiate midi export plugin
|
||||
TrackContainer::TrackList const & tracks = this->tracks();
|
||||
TrackContainer::TrackList const & tracks_BB = Engine::getBBTrackContainer()->tracks();
|
||||
|
||||
efd.setFileMode( FileDialog::AnyFile );
|
||||
|
||||
QStringList types;
|
||||
types << tr("MIDI File (*.mid)");
|
||||
efd.setNameFilters( types );
|
||||
QString base_filename;
|
||||
if( !m_fileName.isEmpty() )
|
||||
ExportFilter *exf = dynamic_cast<ExportFilter *> (Plugin::instantiate("midiexport", nullptr, nullptr));
|
||||
if (exf)
|
||||
{
|
||||
efd.setDirectory( QFileInfo( m_fileName ).absolutePath() );
|
||||
base_filename = QFileInfo( m_fileName ).completeBaseName();
|
||||
exf->tryExport(tracks, tracks_BB, getTempo(), m_masterPitchModel.value(), exportFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
efd.setDirectory( ConfigManager::inst()->userProjectsDir() );
|
||||
base_filename = tr( "untitled" );
|
||||
qDebug() << "failed to load midi export filter!";
|
||||
}
|
||||
efd.selectFile( base_filename + ".mid" );
|
||||
efd.setDefaultSuffix( "mid");
|
||||
efd.setWindowTitle( tr( "Select file for project-export..." ) );
|
||||
|
||||
efd.setAcceptMode( FileDialog::AcceptSave );
|
||||
|
||||
|
||||
if( efd.exec() == QDialog::Accepted && !efd.selectedFiles().isEmpty() && !efd.selectedFiles()[0].isEmpty() )
|
||||
{
|
||||
const QString suffix = ".mid";
|
||||
|
||||
QString export_filename = efd.selectedFiles()[0];
|
||||
if (!export_filename.endsWith(suffix)) export_filename += suffix;
|
||||
|
||||
// NOTE start midi export
|
||||
|
||||
// instantiate midi export plugin
|
||||
TrackContainer::TrackList tracks;
|
||||
TrackContainer::TrackList tracks_BB;
|
||||
tracks = Engine::getSong()->tracks();
|
||||
tracks_BB = Engine::getBBTrackContainer()->tracks();
|
||||
ExportFilter *exf = dynamic_cast<ExportFilter *> (Plugin::instantiate("midiexport", NULL, NULL));
|
||||
if (exf==NULL) {
|
||||
qDebug() << "failed to load midi export filter!";
|
||||
return;
|
||||
}
|
||||
exf->tryExport(tracks, tracks_BB, getTempo(), m_masterPitchModel.value(), export_filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -322,8 +322,8 @@ void MainWindow::finalize()
|
||||
|
||||
project_menu->addAction( embed::getIconPixmap( "midi_file" ),
|
||||
tr( "Export &MIDI..." ),
|
||||
Engine::getSong(),
|
||||
SLOT( exportProjectMidi() ),
|
||||
this,
|
||||
SLOT( onExportProjectMidi() ),
|
||||
Qt::CTRL + Qt::Key_M );
|
||||
|
||||
// Prevent dangling separator at end of menu per https://bugreports.qt.io/browse/QTBUG-40071
|
||||
@@ -1573,3 +1573,42 @@ void MainWindow::autoSave()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onExportProjectMidi()
|
||||
{
|
||||
FileDialog efd( this );
|
||||
|
||||
efd.setFileMode( FileDialog::AnyFile );
|
||||
|
||||
QStringList types;
|
||||
types << tr("MIDI File (*.mid)");
|
||||
efd.setNameFilters( types );
|
||||
QString base_filename;
|
||||
QString const & projectFileName = Engine::getSong()->projectFileName();
|
||||
if( !projectFileName.isEmpty() )
|
||||
{
|
||||
efd.setDirectory( QFileInfo( projectFileName ).absolutePath() );
|
||||
base_filename = QFileInfo( projectFileName ).completeBaseName();
|
||||
}
|
||||
else
|
||||
{
|
||||
efd.setDirectory( ConfigManager::inst()->userProjectsDir() );
|
||||
base_filename = tr( "untitled" );
|
||||
}
|
||||
efd.selectFile( base_filename + ".mid" );
|
||||
efd.setDefaultSuffix( "mid");
|
||||
efd.setWindowTitle( tr( "Select file for project-export..." ) );
|
||||
|
||||
efd.setAcceptMode( FileDialog::AcceptSave );
|
||||
|
||||
|
||||
if( efd.exec() == QDialog::Accepted && !efd.selectedFiles().isEmpty() && !efd.selectedFiles()[0].isEmpty() )
|
||||
{
|
||||
const QString suffix = ".mid";
|
||||
|
||||
QString export_filename = efd.selectedFiles()[0];
|
||||
if (!export_filename.endsWith(suffix)) export_filename += suffix;
|
||||
|
||||
Engine::getSong()->exportProjectMidi(export_filename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user