1 /* $NetBSD: sequencervar.h,v 1.13 2008/04/28 20:23:47 martin Exp $ */ 2 3 /* 4 * Copyright (c) 1998 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@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 34 struct midi_softc; 35 36 struct syn_timer { 37 struct timeval reftime, stoptime; 38 uint16_t tempo_beatpermin, timebase_divperbeat; 39 uint32_t usperdiv; 40 uint32_t divs_lastevent; 41 uint32_t divs_lastchange; 42 int running; 43 }; 44 45 #define SEQ_MAXQ 256 46 struct sequencer_queue { 47 seq_event_t buf[SEQ_MAXQ]; 48 u_int in; /* input index in buf */ 49 u_int out; /* output index in buf */ 50 u_int count; /* filled slots in buf */ 51 }; 52 #define SEQ_QINIT(q) ((q)->in = (q)->out = (q)->count = 0) 53 #define SEQ_QEMPTY(q) ((q)->count == 0) 54 #define SEQ_QFULL(q) ((q)->count >= SEQ_MAXQ) 55 #define SEQ_QPUT(q, e) ((q)->buf[(q)->in++] = (e), (q)->in %= SEQ_MAXQ, (q)->count++) 56 #define SEQ_QGET(q, e) ((e) = (q)->buf[(q)->out++], (q)->out %= SEQ_MAXQ, (q)->count--) 57 #define SEQ_QLEN(q) ((q)->count) 58 59 struct sequencer_softc; 60 61 #define MAXCHAN 16 62 struct midi_dev { 63 const char *name; 64 int subtype; 65 int capabilities; 66 int nr_voices; 67 int instr_bank_size; 68 int unit; 69 struct sequencer_softc *seq; 70 struct midi_softc *msc; 71 char doingsysex; /* doing a SEQ_SYSEX */ 72 }; 73 74 struct sequencer_softc { 75 struct device dev; 76 struct device *sc_dev; /* Hardware device struct */ 77 struct callout sc_callout; 78 int isopen; /* Open indicator */ 79 int flags; /* Open flags */ 80 int mode; 81 #define SEQ_OLD 0 82 #define SEQ_NEW 1 83 int rchan, wchan; 84 int pbus; 85 struct selinfo wsel; /* write selector */ 86 struct selinfo rsel; /* read selector */ 87 struct proc *async; /* process who wants audio SIGIO */ 88 void *sih; 89 90 int nmidi; /* number of MIDI devices */ 91 struct midi_dev **devs; 92 struct syn_timer timer; 93 94 struct sequencer_queue outq; /* output event queue */ 95 u_int lowat; /* output queue low water mark */ 96 char timeout; /* timeout has been set */ 97 98 struct sequencer_queue inq; /* input event queue */ 99 u_long input_stamp; 100 }; 101 102 void seq_event_intr(void *, seq_event_t *); 103 104 #define SEQUENCERUNIT(d) ((d) & 0x7f) 105 #define SEQ_IS_OLD(d) ((d) & 0x80) 106 107