Metadata-Version: 2.4
Name: torqpy
Version: 0.1.0
Summary: torq.py — strongly timed concurrent Python with an optional embedded audio graph
Author-email: Dote <10195318+valid22@users.noreply.github.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/valid22/torq.py
Project-URL: Repository, https://github.com/valid22/torq.py
Project-URL: Documentation, https://github.com/valid22/torq.py#readme
Project-URL: Issues, https://github.com/valid22/torq.py/issues
Project-URL: Release notes, https://github.com/valid22/torq.py/releases
Keywords: timing,music,audio,shreds,logical-clock,strongly-timed
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Sound/Audio
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: numpy; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Dynamic: license-file

# torq.py

**Strongly timed concurrent Python** — logical musical time, sample-exact wakes, and an optional embedded audio graph on the same clock.

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.

| | |
| --- | --- |
| **Brand** | torq.py |
| **PyPI** | `torqpy` |
| **Import** | `import torque` |

> **Status:** research package. PyPI name `torqpy` (first publish: pure-Python wheel; native audio is optional and built locally).

## Install

```bash
pip install torqpy
# or from this repo:
pip install -e .
```

Timing and shreds work with no native build. Audio (`torque.audio`) needs the optional extension:

```bash
# after pip install — sources ship inside the package:
bash "$(python -c 'import torque, pathlib; print(pathlib.Path(torque.__file__).parent / "native" / "build_audio.sh")')"
# from a git checkout:
bash torque/native/build_audio.sh
# needs: g++, python3-dev, portaudio19-dev
```

Then junnu can write:

```python
import torque
from torque.audio import AudioEngine
```

## Hello beep

Laddu wants one polite meow. junnu wires a sine, an envelope, and a shred that opens and closes it on logical time:

```python
from torque import Clock, Time, ms, second, spork
from torque.audio import AudioEngine, write_wav

engine = AudioEngine(48_000)
osc = engine.SinOsc(440)
env = engine.ADSR(0.01, 0.1, 0.3, 0.2)
osc >> env >> engine.Gain(0.35) >> engine.dac

clock = Clock(sample_rate=48_000)

def laddu_meow():
    env.keyOn()
    yield 300 * ms
    env.keyOff()
    yield 300 * ms

with clock:
    spork(laddu_meow)
buf = engine.render_while(clock, until=Time(0) + 600 * ms)
write_wav("beep.wav", buf, engine.sample_rate)
```

Timing without audio — junnu’s metronome:

```python
from torque import Clock, ms, spork

clock = Clock()
hits = []

def junnu_metro():
    for _ in range(4):
        hits.append(clock.now)
        yield 500 * ms

clock.spork(junnu_metro())
clock.run()
# hits at 0, 0.5s, 1s, 1.5s — deterministic, no wall sleep
```

## Features

- **Logical clock** — `Time` / `Dur` as exact rationals; `samp` ties to an integer sample rate
- **Shreds** — generator or `async def` + `await (~d)` on torq.py’s runner (not `asyncio`)
- **Ergonomics** — `with clock:`, `spork` / `now`, `~d`, `t ^ d`, `Pat` / `p["x-x-"]`, `@every`
- **Audio graph** — oscillators, Noise, ADSR, LPF/HPF, Delay, Pan, stereo render/WAV
- **Embedded STK** — Clarinet, BlowBotl, Plucked tick on torq.py’s sample clock
- **Optional live I/O** — PortAudio when a device exists; offline always works

## Quick API

| Need | Start here |
| --- | --- |
| Types & clock | `from torque import Clock, Time, Dur, second, ms, samp` |
| Context helpers | `spork`, `now`, `wait`, `every`, `Pat`, `p` |
| Audio | `from torque.audio import AudioEngine, write_wav, has_output_device` |
| Connect UGens | `src >> dst` or `src.to(dst)` |
| Offline | `engine.render_while(clock, until=...)` |
| Live | `has_output_device()` then `engine.play_while(...)` |

Full surface: [docs/api.md](docs/api.md).

## Docs

| Doc | Contents |
| --- | --- |
| [docs/strongly-timed-python.md](docs/strongly-timed-python.md) | Timing model & type rules |
| [docs/torque-examples.md](docs/torque-examples.md) | Copy-paste timing snippets |
| [docs/torque-audio.md](docs/torque-audio.md) | UGens, stereo, live, STK |
| [docs/torque-ugen-roadmap.md](docs/torque-ugen-roadmap.md) | Coverage roadmap |
| [docs/compare.md](docs/compare.md) | Related systems |
| [docs/api.md](docs/api.md) | Public API |
| [llms.txt](llms.txt) | Agent-oriented install & patterns |

## Build (optional audio extension)

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:

```bash
bash "$(python -c 'import torque, pathlib; print(pathlib.Path(torque.__file__).parent / "native" / "build_audio.sh")')"
# or from a checkout: bash torque/native/build_audio.sh
# needs: g++, python3-dev, portaudio19-dev
```

## Related work (peers)

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).

## License

torq.py is Apache-2.0. Vendored STK under `torque/native/stk/` carries its own MIT-style license (Cook & Scavone).
