To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / MIDIFileReader.h @ 4:a98a66b43882
History | View | Annotate | Download (3.08 KB)
| 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 <QObject> |
| 37 |
#include <QList> |
| 38 |
#include <QMap> |
| 39 |
#include <QSet> |
| 40 |
|
| 41 |
#include <iostream> |
| 42 |
|
| 43 |
#include "MIDIComposition.h" |
| 44 |
|
| 45 |
typedef unsigned char MIDIByte; |
| 46 |
|
| 47 |
class MIDIFileReader |
| 48 |
{
|
| 49 |
public:
|
| 50 |
MIDIFileReader(QString path); |
| 51 |
virtual ~MIDIFileReader(); |
| 52 |
|
| 53 |
virtual bool isOK() const; |
| 54 |
virtual QString getError() const;
|
| 55 |
|
| 56 |
virtual MIDIComposition load() const;
|
| 57 |
|
| 58 |
MIDIConstants::MIDIFileFormatType getFormat() const { return m_format; } |
| 59 |
int getTimingDivision() const { return m_timingDivision; } |
| 60 |
|
| 61 |
protected:
|
| 62 |
|
| 63 |
bool parseFile();
|
| 64 |
bool parseHeader(const std::string &midiHeader); |
| 65 |
bool parseTrack(unsigned int trackNum); |
| 66 |
bool consolidateNoteOffEvents(unsigned int track); |
| 67 |
|
| 68 |
// Internal convenience functions
|
| 69 |
//
|
| 70 |
int midiBytesToInt(const std::string &bytes); |
| 71 |
long midiBytesToLong(const std::string &bytes); |
| 72 |
|
| 73 |
long getNumberFromMIDIBytes(int firstByte = -1); |
| 74 |
|
| 75 |
MIDIByte getMIDIByte(); |
| 76 |
std::string getMIDIBytes(unsigned long bytes); |
| 77 |
|
| 78 |
bool skipToNextTrack();
|
| 79 |
|
| 80 |
int m_timingDivision; // pulses per quarter note |
| 81 |
MIDIConstants::MIDIFileFormatType m_format; |
| 82 |
unsigned int m_numberOfTracks; |
| 83 |
|
| 84 |
long m_trackByteCount;
|
| 85 |
bool m_decrementCount;
|
| 86 |
|
| 87 |
QMap<int, QString> m_trackNames;
|
| 88 |
MIDIComposition m_midiComposition; |
| 89 |
|
| 90 |
QString m_path; |
| 91 |
std::ifstream *m_midiFile; |
| 92 |
size_t m_fileSize; |
| 93 |
QString m_error; |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
#endif // _MIDI_FILE_READER_H_ |