18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci#ifndef __SOUND_SEQ_MIDI_EMUL_H 38c2ecf20Sopenharmony_ci#define __SOUND_SEQ_MIDI_EMUL_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* 68c2ecf20Sopenharmony_ci * Midi channel definition for optional channel management. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright (C) 1999 Steve Ratcliffe 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <sound/seq_kernel.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* 148c2ecf20Sopenharmony_ci * This structure is used to keep track of the current state on each 158c2ecf20Sopenharmony_ci * channel. All drivers for hardware that does not understand midi 168c2ecf20Sopenharmony_ci * directly will probably need to use this structure. 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_cistruct snd_midi_channel { 198c2ecf20Sopenharmony_ci void *private; /* A back pointer to driver data */ 208c2ecf20Sopenharmony_ci int number; /* The channel number */ 218c2ecf20Sopenharmony_ci int client; /* The client associated with this channel */ 228c2ecf20Sopenharmony_ci int port; /* The port associated with this channel */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci unsigned char midi_mode; /* GM, GS, XG etc */ 258c2ecf20Sopenharmony_ci unsigned int 268c2ecf20Sopenharmony_ci drum_channel:1, /* Drum channel */ 278c2ecf20Sopenharmony_ci param_type:1 /* RPN/NRPN */ 288c2ecf20Sopenharmony_ci ; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci unsigned char midi_aftertouch; /* Aftertouch (key pressure) */ 318c2ecf20Sopenharmony_ci unsigned char midi_pressure; /* Channel pressure */ 328c2ecf20Sopenharmony_ci unsigned char midi_program; /* Instrument number */ 338c2ecf20Sopenharmony_ci short midi_pitchbend; /* Pitch bend amount */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci unsigned char control[128]; /* Current value of all controls */ 368c2ecf20Sopenharmony_ci unsigned char note[128]; /* Current status for all notes */ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci short gm_rpn_pitch_bend_range; /* Pitch bend range */ 398c2ecf20Sopenharmony_ci short gm_rpn_fine_tuning; /* Master fine tuning */ 408c2ecf20Sopenharmony_ci short gm_rpn_coarse_tuning; /* Master coarse tuning */ 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* 458c2ecf20Sopenharmony_ci * A structure that represets a set of channels bound to a port. There 468c2ecf20Sopenharmony_ci * would usually be 16 channels per port. But fewer could be used for 478c2ecf20Sopenharmony_ci * particular cases. 488c2ecf20Sopenharmony_ci * The channel set consists of information describing the client and 498c2ecf20Sopenharmony_ci * port for this midi synth and an array of snd_midi_channel structures. 508c2ecf20Sopenharmony_ci * A driver that had no need for snd_midi_channel could still use the 518c2ecf20Sopenharmony_ci * channel set type if it wished with the channel array null. 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_cistruct snd_midi_channel_set { 548c2ecf20Sopenharmony_ci void *private_data; /* Driver data */ 558c2ecf20Sopenharmony_ci int client; /* Client for this port */ 568c2ecf20Sopenharmony_ci int port; /* The port number */ 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci int max_channels; /* Size of the channels array */ 598c2ecf20Sopenharmony_ci struct snd_midi_channel *channels; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci unsigned char midi_mode; /* MIDI operating mode */ 628c2ecf20Sopenharmony_ci unsigned char gs_master_volume; /* SYSEX master volume: 0-127 */ 638c2ecf20Sopenharmony_ci unsigned char gs_chorus_mode; 648c2ecf20Sopenharmony_ci unsigned char gs_reverb_mode; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistruct snd_midi_op { 698c2ecf20Sopenharmony_ci void (*note_on)(void *private_data, int note, int vel, struct snd_midi_channel *chan); 708c2ecf20Sopenharmony_ci void (*note_off)(void *private_data,int note, int vel, struct snd_midi_channel *chan); /* release note */ 718c2ecf20Sopenharmony_ci void (*key_press)(void *private_data, int note, int vel, struct snd_midi_channel *chan); 728c2ecf20Sopenharmony_ci void (*note_terminate)(void *private_data, int note, struct snd_midi_channel *chan); /* terminate note immediately */ 738c2ecf20Sopenharmony_ci void (*control)(void *private_data, int type, struct snd_midi_channel *chan); 748c2ecf20Sopenharmony_ci void (*nrpn)(void *private_data, struct snd_midi_channel *chan, 758c2ecf20Sopenharmony_ci struct snd_midi_channel_set *chset); 768c2ecf20Sopenharmony_ci void (*sysex)(void *private_data, unsigned char *buf, int len, int parsed, 778c2ecf20Sopenharmony_ci struct snd_midi_channel_set *chset); 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* 818c2ecf20Sopenharmony_ci * These defines are used so that pitchbend, aftertouch etc, can be 828c2ecf20Sopenharmony_ci * distinguished from controller values. 838c2ecf20Sopenharmony_ci */ 848c2ecf20Sopenharmony_ci/* 0-127 controller values */ 858c2ecf20Sopenharmony_ci#define MIDI_CTL_PITCHBEND 0x80 868c2ecf20Sopenharmony_ci#define MIDI_CTL_AFTERTOUCH 0x81 878c2ecf20Sopenharmony_ci#define MIDI_CTL_CHAN_PRESSURE 0x82 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* 908c2ecf20Sopenharmony_ci * These names exist to allow symbolic access to the controls array. 918c2ecf20Sopenharmony_ci * The usage is eg: chan->gm_bank_select. Another implementation would 928c2ecf20Sopenharmony_ci * be really have these members in the struct, and not the array. 938c2ecf20Sopenharmony_ci */ 948c2ecf20Sopenharmony_ci#define gm_bank_select control[0] 958c2ecf20Sopenharmony_ci#define gm_modulation control[1] 968c2ecf20Sopenharmony_ci#define gm_breath control[2] 978c2ecf20Sopenharmony_ci#define gm_foot_pedal control[4] 988c2ecf20Sopenharmony_ci#define gm_portamento_time control[5] 998c2ecf20Sopenharmony_ci#define gm_data_entry control[6] 1008c2ecf20Sopenharmony_ci#define gm_volume control[7] 1018c2ecf20Sopenharmony_ci#define gm_balance control[8] 1028c2ecf20Sopenharmony_ci#define gm_pan control[10] 1038c2ecf20Sopenharmony_ci#define gm_expression control[11] 1048c2ecf20Sopenharmony_ci#define gm_effect_control1 control[12] 1058c2ecf20Sopenharmony_ci#define gm_effect_control2 control[13] 1068c2ecf20Sopenharmony_ci#define gm_slider1 control[16] 1078c2ecf20Sopenharmony_ci#define gm_slider2 control[17] 1088c2ecf20Sopenharmony_ci#define gm_slider3 control[18] 1098c2ecf20Sopenharmony_ci#define gm_slider4 control[19] 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define gm_bank_select_lsb control[32] 1128c2ecf20Sopenharmony_ci#define gm_modulation_wheel_lsb control[33] 1138c2ecf20Sopenharmony_ci#define gm_breath_lsb control[34] 1148c2ecf20Sopenharmony_ci#define gm_foot_pedal_lsb control[36] 1158c2ecf20Sopenharmony_ci#define gm_portamento_time_lsb control[37] 1168c2ecf20Sopenharmony_ci#define gm_data_entry_lsb control[38] 1178c2ecf20Sopenharmony_ci#define gm_volume_lsb control[39] 1188c2ecf20Sopenharmony_ci#define gm_balance_lsb control[40] 1198c2ecf20Sopenharmony_ci#define gm_pan_lsb control[42] 1208c2ecf20Sopenharmony_ci#define gm_expression_lsb control[43] 1218c2ecf20Sopenharmony_ci#define gm_effect_control1_lsb control[44] 1228c2ecf20Sopenharmony_ci#define gm_effect_control2_lsb control[45] 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#define gm_sustain control[MIDI_CTL_SUSTAIN] 1258c2ecf20Sopenharmony_ci#define gm_hold gm_sustain 1268c2ecf20Sopenharmony_ci#define gm_portamento control[MIDI_CTL_PORTAMENTO] 1278c2ecf20Sopenharmony_ci#define gm_sostenuto control[MIDI_CTL_SOSTENUTO] 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/* 1308c2ecf20Sopenharmony_ci * These macros give the complete value of the controls that consist 1318c2ecf20Sopenharmony_ci * of coarse and fine pairs. Of course the fine controls are seldom used 1328c2ecf20Sopenharmony_ci * but there is no harm in being complete. 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_ci#define SNDRV_GM_BANK_SELECT(cp) (((cp)->control[0]<<7)|((cp)->control[32])) 1358c2ecf20Sopenharmony_ci#define SNDRV_GM_MODULATION_WHEEL(cp) (((cp)->control[1]<<7)|((cp)->control[33])) 1368c2ecf20Sopenharmony_ci#define SNDRV_GM_BREATH(cp) (((cp)->control[2]<<7)|((cp)->control[34])) 1378c2ecf20Sopenharmony_ci#define SNDRV_GM_FOOT_PEDAL(cp) (((cp)->control[4]<<7)|((cp)->control[36])) 1388c2ecf20Sopenharmony_ci#define SNDRV_GM_PORTAMENTO_TIME(cp) (((cp)->control[5]<<7)|((cp)->control[37])) 1398c2ecf20Sopenharmony_ci#define SNDRV_GM_DATA_ENTRY(cp) (((cp)->control[6]<<7)|((cp)->control[38])) 1408c2ecf20Sopenharmony_ci#define SNDRV_GM_VOLUME(cp) (((cp)->control[7]<<7)|((cp)->control[39])) 1418c2ecf20Sopenharmony_ci#define SNDRV_GM_BALANCE(cp) (((cp)->control[8]<<7)|((cp)->control[40])) 1428c2ecf20Sopenharmony_ci#define SNDRV_GM_PAN(cp) (((cp)->control[10]<<7)|((cp)->control[42])) 1438c2ecf20Sopenharmony_ci#define SNDRV_GM_EXPRESSION(cp) (((cp)->control[11]<<7)|((cp)->control[43])) 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci/* MIDI mode */ 1478c2ecf20Sopenharmony_ci#define SNDRV_MIDI_MODE_NONE 0 /* Generic midi */ 1488c2ecf20Sopenharmony_ci#define SNDRV_MIDI_MODE_GM 1 1498c2ecf20Sopenharmony_ci#define SNDRV_MIDI_MODE_GS 2 1508c2ecf20Sopenharmony_ci#define SNDRV_MIDI_MODE_XG 3 1518c2ecf20Sopenharmony_ci#define SNDRV_MIDI_MODE_MT32 4 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci/* MIDI note state */ 1548c2ecf20Sopenharmony_ci#define SNDRV_MIDI_NOTE_OFF 0x00 1558c2ecf20Sopenharmony_ci#define SNDRV_MIDI_NOTE_ON 0x01 1568c2ecf20Sopenharmony_ci#define SNDRV_MIDI_NOTE_RELEASED 0x02 1578c2ecf20Sopenharmony_ci#define SNDRV_MIDI_NOTE_SOSTENUTO 0x04 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci#define SNDRV_MIDI_PARAM_TYPE_REGISTERED 0 1608c2ecf20Sopenharmony_ci#define SNDRV_MIDI_PARAM_TYPE_NONREGISTERED 1 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci/* SYSEX parse flag */ 1638c2ecf20Sopenharmony_cienum { 1648c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_NOT_PARSED = 0, 1658c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_GM_ON, 1668c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_GS_ON, 1678c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_GS_RESET, 1688c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_GS_CHORUS_MODE, 1698c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_GS_REVERB_MODE, 1708c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_GS_MASTER_VOLUME, 1718c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_GS_PROGRAM, 1728c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_GS_DRUM_CHANNEL, 1738c2ecf20Sopenharmony_ci SNDRV_MIDI_SYSEX_XG_ON, 1748c2ecf20Sopenharmony_ci}; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci/* Prototypes for midi_process.c */ 1778c2ecf20Sopenharmony_civoid snd_midi_process_event(const struct snd_midi_op *ops, 1788c2ecf20Sopenharmony_ci struct snd_seq_event *ev, 1798c2ecf20Sopenharmony_ci struct snd_midi_channel_set *chanset); 1808c2ecf20Sopenharmony_civoid snd_midi_channel_set_clear(struct snd_midi_channel_set *chset); 1818c2ecf20Sopenharmony_cistruct snd_midi_channel_set *snd_midi_channel_alloc_set(int n); 1828c2ecf20Sopenharmony_civoid snd_midi_channel_free_set(struct snd_midi_channel_set *chset); 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci#endif /* __SOUND_SEQ_MIDI_EMUL_H */ 185