[BACK]Return to midisynvar.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / dev

File: [cvs.NetBSD.org] / src / sys / dev / midisynvar.h (download)

Revision 1.14, Mon Apr 9 10:18:16 2012 UTC (12 years ago) by plunky
Branch: MAIN
CVS Tags: yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, tls-maxphys-base-20171202, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, thorpej-ifq-base, thorpej-ifq, thorpej-i2c-spi-conf2-base, thorpej-i2c-spi-conf2, thorpej-i2c-spi-conf-base, thorpej-i2c-spi-conf, thorpej-futex2-base, thorpej-futex2, thorpej-futex-base, thorpej-futex, thorpej-cfargs2-base, thorpej-cfargs2, thorpej-cfargs-base, thorpej-cfargs, thorpej-altq-separation-base, thorpej-altq-separation, rmind-smpnet-nbase, rmind-smpnet-base, rmind-smpnet, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, nick-nhusb-base-20170825, nick-nhusb-base-20170204, nick-nhusb-base-20161204, nick-nhusb-base-20161004, nick-nhusb-base-20160907, nick-nhusb-base-20160529, nick-nhusb-base-20160422, nick-nhusb-base-20160319, nick-nhusb-base-20151226, nick-nhusb-base-20150921, nick-nhusb-base-20150606, nick-nhusb-base-20150406, nick-nhusb-base, nick-nhusb, netbsd-9-base, netbsd-9-3-RELEASE, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-10-base, netbsd-10-0-RELEASE, netbsd-10-0-RC6, netbsd-10-0-RC5, netbsd-10-0-RC4, netbsd-10-0-RC3, netbsd-10-0-RC2, netbsd-10-0-RC1, netbsd-10, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, khorben-n900, jmcneill-usbmp-base9, jmcneill-usbmp-base10, jdolecek-ncqfixes-base, jdolecek-ncqfixes, jdolecek-ncq-base, jdolecek-ncq, isaki-audio2-base, isaki-audio2, is-mlppp-base, is-mlppp, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, bouyer-xenpvh-base2, bouyer-xenpvh-base1, bouyer-xenpvh-base, bouyer-xenpvh, bouyer-sunxi-drm-base, bouyer-sunxi-drm, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, agc-symver-base, agc-symver, ad-namecache-base3, ad-namecache-base2, ad-namecache-base1, ad-namecache-base, ad-namecache, HEAD
Changes since 1.13: +2 -4 lines

Tidy up a little, the way that midi attachment code works

- change midi_attach() to omit the 'parent' arg (there are
  only two callers of this and it is not used)

- change midisyn_attach() to midisyn_init(), so not needing a midi_softc,
  and fix the midi_pcppi driver to set hw_if and hw_hdl directly in
  its midi_softc before calling midi_attach()

- add a device_t to opl_softc structure, change opl drivers to store
  the device 'self' in opl_softc and fix opl_attach() to use this
  opl_softc->dev field directly rather than a field in an otherwise
  unused midi_softc

- remove unnecessary midi_softc from opl and cms drivers (child device
  provides that)

reviewed by mrg

/*	$NetBSD: midisynvar.h,v 1.14 2012/04/09 10:18:16 plunky Exp $	*/

/*
 * Copyright (c) 1998 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Lennart Augustsson (augustss@NetBSD.org).
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _SYS_DEV_MIDISYNVAR_H_
#define _SYS_DEV_MIDISYNVAR_H_

#include "midictl.h"

typedef struct midisyn midisyn;

/*
 * Important: any synth driver that uses midisyn must set up its methods
 * structure in a way that refers to members /by name/ and zeroes the rest
 * (as is the effect of C99 initializers with designators). This discipline
 * will allow the structure to evolve methods for newly implemented
 * functionality or to exploit capabilities of new drivers with a minimal
 * versioning burden.  Because midisyn is at present a very rudimentary and
 * partial implementation, change should be expected in this set of methods.
 * Do not hesitate to add one in the course of implementing new stuff, as
 * long as it will be generally useful and there is some reasonable fallback
 * for drivers without it.
 */
