1 //midi for embedded chips,
2 //Copyright 2010 Alex Norman
4 //This file is part of avr-midi.
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.
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.
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/>.
21 * @brief Device implementation functions
32 * @defgroup midi_device Functions used when implementing your own midi device.
34 * You use the functions when you are implementing your own midi device.
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
40 * You use the midi_device_input to process input data from the device and pass
41 * it through the device's associated callbacks.
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
50 #include "midi_function_types.h"
51 #include "bytequeue/bytequeue.h"
52 #define MIDI_INPUT_QUEUE_LENGTH 192
58 THREE_BYTE_MESSAGE = 3,
59 SYSEX_MESSAGE} input_state_t;
61 typedef void (* midi_no_byte_func_t)(MidiDevice * device);
64 * \struct _midi_device
66 * @brief This structure represents the input and output functions and
67 * processing data for a midi device.
69 * A device can represent an actual physical device [serial port, usb port] or
71 * You should not need to modify this structure directly.
74 //output send function
75 midi_var_byte_func_t send_func;
77 //********input callbacks
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;
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;
91 midi_one_byte_func_t input_realtime_callback;
92 midi_one_byte_func_t input_tunerequest_callback;
95 midi_sysex_func_t input_sysex_callback;
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;
102 //pre input processing function
103 midi_no_byte_func_t pre_input_process_callback;
105 //for internal input processing
106 uint8_t input_buffer[3];
107 input_state_t input_state;
108 uint16_t input_count;
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;
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
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
125 void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input);
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
134 * \param device the midi device to associate this callback with
135 * \param send_func the callback function that will do the sending
137 void midi_device_set_send_func(MidiDevice * device, midi_var_byte_func_t send_func);
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.
145 * \param device the midi device to associate this callback with
146 * \param midi_no_byte_func_t the actual callback function
148 void midi_device_set_pre_input_process_func(MidiDevice * device, midi_no_byte_func_t pre_process_func);