seq_midi_emul.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #ifndef __SOUND_SEQ_MIDI_EMUL_H
  2. #define __SOUND_SEQ_MIDI_EMUL_H
  3. /*
  4. * Midi channel definition for optional channel management.
  5. *
  6. * Copyright (C) 1999 Steve Ratcliffe
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/seq_kernel.h>
  24. /*
  25. * This structure is used to keep track of the current state on each
  26. * channel. All drivers for hardware that does not understand midi
  27. * directly will probably need to use this structure.
  28. */
  29. struct snd_midi_channel {
  30. void *private; /* A back pointer to driver data */
  31. int number; /* The channel number */
  32. int client; /* The client associated with this channel */
  33. int port; /* The port associated with this channel */
  34. unsigned char midi_mode; /* GM, GS, XG etc */
  35. unsigned int
  36. drum_channel:1, /* Drum channel */
  37. param_type:1 /* RPN/NRPN */
  38. ;
  39. unsigned char midi_aftertouch; /* Aftertouch (key pressure) */
  40. unsigned char midi_pressure; /* Channel pressure */
  41. unsigned char midi_program; /* Instrument number */
  42. short midi_pitchbend; /* Pitch bend amount */
  43. unsigned char control[128]; /* Current value of all controls */
  44. unsigned char note[128]; /* Current status for all notes */
  45. short gm_rpn_pitch_bend_range; /* Pitch bend range */
  46. short gm_rpn_fine_tuning; /* Master fine tuning */
  47. short gm_rpn_coarse_tuning; /* Master coarse tuning */
  48. };
  49. /*
  50. * A structure that represets a set of channels bound to a port. There
  51. * would usually be 16 channels per port. But fewer could be used for
  52. * particular cases.
  53. * The channel set consists of information describing the client and
  54. * port for this midi synth and an array of snd_midi_channel structures.
  55. * A driver that had no need for snd_midi_channel could still use the
  56. * channel set type if it wished with the channel array null.
  57. */
  58. struct snd_midi_channel_set {
  59. void *private_data; /* Driver data */
  60. int client; /* Client for this port */
  61. int port; /* The port number */
  62. int max_channels; /* Size of the channels array */
  63. struct snd_midi_channel *channels;
  64. unsigned char midi_mode; /* MIDI operating mode */
  65. unsigned char gs_master_volume; /* SYSEX master volume: 0-127 */
  66. unsigned char gs_chorus_mode;
  67. unsigned char gs_reverb_mode;
  68. };
  69. struct snd_midi_op {
  70. void (*note_on)(void *private_data, int note, int vel, struct snd_midi_channel *chan);
  71. void (*note_off)(void *private_data,int note, int vel, struct snd_midi_channel *chan); /* release note */
  72. void (*key_press)(void *private_data, int note, int vel, struct snd_midi_channel *chan);
  73. void (*note_terminate)(void *private_data, int note, struct snd_midi_channel *chan); /* terminate note immediately */
  74. void (*control)(void *private_data, int type, struct snd_midi_channel *chan);
  75. void (*nrpn)(void *private_data, struct snd_midi_channel *chan,
  76. struct snd_midi_channel_set *chset);
  77. void (*sysex)(void *private_data, unsigned char *buf, int len, int parsed,
  78. struct snd_midi_channel_set *chset);
  79. };
  80. /*
  81. * These defines are used so that pitchbend, aftertouch etc, can be
  82. * distinguished from controller values.
  83. */
  84. /* 0-127 controller values */
  85. #define MIDI_CTL_PITCHBEND 0x80
  86. #define MIDI_CTL_AFTERTOUCH 0x81
  87. #define MIDI_CTL_CHAN_PRESSURE 0x82
  88. /*
  89. * These names exist to allow symbolic access to the controls array.
  90. * The usage is eg: chan->gm_bank_select. Another implementation would
  91. * be really have these members in the struct, and not the array.
  92. */
  93. #define gm_bank_select control[0]
  94. #define gm_modulation control[1]
  95. #define gm_breath control[2]
  96. #define gm_foot_pedal control[4]
  97. #define gm_portamento_time control[5]
  98. #define gm_data_entry control[6]
  99. #define gm_volume control[7]
  100. #define gm_balance control[8]
  101. #define gm_pan control[10]
  102. #define gm_expression control[11]
  103. #define gm_effect_control1 control[12]
  104. #define gm_effect_control2 control[13]
  105. #define gm_slider1 control[16]
  106. #define gm_slider2 control[17]
  107. #define gm_slider3 control[18]
  108. #define gm_slider4 control[19]
  109. #define gm_bank_select_lsb control[32]
  110. #define gm_modulation_wheel_lsb control[33]
  111. #define gm_breath_lsb control[34]
  112. #define gm_foot_pedal_lsb control[36]
  113. #define gm_portamento_time_lsb control[37]
  114. #define gm_data_entry_lsb control[38]
  115. #define gm_volume_lsb control[39]
  116. #define gm_balance_lsb control[40]
  117. #define gm_pan_lsb control[42]
  118. #define gm_expression_lsb control[43]
  119. #define gm_effect_control1_lsb control[44]
  120. #define gm_effect_control2_lsb control[45]
  121. #define gm_sustain control[MIDI_CTL_SUSTAIN]
  122. #define gm_hold gm_sustain
  123. #define gm_portamento control[MIDI_CTL_PORTAMENTO]
  124. #define gm_sostenuto control[MIDI_CTL_SOSTENUTO]
  125. /*
  126. * These macros give the complete value of the controls that consist
  127. * of coarse and fine pairs. Of course the fine controls are seldom used
  128. * but there is no harm in being complete.
  129. */
  130. #define SNDRV_GM_BANK_SELECT(cp) (((cp)->control[0]<<7)|((cp)->control[32]))
  131. #define SNDRV_GM_MODULATION_WHEEL(cp) (((cp)->control[1]<<7)|((cp)->control[33]))
  132. #define SNDRV_GM_BREATH(cp) (((cp)->control[2]<<7)|((cp)->control[34]))
  133. #define SNDRV_GM_FOOT_PEDAL(cp) (((cp)->control[4]<<7)|((cp)->control[36]))
  134. #define SNDRV_GM_PORTAMENTO_TIME(cp) (((cp)->control[5]<<7)|((cp)->control[37]))
  135. #define SNDRV_GM_DATA_ENTRY(cp) (((cp)->control[6]<<7)|((cp)->control[38]))
  136. #define SNDRV_GM_VOLUME(cp) (((cp)->control[7]<<7)|((cp)->control[39]))
  137. #define SNDRV_GM_BALANCE(cp) (((cp)->control[8]<<7)|((cp)->control[40]))
  138. #define SNDRV_GM_PAN(cp) (((cp)->control[10]<<7)|((cp)->control[42]))
  139. #define SNDRV_GM_EXPRESSION(cp) (((cp)->control[11]<<7)|((cp)->control[43]))
  140. /* MIDI mode */
  141. #define SNDRV_MIDI_MODE_NONE 0 /* Generic midi */
  142. #define SNDRV_MIDI_MODE_GM 1
  143. #define SNDRV_MIDI_MODE_GS 2
  144. #define SNDRV_MIDI_MODE_XG 3
  145. #define SNDRV_MIDI_MODE_MT32 4
  146. /* MIDI note state */
  147. #define SNDRV_MIDI_NOTE_OFF 0x00
  148. #define SNDRV_MIDI_NOTE_ON 0x01
  149. #define SNDRV_MIDI_NOTE_RELEASED 0x02
  150. #define SNDRV_MIDI_NOTE_SOSTENUTO 0x04
  151. #define SNDRV_MIDI_PARAM_TYPE_REGISTERED 0
  152. #define SNDRV_MIDI_PARAM_TYPE_NONREGISTERED 1
  153. /* SYSEX parse flag */
  154. enum {
  155. SNDRV_MIDI_SYSEX_NOT_PARSED = 0,
  156. SNDRV_MIDI_SYSEX_GM_ON,
  157. SNDRV_MIDI_SYSEX_GS_ON,
  158. SNDRV_MIDI_SYSEX_GS_RESET,
  159. SNDRV_MIDI_SYSEX_GS_CHORUS_MODE,
  160. SNDRV_MIDI_SYSEX_GS_REVERB_MODE,
  161. SNDRV_MIDI_SYSEX_GS_MASTER_VOLUME,
  162. SNDRV_MIDI_SYSEX_GS_PROGRAM,
  163. SNDRV_MIDI_SYSEX_GS_DRUM_CHANNEL,
  164. SNDRV_MIDI_SYSEX_XG_ON,
  165. };
  166. /* Prototypes for midi_process.c */
  167. void snd_midi_process_event(struct snd_midi_op *ops, struct snd_seq_event *ev,
  168. struct snd_midi_channel_set *chanset);
  169. void snd_midi_channel_set_clear(struct snd_midi_channel_set *chset);
  170. struct snd_midi_channel_set *snd_midi_channel_alloc_set(int n);
  171. void snd_midi_channel_free_set(struct snd_midi_channel_set *chset);
  172. #endif /* __SOUND_SEQ_MIDI_EMUL_H */