Mercurial > hg > svcore
comparison data/fileio/MIDIFileReader.cpp @ 1069:32ab6c48efaa
Merge from branch tonioni
| author | Chris Cannam |
|---|---|
| date | Mon, 20 Apr 2015 09:11:34 +0100 |
| parents | 26cf6d5251ec |
| children | 39271c98cbdd |
comparison
equal
deleted
inserted
replaced
| 1036:682d64f05e72 | 1069:32ab6c48efaa |
|---|---|
| 56 //#define MIDI_SVDEBUG 1 | 56 //#define MIDI_SVDEBUG 1 |
| 57 | 57 |
| 58 | 58 |
| 59 MIDIFileReader::MIDIFileReader(QString path, | 59 MIDIFileReader::MIDIFileReader(QString path, |
| 60 MIDIFileImportPreferenceAcquirer *acquirer, | 60 MIDIFileImportPreferenceAcquirer *acquirer, |
| 61 int mainModelSampleRate) : | 61 sv_samplerate_t mainModelSampleRate) : |
| 62 m_smpte(false), | 62 m_smpte(false), |
| 63 m_timingDivision(0), | 63 m_timingDivision(0), |
| 64 m_fps(0), | 64 m_fps(0), |
| 65 m_subframes(0), | 65 m_subframes(0), |
| 66 m_format(MIDI_FILE_BAD_FORMAT), | 66 m_format(MIDI_FILE_BAD_FORMAT), |
| 299 try { | 299 try { |
| 300 | 300 |
| 301 // Set file size so we can count it off | 301 // Set file size so we can count it off |
| 302 // | 302 // |
| 303 m_midiFile->seekg(0, ios::end); | 303 m_midiFile->seekg(0, ios::end); |
| 304 m_fileSize = m_midiFile->tellg(); | 304 std::streamoff off = m_midiFile->tellg(); |
| 305 m_fileSize = 0; | |
| 306 if (off > 0) m_fileSize = off; | |
| 305 m_midiFile->seekg(0, ios::beg); | 307 m_midiFile->seekg(0, ios::beg); |
| 306 | 308 |
| 307 // Parse the MIDI header first. The first 14 bytes of the file. | 309 // Parse the MIDI header first. The first 14 bytes of the file. |
| 308 if (!parseHeader(getMIDIBytes(14))) { | 310 if (!parseHeader(getMIDIBytes(14))) { |
| 309 m_format = MIDI_FILE_BAD_FORMAT; | 311 m_format = MIDI_FILE_BAD_FORMAT; |
| 438 MIDIFileReader::parseTrack(unsigned int &lastTrackNum) | 440 MIDIFileReader::parseTrack(unsigned int &lastTrackNum) |
| 439 { | 441 { |
| 440 MIDIByte midiByte, metaEventCode, data1, data2; | 442 MIDIByte midiByte, metaEventCode, data1, data2; |
| 441 MIDIByte eventCode = 0x80; | 443 MIDIByte eventCode = 0x80; |
| 442 string metaMessage; | 444 string metaMessage; |
| 443 unsigned int messageLength; | 445 long messageLength; |
| 444 unsigned long deltaTime; | 446 long deltaTime; |
| 445 unsigned long accumulatedTime = 0; | 447 long accumulatedTime = 0; |
| 446 | 448 |
| 447 // The trackNum passed in to this method is the default track for | 449 // The trackNum passed in to this method is the default track for |
| 448 // all events provided they're all on the same channel. If we find | 450 // all events provided they're all on the same channel. If we find |
| 449 // events on more than one channel, we increment trackNum and record | 451 // events on more than one channel, we increment trackNum and record |
| 450 // the mapping from channel to trackNum in this channelTrackMap. | 452 // the mapping from channel to trackNum in this channelTrackMap. |
| 888 } | 890 } |
| 889 } | 891 } |
| 890 | 892 |
| 891 if (tracksToLoad.empty()) return 0; | 893 if (tracksToLoad.empty()) return 0; |
| 892 | 894 |
| 893 int n = tracksToLoad.size(), count = 0; | 895 int n = int(tracksToLoad.size()), count = 0; |
| 894 Model *model = 0; | 896 Model *model = 0; |
| 895 | 897 |
| 896 for (std::set<unsigned int>::iterator i = tracksToLoad.begin(); | 898 for (std::set<unsigned int>::iterator i = tracksToLoad.begin(); |
| 897 i != tracksToLoad.end(); ++i) { | 899 i != tracksToLoad.end(); ++i) { |
| 898 | 900 |
| 936 model->setObjectName(QFileInfo(m_path).fileName()); | 938 model->setObjectName(QFileInfo(m_path).fileName()); |
| 937 } | 939 } |
| 938 | 940 |
| 939 const MIDITrack &track = m_midiComposition.find(trackToLoad)->second; | 941 const MIDITrack &track = m_midiComposition.find(trackToLoad)->second; |
| 940 | 942 |
| 941 int totalEvents = track.size(); | 943 int totalEvents = int(track.size()); |
| 942 int count = 0; | 944 int count = 0; |
| 943 | 945 |
| 944 bool sharpKey = true; | 946 bool sharpKey = true; |
| 945 | 947 |
| 946 for (MIDITrack::const_iterator i = track.begin(); i != track.end(); ++i) { | 948 for (MIDITrack::const_iterator i = track.begin(); i != track.end(); ++i) { |
