5 * Copyright 2006-2013 Haiku Inc. All rights reserved.
6 * Distributed under the terms of the MIT Licence.
10 * Pete Goodeve, pete.goodeve@computer.org
12 * Some portions of this code were originally derived from
13 * USB Joystick driver for BeOS R5
14 * Copyright 2000 (C) ITO, Takayuki
24 #include <usb/USB_midi.h>
26 #include "ring_buffer.h"
28 /* Three levels of printout for convenience: */
29 /* #define DEBUG 1 -- more convenient to define in the code file when needed */
33 /* Normally leave this enabled to leave a record in syslog */
35 #define DPRINTF_ERR(x) dprintf x
37 #define DPRINTF_ERR(x)
40 /* Use this for initialization etc. messages -- nothing repetitive: */
42 #define DPRINTF_INFO(x) dprintf x
44 #define DPRINTF_INFO(x)
47 /* Enable this to record detailed stuff: */
49 #define DPRINTF_DEBUG(x) dprintf x
51 #define DPRINTF_DEBUG(x)
54 /* a convenient way of suppressing some printouts: */
55 #define ZDPRINTF_DEBUG(x)
58 /* driver specific definitions */
60 #define DRIVER_NAME "usb_midi"
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 "
66 do { if (!(x)) { dprintf(MY_ID "assertion failed at " \
67 __FILE__ ", line %d\n", __LINE__); }} while (0)
69 #define DEFAULT_CONFIGURATION 0
74 typedef struct usbmidi_device_info
76 /* Set of actual ports ("cables" -- one or more) */
77 struct usbmidi_port_info
* ports
[16];
79 /* maintain device (common for all ports) */
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 */
87 const usb_device
* dev
;
89 int devnum
; /* unique device number */
91 /* = "/dev/midi/usb/n" --port number will be appended to this */
95 /* work area for transfer */
98 const usb_endpoint_info
* ept_in
;
99 const usb_endpoint_info
* ept_out
;
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
;
106 typedef struct usbmidi_port_info
108 /* list structure for manager */
109 struct usbmidi_port_info
* next
;
111 /* Common device that does the work */
112 usbmidi_device_info
* device
;
114 /* Port-specific variables */
115 char name
[40]; /* complete pathname of this port */
116 struct ring_buffer
* rbuf
;
118 int cable
; /* index of this port */
119 bool has_in
, has_out
;
122 struct driver_cookie
* open_fd
;
131 extern usb_module_info
* usb
;
132 extern const char* usb_midi_base_name
;
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
);
138 extern usbmidi_device_info
* create_device(const usb_device
* dev
, uint16 ifno
);
139 extern void remove_device(usbmidi_device_info
* my_dev
);
146 extern sem_id usbmidi_port_list_lock
;
147 extern bool usbmidi_port_list_changed
;
149 extern void add_port_info(usbmidi_port_info
* port
);
150 extern void remove_port_info(usbmidi_port_info
* port
);
152 extern usbmidi_port_info
* search_port_info(const char* name
);
154 extern int find_free_device_number(void);
156 extern char** usbmidi_port_names
;
158 extern void alloc_port_names(void);
159 extern void free_port_names(void);
160 extern void rebuild_port_names(void);