1 //------------------------------------------------------------------------- 2 /* 3 Copyright (C) 2010-2019 EDuke32 developers and contributors 4 Copyright (C) 2019 Nuke.YKT 5 6 This file is part of NBlood. 7 8 NBlood is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License version 2 10 as published by the Free Software Foundation. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 16 See the GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 */ 22 //------------------------------------------------------------------------- 23 24 #ifndef ___MIDI_H 25 #define ___MIDI_H 26 #include "compat.h" 27 28 #define RELATIVE_BEAT(measure, beat, tick) ((tick) + ((beat) << 9) + ((measure) << 16)) 29 30 //Bobby Prince thinks this may be 100 31 //#define GENMIDI_DefaultVolume 100 32 #define GENMIDI_DefaultVolume 90 33 34 #define MAX_FORMAT 1 35 36 #define NUM_MIDI_CHANNELS 16 37 38 #define TIME_PRECISION 16 39 40 #define MIDI_HEADER_SIGNATURE 0x6468544d // "MThd" 41 #define MIDI_TRACK_SIGNATURE 0x6b72544d // "MTrk" 42 43 #define MIDI_VOLUME 7 44 #define MIDI_PAN 10 45 #define MIDI_DETUNE 94 46 #define MIDI_RHYTHM_CHANNEL 9 47 #define MIDI_BANK_SELECT_MSB 0 48 #define MIDI_BANK_SELECT_LSB 32 49 #define MIDI_RPN_MSB 100 50 #define MIDI_RPN_LSB 101 51 #define MIDI_DATAENTRY_MSB 6 52 #define MIDI_DATAENTRY_LSB 38 53 #define MIDI_PITCHBEND_MSB 0 54 #define MIDI_PITCHBEND_LSB 0 55 #define MIDI_RUNNING_STATUS 0x80 56 #define MIDI_NOTE_OFF 0x8 57 #define MIDI_NOTE_ON 0x9 58 #define MIDI_POLY_AFTER_TCH 0xA 59 #define MIDI_CONTROL_CHANGE 0xB 60 #define MIDI_PROGRAM_CHANGE 0xC 61 #define MIDI_AFTER_TOUCH 0xD 62 #define MIDI_PITCH_BEND 0xE 63 #define MIDI_SPECIAL 0xF 64 #define MIDI_SYSEX 0xF0 65 #define MIDI_SYSEX_CONTINUE 0xF7 66 #define MIDI_META_EVENT 0xFF 67 #define MIDI_END_OF_TRACK 0x2F 68 #define MIDI_HOLD1 0x40 69 #define MIDI_SOSTENUTO 0x42 70 #define MIDI_TEMPO_CHANGE 0x51 71 #define MIDI_TIME_SIGNATURE 0x58 72 #define MIDI_REVERB 0x5b 73 #define MIDI_CHORUS 0x5d 74 #define MIDI_ALL_SOUNDS_OFF 0x78 75 #define MIDI_RESET_ALL_CONTROLLERS 0x79 76 #define MIDI_ALL_NOTES_OFF 0x7b 77 #define MIDI_MONO_MODE_ON 0x7E 78 #define MIDI_SYSTEM_RESET 0xFF 79 80 #define GET_NEXT_EVENT( track, data ) do { \ 81 ( data ) = *( track )->pos; \ 82 ( track )->pos += 1; \ 83 } while (0) 84 85 #define GET_MIDI_CHANNEL( event ) ( ( event ) & 0xf ) 86 #define GET_MIDI_COMMAND( event ) ( ( event ) >> 4 ) 87 88 #define EMIDI_INFINITE -1 89 #define EMIDI_END_LOOP_VALUE 127 90 #define EMIDI_ALL_CARDS 127 91 #define EMIDI_INCLUDE_TRACK 110 92 #define EMIDI_EXCLUDE_TRACK 111 93 #define EMIDI_PROGRAM_CHANGE 112 94 #define EMIDI_VOLUME_CHANGE 113 95 #define EMIDI_CONTEXT_START 114 96 #define EMIDI_CONTEXT_END 115 97 #define EMIDI_LOOP_START 116 98 #define EMIDI_LOOP_END 117 99 #define EMIDI_SONG_LOOP_START 118 100 #define EMIDI_SONG_LOOP_END 119 101 102 #define EMIDI_GeneralMIDI 0 103 #define EMIDI_SoundBlaster 4 104 #define EMIDI_AdLib 7 105 106 #define EMIDI_AffectsCurrentCard(c, type) (((c) == EMIDI_ALL_CARDS) || ((c) == (type))) 107 #define EMIDI_NUM_CONTEXTS 7 108 109 typedef struct 110 { 111 char *pos; 112 char *loopstart; 113 int16_t loopcount; 114 int16_t RunningStatus; 115 unsigned time; 116 int FPSecondsPerTick; 117 int16_t tick; 118 int16_t beat; 119 int16_t measure; 120 int16_t BeatsPerMeasure; 121 int16_t TicksPerBeat; 122 int16_t TimeBase; 123 int delay; 124 int16_t active; 125 } songcontext; 126 127 typedef struct 128 { 129 char *start; 130 char *pos; 131 132 int delay; 133 int16_t active; 134 int16_t RunningStatus; 135 136 int16_t currentcontext; 137 songcontext context[EMIDI_NUM_CONTEXTS]; 138 139 char EMIDI_IncludeTrack; 140 char EMIDI_ProgramChange; 141 char EMIDI_VolumeChange; 142 } track; 143 144 #endif 145