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,331 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""Switch the pedals from a MIDI foot controller.
|
|
6
|
+
|
|
7
|
+
Each of the board's four pedals has a switch. Learn one with
|
|
8
|
+
`Switches.learn` and press it on the controller: whatever it sends, a
|
|
9
|
+
controller change, a note or a program change, is that pedal's switch from
|
|
10
|
+
then on. A press switches the pedal on or off. Until you learn any, the
|
|
11
|
+
switches are program changes 0 to 3 on channel 1, which is what many
|
|
12
|
+
four-switch controllers send out of the box.
|
|
13
|
+
|
|
14
|
+
A switch that sends a controller change works either way a controller sets
|
|
15
|
+
it: momentary (127 down, 0 up on every press) or latching (127 on one press,
|
|
16
|
+
0 on the next). A value that comes back down within `RELEASE_MS` of going up
|
|
17
|
+
is a foot coming up, and is ignored; anything else is a press.
|
|
18
|
+
|
|
19
|
+
`open_input` finds the MIDI input: the one named, else the ones chosen in the
|
|
20
|
+
device picker, else every input the computer, the board's USB host or the
|
|
21
|
+
browser has.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import sys
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
from time import ticks_diff, ticks_ms
|
|
30
|
+
except ImportError: # CPython
|
|
31
|
+
from time import monotonic
|
|
32
|
+
|
|
33
|
+
def ticks_ms():
|
|
34
|
+
return int(monotonic() * 1000)
|
|
35
|
+
|
|
36
|
+
def ticks_diff(a, b):
|
|
37
|
+
return a - b
|
|
38
|
+
|
|
39
|
+
SLOTS = 4
|
|
40
|
+
#: A controller value that drops back within this long is a release.
|
|
41
|
+
RELEASE_MS = 600
|
|
42
|
+
|
|
43
|
+
CC = "cc"
|
|
44
|
+
NOTE = "note"
|
|
45
|
+
PC = "pc"
|
|
46
|
+
|
|
47
|
+
BROWSERS = ("webassembly", "emscripten")
|
|
48
|
+
|
|
49
|
+
#: The switches before any are learned: program changes 0 to 3, channel 1.
|
|
50
|
+
DEFAULT = [[PC, 0, i] for i in range(SLOTS)]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def messages(data):
|
|
54
|
+
"""``(status, data1, data2)`` for each channel message in ``data``;
|
|
55
|
+
system messages (clock, SysEx) and stray data bytes are skipped."""
|
|
56
|
+
i = 0
|
|
57
|
+
n = len(data)
|
|
58
|
+
while i < n:
|
|
59
|
+
status = data[i]
|
|
60
|
+
if status < 0x80:
|
|
61
|
+
i += 1
|
|
62
|
+
continue
|
|
63
|
+
if status >= 0xF0:
|
|
64
|
+
if status == 0xF0:
|
|
65
|
+
while i < n and data[i] != 0xF7:
|
|
66
|
+
i += 1
|
|
67
|
+
elif status in (0xF1, 0xF3):
|
|
68
|
+
i += 1
|
|
69
|
+
elif status == 0xF2:
|
|
70
|
+
i += 2
|
|
71
|
+
i += 1
|
|
72
|
+
continue
|
|
73
|
+
size = 2 if (status & 0xE0) == 0xC0 else 3
|
|
74
|
+
if i + size > n:
|
|
75
|
+
return
|
|
76
|
+
yield status, data[i + 1], data[i + 2] if size == 3 else 0
|
|
77
|
+
i += size
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def read(status, d1, d2):
|
|
81
|
+
"""``(msg, value)``: the switch a message is from, as a slot stores it,
|
|
82
|
+
and its value (127 for a program change, 0 for a note off). ``msg`` is
|
|
83
|
+
None for anything a switch doesn't send."""
|
|
84
|
+
kind = status & 0xF0
|
|
85
|
+
ch = status & 0x0F
|
|
86
|
+
if kind == 0xB0:
|
|
87
|
+
return [CC, ch, d1], d2
|
|
88
|
+
if kind == 0x90:
|
|
89
|
+
return [NOTE, ch, d1], d2
|
|
90
|
+
if kind == 0x80:
|
|
91
|
+
return [NOTE, ch, d1], 0
|
|
92
|
+
if kind == 0xC0:
|
|
93
|
+
return [PC, ch, d1], 127
|
|
94
|
+
return None, None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def describe(msg):
|
|
98
|
+
"""``"CC 20 ch 1"``, ``"Note 36 ch 10"``, ``"PC 3 ch 1"``, or ``"-"``."""
|
|
99
|
+
if not msg:
|
|
100
|
+
return "-"
|
|
101
|
+
kind, ch, num = msg
|
|
102
|
+
return "%s %d ch %d" % ({CC: "CC", NOTE: "Note", PC: "PC"}.get(kind, kind), num, ch + 1)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class Switches:
|
|
106
|
+
"""Four learned switches, one per pedal.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
on_press: ``on_press(slot)`` when the switch for pedal *slot* is
|
|
110
|
+
pressed.
|
|
111
|
+
on_learn: ``on_learn(slot, msg)`` when a switch is learned, and
|
|
112
|
+
``on_learn(next_slot, None)`` when learning moves on.
|
|
113
|
+
path: the file the map is kept in, or None not to keep it.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
def __init__(self, on_press=None, on_learn=None, path=None):
|
|
117
|
+
self.on_press = on_press
|
|
118
|
+
self.on_learn = on_learn
|
|
119
|
+
self.path = path
|
|
120
|
+
self.slots = [list(m) if m else None for m in DEFAULT]
|
|
121
|
+
#: The slot waiting for a switch, or None.
|
|
122
|
+
self.learning = None
|
|
123
|
+
#: Learning walks on to the next slot until this one is learned.
|
|
124
|
+
self._learn_to = None
|
|
125
|
+
#: The last message read, as `describe` says it.
|
|
126
|
+
self.last = ""
|
|
127
|
+
self._up_at = [None] * SLOTS
|
|
128
|
+
self._buf = bytearray(64)
|
|
129
|
+
self.load()
|
|
130
|
+
|
|
131
|
+
# -- the map -----------------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
def load(self):
|
|
134
|
+
if self.path is None:
|
|
135
|
+
return
|
|
136
|
+
try:
|
|
137
|
+
with open(self.path) as f:
|
|
138
|
+
saved = json.load(f)
|
|
139
|
+
except (OSError, ValueError):
|
|
140
|
+
return
|
|
141
|
+
kept = saved.get("switches", [])[:SLOTS]
|
|
142
|
+
kept += [None] * (SLOTS - len(kept))
|
|
143
|
+
self.slots = [list(msg) if msg else None for msg in kept]
|
|
144
|
+
|
|
145
|
+
def save(self):
|
|
146
|
+
if self.path is None:
|
|
147
|
+
return
|
|
148
|
+
try:
|
|
149
|
+
with open(self.path, "w") as f:
|
|
150
|
+
json.dump({"switches": self.slots}, f)
|
|
151
|
+
except OSError as e:
|
|
152
|
+
print("stompbox: couldn't keep the MIDI switches:", e)
|
|
153
|
+
|
|
154
|
+
def learn(self, first=0, last=SLOTS - 1):
|
|
155
|
+
"""Learn the switches for pedals *first* to *last*, one press each,
|
|
156
|
+
in order. ``learn(None)`` stops."""
|
|
157
|
+
if first is None:
|
|
158
|
+
self.learning = self._learn_to = None
|
|
159
|
+
return
|
|
160
|
+
self.learning = first
|
|
161
|
+
self._learn_to = last
|
|
162
|
+
if self.on_learn is not None:
|
|
163
|
+
self.on_learn(first, None)
|
|
164
|
+
|
|
165
|
+
def learned(self):
|
|
166
|
+
return sum(1 for s in self.slots if s)
|
|
167
|
+
|
|
168
|
+
# -- what arrives -------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
def read_port(self, port):
|
|
171
|
+
"""Everything waiting on a midiports input; how many bytes."""
|
|
172
|
+
got = 0
|
|
173
|
+
buf = self._buf
|
|
174
|
+
while port.any():
|
|
175
|
+
n = port.readinto(buf)
|
|
176
|
+
if not n:
|
|
177
|
+
break
|
|
178
|
+
got += n
|
|
179
|
+
self.feed(memoryview(buf)[:n])
|
|
180
|
+
return got
|
|
181
|
+
|
|
182
|
+
def feed(self, data, now=None):
|
|
183
|
+
for status, d1, d2 in messages(data):
|
|
184
|
+
self.handle(status, d1, d2, now)
|
|
185
|
+
|
|
186
|
+
def handle(self, status, d1, d2, now=None):
|
|
187
|
+
"""Act on one message. Returns the slot it pressed or learned, or None."""
|
|
188
|
+
msg, value = read(status, d1, d2)
|
|
189
|
+
if msg is None:
|
|
190
|
+
return None
|
|
191
|
+
self.last = describe(msg)
|
|
192
|
+
now = ticks_ms() if now is None else now
|
|
193
|
+
if self.learning is not None:
|
|
194
|
+
if value < 64:
|
|
195
|
+
return None # a foot coming up from before
|
|
196
|
+
return self._learn(msg, now)
|
|
197
|
+
for i, s in enumerate(self.slots):
|
|
198
|
+
if s == msg:
|
|
199
|
+
if self._is_press(i, msg, value, now):
|
|
200
|
+
if self.on_press is not None:
|
|
201
|
+
self.on_press(i)
|
|
202
|
+
return i
|
|
203
|
+
return None
|
|
204
|
+
return None
|
|
205
|
+
|
|
206
|
+
def _is_press(self, i, msg, value, now):
|
|
207
|
+
if msg[0] == PC:
|
|
208
|
+
return True
|
|
209
|
+
if value >= 64:
|
|
210
|
+
self._up_at[i] = now
|
|
211
|
+
return True
|
|
212
|
+
up = self._up_at[i]
|
|
213
|
+
self._up_at[i] = None
|
|
214
|
+
if msg[0] == NOTE:
|
|
215
|
+
return False # a note off is always the foot coming up
|
|
216
|
+
# A controller back down soon after going up is a momentary switch
|
|
217
|
+
# released; long after, a latching switch pressed again.
|
|
218
|
+
return up is None or ticks_diff(now, up) > RELEASE_MS
|
|
219
|
+
|
|
220
|
+
def _learn(self, msg, now):
|
|
221
|
+
i = self.learning
|
|
222
|
+
for j in range(SLOTS):
|
|
223
|
+
if j != i and self.slots[j] == msg: # one switch, one pedal
|
|
224
|
+
self.slots[j] = None
|
|
225
|
+
self.slots[i] = msg
|
|
226
|
+
self._up_at[i] = now
|
|
227
|
+
if self.on_learn is not None:
|
|
228
|
+
self.on_learn(i, msg)
|
|
229
|
+
if self._learn_to is not None and i < self._learn_to:
|
|
230
|
+
self.learning = i + 1
|
|
231
|
+
if self.on_learn is not None:
|
|
232
|
+
self.on_learn(i + 1, None)
|
|
233
|
+
else:
|
|
234
|
+
self.learning = self._learn_to = None
|
|
235
|
+
self.save()
|
|
236
|
+
return i
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def _getenv(name):
|
|
240
|
+
fn = getattr(os, "getenv", None)
|
|
241
|
+
return (fn(name) or None) if fn is not None else None
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def open_input(spec=None):
|
|
245
|
+
"""``(ports, names)``: the MIDI inputs the switches come in on, or
|
|
246
|
+
``([], "")`` where there are none.
|
|
247
|
+
|
|
248
|
+
*spec*, else ``$STOMPBOX_MIDI``, names one, as ``windows:NAME`` or
|
|
249
|
+
``linux:NAME`` (a computer's port whose name holds NAME), ``usb_host``
|
|
250
|
+
(every USB MIDI device on the board) or ``ble:NAME`` (the board
|
|
251
|
+
advertises Bluetooth LE MIDI as NAME). Without one: the inputs chosen in
|
|
252
|
+
the device picker, else every input there is.
|
|
253
|
+
"""
|
|
254
|
+
spec = spec or _getenv("STOMPBOX_MIDI")
|
|
255
|
+
if spec:
|
|
256
|
+
return _named(spec)
|
|
257
|
+
try:
|
|
258
|
+
import endpointkit
|
|
259
|
+
from midiports import endpoints
|
|
260
|
+
|
|
261
|
+
port = endpoints.merged_in()
|
|
262
|
+
mine = getattr(port, "providers", (port.provider,))
|
|
263
|
+
chosen = [ep for ep in endpointkit.selected("midi.in") if ep.provider in mine]
|
|
264
|
+
if chosen:
|
|
265
|
+
return [port], " + ".join(ep.label for ep in chosen)
|
|
266
|
+
except (ImportError, KeyError, AttributeError, OSError):
|
|
267
|
+
pass
|
|
268
|
+
return _every()
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _named(spec):
|
|
272
|
+
kind, _, name = spec.partition(":")
|
|
273
|
+
if kind in ("windows", "linux"):
|
|
274
|
+
if kind == "windows":
|
|
275
|
+
from midiports import windows as host
|
|
276
|
+
else:
|
|
277
|
+
from midiports import linux as host
|
|
278
|
+
port, out = host.ports(name)
|
|
279
|
+
if out is not None:
|
|
280
|
+
out.close()
|
|
281
|
+
if port is None:
|
|
282
|
+
raise OSError("no MIDI input named %r" % (name,))
|
|
283
|
+
return [port], name
|
|
284
|
+
if kind == "usb_host":
|
|
285
|
+
from midiports import usb_host
|
|
286
|
+
|
|
287
|
+
return list(usb_host.all_ports()), "USB MIDI"
|
|
288
|
+
if kind == "ble":
|
|
289
|
+
from midiports import ble
|
|
290
|
+
|
|
291
|
+
return [ble.ports(name or "Stompbox")[0]], "Bluetooth MIDI"
|
|
292
|
+
raise ValueError("STOMPBOX_MIDI is windows:NAME, linux:NAME, usb_host or ble:NAME, not %r" % (spec,))
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def _every():
|
|
296
|
+
"""Every MIDI input this machine has, opened."""
|
|
297
|
+
if sys.platform in BROWSERS:
|
|
298
|
+
try:
|
|
299
|
+
from midiports import webmidi
|
|
300
|
+
except ImportError:
|
|
301
|
+
return [], ""
|
|
302
|
+
return [webmidi.page_in()], "Web MIDI"
|
|
303
|
+
if sys.platform.startswith("win") or sys.platform.startswith("linux"):
|
|
304
|
+
if sys.platform.startswith("win"):
|
|
305
|
+
from midiports import windows as host
|
|
306
|
+
else:
|
|
307
|
+
from midiports import linux as host
|
|
308
|
+
import midiports
|
|
309
|
+
|
|
310
|
+
ports, names = [], []
|
|
311
|
+
for info in host.available():
|
|
312
|
+
if info.direction not in (midiports.IN, midiports.INOUT):
|
|
313
|
+
continue
|
|
314
|
+
if "loopback" in info.name.lower():
|
|
315
|
+
continue
|
|
316
|
+
try:
|
|
317
|
+
port, out = host.ports(info.name)
|
|
318
|
+
except OSError: # another program has it open
|
|
319
|
+
continue
|
|
320
|
+
if out is not None:
|
|
321
|
+
out.close()
|
|
322
|
+
if port is not None:
|
|
323
|
+
ports.append(port)
|
|
324
|
+
names.append(info.name)
|
|
325
|
+
return ports, " + ".join(names)
|
|
326
|
+
try:
|
|
327
|
+
from midiports import usb_host
|
|
328
|
+
|
|
329
|
+
return list(usb_host.all_ports()), "USB MIDI"
|
|
330
|
+
except (ImportError, OSError, IndexError):
|
|
331
|
+
return [], ""
|