Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: sequencervar.h,v 1.17 2014/12/22 07:02:22 mrg 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 	char	doingsysex;	/* doing a SEQ_SYSEX */
     72 	vnode_t *vp;
     73 };
     74 
     75 struct sequencer_softc {
     76 	callout_t sc_callout;
     77 	kmutex_t lock;
     78 	kcondvar_t wchan;
     79 	kcondvar_t rchan;
     80 	kcondvar_t lchan;
     81 	int	dvlock;
     82 	int	dying;
     83 	u_int	isopen;		/* Open indicator */
     84 	int	flags;		/* Open flags */
     85 	int	mode;
     86 #define SEQ_OLD 0
     87 #define SEQ_NEW 1
     88 	int	pbus;
     89 	struct selinfo wsel;	/* write selector */
     90 	struct selinfo rsel;	/* read selector */
     91 	pid_t	async;	/* process who wants audio SIGIO */
     92 	void	*sih;
     93 	pcq_t	*pcq;
     94 
     95 	int	nmidi;		/* number of MIDI devices */
     96 	int	ndevs;
     97 	struct	midi_dev **devs;
     98 	struct	syn_timer timer;
     99 
    100 	struct	sequencer_queue outq; /* output event queue */
    101 	u_int	lowat;		/* output queue low water mark */
    102 	char	timeout;	/* timeout has been set */
    103 
    104 	struct	sequencer_queue inq; /* input event queue */
    105 	u_long	input_stamp;
    106 	int	sc_unit;
    107 	LIST_ENTRY(sequencer_softc) sc_link;
    108 };
    109 
    110 void seq_event_intr(void *, seq_event_t *);
    111 
    112 #define SEQUENCERUNIT(d) ((d) & 0x7f)
    113 #define SEQ_IS_OLD(d) ((d) & 0x80)
    114 
    115