torqpy 0.1.0__tar.gz

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 (71) hide show
  1. torqpy-0.1.0/LICENSE +201 -0
  2. torqpy-0.1.0/MANIFEST.in +24 -0
  3. torqpy-0.1.0/PKG-INFO +167 -0
  4. torqpy-0.1.0/README.md +135 -0
  5. torqpy-0.1.0/docs/api.md +117 -0
  6. torqpy-0.1.0/docs/compare.md +38 -0
  7. torqpy-0.1.0/docs/strongly-timed-python.md +220 -0
  8. torqpy-0.1.0/docs/torque-audio.md +106 -0
  9. torqpy-0.1.0/docs/torque-examples.md +167 -0
  10. torqpy-0.1.0/docs/torque-ugen-roadmap.md +18 -0
  11. torqpy-0.1.0/llms.txt +101 -0
  12. torqpy-0.1.0/pyproject.toml +72 -0
  13. torqpy-0.1.0/setup.cfg +4 -0
  14. torqpy-0.1.0/torqpy.egg-info/SOURCES.txt +68 -0
  15. torqpy-0.1.0/torque/__init__.py +35 -0
  16. torqpy-0.1.0/torque/audio.py +512 -0
  17. torqpy-0.1.0/torque/clock.py +300 -0
  18. torqpy-0.1.0/torque/context.py +45 -0
  19. torqpy-0.1.0/torque/ergo.py +224 -0
  20. torqpy-0.1.0/torque/examples.py +125 -0
  21. torqpy-0.1.0/torque/native/audio.cpp +1213 -0
  22. torqpy-0.1.0/torque/native/build_audio.sh +16 -0
  23. torqpy-0.1.0/torque/native/build_vm.sh +12 -0
  24. torqpy-0.1.0/torque/native/stk/LICENSE +27 -0
  25. torqpy-0.1.0/torque/native/stk/VENDOR.md +1 -0
  26. torqpy-0.1.0/torque/native/stk/include/ADSR.h +179 -0
  27. torqpy-0.1.0/torque/native/stk/include/BiQuad.h +259 -0
  28. torqpy-0.1.0/torque/native/stk/include/BlowBotl.h +144 -0
  29. torqpy-0.1.0/torque/native/stk/include/Clarinet.h +152 -0
  30. torqpy-0.1.0/torque/native/stk/include/DelayA.h +207 -0
  31. torqpy-0.1.0/torque/native/stk/include/DelayL.h +230 -0
  32. torqpy-0.1.0/torque/native/stk/include/Envelope.h +131 -0
  33. torqpy-0.1.0/torque/native/stk/include/Filter.h +124 -0
  34. torqpy-0.1.0/torque/native/stk/include/Function.h +41 -0
  35. torqpy-0.1.0/torque/native/stk/include/Generator.h +50 -0
  36. torqpy-0.1.0/torque/native/stk/include/Instrmnt.h +108 -0
  37. torqpy-0.1.0/torque/native/stk/include/JetTable.h +112 -0
  38. torqpy-0.1.0/torque/native/stk/include/Noise.h +84 -0
  39. torqpy-0.1.0/torque/native/stk/include/OnePole.h +134 -0
  40. torqpy-0.1.0/torque/native/stk/include/OneZero.h +134 -0
  41. torqpy-0.1.0/torque/native/stk/include/Plucked.h +117 -0
  42. torqpy-0.1.0/torque/native/stk/include/PoleZero.h +113 -0
  43. torqpy-0.1.0/torque/native/stk/include/ReedTable.h +143 -0
  44. torqpy-0.1.0/torque/native/stk/include/SKINImsg.h +129 -0
  45. torqpy-0.1.0/torque/native/stk/include/SineWave.h +159 -0
  46. torqpy-0.1.0/torque/native/stk/include/Stk.h +637 -0
  47. torqpy-0.1.0/torque/native/stk/src/ADSR.cpp +181 -0
  48. torqpy-0.1.0/torque/native/stk/src/BiQuad.cpp +182 -0
  49. torqpy-0.1.0/torque/native/stk/src/BlowBotl.cpp +122 -0
  50. torqpy-0.1.0/torque/native/stk/src/Clarinet.cpp +138 -0
  51. torqpy-0.1.0/torque/native/stk/src/DelayA.cpp +117 -0
  52. torqpy-0.1.0/torque/native/stk/src/DelayL.cpp +73 -0
  53. torqpy-0.1.0/torque/native/stk/src/Envelope.cpp +87 -0
  54. torqpy-0.1.0/torque/native/stk/src/Noise.cpp +34 -0
  55. torqpy-0.1.0/torque/native/stk/src/OnePole.cpp +61 -0
  56. torqpy-0.1.0/torque/native/stk/src/OneZero.cpp +49 -0
  57. torqpy-0.1.0/torque/native/stk/src/Plucked.cpp +98 -0
  58. torqpy-0.1.0/torque/native/stk/src/PoleZero.cpp +73 -0
  59. torqpy-0.1.0/torque/native/stk/src/SineWave.cpp +78 -0
  60. torqpy-0.1.0/torque/native/stk/src/Stk.cpp +401 -0
  61. torqpy-0.1.0/torque/native/vm.cpp +223 -0
  62. torqpy-0.1.0/torque/native_clock.py +162 -0
  63. torqpy-0.1.0/torque/tests/__init__.py +0 -0
  64. torqpy-0.1.0/torque/tests/test_async.py +144 -0
  65. torqpy-0.1.0/torque/tests/test_audio.py +352 -0
  66. torqpy-0.1.0/torque/tests/test_clock.py +251 -0
  67. torqpy-0.1.0/torque/tests/test_ergo.py +232 -0
  68. torqpy-0.1.0/torque/tests/test_examples.py +49 -0
  69. torqpy-0.1.0/torque/tests/test_native.py +104 -0
  70. torqpy-0.1.0/torque/tests/test_types.py +51 -0
  71. torqpy-0.1.0/torque/types.py +259 -0
