mfmidi.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <cstddef>
  2. #define NOTEOFF 0x80
  3. #define NOTEON 0x90
  4. #define PRESSURE 0xa0
  5. #define CONTROLLER 0xb0
  6. #define PITCHBEND 0xe0
  7. #define PROGRAM 0xc0
  8. #define CHANPRESSURE 0xd0
  9. /* These are the strings used in keynote to identify Standard MIDI File */
  10. /* meta text messages. */
  11. #define METATEXT "Text Event"
  12. #define METACOPYRIGHT "Copyright Notice"
  13. #define METASEQUENCE "Sequence/Track Name"
  14. #define METAINSTRUMENT "Instrument Name"
  15. #define METALYRIC "Lyric"
  16. #define METAMARKER "Marker"
  17. #define METACUE "Cue Point"
  18. #define METAUNRECOGNIZED "Unrecognized"
  19. class Midifile_reader {
  20. public:
  21. void midifile();
  22. int Mf_nomerge; /* 1 => continue'ed system exclusives are */
  23. /* not collapsed. */
  24. long Mf_currtime; /* current time in delta-time units */
  25. int Mf_skipinit; /* 1 if initial garbage should be skipped */
  26. Midifile_reader();
  27. // call finalize() when done or you may leak memory.
  28. void finalize(); /* clean up before deletion */
  29. // Note: rather than finalize, we should have ~Midifile_reader(),
  30. // but at least VC++ complains that there is no Mf_free(), even
  31. // though Mf_free is declared as virtual and this is an abstract
  32. // class. I don't understand this, so finalize() is a workaround. -RBD
  33. protected:
  34. int midifile_error;
  35. virtual void *Mf_malloc(size_t size) = 0; /* malloc() */
  36. virtual void Mf_free(void *obj, size_t size) = 0; /* free() */
  37. /* Methods to be called while processing the MIDI file. */
  38. virtual void Mf_starttrack() = 0;
  39. virtual void Mf_endtrack() = 0;
  40. virtual int Mf_getc() = 0;
  41. virtual void Mf_chanprefix(int) = 0;
  42. virtual void Mf_portprefix(int) = 0;
  43. virtual void Mf_eot() = 0;
  44. virtual void Mf_error(char *) = 0;
  45. virtual void Mf_header(int,int,int) = 0;
  46. virtual void Mf_on(int,int,int) = 0;
  47. virtual void Mf_off(int,int,int) = 0;
  48. virtual void Mf_pressure(int,int,int) = 0;
  49. virtual void Mf_controller(int,int,int) = 0;
  50. virtual void Mf_pitchbend(int,int,int) = 0;
  51. virtual void Mf_program(int,int) = 0;
  52. virtual void Mf_chanpressure(int,int) = 0;
  53. virtual void Mf_sysex(int,unsigned char*) = 0;
  54. virtual void Mf_arbitrary(int,unsigned char*) = 0;
  55. virtual void Mf_metamisc(int,int,unsigned char*) = 0;
  56. virtual void Mf_seqnum(int) = 0;
  57. virtual void Mf_smpte(int,int,int,int,int) = 0;
  58. virtual void Mf_timesig(int,int,int,int) = 0;
  59. virtual void Mf_tempo(int) = 0;
  60. virtual void Mf_keysig(int,int) = 0;
  61. virtual void Mf_sqspecific(int,unsigned char*) = 0;
  62. virtual void Mf_text(int,int,unsigned char*) = 0;
  63. private:
  64. long Mf_toberead;
  65. long readvarinum();
  66. long read32bit();
  67. int read16bit();
  68. void msgenlarge();
  69. unsigned char *msg();
  70. int readheader();
  71. void readtrack();
  72. void sysex();
  73. void msginit();
  74. int egetc();
  75. int msgleng();
  76. int readmt(const char*,int);
  77. long to32bit(int,int,int,int);
  78. int to16bit(int,int);
  79. void mferror(char *);
  80. void mferror(const char *);
  81. void badbyte(int);
  82. void metaevent(int);
  83. void msgadd(int);
  84. void chanmessage(int,int,int);
  85. unsigned char *Msgbuff;
  86. long Msgsize;
  87. long Msgindex;
  88. };