| 1 | /*(LGPL) |
| 2 | ------------------------------------------------------------ |
| 3 | a_midifile.c - MIDI file loader and player |
| 4 | ------------------------------------------------------------ |
| 5 | * Stolen from the AdPlug player, stripped down, |
| 6 | * translated into C, and adapted for the Audio Engine |
| 7 | * by David Olofson, 2002. |
| 8 | * |
| 9 | * 20020219: Separated data from player. |
| 10 | * |
| 11 | * 20020613: Removed code for all special formats |
| 12 | * and AdLib hardware specific stuff. (Can't |
| 13 | * use the data. Can't maintain the code.) |
| 14 | * |
| 15 | * 20020615: * Removed all 'long' types. If this engine |
| 16 | * is supposed to work in 16 bit environments, |
| 17 | * there's a *lot* more than a few longs to it. |
| 18 | * * Cleaned up type namespace. |
| 19 | * * Fixed various stuff that Splint whines about. |
| 20 | * * Added musical time printout function. |
| 21 | * |
| 22 | * Below is the original copyright. Of course, the LGPL |
| 23 | * license still applies. |
| 24 | ------------------------------------------------------------ |
| 25 | * Adplug - Replayer for many OPL2/OPL3 audio file formats. |
| 26 | * Copyright (C) 1999, 2000, 2001 Simon Peter, <[email protected]>, et al. |
| 27 | * |
| 28 | * This library is free software; you can redistribute it and/or |
| 29 | * modify it under the terms of the GNU Lesser General Public |
| 30 | * License as published by the Free Software Foundation; either |
| 31 | * version 2.1 of the License, or (at your option) any later version. |
| 32 | * |
| 33 | * This library is distributed in the hope that it will be useful, |
| 34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 36 | * Lesser General Public License for more details. |
| 37 | * |
| 38 | * You should have received a copy of the GNU Lesser General Public |
| 39 | * License along with this library; if not, write to the Free Software |
| 40 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 41 | * |
| 42 | * |
| 43 | * mid.h - LAA & MID & CMF Player by Philip Hassey ([email protected]) |
| 44 | */ |
| 45 | |
| 46 | #ifndef _A_MIDIFILE_H_ |
| 47 | #define _A_MIDIFILE_H_cxx . . $ `sound/a_midifile.h:47:9`! |
| 48 | |
| 49 | #include "a_midisock.h"cxx . . $ `<file>/sound/a_midisock.h`/ |
| 50 | |
| 51 | /*---------------------------------------------------------- |
| 52 | midi_file_t |
| 53 | ----------------------------------------------------------*/ |
| 54 | |
| 55 | typedef struct midi_file_tcxx . . $ midi_file_t# |
| 56 | { |
| 57 | const char *authorcxx . . $ midi_file_t#author.; |
| 58 | const char *titlecxx . . $ midi_file_t#title.; |
| 59 | const char *remarkscxx . . $ midi_file_t#remarks.; |
| 60 | unsigned flencxx . . $ midi_file_t#flen.; |
| 61 | unsigned subsongscxx . . $ midi_file_t#subsongs.; |
| 62 | unsigned formatcxx . . $ midi_file_t#format.; |
| 63 | unsigned trackscxx . . $ midi_file_t#tracks.; |
| 64 | unsigned char *datacxx . . $ midi_file_t#data.; |
| 65 | } midi_file_tcxx . . $ midi_file_t#; |
| 66 | |
| 67 | midi_file_tcxx . . $ midi_file_t# *mf_opencxx . . $ mf_open(92b12b800ef24b7e).(const char *name); |
| 68 | void mf_closecxx . . $ mf_close(61acc4015506cb3e).(midi_file_tcxx . . $ midi_file_t# *mf); |
| 69 | |
| 70 | |
| 71 | /*---------------------------------------------------------- |
| 72 | midi_player_t |
| 73 | ----------------------------------------------------------*/ |
| 74 | |
| 75 | typedef struct mp_track_context_tcxx . . $ mp_track_context_t# |
| 76 | { |
| 77 | int oncxx . . $ mp_track_context_t#on.; |
| 78 | unsigned poscxx . . $ mp_track_context_t#pos.; |
| 79 | unsigned iwaitcxx . . $ mp_track_context_t#iwait.; |
| 80 | unsigned char pvcxx . . $ mp_track_context_t#pv.; |
| 81 | } mp_track_context_tcxx . . $ mp_track_context_t#; |
| 82 | |
| 83 | |
| 84 | typedef struct mp_track_tcxx . . $ mp_track_t# |
| 85 | { |
| 86 | int enabledcxx . . $ mp_track_t#enabled.; |
| 87 | unsigned tendcxx . . $ mp_track_t#tend.; |
| 88 | unsigned sposcxx . . $ mp_track_t#spos.; |
| 89 | mp_track_context_tcxx . . $ mp_track_context_t# ccxx . . $ mp_track_t#c.; |
| 90 | mp_track_context_tcxx . . $ mp_track_context_t# loop_startcxx . . $ mp_track_t#loop_start.; |
| 91 | } mp_track_tcxx . . $ mp_track_t#; |
| 92 | |
| 93 | |
| 94 | typedef struct mp_timesig_tcxx . . $ mp_timesig_t# |
| 95 | { |
| 96 | unsigned char beatscxx . . $ mp_timesig_t#beats.; |
| 97 | unsigned char valuecxx . . $ mp_timesig_t#value.; |
| 98 | unsigned char clockcxx . . $ mp_timesig_t#clock.; |
| 99 | unsigned char qncxx . . $ mp_timesig_t#qn.; |
| 100 | } mp_timesig_tcxx . . $ mp_timesig_t#; |
| 101 | |
| 102 | typedef struct mp_context_tcxx . . $ mp_context_t# |
| 103 | { |
| 104 | unsigned ppqncxx . . $ mp_context_t#ppqn.; /* Pulses Per Quarter Note */ |
| 105 | unsigned usqtrcxx . . $ mp_context_t#usqtr.; /* microseconds per quarter note */ |
| 106 | float spulsecxx . . $ mp_context_t#spulse.; /* seconds per pulse */ |
| 107 | mp_timesig_tcxx . . $ mp_timesig_t# timesigcxx . . $ mp_context_t#timesig.; |
| 108 | unsigned timecxx . . $ mp_context_t#time.; /* Current position in pulses */ |
| 109 | unsigned iwaitcxx . . $ mp_context_t#iwait.; /* Pulses to next event */ |
| 110 | float fwaitcxx . . $ mp_context_t#fwait.; /* Seconds to next event */ |
| 111 | } mp_context_tcxx . . $ mp_context_t#; |
| 112 | |
| 113 | |
| 114 | typedef struct midi_player_tcxx . . $ midi_player_t# |
| 115 | { |
| 116 | midisock_tcxx . . $ midisock_t# *sockcxx . . $ midi_player_t#sock.; |
| 117 | midi_file_tcxx . . $ midi_file_t# *mfcxx . . $ midi_player_t#mf.; |
| 118 | unsigned poscxx . . $ midi_player_t#pos.; |
| 119 | mp_context_tcxx . . $ mp_context_t# ccxx . . $ midi_player_t#c.; |
| 120 | mp_context_tcxx . . $ mp_context_t# loop_startcxx . . $ midi_player_t#loop_start.; |
| 121 | mp_track_tcxx . . $ mp_track_t# trackcxx . . $ midi_player_t#track.[16]; |
| 122 | int doingcxx . . $ midi_player_t#doing.; |
| 123 | int pitchcxx . . $ midi_player_t#pitch.; |
| 124 | } midi_player_tcxx . . $ midi_player_t#; |
| 125 | |
| 126 | |
| 127 | midi_player_tcxx . . $ midi_player_t# *mp_opencxx . . $ mp_open(f32b482edfcfd65f).(midisock_tcxx . . $ midisock_t# *ms); |
| 128 | void mp_closecxx . . $ mp_close(c9296cb28ec3fd8b).(midi_player_tcxx . . $ midi_player_t# *mp); |
| 129 | |
| 130 | /* Select a previously loaded MIDI file for playback */ |
| 131 | int mp_selectcxx . . $ mp_select(2f4a78443eeeabc2).(midi_player_tcxx . . $ midi_player_t# *mp, midi_file_tcxx . . $ midi_file_t# *midifile); |
| 132 | |
| 133 | /* Play all events until the next delay */ |
| 134 | int mp_updatecxx . . $ mp_update(3ab63d27fcc3e5de).(midi_player_tcxx . . $ midi_player_t# *mp); |
| 135 | |
| 136 | /* Play all events until current_position + dt seconds */ |
| 137 | int mp_playcxx . . $ mp_play(69b5ef4a72b67e25).(midi_player_tcxx . . $ midi_player_t# *mp, float dt); |
| 138 | |
| 139 | /* Rewind to start of sub song 'subsong' */ |
| 140 | void mp_rewindcxx . . $ mp_rewind(6cb2fa98a3fc6105).(midi_player_tcxx . . $ midi_player_t# *mp, unsigned subsong); |
| 141 | |
| 142 | void mp_stopcxx . . $ mp_stop(c9296cb28ec3fd8b).(midi_player_tcxx . . $ midi_player_t# *mp); |
| 143 | |
| 144 | #endif /*_A_MIDIFILE_H_*/ |