diff options
author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tmk_core/protocol/midi | |
parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) |
clang-format changes
Diffstat (limited to 'tmk_core/protocol/midi')
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/Config/LUFAConfig.h | 28 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/bytequeue/bytequeue.c | 93 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/bytequeue/bytequeue.h | 59 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/bytequeue/interrupt_setting.c | 54 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/bytequeue/interrupt_setting.h | 33 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/midi.c | 344 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/midi.h | 152 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/midi_device.c | 477 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/midi_device.h | 121 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/midi_function_types.h | 44 | ||||
-rw-r--r-- | tmk_core/protocol/midi/qmk_midi.c | 258 | ||||
-rw-r--r-- | tmk_core/protocol/midi/qmk_midi.h | 10 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/sysex_tools.c | 158 | ||||
-rw-r--r--[-rwxr-xr-x] | tmk_core/protocol/midi/sysex_tools.h | 34 |
14 files changed, 858 insertions, 1007 deletions
diff --git a/tmk_core/protocol/midi/Config/LUFAConfig.h b/tmk_core/protocol/midi/Config/LUFAConfig.h index a1d7482672..b346c05bdd 100755..100644 --- a/tmk_core/protocol/midi/Config/LUFAConfig.h +++ b/tmk_core/protocol/midi/Config/LUFAConfig.h @@ -42,12 +42,12 @@ #ifndef _LUFA_CONFIG_H_ #define _LUFA_CONFIG_H_ - #if (ARCH == ARCH_AVR8) +#if (ARCH == ARCH_AVR8) - /* Non-USB Related Configuration Tokens: */ +/* Non-USB Related Configuration Tokens: */ // #define DISABLE_TERMINAL_CODES - /* USB Class Driver Related Tokens: */ +/* USB Class Driver Related Tokens: */ // #define HID_HOST_BOOT_PROTOCOL_ONLY // #define HID_STATETABLE_STACK_DEPTH {Insert Value Here} // #define HID_USAGE_STACK_DEPTH {Insert Value Here} @@ -56,38 +56,38 @@ // #define HID_MAX_REPORT_IDS {Insert Value Here} // #define NO_CLASS_DRIVER_AUTOFLUSH - /* General USB Driver Related Tokens: */ +/* General USB Driver Related Tokens: */ // #define ORDERED_EP_CONFIG - #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL) - #define USB_DEVICE_ONLY +# define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL) +# define USB_DEVICE_ONLY // #define USB_HOST_ONLY // #define USB_STREAM_TIMEOUT_MS {Insert Value Here} // #define NO_LIMITED_CONTROLLER_CONNECT // #define NO_SOF_EVENTS - /* USB Device Mode Driver Related Tokens: */ +/* USB Device Mode Driver Related Tokens: */ // #define USE_RAM_DESCRIPTORS - #define USE_FLASH_DESCRIPTORS +# define USE_FLASH_DESCRIPTORS // #define USE_EEPROM_DESCRIPTORS // #define NO_INTERNAL_SERIAL - #define FIXED_CONTROL_ENDPOINT_SIZE 8 +# define FIXED_CONTROL_ENDPOINT_SIZE 8 // #define DEVICE_STATE_AS_GPIOR {Insert Value Here} - #define FIXED_NUM_CONFIGURATIONS 1 +# define FIXED_NUM_CONFIGURATIONS 1 // #define CONTROL_ONLY_DEVICE // #define INTERRUPT_CONTROL_ENDPOINT // #define NO_DEVICE_REMOTE_WAKEUP // #define NO_DEVICE_SELF_POWER - /* USB Host Mode Driver Related Tokens: */ +/* USB Host Mode Driver Related Tokens: */ // #define HOST_STATE_AS_GPIOR {Insert Value Here} // #define USB_HOST_TIMEOUT_MS {Insert Value Here} // #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here} // #define NO_AUTO_VBUS_MANAGEMENT // #define INVERTED_VBUS_ENABLE_LINE - #else +#else - #error Unsupported architecture for this LUFA configuration file. +# error Unsupported architecture for this LUFA configuration file. - #endif +#endif #endif diff --git a/tmk_core/protocol/midi/bytequeue/bytequeue.c b/tmk_core/protocol/midi/bytequeue/bytequeue.c index e434956328..e36a9e66b1 100755..100644 --- a/tmk_core/protocol/midi/bytequeue/bytequeue.c +++ b/tmk_core/protocol/midi/bytequeue/bytequeue.c @@ -1,65 +1,62 @@ -//this is a single reader [maybe multiple writer?] byte queue -//Copyright 2008 Alex Norman -//writen by Alex Norman +// this is a single reader [maybe multiple writer?] byte queue +// Copyright 2008 Alex Norman +// writen by Alex Norman // -//This file is part of avr-bytequeue. +// This file is part of avr-bytequeue. // -//avr-bytequeue is free software: you can redistribute it and/or modify -//it under the terms of the GNU General Public License as published by -//the Free Software Foundation, either version 3 of the License, or +// avr-bytequeue is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or //(at your option) any later version. // -//avr-bytequeue is distributed in the hope that it will be useful, -//but WITHOUT ANY WARRANTY; without even the implied warranty of -//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -//GNU General Public License for more details. +// avr-bytequeue is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -//You should have received a copy of the GNU General Public License -//along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. +// You should have received a copy of the GNU General Public License +// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. #include "bytequeue.h" #include "interrupt_setting.h" -void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen){ - queue->length = arrayLen; - queue->data = dataArray; - queue->start = queue->end = 0; +void bytequeue_init(byteQueue_t* queue, uint8_t* dataArray, byteQueueIndex_t arrayLen) { + queue->length = arrayLen; + queue->data = dataArray; + queue->start = queue->end = 0; } -bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item){ - interrupt_setting_t setting = store_and_clear_interrupt(); - //full - if(((queue->end + 1) % queue->length) == queue->start){ - restore_interrupt_setting(setting); - return false; - } else { - queue->data[queue->end] = item; - queue->end = (queue->end + 1) % queue->length; - restore_interrupt_setting(setting); - return true; - } +bool bytequeue_enqueue(byteQueue_t* queue, uint8_t item) { + interrupt_setting_t setting = store_and_clear_interrupt(); + // full + if (((queue->end + 1) % queue->length) == queue->start) { + restore_interrupt_setting(setting); + return false; + } else { + queue->data[queue->end] = item; + queue->end = (queue->end + 1) % queue->length; + restore_interrupt_setting(setting); + return true; + } } -byteQueueIndex_t bytequeue_length(byteQueue_t * queue){ - byteQueueIndex_t len; - interrupt_setting_t setting = store_and_clear_interrupt(); - if(queue->end >= queue->start) - len = queue->end - queue->start; - else - len = (queue->length - queue->start) + queue->end; - restore_interrupt_setting(setting); - return len; +byteQueueIndex_t bytequeue_length(byteQueue_t* queue) { + byteQueueIndex_t len; + interrupt_setting_t setting = store_and_clear_interrupt(); + if (queue->end >= queue->start) + len = queue->end - queue->start; + else + len = (queue->length - queue->start) + queue->end; + restore_interrupt_setting(setting); + return len; } -//we don't need to avoid interrupts if there is only one reader -uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index){ - return queue->data[(queue->start + index) % queue->length]; -} +// we don't need to avoid interrupts if there is only one reader +uint8_t bytequeue_get(byteQueue_t* queue, byteQueueIndex_t index) { return queue->data[(queue->start + index) % queue->length]; } -//we just update the start index to remove elements -void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove){ - interrupt_setting_t setting = store_and_clear_interrupt(); - queue->start = (queue->start + numToRemove) % queue->length; - restore_interrupt_setting(setting); +// we just update the start index to remove elements +void bytequeue_remove(byteQueue_t* queue, byteQueueIndex_t numToRemove) { + interrupt_setting_t setting = store_and_clear_interrupt(); + queue->start = (queue->start + numToRemove) % queue->length; + restore_interrupt_setting(setting); } - diff --git a/tmk_core/protocol/midi/bytequeue/bytequeue.h b/tmk_core/protocol/midi/bytequeue/bytequeue.h index e4a286134f..33fb63a8cb 100755..100644 --- a/tmk_core/protocol/midi/bytequeue/bytequeue.h +++ b/tmk_core/protocol/midi/bytequeue/bytequeue.h @@ -1,28 +1,28 @@ -//this is a single reader [maybe multiple writer?] byte queue -//Copyright 2008 Alex Norman -//writen by Alex Norman +// this is a single reader [maybe multiple writer?] byte queue +// Copyright 2008 Alex Norman +// writen by Alex Norman // -//This file is part of avr-bytequeue. +// This file is part of avr-bytequeue. // -//avr-bytequeue is free software: you can redistribute it and/or modify -//it under the terms of the GNU General Public License as published by -//the Free Software Foundation, either version 3 of the License, or +// avr-bytequeue is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or //(at your option) any later version. // -//avr-bytequeue is distributed in the hope that it will be useful, -//but WITHOUT ANY WARRANTY; without even the implied warranty of -//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -//GNU General Public License for more details. +// avr-bytequeue is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -//You should have received a copy of the GNU General Public License -//along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. +// You should have received a copy of the GNU General Public License +// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. #ifndef BYTEQUEUE_H #define BYTEQUEUE_H #ifdef __cplusplus extern "C" { -#endif +#endif #include <inttypes.h> #include <stdbool.h> @@ -30,30 +30,29 @@ extern "C" { typedef uint8_t byteQueueIndex_t; typedef struct { - byteQueueIndex_t start; - byteQueueIndex_t end; - byteQueueIndex_t length; - uint8_t * data; + byteQueueIndex_t start; + byteQueueIndex_t end; + byteQueueIndex_t length; + uint8_t* data; } byteQueue_t; -//you must have a queue, an array of data which the queue will use, and the length of that array -void bytequeue_init(byteQueue_t * queue, uint8_t * dataArray, byteQueueIndex_t arrayLen); +// you must have a queue, an array of data which the queue will use, and the length of that array +void bytequeue_init(byteQueue_t* queue, uint8_t* dataArray, byteQueueIndex_t arrayLen); -//add an item to the queue, returns false if the queue is full -bool bytequeue_enqueue(byteQueue_t * queue, uint8_t item); +// add an item to the queue, returns false if the queue is full +bool bytequeue_enqueue(byteQueue_t* queue, uint8_t item); -//get the length of the queue -byteQueueIndex_t bytequeue_length(byteQueue_t * queue); +// get the length of the queue +byteQueueIndex_t bytequeue_length(byteQueue_t* queue); -//this grabs data at the index given [starting at queue->start] -uint8_t bytequeue_get(byteQueue_t * queue, byteQueueIndex_t index); +// this grabs data at the index given [starting at queue->start] +uint8_t bytequeue_get(byteQueue_t* queue, byteQueueIndex_t index); -//update the index in the queue to reflect data that has been dealt with -void bytequeue_remove(byteQueue_t * queue, byteQueueIndex_t numToRemove); +// update the index in the queue to reflect data that has been dealt with +void bytequeue_remove(byteQueue_t* queue, byteQueueIndex_t numToRemove); #ifdef __cplusplus } -#endif - #endif +#endif diff --git a/tmk_core/protocol/midi/bytequeue/interrupt_setting.c b/tmk_core/protocol/midi/bytequeue/interrupt_setting.c index 0ab8b54620..1be1fee973 100755..100644 --- a/tmk_core/protocol/midi/bytequeue/interrupt_setting.c +++ b/tmk_core/protocol/midi/bytequeue/interrupt_setting.c @@ -1,49 +1,43 @@ -//Copyright 20010 Alex Norman -//writen by Alex Norman +// Copyright 20010 Alex Norman +// writen by Alex Norman // -//This file is part of avr-bytequeue. +// This file is part of avr-bytequeue. // -//avr-bytequeue is free software: you can redistribute it and/or modify -//it under the terms of the GNU General Public License as published by -//the Free Software Foundation, either version 3 of the License, or +// avr-bytequeue is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or //(at your option) any later version. // -//avr-bytequeue is distributed in the hope that it will be useful, -//but WITHOUT ANY WARRANTY; without even the implied warranty of -//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -//GNU General Public License for more details. +// avr-bytequeue is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -//You should have received a copy of the GNU General Public License -//along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. +// You should have received a copy of the GNU General Public License +// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. - -//AVR specific code -//should be able to port to other systems by simply providing chip specific -//implementations of the typedef and these functions +// AVR specific code +// should be able to port to other systems by simply providing chip specific +// implementations of the typedef and these functions #include "interrupt_setting.h" #if defined(__AVR__) -#include <avr/interrupt.h> +# include <avr/interrupt.h> interrupt_setting_t store_and_clear_interrupt(void) { - uint8_t sreg = SREG; - cli(); - return sreg; + uint8_t sreg = SREG; + cli(); + return sreg; } -void restore_interrupt_setting(interrupt_setting_t setting) { - SREG = setting; -} +void restore_interrupt_setting(interrupt_setting_t setting) { SREG = setting; } #elif defined(__arm__) -#include "ch.h" +# include "ch.h" interrupt_setting_t store_and_clear_interrupt(void) { - chSysLock(); - return 0; + chSysLock(); + return 0; } -void restore_interrupt_setting(interrupt_setting_t setting) { - chSysUnlock(); -} +void restore_interrupt_setting(interrupt_setting_t setting) { chSysUnlock(); } #endif - diff --git a/tmk_core/protocol/midi/bytequeue/interrupt_setting.h b/tmk_core/protocol/midi/bytequeue/interrupt_setting.h index 053d02c9d0..788f75d79f 100755..100644 --- a/tmk_core/protocol/midi/bytequeue/interrupt_setting.h +++ b/tmk_core/protocol/midi/bytequeue/interrupt_setting.h @@ -1,39 +1,38 @@ -//Copyright 20010 Alex Norman -//writen by Alex Norman +// Copyright 20010 Alex Norman +// writen by Alex Norman // -//This file is part of avr-bytequeue. +// This file is part of avr-bytequeue. // -//avr-bytequeue is free software: you can redistribute it and/or modify -//it under the terms of the GNU General Public License as published by -//the Free Software Foundation, either version 3 of the License, or +// avr-bytequeue is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or //(at your option) any later version. // -//avr-bytequeue is distributed in the hope that it will be useful, -//but WITHOUT ANY WARRANTY; without even the implied warranty of -//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -//GNU General Public License for more details. +// avr-bytequeue is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -//You should have received a copy of the GNU General Public License -//along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. +// You should have received a copy of the GNU General Public License +// along with avr-bytequeue. If not, see <http://www.gnu.org/licenses/>. #ifndef INTERRUPT_SETTING_H #define INTERRUPT_SETTING_H #ifdef __cplusplus extern "C" { -#endif +#endif #include <inttypes.h> -//AVR specific typedef +// AVR specific typedef typedef uint8_t interrupt_setting_t; interrupt_setting_t store_and_clear_interrupt(void); -void restore_interrupt_setting(interrupt_setting_t setting); +void restore_interrupt_setting(interrupt_setting_t setting); #ifdef __cplusplus } -#endif - #endif +#endif diff --git a/tmk_core/protocol/midi/midi.c b/tmk_core/protocol/midi/midi.c index 11a589078c..643c43722d 100755..100644 --- a/tmk_core/protocol/midi/midi.c +++ b/tmk_core/protocol/midi/midi.c @@ -1,277 +1,181 @@ -//midi for embedded chips, -//Copyright 2010 Alex Norman +// midi for embedded chips, +// Copyright 2010 Alex Norman // -//This file is part of avr-midi. +// This file is part of avr-midi. // -//avr-midi is free software: you can redistribute it and/or modify -//it under the terms of the GNU General Public License as published by -//the Free Software Foundation, either version 3 of the License, or +// avr-midi is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or //(at your option) any later version. // -//avr-midi is distributed in the hope that it will be useful, -//but WITHOUT ANY WARRANTY; without even the implied warranty of -//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -//GNU General Public License for more details. +// avr-midi is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -//You should have received a copy of the GNU General Public License -//along with avr-midi. If not, see <http://www.gnu.org/licenses/>. +// You should have received a copy of the GNU General Public License +// along with avr-midi. If not, see <http://www.gnu.org/licenses/>. #include "midi.h" -#include <string.h> //for memcpy +#include <string.h> //for memcpy -#define MIN(x,y) (((x) < (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #ifndef NULL -#define NULL 0 +# define NULL 0 #endif -bool midi_is_statusbyte(uint8_t theByte){ - return (bool)(theByte & MIDI_STATUSMASK); -} +bool midi_is_statusbyte(uint8_t theByte) { return (bool)(theByte & MIDI_STATUSMASK); } -bool midi_is_realtime(uint8_t theByte){ - return (theByte >= MIDI_CLOCK); -} +bool midi_is_realtime(uint8_t theByte) { return (theByte >= MIDI_CLOCK); } -midi_packet_length_t midi_packet_length(uint8_t status){ - switch(status & 0xF0){ - case MIDI_CC: - case MIDI_NOTEON: - case MIDI_NOTEOFF: - case MIDI_AFTERTOUCH: - case MIDI_PITCHBEND: - return THREE; - case MIDI_PROGCHANGE: - case MIDI_CHANPRESSURE: - case MIDI_SONGSELECT: - return TWO; - case 0xF0: - switch(status) { - case MIDI_CLOCK: - case MIDI_TICK: - case MIDI_START: - case MIDI_CONTINUE: - case MIDI_STOP: - case MIDI_ACTIVESENSE: - case MIDI_RESET: - case MIDI_TUNEREQUEST: - return ONE; - case MIDI_SONGPOSITION: - return THREE; - case MIDI_TC_QUARTERFRAME: - case MIDI_SONGSELECT: - return TWO; - case SYSEX_END: - case SYSEX_BEGIN: - default: - return UNDEFINED; - } - default: - return UNDEFINED; - } +midi_packet_length_t midi_packet_length(uint8_t status) { + switch (status & 0xF0) { + case MIDI_CC: + case MIDI_NOTEON: + case MIDI_NOTEOFF: + case MIDI_AFTERTOUCH: + case MIDI_PITCHBEND: + return THREE; + case MIDI_PROGCHANGE: + case MIDI_CHANPRESSURE: + case MIDI_SONGSELECT: + return TWO; + case 0xF0: + switch (status) { + case MIDI_CLOCK: + case MIDI_TICK: + case MIDI_START: + case MIDI_CONTINUE: + case MIDI_STOP: + case MIDI_ACTIVESENSE: + case MIDI_RESET: + case MIDI_TUNEREQUEST: + return ONE; + case MIDI_SONGPOSITION: + return THREE; + case MIDI_TC_QUARTERFRAME: + case MIDI_SONGSELECT: + return TWO; + case SYSEX_END: + case SYSEX_BEGIN: + default: + return UNDEFINED; + } + default: + return UNDEFINED; + } } -void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val){ - //CC Status: 0xB0 to 0xBF where the low nibble is the MIDI channel. - //CC Data: Controller Num, Controller Val - device->send_func(device, 3, - MIDI_CC | (chan & MIDI_CHANMASK), - num & 0x7F, - val & 0x7F); +void midi_send_cc(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t val) { + // CC Status: 0xB0 to 0xBF where the low nibble is the MIDI channel. + // CC Data: Controller Num, Controller Val + device->send_func(device, 3, MIDI_CC | (chan & MIDI_CHANMASK), num & 0x7F, val & 0x7F); } -void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel){ - //Note Data: Note Num, Note Velocity - device->send_func(device, 3, - MIDI_NOTEON | (chan & MIDI_CHANMASK), - num & 0x7F, - vel & 0x7F); +void midi_send_noteon(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel) { + // Note Data: Note Num, Note Velocity + device->send_func(device, 3, MIDI_NOTEON | (chan & MIDI_CHANMASK), num & 0x7F, vel & 0x7F); } -void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel){ - //Note Data: Note Num, Note Velocity - device->send_func(device, 3, - MIDI_NOTEOFF | (chan & MIDI_CHANMASK), - num & 0x7F, - vel & 0x7F); +void midi_send_noteoff(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel) { + // Note Data: Note Num, Note Velocity + device->send_func(device, 3, MIDI_NOTEOFF | (chan & MIDI_CHANMASK), num & 0x7F, vel & 0x7F); } -void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, uint8_t amt){ - device->send_func(device, 3, - MIDI_AFTERTOUCH | (chan & MIDI_CHANMASK), - note_num & 0x7F, - amt & 0x7F); -} +void midi_send_aftertouch(MidiDevice* device, uint8_t chan, uint8_t note_num, uint8_t amt) { device->send_func(device, 3, MIDI_AFTERTOUCH | (chan & MIDI_CHANMASK), note_num & 0x7F, amt & 0x7F); } -//XXX does this work right? -//amt in range -0x2000, 0x1fff -//uAmt should be in range.. -//0x0000 to 0x3FFF -void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt){ - uint16_t uAmt; - //check range - if(amt > 0x1fff){ - uAmt = 0x3FFF; - } else if(amt < -0x2000){ - uAmt = 0; - } else { - uAmt = amt + 0x2000; - } - device->send_func(device, 3, - MIDI_PITCHBEND | (chan & MIDI_CHANMASK), - uAmt & 0x7F, - (uAmt >> 7) & 0x7F); +// XXX does this work right? +// amt in range -0x2000, 0x1fff +// uAmt should be in range.. +// 0x0000 to 0x3FFF +void midi_send_pitchbend(MidiDevice* device, uint8_t chan, int16_t amt) { + uint16_t uAmt; + // check range + if (amt > 0x1fff) { + uAmt = 0x3FFF; + } else if (amt < -0x2000) { + uAmt = 0; + } else { + uAmt = amt + 0x2000; + } + device->send_func(device, 3, MIDI_PITCHBEND | (chan & MIDI_CHANMASK), uAmt & 0x7F, (uAmt >> 7) & 0x7F); } -void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num){ - device->send_func(device, 2, - MIDI_PROGCHANGE | (chan & MIDI_CHANMASK), - num & 0x7F, - 0); -} +void midi_send_programchange(MidiDevice* device, uint8_t chan, uint8_t num) { device->send_func(device, 2, MIDI_PROGCHANGE | (chan & MIDI_CHANMASK), num & 0x7F, 0); } -void midi_send_channelpressure(MidiDevice * device, uint8_t chan, uint8_t amt){ - device->send_func(device, 2, - MIDI_CHANPRESSURE | (chan & MIDI_CHANMASK), - amt & 0x7F, - 0); -} +void midi_send_channelpressure(MidiDevice* device, uint8_t chan, uint8_t amt) { device->send_func(device, 2, MIDI_CHANPRESSURE | (chan & MIDI_CHANMASK), amt & 0x7F, 0); } -void midi_send_clock(MidiDevice * device){ - device->send_func(device, 1, MIDI_CLOCK, 0, 0); -} +void midi_send_clock(MidiDevice* device) { device->send_func(device, 1, MIDI_CLOCK, 0, 0); } -void midi_send_tick(MidiDevice * device){ - device->send_func(device, 1, MIDI_TICK, 0, 0); -} +void midi_send_tick(MidiDevice* device) { device->send_func(device, 1, MIDI_TICK, 0, 0); } -void midi_send_start(MidiDevice * device){ - device->send_func(device, 1, MIDI_START, 0, 0); -} +void midi_send_start(MidiDevice* device) { device->send_func(device, 1, MIDI_START, 0, 0); } -void midi_send_continue(MidiDevice * device){ - device->send_func(device, 1, MIDI_CONTINUE, 0, 0); -} +void midi_send_continue(MidiDevice* device) { device->send_func(device, 1, MIDI_CONTINUE, 0, 0); } -void midi_send_stop(MidiDevice * device){ - device->send_func(device, 1, MIDI_STOP, 0, 0); -} - -void midi_send_activesense(MidiDevice * device){ - device->send_func(device, 1, MIDI_ACTIVESENSE, 0, 0); -} +void midi_send_stop(MidiDevice* device) { device->send_func(device, 1, MIDI_STOP, 0, 0); } -void midi_send_reset(MidiDevice * device){ - device->send_func(device, 1, MIDI_RESET, 0, 0); -} +void midi_send_activesense(MidiDevice* device) { device->send_func(device, 1, MIDI_ACTIVESENSE, 0, 0); } -void midi_send_tcquarterframe(MidiDevice * device, uint8_t time){ - device->send_func(device, 2, - MIDI_TC_QUARTERFRAME, - time & 0x7F, - 0); -} +void midi_send_reset(MidiDevice* device) { device->send_func(device, 1, MIDI_RESET, 0, 0); } -//XXX is this right? -void midi_send_songposition(MidiDevice * device, uint16_t pos){ - device->send_func(device, 3, - MIDI_SONGPOSITION, - pos & 0x7F, - (pos >> 7) & 0x7F); -} +void midi_send_tcquarterframe(MidiDevice* device, uint8_t time) { device->send_func(device, 2, MIDI_TC_QUARTERFRAME, time & 0x7F, 0); } -void midi_send_songselect(MidiDevice * device, uint8_t song){ - device->send_func(device, 2, - MIDI_SONGSELECT, - song & 0x7F, - 0); -} +// XXX is this right? +void midi_send_songposition(MidiDevice* device, uint16_t pos) { device->send_func(device, 3, MIDI_SONGPOSITION, pos & 0x7F, (pos >> 7) & 0x7F); } -void midi_send_tunerequest(MidiDevice * device){ - device->send_func(device, 1, MIDI_TUNEREQUEST, 0, 0); -} +void midi_send_songselect(MidiDevice* device, uint8_t song) { device->send_func(device, 2, MIDI_SONGSELECT, song & 0x7F, 0); } -void midi_send_byte(MidiDevice * device, uint8_t b){ - device->send_func(device, 1, b, 0, 0); -} +void midi_send_tunerequest(MidiDevice* device) { device->send_func(device, 1, MIDI_TUNEREQUEST, 0, 0); } -void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2){ - //ensure that the count passed along is always 3 or lower - if (count > 3) { - //TODO how to do this correctly? - } - device->send_func(device, count, byte0, byte1, byte2); -} +void midi_send_byte(MidiDevice* device, uint8_t b) { device->send_func(device, 1, b, 0, 0); } -void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array) { - uint16_t i; - for (i = 0; i < count; i += 3) { - uint8_t b[3] = { 0, 0, 0 }; - uint16_t to_send = count - i; - to_send = (to_send > 3) ? 3 : to_send; - memcpy(b, array + i, to_send); - midi_send_data(device, to_send, b[0], b[1], b[2]); - } +void midi_send_data(MidiDevice* device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2) { + // ensure that the count passed along is always 3 or lower + if (count > 3) { + // TODO how to do this correctly? + } + device->send_func(device, count, byte0, byte1, byte2); } - -void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func){ - device->input_cc_callback = func; +void midi_send_array(MidiDevice* device, uint16_t count, uint8_t* array) { + uint16_t i; + for (i = 0; i < count; i += 3) { + uint8_t b[3] = {0, 0, 0}; + uint16_t to_send = count - i; + to_send = (to_send > 3) ? 3 : to_send; + memcpy(b, array + i, to_send); + midi_send_data(device, to_send, b[0], b[1], b[2]); + } } -void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t func){ - device->input_noteon_callback = func; -} +void midi_register_cc_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_cc_callback = func; } -void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t func){ - device->input_noteoff_callback = func; -} +void midi_register_noteon_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_noteon_callback = func; } -void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func_t func){ - device->input_aftertouch_callback = func; -} +void midi_register_noteoff_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_noteoff_callback = func; } -void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_t func){ - device->input_pitchbend_callback = func; -} +void midi_register_aftertouch_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_aftertouch_callback = func; } -void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_func_t func){ - device->input_songposition_callback = func; -} +void midi_register_pitchbend_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_pitchbend_callback = func; } -void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t func) { - device->input_progchange_callback = func; -} +void midi_register_songposition_callback(MidiDevice* device, midi_three_byte_func_t func) { device->input_songposition_callback = func; } -void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func_t func) { - device->input_chanpressure_callback = func; -} +void midi_register_progchange_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_progchange_callback = func; } -void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t func) { - device->input_songselect_callback = func; -} +void midi_register_chanpressure_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_chanpressure_callback = func; } -void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_func_t func) { - device->input_tc_quarterframe_callback = func; -} +void midi_register_songselect_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_songselect_callback = func; } -void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t func){ - device->input_realtime_callback = func; -} +void midi_register_tc_quarterframe_callback(MidiDevice* device, midi_two_byte_func_t func) { device->input_tc_quarterframe_callback = func; } -void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_t func){ - device->input_tunerequest_callback = func; -} +void midi_register_realtime_callback(MidiDevice* device, midi_one_byte_func_t func) { device->input_realtime_callback = func; } -void midi_register_sysex_callback(MidiDevice * device, midi_sysex_func_t func) { - device->input_sysex_callback = func; -} +void midi_register_tunerequest_callback(MidiDevice* device, midi_one_byte_func_t func) { device->input_tunerequest_callback = func; } -void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_t func){ - device->input_fallthrough_callback = func; -} +void midi_register_sysex_callback(MidiDevice* device, midi_sysex_func_t func) { device->input_sysex_callback = func; } -void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t f |