[BACK]Return to midi.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / sndiod

File: [local] / src / usr.bin / sndiod / midi.h (download)

Revision 1.1, Fri Nov 23 07:03:28 2012 UTC (11 years, 6 months ago) by ratchov
Branch: MAIN

Remplace aucat server by a new sndiod daemon aimed to be simpler
smaller and faster than aucat. It's a drop in replacement with the
following exceptions that don't affect the default setup:
  - The sample rate and the encoding are a per-device parameters
    thus -r and -e options must precede the corresponding -f option
  - MIDI thru boxes are dynamically created and no -M option
    is required anymore, so -M was removed.
  - MIDI ports are exposed with a new ``midi/N'' name, rather
    than abusing MIDI thru boxes.
with help from armani@, ok deraadt@

/*	$OpenBSD: midi.h,v 1.1 2012/11/23 07:03:28 ratchov Exp $	*/
/*
 * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#ifndef MIDI_H
#define MIDI_H

#include "abuf.h"
#include "miofile.h"

/*
 * masks to extract command and channel of status byte
 */
#define MIDI_CMDMASK	0xf0
#define MIDI_CHANMASK	0x0f

/*
 * MIDI status bytes of voice messages
 */
#define MIDI_NOFF	0x80		/* note off */
#define MIDI_NON	0x90		/* note on */
#define MIDI_KAT	0xa0		/* key after touch */
#define MIDI_CTL	0xb0		/* controller */
#define MIDI_PC		0xc0		/* program change */
#define MIDI_CAT	0xd0		/* channel after touch */
#define MIDI_BEND	0xe0		/* pitch bend */
#define MIDI_ACK	0xfe		/* active sensing message */

/*
 * MIDI controller numbers
 */
#define MIDI_CTL_VOL	7		/* volume */

/*
 * Max coarse value
 */
#define MIDI_MAXCTL		127

/*
 * midi stream state structure
 */

struct midiops
{
	void (*imsg)(void *, unsigned char *, int);
	void (*omsg)(void *, unsigned char *, int);
	void (*fill)(void *, int);
	void (*exit)(void *);
};

struct midi {
	struct midiops *ops;		/* port/sock/dev callbacks */
	struct midi *owner;		/* current writer stream */
	unsigned int mode;		/* MODE_{MIDIIN,MIDIOUT} */
	void *arg;			/* user data for callbacks */
#define MIDI_MSGMAX	16		/* max size of MIDI msg */
	unsigned char msg[MIDI_MSGMAX];	/* parsed input message */
	unsigned int st;		/* input MIDI running status */
	unsigned int used;		/* bytes used in ``msg'' */
	unsigned int idx;		/* current ``msg'' size */
	unsigned int len;		/* expected ``msg'' length */
	unsigned int txmask;		/* list of ep we send to */
	unsigned int rxmask;		/* single ep we accept data for */
	struct abuf ibuf;		/* input buffer */
	struct abuf obuf;		/* output buffer */
};

/*
 * midi port
 */
struct port {
	struct port *next;
	struct port_mio mio;
#define PORT_CFG	0
#define PORT_INIT	1
#define PORT_DRAIN	2
	unsigned int state;
	char *path;
	struct midi *midi;
	unsigned int refs;
};

/*
 * midi control ports
 */
extern struct port *port_list;

void midi_init(void);
void midi_done(void);
struct midi *midi_new(struct midiops *, void *, int);
void midi_del(struct midi *);
void midi_log(struct midi *);
int midi_in(struct midi *);
void midi_out(struct midi *, unsigned char *, int);
void midi_send(struct midi *, unsigned char *, int);
void midi_fill(struct midi *);
void midi_tag(struct midi *, unsigned int);
void midi_untag(struct midi *, unsigned int);

struct port *port_new(char *, unsigned int);
struct port *port_bynum(int);
void port_del(struct port *);
int  port_init(struct port *);
void port_done(struct port *);
int  port_close(struct port *);

#endif /* !defined(MIDI_H) */