BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / midi / usb_midi / usb_midi.h
blob42dd5dd066fba137a873045979a1b17ab516b627
1 /*
2 * midi usb driver
3 * usb_midi.h
5 * Copyright 2006-2013 Haiku Inc. All rights reserved.
6 * Distributed under the terms of the MIT Licence.
8 * Authors:
9 * Jérôme Duval
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
15 * All rights reserved
18 #ifndef _USB_MIDI_H
19 #define _USB_MIDI_H
22 #include <Drivers.h>
23 #include <USB.h>
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 */
30 #define DEBUG_INFO 1
31 #define DEBUG_ERR 1
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
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
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
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 "
65 #define assert(x) \
66 do { if (!(x)) { dprintf(MY_ID "assertion failed at " \
67 __FILE__ ", line %d\n", __LINE__); }} while (0)
69 #define DEFAULT_CONFIGURATION 0
71 struct driver_cookie;
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) */
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 */
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 */
93 bool active;
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;
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;
121 int open;
122 struct driver_cookie* open_fd;
124 } usbmidi_port_info;
128 usb_midi.cpp
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);
143 devlist.cpp
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);
162 #endif