annotate midiFileReader/MIDIFileReader.h @ 36:5a1b0c6fa1fb

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