xref: /haiku/headers/os/drivers/midi_driver.h (revision 1e36cfc2721ef13a187c6f7354dc9cbc485e89d3)
1 /* ++++++++++
2 	FILE:	midi_driver.h
3 	REVS:	$Revision: 1.1 $
4 	NAME:	herold
5 	DATE:	Tue Jun  4 15:23:29 PDT 1996
6 
7 	Interface to /dev/midi, the midi driver
8 +++++ */
9 /*
10 	Copyright 1999, Be Incorporated.   All Rights Reserved.
11 	This file may be used under the terms of the Be Sample Code License.
12 */
13 
14 #ifndef _MIDI_DRIVER_H
15 #define _MIDI_DRIVER_H
16 
17 #include <Drivers.h>
18 #include <module.h>
19 
20 /* -----
21 	ioctl codes
22 ----- */
23 
24 /* the old opcodes are deprecated, and may or may not work
25    in newer drivers */
26 enum {
27 	B_MIDI_GET_READ_TIMEOUT = B_MIDI_DRIVER_BASE,
28 	B_MIDI_SET_READ_TIMEOUT,
29 	B_MIDI_TIMED_READ,
30 	B_MIDI_TIMED_WRITE,
31 	B_MIDI_WRITE_SYNC,
32 	B_MIDI_WRITE_CLEAR,
33 	B_MIDI_GET_READ_TIMEOUT_OLD	= B_DEVICE_OP_CODES_END + 1,
34 	B_MIDI_SET_READ_TIMEOUT_OLD
35 };
36 
37 /* the default timeout when you open a midi driver */
38 #define B_MIDI_DEFAULT_TIMEOUT 1000000000000000LL
39 
40 /*	Usage:
41 	To read, set "data" to a pointer to your buffer, and "size" to the
42 	maximum size of this buffer. On return, "when" will contain the time
43 	at which the data was received (first byte) and "size" will contain
44 	the actual amount of data read.
45 	Call ioctl(fd, B_MIDI_TIMED_READ, &midi_timed_data, sizeof(midi_timed_data));
46 	To write, set "when" to when you want the first byte to go out the
47 	wire, set "data" to point to your data, and set "size" to the size
48 	of your data.
49 	Call ioctl(fd, B_MIDI_TIMED_WRITE, &midi_timed_data, sizeof(midi_timed_data));
50 */
51 typedef struct {
52 	bigtime_t when;
53 	size_t size;
54 	unsigned char * data;
55 } midi_timed_data;
56 
57 
58 /* The MIDI parser returns the number of bytes that a message contains, given the */
59 /* initial byte. For some messages, this is not known until the second byte is seen. */
60 /* For such messages, a state > 0 is returned as well as some count > 0. When state */
61 /* is > 0, you should call (*parse) for the next byte as well, which might modify */
62 /* the returned message size. Message size will always be returned with the current */
63 /* byte being counted as byte 1. A return of 0 means that the byte initiates a new */
64 /* message. SysX is handled by returning max_size until the end or next initial message */
65 /* is seen. So your loop looks something like: */
66 /*
67   uint32 state = 0;	// Only set this to 0 the first time you call the parser.
68                   // preserve the 'state' between invocations of your read() hook.
69   int todo = 0;
70   unsigned char * end = in_buf+buf_size
71   unsigned char * out_buf = in_buf;
72   while (true) {
73     uchar byte = read_midi();
74     if (!todo || state) {
75       todo = (*parser->parse)(&state, byte, end-out_buf);
76     }
77     if (todo < 1) {
78       unput_midi(byte);
79     } else {
80       *(out_buf++) = byte;
81       todo--;
82     }
83     if (todo < 1 || out_buf >= end) {
84       received_midi_message(in_buf, out_buf-in_buf);
85       todo = 0;
86     }
87   }
88    */
89 
90 #define B_MIDI_PARSER_MODULE_NAME "media/midiparser/v1"
91 
92 typedef struct _midi_parser_module_info {
93 	module_info	minfo;
94 	int		(*parse)(uint32 * state, uchar byte, size_t max_size);
95 	int		_reserved_;
96 } midi_parser_module_info;
97 
98 #define B_MPU_401_MODULE_NAME "generic/mpu401/v1"
99 
100 enum {
101 	B_MPU_401_ENABLE_CARD_INT = 1,
102 	B_MPU_401_DISABLE_CARD_INT
103 };
104 typedef struct _generic_mpu401_module {
105 	module_info minfo;
106 	status_t (*create_device)(int port, void ** out_storage, uint32 workarounds, void (*interrupt_op)(int32 op, void * card), void * card);
107 	status_t (*delete_device)(void * storage);
108 	status_t (*open_hook)(void * storage, uint32 flags, void ** out_cookie);
109 	status_t (*close_hook)(void * cookie);
110 	status_t (*free_hook)(void * cookie);
111 	status_t (*control_hook)(void * cookie, uint32 op, void * data, size_t len);
112 	status_t (*read_hook)(void * cookie, off_t pos, void * data, size_t * len);
113 	status_t (*write_hook)(void * cookie, off_t pos, const void * data, size_t * len);
114 	bool (*interrupt_hook)(void * cookie);
115 	int	_reserved_;
116 } generic_mpu401_module;
117 
118 #endif
119