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