This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
forked from adafruit/Adafruit_CircuitPython_MIDI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pitch_bend.py
58 lines (41 loc) · 1.38 KB
/
pitch_bend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# SPDX-FileCopyrightText: 2019 Kevin J. Walters for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
`adafruit_midi.pitch_bend`
================================================================================
Pitch Bend Change MIDI message.
* Author(s): Kevin J. Walters
Implementation Notes
--------------------
"""
from .midi_message import MIDIMessage
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MIDI.git"
class PitchBend(MIDIMessage):
"""Pitch Bend Change MIDI message.
:param int pitch_bend: A 14bit unsigned int representing the degree of
bend from 0 through 8192 (midpoint, no bend) to 16383.
"""
_STATUS = 0xE0
_STATUSMASK = 0xF0
LENGTH = 3
def __init__(self, pitch_bend, *, channel=None):
self.pitch_bend = pitch_bend
super().__init__(channel=channel)
if not 0 <= self.pitch_bend <= 16383:
self._raise_valueerror_oor()
def __bytes__(self):
return bytes(
[
self._STATUS | (self.channel & self.CHANNELMASK),
self.pitch_bend & 0x7F,
(self.pitch_bend >> 7) & 0x7F,
]
)
@classmethod
def from_bytes(cls, msg_bytes):
return cls(
msg_bytes[2] << 7 | msg_bytes[1], channel=msg_bytes[0] & cls.CHANNELMASK
)
PitchBend.register_message_type()