17 #define USE_SEQ_MACROS
18 #define USE_SIMPLE_MACROS
22 #define _MIDI_SYNTH_C_
34 unsigned char obuf[8]; \
36 seq_input_event(obuf, len); \
41 #define _SEQ_ADVBUF(x) len=x
46 switch (msg[0] & 0xf0)
79 (msg[1] & 0x7f) | ((msg[2] & 0x7f) << 7)));
90 midi_outc(
int midi_dev,
int data)
94 for (timeout = 0; timeout < 3200; timeout++)
95 if (midi_devs[midi_dev]->outputc(midi_dev, (
unsigned char) (data & 0xff)))
100 prev_out_status[midi_dev] =
101 (
unsigned char) (data & 0xff);
111 printk(
"Midi send timed out\n");
115 prefix_cmd(
int midi_dev,
unsigned char status)
117 if ((
char *) midi_devs[midi_dev]->prefix_cmd ==
NULL)
120 return midi_devs[midi_dev]->prefix_cmd(midi_dev, status);
124 midi_synth_input(
int orig_dev,
unsigned char data)
129 static unsigned char len_tab[] =
142 if (orig_dev < 0 || orig_dev >
num_midis || midi_devs[orig_dev] ==
NULL)
148 dev = midi2synth[orig_dev];
156 if ((data & 0xf0) == 0xf0)
190 inc->
m_left = len_tab[(data >> 4) - 8];
198 inc->
m_left = len_tab[(inc->
m_buf[0] >> 4) - 8] - 1;
229 printk(
"MIDI%d: Unexpected state %d (%02x)\n", orig_dev, inc->
m_state, (
int) data);
240 if (!sysex_state[dev])
243 sysex_state[
dev] = 0;
245 while (!midi_devs[orig_dev]->outputc(orig_dev, 0xf7) &&
249 sysex_state[
dev] = 0;
253 midi_synth_output(
int dev)
288 if (note < 0 || note > 127)
299 msg = prev_out_status[orig_dev] & 0xf0;
300 chn = prev_out_status[orig_dev] & 0x0f;
302 if (chn == channel && ((msg == 0x90 && velocity == 64) || msg == 0x80))
306 if (!prefix_cmd(orig_dev, note))
309 midi_outc(orig_dev, note);
314 midi_outc(orig_dev, 0);
319 midi_outc(orig_dev, velocity);
324 if (!prefix_cmd(orig_dev, 0x90 | (channel & 0x0f)))
326 midi_outc(orig_dev, 0x90 | (channel & 0x0f));
329 midi_outc(orig_dev, note);
330 midi_outc(orig_dev, 0);
335 if (!prefix_cmd(orig_dev, 0x80 | (channel & 0x0f)))
337 midi_outc(orig_dev, 0x80 | (channel & 0x0f));
340 midi_outc(orig_dev, note);
341 midi_outc(orig_dev, velocity);
354 if (instr_no < 0 || instr_no > 127)
361 if (!prefix_cmd(orig_dev, 0xc0 | (channel & 0x0f)))
363 midi_outc(orig_dev, 0xc0 | (channel & 0x0f));
366 midi_outc(orig_dev, instr_no);
378 if (note < 0 || note > 127)
389 msg = prev_out_status[orig_dev] & 0xf0;
390 chn = prev_out_status[orig_dev] & 0x0f;
392 if (chn == channel && msg == 0x90)
396 if (!prefix_cmd(orig_dev, note))
398 midi_outc(orig_dev, note);
399 midi_outc(orig_dev, velocity);
402 if (!prefix_cmd(orig_dev, 0x90 | (channel & 0x0f)))
404 midi_outc(orig_dev, 0x90 | (channel & 0x0f));
407 midi_outc(orig_dev, note);
408 midi_outc(orig_dev, velocity);
432 midi2synth[orig_dev] =
dev;
433 sysex_state[
dev] = 0;
434 prev_out_status[orig_dev] = 0;
437 midi_synth_input, midi_synth_output)) < 0)
465 midi_devs[orig_dev]->outputc(orig_dev, 0xfe);
479 int count,
int pmgr_flag)
485 unsigned long left, src_offs, eox_seen = 0;
491 if (!prefix_cmd(orig_dev, 0xf0))
499 if (count < hdr_size)
512 if ((
unsigned)count < (
unsigned)sysex.
len)
518 for (i = 0; i < left && !signal_pending(
current); i++)
523 (
unsigned char __user *)(addr + hdr_size + i)))
526 eox_seen = (i > 0 && data & 0x80);
528 if (eox_seen && data != 0xf7)
539 while (!
midi_devs[orig_dev]->outputc(orig_dev, (
unsigned char) (data & 0xff)) &&
543 if (!first_byte && data & 0x80)
549 midi_outc(orig_dev, 0xf7);
564 if (pressure < 0 || pressure > 127)
571 msg = prev_out_status[orig_dev] & 0xf0;
572 chn = prev_out_status[orig_dev] & 0x0f;
574 if (msg != 0xd0 || chn != channel)
578 if (!prefix_cmd(orig_dev, 0xd0 | (channel & 0x0f)))
580 midi_outc(orig_dev, 0xd0 | (channel & 0x0f));
583 }
else if (!prefix_cmd(orig_dev, pressure))
586 midi_outc(orig_dev, pressure);
596 if (ctrl_num < 0 || ctrl_num > 127)
603 msg = prev_out_status[orig_dev] & 0xf0;
604 chn = prev_out_status[orig_dev] & 0x0f;
606 if (msg != 0xb0 || chn != channel)
608 if (!prefix_cmd(orig_dev, 0xb0 | (channel & 0x0f)))
610 midi_outc(orig_dev, 0xb0 | (channel & 0x0f));
611 }
else if (!prefix_cmd(orig_dev, ctrl_num))
614 midi_outc(orig_dev, ctrl_num);
615 midi_outc(orig_dev, value & 0x7f);
628 if (value < 0 || value > 16383)
633 msg = prev_out_status[orig_dev] & 0xf0;
634 prev_chn = prev_out_status[orig_dev] & 0x0f;
636 if (msg != 0xd0 || prev_chn != channel)
640 if (!prefix_cmd(orig_dev, 0xe0 | (channel & 0x0f)))
642 midi_outc(orig_dev, 0xe0 | (channel & 0x0f));
643 }
else if (!prefix_cmd(orig_dev, value & 0x7f))
646 midi_outc(orig_dev, value & 0x7f);
647 midi_outc(orig_dev, (value >> 7) & 0x7f);
663 for (i = 0; i <
len; i++)
668 if (!prefix_cmd(orig_dev, 0xf0))
670 sysex_state[
dev] = 1;
674 if (!sysex_state[dev])
676 sysex_state[
dev] = 0;
680 if (!sysex_state[dev])
686 sysex_state[
dev] = 0;
690 if (!
midi_devs[orig_dev]->outputc(orig_dev, bytes[i]))
699 sysex_state[
dev] = 0;
701 while (!
midi_devs[orig_dev]->outputc(orig_dev, bytes[i]) &&
705 if (!sysex_state[dev])