omnipython-applibs 0.1.2__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 (143) hide show
  1. appkit/__init__.py +52 -0
  2. appkit/__init__.pyi +17 -0
  3. appkit/data.py +149 -0
  4. appkit/data.pyi +25 -0
  5. appkit/foreground.py +357 -0
  6. appkit/foreground.pyi +45 -0
  7. appkit/home.py +19 -0
  8. appkit/home.pyi +8 -0
  9. appkit/hover.py +59 -0
  10. appkit/hover.pyi +13 -0
  11. appkit/index.py +199 -0
  12. appkit/index.pyi +30 -0
  13. appkit/launcher.py +1075 -0
  14. appkit/launcher.pyi +96 -0
  15. appkit/manifest.py +75 -0
  16. appkit/manifest.pyi +8 -0
  17. appkit/net.py +167 -0
  18. appkit/net.pyi +34 -0
  19. appkit/places.py +202 -0
  20. appkit/places.pyi +39 -0
  21. appkit/py.typed +0 -0
  22. appkit/scope.py +636 -0
  23. appkit/scope.pyi +110 -0
  24. appkit/shell.py +121 -0
  25. appkit/shell.pyi +32 -0
  26. appkit/worker.py +409 -0
  27. appkit/worker.pyi +83 -0
  28. controlkit/__init__.py +19 -0
  29. controlkit/__init__.pyi +10 -0
  30. controlkit/_draw.py +88 -0
  31. controlkit/_safe.py +29 -0
  32. controlkit/dotmatrix.py +101 -0
  33. controlkit/dotmatrix.pyi +23 -0
  34. controlkit/encoder.py +297 -0
  35. controlkit/encoder.pyi +55 -0
  36. controlkit/font5x7.py +22 -0
  37. controlkit/font5x7.pyi +11 -0
  38. controlkit/lamp_button.py +92 -0
  39. controlkit/lamp_button.pyi +40 -0
  40. controlkit/meter.py +86 -0
  41. controlkit/meter.pyi +30 -0
  42. controlkit/mock.py +116 -0
  43. controlkit/mock.pyi +35 -0
  44. controlkit/pad_grid.py +113 -0
  45. controlkit/pad_grid.pyi +41 -0
  46. controlkit/py.typed +0 -0
  47. controlkit/slider.py +185 -0
  48. controlkit/slider.pyi +49 -0
  49. controlkit/sprites.py +279 -0
  50. controlkit/sprites.pyi +22 -0
  51. controlkit/theme.py +120 -0
  52. controlkit/theme.pyi +15 -0
  53. deskkit/__init__.py +74 -0
  54. deskkit/__init__.pyi +18 -0
  55. deskkit/forecast.py +261 -0
  56. deskkit/forecast.pyi +40 -0
  57. deskkit/localtime.py +215 -0
  58. deskkit/localtime.pyi +33 -0
  59. deskkit/py.typed +0 -0
  60. deskkit/shell.py +113 -0
  61. deskkit/shell.pyi +33 -0
  62. omnipython_applibs-0.1.2.dist-info/METADATA +90 -0
  63. omnipython_applibs-0.1.2.dist-info/RECORD +143 -0
  64. omnipython_applibs-0.1.2.dist-info/WHEEL +5 -0
  65. omnipython_applibs-0.1.2.dist-info/licenses/LICENSE +21 -0
  66. omnipython_applibs-0.1.2.dist-info/top_level.txt +9 -0
  67. programkit/__init__.py +27 -0
  68. programkit/__init__.pyi +8 -0
  69. programkit/board.py +56 -0
  70. programkit/board.pyi +20 -0
  71. programkit/press.py +63 -0
  72. programkit/press.pyi +17 -0
  73. programkit/py.typed +0 -0
  74. programkit/rows.py +149 -0
  75. programkit/rows.pyi +34 -0
  76. sayso/__init__.py +109 -0
  77. sayso/__init__.pyi +124 -0
  78. sayso/auth.py +811 -0
  79. sayso/auth.pyi +102 -0
  80. sayso/client.py +1286 -0
  81. sayso/client.pyi +138 -0
  82. sayso/keepalive.py +371 -0
  83. sayso/keepalive.pyi +53 -0
  84. sayso/local.py +85 -0
  85. sayso/local.pyi +28 -0
  86. sayso/object_specs.py +706 -0
  87. sayso/object_specs.pyi +8 -0
  88. sayso/objects.py +411 -0
  89. sayso/objects.pyi +854 -0
  90. sayso/py.typed +0 -0
  91. sayso/schema_coverage.py +210 -0
  92. sayso/schema_coverage.pyi +13 -0
  93. sayso/transport.py +426 -0
  94. sayso/transport.pyi +47 -0
  95. songmodel/__init__.py +30 -0
  96. songmodel/__init__.pyi +9 -0
  97. songmodel/link.py +189 -0
  98. songmodel/link.pyi +53 -0
  99. songmodel/model.py +238 -0
  100. songmodel/model.pyi +40 -0
  101. songmodel/page.html +225 -0
  102. songmodel/page_data.py +236 -0
  103. songmodel/page_data.pyi +6 -0
  104. songmodel/py.typed +0 -0
  105. soundmodule/__init__.py +7 -0
  106. soundmodule/__init__.pyi +6 -0
  107. soundmodule/engine.py +1001 -0
  108. soundmodule/engine.pyi +196 -0
  109. soundmodule/names.py +298 -0
  110. soundmodule/names.pyi +30 -0
  111. soundmodule/pipes.py +105 -0
  112. soundmodule/pipes.pyi +31 -0
  113. soundmodule/py.typed +0 -0
  114. soundmodule/run.py +249 -0
  115. soundmodule/run.pyi +49 -0
  116. spectrum/__init__.py +72 -0
  117. spectrum/__init__.pyi +30 -0
  118. spectrum/analyzer.py +231 -0
  119. spectrum/analyzer.pyi +67 -0
  120. spectrum/fake_music.py +201 -0
  121. spectrum/fake_music.pyi +36 -0
  122. spectrum/pump_levels.py +126 -0
  123. spectrum/pump_levels.pyi +46 -0
  124. spectrum/py.typed +0 -0
  125. spectrum/spectrum_view.py +403 -0
  126. spectrum/spectrum_view.pyi +80 -0
  127. touchkit/__init__.py +4 -0
  128. touchkit/__init__.pyi +4 -0
  129. touchkit/cam.py +146 -0
  130. touchkit/cam.pyi +35 -0
  131. touchkit/clock.py +18 -0
  132. touchkit/clock.pyi +6 -0
  133. touchkit/ecp.py +134 -0
  134. touchkit/ecp.pyi +28 -0
  135. touchkit/net.py +347 -0
  136. touchkit/net.pyi +27 -0
  137. touchkit/py.typed +0 -0
  138. touchkit/settings.py +85 -0
  139. touchkit/settings.pyi +17 -0
  140. touchkit/shell.py +268 -0
  141. touchkit/shell.pyi +42 -0
  142. touchkit/ui.py +167 -0
  143. touchkit/ui.pyi +53 -0
