comparison data/fileio/MIDIFileReader.cpp @ 687:06f13a3b9e9e debug-output

Convert many cerrs to DEBUGs
author Chris Cannam
date Mon, 16 May 2011 17:19:09 +0100
parents eb1b517f5eeb
children 1424aa29ae95
comparison
equal deleted inserted replaced
686:b4a8d8221eaf 687:06f13a3b9e9e
276 MIDIFileReader::parseFile() 276 MIDIFileReader::parseFile()
277 { 277 {
278 m_error = ""; 278 m_error = "";
279 279
280 #ifdef MIDI_DEBUG 280 #ifdef MIDI_DEBUG
281 cerr << "MIDIFileReader::open() : fileName = " << m_fileName.c_str() << endl; 281 DEBUG << "MIDIFileReader::open() : fileName = " << m_fileName.c_str() << endl;
282 #endif 282 #endif
283 283
284 // Open the file 284 // Open the file
285 m_midiFile = new ifstream(m_path.toLocal8Bit().data(), 285 m_midiFile = new ifstream(m_path.toLocal8Bit().data(),
286 ios::in | ios::binary); 286 ios::in | ios::binary);
313 unsigned int i = 0; 313 unsigned int i = 0;
314 314
315 for (unsigned int j = 0; j < m_numberOfTracks; ++j) { 315 for (unsigned int j = 0; j < m_numberOfTracks; ++j) {
316 316
317 #ifdef MIDI_DEBUG 317 #ifdef MIDI_DEBUG
318 cerr << "Parsing Track " << j << endl; 318 DEBUG << "Parsing Track " << j << endl;
319 #endif 319 #endif
320 320
321 if (!skipToNextTrack()) { 321 if (!skipToNextTrack()) {
322 #ifdef MIDI_DEBUG 322 #ifdef MIDI_DEBUG
323 cerr << "Couldn't find Track " << j << endl; 323 cerr << "Couldn't find Track " << j << endl;
348 m_numberOfTracks = i; 348 m_numberOfTracks = i;
349 retval = true; 349 retval = true;
350 350
351 } catch (MIDIException e) { 351 } catch (MIDIException e) {
352 352
353 cerr << "MIDIFileReader::open() - caught exception - " << e.what() << endl; 353 DEBUG << "MIDIFileReader::open() - caught exception - " << e.what() << endl;
354 m_error = e.what(); 354 m_error = e.what();
355 } 355 }
356 356
357 done: 357 done:
358 m_midiFile->close(); 358 m_midiFile->close();
390 bool 390 bool
391 MIDIFileReader::parseHeader(const string &midiHeader) 391 MIDIFileReader::parseHeader(const string &midiHeader)
392 { 392 {
393 if (midiHeader.size() < 14) { 393 if (midiHeader.size() < 14) {
394 #ifdef MIDI_DEBUG 394 #ifdef MIDI_DEBUG
395 cerr << "MIDIFileReader::parseHeader() - file header undersized" << endl; 395 DEBUG << "MIDIFileReader::parseHeader() - file header undersized" << endl;
396 #endif 396 #endif
397 return false; 397 return false;
398 } 398 }
399 399
400 if (midiHeader.compare(0, 4, MIDI_FILE_HEADER) != 0) { 400 if (midiHeader.compare(0, 4, MIDI_FILE_HEADER) != 0) {
401 #ifdef MIDI_DEBUG 401 #ifdef MIDI_DEBUG
402 cerr << "MIDIFileReader::parseHeader()" 402 DEBUG << "MIDIFileReader::parseHeader()"
403 << "- file header not found or malformed" 403 << "- file header not found or malformed"
404 << endl; 404 << endl;
405 #endif 405 #endif
406 return false; 406 return false;
407 } 407 }
408 408
409 if (midiBytesToLong(midiHeader.substr(4,4)) != 6L) { 409 if (midiBytesToLong(midiHeader.substr(4,4)) != 6L) {
410 #ifdef MIDI_DEBUG 410 #ifdef MIDI_DEBUG
411 cerr << "MIDIFileReader::parseHeader()" 411 DEBUG << "MIDIFileReader::parseHeader()"
412 << " - header length incorrect" 412 << " - header length incorrect"
413 << endl; 413 << endl;
414 #endif 414 #endif
415 return false; 415 return false;
416 } 416 }
496 496
497 eventCode = (MIDIByte)runningStatus; 497 eventCode = (MIDIByte)runningStatus;
498 data1 = midiByte; 498 data1 = midiByte;
499 499
500 #ifdef MIDI_DEBUG 500 #ifdef MIDI_DEBUG
501 cerr << "using running status (byte " << int(midiByte) << " found)" << endl; 501 DEBUG << "using running status (byte " << int(midiByte) << " found)" << endl;
502 #endif 502 #endif
503 } else { 503 } else {
504 #ifdef MIDI_DEBUG 504 #ifdef MIDI_DEBUG
505 cerr << "have new event code " << int(midiByte) << endl; 505 cerr << "have new event code " << int(midiByte) << endl;
506 #endif 506 #endif
609 609
610 if (MIDIByte(metaMessage[metaMessage.length() - 1]) != 610 if (MIDIByte(metaMessage[metaMessage.length() - 1]) !=
611 MIDI_END_OF_EXCLUSIVE) 611 MIDI_END_OF_EXCLUSIVE)
612 { 612 {
613 #ifdef MIDI_DEBUG 613 #ifdef MIDI_DEBUG
614 cerr << "MIDIFileReader::parseTrack() - " 614 DEBUG << "MIDIFileReader::parseTrack() - "
615 << "malformed or unsupported SysEx type" 615 << "malformed or unsupported SysEx type"
616 << endl; 616 << endl;
617 #endif 617 #endif
618 continue; 618 continue;
619 } 619 }
629 m_midiComposition[trackNum].push_back(midiEvent); 629 m_midiComposition[trackNum].push_back(midiEvent);
630 break; 630 break;
631 631
632 case MIDI_END_OF_EXCLUSIVE: 632 case MIDI_END_OF_EXCLUSIVE:
633 #ifdef MIDI_DEBUG 633 #ifdef MIDI_DEBUG
634 cerr << "MIDIFileReader::parseTrack() - " 634 DEBUG << "MIDIFileReader::parseTrack() - "
635 << "Found a stray MIDI_END_OF_EXCLUSIVE" << endl; 635 << "Found a stray MIDI_END_OF_EXCLUSIVE" << endl;
636 #endif 636 #endif
637 break; 637 break;
638 638
639 default: 639 default:
640 #ifdef MIDI_DEBUG 640 #ifdef MIDI_DEBUG
641 cerr << "MIDIFileReader::parseTrack()" 641 DEBUG << "MIDIFileReader::parseTrack()"
642 << " - Unsupported MIDI Event Code: " 642 << " - Unsupported MIDI Event Code: "
643 << (int)eventCode << endl; 643 << (int)eventCode << endl;
644 #endif 644 #endif
645 break; 645 break;
646 } 646 }
785 unsigned long melapsed = midiTime - tempoMIDITime; 785 unsigned long melapsed = midiTime - tempoMIDITime;
786 double quarters = double(melapsed) / double(td); 786 double quarters = double(melapsed) / double(td);
787 double seconds = (60.0 * quarters) / tempo; 787 double seconds = (60.0 * quarters) / tempo;
788 788
789 /* 789 /*
790 std::cerr << "MIDIFileReader::getTimeForMIDITime(" << midiTime << ")" 790 DEBUG << "MIDIFileReader::getTimeForMIDITime(" << midiTime << ")"
791 << std::endl; 791 << endl;
792 std::cerr << "timing division = " << td << std::endl; 792 DEBUG << "timing division = " << td << endl;
793 std::cerr << "nearest tempo event (of " << m_tempoMap.size() << ") is at " << tempoMIDITime << " (" 793 std::cerr << "nearest tempo event (of " << m_tempoMap.size() << ") is at " << tempoMIDITime << " ("
794 << tempoRealTime << ")" << std::endl; 794 << tempoRealTime << ")" << std::endl;
795 std::cerr << "quarters since then = " << quarters << std::endl; 795 std::cerr << "quarters since then = " << quarters << std::endl;
796 std::cerr << "tempo = " << tempo << " quarters per minute" << std::endl; 796 std::cerr << "tempo = " << tempo << " quarters per minute" << std::endl;
797 std::cerr << "seconds since then = " << seconds << std::endl; 797 std::cerr << "seconds since then = " << seconds << std::endl;
798 std::cerr << "resulting time = " << (tempoRealTime + RealTime::fromSeconds(seconds)) << std::endl; 798 DEBUG << "resulting time = " << (tempoRealTime + RealTime::fromSeconds(seconds)) << endl;
799 */ 799 */
800 800
801 return tempoRealTime + RealTime::fromSeconds(seconds); 801 return tempoRealTime + RealTime::fromSeconds(seconds);
802 } 802 }
803 803
1031 float level = float((*i)->getVelocity()) / 128.f; 1031 float level = float((*i)->getVelocity()) / 128.f;
1032 1032
1033 Note note(startFrame, (*i)->getPitch(), 1033 Note note(startFrame, (*i)->getPitch(),
1034 endFrame - startFrame, level, noteLabel); 1034 endFrame - startFrame, level, noteLabel);
1035 1035
1036 // std::cerr << "Adding note " << startFrame << "," << (endFrame-startFrame) << " : " << int((*i)->getPitch()) << std::endl; 1036 // DEBUG << "Adding note " << startFrame << "," << (endFrame-startFrame) << " : " << int((*i)->getPitch()) << endl;
1037 1037
1038 model->addPoint(note); 1038 model->addPoint(note);
1039 break; 1039 break;
1040 } 1040 }
1041 1041