2 * OSS compatible sequencer driver
4 * read/write/select interface to device file
6 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
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.
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.
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
23 #include "seq_oss_device.h"
24 #include "seq_oss_readq.h"
25 #include "seq_oss_writeq.h"
26 #include "seq_oss_synth.h"
27 #include <sound/seq_oss_legacy.h>
28 #include "seq_oss_event.h"
29 #include "seq_oss_timer.h"
30 #include "../seq_clientmgr.h"
36 static int insert_queue(seq_oss_devinfo_t *dp, evrec_t *rec, struct file *opt);
44 snd_seq_oss_read(seq_oss_devinfo_t *dp, char __user *buf, int count)
46 seq_oss_readq_t *readq = dp->readq;
51 if (readq == NULL || ! is_read_mode(dp->file_mode))
54 /* copy queued events to read buffer */
57 q = snd_seq_oss_readq_pick(readq, !is_nonblock_mode(dp->file_mode), &flags);
62 /* tansfer the data */
63 ev_len = ev_length(q);
64 if (copy_to_user(buf + pos, q, ev_len)) {
65 snd_seq_oss_readq_unlock(readq, flags);
68 snd_seq_oss_readq_free(readq, flags);
73 } while ((q = snd_seq_oss_readq_pick(readq, 0, &flags)) != NULL);
84 snd_seq_oss_write(seq_oss_devinfo_t *dp, const char __user *buf, int count, struct file *opt)
86 int rc, c, p, ev_size;
89 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
94 while (c >= SHORT_EVENT_SIZE) {
95 if (copy_from_user(rec.c, buf + p, SHORT_EVENT_SIZE))
97 p += SHORT_EVENT_SIZE;
99 if (rec.s.code == SEQ_FULLSIZE) {
101 int fmt = (*(unsigned short *)rec.c) & 0xffff;
102 return snd_seq_oss_synth_load_patch(dp, rec.s.dev, fmt, buf, p, c);
105 if (ev_is_long(&rec)) {
107 if (rec.s.code == SEQ_EXTENDED &&
108 dp->seq_mode == SNDRV_SEQ_OSS_MODE_MUSIC)
110 ev_size = LONG_EVENT_SIZE;
113 /* copy the reset 4 bytes */
114 if (copy_from_user(rec.c + SHORT_EVENT_SIZE, buf + p,
115 LONG_EVENT_SIZE - SHORT_EVENT_SIZE))
117 p += LONG_EVENT_SIZE - SHORT_EVENT_SIZE;
121 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_MUSIC)
123 ev_size = SHORT_EVENT_SIZE;
127 if ((rc = insert_queue(dp, &rec, opt)) < 0)
133 if (count == c && is_nonblock_mode(dp->file_mode))
140 * insert event record to write queue
141 * return: 0 = OK, non-zero = NG
144 insert_queue(seq_oss_devinfo_t *dp, evrec_t *rec, struct file *opt)
147 snd_seq_event_t event;
149 /* if this is a timing event, process the current time */
150 if (snd_seq_oss_process_timer_event(dp->timer, rec))
151 return 0; /* no need to insert queue */
153 /* parse this event */
154 memset(&event, 0, sizeof(event));
155 /* set dummy -- to be sure */
156 event.type = SNDRV_SEQ_EVENT_NOTEOFF;
157 snd_seq_oss_fill_addr(dp, &event, dp->addr.port, dp->addr.client);
159 if (snd_seq_oss_process_event(dp, rec, &event))
160 return 0; /* invalid event - no need to insert queue */
162 event.time.tick = snd_seq_oss_timer_cur_tick(dp->timer);
163 if (dp->timer->realtime || !dp->timer->running) {
164 snd_seq_oss_dispatch(dp, &event, 0, 0);
166 if (is_nonblock_mode(dp->file_mode))
167 rc = snd_seq_kernel_client_enqueue(dp->cseq, &event, 0, 0);
169 rc = snd_seq_kernel_client_enqueue_blocking(dp->cseq, &event, opt, 0, 0);
180 snd_seq_oss_poll(seq_oss_devinfo_t *dp, struct file *file, poll_table * wait)
182 unsigned int mask = 0;
185 if (dp->readq && is_read_mode(dp->file_mode)) {
186 if (snd_seq_oss_readq_poll(dp->readq, file, wait))
187 mask |= POLLIN | POLLRDNORM;
191 if (dp->writeq && is_write_mode(dp->file_mode)) {
192 if (snd_seq_kernel_client_write_poll(dp->cseq, file, wait))
193 mask |= POLLOUT | POLLWRNORM;