Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef __SOUND_SEQ_MIDI_EMUL_H
0003 #define __SOUND_SEQ_MIDI_EMUL_H
0004 
0005 /*
0006  *  Midi channel definition for optional channel management.
0007  *
0008  *  Copyright (C) 1999 Steve Ratcliffe
0009  */
0010 
0011 #include <sound/seq_kernel.h>
0012 
0013 /*
0014  * This structure is used to keep track of the current state on each
0015  * channel.  All drivers for hardware that does not understand midi
0016  * directly will probably need to use this structure.
0017  */
0018 struct snd_midi_channel {
0019     void *private;      /* A back pointer to driver data */
0020     int  number;        /* The channel number */
0021     int  client;        /* The client associated with this channel */
0022     int  port;      /* The port associated with this channel */
0023 
0024     unsigned char midi_mode;    /* GM, GS, XG etc */
0025     unsigned int 
0026         drum_channel:1,     /* Drum channel */
0027         param_type:1        /* RPN/NRPN */
0028         ;
0029 
0030     unsigned char midi_aftertouch;  /* Aftertouch (key pressure) */
0031     unsigned char midi_pressure;    /* Channel pressure */
0032     unsigned char midi_program; /* Instrument number */
0033     short midi_pitchbend;       /* Pitch bend amount */
0034 
0035     unsigned char control[128]; /* Current value of all controls */
0036     unsigned char note[128];    /* Current status for all notes */
0037 
0038     short gm_rpn_pitch_bend_range;  /* Pitch bend range */
0039     short gm_rpn_fine_tuning;   /* Master fine tuning */
0040     short gm_rpn_coarse_tuning; /* Master coarse tuning */
0041 
0042 };
0043 
0044 /*
0045  * A structure that represets a set of channels bound to a port.  There
0046  * would usually be 16 channels per port.  But fewer could be used for
0047  * particular cases.
0048  * The channel set consists of information describing the client and
0049  * port for this midi synth and an array of snd_midi_channel structures.
0050  * A driver that had no need for snd_midi_channel could still use the
0051  * channel set type if it wished with the channel array null.
0052  */
0053 struct snd_midi_channel_set {
0054     void *private_data;     /* Driver data */
0055     int  client;            /* Client for this port */
0056     int  port;          /* The port number */
0057 
0058     int  max_channels;      /* Size of the channels array */
0059     struct snd_midi_channel *channels;
0060 
0061     unsigned char midi_mode;    /* MIDI operating mode */
0062     unsigned char gs_master_volume; /* SYSEX master volume: 0-127 */
0063     unsigned char gs_chorus_mode;
0064     unsigned char gs_reverb_mode;
0065 
0066 };
0067 
0068 struct snd_midi_op {
0069     void (*note_on)(void *private_data, int note, int vel, struct snd_midi_channel *chan);
0070     void (*note_off)(void *private_data,int note, int vel, struct snd_midi_channel *chan); /* release note */
0071     void (*key_press)(void *private_data, int note, int vel, struct snd_midi_channel *chan);
0072     void (*note_terminate)(void *private_data, int note, struct snd_midi_channel *chan); /* terminate note immediately */
0073     void (*control)(void *private_data, int type, struct snd_midi_channel *chan);
0074     void (*nrpn)(void *private_data, struct snd_midi_channel *chan,
0075              struct snd_midi_channel_set *chset);
0076     void (*sysex)(void *private_data, unsigned char *buf, int len, int parsed,
0077               struct snd_midi_channel_set *chset);
0078 };
0079 
0080 /*
0081  * These defines are used so that pitchbend, aftertouch etc, can be
0082  * distinguished from controller values.
0083  */
0084 /* 0-127 controller values */
0085 #define MIDI_CTL_PITCHBEND  0x80
0086 #define MIDI_CTL_AFTERTOUCH 0x81
0087 #define MIDI_CTL_CHAN_PRESSURE  0x82
0088 
0089 /*
0090  * These names exist to allow symbolic access to the controls array.
0091  * The usage is eg: chan->gm_bank_select.  Another implementation would
0092  * be really have these members in the struct, and not the array.
0093  */
0094 #define gm_bank_select      control[0]
0095 #define gm_modulation       control[1]
0096 #define gm_breath       control[2]
0097 #define gm_foot_pedal       control[4]
0098 #define gm_portamento_time  control[5]
0099 #define gm_data_entry       control[6]
0100 #define gm_volume       control[7]
0101 #define gm_balance      control[8]
0102 #define gm_pan          control[10]
0103 #define gm_expression       control[11]
0104 #define gm_effect_control1  control[12]
0105 #define gm_effect_control2  control[13]
0106 #define gm_slider1      control[16]
0107 #define gm_slider2      control[17]
0108 #define gm_slider3      control[18]
0109 #define gm_slider4      control[19]
0110 
0111 #define gm_bank_select_lsb  control[32]
0112 #define gm_modulation_wheel_lsb control[33]
0113 #define gm_breath_lsb       control[34]
0114 #define gm_foot_pedal_lsb   control[36]
0115 #define gm_portamento_time_lsb  control[37]
0116 #define gm_data_entry_lsb   control[38]
0117 #define gm_volume_lsb       control[39]
0118 #define gm_balance_lsb      control[40]
0119 #define gm_pan_lsb      control[42]
0120 #define gm_expression_lsb   control[43]
0121 #define gm_effect_control1_lsb  control[44]
0122 #define gm_effect_control2_lsb  control[45]
0123 
0124 #define gm_sustain      control[MIDI_CTL_SUSTAIN]
0125 #define gm_hold         gm_sustain
0126 #define gm_portamento       control[MIDI_CTL_PORTAMENTO]
0127 #define gm_sostenuto        control[MIDI_CTL_SOSTENUTO]
0128 
0129 /*
0130  * These macros give the complete value of the controls that consist
0131  * of coarse and fine pairs.  Of course the fine controls are seldom used
0132  * but there is no harm in being complete.
0133  */
0134 #define SNDRV_GM_BANK_SELECT(cp)        (((cp)->control[0]<<7)|((cp)->control[32]))
0135 #define SNDRV_GM_MODULATION_WHEEL(cp)   (((cp)->control[1]<<7)|((cp)->control[33]))
0136 #define SNDRV_GM_BREATH(cp)     (((cp)->control[2]<<7)|((cp)->control[34]))
0137 #define SNDRV_GM_FOOT_PEDAL(cp)     (((cp)->control[4]<<7)|((cp)->control[36]))
0138 #define SNDRV_GM_PORTAMENTO_TIME(cp)    (((cp)->control[5]<<7)|((cp)->control[37]))
0139 #define SNDRV_GM_DATA_ENTRY(cp)     (((cp)->control[6]<<7)|((cp)->control[38]))
0140 #define SNDRV_GM_VOLUME(cp)     (((cp)->control[7]<<7)|((cp)->control[39]))
0141 #define SNDRV_GM_BALANCE(cp)        (((cp)->control[8]<<7)|((cp)->control[40]))
0142 #define SNDRV_GM_PAN(cp)            (((cp)->control[10]<<7)|((cp)->control[42]))
0143 #define SNDRV_GM_EXPRESSION(cp)     (((cp)->control[11]<<7)|((cp)->control[43]))
0144 
0145 
0146 /* MIDI mode */
0147 #define SNDRV_MIDI_MODE_NONE    0   /* Generic midi */
0148 #define SNDRV_MIDI_MODE_GM  1
0149 #define SNDRV_MIDI_MODE_GS  2
0150 #define SNDRV_MIDI_MODE_XG  3
0151 #define SNDRV_MIDI_MODE_MT32    4
0152 
0153 /* MIDI note state */
0154 #define SNDRV_MIDI_NOTE_OFF     0x00
0155 #define SNDRV_MIDI_NOTE_ON      0x01
0156 #define SNDRV_MIDI_NOTE_RELEASED        0x02
0157 #define SNDRV_MIDI_NOTE_SOSTENUTO       0x04
0158  
0159 #define SNDRV_MIDI_PARAM_TYPE_REGISTERED        0
0160 #define SNDRV_MIDI_PARAM_TYPE_NONREGISTERED 1
0161 
0162 /* SYSEX parse flag */
0163 enum {
0164     SNDRV_MIDI_SYSEX_NOT_PARSED = 0,
0165     SNDRV_MIDI_SYSEX_GM_ON, 
0166     SNDRV_MIDI_SYSEX_GS_ON, 
0167     SNDRV_MIDI_SYSEX_GS_RESET,  
0168     SNDRV_MIDI_SYSEX_GS_CHORUS_MODE,
0169     SNDRV_MIDI_SYSEX_GS_REVERB_MODE,
0170     SNDRV_MIDI_SYSEX_GS_MASTER_VOLUME,
0171     SNDRV_MIDI_SYSEX_GS_PROGRAM,
0172     SNDRV_MIDI_SYSEX_GS_DRUM_CHANNEL,
0173     SNDRV_MIDI_SYSEX_XG_ON, 
0174 };
0175 
0176 /* Prototypes for midi_process.c */
0177 void snd_midi_process_event(const struct snd_midi_op *ops,
0178                 struct snd_seq_event *ev,
0179                 struct snd_midi_channel_set *chanset);
0180 void snd_midi_channel_set_clear(struct snd_midi_channel_set *chset);
0181 struct snd_midi_channel_set *snd_midi_channel_alloc_set(int n);
0182 void snd_midi_channel_free_set(struct snd_midi_channel_set *chset);
0183 
0184 #endif /* __SOUND_SEQ_MIDI_EMUL_H */