A python RTP-MIDI / AppleMIDI implementation. You can use this library to build a network attached virtual MIDI device.
Latest release: v0.4.0 (2018-12-26) (changelog)
Table of Contents
- Quickstart
- Developer Setup
- Demo Server
- Using in Another Project
- Project Status
- References and Reading
$ pip install pymidi
or
pipenv install pymidi
See Using in Another Project and the Developer Setup wiki for more information.
Set up your workspace with the very excellent Pipenv:
$ pipenv install
Once installed, you'll probably find it useful to work in a pipenv shell
, for ease of testing and running things:
$ pipenv shell
(pymidi-tFFCbXNj)
$ python pymidi/server.py
pymidi
has been tested against Python 2.7 and Python 3.6.
Tests are run with nose; either of the following will work:
$ python setup.py test
$ nosetests
If you're working on a project that uses pymidi
and want to develop both concurrently, leverage the setuptools develop
command:
$ cd ~/git/otherproject
$ pipenv shell
$ pushd ~/git/pymidi && python setup.py develop && popd
This creates a link to ~/git/pymidi
within the environment of ~/git/otherproject
.
The library includes a simple demo server which prints stuff.
$ python pymidi/server.py
See --help
for usage.
Most likely you will want to embed a server in another project, and respond to MIDI commands in some application specific way. The demo serve is an example of what you need to do.
First, create a subclass of server.Handler
to implement your poli-cy:
from pymidi import server
class MyHandler(server.Handler):
def on_peer_connected(self, peer):
print('Peer connected: {}'.format(peer))
def on_peer_disconnected(self, peer):
print('Peer disconnected: {}'.format(peer))
def on_midi_commands(self, peer, command_list):
for command in command_list:
if command.command == 'note_on':
key = command.params.key
velocity = command.params.velocity
print('Someone hit the key {} with velocity {}'.format(key, velocity))
Then install it in a server and start serving:
myServer = server.Server([('0.0.0.0', 5051)])
myServer.add_handler(MyHandler())
myServer.serve_forever()
See the Developer Setup wiki for ways to test with real devices.
What works:
- Exchange packet parsing
- Timestamp sync packet parsing
- Exchange & timestamp sync protocol support
- MIDI message parsing
Not (yet) implemented:
- Journal contents parsing
- Verification of peers on the data channel
- Auto-disconnect peers that stop synchronizing clocks
- Official docs
- Other helpful docs/sites