changeset 185:f3191ab6d564

* Add MIDI file export (closes FR#1643721)
author Chris Cannam
date Thu, 04 Oct 2007 11:52:38 +0000
parents ebd906049fb6
children 7b943924b8d3
files audioio/AudioGenerator.cpp main/MainWindow.cpp transform/FeatureExtractionPluginTransform.cpp
diffstat 3 files changed, 33 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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<NoteModel *>(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 @@
                 << "</sv>\n";
         }
 
+    } else if (suffix == "mid" || suffix == "midi") {
+
+        NoteModel *nm = dynamic_cast<NoteModel *>(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()) {
--- 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) {