MIDITIME.HPP
资源名称:midi2txt.rar [点击查看]
上传用户:sun1865
上传日期:2008-12-23
资源大小:59k
文件大小:3k
源码类别:
midi
开发平台:
Visual C++
- #ifndef __MIDITIMETAB__
- #define __MIDITIMETAB__
- #include "midiio.hpp"
- class MidiTempoChange
- {
- public:
- MidiTempoChange();
- unsigned long unit;
- unsigned long tempo; // microseconds/beat
- };
- class MidiTactChange
- {
- public:
- MidiTactChange();
- unsigned long unit;
- int tactnom, tactdenom;
- };
- class MidiTimeTable : public MidiRead
- {
- public:
- MidiTimeTable(const char* filename, FILE* midif = 0);
- virtual ~MidiTimeTable();
- // calculations after successful calling run() !!
- unsigned long timeAt(unsigned long unit); // milliseconds
- unsigned long unitAt(unsigned long millisec);
- unsigned long tempoAt(long unit); // microseconds/beat
- int tactnomAt(long unit);
- int tactdenomAt(long unit);
- void tactAt(unsigned long unit, int& tactnom, int& tactdenom);
- unsigned int tactLength(int nom, int denom);
- unsigned long totalunits();
- unsigned long totaltime(); // milliseconds
- // virtual members (if deriving them then call base member!!)
- virtual void track(int trackno, long length, int channel);
- virtual void endtrack(int trackno); // closing track
- virtual void tempo(unsigned long microsecperbeat);
- virtual void tact(int nom, int denom, int, int);
- // options
- int calctempotable_;
- // should load tempo table for time calculations (is default)
- int calctacttable_;
- // should load tact table for tact calculations (is default)
- int calctotaltime_; // requires reading of whole file!
- // read all tracks and calculate total time and total length of midi file
- // (not default because whole file must be read)
- const MidiTempoChange* tempoChange(int changeidx) const;
- const MidiTactChange* tactChange(int changeidx) const;
- unsigned long MeasureInfo(unsigned long unit, int& measurenr, int& tactnom, int& tactdenom);
- // searches measure, its tact and returns measure start unit
- void measureAt(unsigned long unit, int& measureidx, int& nomidx, int& tick);
- int MeasureIndex(unsigned long unit);
- unsigned long MeasureAt(int measureidx);
- unsigned int MeasureLength(int measureidx);
- unsigned long nextMeasure(unsigned long unit);
- virtual void printTempoChanges(FILE* f = 0);
- virtual void printTactChanges(FILE* f = 0);
- virtual void printMeasures(FILE* f = 0);
- protected:
- int tempochanges_;
- MidiTempoChange **tempochange_;
- unsigned long totalunits_;
- unsigned long totaltime_;
- void addtempochange(unsigned long unit, unsigned long tempo);
- void resettempochange();
- protected:
- int tactchanges_;
- MidiTactChange** tactchange_;
- void addtactchange(unsigned long unit, int tactnom, int tactdenom);
- void resettactchange();
- };
- #endif