1 /*         ______   ___    ___
2  *        /\  _  \ /\_ \  /\_ \
3  *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___
4  *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
5  *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
6  *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7  *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8  *                                           /\____/
9  *                                           \_/__/
10  *
11  *      MIDI music routines.
12  *
13  *      By Shawn Hargreaves.
14  *
15  *      See readme.txt for copyright information.
16  */
17 
18 
19 #ifndef ALLEGRO_MIDI_H
20 #define ALLEGRO_MIDI_H
21 
22 #include "base.h"
23 
24 #ifdef __cplusplus
25    extern "C" {
26 #endif
27 
28 struct PACKFILE;
29 
30 
31                                        /* Theoretical maximums: */
32 #define MIDI_VOICES           64       /* actual drivers may not be */
33 #define MIDI_TRACKS           32       /* able to handle this many */
34 
35 
36 
37 typedef struct MIDI                    /* a midi file */
38 {
39    int divisions;                      /* number of ticks per quarter note */
40    struct {
41       unsigned char *data;             /* MIDI message stream */
42       int len;                         /* length of the track data */
43    } track[MIDI_TRACKS];
44 } MIDI;
45 
46 
47 
48 #define MIDI_AUTODETECT       -1
49 #define MIDI_NONE             0
50 #define MIDI_DIGMID           AL_ID('D','I','G','I')
51 
52 typedef struct MIDI_DRIVER             /* driver for playing midi music */
53 {
54    int  id;                            /* driver ID code */
55    AL_CONST char *name;                /* driver name */
56    AL_CONST char *desc;                /* description string */
57    AL_CONST char *ascii_name;          /* ASCII format name string */
58    int  voices;                        /* available voices */
59    int  basevoice;                     /* voice number offset */
60    int  max_voices;                    /* maximum voices we can support */
61    int  def_voices;                    /* default number of voices to use */
62    int  xmin, xmax;                    /* reserved voice range */
63 
64    /* setup routines */
65    AL_METHOD(int,  detect, (int input));
66    AL_METHOD(int,  init, (int input, int voices));
67    AL_METHOD(void, exit, (int input));
68    AL_METHOD(int,  set_mixer_volume, (int volume));
69    AL_METHOD(int,  get_mixer_volume, (void));
70 
71    /* raw MIDI output to MPU-401, etc. */
72    AL_METHOD(void, raw_midi, (int data));
73 
74    /* dynamic patch loading routines */
75    AL_METHOD(int,  load_patches, (AL_CONST char *patches, AL_CONST char *drums));
76    AL_METHOD(void, adjust_patches, (AL_CONST char *patches, AL_CONST char *drums));
77 
78    /* note control functions */
79    AL_METHOD(void, key_on, (int inst, int note, int bend, int vol, int pan));
80    AL_METHOD(void, key_off, (int voice));
81    AL_METHOD(void, set_volume, (int voice, int vol));
82    AL_METHOD(void, set_pitch, (int voice, int note, int bend));
83    AL_METHOD(void, set_pan, (int voice, int pan));
84    AL_METHOD(void, set_vibrato, (int voice, int amount));
85 } MIDI_DRIVER;
86 
87 
88 AL_VAR(MIDI_DRIVER, midi_digmid);
89 
90 AL_ARRAY(_DRIVER_INFO, _midi_driver_list);
91 
92 
93 /* macros for constructing the driver lists */
94 #define BEGIN_MIDI_DRIVER_LIST                                 \
95    _DRIVER_INFO _midi_driver_list[] =                          \
96    {
97 
98 #define END_MIDI_DRIVER_LIST                                   \
99       {  0,                NULL,                0     }        \
100    };
101 
102 #define MIDI_DRIVER_DIGMID                                     \
103       {  MIDI_DIGMID,      &midi_digmid,        TRUE  },
104 
105 
106 AL_VAR(MIDI_DRIVER *, midi_driver);
107 
108 AL_VAR(MIDI_DRIVER *, midi_input_driver);
109 
110 AL_VAR(int, midi_card);
111 
112 AL_VAR(int, midi_input_card);
113 
114 AL_VAR(volatile long, midi_pos);       /* current position in the midi file, in beats */
115 AL_VAR(volatile long, midi_time);      /* current position in the midi file, in seconds */
116 
117 AL_VAR(long, midi_loop_start);         /* where to loop back to at EOF */
118 AL_VAR(long, midi_loop_end);           /* loop when we hit this position */
119 
120 AL_FUNC(int, detect_midi_driver, (int driver_id));
121 
122 AL_FUNC(MIDI *, load_midi, (AL_CONST char *filename));
123 AL_FUNC(MIDI *, load_midi_pf, (struct PACKFILE *f));
124 AL_FUNC(void, destroy_midi, (MIDI *midi));
125 AL_FUNC(int, play_midi, (MIDI *midi, int loop));
126 AL_FUNC(int, play_looped_midi, (MIDI *midi, int loop_start, int loop_end));
127 AL_FUNC(void, stop_midi, (void));
128 AL_FUNC(void, midi_pause, (void));
129 AL_FUNC(void, midi_resume, (void));
130 AL_FUNC(int, midi_seek, (int target));
131 AL_FUNC(int, get_midi_length, (MIDI *midi));
132 AL_FUNC(void, midi_out, (unsigned char *data, int length));
133 AL_FUNC(int, load_midi_patches, (void));
134 
135 AL_FUNCPTR(void, midi_msg_callback, (int msg, int byte1, int byte2));
136 AL_FUNCPTR(void, midi_meta_callback, (int type, AL_CONST unsigned char *data, int length));
137 AL_FUNCPTR(void, midi_sysex_callback, (AL_CONST unsigned char *data, int length));
138 
139 AL_FUNCPTR(void, midi_recorder, (unsigned char data));
140 
141 AL_FUNC(void, lock_midi, (struct MIDI *midi));
142 
143 #ifdef __cplusplus
144    }
145 #endif
146 
147 #endif          /* ifndef ALLEGRO_MIDI_H */
148 
149 
150