source: GPL/alsa-kernel/drivers/virmidi.c@ 1

Last change on this file since 1 was 1, checked in by vladest, 20 years ago

initial import

File size: 6.1 KB
Line 
1/*
2 * Dummy soundcard for virtual rawmidi devices
3 *
4 * Copyright (c) 2000 by Takashi Iwai <tiwai@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22/*
23 * VIRTUAL RAW MIDI DEVICE CARDS
24 *
25 * This dummy card contains up to 4 virtual rawmidi devices.
26 * They are not real rawmidi devices but just associated with sequencer
27 * clients, so that any input/output sources can be connected as a raw
28 * MIDI device arbitrary.
29 * Also, multiple access is allowed to a single rawmidi device.
30 *
31 * Typical usage is like following:
32 * - Load snd-card-virmidi module.
33 * # modprobe snd-card-virmidi snd_index=2
34 * Then, sequencer clients 72:0 to 75:0 will be created, which are
35 * mapped from /dev/snd/midiC1D0 to /dev/snd/midiC1D3, respectively.
36 *
37 * - Connect input/output via aconnect.
38 * % aconnect 64:0 72:0 # keyboard input redirection 64:0 -> 72:0
39 * % aconnect 72:0 65:0 # output device redirection 72:0 -> 65:0
40 *
41 * - Run application using a midi device (eg. /dev/snd/midiC1D0)
42 */
43
44#define SNDRV_MAIN_OBJECT_FILE
45#include <sound/driver.h>
46#include <sound/seq_kernel.h>
47#include <sound/seq_virmidi.h>
48#define SNDRV_GET_ID
49#include <sound/initval.h>
50
51EXPORT_NO_SYMBOLS;
52MODULE_DESCRIPTION("Dummy soundcard for virtual rawmidi devices");
53MODULE_CLASSES("{sound}");
54MODULE_DEVICES("{{ALSA,Virtual rawmidi device}}");
55
56#define MAX_MIDI_DEVICES 8
57
58static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
59static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
60#ifdef TARGET_OS2
61static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
62static int snd_midi_devs[SNDRV_CARDS] = SNDDRV_DEFAULT_MIDI_DEVS
63#else
64 static int snd_enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
65static int snd_midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4};
66#endif
67
68MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
69MODULE_PARM_DESC(snd_index, "Index value for virmidi soundcard.");
70MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
71MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
72MODULE_PARM_DESC(snd_id, "ID string for virmidi soundcard.");
73MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
74MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
75MODULE_PARM_DESC(snd_enable, "Enable this soundcard.");
76MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
77MODULE_PARM(snd_midi_devs, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
78MODULE_PARM_DESC(snd_midi_devs, "MIDI devices # (1-8)");
79MODULE_PARM_SYNTAX(snd_midi_devs, SNDRV_ENABLED ",allows:{{1,8}}");
80
81typedef struct snd_card_virmidi {
82 snd_card_t *card;
83 snd_rawmidi_t *midi[MAX_MIDI_DEVICES];
84} snd_card_virmidi_t;
85
86static snd_card_t *snd_virmidi_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
87
88
89static int __init snd_card_virmidi_probe(int dev)
90{
91 snd_card_t *card;
92 struct snd_card_virmidi *vmidi;
93 int idx, err;
94
95 if (!snd_enable[dev])
96 return -ENODEV;
97 card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE,
98 sizeof(struct snd_card_virmidi));
99 if (card == NULL)
100 return -ENOMEM;
101 vmidi = (struct snd_card_virmidi *)card->private_data;
102 vmidi->card = card;
103
104 if (snd_midi_devs[dev] > MAX_MIDI_DEVICES) {
105 snd_printk("too much midi devices for virmidi %d: force to use %d\n", dev, MAX_MIDI_DEVICES);
106 snd_midi_devs[dev] = MAX_MIDI_DEVICES;
107 }
108 for (idx = 0; idx < snd_midi_devs[dev]; idx++) {
109 snd_rawmidi_t *rmidi;
110 snd_virmidi_dev_t *rdev;
111 if ((err = snd_virmidi_new(card, idx, &rmidi)) < 0)
112 goto __nodev;
113 rdev = rmidi->private_data;
114 vmidi->midi[idx] = rmidi;
115 strcpy(rmidi->name, "Virtual Raw MIDI");
116 rdev->seq_mode = SNDRV_VIRMIDI_SEQ_DISPATCH;
117 }
118
119 strcpy(card->driver, "VirMIDI");
120 strcpy(card->shortname, "VirMIDI");
121 sprintf(card->longname, "Virtual MIDI Card %i", dev + 1);
122 if ((err = snd_card_register(card)) == 0) {
123 snd_virmidi_cards[dev] = card;
124 return 0;
125 }
126__nodev:
127 snd_card_free(card);
128 return err;
129}
130
131static int __init alsa_card_virmidi_init(void)
132{
133 int dev, cards;
134
135 for (dev = cards = 0; dev < SNDRV_CARDS && snd_enable[dev]; dev++) {
136 if (snd_card_virmidi_probe(dev) < 0) {
137#ifdef MODULE
138 snd_printk("Card-VirMIDI #%i not found or device busy\n", dev + 1);
139#endif
140 break;
141 }
142 cards++;
143 }
144 if (!cards) {
145#ifdef MODULE
146 snd_printk("Card-VirMIDI soundcard not found or device busy\n");
147#endif
148 return -ENODEV;
149 }
150 return 0;
151}
152
153static void __exit alsa_card_virmidi_exit(void)
154{
155 int dev;
156
157 for (dev = 0; dev < SNDRV_CARDS; dev++)
158 snd_card_free(snd_virmidi_cards[dev]);
159}
160
161module_init(alsa_card_virmidi_init)
162module_exit(alsa_card_virmidi_exit)
163
164#ifndef MODULE
165
166/* format is: snd-card-virmidi=snd_enable,snd_index,snd_id,snd_midi_devs */
167
168static int __init alsa_card_virmidi_setup(char *str)
169{
170 static unsigned __initdata nr_dev = 0;
171
172 if (nr_dev >= SNDRV_CARDS)
173 return 0;
174 (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
175 get_option(&str,&snd_index[nr_dev]) == 2 &&
176 get_id(&str,&snd_id[nr_dev]) == 2 &&
177 get_option(&str,&snd_midi_devs[nr_dev]) == 2);
178 nr_dev++;
179 return 1;
180}
181
182__setup("snd-card-virmidi=", alsa_card_virmidi_setup);
183
184#endif /* ifndef MODULE */
Note: See TracBrowser for help on using the repository browser.