1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
4 // Copyright(C) 2009 Simon Howard
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 //-----------------------------------------------------------------------------
29 typedef struct midi_file_s midi_file_t
;
30 typedef struct midi_track_iter_s midi_track_iter_t
;
32 #define MIDI_CHANNELS_PER_TRACK 16
36 MIDI_EVENT_NOTE_OFF
= 0x80,
37 MIDI_EVENT_NOTE_ON
= 0x90,
38 MIDI_EVENT_AFTERTOUCH
= 0xa0,
39 MIDI_EVENT_CONTROLLER
= 0xb0,
40 MIDI_EVENT_PROGRAM_CHANGE
= 0xc0,
41 MIDI_EVENT_CHAN_AFTERTOUCH
= 0xd0,
42 MIDI_EVENT_PITCH_BEND
= 0xe0,
44 MIDI_EVENT_SYSEX
= 0xf0,
45 MIDI_EVENT_SYSEX_SPLIT
= 0xf7,
46 MIDI_EVENT_META
= 0xff,
51 MIDI_CONTROLLER_BANK_SELECT
= 0x0,
52 MIDI_CONTROLLER_MODULATION
= 0x1,
53 MIDI_CONTROLLER_BREATH_CONTROL
= 0x2,
54 MIDI_CONTROLLER_FOOT_CONTROL
= 0x3,
55 MIDI_CONTROLLER_PORTAMENTO
= 0x4,
56 MIDI_CONTROLLER_DATA_ENTRY
= 0x5,
58 MIDI_CONTROLLER_MAIN_VOLUME
= 0x7,
59 MIDI_CONTROLLER_PAN
= 0xa
64 MIDI_META_SEQUENCE_NUMBER
= 0x0,
67 MIDI_META_COPYRIGHT
= 0x2,
68 MIDI_META_TRACK_NAME
= 0x3,
69 MIDI_META_INSTR_NAME
= 0x4,
70 MIDI_META_LYRICS
= 0x5,
71 MIDI_META_MARKER
= 0x6,
72 MIDI_META_CUE_POINT
= 0x7,
74 MIDI_META_CHANNEL_PREFIX
= 0x20,
75 MIDI_META_END_OF_TRACK
= 0x2f,
77 MIDI_META_SET_TEMPO
= 0x51,
78 MIDI_META_SMPTE_OFFSET
= 0x54,
79 MIDI_META_TIME_SIGNATURE
= 0x58,
80 MIDI_META_KEY_SIGNATURE
= 0x59,
81 MIDI_META_SEQUENCER_SPECIFIC
= 0x7f,
82 } midi_meta_event_type_t
;
97 } midi_meta_event_data_t
;
108 } midi_sysex_event_data_t
;
112 // The channel number to which this applies:
114 unsigned int channel
;
120 } midi_channel_event_data_t
;
124 // Time between the previous event and this event.
125 unsigned int delta_time
;
128 midi_event_type_t event_type
;
132 midi_channel_event_data_t channel
;
133 midi_meta_event_data_t meta
;
134 midi_sysex_event_data_t sysex
;
140 midi_file_t
*MIDI_LoadFile(char *filename
);
144 void MIDI_FreeFile(midi_file_t
*file
);
146 // Get the time division value from the MIDI header.
148 unsigned int MIDI_GetFileTimeDivision(midi_file_t
*file
);
150 // Get the number of tracks in a MIDI file.
152 unsigned int MIDI_NumTracks(midi_file_t
*file
);
154 // Start iterating over the events in a track.
156 midi_track_iter_t
*MIDI_IterateTrack(midi_file_t
*file
, unsigned int track_num
);
160 void MIDI_FreeIterator(midi_track_iter_t
*iter
);
162 // Get the time until the next MIDI event in a track.
164 unsigned int MIDI_GetDeltaTime(midi_track_iter_t
*iter
);
166 // Get a pointer to the next MIDI event.
168 int MIDI_GetNextEvent(midi_track_iter_t
*iter
, midi_event_t
**event
);
170 // Reset an iterator to the beginning of a track.
172 void MIDI_RestartIterator(midi_track_iter_t
*iter
);
174 #endif /* #ifndef MIDIFILE_H */