Mercurial > hg > svcore
comparison data/fileio/MIDIFileWriter.cpp @ 1128:50210da3997c
Simple MIDI writer test
author | Chris Cannam |
---|---|
date | Tue, 01 Sep 2015 15:51:07 +0100 |
parents | c7e9afcbf070 |
children | 48e9f538e6e9 |
comparison
equal
deleted
inserted
replaced
1121:067b60ae4861 | 1128:50210da3997c |
---|---|
25 #include "data/midi/MIDIEvent.h" | 25 #include "data/midi/MIDIEvent.h" |
26 #include "model/NoteData.h" | 26 #include "model/NoteData.h" |
27 | 27 |
28 #include "base/Pitch.h" | 28 #include "base/Pitch.h" |
29 | 29 |
30 #include <QCoreApplication> | |
31 | |
30 #include <algorithm> | 32 #include <algorithm> |
31 #include <fstream> | 33 #include <fstream> |
34 | |
35 //#define DEBUG_MIDI_FILE_WRITER 1 | |
32 | 36 |
33 using std::ofstream; | 37 using std::ofstream; |
34 using std::string; | 38 using std::string; |
35 using std::ios; | 39 using std::ios; |
36 | 40 |
318 | 322 |
319 int track = 0; | 323 int track = 0; |
320 | 324 |
321 MIDIEvent *event; | 325 MIDIEvent *event; |
322 | 326 |
323 event = new MIDIEvent(0, MIDI_FILE_META_EVENT, MIDI_CUE_POINT, | 327 event = new MIDIEvent |
324 "Exported from Sonic Visualiser"); | 328 (0, MIDI_FILE_META_EVENT, MIDI_CUE_POINT, |
325 m_midiComposition[track].push_back(event); | 329 ("Exported from " + qApp->applicationName()).toStdString()); |
326 | |
327 event = new MIDIEvent(0, MIDI_FILE_META_EVENT, MIDI_CUE_POINT, | |
328 "http://www.sonicvisualiser.org/"); | |
329 m_midiComposition[track].push_back(event); | 330 m_midiComposition[track].push_back(event); |
330 | 331 |
331 long tempoValue = long(60000000.0 / m_tempo + 0.01); | 332 long tempoValue = long(60000000.0 / m_tempo + 0.01); |
332 string tempoString; | 333 string tempoString; |
333 tempoString += (MIDIByte)(tempoValue >> 16 & 0xFF); | 334 tempoString += (MIDIByte)(tempoValue >> 16 & 0xFF); |
382 MIDI_NOTE_OFF | channel, | 383 MIDI_NOTE_OFF | channel, |
383 pitch, | 384 pitch, |
384 127); // loudest silence you can muster | 385 127); // loudest silence you can muster |
385 | 386 |
386 m_midiComposition[track].push_back(event); | 387 m_midiComposition[track].push_back(event); |
388 | |
389 #ifdef DEBUG_MIDI_FILE_WRITER | |
390 cerr << "midiTime = " << midiTime << ", endTime = " << endTime << endl; | |
391 #endif | |
387 } | 392 } |
388 | 393 |
389 // Now gnash through the MIDI events and turn the absolute times | 394 // Now gnash through the MIDI events and turn the absolute times |
390 // into delta times. | 395 // into delta times. |
391 // | 396 // |
402 MIDIEventCmp()); | 407 MIDIEventCmp()); |
403 | 408 |
404 for (MIDITrack::iterator it = m_midiComposition[i].begin(); | 409 for (MIDITrack::iterator it = m_midiComposition[i].begin(); |
405 it != m_midiComposition[i].end(); it++) { | 410 it != m_midiComposition[i].end(); it++) { |
406 unsigned long deltaTime = (*it)->getTime() - lastMidiTime; | 411 unsigned long deltaTime = (*it)->getTime() - lastMidiTime; |
412 #ifdef DEBUG_MIDI_FILE_WRITER | |
413 cerr << "time = " << (*it)->getTime() << ", lastMidiTime = " << lastMidiTime << ", deltaTime = " << deltaTime << endl; | |
414 #endif | |
407 lastMidiTime = (*it)->getTime(); | 415 lastMidiTime = (*it)->getTime(); |
408 (*it)->setTime(deltaTime); | 416 (*it)->setTime(deltaTime); |
409 } | 417 } |
410 | 418 |
411 // Insert end of track event (delta time = 0) | 419 // Insert end of track event (delta time = 0) |