midi.h revision 1.4
1/* $OpenBSD: midi.h,v 1.4 2012/11/30 21:04:35 ratchov Exp $ */ 2/* 3 * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17#ifndef MIDI_H 18#define MIDI_H 19 20#include "abuf.h" 21#include "miofile.h" 22 23/* 24 * masks to extract command and channel of status byte 25 */ 26#define MIDI_CMDMASK 0xf0 27#define MIDI_CHANMASK 0x0f 28 29/* 30 * MIDI status bytes of voice messages 31 */ 32#define MIDI_NOFF 0x80 /* note off */ 33#define MIDI_NON 0x90 /* note on */ 34#define MIDI_KAT 0xa0 /* key after touch */ 35#define MIDI_CTL 0xb0 /* controller */ 36#define MIDI_PC 0xc0 /* program change */ 37#define MIDI_CAT 0xd0 /* channel after touch */ 38#define MIDI_BEND 0xe0 /* pitch bend */ 39#define MIDI_ACK 0xfe /* active sensing message */ 40 41/* 42 * MIDI controller numbers 43 */ 44#define MIDI_CTL_VOL 7 /* volume */ 45 46/* 47 * Max coarse value 48 */ 49#define MIDI_MAXCTL 127 50 51/* 52 * midi stream state structure 53 */ 54 55struct midiops 56{ 57 void (*imsg)(void *, unsigned char *, int); 58 void (*omsg)(void *, unsigned char *, int); 59 void (*fill)(void *, int); 60 void (*exit)(void *); 61}; 62 63struct midi { 64 struct midiops *ops; /* port/sock/dev callbacks */ 65 struct midi *owner; /* current writer stream */ 66 unsigned int mode; /* MODE_{MIDIIN,MIDIOUT} */ 67 void *arg; /* user data for callbacks */ 68#define MIDI_MSGMAX 16 /* max size of MIDI msg */ 69 unsigned char msg[MIDI_MSGMAX]; /* parsed input message */ 70 unsigned int st; /* input MIDI running status */ 71 unsigned int used; /* bytes used in ``msg'' */ 72 unsigned int idx; /* current ``msg'' size */ 73 unsigned int len; /* expected ``msg'' length */ 74 unsigned int txmask; /* list of ep we send to */ 75 unsigned int self; /* equal (1 << index) */ 76 unsigned int tickets; /* max bytes we can process */ 77 struct abuf obuf; /* output buffer */ 78}; 79 80/* 81 * midi port 82 */ 83struct port { 84 struct port *next; 85 struct port_mio mio; 86#define PORT_CFG 0 87#define PORT_INIT 1 88#define PORT_DRAIN 2 89 unsigned int state; 90 char *path; /* hold the port open ? */ 91 int hold; 92 struct midi *midi; 93}; 94 95/* 96 * midi control ports 97 */ 98extern struct port *port_list; 99 100void midi_init(void); 101void midi_done(void); 102struct midi *midi_new(struct midiops *, void *, int); 103void midi_del(struct midi *); 104void midi_log(struct midi *); 105void midi_tickets(struct midi *); 106void midi_in(struct midi *, unsigned char *, int); 107void midi_out(struct midi *, unsigned char *, int); 108void midi_send(struct midi *, unsigned char *, int); 109void midi_fill(struct midi *); 110void midi_tag(struct midi *, unsigned int); 111void midi_link(struct midi *, struct midi *); 112 113struct port *port_new(char *, unsigned int, int); 114struct port *port_bynum(int); 115void port_del(struct port *); 116int port_ref(struct port *); 117void port_unref(struct port *); 118int port_init(struct port *); 119void port_done(struct port *); 120int port_close(struct port *); 121 122#endif /* !defined(MIDI_H) */ 123