comparison data/fileio/MIDIFileReader.h @ 1527:710e6250a401 zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:14 +0100
parents 1dc64d3d323c
children c01cbe41aeb5
comparison
equal deleted inserted replaced
1324:d4a28d1479a8 1527:710e6250a401
10 published by the Free Software Foundation; either version 2 of the 10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file 11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information. 12 COPYING included with this distribution for more information.
13 */ 13 */
14 14
15
16 /* 15 /*
17 This is a modified version of a source file from the 16 This is a modified version of a source file from the
18 Rosegarden MIDI and audio sequencer and notation editor. 17 Rosegarden MIDI and audio sequencer and notation editor.
19 This file copyright 2000-2006 Richard Bown and Chris Cannam. 18 This file copyright 2000-2006 Richard Bown and Chris Cannam.
20 */ 19 */
21 20
22 #ifndef _MIDI_FILE_READER_H_ 21 #ifndef SV_MIDI_FILE_READER_H
23 #define _MIDI_FILE_READER_H_ 22 #define SV_MIDI_FILE_READER_H
24 23
25 #include "DataFileReader.h" 24 #include "DataFileReader.h"
26 #include "base/RealTime.h" 25 #include "base/RealTime.h"
27 26
28 #include <map> 27 #include <map>
30 #include <vector> 29 #include <vector>
31 30
32 #include <QObject> 31 #include <QObject>
33 32
34 class MIDIEvent; 33 class MIDIEvent;
34 class ProgressReporter;
35 35
36 typedef unsigned char MIDIByte; 36 typedef unsigned char MIDIByte;
37 37
38 class MIDIFileImportPreferenceAcquirer // welcome to our grand marble foyer 38 class MIDIFileImportPreferenceAcquirer // welcome to our grand marble foyer
39 { 39 {
59 { 59 {
60 Q_OBJECT 60 Q_OBJECT
61 61
62 public: 62 public:
63 MIDIFileReader(QString path, 63 MIDIFileReader(QString path,
64 MIDIFileImportPreferenceAcquirer *pref, 64 MIDIFileImportPreferenceAcquirer *pref, // may be null
65 sv_samplerate_t mainModelSampleRate); 65 sv_samplerate_t mainModelSampleRate,
66 ProgressReporter *reporter = 0);
66 virtual ~MIDIFileReader(); 67 virtual ~MIDIFileReader();
67 68
68 virtual bool isOK() const; 69 virtual bool isOK() const;
69 virtual QString getError() const; 70 virtual QString getError() const;
70 virtual Model *load() const; 71 virtual Model *load() const;
74 typedef std::map<unsigned int, MIDITrack> MIDIComposition; 75 typedef std::map<unsigned int, MIDITrack> MIDIComposition;
75 typedef std::pair<RealTime, double> TempoChange; // time, qpm 76 typedef std::pair<RealTime, double> TempoChange; // time, qpm
76 typedef std::map<unsigned long, TempoChange> TempoMap; // key is MIDI time 77 typedef std::map<unsigned long, TempoChange> TempoMap; // key is MIDI time
77 78
78 typedef enum { 79 typedef enum {
79 MIDI_SINGLE_TRACK_FILE = 0x00, 80 MIDI_SINGLE_TRACK_FILE = 0x00,
80 MIDI_SIMULTANEOUS_TRACK_FILE = 0x01, 81 MIDI_SIMULTANEOUS_TRACK_FILE = 0x01,
81 MIDI_SEQUENTIAL_TRACK_FILE = 0x02, 82 MIDI_SEQUENTIAL_TRACK_FILE = 0x02,
82 MIDI_FILE_BAD_FORMAT = 0xFF 83 MIDI_FILE_BAD_FORMAT = 0xFF
83 } MIDIFileFormatType; 84 } MIDIFileFormatType;
84 85
85 bool parseFile(); 86 bool parseFile();
86 bool parseHeader(const std::string &midiHeader); 87 bool parseHeader(const std::string &midiHeader);
87 bool parseTrack(unsigned int &trackNum); 88 bool parseTrack(unsigned int &trackNum);
88 89
89 Model *loadTrack(unsigned int trackNum, 90 Model *loadTrack(unsigned int trackNum,
90 Model *existingModel = 0, 91 Model *existingModel = 0,
91 int minProgress = 0, 92 int minProgress = 0,
92 int progressAmount = 100) const; 93 int progressAmount = 100) const;
93 94
94 bool consolidateNoteOffEvents(unsigned int track); 95 bool consolidateNoteOffEvents(unsigned int track);
95 void updateTempoMap(unsigned int track); 96 void updateTempoMap(unsigned int track);
96 void calculateTempoTimestamps(); 97 void calculateTempoTimestamps();
97 RealTime getTimeForMIDITime(unsigned long midiTime) const; 98 RealTime getTimeForMIDITime(unsigned long midiTime) const;