2 * ALSA sequencer MIDI-through client
3 * Copyright (c) 1999-2000 by Takashi Iwai <tiwai@suse.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
24 #include <sound/core.h>
25 #include "seq_clientmgr.h"
26 #include <sound/initval.h>
27 #include <sound/asoundef.h>
31 Sequencer MIDI-through client
33 This gives a simple midi-through client. All the normal input events
34 are redirected to output port immediately.
35 The routing can be done via aconnect program in alsa-utils.
37 Each client has a static client number 62 (= SNDRV_SEQ_CLIENT_DUMMY).
38 If you want to auto-load this module, you may add the following alias
39 in your /etc/conf.modules file.
41 alias snd-seq-client-62 snd-seq-dummy
43 The module is loaded on demand for client 62, or /proc/asound/seq/
44 is accessed. If you don't need this module to be loaded, alias
45 snd-seq-client-62 as "off". This will help modprobe.
47 The number of ports to be created can be specified via the module
48 parameter "ports". For example, to create four ports, add the
49 following option in a configuration file under /etc/modprobe.d/:
51 option snd-seq-dummy ports=4
53 The model option "duplex=1" enables duplex operation to the port.
54 In duplex mode, a pair of ports are created instead of single port,
55 and events are tunneled between pair-ports. For example, input to
56 port A is sent to output port of another port B and vice versa.
57 In duplex mode, each port has DUPLEX capability.
62 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
63 MODULE_DESCRIPTION("ALSA sequencer MIDI-through client");
64 MODULE_LICENSE("GPL");
65 MODULE_ALIAS("snd-seq-client-" __stringify(SNDRV_SEQ_CLIENT_DUMMY
));
70 module_param(ports
, int, 0444);
71 MODULE_PARM_DESC(ports
, "number of ports to be created");
72 module_param(duplex
, bool, 0444);
73 MODULE_PARM_DESC(duplex
, "create DUPLEX ports");
75 struct snd_seq_dummy_port
{
82 static int my_client
= -1;
85 * event input callback - just redirect events to subscribers
88 dummy_input(struct snd_seq_event
*ev
, int direct
, void *private_data
,
91 struct snd_seq_dummy_port
*p
;
92 struct snd_seq_event tmpev
;
95 if (ev
->source
.client
== SNDRV_SEQ_CLIENT_SYSTEM
||
96 ev
->type
== SNDRV_SEQ_EVENT_KERNEL_ERROR
)
97 return 0; /* ignore system messages */
100 tmpev
.source
.port
= p
->connect
;
102 tmpev
.source
.port
= p
->port
;
103 tmpev
.dest
.client
= SNDRV_SEQ_ADDRESS_SUBSCRIBERS
;
104 return snd_seq_kernel_client_dispatch(p
->client
, &tmpev
, atomic
, hop
);
108 * free_private callback
111 dummy_free(void *private_data
)
119 static struct snd_seq_dummy_port __init
*
120 create_port(int idx
, int type
)
122 struct snd_seq_port_info pinfo
;
123 struct snd_seq_port_callback pcb
;
124 struct snd_seq_dummy_port
*rec
;
126 if ((rec
= kzalloc(sizeof(*rec
), GFP_KERNEL
)) == NULL
)
129 rec
->client
= my_client
;
130 rec
->duplex
= duplex
;
132 memset(&pinfo
, 0, sizeof(pinfo
));
133 pinfo
.addr
.client
= my_client
;
135 sprintf(pinfo
.name
, "Midi Through Port-%d:%c", idx
,
138 sprintf(pinfo
.name
, "Midi Through Port-%d", idx
);
139 pinfo
.capability
= SNDRV_SEQ_PORT_CAP_READ
| SNDRV_SEQ_PORT_CAP_SUBS_READ
;
140 pinfo
.capability
|= SNDRV_SEQ_PORT_CAP_WRITE
| SNDRV_SEQ_PORT_CAP_SUBS_WRITE
;
142 pinfo
.capability
|= SNDRV_SEQ_PORT_CAP_DUPLEX
;
143 pinfo
.type
= SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC
144 | SNDRV_SEQ_PORT_TYPE_SOFTWARE
145 | SNDRV_SEQ_PORT_TYPE_PORT
;
146 memset(&pcb
, 0, sizeof(pcb
));
147 pcb
.owner
= THIS_MODULE
;
148 pcb
.event_input
= dummy_input
;
149 pcb
.private_free
= dummy_free
;
150 pcb
.private_data
= rec
;
152 if (snd_seq_kernel_client_ctl(my_client
, SNDRV_SEQ_IOCTL_CREATE_PORT
, &pinfo
) < 0) {
156 rec
->port
= pinfo
.addr
.port
;
161 * register client and create ports
164 register_client(void)
166 struct snd_seq_dummy_port
*rec1
, *rec2
;
170 pr_err("ALSA: seq_dummy: invalid number of ports %d\n", ports
);
175 my_client
= snd_seq_create_kernel_client(NULL
, SNDRV_SEQ_CLIENT_DUMMY
,
181 for (i
= 0; i
< ports
; i
++) {
182 rec1
= create_port(i
, 0);
184 snd_seq_delete_kernel_client(my_client
);
188 rec2
= create_port(i
, 1);
190 snd_seq_delete_kernel_client(my_client
);
193 rec1
->connect
= rec2
->port
;
194 rec2
->connect
= rec1
->port
;
202 * delete client if exists
208 snd_seq_delete_kernel_client(my_client
);
215 static int __init
alsa_seq_dummy_init(void)
217 return register_client();
220 static void __exit
alsa_seq_dummy_exit(void)
225 module_init(alsa_seq_dummy_init
)
226 module_exit(alsa_seq_dummy_exit
)