blob: 835edc80f9186fdcdb269fc455f540d8b3f68a76 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * OSS compatible sequencer driver
3 *
4 * synth device handlers
5 *
6 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include "seq_oss_synth.h"
24#include "seq_oss_midi.h"
25#include "../seq_lock.h"
26#include <linux/init.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040027#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30/*
31 * constants
32 */
33#define SNDRV_SEQ_OSS_MAX_SYNTH_NAME 30
34#define MAX_SYSEX_BUFLEN 128
35
36
37/*
38 * definition of synth info records
39 */
40
41/* sysex buffer */
Takashi Iwai080dece2005-11-17 14:05:16 +010042struct seq_oss_synth_sysex {
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 int len;
44 int skip;
45 unsigned char buf[MAX_SYSEX_BUFLEN];
46};
47
48/* synth info */
Takashi Iwai080dece2005-11-17 14:05:16 +010049struct seq_oss_synth {
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 int seq_device;
51
52 /* for synth_info */
53 int synth_type;
54 int synth_subtype;
55 int nr_voices;
56
57 char name[SNDRV_SEQ_OSS_MAX_SYNTH_NAME];
Takashi Iwai080dece2005-11-17 14:05:16 +010058 struct snd_seq_oss_callback oper;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 int opened;
61
62 void *private_data;
63 snd_use_lock_t use_lock;
64};
65
66
67/*
68 * device table
69 */
70static int max_synth_devs;
Takashi Iwai080dece2005-11-17 14:05:16 +010071static struct seq_oss_synth *synth_devs[SNDRV_SEQ_OSS_MAX_SYNTH_DEVS];
72static struct seq_oss_synth midi_synth_dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 -1, /* seq_device */
74 SYNTH_TYPE_MIDI, /* synth_type */
75 0, /* synth_subtype */
76 16, /* nr_voices */
77 "MIDI", /* name */
78};
79
80static DEFINE_SPINLOCK(register_lock);
81
82/*
83 * prototypes
84 */
Takashi Iwai080dece2005-11-17 14:05:16 +010085static struct seq_oss_synth *get_synthdev(struct seq_oss_devinfo *dp, int dev);
86static void reset_channels(struct seq_oss_synthinfo *info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88/*
89 * global initialization
90 */
91void __init
92snd_seq_oss_synth_init(void)
93{
94 snd_use_lock_init(&midi_synth_dev.use_lock);
95}
96
97/*
98 * registration of the synth device
99 */
100int
Takashi Iwai05662202015-02-12 13:43:22 +0100101snd_seq_oss_synth_probe(struct device *_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
Takashi Iwai05662202015-02-12 13:43:22 +0100103 struct snd_seq_device *dev = to_seq_dev(_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 int i;
Takashi Iwai080dece2005-11-17 14:05:16 +0100105 struct seq_oss_synth *rec;
106 struct snd_seq_oss_reg *reg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 unsigned long flags;
108
Takashi Iwaiecca82b2005-09-09 14:20:49 +0200109 if ((rec = kzalloc(sizeof(*rec), GFP_KERNEL)) == NULL) {
Takashi Iwaibb343e72014-02-04 18:24:04 +0100110 pr_err("ALSA: seq_oss: can't malloc synth info\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 return -ENOMEM;
112 }
113 rec->seq_device = -1;
114 rec->synth_type = reg->type;
115 rec->synth_subtype = reg->subtype;
116 rec->nr_voices = reg->nvoices;
117 rec->oper = reg->oper;
118 rec->private_data = reg->private_data;
119 rec->opened = 0;
120 snd_use_lock_init(&rec->use_lock);
121
122 /* copy and truncate the name of synth device */
123 strlcpy(rec->name, dev->name, sizeof(rec->name));
124
125 /* registration */
126 spin_lock_irqsave(&register_lock, flags);
127 for (i = 0; i < max_synth_devs; i++) {
128 if (synth_devs[i] == NULL)
129 break;
130 }
131 if (i >= max_synth_devs) {
132 if (max_synth_devs >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS) {
133 spin_unlock_irqrestore(&register_lock, flags);
Takashi Iwaibb343e72014-02-04 18:24:04 +0100134 pr_err("ALSA: seq_oss: no more synth slot\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 kfree(rec);
136 return -ENOMEM;
137 }
138 max_synth_devs++;
139 }
140 rec->seq_device = i;
141 synth_devs[i] = rec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 spin_unlock_irqrestore(&register_lock, flags);
143 dev->driver_data = rec;
144#ifdef SNDRV_OSS_INFO_DEV_SYNTH
145 if (i < SNDRV_CARDS)
146 snd_oss_info_register(SNDRV_OSS_INFO_DEV_SYNTH, i, rec->name);
147#endif
148 return 0;
149}
150
151
152int
Takashi Iwai05662202015-02-12 13:43:22 +0100153snd_seq_oss_synth_remove(struct device *_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Takashi Iwai05662202015-02-12 13:43:22 +0100155 struct snd_seq_device *dev = to_seq_dev(_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 int index;
Takashi Iwai080dece2005-11-17 14:05:16 +0100157 struct seq_oss_synth *rec = dev->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 unsigned long flags;
159
160 spin_lock_irqsave(&register_lock, flags);
161 for (index = 0; index < max_synth_devs; index++) {
162 if (synth_devs[index] == rec)
163 break;
164 }
165 if (index >= max_synth_devs) {
166 spin_unlock_irqrestore(&register_lock, flags);
Takashi Iwaibb343e72014-02-04 18:24:04 +0100167 pr_err("ALSA: seq_oss: can't unregister synth\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return -EINVAL;
169 }
170 synth_devs[index] = NULL;
171 if (index == max_synth_devs - 1) {
172 for (index--; index >= 0; index--) {
173 if (synth_devs[index])
174 break;
175 }
176 max_synth_devs = index + 1;
177 }
178 spin_unlock_irqrestore(&register_lock, flags);
179#ifdef SNDRV_OSS_INFO_DEV_SYNTH
180 if (rec->seq_device < SNDRV_CARDS)
181 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_SYNTH, rec->seq_device);
182#endif
183
184 snd_use_lock_sync(&rec->use_lock);
185 kfree(rec);
186
187 return 0;
188}
189
190
191/*
192 */
Takashi Iwai080dece2005-11-17 14:05:16 +0100193static struct seq_oss_synth *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194get_sdev(int dev)
195{
Takashi Iwai080dece2005-11-17 14:05:16 +0100196 struct seq_oss_synth *rec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 unsigned long flags;
198
199 spin_lock_irqsave(&register_lock, flags);
200 rec = synth_devs[dev];
201 if (rec)
202 snd_use_lock_use(&rec->use_lock);
203 spin_unlock_irqrestore(&register_lock, flags);
204 return rec;
205}
206
207
208/*
209 * set up synth tables
210 */
211
212void
Takashi Iwai080dece2005-11-17 14:05:16 +0100213snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
215 int i;
Takashi Iwai080dece2005-11-17 14:05:16 +0100216 struct seq_oss_synth *rec;
217 struct seq_oss_synthinfo *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 dp->max_synthdev = max_synth_devs;
220 dp->synth_opened = 0;
221 memset(dp->synths, 0, sizeof(dp->synths));
222 for (i = 0; i < dp->max_synthdev; i++) {
223 rec = get_sdev(i);
224 if (rec == NULL)
225 continue;
226 if (rec->oper.open == NULL || rec->oper.close == NULL) {
227 snd_use_lock_free(&rec->use_lock);
228 continue;
229 }
230 info = &dp->synths[i];
231 info->arg.app_index = dp->port;
232 info->arg.file_mode = dp->file_mode;
233 info->arg.seq_mode = dp->seq_mode;
234 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_SYNTH)
235 info->arg.event_passing = SNDRV_SEQ_OSS_PROCESS_EVENTS;
236 else
237 info->arg.event_passing = SNDRV_SEQ_OSS_PASS_EVENTS;
238 info->opened = 0;
239 if (!try_module_get(rec->oper.owner)) {
240 snd_use_lock_free(&rec->use_lock);
241 continue;
242 }
243 if (rec->oper.open(&info->arg, rec->private_data) < 0) {
244 module_put(rec->oper.owner);
245 snd_use_lock_free(&rec->use_lock);
246 continue;
247 }
248 info->nr_voices = rec->nr_voices;
249 if (info->nr_voices > 0) {
Takashi Iwai080dece2005-11-17 14:05:16 +0100250 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL);
Takashi Iwaic354cd72008-02-21 12:40:00 +0100251 if (!info->ch) {
Takashi Iwaibb343e72014-02-04 18:24:04 +0100252 pr_err("ALSA: seq_oss: Cannot malloc voices\n");
Takashi Iwaic354cd72008-02-21 12:40:00 +0100253 rec->oper.close(&info->arg);
254 module_put(rec->oper.owner);
255 snd_use_lock_free(&rec->use_lock);
256 continue;
257 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 reset_channels(info);
259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 info->opened++;
261 rec->opened++;
262 dp->synth_opened++;
263 snd_use_lock_free(&rec->use_lock);
264 }
265}
266
267
268/*
269 * set up synth tables for MIDI emulation - /dev/music mode only
270 */
271
272void
Takashi Iwai080dece2005-11-17 14:05:16 +0100273snd_seq_oss_synth_setup_midi(struct seq_oss_devinfo *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
275 int i;
276
277 if (dp->max_synthdev >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS)
278 return;
279
280 for (i = 0; i < dp->max_mididev; i++) {
Takashi Iwai080dece2005-11-17 14:05:16 +0100281 struct seq_oss_synthinfo *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 info = &dp->synths[dp->max_synthdev];
283 if (snd_seq_oss_midi_open(dp, i, dp->file_mode) < 0)
284 continue;
285 info->arg.app_index = dp->port;
286 info->arg.file_mode = dp->file_mode;
287 info->arg.seq_mode = dp->seq_mode;
288 info->arg.private_data = info;
289 info->is_midi = 1;
290 info->midi_mapped = i;
291 info->arg.event_passing = SNDRV_SEQ_OSS_PASS_EVENTS;
292 snd_seq_oss_midi_get_addr(dp, i, &info->arg.addr);
293 info->opened = 1;
294 midi_synth_dev.opened++;
295 dp->max_synthdev++;
296 if (dp->max_synthdev >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS)
297 break;
298 }
299}
300
301
302/*
303 * clean up synth tables
304 */
305
306void
Takashi Iwai080dece2005-11-17 14:05:16 +0100307snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
309 int i;
Takashi Iwai080dece2005-11-17 14:05:16 +0100310 struct seq_oss_synth *rec;
311 struct seq_oss_synthinfo *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200313 if (snd_BUG_ON(dp->max_synthdev >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS))
314 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 for (i = 0; i < dp->max_synthdev; i++) {
316 info = &dp->synths[i];
317 if (! info->opened)
318 continue;
319 if (info->is_midi) {
320 if (midi_synth_dev.opened > 0) {
321 snd_seq_oss_midi_close(dp, info->midi_mapped);
322 midi_synth_dev.opened--;
323 }
324 } else {
325 rec = get_sdev(i);
326 if (rec == NULL)
327 continue;
328 if (rec->opened > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 rec->oper.close(&info->arg);
330 module_put(rec->oper.owner);
331 rec->opened = 0;
332 }
333 snd_use_lock_free(&rec->use_lock);
334 }
Jesper Juhl4d572772005-05-30 17:30:32 +0200335 kfree(info->sysex);
336 info->sysex = NULL;
337 kfree(info->ch);
338 info->ch = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 }
340 dp->synth_opened = 0;
341 dp->max_synthdev = 0;
342}
343
344/*
345 * check if the specified device is MIDI mapped device
346 */
347static int
Takashi Iwai080dece2005-11-17 14:05:16 +0100348is_midi_dev(struct seq_oss_devinfo *dp, int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
350 if (dev < 0 || dev >= dp->max_synthdev)
351 return 0;
352 if (dp->synths[dev].is_midi)
353 return 1;
354 return 0;
355}
356
357/*
358 * return synth device information pointer
359 */
Takashi Iwai080dece2005-11-17 14:05:16 +0100360static struct seq_oss_synth *
361get_synthdev(struct seq_oss_devinfo *dp, int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Takashi Iwai080dece2005-11-17 14:05:16 +0100363 struct seq_oss_synth *rec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 if (dev < 0 || dev >= dp->max_synthdev)
365 return NULL;
366 if (! dp->synths[dev].opened)
367 return NULL;
368 if (dp->synths[dev].is_midi)
369 return &midi_synth_dev;
370 if ((rec = get_sdev(dev)) == NULL)
371 return NULL;
372 if (! rec->opened) {
373 snd_use_lock_free(&rec->use_lock);
374 return NULL;
375 }
376 return rec;
377}
378
379
380/*
381 * reset note and velocity on each channel.
382 */
383static void
Takashi Iwai080dece2005-11-17 14:05:16 +0100384reset_channels(struct seq_oss_synthinfo *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
386 int i;
387 if (info->ch == NULL || ! info->nr_voices)
388 return;
389 for (i = 0; i < info->nr_voices; i++) {
390 info->ch[i].note = -1;
391 info->ch[i].vel = 0;
392 }
393}
394
395
396/*
397 * reset synth device:
398 * call reset callback. if no callback is defined, send a heartbeat
399 * event to the corresponding port.
400 */
401void
Takashi Iwai080dece2005-11-17 14:05:16 +0100402snd_seq_oss_synth_reset(struct seq_oss_devinfo *dp, int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Takashi Iwai080dece2005-11-17 14:05:16 +0100404 struct seq_oss_synth *rec;
405 struct seq_oss_synthinfo *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200407 if (snd_BUG_ON(dev < 0 || dev >= dp->max_synthdev))
408 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 info = &dp->synths[dev];
410 if (! info->opened)
411 return;
412 if (info->sysex)
413 info->sysex->len = 0; /* reset sysex */
414 reset_channels(info);
415 if (info->is_midi) {
416 if (midi_synth_dev.opened <= 0)
417 return;
418 snd_seq_oss_midi_reset(dp, info->midi_mapped);
419 /* reopen the device */
420 snd_seq_oss_midi_close(dp, dev);
421 if (snd_seq_oss_midi_open(dp, info->midi_mapped,
422 dp->file_mode) < 0) {
423 midi_synth_dev.opened--;
424 info->opened = 0;
Jesper Juhl4d572772005-05-30 17:30:32 +0200425 kfree(info->sysex);
426 info->sysex = NULL;
427 kfree(info->ch);
428 info->ch = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
430 return;
431 }
432
433 rec = get_sdev(dev);
434 if (rec == NULL)
435 return;
436 if (rec->oper.reset) {
437 rec->oper.reset(&info->arg);
438 } else {
Takashi Iwai080dece2005-11-17 14:05:16 +0100439 struct snd_seq_event ev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 memset(&ev, 0, sizeof(ev));
441 snd_seq_oss_fill_addr(dp, &ev, info->arg.addr.client,
442 info->arg.addr.port);
443 ev.type = SNDRV_SEQ_EVENT_RESET;
444 snd_seq_oss_dispatch(dp, &ev, 0, 0);
445 }
446 snd_use_lock_free(&rec->use_lock);
447}
448
449
450/*
451 * load a patch record:
452 * call load_patch callback function
453 */
454int
Takashi Iwai080dece2005-11-17 14:05:16 +0100455snd_seq_oss_synth_load_patch(struct seq_oss_devinfo *dp, int dev, int fmt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 const char __user *buf, int p, int c)
457{
Takashi Iwai080dece2005-11-17 14:05:16 +0100458 struct seq_oss_synth *rec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 int rc;
460
461 if (dev < 0 || dev >= dp->max_synthdev)
462 return -ENXIO;
463
464 if (is_midi_dev(dp, dev))
465 return 0;
466 if ((rec = get_synthdev(dp, dev)) == NULL)
467 return -ENXIO;
468
469 if (rec->oper.load_patch == NULL)
470 rc = -ENXIO;
471 else
472 rc = rec->oper.load_patch(&dp->synths[dev].arg, fmt, buf, p, c);
473 snd_use_lock_free(&rec->use_lock);
474 return rc;
475}
476
477/*
478 * check if the device is valid synth device
479 */
480int
Takashi Iwai080dece2005-11-17 14:05:16 +0100481snd_seq_oss_synth_is_valid(struct seq_oss_devinfo *dp, int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Takashi Iwai080dece2005-11-17 14:05:16 +0100483 struct seq_oss_synth *rec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 rec = get_synthdev(dp, dev);
485 if (rec) {
486 snd_use_lock_free(&rec->use_lock);
487 return 1;
488 }
489 return 0;
490}
491
492
493/*
494 * receive OSS 6 byte sysex packet:
495 * the full sysex message will be sent if it reaches to the end of data
496 * (0xff).
497 */
498int
Takashi Iwai080dece2005-11-17 14:05:16 +0100499snd_seq_oss_synth_sysex(struct seq_oss_devinfo *dp, int dev, unsigned char *buf, struct snd_seq_event *ev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
501 int i, send;
502 unsigned char *dest;
Takashi Iwai080dece2005-11-17 14:05:16 +0100503 struct seq_oss_synth_sysex *sysex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 if (! snd_seq_oss_synth_is_valid(dp, dev))
506 return -ENXIO;
507
508 sysex = dp->synths[dev].sysex;
509 if (sysex == NULL) {
Takashi Iwaiecca82b2005-09-09 14:20:49 +0200510 sysex = kzalloc(sizeof(*sysex), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 if (sysex == NULL)
512 return -ENOMEM;
513 dp->synths[dev].sysex = sysex;
514 }
515
516 send = 0;
517 dest = sysex->buf + sysex->len;
518 /* copy 6 byte packet to the buffer */
519 for (i = 0; i < 6; i++) {
520 if (buf[i] == 0xff) {
521 send = 1;
522 break;
523 }
524 dest[i] = buf[i];
525 sysex->len++;
526 if (sysex->len >= MAX_SYSEX_BUFLEN) {
527 sysex->len = 0;
528 sysex->skip = 1;
529 break;
530 }
531 }
532
533 if (sysex->len && send) {
534 if (sysex->skip) {
535 sysex->skip = 0;
536 sysex->len = 0;
537 return -EINVAL; /* skip */
538 }
539 /* copy the data to event record and send it */
540 ev->flags = SNDRV_SEQ_EVENT_LENGTH_VARIABLE;
541 if (snd_seq_oss_synth_addr(dp, dev, ev))
542 return -EINVAL;
543 ev->data.ext.len = sysex->len;
544 ev->data.ext.ptr = sysex->buf;
545 sysex->len = 0;
546 return 0;
547 }
548
549 return -EINVAL; /* skip */
550}
551
552/*
553 * fill the event source/destination addresses
554 */
555int
Takashi Iwai080dece2005-11-17 14:05:16 +0100556snd_seq_oss_synth_addr(struct seq_oss_devinfo *dp, int dev, struct snd_seq_event *ev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
558 if (! snd_seq_oss_synth_is_valid(dp, dev))
559 return -EINVAL;
560 snd_seq_oss_fill_addr(dp, ev, dp->synths[dev].arg.addr.client,
561 dp->synths[dev].arg.addr.port);
562 return 0;
563}
564
565
566/*
567 * OSS compatible ioctl
568 */
569int
Takashi Iwai080dece2005-11-17 14:05:16 +0100570snd_seq_oss_synth_ioctl(struct seq_oss_devinfo *dp, int dev, unsigned int cmd, unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
Takashi Iwai080dece2005-11-17 14:05:16 +0100572 struct seq_oss_synth *rec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 int rc;
574
575 if (is_midi_dev(dp, dev))
576 return -ENXIO;
577 if ((rec = get_synthdev(dp, dev)) == NULL)
578 return -ENXIO;
579 if (rec->oper.ioctl == NULL)
580 rc = -ENXIO;
581 else
582 rc = rec->oper.ioctl(&dp->synths[dev].arg, cmd, addr);
583 snd_use_lock_free(&rec->use_lock);
584 return rc;
585}
586
587
588/*
589 * send OSS raw events - SEQ_PRIVATE and SEQ_VOLUME
590 */
591int
Takashi Iwai080dece2005-11-17 14:05:16 +0100592snd_seq_oss_synth_raw_event(struct seq_oss_devinfo *dp, int dev, unsigned char *data, struct snd_seq_event *ev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
594 if (! snd_seq_oss_synth_is_valid(dp, dev) || is_midi_dev(dp, dev))
595 return -ENXIO;
596 ev->type = SNDRV_SEQ_EVENT_OSS;
597 memcpy(ev->data.raw8.d, data, 8);
598 return snd_seq_oss_synth_addr(dp, dev, ev);
599}
600
601
602/*
603 * create OSS compatible synth_info record
604 */
605int
Takashi Iwai080dece2005-11-17 14:05:16 +0100606snd_seq_oss_synth_make_info(struct seq_oss_devinfo *dp, int dev, struct synth_info *inf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
Takashi Iwai080dece2005-11-17 14:05:16 +0100608 struct seq_oss_synth *rec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Willy Tarreau82e68f72008-08-02 18:25:16 +0200610 if (dev < 0 || dev >= dp->max_synthdev)
611 return -ENXIO;
612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 if (dp->synths[dev].is_midi) {
614 struct midi_info minf;
615 snd_seq_oss_midi_make_info(dp, dp->synths[dev].midi_mapped, &minf);
616 inf->synth_type = SYNTH_TYPE_MIDI;
617 inf->synth_subtype = 0;
618 inf->nr_voices = 16;
619 inf->device = dev;
620 strlcpy(inf->name, minf.name, sizeof(inf->name));
621 } else {
622 if ((rec = get_synthdev(dp, dev)) == NULL)
623 return -ENXIO;
624 inf->synth_type = rec->synth_type;
625 inf->synth_subtype = rec->synth_subtype;
626 inf->nr_voices = rec->nr_voices;
627 inf->device = dev;
628 strlcpy(inf->name, rec->name, sizeof(inf->name));
629 snd_use_lock_free(&rec->use_lock);
630 }
631 return 0;
632}
633
634
Takashi Iwai04f141a2005-12-01 10:43:51 +0100635#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636/*
637 * proc interface
638 */
639void
Takashi Iwai080dece2005-11-17 14:05:16 +0100640snd_seq_oss_synth_info_read(struct snd_info_buffer *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
642 int i;
Takashi Iwai080dece2005-11-17 14:05:16 +0100643 struct seq_oss_synth *rec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 snd_iprintf(buf, "\nNumber of synth devices: %d\n", max_synth_devs);
646 for (i = 0; i < max_synth_devs; i++) {
647 snd_iprintf(buf, "\nsynth %d: ", i);
648 rec = get_sdev(i);
649 if (rec == NULL) {
650 snd_iprintf(buf, "*empty*\n");
651 continue;
652 }
653 snd_iprintf(buf, "[%s]\n", rec->name);
654 snd_iprintf(buf, " type 0x%x : subtype 0x%x : voices %d\n",
655 rec->synth_type, rec->synth_subtype,
656 rec->nr_voices);
657 snd_iprintf(buf, " capabilities : ioctl %s / load_patch %s\n",
658 enabled_str((long)rec->oper.ioctl),
659 enabled_str((long)rec->oper.load_patch));
660 snd_use_lock_free(&rec->use_lock);
661 }
662}
Takashi Iwai04f141a2005-12-01 10:43:51 +0100663#endif /* CONFIG_PROC_FS */