1 /* $NetBSD: midiio.h,v 1.8 2001/10/23 13:07:09 itohy Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Lennart Augustsson (augustss@netbsd.org). 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #ifndef _SYS_MIDIIO_H_ 40 #define _SYS_MIDIIO_H_ 41 42 /* 43 * The API defined here is compatible with the OSS MIDI API except 44 * for naming. 45 */ 46 47 #ifndef _POSIX_SOURCE 48 #define __MIDIIO_UNSET_POSIX_SOURCE 49 #define _POSIX_SOURCE /* make sure we don't get all the gunk */ 50 #endif 51 #include <machine/endian.h> 52 #ifdef __MIDIIO_UNSET_POSIX_SOURCE 53 #undef _POSIX_SOURCE 54 #undef __MIDIIO_UNSET_POSIX_SOURCE 55 #endif 56 57 /* 58 * ioctl() commands for /dev/midi## 59 */ 60 typedef struct { 61 unsigned char cmd; 62 char nr_args, nr_returns; 63 unsigned char data[30]; 64 } mpu_command_rec; 65 66 #define MIDI_PRETIME _IOWR('m', 0, int) 67 #define MIDI_MPUMODE _IOWR('m', 1, int) 68 #define MIDI_MPUCMD _IOWR('m', 2, mpu_command_rec) 69 70 71 /* The MPU401 command acknowledge and active sense command */ 72 #define MIDI_ACK 0xfe 73 74 75 /* Sequencer */ 76 #define SEQUENCER_RESET _IO ('Q', 0) 77 #define SEQUENCER_SYNC _IO ('Q', 1) 78 #define SEQUENCER_INFO _IOWR('Q', 2, struct synth_info) 79 #define SEQUENCER_CTRLRATE _IOWR('Q', 3, int) 80 #define SEQUENCER_GETOUTCOUNT _IOR ('Q', 4, int) 81 #define SEQUENCER_GETINCOUNT _IOR ('Q', 5, int) 82 /*#define SEQUENCER_PERCMODE _IOW ('Q', 6, int)*/ 83 /*#define SEQUENCER_TESTMIDI _IOW ('Q', 8, int)*/ 84 #define SEQUENCER_RESETSAMPLES _IOW ('Q', 9, int) 85 #define SEQUENCER_NRSYNTHS _IOR ('Q',10, int) 86 #define SEQUENCER_NRMIDIS _IOR ('Q',11, int) 87 /*#define SEQUENCER_MIDI_INFO _IOWR('Q',12, struct midi_info)*/ 88 #define SEQUENCER_THRESHOLD _IOW ('Q',13, int) 89 #define SEQUENCER_MEMAVL _IOWR('Q',14, int) 90 /*#define SEQUENCER_FM_4OP_ENABLE _IOW ('Q',15, int)*/ 91 #define SEQUENCER_PANIC _IO ('Q',17) 92 #define SEQUENCER_OUTOFBAND _IOW ('Q',18, struct seq_event_rec) 93 #define SEQUENCER_GETTIME _IOR ('Q',19, int) 94 /*#define SEQUENCER_ID _IOWR('Q',20, struct synth_info)*/ 95 /*#define SEQUENCER_CONTROL _IOWR('Q',21, struct synth_control)*/ 96 /*#define SEQUENCER_REMOVESAMPLE _IOWR('Q',22, struct remove_sample)*/ 97 98 #if 0 99 typedef struct synth_control { 100 int devno; /* Synthesizer # */ 101 char data[4000]; /* Device specific command/data record */ 102 } synth_control; 103 104 typedef struct remove_sample { 105 int devno; /* Synthesizer # */ 106 int bankno; /* MIDI bank # (0=General MIDI) */ 107 int instrno; /* MIDI instrument number */ 108 } remove_sample; 109 #endif 110 111 #define CMDSIZE 8 112 typedef struct seq_event_rec { 113 u_char arr[CMDSIZE]; 114 } seq_event_rec; 115 116 struct synth_info { 117 char name[30]; 118 int device; 119 int synth_type; 120 #define SYNTH_TYPE_FM 0 121 #define SYNTH_TYPE_SAMPLE 1 122 #define SYNTH_TYPE_MIDI 2 123 124 int synth_subtype; 125 #define SYNTH_SUB_FM_TYPE_ADLIB 0x00 126 #define SYNTH_SUB_FM_TYPE_OPL3 0x01 127 #define SYNTH_SUB_MIDI_TYPE_MPU401 0x401 128 129 #define SYNTH_SUB_SAMPLE_TYPE_BASIC 0x10 130 #define SYNTH_SUB_SAMPLE_TYPE_GUS SAMPLE_TYPE_BASIC 131 132 int nr_voices; 133 int instr_bank_size; 134 u_int capabilities; 135 #define SYNTH_CAP_OPL3 0x00000002 136 #define SYNTH_CAP_INPUT 0x00000004 137 }; 138 139 /* Sequencer timer */ 140 #define SEQUENCER_TMR_TIMEBASE _IOWR('T', 1, int) 141 #define SEQUENCER_TMR_START _IO ('T', 2) 142 #define SEQUENCER_TMR_STOP _IO ('T', 3) 143 #define SEQUENCER_TMR_CONTINUE _IO ('T', 4) 144 #define SEQUENCER_TMR_TEMPO _IOWR('T', 5, int) 145 #define SEQUENCER_TMR_SOURCE _IOWR('T', 6, int) 146 # define SEQUENCER_TMR_INTERNAL 0x00000001 147 #if 0 148 # define SEQUENCER_TMR_EXTERNAL 0x00000002 149 # define SEQUENCER_TMR_MODE_MIDI 0x00000010 150 # define SEQUENCER_TMR_MODE_FSK 0x00000020 151 # define SEQUENCER_TMR_MODE_CLS 0x00000040 152 # define SEQUENCER_TMR_MODE_SMPTE 0x00000080 153 #endif 154 #define SEQUENCER_TMR_METRONOME _IOW ('T', 7, int) 155 #define SEQUENCER_TMR_SELECT _IOW ('T', 8, int) 156 157 158 #define MIDI_CTRL_BANK_SELECT_MSB 0 159 #define MIDI_CTRL_MODULATION_MSB 1 160 #define MIDI_CTRL_BREATH_MSB 2 161 #define MIDI_CTRL_FOOT_MSB 4 162 #define MIDI_CTRL_PORTAMENTO_TIME_MSB 5 163 #define MIDI_CTRL_DATA_ENTRY_MSB 6 164 #define MIDI_CTRL_CHANNEL_VOLUME_MSB 7 165 #define MIDI_CTRL_BALANCE_MSB 8 166 #define MIDI_CTRL_PAN_MSB 10 167 #define MIDI_CTRL_EXPRESSION_MSB 11 168 #define MIDI_CTRL_GENERAL_PURPOSE_1_MSB 16 169 #define MIDI_CTRL_GENERAL_PURPOSE_2_MSB 17 170 #define MIDI_CTRL_GENERAL_PURPOSE_3_MSB 18 171 #define MIDI_CTRL_GENERAL_PURPOSE_4_MSB 19 172 #define MIDI_CTRL_BANK_SELECT_LSB 32 173 #define MIDI_CTRL_MODULATION_LSB 33 174 #define MIDI_CTRL_BREATH_LSB 34 175 #define MIDI_CTRL_FOOT_LSB 36 176 #define MIDI_CTRL_PORTAMENTO_TIME_LSB 37 177 #define MIDI_CTRL_DATA_ENTRY_LSB 38 178 #define MIDI_CTRL_CHANNEL_VOLUME_LSB 39 179 #define MIDI_CTRL_BALANCE_LSB 40 180 #define MIDI_CTRL_PAN_LSB 42 181 #define MIDI_CTRL_EXPRESSION_LSB 43 182 #define MIDI_CTRL_GENERAL_PURPOSE_1_LSB 48 183 #define MIDI_CTRL_GENERAL_PURPOSE_2_LSB 49 184 #define MIDI_CTRL_GENERAL_PURPOSE_3_LSB 50 185 #define MIDI_CTRL_GENERAL_PURPOSE_4_LSB 51 186 #define MIDI_CTRL_HOLD_1 64 187 #define MIDI_CTRL_PORTAMENTO 65 188 #define MIDI_CTRL_SOSTENUTO 66 189 #define MIDI_CTRL_SOFT_PEDAL 67 190 #define MIDI_CTRL_HOLD_2 69 191 #define MIDI_CTRL_SOUND_VARIATION 70 192 #define MIDI_CTRL_HARMONIC_INTENSITY 71 193 #define MIDI_CTRL_RELEASE_TIME 72 194 #define MIDI_CTRL_ATTACK_TIME 73 195 #define MIDI_CTRL_BRIGHTNESS 74 196 #define MIDI_CTRL_DECAY_TIME 75 197 #define MIDI_CTRL_VIBRATO_RATE 76 198 #define MIDI_CTRL_VIBRATO_DEPTH 77 199 #define MIDI_CTRL_VIBRATO_DECAY 78 200 #define MIDI_CTRL_GENERAL_PURPOSE_5 80 201 #define MIDI_CTRL_GENERAL_PURPOSE_6 81 202 #define MIDI_CTRL_GENERAL_PURPOSE_7 82 203 #define MIDI_CTRL_GENERAL_PURPOSE_8 83 204 #define MIDI_CTRL_PORTAMENTO_CONTROL 84 205 #define MIDI_CTRL_EFFECT_DEPTH_1 91 206 #define MIDI_CTRL_EFFECT_DEPTH_2 92 207 #define MIDI_CTRL_EFFECT_DEPTH_3 93 208 #define MIDI_CTRL_EFFECT_DEPTH_4 94 209 #define MIDI_CTRL_EFFECT_DEPTH_5 95 210 #define MIDI_CTRL_RPN_INCREMENT 96 211 #define MIDI_CTRL_RPN_DECREMENT 97 212 #define MIDI_CTRL_NRPN_LSB 98 213 #define MIDI_CTRL_NRPN_MSB 99 214 #define MIDI_CTRL_RPN_LSB 100 215 #define MIDI_CTRL_RPN_MSB 101 216 #define MIDI_CTRL_SOUND_OFF 120 217 #define MIDI_CTRL_RESET 121 218 #define MIDI_CTRL_ALLOFF 123 219 220 #define MIDI_BEND_NEUTRAL (1<<13) 221 222 #define MIDI_NOTEOFF 0x80 223 #define MIDI_NOTEON 0x90 224 #define MIDI_KEY_PRESSURE 0xA0 225 #define MIDI_CTL_CHANGE 0xB0 226 #define MIDI_PGM_CHANGE 0xC0 227 #define MIDI_CHN_PRESSURE 0xD0 228 #define MIDI_PITCH_BEND 0xE0 229 #define MIDI_SYSTEM_PREFIX 0xF0 230 231 #define MIDI_IS_STATUS(d) ((d) >= 0x80) 232 #define MIDI_IS_COMMON(d) ((d) >= 0xf0) 233 234 #define MIDI_SYSEX_START 0xF0 235 #define MIDI_SYSEX_END 0xF7 236 237 #define MIDI_GET_STATUS(d) ((d) & 0xf0) 238 #define MIDI_GET_CHAN(d) ((d) & 0x0f) 239 240 #define MIDI_HALF_VEL 64 241 242 #define SEQ_LOCAL 0x80 243 #define SEQ_TIMING 0x81 244 #define SEQ_CHN_COMMON 0x92 245 #define SEQ_CHN_VOICE 0x93 246 #define SEQ_SYSEX 0x94 247 #define SEQ_FULLSIZE 0xfd 248 249 #define SEQ_MK_CHN_VOICE(e, unit, cmd, chan, key, vel) (\ 250 (e)->arr[0] = SEQ_CHN_VOICE, (e)->arr[1] = (unit), (e)->arr[2] = (cmd),\ 251 (e)->arr[3] = (chan), (e)->arr[4] = (key), (e)->arr[5] = (vel),\ 252 (e)->arr[6] = 0, (e)->arr[7] = 0) 253 #define SEQ_MK_CHN_COMMON(e, unit, cmd, chan, p1, p2, w14) (\ 254 (e)->arr[0] = SEQ_CHN_COMMON, (e)->arr[1] = (unit), (e)->arr[2] = (cmd),\ 255 (e)->arr[3] = (chan), (e)->arr[4] = (p1), (e)->arr[5] = (p2),\ 256 *(short*)&(e)->arr[6] = (w14)) 257 258 #if _QUAD_LOWWORD == 1 259 /* big endian */ 260 #define SEQ_PATCHKEY(id) (0xfd00|id) 261 #else 262 /* little endian */ 263 #define SEQ_PATCHKEY(id) ((id<<8)|0xfd) 264 #endif 265 struct sysex_info { 266 u_int16_t key; /* Use SYSEX_PATCH or MAUI_PATCH here */ 267 #define SEQ_SYSEX_PATCH SEQ_PATCHKEY(0x05) 268 #define SEQ_MAUI_PATCH SEQ_PATCHKEY(0x06) 269 int16_t device_no; /* Synthesizer number */ 270 int32_t len; /* Size of the sysex data in bytes */ 271 u_char data[1]; /* Sysex data starts here */ 272 }; 273 #define SEQ_SYSEX_HDRSIZE ((u_long)((struct sysex_info *)0)->data) 274 275 typedef unsigned char sbi_instr_data[32]; 276 struct sbi_instrument { 277 u_int16_t key; /* FM_PATCH or OPL3_PATCH */ 278 #define SBI_FM_PATCH SEQ_PATCHKEY(0x01) 279 #define SBI_OPL3_PATCH SEQ_PATCHKEY(0x03) 280 int16_t device; 281 int32_t channel; 282 sbi_instr_data operators; 283 }; 284 285 #define TMR_RESET 0 286 #define TMR_WAIT_REL 1 /* Time relative to the prev time */ 287 #define TMR_WAIT_ABS 2 /* Absolute time since TMR_START */ 288 #define TMR_STOP 3 289 #define TMR_START 4 290 #define TMR_CONTINUE 5 291 #define TMR_TEMPO 6 292 #define TMR_ECHO 8 293 #define TMR_CLOCK 9 /* MIDI clock */ 294 #define TMR_SPP 10 /* Song position pointer */ 295 #define TMR_TIMESIG 11 /* Time signature */ 296 297 /* Old sequencer definitions */ 298 #define SEQOLD_CMDSIZE 4 299 300 #define SEQOLD_NOTEOFF 0 301 #define SEQOLD_NOTEON 1 302 #define SEQOLD_WAIT TMR_WAIT_ABS 303 #define SEQOLD_PGMCHANGE 3 304 #define SEQOLD_SYNCTIMER TMR_START 305 #define SEQOLD_MIDIPUTC 5 306 #define SEQOLD_ECHO TMR_ECHO 307 #define SEQOLD_AFTERTOUCH 9 308 #define SEQOLD_CONTROLLER 10 309 #define SEQOLD_PRIVATE 0xfe 310 #define SEQOLD_EXTENDED 0xff 311 312 #endif /* !_SYS_MIDIIO_H_ */ 313