xref: /openbsd/usr.bin/sndiod/sysex.h (revision d9a51c35)
1 /*	$OpenBSD: sysex.h,v 1.3 2022/12/26 19:16:03 jmc Exp $	*/
2 /*
3  * Copyright (c) 2011 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 AUCAT_SYSEX_H
18 #define AUCAT_SYSEX_H
19 
20 #include <stdint.h>
21 
22 /*
23  * start and end markers
24  */
25 #define SYSEX_START		0xf0
26 #define SYSEX_END		0xf7
27 
28 /*
29  * type/vendor namespace IDs we use
30  */
31 #define SYSEX_TYPE_RT		0x7f	/* real-time universal */
32 #define SYSEX_TYPE_EDU		0x7d	/* non-comercial */
33 
34 /*
35  * realtime messages in the "universal real-time" namespace
36  */
37 #define SYSEX_MTC		0x01		/* mtc messages */
38 #define   SYSEX_MTC_FULL	0x01		/* mtc full frame message */
39 #define SYSEX_CONTROL		0x04
40 #define   SYSEX_MASTER		0x01
41 #define SYSEX_MMC		0x06
42 #define   SYSEX_MMC_STOP	0x01
43 #define   SYSEX_MMC_START	0x02
44 #define   SYSEX_MMC_LOC		0x44
45 #define   SYSEX_MMC_LOC_LEN	0x06
46 #define   SYSEX_MMC_LOC_CMD	0x01
47 
48 /*
49  * special "any" midi device number
50  */
51 #define SYSEX_DEV_ANY		0x7f
52 
53 /*
54  * aucat-specific messages, in the "edu" namespace
55  */
56 #define SYSEX_AUCAT		0x23		/* aucat-specific */
57 #define   SYSEX_AUCAT_SLOTDESC	0x01		/* mixer info */
58 #define   SYSEX_AUCAT_DUMPREQ	0x02		/* dump request */
59 #define   SYSEX_AUCAT_DUMPEND	0x03		/* end of dump */
60 
61 /*
62  * minimum size of sysex message we accept
63  */
64 #define SYSEX_SIZE(m)	(5 + sizeof(struct sysex_ ## m))
65 
66 /*
67  * all possible system exclusive messages we support. For aucat-specific
68  * messages we use the same header as real-time messages to simplify the
69  * message parser
70  */
71 struct sysex {
72 	uint8_t start;
73 	uint8_t type;				/* type or vendor id */
74 	uint8_t dev;				/* device or product id */
75 	uint8_t id0;				/* message id */
76 	uint8_t id1;				/* sub-id */
77 	union sysex_all {
78 		struct sysex_empty {
79 			uint8_t end;
80 		} empty;
81 		struct sysex_master {
82 			uint8_t fine;
83 			uint8_t coarse;
84 			uint8_t end;
85 		} master;
86 		struct sysex_start {
87 			uint8_t end;
88 		} start;
89 		struct sysex_stop {
90 			uint8_t end;
91 		} stop;
92 		struct sysex_loc {
93 			uint8_t len;
94 			uint8_t cmd;
95 			uint8_t hr;
96 			uint8_t min;
97 			uint8_t sec;
98 			uint8_t fr;
99 			uint8_t cent;
100 			uint8_t end;
101 		} loc;
102 		struct sysex_full {
103 			uint8_t hr;
104 			uint8_t min;
105 			uint8_t sec;
106 			uint8_t fr;
107 			uint8_t end;
108 		} full;
109 		struct sysex_slotdesc {
110 			uint8_t chan;			/* channel */
111 			uint8_t vol;			/* current volume */
112 #define SYSEX_NAMELEN	10				/* \0 included */
113 			uint8_t name[SYSEX_NAMELEN];	/* stream name */
114 			uint8_t end;
115 		} slotdesc;
116 		struct sysex_dumpreq {
117 			uint8_t end;
118 		} dumpreq;
119 		struct sysex_dumpend {
120 			uint8_t end;
121 		} dumpend;
122 	} u;
123 };
124 
125 #endif /* !defined(AUCAT_SYSEX_H) */
126