1 /* FluidSynth - A Software Synthesizer 2 * 3 * Copyright (C) 2003 Peter Hanappe and others. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public License 7 * as published by the Free Software Foundation; either version 2 of 8 * the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, write to the Free 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18 * 02111-1307, USA 19 */ 20 21 #ifndef _FLUID_MIDI_H 22 #define _FLUID_MIDI_H 23 24 #include "fluidsynth_priv.h" 25 #include "fluid_sys.h" 26 #include "fluid_list.h" 27 28 typedef struct _fluid_midi_parser_t fluid_midi_parser_t; 29 30 fluid_midi_parser_t* new_fluid_midi_parser(void); 31 int delete_fluid_midi_parser(fluid_midi_parser_t* parser); 32 fluid_midi_event_t* fluid_midi_parser_parse(fluid_midi_parser_t* parser, unsigned char c); 33 34 int fluid_midi_send_event(fluid_synth_t* synth, fluid_player_t* player, fluid_midi_event_t* evt); 35 36 37 /*************************************************************** 38 * 39 * CONSTANTS & ENUM 40 */ 41 42 43 #define MAX_NUMBER_OF_TRACKS 128 44 45 enum fluid_midi_event_type { 46 /* channel messages */ 47 NOTE_OFF = 0x80, 48 NOTE_ON = 0x90, 49 KEY_PRESSURE = 0xa0, 50 CONTROL_CHANGE = 0xb0, 51 PROGRAM_CHANGE = 0xc0, 52 CHANNEL_PRESSURE = 0xd0, 53 PITCH_BEND = 0xe0, 54 /* system exclusive */ 55 MIDI_SYSEX = 0xf0, 56 /* system common - never in midi files */ 57 MIDI_TIME_CODE = 0xf1, 58 MIDI_SONG_POSITION = 0xf2, 59 MIDI_SONG_SELECT = 0xf3, 60 MIDI_TUNE_REQUEST = 0xf6, 61 MIDI_EOX = 0xf7, 62 /* system real-time - never in midi files */ 63 MIDI_SYNC = 0xf8, 64 MIDI_TICK = 0xf9, 65 MIDI_START = 0xfa, 66 MIDI_CONTINUE = 0xfb, 67 MIDI_STOP = 0xfc, 68 MIDI_ACTIVE_SENSING = 0xfe, 69 MIDI_SYSTEM_RESET = 0xff, 70 /* meta event - for midi files only */ 71 MIDI_META_EVENT = 0xff 72 }; 73 74 enum fluid_midi_control_change { 75 BANK_SELECT_MSB = 0x00, 76 MODULATION_MSB = 0x01, 77 BREATH_MSB = 0x02, 78 FOOT_MSB = 0x04, 79 PORTAMENTO_TIME_MSB = 0x05, 80 DATA_ENTRY_MSB = 0x06, 81 VOLUME_MSB = 0x07, 82 BALANCE_MSB = 0x08, 83 PAN_MSB = 0x0A, 84 EXPRESSION_MSB = 0x0B, 85 EFFECTS1_MSB = 0x0C, 86 EFFECTS2_MSB = 0x0D, 87 GPC1_MSB = 0x10, /* general purpose controller */ 88 GPC2_MSB = 0x11, 89 GPC3_MSB = 0x12, 90 GPC4_MSB = 0x13, 91 BANK_SELECT_LSB = 0x20, 92 MODULATION_WHEEL_LSB = 0x21, 93 BREATH_LSB = 0x22, 94 FOOT_LSB = 0x24, 95 PORTAMENTO_TIME_LSB = 0x25, 96 DATA_ENTRY_LSB = 0x26, 97 VOLUME_LSB = 0x27, 98 BALANCE_LSB = 0x28, 99 PAN_LSB = 0x2A, 100 EXPRESSION_LSB = 0x2B, 101 EFFECTS1_LSB = 0x2C, 102 EFFECTS2_LSB = 0x2D, 103 GPC1_LSB = 0x30, 104 GPC2_LSB = 0x31, 105 GPC3_LSB = 0x32, 106 GPC4_LSB = 0x33, 107 SUSTAIN_SWITCH = 0x40, 108 PORTAMENTO_SWITCH = 0x41, 109 SOSTENUTO_SWITCH = 0x42, 110 SOFT_PEDAL_SWITCH = 0x43, 111 LEGATO_SWITCH = 0x45, 112 HOLD2_SWITCH = 0x45, 113 SOUND_CTRL1 = 0x46, 114 SOUND_CTRL2 = 0x47, 115 SOUND_CTRL3 = 0x48, 116 SOUND_CTRL4 = 0x49, 117 SOUND_CTRL5 = 0x4A, 118 SOUND_CTRL6 = 0x4B, 119 SOUND_CTRL7 = 0x4C, 120 SOUND_CTRL8 = 0x4D, 121 SOUND_CTRL9 = 0x4E, 122 SOUND_CTRL10 = 0x4F, 123 GPC5 = 0x50, 124 GPC6 = 0x51, 125 GPC7 = 0x52, 126 GPC8 = 0x53, 127 PORTAMENTO_CTRL = 0x54, 128 EFFECTS_DEPTH1 = 0x5B, 129 EFFECTS_DEPTH2 = 0x5C, 130 EFFECTS_DEPTH3 = 0x5D, 131 EFFECTS_DEPTH4 = 0x5E, 132 EFFECTS_DEPTH5 = 0x5F, 133 DATA_ENTRY_INCR = 0x60, 134 DATA_ENTRY_DECR = 0x61, 135 NRPN_LSB = 0x62, 136 NRPN_MSB = 0x63, 137 RPN_LSB = 0x64, 138 RPN_MSB = 0x65, 139 ALL_SOUND_OFF = 0x78, 140 ALL_CTRL_OFF = 0x79, 141 LOCAL_CONTROL = 0x7A, 142 ALL_NOTES_OFF = 0x7B, 143 OMNI_OFF = 0x7C, 144 OMNI_ON = 0x7D, 145 POLY_OFF = 0x7E, 146 POLY_ON = 0x7F 147 }; 148 149 /* General MIDI RPN event numbers (LSB, MSB = 0) */ 150 enum midi_rpn_event { 151 RPN_PITCH_BEND_RANGE = 0x00, 152 RPN_CHANNEL_FINE_TUNE = 0x01, 153 RPN_CHANNEL_COARSE_TUNE = 0x02, 154 RPN_TUNING_PROGRAM_CHANGE = 0x03, 155 RPN_TUNING_BANK_SELECT = 0x04, 156 RPN_MODULATION_DEPTH_RANGE = 0x05 157 }; 158 159 enum midi_meta_event { 160 MIDI_COPYRIGHT = 0x02, 161 MIDI_TRACK_NAME = 0x03, 162 MIDI_INST_NAME = 0x04, 163 MIDI_LYRIC = 0x05, 164 MIDI_MARKER = 0x06, 165 MIDI_CUE_POINT = 0x07, 166 MIDI_EOT = 0x2f, 167 MIDI_SET_TEMPO = 0x51, 168 MIDI_SMPTE_OFFSET = 0x54, 169 MIDI_TIME_SIGNATURE = 0x58, 170 MIDI_KEY_SIGNATURE = 0x59, 171 MIDI_SEQUENCER_EVENT = 0x7f 172 }; 173 174 /* MIDI SYSEX useful manufacturer values */ 175 enum midi_sysex_manuf { 176 MIDI_SYSEX_MANUF_ROLAND = 0x41, /**< Roland manufacturer ID */ 177 MIDI_SYSEX_UNIV_NON_REALTIME = 0x7E, /**< Universal non realtime message */ 178 MIDI_SYSEX_UNIV_REALTIME = 0x7F /**< Universal realtime message */ 179 }; 180 181 #define MIDI_SYSEX_DEVICE_ID_ALL 0x7F /**< Device ID used in SYSEX messages to indicate all devices */ 182 183 /* SYSEX sub-ID #1 which follows device ID */ 184 #define MIDI_SYSEX_MIDI_TUNING_ID 0x08 /**< Sysex sub-ID #1 for MIDI tuning messages */ 185 #define MIDI_SYSEX_GM_ID 0x09 /**< Sysex sub-ID #1 for General MIDI messages */ 186 187 /** 188 * SYSEX tuning message IDs. 189 */ 190 enum midi_sysex_tuning_msg_id { 191 MIDI_SYSEX_TUNING_BULK_DUMP_REQ = 0x00, /**< Bulk tuning dump request (non-realtime) */ 192 MIDI_SYSEX_TUNING_BULK_DUMP = 0x01, /**< Bulk tuning dump response (non-realtime) */ 193 MIDI_SYSEX_TUNING_NOTE_TUNE = 0x02, /**< Tuning note change message (realtime) */ 194 MIDI_SYSEX_TUNING_BULK_DUMP_REQ_BANK = 0x03, /**< Bulk tuning dump request (with bank, non-realtime) */ 195 MIDI_SYSEX_TUNING_BULK_DUMP_BANK = 0x04, /**< Bulk tuning dump resonse (with bank, non-realtime) */ 196 MIDI_SYSEX_TUNING_OCTAVE_DUMP_1BYTE = 0x05, /**< Octave tuning dump using 1 byte values (non-realtime) */ 197 MIDI_SYSEX_TUNING_OCTAVE_DUMP_2BYTE = 0x06, /**< Octave tuning dump using 2 byte values (non-realtime) */ 198 MIDI_SYSEX_TUNING_NOTE_TUNE_BANK = 0x07, /**< Tuning note change message (with bank, realtime/non-realtime) */ 199 MIDI_SYSEX_TUNING_OCTAVE_TUNE_1BYTE = 0x08, /**< Octave tuning message using 1 byte values (realtime/non-realtime) */ 200 MIDI_SYSEX_TUNING_OCTAVE_TUNE_2BYTE = 0x09 /**< Octave tuning message using 2 byte values (realtime/non-realtime) */ 201 }; 202 203 /* General MIDI sub-ID #2 */ 204 #define MIDI_SYSEX_GM_ON 0x01 /**< Enable GM mode */ 205 #define MIDI_SYSEX_GM_OFF 0x02 /**< Disable GM mode */ 206 207 208 enum fluid_player_status 209 { 210 FLUID_PLAYER_READY, 211 FLUID_PLAYER_PLAYING, 212 FLUID_PLAYER_DONE 213 }; 214 215 enum fluid_driver_status 216 { 217 FLUID_MIDI_READY, 218 FLUID_MIDI_LISTENING, 219 FLUID_MIDI_DONE 220 }; 221 222 /*************************************************************** 223 * 224 * TYPE DEFINITIONS & FUNCTION DECLARATIONS 225 */ 226 227 /* From ctype.h */ 228 #define fluid_isascii(c) (((c) & ~0x7f) == 0) 229 230 231 232 /* 233 * fluid_midi_event_t 234 */ 235 struct _fluid_midi_event_t { 236 fluid_midi_event_t* next; /* Don't use it, it will dissappear. Used in midi tracks. */ 237 unsigned int dtime; /* Delay (ticks) between this and previous event. midi tracks. */ 238 unsigned char type; /* MIDI event type */ 239 unsigned char channel; /* MIDI channel */ 240 unsigned int param1; /* First parameter */ 241 unsigned int param2; /* Second parameter */ 242 }; 243 244 245 246 247 #endif /* _FLUID_MIDI_H */ 248