2 * OSS compatible sequencer driver
4 * OSS compatible i/o control
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_timer.h"
27 #include "seq_oss_synth.h"
28 #include "seq_oss_midi.h"
29 #include "seq_oss_event.h"
32 snd_seq_oss_ioctl(seq_oss_devinfo_t *dp, unsigned int cmd, unsigned long carg)
35 struct synth_info inf;
36 struct midi_info minf;
38 void __user *arg = (void __user *)carg;
40 snd_seq_event_t tmpev;
43 case SNDCTL_TMR_TIMEBASE:
44 case SNDCTL_TMR_TEMPO:
45 case SNDCTL_TMR_START:
47 case SNDCTL_TMR_CONTINUE:
48 case SNDCTL_TMR_METRONOME:
49 case SNDCTL_TMR_SOURCE:
50 case SNDCTL_TMR_SELECT:
51 case SNDCTL_SEQ_CTRLRATE:
52 return snd_seq_oss_timer_ioctl(dp->timer, cmd, arg);
54 case SNDCTL_SEQ_PANIC:
55 debug_printk(("panic\n"));
56 snd_seq_oss_reset(dp);
60 debug_printk(("sync\n"));
61 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
63 while (snd_seq_oss_writeq_sync(dp->writeq))
65 if (signal_pending(current))
69 case SNDCTL_SEQ_RESET:
70 debug_printk(("reset\n"));
71 snd_seq_oss_reset(dp);
74 case SNDCTL_SEQ_TESTMIDI:
75 debug_printk(("test midi\n"));
78 return snd_seq_oss_midi_open(dp, dev, dp->file_mode);
80 case SNDCTL_SEQ_GETINCOUNT:
81 debug_printk(("get in count\n"));
82 if (dp->readq == NULL || ! is_read_mode(dp->file_mode))
84 return put_user(dp->readq->qlen, p) ? -EFAULT : 0;
86 case SNDCTL_SEQ_GETOUTCOUNT:
87 debug_printk(("get out count\n"));
88 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
90 return put_user(snd_seq_oss_writeq_get_free_size(dp->writeq), p) ? -EFAULT : 0;
92 case SNDCTL_SEQ_GETTIME:
93 debug_printk(("get time\n"));
94 return put_user(snd_seq_oss_timer_cur_tick(dp->timer), p) ? -EFAULT : 0;
96 case SNDCTL_SEQ_RESETSAMPLES:
97 debug_printk(("reset samples\n"));
100 return snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
102 case SNDCTL_SEQ_NRSYNTHS:
103 debug_printk(("nr synths\n"));
104 return put_user(dp->max_synthdev, p) ? -EFAULT : 0;
106 case SNDCTL_SEQ_NRMIDIS:
107 debug_printk(("nr midis\n"));
108 return put_user(dp->max_mididev, p) ? -EFAULT : 0;
110 case SNDCTL_SYNTH_MEMAVL:
111 debug_printk(("mem avail\n"));
112 if (get_user(dev, p))
114 val = snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
115 return put_user(val, p) ? -EFAULT : 0;
117 case SNDCTL_FM_4OP_ENABLE:
118 debug_printk(("4op\n"));
119 if (get_user(dev, p))
121 snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
124 case SNDCTL_SYNTH_INFO:
125 case SNDCTL_SYNTH_ID:
126 debug_printk(("synth info\n"));
127 if (copy_from_user(&inf, arg, sizeof(inf)))
129 if (snd_seq_oss_synth_make_info(dp, inf.device, &inf) < 0)
131 if (copy_to_user(arg, &inf, sizeof(inf)))
135 case SNDCTL_SEQ_OUTOFBAND:
136 debug_printk(("out of bound\n"));
137 if (copy_from_user(ev, arg, 8))
139 memset(&tmpev, 0, sizeof(tmpev));
140 snd_seq_oss_fill_addr(dp, &tmpev, dp->addr.port, dp->addr.client);
142 if (! snd_seq_oss_process_event(dp, (evrec_t*)ev, &tmpev)) {
143 snd_seq_oss_dispatch(dp, &tmpev, 0, 0);
147 case SNDCTL_MIDI_INFO:
148 debug_printk(("midi info\n"));
149 if (copy_from_user(&minf, arg, sizeof(minf)))
151 if (snd_seq_oss_midi_make_info(dp, minf.device, &minf) < 0)
153 if (copy_to_user(arg, &minf, sizeof(minf)))
157 case SNDCTL_SEQ_THRESHOLD:
158 debug_printk(("threshold\n"));
159 if (! is_write_mode(dp->file_mode))
161 if (get_user(val, p))
165 if (val >= dp->writeq->maxlen)
166 val = dp->writeq->maxlen - 1;
167 snd_seq_oss_writeq_set_output(dp->writeq, val);
170 case SNDCTL_MIDI_PRETIME:
171 debug_printk(("pretime\n"));
172 if (dp->readq == NULL || !is_read_mode(dp->file_mode))
174 if (get_user(val, p))
179 val = (HZ * val) / 10;
180 dp->readq->pre_event_timeout = val;
181 return put_user(val, p) ? -EFAULT : 0;
184 debug_printk(("others\n"));
185 if (! is_write_mode(dp->file_mode))
187 return snd_seq_oss_synth_ioctl(dp, 0, cmd, carg);