comparison data/fileio/MIDIFileReader.cpp @ 1599:ce185d4dd408 bqaudiostream

Merge from default branch
author Chris Cannam
date Wed, 23 Jan 2019 14:43:43 +0000
parents 70e172e6cc59
children 7a23dfe65d66
comparison
equal deleted inserted replaced
1598:d2555df635ec 1599:ce185d4dd408
67 m_format(MIDI_FILE_BAD_FORMAT), 67 m_format(MIDI_FILE_BAD_FORMAT),
68 m_numberOfTracks(0), 68 m_numberOfTracks(0),
69 m_trackByteCount(0), 69 m_trackByteCount(0),
70 m_decrementCount(false), 70 m_decrementCount(false),
71 m_path(path), 71 m_path(path),
72 m_midiFile(0), 72 m_midiFile(nullptr),
73 m_fileSize(0), 73 m_fileSize(0),
74 m_mainModelSampleRate(mainModelSampleRate), 74 m_mainModelSampleRate(mainModelSampleRate),
75 m_acquirer(acquirer) 75 m_acquirer(acquirer)
76 { 76 {
77 if (parseFile()) { 77 if (parseFile()) {
289 289
290 if (!*m_midiFile) { 290 if (!*m_midiFile) {
291 m_error = "File not found or not readable."; 291 m_error = "File not found or not readable.";
292 m_format = MIDI_FILE_BAD_FORMAT; 292 m_format = MIDI_FILE_BAD_FORMAT;
293 delete m_midiFile; 293 delete m_midiFile;
294 m_midiFile = 0; 294 m_midiFile = nullptr;
295 return false; 295 return false;
296 } 296 }
297 297
298 bool retval = false; 298 bool retval = false;
299 299
799 } 799 }
800 800
801 Model * 801 Model *
802 MIDIFileReader::load() const 802 MIDIFileReader::load() const
803 { 803 {
804 if (!isOK()) return 0; 804 if (!isOK()) return nullptr;
805 805
806 if (m_loadableTracks.empty()) { 806 if (m_loadableTracks.empty()) {
807 if (m_acquirer) { 807 if (m_acquirer) {
808 m_acquirer->showError 808 m_acquirer->showError
809 (tr("MIDI file \"%1\" has no notes in any track").arg(m_path)); 809 (tr("MIDI file \"%1\" has no notes in any track").arg(m_path));
810 } 810 }
811 return 0; 811 return nullptr;
812 } 812 }
813 813
814 std::set<unsigned int> tracksToLoad; 814 std::set<unsigned int> tracksToLoad;
815 815
816 if (m_loadableTracks.size() == 1) { 816 if (m_loadableTracks.size() == 1) {
857 singleTrack); 857 singleTrack);
858 } else { 858 } else {
859 pref = MIDIFileImportPreferenceAcquirer::MergeAllTracks; 859 pref = MIDIFileImportPreferenceAcquirer::MergeAllTracks;
860 } 860 }
861 861
862 if (pref == MIDIFileImportPreferenceAcquirer::ImportNothing) return 0; 862 if (pref == MIDIFileImportPreferenceAcquirer::ImportNothing) return nullptr;
863 863
864 if (pref == MIDIFileImportPreferenceAcquirer::MergeAllTracks || 864 if (pref == MIDIFileImportPreferenceAcquirer::MergeAllTracks ||
865 pref == MIDIFileImportPreferenceAcquirer::MergeAllNonPercussionTracks) { 865 pref == MIDIFileImportPreferenceAcquirer::MergeAllNonPercussionTracks) {
866 866
867 for (set<unsigned int>::iterator i = m_loadableTracks.begin(); 867 for (set<unsigned int>::iterator i = m_loadableTracks.begin();
889 ++j; 889 ++j;
890 } 890 }
891 } 891 }
892 } 892 }
893 893
894 if (tracksToLoad.empty()) return 0; 894 if (tracksToLoad.empty()) return nullptr;
895 895
896 int n = int(tracksToLoad.size()), count = 0; 896 int n = int(tracksToLoad.size()), count = 0;
897 Model *model = 0; 897 Model *model = nullptr;
898 898
899 for (std::set<unsigned int>::iterator i = tracksToLoad.begin(); 899 for (std::set<unsigned int>::iterator i = tracksToLoad.begin();
900 i != tracksToLoad.end(); ++i) { 900 i != tracksToLoad.end(); ++i) {
901 901
902 int minProgress = (100 * count) / n; 902 int minProgress = (100 * count) / n;
919 Model *existingModel, 919 Model *existingModel,
920 int minProgress, 920 int minProgress,
921 int progressAmount) const 921 int progressAmount) const
922 { 922 {
923 if (m_midiComposition.find(trackToLoad) == m_midiComposition.end()) { 923 if (m_midiComposition.find(trackToLoad) == m_midiComposition.end()) {
924 return 0; 924 return nullptr;
925 } 925 }
926 926
927 NoteModel *model = 0; 927 NoteModel *model = nullptr;
928 928
929 if (existingModel) { 929 if (existingModel) {
930 model = dynamic_cast<NoteModel *>(existingModel); 930 model = dynamic_cast<NoteModel *>(existingModel);
931 if (!model) { 931 if (!model) {
932 SVDEBUG << "WARNING: MIDIFileReader::loadTrack: Existing model given, but it isn't a NoteModel -- ignoring it" << endl; 932 SVDEBUG << "WARNING: MIDIFileReader::loadTrack: Existing model given, but it isn't a NoteModel -- ignoring it" << endl;