18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  NRPN / SYSEX callbacks for Emu8k/Emu10k1
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (c) 1999-2000 Takashi Iwai <tiwai@suse.de>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "emux_voice.h"
98c2ecf20Sopenharmony_ci#include <sound/asoundef.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/*
128c2ecf20Sopenharmony_ci * conversion from NRPN/control parameters to Emu8000 raw parameters
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* NRPN / CC -> Emu8000 parameter converter */
168c2ecf20Sopenharmony_cistruct nrpn_conv_table {
178c2ecf20Sopenharmony_ci	int control;
188c2ecf20Sopenharmony_ci	int effect;
198c2ecf20Sopenharmony_ci	int (*convert)(int val);
208c2ecf20Sopenharmony_ci};
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* effect sensitivity */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define FX_CUTOFF	0
258c2ecf20Sopenharmony_ci#define FX_RESONANCE	1
268c2ecf20Sopenharmony_ci#define FX_ATTACK	2
278c2ecf20Sopenharmony_ci#define FX_RELEASE	3
288c2ecf20Sopenharmony_ci#define FX_VIBRATE	4
298c2ecf20Sopenharmony_ci#define FX_VIBDEPTH	5
308c2ecf20Sopenharmony_ci#define FX_VIBDELAY	6
318c2ecf20Sopenharmony_ci#define FX_NUMS		7
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/*
348c2ecf20Sopenharmony_ci * convert NRPN/control values
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic int send_converted_effect(const struct nrpn_conv_table *table,
388c2ecf20Sopenharmony_ci				 int num_tables,
398c2ecf20Sopenharmony_ci				 struct snd_emux_port *port,
408c2ecf20Sopenharmony_ci				 struct snd_midi_channel *chan,
418c2ecf20Sopenharmony_ci				 int type, int val, int mode)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	int i, cval;
448c2ecf20Sopenharmony_ci	for (i = 0; i < num_tables; i++) {
458c2ecf20Sopenharmony_ci		if (table[i].control == type) {
468c2ecf20Sopenharmony_ci			cval = table[i].convert(val);
478c2ecf20Sopenharmony_ci			snd_emux_send_effect(port, chan, table[i].effect,
488c2ecf20Sopenharmony_ci					     cval, mode);
498c2ecf20Sopenharmony_ci			return 1;
508c2ecf20Sopenharmony_ci		}
518c2ecf20Sopenharmony_ci	}
528c2ecf20Sopenharmony_ci	return 0;
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define DEF_FX_CUTOFF		170
568c2ecf20Sopenharmony_ci#define DEF_FX_RESONANCE	6
578c2ecf20Sopenharmony_ci#define DEF_FX_ATTACK		50
588c2ecf20Sopenharmony_ci#define DEF_FX_RELEASE		50
598c2ecf20Sopenharmony_ci#define DEF_FX_VIBRATE		30
608c2ecf20Sopenharmony_ci#define DEF_FX_VIBDEPTH		4
618c2ecf20Sopenharmony_ci#define DEF_FX_VIBDELAY		1500
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* effect sensitivities for GS NRPN:
648c2ecf20Sopenharmony_ci *  adjusted for chaos 8MB soundfonts
658c2ecf20Sopenharmony_ci */
668c2ecf20Sopenharmony_cistatic const int gs_sense[] =
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	DEF_FX_CUTOFF, DEF_FX_RESONANCE, DEF_FX_ATTACK, DEF_FX_RELEASE,
698c2ecf20Sopenharmony_ci	DEF_FX_VIBRATE, DEF_FX_VIBDEPTH, DEF_FX_VIBDELAY
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* effect sensitivies for XG controls:
738c2ecf20Sopenharmony_ci * adjusted for chaos 8MB soundfonts
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_cistatic const int xg_sense[] =
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	DEF_FX_CUTOFF, DEF_FX_RESONANCE, DEF_FX_ATTACK, DEF_FX_RELEASE,
788c2ecf20Sopenharmony_ci	DEF_FX_VIBRATE, DEF_FX_VIBDEPTH, DEF_FX_VIBDELAY
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/*
838c2ecf20Sopenharmony_ci * AWE32 NRPN effects
848c2ecf20Sopenharmony_ci */
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistatic int fx_delay(int val);
878c2ecf20Sopenharmony_cistatic int fx_attack(int val);
888c2ecf20Sopenharmony_cistatic int fx_hold(int val);
898c2ecf20Sopenharmony_cistatic int fx_decay(int val);
908c2ecf20Sopenharmony_cistatic int fx_the_value(int val);
918c2ecf20Sopenharmony_cistatic int fx_twice_value(int val);
928c2ecf20Sopenharmony_cistatic int fx_conv_pitch(int val);
938c2ecf20Sopenharmony_cistatic int fx_conv_Q(int val);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/* function for each NRPN */		/* [range]  units */
968c2ecf20Sopenharmony_ci#define fx_env1_delay	fx_delay	/* [0,5900] 4msec */
978c2ecf20Sopenharmony_ci#define fx_env1_attack	fx_attack	/* [0,5940] 1msec */
988c2ecf20Sopenharmony_ci#define fx_env1_hold	fx_hold		/* [0,8191] 1msec */
998c2ecf20Sopenharmony_ci#define fx_env1_decay	fx_decay	/* [0,5940] 4msec */
1008c2ecf20Sopenharmony_ci#define fx_env1_release	fx_decay	/* [0,5940] 4msec */
1018c2ecf20Sopenharmony_ci#define fx_env1_sustain	fx_the_value	/* [0,127] 0.75dB */
1028c2ecf20Sopenharmony_ci#define fx_env1_pitch	fx_the_value	/* [-127,127] 9.375cents */
1038c2ecf20Sopenharmony_ci#define fx_env1_cutoff	fx_the_value	/* [-127,127] 56.25cents */
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define fx_env2_delay	fx_delay	/* [0,5900] 4msec */
1068c2ecf20Sopenharmony_ci#define fx_env2_attack	fx_attack	/* [0,5940] 1msec */
1078c2ecf20Sopenharmony_ci#define fx_env2_hold	fx_hold		/* [0,8191] 1msec */
1088c2ecf20Sopenharmony_ci#define fx_env2_decay	fx_decay	/* [0,5940] 4msec */
1098c2ecf20Sopenharmony_ci#define fx_env2_release	fx_decay	/* [0,5940] 4msec */
1108c2ecf20Sopenharmony_ci#define fx_env2_sustain	fx_the_value	/* [0,127] 0.75dB */
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define fx_lfo1_delay	fx_delay	/* [0,5900] 4msec */
1138c2ecf20Sopenharmony_ci#define fx_lfo1_freq	fx_twice_value	/* [0,127] 84mHz */
1148c2ecf20Sopenharmony_ci#define fx_lfo1_volume	fx_twice_value	/* [0,127] 0.1875dB */
1158c2ecf20Sopenharmony_ci#define fx_lfo1_pitch	fx_the_value	/* [-127,127] 9.375cents */
1168c2ecf20Sopenharmony_ci#define fx_lfo1_cutoff	fx_twice_value	/* [-64,63] 56.25cents */
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#define fx_lfo2_delay	fx_delay	/* [0,5900] 4msec */
1198c2ecf20Sopenharmony_ci#define fx_lfo2_freq	fx_twice_value	/* [0,127] 84mHz */
1208c2ecf20Sopenharmony_ci#define fx_lfo2_pitch	fx_the_value	/* [-127,127] 9.375cents */
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#define fx_init_pitch	fx_conv_pitch	/* [-8192,8192] cents */
1238c2ecf20Sopenharmony_ci#define fx_chorus	fx_the_value	/* [0,255] -- */
1248c2ecf20Sopenharmony_ci#define fx_reverb	fx_the_value	/* [0,255] -- */
1258c2ecf20Sopenharmony_ci#define fx_cutoff	fx_twice_value	/* [0,127] 62Hz */
1268c2ecf20Sopenharmony_ci#define fx_filterQ	fx_conv_Q	/* [0,127] -- */
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_cistatic int fx_delay(int val)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci	return (unsigned short)snd_sf_calc_parm_delay(val);
1318c2ecf20Sopenharmony_ci}
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic int fx_attack(int val)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	return (unsigned short)snd_sf_calc_parm_attack(val);
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic int fx_hold(int val)
1398c2ecf20Sopenharmony_ci{
1408c2ecf20Sopenharmony_ci	return (unsigned short)snd_sf_calc_parm_hold(val);
1418c2ecf20Sopenharmony_ci}
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_cistatic int fx_decay(int val)
1448c2ecf20Sopenharmony_ci{
1458c2ecf20Sopenharmony_ci	return (unsigned short)snd_sf_calc_parm_decay(val);
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic int fx_the_value(int val)
1498c2ecf20Sopenharmony_ci{
1508c2ecf20Sopenharmony_ci	return (unsigned short)(val & 0xff);
1518c2ecf20Sopenharmony_ci}
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cistatic int fx_twice_value(int val)
1548c2ecf20Sopenharmony_ci{
1558c2ecf20Sopenharmony_ci	return (unsigned short)((val * 2) & 0xff);
1568c2ecf20Sopenharmony_ci}
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistatic int fx_conv_pitch(int val)
1598c2ecf20Sopenharmony_ci{
1608c2ecf20Sopenharmony_ci	return (short)(val * 4096 / 1200);
1618c2ecf20Sopenharmony_ci}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistatic int fx_conv_Q(int val)
1648c2ecf20Sopenharmony_ci{
1658c2ecf20Sopenharmony_ci	return (unsigned short)((val / 8) & 0xff);
1668c2ecf20Sopenharmony_ci}
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cistatic const struct nrpn_conv_table awe_effects[] =
1708c2ecf20Sopenharmony_ci{
1718c2ecf20Sopenharmony_ci	{ 0, EMUX_FX_LFO1_DELAY,	fx_lfo1_delay},
1728c2ecf20Sopenharmony_ci	{ 1, EMUX_FX_LFO1_FREQ,	fx_lfo1_freq},
1738c2ecf20Sopenharmony_ci	{ 2, EMUX_FX_LFO2_DELAY,	fx_lfo2_delay},
1748c2ecf20Sopenharmony_ci	{ 3, EMUX_FX_LFO2_FREQ,	fx_lfo2_freq},
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	{ 4, EMUX_FX_ENV1_DELAY,	fx_env1_delay},
1778c2ecf20Sopenharmony_ci	{ 5, EMUX_FX_ENV1_ATTACK,fx_env1_attack},
1788c2ecf20Sopenharmony_ci	{ 6, EMUX_FX_ENV1_HOLD,	fx_env1_hold},
1798c2ecf20Sopenharmony_ci	{ 7, EMUX_FX_ENV1_DECAY,	fx_env1_decay},
1808c2ecf20Sopenharmony_ci	{ 8, EMUX_FX_ENV1_SUSTAIN,	fx_env1_sustain},
1818c2ecf20Sopenharmony_ci	{ 9, EMUX_FX_ENV1_RELEASE,	fx_env1_release},
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	{10, EMUX_FX_ENV2_DELAY,	fx_env2_delay},
1848c2ecf20Sopenharmony_ci	{11, EMUX_FX_ENV2_ATTACK,	fx_env2_attack},
1858c2ecf20Sopenharmony_ci	{12, EMUX_FX_ENV2_HOLD,	fx_env2_hold},
1868c2ecf20Sopenharmony_ci	{13, EMUX_FX_ENV2_DECAY,	fx_env2_decay},
1878c2ecf20Sopenharmony_ci	{14, EMUX_FX_ENV2_SUSTAIN,	fx_env2_sustain},
1888c2ecf20Sopenharmony_ci	{15, EMUX_FX_ENV2_RELEASE,	fx_env2_release},
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	{16, EMUX_FX_INIT_PITCH,	fx_init_pitch},
1918c2ecf20Sopenharmony_ci	{17, EMUX_FX_LFO1_PITCH,	fx_lfo1_pitch},
1928c2ecf20Sopenharmony_ci	{18, EMUX_FX_LFO2_PITCH,	fx_lfo2_pitch},
1938c2ecf20Sopenharmony_ci	{19, EMUX_FX_ENV1_PITCH,	fx_env1_pitch},
1948c2ecf20Sopenharmony_ci	{20, EMUX_FX_LFO1_VOLUME,	fx_lfo1_volume},
1958c2ecf20Sopenharmony_ci	{21, EMUX_FX_CUTOFF,		fx_cutoff},
1968c2ecf20Sopenharmony_ci	{22, EMUX_FX_FILTERQ,	fx_filterQ},
1978c2ecf20Sopenharmony_ci	{23, EMUX_FX_LFO1_CUTOFF,	fx_lfo1_cutoff},
1988c2ecf20Sopenharmony_ci	{24, EMUX_FX_ENV1_CUTOFF,	fx_env1_cutoff},
1998c2ecf20Sopenharmony_ci	{25, EMUX_FX_CHORUS,		fx_chorus},
2008c2ecf20Sopenharmony_ci	{26, EMUX_FX_REVERB,		fx_reverb},
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/*
2058c2ecf20Sopenharmony_ci * GS(SC88) NRPN effects; still experimental
2068c2ecf20Sopenharmony_ci */
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/* cutoff: quarter semitone step, max=255 */
2098c2ecf20Sopenharmony_cistatic int gs_cutoff(int val)
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci	return (val - 64) * gs_sense[FX_CUTOFF] / 50;
2128c2ecf20Sopenharmony_ci}
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/* resonance: 0 to 15(max) */
2158c2ecf20Sopenharmony_cistatic int gs_filterQ(int val)
2168c2ecf20Sopenharmony_ci{
2178c2ecf20Sopenharmony_ci	return (val - 64) * gs_sense[FX_RESONANCE] / 50;
2188c2ecf20Sopenharmony_ci}
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci/* attack: */
2218c2ecf20Sopenharmony_cistatic int gs_attack(int val)
2228c2ecf20Sopenharmony_ci{
2238c2ecf20Sopenharmony_ci	return -(val - 64) * gs_sense[FX_ATTACK] / 50;
2248c2ecf20Sopenharmony_ci}
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci/* decay: */
2278c2ecf20Sopenharmony_cistatic int gs_decay(int val)
2288c2ecf20Sopenharmony_ci{
2298c2ecf20Sopenharmony_ci	return -(val - 64) * gs_sense[FX_RELEASE] / 50;
2308c2ecf20Sopenharmony_ci}
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci/* release: */
2338c2ecf20Sopenharmony_cistatic int gs_release(int val)
2348c2ecf20Sopenharmony_ci{
2358c2ecf20Sopenharmony_ci	return -(val - 64) * gs_sense[FX_RELEASE] / 50;
2368c2ecf20Sopenharmony_ci}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci/* vibrato freq: 0.042Hz step, max=255 */
2398c2ecf20Sopenharmony_cistatic int gs_vib_rate(int val)
2408c2ecf20Sopenharmony_ci{
2418c2ecf20Sopenharmony_ci	return (val - 64) * gs_sense[FX_VIBRATE] / 50;
2428c2ecf20Sopenharmony_ci}
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci/* vibrato depth: max=127, 1 octave */
2458c2ecf20Sopenharmony_cistatic int gs_vib_depth(int val)
2468c2ecf20Sopenharmony_ci{
2478c2ecf20Sopenharmony_ci	return (val - 64) * gs_sense[FX_VIBDEPTH] / 50;
2488c2ecf20Sopenharmony_ci}
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci/* vibrato delay: -0.725msec step */
2518c2ecf20Sopenharmony_cistatic int gs_vib_delay(int val)
2528c2ecf20Sopenharmony_ci{
2538c2ecf20Sopenharmony_ci	return -(val - 64) * gs_sense[FX_VIBDELAY] / 50;
2548c2ecf20Sopenharmony_ci}
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_cistatic const struct nrpn_conv_table gs_effects[] =
2578c2ecf20Sopenharmony_ci{
2588c2ecf20Sopenharmony_ci	{32, EMUX_FX_CUTOFF,	gs_cutoff},
2598c2ecf20Sopenharmony_ci	{33, EMUX_FX_FILTERQ,	gs_filterQ},
2608c2ecf20Sopenharmony_ci	{99, EMUX_FX_ENV2_ATTACK, gs_attack},
2618c2ecf20Sopenharmony_ci	{100, EMUX_FX_ENV2_DECAY, gs_decay},
2628c2ecf20Sopenharmony_ci	{102, EMUX_FX_ENV2_RELEASE, gs_release},
2638c2ecf20Sopenharmony_ci	{8, EMUX_FX_LFO1_FREQ, gs_vib_rate},
2648c2ecf20Sopenharmony_ci	{9, EMUX_FX_LFO1_VOLUME, gs_vib_depth},
2658c2ecf20Sopenharmony_ci	{10, EMUX_FX_LFO1_DELAY, gs_vib_delay},
2668c2ecf20Sopenharmony_ci};
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/*
2708c2ecf20Sopenharmony_ci * NRPN events
2718c2ecf20Sopenharmony_ci */
2728c2ecf20Sopenharmony_civoid
2738c2ecf20Sopenharmony_cisnd_emux_nrpn(void *p, struct snd_midi_channel *chan,
2748c2ecf20Sopenharmony_ci	      struct snd_midi_channel_set *chset)
2758c2ecf20Sopenharmony_ci{
2768c2ecf20Sopenharmony_ci	struct snd_emux_port *port;
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	port = p;
2798c2ecf20Sopenharmony_ci	if (snd_BUG_ON(!port || !chan))
2808c2ecf20Sopenharmony_ci		return;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	if (chan->control[MIDI_CTL_NONREG_PARM_NUM_MSB] == 127 &&
2838c2ecf20Sopenharmony_ci	    chan->control[MIDI_CTL_NONREG_PARM_NUM_LSB] <= 26) {
2848c2ecf20Sopenharmony_ci		int val;
2858c2ecf20Sopenharmony_ci		/* Win/DOS AWE32 specific NRPNs */
2868c2ecf20Sopenharmony_ci		/* both MSB/LSB necessary */
2878c2ecf20Sopenharmony_ci		val = (chan->control[MIDI_CTL_MSB_DATA_ENTRY] << 7) |
2888c2ecf20Sopenharmony_ci			chan->control[MIDI_CTL_LSB_DATA_ENTRY];
2898c2ecf20Sopenharmony_ci		val -= 8192;
2908c2ecf20Sopenharmony_ci		send_converted_effect
2918c2ecf20Sopenharmony_ci			(awe_effects, ARRAY_SIZE(awe_effects),
2928c2ecf20Sopenharmony_ci			 port, chan, chan->control[MIDI_CTL_NONREG_PARM_NUM_LSB],
2938c2ecf20Sopenharmony_ci			 val, EMUX_FX_FLAG_SET);
2948c2ecf20Sopenharmony_ci		return;
2958c2ecf20Sopenharmony_ci	}
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	if (port->chset.midi_mode == SNDRV_MIDI_MODE_GS &&
2988c2ecf20Sopenharmony_ci	    chan->control[MIDI_CTL_NONREG_PARM_NUM_MSB] == 1) {
2998c2ecf20Sopenharmony_ci		int val;
3008c2ecf20Sopenharmony_ci		/* GS specific NRPNs */
3018c2ecf20Sopenharmony_ci		/* only MSB is valid */
3028c2ecf20Sopenharmony_ci		val = chan->control[MIDI_CTL_MSB_DATA_ENTRY];
3038c2ecf20Sopenharmony_ci		send_converted_effect
3048c2ecf20Sopenharmony_ci			(gs_effects, ARRAY_SIZE(gs_effects),
3058c2ecf20Sopenharmony_ci			 port, chan, chan->control[MIDI_CTL_NONREG_PARM_NUM_LSB],
3068c2ecf20Sopenharmony_ci			 val, EMUX_FX_FLAG_ADD);
3078c2ecf20Sopenharmony_ci		return;
3088c2ecf20Sopenharmony_ci	}
3098c2ecf20Sopenharmony_ci}
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci/*
3138c2ecf20Sopenharmony_ci * XG control effects; still experimental
3148c2ecf20Sopenharmony_ci */
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci/* cutoff: quarter semitone step, max=255 */
3178c2ecf20Sopenharmony_cistatic int xg_cutoff(int val)
3188c2ecf20Sopenharmony_ci{
3198c2ecf20Sopenharmony_ci	return (val - 64) * xg_sense[FX_CUTOFF] / 64;
3208c2ecf20Sopenharmony_ci}
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci/* resonance: 0(open) to 15(most nasal) */
3238c2ecf20Sopenharmony_cistatic int xg_filterQ(int val)
3248c2ecf20Sopenharmony_ci{
3258c2ecf20Sopenharmony_ci	return (val - 64) * xg_sense[FX_RESONANCE] / 64;
3268c2ecf20Sopenharmony_ci}
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci/* attack: */
3298c2ecf20Sopenharmony_cistatic int xg_attack(int val)
3308c2ecf20Sopenharmony_ci{
3318c2ecf20Sopenharmony_ci	return -(val - 64) * xg_sense[FX_ATTACK] / 64;
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci/* release: */
3358c2ecf20Sopenharmony_cistatic int xg_release(int val)
3368c2ecf20Sopenharmony_ci{
3378c2ecf20Sopenharmony_ci	return -(val - 64) * xg_sense[FX_RELEASE] / 64;
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_cistatic const struct nrpn_conv_table xg_effects[] =
3418c2ecf20Sopenharmony_ci{
3428c2ecf20Sopenharmony_ci	{71, EMUX_FX_CUTOFF,	xg_cutoff},
3438c2ecf20Sopenharmony_ci	{74, EMUX_FX_FILTERQ,	xg_filterQ},
3448c2ecf20Sopenharmony_ci	{72, EMUX_FX_ENV2_RELEASE, xg_release},
3458c2ecf20Sopenharmony_ci	{73, EMUX_FX_ENV2_ATTACK, xg_attack},
3468c2ecf20Sopenharmony_ci};
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ciint
3498c2ecf20Sopenharmony_cisnd_emux_xg_control(struct snd_emux_port *port, struct snd_midi_channel *chan,
3508c2ecf20Sopenharmony_ci		    int param)
3518c2ecf20Sopenharmony_ci{
3528c2ecf20Sopenharmony_ci	if (param >= ARRAY_SIZE(chan->control))
3538c2ecf20Sopenharmony_ci		return -EINVAL;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	return send_converted_effect(xg_effects, ARRAY_SIZE(xg_effects),
3568c2ecf20Sopenharmony_ci				     port, chan, param,
3578c2ecf20Sopenharmony_ci				     chan->control[param],
3588c2ecf20Sopenharmony_ci				     EMUX_FX_FLAG_ADD);
3598c2ecf20Sopenharmony_ci}
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci/*
3628c2ecf20Sopenharmony_ci * receive sysex
3638c2ecf20Sopenharmony_ci */
3648c2ecf20Sopenharmony_civoid
3658c2ecf20Sopenharmony_cisnd_emux_sysex(void *p, unsigned char *buf, int len, int parsed,
3668c2ecf20Sopenharmony_ci	       struct snd_midi_channel_set *chset)
3678c2ecf20Sopenharmony_ci{
3688c2ecf20Sopenharmony_ci	struct snd_emux_port *port;
3698c2ecf20Sopenharmony_ci	struct snd_emux *emu;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	port = p;
3728c2ecf20Sopenharmony_ci	if (snd_BUG_ON(!port || !chset))
3738c2ecf20Sopenharmony_ci		return;
3748c2ecf20Sopenharmony_ci	emu = port->emu;
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	switch (parsed) {
3778c2ecf20Sopenharmony_ci	case SNDRV_MIDI_SYSEX_GS_MASTER_VOLUME:
3788c2ecf20Sopenharmony_ci		snd_emux_update_port(port, SNDRV_EMUX_UPDATE_VOLUME);
3798c2ecf20Sopenharmony_ci		break;
3808c2ecf20Sopenharmony_ci	default:
3818c2ecf20Sopenharmony_ci		if (emu->ops.sysex)
3828c2ecf20Sopenharmony_ci			emu->ops.sysex(emu, buf, len, parsed, chset);
3838c2ecf20Sopenharmony_ci		break;
3848c2ecf20Sopenharmony_ci	}
3858c2ecf20Sopenharmony_ci}
3868c2ecf20Sopenharmony_ci
387