omnipython-apps 0.1.4.dev8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. apps/__init__.py +5 -0
  2. apps/about/__init__.py +257 -0
  3. apps/about/app.json +1 -0
  4. apps/about/credits.py +12 -0
  5. apps/about/facts.py +398 -0
  6. apps/about/fonts/OFL.txt +93 -0
  7. apps/about/fonts/latin1_14.bin +0 -0
  8. apps/about/fonts/latin1_16.bin +0 -0
  9. apps/about/fonts/latin1_24.bin +0 -0
  10. apps/about/fonts/latin1_32.bin +0 -0
  11. apps/about/fonts/latin1_40.bin +0 -0
  12. apps/backline/__init__.py +58 -0
  13. apps/backline/app.json +1 -0
  14. apps/backline/app.py +475 -0
  15. apps/backline/art.py +717 -0
  16. apps/backline/ask.py +781 -0
  17. apps/backline/box.py +502 -0
  18. apps/backline/cast.py +137 -0
  19. apps/backline/desk/__init__.py +329 -0
  20. apps/backline/desk/editor.py +331 -0
  21. apps/backline/desk/grid.py +154 -0
  22. apps/backline/desk/look.py +169 -0
  23. apps/backline/desk/pedals.py +102 -0
  24. apps/backline/desk/perform.py +157 -0
  25. apps/backline/desk/prompt.py +210 -0
  26. apps/backline/desk/strip.py +159 -0
  27. apps/backline/desk_main.py +226 -0
  28. apps/backline/engine.py +622 -0
  29. apps/backline/floor.py +509 -0
  30. apps/backline/footswitch.py +119 -0
  31. apps/backline/glyphs.py +82 -0
  32. apps/backline/kits.py +428 -0
  33. apps/backline/midipedal.py +362 -0
  34. apps/backline/page_data.py +413 -0
  35. apps/backline/parts.py +145 -0
  36. apps/backline/pedal.py +107 -0
  37. apps/backline/remote.py +134 -0
  38. apps/backline/songs/ballad_68.json +1 -0
  39. apps/backline/songs/bossa.json +1 -0
  40. apps/backline/songs/country_train.json +1 -0
  41. apps/backline/songs/funk.json +1 -0
  42. apps/backline/songs/metal.json +1 -0
  43. apps/backline/songs/pop.json +1 -0
  44. apps/backline/songs/rock.json +1 -0
  45. apps/backline/songs/shuffle.json +1 -0
  46. apps/battery/__init__.py +101 -0
  47. apps/battery/app.json +1 -0
  48. apps/bit_world/act_deck.py +683 -0
  49. apps/bit_world/act_game.py +762 -0
  50. apps/bit_world/act_pet.py +1032 -0
  51. apps/bit_world/app.json +1 -0
  52. apps/bit_world/bit_output.py +45 -0
  53. apps/bit_world/bit_palette.py +503 -0
  54. apps/bit_world/bit_sound.py +431 -0
  55. apps/bit_world/bit_sprites.py +632 -0
  56. apps/bit_world/bit_world.py +534 -0
  57. apps/btreceiver/__init__.py +690 -0
  58. apps/btreceiver/app.json +1 -0
  59. apps/btreceiver/chime.py +155 -0
  60. apps/btreceiver/demo.py +529 -0
  61. apps/btreceiver/screen.py +633 -0
  62. apps/camera/__init__.py +316 -0
  63. apps/camera/app.json +1 -0
  64. apps/card/__init__.py +113 -0
  65. apps/card/app.json +1 -0
  66. apps/cast/__init__.py +631 -0
  67. apps/cast/app.json +1 -0
  68. apps/cast/receivers.py +193 -0
  69. apps/chess/__init__.py +18 -0
  70. apps/chess/app.json +1 -0
  71. apps/chess/app.py +922 -0
  72. apps/chess/art.py +323 -0
  73. apps/chess/ble.py +411 -0
  74. apps/chess/engine.py +925 -0
  75. apps/chess/game.py +327 -0
  76. apps/chess/net.py +261 -0
  77. apps/clock/__init__.py +38 -0
  78. apps/clock/app.json +1 -0
  79. apps/detect/__init__.py +214 -0
  80. apps/detect/app.json +1 -0
  81. apps/fmsynth/__init__.py +41 -0
  82. apps/fmsynth/algorithms.py +61 -0
  83. apps/fmsynth/app.json +1 -0
  84. apps/fmsynth/app.py +355 -0
  85. apps/fmsynth/editor.py +206 -0
  86. apps/fmsynth/engine.py +257 -0
  87. apps/fmsynth/meters.py +262 -0
  88. apps/fmsynth/midi.py +375 -0
  89. apps/fmsynth/panel_view.py +1071 -0
  90. apps/fmsynth/patches/fmsynth-01.syx +0 -0
  91. apps/fmsynth/settings.py +138 -0
  92. apps/fmsynth/voice.py +398 -0
  93. apps/gamepad/__init__.py +685 -0
  94. apps/gamepad/app.json +1 -0
  95. apps/gamepad/pad.py +94 -0
  96. apps/gamepad/watch.py +352 -0
  97. apps/hidden/__init__.py +72 -0
  98. apps/hidden/app.json +1 -0
  99. apps/home/__init__.py +483 -0
  100. apps/home/app.json +1 -0
  101. apps/home/main.py +36 -0
  102. apps/homeassistant/__init__.py +213 -0
  103. apps/homeassistant/api.py +104 -0
  104. apps/homeassistant/app.json +1 -0
  105. apps/huey/__init__.py +287 -0
  106. apps/huey/acting.py +184 -0
  107. apps/huey/actor.py +194 -0
  108. apps/huey/app.json +1 -0
  109. apps/huey/client.py +125 -0
  110. apps/huey/servers.py +121 -0
  111. apps/huey/settings.example.json +8 -0
  112. apps/huey/settings.py +97 -0
  113. apps/huey/turn.py +504 -0
  114. apps/huey/voice.py +217 -0
  115. apps/info/__init__.py +810 -0
  116. apps/info/app.json +1 -0
  117. apps/lora/__init__.py +62 -0
  118. apps/lora/app.json +1 -0
  119. apps/manifest.py +71 -0
  120. apps/medialink_baby_monitor/__init__.py +222 -0
  121. apps/medialink_baby_monitor/app.json +1 -0
  122. apps/medialink_doorbell/__init__.py +251 -0
  123. apps/medialink_doorbell/app.json +1 -0
  124. apps/medialink_hands_free/__init__.py +217 -0
  125. apps/medialink_hands_free/app.json +1 -0
  126. apps/medialink_surveillance_camera/__init__.py +258 -0
  127. apps/medialink_surveillance_camera/app.json +1 -0
  128. apps/medialink_video_doorbell/__init__.py +289 -0
  129. apps/medialink_video_doorbell/app.json +1 -0
  130. apps/medialink_videophone/__init__.py +273 -0
  131. apps/medialink_videophone/app.json +1 -0
  132. apps/medialink_walkie_talkie/__init__.py +228 -0
  133. apps/medialink_walkie_talkie/app.json +1 -0
  134. apps/midicontroller/__init__.py +774 -0
  135. apps/midicontroller/app.json +1 -0
  136. apps/midicontroller/links.py +421 -0
  137. apps/midicontroller/surface.py +343 -0
  138. apps/midiengine/__init__.py +977 -0
  139. apps/midiengine/app.json +1 -0
  140. apps/midiengine/banks.py +85 -0
  141. apps/midiengine/midiin.py +165 -0
  142. apps/midiengine/player.py +392 -0
  143. apps/midiengine/umidiparser.py +1413 -0
  144. apps/mp3/__init__.py +240 -0
  145. apps/mp3/app.json +1 -0
  146. apps/perch/__init__.py +119 -0
  147. apps/perch/app.json +1 -0
  148. apps/perch/huey.py +481 -0
  149. apps/perch/huey_props.py +386 -0
  150. apps/perch/huey_shift.py +42 -0
  151. apps/perch/huey_views.py +296 -0
  152. apps/perch/scene_bench.py +680 -0
  153. apps/perch/scene_coast.py +479 -0
  154. apps/perch/scene_desk.py +492 -0
  155. apps/perch/stage.py +1274 -0
  156. apps/perch/vec.py +366 -0
  157. apps/repl/__init__.py +325 -0
  158. apps/repl/app.json +1 -0
  159. apps/roku/__init__.py +156 -0
  160. apps/roku/app.json +1 -0
  161. apps/rokucam/__init__.py +362 -0
  162. apps/rokucam/app.json +1 -0
  163. apps/security/__init__.py +261 -0
  164. apps/security/app.json +1 -0
  165. apps/settings/__init__.py +221 -0
  166. apps/settings/app.json +1 -0
  167. apps/shell/__init__.py +33 -0
  168. apps/shell/app.json +1 -0
  169. apps/spotify/__init__.py +669 -0
  170. apps/spotify/app.json +1 -0
  171. apps/spotify/screen.py +82 -0
  172. apps/steps/__init__.py +58 -0
  173. apps/steps/app.json +1 -0
  174. apps/stompbox/__init__.py +31 -0
  175. apps/stompbox/app.json +1 -0
  176. apps/stompbox/app.py +668 -0
  177. apps/stompbox/boards.json +20 -0
  178. apps/stompbox/effects.py +241 -0
  179. apps/stompbox/engine.py +340 -0
  180. apps/stompbox/footswitch.py +331 -0
  181. apps/stompbox/inputs.py +449 -0
  182. apps/stompbox/meter.py +72 -0
  183. apps/stompbox/outputs.py +135 -0
  184. apps/stompbox/pedals.txt +45 -0
  185. apps/stompbox/presets.py +106 -0
  186. apps/stompbox/styles.py +135 -0
  187. apps/stompbox/ui.py +817 -0
  188. apps/stompbox/wavfile.py +73 -0
  189. apps/synthstation/__init__.py +20 -0
  190. apps/synthstation/app.json +1 -0
  191. apps/synthstation/audio.py +397 -0
  192. apps/synthstation/catalog.py +50 -0
  193. apps/synthstation/meters.py +136 -0
  194. apps/synthstation/midi.py +380 -0
  195. apps/synthstation/pads.py +177 -0
  196. apps/synthstation/parts.py +128 -0
  197. apps/synthstation/station.py +1069 -0
  198. apps/system/__init__.py +11 -0
  199. apps/system/app.json +1 -0
  200. apps/touchcal/__init__.py +324 -0
  201. apps/touchcal/app.json +1 -0
  202. apps/touchcal/fit.py +262 -0
  203. apps/wake/__init__.py +268 -0
  204. apps/wake/app.json +1 -0
  205. apps/wake/feed.py +155 -0
  206. apps/watch/__init__.py +355 -0
  207. apps/watch/app.json +1 -0
  208. apps/watch/faces.py +35 -0
  209. apps/watch/wheel.py +157 -0
  210. apps/weather/__init__.py +278 -0
  211. apps/weather/app.json +1 -0
  212. apps/weather/icons.py +172 -0
  213. apps/weather/sizing.py +71 -0
  214. apps/weather/zippad.py +172 -0
  215. omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
  216. omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
  217. omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
  218. omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,343 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """What each control sends, what the user changed, and what comes back.
5
+
6
+ This is the controller without a screen: the mapping from each control to
7
+ a note or a CC, the channel, the velocity, the pad bank and the keyboard's
8
+ octave, and the MIDI bytes each touch makes. The screen calls `Surface.press`,
9
+ `Surface.release` and `Surface.move`, and hands what arrives on the input to
10
+ `Surface.feed`, which says which controls should move to match.
11
+
12
+ A control is named by an id: ``pad0`` to ``pad15`` (``pad0`` at the bottom
13
+ left, as on a pad controller), ``knob0`` to ``knob15``, ``fader0`` to
14
+ ``fader15``, the mixer's ``mix0`` to ``mix7`` with ``mute0`` to ``mute7``
15
+ and ``solo0`` to ``solo7``, the XY pad's ``x`` and ``y``, the transport's
16
+ ``tr0`` to ``tr5`` and the keyboard's ``mod`` wheel. Each maps to
17
+ ``(kind, number)``, where kind is ``"note"`` or ``"cc"``. The mixer's strips
18
+ play on the channel plus the strip's number, so strip 1 is on the channel
19
+ and strip 8 seven above it: with the channel at 1, the faders are the
20
+ volumes of a synth's first eight parts.
21
+ """
22
+
23
+ NOTE = "note"
24
+ CC = "cc"
25
+
26
+ #: The defaults, which a saved file only overrides. Pads start at 36, the
27
+ #: drum kit's kick; knobs on 70 to 85, a synth's sound controllers (74 is
28
+ #: the filter's cutoff); faders on 102 to 117, which nothing else uses.
29
+ PADS = 16
30
+ KNOBS = 16
31
+ FADERS = 16
32
+ STRIPS = 8
33
+ TRANSPORT = ("Rewind", "Forward", "Stop", "Play", "Record", "Loop")
34
+ BANKS = "ABCD"
35
+
36
+
37
+ def _defaults():
38
+ d = {}
39
+ for i in range(PADS):
40
+ d["pad%d" % i] = (NOTE, 36 + i)
41
+ for i in range(KNOBS):
42
+ d["knob%d" % i] = (CC, 70 + i)
43
+ for i in range(FADERS):
44
+ d["fader%d" % i] = (CC, 102 + i)
45
+ for i in range(STRIPS):
46
+ d["mix%d" % i] = (CC, 7)
47
+ d["mute%d" % i] = (CC, 14)
48
+ d["solo%d" % i] = (CC, 15)
49
+ d["x"] = (CC, 16)
50
+ d["y"] = (CC, 17)
51
+ for i in range(len(TRANSPORT)):
52
+ d["tr%d" % i] = (CC, 20 + i)
53
+ d["mod"] = (CC, 1)
54
+ return d
55
+
56
+
57
+ DEFAULT_MAP = _defaults()
58
+
59
+ #: The settings a file can hold, and their defaults. ``velocity`` 0 means
60
+ #: from the touch; 1 to 127 is a fixed velocity.
61
+ DEFAULTS = {"channel": 1, "velocity": 0, "bank": 0, "octave": 4, "output": None, "view": "pads"}
62
+
63
+ #: Controls that are pressed and let go; the rest move through 0 to 127.
64
+ _BUTTONS = ("pad", "mute", "solo", "tr")
65
+ #: Buttons that stay on until pressed again.
66
+ _TOGGLES = ("mute", "solo")
67
+ #: How long a control ignores what comes in after a hand moved it, in ms,
68
+ #: so a port that echoes (a loopback, a DAW) doesn't pull it back.
69
+ HOLD_MS = 300
70
+
71
+ NAMES = ("C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B")
72
+
73
+
74
+ def note_name(n):
75
+ """Note *n* as a name and octave, middle C (60) as ``C4``."""
76
+ return "%s%d" % (NAMES[n % 12], n // 12 - 1)
77
+
78
+
79
+ def family(cid):
80
+ """The id without its number: ``"pad"`` for ``"pad12"``."""
81
+ i = len(cid)
82
+ while i and cid[i - 1] in "0123456789":
83
+ i -= 1
84
+ return cid[:i]
85
+
86
+
87
+ def index(cid):
88
+ """The id's number: 12 for ``"pad12"``; 0 for ``"x"``."""
89
+ f = family(cid)
90
+ return int(cid[len(f):]) if len(cid) > len(f) else 0
91
+
92
+
93
+ def is_button(cid):
94
+ return family(cid) in _BUTTONS
95
+
96
+
97
+ def touch_velocity(frac):
98
+ """A velocity from where a finger landed: *frac* is 0 at the soft edge
99
+ and 1 at the hard one. A touch panel reads no pressure, so this is the
100
+ one thing a finger can choose."""
101
+ frac = 0.0 if frac < 0 else (1.0 if frac > 1 else frac)
102
+ return 32 + int(95 * frac + 0.5)
103
+
104
+
105
+ class Surface:
106
+ """The controller's state, and the bytes each touch sends to *out*.
107
+
108
+ *out* has ``write(buf, nbytes)`` (a MIDI output port) or is None, when
109
+ the touches are only counted.
110
+ """
111
+
112
+ def __init__(self, config=None, out=None):
113
+ self.settings = dict(DEFAULTS)
114
+ self.map = dict(DEFAULT_MAP)
115
+ self.values = {}
116
+ self.out = out
117
+ self.sent = 0
118
+ self.last = None # the last message, for the status line
119
+ self.error = None
120
+ self.changed = False # something to save
121
+ self._index = None
122
+ self._moved = {}
123
+ if config:
124
+ self.load(config)
125
+
126
+ # -- settings and the mapping --------------------------------------------
127
+
128
+ def load(self, config):
129
+ """Take a saved file's dict; anything it lacks keeps its default."""
130
+ for k in DEFAULTS:
131
+ if k in config:
132
+ self.settings[k] = config[k]
133
+ for cid, entry in (config.get("map") or {}).items():
134
+ if cid in DEFAULT_MAP and isinstance(entry, (list, tuple)) and len(entry) == 2:
135
+ kind, num = entry
136
+ if kind in (NOTE, CC) and 0 <= int(num) <= 127:
137
+ self.map[cid] = (kind, int(num))
138
+ self._clamp()
139
+ self._index = None
140
+
141
+ def config(self):
142
+ """What to save: only what differs from the defaults."""
143
+ out = {k: v for k, v in self.settings.items() if v != DEFAULTS[k]}
144
+ edits = {cid: list(m) for cid, m in self.map.items() if m != DEFAULT_MAP[cid]}
145
+ if edits:
146
+ out["map"] = edits
147
+ return out
148
+
149
+ def _clamp(self):
150
+ s = self.settings
151
+ s["channel"] = min(16, max(1, int(s["channel"])))
152
+ s["velocity"] = min(127, max(0, int(s["velocity"])))
153
+ s["bank"] = min(len(BANKS) - 1, max(0, int(s["bank"])))
154
+ s["octave"] = min(8, max(-1, int(s["octave"])))
155
+
156
+ def set(self, key, value):
157
+ """Change one setting, kept within its range."""
158
+ self.settings[key] = value
159
+ self._clamp()
160
+ self.changed = True
161
+ self._index = None
162
+
163
+ def remap(self, cid, kind=None, number=None):
164
+ """Point control *cid* at another note or CC. A control that moves
165
+ through a range stays a CC."""
166
+ old_kind, old_num = self.map[cid]
167
+ kind = kind or old_kind
168
+ if not is_button(cid):
169
+ kind = CC
170
+ number = old_num if number is None else min(127, max(0, int(number)))
171
+ self.map[cid] = (kind, number)
172
+ self.changed = True
173
+ self._index = None
174
+
175
+ def reset(self, cid=None):
176
+ """Put one control, or every one, back to its default."""
177
+ if cid is None:
178
+ self.map = dict(DEFAULT_MAP)
179
+ else:
180
+ self.map[cid] = DEFAULT_MAP[cid]
181
+ self.changed = True
182
+ self._index = None
183
+
184
+ def channel_of(self, cid):
185
+ """The 0-based channel *cid* plays on."""
186
+ ch = self.settings["channel"] - 1
187
+ if family(cid) in ("mix", "mute", "solo"):
188
+ ch = (ch + index(cid)) % 16
189
+ return ch
190
+
191
+ def target(self, cid):
192
+ """``(kind, number, channel)`` for *cid* now, with the pad bank
193
+ applied; the number is None for a pad the bank pushed past 127."""
194
+ kind, num = self.map[cid]
195
+ if family(cid) == "pad" and kind == NOTE:
196
+ num += 16 * self.settings["bank"]
197
+ if num > 127:
198
+ num = None
199
+ return kind, num, self.channel_of(cid)
200
+
201
+ def describe(self, cid):
202
+ """What *cid* sends, for its label: ``C1``, ``CC 74``."""
203
+ kind, num, _ = self.target(cid)
204
+ if num is None:
205
+ return "-"
206
+ return note_name(num) if kind == NOTE else "CC %d" % num
207
+
208
+ def key_note(self, k):
209
+ """The note of the keyboard's key *k* (0 is the strip's first C)."""
210
+ return 12 * (self.settings["octave"] + 1) + k
211
+
212
+ # -- touches ---------------------------------------------------------------
213
+
214
+ def velocity(self, frac=None):
215
+ """The fixed velocity, or one from the touch's *frac*."""
216
+ v = self.settings["velocity"]
217
+ if v:
218
+ return v
219
+ return touch_velocity(0.75 if frac is None else frac)
220
+
221
+ def _send(self, status, a, b):
222
+ msg = bytes((status, a, b))
223
+ self.last = msg
224
+ out = self.out
225
+ if out is None:
226
+ return msg
227
+ try:
228
+ out.write(msg, 3)
229
+ self.sent += 1
230
+ self.error = None
231
+ except Exception as e: # noqa: BLE001 - a port that went away says so on the status line
232
+ self.error = str(e) or type(e).__name__
233
+ return msg
234
+
235
+ def press(self, cid, frac=None):
236
+ """A button went down (a toggle flips). *frac* says where the finger
237
+ landed, for the velocity. Returns the bytes sent, or None."""
238
+ kind, num, ch = self.target(cid)
239
+ if num is None:
240
+ return None
241
+ if family(cid) in _TOGGLES:
242
+ on = not self.values.get(cid)
243
+ self.values[cid] = 127 if on else 0
244
+ if kind == NOTE:
245
+ return self._send((0x90 if on else 0x80) | ch, num, 127 if on else 0)
246
+ return self._send(0xB0 | ch, num, 127 if on else 0)
247
+ vel = 127 if family(cid) == "tr" else self.velocity(frac)
248
+ self.values[cid] = vel
249
+ return self._send((0x90 if kind == NOTE else 0xB0) | ch, num, vel)
250
+
251
+ def release(self, cid):
252
+ """A momentary button let go. Toggles send nothing."""
253
+ if family(cid) in _TOGGLES:
254
+ return None
255
+ kind, num, ch = self.target(cid)
256
+ if num is None:
257
+ return None
258
+ self.values[cid] = 0
259
+ if kind == NOTE:
260
+ return self._send(0x80 | ch, num, 0)
261
+ return self._send(0xB0 | ch, num, 0)
262
+
263
+ def move(self, cid, value, now=None):
264
+ """A knob, fader or the XY pad moved to *value* (0 to 127).
265
+ *now* in ms keeps what comes back from moving it again for a while."""
266
+ value = min(127, max(0, int(value)))
267
+ self.values[cid] = value
268
+ if now is not None:
269
+ self._moved[cid] = now
270
+ kind, num, ch = self.target(cid)
271
+ if kind == NOTE:
272
+ return self._send((0x90 if value else 0x80) | ch, num, value)
273
+ return self._send(0xB0 | ch, num, value)
274
+
275
+ def key(self, k, down, frac=None):
276
+ """Key *k* of the keyboard strip pressed or let go."""
277
+ n = self.key_note(k)
278
+ if not 0 <= n <= 127:
279
+ return None
280
+ ch = self.settings["channel"] - 1
281
+ if down:
282
+ return self._send(0x90 | ch, n, self.velocity(frac))
283
+ return self._send(0x80 | ch, n, 0)
284
+
285
+ def panic(self):
286
+ """All notes off on the channel, and on the mixer's channels."""
287
+ seen = []
288
+ for cid in ["pad0"] + ["mix%d" % i for i in range(STRIPS)]:
289
+ ch = self.channel_of(cid)
290
+ if ch not in seen:
291
+ seen.append(ch)
292
+ self._send(0xB0 | ch, 123, 0)
293
+
294
+ # -- what comes in ----------------------------------------------------------
295
+
296
+ def _build_index(self):
297
+ idx = {}
298
+ for cid in self.map:
299
+ kind, num, ch = self.target(cid)
300
+ if num is None:
301
+ continue
302
+ idx.setdefault((kind, ch, num), []).append(cid)
303
+ self._index = idx
304
+
305
+ def feed(self, data, now=None, since=None):
306
+ """Read whole MIDI messages in *data*; return ``[(cid, value), ...]``
307
+ for each control that should move to match. A note's value is its
308
+ velocity, 0 when it ends. *now* and *since* (``ticks_diff``) skip
309
+ controls a hand moved within `HOLD_MS`."""
310
+ if self._index is None:
311
+ self._build_index()
312
+ out = []
313
+ i = 0
314
+ n = len(data)
315
+ while i < n:
316
+ status = data[i]
317
+ if status < 0x80:
318
+ i += 1 # a stray data byte: the ports hand out whole messages
319
+ continue
320
+ hi = status & 0xF0
321
+ if status >= 0xF0:
322
+ i += 1
323
+ continue
324
+ size = 2 if hi in (0xC0, 0xD0) else 3
325
+ if i + size > n:
326
+ break
327
+ ch = status & 0x0F
328
+ if hi in (0x80, 0x90, 0xB0):
329
+ a, b = data[i + 1], data[i + 2]
330
+ if hi == 0xB0:
331
+ key = (CC, ch, a)
332
+ value = b
333
+ else:
334
+ key = (NOTE, ch, a)
335
+ value = b if hi == 0x90 else 0
336
+ for cid in self._index.get(key, ()):
337
+ if now is not None and since is not None and cid in self._moved:
338
+ if since(now, self._moved[cid]) < HOLD_MS:
339
+ continue
340
+ self.values[cid] = value
341
+ out.append((cid, value))
342
+ i += size
343
+ return out