diff data/fileio/MIDIFileWriter.cpp @ 996:0d3d1ec7dfde

Add MIDI channel to note data and MIDI writer
author Chris Cannam
date Mon, 13 Oct 2014 10:55:43 +0100
parents dad0fc8ff405
children cc27f35aa75c
line wrap: on
line diff
--- a/data/fileio/MIDIFileWriter.cpp	Mon Oct 13 10:00:54 2014 +0100
+++ b/data/fileio/MIDIFileWriter.cpp	Mon Oct 13 10:55:43 2014 +0100
@@ -317,7 +317,6 @@
     m_numberOfTracks = 1;
 
     int track = 0;
-    int midiChannel = 0;
 
     MIDIEvent *event;
 
@@ -349,10 +348,14 @@
         int duration = i->duration;
         int pitch = i->midiPitch;
         int velocity = i->velocity;
+        int channel = i->channel;
 
         if (pitch < 0) pitch = 0;
         if (pitch > 127) pitch = 127;
 
+        if (channel < 0) channel = 0;
+        if (channel > 15) channel = 0;
+
         // Convert frame to MIDI time
 
         double seconds = double(frame) / double(m_sampleRate);
@@ -370,13 +373,13 @@
         // in place).
 
         event = new MIDIEvent(midiTime,
-                              MIDI_NOTE_ON | midiChannel,
+                              MIDI_NOTE_ON | channel,
                               pitch,
                               velocity);
         m_midiComposition[track].push_back(event);
 
         event = new MIDIEvent(endTime,
-                              MIDI_NOTE_OFF | midiChannel,
+                              MIDI_NOTE_OFF | channel,
                               pitch,
                               127); // loudest silence you can muster