Skip to content

Commit 4564a3d

Browse files
committed
catched up with latest release of rtmidi, finally allowing to specify the api used in linux. Also a more correct approach to sending midi for the special case of 3 bytes
0 parents  commit 4564a3d

File tree

10 files changed

+5219
-0
lines changed

10 files changed

+5219
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rtmidi2.cpp
2+
*.so
3+
build/
4+
dist/

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2012 Guido Lorenz
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

MANIFEST

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MANIFEST
2+
tests.py
3+
README.rst
4+
rtmidi2.pyx
5+
setup.py
6+
RtMidi/RtMidi.h
7+
RtMidi/RtMidi.cpp
8+
version.cfg

README.rst

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
=======
2+
rtmidi2
3+
=======
4+
5+
Python wrapper for RtMidi_, the lightweight, cross-platform MIDI I/O library. For Linux, Mac OS X and Windows.
6+
7+
Based on rtmidi-python
8+
9+
Setup
10+
-----
11+
12+
The wrapper is written in Cython_. Cython should be installed for this module to be installed.
13+
RtMidi is included in the source tree, so you only need to do::
14+
15+
python setup.py install
16+
17+
Python 2 & 3
18+
------------
19+
20+
This module is compatible with both Python 2 and Python 3. The only visible difference is that under python 3, all strings are byte strings. If you pass a unicode string to any function taking a string (open_virtual_port), an attempt will be made to encode the string as ASCII, through .encode("ASCII", errors="ignore").
21+
22+
Usage Examples
23+
--------------
24+
25+
`rtmidi2` uses a very similar API as RtMidi
26+
27+
Print all in and out ports
28+
~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
30+
.. code-block:: python
31+
32+
import rtmidi2
33+
print(rtmidi2.get_in_ports())
34+
print(rtmidi2.get_out_ports())
35+
36+
37+
Send messages
38+
~~~~~~~~~~~~~
39+
40+
.. code-block:: python
41+
42+
import rtmidi2
43+
44+
midi_out = rtmidi2.MidiOut()
45+
# open the first available port
46+
midi_out.open_port(0)
47+
# send C3 with vel. 100 on channel 1
48+
midi_out.send_noteon(0, 48, 100)
49+
50+
51+
52+
Get incoming messages - blocking interface
53+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54+
55+
.. code-block:: python
56+
57+
midi_in = rtmidi.MidiIn()
58+
midi_in.open_port(0)
59+
60+
while True:
61+
message, delta_time = midi_in.get_message() # will block until a message is available
62+
if message:
63+
print(message, delta_time)
64+
65+
66+
Get incoming messages using a callback -- non blocking
67+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68+
69+
.. code-block:: python
70+
71+
def callback(message, time_stamp):
72+
print(message, time_stamp)
73+
74+
midi_in = rtmidi2.MidiIn()
75+
midi_in.callback = callback
76+
midi_in.open_port(0)
77+
78+
79+
Open multiple ports at once
80+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
81+
82+
.. code-block:: python
83+
84+
# get messages from all available ports
85+
midi_in = MidiInMulti().open_ports("*")
86+
87+
def callback(msg, timestamp):
88+
msgtype, channel = splitchannel(msg[0])
89+
print(msgtype2str(msgtype), msg[1], msg[2])
90+
91+
midi_in.callback = callback
92+
93+
94+
You can also get the device which generated the event by changing your callback to:
95+
96+
.. code-block:: python
97+
98+
def callback(src, msg, timestamp):
99+
# src will hold the name of the device
100+
print("got message from", src)
101+
102+
103+
Send multiple notes at once
104+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
105+
106+
.. code-block:: python
107+
108+
# send a cluster of ALL notes with a duration of 1 second
109+
midi_out = MidiOut().open_port()
110+
notes = range(127)
111+
velocities = [90] * len(notes)
112+
midi_out.send_noteon_many(0, notes, velocities)
113+
time.sleep(1)
114+
midi_out.send_noteon_many(0, notes, [0] * len(notes))
115+
116+
117+
----
118+
119+
120+
License
121+
-------
122+
123+
`rtmidi2` is licensed under the MIT License, see `LICENSE`.
124+
125+
It uses RtMidi, licensed under a modified MIT License, see `RtMidi/RtMidi.h`.
126+
127+
128+
.. _RtMidi: http://www.music.mcgill.ca/~gary/rtmidi/
129+
.. _Cython: http://www.cython.org

0 commit comments

Comments
 (0)