pyquist 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.
pyquist-0.1.0/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2026 Chris Donahue
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pyquist-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,180 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyquist
3
+ Version: 0.1.0
4
+ Summary: Barebones utilities for low-level computer music programming in Python and NumPy. Teaching library for CMU 15-322.
5
+ Author: Chris Donahue
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://gclef-cmu.org/pyquist
8
+ Project-URL: Documentation, https://gclef-cmu.org/pyquist
9
+ Project-URL: Repository, https://github.com/gclef-cmu/pyquist
10
+ Project-URL: Issues, https://github.com/gclef-cmu/pyquist/issues
11
+ Keywords: audio,music,dsp,midi,numpy,computer-music,education
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Multimedia :: Sound/Audio
21
+ Classifier: Topic :: Scientific/Engineering
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: matplotlib
27
+ Requires-Dist: mido
28
+ Requires-Dist: numpy>=2.0
29
+ Requires-Dist: requests
30
+ Requires-Dist: resampy
31
+ Requires-Dist: sounddevice
32
+ Requires-Dist: soundfile
33
+ Requires-Dist: tqdm
34
+ Provides-Extra: dev
35
+ Requires-Dist: mypy>=1.13; extra == "dev"
36
+ Requires-Dist: pre-commit>=4.0; extra == "dev"
37
+ Requires-Dist: ruff>=0.8; extra == "dev"
38
+ Provides-Extra: notebook
39
+ Requires-Dist: ipython; extra == "notebook"
40
+ Provides-Extra: docs
41
+ Requires-Dist: sphinx>=7; extra == "docs"
42
+ Requires-Dist: sphinx-autodoc-typehints>=2; extra == "docs"
43
+ Dynamic: license-file
44
+
45
+ # `pyquist`
46
+
47
+ `pyquist` provides basic utilities for **low-level computer music programming in Python and NumPy**.
48
+
49
+ `pyquist` is **designed for learning** and is the teaching library for CMU's 15-322 Intro to Computer Music. Its primary purpose is to provide a _barebones foundation_ for working with audio in Python, e.g., allocating sample buffers, audio file decoding and playback. Accordingly, it intentionally lacks a lot of functionality found in full-fledged computer music programming frameworks, such as a rich collection of unit generators.
50
+
51
+ Want to try it without installing anything? [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gclef-cmu/pyquist/blob/main/examples/HelloPyquist.ipynb)
52
+
53
+ ## Quick example
54
+
55
+ ```python
56
+ import numpy as np
57
+ import pyquist as pq
58
+
59
+ # A 1-second, 440 Hz sine wave at CD quality.
60
+ sr = 44100
61
+ t = np.arange(sr) / sr
62
+ audio = pq.Audio(0.5 * np.sin(2 * np.pi * 440 * t), sample_rate=sr)
63
+
64
+ pq.play(audio) # play through default output (or notebook widget)
65
+ pq.plot(audio) # waveform
66
+ pq.plot_spec(audio) # spectrogram
67
+ ```
68
+
69
+ Loading and transforming:
70
+
71
+ ```python
72
+ riff = pq.Audio.from_url(
73
+ "https://github.com/gclef-cmu/pyquist/raw/refs/heads/main/pyquist/test_data/388954__fullmetaljedi__blues-riff-in-g-nylon.wav"
74
+ )
75
+ clip = riff.segment(offset=5.0, duration=3.0).resample(8000)
76
+ pq.play(clip)
77
+ ```
78
+
79
+ Rendering a `Score` with a custom instrument. An instrument is called as `instrument(**event.kwargs)` — declare the kwargs you use and absorb the rest with `**kwargs`:
80
+
81
+ ```python
82
+ from pyquist.score import Score, Event, BasicMetronome
83
+ from pyquist.helper import pitch_to_frequency
84
+
85
+ def sine_instrument(pitch, duration, **kwargs):
86
+ sr = 44100
87
+ t = np.arange(int(duration * sr)) / sr
88
+ freq = pitch_to_frequency(pitch)
89
+ return pq.Audio(0.3 * np.sin(2 * np.pi * freq * t) * np.exp(-3 * t), sample_rate=sr)
90
+
91
+ score = Score([
92
+ Event(0, {"pitch": 60, "duration": 0.5}),
93
+ Event(1, {"pitch": 64, "duration": 0.5}),
94
+ Event(2, {"pitch": 67, "duration": 0.5}),
95
+ ])
96
+ pq.play(score.render(sine_instrument, metronome=BasicMetronome(120)))
97
+ ```
98
+
99
+ For a guided walkthrough — visualization, MIDI parsing, scores, instruments — open [`examples/HelloPyquist.ipynb`](examples/HelloPyquist.ipynb) or [run it in Colab](https://colab.research.google.com/github/gclef-cmu/pyquist/blob/main/examples/HelloPyquist.ipynb).
100
+
101
+ ## Installation
102
+
103
+ Requires **Python 3.10 or later**.
104
+
105
+ ### macOS
106
+
107
+ ```sh
108
+ brew install python@3.10 # or 3.11, 3.12, 3.13
109
+ python3.10 -m venv .venv
110
+ source .venv/bin/activate
111
+ pip install --upgrade pyquist
112
+ ```
113
+
114
+ If `pq.play(...)` is silent, give Terminal (or your IDE) microphone/audio access in **System Settings → Privacy & Security → Microphone**.
115
+
116
+ ### Linux
117
+
118
+ Install Python and the PortAudio system library that `sounddevice` wraps:
119
+
120
+ ```sh
121
+ # Debian / Ubuntu
122
+ sudo apt install python3 python3-venv libportaudio2
123
+
124
+ # Fedora
125
+ sudo dnf install python3 python3-virtualenv portaudio
126
+
127
+ python3 -m venv .venv
128
+ source .venv/bin/activate
129
+ pip install --upgrade pyquist
130
+ ```
131
+
132
+ ### Windows
133
+
134
+ Install [Python](https://www.python.org/downloads/) (3.10 or later, with "Add Python to PATH" checked), then open **Command Prompt**:
135
+
136
+ ```bat
137
+ python -m venv .venv
138
+ .venv\Scripts\activate.bat
139
+ pip install --upgrade pyquist
140
+ ```
141
+
142
+ ### From source
143
+
144
+ For hacking on pyquist itself:
145
+
146
+ ```sh
147
+ git clone https://github.com/gclef-cmu/pyquist.git
148
+ cd pyquist
149
+ python3 -m venv .venv
150
+ source .venv/bin/activate
151
+ pip install -e ".[dev,notebook]"
152
+ pre-commit install
153
+ ```
154
+
155
+ ### Pick default audio devices
156
+
157
+ Once installed, the `pyquist` CLI lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):
158
+
159
+ ```sh
160
+ pyquist devices
161
+ ```
162
+
163
+ ### Run notebooks
164
+
165
+ ```sh
166
+ pip install jupyter ipykernel ipywidgets
167
+ python -m ipykernel install --user --name=pyquist --display-name "Pyquist"
168
+ cd examples
169
+ jupyter notebook
170
+ ```
171
+
172
+ Then open [`HelloPyquist.ipynb`](examples/HelloPyquist.ipynb) and select the **Pyquist** kernel.
173
+
174
+ ## Acknowledgements
175
+
176
+ Inspired in part by:
177
+
178
+ - [Nyquist](https://sourceforge.net/projects/nyquist/)
179
+ - [Tone.js](https://tonejs.github.io/)
180
+ - [JUCE](https://juce.com/)
@@ -0,0 +1,136 @@
1
+ # `pyquist`
2
+
3
+ `pyquist` provides basic utilities for **low-level computer music programming in Python and NumPy**.
4
+
5
+ `pyquist` is **designed for learning** and is the teaching library for CMU's 15-322 Intro to Computer Music. Its primary purpose is to provide a _barebones foundation_ for working with audio in Python, e.g., allocating sample buffers, audio file decoding and playback. Accordingly, it intentionally lacks a lot of functionality found in full-fledged computer music programming frameworks, such as a rich collection of unit generators.
6
+
7
+ Want to try it without installing anything? [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/gclef-cmu/pyquist/blob/main/examples/HelloPyquist.ipynb)
8
+
9
+ ## Quick example
10
+
11
+ ```python
12
+ import numpy as np
13
+ import pyquist as pq
14
+
15
+ # A 1-second, 440 Hz sine wave at CD quality.
16
+ sr = 44100
17
+ t = np.arange(sr) / sr
18
+ audio = pq.Audio(0.5 * np.sin(2 * np.pi * 440 * t), sample_rate=sr)
19
+
20
+ pq.play(audio) # play through default output (or notebook widget)
21
+ pq.plot(audio) # waveform
22
+ pq.plot_spec(audio) # spectrogram
23
+ ```
24
+
25
+ Loading and transforming:
26
+
27
+ ```python
28
+ riff = pq.Audio.from_url(
29
+ "https://github.com/gclef-cmu/pyquist/raw/refs/heads/main/pyquist/test_data/388954__fullmetaljedi__blues-riff-in-g-nylon.wav"
30
+ )
31
+ clip = riff.segment(offset=5.0, duration=3.0).resample(8000)
32
+ pq.play(clip)
33
+ ```
34
+
35
+ Rendering a `Score` with a custom instrument. An instrument is called as `instrument(**event.kwargs)` — declare the kwargs you use and absorb the rest with `**kwargs`:
36
+
37
+ ```python
38
+ from pyquist.score import Score, Event, BasicMetronome
39
+ from pyquist.helper import pitch_to_frequency
40
+
41
+ def sine_instrument(pitch, duration, **kwargs):
42
+ sr = 44100
43
+ t = np.arange(int(duration * sr)) / sr
44
+ freq = pitch_to_frequency(pitch)
45
+ return pq.Audio(0.3 * np.sin(2 * np.pi * freq * t) * np.exp(-3 * t), sample_rate=sr)
46
+
47
+ score = Score([
48
+ Event(0, {"pitch": 60, "duration": 0.5}),
49
+ Event(1, {"pitch": 64, "duration": 0.5}),
50
+ Event(2, {"pitch": 67, "duration": 0.5}),
51
+ ])
52
+ pq.play(score.render(sine_instrument, metronome=BasicMetronome(120)))
53
+ ```
54
+
55
+ For a guided walkthrough — visualization, MIDI parsing, scores, instruments — open [`examples/HelloPyquist.ipynb`](examples/HelloPyquist.ipynb) or [run it in Colab](https://colab.research.google.com/github/gclef-cmu/pyquist/blob/main/examples/HelloPyquist.ipynb).
56
+
57
+ ## Installation
58
+
59
+ Requires **Python 3.10 or later**.
60
+
61
+ ### macOS
62
+
63
+ ```sh
64
+ brew install python@3.10 # or 3.11, 3.12, 3.13
65
+ python3.10 -m venv .venv
66
+ source .venv/bin/activate
67
+ pip install --upgrade pyquist
68
+ ```
69
+
70
+ If `pq.play(...)` is silent, give Terminal (or your IDE) microphone/audio access in **System Settings → Privacy & Security → Microphone**.
71
+
72
+ ### Linux
73
+
74
+ Install Python and the PortAudio system library that `sounddevice` wraps:
75
+
76
+ ```sh
77
+ # Debian / Ubuntu
78
+ sudo apt install python3 python3-venv libportaudio2
79
+
80
+ # Fedora
81
+ sudo dnf install python3 python3-virtualenv portaudio
82
+
83
+ python3 -m venv .venv
84
+ source .venv/bin/activate
85
+ pip install --upgrade pyquist
86
+ ```
87
+
88
+ ### Windows
89
+
90
+ Install [Python](https://www.python.org/downloads/) (3.10 or later, with "Add Python to PATH" checked), then open **Command Prompt**:
91
+
92
+ ```bat
93
+ python -m venv .venv
94
+ .venv\Scripts\activate.bat
95
+ pip install --upgrade pyquist
96
+ ```
97
+
98
+ ### From source
99
+
100
+ For hacking on pyquist itself:
101
+
102
+ ```sh
103
+ git clone https://github.com/gclef-cmu/pyquist.git
104
+ cd pyquist
105
+ python3 -m venv .venv
106
+ source .venv/bin/activate
107
+ pip install -e ".[dev,notebook]"
108
+ pre-commit install
109
+ ```
110
+
111
+ ### Pick default audio devices
112
+
113
+ Once installed, the `pyquist` CLI lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):
114
+
115
+ ```sh
116
+ pyquist devices
117
+ ```
118
+
119
+ ### Run notebooks
120
+
121
+ ```sh
122
+ pip install jupyter ipykernel ipywidgets
123
+ python -m ipykernel install --user --name=pyquist --display-name "Pyquist"
124
+ cd examples
125
+ jupyter notebook
126
+ ```
127
+
128
+ Then open [`HelloPyquist.ipynb`](examples/HelloPyquist.ipynb) and select the **Pyquist** kernel.
129
+
130
+ ## Acknowledgements
131
+
132
+ Inspired in part by:
133
+
134
+ - [Nyquist](https://sourceforge.net/projects/nyquist/)
135
+ - [Tone.js](https://tonejs.github.io/)
136
+ - [JUCE](https://juce.com/)
@@ -0,0 +1,95 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pyquist"
7
+ dynamic = ["version"]
8
+ description = "Barebones utilities for low-level computer music programming in Python and NumPy. Teaching library for CMU 15-322."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ authors = [{ name = "Chris Donahue" }]
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ keywords = ["audio", "music", "dsp", "midi", "numpy", "computer-music", "education"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Education",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Multimedia :: Sound/Audio",
25
+ "Topic :: Scientific/Engineering",
26
+ "Typing :: Typed",
27
+ ]
28
+ dependencies = [
29
+ "matplotlib",
30
+ "mido",
31
+ "numpy>=2.0",
32
+ "requests",
33
+ "resampy",
34
+ "sounddevice",
35
+ "soundfile",
36
+ "tqdm",
37
+ ]
38
+
39
+ [project.optional-dependencies]
40
+ dev = [
41
+ "mypy>=1.13",
42
+ "pre-commit>=4.0",
43
+ "ruff>=0.8",
44
+ ]
45
+ notebook = [
46
+ "ipython",
47
+ ]
48
+ docs = [
49
+ "sphinx>=7",
50
+ "sphinx-autodoc-typehints>=2",
51
+ ]
52
+
53
+ [project.urls]
54
+ Homepage = "https://gclef-cmu.org/pyquist"
55
+ Documentation = "https://gclef-cmu.org/pyquist"
56
+ Repository = "https://github.com/gclef-cmu/pyquist"
57
+ Issues = "https://github.com/gclef-cmu/pyquist/issues"
58
+
59
+ [project.scripts]
60
+ pyquist = "pyquist.cli:main"
61
+
62
+ [tool.setuptools.dynamic]
63
+ version = { attr = "pyquist.__version__" }
64
+
65
+ [tool.setuptools.packages.find]
66
+ include = ["pyquist*"]
67
+ exclude = ["examples*", "docs*"]
68
+
69
+ # Ship the bundled audio + MIDI samples (used by the HelloPyquist notebook,
70
+ # the README examples, and the test suite). Total ~2 MB.
71
+ [tool.setuptools.package-data]
72
+ # py.typed: PEP 561 marker so downstream type checkers honor our type hints.
73
+ pyquist = ["py.typed", "test_data/*"]
74
+
75
+ [tool.ruff]
76
+ line-length = 88
77
+ target-version = "py310"
78
+
79
+ [tool.ruff.lint]
80
+ # E203: whitespace before ':' (conflicts with formatter)
81
+ # E501: line too long (formatter handles wrapping; soft limit only)
82
+ # E731: do not assign a lambda expression
83
+ extend-select = ["I"] # isort
84
+ ignore = ["E203", "E501", "E731"]
85
+
86
+ [tool.ruff.lint.isort]
87
+ known-first-party = ["pyquist"]
88
+
89
+ [tool.mypy]
90
+ python_version = "3.10"
91
+ ignore_missing_imports = true
92
+
93
+ [[tool.mypy.overrides]]
94
+ module = "requests.*"
95
+ ignore_missing_imports = true
@@ -0,0 +1,40 @@
1
+ __version__ = "0.1.0"
2
+
3
+ from .audio import Audio
4
+ from .device import (
5
+ play,
6
+ record,
7
+ set_input_device,
8
+ set_output_device,
9
+ )
10
+ from .paths import LIB_DIR
11
+ from .plot import plot, plot_freq, plot_spec
12
+ from .score import (
13
+ BasicMetronome,
14
+ Event,
15
+ Metronome,
16
+ Score,
17
+ )
18
+
19
+ __all__ = [
20
+ "__version__",
21
+ "Audio",
22
+ "BasicMetronome",
23
+ "Metronome",
24
+ "Score",
25
+ "Event",
26
+ "play",
27
+ "plot",
28
+ "plot_freq",
29
+ "plot_spec",
30
+ "record",
31
+ "set_input_device",
32
+ "set_output_device",
33
+ ]
34
+
35
+
36
+ # NOTE: This changes the test discovery pattern from "test*.py" (default) to "*test.py".
37
+ def load_tests(loader, standard_tests, pattern):
38
+ package_tests = loader.discover(start_dir=LIB_DIR, pattern="*test.py")
39
+ standard_tests.addTests(package_tests)
40
+ return standard_tests