home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu 2008 / 2008-06-02_hobbes.nmsu.edu.zip / new / scummc-0.2.0-os2.zip / ScummC / src / scc_smf.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-11-01  |  2.9 KB  |  93 lines

  1. /* ScummC
  2.  * Copyright (C) 2006  Alban Bedel
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  17.  *
  18.  */
  19.  
  20. /** @file scc_smf.h
  21.  *  @brief A simple Standard MIDI File parser/writer.
  22.  */
  23.  
  24. #define SMF_META_EVENT            0xFF
  25. #define SMF_SYSEX_EVENT           0xF0
  26. #define SMF_SYSEX_CONTINUATION    0xF7
  27.  
  28. /// A MIDI event.
  29. typedef struct scc_smf_event {
  30.     struct scc_smf_event* next;
  31.     uint64_t time;          ///< Absolute time position.
  32.     uint8_t  cmd;           ///< Event command.
  33.     uint8_t  meta;          ///< Meta event code
  34.     unsigned args_size;     ///< Size of the arguments
  35.     unsigned char args[0];
  36. } scc_smf_event_t;
  37.  
  38. /// A MIDI track.
  39. typedef struct scc_smf_track {
  40.     unsigned size;                ///< Size of the track when wrote in a file.
  41.     scc_smf_event_t *events;      ///< Event list.
  42.     scc_smf_event_t *last_event;  ///< Event list tail.
  43. } scc_smf_track_t;
  44.  
  45. /// A MIDI file.
  46. typedef struct scc_smf {
  47.     unsigned size;             ///< Size of the whole file.
  48.     unsigned type;             ///< MIDI file type.
  49.     unsigned division;
  50.     unsigned num_track;
  51.     scc_smf_track_t* track;
  52. } scc_smf_t;
  53.  
  54. /// Read a MIDI variable length integer.
  55. unsigned scc_fd_read_smf_int(scc_fd_t* fd, unsigned max_size,
  56.                              uint32_t* ret);
  57.  
  58. /// Write a MIDI variable length integer.
  59. int scc_fd_write_smf_int(scc_fd_t* fd, unsigned v);
  60.  
  61. /// Parse a MIDI file from a scc_fd_t.
  62. scc_smf_t* scc_smf_parse(scc_fd_t* fd);
  63.  
  64. /// Parse a MIDI file at the given path.
  65. scc_smf_t* scc_smf_parse_file(char* file);
  66.  
  67. /// Free the memory used for the MIDI file.
  68. void scc_smf_free(scc_smf_t* smf);
  69.  
  70. /// Find the size of an integer coded in variable length.
  71. unsigned scc_smf_get_int_size(unsigned v);
  72.  
  73. /// Compute the size of a MIDI track.
  74. int scc_smf_track_get_size(scc_smf_track_t* track);
  75.  
  76. /// Compute the size of a whole MIDI file.
  77. int scc_smf_get_size(scc_smf_t* smf);
  78.  
  79. /// Remove a track.
  80. int scc_smf_remove_track(scc_smf_t* smf, unsigned track);
  81.  
  82. /// Merge 2 tracks together.
  83. int scc_smf_merge_track(scc_smf_t* smf, unsigned trackA, unsigned trackB);
  84.  
  85. /// Write a MIDI file to a fd.
  86. int scc_smf_write(scc_smf_t* smf, scc_fd_t* fd);
  87.  
  88. /// Save to a MIDI file
  89. int scc_smf_write_file(scc_smf_t* smf, char* path);
  90.  
  91. /// Print all the tracks and their events, for debug purpose.
  92. void scc_smf_dump(scc_smf_t* smf);
  93.