Linux 2.6.13-rc3
[linux-2.6/next.git] / include / sound / rawmidi.h
blob3f9db510dee33391888d4da37dc506045c5221be
1 #ifndef __SOUND_RAWMIDI_H
2 #define __SOUND_RAWMIDI_H
4 /*
5 * Abstract layer for MIDI v1.0 stream
6 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
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.
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.
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
25 #include <sound/asound.h>
26 #include <linux/interrupt.h>
27 #include <linux/spinlock.h>
28 #include <linux/wait.h>
29 #include <asm/semaphore.h>
31 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
32 #include "seq_device.h"
33 #endif
36 * Raw MIDI interface
39 typedef enum sndrv_rawmidi_stream snd_rawmidi_stream_t;
40 typedef struct sndrv_rawmidi_info snd_rawmidi_info_t;
41 typedef struct sndrv_rawmidi_params snd_rawmidi_params_t;
42 typedef struct sndrv_rawmidi_status snd_rawmidi_status_t;
44 #define SNDRV_RAWMIDI_DEVICES 8
46 #define SNDRV_RAWMIDI_LFLG_OUTPUT (1<<0)
47 #define SNDRV_RAWMIDI_LFLG_INPUT (1<<1)
48 #define SNDRV_RAWMIDI_LFLG_OPEN (3<<0)
49 #define SNDRV_RAWMIDI_LFLG_APPEND (1<<2)
50 #define SNDRV_RAWMIDI_LFLG_NOOPENLOCK (1<<3)
52 typedef struct _snd_rawmidi_runtime snd_rawmidi_runtime_t;
53 typedef struct _snd_rawmidi_substream snd_rawmidi_substream_t;
54 typedef struct _snd_rawmidi_str snd_rawmidi_str_t;
56 typedef struct _snd_rawmidi_ops {
57 int (*open) (snd_rawmidi_substream_t * substream);
58 int (*close) (snd_rawmidi_substream_t * substream);
59 void (*trigger) (snd_rawmidi_substream_t * substream, int up);
60 void (*drain) (snd_rawmidi_substream_t * substream);
61 } snd_rawmidi_ops_t;
63 typedef struct _snd_rawmidi_global_ops {
64 int (*dev_register) (snd_rawmidi_t * rmidi);
65 int (*dev_unregister) (snd_rawmidi_t * rmidi);
66 } snd_rawmidi_global_ops_t;
68 struct _snd_rawmidi_runtime {
69 unsigned int 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 (new bytes, input only) */
83 void (*event)(snd_rawmidi_substream_t *substream);
84 /* defers calls to event [input] or ops->trigger [output] */
85 struct tasklet_struct tasklet;
86 /* private data */
87 void *private_data;
88 void (*private_free)(snd_rawmidi_substream_t *substream);
91 struct _snd_rawmidi_substream {
92 struct list_head list; /* list of all substream for given stream */
93 int stream; /* direction */
94 int number; /* substream number */
95 unsigned int opened: 1, /* open flag */
96 append: 1, /* append flag (merge more streams) */
97 active_sensing: 1; /* send active sensing when close */
98 int use_count; /* use counter (for output) */
99 size_t bytes;
100 snd_rawmidi_t *rmidi;
101 snd_rawmidi_str_t *pstr;
102 char name[32];
103 snd_rawmidi_runtime_t *runtime;
104 /* hardware layer */
105 snd_rawmidi_ops_t *ops;
108 typedef struct _snd_rawmidi_file {
109 snd_rawmidi_t *rmidi;
110 snd_rawmidi_substream_t *input;
111 snd_rawmidi_substream_t *output;
112 } snd_rawmidi_file_t;
114 struct _snd_rawmidi_str {
115 unsigned int substream_count;
116 unsigned int substream_opened;
117 struct list_head substreams;
120 struct _snd_rawmidi {
121 snd_card_t *card;
123 unsigned int device; /* device number */
124 unsigned int info_flags; /* SNDRV_RAWMIDI_INFO_XXXX */
125 char id[64];
126 char name[80];
128 #ifdef CONFIG_SND_OSSEMUL
129 int ossreg;
130 #endif
132 snd_rawmidi_global_ops_t *ops;
134 snd_rawmidi_str_t streams[2];
136 void *private_data;
137 void (*private_free) (snd_rawmidi_t *rmidi);
139 struct semaphore open_mutex;
140 wait_queue_head_t open_wait;
142 snd_info_entry_t *dev;
143 snd_info_entry_t *proc_entry;
145 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
146 snd_seq_device_t *seq_dev;
147 #endif
150 /* main rawmidi functions */
152 int snd_rawmidi_new(snd_card_t * card, char *id, int device,
153 int output_count, int input_count,
154 snd_rawmidi_t ** rmidi);
155 void snd_rawmidi_set_ops(snd_rawmidi_t * rmidi, int stream, snd_rawmidi_ops_t * ops);
157 /* callbacks */
159 void snd_rawmidi_receive_reset(snd_rawmidi_substream_t * substream);
160 int snd_rawmidi_receive(snd_rawmidi_substream_t * substream, const unsigned char *buffer, int count);
161 void snd_rawmidi_transmit_reset(snd_rawmidi_substream_t * substream);
162 int snd_rawmidi_transmit_empty(snd_rawmidi_substream_t * substream);
163 int snd_rawmidi_transmit_peek(snd_rawmidi_substream_t * substream, unsigned char *buffer, int count);
164 int snd_rawmidi_transmit_ack(snd_rawmidi_substream_t * substream, int count);
165 int snd_rawmidi_transmit(snd_rawmidi_substream_t * substream, unsigned char *buffer, int count);
167 /* main midi functions */
169 int snd_rawmidi_info_select(snd_card_t *card, snd_rawmidi_info_t *info);
170 int snd_rawmidi_kernel_open(int cardnum, int device, int subdevice, int mode, snd_rawmidi_file_t * rfile);
171 int snd_rawmidi_kernel_release(snd_rawmidi_file_t * rfile);
172 int snd_rawmidi_output_params(snd_rawmidi_substream_t * substream, snd_rawmidi_params_t * params);
173 int snd_rawmidi_input_params(snd_rawmidi_substream_t * substream, snd_rawmidi_params_t * params);
174 int snd_rawmidi_drop_output(snd_rawmidi_substream_t * substream);
175 int snd_rawmidi_drain_output(snd_rawmidi_substream_t * substream);
176 int snd_rawmidi_drain_input(snd_rawmidi_substream_t * substream);
177 long snd_rawmidi_kernel_read(snd_rawmidi_substream_t * substream, unsigned char *buf, long count);
178 long snd_rawmidi_kernel_write(snd_rawmidi_substream_t * substream, const unsigned char *buf, long count);
180 #endif /* __SOUND_RAWMIDI_H */