Lines Matching full:midi
6 /* The low level driver for the WaveFront ICS2115 MIDI interface(s)
14 * "Virtual MIDI" mode. In this mode, there are effectively *two*
15 * MIDI buses accessible via the interface, one that is routed
18 * MIDI devices to the board.
20 * This driver fully supports this mode, allowing two distinct MIDI
22 * MIDI routing, 16 to the WaveFront synth and 16 to the external MIDI
29 * using the two otherwise unused MIDI bytes. See the code for more details.
31 * NOTE: VIRTUAL MIDI MODE IS ON BY DEFAULT (see lowlevel/isa/wavefront.c)
33 * The main reason to turn off Virtual MIDI mode is when you want to
34 * tightly couple the WaveFront synth with an external MIDI
35 * device. You won't be able to distinguish the source of any MIDI
37 * part, the WaveFront won't be sending any MIDI data at all.
39 * The main reason to turn on Virtual MIDI Mode is to provide two
40 * completely independent 16-channel MIDI buses, one to the
41 * WaveFront and one to any external MIDI devices. Given the 32
55 wf_mpu_status (snd_wavefront_midi_t *midi) in wf_mpu_status() argument
58 return inb (midi->mpu_status_port); in wf_mpu_status()
62 input_avail (snd_wavefront_midi_t *midi) in input_avail() argument
65 return !(wf_mpu_status(midi) & INPUT_AVAIL); in input_avail()
69 output_ready (snd_wavefront_midi_t *midi) in output_ready() argument
72 return !(wf_mpu_status(midi) & OUTPUT_READY); in output_ready()
76 read_data (snd_wavefront_midi_t *midi) in read_data() argument
79 return inb (midi->mpu_data_port); in read_data()
83 write_data (snd_wavefront_midi_t *midi, unsigned char byte) in write_data() argument
86 outb (byte, midi->mpu_data_port); in write_data()
109 return &acard->wavefront.midi; in get_wavefront_midi()
114 snd_wavefront_midi_t *midi = &card->wavefront.midi; in snd_wavefront_midi_output_write() local
122 the MIDI interface while we're outputting stuff. See in snd_wavefront_midi_output_write()
132 if (midi->substream_output[midi->output_mpu] == NULL) { in snd_wavefront_midi_output_write()
141 if (output_ready (midi)) in snd_wavefront_midi_output_write()
145 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_output_write()
146 if ((midi->mode[midi->output_mpu] & MPU401_MODE_OUTPUT) == 0) { in snd_wavefront_midi_output_write()
147 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
150 if (output_ready (midi)) { in snd_wavefront_midi_output_write()
151 if (snd_rawmidi_transmit(midi->substream_output[midi->output_mpu], &midi_byte, 1) == 1) { in snd_wavefront_midi_output_write()
152 if (!midi->isvirtual || in snd_wavefront_midi_output_write()
155 write_data(midi, midi_byte); in snd_wavefront_midi_output_write()
158 if (midi->istimer) { in snd_wavefront_midi_output_write()
159 if (--midi->istimer <= 0) in snd_wavefront_midi_output_write()
160 del_timer(&midi->timer); in snd_wavefront_midi_output_write()
162 midi->mode[midi->output_mpu] &= ~MPU401_MODE_OUTPUT_TRIGGER; in snd_wavefront_midi_output_write()
163 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
167 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
170 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
175 if (midi->substream_output[!midi->output_mpu] == NULL) { in snd_wavefront_midi_output_write()
184 if (output_ready (midi)) in snd_wavefront_midi_output_write()
188 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_output_write()
189 if (!midi->isvirtual) in snd_wavefront_midi_output_write()
191 mpu = midi->output_mpu ^ mask; in snd_wavefront_midi_output_write()
193 if ((midi->mode[mpu] & MPU401_MODE_OUTPUT) == 0) { in snd_wavefront_midi_output_write()
194 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
197 if (snd_rawmidi_transmit_empty(midi->substream_output[mpu])) in snd_wavefront_midi_output_write()
199 if (output_ready (midi)) { in snd_wavefront_midi_output_write()
200 if (mpu != midi->output_mpu) { in snd_wavefront_midi_output_write()
201 write_data(midi, mpu == internal_mpu ? in snd_wavefront_midi_output_write()
204 midi->output_mpu = mpu; in snd_wavefront_midi_output_write()
205 } else if (snd_rawmidi_transmit(midi->substream_output[mpu], &midi_byte, 1) == 1) { in snd_wavefront_midi_output_write()
206 if (!midi->isvirtual || in snd_wavefront_midi_output_write()
209 write_data(midi, midi_byte); in snd_wavefront_midi_output_write()
213 if (midi->istimer) { in snd_wavefront_midi_output_write()
214 if (--midi->istimer <= 0) in snd_wavefront_midi_output_write()
215 del_timer(&midi->timer); in snd_wavefront_midi_output_write()
217 midi->mode[mpu] &= ~MPU401_MODE_OUTPUT_TRIGGER; in snd_wavefront_midi_output_write()
218 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
222 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
225 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_write()
232 snd_wavefront_midi_t *midi; in snd_wavefront_midi_input_open() local
242 midi = get_wavefront_midi(substream); in snd_wavefront_midi_input_open()
243 if (!midi) in snd_wavefront_midi_input_open()
246 spin_lock_irqsave (&midi->open, flags); in snd_wavefront_midi_input_open()
247 midi->mode[mpu] |= MPU401_MODE_INPUT; in snd_wavefront_midi_input_open()
248 midi->substream_input[mpu] = substream; in snd_wavefront_midi_input_open()
249 spin_unlock_irqrestore (&midi->open, flags); in snd_wavefront_midi_input_open()
257 snd_wavefront_midi_t *midi; in snd_wavefront_midi_output_open() local
267 midi = get_wavefront_midi(substream); in snd_wavefront_midi_output_open()
268 if (!midi) in snd_wavefront_midi_output_open()
271 spin_lock_irqsave (&midi->open, flags); in snd_wavefront_midi_output_open()
272 midi->mode[mpu] |= MPU401_MODE_OUTPUT; in snd_wavefront_midi_output_open()
273 midi->substream_output[mpu] = substream; in snd_wavefront_midi_output_open()
274 spin_unlock_irqrestore (&midi->open, flags); in snd_wavefront_midi_output_open()
282 snd_wavefront_midi_t *midi; in snd_wavefront_midi_input_close() local
292 midi = get_wavefront_midi(substream); in snd_wavefront_midi_input_close()
293 if (!midi) in snd_wavefront_midi_input_close()
296 spin_lock_irqsave (&midi->open, flags); in snd_wavefront_midi_input_close()
297 midi->mode[mpu] &= ~MPU401_MODE_INPUT; in snd_wavefront_midi_input_close()
298 spin_unlock_irqrestore (&midi->open, flags); in snd_wavefront_midi_input_close()
306 snd_wavefront_midi_t *midi; in snd_wavefront_midi_output_close() local
316 midi = get_wavefront_midi(substream); in snd_wavefront_midi_output_close()
317 if (!midi) in snd_wavefront_midi_output_close()
320 spin_lock_irqsave (&midi->open, flags); in snd_wavefront_midi_output_close()
321 midi->mode[mpu] &= ~MPU401_MODE_OUTPUT; in snd_wavefront_midi_output_close()
322 spin_unlock_irqrestore (&midi->open, flags); in snd_wavefront_midi_output_close()
329 snd_wavefront_midi_t *midi; in snd_wavefront_midi_input_trigger() local
340 midi = get_wavefront_midi(substream); in snd_wavefront_midi_input_trigger()
341 if (!midi) in snd_wavefront_midi_input_trigger()
344 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_input_trigger()
346 midi->mode[mpu] |= MPU401_MODE_INPUT_TRIGGER; in snd_wavefront_midi_input_trigger()
348 midi->mode[mpu] &= ~MPU401_MODE_INPUT_TRIGGER; in snd_wavefront_midi_input_trigger()
350 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_input_trigger()
355 snd_wavefront_midi_t *midi = from_timer(midi, t, timer); in snd_wavefront_midi_output_timer() local
356 snd_wavefront_card_t *card = midi->timer_card; in snd_wavefront_midi_output_timer()
359 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_output_timer()
360 mod_timer(&midi->timer, 1 + jiffies); in snd_wavefront_midi_output_timer()
361 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_timer()
368 snd_wavefront_midi_t *midi; in snd_wavefront_midi_output_trigger() local
379 midi = get_wavefront_midi(substream); in snd_wavefront_midi_output_trigger()
380 if (!midi) in snd_wavefront_midi_output_trigger()
383 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_output_trigger()
385 if ((midi->mode[mpu] & MPU401_MODE_OUTPUT_TRIGGER) == 0) { in snd_wavefront_midi_output_trigger()
386 if (!midi->istimer) { in snd_wavefront_midi_output_trigger()
387 timer_setup(&midi->timer, in snd_wavefront_midi_output_trigger()
390 mod_timer(&midi->timer, 1 + jiffies); in snd_wavefront_midi_output_trigger()
392 midi->istimer++; in snd_wavefront_midi_output_trigger()
393 midi->mode[mpu] |= MPU401_MODE_OUTPUT_TRIGGER; in snd_wavefront_midi_output_trigger()
396 midi->mode[mpu] &= ~MPU401_MODE_OUTPUT_TRIGGER; in snd_wavefront_midi_output_trigger()
398 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_output_trigger()
409 snd_wavefront_midi_t *midi; in snd_wavefront_midi_interrupt() local
415 midi = &card->wavefront.midi; in snd_wavefront_midi_interrupt()
417 if (!input_avail (midi)) { /* not for us */ in snd_wavefront_midi_interrupt()
422 spin_lock_irqsave (&midi->virtual, flags); in snd_wavefront_midi_interrupt()
425 if (input_avail (midi)) { in snd_wavefront_midi_interrupt()
426 byte = read_data (midi); in snd_wavefront_midi_interrupt()
428 if (midi->isvirtual) { in snd_wavefront_midi_interrupt()
430 substream = midi->substream_input[external_mpu]; in snd_wavefront_midi_interrupt()
433 substream = midi->substream_output[internal_mpu]; in snd_wavefront_midi_interrupt()
437 substream = midi->substream_input[internal_mpu]; in snd_wavefront_midi_interrupt()
445 if (midi->mode[mpu] & MPU401_MODE_INPUT_TRIGGER) { in snd_wavefront_midi_interrupt()
452 spin_unlock_irqrestore (&midi->virtual, flags); in snd_wavefront_midi_interrupt()
463 spin_lock_irqsave (&card->wavefront.midi.virtual, flags); in snd_wavefront_midi_enable_virtual()
464 card->wavefront.midi.isvirtual = 1; in snd_wavefront_midi_enable_virtual()
465 card->wavefront.midi.output_mpu = internal_mpu; in snd_wavefront_midi_enable_virtual()
466 card->wavefront.midi.input_mpu = internal_mpu; in snd_wavefront_midi_enable_virtual()
467 spin_unlock_irqrestore (&card->wavefront.midi.virtual, flags); in snd_wavefront_midi_enable_virtual()
476 spin_lock_irqsave (&card->wavefront.midi.virtual, flags); in snd_wavefront_midi_disable_virtual()
479 card->wavefront.midi.isvirtual = 0; in snd_wavefront_midi_disable_virtual()
480 spin_unlock_irqrestore (&card->wavefront.midi.virtual, flags); in snd_wavefront_midi_disable_virtual()
490 snd_wavefront_midi_t *midi; in snd_wavefront_midi_start() local
493 midi = &dev->midi; in snd_wavefront_midi_start()
501 for (i = 0; i < 30000 && !output_ready (midi); i++); in snd_wavefront_midi_start()
503 if (!output_ready (midi)) { in snd_wavefront_midi_start()
505 "MIDI interface not ready for command\n"); in snd_wavefront_midi_start()
510 are owned by the MIDI side of things. in snd_wavefront_midi_start()
515 outb (UART_MODE_ON, midi->mpu_command_port); in snd_wavefront_midi_start()
518 if (input_avail (midi)) { in snd_wavefront_midi_start()
519 if (read_data (midi) == MPU_ACK) { in snd_wavefront_midi_start()
528 "cannot set UART mode for MIDI interface"); in snd_wavefront_midi_start()
533 /* Route external MIDI to WaveFront synth (by default) */ in snd_wavefront_midi_start()
537 "can't enable MIDI-IN-2-synth routing.\n"); in snd_wavefront_midi_start()
541 /* Turn on Virtual MIDI, but first *always* turn it off, in snd_wavefront_midi_start()
544 "external" source bytes in the MIDI data stream. This in snd_wavefront_midi_start()
546 be used to generate none or very little MIDI output, and in snd_wavefront_midi_start()
547 thus the only source of MIDI data is actually external. Without in snd_wavefront_midi_start()
554 "virtual MIDI mode not disabled\n"); in snd_wavefront_midi_start()
555 return 0; /* We're OK, but missing the external MIDI dev */ in snd_wavefront_midi_start()
562 "cannot enable virtual MIDI mode.\n"); in snd_wavefront_midi_start()