Skip to content

Commit c31d7e0

Browse files
author
Kevin J Walters
committed
Merge branch 'master' of dev version.
2 parents e371617 + 279345b commit c31d7e0

14 files changed

Lines changed: 79 additions & 153 deletions

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ install:
4444
- pip install --force-reinstall pylint==1.9.2
4545

4646
script:
47-
- ([[ -d "tests" ]] && py.test)
47+
- [[ ! -d "tests" ]] || py.test
4848
- pylint adafruit_midi/*.py
49-
- ([[ -d "tests" ]] && pylint --disable=missing-docstring,invalid-name,bad-whitespace,trailing-whitespace,line-too-long,wrong-import-position,unused-import tests/*.py)
50-
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py)
49+
- [[ ! -d "tests" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace,trailing-whitespace,line-too-long,wrong-import-position,unused-import tests/*.py
50+
- [[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py
5151
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-midi --library_location .
52-
- cd docs && sphinx-build -E -W -b html . _build/html && cd ..
52+
- ( cd docs && sphinx-build -E -W -b html . _build/html )

adafruit_midi/__init__.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,32 @@
5151

5252

5353
class MIDI:
54-
"""MIDI helper class."""
54+
"""MIDI helper class.
55+
56+
:param midi_in: an object which implements ``read(length)``,
57+
defaults to ``usb_midi.ports[0]``.
58+
:param midi_out: an object which implements ``write(buffer, length)``,
59+
defaults to ``usb_midi.ports[1]``.
60+
:param in_channel: The input channel(s).
61+
This is used by ``receive`` to filter data.
62+
This can either be an ``int`` for the wire protocol channel number (0-15)
63+
a tuple of ``int`` to listen for multiple channels or ``"ALL"``.
64+
Defaults to None.
65+
:param int out_channel: The wire protocol output channel number (0-15)
66+
used by ``send`` if no channel is specified,
67+
defaults to 0 (MIDI Channel 1).
68+
:param int in_buf_size: Size of input buffer in bytes, default 30.
69+
:param bool debug: Debug mode, default False.
70+
71+
"""
5572

5673
NOTE_ON = 0x90
5774
NOTE_OFF = 0x80
5875
PITCH_BEND = 0xE0
5976
CONTROL_CHANGE = 0xB0
6077

6178
def __init__(self, midi_in=usb_midi.ports[0], midi_out=usb_midi.ports[1], *,
62-
in_channel=None, out_channel=0, debug=False, in_buf_size=30):
79+
in_channel=None, out_channel=0, in_buf_size=30, debug=False):
6380
self._midi_in = midi_in
6481
self._midi_out = midi_out
6582
self.in_channel = in_channel
@@ -108,8 +125,10 @@ def out_channel(self, channel):
108125
def receive(self):
109126
"""Read messages from MIDI port, store them in internal read buffer, then parse that data
110127
and return the first MIDI message (event).
128+
This maintains the blocking characteristics of the midi_in port.
111129
112-
Returns (MIDIMessage object, channel) or (None, None) for nothing.
130+
:returns (MIDIMessage object, int channel): Returns object and channel
131+
or (None, None) for nothing.
113132
"""
114133
### could check _midi_in is an object OR correct object OR correct interface here?
115134
# If the buffer here is not full then read as much as we can fit from

adafruit_midi/channel_pressure.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,17 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_midi`
23+
`adafruit_midi.channel_pressure`
2424
================================================================================
2525
26-
A CircuitPython helper for encoding/decoding MIDI packets over a MIDI or UART connection.
26+
Channel Pressure MIDI message.
2727
2828
2929
* Author(s): Kevin J. Walters
3030
3131
Implementation Notes
3232
--------------------
3333
34-
**Hardware:**
35-
36-
37-
38-
**Software and Dependencies:**
39-
40-
* Adafruit CircuitPython firmware for the supported boards:
41-
https://github.com/adafruit/circuitpython/releases
42-
4334
"""
4435

4536
from .midi_message import MIDIMessage

adafruit_midi/control_change.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,17 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_midi`
23+
`adafruit_midi.control_change`
2424
================================================================================
2525
26-
A CircuitPython helper for encoding/decoding MIDI packets over a MIDI or UART connection.
26+
Control Change MIDI message.
2727
2828
2929
* Author(s): Kevin J. Walters
3030
3131
Implementation Notes
3232
--------------------
3333
34-
**Hardware:**
35-
36-
37-
38-
**Software and Dependencies:**
39-
40-
* Adafruit CircuitPython firmware for the supported boards:
41-
https://github.com/adafruit/circuitpython/releases
42-
4334
"""
4435

4536
from .midi_message import MIDIMessage

adafruit_midi/midi_message.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,23 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_midi`
23+
`adafruit_midi.midi_message.MIDIMessage`
2424
================================================================================
2525
26-
A CircuitPython helper for encoding/decoding MIDI packets over a MIDI or UART connection.
26+
An abstract class for objects which represent MIDI messages (events).
27+
When individual messages are imported they register themselves with
28+
:func:register_message_type which makes them recognised
29+
by the parser, :func:from_message_bytes.
30+
31+
Large messages like :class:SystemExclusive can only be parsed if they fit
32+
within the input buffer in :class:MIDI.
2733
2834
2935
* Author(s): Kevin J. Walters
3036
3137
Implementation Notes
3238
--------------------
3339
34-
**Hardware:**
35-
36-
37-
38-
**Software and Dependencies:**
39-
40-
* Adafruit CircuitPython firmware for the supported boards:
41-
https://github.com/adafruit/circuitpython/releases
42-
4340
"""
4441

4542
__version__ = "0.0.0-auto.0"
@@ -97,15 +94,19 @@ def note_parser(note):
9794

9895
class MIDIMessage:
9996
"""
100-
A MIDI message:
101-
- _STATUS - extracted from Status byte with channel replaced by 0s
102-
(high bit always set).
103-
- _STATUSMASK - mask used to compared a status byte with _STATUS value
104-
- LENGTH - length for a fixed size message including status
105-
or -1 for variable length.
106-
- CHANNELMASK - mask use to apply a (wire protocol) channel number.
107-
- ENDSTATUS - the EOM status byte, only set for variable length.
108-
This is an abstract class.
97+
The parent class for MIDI messages.
98+
99+
Class variables:
100+
101+
* ``_STATUS`` - extracted from status byte with channel replaced by 0s
102+
(high bit is always set by convention).
103+
* ``_STATUSMASK`` - mask used to compared a status byte with ``_STATUS`` value.
104+
* ``LENGTH`` - length for a fixed size message *including* status
105+
or -1 for variable length.
106+
* ``CHANNELMASK`` - mask used to apply a (wire protocol) channel number.
107+
* ``ENDSTATUS`` - the end of message status byte, only set for variable length.
108+
109+
This is an *abstract* class.
109110
"""
110111
_STATUS = None
111112
_STATUSMASK = None
@@ -146,7 +147,7 @@ def _search_eom_status(cls, buf, eom_status, msgstartidx, msgendidxplusone, endi
146147
# Look for a status byte
147148
# Second rule of the MIDI club is status bytes have MSB set
148149
if buf[msgendidxplusone] & 0x80:
149-
# pylint disable=simplifiable-if-statement # n/a for this technique
150+
# pylint disable=simplifiable-if-statement
150151
if buf[msgendidxplusone] == eom_status:
151152
good_termination = True
152153
else:
@@ -276,18 +277,21 @@ def from_message_bytes(cls, midibytes, channel_in):
276277
return (msg, msgendidxplusone, skipped, channel)
277278

278279
# channel value present to keep interface uniform but unused
280+
# A default method for constructing wire messages with no data.
281+
# Returns a (mutable) bytearray with just the status code in.
279282
# pylint: disable=unused-argument
280283
def as_bytes(self, channel=None):
281-
"""A default method for constructing wire messages with no data.
282-
Returns a (mutable) bytearray with just status code in."""
284+
"""Return the ``bytearray`` wire protocol representation of the object."""
283285
return bytearray([self._STATUS])
284286

285287
# databytes value present to keep interface uniform but unused
288+
# A default method for constructing message objects with no data.
289+
# Returns the new object.
286290
# pylint: disable=unused-argument
287291
@classmethod
288292
def from_bytes(cls, databytes):
289-
"""A default method for constructing message objects with no data.
290-
Returns the new object."""
293+
"""Creates an object from the byte stream of the wire protocol
294+
(not including the first status byte)."""
291295
return cls()
292296

293297

adafruit_midi/note_off.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,17 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_midi`
23+
`adafruit_midi.note_off`
2424
================================================================================
2525
26-
A CircuitPython helper for encoding/decoding MIDI packets over a MIDI or UART connection.
26+
Note Off Change MIDI message.
2727
2828
2929
* Author(s): Kevin J. Walters
3030
3131
Implementation Notes
3232
--------------------
3333
34-
**Hardware:**
35-
36-
37-
38-
**Software and Dependencies:**
39-
40-
* Adafruit CircuitPython firmware for the supported boards:
41-
https://github.com/adafruit/circuitpython/releases
42-
4334
"""
4435

4536
from .midi_message import MIDIMessage, note_parser

adafruit_midi/note_on.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,17 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_midi`
23+
`adafruit_midi.note_on`
2424
================================================================================
2525
26-
A CircuitPython helper for encoding/decoding MIDI packets over a MIDI or UART connection.
26+
Note On Change MIDI message.
2727
2828
2929
* Author(s): Kevin J. Walters
3030
3131
Implementation Notes
3232
--------------------
3333
34-
**Hardware:**
35-
36-
37-
38-
**Software and Dependencies:**
39-
40-
* Adafruit CircuitPython firmware for the supported boards:
41-
https://github.com/adafruit/circuitpython/releases
42-
4334
"""
4435

4536
from .midi_message import MIDIMessage, note_parser

adafruit_midi/pitch_bend_change.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,17 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_midi`
23+
`adafruit_midi.pitch_bend_change`
2424
================================================================================
2525
26-
A CircuitPython helper for encoding/decoding MIDI packets over a MIDI or UART connection.
26+
Pitch Bend Change MIDI message.
2727
2828
2929
* Author(s): Kevin J. Walters
3030
3131
Implementation Notes
3232
--------------------
3333
34-
**Hardware:**
35-
36-
37-
38-
**Software and Dependencies:**
39-
40-
* Adafruit CircuitPython firmware for the supported boards:
41-
https://github.com/adafruit/circuitpython/releases
42-
4334
"""
4435

4536
from .midi_message import MIDIMessage

adafruit_midi/polyphonic_key_pressure.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,17 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_midi`
23+
`adafruit_midi.polyphonic_key_pressure`
2424
================================================================================
2525
26-
A CircuitPython helper for encoding/decoding MIDI packets over a MIDI or UART connection.
26+
Polyphonic Key Pressure MIDI message.
2727
2828
2929
* Author(s): Kevin J. Walters
3030
3131
Implementation Notes
3232
--------------------
3333
34-
**Hardware:**
35-
36-
37-
38-
**Software and Dependencies:**
39-
40-
* Adafruit CircuitPython firmware for the supported boards:
41-
https://github.com/adafruit/circuitpython/releases
42-
4334
"""
4435

4536
from .midi_message import MIDIMessage, note_parser

adafruit_midi/program_change.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,17 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_midi`
23+
`adafruit_midi.program_change`
2424
================================================================================
2525
26-
A CircuitPython helper for encoding/decoding MIDI packets over a MIDI or UART connection.
26+
Program Change MIDI message.
2727
2828
2929
* Author(s): Kevin J. Walters
3030
3131
Implementation Notes
3232
--------------------
3333
34-
**Hardware:**
35-
36-
37-
38-
**Software and Dependencies:**
39-
40-
* Adafruit CircuitPython firmware for the supported boards:
41-
https://github.com/adafruit/circuitpython/releases
42-
4334
"""
4435

4536
from .midi_message import MIDIMessage

0 commit comments

Comments
 (0)