comparison 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
comparison
equal deleted inserted replaced
995:952005e25266 996:0d3d1ec7dfde
315 m_timingDivision = 480; 315 m_timingDivision = 480;
316 m_format = MIDI_SINGLE_TRACK_FILE; 316 m_format = MIDI_SINGLE_TRACK_FILE;
317 m_numberOfTracks = 1; 317 m_numberOfTracks = 1;
318 318
319 int track = 0; 319 int track = 0;
320 int midiChannel = 0;
321 320
322 MIDIEvent *event; 321 MIDIEvent *event;
323 322
324 event = new MIDIEvent(0, MIDI_FILE_META_EVENT, MIDI_CUE_POINT, 323 event = new MIDIEvent(0, MIDI_FILE_META_EVENT, MIDI_CUE_POINT,
325 "Exported from Sonic Visualiser"); 324 "Exported from Sonic Visualiser");
347 346
348 int frame = i->start; 347 int frame = i->start;
349 int duration = i->duration; 348 int duration = i->duration;
350 int pitch = i->midiPitch; 349 int pitch = i->midiPitch;
351 int velocity = i->velocity; 350 int velocity = i->velocity;
351 int channel = i->channel;
352 352
353 if (pitch < 0) pitch = 0; 353 if (pitch < 0) pitch = 0;
354 if (pitch > 127) pitch = 127; 354 if (pitch > 127) pitch = 127;
355
356 if (channel < 0) channel = 0;
357 if (channel > 15) channel = 0;
355 358
356 // Convert frame to MIDI time 359 // Convert frame to MIDI time
357 360
358 double seconds = double(frame) / double(m_sampleRate); 361 double seconds = double(frame) / double(m_sampleRate);
359 double quarters = (seconds * m_tempo) / 60.0; 362 double quarters = (seconds * m_tempo) / 60.0;
368 // in the delta time fields. We resolve these into delta 371 // in the delta time fields. We resolve these into delta
369 // times further down (can't do it until all the note offs are 372 // times further down (can't do it until all the note offs are
370 // in place). 373 // in place).
371 374
372 event = new MIDIEvent(midiTime, 375 event = new MIDIEvent(midiTime,
373 MIDI_NOTE_ON | midiChannel, 376 MIDI_NOTE_ON | channel,
374 pitch, 377 pitch,
375 velocity); 378 velocity);
376 m_midiComposition[track].push_back(event); 379 m_midiComposition[track].push_back(event);
377 380
378 event = new MIDIEvent(endTime, 381 event = new MIDIEvent(endTime,
379 MIDI_NOTE_OFF | midiChannel, 382 MIDI_NOTE_OFF | channel,
380 pitch, 383 pitch,
381 127); // loudest silence you can muster 384 127); // loudest silence you can muster
382 385
383 m_midiComposition[track].push_back(event); 386 m_midiComposition[track].push_back(event);
384 } 387 }