#include <MIDIFileReader.h>
Inherits DataFileReader.
Inheritance diagram for MIDIFileReader:


Definition at line 38 of file MIDIFileReader.h.
Public Member Functions | |
| MIDIFileReader (QString path, size_t mainModelSampleRate) | |
| virtual | ~MIDIFileReader () |
| virtual bool | isOK () const |
| Return true if the file appears to be of the correct type. | |
| virtual QString | getError () const |
| virtual Model * | load () const |
| Read the file and return the corresponding data model. | |
Protected Types | |
| enum | MIDIFileFormatType { MIDI_SINGLE_TRACK_FILE = 0x00, MIDI_SIMULTANEOUS_TRACK_FILE = 0x01, MIDI_SEQUENTIAL_TRACK_FILE = 0x02, MIDI_FILE_BAD_FORMAT = 0xFF } |
| typedef std::vector< MIDIEvent * > | MIDITrack |
| typedef std::map< unsigned int, MIDITrack > | MIDIComposition |
| typedef std::pair< RealTime, double > | TempoChange |
| typedef std::map< unsigned long, TempoChange > | TempoMap |
Protected Member Functions | |
| bool | parseFile () |
| bool | parseHeader (const std::string &midiHeader) |
| bool | parseTrack (unsigned int &trackNum) |
| Model * | loadTrack (unsigned int trackNum, Model *existingModel=0, int minProgress=0, int progressAmount=100) const |
| bool | consolidateNoteOffEvents (unsigned int track) |
| void | updateTempoMap (unsigned int track) |
| void | calculateTempoTimestamps () |
| RealTime | getTimeForMIDITime (unsigned long midiTime) const |
| int | midiBytesToInt (const std::string &bytes) |
| long | midiBytesToLong (const std::string &bytes) |
| long | getNumberFromMIDIBytes (int firstByte=-1) |
| MIDIByte | getMIDIByte () |
| std::string | getMIDIBytes (unsigned long bytes) |
| bool | skipToNextTrack () |
Protected Attributes | |
| int | m_timingDivision |
| MIDIFileFormatType | m_format |
| unsigned int | m_numberOfTracks |
| long | m_trackByteCount |
| bool | m_decrementCount |
| std::map< int, QString > | m_trackNames |
| std::set< unsigned int > | m_loadableTracks |
| std::set< unsigned int > | m_percussionTracks |
| MIDIComposition | m_midiComposition |
| TempoMap | m_tempoMap |
| QString | m_path |
| std::ifstream * | m_midiFile |
| size_t | m_fileSize |
| QString | m_error |
| size_t | m_mainModelSampleRate |
typedef std::vector<MIDIEvent *> MIDIFileReader::MIDITrack [protected] |
Definition at line 51 of file MIDIFileReader.h.
typedef std::map<unsigned int, MIDITrack> MIDIFileReader::MIDIComposition [protected] |
Definition at line 52 of file MIDIFileReader.h.
typedef std::pair<RealTime, double> MIDIFileReader::TempoChange [protected] |
Definition at line 53 of file MIDIFileReader.h.
typedef std::map<unsigned long, TempoChange> MIDIFileReader::TempoMap [protected] |
Definition at line 54 of file MIDIFileReader.h.
enum MIDIFileReader::MIDIFileFormatType [protected] |
| MIDI_SINGLE_TRACK_FILE | |
| MIDI_SIMULTANEOUS_TRACK_FILE | |
| MIDI_SEQUENTIAL_TRACK_FILE | |
| MIDI_FILE_BAD_FORMAT |
Definition at line 56 of file MIDIFileReader.h.
| MIDIFileReader::MIDIFileReader | ( | QString | path, | |
| size_t | mainModelSampleRate | |||
| ) |
| MIDIFileReader::~MIDIFileReader | ( | ) | [virtual] |
| bool MIDIFileReader::isOK | ( | ) | const [virtual] |
Return true if the file appears to be of the correct type.
The DataFileReader will be constructed by passing a file path to its constructor. If the file can at that time be determined to be not of a type that this reader can read, it should return false in response to any subsequent call to isOK().
If the file is apparently of the correct type, isOK() should return true; if it turns out that the file cannot after all be read (because it's corrupted or the detection misfired), then the read() function may return NULL.
Implements DataFileReader.
Definition at line 94 of file MIDIFileReader.cpp.
References m_error.
Referenced by load().
| QString MIDIFileReader::getError | ( | ) | const [virtual] |
Reimplemented from DataFileReader.
Definition at line 100 of file MIDIFileReader.cpp.
References m_error.
| Model * MIDIFileReader::load | ( | ) | const [virtual] |
Read the file and return the corresponding data model.
This function is not expected to be thread-safe or reentrant. This function may be interactive (i.e. it's permitted to pop up dialogs and windows and ask the user to specify any details that can't be automatically extracted from the file).
Return NULL if the file cannot be parsed at all (although it's preferable to return a partial model and warn the user).
Caller owns the returned model and must delete it after use.
Implements DataFileReader.
Definition at line 811 of file MIDIFileReader.cpp.
References isOK(), loadTrack(), m_loadableTracks, m_path, m_percussionTracks, and m_trackNames.
| bool MIDIFileReader::parseFile | ( | ) | [protected] |
Definition at line 273 of file MIDIFileReader.cpp.
References calculateTempoTimestamps(), consolidateNoteOffEvents(), getMIDIBytes(), m_error, m_fileSize, m_format, m_loadableTracks, m_midiComposition, m_midiFile, m_numberOfTracks, m_path, m_trackByteCount, MIDI_FILE_BAD_FORMAT, parseHeader(), parseTrack(), skipToNextTrack(), updateTempoMap(), and MIDIException::what().
Referenced by MIDIFileReader().
| bool MIDIFileReader::parseHeader | ( | const std::string & | midiHeader | ) | [protected] |
Referenced by parseFile().
| bool MIDIFileReader::parseTrack | ( | unsigned int & | trackNum | ) | [protected] |
Definition at line 443 of file MIDIFileReader.cpp.
References MIDIEvent::getChannelNumber(), getMIDIByte(), getMIDIBytes(), getNumberFromMIDIBytes(), m_midiComposition, m_midiFile, m_percussionTracks, m_trackByteCount, m_trackNames, MIDIConstants::MIDI_CHANNEL_NUM_MASK, MIDIConstants::MIDI_CHNL_AFTERTOUCH, MIDIConstants::MIDI_CTRL_CHANGE, MIDIConstants::MIDI_END_OF_EXCLUSIVE, MIDIConstants::MIDI_FILE_META_EVENT, MIDIConstants::MIDI_MESSAGE_TYPE_MASK, MIDIConstants::MIDI_NOTE_OFF, MIDIConstants::MIDI_NOTE_ON, MIDIConstants::MIDI_PERCUSSION_CHANNEL, MIDIConstants::MIDI_PITCH_BEND, MIDIConstants::MIDI_POLY_AFTERTOUCH, MIDIConstants::MIDI_PROG_CHANGE, MIDIConstants::MIDI_STATUS_BYTE_MASK, MIDIConstants::MIDI_SYSTEM_EXCLUSIVE, and MIDIConstants::MIDI_TRACK_NAME.
Referenced by parseFile().
| Model * MIDIFileReader::loadTrack | ( | unsigned int | trackNum, | |
| Model * | existingModel = 0, |
|||
| int | minProgress = 0, |
|||
| int | progressAmount = 100 | |||
| ) | const [protected] |
Definition at line 926 of file MIDIFileReader.cpp.
References SparseValueModel< PointType >::addPoint(), Pitch::getPitchLabel(), SparseModel< PointType >::getSampleRate(), getTimeForMIDITime(), m_mainModelSampleRate, m_midiComposition, MIDIConstants::MIDI_CHANNEL_PREFIX, MIDIConstants::MIDI_CHANNEL_PREFIX_OR_PORT, MIDIConstants::MIDI_CHNL_AFTERTOUCH, MIDIConstants::MIDI_COPYRIGHT_NOTICE, MIDIConstants::MIDI_CTRL_CHANGE, MIDIConstants::MIDI_CUE_POINT, MIDIConstants::MIDI_INSTRUMENT_NAME, MIDIConstants::MIDI_KEY_SIGNATURE, MIDIConstants::MIDI_LYRIC, MIDIConstants::MIDI_NOTE_OFF, MIDIConstants::MIDI_NOTE_ON, MIDIConstants::MIDI_PITCH_BEND, MIDIConstants::MIDI_POLY_AFTERTOUCH, MIDIConstants::MIDI_PROG_CHANGE, MIDIConstants::MIDI_SEQUENCE_NUMBER, MIDIConstants::MIDI_SEQUENCER_SPECIFIC, MIDIConstants::MIDI_SET_TEMPO, MIDIConstants::MIDI_SMPTE_OFFSET, MIDIConstants::MIDI_SYSTEM_EXCLUSIVE, MIDIConstants::MIDI_TEXT_EVENT, MIDIConstants::MIDI_TEXT_MARKER, MIDIConstants::MIDI_TIME_SIGNATURE, MIDIConstants::MIDI_TRACK_NAME, RealTime::realTime2Frame(), SparseModel< PointType >::setCompletion(), and NoteModel::setValueQuantization().
Referenced by load().
| bool MIDIFileReader::consolidateNoteOffEvents | ( | unsigned int | track | ) | [protected] |
Definition at line 671 of file MIDIFileReader.cpp.
References m_midiComposition, MIDIConstants::MIDI_NOTE_OFF, and MIDIConstants::MIDI_NOTE_ON.
Referenced by parseFile().
| void MIDIFileReader::updateTempoMap | ( | unsigned int | track | ) | [protected] |
Definition at line 720 of file MIDIFileReader.cpp.
References m_midiComposition, m_tempoMap, MIDIConstants::MIDI_SET_TEMPO, and RealTime::zeroTime.
Referenced by parseFile().
| void MIDIFileReader::calculateTempoTimestamps | ( | ) | [protected] |
Definition at line 748 of file MIDIFileReader.cpp.
References RealTime::fromSeconds(), m_tempoMap, and RealTime::zeroTime.
Referenced by parseFile().
| RealTime MIDIFileReader::getTimeForMIDITime | ( | unsigned long | midiTime | ) | const [protected] |
Definition at line 774 of file MIDIFileReader.cpp.
References RealTime::fromSeconds(), m_tempoMap, and RealTime::zeroTime.
Referenced by loadTrack().
| int MIDIFileReader::midiBytesToInt | ( | const std::string & | bytes | ) | [protected] |
| long MIDIFileReader::midiBytesToLong | ( | const std::string & | bytes | ) | [protected] |
Referenced by skipToNextTrack().
| long MIDIFileReader::getNumberFromMIDIBytes | ( | int | firstByte = -1 |
) | [protected] |
Definition at line 208 of file MIDIFileReader.cpp.
References getMIDIByte(), and m_midiFile.
Referenced by parseTrack().
| MIDIByte MIDIFileReader::getMIDIByte | ( | ) | [protected] |
Definition at line 138 of file MIDIFileReader.cpp.
References m_decrementCount, m_midiFile, and m_trackByteCount.
Referenced by getNumberFromMIDIBytes(), and parseTrack().
| string MIDIFileReader::getMIDIBytes | ( | unsigned long | bytes | ) | [protected] |
Definition at line 167 of file MIDIFileReader.cpp.
References m_decrementCount, m_midiFile, and m_trackByteCount.
Referenced by parseFile(), parseTrack(), and skipToNextTrack().
| bool MIDIFileReader::skipToNextTrack | ( | ) | [protected] |
Definition at line 242 of file MIDIFileReader.cpp.
References getMIDIBytes(), m_decrementCount, m_midiFile, m_trackByteCount, MIDIConstants::MIDI_TRACK_HEADER, and midiBytesToLong().
Referenced by parseFile().
int MIDIFileReader::m_timingDivision [protected] |
Definition at line 89 of file MIDIFileReader.h.
MIDIFileFormatType MIDIFileReader::m_format [protected] |
unsigned int MIDIFileReader::m_numberOfTracks [protected] |
long MIDIFileReader::m_trackByteCount [protected] |
Definition at line 93 of file MIDIFileReader.h.
Referenced by getMIDIByte(), getMIDIBytes(), parseFile(), parseTrack(), and skipToNextTrack().
bool MIDIFileReader::m_decrementCount [protected] |
Definition at line 94 of file MIDIFileReader.h.
Referenced by getMIDIByte(), getMIDIBytes(), and skipToNextTrack().
std::map<int, QString> MIDIFileReader::m_trackNames [protected] |
std::set<unsigned int> MIDIFileReader::m_loadableTracks [protected] |
std::set<unsigned int> MIDIFileReader::m_percussionTracks [protected] |
MIDIComposition MIDIFileReader::m_midiComposition [protected] |
Definition at line 99 of file MIDIFileReader.h.
Referenced by consolidateNoteOffEvents(), loadTrack(), parseFile(), parseTrack(), updateTempoMap(), and ~MIDIFileReader().
TempoMap MIDIFileReader::m_tempoMap [protected] |
Definition at line 100 of file MIDIFileReader.h.
Referenced by calculateTempoTimestamps(), getTimeForMIDITime(), and updateTempoMap().
QString MIDIFileReader::m_path [protected] |
std::ifstream* MIDIFileReader::m_midiFile [protected] |
Definition at line 103 of file MIDIFileReader.h.
Referenced by getMIDIByte(), getMIDIBytes(), getNumberFromMIDIBytes(), parseFile(), parseTrack(), and skipToNextTrack().
size_t MIDIFileReader::m_fileSize [protected] |
QString MIDIFileReader::m_error [protected] |
Definition at line 105 of file MIDIFileReader.h.
Referenced by getError(), isOK(), MIDIFileReader(), and parseFile().
size_t MIDIFileReader::m_mainModelSampleRate [protected] |
1.5.1