comparison data/fileio/MIDIFileWriter.cpp @ 1069:32ab6c48efaa

Merge from branch tonioni
author Chris Cannam
date Mon, 20 Apr 2015 09:11:34 +0100
parents c7e9afcbf070
children 50210da3997c
comparison
equal deleted inserted replaced
1036:682d64f05e72 1069:32ab6c48efaa
35 using std::ios; 35 using std::ios;
36 36
37 using namespace MIDIConstants; 37 using namespace MIDIConstants;
38 38
39 MIDIFileWriter::MIDIFileWriter(QString path, const NoteExportable *exportable, 39 MIDIFileWriter::MIDIFileWriter(QString path, const NoteExportable *exportable,
40 int sampleRate, float tempo) : 40 sv_samplerate_t sampleRate, float tempo) :
41 m_path(path), 41 m_path(path),
42 m_exportable(exportable), 42 m_exportable(exportable),
43 m_sampleRate(sampleRate), 43 m_sampleRate(sampleRate),
44 m_tempo(tempo), 44 m_tempo(tempo),
45 m_midiFile(0) 45 m_midiFile(0)
87 MIDIFileWriter::intToMIDIBytes(int number) const 87 MIDIFileWriter::intToMIDIBytes(int number) const
88 { 88 {
89 MIDIByte upper; 89 MIDIByte upper;
90 MIDIByte lower; 90 MIDIByte lower;
91 91
92 upper = (number & 0xFF00) >> 8; 92 upper = MIDIByte((number & 0xFF00) >> 8);
93 lower = (number & 0x00FF); 93 lower = MIDIByte( number & 0x00FF);
94 94
95 string rv; 95 string rv;
96 rv += upper; 96 rv += upper;
97 rv += lower; 97 rv += lower;
98 return rv; 98 return rv;
104 MIDIByte upper1; 104 MIDIByte upper1;
105 MIDIByte lower1; 105 MIDIByte lower1;
106 MIDIByte upper2; 106 MIDIByte upper2;
107 MIDIByte lower2; 107 MIDIByte lower2;
108 108
109 upper1 = (number & 0xff000000) >> 24; 109 upper1 = MIDIByte((number & 0xff000000) >> 24);
110 lower1 = (number & 0x00ff0000) >> 16; 110 lower1 = MIDIByte((number & 0x00ff0000) >> 16);
111 upper2 = (number & 0x0000ff00) >> 8; 111 upper2 = MIDIByte((number & 0x0000ff00) >> 8);
112 lower2 = (number & 0x000000ff); 112 lower2 = MIDIByte((number & 0x000000ff));
113 113
114 string rv; 114 string rv;
115 rv += upper1; 115 rv += upper1;
116 rv += lower1; 116 rv += lower1;
117 rv += upper2; 117 rv += upper2;
342 342
343 NoteList notes = m_exportable->getNotes(); 343 NoteList notes = m_exportable->getNotes();
344 344
345 for (NoteList::const_iterator i = notes.begin(); i != notes.end(); ++i) { 345 for (NoteList::const_iterator i = notes.begin(); i != notes.end(); ++i) {
346 346
347 int frame = i->start; 347 sv_frame_t frame = i->start;
348 int duration = i->duration; 348 sv_frame_t duration = i->duration;
349 int pitch = i->midiPitch; 349 int pitch = i->midiPitch;
350 int velocity = i->velocity; 350 int velocity = i->velocity;
351 int channel = i->channel; 351 int channel = i->channel;
352 352
353 if (pitch < 0) pitch = 0; 353 if (pitch < 0) pitch = 0;
356 if (channel < 0) channel = 0; 356 if (channel < 0) channel = 0;
357 if (channel > 15) channel = 0; 357 if (channel > 15) channel = 0;
358 358
359 // Convert frame to MIDI time 359 // Convert frame to MIDI time
360 360
361 double seconds = double(frame) / double(m_sampleRate); 361 double seconds = double(frame) / m_sampleRate;
362 double quarters = (seconds * m_tempo) / 60.0; 362 double quarters = (seconds * m_tempo) / 60.0;
363 unsigned long midiTime = int(quarters * m_timingDivision + 0.5); 363 unsigned long midiTime = int(quarters * m_timingDivision + 0.5);
364 364
365 // Get the sounding time for the matching NOTE_OFF 365 // Get the sounding time for the matching NOTE_OFF
366 seconds = double(frame + duration) / double(m_sampleRate); 366 seconds = double(frame + duration) / m_sampleRate;
367 quarters = (seconds * m_tempo) / 60.0; 367 quarters = (seconds * m_tempo) / 60.0;
368 unsigned long endTime = int(quarters * m_timingDivision + 0.5); 368 unsigned long endTime = int(quarters * m_timingDivision + 0.5);
369 369
370 // At this point all the notes we insert have absolute times 370 // At this point all the notes we insert have absolute times
371 // in the delta time fields. We resolve these into delta 371 // in the delta time fields. We resolve these into delta