Home | History | Annotate | Line # | Download | only in dev
sequencervar.h revision 1.14
      1 /*	$NetBSD: sequencervar.h,v 1.14 2011/11/23 23:07:31 jmcneill Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (augustss (at) NetBSD.org).
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/callout.h>
     33 #include <sys/vnode.h>
     34 
     35 struct midi_softc;
     36 
     37 struct syn_timer {
     38 	struct	timeval reftime, stoptime;
     39 	uint16_t	tempo_beatpermin, timebase_divperbeat;
     40 	uint32_t	usperdiv;
     41 	uint32_t	divs_lastevent;
     42 	uint32_t	divs_lastchange;
     43 	int		running;
     44 };
     45 
     46 #define SEQ_MAXQ 256
     47 struct sequencer_queue {
     48 	seq_event_t buf[SEQ_MAXQ];
     49 	u_int	in;		/* input index in buf */
     50 	u_int	out;		/* output index in buf */
     51 	u_int	count;		/* filled slots in buf */
     52 };
     53 #define SEQ_QINIT(q) ((q)->in = (q)->out = (q)->count = 0)
     54 #define SEQ_QEMPTY(q) ((q)->count == 0)
     55 #define SEQ_QFULL(q) ((q)->count >= SEQ_MAXQ)
     56 #define SEQ_QPUT(q, e) ((q)->buf[(q)->in++] = (e), (q)->in %= SEQ_MAXQ, (q)->count++)
     57 #define SEQ_QGET(q, e) ((e) = (q)->buf[(q)->out++], (q)->out %= SEQ_MAXQ, (q)->count--)
     58 #define SEQ_QLEN(q) ((q)->count)
     59 
     60 struct sequencer_softc;
     61 
     62 #define MAXCHAN 16
     63 struct midi_dev {
     64 	const char *name;
     65 	int	subtype;
     66 	int	capabilities;
     67 	int	nr_voices;
     68 	int	instr_bank_size;
     69 	int	unit;
     70 	struct	sequencer_softc *seq;
     71 	struct	midi_softc *msc;
     72 	char	doingsysex;	/* doing a SEQ_SYSEX */
     73 	vnode_t *vp;
     74 };
     75 
     76 struct sequencer_softc {
     77 	struct	device dev;
     78 	struct	device *sc_dev;	/* Hardware device struct */
     79 	callout_t sc_callout;
     80 	kmutex_t lock;
     81 	kcondvar_t wchan;
     82 	kcondvar_t rchan;
     83 	kcondvar_t lchan;
     84 	int	dvlock;
     85 	int	dying;
     86 	u_int	isopen;		/* Open indicator */
     87 	int	flags;		/* Open flags */
     88 	int	mode;
     89 #define SEQ_OLD 0
     90 #define SEQ_NEW 1
     91 	int	pbus;
     92 	struct selinfo wsel;	/* write selector */
     93 	struct selinfo rsel;	/* read selector */
     94 	pid_t	async;	/* process who wants audio SIGIO */
     95 	void	*sih;
     96 	pcq_t	*pcq;
     97 
     98 	int	nmidi;		/* number of MIDI devices */
     99 	int	ndevs;
    100 	struct	midi_dev **devs;
    101 	struct	syn_timer timer;
    102 
    103 	struct	sequencer_queue outq; /* output event queue */
    104 	u_int	lowat;		/* output queue low water mark */
    105 	char	timeout;	/* timeout has been set */
    106 
    107 	struct	sequencer_queue inq; /* input event queue */
    108 	u_long	input_stamp;
    109 };
    110 
    111 void seq_event_intr(void *, seq_event_t *);
    112 
    113 #define SEQUENCERUNIT(d) ((d) & 0x7f)
    114 #define SEQ_IS_OLD(d) ((d) & 0x80)
    115 
    116