Commit | Line | Data |
---|---|---|
1d43110e JH |
1 | /* |
2 | * Copyright by UWM - comments to soft-eng@cs.uwm.edu | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * 1. Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * | |
13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
23 | * SUCH DAMAGE. | |
24 | * | |
25 | */ | |
1b261ae5 JH |
26 | #define _MIDI_TABLE_C_ |
27 | #include "sound_config.h" | |
28 | ||
29 | #ifdef CONFIGURE_SOUNDCARD | |
30 | ||
31 | #ifndef EXCLUDE_CHIP_MIDI | |
32 | ||
33 | ||
34 | static int generic_midi_busy[MAX_MIDI_DEV]; | |
35 | ||
36 | long CMIDI_init (long mem_start) | |
37 | { | |
38 | ||
39 | int i; | |
40 | int n = num_midi_drivers; | |
41 | /* int n = sizeof (midi_supported) / sizeof( struct generic_midi_info ); | |
42 | */ | |
43 | for (i = 0; i < n; i++) | |
44 | { | |
45 | if ( midi_supported[i].attach (mem_start) ) | |
46 | { | |
47 | printk("MIDI: Successfully attached %s\n",midi_supported[i].name); | |
48 | } | |
49 | ||
50 | } | |
51 | return (mem_start); | |
52 | } | |
53 | ||
54 | ||
55 | int | |
56 | CMIDI_open (int dev, struct fileinfo *file) | |
57 | { | |
58 | ||
59 | int mode, err, retval; | |
60 | ||
61 | dev = dev >> 4; | |
62 | ||
63 | mode = file->mode & O_ACCMODE; | |
64 | ||
65 | ||
66 | if (generic_midi_busy[dev]) | |
67 | return (RET_ERROR(EBUSY)); | |
68 | ||
69 | ||
70 | if (dev >= num_generic_midis) | |
71 | { | |
72 | printk(" MIDI device %d not installed.\n", dev); | |
73 | return (ENXIO); | |
74 | } | |
75 | ||
76 | if (!generic_midi_devs[dev]) | |
77 | { | |
78 | printk(" MIDI device %d not initialized\n",dev); | |
79 | return (ENXIO); | |
80 | } | |
81 | ||
82 | /* If all good and healthy, go ahead and issue call! */ | |
83 | ||
84 | ||
85 | retval = generic_midi_devs[dev]->open (dev, mode) ; | |
86 | ||
87 | /* If everything ok, set device as busy */ | |
88 | ||
89 | if ( retval >= 0 ) | |
90 | generic_midi_busy[dev] = 1; | |
91 | ||
92 | return ( retval ); | |
93 | ||
94 | } | |
95 | ||
96 | int | |
97 | CMIDI_write (int dev, struct fileinfo *file, snd_rw_buf * buf, int count) | |
98 | { | |
99 | ||
100 | int retval; | |
101 | ||
102 | dev = dev >> 4; | |
103 | ||
104 | if (dev >= num_generic_midis) | |
105 | { | |
106 | printk(" MIDI device %d not installed.\n", dev); | |
107 | return (ENXIO); | |
108 | } | |
109 | ||
110 | /* Make double sure of healthiness -- doubt | |
111 | * Need we check this again?? | |
112 | * | |
113 | */ | |
114 | ||
115 | if (!generic_midi_devs[dev]) | |
116 | { | |
117 | printk(" MIDI device %d not initialized\n",dev); | |
118 | return (ENXIO); | |
119 | } | |
120 | ||
121 | /* If all good and healthy, go ahead and issue call! */ | |
122 | ||
123 | ||
124 | retval = generic_midi_devs[dev]->write (dev, buf); | |
125 | ||
126 | return ( retval ); | |
127 | ||
128 | } | |
129 | ||
130 | int | |
131 | CMIDI_read (int dev, struct fileinfo *file, snd_rw_buf *buf, int count) | |
132 | { | |
133 | int retval; | |
134 | ||
135 | dev = dev >> 4; | |
136 | ||
137 | if (dev >= num_generic_midis) | |
138 | { | |
139 | printk(" MIDI device %d not installed.\n", dev); | |
140 | return (ENXIO); | |
141 | } | |
142 | ||
143 | /* Make double sure of healthiness -- doubt | |
144 | * Need we check this again?? | |
145 | * | |
146 | */ | |
147 | ||
148 | if (!generic_midi_devs[dev]) | |
149 | { | |
150 | printk(" MIDI device %d not initialized\n",dev); | |
151 | return (ENXIO); | |
152 | } | |
153 | ||
154 | /* If all good and healthy, go ahead and issue call! */ | |
155 | ||
156 | ||
157 | retval = generic_midi_devs[dev]->read(dev,buf); | |
158 | ||
159 | return (retval); | |
160 | ||
161 | } | |
162 | ||
163 | int | |
164 | CMIDI_close (int dev, struct fileinfo *file) | |
165 | { | |
166 | ||
167 | int retval; | |
168 | dev = dev >> 4; | |
169 | ||
170 | if (dev >= num_generic_midis) | |
171 | { | |
172 | printk(" MIDI device %d not installed.\n", dev); | |
173 | return (ENXIO); | |
174 | } | |
175 | ||
176 | /* Make double sure of healthiness -- doubt | |
177 | * Need we check this again?? | |
178 | * | |
179 | */ | |
180 | ||
181 | if (!generic_midi_devs[dev]) | |
182 | { | |
183 | printk(" MIDI device %d not initialized\n",dev); | |
184 | return (ENXIO); | |
185 | } | |
186 | ||
187 | /* If all good and healthy, go ahead and issue call! */ | |
188 | ||
189 | ||
190 | generic_midi_devs[dev]->close(dev); | |
191 | ||
192 | generic_midi_busy[dev] = 0; /* Free the device */ | |
193 | ||
194 | return (0) ; | |
195 | ||
196 | } | |
197 | ||
198 | #endif | |
199 | ||
200 | #endif |