Skip to content

Commit 8c3b61d

Browse files
committed
Add MIDI Time Code Quarter Frame message support
1 parent 01ae093 commit 8c3b61d

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

adafruit_midi/mtc_quarter_frame.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-FileCopyrightText: 2021 Raphaël Doursenaud
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`adafruit_midi.mtc_quarter_frame`
7+
================================================================================
8+
9+
MIDI Time Code (MTC) Quarter Frame message.
10+
11+
12+
* Author(s): Raphaël Doursenaud
13+
14+
Implementation Notes
15+
--------------------
16+
17+
Based upon the official MMA0001 / RP004 / RP008 v4.2.1 MIDI Time Code Specification
18+
19+
"""
20+
21+
from adafruit_midi.midi_message import MIDIMessage
22+
23+
__version__ = "0.0.0-auto.0"
24+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MIDI.git"
25+
26+
27+
class MtcQuarterFrame(MIDIMessage):
28+
"""MIDI Time Code (MTC) Quarter Frame message.
29+
30+
:param msgtype: The quarter frame message type:
31+
- 0: Frame count LS nibble
32+
- 1: Frame count MS nibble
33+
- 2: Seconds count LS nibble
34+
- 3: Seconds count MS nibble
35+
- 4: Minutes count LS nibble
36+
- 5: Minutes count MS nibble
37+
- 6: Hours count LS nibble
38+
- 7: Hours count MS nibble and SMPTE Type
39+
:param value: The quarter frame value for the specified type.
40+
"""
41+
42+
_STATUS = 0xF1
43+
_STATUSMASK = 0xFF
44+
LENGTH = 2
45+
46+
def __init__(self, msgtype, value):
47+
self.type = msgtype
48+
self.value = value
49+
super().__init__()
50+
if not 0 <= self.type <= 7 or not 0 <= self.value <= 0x0F:
51+
raise self._EX_VALUEERROR_OOR
52+
53+
def __bytes__(self):
54+
return bytes(
55+
[
56+
self._STATUS,
57+
(self.type << 4) + self.value # Assemble low and high nibbles
58+
]
59+
)
60+
61+
@classmethod
62+
def from_bytes(cls, msg_bytes):
63+
return cls(
64+
msg_bytes[1] >> 4, # High nibble
65+
msg_bytes[1] & 15 # Low nibble
66+
)
67+
68+
69+
MtcQuarterFrame.register_message_type()

0 commit comments

Comments
 (0)