soundmodule/engine.pyi ADDED
@@ -0,0 +1,196 @@
1
+ # SPDX-FileCopyrightText: 2026 PyDevices
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """The sound module's engine: sixteen parts, one per MIDI channel, mixed through chorus and reverb."""
5
+
6
+ from typing import Any, Callable, ContextManager
7
+
8
+ DRUM_CHANNEL: int
9
+ MELODIC: str
10
+ DRUMS: str
11
+ PERCUSSION_BANK: int
12
+ BANK_INSTRUMENTS: int
13
+ BANK_DRUM_MACHINES: int
14
+ INSTRUMENTS: tuple[str | None, ...]
15
+ DRUM_MACHINES: tuple[str | None, ...]
16
+ CC_BANK_MSB: int
17
+ CC_BANK_LSB: int
18
+ CC_VOLUME: int
19
+ CC_PAN: int
20
+ CC_SUSTAIN: int
21
+ CC_REVERB: int
22
+ CC_CHORUS: int
23
+ CC_ALL_SOUND_OFF: int
24
+ CC_RESET_CONTROLLERS: int
25
+ CC_ALL_NOTES_OFF: int
26
+ CC_MOD_WHEEL: int
27
+ CC_EXPRESSION: int
28
+ CC_DATA_MSB: int
29
+ CC_DATA_LSB: int
30
+ CC_DATA_INC: int
31
+ CC_DATA_DEC: int
32
+ CC_NRPN_LSB: int
33
+ CC_NRPN_MSB: int
34
+ CC_RPN_LSB: int
35
+ CC_RPN_MSB: int
36
+ RPN_BEND_RANGE: tuple[int, int]
37
+ RPN_FINE_TUNING: tuple[int, int]
38
+ RPN_COARSE_TUNING: tuple[int, int]
39
+ RPN_NULL: tuple[int, int]
40
+ RPN_DEFAULTS: dict[tuple[int, int], int]
41
+ MAX_BEND_RANGE: int
42
+ NATIVE_BEND_RANGE: float
43
+ MACRO_CC: int
44
+ MACRO_CCS: int
45
+ MANUFACTURER: int
46
+ FAMILY: int
47
+ MODEL: int
48
+ VERSION: tuple[int, int, int, int]
49
+ DEVICE_ID: int
50
+ DEFAULT_VOLUME: int
51
+ DEFAULT_PAN: int
52
+ DEFAULT_EXPRESSION: int
53
+ VOLUME_MACRO: int
54
+ PAN_MACRO: int
55
+ DEFAULT_REVERB: int
56
+ DEFAULT_CHORUS: int
57
+ DEFAULT_MASTER: int
58
+ VOICES: int
59
+ BOARD: bool
60
+ BOARD_VOICES: int
61
+ RESERVE: int
62
+ GAIN: float
63
+ PART_LEVEL: float
64
+ BEND_CENTER: int
65
+ CACHE_SHARE: int
66
+ FALLBACK_CACHE_BYTES: int
67
+ MIXER_BUFFER: int
68
+ PARTS_MIXER_BUFFER: int
69
+ GM_NAMES: tuple[str, ...]
70
+ GM_KITS: tuple[tuple[int, str], ...]
71
+
72
+ def board_cache_bytes() -> int | None:
73
+ """The bound for the open bank's samples on a board, or None on CPython."""
74
+ def identity_reply(device_id: int = ...) -> bytes:
75
+ """The Identity Reply this module sends, F0 to F7."""
76
+ def deferred(module: Module | None) -> ContextManager[Any]:
77
+ """Queue the voices' writes inside a `with` block and send them together at the end."""
78
+
79
+ class Part:
80
+ """One MIDI channel's state."""
81
+
82
+ channel: int
83
+ inst: Any
84
+ inst_name: str | None
85
+ notes: int
86
+ last: tuple[int, int] | None
87
+ played: dict[tuple[int, int, int], list[Any]]
88
+ program: int
89
+ bank_msb: int
90
+ bank_lsb: int
91
+ volume: int
92
+ expression: int
93
+ pan: int
94
+ sustain: bool
95
+ held: set[int]
96
+ sustained: set[int]
97
+ bend: int
98
+ rpn: tuple[int, int] | None
99
+ params: dict[tuple[int, int], int]
100
+ reverb: int
101
+ chorus: int
102
+ def __init__(self, channel: int) -> None: ...
103
+ def reset(self) -> None: ...
104
+ @property
105
+ def bend_range(self) -> float:
106
+ """Pitch Bend Sensitivity in semitones, cents included."""
107
+ @property
108
+ def tuning(self) -> float:
109
+ """Fine and coarse tuning together, in semitones."""
110
+ @property
111
+ def drums(self) -> bool: ...
112
+ @property
113
+ def gm(self) -> bool:
114
+ """True when the part's bank is General MIDI's."""
115
+
116
+ class Module:
117
+ """Sixteen parts, mixed, with chorus and reverb on the master."""
118
+
119
+ rate: int
120
+ channels: int
121
+ bank: str | None
122
+ send: Callable[[bytes], Any] | None
123
+ parts: list[Part]
124
+ instruments: bool
125
+ voice_pool: Any
126
+ mixer: Any
127
+ chorus: Any
128
+ output: Any
129
+ reverb: Any
130
+ reverb_level: int
131
+ chorus_level: int
132
+ master_level: int
133
+ on_master: Callable[[int], Any] | None
134
+ error: BaseException | None
135
+ loaded: Any
136
+ cache_bytes: int | None
137
+ identities: int
138
+ def __init__(
139
+ self,
140
+ rate: int = 48000,
141
+ channels: int = 2,
142
+ bank: str | None = None,
143
+ create: Callable[..., Any] | None = None,
144
+ mixer: Any = None,
145
+ effects: bool = True,
146
+ kits: list[int] | None = None,
147
+ voices: int | None = None,
148
+ chorus: bool | None = None,
149
+ instruments: bool | None = None,
150
+ send: Callable[[bytes], Any] | None = None,
151
+ ) -> None: ...
152
+ @property
153
+ def voice_count(self) -> int | None:
154
+ """How many engine voices the parts share, or None without a shared pool."""
155
+ @voice_count.setter
156
+ def voice_count(self, count: int) -> None: ...
157
+ def prepare(self) -> Any:
158
+ """Open the bank now, so no part has to; None with the reason in `error`."""
159
+ def wanted(self, part: Part) -> str | None:
160
+ """The instrument the part's bank and program ask for."""
161
+ def instrument(self, part: Part) -> Any:
162
+ """The part's instrument, made on first use; None without one."""
163
+ def kit_index(self, program: int) -> int:
164
+ """The drum instrument's patch for GM drum program `program`."""
165
+ def kit_programs(self) -> list[int]:
166
+ """The GM drum program numbers the bank has kits for, in order."""
167
+ def name(self, channel: int) -> str:
168
+ """What channel `channel` plays."""
169
+ def feed(self, data: bytes | bytearray | memoryview, nbytes: int | None = None) -> None:
170
+ """Parse raw MIDI 1.0 bytes, the first `nbytes` when given."""
171
+ def message(self, status: int, d1: int, d2: int = 0) -> None:
172
+ """One channel message: `status` with its channel, and its data."""
173
+ def sysex(self, data: bytes) -> None:
174
+ """Handle the bytes between F0 and F7."""
175
+ def note_on(self, part: Part, note: int, velocity: int) -> None: ...
176
+ def note_off(self, part: Part, note: int) -> None: ...
177
+ def control(self, part: Part, cc: int, value: int) -> None: ...
178
+ def program(self, part: Part, number: int) -> None: ...
179
+ def bend(self, part: Part, value: int) -> None: ...
180
+ def data_entry(self, part: Part, cc: int, value: int) -> None: ...
181
+ def all_notes_off(self, part: Part) -> None: ...
182
+ def all_sound_off(self, part: Part) -> None: ...
183
+ def reset_controllers(self, part: Part) -> None: ...
184
+ def panic(self) -> None: ...
185
+ def gm_reset(self) -> None: ...
186
+ def set_volume(self, part: Part, value: int) -> None:
187
+ """A volume slider for one channel: the path CC7 takes."""
188
+ def set_pan(self, part: Part, value: int) -> None:
189
+ """A pan slider for one channel: the path CC10 takes."""
190
+ def set_master(self, level: int | float) -> None:
191
+ """The master level, 0-100."""
192
+ def set_reverb(self, level: int) -> None: ...
193
+ def set_chorus(self, level: int) -> None: ...
194
+ def fill(self) -> None:
195
+ """Let the parts' instruments move their notes and knobs on."""
196
+ def close(self) -> None: ...
soundmodule/names.py ADDED
@@ -0,0 +1,298 @@
1
+ # SPDX-FileCopyrightText: 2026 PyDevices
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Patch, note and controller names a DAW can read: a MIDNAM file, a
5
+ Cakewalk instrument definition (``.ins``) and a REAPER bank file
6
+ (``.reabank``) for the sound module.
7
+
8
+ python -m soundmodule.names --out names/
9
+
10
+ Both are built from the catalogs audioinstruments and audioeffects carry
11
+ (``catalog.json`` in each package), so the names match the instruments you
12
+ have installed. ``--instruments`` and ``--effects`` read a catalog from a
13
+ file instead.
14
+
15
+ Every instrument's patches are listed under it, with the Bank Select and
16
+ Program Change that play them on the sound module (bank ``BANK_INSTRUMENTS``
17
+ or ``BANK_DRUM_MACHINES``, the instrument's program, its patch as the LSB),
18
+ and General MIDI's programs are bank 0. A drum machine's patches name its
19
+ keys. The macros are CC 102 to 117: the default mode names them "Macro 0"
20
+ and on, and each instrument has a mode of its own (a ``CustomDeviceMode`` in
21
+ the MIDNAM, an instrument definition in the ``.ins``) that gives them its
22
+ names. CC91 and CC93 are named after the reverb and chorus the module plays.
23
+ """
24
+
25
+ import json
26
+ import sys
27
+
28
+ from . import engine
29
+
30
+ MANUFACTURER = "PyDevices"
31
+ MODEL = "Sound Module"
32
+ #: The CCs every part answers, beside the macros.
33
+ CONTROLS = (
34
+ (1, "Modulation"),
35
+ (7, "Volume"),
36
+ (10, "Pan"),
37
+ (11, "Expression"),
38
+ (64, "Sustain"),
39
+ )
40
+ #: The master effects CC91 and CC93 send to, by their catalog name.
41
+ SENDS = ((engine.CC_REVERB, "Reverb"), (engine.CC_CHORUS, "Chorus"))
42
+
43
+
44
+ def load(path):
45
+ """A catalog read from ``path``."""
46
+ with open(path, encoding="utf-8") as f:
47
+ return json.load(f)
48
+
49
+
50
+ def installed(package):
51
+ """The catalog that the installed ``package`` carries."""
52
+ module = __import__(package)
53
+ folder = module.__file__.replace("\\", "/").rsplit("/", 1)[0]
54
+ try:
55
+ return load(folder + "/catalog.json")
56
+ except OSError:
57
+ raise SystemExit("%s in %s has no catalog.json: install a newer release, or pass its"
58
+ " file with --%s" % (package, folder, package[5:]))
59
+
60
+
61
+ def _by_name(catalog, key):
62
+ return {e["name"]: e for e in catalog[key]}
63
+
64
+
65
+ def parts(instruments):
66
+ """``(bank MSB, program, entry)`` for each instrument the module plays,
67
+ melodic first, in program order."""
68
+ found = _by_name(instruments, "instruments")
69
+ out = []
70
+ for msb, table in ((engine.BANK_INSTRUMENTS, engine.INSTRUMENTS),
71
+ (engine.BANK_DRUM_MACHINES, engine.DRUM_MACHINES)):
72
+ for program, name in enumerate(table):
73
+ if name is None:
74
+ continue
75
+ if name not in found:
76
+ raise ValueError("the catalog has no instrument %r" % name)
77
+ out.append((msb, program, found[name]))
78
+ return out
79
+
80
+
81
+ def controls(effects, macros=None):
82
+ """``(cc, name)`` for every controller: the fixed ones, the two sends and
83
+ the macros, named from ``macros`` (a catalog entry's) where given."""
84
+ found = _by_name(effects, "effects")
85
+ out = list(CONTROLS)
86
+ for cc, name in SENDS:
87
+ if name not in found:
88
+ raise ValueError("the effects catalog has no %r" % name)
89
+ out.append((cc, "%s send" % found[name]["display_name"]))
90
+ labels = [m["label"] for m in macros] if macros else []
91
+ for i in range(engine.MACRO_CCS):
92
+ label = labels[i] if i < len(labels) else "Macro %d" % i
93
+ out.append((engine.MACRO_CC + i, label))
94
+ return sorted(out)
95
+
96
+
97
+ def _xml(text):
98
+ return (str(text).replace("&", "&amp;").replace("<", "&lt;")
99
+ .replace(">", "&gt;").replace('"', "&quot;"))
100
+
101
+
102
+ def midnam(instruments, effects):
103
+ """The MIDNAM document, as text."""
104
+ entries = parts(instruments)
105
+ out = [
106
+ '<?xml version="1.0" encoding="UTF-8"?>',
107
+ '<!DOCTYPE MIDINameDocument PUBLIC "-//MIDI Manufacturers Association//DTD'
108
+ ' MIDINameDocument 1.0//EN" "http://www.midi.org/dtds/MIDINameDocument10.dtd">',
109
+ "<MIDINameDocument>",
110
+ " <Author>%s</Author>" % MANUFACTURER,
111
+ " <MasterDeviceNames>",
112
+ " <Manufacturer>%s</Manufacturer>" % MANUFACTURER,
113
+ " <Model>%s</Model>" % MODEL,
114
+ ]
115
+ modes = [("Default", "All", None)]
116
+ for msb, program, e in entries:
117
+ if e["macros"]:
118
+ modes.append((e["display_name"], e["name"], e))
119
+ for mode, nameset, _ in modes:
120
+ out.append(' <CustomDeviceMode Name="%s">' % _xml(mode))
121
+ out.append(" <ChannelNameSetAssignments>")
122
+ for ch in range(1, 17):
123
+ out.append(' <ChannelNameSetAssign Channel="%d" NameSet="%s"/>'
124
+ % (ch, _xml(nameset)))
125
+ out.append(" </ChannelNameSetAssignments>")
126
+ out.append(" </CustomDeviceMode>")
127
+ for mode, nameset, only in modes:
128
+ out.append(' <ChannelNameSet Name="%s">' % _xml(nameset))
129
+ out.append(" <AvailableForChannels>")
130
+ for ch in range(1, 17):
131
+ out.append(' <AvailableChannel Channel="%d" Available="true"/>' % ch)
132
+ out.append(" </AvailableForChannels>")
133
+ out.append(' <UsesControlNameList Name="%s"/>' % _xml(nameset))
134
+ if only is None:
135
+ out.append(' <PatchBank Name="General MIDI">')
136
+ out.append(" <MIDICommands>")
137
+ out.append(' <ControlChange Control="0" Value="0"/>')
138
+ out.append(' <ControlChange Control="32" Value="0"/>')
139
+ out.append(" </MIDICommands>")
140
+ out.append(" <PatchNameList>")
141
+ for program, name in enumerate(engine.GM_NAMES):
142
+ out.append(' <Patch Number="%d" Name="%s" ProgramChange="%d"/>'
143
+ % (program + 1, _xml(name), program))
144
+ out.append(" </PatchNameList>")
145
+ out.append(" </PatchBank>")
146
+ for msb, program, e in entries:
147
+ if only is not None and e is not only:
148
+ continue
149
+ out.append(' <PatchBank Name="%s">' % _xml(e["display_name"]))
150
+ out.append(" <MIDICommands>")
151
+ out.append(' <ControlChange Control="0" Value="%d"/>' % msb)
152
+ out.append(' <ControlChange Control="32" Value="0"/>')
153
+ out.append(" </MIDICommands>")
154
+ out.append(" <PatchNameList>")
155
+ for p in e["patches"]:
156
+ out.append(' <Patch Number="%d" Name="%s" ProgramChange="%d">'
157
+ % (p["index"] + 1, _xml(p["name"]), program))
158
+ out.append(" <PatchMIDICommands>")
159
+ out.append(' <ControlChange Control="0" Value="%d"/>' % msb)
160
+ out.append(' <ControlChange Control="32" Value="%d"/>' % p["index"])
161
+ out.append(' <ProgramChange Number="%d"/>' % program)
162
+ out.append(" </PatchMIDICommands>")
163
+ if e.get("notes"):
164
+ out.append(' <UsesNoteNameList Name="%s"/>' % _xml(e["name"]))
165
+ out.append(" </Patch>")
166
+ out.append(" </PatchNameList>")
167
+ out.append(" </PatchBank>")
168
+ out.append(" </ChannelNameSet>")
169
+ for msb, program, e in entries:
170
+ if e.get("notes"):
171
+ out.append(' <NoteNameList Name="%s">' % _xml(e["name"]))
172
+ for n in e["notes"]:
173
+ out.append(' <Note Number="%d" Name="%s"/>' % (n["key"], _xml(n["name"])))
174
+ out.append(" </NoteNameList>")
175
+ for mode, nameset, only in modes:
176
+ out.append(' <ControlNameList Name="%s">' % _xml(nameset))
177
+ for cc, name in controls(effects, only["macros"] if only else None):
178
+ out.append(' <Control Type="7bit" Number="%d" Name="%s"/>' % (cc, _xml(name)))
179
+ out.append(" </ControlNameList>")
180
+ out.append(" </MasterDeviceNames>")
181
+ out.append("</MIDINameDocument>")
182
+ return "\n".join(out) + "\n"
183
+
184
+
185
+ def cakewalk_ins(instruments, effects):
186
+ """The Cakewalk instrument definition file, as text.
187
+
188
+ An ``.ins`` bank is one MSB and LSB, so the module's patches are listed a
189
+ bank per patch number: bank 80/k holds patch k of each instrument, at the
190
+ instrument's program.
191
+ """
192
+ entries = parts(instruments)
193
+ title = "%s %s" % (MANUFACTURER, MODEL)
194
+ out = ["; %s: patch, key and controller names." % title, "", ".Patch Names", ""]
195
+ out.append("[%s General MIDI]" % MODEL)
196
+ out += ["%d=%s" % (i, name) for i, name in enumerate(engine.GM_NAMES)]
197
+ out.append("")
198
+ banks = []
199
+ for msb in (engine.BANK_INSTRUMENTS, engine.BANK_DRUM_MACHINES):
200
+ group = [(program, e) for m, program, e in entries if m == msb]
201
+ most = max(len(e["patches"]) for _, e in group)
202
+ kind = "Instruments" if msb == engine.BANK_INSTRUMENTS else "Drum Machines"
203
+ for lsb in range(most):
204
+ name = "%s %s, patch %d" % (MODEL, kind, lsb + 1)
205
+ banks.append((msb * 128 + lsb, name, msb))
206
+ out.append("[%s]" % name)
207
+ for program, e in group:
208
+ for p in e["patches"]:
209
+ if p["index"] == lsb:
210
+ out.append("%d=%s: %s" % (program, e["display_name"], p["name"]))
211
+ out.append("")
212
+ out += [".Note Names", ""]
213
+ for _, _, e in entries:
214
+ if e.get("notes"):
215
+ out.append("[%s]" % e["display_name"])
216
+ out += ["%d=%s" % (n["key"], n["name"]) for n in e["notes"]]
217
+ out.append("")
218
+ out += [".Controller Names", ""]
219
+ defs = [(title, MODEL, None)]
220
+ for _, _, e in entries:
221
+ if e["macros"]:
222
+ defs.append(("%s: %s" % (title, e["display_name"]),
223
+ "%s %s" % (MODEL, e["display_name"]), e))
224
+ for _, control, e in defs:
225
+ out.append("[%s]" % control)
226
+ out += ["%d=%s" % (cc, name) for cc, name in controls(effects, e["macros"] if e else None)]
227
+ out.append("")
228
+ out += [".Instrument Definitions", ""]
229
+ for definition, control, _ in defs:
230
+ out.append("[%s]" % definition)
231
+ out.append("Control=%s" % control)
232
+ out.append("BankSelMethod=0")
233
+ out.append("Patch[0]=%s General MIDI" % MODEL)
234
+ for bank, name, _ in banks:
235
+ out.append("Patch[%d]=%s" % (bank, name))
236
+ for msb, program, e in entries:
237
+ if e.get("notes"):
238
+ for bank, _, bank_msb in banks:
239
+ if bank_msb == msb:
240
+ out.append("Key[%d,%d]=%s" % (bank, program, e["display_name"]))
241
+ out.append("Drum[%d,%d]=1" % (bank, program))
242
+ out.append("")
243
+ return "\n".join(out)
244
+
245
+
246
+ def reabank(instruments):
247
+ """The REAPER bank/program file, as text: the patch names only.
248
+
249
+ REAPER reads this format, not MIDNAM or ``.ins``. Bank 0 is General MIDI;
250
+ each other bank is one MSB and LSB, as in `cakewalk_ins`.
251
+ """
252
+ entries = parts(instruments)
253
+ out = ["Bank 0 0 %s General MIDI" % MODEL]
254
+ out += ["%d %s" % (i, name) for i, name in enumerate(engine.GM_NAMES)]
255
+ for msb in (engine.BANK_INSTRUMENTS, engine.BANK_DRUM_MACHINES):
256
+ group = [(program, e) for m, program, e in entries if m == msb]
257
+ kind = "Instruments" if msb == engine.BANK_INSTRUMENTS else "Drum Machines"
258
+ for lsb in range(max(len(e["patches"]) for _, e in group)):
259
+ out.append("Bank %d %d %s %s, patch %d" % (msb, lsb, MODEL, kind, lsb + 1))
260
+ for program, e in group:
261
+ for p in e["patches"]:
262
+ if p["index"] == lsb:
263
+ out.append("%d %s: %s" % (program, e["display_name"], p["name"]))
264
+ return "\n".join(out) + "\n"
265
+
266
+
267
+ def main(argv):
268
+ folder = "."
269
+ instruments = effects = None
270
+ i = 1
271
+ while i < len(argv):
272
+ if argv[i] == "--out":
273
+ folder = argv[i + 1]
274
+ elif argv[i] == "--instruments":
275
+ instruments = load(argv[i + 1])
276
+ elif argv[i] == "--effects":
277
+ effects = load(argv[i + 1])
278
+ else:
279
+ print(__doc__)
280
+ return 2
281
+ i += 2
282
+ instruments = instruments or installed("audioinstruments")
283
+ effects = effects or installed("audioeffects")
284
+ import os
285
+
286
+ os.makedirs(folder, exist_ok=True)
287
+ for filename, text in (("PyDevices Sound Module.midnam", midnam(instruments, effects)),
288
+ ("PyDevices Sound Module.ins", cakewalk_ins(instruments, effects)),
289
+ ("PyDevices Sound Module.reabank", reabank(instruments))):
290
+ path = folder.rstrip("/") + "/" + filename
291
+ with open(path, "w", encoding="utf-8") as f:
292
+ f.write(text)
293
+ print(path)
294
+ return 0
295
+
296
+
297
+ if __name__ == "__main__":
298
+ sys.exit(main(sys.argv))
soundmodule/names.pyi ADDED
@@ -0,0 +1,30 @@
1
+ # SPDX-FileCopyrightText: 2026 PyDevices
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Patch, note and controller names a DAW can read, for the sound module."""
5
+
6
+ from typing import Any
7
+
8
+ _Catalog = dict[str, Any]
9
+ _Entry = dict[str, Any]
10
+
11
+ MANUFACTURER: str
12
+ MODEL: str
13
+ CONTROLS: tuple[tuple[int, str], ...]
14
+ SENDS: tuple[tuple[int, str], ...]
15
+
16
+ def load(path: str) -> _Catalog:
17
+ """A catalog read from `path`."""
18
+ def installed(package: str) -> _Catalog:
19
+ """The catalog that the installed `package` carries."""
20
+ def parts(instruments: _Catalog) -> list[tuple[int, int, _Entry]]:
21
+ """`(bank MSB, program, entry)` for each instrument the module plays."""
22
+ def controls(effects: _Catalog, macros: list[dict[str, Any]] | None = None) -> list[tuple[int, str]]:
23
+ """`(cc, name)` for every controller."""
24
+ def midnam(instruments: _Catalog, effects: _Catalog) -> str:
25
+ """The MIDNAM document, as text."""
26
+ def cakewalk_ins(instruments: _Catalog, effects: _Catalog) -> str:
27
+ """The Cakewalk instrument definition file, as text."""
28
+ def reabank(instruments: _Catalog) -> str:
29
+ """The REAPER bank/program file, as text."""
30
+ def main(argv: list[str]) -> int: ...
soundmodule/pipes.py ADDED
@@ -0,0 +1,105 @@
1
+ # SPDX-FileCopyrightText: 2026 PyDevices
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """MIDI through two files, for an interpreter that can't open the MIDI port
5
+ itself: MicroPython's and CircuitPython's unix ports under WSL, which see
6
+ no Windows MIDI port and have no ALSA one to open.
7
+
8
+ ``tools/bridge.py``, on the Windows side, appends what a Windows MIDI port
9
+ receives to ``<folder>/in.mid`` and sends what is appended to
10
+ ``<folder>/out.mid``. The module reads one file and appends to the other,
11
+ through ports with midiports' contract (``read``, ``readinto``, ``any``
12
+ and ``write``), so the rest of the module can't tell.
13
+
14
+ A read at the end of the file returns nothing and leaves the file open;
15
+ bytes appended later are read on a later call. Nothing here blocks.
16
+ """
17
+
18
+ IN = "in.mid"
19
+ OUT = "out.mid"
20
+
21
+
22
+ def _count(buf, nbytes):
23
+ n = len(buf)
24
+ return n if nbytes is None or nbytes > n else nbytes
25
+
26
+
27
+ class FileIn:
28
+ """The bytes appended to a file, as a MIDI input port."""
29
+
30
+ def __init__(self, path, size=256):
31
+ open(path, "ab").close() # there, and empty if new
32
+ try:
33
+ self._f = open(path, "rb", buffering=0) # CPython: no read-ahead past what is there
34
+ except TypeError:
35
+ self._f = open(path, "rb")
36
+ self._scratch = bytearray(size)
37
+ self._pending = 0
38
+
39
+ def any(self):
40
+ """Bytes read ahead and not yet taken: a peek reads up to the scratch's size."""
41
+ if not self._pending:
42
+ n = self._f.readinto(self._scratch)
43
+ self._pending = n or 0
44
+ return self._pending
45
+
46
+ def readinto(self, buf, nbytes=None):
47
+ want = _count(buf, nbytes)
48
+ got = 0
49
+ if self._pending:
50
+ n = min(want, self._pending)
51
+ for i in range(n):
52
+ buf[i] = self._scratch[i]
53
+ rest = self._pending - n
54
+ for i in range(rest):
55
+ self._scratch[i] = self._scratch[n + i]
56
+ self._pending = rest
57
+ got = n
58
+ if got < want:
59
+ if got:
60
+ view = memoryview(buf)[got:want]
61
+ n = self._f.readinto(view)
62
+ elif want == len(buf):
63
+ n = self._f.readinto(buf)
64
+ else:
65
+ n = self._f.readinto(memoryview(buf)[:want])
66
+ got += n or 0
67
+ return got or None
68
+
69
+ def read(self, nbytes=None):
70
+ buf = bytearray(_count(self._scratch, nbytes))
71
+ n = self.readinto(buf)
72
+ return bytes(buf[:n]) if n else None
73
+
74
+ def close(self):
75
+ if self._f is not None:
76
+ self._f.close()
77
+ self._f = None
78
+
79
+ deinit = close
80
+
81
+
82
+ class FileOut:
83
+ """A MIDI output port that appends to a file."""
84
+
85
+ def __init__(self, path):
86
+ self._f = open(path, "ab")
87
+
88
+ def write(self, buf, nbytes=None):
89
+ n = _count(buf, nbytes)
90
+ self._f.write(bytes(buf[:n]) if n != len(buf) else buf)
91
+ self._f.flush()
92
+ return n
93
+
94
+ def close(self):
95
+ if self._f is not None:
96
+ self._f.close()
97
+ self._f = None
98
+
99
+ deinit = close
100
+
101
+
102
+ def ports(folder):
103
+ """``(midi_in, midi_out)`` through ``folder``'s two files."""
104
+ folder = folder.rstrip("/")
105
+ return FileIn(folder + "/" + IN), FileOut(folder + "/" + OUT)
soundmodule/pipes.pyi ADDED
@@ -0,0 +1,31 @@
1
+ # SPDX-FileCopyrightText: 2026 PyDevices
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """MIDI through two files, for an interpreter that can't open the MIDI port itself."""
5
+
6
+ from typing import Any
7
+
8
+ IN: str
9
+ OUT: str
10
+
11
+ class FileIn:
12
+ """The bytes appended to a file, as a MIDI input port."""
13
+
14
+ def __init__(self, path: str, size: int = 256) -> None: ...
15
+ def any(self) -> int:
16
+ """Bytes read ahead and not yet taken."""
17
+ def readinto(self, buf: bytearray | memoryview, nbytes: int | None = None) -> int | None: ...
18
+ def read(self, nbytes: int | None = None) -> bytes | None: ...
19
+ def close(self) -> None: ...
20
+ def deinit(self) -> None: ...
21
+
22
+ class FileOut:
23
+ """A MIDI output port that appends to a file."""
24
+
25
+ def __init__(self, path: str) -> None: ...
26
+ def write(self, buf: bytes | bytearray | memoryview, nbytes: int | None = None) -> int: ...
27
+ def close(self) -> None: ...
28
+ def deinit(self) -> None: ...
29
+
30
+ def ports(folder: str) -> tuple[FileIn, FileOut]:
31
+ """`(midi_in, midi_out)` through `folder`'s two files."""
soundmodule/py.typed ADDED
File without changes