This program enables a RedBearlab nRF51822 to be used as a "bridge device" with full bi-directional communication between MIDI through standard MIDI cables and BLE-MIDI. MIDI cables are connected to the UART. This allows for example to send MIDI data to synthesizers directly from a computer or a tablet via BLE-MIDI and vice-versa, "wires-free" . The Midi Manufacturers Association BLE-MIDI Specification is used. This project is inspired by Matthias Frick's "blidino" project which implements a USB-MIDI to BLE-MIDI bridge with the nRF51822 and is available at https://github.com/sieren/blidino. I owe to him all the BLE-MIDI to MIDI parsing part.

Dependencies:   BLE_API BufferedSerial mbed nRF51822

/media/uploads/popcornell/wp_20160713_22_30_15_rich.jpg

Video

Committer:
popcornell
Date:
Tue Aug 09 12:57:23 2016 +0000
Revision:
0:244f1d0a3810
first

Who changed what in which revision?

UserRevisionLine numberNew contents of line
popcornell 0:244f1d0a3810 1 /*
popcornell 0:244f1d0a3810 2 * Copyright (c) 2016 Samuele Cornell
popcornell 0:244f1d0a3810 3 *
popcornell 0:244f1d0a3810 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
popcornell 0:244f1d0a3810 5 * of this software and associated documentation files (the "Software"), to deal
popcornell 0:244f1d0a3810 6 * in the Software without restriction, including without limitation the rights
popcornell 0:244f1d0a3810 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
popcornell 0:244f1d0a3810 8 * copies of the Software, and to permit persons to whom the Software is
popcornell 0:244f1d0a3810 9 * furnished to do so, subject to the following conditions:
popcornell 0:244f1d0a3810 10 *
popcornell 0:244f1d0a3810 11 * The above copyright notice and this permission notice shall be included in all
popcornell 0:244f1d0a3810 12 * copies or substantial portions of the Software.
popcornell 0:244f1d0a3810 13 *
popcornell 0:244f1d0a3810 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
popcornell 0:244f1d0a3810 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
popcornell 0:244f1d0a3810 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
popcornell 0:244f1d0a3810 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
popcornell 0:244f1d0a3810 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
popcornell 0:244f1d0a3810 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
popcornell 0:244f1d0a3810 20 * SOFTWARE.
popcornell 0:244f1d0a3810 21 *
popcornell 0:244f1d0a3810 22 */
popcornell 0:244f1d0a3810 23
popcornell 0:244f1d0a3810 24 #define UART_RX_PIN D0 // RX UART Pin
popcornell 0:244f1d0a3810 25
popcornell 0:244f1d0a3810 26 #define UART_TX_PIN D1 // TX UART Pin
popcornell 0:244f1d0a3810 27
popcornell 0:244f1d0a3810 28 // i have used DFRobot MIDI Shield but there are other commercially available similar products, also it is possible to interface directly a MIDI cable via an optocoupler (several projects are already available online )
popcornell 0:244f1d0a3810 29
popcornell 0:244f1d0a3810 30 #define LIGHT_SHOW 1 // 0 if visual feedback isn't needed (saves energy )
popcornell 0:244f1d0a3810 31
popcornell 0:244f1d0a3810 32 #define TX_LED D6 // the state of this led will change whenever a message is to be sent over ble-midi
popcornell 0:244f1d0a3810 33
popcornell 0:244f1d0a3810 34 #define RX_LED D7 // the state of this led will change whenever a message received over ble-midi
popcornell 0:244f1d0a3810 35
popcornell 0:244f1d0a3810 36
popcornell 0:244f1d0a3810 37 /*******************************************************************************************************
popcornell 0:244f1d0a3810 38 PERFORMANCE TWEAKS
popcornell 0:244f1d0a3810 39 *******************************************************************************************************/
popcornell 0:244f1d0a3810 40
popcornell 0:244f1d0a3810 41
popcornell 0:244f1d0a3810 42 #define BUFSERIAL_LENGHT 256 // define the software circular buffer lenght used for the UART.
popcornell 0:244f1d0a3810 43
popcornell 0:244f1d0a3810 44
popcornell 0:244f1d0a3810 45 #define ONLY_MIDI_to_BLEMIDI 0 // if only unidirectional MIDI to BLE-MIDI is desired set this to 1
popcornell 0:244f1d0a3810 46
popcornell 0:244f1d0a3810 47
popcornell 0:244f1d0a3810 48 #define ONLY_BLEMIDI_to_MIDI 0 // if only unidirectional BLE-MIDI to MIDI is desired set this to 1
popcornell 0:244f1d0a3810 49
popcornell 0:244f1d0a3810 50 // unidirectional operation allows to save energy. It also leads to better performance as if ONLY MIDI to BLE MIDI is required, for example it is possible to shorten the SENDBLE_INTERVAL
popcornell 0:244f1d0a3810 51 // without reliability issues (to a certain extent).
popcornell 0:244f1d0a3810 52
popcornell 0:244f1d0a3810 53 #define SENDBLEMIDI_INTERVAL 0.01 // this defines how frequently MIDI Events from the UART are polled, parsed and then sent via BLE-MIDI.
popcornell 0:244f1d0a3810 54 // a lower value means less latency but it also increase energy comsuption and if is set too low can cause reliability issues in MIDI to BLE-MIDI operation (especially for long SysEx messages).
popcornell 0:244f1d0a3810 55
popcornell 0:244f1d0a3810 56
popcornell 0:244f1d0a3810 57 /***************************************************************************************************************
popcornell 0:244f1d0a3810 58 CONNECTION PARAMETERS
popcornell 0:244f1d0a3810 59 ***************************************************************************************************************/
popcornell 0:244f1d0a3810 60
popcornell 0:244f1d0a3810 61 namespace Config {
popcornell 0:244f1d0a3810 62
popcornell 0:244f1d0a3810 63 //
popcornell 0:244f1d0a3810 64 const int minConnectionInterval = 6; // (1.25 ms units)
popcornell 0:244f1d0a3810 65 const int maxConnectionInterval = 15; // (1.25 ms units)
popcornell 0:244f1d0a3810 66 const int slaveLatency = 0;
popcornell 0:244f1d0a3810 67 const int supervisionTimeout = 500; // (10 ms units)
popcornell 0:244f1d0a3810 68
popcornell 0:244f1d0a3810 69
popcornell 0:244f1d0a3810 70
popcornell 0:244f1d0a3810 71 }