GNU Linux-libre 4.19.286-gnu1
[releases.git] / sound / core / seq / oss / seq_oss_midi.c
1 /*
2  * OSS compatible sequencer driver
3  *
4  * MIDI 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 <sound/asoundef.h>
24 #include "seq_oss_midi.h"
25 #include "seq_oss_readq.h"
26 #include "seq_oss_timer.h"
27 #include "seq_oss_event.h"
28 #include <sound/seq_midi_event.h>
29 #include "../seq_lock.h"
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/nospec.h>
33
34
35 /*
36  * constants
37  */
38 #define SNDRV_SEQ_OSS_MAX_MIDI_NAME     30
39
40 /*
41  * definition of midi device record
42  */
43 struct seq_oss_midi {
44         int seq_device;         /* device number */
45         int client;             /* sequencer client number */
46         int port;               /* sequencer port number */
47         unsigned int flags;     /* port capability */
48         int opened;             /* flag for opening */
49         unsigned char name[SNDRV_SEQ_OSS_MAX_MIDI_NAME];
50         struct snd_midi_event *coder;   /* MIDI event coder */
51         struct seq_oss_devinfo *devinfo;        /* assigned OSSseq device */
52         snd_use_lock_t use_lock;
53 };
54
55
56 /*
57  * midi device table
58  */
59 static int max_midi_devs;
60 static struct seq_oss_midi *midi_devs[SNDRV_SEQ_OSS_MAX_MIDI_DEVS];
61
62 static DEFINE_SPINLOCK(register_lock);
63
64 /*
65  * prototypes
66  */
67 static struct seq_oss_midi *get_mdev(int dev);
68 static struct seq_oss_midi *get_mididev(struct seq_oss_devinfo *dp, int dev);
69 static int send_synth_event(struct seq_oss_devinfo *dp, struct snd_seq_event *ev, int dev);
70 static int send_midi_event(struct seq_oss_devinfo *dp, struct snd_seq_event *ev, struct seq_oss_midi *mdev);
71
72 /*
73  * look up the existing ports
74  * this looks a very exhausting job.
75  */
76 int
77 snd_seq_oss_midi_lookup_ports(int client)
78 {
79         struct snd_seq_client_info *clinfo;
80         struct snd_seq_port_info *pinfo;
81
82         clinfo = kzalloc(sizeof(*clinfo), GFP_KERNEL);
83         pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL);
84         if (! clinfo || ! pinfo) {
85                 kfree(clinfo);
86                 kfree(pinfo);
87                 return -ENOMEM;
88         }
89         clinfo->client = -1;
90         while (snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT, clinfo) == 0) {
91                 if (clinfo->client == client)
92                         continue; /* ignore myself */
93                 pinfo->addr.client = clinfo->client;
94                 pinfo->addr.port = -1;
95                 while (snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, pinfo) == 0)
96                         snd_seq_oss_midi_check_new_port(pinfo);
97         }
98         kfree(clinfo);
99         kfree(pinfo);
100         return 0;
101 }
102
103
104 /*
105  */
106 static struct seq_oss_midi *
107 get_mdev(int dev)
108 {
109         struct seq_oss_midi *mdev;
110         unsigned long flags;
111
112         spin_lock_irqsave(&register_lock, flags);
113         mdev = midi_devs[dev];
114         if (mdev)
115                 snd_use_lock_use(&mdev->use_lock);
116         spin_unlock_irqrestore(&register_lock, flags);
117         return mdev;
118 }
119
120 /*
121  * look for the identical slot
122  */
123 static struct seq_oss_midi *
124 find_slot(int client, int port)
125 {
126         int i;
127         struct seq_oss_midi *mdev;
128         unsigned long flags;
129
130         spin_lock_irqsave(&register_lock, flags);
131         for (i = 0; i < max_midi_devs; i++) {
132                 mdev = midi_devs[i];
133                 if (mdev && mdev->client == client && mdev->port == port) {
134                         /* found! */
135                         snd_use_lock_use(&mdev->use_lock);
136                         spin_unlock_irqrestore(&register_lock, flags);
137                         return mdev;
138                 }
139         }
140         spin_unlock_irqrestore(&register_lock, flags);
141         return NULL;
142 }
143
144
145 #define PERM_WRITE (SNDRV_SEQ_PORT_CAP_WRITE|SNDRV_SEQ_PORT_CAP_SUBS_WRITE)
146 #define PERM_READ (SNDRV_SEQ_PORT_CAP_READ|SNDRV_SEQ_PORT_CAP_SUBS_READ)
147 /*
148  * register a new port if it doesn't exist yet
149  */
150 int
151 snd_seq_oss_midi_check_new_port(struct snd_seq_port_info *pinfo)
152 {
153         int i;
154         struct seq_oss_midi *mdev;
155         unsigned long flags;
156
157         /* the port must include generic midi */
158         if (! (pinfo->type & SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC))
159                 return 0;
160         /* either read or write subscribable */
161         if ((pinfo->capability & PERM_WRITE) != PERM_WRITE &&
162             (pinfo->capability & PERM_READ) != PERM_READ)
163                 return 0;
164
165         /*
166          * look for the identical slot
167          */
168         if ((mdev = find_slot(pinfo->addr.client, pinfo->addr.port)) != NULL) {
169                 /* already exists */
170                 snd_use_lock_free(&mdev->use_lock);
171                 return 0;
172         }
173
174         /*
175          * allocate midi info record
176          */
177         mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
178         if (!mdev)
179                 return -ENOMEM;
180
181         /* copy the port information */
182         mdev->client = pinfo->addr.client;
183         mdev->port = pinfo->addr.port;
184         mdev->flags = pinfo->capability;
185         mdev->opened = 0;
186         snd_use_lock_init(&mdev->use_lock);
187
188         /* copy and truncate the name of synth device */
189         strlcpy(mdev->name, pinfo->name, sizeof(mdev->name));
190
191         /* create MIDI coder */
192         if (snd_midi_event_new(MAX_MIDI_EVENT_BUF, &mdev->coder) < 0) {
193                 pr_err("ALSA: seq_oss: can't malloc midi coder\n");
194                 kfree(mdev);
195                 return -ENOMEM;
196         }
197         /* OSS sequencer adds running status to all sequences */
198         snd_midi_event_no_status(mdev->coder, 1);
199
200         /*
201          * look for en empty slot
202          */
203         spin_lock_irqsave(&register_lock, flags);
204         for (i = 0; i < max_midi_devs; i++) {
205                 if (midi_devs[i] == NULL)
206                         break;
207         }
208         if (i >= max_midi_devs) {
209                 if (max_midi_devs >= SNDRV_SEQ_OSS_MAX_MIDI_DEVS) {
210                         spin_unlock_irqrestore(&register_lock, flags);
211                         snd_midi_event_free(mdev->coder);
212                         kfree(mdev);
213                         return -ENOMEM;
214                 }
215                 max_midi_devs++;
216         }
217         mdev->seq_device = i;
218         midi_devs[mdev->seq_device] = mdev;
219         spin_unlock_irqrestore(&register_lock, flags);
220
221         return 0;
222 }
223
224 /*
225  * release the midi device if it was registered
226  */
227 int
228 snd_seq_oss_midi_check_exit_port(int client, int port)
229 {
230         struct seq_oss_midi *mdev;
231         unsigned long flags;
232         int index;
233
234         if ((mdev = find_slot(client, port)) != NULL) {
235                 spin_lock_irqsave(&register_lock, flags);
236                 midi_devs[mdev->seq_device] = NULL;
237                 spin_unlock_irqrestore(&register_lock, flags);
238                 snd_use_lock_free(&mdev->use_lock);
239                 snd_use_lock_sync(&mdev->use_lock);
240                 snd_midi_event_free(mdev->coder);
241                 kfree(mdev);
242         }
243         spin_lock_irqsave(&register_lock, flags);
244         for (index = max_midi_devs - 1; index >= 0; index--) {
245                 if (midi_devs[index])
246                         break;
247         }
248         max_midi_devs = index + 1;
249         spin_unlock_irqrestore(&register_lock, flags);
250         return 0;
251 }
252
253
254 /*
255  * release the midi device if it was registered
256  */
257 void
258 snd_seq_oss_midi_clear_all(void)
259 {
260         int i;
261         struct seq_oss_midi *mdev;
262         unsigned long flags;
263
264         spin_lock_irqsave(&register_lock, flags);
265         for (i = 0; i < max_midi_devs; i++) {
266                 if ((mdev = midi_devs[i]) != NULL) {
267                         snd_midi_event_free(mdev->coder);
268                         kfree(mdev);
269                         midi_devs[i] = NULL;
270                 }
271         }
272         max_midi_devs = 0;
273         spin_unlock_irqrestore(&register_lock, flags);
274 }
275
276
277 /*
278  * set up midi tables
279  */
280 void
281 snd_seq_oss_midi_setup(struct seq_oss_devinfo *dp)
282 {
283         spin_lock_irq(&register_lock);
284         dp->max_mididev = max_midi_devs;
285         spin_unlock_irq(&register_lock);
286 }
287
288 /*
289  * clean up midi tables
290  */
291 void
292 snd_seq_oss_midi_cleanup(struct seq_oss_devinfo *dp)
293 {
294         int i;
295         for (i = 0; i < dp->max_mididev; i++)
296                 snd_seq_oss_midi_close(dp, i);
297         dp->max_mididev = 0;
298 }
299
300
301 /*
302  * open all midi devices.  ignore errors.
303  */
304 void
305 snd_seq_oss_midi_open_all(struct seq_oss_devinfo *dp, int file_mode)
306 {
307         int i;
308         for (i = 0; i < dp->max_mididev; i++)
309                 snd_seq_oss_midi_open(dp, i, file_mode);
310 }
311
312
313 /*
314  * get the midi device information
315  */
316 static struct seq_oss_midi *
317 get_mididev(struct seq_oss_devinfo *dp, int dev)
318 {
319         if (dev < 0 || dev >= dp->max_mididev)
320                 return NULL;
321         dev = array_index_nospec(dev, dp->max_mididev);
322         return get_mdev(dev);
323 }
324
325
326 /*
327  * open the midi device if not opened yet
328  */
329 int
330 snd_seq_oss_midi_open(struct seq_oss_devinfo *dp, int dev, int fmode)
331 {
332         int perm;
333         struct seq_oss_midi *mdev;
334         struct snd_seq_port_subscribe subs;
335
336         if ((mdev = get_mididev(dp, dev)) == NULL)
337                 return -ENODEV;
338
339         /* already used? */
340         if (mdev->opened && mdev->devinfo != dp) {
341                 snd_use_lock_free(&mdev->use_lock);
342                 return -EBUSY;
343         }
344
345         perm = 0;
346         if (is_write_mode(fmode))
347                 perm |= PERM_WRITE;
348         if (is_read_mode(fmode))
349                 perm |= PERM_READ;
350         perm &= mdev->flags;
351         if (perm == 0) {
352                 snd_use_lock_free(&mdev->use_lock);
353                 return -ENXIO;
354         }
355
356         /* already opened? */
357         if ((mdev->opened & perm) == perm) {
358                 snd_use_lock_free(&mdev->use_lock);
359                 return 0;
360         }
361
362         perm &= ~mdev->opened;
363
364         memset(&subs, 0, sizeof(subs));
365
366         if (perm & PERM_WRITE) {
367                 subs.sender = dp->addr;
368                 subs.dest.client = mdev->client;
369                 subs.dest.port = mdev->port;
370                 if (snd_seq_kernel_client_ctl(dp->cseq, SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, &subs) >= 0)
371                         mdev->opened |= PERM_WRITE;
372         }
373         if (perm & PERM_READ) {
374                 subs.sender.client = mdev->client;
375                 subs.sender.port = mdev->port;
376                 subs.dest = dp->addr;
377                 subs.flags = SNDRV_SEQ_PORT_SUBS_TIMESTAMP;
378                 subs.queue = dp->queue;         /* queue for timestamps */
379                 if (snd_seq_kernel_client_ctl(dp->cseq, SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, &subs) >= 0)
380                         mdev->opened |= PERM_READ;
381         }
382
383         if (! mdev->opened) {
384                 snd_use_lock_free(&mdev->use_lock);
385                 return -ENXIO;
386         }
387
388         mdev->devinfo = dp;
389         snd_use_lock_free(&mdev->use_lock);
390         return 0;
391 }
392
393 /*
394  * close the midi device if already opened
395  */
396 int
397 snd_seq_oss_midi_close(struct seq_oss_devinfo *dp, int dev)
398 {
399         struct seq_oss_midi *mdev;
400         struct snd_seq_port_subscribe subs;
401
402         if ((mdev = get_mididev(dp, dev)) == NULL)
403                 return -ENODEV;
404         if (! mdev->opened || mdev->devinfo != dp) {
405                 snd_use_lock_free(&mdev->use_lock);
406                 return 0;
407         }
408
409         memset(&subs, 0, sizeof(subs));
410         if (mdev->opened & PERM_WRITE) {
411                 subs.sender = dp->addr;
412                 subs.dest.client = mdev->client;
413                 subs.dest.port = mdev->port;
414                 snd_seq_kernel_client_ctl(dp->cseq, SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT, &subs);
415         }
416         if (mdev->opened & PERM_READ) {
417                 subs.sender.client = mdev->client;
418                 subs.sender.port = mdev->port;
419                 subs.dest = dp->addr;
420                 snd_seq_kernel_client_ctl(dp->cseq, SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT, &subs);
421         }
422
423         mdev->opened = 0;
424         mdev->devinfo = NULL;
425
426         snd_use_lock_free(&mdev->use_lock);
427         return 0;
428 }
429
430 /*
431  * change seq capability flags to file mode flags
432  */
433 int
434 snd_seq_oss_midi_filemode(struct seq_oss_devinfo *dp, int dev)
435 {
436         struct seq_oss_midi *mdev;
437         int mode;
438
439         if ((mdev = get_mididev(dp, dev)) == NULL)
440                 return 0;
441
442         mode = 0;
443         if (mdev->opened & PERM_WRITE)
444                 mode |= SNDRV_SEQ_OSS_FILE_WRITE;
445         if (mdev->opened & PERM_READ)
446                 mode |= SNDRV_SEQ_OSS_FILE_READ;
447
448         snd_use_lock_free(&mdev->use_lock);
449         return mode;
450 }
451
452 /*
453  * reset the midi device and close it:
454  * so far, only close the device.
455  */
456 void
457 snd_seq_oss_midi_reset(struct seq_oss_devinfo *dp, int dev)
458 {
459         struct seq_oss_midi *mdev;
460
461         if ((mdev = get_mididev(dp, dev)) == NULL)
462                 return;
463         if (! mdev->opened) {
464                 snd_use_lock_free(&mdev->use_lock);
465                 return;
466         }
467
468         if (mdev->opened & PERM_WRITE) {
469                 struct snd_seq_event ev;
470                 int c;
471
472                 memset(&ev, 0, sizeof(ev));
473                 ev.dest.client = mdev->client;
474                 ev.dest.port = mdev->port;
475                 ev.queue = dp->queue;
476                 ev.source.port = dp->port;
477                 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_SYNTH) {
478                         ev.type = SNDRV_SEQ_EVENT_SENSING;
479                         snd_seq_oss_dispatch(dp, &ev, 0, 0);
480                 }
481                 for (c = 0; c < 16; c++) {
482                         ev.type = SNDRV_SEQ_EVENT_CONTROLLER;
483                         ev.data.control.channel = c;
484                         ev.data.control.param = MIDI_CTL_ALL_NOTES_OFF;
485                         snd_seq_oss_dispatch(dp, &ev, 0, 0);
486                         if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_MUSIC) {
487                                 ev.data.control.param =
488                                         MIDI_CTL_RESET_CONTROLLERS;
489                                 snd_seq_oss_dispatch(dp, &ev, 0, 0);
490                                 ev.type = SNDRV_SEQ_EVENT_PITCHBEND;
491                                 ev.data.control.value = 0;
492                                 snd_seq_oss_dispatch(dp, &ev, 0, 0);
493                         }
494                 }
495         }
496         // snd_seq_oss_midi_close(dp, dev);
497         snd_use_lock_free(&mdev->use_lock);
498 }
499
500
501 /*
502  * get client/port of the specified MIDI device
503  */
504 void
505 snd_seq_oss_midi_get_addr(struct seq_oss_devinfo *dp, int dev, struct snd_seq_addr *addr)
506 {
507         struct seq_oss_midi *mdev;
508
509         if ((mdev = get_mididev(dp, dev)) == NULL)
510                 return;
511         addr->client = mdev->client;
512         addr->port = mdev->port;
513         snd_use_lock_free(&mdev->use_lock);
514 }
515
516
517 /*
518  * input callback - this can be atomic
519  */
520 int
521 snd_seq_oss_midi_input(struct snd_seq_event *ev, int direct, void *private_data)
522 {
523         struct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private_data;
524         struct seq_oss_midi *mdev;
525         int rc;
526
527         if (dp->readq == NULL)
528                 return 0;
529         if ((mdev = find_slot(ev->source.client, ev->source.port)) == NULL)
530                 return 0;
531         if (! (mdev->opened & PERM_READ)) {
532                 snd_use_lock_free(&mdev->use_lock);
533                 return 0;
534         }
535
536         if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_MUSIC)
537                 rc = send_synth_event(dp, ev, mdev->seq_device);
538         else
539                 rc = send_midi_event(dp, ev, mdev);
540
541         snd_use_lock_free(&mdev->use_lock);
542         return rc;
543 }
544
545 /*
546  * convert ALSA sequencer event to OSS synth event
547  */
548 static int
549 send_synth_event(struct seq_oss_devinfo *dp, struct snd_seq_event *ev, int dev)
550 {
551         union evrec ossev;
552
553         memset(&ossev, 0, sizeof(ossev));
554
555         switch (ev->type) {
556         case SNDRV_SEQ_EVENT_NOTEON:
557                 ossev.v.cmd = MIDI_NOTEON; break;
558         case SNDRV_SEQ_EVENT_NOTEOFF:
559                 ossev.v.cmd = MIDI_NOTEOFF; break;
560         case SNDRV_SEQ_EVENT_KEYPRESS:
561                 ossev.v.cmd = MIDI_KEY_PRESSURE; break;
562         case SNDRV_SEQ_EVENT_CONTROLLER:
563                 ossev.l.cmd = MIDI_CTL_CHANGE; break;
564         case SNDRV_SEQ_EVENT_PGMCHANGE:
565                 ossev.l.cmd = MIDI_PGM_CHANGE; break;
566         case SNDRV_SEQ_EVENT_CHANPRESS:
567                 ossev.l.cmd = MIDI_CHN_PRESSURE; break;
568         case SNDRV_SEQ_EVENT_PITCHBEND:
569                 ossev.l.cmd = MIDI_PITCH_BEND; break;
570         default:
571                 return 0; /* not supported */
572         }
573
574         ossev.v.dev = dev;
575
576         switch (ev->type) {
577         case SNDRV_SEQ_EVENT_NOTEON:
578         case SNDRV_SEQ_EVENT_NOTEOFF:
579         case SNDRV_SEQ_EVENT_KEYPRESS:
580                 ossev.v.code = EV_CHN_VOICE;
581                 ossev.v.note = ev->data.note.note;
582                 ossev.v.parm = ev->data.note.velocity;
583                 ossev.v.chn = ev->data.note.channel;
584                 break;
585         case SNDRV_SEQ_EVENT_CONTROLLER:
586         case SNDRV_SEQ_EVENT_PGMCHANGE:
587         case SNDRV_SEQ_EVENT_CHANPRESS:
588                 ossev.l.code = EV_CHN_COMMON;
589                 ossev.l.p1 = ev->data.control.param;
590                 ossev.l.val = ev->data.control.value;
591                 ossev.l.chn = ev->data.control.channel;
592                 break;
593         case SNDRV_SEQ_EVENT_PITCHBEND:
594                 ossev.l.code = EV_CHN_COMMON;
595                 ossev.l.val = ev->data.control.value + 8192;
596                 ossev.l.chn = ev->data.control.channel;
597                 break;
598         }
599         
600         snd_seq_oss_readq_put_timestamp(dp->readq, ev->time.tick, dp->seq_mode);
601         snd_seq_oss_readq_put_event(dp->readq, &ossev);
602
603         return 0;
604 }
605
606 /*
607  * decode event and send MIDI bytes to read queue
608  */
609 static int
610 send_midi_event(struct seq_oss_devinfo *dp, struct snd_seq_event *ev, struct seq_oss_midi *mdev)
611 {
612         char msg[32];
613         int len;
614         
615         snd_seq_oss_readq_put_timestamp(dp->readq, ev->time.tick, dp->seq_mode);
616         if (!dp->timer->running)
617                 len = snd_seq_oss_timer_start(dp->timer);
618         if (ev->type == SNDRV_SEQ_EVENT_SYSEX) {
619                 snd_seq_oss_readq_sysex(dp->readq, mdev->seq_device, ev);
620                 snd_midi_event_reset_decode(mdev->coder);
621         } else {
622                 len = snd_midi_event_decode(mdev->coder, msg, sizeof(msg), ev);
623                 if (len > 0)
624                         snd_seq_oss_readq_puts(dp->readq, mdev->seq_device, msg, len);
625         }
626
627         return 0;
628 }
629
630
631 /*
632  * dump midi data
633  * return 0 : enqueued
634  *        non-zero : invalid - ignored
635  */
636 int
637 snd_seq_oss_midi_putc(struct seq_oss_devinfo *dp, int dev, unsigned char c, struct snd_seq_event *ev)
638 {
639         struct seq_oss_midi *mdev;
640
641         if ((mdev = get_mididev(dp, dev)) == NULL)
642                 return -ENODEV;
643         if (snd_midi_event_encode_byte(mdev->coder, c, ev)) {
644                 snd_seq_oss_fill_addr(dp, ev, mdev->client, mdev->port);
645                 snd_use_lock_free(&mdev->use_lock);
646                 return 0;
647         }
648         snd_use_lock_free(&mdev->use_lock);
649         return -EINVAL;
650 }
651
652 /*
653  * create OSS compatible midi_info record
654  */
655 int
656 snd_seq_oss_midi_make_info(struct seq_oss_devinfo *dp, int dev, struct midi_info *inf)
657 {
658         struct seq_oss_midi *mdev;
659
660         if ((mdev = get_mididev(dp, dev)) == NULL)
661                 return -ENXIO;
662         inf->device = dev;
663         inf->dev_type = 0; /* FIXME: ?? */
664         inf->capabilities = 0; /* FIXME: ?? */
665         strlcpy(inf->name, mdev->name, sizeof(inf->name));
666         snd_use_lock_free(&mdev->use_lock);
667         return 0;
668 }
669
670
671 #ifdef CONFIG_SND_PROC_FS
672 /*
673  * proc interface
674  */
675 static char *
676 capmode_str(int val)
677 {
678         val &= PERM_READ|PERM_WRITE;
679         if (val == (PERM_READ|PERM_WRITE))
680                 return "read/write";
681         else if (val == PERM_READ)
682                 return "read";
683         else if (val == PERM_WRITE)
684                 return "write";
685         else
686                 return "none";
687 }
688
689 void
690 snd_seq_oss_midi_info_read(struct snd_info_buffer *buf)
691 {
692         int i;
693         struct seq_oss_midi *mdev;
694
695         snd_iprintf(buf, "\nNumber of MIDI devices: %d\n", max_midi_devs);
696         for (i = 0; i < max_midi_devs; i++) {
697                 snd_iprintf(buf, "\nmidi %d: ", i);
698                 mdev = get_mdev(i);
699                 if (mdev == NULL) {
700                         snd_iprintf(buf, "*empty*\n");
701                         continue;
702                 }
703                 snd_iprintf(buf, "[%s] ALSA port %d:%d\n", mdev->name,
704                             mdev->client, mdev->port);
705                 snd_iprintf(buf, "  capability %s / opened %s\n",
706                             capmode_str(mdev->flags),
707                             capmode_str(mdev->opened));
708                 snd_use_lock_free(&mdev->use_lock);
709         }
710 }
711 #endif /* CONFIG_SND_PROC_FS */