diff options
Diffstat (limited to 'protocol/lufa/midi/midi_device.h')
| -rwxr-xr-x | protocol/lufa/midi/midi_device.h | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/protocol/lufa/midi/midi_device.h b/protocol/lufa/midi/midi_device.h new file mode 100755 index 000000000..088995286 --- /dev/null +++ b/protocol/lufa/midi/midi_device.h | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | //midi for embedded chips, | ||
| 2 | //Copyright 2010 Alex Norman | ||
| 3 | // | ||
| 4 | //This file is part of avr-midi. | ||
| 5 | // | ||
| 6 | //avr-midi is free software: you can redistribute it and/or modify | ||
| 7 | //it under the terms of the GNU General Public License as published by | ||
| 8 | //the Free Software Foundation, either version 3 of the License, or | ||
| 9 | //(at your option) any later version. | ||
| 10 | // | ||
| 11 | //avr-midi is distributed in the hope that it will be useful, | ||
| 12 | //but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | //GNU General Public License for more details. | ||
| 15 | // | ||
| 16 | //You should have received a copy of the GNU General Public License | ||
| 17 | //along with avr-midi. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | /** | ||
| 20 | * @file | ||
| 21 | * @brief Device implementation functions | ||
| 22 | */ | ||
| 23 | |||
| 24 | #ifndef MIDI_DEVICE_H | ||
| 25 | #define MIDI_DEVICE_H | ||
| 26 | |||
| 27 | #ifdef __cplusplus | ||
| 28 | extern "C" { | ||
| 29 | #endif | ||
| 30 | |||
| 31 | /** | ||
| 32 | * @defgroup midi_device Functions used when implementing your own midi device. | ||
| 33 | * | ||
| 34 | * You use the functions when you are implementing your own midi device. | ||
| 35 | * | ||
| 36 | * You set a send function to actually send bytes via your device, this method | ||
| 37 | * is called when you call a send function with this device, for instance | ||
| 38 | * midi_send_cc | ||
| 39 | * | ||
| 40 | * You use the midi_device_input to process input data from the device and pass | ||
| 41 | * it through the device's associated callbacks. | ||
| 42 | * | ||
| 43 | * You use the midi_device_set_pre_input_process_func if you want to have a | ||
| 44 | * function called at the beginning of the device's process function, generally | ||
| 45 | * to poll for input and pass that into midi_device_input | ||
| 46 | * | ||
| 47 | * @{ | ||
| 48 | */ | ||
| 49 | |||
| 50 | #include "midi_function_types.h" | ||
| 51 | #include "bytequeue/bytequeue.h" | ||
| 52 | #define MIDI_INPUT_QUEUE_LENGTH 192 | ||
| 53 | |||
| 54 | typedef enum { | ||
| 55 | IDLE, | ||
| 56 | ONE_BYTE_MESSAGE = 1, | ||
| 57 | TWO_BYTE_MESSAGE = 2, | ||
| 58 | THREE_BYTE_MESSAGE = 3, | ||
| 59 | SYSEX_MESSAGE} input_state_t; | ||
| 60 | |||
| 61 | typedef void (* midi_no_byte_func_t)(MidiDevice * device); | ||
| 62 | |||
| 63 | /** | ||
| 64 | * \struct _midi_device | ||
| 65 | * | ||
| 66 | * @brief This structure represents the input and output functions and | ||
| 67 | * processing data for a midi device. | ||
| 68 | * | ||
| 69 | * A device can represent an actual physical device [serial port, usb port] or | ||
| 70 | * something virtual. | ||
| 71 | * You should not need to modify this structure directly. | ||
| 72 | */ | ||
| 73 | struct _midi_device { | ||
| 74 | //output send function | ||
| 75 | midi_var_byte_func_t send_func; | ||
| 76 | |||
| 77 | //********input callbacks | ||
| 78 | //three byte funcs | ||
| 79 | midi_three_byte_func_t input_cc_callback; | ||
| 80 | midi_three_byte_func_t input_noteon_callback; | ||
| 81 | midi_three_byte_func_t input_noteoff_callback; | ||
| 82 | midi_three_byte_func_t input_aftertouch_callback; | ||
| 83 | midi_three_byte_func_t input_pitchbend_callback; | ||
| 84 | midi_three_byte_func_t input_songposition_callback; | ||
| 85 | //two byte funcs | ||
| 86 | midi_two_byte_func_t input_progchange_callback; | ||
| 87 | midi_two_byte_func_t input_chanpressure_callback; | ||
| 88 | midi_two_byte_func_t input_songselect_callback; | ||
| 89 | midi_two_byte_func_t input_tc_quarterframe_callback; | ||
| 90 | //one byte funcs | ||
| 91 | midi_one_byte_func_t input_realtime_callback; | ||
| 92 | midi_one_byte_func_t input_tunerequest_callback; | ||
| 93 | |||
| 94 | //sysex | ||
| 95 | midi_sysex_func_t input_sysex_callback; | ||
| 96 | |||
| 97 | //only called if more specific callback is not matched | ||
| 98 | midi_var_byte_func_t input_fallthrough_callback; | ||
| 99 | //called if registered, independent of other callbacks | ||
| 100 | midi_var_byte_func_t input_catchall_callback; | ||
| 101 | |||
| 102 | //pre input processing function | ||
| 103 | midi_no_byte_func_t pre_input_process_callback; | ||
| 104 | |||
| 105 | //for internal input processing | ||
| 106 | uint8_t input_buffer[3]; | ||
| 107 | input_state_t input_state; | ||
| 108 | uint16_t input_count; | ||
| 109 | |||
| 110 | //for queueing data between the input and the processing functions | ||
| 111 | uint8_t input_queue_data[MIDI_INPUT_QUEUE_LENGTH]; | ||
| 112 | byteQueue_t input_queue; | ||
| 113 | }; | ||
| 114 | |||
| 115 | /** | ||
| 116 | * @brief Process input bytes. This function parses bytes and calls the | ||
| 117 | * appropriate callbacks associated with the given device. You use this | ||
| 118 | * function if you are creating a custom device and you want to have midi | ||
| 119 | * input. | ||
| 120 | * | ||
| 121 | * @param device the midi device to associate the input with | ||
| 122 | * @param cnt the number of bytes you are processing | ||
| 123 | * @param input the bytes to process | ||
| 124 | */ | ||
| 125 | void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input); | ||
| 126 | |||
| 127 | /** | ||
| 128 | * @brief Set the callback function that will be used for sending output | ||
| 129 | * data bytes. This is only used if you're creating a custom device. | ||
| 130 | * You'll most likely want the callback function to disable interrupts so | ||
| 131 | * that you can call the various midi send functions without worrying about | ||
| 132 | * locking. | ||
| 133 | * | ||
| 134 | * \param device the midi device to associate this callback with | ||
| 135 | * \param send_func the callback function that will do the sending | ||
| 136 | */ | ||
| 137 | void midi_device_set_send_func(MidiDevice * device, midi_var_byte_func_t send_func); | ||
| 138 | |||
| 139 | /** | ||
| 140 | * @brief Set a callback which is called at the beginning of the | ||
| 141 | * midi_device_process call. This can be used to poll for input | ||
| 142 | * data and send the data through the midi_device_input function. | ||
| 143 | * You'll probably only use this if you're creating a custom device. | ||
| 144 | * | ||
| 145 | * \param device the midi device to associate this callback with | ||
| 146 | * \param midi_no_byte_func_t the actual callback function | ||
| 147 | */ | ||
| 148 | void midi_device_set_pre_input_process_func(MidiDevice * device, midi_no_byte_func_t pre_process_func); | ||
| 149 | |||
| 150 | /**@}*/ | ||
| 151 | |||
| 152 | #ifdef __cplusplus | ||
| 153 | } | ||
| 154 | #endif | ||
| 155 | |||
| 156 | #endif | ||
