# HG changeset patch # User Chris Cannam # Date 1191498758 0 # Node ID f3191ab6d5646edd214eb68c3cf775a43630f48e # Parent ebd906049fb64b8e9f380f6a319662554dc1cd53 * Add MIDI file export (closes FR#1643721) diff -r ebd906049fb6 -r f3191ab6d564 audioio/AudioGenerator.cpp --- a/audioio/AudioGenerator.cpp Mon Oct 01 13:48:38 2007 +0000 +++ b/audioio/AudioGenerator.cpp Thu Oct 04 11:52:38 2007 +0000 @@ -536,7 +536,7 @@ onEv.type = SND_SEQ_EVENT_NOTEON; onEv.data.note.channel = 0; onEv.data.note.note = 64; - onEv.data.note.velocity = 127; + onEv.data.note.velocity = 100; snd_seq_event_t offEv; offEv.type = SND_SEQ_EVENT_NOTEOFF; @@ -680,7 +680,7 @@ onEv.type = SND_SEQ_EVENT_NOTEON; onEv.data.note.channel = 0; onEv.data.note.note = 64; - onEv.data.note.velocity = 127; + onEv.data.note.velocity = 100; snd_seq_event_t offEv; offEv.type = SND_SEQ_EVENT_NOTEOFF; diff -r ebd906049fb6 -r f3191ab6d564 main/MainWindow.cpp --- a/main/MainWindow.cpp Mon Oct 01 13:48:38 2007 +0000 +++ b/main/MainWindow.cpp Thu Oct 04 11:52:38 2007 +0000 @@ -23,6 +23,7 @@ #include "view/PaneStack.h" #include "data/model/WaveFileModel.h" #include "data/model/SparseOneDimensionalModel.h" +#include "data/model/NoteModel.h" #include "view/ViewManager.h" #include "base/Preferences.h" #include "layer/WaveformLayer.h" @@ -51,6 +52,7 @@ #include "data/fileio/PlaylistFileReader.h" #include "data/fileio/WavFileWriter.h" #include "data/fileio/CSVFileWriter.h" +#include "data/fileio/MIDIFileWriter.h" #include "data/fileio/BZipFileDevice.h" #include "data/fileio/RemoteFile.h" #include "data/fft/FFTDataServer.h" @@ -374,6 +376,8 @@ return ff->getOpenFileName(type, m_audioFile); case FileFinder::LayerFile: return ff->getOpenFileName(type, m_sessionFile); + case FileFinder::LayerFileNoMidi: + return ff->getOpenFileName(type, m_sessionFile); case FileFinder::SessionOrAudioFile: return ff->getOpenFileName(type, m_sessionFile); case FileFinder::ImageFile: @@ -402,6 +406,8 @@ return ff->getSaveFileName(type, m_audioFile); case FileFinder::LayerFile: return ff->getSaveFileName(type, m_sessionFile); + case FileFinder::LayerFileNoMidi: + return ff->getSaveFileName(type, m_sessionFile); case FileFinder::SessionOrAudioFile: return ff->getSaveFileName(type, m_sessionFile); case FileFinder::ImageFile: @@ -2604,15 +2610,21 @@ Model *model = layer->getModel(); if (!model) return; - QString path = getSaveFileName(FileFinder::LayerFile); + FileFinder::FileType type = FileFinder::LayerFileNoMidi; + + if (dynamic_cast(model)) type = FileFinder::LayerFile; + + QString path = getSaveFileName(type); if (path == "") return; if (QFileInfo(path).suffix() == "") path += ".svl"; + QString suffix = QFileInfo(path).suffix().toLower(); + QString error; - if (path.endsWith(".xml") || path.endsWith(".svl")) { + if (suffix == "xml" || suffix == "svl") { QFile file(path); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { @@ -2635,10 +2647,24 @@ << "\n"; } + } else if (suffix == "mid" || suffix == "midi") { + + NoteModel *nm = dynamic_cast(model); + + if (!nm) { + error = tr("Can't export non-note layers to MIDI"); + } else { + MIDIFileWriter writer(path, nm); + writer.write(); + if (!writer.isOK()) { + error = writer.getError(); + } + } + } else { CSVFileWriter writer(path, model, - (path.endsWith(".csv") ? "," : "\t")); + ((suffix == "csv") ? "," : "\t")); writer.write(); if (!writer.isOK()) { diff -r ebd906049fb6 -r f3191ab6d564 transform/FeatureExtractionPluginTransform.cpp --- a/transform/FeatureExtractionPluginTransform.cpp Mon Oct 01 13:48:38 2007 +0000 +++ b/transform/FeatureExtractionPluginTransform.cpp Thu Oct 04 11:52:38 2007 +0000 @@ -520,8 +520,8 @@ binCount = m_descriptor->binCount; } - std::cerr << "FeatureExtractionPluginTransform::setCompletion(" - << completion << ")" << std::endl; +// std::cerr << "FeatureExtractionPluginTransform::setCompletion(" +// << completion << ")" << std::endl; if (binCount == 0) {