Mercurial > hg > midi-score-follower
comparison midiFileReader/MIDIFileReader.h @ 0:b299a65a3ad0
start project
| author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
|---|---|
| date | Tue, 16 Aug 2011 11:29:59 +0100 |
| parents | |
| children | 5a11b19906c7 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:b299a65a3ad0 |
|---|---|
| 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
| 2 | |
| 3 /* | |
| 4 This is a modified version of a source file from the | |
| 5 Rosegarden MIDI and audio sequencer and notation editor. | |
| 6 This file copyright 2000-2010 Richard Bown and Chris Cannam. | |
| 7 | |
| 8 Permission is hereby granted, free of charge, to any person | |
| 9 obtaining a copy of this software and associated documentation | |
| 10 files (the "Software"), to deal in the Software without | |
| 11 restriction, including without limitation the rights to use, copy, | |
| 12 modify, merge, publish, distribute, sublicense, and/or sell copies | |
| 13 of the Software, and to permit persons to whom the Software is | |
| 14 furnished to do so, subject to the following conditions: | |
| 15 | |
| 16 The above copyright notice and this permission notice shall be | |
| 17 included in all copies or substantial portions of the Software. | |
| 18 | |
| 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
| 20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
| 21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
| 22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | |
| 23 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
| 24 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
| 25 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 26 | |
| 27 Except as contained in this notice, the names of the authors | |
| 28 shall not be used in advertising or otherwise to promote the sale, | |
| 29 use or other dealings in this Software without prior written | |
| 30 authorization. | |
| 31 */ | |
| 32 | |
| 33 #ifndef _MIDI_FILE_READER_H_ | |
| 34 #define _MIDI_FILE_READER_H_ | |
| 35 | |
| 36 #include "MIDIComposition.h" | |
| 37 | |
| 38 #include <set> | |
| 39 #include <iostream> | |
| 40 | |
| 41 typedef unsigned char MIDIByte; | |
| 42 | |
| 43 class MIDIFileReader | |
| 44 { | |
| 45 public: | |
| 46 MIDIFileReader(std::string path); | |
| 47 virtual ~MIDIFileReader(); | |
| 48 | |
| 49 virtual bool isOK() const; | |
| 50 virtual std::string getError() const; | |
| 51 | |
| 52 virtual MIDIComposition load() const; | |
| 53 | |
| 54 MIDIConstants::MIDIFileFormatType getFormat() const { return m_format; } | |
| 55 int getTimingDivision() const { return m_timingDivision; } | |
| 56 | |
| 57 protected: | |
| 58 | |
| 59 bool parseFile(); | |
| 60 bool parseHeader(const std::string &midiHeader); | |
| 61 bool parseTrack(unsigned int trackNum); | |
| 62 bool consolidateNoteOffEvents(unsigned int track); | |
| 63 | |
| 64 // Internal convenience functions | |
| 65 // | |
| 66 int midiBytesToInt(const std::string &bytes); | |
| 67 long midiBytesToLong(const std::string &bytes); | |
| 68 | |
| 69 long getNumberFromMIDIBytes(int firstByte = -1); | |
| 70 | |
| 71 MIDIByte getMIDIByte(); | |
| 72 std::string getMIDIBytes(unsigned long bytes); | |
| 73 | |
| 74 bool skipToNextTrack(); | |
| 75 | |
| 76 int m_timingDivision; // pulses per quarter note | |
| 77 MIDIConstants::MIDIFileFormatType m_format; | |
| 78 unsigned int m_numberOfTracks; | |
| 79 | |
| 80 long m_trackByteCount; | |
| 81 bool m_decrementCount; | |
| 82 | |
| 83 std::map<int, std::string> m_trackNames; | |
| 84 MIDIComposition m_midiComposition; | |
| 85 | |
| 86 std::string m_path; | |
| 87 std::ifstream *m_midiFile; | |
| 88 size_t m_fileSize; | |
| 89 std::string m_error; | |
| 90 }; | |
| 91 | |
| 92 | |
| 93 #endif // _MIDI_FILE_READER_H_ |
