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.
- apps/__init__.py +5 -0
- apps/about/__init__.py +257 -0
- apps/about/app.json +1 -0
- apps/about/credits.py +12 -0
- apps/about/facts.py +398 -0
- apps/about/fonts/OFL.txt +93 -0
- apps/about/fonts/latin1_14.bin +0 -0
- apps/about/fonts/latin1_16.bin +0 -0
- apps/about/fonts/latin1_24.bin +0 -0
- apps/about/fonts/latin1_32.bin +0 -0
- apps/about/fonts/latin1_40.bin +0 -0
- apps/backline/__init__.py +58 -0
- apps/backline/app.json +1 -0
- apps/backline/app.py +475 -0
- apps/backline/art.py +717 -0
- apps/backline/ask.py +781 -0
- apps/backline/box.py +502 -0
- apps/backline/cast.py +137 -0
- apps/backline/desk/__init__.py +329 -0
- apps/backline/desk/editor.py +331 -0
- apps/backline/desk/grid.py +154 -0
- apps/backline/desk/look.py +169 -0
- apps/backline/desk/pedals.py +102 -0
- apps/backline/desk/perform.py +157 -0
- apps/backline/desk/prompt.py +210 -0
- apps/backline/desk/strip.py +159 -0
- apps/backline/desk_main.py +226 -0
- apps/backline/engine.py +622 -0
- apps/backline/floor.py +509 -0
- apps/backline/footswitch.py +119 -0
- apps/backline/glyphs.py +82 -0
- apps/backline/kits.py +428 -0
- apps/backline/midipedal.py +362 -0
- apps/backline/page_data.py +413 -0
- apps/backline/parts.py +145 -0
- apps/backline/pedal.py +107 -0
- apps/backline/remote.py +134 -0
- apps/backline/songs/ballad_68.json +1 -0
- apps/backline/songs/bossa.json +1 -0
- apps/backline/songs/country_train.json +1 -0
- apps/backline/songs/funk.json +1 -0
- apps/backline/songs/metal.json +1 -0
- apps/backline/songs/pop.json +1 -0
- apps/backline/songs/rock.json +1 -0
- apps/backline/songs/shuffle.json +1 -0
- apps/battery/__init__.py +101 -0
- apps/battery/app.json +1 -0
- apps/bit_world/act_deck.py +683 -0
- apps/bit_world/act_game.py +762 -0
- apps/bit_world/act_pet.py +1032 -0
- apps/bit_world/app.json +1 -0
- apps/bit_world/bit_output.py +45 -0
- apps/bit_world/bit_palette.py +503 -0
- apps/bit_world/bit_sound.py +431 -0
- apps/bit_world/bit_sprites.py +632 -0
- apps/bit_world/bit_world.py +534 -0
- apps/btreceiver/__init__.py +690 -0
- apps/btreceiver/app.json +1 -0
- apps/btreceiver/chime.py +155 -0
- apps/btreceiver/demo.py +529 -0
- apps/btreceiver/screen.py +633 -0
- apps/camera/__init__.py +316 -0
- apps/camera/app.json +1 -0
- apps/card/__init__.py +113 -0
- apps/card/app.json +1 -0
- apps/cast/__init__.py +631 -0
- apps/cast/app.json +1 -0
- apps/cast/receivers.py +193 -0
- apps/chess/__init__.py +18 -0
- apps/chess/app.json +1 -0
- apps/chess/app.py +922 -0
- apps/chess/art.py +323 -0
- apps/chess/ble.py +411 -0
- apps/chess/engine.py +925 -0
- apps/chess/game.py +327 -0
- apps/chess/net.py +261 -0
- apps/clock/__init__.py +38 -0
- apps/clock/app.json +1 -0
- apps/detect/__init__.py +214 -0
- apps/detect/app.json +1 -0
- apps/fmsynth/__init__.py +41 -0
- apps/fmsynth/algorithms.py +61 -0
- apps/fmsynth/app.json +1 -0
- apps/fmsynth/app.py +355 -0
- apps/fmsynth/editor.py +206 -0
- apps/fmsynth/engine.py +257 -0
- apps/fmsynth/meters.py +262 -0
- apps/fmsynth/midi.py +375 -0
- apps/fmsynth/panel_view.py +1071 -0
- apps/fmsynth/patches/fmsynth-01.syx +0 -0
- apps/fmsynth/settings.py +138 -0
- apps/fmsynth/voice.py +398 -0
- apps/gamepad/__init__.py +685 -0
- apps/gamepad/app.json +1 -0
- apps/gamepad/pad.py +94 -0
- apps/gamepad/watch.py +352 -0
- apps/hidden/__init__.py +72 -0
- apps/hidden/app.json +1 -0
- apps/home/__init__.py +483 -0
- apps/home/app.json +1 -0
- apps/home/main.py +36 -0
- apps/homeassistant/__init__.py +213 -0
- apps/homeassistant/api.py +104 -0
- apps/homeassistant/app.json +1 -0
- apps/huey/__init__.py +287 -0
- apps/huey/acting.py +184 -0
- apps/huey/actor.py +194 -0
- apps/huey/app.json +1 -0
- apps/huey/client.py +125 -0
- apps/huey/servers.py +121 -0
- apps/huey/settings.example.json +8 -0
- apps/huey/settings.py +97 -0
- apps/huey/turn.py +504 -0
- apps/huey/voice.py +217 -0
- apps/info/__init__.py +810 -0
- apps/info/app.json +1 -0
- apps/lora/__init__.py +62 -0
- apps/lora/app.json +1 -0
- apps/manifest.py +71 -0
- apps/medialink_baby_monitor/__init__.py +222 -0
- apps/medialink_baby_monitor/app.json +1 -0
- apps/medialink_doorbell/__init__.py +251 -0
- apps/medialink_doorbell/app.json +1 -0
- apps/medialink_hands_free/__init__.py +217 -0
- apps/medialink_hands_free/app.json +1 -0
- apps/medialink_surveillance_camera/__init__.py +258 -0
- apps/medialink_surveillance_camera/app.json +1 -0
- apps/medialink_video_doorbell/__init__.py +289 -0
- apps/medialink_video_doorbell/app.json +1 -0
- apps/medialink_videophone/__init__.py +273 -0
- apps/medialink_videophone/app.json +1 -0
- apps/medialink_walkie_talkie/__init__.py +228 -0
- apps/medialink_walkie_talkie/app.json +1 -0
- apps/midicontroller/__init__.py +774 -0
- apps/midicontroller/app.json +1 -0
- apps/midicontroller/links.py +421 -0
- apps/midicontroller/surface.py +343 -0
- apps/midiengine/__init__.py +977 -0
- apps/midiengine/app.json +1 -0
- apps/midiengine/banks.py +85 -0
- apps/midiengine/midiin.py +165 -0
- apps/midiengine/player.py +392 -0
- apps/midiengine/umidiparser.py +1413 -0
- apps/mp3/__init__.py +240 -0
- apps/mp3/app.json +1 -0
- apps/perch/__init__.py +119 -0
- apps/perch/app.json +1 -0
- apps/perch/huey.py +481 -0
- apps/perch/huey_props.py +386 -0
- apps/perch/huey_shift.py +42 -0
- apps/perch/huey_views.py +296 -0
- apps/perch/scene_bench.py +680 -0
- apps/perch/scene_coast.py +479 -0
- apps/perch/scene_desk.py +492 -0
- apps/perch/stage.py +1274 -0
- apps/perch/vec.py +366 -0
- apps/repl/__init__.py +325 -0
- apps/repl/app.json +1 -0
- apps/roku/__init__.py +156 -0
- apps/roku/app.json +1 -0
- apps/rokucam/__init__.py +362 -0
- apps/rokucam/app.json +1 -0
- apps/security/__init__.py +261 -0
- apps/security/app.json +1 -0
- apps/settings/__init__.py +221 -0
- apps/settings/app.json +1 -0
- apps/shell/__init__.py +33 -0
- apps/shell/app.json +1 -0
- apps/spotify/__init__.py +669 -0
- apps/spotify/app.json +1 -0
- apps/spotify/screen.py +82 -0
- apps/steps/__init__.py +58 -0
- apps/steps/app.json +1 -0
- apps/stompbox/__init__.py +31 -0
- apps/stompbox/app.json +1 -0
- apps/stompbox/app.py +668 -0
- apps/stompbox/boards.json +20 -0
- apps/stompbox/effects.py +241 -0
- apps/stompbox/engine.py +340 -0
- apps/stompbox/footswitch.py +331 -0
- apps/stompbox/inputs.py +449 -0
- apps/stompbox/meter.py +72 -0
- apps/stompbox/outputs.py +135 -0
- apps/stompbox/pedals.txt +45 -0
- apps/stompbox/presets.py +106 -0
- apps/stompbox/styles.py +135 -0
- apps/stompbox/ui.py +817 -0
- apps/stompbox/wavfile.py +73 -0
- apps/synthstation/__init__.py +20 -0
- apps/synthstation/app.json +1 -0
- apps/synthstation/audio.py +397 -0
- apps/synthstation/catalog.py +50 -0
- apps/synthstation/meters.py +136 -0
- apps/synthstation/midi.py +380 -0
- apps/synthstation/pads.py +177 -0
- apps/synthstation/parts.py +128 -0
- apps/synthstation/station.py +1069 -0
- apps/system/__init__.py +11 -0
- apps/system/app.json +1 -0
- apps/touchcal/__init__.py +324 -0
- apps/touchcal/app.json +1 -0
- apps/touchcal/fit.py +262 -0
- apps/wake/__init__.py +268 -0
- apps/wake/app.json +1 -0
- apps/wake/feed.py +155 -0
- apps/watch/__init__.py +355 -0
- apps/watch/app.json +1 -0
- apps/watch/faces.py +35 -0
- apps/watch/wheel.py +157 -0
- apps/weather/__init__.py +278 -0
- apps/weather/app.json +1 -0
- apps/weather/icons.py +172 -0
- apps/weather/sizing.py +71 -0
- apps/weather/zippad.py +172 -0
- omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
- omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
- omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
- omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Play Backline from a MIDI foot controller: each switch learned, then bound
|
|
5
|
+
to a pedal or to one action.
|
|
6
|
+
|
|
7
|
+
A `MidiPedal` holds four slots, one for each switch. Arm a slot with
|
|
8
|
+
`MidiPedal.learn` and press the switch: the message it sends fills the slot.
|
|
9
|
+
Then bind the slot to one of `BINDINGS`:
|
|
10
|
+
|
|
11
|
+
- ``"pedal_a"`` or ``"pedal_b"``: the switch is that pedal, with its taps,
|
|
12
|
+
holds and double taps. The switch must say when it goes down and when it
|
|
13
|
+
comes up: a controller change of 64 or more and then one below 64 (a
|
|
14
|
+
momentary switch), or a note on and then its note off.
|
|
15
|
+
- ``"start"``, ``"fill"``, ``"next"``, ``"outro"``, ``"stop"`` or
|
|
16
|
+
``"tap_tempo"``: the switch does that one thing each time it's pressed. A
|
|
17
|
+
program change, or a controller that only ever sends one value, can only
|
|
18
|
+
do this, since it never says when the foot comes up.
|
|
19
|
+
|
|
20
|
+
Messages that no slot holds are ignored, so the same port can carry a
|
|
21
|
+
keyboard or a clock.
|
|
22
|
+
|
|
23
|
+
The map saves as plain lists and strings (`MidiPedal.saved`), so it goes in
|
|
24
|
+
the app's settings as it is. `open_input` opens the MIDI input that
|
|
25
|
+
settings name; it is the one place that knows how.
|
|
26
|
+
|
|
27
|
+
Example::
|
|
28
|
+
|
|
29
|
+
pedals = MidiPedal(on_pedal=box.pedal, on_action=box.action)
|
|
30
|
+
pedals.learn(0)
|
|
31
|
+
pedals.feed(b"\\xb0\\x50\\x7f") # switch 1 sends CC 80 = 127: slot 1 learns it
|
|
32
|
+
pedals.feed(b"\\xb0\\x50\\x7f") # pedal A goes down
|
|
33
|
+
pedals.feed(b"\\xb0\\x50\\x00") # and comes up: a tap
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
from time import ticks_diff
|
|
38
|
+
except ImportError: # CPython
|
|
39
|
+
def ticks_diff(a, b):
|
|
40
|
+
return a - b
|
|
41
|
+
|
|
42
|
+
CC = "cc"
|
|
43
|
+
NOTE = "note"
|
|
44
|
+
PC = "pc"
|
|
45
|
+
|
|
46
|
+
#: What a slot can be bound to, in the order a menu lists them.
|
|
47
|
+
BINDINGS = ("pedal_a", "pedal_b", "start", "fill", "next", "outro", "stop", "tap_tempo", "none")
|
|
48
|
+
#: A short name for each, for a menu.
|
|
49
|
+
LABELS = {"pedal_a": "Pedal A", "pedal_b": "Pedal B", "start": "Start", "fill": "Fill", "next": "Next part",
|
|
50
|
+
"outro": "Outro", "stop": "Stop", "tap_tempo": "Tap tempo", "none": "Nothing"}
|
|
51
|
+
#: The bindings that need a press and a release, and which pedal each is.
|
|
52
|
+
PEDALS = {"pedal_a": 0, "pedal_b": 1}
|
|
53
|
+
#: What a learned switch that can't be a pedal is bound to instead.
|
|
54
|
+
ONE_SHOT = "fill"
|
|
55
|
+
|
|
56
|
+
SLOTS = 4
|
|
57
|
+
#: Switch 1 is the main pedal, 2 the second pedal, 3 taps the tempo and 4
|
|
58
|
+
#: stops. No message is filled in: learn each switch, since a foot
|
|
59
|
+
#: controller's factory messages differ from one model to the next.
|
|
60
|
+
DEFAULT = ("pedal_a", "pedal_b", "tap_tempo", "stop")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def new_slots():
|
|
64
|
+
return [{"msg": None, "bind": b} for b in DEFAULT]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def describe_msg(msg):
|
|
68
|
+
"""``"CC 80 ch 1"``, ``"Note 36 ch 10"``, ``"PC 3 ch 1"``, or ``"-"``."""
|
|
69
|
+
if not msg:
|
|
70
|
+
return "-"
|
|
71
|
+
kind, ch, num = msg
|
|
72
|
+
return "%s %d ch %d" % ({CC: "CC", NOTE: "Note", PC: "PC"}.get(kind, kind), num, ch + 1)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def can_pedal(msg):
|
|
76
|
+
"""Whether a switch sending ``msg`` can say when it comes up."""
|
|
77
|
+
return not msg or msg[0] != PC
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def messages(data):
|
|
81
|
+
"""``(status, data1, data2)`` for each channel message in ``data``.
|
|
82
|
+
|
|
83
|
+
Whole messages, as midiports' inputs hand them out. System messages
|
|
84
|
+
(clock, SysEx) are skipped, and so is a stray data byte."""
|
|
85
|
+
i = 0
|
|
86
|
+
n = len(data)
|
|
87
|
+
while i < n:
|
|
88
|
+
status = data[i]
|
|
89
|
+
if status < 0x80:
|
|
90
|
+
i += 1
|
|
91
|
+
continue
|
|
92
|
+
if status >= 0xF0:
|
|
93
|
+
if status == 0xF0:
|
|
94
|
+
while i < n and data[i] != 0xF7:
|
|
95
|
+
i += 1
|
|
96
|
+
elif status in (0xF1, 0xF3):
|
|
97
|
+
i += 1
|
|
98
|
+
elif status == 0xF2:
|
|
99
|
+
i += 2
|
|
100
|
+
i += 1
|
|
101
|
+
continue
|
|
102
|
+
size = 2 if (status & 0xE0) == 0xC0 else 3
|
|
103
|
+
if i + size > n:
|
|
104
|
+
return
|
|
105
|
+
yield status, data[i + 1], data[i + 2] if size == 3 else 0
|
|
106
|
+
i += size
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def read(status, d1, d2):
|
|
110
|
+
"""``(msg, press)``: what a message is, as a slot stores it, and whether
|
|
111
|
+
it is a switch going down (True), coming up (False), or neither (None,
|
|
112
|
+
and ``msg`` None)."""
|
|
113
|
+
kind = status & 0xF0
|
|
114
|
+
ch = status & 0x0F
|
|
115
|
+
if kind == 0xB0:
|
|
116
|
+
return [CC, ch, d1], d2 >= 64
|
|
117
|
+
if kind == 0x90:
|
|
118
|
+
return [NOTE, ch, d1], d2 > 0
|
|
119
|
+
if kind == 0x80:
|
|
120
|
+
return [NOTE, ch, d1], False
|
|
121
|
+
if kind == 0xC0:
|
|
122
|
+
return [PC, ch, d1], True
|
|
123
|
+
return None, None
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class TapTempo:
|
|
127
|
+
"""A tempo from taps: the average of the last few gaps between them.
|
|
128
|
+
|
|
129
|
+
A gap longer than ``reset_ms`` starts again, so the first tap after a
|
|
130
|
+
pause is the first of a new count.
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
def __init__(self, reset_ms=2000, keep=4, lo=40.0, hi=240.0):
|
|
134
|
+
self.reset_ms = reset_ms
|
|
135
|
+
self.keep = keep
|
|
136
|
+
self.lo = lo
|
|
137
|
+
self.hi = hi
|
|
138
|
+
self.taps = []
|
|
139
|
+
|
|
140
|
+
def tap(self, now):
|
|
141
|
+
"""A tap at ``now`` (ms). Returns the tempo in BPM once two taps
|
|
142
|
+
are close enough, else None."""
|
|
143
|
+
if self.taps and ticks_diff(now, self.taps[-1]) > self.reset_ms:
|
|
144
|
+
self.taps = []
|
|
145
|
+
self.taps.append(now)
|
|
146
|
+
self.taps = self.taps[-(self.keep + 1):]
|
|
147
|
+
if len(self.taps) < 2:
|
|
148
|
+
return None
|
|
149
|
+
span = ticks_diff(self.taps[-1], self.taps[0]) / (len(self.taps) - 1)
|
|
150
|
+
if span <= 0:
|
|
151
|
+
return None
|
|
152
|
+
return max(self.lo, min(self.hi, round(60000.0 / span, 1)))
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class MidiPedal:
|
|
156
|
+
"""Four learned switches, each a pedal or an action.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
slots: the saved map (`saved`), or None for `DEFAULT`.
|
|
160
|
+
on_pedal: ``on_pedal(which, down)`` when a pedal-bound switch moves.
|
|
161
|
+
on_action: ``on_action(name)`` when an action-bound switch is pressed.
|
|
162
|
+
on_change: ``on_change()`` when a slot is learned or bound.
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
def __init__(self, slots=None, on_pedal=None, on_action=None, on_change=None):
|
|
166
|
+
self.slots = new_slots()
|
|
167
|
+
if slots:
|
|
168
|
+
for i, s in enumerate(slots[:SLOTS]):
|
|
169
|
+
msg = s.get("msg")
|
|
170
|
+
bind = s.get("bind")
|
|
171
|
+
self.slots[i] = {"msg": list(msg) if msg else None,
|
|
172
|
+
"bind": bind if bind in BINDINGS else DEFAULT[i]}
|
|
173
|
+
self.on_pedal = on_pedal
|
|
174
|
+
self.on_action = on_action
|
|
175
|
+
self.on_change = on_change
|
|
176
|
+
#: The slot waiting for a switch, or None.
|
|
177
|
+
self.learning = None
|
|
178
|
+
#: The last message read, as `describe_msg` says it, for a screen.
|
|
179
|
+
self.last = ""
|
|
180
|
+
self.down = [False] * SLOTS
|
|
181
|
+
self._buf = bytearray(64)
|
|
182
|
+
|
|
183
|
+
# -- the map ------------------------------------------------------------------
|
|
184
|
+
|
|
185
|
+
def learn(self, i):
|
|
186
|
+
"""Fill slot ``i`` from the next switch pressed; None (or -1) stops."""
|
|
187
|
+
self.learning = i if i is not None and 0 <= i < SLOTS else None
|
|
188
|
+
self._changed()
|
|
189
|
+
|
|
190
|
+
def bind(self, i, binding):
|
|
191
|
+
"""Bind slot ``i`` to one of `BINDINGS`.
|
|
192
|
+
|
|
193
|
+
Raises:
|
|
194
|
+
ValueError: ``binding`` isn't one, or it is a pedal and the
|
|
195
|
+
slot's switch sends a program change, which has no release.
|
|
196
|
+
"""
|
|
197
|
+
if binding not in BINDINGS:
|
|
198
|
+
raise ValueError("bind a switch to one of %s, not %r" % (", ".join(BINDINGS), binding))
|
|
199
|
+
if binding in PEDALS and not can_pedal(self.slots[i]["msg"]):
|
|
200
|
+
raise ValueError("a program change never says the switch came up: bind it to an action")
|
|
201
|
+
self._let_go(i)
|
|
202
|
+
self.slots[i]["bind"] = binding
|
|
203
|
+
self._changed()
|
|
204
|
+
|
|
205
|
+
def clear(self, i):
|
|
206
|
+
"""Forget slot ``i``'s message."""
|
|
207
|
+
self._let_go(i)
|
|
208
|
+
self.slots[i]["msg"] = None
|
|
209
|
+
self._changed()
|
|
210
|
+
|
|
211
|
+
def saved(self):
|
|
212
|
+
"""The map, as settings keep it."""
|
|
213
|
+
return [{"msg": s["msg"], "bind": s["bind"]} for s in self.slots]
|
|
214
|
+
|
|
215
|
+
def describe(self):
|
|
216
|
+
"""The map and what can be chosen, for a panel."""
|
|
217
|
+
return {"slots": self.saved(), "learning": -1 if self.learning is None else self.learning,
|
|
218
|
+
"bindings": [[b, LABELS[b]] for b in BINDINGS], "last": self.last}
|
|
219
|
+
|
|
220
|
+
def _changed(self):
|
|
221
|
+
if self.on_change is not None:
|
|
222
|
+
self.on_change()
|
|
223
|
+
|
|
224
|
+
def _let_go(self, i):
|
|
225
|
+
"""A pedal that is down when its slot changes comes up, so it never sticks."""
|
|
226
|
+
if self.down[i]:
|
|
227
|
+
self.down[i] = False
|
|
228
|
+
which = PEDALS.get(self.slots[i]["bind"])
|
|
229
|
+
if which is not None and self.on_pedal is not None:
|
|
230
|
+
self.on_pedal(which, False)
|
|
231
|
+
|
|
232
|
+
# -- what arrives ---------------------------------------------------------------
|
|
233
|
+
|
|
234
|
+
def read_port(self, port):
|
|
235
|
+
"""Everything waiting on a midiports input. Returns how many bytes."""
|
|
236
|
+
got = 0
|
|
237
|
+
buf = self._buf
|
|
238
|
+
while port.any():
|
|
239
|
+
n = port.readinto(buf)
|
|
240
|
+
if not n:
|
|
241
|
+
break
|
|
242
|
+
got += n
|
|
243
|
+
self.feed(memoryview(buf)[:n])
|
|
244
|
+
return got
|
|
245
|
+
|
|
246
|
+
def feed(self, data):
|
|
247
|
+
"""Act on the MIDI bytes in ``data``."""
|
|
248
|
+
for status, d1, d2 in messages(data):
|
|
249
|
+
self.handle(status, d1, d2)
|
|
250
|
+
|
|
251
|
+
def handle(self, status, d1, d2):
|
|
252
|
+
"""Act on one channel message. Returns the slot it moved, or None."""
|
|
253
|
+
msg, press = read(status, d1, d2)
|
|
254
|
+
if msg is None:
|
|
255
|
+
return None
|
|
256
|
+
self.last = describe_msg(msg)
|
|
257
|
+
if self.learning is not None:
|
|
258
|
+
if not press:
|
|
259
|
+
return None # the foot coming up from before the slot was armed
|
|
260
|
+
return self._learn(msg)
|
|
261
|
+
for i, s in enumerate(self.slots):
|
|
262
|
+
if s["msg"] == msg:
|
|
263
|
+
self._act(i, s, press)
|
|
264
|
+
return i
|
|
265
|
+
return None
|
|
266
|
+
|
|
267
|
+
def _learn(self, msg):
|
|
268
|
+
i = self.learning
|
|
269
|
+
self.learning = None
|
|
270
|
+
for j, s in enumerate(self.slots):
|
|
271
|
+
if j != i and s["msg"] == msg: # one switch, one slot
|
|
272
|
+
self._let_go(j)
|
|
273
|
+
s["msg"] = None
|
|
274
|
+
self._let_go(i)
|
|
275
|
+
slot = self.slots[i]
|
|
276
|
+
slot["msg"] = msg
|
|
277
|
+
if slot["bind"] in PEDALS and not can_pedal(msg):
|
|
278
|
+
slot["bind"] = ONE_SHOT
|
|
279
|
+
self._changed()
|
|
280
|
+
return i
|
|
281
|
+
|
|
282
|
+
def _act(self, i, slot, press):
|
|
283
|
+
bind = slot["bind"]
|
|
284
|
+
which = PEDALS.get(bind)
|
|
285
|
+
if which is not None:
|
|
286
|
+
if press == self.down[i]:
|
|
287
|
+
return # a repeat of where the switch already is
|
|
288
|
+
self.down[i] = press
|
|
289
|
+
if self.on_pedal is not None:
|
|
290
|
+
self.on_pedal(which, press)
|
|
291
|
+
return
|
|
292
|
+
if press and bind != "none" and self.on_action is not None:
|
|
293
|
+
self.on_action(bind)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def open_input(prefs=None, spec=None):
|
|
297
|
+
"""The MIDI input Backline reads its switches from, or None for none.
|
|
298
|
+
|
|
299
|
+
``spec``, else ``prefs["midi_in"]``, else ``$BACKLINE_MIDI``, as
|
|
300
|
+
``KIND`` or ``KIND:NAME``:
|
|
301
|
+
|
|
302
|
+
- ``picker``: whatever MIDI inputs the device picker has chosen
|
|
303
|
+
(endpointkit's ``midi.in``), read as one.
|
|
304
|
+
- ``windows:NAME`` or ``linux:NAME``: a computer's MIDI port whose name
|
|
305
|
+
holds NAME, such as a foot controller paired over Bluetooth or plugged
|
|
306
|
+
in over USB.
|
|
307
|
+
- ``usb_host``: every USB MIDI device plugged into the board.
|
|
308
|
+
- ``usb_device``: the board as a USB MIDI device, played from a computer.
|
|
309
|
+
- ``ble:NAME``: the board advertises Bluetooth LE MIDI as NAME, and a
|
|
310
|
+
phone, a computer or a controller that connects plays it.
|
|
311
|
+
- ``uart:ID:RX``: 5-pin DIN or TRS MIDI on UART ``ID``, pin ``RX``.
|
|
312
|
+
|
|
313
|
+
Raises:
|
|
314
|
+
ValueError: The kind isn't one of these.
|
|
315
|
+
ImportError: midiports, or what the kind needs, isn't installed.
|
|
316
|
+
OSError: No port of that name.
|
|
317
|
+
"""
|
|
318
|
+
if spec is None and prefs is not None:
|
|
319
|
+
spec = prefs.get("midi_in")
|
|
320
|
+
if spec is None:
|
|
321
|
+
import os
|
|
322
|
+
|
|
323
|
+
getenv = getattr(os, "getenv", None)
|
|
324
|
+
spec = getenv("BACKLINE_MIDI") if getenv is not None else None
|
|
325
|
+
if not spec:
|
|
326
|
+
return None
|
|
327
|
+
kind, _, name = spec.partition(":")
|
|
328
|
+
if kind == "picker":
|
|
329
|
+
from midiports import endpoints
|
|
330
|
+
|
|
331
|
+
endpoints.register()
|
|
332
|
+
return endpoints.merged_in()
|
|
333
|
+
if kind == "windows":
|
|
334
|
+
from midiports import windows as host
|
|
335
|
+
elif kind == "linux":
|
|
336
|
+
from midiports import linux as host
|
|
337
|
+
else:
|
|
338
|
+
host = None
|
|
339
|
+
if host is not None:
|
|
340
|
+
midi_in, _out = host.ports(name)
|
|
341
|
+
if midi_in is None:
|
|
342
|
+
raise OSError("no MIDI input named %r" % (name,))
|
|
343
|
+
return midi_in
|
|
344
|
+
if kind == "usb_host":
|
|
345
|
+
from midiports import usb_host
|
|
346
|
+
|
|
347
|
+
return usb_host.all_ports()[0]
|
|
348
|
+
if kind == "usb_device":
|
|
349
|
+
from midiports import usb_device
|
|
350
|
+
|
|
351
|
+
return usb_device.ports()[0]
|
|
352
|
+
if kind == "ble":
|
|
353
|
+
from midiports import ble
|
|
354
|
+
|
|
355
|
+
return ble.ports(name or "Backline")[0]
|
|
356
|
+
if kind == "uart":
|
|
357
|
+
from midiports import uart
|
|
358
|
+
|
|
359
|
+
uid, _, rx = name.partition(":")
|
|
360
|
+
return uart.ports(int(uid), rx=int(rx))[0]
|
|
361
|
+
raise ValueError("MIDI in from picker, windows:NAME, linux:NAME, usb_host, usb_device, ble:NAME or uart:ID:RX, "
|
|
362
|
+
"not %r" % (spec,))
|