From b624f32f944acdc59dcb130674c09090c5c404cb Mon Sep 17 00:00:00 2001 From: skullY Date: Fri, 30 Aug 2019 11:19:03 -0700 Subject: clang-format changes --- tmk_core/protocol/midi/Config/LUFAConfig.h | 28 +- tmk_core/protocol/midi/bytequeue/bytequeue.c | 93 ++-- tmk_core/protocol/midi/bytequeue/bytequeue.h | 59 ++- .../protocol/midi/bytequeue/interrupt_setting.c | 54 ++- .../protocol/midi/bytequeue/interrupt_setting.h | 33 +- tmk_core/protocol/midi/midi.c | 344 ++++++--------- tmk_core/protocol/midi/midi.h | 152 ++++--- tmk_core/protocol/midi/midi_device.c | 477 ++++++++++----------- tmk_core/protocol/midi/midi_device.h | 121 +++--- tmk_core/protocol/midi/midi_function_types.h | 44 +- tmk_core/protocol/midi/qmk_midi.c | 258 ++++++----- tmk_core/protocol/midi/qmk_midi.h | 10 +- tmk_core/protocol/midi/sysex_tools.c | 158 ++++--- tmk_core/protocol/midi/sysex_tools.h | 34 +- 14 files changed, 858 insertions(+), 1007 deletions(-) mode change 100755 => 100644 tmk_core/protocol/midi/Config/LUFAConfig.h mode change 100755 => 100644 tmk_core/protocol/midi/bytequeue/bytequeue.c mode change 100755 => 100644 tmk_core/protocol/midi/bytequeue/bytequeue.h mode change 100755 => 100644 tmk_core/protocol/midi/bytequeue/interrupt_setting.c mode change 100755 => 100644 tmk_core/protocol/midi/bytequeue/interrupt_setting.h mode change 100755 => 100644 tmk_core/protocol/midi/midi.c mode change 100755 => 100644 tmk_core/protocol/midi/midi.h mode change 100755 => 100644 tmk_core/protocol/midi/midi_device.c mode change 100755 => 100644 tmk_core/protocol/midi/midi_device.h mode change 100755 => 100644 tmk_core/protocol/midi/midi_function_types.h mode change 100755 => 100644 tmk_core/protocol/midi/sysex_tools.c mode change 100755 => 100644 tmk_core/protocol/midi/sysex_tools.h (limited to 'tmk_core/protocol/midi') diff --git a/tmk_core/protocol/midi/Config/LUFAConfig.h b/tmk_core/protocol/midi/Config/LUFAConfig.h old mode 100755 new mode 100644 index a1d7482672..b346c05bdd --- 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 old mode 100755 new mode 100644 index e434956328..e36a9e66b1 --- 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 . +// You should have received a copy of the GNU General Public License +// along with avr-bytequeue. If not, see . #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 old mode 100755 new mode 100644 index e4a286134f..33fb63a8cb --- 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 . +// You should have received a copy of the GNU General Public License +// along with avr-bytequeue. If not, see . #ifndef BYTEQUEUE_H #define BYTEQUEUE_H #ifdef __cplusplus extern "C" { -#endif +#endif #include #include @@ -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 old mode 100755 new mode 100644 index 0ab8b54620..1be1fee973 --- 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 . +// You should have received a copy of the GNU General Public License +// along with avr-bytequeue. If not, see . - -//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 +# include 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 old mode 100755 new mode 100644 index 053d02c9d0..788f75d79f --- 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 . +// You should have received a copy of the GNU General Public License +// along with avr-bytequeue. If not, see . #ifndef INTERRUPT_SETTING_H #define INTERRUPT_SETTING_H #ifdef __cplusplus extern "C" { -#endif +#endif #include -//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 old mode 100755 new mode 100644 index 11a589078c..643c43722d --- 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 . +// You should have received a copy of the GNU General Public License +// along with avr-midi. If not, see . #include "midi.h" -#include //for memcpy +#include //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 func){ - device->input_catchall_callback = func; -} +void midi_register_fallthrough_callback(MidiDevice* device, midi_var_byte_func_t func) { device->input_fallthrough_callback = func; } +void midi_register_catchall_callback(MidiDevice* device, midi_var_byte_func_t func) { device->input_catchall_callback = func; } diff --git a/tmk_core/protocol/midi/midi.h b/tmk_core/protocol/midi/midi.h old mode 100755 new mode 100644 index 1a36737df8..07d8cebc10 --- a/tmk_core/protocol/midi/midi.h +++ b/tmk_core/protocol/midi/midi.h @@ -1,20 +1,20 @@ -//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 . +// You should have received a copy of the GNU General Public License +// along with avr-midi. If not, see . /** * @file @@ -30,7 +30,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif #include "midi_device.h" #include "midi_function_types.h" @@ -48,8 +48,8 @@ extern "C" { * You must call this before using the device in question. * * @param device the device to initialize -*/ -void midi_device_init(MidiDevice * device); // [implementation in midi_device.c] + */ +void midi_device_init(MidiDevice* device); // [implementation in midi_device.c] /** * @brief Process input data @@ -58,8 +58,8 @@ void midi_device_init(MidiDevice * device); // [implementation in midi_device.c] * if you expect to have your input callbacks called. * * @param device the device to process -*/ -void midi_device_process(MidiDevice * device); // [implementation in midi_device.c] + */ +void midi_device_process(MidiDevice* device); // [implementation in midi_device.c] /**@}*/ @@ -76,8 +76,8 @@ void midi_device_process(MidiDevice * device); // [implementation in midi_device * @param chan the channel to send on, 0-15 * @param num the cc num * @param val the value of that cc num -*/ -void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val); + */ +void midi_send_cc(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t val); /** * @brief Send a note on message via the given device. @@ -86,8 +86,8 @@ void midi_send_cc(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t val); * @param chan the channel to send on, 0-15 * @param num the note number * @param vel the note velocity -*/ -void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel); + */ +void midi_send_noteon(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel); /** * @brief Send a note off message via the given device. @@ -96,8 +96,8 @@ void midi_send_noteon(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t ve * @param chan the channel to send on, 0-15 * @param num the note number * @param vel the note velocity -*/ -void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t vel); + */ +void midi_send_noteoff(MidiDevice* device, uint8_t chan, uint8_t num, uint8_t vel); /** * @brief Send an after touch message via the given device. @@ -106,8 +106,8 @@ void midi_send_noteoff(MidiDevice * device, uint8_t chan, uint8_t num, uint8_t v * @param chan the channel to send on, 0-15 * @param note_num the note number * @param amt the after touch amount -*/ -void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, uint8_t amt); + */ +void midi_send_aftertouch(MidiDevice* device, uint8_t chan, uint8_t note_num, uint8_t amt); /** * @brief Send a pitch bend message via the given device. @@ -115,8 +115,8 @@ void midi_send_aftertouch(MidiDevice * device, uint8_t chan, uint8_t note_num, u * @param device the device to use for sending * @param chan the channel to send on, 0-15 * @param amt the bend amount range: -8192..8191, 0 means no bend -*/ -void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt); //range -8192, 8191 + */ +void midi_send_pitchbend(MidiDevice* device, uint8_t chan, int16_t amt); // range -8192, 8191 /** * @brief Send a program change message via the given device. @@ -124,8 +124,8 @@ void midi_send_pitchbend(MidiDevice * device, uint8_t chan, int16_t amt); //rang * @param device the device to use for sending * @param chan the channel to send on, 0-15 * @param num the program to change to -*/ -void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num); + */ +void midi_send_programchange(MidiDevice* device, uint8_t chan, uint8_t num); /** * @brief Send a channel pressure message via the given device. @@ -133,58 +133,57 @@ void midi_send_programchange(MidiDevice * device, uint8_t chan, uint8_t num); * @param device the device to use for sending * @param chan the channel to send on, 0-15 * @param amt the amount of channel pressure -*/ -void midi_send_channelpressure(MidiDevice * device, uint8_t chan, uint8_t amt); + */ +void midi_send_channelpressure(MidiDevice* device, uint8_t chan, uint8_t amt); /** * @brief Send a clock message via the given device. * * @param device the device to use for sending */ -void midi_send_clock(MidiDevice * device); +void midi_send_clock(MidiDevice* device); /** * @brief Send a tick message via the given device. * * @param device the device to use for sending */ -void midi_send_tick(MidiDevice * device); +void midi_send_tick(MidiDevice* device); /** * @brief Send a start message via the given device. * * @param device the device to use for sending */ -void midi_send_start(MidiDevice * device); +void midi_send_start(MidiDevice* device); /** * @brief Send a continue message via the given device. * * @param device the device to use for sending */ -void midi_send_continue(MidiDevice * device); +void midi_send_continue(MidiDevice* device); /** * @brief Send a stop message via the given device. * * @param device the device to use for sending */ -void midi_send_stop(MidiDevice * device); +void midi_send_stop(MidiDevice* device); /** * @brief Send an active sense message via the given device. * * @param device the device to use for sending */ -void midi_send_activesense(MidiDevice * device); +void midi_send_activesense(MidiDevice* device); /** * @brief Send a reset message via the given device. * * @param device the device to use for sending */ -void midi_send_reset(MidiDevice * device); - +void midi_send_reset(MidiDevice* device); /** * @brief Send a tc quarter frame message via the given device. @@ -192,7 +191,7 @@ void midi_send_reset(MidiDevice * device); * @param device the device to use for sending * @param time the time of this quarter frame, range 0..16383 */ -void midi_send_tcquarterframe(MidiDevice * device, uint8_t time); +void midi_send_tcquarterframe(MidiDevice* device, uint8_t time); /** * @brief Send a song position message via the given device. @@ -200,7 +199,7 @@ void midi_send_tcquarterframe(MidiDevice * device, uint8_t time); * @param device the device to use for sending * @param pos the song position */ -void midi_send_songposition(MidiDevice * device, uint16_t pos); +void midi_send_songposition(MidiDevice* device, uint16_t pos); /** * @brief Send a song select message via the given device. @@ -208,14 +207,14 @@ void midi_send_songposition(MidiDevice * device, uint16_t pos); * @param device the device to use for sending * @param song the song to select */ -void midi_send_songselect(MidiDevice * device, uint8_t song); +void midi_send_songselect(MidiDevice* device, uint8_t song); /** * @brief Send a tune request message via the given device. * * @param device the device to use for sending */ -void midi_send_tunerequest(MidiDevice * device); +void midi_send_tunerequest(MidiDevice* device); /** * @brief Send a byte via the given device. @@ -228,7 +227,7 @@ void midi_send_tunerequest(MidiDevice * device); * @param device the device to use for sending * @param b the byte to send */ -void midi_send_byte(MidiDevice * device, uint8_t b); +void midi_send_byte(MidiDevice* device, uint8_t b); /** * @brief Send up to 3 bytes of data @@ -241,7 +240,7 @@ void midi_send_byte(MidiDevice * device, uint8_t b); * @param byte1 the second byte, ignored if cnt % 4 != 2 * @param byte2 the third byte, ignored if cnt % 4 != 3 */ -void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2); +void midi_send_data(MidiDevice* device, uint16_t count, uint8_t byte0, uint8_t byte1, uint8_t byte2); /** * @brief Send an array of formatted midi data. @@ -252,14 +251,13 @@ void midi_send_data(MidiDevice * device, uint16_t count, uint8_t byte0, uint8_t * @param count the count of bytes to send * @param array the array of bytes */ -void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array); +void midi_send_array(MidiDevice* device, uint16_t count, uint8_t* array); /**@}*/ - /** * @defgroup input_callback_reg Input callback registration functions - * + * * @brief These are the functions you use to register your input callbacks. * * The functions are called when the appropriate midi message is matched on the @@ -268,7 +266,7 @@ void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array); * @{ */ -//three byte funcs +// three byte funcs /** * @brief Register a control change message (cc) callback. @@ -276,7 +274,7 @@ void midi_send_array(MidiDevice * device, uint16_t count, uint8_t * array); * @param device the device associate with * @param func the callback function to register */ -void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func); +void midi_register_cc_callback(MidiDevice* device, midi_three_byte_func_t func); /** * @brief Register a note on callback. @@ -284,7 +282,7 @@ void midi_register_cc_callback(MidiDevice * device, midi_three_byte_func_t func) * @param device the device associate with * @param func the callback function to register */ -void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t func); +void midi_register_noteon_callback(MidiDevice* device, midi_three_byte_func_t func); /** * @brief Register a note off callback. @@ -292,7 +290,7 @@ void midi_register_noteon_callback(MidiDevice * device, midi_three_byte_func_t f * @param device the device associate with * @param func the callback function to register */ -void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t func); +void midi_register_noteoff_callback(MidiDevice* device, midi_three_byte_func_t func); /** * @brief Register an after touch callback. @@ -301,7 +299,7 @@ void midi_register_noteoff_callback(MidiDevice * device, midi_three_byte_func_t * @param func the callback function to register */ -void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func_t func); +void midi_register_aftertouch_callback(MidiDevice* device, midi_three_byte_func_t func); /** * @brief Register a pitch bend callback. @@ -309,7 +307,7 @@ void midi_register_aftertouch_callback(MidiDevice * device, midi_three_byte_func * @param device the device associate with * @param func the callback function to register */ -void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_t func); +void midi_register_pitchbend_callback(MidiDevice* device, midi_three_byte_func_t func); /** * @brief Register a song position callback. @@ -317,9 +315,9 @@ void midi_register_pitchbend_callback(MidiDevice * device, midi_three_byte_func_ * @param device the device associate with * @param func the callback function to register */ -void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_func_t func); +void midi_register_songposition_callback(MidiDevice* device, midi_three_byte_func_t func); -//two byte funcs +// two byte funcs /** * @brief Register a program change callback. @@ -327,7 +325,7 @@ void midi_register_songposition_callback(MidiDevice * device, midi_three_byte_fu * @param device the device associate with * @param func the callback function to register */ -void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t func); +void midi_register_progchange_callback(MidiDevice* device, midi_two_byte_func_t func); /** * @brief Register a channel pressure callback. @@ -335,7 +333,7 @@ void midi_register_progchange_callback(MidiDevice * device, midi_two_byte_func_t * @param device the device associate with * @param func the callback function to register */ -void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func_t func); +void midi_register_chanpressure_callback(MidiDevice* device, midi_two_byte_func_t func); /** * @brief Register a song select callback. @@ -343,7 +341,7 @@ void midi_register_chanpressure_callback(MidiDevice * device, midi_two_byte_func * @param device the device associate with * @param func the callback function to register */ -void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t func); +void midi_register_songselect_callback(MidiDevice* device, midi_two_byte_func_t func); /** * @brief Register a tc quarter frame callback. @@ -351,9 +349,9 @@ void midi_register_songselect_callback(MidiDevice * device, midi_two_byte_func_t * @param device the device associate with * @param func the callback function to register */ -void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_func_t func); +void midi_register_tc_quarterframe_callback(MidiDevice* device, midi_two_byte_func_t func); -//one byte funcs +// one byte funcs /** * @brief Register a realtime callback. @@ -363,7 +361,7 @@ void midi_register_tc_quarterframe_callback(MidiDevice * device, midi_two_byte_f * @param device the device associate with * @param func the callback function to register */ -void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t func); +void midi_register_realtime_callback(MidiDevice* device, midi_one_byte_func_t func); /** * @brief Register a tune request callback. @@ -371,7 +369,7 @@ void midi_register_realtime_callback(MidiDevice * device, midi_one_byte_func_t f * @param device the device associate with * @param func the callback function to register */ -void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_t func); +void midi_register_tunerequest_callback(MidiDevice* device, midi_one_byte_func_t func); /** * @brief Register a sysex callback. @@ -379,7 +377,7 @@ void midi_register_tunerequest_callback(MidiDevice * device, midi_one_byte_func_ * @param device the device associate with * @param func the callback function to register */ -void midi_register_sysex_callback(MidiDevice * device, midi_sysex_func_t func); +void midi_register_sysex_callback(MidiDevice* device, midi_sysex_func_t func); /** * @brief Register fall through callback. @@ -391,8 +389,7 @@ void midi_register_sysex_callback(MidiDevice * device, midi_sysex_func_t func); * @param device the device associate with * @param func the callback function to register */ -void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_t func); - +void midi_register_fallthrough_callback(MidiDevice* device, midi_var_byte_func_t func); /** * @brief Register a catch all callback. @@ -403,7 +400,7 @@ void midi_register_fallthrough_callback(MidiDevice * device, midi_var_byte_func_ * @param device the device associate with * @param func the callback function to register */ -void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t func); +void midi_register_catchall_callback(MidiDevice* device, midi_var_byte_func_t func); /**@}*/ @@ -417,11 +414,7 @@ void midi_register_catchall_callback(MidiDevice * device, midi_var_byte_func_t f * * An enumeration of the possible packet length values. */ -typedef enum { - UNDEFINED = 0, - ONE = 1, - TWO = 2, - THREE = 3} midi_packet_length_t; +typedef enum { UNDEFINED = 0, ONE = 1, TWO = 2, THREE = 3 } midi_packet_length_t; /** * @brief Test to see if the byte given is a status byte @@ -456,11 +449,11 @@ midi_packet_length_t midi_packet_length(uint8_t status); #define SYSEX_BEGIN 0xF0 #define SYSEX_END 0xF7 -//if you and this with a byte and you get anything non-zero -//it is a status message +// if you and this with a byte and you get anything non-zero +// it is a status message #define MIDI_STATUSMASK 0x80 -//if you and this with a status message that contains channel info, -//you'll get the channel +// if you and this with a status message that contains channel info, +// you'll get the channel #define MIDI_CHANMASK 0x0F #define MIDI_CC 0xB0 @@ -471,7 +464,7 @@ midi_packet_length_t midi_packet_length(uint8_t status); #define MIDI_PROGCHANGE 0xC0 #define MIDI_CHANPRESSURE 0xD0 -//midi realtime +// midi realtime #define MIDI_CLOCK 0xF8 #define MIDI_TICK 0xF9 #define MIDI_START 0xFA @@ -485,14 +478,13 @@ midi_packet_length_t midi_packet_length(uint8_t status); #define MIDI_SONGSELECT 0xF3 #define MIDI_TUNEREQUEST 0xF6 -//This ID is for educational or development use only +// This ID is for educational or development use only #define SYSEX_EDUMANUFID 0x7D /**@}*/ #ifdef __cplusplus } -#endif - #endif +#endif diff --git a/tmk_core/protocol/midi/midi_device.c b/tmk_core/protocol/midi/midi_device.c old mode 100755 new mode 100644 index 3215a007d5..58fe685e2d --- a/tmk_core/protocol/midi/midi_device.c +++ b/tmk_core/protocol/midi/midi_device.c @@ -1,291 +1,272 @@ -//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 . +// You should have received a copy of the GNU General Public License +// along with avr-midi. If not, see . #include "midi_device.h" #include "midi.h" #ifndef NULL -#define NULL 0 +# define NULL 0 #endif -//forward declarations, internally used to call the callbacks -void midi_input_callbacks(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); -void midi_process_byte(MidiDevice * device, uint8_t input); +// forward declarations, internally used to call the callbacks +void midi_input_callbacks(MidiDevice* device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2); +void midi_process_byte(MidiDevice* device, uint8_t input); -void midi_device_init(MidiDevice * device){ - device->input_state = IDLE; - device->input_count = 0; - bytequeue_init(&device->input_queue, device->input_queue_data, MIDI_INPUT_QUEUE_LENGTH); +void midi_device_init(MidiDevice* device) { + device->input_state = IDLE; + device->input_count = 0; + bytequeue_init(&device->input_queue, device->input_queue_data, MIDI_INPUT_QUEUE_LENGTH); - //three byte funcs - device->input_cc_callback = NULL; - device->input_noteon_callback = NULL; - device->input_noteoff_callback = NULL; - device->input_aftertouch_callback = NULL; - device->input_pitchbend_callback = NULL; - device->input_songposition_callback = NULL; + // three byte funcs + device->input_cc_callback = NULL; + device->input_noteon_callback = NULL; + device->input_noteoff_callback = NULL; + device->input_aftertouch_callback = NULL; + device->input_pitchbend_callback = NULL; + device->input_songposition_callback = NULL; - //two byte funcs - device->input_progchange_callback = NULL; - device->input_chanpressure_callback = NULL; - device->input_songselect_callback = NULL; - device->input_tc_quarterframe_callback = NULL; + // two byte funcs + device->input_progchange_callback = NULL; + device->input_chanpressure_callback = NULL; + device->input_songselect_callback = NULL; + device->input_tc_quarterframe_callback = NULL; - //one byte funcs - device->input_realtime_callback = NULL; - device->input_tunerequest_callback = NULL; + // one byte funcs + device->input_realtime_callback = NULL; + device->input_tunerequest_callback = NULL; - //var byte functions - device->input_sysex_callback = NULL; - device->input_fallthrough_callback = NULL; - device->input_catchall_callback = NULL; + // var byte functions + device->input_sysex_callback = NULL; + device->input_fallthrough_callback = NULL; + device->input_catchall_callback = NULL; - device->pre_input_process_callback = NULL; + device->pre_input_process_callback = NULL; } -void midi_device_input(MidiDevice * device, uint8_t cnt, uint8_t * input) { - uint8_t i; - for (i = 0; i < cnt; i++) - bytequeue_enqueue(&device->input_queue, input[i]); +void midi_device_input(MidiDevice* device, uint8_t cnt, uint8_t* input) { + uint8_t i; + for (i = 0; i < cnt; i++) bytequeue_enqueue(&device->input_queue, input[i]); } -void midi_device_set_send_func(MidiDevice * device, midi_var_byte_func_t send_func){ - device->send_func = send_func; -} +void midi_device_set_send_func(MidiDevice* device, midi_var_byte_func_t send_func) { device->send_func = send_func; } -void midi_device_set_pre_input_process_func(MidiDevice * device, midi_no_byte_func_t pre_process_func){ - device->pre_input_process_callback = pre_process_func; -} +void midi_device_set_pre_input_process_func(MidiDevice* device, midi_no_byte_func_t pre_process_func) { device->pre_input_process_callback = pre_process_func; } -void midi_device_process(MidiDevice * device) { - //call the pre_input_process_callback if there is one - if(device->pre_input_process_callback) - device->pre_input_process_callback(device); +void midi_device_process(MidiDevice* device) { + // call the pre_input_process_callback if there is one + if (device->pre_input_process_callback) device->pre_input_process_callback(device); - //pull stuff off the queue and process - byteQueueIndex_t len = bytequeue_length(&device->input_queue); - uint16_t i; - //TODO limit number of bytes processed? - for(i = 0; i < len; i++) { - uint8_t val = bytequeue_get(&device->input_queue, 0); - midi_process_byte(device, val); - bytequeue_remove(&device->input_queue, 1); - } + // pull stuff off the queue and process + byteQueueIndex_t len = bytequeue_length(&device->input_queue); + uint16_t i; + // TODO limit number of bytes processed? + for (i = 0; i < len; i++) { + uint8_t val = bytequeue_get(&device->input_queue, 0); + midi_process_byte(device, val); + bytequeue_remove(&device->input_queue, 1); + } } -void midi_process_byte(MidiDevice * device, uint8_t input) { - if (midi_is_realtime(input)) { - //call callback, store and restore state - input_state_t state = device->input_state; - device->input_state = ONE_BYTE_MESSAGE; - midi_input_callbacks(device, 1, input, 0, 0); - device->input_state = state; - } else if (midi_is_statusbyte(input)) { - //store the byte - if (device->input_state != SYSEX_MESSAGE) { - device->input_buffer[0] = input; - device->input_count = 1; - } - switch (midi_packet_length(input)) { - case ONE: - device->input_state = ONE_BYTE_MESSAGE;; +void midi_process_byte(MidiDevice* device, uint8_t input) { + if (midi_is_realtime(input)) { + // call callback, store and restore state + input_state_t state = device->input_state; + device->input_state = ONE_BYTE_MESSAGE; midi_input_callbacks(device, 1, input, 0, 0); - device->input_state = IDLE; - break; - case TWO: - device->input_state = TWO_BYTE_MESSAGE; - break; - case THREE: - device->input_state = THREE_BYTE_MESSAGE; - break; - case UNDEFINED: - switch(input) { - case SYSEX_BEGIN: - device->input_state = SYSEX_MESSAGE; + device->input_state = state; + } else if (midi_is_statusbyte(input)) { + // store the byte + if (device->input_state != SYSEX_MESSAGE) { device->input_buffer[0] = input; - device->input_count = 1; - break; - case SYSEX_END: - //send what is left in the input buffer, set idle - device->input_buffer[device->input_count % 3] = input; - device->input_count += 1; - //call the callback - midi_input_callbacks(device, device->input_count, - device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]); - device->input_state = IDLE; - break; - default: - device->input_state = IDLE; - device->input_count = 0; + device->input_count = 1; } + switch (midi_packet_length(input)) { + case ONE: + device->input_state = ONE_BYTE_MESSAGE; + ; + midi_input_callbacks(device, 1, input, 0, 0); + device->input_state = IDLE; + break; + case TWO: + device->input_state = TWO_BYTE_MESSAGE; + break; + case THREE: + device->input_state = THREE_BYTE_MESSAGE; + break; + case UNDEFINED: + switch (input) { + case SYSEX_BEGIN: + device->input_state = SYSEX_MESSAGE; + device->input_buffer[0] = input; + device->input_count = 1; + break; + case SYSEX_END: + // send what is left in the input buffer, set idle + device->input_buffer[device->input_count % 3] = input; + device->input_count += 1; + // call the callback + midi_input_callbacks(device, device->input_count, device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]); + device->input_state = IDLE; + break; + default: + device->input_state = IDLE; + device->input_count = 0; + } - break; - default: - device->input_state = IDLE; - device->input_count = 0; - break; - } - } else { - if (device->input_state != IDLE) { - //store the byte - device->input_buffer[device->input_count % 3] = input; - //increment count - uint16_t prev = device->input_count; - device->input_count += 1; + break; + default: + device->input_state = IDLE; + device->input_count = 0; + break; + } + } else { + if (device->input_state != IDLE) { + // store the byte + device->input_buffer[device->input_count % 3] = input; + // increment count + uint16_t prev = device->input_count; + device->input_count += 1; - switch(prev % 3) { - case 2: - //call callback - midi_input_callbacks(device, device->input_count, - device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]); - if (device->input_state != SYSEX_MESSAGE) { - //set to 1, keeping status byte, allowing for running status - device->input_count = 1; - } - break; - case 1: - if (device->input_state == TWO_BYTE_MESSAGE) { - //call callback - midi_input_callbacks(device, device->input_count, - device->input_buffer[0], device->input_buffer[1], 0); - if (device->input_state != SYSEX_MESSAGE) { - //set to 1, keeping status byte, allowing for running status - device->input_count = 1; + switch (prev % 3) { + case 2: + // call callback + midi_input_callbacks(device, device->input_count, device->input_buffer[0], device->input_buffer[1], device->input_buffer[2]); + if (device->input_state != SYSEX_MESSAGE) { + // set to 1, keeping status byte, allowing for running stat