Main Page   Compound List   File List   Compound Members   File Members  

midi.c

Go to the documentation of this file.
00001 //  Midi.c
00002 //
00003 //  Midi output routines for the atmel atmega163 (and others)
00004 //  
00005 //  depends on avrlib for buffer
00006 //  
00007 
00008 #include "uart.h"
00009 #include "midi.h"
00010 #include "debug.h"
00011 
00012 
00013 void midiInit() {
00014         uartInit();
00015         uartSetBaudRate(MIDI_BAUD_RATE);
00016 }
00017 
00018 // send a midi NOTE ON message from the uart of the form [0x9n, note, vel]
00019 // where n is the midi channel from 0-F, note and vel are 7-bit numbers
00020 u08 midiNoteOnOut(u08 note, u08 vel, u08 channel) {
00021         uartSendByte(MIDI_NOTE_ON | (channel & MIDI_CHANNEL_MASK));
00022         uartSendByte(MIDI_DATA_MASK & note);
00023         uartSendByte(MIDI_DATA_MASK & vel);
00024 
00025         return 0;
00026 }
00027 
00028 // send a midi NOTE OFF  message from the uart of the form [0x8n, note, vel]
00029 // where n is the midi channel from 0-F, note and vel are 7-bit numbers
00030 u08 midiNoteOffOut(u08 note, u08 vel, u08 channel) {
00031         uartSendByte(MIDI_NOTE_OFF | (channel & MIDI_CHANNEL_MASK));
00032         uartSendByte(MIDI_DATA_MASK & note);
00033         uartSendByte(MIDI_DATA_MASK & vel);
00034 
00035         return 0;
00036 }
00037 
00038 // send a midi CONTROL CHANGE message from the uart of the form [0xBn, controller, value]
00039 // where n is the midi channel from 0-F, controller and value are 7-bit numbers
00040 u08 midiControlChangeOut(u08 controller, u08 value, u08 channel) {
00041         uartSendByte(MIDI_CONTROL_CHANGE | (channel & MIDI_CHANNEL_MASK));
00042         uartSendByte(MIDI_DATA_MASK & controller);
00043         uartSendByte(MIDI_DATA_MASK & value);
00044 
00045         return 0;
00046 }
00047 
00048 // send a midi PROGRAM CHANGE message from the uart of the form [0xCn, program]
00049 // where n is the midi channel from 0-F, program is a 7-bit number
00050 u08 midiProgramChangeOut(u08 program, u08 channel) {
00051         uartSendByte(MIDI_PROGRAM_CHANGE | (channel & MIDI_CHANNEL_MASK));
00052         uartSendByte(MIDI_DATA_MASK & program);
00053 
00054         return 0;
00055 }
00056 
00057 // send a midi POLYPHONIC AFTERTOUCH message from the uart of the form [0xCn, controller, value]
00058 // where n is the midi channel from 0-F, note and pressure are 7-bit numbers
00059 u08 midiPolyTouchOut(u08 note, u08 pressure, u08 channel) {
00060         uartSendByte(MIDI_POLY_TOUCH | (channel & MIDI_CHANNEL_MASK));
00061         uartSendByte(MIDI_DATA_MASK & note);
00062         uartSendByte(MIDI_DATA_MASK & pressure);
00063 
00064         return 0;
00065 }
00066 
00067 // send a midi CHANNEL AFTERTOUCH message from the uart of the form [0xDn, pressure]
00068 // where n is the midi channel from 0-F, and pressure is a 7-bit number
00069 u08 midiChannelTouchOut(u08 pressure, u08 channel) {
00070         uartSendByte(MIDI_CHANNEL_TOUCH | (channel & MIDI_CHANNEL_MASK));
00071         uartSendByte(MIDI_DATA_MASK & pressure);
00072 
00073         return 0;
00074 }
00075 
00076 // send a midi PITCH BEND message from the uart of the form [0xEn, bendLSB, bendMSB ]
00077 // where n is the midi channel from 0-F, and bendLSB and bendMSB are 7-bit numbers
00078 // note that MIDI devices normally pack together bendLSB and bendMSB to make a 14-bit number
00079 u08 midiPitchBendOut(u08 bendLSB, u08 bendMSB, u08 channel) {
00080         uartSendByte(MIDI_PITCH_BEND | (channel & MIDI_CHANNEL_MASK));
00081         uartSendByte(MIDI_DATA_MASK & bendLSB);
00082         uartSendByte(MIDI_DATA_MASK & bendMSB);
00083         return 0;
00084 }

Generated at Fri Oct 25 15:36:38 2002 for avrlib by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001