summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authornetchild <netchild@FreeBSD.org>2007-02-25 13:51:52 +0000
committernetchild <netchild@FreeBSD.org>2007-02-25 13:51:52 +0000
commitb325c96ab118f6babf5bdb598e112d479febd6c6 (patch)
treedd36eac7f238eb80fea8335efd23cbe29e7177e2 /sys
parent249ecc90783a698115fee53b0e6eb803f57f32d1 (diff)
downloadFreeBSD-src-b325c96ab118f6babf5bdb598e112d479febd6c6.zip
FreeBSD-src-b325c96ab118f6babf5bdb598e112d479febd6c6.tar.gz
semi-automatic style(9)
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/sound/midi/midi.c1057
-rw-r--r--sys/dev/sound/midi/midi.h20
-rw-r--r--sys/dev/sound/midi/midiq.h2
-rw-r--r--sys/dev/sound/midi/mpu401.c93
-rw-r--r--sys/dev/sound/midi/mpu401.h10
-rw-r--r--sys/dev/sound/midi/mpu_if.m48
-rw-r--r--sys/dev/sound/midi/mpufoi_if.m10
-rw-r--r--sys/dev/sound/midi/sequencer.c1348
-rw-r--r--sys/dev/sound/midi/sequencer.h13
-rw-r--r--sys/dev/sound/midi/synth_if.m104
10 files changed, 1377 insertions, 1328 deletions
diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c
index e183cb1..da5424c 100644
--- a/sys/dev/sound/midi/midi.c
+++ b/sys/dev/sound/midi/midi.c
@@ -99,37 +99,36 @@ enum midi_states {
#define MIDI_NAMELEN 16
struct snd_midi {
KOBJ_FIELDS;
- struct mtx lock; /* Protects all but queues */
- void *cookie;
-
- int unit; /* Should only be used in midistat */
- int channel;/* Should only be used in midistat */
-
- int busy;
- int flags; /* File flags */
- char name[MIDI_NAMELEN];
- struct mtx qlock; /* Protects inq, outq and flags */
- MIDIQ_HEAD(, char)inq, outq;
- int rchan, wchan;
- struct selinfo rsel, wsel;
- int hiwat; /* QLEN(outq)>High-water -> disable writes
- * from userland */
+ struct mtx lock; /* Protects all but queues */
+ void *cookie;
+
+ int unit; /* Should only be used in midistat */
+ int channel; /* Should only be used in midistat */
+
+ int busy;
+ int flags; /* File flags */
+ char name[MIDI_NAMELEN];
+ struct mtx qlock; /* Protects inq, outq and flags */
+ MIDIQ_HEAD(, char) inq, outq;
+ int rchan, wchan;
+ struct selinfo rsel, wsel;
+ int hiwat; /* QLEN(outq)>High-water -> disable
+ * writes from userland */
enum midi_states inq_state;
- int inq_status, inq_left; /* Variables for the state
- * machine in Midi_in, this
- * is to provide that signals
- * only get issued only
- * complete command packets. */
- struct proc *async;
- struct cdev *dev;
+ int inq_status, inq_left; /* Variables for the state machine in
+ * Midi_in, this is to provide that
+ * signals only get issued only
+ * complete command packets. */
+ struct proc *async;
+ struct cdev *dev;
struct synth_midi *synth;
- int synth_flags;
+ int synth_flags;
TAILQ_ENTRY(snd_midi) link;
};
struct synth_midi {
- KOBJ_FIELDS;
- struct snd_midi *m;
+ KOBJ_FIELDS;
+ struct snd_midi *m;
};
static synth_open_t midisynth_open;
@@ -144,30 +143,30 @@ static synth_bender_t midisynth_bender;
static kobj_method_t midisynth_methods[] = {
- KOBJMETHOD(synth_open,midisynth_open),
- KOBJMETHOD(synth_close,midisynth_close),
- KOBJMETHOD(synth_writeraw,midisynth_writeraw),
- KOBJMETHOD(synth_setinstr,midisynth_setinstr),
- KOBJMETHOD(synth_startnote,midisynth_startnote),
- KOBJMETHOD(synth_killnote,midisynth_killnote),
- KOBJMETHOD(synth_alloc, midisynth_alloc),
- KOBJMETHOD(synth_controller, midisynth_controller),
- KOBJMETHOD(synth_bender, midisynth_bender),
- { 0, 0 }
+ KOBJMETHOD(synth_open, midisynth_open),
+ KOBJMETHOD(synth_close, midisynth_close),
+ KOBJMETHOD(synth_writeraw, midisynth_writeraw),
+ KOBJMETHOD(synth_setinstr, midisynth_setinstr),
+ KOBJMETHOD(synth_startnote, midisynth_startnote),
+ KOBJMETHOD(synth_killnote, midisynth_killnote),
+ KOBJMETHOD(synth_alloc, midisynth_alloc),
+ KOBJMETHOD(synth_controller, midisynth_controller),
+ KOBJMETHOD(synth_bender, midisynth_bender),
+ {0, 0}
};
DEFINE_CLASS(midisynth, midisynth_methods, 0);
/*
* Module Exports & Interface
- *
+ *
* struct midi_chan *midi_init(MPU_CLASS cls, int unit, int chan) int
* midi_uninit(struct snd_midi *) 0 == no error EBUSY or other error int
* Midi_in(struct midi_chan *, char *buf, int count) int Midi_out(struct
* midi_chan *, char *buf, int count)
- *
+ *
* midi_{in,out} return actual size transfered
- *
+ *
*/
@@ -268,21 +267,21 @@ SYSCTL_INT(_hw_midi_stat, OID_AUTO, verbose, CTLFLAG_RW,
* cookie is passed back on MPU calls Typical device drivers will call with
* unit=0, channel=1..(number of channels) and cookie=soft_c and won't care
* what unit number is used.
- *
+ *
* It is an error to call midi_init with an already used unit/channel combo.
- *
+ *
* Returns NULL on error
- *
+ *
*/
struct snd_midi *
midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
{
struct snd_midi *m;
- int i;
- int inqsize, outqsize;
- MIDI_TYPE *buf;
+ int i;
+ int inqsize, outqsize;
+ MIDI_TYPE *buf;
- MIDI_DEBUG(1,printf("midiinit: unit %d/%d.\n", unit, channel));
+ MIDI_DEBUG(1, printf("midiinit: unit %d/%d.\n", unit, channel));
mtx_lock(&midistat_lock);
/*
* Protect against call with existing unit/channel or auto-allocate a
@@ -290,29 +289,29 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
*/
i = -1;
TAILQ_FOREACH(m, &midi_devs, link) {
- mtx_lock(&m->lock);
- if (unit != 0) {
- if (m->unit == unit && m->channel == channel) {
- mtx_unlock(&m->lock);
- goto err0;
+ mtx_lock(&m->lock);
+ if (unit != 0) {
+ if (m->unit == unit && m->channel == channel) {
+ mtx_unlock(&m->lock);
+ goto err0;
+ }
+ } else {
+ /*
+ * Find a better unit number
+ */
+ if (m->unit > i)
+ i = m->unit;
}
- } else {
- /*
- * Find a better unit number
- */
- if (m->unit > i)
- i = m->unit;
- }
- mtx_unlock(&m->lock);
+ mtx_unlock(&m->lock);
}
if (unit == 0)
- unit = i + 1;
+ unit = i + 1;
MIDI_DEBUG(1, printf("midiinit #2: unit %d/%d.\n", unit, channel));
m = malloc(sizeof(*m), M_MIDI, M_NOWAIT | M_ZERO);
if (m == NULL)
- goto err0;
+ goto err0;
m->synth = malloc(sizeof(*m->synth), M_MIDI, M_NOWAIT | M_ZERO);
kobj_init((kobj_t)m->synth, &midisynth_class);
@@ -323,7 +322,7 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
MIDI_DEBUG(1, printf("midiinit queues %d/%d.\n", inqsize, outqsize));
if (!inqsize && !outqsize)
- goto err1;
+ goto err1;
mtx_init(&m->lock, "raw midi", 0, 0);
mtx_init(&m->qlock, "q raw midi", 0, 0);
@@ -332,23 +331,23 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
mtx_lock(&m->qlock);
if (inqsize)
- buf = malloc(sizeof(MIDI_TYPE) * inqsize, M_MIDI, M_NOWAIT);
+ buf = malloc(sizeof(MIDI_TYPE) * inqsize, M_MIDI, M_NOWAIT);
else
- buf = NULL;
+ buf = NULL;
MIDIQ_INIT(m->inq, buf, inqsize);
if (outqsize)
- buf = malloc(sizeof(MIDI_TYPE) * outqsize, M_MIDI, M_NOWAIT);
+ buf = malloc(sizeof(MIDI_TYPE) * outqsize, M_MIDI, M_NOWAIT);
else
- buf = NULL;
+ buf = NULL;
m->hiwat = outqsize / 2;
MIDIQ_INIT(m->outq, buf, outqsize);
if ((inqsize && !MIDIQ_BUF(m->inq)) ||
(outqsize && !MIDIQ_BUF(m->outq)))
- goto err2;
+ goto err2;
m->busy = 0;
@@ -358,7 +357,7 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
m->cookie = cookie;
if (MPU_INIT(m, cookie))
- goto err2;
+ goto err2;
mtx_unlock(&m->lock);
mtx_unlock(&m->qlock);
@@ -368,8 +367,8 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
mtx_unlock(&midistat_lock);
m->dev = make_dev(&midi_cdevsw,
- MIDIMKMINOR(unit, MIDI_DEV_RAW, channel),
- UID_ROOT, GID_WHEEL, 0666, "midi%d.%d", unit, channel);
+ MIDIMKMINOR(unit, MIDI_DEV_RAW, channel),
+ UID_ROOT, GID_WHEEL, 0666, "midi%d.%d", unit, channel);
m->dev->si_drv1 = m;
return m;
@@ -378,9 +377,9 @@ err2: mtx_destroy(&m->qlock);
mtx_destroy(&m->lock);
if (MIDIQ_BUF(m->inq))
- free(MIDIQ_BUF(m->inq), M_MIDI);
+ free(MIDIQ_BUF(m->inq), M_MIDI);
if (MIDIQ_BUF(m->outq))
- free(MIDIQ_BUF(m->outq), M_MIDI);
+ free(MIDIQ_BUF(m->outq), M_MIDI);
err1: free(m, M_MIDI);
err0: mtx_unlock(&midistat_lock);
MIDI_DEBUG(1, printf("midi_init ended in error\n"));
@@ -391,32 +390,32 @@ err0: mtx_unlock(&midistat_lock);
* midi_uninit does not call MIDI_UNINIT, as since this is the implementors
* entry point. midi_unint if fact, does not send any methods. A call to
* midi_uninit is a defacto promise that you won't manipulate ch anymore
- *
+ *
*/
int
-midi_uninit(struct snd_midi * m)
+midi_uninit(struct snd_midi *m)
{
- int err;
+ int err;
err = ENXIO;
mtx_lock(&midistat_lock);
mtx_lock(&m->lock);
if (m->busy) {
- if (!(m->rchan || m->wchan))
- goto err;
+ if (!(m->rchan || m->wchan))
+ goto err;
- if (m->rchan) {
- wakeup(&m->rchan);
- m->rchan = 0;
- }
- if (m->wchan) {
- wakeup(&m->wchan);
- m->wchan = 0;
- }
+ if (m->rchan) {
+ wakeup(&m->rchan);
+ m->rchan = 0;
+ }
+ if (m->wchan) {
+ wakeup(&m->wchan);
+ m->wchan = 0;
+ }
}
err = midi_destroy(m, 0);
- if(!err)
+ if (!err)
goto exit;
err: mtx_unlock(&m->lock);
@@ -432,8 +431,9 @@ exit: mtx_unlock(&midistat_lock);
*/
#ifdef notdef
-static int midi_lengths[] = {2, 2, 2, 2, 1, 1, 2, 0};
-#endif /* notdef */
+static int midi_lengths[] = {2, 2, 2, 2, 1, 1, 2, 0};
+
+#endif /* notdef */
/* Number of bytes in a MIDI command */
#define MIDI_LENGTH(d) (midi_lengths[((d) >> 4) & 7])
#define MIDI_ACK 0xfe
@@ -445,10 +445,11 @@ static int midi_lengths[] = {2, 2, 2, 2, 1, 1, 2, 0};
int
-midi_in(struct snd_midi * m, MIDI_TYPE * buf, int size)
+midi_in(struct snd_midi *m, MIDI_TYPE *buf, int size)
{
/* int i, sig, enq; */
- int used;
+ int used;
+
/* MIDI_TYPE data; */
MIDI_DEBUG(5, printf("midi_in: m=%p size=%d\n", m, size));
@@ -456,7 +457,7 @@ midi_in(struct snd_midi * m, MIDI_TYPE * buf, int size)
* XXX: locking flub
*/
if (!(m->flags & M_RX))
- return size;
+ return size;
used = 0;
@@ -468,100 +469,102 @@ midi_in(struct snd_midi * m, MIDI_TYPE * buf, int size)
*/
if (!(m->flags & M_RX))
- return size;
+ return size;
for (i = sig = 0; i < size; i++) {
- data = buf[i];
- enq = 0;
- if (data == MIDI_ACK)
- continue;
-
- switch (m->inq_state) {
- case MIDI_IN_START:
- if (MIDI_IS_STATUS(data)) {
- switch (data) {
- case 0xf0: /* Sysex */
- m->inq_state = MIDI_IN_SYSEX;
- break;
- case 0xf1: /* MTC quarter frame */
- case 0xf3: /* Song select */
- m->inq_state = MIDI_IN_DATA;
- enq = 1;
- m->inq_left = 1;
+ data = buf[i];
+ enq = 0;
+ if (data == MIDI_ACK)
+ continue;
+
+ switch (m->inq_state) {
+ case MIDI_IN_START:
+ if (MIDI_IS_STATUS(data)) {
+ switch (data) {
+ case 0xf0: /* Sysex */
+ m->inq_state = MIDI_IN_SYSEX;
+ break;
+ case 0xf1: /* MTC quarter frame */
+ case 0xf3: /* Song select */
+ m->inq_state = MIDI_IN_DATA;
+ enq = 1;
+ m->inq_left = 1;
+ break;
+ case 0xf2: /* Song position pointer */
+ m->inq_state = MIDI_IN_DATA;
+ enq = 1;
+ m->inq_left = 2;
+ break;
+ default:
+ if (MIDI_IS_COMMON(data)) {
+ enq = 1;
+ sig = 1;
+ } else {
+ m->inq_state = MIDI_IN_DATA;
+ enq = 1;
+ m->inq_status = data;
+ m->inq_left = MIDI_LENGTH(data);
+ }
+ break;
+ }
+ } else if (MIDI_IS_STATUS(m->inq_status)) {
+ m->inq_state = MIDI_IN_DATA;
+ if (!MIDIQ_FULL(m->inq)) {
+ used++;
+ MIDIQ_ENQ(m->inq, &m->inq_status, 1);
+ }
+ enq = 1;
+ m->inq_left = MIDI_LENGTH(m->inq_status) - 1;
+ }
break;
- case 0xf2: /* Song position pointer */
- m->inq_state = MIDI_IN_DATA;
+ /*
+ * End of case MIDI_IN_START:
+ */
+
+ case MIDI_IN_DATA:
enq = 1;
- m->inq_left = 2;
+ if (--m->inq_left <= 0)
+ sig = 1;/* deliver data */
break;
- default:
- if (MIDI_IS_COMMON(data)) {
- enq = 1;
- sig = 1;
- } else {
- m->inq_state = MIDI_IN_DATA;
- enq = 1;
- m->inq_status = data;
- m->inq_left = MIDI_LENGTH(data);
- }
+ case MIDI_IN_SYSEX:
+ if (data == MIDI_SYSEX_END)
+ m->inq_state = MIDI_IN_START;
break;
- }
- } else if (MIDI_IS_STATUS(m->inq_status)) {
- m->inq_state = MIDI_IN_DATA;
- if (!MIDIQ_FULL(m->inq)) {
- used++;
- MIDIQ_ENQ(m->inq, &m->inq_status, 1);
- }
- enq = 1;
- m->inq_left = MIDI_LENGTH(m->inq_status) - 1;
}
- break;
- /*
- * End of case MIDI_IN_START:
- */
- case MIDI_IN_DATA:
- enq = 1;
- if (--m->inq_left <= 0)
- sig = 1; /* deliver data */
- break;
- case MIDI_IN_SYSEX:
- if (data == MIDI_SYSEX_END)
- m->inq_state = MIDI_IN_START;
- break;
- }
-
- if (enq)
- if (!MIDIQ_FULL(m->inq)) {
- MIDIQ_ENQ(m->inq, &data, 1);
- used++;
- }
- /*
- * End of the state machines main "for loop"
- */
+ if (enq)
+ if (!MIDIQ_FULL(m->inq)) {
+ MIDIQ_ENQ(m->inq, &data, 1);
+ used++;
+ }
+ /*
+ * End of the state machines main "for loop"
+ */
}
if (sig) {
#endif
- MIDI_DEBUG(6, printf("midi_in: len %jd avail %jd\n", (intmax_t)MIDIQ_LEN(m->inq), (intmax_t)MIDIQ_AVAIL(m->inq))) ;
- if (MIDIQ_AVAIL(m->inq) > size) {
- used=size;
- MIDIQ_ENQ(m->inq, buf, size);
- } else {
- MIDI_DEBUG(4,printf("midi_in: Discarding data qu\n"));
- mtx_unlock(&m->qlock);
- return 0;
- }
- if (m->rchan) {
- wakeup(&m->rchan);
- m->rchan = 0;
- }
- selwakeup(&m->rsel);
- if (m->async) {
- PROC_LOCK(m->async);
- psignal(m->async, SIGIO);
- PROC_UNLOCK(m->async);
- }
+ MIDI_DEBUG(6, printf("midi_in: len %jd avail %jd\n",
+ (intmax_t)MIDIQ_LEN(m->inq),
+ (intmax_t)MIDIQ_AVAIL(m->inq)));
+ if (MIDIQ_AVAIL(m->inq) > size) {
+ used = size;
+ MIDIQ_ENQ(m->inq, buf, size);
+ } else {
+ MIDI_DEBUG(4, printf("midi_in: Discarding data qu\n"));
+ mtx_unlock(&m->qlock);
+ return 0;
+ }
+ if (m->rchan) {
+ wakeup(&m->rchan);
+ m->rchan = 0;
+ }
+ selwakeup(&m->rsel);
+ if (m->async) {
+ PROC_LOCK(m->async);
+ psignal(m->async, SIGIO);
+ PROC_UNLOCK(m->async);
+ }
#if 0
}
#endif
@@ -573,9 +576,9 @@ midi_in(struct snd_midi * m, MIDI_TYPE * buf, int size)
* midi_out: The only clearer of the M_TXEN flag.
*/
int
-midi_out(struct snd_midi * m, MIDI_TYPE * buf, int size)
+midi_out(struct snd_midi *m, MIDI_TYPE *buf, int size)
{
- int used;
+ int used;
/*
* XXX: locking flub
@@ -583,23 +586,23 @@ midi_out(struct snd_midi * m, MIDI_TYPE * buf, int size)
if (!(m->flags & M_TXEN))
return 0;
- MIDI_DEBUG(2, printf("midi_out: %p\n", m));
+ MIDI_DEBUG(2, printf("midi_out: %p\n", m));
mtx_lock(&m->qlock);
used = MIN(size, MIDIQ_LEN(m->outq));
MIDI_DEBUG(3, printf("midi_out: used %d\n", used));
if (used)
- MIDIQ_DEQ(m->outq, buf, used);
+ MIDIQ_DEQ(m->outq, buf, used);
if (MIDIQ_EMPTY(m->outq)) {
- m->flags &= ~M_TXEN;
- MPU_CALLBACKP(m, m->cookie, m->flags);
+ m->flags &= ~M_TXEN;
+ MPU_CALLBACKP(m, m->cookie, m->flags);
}
- if (used && MIDIQ_AVAIL(m->outq) > m->hiwat ) {
+ if (used && MIDIQ_AVAIL(m->outq) > m->hiwat) {
if (m->wchan) {
wakeup(&m->wchan);
m->wchan = 0;
}
selwakeup(&m->wsel);
- if (m->async) {
+ if (m->async) {
PROC_LOCK(m->async);
psignal(m->async, SIGIO);
PROC_UNLOCK(m->async);
@@ -614,15 +617,15 @@ midi_out(struct snd_midi * m, MIDI_TYPE * buf, int size)
* /dev/rmidi#.# device access functions
*/
int
-midi_open(struct cdev *i_dev, int flags, int mode, struct thread * td)
+midi_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
{
struct snd_midi *m = i_dev->si_drv1;
- int retval;
+ int retval;
- MIDI_DEBUG(1,printf("midiopen %p %s %s\n", td,
- flags & FREAD?"M_RX":"", flags & FWRITE?"M_TX":""));
+ MIDI_DEBUG(1, printf("midiopen %p %s %s\n", td,
+ flags & FREAD ? "M_RX" : "", flags & FWRITE ? "M_TX" : ""));
if (m == NULL)
- return ENXIO;
+ return ENXIO;
mtx_lock(&m->lock);
mtx_lock(&m->qlock);
@@ -630,20 +633,20 @@ midi_open(struct cdev *i_dev, int flags, int mode, struct thread * td)
retval = 0;
if (flags & FREAD) {
- if (MIDIQ_SIZE(m->inq) == 0)
- retval = ENXIO;
- else if (m->flags & M_RX)
- retval = EBUSY;
- if (retval)
- goto err;
+ if (MIDIQ_SIZE(m->inq) == 0)
+ retval = ENXIO;
+ else if (m->flags & M_RX)
+ retval = EBUSY;
+ if (retval)
+ goto err;
}
if (flags & FWRITE) {
- if (MIDIQ_SIZE(m->outq) == 0)
- retval = ENXIO;
- else if (m->flags & M_TX)
- retval = EBUSY;
- if (retval)
- goto err;
+ if (MIDIQ_SIZE(m->outq) == 0)
+ retval = ENXIO;
+ else if (m->flags & M_TX)
+ retval = EBUSY;
+ if (retval)
+ goto err;
}
m->busy++;
@@ -652,16 +655,16 @@ midi_open(struct cdev *i_dev, int flags, int mode, struct thread * td)
m->async = 0;
if (flags & FREAD) {
- m->flags |= M_RX | M_RXEN;
- /*
- * Only clear the inq, the outq might still have data to drain from
- * a previous session
- */
- MIDIQ_CLEAR(m->inq);
+ m->flags |= M_RX | M_RXEN;
+ /*
+ * Only clear the inq, the outq might still have data to drain
+ * from a previous session
+ */
+ MIDIQ_CLEAR(m->inq);
};
if (flags & FWRITE)
- m->flags |= M_TX;
+ m->flags |= M_TX;
MPU_CALLBACK(m, m->cookie, m->flags);
@@ -673,37 +676,36 @@ err: mtx_unlock(&m->qlock);
}
int
-midi_close(struct cdev *i_dev, int flags, int mode, struct thread * td)
+midi_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
{
struct snd_midi *m = i_dev->si_drv1;
- int retval;
- int oldflags;
+ int retval;
+ int oldflags;
MIDI_DEBUG(1, printf("midi_close %p %s %s\n", td,
- flags & FREAD?"M_RX":"", flags & FWRITE?"M_TX":""));
+ flags & FREAD ? "M_RX" : "", flags & FWRITE ? "M_TX" : ""));
if (m == NULL)
- return ENXIO;
+ return ENXIO;
mtx_lock(&m->lock);
mtx_lock(&m->qlock);
- if ( (flags & FREAD && !(m->flags & M_RX)) ||
- (flags & FWRITE && !(m->flags & M_TX)) ) {
- retval = ENXIO;
- goto err;
+ if ((flags & FREAD && !(m->flags & M_RX)) ||
+ (flags & FWRITE && !(m->flags & M_TX))) {
+ retval = ENXIO;
+ goto err;
}
-
m->busy--;
oldflags = m->flags;
if (flags & FREAD)
- m->flags &= ~(M_RX | M_RXEN);
+ m->flags &= ~(M_RX | M_RXEN);
if (flags & FWRITE)
- m->flags &= ~M_TX;
+ m->flags &= ~M_TX;
- if( (m->flags & (M_TXEN | M_RXEN)) != (oldflags & (M_RXEN | M_TXEN)) )
+ if ((m->flags & (M_TXEN | M_RXEN)) != (oldflags & (M_RXEN | M_TXEN)))
MPU_CALLBACK(m, m->cookie, m->flags);
MIDI_DEBUG(1, printf("midi_close: closed, busy = %d.\n", m->busy));
@@ -713,70 +715,73 @@ midi_close(struct cdev *i_dev, int flags, int mode, struct thread * td)
retval = 0;
err: return retval;
}
+
/*
- * TODO: midi_read, per oss programmer's guide pg. 42 should return as soon as data is available.
+ * TODO: midi_read, per oss programmer's guide pg. 42 should return as soon
+ * as data is available.
*/
int
-midi_read(struct cdev *i_dev, struct uio * uio, int ioflag)
+midi_read(struct cdev *i_dev, struct uio *uio, int ioflag)
{
#define MIDI_RSIZE 32
struct snd_midi *m = i_dev->si_drv1;
- int retval;
- int used;
- char buf[MIDI_RSIZE];
+ int retval;
+ int used;
+ char buf[MIDI_RSIZE];
- MIDI_DEBUG(5, printf("midiread: count=%lu\n", (unsigned long)uio->uio_resid));
+ MIDI_DEBUG(5, printf("midiread: count=%lu\n",
+ (unsigned long)uio->uio_resid));
retval = EIO;
if (m == NULL)
- goto err0;
+ goto err0;
mtx_lock(&m->lock);
mtx_lock(&m->qlock);
if (!(m->flags & M_RX))
- goto err1;
+ goto err1;
while (uio->uio_resid > 0) {
- while (MIDIQ_EMPTY(m->inq)) {
- retval = EWOULDBLOCK;
- if (ioflag & O_NONBLOCK)
- goto err1;
- mtx_unlock(&m->lock);
- m->rchan = 1;
- retval = msleep(&m->rchan, &m->qlock,
- PCATCH | PDROP, "midi RX", 0);
- /*
- * We slept, maybe things have changed since last
- * dying check
- */
- if (retval == EINTR)
- goto err0;
- if (m != i_dev->si_drv1)
- retval = ENXIO;
- /* if (retval && retval != ERESTART) */
- if (retval)
- goto err0;
- mtx_lock(&m->lock);
- mtx_lock(&m->qlock);
- m->rchan = 0;
- if (!m->busy)
- goto err1;
- }
+ while (MIDIQ_EMPTY(m->inq)) {
+ retval = EWOULDBLOCK;
+ if (ioflag & O_NONBLOCK)
+ goto err1;
+ mtx_unlock(&m->lock);
+ m->rchan = 1;
+ retval = msleep(&m->rchan, &m->qlock,
+ PCATCH | PDROP, "midi RX", 0);
+ /*
+ * We slept, maybe things have changed since last
+ * dying check
+ */
+ if (retval == EINTR)
+ goto err0;
+ if (m != i_dev->si_drv1)
+ retval = ENXIO;
+ /* if (retval && retval != ERESTART) */
+ if (retval)
+ goto err0;
+ mtx_lock(&m->lock);
+ mtx_lock(&m->qlock);
+ m->rchan = 0;
+ if (!m->busy)
+ goto err1;
+ }
MIDI_DEBUG(6, printf("midi_read start\n"));
- /*
- * At this point, it is certain that m->inq has data
- */
+ /*
+ * At this point, it is certain that m->inq has data
+ */
- used = MIN(MIDIQ_LEN(m->inq), uio->uio_resid);
- used = MIN(used, MIDI_RSIZE);
+ used = MIN(MIDIQ_LEN(m->inq), uio->uio_resid);
+ used = MIN(used, MIDI_RSIZE);
- MIDI_DEBUG(6,printf("midiread: uiomove cc=%d\n", used));
- MIDIQ_DEQ(m->inq, buf, used);
- retval = uiomove(buf, used, uio);
- if (retval)
- goto err1;
+ MIDI_DEBUG(6, printf("midiread: uiomove cc=%d\n", used));
+ MIDIQ_DEQ(m->inq, buf, used);
+ retval = uiomove(buf, used, uio);
+ if (retval)
+ goto err1;
}
/*
@@ -785,7 +790,7 @@ midi_read(struct cdev *i_dev, struct uio * uio, int ioflag)
retval = 0;
err1: mtx_unlock(&m->qlock);
mtx_unlock(&m->lock);
-err0: MIDI_DEBUG(4, printf("midi_read: ret %d\n",retval));
+err0: MIDI_DEBUG(4, printf("midi_read: ret %d\n", retval));
return retval;
}
@@ -794,74 +799,76 @@ err0: MIDI_DEBUG(4, printf("midi_read: ret %d\n",retval));
*/
int
-midi_write(struct cdev *i_dev, struct uio * uio, int ioflag)
+midi_write(struct cdev *i_dev, struct uio *uio, int ioflag)
{
#define MIDI_WSIZE 32
struct snd_midi *m = i_dev->si_drv1;
- int retval;
- int used;
- char buf[MIDI_WSIZE];
+ int retval;
+ int used;
+ char buf[MIDI_WSIZE];
- MIDI_DEBUG(4, printf("midi_write\n"));
+ MIDI_DEBUG(4, printf("midi_write\n"));
retval = 0;
if (m == NULL)
- goto err0;
+ goto err0;
mtx_lock(&m->lock);
mtx_lock(&m->qlock);
if (!(m->flags & M_TX))
- goto err1;
+ goto err1;
while (uio->uio_resid > 0) {
- while (MIDIQ_AVAIL(m->outq) == 0) {
- retval = EWOULDBLOCK;
- if (ioflag & O_NONBLOCK)
- goto err1;
- mtx_unlock(&m->lock);
- m->wchan = 1;
- MIDI_DEBUG(3,printf("midi_write msleep\n"));
- retval = msleep(&m->wchan, &m->qlock,
- PCATCH | PDROP, "midi TX", 0);
- /*
- * We slept, maybe things have changed since last
- * dying check
- */
- if (retval == EINTR)
- goto err0;
- if (m != i_dev->si_drv1)
- retval = ENXIO;
- if (retval)
- goto err0;
- mtx_lock(&m->lock);
- mtx_lock(&m->qlock);
- m->wchan = 0;
- if (!m->busy)
- goto err1;
- }
+ while (MIDIQ_AVAIL(m->outq) == 0) {
+ retval = EWOULDBLOCK;
+ if (ioflag & O_NONBLOCK)
+ goto err1;
+ mtx_unlock(&m->lock);
+ m->wchan = 1;
+ MIDI_DEBUG(3, printf("midi_write msleep\n"));
+ retval = msleep(&m->wchan, &m->qlock,
+ PCATCH | PDROP, "midi TX", 0);
+ /*
+ * We slept, maybe things have changed since last
+ * dying check
+ */
+ if (retval == EINTR)
+ goto err0;
+ if (m != i_dev->si_drv1)
+ retval = ENXIO;
+ if (retval)
+ goto err0;
+ mtx_lock(&m->lock);
+ mtx_lock(&m->qlock);
+ m->wchan = 0;
+ if (!m->busy)
+ goto err1;
+ }
- /*
- * We are certain than data can be placed on the queue
- */
+ /*
+ * We are certain than data can be placed on the queue
+ */
- used = MIN(MIDIQ_AVAIL(m->outq), uio->uio_resid);
- used = MIN(used, MIDI_WSIZE);
- MIDI_DEBUG(5,printf("midiout: resid %d len %jd avail %jd\n", uio->uio_resid, (intmax_t)MIDIQ_LEN(m->outq), (intmax_t)MIDIQ_AVAIL(m->outq)));
+ used = MIN(MIDIQ_AVAIL(m->outq), uio->uio_resid);
+ used = MIN(used, MIDI_WSIZE);
+ MIDI_DEBUG(5, printf("midiout: resid %d len %jd avail %jd\n",
+ uio->uio_resid, (intmax_t)MIDIQ_LEN(m->outq),
+ (intmax_t)MIDIQ_AVAIL(m->outq)));
- MIDI_DEBUG(5,printf("midi_write: uiomove cc=%d\n", used));
- retval = uiomove(buf, used, uio);
- if (retval)
- goto err1;
- MIDIQ_ENQ(m->outq, buf, used);
- /*
- * Inform the bottom half that data can be written
- */
- if (!(m->flags & M_TXEN)) {
- m->flags |= M_TXEN;
- MPU_CALLBACK(m, m->cookie, m->flags);
- }
+ MIDI_DEBUG(5, printf("midi_write: uiomove cc=%d\n", used));
+ retval = uiomove(buf, used, uio);
+ if (retval)
+ goto err1;
+ MIDIQ_ENQ(m->outq, buf, used);
+ /*
+ * Inform the bottom half that data can be written
+ */
+ if (!(m->flags & M_TXEN)) {
+ m->flags |= M_TXEN;
+ MPU_CALLBACK(m, m->cookie, m->flags);
+ }
}
/*
* If we Made it here then transfer is good
@@ -873,19 +880,20 @@ err0: return retval;
}
int
-midi_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread * td)
+midi_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
+ struct thread *td)
{
return ENXIO;
}
int
-midi_poll(struct cdev *i_dev, int events, struct thread * td)
+midi_poll(struct cdev *i_dev, int events, struct thread *td)
{
struct snd_midi *m = i_dev->si_drv1;
- int revents;
+ int revents;
if (m == NULL)
- return 0;
+ return 0;
revents = 0;
@@ -893,19 +901,19 @@ midi_poll(struct cdev *i_dev, int events, struct thread * td)
mtx_lock(&m->qlock);
if (events & (POLLIN | POLLRDNORM))
- if (!MIDIQ_EMPTY(m->inq))
- events |= events & (POLLIN | POLLRDNORM);
+ if (!MIDIQ_EMPTY(m->inq))
+ events |= events & (POLLIN | POLLRDNORM);
if (events & (POLLOUT | POLLWRNORM))
- if (MIDIQ_AVAIL(m->outq) < m->hiwat)
- events |= events & (POLLOUT | POLLWRNORM);
+ if (MIDIQ_AVAIL(m->outq) < m->hiwat)
+ events |= events & (POLLOUT | POLLWRNORM);
if (revents == 0) {
- if (events & (POLLIN | POLLRDNORM))
- selrecord(td, &m->rsel);
+ if (events & (POLLIN | POLLRDNORM))
+ selrecord(td, &m->rsel);
- if (events & (POLLOUT | POLLWRNORM))
- selrecord(td, &m->wsel);
+ if (events & (POLLOUT | POLLWRNORM))
+ selrecord(td, &m->wsel);
}
mtx_unlock(&m->lock);
mtx_unlock(&m->qlock);
@@ -915,47 +923,46 @@ midi_poll(struct cdev *i_dev, int events, struct thread * td)
/*
* /dev/midistat device functions
- *
+ *
*/
static int
-midistat_open(struct cdev *i_dev, int flags, int mode, struct thread * td)
+midistat_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
{
- int error;
+ int error;
- MIDI_DEBUG(1,printf("midistat_open\n"));
+ MIDI_DEBUG(1, printf("midistat_open\n"));
mtx_lock(&midistat_lock);
if (midistat_isopen) {
- mtx_unlock(&midistat_lock);
- return EBUSY;
+ mtx_unlock(&midistat_lock);
+ return EBUSY;
}
midistat_isopen = 1;
mtx_unlock(&midistat_lock);
if (sbuf_new(&midistat_sbuf, NULL, 4096, SBUF_AUTOEXTEND) == NULL) {
- error = ENXIO;
- mtx_lock(&midistat_lock);
- goto out;
+ error = ENXIO;
+ mtx_lock(&midistat_lock);
+ goto out;
}
-
mtx_lock(&midistat_lock);
midistat_bufptr = 0;
error = (midistat_prepare(&midistat_sbuf) > 0) ? 0 : ENOMEM;
out: if (error)
- midistat_isopen = 0;
+ midistat_isopen = 0;
mtx_unlock(&midistat_lock);
return error;
}
static int
-midistat_close(struct cdev *i_dev, int flags, int mode, struct thread * td)
+midistat_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
{
- MIDI_DEBUG(1,printf("midistat_close\n"));
+ MIDI_DEBUG(1, printf("midistat_close\n"));
mtx_lock(&midistat_lock);
if (!midistat_isopen) {
- mtx_unlock(&midistat_lock);
- return EBADF;
+ mtx_unlock(&midistat_lock);
+ return EBADF;
}
sbuf_delete(&midistat_sbuf);
midistat_isopen = 0;
@@ -965,24 +972,25 @@ midistat_close(struct cdev *i_dev, int flags, int mode, struct thread * td)
}
static int
-midistat_read(struct cdev *i_dev, struct uio * buf, int flag)
+midistat_read(struct cdev *i_dev, struct uio *buf, int flag)
{
- int l, err;
+ int l, err;
- MIDI_DEBUG(4,printf("midistat_read\n"));
+ MIDI_DEBUG(4, printf("midistat_read\n"));
mtx_lock(&midistat_lock);
if (!midistat_isopen) {
- mtx_unlock(&midistat_lock);
- return EBADF;
+ mtx_unlock(&midistat_lock);
+ return EBADF;
}
l = min(buf->uio_resid, sbuf_len(&midistat_sbuf) - midistat_bufptr);
err = 0;
if (l > 0) {
- mtx_unlock(&midistat_lock);
- err = uiomove(sbuf_data(&midistat_sbuf) + midistat_bufptr, l, buf);
- mtx_lock(&midistat_lock);
+ mtx_unlock(&midistat_lock);
+ err = uiomove(sbuf_data(&midistat_sbuf) + midistat_bufptr, l,
+ buf);
+ mtx_lock(&midistat_lock);
} else
- l = 0;
+ l = 0;
midistat_bufptr += l;
mtx_unlock(&midistat_lock);
return err;
@@ -993,7 +1001,7 @@ midistat_read(struct cdev *i_dev, struct uio * buf, int flag)
*/
static int
-midistat_prepare(struct sbuf * s)
+midistat_prepare(struct sbuf *s)
{
struct snd_midi *m;
@@ -1001,19 +1009,19 @@ midistat_prepare(struct sbuf * s)
sbuf_printf(s, "FreeBSD Midi Driver (midi2)\n");
if (TAILQ_EMPTY(&midi_devs)) {
- sbuf_printf(s, "No devices installed.\n");
- sbuf_finish(s);
- return sbuf_len(s);
+ sbuf_printf(s, "No devices installed.\n");
+ sbuf_finish(s);
+ return sbuf_len(s);
}
sbuf_printf(s, "Installed devices:\n");
TAILQ_FOREACH(m, &midi_devs, link) {
- mtx_lock(&m->lock);
- sbuf_printf(s, "%s [%d/%d:%s]", m->name, m->unit, m->channel,
+ mtx_lock(&m->lock);
+ sbuf_printf(s, "%s [%d/%d:%s]", m->name, m->unit, m->channel,
MPU_PROVIDER(m, m->cookie));
- sbuf_printf(s, "%s", MPU_DESCR(m, m->cookie, midistat_verbose));
- sbuf_printf(s, "\n");
- mtx_unlock(&m->lock);
+ sbuf_printf(s, "%s", MPU_DESCR(m, m->cookie, midistat_verbose));
+ sbuf_printf(s, "\n");
+ mtx_unlock(&m->lock);
}
sbuf_finish(s);
@@ -1025,38 +1033,38 @@ midistat_prepare(struct sbuf * s)
* Convert IOCTL command to string for debugging
*/
-static char *
+static char *
midi_cmdname(int cmd)
{
static struct {
- int cmd;
- char *name;
- } *tab, cmdtab_midiioctl[] = {
+ int cmd;
+ char *name;
+ } *tab, cmdtab_midiioctl[] = {
#define A(x) {x, ## x}
- /*
- * Once we have some real IOCTLs define, the following will
- * be relavant.
- *
- * A(SNDCTL_MIDI_PRETIME), A(SNDCTL_MIDI_MPUMODE),
- * A(SNDCTL_MIDI_MPUCMD), A(SNDCTL_SYNTH_INFO),
- * A(SNDCTL_MIDI_INFO), A(SNDCTL_SYNTH_MEMAVL),
- * A(SNDCTL_FM_LOAD_INSTR), A(SNDCTL_FM_4OP_ENABLE),
- * A(MIOSPASSTHRU), A(MIOGPASSTHRU), A(AIONWRITE),
- * A(AIOGSIZE), A(AIOSSIZE), A(AIOGFMT), A(AIOSFMT),
- * A(AIOGMIX), A(AIOSMIX), A(AIOSTOP), A(AIOSYNC),
- * A(AIOGCAP),
- */
+ /*
+ * Once we have some real IOCTLs define, the following will
+ * be relavant.
+ *
+ * A(SNDCTL_MIDI_PRETIME), A(SNDCTL_MIDI_MPUMODE),
+ * A(SNDCTL_MIDI_MPUCMD), A(SNDCTL_SYNTH_INFO),
+ * A(SNDCTL_MIDI_INFO), A(SNDCTL_SYNTH_MEMAVL),
+ * A(SNDCTL_FM_LOAD_INSTR), A(SNDCTL_FM_4OP_ENABLE),
+ * A(MIOSPASSTHRU), A(MIOGPASSTHRU), A(AIONWRITE),
+ * A(AIOGSIZE), A(AIOSSIZE), A(AIOGFMT), A(AIOSFMT),
+ * A(AIOGMIX), A(AIOSMIX), A(AIOSTOP), A(AIOSYNC),
+ * A(AIOGCAP),
+ */
#undef A
- {
- -1, "unknown"
- },
+ {
+ -1, "unknown"
+ },
};
- for (tab = cmdtab_midiioctl; tab->cmd != cmd && tab->cmd != -1; tab++)
- ;
+ for (tab = cmdtab_midiioctl; tab->cmd != cmd && tab->cmd != -1; tab++);
return tab->name;
}
-#endif /* notdef */
+
+#endif /* notdef */
/*
* midisynth
@@ -1066,14 +1074,14 @@ midi_cmdname(int cmd)
int
midisynth_open(void *n, void *arg, int flags)
{
- struct snd_midi *m = ((struct synth_midi * ) n)->m;
- int retval;
+ struct snd_midi *m = ((struct synth_midi *)n)->m;
+ int retval;
- MIDI_DEBUG(1,printf("midisynth_open %s %s\n",
- flags & FREAD?"M_RX":"", flags & FWRITE?"M_TX":""));
+ MIDI_DEBUG(1, printf("midisynth_open %s %s\n",
+ flags & FREAD ? "M_RX" : "", flags & FWRITE ? "M_TX" : ""));
if (m == NULL)
- return ENXIO;
+ return ENXIO;
mtx_lock(&m->lock);
mtx_lock(&m->qlock);
@@ -1081,20 +1089,20 @@ midisynth_open(void *n, void *arg, int flags)
retval = 0;
if (flags & FREAD) {
- if (MIDIQ_SIZE(m->inq) == 0)
- retval = ENXIO;
- else if (m->flags & M_RX)
- retval = EBUSY;
- if (retval)
- goto err;
+ if (MIDIQ_SIZE(m->inq) == 0)
+ retval = ENXIO;
+ else if (m->flags & M_RX)
+ retval = EBUSY;
+ if (retval)
+ goto err;
}
if (flags & FWRITE) {
- if (MIDIQ_SIZE(m->outq) == 0)
- retval = ENXIO;
- else if (m->flags & M_TX)
- retval = EBUSY;
- if (retval)
- goto err;
+ if (MIDIQ_SIZE(m->outq) == 0)
+ retval = ENXIO;
+ else if (m->flags & M_TX)
+ retval = EBUSY;
+ if (retval)
+ goto err;
}
m->busy++;
@@ -1103,22 +1111,21 @@ midisynth_open(void *n, void *arg, int flags)
*/
if (flags & FREAD) {
- m->flags |= M_RX | M_RXEN;
- /*
- * Only clear the inq, the outq might still have data to drain from
- * a previous session
- */
- MIDIQ_CLEAR(m->inq);
- m->rchan = 0;
+ m->flags |= M_RX | M_RXEN;
+ /*
+ * Only clear the inq, the outq might still have data to drain
+ * from a previous session
+ */
+ MIDIQ_CLEAR(m->inq);
+ m->rchan = 0;
};
if (flags & FWRITE) {
- m->flags |= M_TX;
- m->wchan = 0;
+ m->flags |= M_TX;
+ m->wchan = 0;
}
-
m->synth_flags = flags & (FREAD | FWRITE);
-
+
MPU_CALLBACK(m, m->cookie, m->flags);
@@ -1132,35 +1139,34 @@ int
midisynth_close(void *n)
{
struct snd_midi *m = ((struct synth_midi *)n)->m;
- int retval;
- int oldflags;
+ int retval;
+ int oldflags;
MIDI_DEBUG(1, printf("midisynth_close %s %s\n",
- m->synth_flags & FREAD ? "M_RX" : "",
- m->synth_flags & FWRITE ? "M_TX" : ""));
+ m->synth_flags & FREAD ? "M_RX" : "",
+ m->synth_flags & FWRITE ? "M_TX" : ""));
if (m == NULL)
- return ENXIO;
+ return ENXIO;
mtx_lock(&m->lock);
mtx_lock(&m->qlock);
- if ( (m->synth_flags & FREAD && !(m->flags & M_RX)) ||
- (m->synth_flags & FWRITE && !(m->flags & M_TX)) ) {
- retval = ENXIO;
- goto err;
+ if ((m->synth_flags & FREAD && !(m->flags & M_RX)) ||
+ (m->synth_flags & FWRITE && !(m->flags & M_TX))) {
+ retval = ENXIO;
+ goto err;
}
-
m->busy--;
oldflags = m->flags;
if (m->synth_flags & FREAD)
- m->flags &= ~(M_RX | M_RXEN);
+ m->flags &= ~(M_RX | M_RXEN);
if (m->synth_flags & FWRITE)
- m->flags &= ~M_TX;
+ m->flags &= ~M_TX;
- if( (m->flags & (M_TXEN | M_RXEN)) != (oldflags & (M_RXEN | M_TXEN)) )
+ if ((m->flags & (M_TXEN | M_RXEN)) != (oldflags & (M_RXEN | M_TXEN)))
MPU_CALLBACK(m, m->cookie, m->flags);
MIDI_DEBUG(1, printf("midi_close: closed, busy = %d.\n", m->busy));
@@ -1178,83 +1184,85 @@ err: return retval;
int
midisynth_writeraw(void *n, uint8_t *buf, size_t len)
{
- struct snd_midi *m = ((struct synth_midi *)n)->m;
- int retval;
- int used;
+ struct snd_midi *m = ((struct synth_midi *)n)->m;
+ int retval;
+ int used;
int i;
- MIDI_DEBUG(4, printf("midisynth_writeraw\n"));
+ MIDI_DEBUG(4, printf("midisynth_writeraw\n"));
retval = 0;
if (m == NULL)
- return ENXIO;
+ return ENXIO;
mtx_lock(&m->lock);
mtx_lock(&m->qlock);
if (!(m->flags & M_TX))
- goto err1;
+ goto err1;
if (midi_dumpraw)
- printf("midi dump: ");
+ printf("midi dump: ");
while (len > 0) {
- while (MIDIQ_AVAIL(m->outq) == 0) {
- if (!(m->flags & M_TXEN)) {
- m->flags |= M_TXEN;
- MPU_CALLBACK(m, m->cookie, m->flags);
- }
- mtx_unlock(&m->lock);
- m->wchan = 1;
- MIDI_DEBUG(3,printf("midisynth_writeraw msleep\n"));
- retval = msleep(&m->wchan, &m->qlock,
- PCATCH | PDROP, "midi TX", 0);
+ while (MIDIQ_AVAIL(m->outq) == 0) {
+ if (!(m->flags & M_TXEN)) {
+ m->flags |= M_TXEN;
+ MPU_CALLBACK(m, m->cookie, m->flags);
+ }
+ mtx_unlock(&m->lock);
+ m->wchan = 1;
+ MIDI_DEBUG(3, printf("midisynth_writeraw msleep\n"));
+ retval = msleep(&m->wchan, &m->qlock,
+ PCATCH | PDROP, "midi TX", 0);
+ /*
+ * We slept, maybe things have changed since last
+ * dying check
+ */
+ if (retval == EINTR)
+ goto err0;
+
+ if (retval)
+ goto err0;
+ mtx_lock(&m->lock);
+ mtx_lock(&m->qlock);
+ m->wchan = 0;
+ if (!m->busy)
+ goto err1;
+ }
+
/*
- * We slept, maybe things have changed since last
- * dying check
- */
- if (retval == EINTR)
- goto err0;
+ * We are certain than data can be placed on the queue
+ */
- if (retval)
- goto err0;
- mtx_lock(&m->lock);
- mtx_lock(&m->qlock);
- m->wchan = 0;
- if (!m->busy)
- goto err1;
- }
-
- /*
- * We are certain than data can be placed on the queue
- */
-
- used = MIN(MIDIQ_AVAIL(m->outq), len);
- used = MIN(used, MIDI_WSIZE);
- MIDI_DEBUG(5,printf("midi_synth: resid %zu len %jd avail %jd\n",
- len, (intmax_t)MIDIQ_LEN(m->outq),
- (intmax_t)MIDIQ_AVAIL(m->outq)));
-
- if (midi_dumpraw)
- for(i=0;i<used;i++) printf("%x ", buf[i]);
-
- MIDIQ_ENQ(m->outq, buf, used);
- len -= used;
-
- /*
- * Inform the bottom half that data can be written
- */
- if (!(m->flags & M_TXEN)) {
- m->flags |= M_TXEN;
- MPU_CALLBACK(m, m->cookie, m->flags);
- }
+ used = MIN(MIDIQ_AVAIL(m->outq), len);
+ used = MIN(used, MIDI_WSIZE);
+ MIDI_DEBUG(5,
+ printf("midi_synth: resid %zu len %jd avail %jd\n",
+ len, (intmax_t)MIDIQ_LEN(m->outq),
+ (intmax_t)MIDIQ_AVAIL(m->outq)));
+
+ if (midi_dumpraw)
+ for (i = 0; i < used; i++)
+ printf("%x ", buf[i]);
+
+ MIDIQ_ENQ(m->outq, buf, used);
+ len -= used;
+
+ /*
+ * Inform the bottom half that data can be written
+ */
+ if (!(m->flags & M_TXEN)) {
+ m->flags |= M_TXEN;
+ MPU_CALLBACK(m, m->cookie, m->flags);
+ }
}
/*
* If we Made it here then transfer is good
*/
if (midi_dumpraw)
- printf("\n");
+ printf("\n");
retval = 0;
err1: mtx_unlock(&m->qlock);
@@ -1272,14 +1280,14 @@ midisynth_killnote(void *n, uint8_t chn, uint8_t note, uint8_t vel)
return (EINVAL);
if (vel > 127)
- vel = 127;
+ vel = 127;
if (vel == 64) {
- c[0] = 0x90 | (chn & 0x0f); /* Note on. */
+ c[0] = 0x90 | (chn & 0x0f); /* Note on. */
c[1] = (u_char)note;
c[2] = 0;
} else {
- c[0] = 0x80 | (chn & 0x0f); /* Note off. */
+ c[0] = 0x80 | (chn & 0x0f); /* Note off. */
c[1] = (u_char)note;
c[2] = (u_char)vel;
}
@@ -1295,7 +1303,7 @@ midisynth_setinstr(void *n, uint8_t chn, uint16_t instr)
if (instr > 127 || chn > 15)
return EINVAL;
- c[0] = 0xc0 | (chn & 0x0f); /* Progamme change. */
+ c[0] = 0xc0 | (chn & 0x0f); /* Progamme change. */
c[1] = instr + midi_instroff;
return midisynth_writeraw(n, c, 2);
@@ -1310,9 +1318,9 @@ midisynth_startnote(void *n, uint8_t chn, uint8_t note, uint8_t vel)
return EINVAL;
if (vel > 127)
- vel = 127;
+ vel = 127;
- c[0] = 0x90 | (chn & 0x0f); /* Note on. */
+ c[0] = 0x90 | (chn & 0x0f); /* Note on. */
c[1] = (u_char)note;
c[2] = (u_char)vel;
@@ -1330,9 +1338,9 @@ midisynth_controller(void *n, uint8_t chn, uint8_t ctrlnum, uint16_t val)
u_char c[3];
if (ctrlnum > 127 || chn > 15)
- return EINVAL;
+ return EINVAL;
- c[0] = 0xb0 | (chn & 0x0f); /* Control Message. */
+ c[0] = 0xb0 | (chn & 0x0f); /* Control Message. */
c[1] = ctrlnum;
c[2] = val;
return midisynth_writeraw(n, c, 3);
@@ -1345,9 +1353,9 @@ midisynth_bender(void *n, uint8_t chn, uint16_t val)
if (val > 16383 || chn > 15)
- return EINVAL;
+ return EINVAL;
- c[0] = 0xe0 | (chn & 0x0f); /* Pitch bend. */
+ c[0] = 0xe0 | (chn & 0x0f); /* Pitch bend. */
c[1] = (u_char)val & 0x7f;
c[2] = (u_char)(val >> 7) & 0x7f;
@@ -1358,18 +1366,18 @@ midisynth_bender(void *n, uint8_t chn, uint16_t val)
* Single point of midi destructions.
*/
static int
-midi_destroy(struct snd_midi * m, int midiuninit)
+midi_destroy(struct snd_midi *m, int midiuninit)
{
mtx_assert(&midistat_lock, MA_OWNED);
mtx_assert(&m->lock, MA_OWNED);
- MIDI_DEBUG(3,printf("midi_destroy\n"));
+ MIDI_DEBUG(3, printf("midi_destroy\n"));
m->dev->si_drv1 = NULL;
destroy_dev(m->dev);
TAILQ_REMOVE(&midi_devs, m, link);
if (midiuninit)
- MPU_UNINIT(m, m->cookie);
+ MPU_UNINIT(m, m->cookie);
free(MIDIQ_BUF(m->inq), M_MIDI);
free(MIDIQ_BUF(m->outq), M_MIDI);
mtx_destroy(&m->qlock);
@@ -1386,11 +1394,11 @@ static int
midi_load()
{
mtx_init(&midistat_lock, "midistat lock", 0, 0);
- TAILQ_INIT(&midi_devs); /* Initialize the queue. */
+ TAILQ_INIT(&midi_devs); /* Initialize the queue. */
midistat_dev = make_dev(&midistat_cdevsw,
- MIDIMKMINOR(0, MIDI_DEV_MIDICTL, 0),
- UID_ROOT, GID_WHEEL, 0666, "midistat");
+ MIDIMKMINOR(0, MIDI_DEV_MIDICTL, 0),
+ UID_ROOT, GID_WHEEL, 0666, "midistat");
return 0;
}
@@ -1399,22 +1407,22 @@ static int
midi_unload()
{
struct snd_midi *m;
- int retval;
+ int retval;
- MIDI_DEBUG(1,printf("midi_unload()\n"));
+ MIDI_DEBUG(1, printf("midi_unload()\n"));
retval = EBUSY;
mtx_lock(&midistat_lock);
if (midistat_isopen)
- goto exit0;
+ goto exit0;
TAILQ_FOREACH(m, &midi_devs, link) {
- mtx_lock(&m->lock);
- if (m->busy)
- retval = EBUSY;
- else
- retval = midi_destroy(m, 1);
- if (retval)
- goto exit1;
+ mtx_lock(&m->lock);
+ if (m->busy)
+ retval = EBUSY;
+ else
+ retval = midi_destroy(m, 1);
+ if (retval)
+ goto exit1;
}
destroy_dev(midistat_dev);
@@ -1428,7 +1436,8 @@ exit1:
mtx_unlock(&m->lock);
exit0:
mtx_unlock(&midistat_lock);
- if(retval) MIDI_DEBUG(2,printf("midi_unload: failed\n"));
+ if (retval)
+ MIDI_DEBUG(2, printf("midi_unload: failed\n"));
return retval;
}
@@ -1437,25 +1446,25 @@ extern int seq_modevent(module_t mod, int type, void *data);
static int
midi_modevent(module_t mod, int type, void *data)
{
- int retval;
+ int retval;
retval = 0;
switch (type) {
case MOD_LOAD:
- retval = midi_load();
- if (retval == 0)
- retval = seq_modevent(mod, type, data);
- break;
+ retval = midi_load();
+ if (retval == 0)
+ retval = seq_modevent(mod, type, data);
+ break;
case MOD_UNLOAD:
- retval = midi_unload();
- if (retval == 0)
- retval = seq_modevent(mod, type, data);
- break;
+ retval = midi_unload();
+ if (retval == 0)
+ retval = seq_modevent(mod, type, data);
+ break;
default:
- break;
+ break;
}
return retval;
@@ -1466,7 +1475,7 @@ midimapper_addseq(void *arg1, int *unit, void **cookie)
{
unit = 0;
- return (kobj_t) arg1;
+ return (kobj_t)arg1;
}
int
@@ -1475,14 +1484,14 @@ midimapper_open(void *arg1, void **cookie)
int retval = 0;
struct snd_midi *m;
- mtx_lock(&midistat_lock);
+ mtx_lock(&midistat_lock);
- TAILQ_FOREACH(m, &midi_devs, link) {
- retval++;
- }
+ TAILQ_FOREACH(m, &midi_devs, link) {
+ retval++;
+ }
- mtx_unlock(&midistat_lock);
- return retval;
+ mtx_unlock(&midistat_lock);
+ return retval;
}
int
@@ -1500,11 +1509,11 @@ midimapper_fetch_synth(void *arg, void *cookie, int unit)
mtx_lock(&midistat_lock);
TAILQ_FOREACH(m, &midi_devs, link) {
- if (unit == retval) {
- mtx_unlock(&midistat_lock);
- return (kobj_t)m->synth;
- }
- retval++;
+ if (unit == retval) {
+ mtx_unlock(&midistat_lock);
+ return (kobj_t)m->synth;
+ }
+ retval++;
}
mtx_unlock(&midistat_lock);
diff --git a/sys/dev/sound/midi/midi.h b/sys/dev/sound/midi/midi.h
index 3eee732..c694b7b 100644
--- a/sys/dev/sound/midi/midi.h
+++ b/sys/dev/sound/midi/midi.h
@@ -43,15 +43,15 @@ MALLOC_DECLARE(M_MIDI);
struct snd_midi;
-struct snd_midi *midi_init(kobj_class_t _mpu_cls, int _unit, int _channel,
- void *cookie);
-int midi_uninit(struct snd_midi * _m);
-int midi_out(struct snd_midi * _m, MIDI_TYPE * _buf, int _size);
-int midi_in(struct snd_midi * _m, MIDI_TYPE * _buf, int _size);
-
-kobj_t midimapper_addseq(void *arg1, int *unit, void **cookie);
-int midimapper_open(void *arg1, void **cookie);
-int midimapper_close(void *arg1, void *cookie);
-kobj_t midimapper_fetch_synth(void *arg, void *cookie, int unit);
+struct snd_midi *
+midi_init(kobj_class_t _mpu_cls, int _unit, int _channel, void *cookie);
+int midi_uninit(struct snd_midi *_m);
+int midi_out(struct snd_midi *_m, MIDI_TYPE *_buf, int _size);
+int midi_in(struct snd_midi *_m, MIDI_TYPE *_buf, int _size);
+
+kobj_t midimapper_addseq(void *arg1, int *unit, void **cookie);
+int midimapper_open(void *arg1, void **cookie);
+int midimapper_close(void *arg1, void *cookie);
+kobj_t midimapper_fetch_synth(void *arg, void *cookie, int unit);
#endif
diff --git a/sys/dev/sound/midi/midiq.h b/sys/dev/sound/midi/midiq.h
index b5f4fcf..6b30175 100644
--- a/sys/dev/sound/midi/midiq.h
+++ b/sys/dev/sound/midi/midiq.h
@@ -35,7 +35,7 @@
struct name { \
int h, t, s; \
type * b; \
-}
+}
#define MIDIQ_INIT(head, buf, size) do { \
(head).h=(head).t=0; \
diff --git a/sys/dev/sound/midi/mpu401.c b/sys/dev/sound/midi/mpu401.c
index 468ee7a..14f2212 100644
--- a/sys/dev/sound/midi/mpu401.c
+++ b/sys/dev/sound/midi/mpu401.c
@@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/kobj.h>
#include <sys/malloc.h>
-#include <sys/bus.h> /* to get driver_intr_t */
+#include <sys/bus.h> /* to get driver_intr_t */
#include <dev/sound/midi/mpu401.h>
#include <dev/sound/midi/midi.h>
@@ -66,13 +66,13 @@ __FBSDID("$FreeBSD$");
struct mpu401 {
KOBJ_FIELDS;
struct snd_midi *mid;
- int flags;
+ int flags;
driver_intr_t *si;
- void *cookie;
+ void *cookie;
struct callout timer;
};
-static void mpu401_timeout(void *m) ;
+static void mpu401_timeout(void *m);
static mpu401_intr_t mpu401_intr;
static int mpu401_minit(kobj_t obj, struct mpu401 *m);
@@ -85,22 +85,23 @@ static const char *mpu401_mdescr(kobj_t obj, struct mpu401 *m, int verbosity);
static const char *mpu401_mprovider(kobj_t obj, struct mpu401 *m);
static kobj_method_t mpu401_methods[] = {
- KOBJMETHOD(mpu_init,mpu401_minit),
- KOBJMETHOD(mpu_uninit,mpu401_muninit),
- KOBJMETHOD(mpu_inqsize,mpu401_minqsize),
- KOBJMETHOD(mpu_outqsize,mpu401_moutqsize),
- KOBJMETHOD(mpu_callback,mpu401_mcallback),
- KOBJMETHOD(mpu_callbackp,mpu401_mcallbackp),
- KOBJMETHOD(mpu_descr,mpu401_mdescr),
- KOBJMETHOD(mpu_provider,mpu401_mprovider),
- { 0, 0 }
+ KOBJMETHOD(mpu_init, mpu401_minit),
+ KOBJMETHOD(mpu_uninit, mpu401_muninit),
+ KOBJMETHOD(mpu_inqsize, mpu401_minqsize),
+ KOBJMETHOD(mpu_outqsize, mpu401_moutqsize),
+ KOBJMETHOD(mpu_callback, mpu401_mcallback),
+ KOBJMETHOD(mpu_callbackp, mpu401_mcallbackp),
+ KOBJMETHOD(mpu_descr, mpu401_mdescr),
+ KOBJMETHOD(mpu_provider, mpu401_mprovider),
+ {0, 0}
};
DEFINE_CLASS(mpu401, mpu401_methods, 0);
void
-mpu401_timeout(void *a)
-{ struct mpu401 *m=(struct mpu401 *)a;
+mpu401_timeout(void *a)
+{
+ struct mpu401 *m = (struct mpu401 *)a;
if (m->si)
(m->si)(m->cookie);
@@ -113,6 +114,7 @@ mpu401_intr(struct mpu401 *m)
MIDI_TYPE b[MPU_INTR_BUF];
int i;
int s;
+
/*
printf("mpu401_intr\n");
*/
@@ -123,54 +125,54 @@ mpu401_intr(struct mpu401 *m)
#else
#define D(x,l)
#endif
- i=0;
+ i = 0;
s = STATUS(m);
- D(s,1);
- while ( (s&MPU_INPUTBUSY) == 0 && i<MPU_INTR_BUF) {
- b[i]=READ(m);
+ D(s, 1);
+ while ((s & MPU_INPUTBUSY) == 0 && i < MPU_INTR_BUF) {
+ b[i] = READ(m);
/*
printf("mpu401_intr in i %d d %d\n", i, b[i]);
*/
i++;
- s = STATUS(m);
+ s = STATUS(m);
}
- if (i) midi_in(m->mid, b, i);
- i=0;
- while ( !(s&MPU_OUTPUTBUSY) && i<MPU_INTR_BUF) {
- if(midi_out(m->mid, b, 1)) {
+ if (i)
+ midi_in(m->mid, b, i);
+ i = 0;
+ while (!(s & MPU_OUTPUTBUSY) && i < MPU_INTR_BUF) {
+ if (midi_out(m->mid, b, 1)) {
/*
printf("mpu401_intr out i %d d %d\n", i, b[0]);
*/
-
+
WRITE(m, *b);
- }
- else {
+ } else {
/*
printf("mpu401_intr write: no output\n");
*/
return 0;
}
i++;
- /* DELAY(100); */
- s = STATUS(m);
+ /* DELAY(100); */
+ s = STATUS(m);
}
- if ((m->flags & M_TXEN) && (m->si) ) {
- callout_reset(&m->timer, 1, mpu401_timeout, m);
+ if ((m->flags & M_TXEN) && (m->si)) {
+ callout_reset(&m->timer, 1, mpu401_timeout, m);
}
-
return (m->flags & M_TXEN) == M_TXEN;
}
struct mpu401 *
-mpu401_init(kobj_class_t cls, void *cookie,driver_intr_t softintr, mpu401_intr_t **cb)
+mpu401_init(kobj_class_t cls, void *cookie, driver_intr_t softintr,
+ mpu401_intr_t ** cb)
{
struct mpu401 *m;
*cb = NULL;
m = malloc(sizeof(*m), M_MIDI, M_NOWAIT | M_ZERO);
- if(!m)
+ if (!m)
return NULL;
kobj_init((kobj_t)m, cls);
@@ -181,7 +183,7 @@ mpu401_init(kobj_class_t cls, void *cookie,driver_intr_t softintr, mpu401_intr_t
m->cookie = cookie;
m->flags = 0;
- m->mid = midi_init(&mpu401_class,0,0,m);
+ m->mid = midi_init(&mpu401_class, 0, 0, m);
if (!m->mid)
goto err;
*cb = mpu401_intr;
@@ -213,14 +215,14 @@ mpu401_minit(kobj_t obj, struct mpu401 *m)
CMD(m, MPU_RESET);
CMD(m, MPU_UART);
return 0;
- i=0;
- while(++i<2000) {
- if(RXRDY(m))
- if(READ(m) == MPU_ACK)
+ i = 0;
+ while (++i < 2000) {
+ if (RXRDY(m))
+ if (READ(m) == MPU_ACK)
break;
}
- if( i < 2000 ) {
+ if (i < 2000) {
CMD(m, MPU_UART);
return 0;
}
@@ -252,16 +254,15 @@ static void
mpu401_mcallback(kobj_t obj, struct mpu401 *m, int flags)
{
#if 0
- printf("mpu401_callback %s %s %s %s\n",
- flags & M_RX ? "M_RX" : "",
- flags & M_TX ? "M_TX" : "",
- flags & M_RXEN ? "M_RXEN" : "",
- flags & M_TXEN ? "M_TXEN" : "" );
+ printf("mpu401_callback %s %s %s %s\n",
+ flags & M_RX ? "M_RX" : "",
+ flags & M_TX ? "M_TX" : "",
+ flags & M_RXEN ? "M_RXEN" : "",
+ flags & M_TXEN ? "M_TXEN" : "");
#endif
if (flags & M_TXEN && m->si) {
callout_reset(&m->timer, 1, mpu401_timeout, m);
}
-
m->flags = flags;
}
diff --git a/sys/dev/sound/midi/mpu401.h b/sys/dev/sound/midi/mpu401.h
index 7c49e74..9ac99a6 100644
--- a/sys/dev/sound/midi/mpu401.h
+++ b/sys/dev/sound/midi/mpu401.h
@@ -31,9 +31,11 @@
struct mpu401;
-typedef int mpu401_intr_t(struct mpu401 * _obj);
+typedef int mpu401_intr_t(struct mpu401 *_obj);
+
+extern struct mpu401 *
+mpu401_init(kobj_class_t _cls, void *cookie, driver_intr_t *_softintr,
+ mpu401_intr_t ** _cb);
+extern int mpu401_uninit(struct mpu401 *_obj);
-extern struct mpu401 *mpu401_init(kobj_class_t _cls, void *cookie,
- driver_intr_t *_softintr,mpu401_intr_t **_cb);
-extern int mpu401_uninit(struct mpu401 * _obj);
#endif
diff --git a/sys/dev/sound/midi/mpu_if.m b/sys/dev/sound/midi/mpu_if.m
index 5edb0ad..2db606e 100644
--- a/sys/dev/sound/midi/mpu_if.m
+++ b/sys/dev/sound/midi/mpu_if.m
@@ -30,45 +30,45 @@
INTERFACE mpu;
-METHOD int inqsize{
- struct snd_midi * _kobj;
- void *_cookie;
+METHOD int inqsize {
+ struct snd_midi *_kobj;
+ void *_cookie;
};
METHOD int outqsize {
- struct snd_midi * _kobj;
- void *_cookie;
+ struct snd_midi *_kobj;
+ void *_cookie;
};
METHOD int init {
- struct snd_midi * _kobj;
- void *_cookie;
+ struct snd_midi *_kobj;
+ void *_cookie;
};
METHOD void callbackp {
- struct snd_midi * _kobj;
- void *_cookie;
- int _flags;
+ struct snd_midi *_kobj;
+ void *_cookie;
+ int _flags;
};
-METHOD void callback {
- struct snd_midi * _kobj;
- void *_cookie;
- int _flags;
+METHOD void callback {
+ struct snd_midi *_kobj;
+ void *_cookie;
+ int _flags;
};
-METHOD const char * provider{
- struct snd_midi * _kobj;
- void *_cookie;
+METHOD const char * provider {
+ struct snd_midi *_kobj;
+ void *_cookie;
};
-METHOD const char * descr {
- struct snd_midi * _kobj;
- void *_cookie;
- int _verbosity;
+METHOD const char * descr {
+ struct snd_midi *_kobj;
+ void *_cookie;
+ int _verbosity;
};
-METHOD int uninit {
- struct snd_midi * _kobj;
- void *_cookie;
+METHOD int uninit {
+ struct snd_midi *_kobj;
+ void *_cookie;
};
diff --git a/sys/dev/sound/midi/mpufoi_if.m b/sys/dev/sound/midi/mpufoi_if.m
index 0941ab4..299b7f9 100644
--- a/sys/dev/sound/midi/mpufoi_if.m
+++ b/sys/dev/sound/midi/mpufoi_if.m
@@ -33,18 +33,18 @@ INTERFACE mpufoi;
METHOD unsigned char read {
struct mpu401 *_kobj;
- void *_cookie;
- int _reg;
+ void *_cookie;
+ int _reg;
};
METHOD void write {
struct mpu401 *_kobj;
- void *_cookie;
- int _reg;
+ void *_cookie;
+ int _reg;
unsigned char _d;
};
METHOD int uninit {
struct mpu401 *_kobj;
- void *_cookie;
+ void *_cookie;
};
diff --git a/sys/dev/sound/midi/sequencer.c b/sys/dev/sound/midi/sequencer.c
index 030cd82..6af7662 100644
--- a/sys/dev/sound/midi/sequencer.c
+++ b/sys/dev/sound/midi/sequencer.c
@@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/sysctl.h>
-#include <sys/kernel.h> /* for DATA_SET */
+#include <sys/kernel.h> /* for DATA_SET */
#include <sys/module.h>
#include <sys/conf.h>
@@ -56,7 +56,7 @@ __FBSDID("$FreeBSD$");
#include <sys/bus.h>
#include <machine/resource.h>
#include <machine/bus.h>
-#include <machine/clock.h> /* for DELAY */
+#include <machine/clock.h> /* for DELAY */
#include <sys/soundcard.h>
#include <sys/rman.h>
#include <sys/mman.h>
@@ -76,9 +76,9 @@ __FBSDID("$FreeBSD$");
#define TMR_TIMERBASE 13
-#define SND_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM
- synthesizer and MIDI output) */
-#define SND_DEV_MUSIC 8 /* /dev/music, level 2 interface */
+#define SND_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM
+ * synthesizer and MIDI output) */
+#define SND_DEV_MUSIC 8 /* /dev/music, level 2 interface */
/* Length of a sequencer event. */
#define EV_SZ 8
@@ -105,13 +105,13 @@ static d_poll_t seq_poll;
static struct cdevsw seq_cdevsw = {
.d_version = D_VERSION,
- .d_open = seq_open,
- .d_close = seq_close,
- .d_read = seq_read,
- .d_write = seq_write,
- .d_ioctl = seq_ioctl,
- .d_poll = seq_poll,
- .d_name = "sequencer",
+ .d_open = seq_open,
+ .d_close = seq_close,
+ .d_read = seq_read,
+ .d_write = seq_write,
+ .d_ioctl = seq_ioctl,
+ .d_poll = seq_poll,
+ .d_name = "sequencer",
};
struct seq_softc {
@@ -122,32 +122,32 @@ struct seq_softc {
MIDIQ_HEAD(, u_char) in_q, out_q;
- u_long flags;
+ u_long flags;
/* Flags (protected by flag_mtx of mididev_info) */
- int fflags; /* Access mode */
- int music;
+ int fflags; /* Access mode */
+ int music;
- int out_water; /* Sequence output threshould */
- snd_sync_parm sync_parm; /* AIOSYNC parameter set */
- struct thread *sync_thread; /* AIOSYNCing thread */
+ int out_water; /* Sequence output threshould */
+ snd_sync_parm sync_parm; /* AIOSYNC parameter set */
+ struct thread *sync_thread; /* AIOSYNCing thread */
struct selinfo in_sel, out_sel;
- int midi_number;
+ int midi_number;
struct cdev *seqdev, *musicdev;
- int unit;
- int maxunits;
+ int unit;
+ int maxunits;
kobj_t *midis;
- int *midi_flags;
- kobj_t mapper;
- void *mapper_cookie;
+ int *midi_flags;
+ kobj_t mapper;
+ void *mapper_cookie;
struct timeval timerstop, timersub;
- int timerbase, tempo;
- int timerrun;
- int done;
- int playing;
- int recording;
- int busy;
- int pre_event_timeout;
- int waiting;
+ int timerbase, tempo;
+ int timerrun;
+ int done;
+ int playing;
+ int recording;
+ int busy;
+ int pre_event_timeout;
+ int waiting;
};
/*
@@ -265,33 +265,35 @@ midi_cmdtab cmdtab_seqccmn[] = {
static kobj_method_t seq_methods[] = {
/* KOBJMETHOD(mpu_provider,mpu401_mprovider), */
- { 0, 0 }
+ {0, 0}
};
+
DEFINE_CLASS(sequencer, seq_methods, 0);
/* The followings are the local function. */
static int seq_convertold(u_char *event, u_char *out);
+
/*
* static void seq_midiinput(struct seq_softc * scp, void *md);
*/
-static void seq_reset(struct seq_softc * scp);
-static int seq_sync(struct seq_softc * scp);
+static void seq_reset(struct seq_softc *scp);
+static int seq_sync(struct seq_softc *scp);
-static int seq_processevent(struct seq_softc * scp, u_char *event);
+static int seq_processevent(struct seq_softc *scp, u_char *event);
-static int seq_timing(struct seq_softc * scp, u_char *event);
-static int seq_local(struct seq_softc * scp, u_char *event);
+static int seq_timing(struct seq_softc *scp, u_char *event);
+static int seq_local(struct seq_softc *scp, u_char *event);
-static int seq_chnvoice(struct seq_softc * scp, kobj_t md, u_char *event);
-static int seq_chncommon(struct seq_softc * scp, kobj_t md, u_char *event);
-static int seq_sysex(struct seq_softc * scp, kobj_t md, u_char *event);
+static int seq_chnvoice(struct seq_softc *scp, kobj_t md, u_char *event);
+static int seq_chncommon(struct seq_softc *scp, kobj_t md, u_char *event);
+static int seq_sysex(struct seq_softc *scp, kobj_t md, u_char *event);
static int seq_fetch_mid(struct seq_softc *scp, int unit, kobj_t *md);
-void seq_copytoinput(struct seq_softc *scp, u_char *event, int len);
-int seq_modevent(module_t mod, int type, void *data);
+void seq_copytoinput(struct seq_softc *scp, u_char *event, int len);
+int seq_modevent(module_t mod, int type, void *data);
struct seq_softc *seqs[10];
-static struct mtx seqinfo_mtx;
-static u_long nseq = 0;
+static struct mtx seqinfo_mtx;
+static u_long nseq = 0;
static void timer_start(struct seq_softc *t);
static void timer_stop(struct seq_softc *t);
@@ -313,7 +315,7 @@ timer_continue(struct seq_softc *t)
struct timeval now;
if (t->timerrun == 1)
- return;
+ return;
t->timerrun = 1;
getmicrotime(&now);
timevalsub(&now, &t->timerstop);
@@ -342,16 +344,16 @@ timer_wait(struct seq_softc *t, int ticks, int wait_abs)
unsigned long long i;
while (t->timerrun == 0) {
- SEQ_DEBUG(2,printf("Timer wait when timer isn't running\n"));
- /*
- * The old sequencer used timeouts that only increased
- * the timer when the timer was running.
- * Hence the sequencer would stick (?) if the
- * timer was disabled.
- */
- cv_wait(&t->reset_cv, &t->seq_lock);
- if (t->playing == 0)
- return;
+ SEQ_DEBUG(2, printf("Timer wait when timer isn't running\n"));
+ /*
+ * The old sequencer used timeouts that only increased
+ * the timer when the timer was running.
+ * Hence the sequencer would stick (?) if the
+ * timer was disabled.
+ */
+ cv_wait(&t->reset_cv, &t->seq_lock);
+ if (t->playing == 0)
+ return;
}
i = ticks * 60ull * 1000000ull / (t->tempo * t->timerbase);
@@ -360,34 +362,35 @@ timer_wait(struct seq_softc *t, int ticks, int wait_abs)
when.tv_usec = i % 1000000;
#if 0
- printf("timer_wait tempo %d timerbase %d ticks %d abs %d u_sec %llu\n", t->tempo, t->timerbase, ticks, wait_abs, i);
+ printf("timer_wait tempo %d timerbase %d ticks %d abs %d u_sec %llu\n",
+ t->tempo, t->timerbase, ticks, wait_abs, i);
#endif
if (wait_abs != 0) {
- getmicrotime(&now);
- timevalsub(&now, &t->timersub);
- timevalsub(&when, &now);
+ getmicrotime(&now);
+ timevalsub(&now, &t->timersub);
+ timevalsub(&when, &now);
}
-
if (when.tv_sec < 0 || when.tv_usec < 0) {
- SEQ_DEBUG(3,printf("seq_timer error negative time %lds.%06lds\n",
- (long)when.tv_sec,(long)when.tv_usec));
- return;
+ SEQ_DEBUG(3,
+ printf("seq_timer error negative time %lds.%06lds\n",
+ (long)when.tv_sec, (long)when.tv_usec));
+ return;
}
-
i = when.tv_sec * 1000000ull;
i += when.tv_usec;
i *= hz;
i /= 1000000ull;
#if 0
- printf("seq_timer usec %llu ticks %llu\n", when.tv_sec * 1000000ull + when.tv_usec, i);
+ printf("seq_timer usec %llu ticks %llu\n",
+ when.tv_sec * 1000000ull + when.tv_usec, i);
#endif
t->waiting = 1;
ret = cv_timedwait(&t->reset_cv, &t->seq_lock, i + 1);
t->waiting = 0;
if (ret != EWOULDBLOCK)
- SEQ_DEBUG(3,printf("seq_timer didn't timeout\n"));
+ SEQ_DEBUG(3, printf("seq_timer didn't timeout\n"));
}
@@ -399,9 +402,9 @@ timer_now(struct seq_softc *t)
int ret;
if (t->timerrun == 0)
- now = t->timerstop;
+ now = t->timerstop;
else
- getmicrotime(&now);
+ getmicrotime(&now);
timevalsub(&now, &t->timersub);
@@ -426,39 +429,38 @@ seq_eventthread(void *arg)
char event[EV_SZ];
mtx_lock(&scp->seq_lock);
- SEQ_DEBUG(2,printf("seq_eventthread started\n"));
- while(scp->done == 0) {
+ SEQ_DEBUG(2, printf("seq_eventthread started\n"));
+ while (scp->done == 0) {
restart:
- while (scp->playing == 0) {
- cv_wait(&scp->state_cv, &scp->seq_lock);
- if (scp->done)
- goto done;
- }
-
- while (MIDIQ_EMPTY(scp->out_q)) {
- cv_broadcast(&scp->empty_cv);
- cv_wait(&scp->out_cv, &scp->seq_lock);
- if (scp->playing == 0)
- goto restart;
- if (scp->done)
- goto done;
- }
-
- MIDIQ_DEQ(scp->out_q, event, EV_SZ);
-
- if (MIDIQ_AVAIL(scp->out_q) < scp->out_water) {
- cv_broadcast(&scp->out_cv);
- selwakeup(&scp->out_sel);
- }
+ while (scp->playing == 0) {
+ cv_wait(&scp->state_cv, &scp->seq_lock);
+ if (scp->done)
+ goto done;
+ }
+
+ while (MIDIQ_EMPTY(scp->out_q)) {
+ cv_broadcast(&scp->empty_cv);
+ cv_wait(&scp->out_cv, &scp->seq_lock);
+ if (scp->playing == 0)
+ goto restart;
+ if (scp->done)
+ goto done;
+ }
- seq_processevent(scp, event);
+ MIDIQ_DEQ(scp->out_q, event, EV_SZ);
+
+ if (MIDIQ_AVAIL(scp->out_q) < scp->out_water) {
+ cv_broadcast(&scp->out_cv);
+ selwakeup(&scp->out_sel);
+ }
+ seq_processevent(scp, event);
}
done:
cv_broadcast(&scp->th_cv);
mtx_unlock(&scp->seq_lock);
mtx_lock(&Giant);
- SEQ_DEBUG(2,printf("seq_eventthread finished\n"));
+ SEQ_DEBUG(2, printf("seq_eventthread finished\n"));
kthread_exit(0);
}
@@ -479,16 +481,19 @@ seq_processevent(struct seq_softc *scp, u_char *event)
else if (event[0] == EV_TIMING)
ret = seq_timing(scp, event);
else if (event[0] != EV_CHN_VOICE &&
- event[0] != EV_CHN_COMMON &&
- event[0] != EV_SYSEX &&
- event[0] != SEQ_MIDIPUTC) {
+ event[0] != EV_CHN_COMMON &&
+ event[0] != EV_SYSEX &&
+ event[0] != SEQ_MIDIPUTC) {
ret = 1;
- SEQ_DEBUG(2,printf("seq_processevent not known %d\n", event[0]));
+ SEQ_DEBUG(2, printf("seq_processevent not known %d\n",
+ event[0]));
} else if (seq_fetch_mid(scp, event[1], &m) != 0) {
ret = 1;
- SEQ_DEBUG(2,printf("seq_processevent midi unit not found %d\n", event[1]));
- } else switch(event[0]) {
- case EV_CHN_VOICE:
+ SEQ_DEBUG(2, printf("seq_processevent midi unit not found %d\n",
+ event[1]));
+ } else
+ switch (event[0]) {
+ case EV_CHN_VOICE:
ret = seq_chnvoice(scp, m, event);
break;
case EV_CHN_COMMON:
@@ -502,7 +507,7 @@ seq_processevent(struct seq_softc *scp, u_char *event)
ret = SYNTH_WRITERAW(m, &event[2], 1);
mtx_lock(&scp->seq_lock);
break;
- }
+ }
return ret;
}
@@ -517,27 +522,27 @@ seq_addunit(void)
ret = ENOMEM;
scp = malloc(sizeof(*scp), M_DEVBUF, M_NOWAIT | M_ZERO);
if (scp == NULL) {
- SEQ_DEBUG(1,printf("seq_addunit: softc allocation failed.\n"));
+ SEQ_DEBUG(1, printf("seq_addunit: softc allocation failed.\n"));
goto err;
}
- kobj_init((kobj_t) scp, &sequencer_class);
+ kobj_init((kobj_t)scp, &sequencer_class);
buf = malloc(sizeof(*buf) * EV_SZ * 1024, M_TEMP, M_NOWAIT | M_ZERO);
if (buf == NULL)
- goto err;
+ goto err;
MIDIQ_INIT(scp->in_q, buf, EV_SZ * 1024);
buf = malloc(sizeof(*buf) * EV_SZ * 1024, M_TEMP, M_NOWAIT | M_ZERO);
if (buf == NULL)
- goto err;
+ goto err;
MIDIQ_INIT(scp->out_q, buf, EV_SZ * 1024);
ret = EINVAL;
scp->midis = malloc(sizeof(kobj_t) * 32, M_TEMP, M_NOWAIT | M_ZERO);
scp->midi_flags = malloc(sizeof(*scp->midi_flags) * 32, M_TEMP,
- M_NOWAIT | M_ZERO);
+ M_NOWAIT | M_ZERO);
- if ( scp->midis == NULL || scp->midi_flags == NULL)
- goto err;
+ if (scp->midis == NULL || scp->midi_flags == NULL)
+ goto err;
scp->flags = 0;
@@ -555,57 +560,58 @@ seq_addunit(void)
scp->mapper = midimapper_addseq(scp, &scp->unit, &scp->mapper_cookie);
if (scp->mapper == NULL)
- goto err;
+ goto err;
scp->seqdev = make_dev(&seq_cdevsw,
- MIDIMKMINOR(scp->unit, SND_DEV_SEQ,0), UID_ROOT,
- GID_WHEEL, 0666, "sequencer%d", scp->unit);
+ MIDIMKMINOR(scp->unit, SND_DEV_SEQ, 0), UID_ROOT,
+ GID_WHEEL, 0666, "sequencer%d", scp->unit);
scp->musicdev = make_dev(&seq_cdevsw,
- MIDIMKMINOR(scp->unit, SND_DEV_MUSIC,0), UID_ROOT,
- GID_WHEEL, 0666, "music%d", scp->unit);
+ MIDIMKMINOR(scp->unit, SND_DEV_MUSIC, 0), UID_ROOT,
+ GID_WHEEL, 0666, "music%d", scp->unit);
if (scp->seqdev == NULL || scp->musicdev == NULL)
- goto err;
+ goto err;
/*
* TODO: Add to list of sequencers this module provides
*/
- ret = kthread_create(seq_eventthread, scp, NULL, RFHIGHPID, 0, "sequencer %02d", scp->unit);
+ ret = kthread_create(seq_eventthread, scp, NULL, RFHIGHPID, 0,
+ "sequencer %02d", scp->unit);
if (ret)
- goto err;
+ goto err;
scp->seqdev->si_drv1 = scp->musicdev->si_drv1 = scp;
- SEQ_DEBUG(2,printf("sequencer %d created scp %p\n", scp->unit, scp));
+ SEQ_DEBUG(2, printf("sequencer %d created scp %p\n", scp->unit, scp));
ret = 0;
mtx_lock(&seqinfo_mtx);
- seqs[nseq++]=scp;
+ seqs[nseq++] = scp;
mtx_unlock(&seqinfo_mtx);
goto ok;
err:
if (scp != NULL) {
- if (scp->seqdev != NULL)
- destroy_dev(scp->seqdev);
- if (scp->musicdev != NULL)
- destroy_dev(scp->musicdev);
- /*
- * TODO: Destroy mutex and cv
- */
- if (scp->midis != NULL)
- free(scp->midis, M_TEMP);
- if (scp->midi_flags != NULL)
- free(scp->midi_flags, M_TEMP);
- if (scp->out_q.b)
- free(scp->out_q.b, M_TEMP);
- if (scp->in_q.b)
- free(scp->in_q.b, M_TEMP);
- free(scp, M_DEVBUF);
+ if (scp->seqdev != NULL)
+ destroy_dev(scp->seqdev);
+ if (scp->musicdev != NULL)
+ destroy_dev(scp->musicdev);
+ /*
+ * TODO: Destroy mutex and cv
+ */
+ if (scp->midis != NULL)
+ free(scp->midis, M_TEMP);
+ if (scp->midi_flags != NULL)
+ free(scp->midi_flags, M_TEMP);
+ if (scp->out_q.b)
+ free(scp->out_q.b, M_TEMP);
+ if (scp->in_q.b)
+ free(scp->in_q.b, M_TEMP);
+ free(scp, M_DEVBUF);
}
ok:
return ret;
@@ -617,7 +623,7 @@ seq_delunit(int unit)
struct seq_softc *scp = seqs[unit];
int i;
- //SEQ_DEBUG(4,printf("seq_delunit: %d\n", unit));
+ //SEQ_DEBUG(4, printf("seq_delunit: %d\n", unit));
SEQ_DEBUG(1, printf("seq_delunit: 1 \n"));
mtx_lock(&scp->seq_lock);
@@ -646,17 +652,17 @@ seq_delunit(int unit)
SEQ_DEBUG(1, printf("seq_delunit: 10 \n"));
if (scp->seqdev)
- destroy_dev(scp->seqdev);
+ destroy_dev(scp->seqdev);
SEQ_DEBUG(1, printf("seq_delunit: 11 \n"));
if (scp->musicdev)
- destroy_dev(scp->musicdev);
+ destroy_dev(scp->musicdev);
SEQ_DEBUG(1, printf("seq_delunit: 12 \n"));
scp->seqdev = scp->musicdev = NULL;
if (scp->midis != NULL)
- free(scp->midis, M_TEMP);
+ free(scp->midis, M_TEMP);
SEQ_DEBUG(1, printf("seq_delunit: 13 \n"));
if (scp->midi_flags != NULL)
- free(scp->midi_flags, M_TEMP);
+ free(scp->midi_flags, M_TEMP);
SEQ_DEBUG(1, printf("seq_delunit: 14 \n"));
free(scp->out_q.b, M_TEMP);
SEQ_DEBUG(1, printf("seq_delunit: 15 \n"));
@@ -669,8 +675,8 @@ seq_delunit(int unit)
free(scp, M_DEVBUF);
mtx_lock(&seqinfo_mtx);
- for ( i = unit ; i < (nseq - 1) ; i++ )
- seqs[i] = seqs[i+1];
+ for (i = unit; i < (nseq - 1); i++)
+ seqs[i] = seqs[i + 1];
nseq--;
mtx_unlock(&seqinfo_mtx);
@@ -685,26 +691,26 @@ seq_modevent(module_t mod, int type, void *data)
retval = 0;
switch (type) {
- case MOD_LOAD:
+ case MOD_LOAD:
mtx_init(&seqinfo_mtx, "seqmod", 0, 0);
retval = seq_addunit();
break;
- case MOD_UNLOAD:
+ case MOD_UNLOAD:
while (nseq) {
- r=seq_delunit(nseq-1);
+ r = seq_delunit(nseq - 1);
if (r) {
retval = r;
break;
}
}
- if(nseq == 0) {
+ if (nseq == 0) {
retval = 0;
mtx_destroy(&seqinfo_mtx);
}
break;
- default:
+ default:
break;
}
@@ -716,7 +722,7 @@ seq_fetch_mid(struct seq_softc *scp, int unit, kobj_t *md)
{
if (unit > scp->midi_number || unit < 0)
- return EINVAL;
+ return EINVAL;
*md = scp->midis[unit];
@@ -730,19 +736,19 @@ seq_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
int i;
if (scp == NULL)
- return ENXIO;
+ return ENXIO;
- SEQ_DEBUG(3,printf("seq_open: scp %p unit %d, flags 0x%x.\n",
- scp, scp->unit, flags));
+ SEQ_DEBUG(3, printf("seq_open: scp %p unit %d, flags 0x%x.\n",
+ scp, scp->unit, flags));
/*
- * Mark this device busy.
+ * Mark this device busy.
*/
mtx_lock(&scp->seq_lock);
if (scp->busy) {
mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(2,printf("seq_open: unit %d is busy.\n", scp->unit));
+ SEQ_DEBUG(2, printf("seq_open: unit %d is busy.\n", scp->unit));
return EBUSY;
}
scp->fflags = flags;
@@ -759,21 +765,21 @@ seq_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
scp->maxunits = midimapper_open(scp->mapper, &scp->mapper_cookie);
if (scp->maxunits == 0)
- SEQ_DEBUG(2,printf("seq_open: no midi devices\n"));
-
- for (i = 0 ; i < scp->maxunits; i++) {
- scp->midis[scp->midi_number] =
- midimapper_fetch_synth(scp->mapper, scp->mapper_cookie, i);
- if (scp->midis[scp->midi_number]) {
- if ( SYNTH_OPEN(scp->midis[scp->midi_number], scp, scp->fflags)
- != 0 )
- scp->midis[scp->midi_number] = NULL;
- else {
- scp->midi_flags[scp->midi_number] =
- SYNTH_QUERY(scp->midis[scp->midi_number]);
- scp->midi_number++;
+ SEQ_DEBUG(2, printf("seq_open: no midi devices\n"));
+
+ for (i = 0; i < scp->maxunits; i++) {
+ scp->midis[scp->midi_number] =
+ midimapper_fetch_synth(scp->mapper, scp->mapper_cookie, i);
+ if (scp->midis[scp->midi_number]) {
+ if (SYNTH_OPEN(scp->midis[scp->midi_number], scp,
+ scp->fflags) != 0)
+ scp->midis[scp->midi_number] = NULL;
+ else {
+ scp->midi_flags[scp->midi_number] =
+ SYNTH_QUERY(scp->midis[scp->midi_number]);
+ scp->midi_number++;
+ }
}
- }
}
timer_setvals(scp, 60, 100);
@@ -792,11 +798,13 @@ seq_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
scp->busy = 1;
mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(2,printf("seq_open: opened, mode %s.\n",
- scp->music ? "music" : "sequencer"));
- SEQ_DEBUG(2,printf("Sequencer %d %p opened maxunits %d midi_number %d:\n", scp->unit, scp, scp->maxunits, scp->midi_number));
- for (i=0;i<scp->midi_number;i++)
- SEQ_DEBUG(3,printf(" midi %d %p\n", i, scp->midis[i]));
+ SEQ_DEBUG(2, printf("seq_open: opened, mode %s.\n",
+ scp->music ? "music" : "sequencer"));
+ SEQ_DEBUG(2,
+ printf("Sequencer %d %p opened maxunits %d midi_number %d:\n",
+ scp->unit, scp, scp->maxunits, scp->midi_number));
+ for (i = 0; i < scp->midi_number; i++)
+ SEQ_DEBUG(3, printf(" midi %d %p\n", i, scp->midis[i]));
return 0;
}
@@ -812,22 +820,22 @@ seq_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
int ret;
if (scp == NULL)
- return ENXIO;
+ return ENXIO;
- SEQ_DEBUG(2,printf("seq_close: unit %d.\n", scp->unit));
+ SEQ_DEBUG(2, printf("seq_close: unit %d.\n", scp->unit));
mtx_lock(&scp->seq_lock);
ret = ENXIO;
if (scp->busy == 0)
- goto err;
+ goto err;
seq_reset(scp);
seq_sync(scp);
- for (i = 0 ; i < scp->midi_number; i++)
- if (scp->midis[i])
- SYNTH_CLOSE(scp->midis[i]);
+ for (i = 0; i < scp->midi_number; i++)
+ if (scp->midis[i])
+ SYNTH_CLOSE(scp->midis[i]);
midimapper_close(scp->mapper, scp->mapper_cookie);
@@ -837,7 +845,7 @@ seq_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
ret = 0;
err:
- SEQ_DEBUG(3,printf("seq_close: closed ret = %d.\n", ret));
+ SEQ_DEBUG(3, printf("seq_close: closed ret = %d.\n", ret));
mtx_unlock(&scp->seq_lock);
return ret;
}
@@ -847,23 +855,23 @@ seq_read(struct cdev *i_dev, struct uio *uio, int ioflag)
{
int retval, used;
struct seq_softc *scp = i_dev->si_drv1;
+
#define SEQ_RSIZE 32
u_char buf[SEQ_RSIZE];
if (scp == NULL)
- return ENXIO;
+ return ENXIO;
- SEQ_DEBUG(7,printf("seq_read: unit %d, resid %d.\n",
- scp->unit, uio->uio_resid));
+ SEQ_DEBUG(7, printf("seq_read: unit %d, resid %d.\n",
+ scp->unit, uio->uio_resid));
mtx_lock(&scp->seq_lock);
if ((scp->fflags & FREAD) == 0) {
- SEQ_DEBUG(2,printf("seq_read: unit %d is not for reading.\n",
- scp->unit));
- retval = EIO;
- goto err1;
+ SEQ_DEBUG(2, printf("seq_read: unit %d is not for reading.\n",
+ scp->unit));
+ retval = EIO;
+ goto err1;
}
-
/*
* Begin recording.
*/
@@ -883,37 +891,37 @@ seq_read(struct cdev *i_dev, struct uio *uio, int ioflag)
*/
while (uio->uio_resid > 0) {
- while (MIDIQ_EMPTY(scp->in_q)) {
- retval = EWOULDBLOCK;
- /*
- * I wish I knew which one to care about
- */
+ while (MIDIQ_EMPTY(scp->in_q)) {
+ retval = EWOULDBLOCK;
+ /*
+ * I wish I knew which one to care about
+ */
- if (scp->fflags & O_NONBLOCK)
- goto err1;
- if (ioflag & O_NONBLOCK)
- goto err1;
+ if (scp->fflags & O_NONBLOCK)
+ goto err1;
+ if (ioflag & O_NONBLOCK)
+ goto err1;
- retval = cv_wait_sig(&scp->in_cv, &scp->seq_lock);
- if (retval == EINTR)
- goto err1;
- }
+ retval = cv_wait_sig(&scp->in_cv, &scp->seq_lock);
+ if (retval == EINTR)
+ goto err1;
+ }
- used = MIN(MIDIQ_LEN(scp->in_q), uio->uio_resid);
- used = MIN(used, SEQ_RSIZE);
+ used = MIN(MIDIQ_LEN(scp->in_q), uio->uio_resid);
+ used = MIN(used, SEQ_RSIZE);
- SEQ_DEBUG(8,printf("midiread: uiomove cc=%d\n", used));
- MIDIQ_DEQ(scp->in_q, buf, used);
- retval = uiomove(buf, used, uio);
- if (retval)
- goto err1;
+ SEQ_DEBUG(8, printf("midiread: uiomove cc=%d\n", used));
+ MIDIQ_DEQ(scp->in_q, buf, used);
+ retval = uiomove(buf, used, uio);
+ if (retval)
+ goto err1;
}
retval = 0;
err1:
mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(6,printf("seq_read: ret %d, resid %d.\n",
- retval, uio->uio_resid));
+ SEQ_DEBUG(6, printf("seq_read: ret %d, resid %d.\n",
+ retval, uio->uio_resid));
return retval;
}
@@ -926,158 +934,160 @@ seq_write(struct cdev *i_dev, struct uio *uio, int ioflag)
int retval;
int used;
- SEQ_DEBUG(7,printf("seq_write: unit %d, resid %d.\n",
- scp->unit, uio->uio_resid));
+ SEQ_DEBUG(7, printf("seq_write: unit %d, resid %d.\n",
+ scp->unit, uio->uio_resid));
if (scp == NULL)
- return ENXIO;
+ return ENXIO;
mtx_lock(&scp->seq_lock);
if ((scp->fflags & FWRITE) == 0) {
- SEQ_DEBUG(2,printf("seq_write: unit %d is not for writing.\n",
- scp->unit));
- retval = EIO;
- goto err0;
+ SEQ_DEBUG(2, printf("seq_write: unit %d is not for writing.\n",
+ scp->unit));
+ retval = EIO;
+ goto err0;
}
-
while (uio->uio_resid > 0) {
- while (MIDIQ_AVAIL(scp->out_q) == 0) {
- retval = EWOULDBLOCK;
- if (scp->fflags & O_NONBLOCK)
- goto err0;
- if (ioflag & O_NONBLOCK)
- goto err0;
- SEQ_DEBUG(8,printf("seq_write cvwait\n"));
-
- scp->playing = 1;
- cv_broadcast(&scp->out_cv);
- cv_broadcast(&scp->state_cv);
-
- retval = cv_wait_sig(&scp->out_cv, &scp->seq_lock);
- /*
- * We slept, maybe things have changed since last
- * dying check
- */
- if (retval == EINTR)
- goto err0;
+ while (MIDIQ_AVAIL(scp->out_q) == 0) {
+ retval = EWOULDBLOCK;
+ if (scp->fflags & O_NONBLOCK)
+ goto err0;
+ if (ioflag & O_NONBLOCK)
+ goto err0;
+ SEQ_DEBUG(8, printf("seq_write cvwait\n"));
+
+ scp->playing = 1;
+ cv_broadcast(&scp->out_cv);
+ cv_broadcast(&scp->state_cv);
+
+ retval = cv_wait_sig(&scp->out_cv, &scp->seq_lock);
+ /*
+ * We slept, maybe things have changed since last
+ * dying check
+ */
+ if (retval == EINTR)
+ goto err0;
#if 0
- /*
- * Useless test
- */
- if (scp != i_dev->si_drv1)
- retval = ENXIO;
+ /*
+ * Useless test
+ */
+ if (scp != i_dev->si_drv1)
+ retval = ENXIO;
#endif
- }
-
- used = MIN(uio->uio_resid, 4);
+ }
- SEQ_DEBUG(8,printf("seqout: resid %d len %jd avail %jd\n",
- uio->uio_resid, (intmax_t)MIDIQ_LEN(scp->out_q),
- (intmax_t)MIDIQ_AVAIL(scp->out_q)));
+ used = MIN(uio->uio_resid, 4);
- if (used != 4) {
- retval = ENXIO;
- goto err0;
- }
+ SEQ_DEBUG(8, printf("seqout: resid %d len %jd avail %jd\n",
+ uio->uio_resid, (intmax_t)MIDIQ_LEN(scp->out_q),
+ (intmax_t)MIDIQ_AVAIL(scp->out_q)));
- retval = uiomove(event, used, uio);
- if (retval)
- goto err0;
+ if (used != 4) {
+ retval = ENXIO;
+ goto err0;
+ }
+ retval = uiomove(event, used, uio);
+ if (retval)
+ goto err0;
- ev_code = event[0];
- SEQ_DEBUG(8,printf("seq_write: unit %d, event %s.\n",
- scp->unit, midi_cmdname(ev_code, cmdtab_seqevent)));
+ ev_code = event[0];
+ SEQ_DEBUG(8, printf("seq_write: unit %d, event %s.\n",
+ scp->unit, midi_cmdname(ev_code, cmdtab_seqevent)));
- /* Have a look at the event code. */
- if (ev_code == SEQ_FULLSIZE) {
+ /* Have a look at the event code. */
+ if (ev_code == SEQ_FULLSIZE) {
- /*
- * TODO: restore code for SEQ_FULLSIZE
- */
+ /*
+ * TODO: restore code for SEQ_FULLSIZE
+ */
#if 0
- /* A long event, these are the patches/samples for a synthesizer. */
- midiunit = *(u_short *)&event[2];
- mtx_lock(&sd->seq_lock);
- ret = lookup_mididev(scp, midiunit, LOOKUP_OPEN, &md);
- mtx_unlock(&sd->seq_lock);
- if (ret != 0)
- return (ret);
-
- SEQ_DEBUG(printf("seq_write: loading a patch to the unit %d.\n", midiunit));
-
- ret = md->synth.loadpatch(md, *(short *)&event[0], buf, p + 4, count, 0);
- return (ret);
+ /*
+ * A long event, these are the patches/samples for a
+ * synthesizer.
+ */
+ midiunit = *(u_short *)&event[2];
+ mtx_lock(&sd->seq_lock);
+ ret = lookup_mididev(scp, midiunit, LOOKUP_OPEN, &md);
+ mtx_unlock(&sd->seq_lock);
+ if (ret != 0)
+ return (ret);
+
+ SEQ_DEBUG(printf("seq_write: loading a patch to the unit %d.\n", midiunit));
+
+ ret = md->synth.loadpatch(md, *(short *)&event[0], buf,
+ p + 4, count, 0);
+ return (ret);
#else
- /*
- * For now, just flush the darn buffer
- */
- SEQ_DEBUG(2,printf("seq_write: SEQ_FULLSIZE flusing buffer.\n"));
- while (uio->uio_resid > 0) {
- retval = uiomove(event, EV_SZ, uio);
- if (retval)
- goto err0;
+ /*
+ * For now, just flush the darn buffer
+ */
+ SEQ_DEBUG(2,
+ printf("seq_write: SEQ_FULLSIZE flusing buffer.\n"));
+ while (uio->uio_resid > 0) {
+ retval = uiomove(event, EV_SZ, uio);
+ if (retval)
+ goto err0;
- }
- retval = 0;
- goto err0;
+ }
+ retval = 0;
+ goto err0;
#endif
- }
-
- retval = EINVAL;
- if (ev_code >= 128) {
+ }
+ retval = EINVAL;
+ if (ev_code >= 128) {
- /*
- * Some sort of an extended event. The size is eight bytes.
- * scoop extra info.
- */
- if (scp->music && ev_code == SEQ_EXTENDED) {
- SEQ_DEBUG(2,printf("seq_write: invalid level two event %x.\n", ev_code));
- goto err0;
+ /*
+ * Some sort of an extended event. The size is eight
+ * bytes. scoop extra info.
+ */
+ if (scp->music && ev_code == SEQ_EXTENDED) {
+ SEQ_DEBUG(2, printf("seq_write: invalid level two event %x.\n", ev_code));
+ goto err0;
+ }
+ if (uiomove((caddr_t)&event[4], 4, uio)) {
+ SEQ_DEBUG(2,
+ printf("seq_write: user memory mangled?\n"));
+ goto err0;
+ }
+ } else {
+ /*
+ * Size four event.
+ */
+ if (scp->music) {
+ SEQ_DEBUG(2, printf("seq_write: four byte event in music mode.\n"));
+ goto err0;
+ }
}
- if (uiomove((caddr_t)&event[4], 4, uio)) {
- SEQ_DEBUG(2,printf("seq_write: user memory mangled?\n"));
- goto err0;
+ if (ev_code == SEQ_MIDIPUTC) {
+ /*
+ * TODO: event[2] is unit number to receive char.
+ * Range check it.
+ */
}
- } else {
- /*
- * Size four event.
- */
if (scp->music) {
- SEQ_DEBUG(2,printf("seq_write: four byte event in music mode.\n"));
- goto err0;
- }
- }
- if (ev_code == SEQ_MIDIPUTC) {
- /*
- * TODO: event[2] is unit number to receive char. Range check
- * it
- */
- }
-
- if (scp->music) {
#ifdef not_ever_ever
- if (event[0] == EV_TIMING &&
- (event[1] == TMR_START || event[1] == TMR_STOP) ) {
- /*
- * For now, try to make midimoutain work by
- * forcing these events to be processed immediatly
- */
- seq_processevent(scp, event);
- }
- else
- MIDIQ_ENQ(scp->out_q, event, EV_SZ);
+ if (event[0] == EV_TIMING &&
+ (event[1] == TMR_START || event[1] == TMR_STOP)) {
+ /*
+ * For now, try to make midimoutain work by
+ * forcing these events to be processed
+ * immediatly.
+ */
+ seq_processevent(scp, event);
+ } else
+ MIDIQ_ENQ(scp->out_q, event, EV_SZ);
#else
- MIDIQ_ENQ(scp->out_q, event, EV_SZ);
+ MIDIQ_ENQ(scp->out_q, event, EV_SZ);
#endif
- } else {
- if (seq_convertold(event, newevent) > 0)
- MIDIQ_ENQ(scp->out_q, newevent, EV_SZ);
+ } else {
+ if (seq_convertold(event, newevent) > 0)
+ MIDIQ_ENQ(scp->out_q, newevent, EV_SZ);
#if 0
- else
- goto err0;
+ else
+ goto err0;
#endif
- }
+ }
}
@@ -1088,14 +1098,16 @@ seq_write(struct cdev *i_dev, struct uio *uio, int ioflag)
retval = 0;
err0:
- SEQ_DEBUG(6,printf("seq_write done: leftover buffer length %d retval %d\n",
- uio->uio_resid, retval));
+ SEQ_DEBUG(6,
+ printf("seq_write done: leftover buffer length %d retval %d\n",
+ uio->uio_resid, retval));
mtx_unlock(&scp->seq_lock);
return retval;
}
int
-seq_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *td)
+seq_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
+ struct thread *td)
{
int midiunit, ret, tmp;
struct seq_softc *scp = i_dev->si_drv1;
@@ -1105,86 +1117,88 @@ seq_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
u_char newevent[EV_SZ];
kobj_t md;
+
/*
* struct snd_size *sndsize;
*/
if (scp == NULL)
- return ENXIO;
+ return ENXIO;
- SEQ_DEBUG(6,printf("seq_ioctl: unit %d, cmd %s.\n",
- scp->unit, midi_cmdname(cmd, cmdtab_seqioctl)));
+ SEQ_DEBUG(6, printf("seq_ioctl: unit %d, cmd %s.\n",
+ scp->unit, midi_cmdname(cmd, cmdtab_seqioctl)));
ret = 0;
switch (cmd) {
- case SNDCTL_SEQ_GETTIME:
+ case SNDCTL_SEQ_GETTIME:
/*
* ioctl needed by libtse
*/
mtx_lock(&scp->seq_lock);
*(int *)arg = timer_now(scp);
mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(6,printf("seq_ioctl: gettime %d.\n", *(int *)arg));
+ SEQ_DEBUG(6, printf("seq_ioctl: gettime %d.\n", *(int *)arg));
ret = 0;
break;
- case SNDCTL_TMR_METRONOME:
+ case SNDCTL_TMR_METRONOME:
/* fallthrough */
- case SNDCTL_TMR_SOURCE:
+ case SNDCTL_TMR_SOURCE:
/*
* Not implemented
*/
ret = 0;
break;
- case SNDCTL_TMR_TEMPO:
+ case SNDCTL_TMR_TEMPO:
event[1] = TMR_TEMPO;
event[4] = *(int *)arg & 0xFF;
event[5] = (*(int *)arg >> 8) & 0xFF;
event[6] = (*(int *)arg >> 16) & 0xFF;
event[7] = (*(int *)arg >> 24) & 0xFF;
goto timerevent;
- case SNDCTL_TMR_TIMEBASE:
+ case SNDCTL_TMR_TIMEBASE:
event[1] = TMR_TIMERBASE;
event[4] = *(int *)arg & 0xFF;
event[5] = (*(int *)arg >> 8) & 0xFF;
event[6] = (*(int *)arg >> 16) & 0xFF;
event[7] = (*(int *)arg >> 24) & 0xFF;
goto timerevent;
- case SNDCTL_TMR_START:
+ case SNDCTL_TMR_START:
event[1] = TMR_START;
goto timerevent;
- case SNDCTL_TMR_STOP:
+ case SNDCTL_TMR_STOP:
event[1] = TMR_STOP;
goto timerevent;
- case SNDCTL_TMR_CONTINUE:
+ case SNDCTL_TMR_CONTINUE:
event[1] = TMR_CONTINUE;
- timerevent:
+timerevent:
event[0] = EV_TIMING;
mtx_lock(&scp->seq_lock);
if (!scp->music) {
- ret = EINVAL;
- mtx_unlock(&scp->seq_lock);
- break;
+ ret = EINVAL;
+ mtx_unlock(&scp->seq_lock);
+ break;
}
seq_processevent(scp, event);
mtx_unlock(&scp->seq_lock);
break;
- case SNDCTL_TMR_SELECT:
- SEQ_DEBUG(2,printf("seq_ioctl: SNDCTL_TMR_SELECT not supported\n"));
+ case SNDCTL_TMR_SELECT:
+ SEQ_DEBUG(2,
+ printf("seq_ioctl: SNDCTL_TMR_SELECT not supported\n"));
ret = EINVAL;
break;
- case SNDCTL_SEQ_SYNC:
+ case SNDCTL_SEQ_SYNC:
if (mode == O_RDONLY) {
- ret = 0;
- break;
+ ret = 0;
+ break;
}
mtx_lock(&scp->seq_lock);
ret = seq_sync(scp);
mtx_unlock(&scp->seq_lock);
break;
- case SNDCTL_SEQ_PANIC:
+ case SNDCTL_SEQ_PANIC:
/* fallthrough */
- case SNDCTL_SEQ_RESET:
+ case SNDCTL_SEQ_RESET:
/*
* SNDCTL_SEQ_PANIC == SNDCTL_SEQ_RESET
*/
@@ -1193,7 +1207,7 @@ seq_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
mtx_unlock(&scp->seq_lock);
ret = 0;
break;
- case SNDCTL_SEQ_TESTMIDI:
+ case SNDCTL_SEQ_TESTMIDI:
mtx_lock(&scp->seq_lock);
/*
* TODO: SNDCTL_SEQ_TESTMIDI now means "can I write to the
@@ -1202,176 +1216,181 @@ seq_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
mtx_unlock(&scp->seq_lock);
break;
#if 0
- case SNDCTL_SEQ_GETINCOUNT:
+ case SNDCTL_SEQ_GETINCOUNT:
if (mode == O_WRONLY)
- *(int *)arg = 0;
+ *(int *)arg = 0;
else {
- mtx_lock(&scp->seq_lock);
- *(int *)arg = scp->in_q.rl;
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(printf("seq_ioctl: incount %d.\n", *(int *)arg));
+ mtx_lock(&scp->seq_lock);
+ *(int *)arg = scp->in_q.rl;
+ mtx_unlock(&scp->seq_lock);
+ SEQ_DEBUG(printf("seq_ioctl: incount %d.\n",
+ *(int *)arg));
}
ret = 0;
break;
- case SNDCTL_SEQ_GETOUTCOUNT:
+ case SNDCTL_SEQ_GETOUTCOUNT:
if (mode == O_RDONLY)
- *(int *)arg = 0;
+ *(int *)arg = 0;
else {
- mtx_lock(&scp->seq_lock);
- *(int *)arg = scp->out_q.fl;
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(printf("seq_ioctl: outcount %d.\n", *(int *)arg));
+ mtx_lock(&scp->seq_lock);
+ *(int *)arg = scp->out_q.fl;
+ mtx_unlock(&scp->seq_lock);
+ SEQ_DEBUG(printf("seq_ioctl: outcount %d.\n",
+ *(int *)arg));
}
ret = 0;
break;
#endif
- case SNDCTL_SEQ_CTRLRATE:
+ case SNDCTL_SEQ_CTRLRATE:
if (*(int *)arg != 0) {
- ret = EINVAL;
- break;
+ ret = EINVAL;
+ break;
}
mtx_lock(&scp->seq_lock);
*(int *)arg = scp->timerbase;
mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3,printf("seq_ioctl: ctrlrate %d.\n", *(int *)arg));
+ SEQ_DEBUG(3, printf("seq_ioctl: ctrlrate %d.\n", *(int *)arg));
ret = 0;
break;
/*
* TODO: ioctl SNDCTL_SEQ_RESETSAMPLES
*/
#if 0
- case SNDCTL_SEQ_RESETSAMPLES:
+ case SNDCTL_SEQ_RESETSAMPLES:
mtx_lock(&scp->seq_lock);
ret = lookup_mididev(scp, *(int *)arg, LOOKUP_OPEN, &md);
mtx_unlock(&scp->seq_lock);
if (ret != 0)
- break;
- ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg, SND_DEV_MIDIN), cmd, arg, mode, td);
+ break;
+ ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg,
+ SND_DEV_MIDIN), cmd, arg, mode, td);
break;
#endif
- case SNDCTL_SEQ_NRSYNTHS:
+ case SNDCTL_SEQ_NRSYNTHS:
mtx_lock(&scp->seq_lock);
- *(int *)arg = scp->midi_number;
+ *(int *)arg = scp->midi_number;
mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3,printf("seq_ioctl: synths %d.\n", *(int *)arg));
+ SEQ_DEBUG(3, printf("seq_ioctl: synths %d.\n", *(int *)arg));
ret = 0;
break;
- case SNDCTL_SEQ_NRMIDIS:
+ case SNDCTL_SEQ_NRMIDIS:
mtx_lock(&scp->seq_lock);
if (scp->music)
- *(int *)arg = 0;
+ *(int *)arg = 0;
else {
- /*
- * TODO: count the numbder of devices that can WRITERAW
- */
- *(int *)arg = scp->midi_number;
+ /*
+ * TODO: count the numbder of devices that can WRITERAW
+ */
+ *(int *)arg = scp->midi_number;
}
mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3,printf("seq_ioctl: midis %d.\n", *(int *)arg));
+ SEQ_DEBUG(3, printf("seq_ioctl: midis %d.\n", *(int *)arg));
ret = 0;
break;
/*
* TODO: ioctl SNDCTL_SYNTH_MEMAVL
*/
#if 0
- case SNDCTL_SYNTH_MEMAVL:
+ case SNDCTL_SYNTH_MEMAVL:
mtx_lock(&scp->seq_lock);
ret = lookup_mididev(scp, *(int *)arg, LOOKUP_OPEN, &md);
mtx_unlock(&scp->seq_lock);
if (ret != 0)
- break;
- ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg, SND_DEV_MIDIN), cmd, arg, mode, td);
+ break;
+ ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg,
+ SND_DEV_MIDIN), cmd, arg, mode, td);
break;
#endif
- case SNDCTL_SEQ_OUTOFBAND:
+ case SNDCTL_SEQ_OUTOFBAND:
for (ret = 0; ret < EV_SZ; ret++)
- event[ret] = (u_char)arg[0];
+ event[ret] = (u_char)arg[0];
mtx_lock(&scp->seq_lock);
if (scp->music)
- ret = seq_processevent(scp, event);
+ ret = seq_processevent(scp, event);
else {
- if (seq_convertold(event, newevent) > 0)
- ret = seq_processevent(scp, newevent);
- else ret = EINVAL;
+ if (seq_convertold(event, newevent) > 0)
+ ret = seq_processevent(scp, newevent);
+ else
+ ret = EINVAL;
}
mtx_unlock(&scp->seq_lock);
break;
- case SNDCTL_SYNTH_INFO:
+ case SNDCTL_SYNTH_INFO:
synthinfo = (struct synth_info *)arg;
midiunit = synthinfo->device;
mtx_lock(&scp->seq_lock);
if (seq_fetch_mid(scp, midiunit, &md) == 0) {
- bzero(synthinfo, sizeof(*synthinfo));
- synthinfo->name[0] = 'f';
- synthinfo->name[1] = 'a';
- synthinfo->name[2] = 'k';
- synthinfo->name[3] = 'e';
- synthinfo->name[4] = 's';
- synthinfo->name[5] = 'y';
- synthinfo->name[6] = 'n';
- synthinfo->name[7] = 't';
- synthinfo->name[8] = 'h';
- synthinfo->device = midiunit;
- synthinfo->synth_type = SYNTH_TYPE_MIDI;
- synthinfo->capabilities = scp->midi_flags[midiunit];
- ret = 0;
+ bzero(synthinfo, sizeof(*synthinfo));
+ synthinfo->name[0] = 'f';
+ synthinfo->name[1] = 'a';
+ synthinfo->name[2] = 'k';
+ synthinfo->name[3] = 'e';
+ synthinfo->name[4] = 's';
+ synthinfo->name[5] = 'y';
+ synthinfo->name[6] = 'n';
+ synthinfo->name[7] = 't';
+ synthinfo->name[8] = 'h';
+ synthinfo->device = midiunit;
+ synthinfo->synth_type = SYNTH_TYPE_MIDI;
+ synthinfo->capabilities = scp->midi_flags[midiunit];
+ ret = 0;
} else
- ret = EINVAL;
+ ret = EINVAL;
mtx_unlock(&scp->seq_lock);
break;
- case SNDCTL_MIDI_INFO:
+ case SNDCTL_MIDI_INFO:
midiinfo = (struct midi_info *)arg;
midiunit = midiinfo->device;
mtx_lock(&scp->seq_lock);
if (seq_fetch_mid(scp, midiunit, &md) == 0) {
- bzero(midiinfo, sizeof(*midiinfo));
- midiinfo->name[0] = 'f';
- midiinfo->name[1] = 'a';
- midiinfo->name[2] = 'k';
- midiinfo->name[3] = 'e';
- midiinfo->name[4] = 'm';
- midiinfo->name[5] = 'i';
- midiinfo->name[6] = 'd';
- midiinfo->name[7] = 'i';
- midiinfo->device = midiunit;
- midiinfo->capabilities = scp->midi_flags[midiunit];
- /*
- * TODO: What devtype?
- */
- midiinfo->dev_type = 0x01;
- ret = 0;
+ bzero(midiinfo, sizeof(*midiinfo));
+ midiinfo->name[0] = 'f';
+ midiinfo->name[1] = 'a';
+ midiinfo->name[2] = 'k';
+ midiinfo->name[3] = 'e';
+ midiinfo->name[4] = 'm';
+ midiinfo->name[5] = 'i';
+ midiinfo->name[6] = 'd';
+ midiinfo->name[7] = 'i';
+ midiinfo->device = midiunit;
+ midiinfo->capabilities = scp->midi_flags[midiunit];
+ /*
+ * TODO: What devtype?
+ */
+ midiinfo->dev_type = 0x01;
+ ret = 0;
} else
- ret = EINVAL;
+ ret = EINVAL;
mtx_unlock(&scp->seq_lock);
break;
- case SNDCTL_SEQ_THRESHOLD:
+ case SNDCTL_SEQ_THRESHOLD:
mtx_lock(&scp->seq_lock);
RANGE(*(int *)arg, 1, MIDIQ_SIZE(scp->out_q) - 1);
scp->out_water = *(int *)arg;
mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3,printf("seq_ioctl: water %d.\n", *(int *)arg));
+ SEQ_DEBUG(3, printf("seq_ioctl: water %d.\n", *(int *)arg));
ret = 0;
break;
- case SNDCTL_MIDI_PRETIME:
+ case SNDCTL_MIDI_PRETIME:
tmp = *(int *)arg;
if (tmp < 0)
- tmp = 0;
+ tmp = 0;
mtx_lock(&scp->seq_lock);
scp->pre_event_timeout = (hz * tmp) / 10;
*(int *)arg = scp->pre_event_timeout;
mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3,printf("seq_ioctl: pretime %d.\n", *(int *)arg));
+ SEQ_DEBUG(3, printf("seq_ioctl: pretime %d.\n", *(int *)arg));
ret = 0;
break;
- case SNDCTL_FM_4OP_ENABLE:
- case SNDCTL_PMGR_IFACE:
- case SNDCTL_PMGR_ACCESS:
+ case SNDCTL_FM_4OP_ENABLE:
+ case SNDCTL_PMGR_IFACE:
+ case SNDCTL_PMGR_ACCESS:
/*
* Patch manager and fm are ded, ded, ded.
*/
/* fallthrough */
- default:
+ default:
/*
* TODO: Consider ioctl default case.
* Old code used to
@@ -1381,7 +1400,8 @@ seq_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *
* }
* Then pass on the ioctl to device 0
*/
- SEQ_DEBUG(2,printf("seq_ioctl: unsupported IOCTL %ld.\n", cmd));
+ SEQ_DEBUG(2,
+ printf("seq_ioctl: unsupported IOCTL %ld.\n", cmd));
ret = EINVAL;
break;
}
@@ -1404,38 +1424,37 @@ seq_poll(struct cdev *i_dev, int events, struct thread *td)
/* Look up the apropriate queue and select it. */
if ((events & (POLLOUT | POLLWRNORM)) != 0) {
- /* Start playing. */
- scp->playing = 1;
- cv_broadcast(&scp->state_cv);
- cv_broadcast(&scp->out_cv);
-
- lim = scp->out_water;
-
- if (MIDIQ_AVAIL(scp->out_q) < lim)
- /* No enough space, record select. */
- selrecord(td, &scp->out_sel);
- else
- /* We can write now. */
- ret |= events & (POLLOUT | POLLWRNORM);
- }
+ /* Start playing. */
+ scp->playing = 1;
+ cv_broadcast(&scp->state_cv);
+ cv_broadcast(&scp->out_cv);
- if ((events & (POLLIN | POLLRDNORM)) != 0) {
- /* TODO: Start recording. */
-
- /* Find out the boundary. */
- lim = 1;
- if (MIDIQ_LEN(scp->in_q) < lim)
- /* No data ready, record select. */
- selrecord(td, &scp->in_sel);
- else
- /* We can read now. */
- ret |= events & (POLLIN | POLLRDNORM);
+ lim = scp->out_water;
+
+ if (MIDIQ_AVAIL(scp->out_q) < lim)
+ /* No enough space, record select. */
+ selrecord(td, &scp->out_sel);
+ else
+ /* We can write now. */
+ ret |= events & (POLLOUT | POLLWRNORM);
}
+ if ((events & (POLLIN | POLLRDNORM)) != 0) {
+ /* TODO: Start recording. */
+ /* Find out the boundary. */
+ lim = 1;
+ if (MIDIQ_LEN(scp->in_q) < lim)
+ /* No data ready, record select. */
+ selrecord(td, &scp->in_sel);
+ else
+ /* We can read now. */
+ ret |= events & (POLLIN | POLLRDNORM);
+ }
mtx_unlock(&scp->seq_lock);
return (ret);
}
+
#if 0
static void
sein_qtr(void *p, void /* mididev_info */ *md)
@@ -1455,11 +1474,12 @@ sein_qtr(void *p, void /* mididev_info */ *md)
mtx_unlock(&scp->seq_lock);
}
+
#endif
/*
* seq_convertold
* Was the old playevent. Use this to convert and old
- * style /dev/sequencer event to a /dev/music event
+ * style /dev/sequencer event to a /dev/music event
*/
static int
seq_convertold(u_char *event, u_char *out)
@@ -1467,7 +1487,8 @@ seq_convertold(u_char *event, u_char *out)
int used;
u_char dev, chn, note, vel;
- out[0] = out[1] = out[2] = out[3] = out[4] = out[5] = out[6] = out[7] = 0;
+ out[0] = out[1] = out[2] = out[3] = out[4] = out[5] = out[6] =
+ out[7] = 0;
dev = 0;
chn = event[1];
@@ -1480,12 +1501,12 @@ restart:
/*
* TODO: Debug statement
*/
- switch(event[0]) {
- case EV_TIMING:
- case EV_CHN_VOICE:
- case EV_CHN_COMMON:
-case EV_SYSEX:
-case EV_SEQ_LOCAL:
+ switch (event[0]) {
+ case EV_TIMING:
+ case EV_CHN_VOICE:
+ case EV_CHN_COMMON:
+ case EV_SYSEX:
+ case EV_SEQ_LOCAL:
out[0] = event[0];
out[1] = event[1];
out[2] = event[2];
@@ -1496,38 +1517,38 @@ case EV_SEQ_LOCAL:
out[7] = event[7];
used += 8;
break;
- case SEQ_NOTEOFF:
+ case SEQ_NOTEOFF:
out[0] = EV_CHN_VOICE;
out[1] = dev;
out[2] = MIDI_NOTEOFF;
out[3] = chn;
out[4] = note;
out[5] = 255;
- used += 4;
+ used += 4;
break;
- case SEQ_NOTEON:
+ case SEQ_NOTEON:
out[0] = EV_CHN_VOICE;
out[1] = dev;
out[2] = MIDI_NOTEON;
out[3] = chn;
out[4] = note;
out[5] = vel;
- used += 4;
+ used += 4;
break;
/*
* wait delay = (event[2] << 16) + (event[3] << 8) + event[4]
*/
- case SEQ_PGMCHANGE:
+ case SEQ_PGMCHANGE:
out[0] = EV_CHN_COMMON;
out[1] = dev;
out[2] = MIDI_PGM_CHANGE;
out[3] = chn;
out[4] = note;
out[5] = vel;
- used += 4;
+ used += 4;
break;
/*
out[0] = EV_TIMING;
@@ -1540,9 +1561,10 @@ case EV_SEQ_LOCAL:
break;
*/
- case SEQ_MIDIPUTC:
- SEQ_DEBUG(4,printf("seq_playevent: put data 0x%02x, unit %d.\n",
- event[1], event[2]));
+ case SEQ_MIDIPUTC:
+ SEQ_DEBUG(4,
+ printf("seq_playevent: put data 0x%02x, unit %d.\n",
+ event[1], event[2]));
/*
* Pass through to the midi device.
* device = event[2]
@@ -1551,70 +1573,74 @@ case EV_SEQ_LOCAL:
out[0] = SEQ_MIDIPUTC;
out[1] = dev;
out[2] = chn;
- used += 4;
+ used += 4;
break;
#ifdef notyet
- case SEQ_ECHO:
+ case SEQ_ECHO:
/*
* This isn't handled here yet because I don't know if I can
- * just use four bytes events. There might be consequences
+ * just use four bytes events. There might be consequences
* in the _read routing
*/
if (seq_copytoinput(scp, event, 4) == EAGAIN) {
- ret = QUEUEFULL;
- break;
+ ret = QUEUEFULL;
+ break;
}
ret = MORE;
break;
#endif
- case SEQ_EXTENDED:
+ case SEQ_EXTENDED:
switch (event[1]) {
- case SEQ_NOTEOFF:
- case SEQ_NOTEON:
- case SEQ_PGMCHANGE:
+ case SEQ_NOTEOFF:
+ case SEQ_NOTEON:
+ case SEQ_PGMCHANGE:
event++;
used = 4;
goto restart;
break;
- case SEQ_AFTERTOUCH:
+ case SEQ_AFTERTOUCH:
/*
* SYNTH_AFTERTOUCH(md, event[3], event[4])
*/
- case SEQ_BALANCE:
+ case SEQ_BALANCE:
/*
* SYNTH_PANNING(md, event[3], (char)event[4])
*/
- case SEQ_CONTROLLER:
+ case SEQ_CONTROLLER:
/*
* SYNTH_CONTROLLER(md, event[3], event[4], *(short *)&event[5])
*/
- case SEQ_VOLMODE:
+ case SEQ_VOLMODE:
/*
- * SYNTH_VOLUMEMETHOD(md, event[3])
+ * SYNTH_VOLUMEMETHOD(md, event[3])
*/
- default:
- SEQ_DEBUG(2,printf("seq_convertold: SEQ_EXTENDED type %d"
- "not handled\n", event[1]));
+ default:
+ SEQ_DEBUG(2,
+ printf("seq_convertold: SEQ_EXTENDED type %d"
+ "not handled\n", event[1]));
break;
}
break;
- case SEQ_WAIT:
+ case SEQ_WAIT:
out[0] = EV_TIMING;
out[1] = TMR_WAIT_REL;
out[4] = event[2];
out[5] = event[3];
out[6] = event[4];
- SEQ_DEBUG(5,printf("SEQ_WAIT %d", event[2] + (event[3] << 8) + (event[4] << 24)));
+ SEQ_DEBUG(5, printf("SEQ_WAIT %d",
+ event[2] + (event[3] << 8) + (event[4] << 24)));
- used+= 4;
+ used += 4;
break;
- case SEQ_ECHO:
- case SEQ_SYNCTIMER:
- case SEQ_PRIVATE:
- default:
- SEQ_DEBUG(2,printf("seq_convertold: event type %d not handled %d %d %d\n", event[0], event[1], event[2], event[3]));
+ case SEQ_ECHO:
+ case SEQ_SYNCTIMER:
+ case SEQ_PRIVATE:
+ default:
+ SEQ_DEBUG(2,
+ printf("seq_convertold: event type %d not handled %d %d %d\n",
+ event[0], event[1], event[2], event[3]));
break;
}
return used;
@@ -1631,14 +1657,14 @@ seq_copytoinput(struct seq_softc *scp, u_char *event, int len)
mtx_assert(&scp->seq_lock, MA_OWNED);
if (MIDIQ_AVAIL(scp->in_q) < len) {
- /*
- * ENOROOM? EINPUTDROPPED? ETOUGHLUCK?
- */
- SEQ_DEBUG(2,printf("seq_copytoinput: queue full\n"));
+ /*
+ * ENOROOM? EINPUTDROPPED? ETOUGHLUCK?
+ */
+ SEQ_DEBUG(2, printf("seq_copytoinput: queue full\n"));
} else {
- MIDIQ_ENQ(scp->in_q, event, len);
- selwakeup(&scp->in_sel);
- cv_broadcast(&scp->in_cv);
+ MIDIQ_ENQ(scp->in_q, event, len);
+ selwakeup(&scp->in_sel);
+ cv_broadcast(&scp->in_cv);
}
}
@@ -1657,45 +1683,47 @@ seq_chnvoice(struct seq_softc *scp, kobj_t md, u_char *event)
mtx_assert(&scp->seq_lock, MA_OWNED);
- SEQ_DEBUG(5,printf("seq_chnvoice: unit %d, dev %d, cmd %s,"
- " chn %d, note %d, parm %d.\n", scp->unit, event[1],
- midi_cmdname(cmd, cmdtab_seqcv), chn, note, parm));
+ SEQ_DEBUG(5, printf("seq_chnvoice: unit %d, dev %d, cmd %s,"
+ " chn %d, note %d, parm %d.\n", scp->unit, event[1],
+ midi_cmdname(cmd, cmdtab_seqcv), chn, note, parm));
voice = SYNTH_ALLOC(md, chn, note);
mtx_unlock(&scp->seq_lock);
switch (cmd) {
- case MIDI_NOTEON:
+ case MIDI_NOTEON:
if (note < 128 || note == 255) {
#if 0
- if (scp->music && chn == 9) {
- /*
- * This channel is a percussion. The note number is the
- * patch number.
- */
- /*
- mtx_unlock(&scp->seq_lock);
- if (SYNTH_SETINSTR(md, voice, 128 + note) == EAGAIN) {
- mtx_lock(&scp->seq_lock);
- return (QUEUEFULL);
+ if (scp->music && chn == 9) {
+ /*
+ * This channel is a percussion. The note
+ * number is the patch number.
+ */
+ /*
+ mtx_unlock(&scp->seq_lock);
+ if (SYNTH_SETINSTR(md, voice, 128 + note)
+ == EAGAIN) {
+ mtx_lock(&scp->seq_lock);
+ return (QUEUEFULL);
+ }
+ mtx_lock(&scp->seq_lock);
+ */
+ note = 60; /* Middle C. */
}
- mtx_lock(&scp->seq_lock);
- */
- note = 60; /* Middle C. */
- }
#endif
- if (scp->music) {
- /*
- mtx_unlock(&scp->seq_lock);
- if (SYNTH_SETUPVOICE(md, voice, chn) == EAGAIN) {
- mtx_lock(&scp->seq_lock);
- return (QUEUEFULL);
+ if (scp->music) {
+ /*
+ mtx_unlock(&scp->seq_lock);
+ if (SYNTH_SETUPVOICE(md, voice, chn)
+ == EAGAIN) {
+ mtx_lock(&scp->seq_lock);
+ return (QUEUEFULL);
+ }
+ mtx_lock(&scp->seq_lock);
+ */
}
- mtx_lock(&scp->seq_lock);
- */
- }
- SYNTH_STARTNOTE(md, voice, note, parm);
+ SYNTH_STARTNOTE(md, voice, note, parm);
}
break;
case MIDI_NOTEOFF:
@@ -1706,7 +1734,8 @@ seq_chnvoice(struct seq_softc *scp, kobj_t md, u_char *event)
break;
default:
ret = 1;
- SEQ_DEBUG(2,printf("seq_chnvoice event type %d not handled\n", event[1]));
+ SEQ_DEBUG(2, printf("seq_chnvoice event type %d not handled\n",
+ event[1]));
break;
}
@@ -1727,58 +1756,63 @@ seq_chncommon(struct seq_softc *scp, kobj_t md, u_char *event)
p1 = event[4];
w14 = *(u_short *)&event[6];
- SEQ_DEBUG(5,printf("seq_chncommon: unit %d, dev %d, cmd %s, chn %d,"
- " p1 %d, w14 %d.\n", scp->unit, event[1],
- midi_cmdname(cmd, cmdtab_seqccmn), chn, p1, w14));
+ SEQ_DEBUG(5, printf("seq_chncommon: unit %d, dev %d, cmd %s, chn %d,"
+ " p1 %d, w14 %d.\n", scp->unit, event[1],
+ midi_cmdname(cmd, cmdtab_seqccmn), chn, p1, w14));
mtx_unlock(&scp->seq_lock);
switch (cmd) {
- case MIDI_PGM_CHANGE:
- SEQ_DEBUG(4,printf("seq_chncommon pgmchn chn %d pg %d\n",
- chn, p1));
- SYNTH_SETINSTR(md, chn, p1);
+ case MIDI_PGM_CHANGE:
+ SEQ_DEBUG(4, printf("seq_chncommon pgmchn chn %d pg %d\n",
+ chn, p1));
+ SYNTH_SETINSTR(md, chn, p1);
break;
- case MIDI_CTL_CHANGE:
- SEQ_DEBUG(4,printf("seq_chncommon ctlch chn %d pg %d %d\n",
- chn, p1, w14));
+ case MIDI_CTL_CHANGE:
+ SEQ_DEBUG(4, printf("seq_chncommon ctlch chn %d pg %d %d\n",
+ chn, p1, w14));
SYNTH_CONTROLLER(md, chn, p1, w14);
break;
- case MIDI_PITCH_BEND:
+ case MIDI_PITCH_BEND:
if (scp->music) {
- /*
- * TODO: MIDI_PITCH_BEND
- */
+ /*
+ * TODO: MIDI_PITCH_BEND
+ */
#if 0
- mtx_lock(&md->synth.vc_mtx);
- md->synth.chn_info[chn].bender_value = w14;
- if (md->midiunit >= 0) {
- /* Handle all of the notes playing on this channel. */
- key = ((int)chn << 8);
- for (i = 0 ; i < md->synth.alloc.max_voice ; i++)
- if ((md->synth.alloc.map[i] & 0xff00) == key) {
+ mtx_lock(&md->synth.vc_mtx);
+ md->synth.chn_info[chn].bender_value = w14;
+ if (md->midiunit >= 0) {
+ /*
+ * Handle all of the notes playing on this
+ * channel.
+ */
+ key = ((int)chn << 8);
+ for (i = 0; i < md->synth.alloc.max_voice; i++)
+ if ((md->synth.alloc.map[i] & 0xff00) == key) {
+ mtx_unlock(&md->synth.vc_mtx);
+ mtx_unlock(&scp->seq_lock);
+ if (md->synth.bender(md, i, w14) == EAGAIN) {
+ mtx_lock(&scp->seq_lock);
+ return (QUEUEFULL);
+ }
+ mtx_lock(&scp->seq_lock);
+ }
+ } else {
mtx_unlock(&md->synth.vc_mtx);
mtx_unlock(&scp->seq_lock);
- if (md->synth.bender(md, i, w14) == EAGAIN) {
- mtx_lock(&scp->seq_lock);
- return (QUEUEFULL);
+ if (md->synth.bender(md, chn, w14) == EAGAIN) {
+ mtx_lock(&scp->seq_lock);
+ return (QUEUEFULL);
}
mtx_lock(&scp->seq_lock);
- }
- } else {
- mtx_unlock(&md->synth.vc_mtx);
- mtx_unlock(&scp->seq_lock);
- if (md->synth.bender(md, chn, w14) == EAGAIN) {
- mtx_lock(&scp->seq_lock);
- return (QUEUEFULL);
}
- mtx_lock(&scp->seq_lock);
- }
#endif
} else
- SYNTH_BENDER(md, chn, w14);
+ SYNTH_BENDER(md, chn, w14);
break;
- default:
+ default:
ret = 1;
- SEQ_DEBUG(2,printf("seq_chncommon event type %d not handled.\n", event[1]));
+ SEQ_DEBUG(2,
+ printf("seq_chncommon event type %d not handled.\n",
+ event[1]));
break;
}
@@ -1796,14 +1830,14 @@ seq_timing(struct seq_softc *scp, u_char *event)
param = event[4] + (event[5] << 8) +
(event[6] << 16) + (event[7] << 24);
- SEQ_DEBUG(5,printf("seq_timing: unit %d, cmd %d, param %d.\n",
- scp->unit, event[1], param));
+ SEQ_DEBUG(5, printf("seq_timing: unit %d, cmd %d, param %d.\n",
+ scp->unit, event[1], param));
switch (event[1]) {
case TMR_WAIT_REL:
- timer_wait(scp, param, 0);
+ timer_wait(scp, param, 0);
break;
case TMR_WAIT_ABS:
- timer_wait(scp, param, 1);
+ timer_wait(scp, param, 1);
break;
case TMR_START:
timer_start(scp);
@@ -1823,18 +1857,18 @@ seq_timing(struct seq_softc *scp, u_char *event)
break;
case TMR_TEMPO:
if (param < 8)
- param = 8;
+ param = 8;
if (param > 360)
- param = 360;
- SEQ_DEBUG(4,printf("Timer set tempo %d\n", param));
+ param = 360;
+ SEQ_DEBUG(4, printf("Timer set tempo %d\n", param));
timer_setvals(scp, param, scp->timerbase);
break;
case TMR_TIMERBASE:
if (param < 1)
- param = 1;
+ param = 1;
if (param > 1000)
- param = 1000;
- SEQ_DEBUG(4,printf("Timer set timerbase %d\n", param));
+ param = 1000;
+ SEQ_DEBUG(4, printf("Timer set timerbase %d\n", param));
timer_setvals(scp, scp->tempo, param);
break;
case TMR_ECHO:
@@ -1855,8 +1889,9 @@ seq_timing(struct seq_softc *scp, u_char *event)
seq_copytoinput(scp, event, 8);
#endif
break;
- default:
- SEQ_DEBUG(2,printf("seq_timing event type %d not handled.\n", event[1]));
+ default:
+ SEQ_DEBUG(2, printf("seq_timing event type %d not handled.\n",
+ event[1]));
ret = 1;
break;
}
@@ -1871,10 +1906,12 @@ seq_local(struct seq_softc *scp, u_char *event)
ret = 0;
mtx_assert(&scp->seq_lock, MA_OWNED);
- SEQ_DEBUG(5,printf("seq_local: unit %d, cmd %d\n", scp->unit, event[1]));
+ SEQ_DEBUG(5, printf("seq_local: unit %d, cmd %d\n", scp->unit,
+ event[1]));
switch (event[1]) {
- default:
- SEQ_DEBUG(1, printf("seq_local event type %d not handled\n", event[1]));
+ default:
+ SEQ_DEBUG(1, printf("seq_local event type %d not handled\n",
+ event[1]));
ret = 1;
break;
}
@@ -1887,9 +1924,10 @@ seq_sysex(struct seq_softc *scp, kobj_t md, u_char *event)
int i, l;
mtx_assert(&scp->seq_lock, MA_OWNED);
- SEQ_DEBUG(5,printf("seq_sysex: unit %d device %d\n", scp->unit, event[1]));
+ SEQ_DEBUG(5, printf("seq_sysex: unit %d device %d\n", scp->unit,
+ event[1]));
l = 0;
- for (i = 0 ; i < 6 && event[i + 2] != 0xff ; i++)
+ for (i = 0; i < 6 && event[i + 2] != 0xff; i++)
l = i + 1;
if (l > 0) {
mtx_unlock(&scp->seq_lock);
@@ -1909,12 +1947,12 @@ seq_sysex(struct seq_softc *scp, kobj_t md, u_char *event)
static void
seq_reset(struct seq_softc *scp)
{
- int chn, i;
+ int chn, i;
kobj_t m;
mtx_assert(&scp->seq_lock, MA_OWNED);
- SEQ_DEBUG(5,printf("seq_reset: unit %d.\n", scp->unit));
+ SEQ_DEBUG(5, printf("seq_reset: unit %d.\n", scp->unit));
/*
* Stop reading and writing.
@@ -1933,15 +1971,15 @@ seq_reset(struct seq_softc *scp)
MIDIQ_CLEAR(scp->out_q);
for (i = 0; i < scp->midi_number; i++) {
- m = scp->midis[i];
- mtx_unlock(&scp->seq_lock);
- SYNTH_RESET(m);
- for (chn = 0 ; chn < 16 ; chn++) {
- SYNTH_CONTROLLER(m, chn, 123, 0) ;
- SYNTH_CONTROLLER(m, chn, 121, 0);
- SYNTH_BENDER(m, chn, 1 << 13);
- }
- mtx_lock(&scp->seq_lock);
+ m = scp->midis[i];
+ mtx_unlock(&scp->seq_lock);
+ SYNTH_RESET(m);
+ for (chn = 0; chn < 16; chn++) {
+ SYNTH_CONTROLLER(m, chn, 123, 0);
+ SYNTH_CONTROLLER(m, chn, 121, 0);
+ SYNTH_BENDER(m, chn, 1 << 13);
+ }
+ mtx_lock(&scp->seq_lock);
}
}
@@ -1960,7 +1998,7 @@ seq_sync(struct seq_softc *scp)
mtx_assert(&scp->seq_lock, MA_OWNED);
- SEQ_DEBUG(4,printf("seq_sync: unit %d.\n", scp->unit));
+ SEQ_DEBUG(4, printf("seq_sync: unit %d.\n", scp->unit));
/*
* Wait until output queue is empty. Check every so often to see if
@@ -1968,47 +2006,46 @@ seq_sync(struct seq_softc *scp)
*/
while (!MIDIQ_EMPTY(scp->out_q)) {
- if (!scp->playing) {
- scp->playing = 1;
- cv_broadcast(&scp->state_cv);
- cv_broadcast(&scp->out_cv);
- }
-
- rl = MIDIQ_LEN(scp->out_q);
+ if (!scp->playing) {
+ scp->playing = 1;
+ cv_broadcast(&scp->state_cv);
+ cv_broadcast(&scp->out_cv);
+ }
+ rl = MIDIQ_LEN(scp->out_q);
- i = cv_timedwait_sig(&scp->out_cv,
+ i = cv_timedwait_sig(&scp->out_cv,
&scp->seq_lock, SEQ_SYNC_TIMEOUT * hz);
- if (i == EINTR || i == ERESTART) {
- if (i == EINTR) {
- /*
- * XXX: I don't know why we stop playing
- */
- scp->playing = 0;
- cv_broadcast(&scp->out_cv);
+ if (i == EINTR || i == ERESTART) {
+ if (i == EINTR) {
+ /*
+ * XXX: I don't know why we stop playing
+ */
+ scp->playing = 0;
+ cv_broadcast(&scp->out_cv);
+ }
+ return i;
}
- return i;
- }
-
- if (i == EWOULDBLOCK && rl == MIDIQ_LEN(scp->out_q) &&
+ if (i == EWOULDBLOCK && rl == MIDIQ_LEN(scp->out_q) &&
scp->waiting == 0) {
- /*
- * A queue seems to be stuck up. Give up and clear queues.
- */
- MIDIQ_CLEAR(scp->out_q);
- scp->playing = 0;
- cv_broadcast(&scp->state_cv);
- cv_broadcast(&scp->out_cv);
- cv_broadcast(&scp->reset_cv);
+ /*
+ * A queue seems to be stuck up. Give up and clear
+ * queues.
+ */
+ MIDIQ_CLEAR(scp->out_q);
+ scp->playing = 0;
+ cv_broadcast(&scp->state_cv);
+ cv_broadcast(&scp->out_cv);
+ cv_broadcast(&scp->reset_cv);
- /*
- * TODO: Consider if the raw devices need to be flushed
- */
+ /*
+ * TODO: Consider if the raw devices need to be flushed
+ */
- SEQ_DEBUG(1,printf("seq_sync queue stuck, aborting\n"));
+ SEQ_DEBUG(1, printf("seq_sync queue stuck, aborting\n"));
- return i;
- }
+ return i;
+ }
}
scp->playing = 0;
@@ -2017,21 +2054,20 @@ seq_sync(struct seq_softc *scp)
*/
mtx_unlock(&scp->seq_lock);
- for(i = 0 ; i < scp->midi_number; i++)
- sync[i] = 1;
+ for (i = 0; i < scp->midi_number; i++)
+ sync[i] = 1;
do {
- done = 1;
- for (i = 0 ; i < scp->midi_number; i++)
- if (sync[i]) {
- if (SYNTH_INSYNC(scp->midis[i]) == 0)
- sync[i] = 0;
- else
- done = 0;
- }
-
- if (!done)
- DELAY(5000);
+ done = 1;
+ for (i = 0; i < scp->midi_number; i++)
+ if (sync[i]) {
+ if (SYNTH_INSYNC(scp->midis[i]) == 0)
+ sync[i] = 0;
+ else
+ done = 0;
+ }
+ if (!done)
+ DELAY(5000);
} while (!done);
@@ -2039,7 +2075,7 @@ seq_sync(struct seq_softc *scp)
return 0;
}
-char *
+char *
midi_cmdname(int cmd, midi_cmdtab *tab)
{
while (tab->name != NULL) {
diff --git a/sys/dev/sound/midi/sequencer.h b/sys/dev/sound/midi/sequencer.h
index d0f28ae..946582e 100644
--- a/sys/dev/sound/midi/sequencer.h
+++ b/sys/dev/sound/midi/sequencer.h
@@ -50,7 +50,8 @@ void seq_timer(void *arg);
SYSCTL_DECL(_hw_midi_seq);
-extern int seq_debug;
+extern int seq_debug;
+
#define SEQ_DEBUG(y, x) \
do { \
if (seq_debug >= y) { \
@@ -60,7 +61,7 @@ extern int seq_debug;
SYSCTL_DECL(_hw_midi);
-#endif /* _KERNEL */
+#endif /* _KERNEL */
#define SYNTHPROP_MIDI 1
#define SYNTHPROP_SYNTH 2
@@ -68,17 +69,17 @@ SYSCTL_DECL(_hw_midi);
#define SYNTHPROP_TX 8
struct _midi_cmdtab {
- int cmd;
- char * name;
+ int cmd;
+ char *name;
};
-typedef struct _midi_cmdtab midi_cmdtab;
+typedef struct _midi_cmdtab midi_cmdtab;
extern midi_cmdtab cmdtab_seqevent[];
extern midi_cmdtab cmdtab_seqioctl[];
extern midi_cmdtab cmdtab_timer[];
extern midi_cmdtab cmdtab_seqcv[];
extern midi_cmdtab cmdtab_seqccmn[];
-char *midi_cmdname(int cmd, midi_cmdtab *tab);
+char *midi_cmdname(int cmd, midi_cmdtab * tab);
enum {
MORE,
diff --git a/sys/dev/sound/midi/synth_if.m b/sys/dev/sound/midi/synth_if.m
index ae6f1ad..e29032b 100644
--- a/sys/dev/sound/midi/synth_if.m
+++ b/sys/dev/sound/midi/synth_if.m
@@ -201,113 +201,113 @@ synth_alloc_t noalloc;
}
METHOD int killnote {
- void /* X */ * _kobj;
- uint8_t _chan;
- uint8_t _note;
- uint8_t _vel;
+ void /* X */ *_kobj;
+ uint8_t _chan;
+ uint8_t _note;
+ uint8_t _vel;
} DEFAULT nokillnote;
METHOD int startnote {
- void /* X */ * _kobj;
- uint8_t _voice;
- uint8_t _note;
- uint8_t _parm;
+ void /* X */ *_kobj;
+ uint8_t _voice;
+ uint8_t _note;
+ uint8_t _parm;
} DEFAULT nostartnote;
METHOD int setinstr {
- void /* X */ * _kobj;
- uint8_t _chn;
- uint16_t _patchno;
+ void /* X */ *_kobj;
+ uint8_t _chn;
+ uint16_t _patchno;
} DEFAULT nosetinstr;
METHOD int hwcontrol {
- void /* X */ * _kobj;
- uint8_t *_event;
+ void /* X */ *_kobj;
+ uint8_t *_event;
} DEFAULT nohwcontrol;
METHOD int aftertouch {
- void /* X */ * _kobj;
- uint8_t _x1;
- uint8_t _x2;
+ void /* X */ *_kobj;
+ uint8_t _x1;
+ uint8_t _x2;
} DEFAULT noaftertouch;
METHOD int panning {
- void /* X */ * _kobj;
- uint8_t _x1;
- uint8_t _x2;
+ void /* X */ *_kobj;
+ uint8_t _x1;
+ uint8_t _x2;
} DEFAULT nopanning;
METHOD int controller {
- void /* X */ * _kobj;
- uint8_t _x1;
- uint8_t _x2;
- uint16_t _x3;
+ void /* X */ *_kobj;
+ uint8_t _x1;
+ uint8_t _x2;
+ uint16_t _x3;
} DEFAULT nocontroller;
METHOD int volumemethod {
- void /* X */ * _kobj;
- uint8_t _x1;
+ void /* X */ *_kobj;
+ uint8_t _x1;
} DEFAULT novolumemethod;
METHOD int bender {
- void /* X */ * _kobj;
- uint8_t _voice;
- uint16_t _bend;
+ void /* X */ *_kobj;
+ uint8_t _voice;
+ uint16_t _bend;
} DEFAULT nobender;
METHOD int setupvoice {
- void /* X */ * _kobj;
- uint8_t _voice;
- uint8_t _chn;
+ void /* X */ *_kobj;
+ uint8_t _voice;
+ uint8_t _chn;
} DEFAULT nosetupvoice;
METHOD int sendsysex {
- void /* X */ * _kobj;
- void * _buf;
- size_t _len;
+ void /* X */ *_kobj;
+ void *_buf;
+ size_t _len;
} DEFAULT nosendsysex;
METHOD int allocvoice {
- void /* X */ * _kobj;
- uint8_t _chn;
- uint8_t _note;
- void *_x;
+ void /* X */ *_kobj;
+ uint8_t _chn;
+ uint8_t _note;
+ void *_x;
} DEFAULT noallocvoice;
METHOD int writeraw {
- void /* X */ * _kobjt;
- uint8_t * _buf;
- size_t _len;
+ void /* X */ *_kobjt;
+ uint8_t *_buf;
+ size_t _len;
} DEFAULT nowriteraw;
METHOD int reset {
- void /* X */ * _kobjt;
+ void /* X */ *_kobjt;
} DEFAULT noreset;
METHOD char * shortname {
- void /* X */ * _kobjt;
+ void /* X */ *_kobjt;
} DEFAULT noshortname;
METHOD int open {
- void /* X */ * _kobjt;
- void * _sythn;
- int _mode;
+ void /* X */ *_kobjt;
+ void *_sythn;
+ int _mode;
} DEFAULT noopen;
METHOD int close {
- void /* X */ * _kobjt;
+ void /* X */ *_kobjt;
} DEFAULT noclose;
METHOD int query {
- void /* X */ * _kobjt;
+ void /* X */ *_kobjt;
} DEFAULT noquery;
METHOD int insync {
- void /* X */ * _kobjt;
+ void /* X */ *_kobjt;
} DEFAULT noinsync;
METHOD int alloc {
- void /* x */ * _kbojt;
- uint8_t _chn;
- uint8_t _note;
+ void /* x */ *_kbojt;
+ uint8_t _chn;
+ uint8_t _note;
} DEFAULT noalloc;
OpenPOWER on IntegriCloud