xref: /haiku/src/add-ons/kernel/drivers/midi/usb_midi/usb_midi.h (revision 04a0e9c7b68cbe3a43d38e2bca8e860fd80936fb)
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 "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 	/* list structure */ /* should not be needed eventually */
77 	struct usbmidi_device_info* next;
78 
79 	/* Set of actual ports ("cables" -- one or more) */
80 	struct usbmidi_port_info* ports[16];
81 
82 	/* maintain device  (common for all ports) */
83 	sem_id sem_lock;
84 	sem_id sem_send;
85 	area_id buffer_area;
86 	usb_midi_event_packet* buffer;	/* input buffer & base of area */
87 	usb_midi_event_packet* out_buffer;	/* above input buffer */
88 	size_t inMaxPkt, outMaxPkt;		/* for each of in and out buffers */
89 
90 	const usb_device* dev;
91 	uint16 ifno;
92 	int devnum;	/* unique device number */
93 	char name[20];
94 		/* = "/dev/midi/usb/n" --port number will be appended to this */
95 
96 	bool active;
97 
98 	/* work area for transfer */
99 	int bus_status;
100 	int actual_length;
101 	const usb_endpoint_info* ept_in;
102 	const usb_endpoint_info* ept_out;
103 
104 	bigtime_t timestamp;	/* Is this needed? Currently set but never read */
105 	uint flags;				/* set to 0 but never used */
106 } usbmidi_device_info;
107 
108 
109 typedef struct usbmidi_port_info
110 {
111 	/* list structure for manager */
112 	struct usbmidi_port_info* next;
113 
114 	/* Common device that does the work */
115 	usbmidi_device_info* device;
116 
117 	/* Port-specific variables */
118 	char name[40];	/* complete pathname of this port */
119 	struct ring_buffer* rbuf;
120 
121 	int cable;	/* index of this port */
122 	bool has_in, has_out;
123 
124 	int open;
125 	struct driver_cookie* open_fd;
126 
127 } usbmidi_port_info;
128 
129 
130 /*
131  usb_midi.cpp
132 */
133 
134 extern usb_module_info* usb;
135 extern const char* usb_midi_base_name;
136 
137 extern usbmidi_port_info* create_usbmidi_port(usbmidi_device_info* devinfo,
138 	int cable, bool has_in, bool has_out);
139 extern void remove_port(usbmidi_port_info* port);
140 
141 extern usbmidi_device_info* create_device(const usb_device* dev, uint16 ifno);
142 extern void remove_device(usbmidi_device_info* my_dev);
143 
144 
145 /*
146  devlist.cpp
147 */
148 
149 extern sem_id usbmidi_port_list_lock;
150 extern bool usbmidi_port_list_changed;
151 
152 extern void add_port_info(usbmidi_port_info* port);
153 extern void remove_port_info(usbmidi_port_info* port);
154 
155 extern usbmidi_port_info* search_port_info(const char* name);
156 
157 extern int find_free_device_number(void);
158 
159 extern char** usbmidi_port_names;
160 
161 extern void alloc_port_names(void);
162 extern void free_port_names(void);
163 extern void rebuild_port_names(void);
164 
165 #endif
166 
167