1 #ifndef __SOUND_RAWMIDI_H
2 #define __SOUND_RAWMIDI_H
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/spinlock.h>
27 #include <linux/wait.h>
28 #include <asm/semaphore.h>
30 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
31 #include "seq_device.h"
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
;
43 #define SNDRV_RAWMIDI_DEVICES 8
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)
50 typedef struct _snd_rawmidi_runtime snd_rawmidi_runtime_t
;
51 typedef struct _snd_rawmidi_substream snd_rawmidi_substream_t
;
52 typedef struct _snd_rawmidi_str snd_rawmidi_str_t
;
54 typedef struct _snd_rawmidi_ops
{
55 int (*open
) (snd_rawmidi_substream_t
* substream
);
56 int (*close
) (snd_rawmidi_substream_t
* substream
);
57 void (*trigger
) (snd_rawmidi_substream_t
* substream
, int up
);
58 void (*drain
) (snd_rawmidi_substream_t
* substream
);
61 typedef struct _snd_rawmidi_global_ops
{
62 int (*dev_register
) (snd_rawmidi_t
* rmidi
);
63 int (*dev_unregister
) (snd_rawmidi_t
* rmidi
);
64 } snd_rawmidi_global_ops_t
;
66 struct _snd_rawmidi_runtime
{
67 unsigned int trigger
: 1, /* transfer is running */
68 drain
: 1, /* drain stage */
69 oss
: 1; /* OSS compatible mode */
70 /* midi stream buffer */
71 unsigned char *buffer
; /* buffer for MIDI data */
72 size_t buffer_size
; /* size of buffer */
73 size_t appl_ptr
; /* application pointer */
74 size_t hw_ptr
; /* hardware pointer */
75 size_t avail_min
; /* min avail for wakeup */
76 size_t avail
; /* max used buffer for wakeup */
77 size_t xruns
; /* over/underruns counter */
80 wait_queue_head_t sleep
;
81 /* event handler (room [output] or new bytes [input]) */
82 void (*event
)(snd_rawmidi_substream_t
*substream
);
85 void (*private_free
)(snd_rawmidi_substream_t
*substream
);
88 struct _snd_rawmidi_substream
{
89 struct list_head list
; /* list of all substream for given stream */
90 int stream
; /* direction */
91 int number
; /* substream number */
92 unsigned int opened
: 1, /* open flag */
93 append
: 1, /* append flag (merge more streams) */
94 active_sensing
: 1; /* send active sensing when close */
95 int use_count
; /* use counter (for output) */
98 snd_rawmidi_str_t
*pstr
;
100 snd_rawmidi_runtime_t
*runtime
;
102 snd_rawmidi_ops_t
*ops
;
105 typedef struct _snd_rawmidi_file
{
106 snd_rawmidi_t
*rmidi
;
107 snd_rawmidi_substream_t
*input
;
108 snd_rawmidi_substream_t
*output
;
109 } snd_rawmidi_file_t
;
111 struct _snd_rawmidi_str
{
112 unsigned int substream_count
;
113 unsigned int substream_opened
;
114 struct list_head substreams
;
117 struct _snd_rawmidi
{
120 unsigned int device
; /* device number */
121 unsigned int info_flags
; /* SNDRV_RAWMIDI_INFO_XXXX */
125 #ifdef CONFIG_SND_OSSEMUL
129 snd_rawmidi_global_ops_t
*ops
;
131 snd_rawmidi_str_t streams
[2];
134 void (*private_free
) (snd_rawmidi_t
*rmidi
);
136 struct semaphore open_mutex
;
137 wait_queue_head_t open_wait
;
139 snd_info_entry_t
*dev
;
140 snd_info_entry_t
*proc_entry
;
142 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
143 snd_seq_device_t
*seq_dev
;
147 /* main rawmidi functions */
149 int snd_rawmidi_new(snd_card_t
* card
, char *id
, int device
,
150 int output_count
, int input_count
,
151 snd_rawmidi_t
** rmidi
);
152 void snd_rawmidi_set_ops(snd_rawmidi_t
* rmidi
, int stream
, snd_rawmidi_ops_t
* ops
);
154 /* control functions */
156 int snd_rawmidi_control_ioctl(snd_card_t
* card
,
157 snd_ctl_file_t
* control
,
163 void snd_rawmidi_receive_reset(snd_rawmidi_substream_t
* substream
);
164 int snd_rawmidi_receive(snd_rawmidi_substream_t
* substream
, const unsigned char *buffer
, int count
);
165 void snd_rawmidi_transmit_reset(snd_rawmidi_substream_t
* substream
);
166 int snd_rawmidi_transmit_empty(snd_rawmidi_substream_t
* substream
);
167 int snd_rawmidi_transmit_peek(snd_rawmidi_substream_t
* substream
, unsigned char *buffer
, int count
);
168 int snd_rawmidi_transmit_ack(snd_rawmidi_substream_t
* substream
, int count
);
169 int snd_rawmidi_transmit(snd_rawmidi_substream_t
* substream
, unsigned char *buffer
, int count
);
171 /* main midi functions */
173 int snd_rawmidi_info_select(snd_card_t
*card
, snd_rawmidi_info_t
*info
);
174 int snd_rawmidi_kernel_open(int cardnum
, int device
, int subdevice
, int mode
, snd_rawmidi_file_t
* rfile
);
175 int snd_rawmidi_kernel_release(snd_rawmidi_file_t
* rfile
);
176 int snd_rawmidi_output_params(snd_rawmidi_substream_t
* substream
, snd_rawmidi_params_t
* params
);
177 int snd_rawmidi_input_params(snd_rawmidi_substream_t
* substream
, snd_rawmidi_params_t
* params
);
178 int snd_rawmidi_drop_output(snd_rawmidi_substream_t
* substream
);
179 int snd_rawmidi_drain_output(snd_rawmidi_substream_t
* substream
);
180 int snd_rawmidi_drain_input(snd_rawmidi_substream_t
* substream
);
181 long snd_rawmidi_kernel_read(snd_rawmidi_substream_t
* substream
, unsigned char *buf
, long count
);
182 long snd_rawmidi_kernel_write(snd_rawmidi_substream_t
* substream
, const unsigned char *buf
, long count
);
184 #endif /* __SOUND_RAWMIDI_H */