midi.h revision 1.13
1/* $OpenBSD: midi.h,v 1.13 2020/06/12 15:40:18 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 last_st; /* backup of st during sysex */ 72 unsigned int used; /* bytes used in ``msg'' */ 73 unsigned int idx; /* current ``msg'' size */ 74 unsigned int len; /* expected ``msg'' length */ 75 unsigned int txmask; /* list of ep we send to */ 76 unsigned int self; /* equal (1 << index) */ 77 int tickets; /* max bytes we can process */ 78 struct abuf obuf; /* output buffer */ 79}; 80 81/* 82 * midi port 83 */ 84struct port { 85 struct port *next; 86 struct port_mio mio; 87#define PORT_CFG 0 88#define PORT_INIT 1 89#define PORT_DRAIN 2 90 unsigned int state; 91 unsigned int num; /* port serial number */ 92 struct name *path_list; 93 int hold; /* hold the port open ? */ 94 struct midi *midi; 95}; 96 97/* 98 * midi control ports 99 */ 100extern struct port *port_list; 101 102void midi_init(void); 103void midi_done(void); 104struct midi *midi_new(struct midiops *, void *, int); 105void midi_del(struct midi *); 106void midi_log(struct midi *); 107void midi_tickets(struct midi *); 108void midi_in(struct midi *, unsigned char *, int); 109void midi_out(struct midi *, unsigned char *, int); 110void midi_send(struct midi *, unsigned char *, int); 111void midi_fill(struct midi *); 112void midi_tag(struct midi *, unsigned int); 113unsigned int midi_tags(struct midi *); 114void midi_link(struct midi *, struct midi *); 115 116void port_log(struct port *); 117struct port *port_new(char *, unsigned int, int); 118struct port *port_bynum(int); 119void port_del(struct port *); 120int port_ref(struct port *); 121void port_unref(struct port *); 122int port_init(struct port *); 123void port_done(struct port *); 124void port_drain(struct port *); 125int port_close(struct port *); 126int port_reopen(struct port *); 127void port_abort(struct port *); 128 129#endif /* !defined(MIDI_H) */ 130