| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | // Midi.c |
| 2 | // |
||
| 3 | // Midi output routines for the atmel atmega163 (and others) |
||
| 4 | // |
||
| 5 | // depends on avrlib for buffer |
||
| 6 | // |
||
| 7 | |||
| 8 | #include "uart.h" |
||
| 9 | #include "midi.h" |
||
| 10 | //#include "debug.h" |
||
| 11 | |||
| 12 | |||
| 13 | void midiInit() { |
||
| 14 | uartInit(); |
||
| 15 | uartSetBaudRate(MIDI_BAUD_RATE); |
||
| 16 | } |
||
| 17 | |||
| 18 | // send a midi NOTE ON message from the uart of the form [0x9n, note, vel] |
||
| 19 | // where n is the midi channel from 0-F, note and vel are 7-bit numbers |
||
| 20 | u08 midiNoteOnOut(u08 note, u08 vel, u08 channel) { |
||
| 21 | uartSendByte(MIDI_NOTE_ON | (channel & MIDI_CHANNEL_MASK)); |
||
| 22 | uartSendByte(MIDI_DATA_MASK & note); |
||
| 23 | uartSendByte(MIDI_DATA_MASK & vel); |
||
| 24 | |||
| 25 | return 0; |
||
| 26 | } |
||
| 27 | |||
| 28 | // send a midi NOTE OFF message from the uart of the form [0x8n, note, vel] |
||
| 29 | // where n is the midi channel from 0-F, note and vel are 7-bit numbers |
||
| 30 | u08 midiNoteOffOut(u08 note, u08 vel, u08 channel) { |
||
| 31 | uartSendByte(MIDI_NOTE_OFF | (channel & MIDI_CHANNEL_MASK)); |
||
| 32 | uartSendByte(MIDI_DATA_MASK & note); |
||
| 33 | uartSendByte(MIDI_DATA_MASK & vel); |
||
| 34 | |||
| 35 | return 0; |
||
| 36 | } |
||
| 37 | |||
| 38 | // send a midi CONTROL CHANGE message from the uart of the form [0xBn, controller, value] |
||
| 39 | // where n is the midi channel from 0-F, controller and value are 7-bit numbers |
||
| 40 | u08 midiControlChangeOut(u08 controller, u08 value, u08 channel) { |
||
| 41 | uartSendByte(MIDI_CONTROL_CHANGE | (channel & MIDI_CHANNEL_MASK)); |
||
| 42 | uartSendByte(MIDI_DATA_MASK & controller); |
||
| 43 | uartSendByte(MIDI_DATA_MASK & value); |
||
| 44 | |||
| 45 | return 0; |
||
| 46 | } |
||
| 47 | |||
| 48 | // send a midi PROGRAM CHANGE message from the uart of the form [0xCn, program] |
||
| 49 | // where n is the midi channel from 0-F, program is a 7-bit number |
||
| 50 | u08 midiProgramChangeOut(u08 program, u08 channel) { |
||
| 51 | uartSendByte(MIDI_PROGRAM_CHANGE | (channel & MIDI_CHANNEL_MASK)); |
||
| 52 | uartSendByte(MIDI_DATA_MASK & program); |
||
| 53 | |||
| 54 | return 0; |
||
| 55 | } |
||
| 56 | |||
| 57 | // send a midi POLYPHONIC AFTERTOUCH message from the uart of the form [0xCn, controller, value] |
||
| 58 | // where n is the midi channel from 0-F, note and pressure are 7-bit numbers |
||
| 59 | u08 midiPolyTouchOut(u08 note, u08 pressure, u08 channel) { |
||
| 60 | uartSendByte(MIDI_POLY_TOUCH | (channel & MIDI_CHANNEL_MASK)); |
||
| 61 | uartSendByte(MIDI_DATA_MASK & note); |
||
| 62 | uartSendByte(MIDI_DATA_MASK & pressure); |
||
| 63 | |||
| 64 | return 0; |
||
| 65 | } |
||
| 66 | |||
| 67 | // send a midi CHANNEL AFTERTOUCH message from the uart of the form [0xDn, pressure] |
||
| 68 | // where n is the midi channel from 0-F, and pressure is a 7-bit number |
||
| 69 | u08 midiChannelTouchOut(u08 pressure, u08 channel) { |
||
| 70 | uartSendByte(MIDI_CHANNEL_TOUCH | (channel & MIDI_CHANNEL_MASK)); |
||
| 71 | uartSendByte(MIDI_DATA_MASK & pressure); |
||
| 72 | |||
| 73 | return 0; |
||
| 74 | } |
||
| 75 | |||
| 76 | // send a midi PITCH BEND message from the uart of the form [0xEn, bendLSB, bendMSB ] |
||
| 77 | // where n is the midi channel from 0-F, and bendLSB and bendMSB are 7-bit numbers |
||
| 78 | // note that MIDI devices normally pack together bendLSB and bendMSB to make a 14-bit number |
||
| 79 | u08 midiPitchBendOut(u08 bendLSB, u08 bendMSB, u08 channel) { |
||
| 80 | uartSendByte(MIDI_PITCH_BEND | (channel & MIDI_CHANNEL_MASK)); |
||
| 81 | uartSendByte(MIDI_DATA_MASK & bendLSB); |
||
| 82 | uartSendByte(MIDI_DATA_MASK & bendMSB); |
||
| 83 | return 0; |
||
| 84 | } |
Powered by WebSVN v2.8.3