1 /* $NetBSD: sequencervar.h,v 1.16 2013/04/27 22:12:42 christos 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@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 callout_t sc_callout; 78 kmutex_t lock; 79 kcondvar_t wchan; 80 kcondvar_t rchan; 81 kcondvar_t lchan; 82 int dvlock; 83 int dying; 84 u_int isopen; /* Open indicator */ 85 int flags; /* Open flags */ 86 int mode; 87 #define SEQ_OLD 0 88 #define SEQ_NEW 1 89 int pbus; 90 struct selinfo wsel; /* write selector */ 91 struct selinfo rsel; /* read selector */ 92 pid_t async; /* process who wants audio SIGIO */ 93 void *sih; 94 pcq_t *pcq; 95 96 int nmidi; /* number of MIDI devices */ 97 int ndevs; 98 struct midi_dev **devs; 99 struct syn_timer timer; 100 101 struct sequencer_queue outq; /* output event queue */ 102 u_int lowat; /* output queue low water mark */ 103 char timeout; /* timeout has been set */ 104 105 struct sequencer_queue inq; /* input event queue */ 106 u_long input_stamp; 107 int sc_unit; 108 LIST_ENTRY(sequencer_softc) sc_link; 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