struct midisyn_methods {
	int  (*open)	(midisyn *, int /* flags */);
	void (*close)   (midisyn *);
	int  (*ioctl)   (midisyn *, u_long, void *, int, struct lwp *);
	/*
	 * allocv(midisyn *ms, uint_fast8_t chan, uint_fast8_t key);
	 * Allocate one of the devices actual voices (stealing one if
	 * necessary) to play note number 'key' (the MIDI note number, not
	 * a frequency) associated with MIDI channel chan. An implementation
	 * might want to choose a voice already last used on chan, to save
	 * shuffling of patches.
	 * One day a variant of this method will probably be needed, with an
	 * extra argument indicating whether a melodic or percussive voice is
	 * wanted.
	 */
	uint_fast16_t  (*allocv)  (midisyn *, uint_fast8_t, uint_fast8_t);
	/*
	 * attackv(midisyn *ms,
	 *         uint_fast16_t voice, midipitch_t mp, int16_t level_cB);
	 * Attack the voice 'voice' at pitch 'midipitch' with level 'level_cB'.
	 * The pitch is in MIDI Tuning units and accounts for all of the pitch
	 * adjustment controls that midisyn supports and that the driver has
	 * not reported handling internally. The level is in centibels of
	 * attenuation (0 == no attenuation, full output; reduced levels are
	 * negative) and again accounts for all level adjustments midisyn
	 * supports, except any the driver reports handling itself.
	 * The program used for the voice should be the current program of the
	 * voice's associated MIDI channel, and can be queried with MS_GETPGM.
	 */
	void (*attackv)  (midisyn *, uint_fast16_t, midipitch_t, int16_t);
	/*
	 * attackv_vel(midisyn *ms, uint_fast16_t voice,
	 *             midipitch_t mp, int16_t level_cB, uint_fast8_t vel);
	 * If the driver can do something useful with the voice's attack
	 * velocity, such as vary the attack envelope or timbre, it should
	 * provide this method. Velocity 64 represents the normal attack for
	 * the patch, lower values are softer, higher harder. IF the driver
	 * does not supply this method, midisyn will call the attackv method
	 * instead, and include the velocity in the calculation of level_cB.
	 */
	void (*attackv_vel) (midisyn *,
	                     uint_fast16_t, midipitch_t, int16_t, uint_fast8_t);
	/*
	 * releasev(midisyn *ms, uint_fast16_t voice, uint_fast8_t vel);
	 * Release the voice 'voice' with release velocity 'vel' where lower
	 * values mean slower decay, 64 refers to the normal decay envelope
	 * for the patch, and higher values mean decay faster.
	 */
	void (*releasev) (midisyn *, uint_fast16_t, uint_fast8_t);
	/*
	 * repitchv(midisyn *ms, uint_fast16_t voice, midipitch_t mp);
	 * A driver should provide this method if it is able to change the
	 * pitch of a sounding voice without rearticulating or glitching it.
	 * [not yet implemented in midisyn]
	 */
	void (*repitchv) (midisyn *, uint_fast16_t, midipitch_t);
	/*
	 * relevelv(midisyn *ms, uint_fast16_t voice, int16_t level_cB);
	 * A driver should provide this method if it is able to change the
	 * level of a sounding voice without rearticulating or glitching it.
	 * How the driver should adjust 'level_cB' to account for envelope
	 * decay since the initial level is not (quite, yet) specified; the
	 * driver may save the last level it got from midisyn, subtract from
	 * this one, and use the difference to adjust the current level out of
	 * the envelope generator. Or not.... [not yet implemented in midisyn]
	 */
	void (*relevelv) (midisyn *, uint_fast16_t, int16_t);
	/*
	 * pgmchg(midisyn *ms, uint_fast8_t chan, uint_fast8_t pgm);
	 * If the driver supports changing programs, it should do whatever it
	 * does AND be sure to store pgm in ms->pgms[chan].  (XXX?)
	 */
	void (*pgmchg)  (midisyn *, uint_fast8_t, uint_fast8_t);
	/*
	 * ctlnotice(midisyn *ms,
	 *           midictl_evt evt, uint_fast8_t chan, uint_fast16_t key);
	 * Reports any of the events on channel 'chan' that midictl (which see)
	 * manages. Return 0 for a particular event if it is not handled by the
	 * driver, nonzero if the driver handles it. Many events can be handled
	 * by midisyn if the driver ignores them, but will be left to the driver
	 * if it returns non-zero. For example, midisyn will usually combine
	 * the volume and expression controllers, plus a note's attack velocity,
	 * into a single 'level' parameter to attackv, but if the driver is
	 * responding to the volume controller on its own, midisyn will leave
	 * that controller out of the combined level computation.
	 *   The driver should respond to MIDICTL_RESET events specially. There
	 * are some items of state other than controllers that are specified to
	 * be reset; if the driver keeps such state, it should be reset. The
	 * driver should also midictl_read() all controllers it can respond to,
	 * which will ensure that midictl tracks them.
	 *   There are also things that RP-015 specifies do NOT get reset by
	 * the MIDICTL_RESET event. Don't reset those. :)
	 */
	int (*ctlnotice) (midisyn *, midictl_evt, uint_fast8_t, uint_fast16_t);
};

struct voice {
	u_int chan_note;	/* channel and note */
#define MS_CHANNOTE(chan, note) ((chan) * 256 + (note))
#define MS_GETCHAN(v) ((v)->chan_note >> 8)
	u_int seqno;		/* allocation index (increases with time) */
	int16_t velcB;		/* cB based on attack vel (relevel may need) */
	u_char inuse;
};

#define MIDI_MAX_CHANS 16

struct channelstate;

struct midisyn {
	/* Filled by synth driver */
	struct midisyn_methods *mets;
	char name[32];
	int nvoice;
	int flags;
	void *data;
	kmutex_t *lock;

	/* Set up by midisyn but available to synth driver for reading ctls */
	/*
	 * Note - there is currently no locking on this structure; if the synth
	 * driver interacts with midictl it should do so synchronously, when
	 * processing a call from midisyn, and not at other times such as upon
	 * an interrupt. (may revisit locking if problems crop up.)
	 */
	midictl ctl;
	
	/* Used by midisyn driver */
	struct voice *voices;
	u_int seqno;
	u_int16_t pgms[MIDI_MAX_CHANS]; /* ref'd if driver uses MS_GETPGM */
	struct channelstate *chnstate;
};

#define MS_GETPGM(ms, vno) ((ms)->pgms[MS_GETCHAN(&(ms)->voices[vno])])

extern const struct midi_hw_if midisyn_hw_if;

void	midisyn_init(midisyn *);

/*
 * Convert a 14-bit volume or expression controller value to centibels using
 * the General MIDI formula. The maximum controller value translates to 0 cB
 * (no attenuation), a half-range controller to -119 cB (level cut by 11.9 dB)
 * and a zero controller to INT16_MIN. If you are converting a 7-bit value
 * just shift it 7 bits left first.
 */
extern int16_t midisyn_vol2cB(uint_fast16_t);

#endif /* _SYS_DEV_MIDISYNVAR_H_ */