ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / sound / rawmidi.h
1 #ifndef __SOUND_RAWMIDI_H
2 #define __SOUND_RAWMIDI_H
3
4 /*
5  *  Abstract layer for MIDI v1.0 stream
6  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
7  *
8  *
9  *   This program is free software; you can redistribute it and/or modify
10  *   it under the terms of the GNU General Public License as published by
11  *   the Free Software Foundation; either version 2 of the License, or
12  *   (at your option) any later version.
13  *
14  *   This program is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with this program; if not, write to the Free Software
21  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22  *
23  */
24
25 #include <sound/asound.h>
26 #include <linux/spinlock.h>
27 #include <linux/wait.h>
28 #include <asm/semaphore.h>
29
30 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
31 #include "seq_device.h"
32 #endif
33
34 /*
35  *  Raw MIDI interface
36  */
37
38 typedef enum sndrv_rawmidi_stream snd_rawmidi_stream_t;
39 typedef struct sndrv_rawmidi_info snd_rawmidi_info_t;
40 typedef struct sndrv_rawmidi_params snd_rawmidi_params_t;
41 typedef struct sndrv_rawmidi_status snd_rawmidi_status_t;
42
43 #define SNDRV_RAWMIDI_DEVICES           8
44
45 #define SNDRV_RAWMIDI_LFLG_OUTPUT       (1<<0)
46 #define SNDRV_RAWMIDI_LFLG_INPUT        (1<<1)
47 #define SNDRV_RAWMIDI_LFLG_OPEN         (3<<0)
48 #define SNDRV_RAWMIDI_LFLG_APPEND       (1<<2)
49 #define SNDRV_RAWMIDI_LFLG_NOOPENLOCK   (1<<3)
50
51 typedef struct _snd_rawmidi_runtime snd_rawmidi_runtime_t;
52 typedef struct _snd_rawmidi_substream snd_rawmidi_substream_t;
53 typedef struct _snd_rawmidi_str snd_rawmidi_str_t;
54
55 typedef struct _snd_rawmidi_ops {
56         int (*open) (snd_rawmidi_substream_t * substream);
57         int (*close) (snd_rawmidi_substream_t * substream);
58         void (*trigger) (snd_rawmidi_substream_t * substream, int up);
59         void (*drain) (snd_rawmidi_substream_t * substream);
60 } snd_rawmidi_ops_t;
61
62 typedef struct _snd_rawmidi_global_ops {
63         int (*dev_register) (snd_rawmidi_t * rmidi);
64         int (*dev_unregister) (snd_rawmidi_t * rmidi);
65 } snd_rawmidi_global_ops_t;
66
67 struct _snd_rawmidi_runtime {
68         unsigned int trigger: 1, /* transfer is running */
69                      drain: 1,  /* drain stage */
70                      oss: 1;    /* OSS compatible mode */
71         /* midi stream buffer */
72         unsigned char *buffer;  /* buffer for MIDI data */
73         size_t buffer_size;     /* size of buffer */
74         size_t appl_ptr;        /* application pointer */
75         size_t hw_ptr;          /* hardware pointer */
76         size_t avail_min;       /* min avail for wakeup */
77         size_t avail;           /* max used buffer for wakeup */
78         size_t xruns;           /* over/underruns counter */
79         /* misc */
80         spinlock_t lock;
81         wait_queue_head_t sleep;
82         /* event handler (room [output] or new bytes [input]) */
83         void (*event)(snd_rawmidi_substream_t *substream);
84         /* private data */
85         void *private_data;
86         void (*private_free)(snd_rawmidi_substream_t *substream);
87 };
88
89 struct _snd_rawmidi_substream {
90         struct list_head list;          /* list of all substream for given stream */
91         int stream;                     /* direction */
92         int number;                     /* substream number */
93         unsigned int opened: 1,         /* open flag */
94                      append: 1,         /* append flag (merge more streams) */
95                      active_sensing: 1; /* send active sensing when close */
96         int use_count;                  /* use counter (for output) */
97         size_t bytes;
98         snd_rawmidi_t *rmidi;
99         snd_rawmidi_str_t *pstr;
100         char name[32];
101         snd_rawmidi_runtime_t *runtime;
102         /* hardware layer */
103         snd_rawmidi_ops_t *ops;
104 };
105
106 typedef struct _snd_rawmidi_file {
107         snd_rawmidi_t *rmidi;
108         snd_rawmidi_substream_t *input;
109         snd_rawmidi_substream_t *output;
110 } snd_rawmidi_file_t;
111
112 struct _snd_rawmidi_str {
113         unsigned int substream_count;
114         unsigned int substream_opened;
115         struct list_head substreams;
116 };
117
118 struct _snd_rawmidi {
119         snd_card_t *card;
120
121         unsigned int device;            /* device number */
122         unsigned int info_flags;        /* SNDRV_RAWMIDI_INFO_XXXX */
123         char id[64];
124         char name[80];
125
126 #ifdef CONFIG_SND_OSSEMUL
127         int ossreg;
128 #endif
129
130         snd_rawmidi_global_ops_t *ops;
131
132         snd_rawmidi_str_t streams[2];
133
134         void *private_data;
135         void (*private_free) (snd_rawmidi_t *rmidi);
136
137         struct semaphore open_mutex;
138         wait_queue_head_t open_wait;
139
140         snd_info_entry_t *dev;
141         snd_info_entry_t *proc_entry;
142
143 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
144         snd_seq_device_t *seq_dev;
145 #endif
146 };
147
148 /* main rawmidi functions */
149
150 int snd_rawmidi_new(snd_card_t * card, char *id, int device,
151                     int output_count, int input_count,
152                     snd_rawmidi_t ** rmidi);
153 void snd_rawmidi_set_ops(snd_rawmidi_t * rmidi, int stream, snd_rawmidi_ops_t * ops);
154
155 /* control functions */
156
157 int snd_rawmidi_control_ioctl(snd_card_t * card,
158                               snd_ctl_file_t * control,
159                               unsigned int cmd,
160                               unsigned long arg);
161
162 /* callbacks */
163
164 void snd_rawmidi_receive_reset(snd_rawmidi_substream_t * substream);
165 int snd_rawmidi_receive(snd_rawmidi_substream_t * substream, const unsigned char *buffer, int count);
166 void snd_rawmidi_transmit_reset(snd_rawmidi_substream_t * substream);
167 int snd_rawmidi_transmit_empty(snd_rawmidi_substream_t * substream);
168 int snd_rawmidi_transmit_peek(snd_rawmidi_substream_t * substream, unsigned char *buffer, int count);
169 int snd_rawmidi_transmit_ack(snd_rawmidi_substream_t * substream, int count);
170 int snd_rawmidi_transmit(snd_rawmidi_substream_t * substream, unsigned char *buffer, int count);
171
172 /* main midi functions */
173
174 int snd_rawmidi_info_select(snd_card_t *card, snd_rawmidi_info_t *info);
175 int snd_rawmidi_kernel_open(int cardnum, int device, int subdevice, int mode, snd_rawmidi_file_t * rfile);
176 int snd_rawmidi_kernel_release(snd_rawmidi_file_t * rfile);
177 int snd_rawmidi_output_params(snd_rawmidi_substream_t * substream, snd_rawmidi_params_t * params);
178 int snd_rawmidi_input_params(snd_rawmidi_substream_t * substream, snd_rawmidi_params_t * params);
179 int snd_rawmidi_drop_output(snd_rawmidi_substream_t * substream);
180 int snd_rawmidi_drain_output(snd_rawmidi_substream_t * substream);
181 int snd_rawmidi_drain_input(snd_rawmidi_substream_t * substream);
182 long snd_rawmidi_kernel_read(snd_rawmidi_substream_t * substream, unsigned char *buf, long count);
183 long snd_rawmidi_kernel_write(snd_rawmidi_substream_t * substream, const unsigned char *buf, long count);
184
185 #endif /* __SOUND_RAWMIDI_H */