From 2260907285284b8c4b5b7cfee9a217ee3ff57785 Mon Sep 17 00:00:00 2001 From: mohamed Date: Wed, 4 Feb 2015 22:37:43 +0100 Subject: [PATCH] adding exportProjectMidi method, internally uses midiexport plugin --- include/Song.h | 1 + src/core/Song.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/Song.h b/include/Song.h index 5da09818a..487e856a6 100644 --- a/include/Song.h +++ b/include/Song.h @@ -268,6 +268,7 @@ public slots: void importProject(); void exportProject(bool multiExport=false); void exportProjectTracks(); + void exportProjectMidi(); void startExport(); void stopExport(); diff --git a/src/core/Song.cpp b/src/core/Song.cpp index 7198416cc..7942b6452 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -47,6 +47,7 @@ #include "FxMixerView.h" #include "GuiApplication.h" #include "ImportFilter.h" +#include "ExportFilter.h" #include "InstrumentTrack.h" #include "MainWindow.h" #include "FileDialog.h" @@ -1275,6 +1276,64 @@ void Song::exportProject(bool multiExport) } +void Song::exportProjectMidi() +{ + if( isEmpty() ) + { + QMessageBox::information( gui->mainWindow(), + tr( "Empty project" ), + tr( "This project is empty so exporting makes " + "no sense. Please put some items into " + "Song Editor first!" ) ); + return; + } + + FileDialog efd( gui->mainWindow() ); + + efd.setFileMode( FileDialog::AnyFile ); + + QStringList types; + types << tr("MIDI File (*.mid)"); + efd.setNameFilters( types ); + QString base_filename; + if( !m_fileName.isEmpty() ) + { + efd.setDirectory( QFileInfo( m_fileName ).absolutePath() ); + base_filename = QFileInfo( m_fileName ).completeBaseName(); + } + else + { + efd.setDirectory( ConfigManager::inst()->userProjectsDir() ); + base_filename = tr( "untitled" ); + } + efd.selectFile( base_filename + ".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; + tracks += Engine::getSong()->tracks(); + tracks += Engine::getBBTrackContainer()->tracks(); + ExportFilter *exf = dynamic_cast (Plugin::instantiate("midiexport", NULL, NULL)); + if (exf==NULL) { + qDebug() << "failed to load midi export filter!"; + return; + } + exf->tryExport(tracks, Engine::getSong()->getTempo(), export_filename); + } +} + void Song::updateFramesPerTick()