torqpy-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,24 @@
1
+ # sdist contents for torqpy (import name: torque)
2
+ include LICENSE
3
+ include README.md
4
+ include llms.txt
5
+ include pyproject.toml
6
+ recursive-include docs *.md
7
+
8
+ # Package + optional native build sources (STK + build scripts)
9
+ recursive-include torque *.py
10
+ recursive-include torque/native *.cpp *.h *.sh LICENSE VENDOR.md
11
+
12
+ # Tests ride along in the sdist for downstream checkers; the wheel omits them
13
+ # via [tool.setuptools.packages.find] exclude.
14
+ recursive-include torque/tests *.py
15
+
16
+ # Keep build artifacts and binaries out of both sdist and wheel
17
+ global-exclude *.py[cod] *.so *.dylib *.dll *.o *.a *~ .DS_Store
18
+ global-exclude .git* .pytest_cache/* .mypy_cache/* .ruff_cache/*
19
+ prune __pycache__
20
+ prune torque/__pycache__
21
+ prune torque/tests/__pycache__
22
+ prune build
23
+ prune dist
24
+ prune *.egg-info
torqpy-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.4
2
+ Name: torqpy
3
+ Version: 0.1.0
4
+ Summary: torq.py — strongly timed concurrent Python with an optional embedded audio graph
5
+ Author-email: Dote <10195318+valid22@users.noreply.github.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/valid22/torq.py
8
+ Project-URL: Repository, https://github.com/valid22/torq.py
9
+ Project-URL: Documentation, https://github.com/valid22/torq.py#readme
10
+ Project-URL: Issues, https://github.com/valid22/torq.py/issues
11
+ Project-URL: Release notes, https://github.com/valid22/torq.py/releases
12
+ Keywords: timing,music,audio,shreds,logical-clock,strongly-timed
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Multimedia :: Sound/Audio
23
+ Classifier: Topic :: Software Development :: Libraries
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Provides-Extra: dev
28
+ Requires-Dist: numpy; extra == "dev"
29
+ Requires-Dist: build; extra == "dev"
30
+ Requires-Dist: pytest; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # torq.py
34
+
35
+ **Strongly timed concurrent Python** — logical musical time, sample-exact wakes, and an optional embedded audio graph on the same clock.
36
+
37
+ torq.py advances `now` only when shreds yield a duration (or you `advance` / `run`). It does not sleep on the wall clock. Audio UGens (first-party + embedded STK) tick inside the native graph; there is no external synth server.
38
+
39
+ | | |
40
+ | --- | --- |
41
+ | **Brand** | torq.py |
42
+ | **PyPI** | `torqpy` |
43
+ | **Import** | `import torque` |
44
+
45
+ > **Status:** research package. PyPI name `torqpy` (first publish: pure-Python wheel; native audio is optional and built locally).
46
+
47
+ ## Install
48
+
49
+ ```bash
50
+ pip install torqpy
51
+ # or from this repo:
52
+ pip install -e .
53
+ ```
54
+
55
+ Timing and shreds work with no native build. Audio (`torque.audio`) needs the optional extension:
56
+
57
+ ```bash
58
+ # after pip install — sources ship inside the package:
59
+ bash "$(python -c 'import torque, pathlib; print(pathlib.Path(torque.__file__).parent / "native" / "build_audio.sh")')"
60
+ # from a git checkout:
61
+ bash torque/native/build_audio.sh
62
+ # needs: g++, python3-dev, portaudio19-dev
63
+ ```
64
+
65
+ Then junnu can write:
66
+
67
+ ```python
68
+ import torque
69
+ from torque.audio import AudioEngine
70
+ ```
71
+
72
+ ## Hello beep
73
+
74
+ Laddu wants one polite meow. junnu wires a sine, an envelope, and a shred that opens and closes it on logical time:
75
+
76
+ ```python
77
+ from torque import Clock, Time, ms, second, spork
78
+ from torque.audio import AudioEngine, write_wav
79
+
80
+ engine = AudioEngine(48_000)
81
+ osc = engine.SinOsc(440)
82
+ env = engine.ADSR(0.01, 0.1, 0.3, 0.2)
83
+ osc >> env >> engine.Gain(0.35) >> engine.dac
84
+
85
+ clock = Clock(sample_rate=48_000)
86
+
87
+ def laddu_meow():
88
+ env.keyOn()
89
+ yield 300 * ms
90
+ env.keyOff()
91
+ yield 300 * ms
92
+
93
+ with clock:
94
+ spork(laddu_meow)
95
+ buf = engine.render_while(clock, until=Time(0) + 600 * ms)
96
+ write_wav("beep.wav", buf, engine.sample_rate)
97
+ ```
98
+
99
+ Timing without audio — junnu’s metronome:
100
+
101
+ ```python
102
+ from torque import Clock, ms, spork
103
+
104
+ clock = Clock()
105
+ hits = []
106
+
107
+ def junnu_metro():
108
+ for _ in range(4):
109
+ hits.append(clock.now)
110
+ yield 500 * ms
111
+
112
+ clock.spork(junnu_metro())
113
+ clock.run()
114
+ # hits at 0, 0.5s, 1s, 1.5s — deterministic, no wall sleep
115
+ ```
116
+
117
+ ## Features
118
+
119
+ - **Logical clock** — `Time` / `Dur` as exact rationals; `samp` ties to an integer sample rate
120
+ - **Shreds** — generator or `async def` + `await (~d)` on torq.py’s runner (not `asyncio`)
121
+ - **Ergonomics** — `with clock:`, `spork` / `now`, `~d`, `t ^ d`, `Pat` / `p["x-x-"]`, `@every`
122
+ - **Audio graph** — oscillators, Noise, ADSR, LPF/HPF, Delay, Pan, stereo render/WAV
123
+ - **Embedded STK** — Clarinet, BlowBotl, Plucked tick on torq.py’s sample clock
124
+ - **Optional live I/O** — PortAudio when a device exists; offline always works
125
+
126
+ ## Quick API
127
+
128
+ | Need | Start here |
129
+ | --- | --- |
130
+ | Types & clock | `from torque import Clock, Time, Dur, second, ms, samp` |
131
+ | Context helpers | `spork`, `now`, `wait`, `every`, `Pat`, `p` |
132
+ | Audio | `from torque.audio import AudioEngine, write_wav, has_output_device` |
133
+ | Connect UGens | `src >> dst` or `src.to(dst)` |
134
+ | Offline | `engine.render_while(clock, until=...)` |
135
+ | Live | `has_output_device()` then `engine.play_while(...)` |
136
+
137
+ Full surface: [docs/api.md](docs/api.md).
138
+
139
+ ## Docs
140
+
141
+ | Doc | Contents |
142
+ | --- | --- |
143
+ | [docs/strongly-timed-python.md](docs/strongly-timed-python.md) | Timing model & type rules |
144
+ | [docs/torque-examples.md](docs/torque-examples.md) | Copy-paste timing snippets |
145
+ | [docs/torque-audio.md](docs/torque-audio.md) | UGens, stereo, live, STK |
146
+ | [docs/torque-ugen-roadmap.md](docs/torque-ugen-roadmap.md) | Coverage roadmap |
147
+ | [docs/compare.md](docs/compare.md) | Related systems |
148
+ | [docs/api.md](docs/api.md) | Public API |
149
+ | [llms.txt](llms.txt) | Agent-oriented install & patterns |
150
+
151
+ ## Build (optional audio extension)
152
+
153
+ The published wheel is pure Python. Native sources (`torque/native/`, including vendored STK) are included so you can build `_audio` on the machine that will run audio:
154
+
155
+ ```bash
156
+ bash "$(python -c 'import torque, pathlib; print(pathlib.Path(torque.__file__).parent / "native" / "build_audio.sh")')"
157
+ # or from a checkout: bash torque/native/build_audio.sh
158
+ # needs: g++, python3-dev, portaudio19-dev
159
+ ```
160
+
161
+ ## Related work (peers)
162
+
163
+ See [docs/compare.md](docs/compare.md) for related systems and when each is a better fit. Peers include ChucK, Extempore, Tidal/Strudel, SuperCollider, pyo, and Python `asyncio` (wall-clock concurrency — different job).
164
+
165
+ ## License
166
+
167
+ torq.py is Apache-2.0. Vendored STK under `torque/native/stk/` carries its own MIT-style license (Cook & Scavone).
torqpy-0.1.0/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # torq.py
2
+
3
+ **Strongly timed concurrent Python** — logical musical time, sample-exact wakes, and an optional embedded audio graph on the same clock.
4
+
5
+ torq.py advances `now` only when shreds yield a duration (or you `advance` / `run`). It does not sleep on the wall clock. Audio UGens (first-party + embedded STK) tick inside the native graph; there is no external synth server.
6
+
7
+ | | |
8
+ | --- | --- |
9
+ | **Brand** | torq.py |
10
+ | **PyPI** | `torqpy` |
11
+ | **Import** | `import torque` |
12
+
13
+ > **Status:** research package. PyPI name `torqpy` (first publish: pure-Python wheel; native audio is optional and built locally).
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install torqpy
19
+ # or from this repo:
20
+ pip install -e .
21
+ ```
22
+
23
+ Timing and shreds work with no native build. Audio (`torque.audio`) needs the optional extension:
24
+
25
+ ```bash
26
+ # after pip install — sources ship inside the package:
27
+ bash "$(python -c 'import torque, pathlib; print(pathlib.Path(torque.__file__).parent / "native" / "build_audio.sh")')"
28
+ # from a git checkout:
29
+ bash torque/native/build_audio.sh
30
+ # needs: g++, python3-dev, portaudio19-dev
31
+ ```
32
+
33
+ Then junnu can write:
34
+
35
+ ```python
36
+ import torque
37
+ from torque.audio import AudioEngine
38
+ ```
39
+
40
+ ## Hello beep
41
+
42
+ Laddu wants one polite meow. junnu wires a sine, an envelope, and a shred that opens and closes it on logical time:
43
+
44
+ ```python
45
+ from torque import Clock, Time, ms, second, spork
46
+ from torque.audio import AudioEngine, write_wav
47
+
48
+ engine = AudioEngine(48_000)
49
+ osc = engine.SinOsc(440)
50
+ env = engine.ADSR(0.01, 0.1, 0.3, 0.2)
51
+ osc >> env >> engine.Gain(0.35) >> engine.dac
52
+
53
+ clock = Clock(sample_rate=48_000)
54
+
55
+ def laddu_meow():
56
+ env.keyOn()
57
+ yield 300 * ms
58
+ env.keyOff()
59
+ yield 300 * ms
60
+
61
+ with clock:
62
+ spork(laddu_meow)
63
+ buf = engine.render_while(clock, until=Time(0) + 600 * ms)
64
+ write_wav("beep.wav", buf, engine.sample_rate)
65
+ ```
66
+
67
+ Timing without audio — junnu’s metronome:
68
+
69
+ ```python
70
+ from torque import Clock, ms, spork
71
+
72
+ clock = Clock()
73
+ hits = []
74
+
75
+ def junnu_metro():
76
+ for _ in range(4):
77
+ hits.append(clock.now)
78
+ yield 500 * ms
79
+
80
+ clock.spork(junnu_metro())
81
+ clock.run()
82
+ # hits at 0, 0.5s, 1s, 1.5s — deterministic, no wall sleep
83
+ ```
84
+
85
+ ## Features
86
+
87
+ - **Logical clock** — `Time` / `Dur` as exact rationals; `samp` ties to an integer sample rate
88
+ - **Shreds** — generator or `async def` + `await (~d)` on torq.py’s runner (not `asyncio`)
89
+ - **Ergonomics** — `with clock:`, `spork` / `now`, `~d`, `t ^ d`, `Pat` / `p["x-x-"]`, `@every`
90
+ - **Audio graph** — oscillators, Noise, ADSR, LPF/HPF, Delay, Pan, stereo render/WAV
91
+ - **Embedded STK** — Clarinet, BlowBotl, Plucked tick on torq.py’s sample clock
92
+ - **Optional live I/O** — PortAudio when a device exists; offline always works
93
+
94
+ ## Quick API
95
+
96
+ | Need | Start here |
97
+ | --- | --- |
98
+ | Types & clock | `from torque import Clock, Time, Dur, second, ms, samp` |
99
+ | Context helpers | `spork`, `now`, `wait`, `every`, `Pat`, `p` |
100
+ | Audio | `from torque.audio import AudioEngine, write_wav, has_output_device` |
101
+ | Connect UGens | `src >> dst` or `src.to(dst)` |
102
+ | Offline | `engine.render_while(clock, until=...)` |
103
+ | Live | `has_output_device()` then `engine.play_while(...)` |
104
+
105
+ Full surface: [docs/api.md](docs/api.md).
106
+
107
+ ## Docs
108
+
109
+ | Doc | Contents |
110
+ | --- | --- |
111
+ | [docs/strongly-timed-python.md](docs/strongly-timed-python.md) | Timing model & type rules |
112
+ | [docs/torque-examples.md](docs/torque-examples.md) | Copy-paste timing snippets |
113
+ | [docs/torque-audio.md](docs/torque-audio.md) | UGens, stereo, live, STK |
114
+ | [docs/torque-ugen-roadmap.md](docs/torque-ugen-roadmap.md) | Coverage roadmap |
115
+ | [docs/compare.md](docs/compare.md) | Related systems |
116
+ | [docs/api.md](docs/api.md) | Public API |
117
+ | [llms.txt](llms.txt) | Agent-oriented install & patterns |
118
+
119
+ ## Build (optional audio extension)
120
+
121
+ The published wheel is pure Python. Native sources (`torque/native/`, including vendored STK) are included so you can build `_audio` on the machine that will run audio:
122
+
123
+ ```bash
124
+ bash "$(python -c 'import torque, pathlib; print(pathlib.Path(torque.__file__).parent / "native" / "build_audio.sh")')"
125
+ # or from a checkout: bash torque/native/build_audio.sh
126
+ # needs: g++, python3-dev, portaudio19-dev
127
+ ```
128
+
129
+ ## Related work (peers)
130
+
131
+ See [docs/compare.md](docs/compare.md) for related systems and when each is a better fit. Peers include ChucK, Extempore, Tidal/Strudel, SuperCollider, pyo, and Python `asyncio` (wall-clock concurrency — different job).
132
+
133
+ ## License
134
+
135
+ torq.py is Apache-2.0. Vendored STK under `torque/native/stk/` carries its own MIT-style license (Cook & Scavone).
@@ -0,0 +1,117 @@
1
+ # torq.py public API
2
+
3
+ | | |
4
+ | --- | --- |
5
+ | Brand | **torq.py** |
6
+ | PyPI | `pip install torqpy` |
7
+ | Import | `import torque` / `from torque.audio import ...` |
8
+
9
+ Importable package: `torque` (timing) and `torque.audio` (graph). Built native extensions: `torque._vm` (optional native clock), `torque._audio` (UGens / STK / PortAudio).
10
+
11
+ ## `torque` — timing
12
+
13
+ ```python
14
+ from torque import (
15
+ Clock, Shred,
16
+ Time, Dur, Wait,
17
+ second, ms, samp, minute,
18
+ spork, now, wait, until, every, at,
19
+ Pat, p, shred, ShredFn,
20
+ current_clock,
21
+ )
22
+ ```
23
+
24
+ ### Types
25
+
26
+ | Symbol | Role |
27
+ | --- | --- |
28
+ | `Time` | Logical instant (rational seconds) |
29
+ | `Dur` | Duration (rational seconds) |
30
+ | `Wait` | Awaitable wait token from `~dur` / invert |
31
+ | `second`, `ms`, `minute` | Module-level durations |
32
+ | `samp` | One sample at 48000 Hz (use `clock.samp` for other rates) |
33
+
34
+ Legal arithmetic: `time±dur`, `time−time→dur`, `dur±dur`, `dur*number`, `dur/dur→Fraction`. Illegal mixes raise `TypeError`.
35
+
36
+ ### `Clock`
37
+
38
+ | Member | Meaning |
39
+ | --- | --- |
40
+ | `Clock(sample_rate=48000)` | Logical scheduler |
41
+ | `.now` | Current `Time` |
42
+ | `.samp` / `.second` / `.ms` / `.minute` | Rate-aware units |
43
+ | `.spork(gen_or_async)` | Start a shred (creation order = tie-break) |
44
+ | `.run()` / `.run(until=Time)` | Drain shreds |
45
+ | `.advance(dur)` | Move `now` forward, run due shreds |
46
+ | `.next_wake` | Next scheduled wake or `None` |
47
+ | context manager | Binds module `spork` / `now` via contextvars |
48
+
49
+ ### Ergonomics (`torque.ergo` / re-exported)
50
+
51
+ | Symbol | Meaning |
52
+ | --- | --- |
53
+ | `spork`, `now` | Context-bound helpers |
54
+ | `wait(dur)`, `until(time)` | Suspend helpers |
55
+ | `every(dur)`, `at(time)` | Scheduling helpers |
56
+ | `~dur` | Wait token (`Wait`); async: `await (~dur)` |
57
+ | `time ^ dur` | Time offset sugar |
58
+ | `Pat`, `p["x-x-"]` | Pattern helpers |
59
+ | `@shred` / `ShredFn` | Enables unary `+` spork for decorated callables — not required for async |
60
+
61
+ Shreds may be generators (`yield dur` or `yield ~dur`) or `async def` driven by torq.py (not `asyncio.run`).
62
+
63
+ ### Native clock
64
+
65
+ `torque.native_clock` exposes a C++-backed clock matching Python semantics when `torque._vm` is built. Same public timing ideas; see tests under `torque/tests/test_native.py`.
66
+
67
+ ---
68
+
69
+ ## `torque.audio` — graph
70
+
71
+ ```python
72
+ from torque.audio import AudioEngine, write_wav, has_output_device
73
+ ```
74
+
75
+ Requires built `torque._audio` (`bash torque/native/build_audio.sh`).
76
+
77
+ ### `AudioEngine(sample_rate=48000, channels=1|2)`
78
+
79
+ | Member | Meaning |
80
+ | --- | --- |
81
+ | `.dac`, `.blackhole` | Sinks |
82
+ | `.sample_rate`, `.channels`, `.now_samples` | Engine state |
83
+ | Factories | `SinOsc`, `TriOsc`, `SawOsc`, `SqrOsc`, `Noise`, `Gain`, `ADSR`, `LPF`, `HPF`, `Delay`, `Pan`, `Clarinet`, `BlowBotl`, `Plucked` |
84
+ | `.connect(src, dst)` | Same as `src >> dst` |
85
+ | `.render(n)` / `.render_dur(dur)` | Offline buffers — mono `(N,)` or stereo `(N, 2)` |
86
+ | `.render_while(clock, until=Time)` | Interleave shreds + offline render |
87
+ | `.play_while(clock, until=Time)` | Same with PortAudio stream |
88
+ | `.start()` / `.stop()` / `.play(n)` | Live device I/O |
89
+ | `.has_output_device()` | Default output present? |
90
+
91
+ ### UGen conventions
92
+
93
+ - Connect: `a >> b >> engine.dac` or `a.to(b)`
94
+ - Oscillators / filters / STK: `.freq`
95
+ - `SqrOsc.width`; `Gain.gain`; `Pan.pan`
96
+ - `ADSR.keyOn` / `keyOff` (and snake_case aliases)
97
+ - `Delay.delay`, `.mix`, `.feedback`
98
+ - STK: `noteOn(amp=0.5)` / `noteOff(amp=0.5)`
99
+
100
+ Sources (oscs, Noise, STK instruments) do not accept audio inputs.
101
+
102
+ ### Helpers
103
+
104
+ | Function | Meaning |
105
+ | --- | --- |
106
+ | `write_wav(path, samples, sample_rate=48000)` | Mono or stereo float → 16-bit PCM WAV |
107
+ | `has_output_device()` | Process-wide PortAudio default output check |
108
+
109
+ ---
110
+
111
+ ## See also
112
+
113
+ - [strongly-timed-python.md](./strongly-timed-python.md) — semantics
114
+ - [torque-examples.md](./torque-examples.md) — timing snippets
115
+ - [torque-audio.md](./torque-audio.md) — audio / STK / live
116
+ - [torque-ugen-roadmap.md](./torque-ugen-roadmap.md) — coverage plan
117
+ - [compare.md](./compare.md) — peers
@@ -0,0 +1,38 @@
1
+ # Related systems
2
+
3
+ **torq.py** (`pip install torqpy`, `import torque`) is a **Python library for logical musical time** with an optional embedded audio graph. The systems below are peers — not a claim that torq.py replaces them, and not a performance bake-off (no fabricated benchmarks).
4
+
5
+ ## Quick map
6
+
7
+ | System | Home language | Time model | Audio | Overlap with torq.py |
8
+ | --- | --- | --- | --- | --- |
9
+ | **torq.py** | Python | Logical `now`; shreds yield `Dur` | Embedded native graph + STK; optional PortAudio | — |
10
+ | **ChucK** | ChucK | Strong timing; `now` advances by duration | Built-in UGens / VM | Closest conceptual peer for timing + ugens |
11
+ | **Extempore** | xtlang / Scheme | Temporal recursion, precise scheduling | Native audio | Live coding with hard timing in a dedicated runtime |
12
+ | **Tidal / Strudel** | Haskell / JS | Pattern cycles, mini-notation | Usually SuperCollider / WebAudio | Pattern-first sequencing |
13
+ | **SuperCollider** | sclang + scsynth | Language schedules; server renders | Separate audio server | Server/client audio architecture |
14
+ | **pyo** | Python | Callback / server-oriented | Own audio engine | Python DSP without torq.py’s shred clock |
15
+ | **asyncio** | Python | Wall-clock event loop | N/A | Concurrent I/O — not sample-exact musical time |
16
+
17
+ ## When torq.py is a better fit
18
+
19
+ - You want **musical time in ordinary Python** (generators or `async` spelling) without a new language runtime.
20
+ - Deterministic offline render must **share one clock** with concurrent shreds (param changes at exact wake times).
21
+ - You prefer an **in-process** graph (first-party + embedded STK) over talking to scsynth/pyo as a server.
22
+ - Teaching or prototyping **strong timing** where rational `Time`/`Dur` and shred order matter more than a full DAW.
23
+
24
+ ## When a peer is a better fit
25
+
26
+ - **ChucK** — you want the mature ChucK language, IDE, and ugen ecosystem as the primary environment.
27
+ - **Extempore** — xtlang live coding and its temporal programming model are the goal.
28
+ - **Tidal / Strudel** — pattern algebra and mini-notation are the main interface (especially browser/Haskell workflows).
29
+ - **SuperCollider** — you need scsynth’s ugen server, massive community synthdefs, or NRT pipelines already built around OSC.
30
+ - **pyo** — Python DSP objects and its server/callback style without torq.py’s logical shred scheduler.
31
+ - **asyncio** — network/UI concurrency on wall time; not a substitute for sample-accurate musical `now`.
32
+
33
+ ## Honest limits (torq.py today)
34
+
35
+ - Research package; PyPI name is **`torqpy`** (not uploaded yet — clone this repo and `pip install -e .`).
36
+ - UGen coverage is growing (roadmap: [torque-ugen-roadmap.md](./torque-ugen-roadmap.md)); not peer-ecosystem complete.
37
+ - Live audio needs a host device; many VMs have none — offline stereo still works.
38
+ - Hard real-time (PREEMPT_RT audio thread) is a later profile; the native path already avoids calling Python while filling buffers.