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