xref: /haiku/src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.h (revision e1c4049fed1047bdb957b0529e1921e97ef94770)
1 /*
2  * midi usb driver
3  * usb_midi.h
4  *
5  * Copyright 2006-2013 Haiku Inc.  All rights reserved.
6  * Distributed under the terms of the MIT Licence.
7  *
8  * Authors:
9  *		Jérôme Duval
10  *		Pete Goodeve, pete.goodeve@computer.org
11  *
12  *		Some portions of this code were originally derived from
13  *		USB Joystick driver for BeOS R5
14  *		Copyright 2000 (C) ITO, Takayuki
15  *		All rights reserved
16  *
17  */
18 #ifndef _USB_MIDI_H
19 #define _USB_MIDI_H
20 
21 
22 #include <Drivers.h>
23 #include <USB.h>
24 #include <usb/USB_midi.h>
25 
26 #include <util/ring_buffer.h>
27 
28 /* Three levels of printout for convenience: */
29 /* #define DEBUG 1 -- more convenient to define in the code file when needed */
30 #define DEBUG_INFO 1
31 #define DEBUG_ERR 1
32 
33 /* Normally leave this enabled to leave a record in syslog */
34 #if DEBUG_ERR
35 	#define	DPRINTF_ERR(x)	dprintf x
36 #else
37 	#define DPRINTF_ERR(x)
38 #endif
39 
40 /* Use this for initialization etc. messages -- nothing repetitive: */
41 #if DEBUG_INFO
42 	#define	DPRINTF_INFO(x)	dprintf x
43 #else
44 	#define DPRINTF_INFO(x)
45 #endif
46 
47 /* Enable this to record detailed stuff: */
48 #if DEBUG
49 	#define	DPRINTF_DEBUG(x)	dprintf x
50 #else
51 	#define DPRINTF_DEBUG(x)
52 #endif
53 
54 /* a convenient way of suppressing some printouts: */
55 #define ZDPRINTF_DEBUG(x)
56 
57 
58 /* driver specific definitions */
59 
60 #define	DRIVER_NAME	"usb_midi"
61 
62 #define	MY_ID	"\033[34m" DRIVER_NAME ":\033[m "
63 #define	MY_ERR	"\033[31merror:\033[m "
64 #define	MY_WARN	"\033[31mwarning:\033[m "
65 #define	assert(x) \
66 	do { if (!(x)) { dprintf(MY_ID "assertion failed at " \
67 	 __FILE__ ", line %d\n", __LINE__); }} while (0)
68 
69 #define	DEFAULT_CONFIGURATION	0
70 
71 struct driver_cookie;
72 
73 
74 typedef struct usbmidi_device_info
75 {
76 	/* Set of actual ports ("cables" -- one or more) */
77 	struct usbmidi_port_info* ports[16];
78 
79 	/* maintain device  (common for all ports) */
80 	sem_id sem_lock;
81 	sem_id sem_send;
82 	area_id buffer_area;
83 	usb_midi_event_packet* buffer;	/* input buffer & base of area */
84 	usb_midi_event_packet* out_buffer;	/* above input buffer */
85 	size_t inMaxPkt, outMaxPkt;		/* for each of in and out buffers */
86 
87 	const usb_device* dev;
88 	uint16 ifno;
89 	int devnum;	/* unique device number */
90 	char name[20];
91 		/* = "/dev/midi/usb/n" --port number will be appended to this */
92 
93 	bool active;
94 
95 	/* work area for transfer */
96 	int bus_status;
97 	int actual_length;
98 	const usb_endpoint_info* ept_in;
99 	const usb_endpoint_info* ept_out;
100 
101 	bigtime_t timestamp;	/* Is this needed? Currently set but never read */
102 	uint flags;				/* set to 0 but never used */
103 } usbmidi_device_info;
104 
105 
106 typedef struct usbmidi_port_info
107 {
108 	/* list structure for manager */
109 	struct usbmidi_port_info* next;
110 
111 	/* Common device that does the work */
112 	usbmidi_device_info* device;
113 
114 	/* Port-specific variables */
115 	char name[40];	/* complete pathname of this port */
116 	struct ring_buffer* rbuf;
117 
118 	int cable;	/* index of this port */
119 	bool has_in, has_out;
120 
121 	int open;
122 	struct driver_cookie* open_fd;
123 
124 } usbmidi_port_info;
125 
126 
127 /*
128  usb_midi.cpp
129 */
130 
131 extern usb_module_info* usb;
132 extern const char* usb_midi_base_name;
133 
134 extern usbmidi_port_info* create_usbmidi_port(usbmidi_device_info* devinfo,
135 	int cable, bool has_in, bool has_out);
136 extern void remove_port(usbmidi_port_info* port);
137 
138 extern usbmidi_device_info* create_device(const usb_device* dev, uint16 ifno);
139 extern void remove_device(usbmidi_device_info* my_dev);
140 
141 
142 /*
143  devlist.cpp
144 */
145 
146 extern sem_id usbmidi_port_list_lock;
147 extern bool usbmidi_port_list_changed;
148 
149 extern void add_port_info(usbmidi_port_info* port);
150 extern void remove_port_info(usbmidi_port_info* port);
151 
152 extern usbmidi_port_info* search_port_info(const char* name);
153 
154 extern int find_free_device_number(void);
155 
156 extern char** usbmidi_port_names;
157 
158 extern void alloc_port_names(void);
159 extern void free_port_names(void);
160 extern void rebuild_port_names(void);
161 
162 #endif
163 
164