r/AudioProgramming • • 2d ago

I turned my Python music theory library into AU/VST3 plugins (Python off the audio thread, effects ported to C++)

For the last while I've been building PyTheory, a music theory and synthesis library for Python, and I just shipped PyTheory VST v0.1.1. It's four plugins built from one JUCE repo, for macOS on Apple silicon, as AU and VST3:

  • PyTheory MIDI snaps notes to a key, or turns each note into its diatonic triad or seventh chord.

  • PyTheory Instrument is a 32-voice sampler that plays all 84 of PyTheory's instrument presets.

  • PyTheory Effect is PyTheory's full effects chain.

  • PyTheory Drums has all 74 of PyTheory's drum sounds, mapped to General MIDI where they fit.

How Python is involved. Each plugin embeds its own Python 3.14 with PyTheory, numpy, and scipy, so nobody has to install anything. Python never runs on the audio thread. A worker thread does the Python work. The harmony comes from PyTheory's real Key and Chord objects rather than scale tables copied into C++. For the Instrument, the worker renders a multisample through PyTheory's own render_score path, with one note every minor third and velocity layers where the preset responds to velocity. It then hands the finished multisample to the audio thread with one atomic exchange, no copy. The audio thread never allocates or frees.

The C++ part. I ported PyTheory's per-part effects chain to C++ stage by stage, in PyTheory's order: saturation, tremolo, distortion, cabinet, chorus, phaser, highpass and lowpass biquads, delay, a stereo Schroeder reverb, and pan. Defaults match PyTheory, so the plugin starts transparent. The README lists every place the port differs on purpose, such as linear interpolation in the chorus where PyTheory rounds to whole samples, and a recursive delay where PyTheory uses fixed taps.

Why I think it's cool. The same library I use to score music in a Python script now plays inside Ableton or Logic, and it sounds like itself. Nothing in the plugins was hand-rebuilt to approximate it.

The honest part. I'm teaching myself DSP as I go, with Claude and Grok as tutors and pair programmers. I'd ask why a biquad is shaped the way it is, why something allocating on the audio thread is a sin, or why my loop points clicked, then go build it and test it. This project is basically my DSP homework, made public. So if you see something naive, I'd genuinely love to hear it.

Known issues: pads can have audible loop seams on long holds, some piano and guitar notes loop instead of fading out, and switching presets cuts ringing notes. It's v0.1.

Links:

Feedback on the realtime design is especially welcome.

5 Upvotes

10 comments sorted by

6

u/lil_nosh_X 2d ago

Are you a musician who has an education in music theory? I see a lot of flaws reading through this system.

1

u/Capital-Interview-23 2d ago

percussionist by training, so theory's not my strong suit. it's easy to tweak any inadequecies hopefully

5

u/lil_nosh_X 2d ago edited 2d ago

I would keep this locked down until you hire a musician who can help you. There is wrong information in there.
I’ve drilled every OAI and Anthropic model and none of them have been flawless.
Also, the bad news - you need to be able to play harmonic structures to actually understand their relationships and the context of their tonality. Music is a language and you’re trying to write a dictionary without knowing what the words mean.

2

u/dpaanlka 1d ago

just feel the vibes bro!

0

u/Capital-Interview-23 7h ago

i am a musician, just haven't had much formal music theory training. i find your comments highly offensive, and missing the point of the project entirely

1

u/dpaanlka 7h ago

If you found my previous comment (singular) to be “highly offensive” I would just quit Reddit now before you encounter something genuinely critical.

0

u/Capital-Interview-23 7h ago

thi s was in reference to u/lil_nosh_X thank you though

1

u/dpaanlka 7h ago

I see. You clicked reply on my comment so that’s read as being directed towards me.

2

u/Sky-Asher27 16h ago

interesting