|
20 | 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21 | 21 | # THE SOFTWARE. |
22 | 22 | """ |
23 | | -`adafruit_midi` |
| 23 | +`adafruit_midi.midi_message.MIDIMessage` |
24 | 24 | ================================================================================ |
25 | 25 |
|
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. |
27 | 33 |
|
28 | 34 |
|
29 | 35 | * Author(s): Kevin J. Walters |
30 | 36 |
|
31 | 37 | Implementation Notes |
32 | 38 | -------------------- |
33 | 39 |
|
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 | | -
|
43 | 40 | """ |
44 | 41 |
|
45 | 42 | __version__ = "0.0.0-auto.0" |
@@ -97,15 +94,19 @@ def note_parser(note): |
97 | 94 |
|
98 | 95 | class MIDIMessage: |
99 | 96 | """ |
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. |
109 | 110 | """ |
110 | 111 | _STATUS = None |
111 | 112 | _STATUSMASK = None |
@@ -146,7 +147,7 @@ def _search_eom_status(cls, buf, eom_status, msgstartidx, msgendidxplusone, endi |
146 | 147 | # Look for a status byte |
147 | 148 | # Second rule of the MIDI club is status bytes have MSB set |
148 | 149 | if buf[msgendidxplusone] & 0x80: |
149 | | - # pylint disable=simplifiable-if-statement # n/a for this technique |
| 150 | + # pylint disable=simplifiable-if-statement |
150 | 151 | if buf[msgendidxplusone] == eom_status: |
151 | 152 | good_termination = True |
152 | 153 | else: |
@@ -276,18 +277,21 @@ def from_message_bytes(cls, midibytes, channel_in): |
276 | 277 | return (msg, msgendidxplusone, skipped, channel) |
277 | 278 |
|
278 | 279 | # 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. |
279 | 282 | # pylint: disable=unused-argument |
280 | 283 | 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.""" |
283 | 285 | return bytearray([self._STATUS]) |
284 | 286 |
|
285 | 287 | # 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. |
286 | 290 | # pylint: disable=unused-argument |
287 | 291 | @classmethod |
288 | 292 | 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).""" |
291 | 295 | return cls() |
292 | 296 |
|
293 | 297 |
|
|
0 commit comments