/ README.rst
README.rst
1 Introduction 2 ============ 3 4 .. image:: https://readthedocs.org/projects/adafruit-circuitpython-ble_midi/badge/?version=latest 5 :target: https://circuitpython.readthedocs.io/projects/ble_midi/en/latest/ 6 :alt: Documentation Status 7 8 .. image:: https://img.shields.io/discord/327254708534116352.svg 9 :target: https://adafru.it/discord 10 :alt: Discord 11 12 .. image:: https://github.com/adafruit/Adafruit_CircuitPython_BLE_MIDI/workflows/Build%20CI/badge.svg 13 :target: https://github.com/adafruit/Adafruit_CircuitPython_BLE_MIDI/actions 14 :alt: Build Status 15 16 .. image:: https://img.shields.io/badge/code%20style-black-000000.svg 17 :target: https://github.com/psf/black 18 :alt: Code Style: Black 19 20 BLE MIDI service for CircuitPython 21 22 23 Dependencies 24 ============= 25 This driver depends on: 26 27 * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_ 28 29 Please ensure all dependencies are available on the CircuitPython filesystem. 30 This is easily achieved by downloading 31 `the Adafruit library and driver bundle <https://circuitpython.org/libraries>`_. 32 33 Installing from PyPI 34 ===================== 35 .. note:: This library is not available on PyPI yet. Install documentation is included 36 as a standard element. Stay tuned for PyPI availability! 37 38 On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 39 PyPI <https://pypi.org/project/adafruit-circuitpython-ble_midi/>`_. To install for current user: 40 41 .. code-block:: shell 42 43 pip3 install adafruit-circuitpython-ble-midi 44 45 To install system-wide (this may be required in some cases): 46 47 .. code-block:: shell 48 49 sudo pip3 install adafruit-circuitpython-ble-midi 50 51 To install in a virtual environment in your current project: 52 53 .. code-block:: shell 54 55 mkdir project-name && cd project-name 56 python3 -m venv .env 57 source .env/bin/activate 58 pip3 install adafruit-circuitpython-ble-midi 59 60 Usage Example 61 ============= 62 63 .. code-block:: python 64 65 """ 66 This example sends MIDI out. It sends NoteOn and then NoteOff with a random pitch bend. 67 """ 68 69 import time 70 import random 71 import adafruit_ble 72 from adafruit_ble.advertising.standard import ProvideServicesAdvertisement 73 import adafruit_ble_midi 74 import adafruit_midi 75 from adafruit_midi.control_change import ControlChange 76 from adafruit_midi.note_off import NoteOff 77 from adafruit_midi.note_on import NoteOn 78 from adafruit_midi.pitch_bend import PitchBend 79 80 # Use default HID descriptor 81 midi_service = adafruit_ble_midi.MIDIService() 82 advertisement = ProvideServicesAdvertisement(midi_service) 83 # advertisement.appearance = 961 84 85 ble = adafruit_ble.BLERadio() 86 if ble.connected: 87 for c in ble.connections: 88 c.disconnect() 89 90 midi = adafruit_midi.MIDI(midi_out=midi_service, out_channel=0) 91 92 print("advertising") 93 ble.start_advertising(advertisement) 94 95 while True: 96 print("Waiting for connection") 97 while not ble.connected: 98 pass 99 print("Connected") 100 while ble.connected: 101 midi.send(NoteOn(44, 120)) # G sharp 2nd octave 102 time.sleep(0.25) 103 a_pitch_bend = PitchBend(random.randint(0, 16383)) 104 midi.send(a_pitch_bend) 105 time.sleep(0.25) 106 # note how a list of messages can be used 107 midi.send([NoteOff("G#2", 120), ControlChange(3, 44)]) 108 time.sleep(0.5) 109 print("Disconnected") 110 print() 111 ble.start_advertising(advertisement) 112 113 Contributing 114 ============ 115 116 Contributions are welcome! Please read our `Code of Conduct 117 <https://github.com/adafruit/Adafruit_CircuitPython_BLE_MIDI/blob/master/CODE_OF_CONDUCT.md>`_ 118 before contributing to help this project stay welcoming. 119 120 Documentation 121 ============= 122 123 For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.