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 @ 1:3e65e0344413
History | View | Annotate | Download (1.82 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-2006 Richard Bown and Chris Cannam.
|
| 7 |
*/
|
| 8 |
|
| 9 |
#ifndef _MIDI_FILE_READER_H_
|
| 10 |
#define _MIDI_FILE_READER_H_
|
| 11 |
|
| 12 |
#include <QObject> |
| 13 |
#include <QList> |
| 14 |
#include <QMap> |
| 15 |
#include <QSet> |
| 16 |
|
| 17 |
#include <iostream> |
| 18 |
|
| 19 |
#include "MIDIComposition.h" |
| 20 |
|
| 21 |
typedef unsigned char MIDIByte; |
| 22 |
|
| 23 |
class MIDIFileReader |
| 24 |
{
|
| 25 |
public:
|
| 26 |
MIDIFileReader(QString path); |
| 27 |
virtual ~MIDIFileReader(); |
| 28 |
|
| 29 |
virtual bool isOK() const; |
| 30 |
virtual QString getError() const;
|
| 31 |
|
| 32 |
virtual MIDIComposition load() const;
|
| 33 |
|
| 34 |
MIDIConstants::MIDIFileFormatType getFormat() const { return m_format; } |
| 35 |
int getTimingDivision() const { return m_timingDivision; } |
| 36 |
|
| 37 |
protected:
|
| 38 |
|
| 39 |
bool parseFile();
|
| 40 |
bool parseHeader(const std::string &midiHeader); |
| 41 |
bool parseTrack(unsigned int trackNum); |
| 42 |
bool consolidateNoteOffEvents(unsigned int track); |
| 43 |
|
| 44 |
// Internal convenience functions
|
| 45 |
//
|
| 46 |
int midiBytesToInt(const std::string &bytes); |
| 47 |
long midiBytesToLong(const std::string &bytes); |
| 48 |
|
| 49 |
long getNumberFromMIDIBytes(int firstByte = -1); |
| 50 |
|
| 51 |
MIDIByte getMIDIByte(); |
| 52 |
std::string getMIDIBytes(unsigned long bytes); |
| 53 |
|
| 54 |
bool skipToNextTrack();
|
| 55 |
|
| 56 |
int m_timingDivision; // pulses per quarter note |
| 57 |
MIDIConstants::MIDIFileFormatType m_format; |
| 58 |
unsigned int m_numberOfTracks; |
| 59 |
|
| 60 |
long m_trackByteCount;
|
| 61 |
bool m_decrementCount;
|
| 62 |
|
| 63 |
QMap<int, QString> m_trackNames;
|
| 64 |
MIDIComposition m_midiComposition; |
| 65 |
|
| 66 |
QString m_path; |
| 67 |
std::ifstream *m_midiFile; |
| 68 |
size_t m_fileSize; |
| 69 |
QString m_error; |
| 70 |
}; |
| 71 |
|
| 72 |
|
| 73 |
#endif // _MIDI_FILE_READER_H_ |