_AL_MIDI.H 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. Copyright (C) 1994-1995 Apogee Software, Ltd.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef ___AL_MIDI_H
  16. #define ___AL_MIDI_H
  17. #define NO_ADLIB_DETECTION "NOAL"
  18. #define STEREO_DETUNE 5
  19. #define lobyte( num ) ( ( unsigned )*( ( char * )&( num ) ) )
  20. #define hibyte( num ) ( ( unsigned )*( ( ( char * )&( num ) ) + 1 ) )
  21. #define AL_VoiceNotFound -1
  22. #define alFreqH 0xb0
  23. #define alEffects 0xbd
  24. /* Number of slots for the voices on the chip */
  25. #define NumChipSlots 18
  26. #define NUM_VOICES 9
  27. #define NUM_CHANNELS 16
  28. #define NOTE_ON 0x2000 /* Used to turn note on or toggle note */
  29. #define NOTE_OFF 0x0000
  30. #define MAX_VELOCITY 0x7f
  31. #define MAX_OCTAVE 7
  32. #define MAX_NOTE ( MAX_OCTAVE * 12 + 11 )
  33. #define FINETUNE_MAX 31
  34. #define FINETUNE_RANGE ( FINETUNE_MAX + 1 )
  35. #define PITCHBEND_CENTER 1638400
  36. #define note_off 0x80
  37. #define note_on 0x90
  38. #define poly_aftertouch 0xa0
  39. #define control_change 0xb0
  40. #define program_chng 0xc0
  41. #define channel_aftertouch 0xd0
  42. #define pitch_wheel 0xe0
  43. #define MIDI_VOLUME 7
  44. #define MIDI_PAN 10
  45. #define MIDI_DETUNE 94
  46. #define MIDI_ALL_NOTES_OFF 0x7B
  47. #define MIDI_RESET_ALL_CONTROLLERS 0x79
  48. #define MIDI_RPN_MSB 100
  49. #define MIDI_RPN_LSB 101
  50. #define MIDI_DATAENTRY_MSB 6
  51. #define MIDI_DATAENTRY_LSB 38
  52. #define MIDI_PITCHBEND_RPN 0
  53. enum cromatic_scale
  54. {
  55. C = 0x157,
  56. C_SHARP = 0x16B,
  57. D_FLAT = 0x16B,
  58. D = 0x181,
  59. D_SHARP = 0x198,
  60. E_FLAT = 0x198,
  61. E = 0x1B0,
  62. F_FLAT = 0x1B0,
  63. E_SHARP = 0x1CA,
  64. F = 0x1CA,
  65. F_SHARP = 0x1E5,
  66. G_FLAT = 0x1E5,
  67. G = 0x202,
  68. G_SHARP = 0x220,
  69. A_FLAT = 0x220,
  70. A = 0x241,
  71. A_SHARP = 0x263,
  72. B_FLAT = 0x263,
  73. B = 0x287,
  74. C_FLAT = 0x287,
  75. B_SHARP = 0x2AE,
  76. };
  77. /* Definition of octave information to be ORed onto F-Number */
  78. enum octaves
  79. {
  80. OCTAVE_0 = 0x0000,
  81. OCTAVE_1 = 0x0400,
  82. OCTAVE_2 = 0x0800,
  83. OCTAVE_3 = 0x0C00,
  84. OCTAVE_4 = 0x1000,
  85. OCTAVE_5 = 0x1400,
  86. OCTAVE_6 = 0x1800,
  87. OCTAVE_7 = 0x1C00
  88. };
  89. typedef struct VOICE
  90. {
  91. struct VOICE *next;
  92. struct VOICE *prev;
  93. unsigned num;
  94. unsigned key;
  95. unsigned velocity;
  96. unsigned channel;
  97. unsigned pitchleft;
  98. unsigned pitchright;
  99. int timbre;
  100. int port;
  101. unsigned status;
  102. } VOICE;
  103. typedef struct
  104. {
  105. VOICE *start;
  106. VOICE *end;
  107. } VOICELIST;
  108. typedef struct
  109. {
  110. VOICELIST Voices;
  111. int Timbre;
  112. int Pitchbend;
  113. int KeyOffset;
  114. unsigned KeyDetune;
  115. unsigned Volume;
  116. unsigned EffectiveVolume;
  117. int Pan;
  118. int Detune;
  119. unsigned RPN;
  120. short PitchBendRange;
  121. short PitchBendSemiTones;
  122. short PitchBendHundreds;
  123. } CHANNEL;
  124. typedef struct
  125. {
  126. unsigned char SAVEK[ 2 ];
  127. unsigned char Level[ 2 ];
  128. unsigned char Env1[ 2 ];
  129. unsigned char Env2[ 2 ];
  130. unsigned char Wave[ 2 ];
  131. unsigned char Feedback;
  132. signed char Transpose;
  133. signed char Velocity;
  134. } TIMBRE;
  135. extern TIMBRE ADLIB_TimbreBank[ 256 ];
  136. static void AL_ResetVoices( void );
  137. static void AL_CalcPitchInfo( void );
  138. static void AL_SetVoiceTimbre( int voice );
  139. static void AL_SetVoiceVolume( int voice );
  140. static int AL_AllocVoice( void );
  141. static int AL_GetVoice( int channel, int key );
  142. static void AL_SetVoicePitch( int voice );
  143. static void AL_SetChannelVolume( int channel, int volume );
  144. static void AL_SetChannelPan( int channel, int pan );
  145. static void AL_SetChannelDetune( int channel, int detune );
  146. #endif