changeset 140:9b94545a7fdc midi

More of MIDIFeatureWriter
author Chris Cannam
date Mon, 13 Oct 2014 12:00:22 +0100
parents a4bee1a374b4
children d7a91e07ca57
files runner/MIDIFeatureWriter.cpp runner/MIDIFeatureWriter.h
diffstat 2 files changed, 39 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/runner/MIDIFeatureWriter.cpp	Mon Oct 13 11:43:24 2014 +0100
+++ b/runner/MIDIFeatureWriter.cpp	Mon Oct 13 12:00:22 2014 +0100
@@ -60,12 +60,42 @@
 			 const Plugin::FeatureList& features,
 			 std::string summaryType)
 {
-    QString filename = getOutputFilename(trackId, transform.getIdentifier());
+    QString transformId = transform.getIdentifier();
+
+    QString filename = getOutputFilename(trackId, transformId);
     if (filename == "") {
-	throw FailedToOpenOutputStream(trackId, transform.getIdentifier());
+	throw FailedToOpenOutputStream(trackId, transformId);
     }
 
-    //!!! implement!
+    if (m_rates.find(filename) == m_rates.end()) {
+        // If the output is FixedSampleRate, we draw the sample rate
+        // from the output descriptor; otherwise from the transform
+        float sampleRate;
+        if (output.sampleType == Plugin::OutputDescriptor::FixedSampleRate) {
+            sampleRate = output.sampleRate;
+        } else {
+            sampleRate = transform.getSampleRate();
+        }
+        m_rates[filename] = sampleRate;
+    }
+
+    if (m_fileTransforms[filename].find(transformId) == 
+        m_fileTransforms[filename].end()) {
+
+        // This transform is new to the file, give it a channel number
+
+        int channel = m_nextChannels[filename];
+        m_nextChannels[filename] = channel + 1;
+
+        m_fileTransforms[filename].insert(transformId);
+        m_channels[transformId] = channel;
+    }
+
+    NoteList notes = m_notes[filename];
+
+    
+
+    m_notes[filename] = notes;
 }
 
 void
--- a/runner/MIDIFeatureWriter.h	Mon Oct 13 11:43:24 2014 +0100
+++ b/runner/MIDIFeatureWriter.h	Mon Oct 13 12:00:22 2014 +0100
@@ -50,7 +50,7 @@
 	virtual NoteList getNotes() const {
 	    return m_notes;
 	}
-	virtual NoteList getNotesWithin(int startFrame, int endFrame) const {
+	virtual NoteList getNotesWithin(int, int) const {
 	    // Not required by MIDIFileWriter, not supported
 	    return NoteList();
 	}
@@ -60,6 +60,9 @@
 
     typedef map<QString, NoteList> NoteMap; // output filename -> notes
     NoteMap m_notes;
+    
+    typedef map<QString, set<TransformId> > FileTransformMap;
+    FileTransformMap m_fileTransforms;
 
     typedef map<QString, float> SampleRateMap; // NoteData uses sample timing
     SampleRateMap m_rates;
@@ -67,8 +70,8 @@
     typedef map<TransformId, int> ChannelMap;
     ChannelMap m_channels;
     
-    typedef map<QString, int> LastChannelMap;
-    LastChannelMap m_lastChannels;
+    typedef map<QString, int> NextChannelMap;
+    NextChannelMap m_nextChannels;
 };
 
 #endif