mirror of
https://github.com/kennethreitz/pytheory.git
synced 2026-06-05 23:00:20 +00:00
Compare commits
294 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b8d1fe5e81 | |||
| 2612444146 | |||
| 48a954d063 | |||
| 8a07be23e6 | |||
| d771117d5c | |||
| 1ae9404f07 | |||
| 2e5b18de2e | |||
| 248594fb21 | |||
| 3ce890c54c | |||
| 499c49b6eb | |||
| f85504b456 | |||
| d0624f8b78 | |||
| fb37a7c27b | |||
| fb36e75a42 | |||
| 81b54d2394 | |||
| fa6a3090cb | |||
| 58286ddb69 | |||
| 6d137be9f5 | |||
| 383802a1e1 | |||
| 7f2aeb2395 | |||
| 16b4c7d1fa | |||
| b9ee5c9cde | |||
| 7375d58209 | |||
| 6316a6c910 | |||
| 237cfe171c | |||
| 1751f97617 | |||
| 943a12b3bb | |||
| 04d2de3e70 | |||
| ead42751ef | |||
| 8dee0d00d8 | |||
| de112e0d9f | |||
| f469ad90f8 | |||
| bab7f39304 | |||
| 62557ba534 | |||
| 8b50a9c325 | |||
| 7e9caac70b | |||
| a0756b3172 | |||
| e3dd706032 | |||
| 9b412906bc | |||
| 54e0421997 | |||
| 109343ad30 | |||
| 28e84de566 | |||
| d353d64298 | |||
| 7ee02e7ed2 | |||
| a5c9a46eb2 | |||
| f9c63ec360 | |||
| b9e88b77d8 | |||
| 1910b09132 | |||
| 0c5287450b | |||
| 5ac1873d83 | |||
| 9fafca2b08 | |||
| af044f68ca | |||
| 60f697f846 | |||
| 7d678e364e | |||
| 3a8d829010 | |||
| 2a67906937 | |||
| b9dcad0454 | |||
| db9726168a | |||
| 26af923789 | |||
| 72e18a9bec | |||
| 7d56ed7a2c | |||
| 6efa4f18ce | |||
| 06fc4cabb7 | |||
| d3a93c18b3 | |||
| 0e10359236 | |||
| df00c3436d | |||
| 2f02df15b8 | |||
| a2740b8d57 | |||
| 840bfcc36c | |||
| 938c1cc132 | |||
| 9dc22db4b2 | |||
| f570e226cd | |||
| 0c5c3abedc | |||
| 35d07b984b | |||
| aec7723ee6 | |||
| b98a40297b | |||
| 9117568b74 | |||
| 11e4417c62 | |||
| 4edf1d983d | |||
| 74b07b1a8a | |||
| c9437209a7 | |||
| 92cb855a49 | |||
| f06c6f77d1 | |||
| 51bd63658f | |||
| 92ade3ee3d | |||
| 833867329e | |||
| 93b9fe9ced | |||
| 88a1171bbe | |||
| 3ca0842b7a | |||
| 00de5eb354 | |||
| d2b0c6f329 | |||
| 76612682f1 | |||
| ce480858e9 | |||
| 70efb0ad40 | |||
| bf6deaab64 | |||
| 7c792c0a2a | |||
| bf8d4b9a77 | |||
| d2d5115c8a | |||
| 3cdd98b158 | |||
| 751d5a49b8 | |||
| 6a836dd891 | |||
| 1f888e2b21 | |||
| fb923f6c76 | |||
| 59e3338892 | |||
| 8cf4145c15 | |||
| b3885b2c15 | |||
| ae04fa60cc | |||
| 6c411e43f8 | |||
| e0427af3cc | |||
| 552836ae5b | |||
| 0fe53fcdeb | |||
| f6fb2a2cd6 | |||
| 70d6e6b8ce | |||
| aec9a999cb | |||
| 3acde86028 | |||
| aa405702a9 | |||
| b7c018fb94 | |||
| 07a52a3a25 | |||
| e12cb9003b | |||
| 28968a1b5c | |||
| 8a4a2df1aa | |||
| f4a90637db | |||
| 90a1a31049 | |||
| 33b2e82594 | |||
| 9f8dd0006d | |||
| 417f7f74a3 | |||
| cd6f814049 | |||
| 83fcdb0a09 | |||
| aa21bf0f2a | |||
| e7e35ad4e4 | |||
| 503dbce937 | |||
| c6bbfae7e6 | |||
| 64ef7f0803 | |||
| 406e5d7e54 | |||
| 267b7284ba | |||
| 9b62b56120 | |||
| 4fe7771d83 | |||
| 57079a43ac | |||
| 1d07b06968 | |||
| 9887b59cfb | |||
| 9850a8016e | |||
| 35f5f35dc5 | |||
| 47ca94111f | |||
| 62cfbb2591 | |||
| de855a3fe6 | |||
| dc9f7b3342 | |||
| 60fdff6d36 | |||
| f42d38d1fd | |||
| 5a4122d61f | |||
| 3e4ba54a32 | |||
| 5dd1c5e15d | |||
| e46732fb5a | |||
| 833ab56857 | |||
| 6b2b1e201e | |||
| f9c81fe05f | |||
| 931ec905c3 | |||
| 799ffbdac9 | |||
| b29b33524f | |||
| 25f25c1f23 | |||
| 3f1d632285 | |||
| 1938037458 | |||
| f7c05e1b31 | |||
| c375785bb9 | |||
| 9ebd54b7fc | |||
| ce68ad8f19 | |||
| f402e76480 | |||
| 4d3c7e0d6c | |||
| 5a74a6f715 | |||
| 5416674858 | |||
| 9a5f305ac6 | |||
| bc38ce73f0 | |||
| 081b924d29 | |||
| 427ff44ce9 | |||
| 360a908464 | |||
| a8dd4d6542 | |||
| 866b110afa | |||
| 0fc0b87017 | |||
| 1a724a94b0 | |||
| b239e9a997 | |||
| a766737707 | |||
| 0843c21884 | |||
| eb7a2bf27d | |||
| c78530611d | |||
| 7267d25fb5 | |||
| 53db299b5f | |||
| a4fa233edf | |||
| e7e90382c5 | |||
| 1ef32ecc92 | |||
| f9af708f0a | |||
| 0e93e45853 | |||
| f0802ae614 | |||
| 4a992eba2b | |||
| 398cc68166 | |||
| 3b0a63d57c | |||
| c86ae7b118 | |||
| d2044f1f53 | |||
| 7991516c3e | |||
| a0e0dbc807 | |||
| a77db557f3 | |||
| f4c3b2dd88 | |||
| 32387e2d23 | |||
| 2ecb1e5ce8 | |||
| 30dacc4fbf | |||
| 2a5ffcf78a | |||
| fe00644e3f | |||
| 89df5c4201 | |||
| b396f42f84 | |||
| 45789f7af0 | |||
| e0bf637de5 | |||
| e5f258bc21 | |||
| a294887215 | |||
| 20932f48ab | |||
| 9e0faf840b | |||
| c7c733044c | |||
| 866065d7d7 | |||
| aa9d4282c9 | |||
| 3593735243 | |||
| 54fd4c2241 | |||
| a4b11e6f35 | |||
| 044e9a7eac | |||
| 094887c849 | |||
| 2fc5aae678 | |||
| ac0cc0b6ce | |||
| ce5f3e7626 | |||
| 0c4ba83b0c | |||
| f81b1e882d | |||
| ebf26cfbfa | |||
| f9654fcdea | |||
| f3f4174783 | |||
| 119dd2d921 | |||
| 80698ccc3a | |||
| a41f20e805 | |||
| 2de263c814 | |||
| a7ad8a374b | |||
| e75c35a099 | |||
| b9f0a3870a | |||
| d425d6b624 | |||
| 8c61cb146b | |||
| a11523e889 | |||
| cf061e3783 | |||
| 5d746ed0b1 | |||
| 89323c0eb3 | |||
| 5a44d619d0 | |||
| f5bf7ce505 | |||
| 4f3b706336 | |||
| 83a988d085 | |||
| d0e8e43b56 | |||
| c67a08a34e | |||
| e72ef4a6a7 | |||
| 994c4e244a | |||
| adfbc3079a | |||
| 772fa84b4f | |||
| b97378c836 | |||
| f00cf10c41 | |||
| d57e780f6f | |||
| 4f03bb6616 | |||
| 4aafd8d0b0 | |||
| c74600d42f | |||
| b3ef0ddc58 | |||
| dd3b7bd03e | |||
| 62111de2da | |||
| c3ae02ec4f | |||
| f4d2cca663 | |||
| 3b5a07dfce | |||
| aa454ea7e9 | |||
| 5aed586187 | |||
| 09d90b3425 | |||
| 96131da59c | |||
| d2058668a6 | |||
| a5ffdc6104 | |||
| 724a0df7b5 | |||
| 4750061b87 | |||
| d53d8b60dd | |||
| de1db0aa8d | |||
| b22b3c063f | |||
| 7e1d9e76bd | |||
| 447d03a2d2 | |||
| 7b82d70ad6 | |||
| 44f8b902e2 | |||
| 03eb61cd5d | |||
| eba299d406 | |||
| d11c930308 | |||
| 19663ed6c5 | |||
| f949ca5b45 | |||
| d9f847603a | |||
| ee41691728 | |||
| 02df87af09 | |||
| b3110c6e0e | |||
| fd82dccbfd | |||
| 6f7f9008b0 | |||
| acb92171a1 | |||
| c006f5b3da | |||
| 9da3ac8b28 | |||
| e94ef5dcfd |
+684
@@ -0,0 +1,684 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to PyTheory are documented here.
|
||||
|
||||
## 0.40.0
|
||||
|
||||
- **Rhodes electric piano synth** — tine + tonebar + electromagnetic
|
||||
pickup model. `electric_piano` preset now uses dedicated `rhodes_synth`
|
||||
instead of FM
|
||||
- **73 audio demos in docs** — every synth, every drum pattern, every
|
||||
code example with `play_score()` now has an embedded audio player
|
||||
- Idiomatic demos: harp arpeggiates, guitars strum, cello bows, sitar
|
||||
drones, strings use ensemble
|
||||
- Trailing silence trimming on all audio exports
|
||||
- Raw waveform demos (no envelope) for classic waveforms
|
||||
|
||||
## 0.39.3
|
||||
|
||||
- **33 audio samples in documentation** — every `play_score()` example
|
||||
now has an embedded stereo audio player. Covers quickstart, sequencing,
|
||||
drums (all world percussion), playback, and cookbook.
|
||||
- **`docs/generate_audio.py`** — renders all doc examples to WAV
|
||||
- Numpy vectorization: cached time arrays, decay envelopes, drum hits;
|
||||
vectorized piano harmonic synthesis
|
||||
- Fixed acid legato example (removed pad envelope, added proper 303 recipe)
|
||||
|
||||
## 0.39.2
|
||||
|
||||
- **Marching percussion** — snare, rimshot, and stick click sounds with
|
||||
high-tension kevlar synthesis and woody-metallic rimshot crack
|
||||
- **`Part.flam()`**, **`Part.diddle()`**, **`Part.cheese()`** — marching
|
||||
rudiment methods for any drum sound
|
||||
- **`Part ensemble=`** — duplicate voices with per-player timing tendencies
|
||||
and micro pitch drift. Works on any Part (drumline, string section, choir).
|
||||
`ensemble=20` for a full snare line, `ensemble=4` for a string quartet.
|
||||
- **Sympathetic resonance** — marching snare buzz builds up with repeated
|
||||
hits, decays during rests (like real snare wire response)
|
||||
- **4 marching patterns** — march, cadence, paradiddle, roll
|
||||
- **Chakradar tabla pattern** — 16-beat tihai of tihais composition
|
||||
- Song #32: Snare Cadence (flams, diddles, cheese, triplets, 32nds)
|
||||
|
||||
## 0.39.1
|
||||
|
||||
- **Chakradar tabla pattern** — 16-beat tihai of tihais composition with
|
||||
3 escalating phrases and a crescendo triplet finale
|
||||
|
||||
## 0.39.0
|
||||
|
||||
- **Dropped `numeral` dependency** — Roman numeral helpers inlined,
|
||||
reducing supply chain surface (#47)
|
||||
- **`Part.ramp()`** — smooth parameter automation with 4 interpolation
|
||||
curves (linear, ease_in, ease_out, ease_in_out)
|
||||
- **Articulations** — staccato, legato, marcato, tenuto, accent, fermata
|
||||
- **Dynamic curves** — crescendo(), decrescendo(), swell(), dynamics()
|
||||
- **`Part.hit()`** — individual drum sounds with articulation support
|
||||
- **Cross-choke drum damping** — djembe, hi-hats, cajón, doumbek
|
||||
- **5 new djembe patterns** + 3 djembe fills (30 fills total)
|
||||
- **6 new drum fills** — 3 cajón, 3 metal
|
||||
- **Duration arithmetic** — multiply, divide, add
|
||||
- **Improved djembe slap** synthesis
|
||||
- Song #31: Acid Tabla
|
||||
|
||||
## 0.38.2
|
||||
|
||||
- **`Part.ramp()`** — smooth parameter automation from current value to
|
||||
target over a duration. Works for lowpass, reverb, distortion, chorus,
|
||||
delay, volume, and any `.set()` parameter. Four interpolation curves:
|
||||
linear, ease_in, ease_out, ease_in_out.
|
||||
|
||||
## 0.38.1
|
||||
|
||||
- **Dynamic curves** — `Part.crescendo()`, `Part.decrescendo()`,
|
||||
`Part.swell()`, and `Part.dynamics()` for velocity ramps and custom
|
||||
curves across a sequence of notes
|
||||
|
||||
## 0.38.0
|
||||
|
||||
- **Articulations** — `staccato`, `legato`, `marcato`, `tenuto`, `accent`,
|
||||
`fermata` via `articulation=` on `Part.add()` and `Part.hold()`
|
||||
- **`Part.hit()`** — place individual drum sounds in a Part's note stream
|
||||
with articulation, velocity, and effects support
|
||||
- **5 new djembe patterns** — dununba, tiriba, yankadi, djansa, mendiani
|
||||
- **3 new djembe fills** — djembe call, djembe roll, djembe break (30 fills total)
|
||||
- **Cross-choke drum damping** — striking one sound fades out related sounds
|
||||
(djembe, hi-hats, cajón, doumbek)
|
||||
- **Improved djembe slap** — dry goatskin pop instead of snare-like noise
|
||||
|
||||
## 0.37.0
|
||||
|
||||
- **5 new djembe patterns** — dununba, tiriba, yankadi, djansa, mendiani
|
||||
- **3 new djembe fills** — djembe call, djembe roll, djembe break (30 fills total)
|
||||
- **Cross-choke drum damping** — striking one sound on a hand drum fades
|
||||
out the ring of related sounds (djembe slap kills bass resonance, closed
|
||||
hat chokes open hat, cajón slap dampens bass, doumbek tek dampens dum)
|
||||
- **Improved djembe slap** — dry, high-pitched goatskin pop instead of
|
||||
snare-like noise rattle
|
||||
|
||||
## 0.36.6
|
||||
|
||||
- **6 new drum fills** — 3 cajón (flam, rumble, breakdown) and 3 metal
|
||||
(triplet, blast, cascade). 27 fills total.
|
||||
- Updated drums documentation with fill lists and examples
|
||||
|
||||
## 0.36.5
|
||||
|
||||
- **Duration arithmetic** — `Duration.WHOLE * 2`, `Duration.HALF + Duration.QUARTER`,
|
||||
division, and reverse multiply all work now (previously raised TypeError)
|
||||
|
||||
## 0.36.3
|
||||
|
||||
- **`Part.hold()`** — polyphonic overlap on a single part. Add notes
|
||||
without advancing the beat position so they play simultaneously.
|
||||
Enables: piano sustain, sitar drone under melody, guitar strum texture.
|
||||
- **Strum uses hold()** — leading string plays simultaneously with chord,
|
||||
no more timing gaps or choppiness
|
||||
- **Improved songs** 1-16: humanize, velocity dynamics, reverb, saxophone
|
||||
for blues
|
||||
- **Ctrl-C handling** — clean stop on all playback functions
|
||||
- **REPL updates** — strum, roll, bend, temperament, reference commands
|
||||
- Song #28 Descent (generative), #29 Pop Rock, #30 Sitar Drone
|
||||
- 862 tests
|
||||
|
||||
## 0.36.1
|
||||
|
||||
- **7 new instrument synths:** pedal steel guitar, theremin, kalimba/thumb
|
||||
piano, steel drum/pan, accordion (musette reeds), didgeridoo (drone +
|
||||
shifting formants), bagpipes (chanter reed)
|
||||
- **9 new demo moods** in ``pytheory demo``: Theremin Noir, Caribbean,
|
||||
Accordion Waltz, Kalimba Dreams, Outback Drone, Highland, Nashville
|
||||
Tears, Tabla Fusion
|
||||
- Improved existing songs with dedicated instrument synths
|
||||
- 41 synth waveforms, 26+ songs, 21 demo moods
|
||||
|
||||
## 0.36.0
|
||||
|
||||
- **Banjo synth** — steel strings on drum-head body, nasal twang,
|
||||
fast decay with membrane resonance
|
||||
- **Mandolin synth** — paired steel strings (natural chorus from
|
||||
doubled courses), bright body resonance
|
||||
- **Ukulele synth** — nylon strings, small mid-heavy body, shorter
|
||||
sustain than guitar
|
||||
- **Cajón drums** — bass (woody box thump), slap (snare wire buzz),
|
||||
tap (ghost note). 3 patterns: cajon, cajon rumba, cajon folk
|
||||
- **Vocal/formant synth** — LF glottal model, 5 Peterson & Barney
|
||||
formant peaks, jitter/shimmer, consonant onsets, per-note lyrics.
|
||||
Presets: vocal, choir
|
||||
- **Granular synthesis** — grain cloud engine with scatter, pitch
|
||||
variation, Hanning windows. Presets: granular_pad, granular_texture
|
||||
- **Strum sweep** — subtle grace notes before chord hit for natural
|
||||
strum feel on all fretboard instruments
|
||||
- Mandola preset, 34 synth waveforms, 26 songs
|
||||
|
||||
## 0.35.0
|
||||
|
||||
- **8.5x faster import** — dropped pytuning/sympy, lazy-load scipy.
|
||||
`import pytheory` now takes ~50ms instead of ~480ms (#44)
|
||||
- **Proper shruti JI ratios** — 22 positions with 5-limit just intonation
|
||||
(pure 3/2 fifths, 5/4 thirds), not 22-TET approximation
|
||||
- **Arabic maqam JI ratios** — Zalzalian 11-limit ratios.
|
||||
Mi↓ (the Rast third) is exactly 27/22 from Do
|
||||
- **B#/Cb octave boundary fix** — B#4 = C5, Cb4 = B3 (#45)
|
||||
- **Int tone names** — `Tone(0, system=TET(22))` works alongside strings.
|
||||
Wrapping: `Tone(22)` → tone 0, octave+1. `System.tone()` convenience.
|
||||
- **Timpani synth** — inharmonic membrane modes, felt mallet, copper kettle
|
||||
resonance, cathedral reverb
|
||||
- **Saxophone synth** — conical bore, reed buzz, brass body warmth.
|
||||
4 presets: saxophone, alto_sax, tenor_sax, bari_sax
|
||||
- **Part.roll()** — rapid repeated notes with velocity ramp for crescendo/
|
||||
decrescendo rolls on any instrument
|
||||
- **Vibrato tuning** — all instruments reduced to 0.001 depth for cleaner
|
||||
ensemble sound
|
||||
- **Granular synthesis** — grain cloud engine with scatter, pitch
|
||||
variation, and Hanning-windowed grains. Two presets: granular_pad,
|
||||
granular_texture.
|
||||
- 30 synth waveforms, 838 tests
|
||||
|
||||
## 0.34.0
|
||||
|
||||
- **16 dedicated instrument synths** — physical modeling and specialized
|
||||
synthesis for: piano (hammer + steel strings + soundboard), bass guitar
|
||||
(thick KS + pickup), flute (breath + tube resonance), trumpet (lip buzz
|
||||
+ bell), clarinet (odd harmonics + reed), oboe (double reed + conical
|
||||
bore), marimba (inharmonic bar modes), harpsichord (quill pluck),
|
||||
cello (deep bowed + body), harp (soft pluck + soundboard bloom),
|
||||
upright bass (pizzicato + wooden body), acoustic guitar (KS + body
|
||||
resonance), electric guitar (KS + pickup comb filter), sitar (jawari
|
||||
+ chikari), plus organ and bowed strings
|
||||
- **Speaker cabinet simulation** — tames distorted guitar fizz
|
||||
- **Guitar strumming** — `Part.strum("Am")` with fretboard lookup
|
||||
- **Analog oscillator drift** — subtle per-note pitch wobble on synth presets
|
||||
- **World percussion:** dhol, dholak, mridangam, djembe, metal kit
|
||||
with 22 new drum patterns
|
||||
- **Piano improvements:** brightness scales with pitch, two-stage decay,
|
||||
hammer impact with felt character
|
||||
- **Vibrato tuning:** reduced across flute, oboe, trumpet, cello for
|
||||
smoother ensemble sound
|
||||
- 27 synth waveforms, 10 envelopes, 40+ instrument presets, 80+ drum patterns
|
||||
|
||||
## 0.33.1
|
||||
|
||||
- **Electric guitar synth** — Karplus-Strong with magnetic pickup comb filter
|
||||
simulation (single-coil honk, proper sustain)
|
||||
- **Speaker cabinet simulation** — steep rolloff above 4-5kHz with presence
|
||||
bump. Makes distorted guitar sound warm instead of fizzy.
|
||||
- **6 guitar presets:** electric_guitar, clean_guitar, crunch_guitar,
|
||||
distorted_guitar, orange_crunch, metal_guitar — all with proper cab sim
|
||||
- **Sitar synth** — Karplus-Strong with jawari bridge buzz, chikari
|
||||
sympathetic strings, variable damping
|
||||
- **Guitar strumming** — `Part.strum("Am", Duration.HALF)` with
|
||||
fretboard fingering lookup, down/up direction, adjustable strum speed
|
||||
- **World drums:** dhol (bhangra, chaal), dholak (qawwali, folk),
|
||||
mridangam (adi talam, korvai), djembe (standard, kuku, soli)
|
||||
— all with bandpass-filtered membrane noise for realistic drum head sound
|
||||
- **Metal drum kit** — clicky kick, bright snare, tight hats
|
||||
with 4 patterns (double kick, metal blast, metal groove, metal gallop)
|
||||
- 15 synth waveforms, 10 envelopes, 40+ instrument presets
|
||||
|
||||
## 0.33.0
|
||||
|
||||
- **Non-12-TET support** — `TET(n)` factory creates any equal temperament
|
||||
- **11 microtonal systems:**
|
||||
- `"shruti"` (22-TET Indian, 10 thaats with proper shruti intervals)
|
||||
- `"maqam"` (24-TET Arabic, quarter-tone Rast/Bayati/Hijaz + 7 more)
|
||||
- `"slendro"` (5-TET gamelan), `"pelog"` (9-TET gamelan with 3 pathet)
|
||||
- `"thai"` (7-TET, 171 cents/step)
|
||||
- `"makam"` (53-TET Turkish Arel-Ezgi-Uzdilek, 9 makams)
|
||||
- `"carnatic"` (72-TET, 10 melakartas)
|
||||
- `"19-tet"`, `"31-tet"` (historical Western)
|
||||
- `"bohlen-pierce"` (13 divisions of the tritave 3:1 — non-octave!)
|
||||
- **Just intonation** — `temperament="just"` for pure 5-limit ratios
|
||||
- **Historical pitch** — `Score(reference_pitch=415.0)` for Baroque A=415
|
||||
- **`Score(system=, temperament=, reference_pitch=)`** flows through to all playback
|
||||
- Per-system `c_index` and `period` replace hardcoded constants
|
||||
- Fixed all hardcoded `12`s in tone arithmetic
|
||||
- Song #22: Greensleeves (Renaissance lute, meantone, A=415)
|
||||
- 22 new microtonal tests (819 total)
|
||||
|
||||
## 0.32.1
|
||||
|
||||
- `Tone("X")` now raises `ValueError` immediately instead of silently accepting invalid names (#39)
|
||||
- Support enharmonic spellings: `Cb`, `Fb`, `E#`, `B#` resolve correctly (#40)
|
||||
- Support double sharps (`C##`, `Fx`) and double flats (`Dbb`) via semitone arithmetic (#41)
|
||||
- Accept unicode music symbols: `♯` `♭` `𝄪` `𝄫`
|
||||
|
||||
## 0.32.0
|
||||
|
||||
- **8 new synth engine features:**
|
||||
- Filter envelope: per-note lowpass sweep (`filter_amount`, `filter_attack`, `filter_decay`, `filter_sustain`)
|
||||
- Velocity → brightness: harder notes = brighter filter (`vel_to_filter`)
|
||||
- Sub-oscillator: octave-below sine for bass weight (`sub_osc`)
|
||||
- Tremolo: amplitude LFO modulation (`tremolo_depth`, `tremolo_rate`)
|
||||
- Saturation: even-harmonic tape/tube warmth (`saturation`)
|
||||
- Noise layer: per-note breath/air texture (`noise_mix`)
|
||||
- Phaser: swept allpass filter chain (`phaser`, `phaser_rate`)
|
||||
- Configurable FM: `fm_ratio` and `fm_index` params
|
||||
- **Highpass filter** (12 dB/oct biquad) on any part
|
||||
- **2 new envelopes:** `bowed` (bow attack with sustain), `mallet` (strike with ringing sustain)
|
||||
- **Improved `strings_synth`:** additive synthesis with body resonance curve, per-harmonic phase randomization, delayed vibrato onset, bow pressure variation
|
||||
- **Instrument preset overhaul:** every preset sanity-checked against real instrument behavior
|
||||
- Mallet instruments (vibraphone, celesta, music box, glockenspiel, tubular bells) now ring properly
|
||||
- Trumpet uses sustaining envelope instead of pluck
|
||||
- Woodwinds have breath noise, brass has velocity brightness
|
||||
- Bass instruments have sub-oscillators, synth presets have filter envelopes
|
||||
- Piano has velocity-to-brightness and subtle hammer noise
|
||||
- Signal chain: saturation → tremolo → distortion → chorus → phaser → highpass → lowpass → delay → reverb
|
||||
- Song #21: Cinematic Showcase (Orchestral)
|
||||
|
||||
## 0.31.0
|
||||
|
||||
- 3 new synth engines: Karplus-Strong pluck, Hammond organ, string ensemble with body formants
|
||||
- 38 instrument presets: `score.part("lead", instrument="violin")`
|
||||
- Keys, strings, woodwinds, brass, plucked, synth, and mallet categories
|
||||
- 13 total synth waveforms
|
||||
|
||||
## 0.30.0
|
||||
|
||||
- Drums are a real Part — same effects pipeline as any voice
|
||||
- `score.drums("rock", split=True)` splits kit into kick/snare/hats/toms/cymbals/percussion Parts
|
||||
- Each split Part gets independent effects (reverb on snare, LP on hats, etc.)
|
||||
- `set_drum_effects()` applies to all drum Parts (split or not)
|
||||
- Sidechain triggers on kick only — hats and snare don't duck the pad
|
||||
- MIDI import via `Score.from_midi(path)`
|
||||
|
||||
## 0.29.3
|
||||
|
||||
- Drums are now a real Part — same effects pipeline as any other voice, zero code duplication
|
||||
- `score.parts["drums"]` is a standard Part with reverb, delay, lowpass, etc.
|
||||
- `set_drum_effects()` is sugar over the Part's attributes
|
||||
|
||||
## 0.29.2
|
||||
|
||||
- Add `score.set_drum_effects()` — reverb, delay, lowpass, distortion, chorus on the drum bus
|
||||
- Same effects engine as parts, zero code duplication
|
||||
|
||||
## 0.29.1
|
||||
|
||||
- Rename song.py → songs.py
|
||||
- Polish all 20 example songs with stereo, convolution reverb, humanize, detune, sidechain
|
||||
|
||||
## 0.29.0
|
||||
|
||||
- Add `Score.from_midi(path)` — import any Standard MIDI File into a Score
|
||||
- Minimal zero-dependency MIDI parser (Type 0 and Type 1)
|
||||
- Each channel becomes a named Part, channel 10 becomes drum hits
|
||||
- Tempo, time signature, velocities, and note durations preserved
|
||||
- Roundtrip: save_midi → from_midi works
|
||||
|
||||
## 0.28.3
|
||||
|
||||
- Rewrite `pytheory demo` — 8 moods with stereo, effects, humanize, convolution reverb, sidechain
|
||||
- Added Dub and Temple moods
|
||||
|
||||
## 0.28.2
|
||||
|
||||
- Lower drum_humanize default to 0.15 — tighter, more professional feel
|
||||
|
||||
## 0.28.1
|
||||
|
||||
- Humanize drum hits — random timing jitter and velocity variation (default 0.3)
|
||||
- Control via `Score(drum_humanize=0.5)` — 0.0 = quantized, 0.3 = natural, 0.5+ = loose
|
||||
|
||||
## 0.28.0
|
||||
|
||||
- Add figured bass notation: `Chord.figured_bass` and `Chord.analyze_figured()` for classical inversion symbols
|
||||
- Add pitch class set theory: `pitch_classes`, `normal_form`, `prime_form`, `forte_number` on Chord
|
||||
- Add `Scale.recommend()` — ranked scale suggestions for a set of notes
|
||||
- Forte number catalog covers all trichords and tetrachords
|
||||
|
||||
## 0.27.1
|
||||
|
||||
- Tab completion in REPL — context-aware for commands, drum presets, synths, envelopes, chords, notes, systems
|
||||
|
||||
## 0.27.0
|
||||
|
||||
- Rewrite all 15 drum sounds for higher quality (inharmonic partials, proper transients, multi-mode resonance, saturation)
|
||||
- 19 example songs including Dance Party at the Reitz House
|
||||
|
||||
## 0.26.3
|
||||
|
||||
- Stereo drum panning — each sound placed in the stereo field (hat right, crash left, toms spread, kick/snare center)
|
||||
- Stereo convolution reverb — different IR per L/R channel for all 7 presets
|
||||
- 2 new songs: Neon Grid (stereo acid), Glass and Silk (sine+triangle waltz)
|
||||
|
||||
## 0.26.2
|
||||
|
||||
- Stereo convolution reverb — different IR per L/R channel for all 7 presets
|
||||
- Both algorithmic and convolution reverbs now output true stereo
|
||||
|
||||
## 0.26.1
|
||||
|
||||
- Stereo reverb — L and R channels get different early reflection patterns for natural width
|
||||
- Effects chain now skips mono reverb in favor of stereo reverb in the mixer
|
||||
|
||||
## 0.26.0
|
||||
|
||||
- **Stereo output** — render_score() now returns stereo (N, 2) arrays
|
||||
- Add `pan` parameter: -1.0 (left) to 1.0 (right), constant-power panning
|
||||
- Add `spread` parameter: detuned oscillators spread across L/R channels
|
||||
- Master bus compressor runs per-channel for stereo
|
||||
- All playback functions handle stereo natively
|
||||
|
||||
## 0.25.7
|
||||
|
||||
- Add `detune` parameter — ±cents oscillator spread on any synth (3 oscillators per note)
|
||||
- Swing now applies to drum hits (offbeats shift with the groove)
|
||||
- Improved snare and hi-hat sounds (metallic harmonics, faster attack)
|
||||
|
||||
## 0.25.6
|
||||
|
||||
- Swing now applies to drum hits — offbeats shift with the groove, everything locks into the same pocket
|
||||
- Improved snare: 220Hz body, transient click, tanh saturation
|
||||
- Improved hi-hats: metallic harmonics (6k+8.5k+12k Hz), crisper attack, shorter decay
|
||||
|
||||
## 0.25.5
|
||||
|
||||
- Improved snare: 220Hz body, transient click, tanh saturation — snappier and more present
|
||||
- Improved hi-hats: metallic harmonics (6k+8.5k+12k Hz), shorter decay, crisper attack
|
||||
|
||||
## 0.25.4
|
||||
|
||||
- Add master bus compressor/limiter — louder, punchier, more cohesive mixes
|
||||
- Feed-forward compression with configurable threshold, ratio, attack, release
|
||||
- Makeup gain restores loudness after compression
|
||||
- Brick-wall limiter at 0.95 prevents clipping
|
||||
- Replaces simple normalization in render_score()
|
||||
|
||||
## 0.25.3
|
||||
|
||||
- Add `pytheory repl` — interactive music theory scratchpad and composition tool
|
||||
- Context-aware prompt shows key, bpm, drums, active part + effects
|
||||
- Theory commands: key, chords, modes, scales, circle, interval, identify, system
|
||||
- Composition: drums, part, add, rest, arp, prog, effects, automation, LFO
|
||||
- Guitar: fingering, scale diagram
|
||||
- 6 musical systems with correct default tonics
|
||||
- REPL guide documentation
|
||||
|
||||
## 0.25.1
|
||||
|
||||
- Add `pytheory demo` CLI command — plays a randomly generated track, different every time
|
||||
- Rewrite README to showcase the full feature set (composition, effects, drums, MIDI export)
|
||||
|
||||
## 0.25.0
|
||||
|
||||
- Add sidechain compression — kick ducks pad/bass for the classic EDM pump effect
|
||||
- Add song structure: `score.section("verse")`, `score.section("chorus")`, `score.repeat("verse")`
|
||||
- Punchier kick drum: 808-style with faster pitch sweep (200→45Hz), sub thump, and soft saturation
|
||||
- Section repeat copies all part notes, drum hits, and automation with proper offset
|
||||
|
||||
## 0.24.1
|
||||
|
||||
- Add `humanize` parameter on Parts — random micro-timing and velocity variation
|
||||
- Makes programmed parts feel like a real player (0.1 = subtle, 0.3 = natural, 0.5+ = loose)
|
||||
|
||||
## 0.24.0
|
||||
|
||||
- Add per-note velocity: `lead.add("C5", Duration.QUARTER, velocity=90)` — dynamics, accents, ghost notes
|
||||
- Add swing/groove: `Score("4/4", bpm=120, swing=0.5)` — shuffles every other note for human feel
|
||||
- Add tempo changes mid-song: `score.set_tempo(140)` — accelerando, ritardando, tempo drops
|
||||
- Add `Part.fade_in(bars)` and `Part.fade_out(bars)` — volume envelopes over sections
|
||||
- Arpeggiator supports velocity parameter
|
||||
- Per-part swing override (set independently from score swing)
|
||||
- Tempo map engine: beat-to-sample conversion handles variable BPM throughout a score
|
||||
|
||||
## 0.23.0
|
||||
|
||||
- Add convolution reverb with 7 synthetic impulse responses: Taj Mahal, cathedral, plate, spring, cave, parking garage, canyon
|
||||
- Each IR models real acoustic properties: early reflections, frequency-dependent absorption, diffusion density, and modulation
|
||||
- FFT-based convolution via `scipy.signal.fftconvolve` for fast processing even with long tails (12s Taj Mahal)
|
||||
- Select via `reverb_type` parameter on `Score.part()` — drop-in alongside existing algorithmic reverb
|
||||
- IR cache for zero-cost reuse across parts
|
||||
- Automatable via `Part.set(reverb_type="cathedral")` mid-song
|
||||
|
||||
## 0.22.0
|
||||
|
||||
- Add `Part.lfo()` for automated parameter modulation (filter sweeps, tremolo, auto-wah)
|
||||
- 4 LFO shapes: sine, triangle, saw, square
|
||||
- Configurable rate (cycles per bar), min/max range, duration, and resolution
|
||||
- Stack multiple LFOs on different parameters for complex modulation
|
||||
|
||||
## 0.21.0
|
||||
|
||||
- Add `Part.set()` for mid-song effect automation (filter sweeps, reverb swells, distortion kicks)
|
||||
- Add chorus effect (LFO-modulated delay, Juno-style)
|
||||
- Renderer segments audio at automation points for per-section effect processing
|
||||
- Updated effect chain: distortion → chorus → lowpass → delay → reverb
|
||||
- Document automation, chorus, and updated signal chain
|
||||
|
||||
## 0.20.0
|
||||
|
||||
- Add `Part.arpeggio()` — arpeggiator with up/down/updown/downup/random patterns, octave spanning
|
||||
- Fix Roman numeral parser to handle flat/sharp degree prefixes (bVI, bVII, bIII, #IV)
|
||||
- Add `song_showoff.py` — generative composition that's different every time, uses every feature
|
||||
- 4 mood palettes (dark, bright, ethereal, aggressive) with matched keys, progressions, drums, and effects
|
||||
|
||||
## 0.19.1
|
||||
|
||||
- Add `Part.arpeggio()` — arpeggiator with up/down/updown/downup/random patterns, octave spanning, and division control
|
||||
- Arpeggiator chains with legato + glide for classic acid/trance sequencer sound
|
||||
- Rename rhythm docs to "Sequencing: Rhythm and Scores"
|
||||
- Document arpeggiator, legato, and glide in rhythm guide
|
||||
|
||||
## 0.19.0
|
||||
|
||||
- Add legato mode for parts — continuous waveform without retriggering envelope per note
|
||||
- Add glide/portamento — smooth pitch slides between consecutive notes (303-style)
|
||||
- Legato renders entire phrase as one oscillator with phase-accumulating frequency changes
|
||||
- Glide uses exponential interpolation for perceptually linear pitch slides
|
||||
|
||||
## 0.18.1
|
||||
|
||||
- Add distortion effect (tanh soft-clip waveshaping) with drive and mix controls
|
||||
- 3 new example songs: Dub Delay Madness (separate delay snare), Liquid DnB (174bpm), Late Night Texts (Drake-style trap)
|
||||
- 16 total songs in the song player
|
||||
|
||||
## 0.18.0
|
||||
|
||||
- Add per-part audio effects: reverb, delay, and lowpass filter
|
||||
- Reverb: Schroeder algorithm with configurable mix and decay
|
||||
- Delay: tempo-synced echoes with feedback control
|
||||
- Lowpass: 12 dB/octave biquad filter with resonance (Q) control
|
||||
- All effects set at part creation: `score.part("lead", reverb=0.3, delay=0.25, lowpass=2000, lowpass_q=1.5)`
|
||||
- Effects applied per-part before mixing for independent processing
|
||||
|
||||
## 0.17.0
|
||||
|
||||
- Add 10 new groove presets: country, ska, dub, jungle, techno, gospel, swing, bolero, tango, flamenco (58 total)
|
||||
- Add 10 new fill presets: reggae, afrobeat, bossa nova, house, trap, hip hop, disco, cumbia, highlife, second line (21 total)
|
||||
- Every major genre family now has matching groove + fill presets
|
||||
|
||||
## 0.16.0
|
||||
|
||||
- Add drum fill system with 11 genre-specific presets: rock, rock crash, jazz, jazz brush, salsa, samba, funk, metal, blast, buildup, breakdown
|
||||
- `Pattern.fill("rock")` returns a 1-bar fill pattern
|
||||
- `Score.fill("rock")` inserts a fill at the current position
|
||||
- `Score.drums("rock", repeats=8, fill="rock", fill_every=4)` auto-fills every Nth bar
|
||||
- Without `fill_every`, fill replaces only the last bar
|
||||
|
||||
## 0.15.1
|
||||
|
||||
- Add `Synth.PWM_SLOW` and `Synth.PWM_FAST` — pulse width modulation with LFO sweep (Juno-style pads)
|
||||
- Add `Score.drums()` shorthand for `score.add_pattern(Pattern.preset(...), repeats=...)`
|
||||
- Update all docs to use `score.drums()` syntax and document all 10 synth waveforms
|
||||
|
||||
## 0.15.0
|
||||
|
||||
- Add 5 new synth waveforms: `Synth.SQUARE`, `Synth.PULSE`, `Synth.FM`, `Synth.NOISE`, `Synth.SUPERSAW`
|
||||
- Square wave: classic chiptune / 8-bit sound (odd harmonics at 1/n)
|
||||
- Pulse wave: variable duty cycle for NES-style timbres (25%, 12.5%)
|
||||
- FM synthesis: DX7-style frequency modulation (electric piano, bells, brass, metallic)
|
||||
- Noise: white noise for percussion textures and effects
|
||||
- Supersaw: 7 detuned saw oscillators for trance/EDM pads
|
||||
- All 8 synths available in both the API (`Synth.FM`) and Part strings (`synth="fm"`)
|
||||
- CLI play command supports all 8 waveforms
|
||||
|
||||
## 0.14.0
|
||||
|
||||
- Add `Part` class for multi-voice Score arrangements (lead, bass, pads, etc.)
|
||||
- `Score.part()` creates named parts with independent synth, envelope, and volume
|
||||
- `Score.add_pattern()` for attaching drum patterns
|
||||
- `render_score()` exported for headless buffer rendering
|
||||
- Parts accept raw float beat values alongside `Duration` enums
|
||||
- All 10 example songs rewritten with drums + chords + lead + bass parts
|
||||
|
||||
## 0.13.1
|
||||
|
||||
- Fix drum pattern repeats: hits now correctly offset across cycles instead of piling up on the first bar
|
||||
|
||||
## 0.13.0
|
||||
|
||||
- Add drum synthesizer with 27 individual instrument voices (kick, snare, hat, conga, timbale, etc.)
|
||||
- Add `play_pattern()` for playing drum patterns through the speakers
|
||||
- Add `play_score()` for playing mixed drum patterns + chord progressions together
|
||||
- Every `DrumSound` has a dedicated synthesis algorithm (pitch sweeps, noise bursts, membrane resonance, metallic rings)
|
||||
|
||||
## 0.12.0
|
||||
|
||||
- Add rhythm module: `Duration`, `TimeSignature`, `Note`, `Rest`, `Score`
|
||||
- `Duration` enum with 8 note lengths (whole through sixteenth, dotted, triplet)
|
||||
- `TimeSignature` with string parsing ("4/4", "3/4", "6/8", "12/8") and beats_per_measure
|
||||
- `Score` class with fluent `.add()` / `.rest()` chaining, measure counting, and `save_midi()` export
|
||||
- Measure-aware MIDI export with proper time signature and tempo meta events
|
||||
- Add `DrumSound` enum with 27 General MIDI percussion sounds
|
||||
- Add `Pattern` class with 48 drum pattern presets covering:
|
||||
- **Rock/Pop**: rock, half time, double time, disco, motown, train beat
|
||||
- **Jazz**: jazz, bebop, shuffle, linear, paradiddle
|
||||
- **Latin**: salsa, bossa nova, samba, cumbia, merengue, baiao, maracatu
|
||||
- **Afro-Cuban**: son clave 3-2/2-3, rumba clave 3-2/2-3, cascara, guaguanco, mozambique, nanigo, bembe, 6/8 afro-cuban, tresillo, habanera
|
||||
- **African**: afrobeat, highlife
|
||||
- **Caribbean**: reggae, dancehall
|
||||
- **Electronic**: house, trap, drum and bass, breakbeat
|
||||
- **Metal/Punk**: metal, blast beat, punk
|
||||
- **Other**: funk, hip hop, bo diddley, second line, new orleans, waltz, 12/8 blues
|
||||
- `Pattern.to_score()` renders drum patterns to Score for MIDI export
|
||||
|
||||
## 0.11.0
|
||||
|
||||
- Add drop voicings: `Chord.close_voicing()`, `Chord.open_voicing()`, `Chord.drop2()`, `Chord.drop3()`
|
||||
- Add `Key.modulation_path(target)` for chord-by-chord modulation suggestions via pivot chords
|
||||
- Add `Scale.degree_name(n)` returning traditional names (tonic, dominant, leading tone, etc.)
|
||||
- Add `Chord.extensions()` to suggest available 9th/11th/13th extensions
|
||||
- Add `Tone.solfege` property for fixed-Do solfege syllables (Do, Re, Mi, Fi, etc.)
|
||||
- Add CLI `identify` command for full chord analysis from a symbol
|
||||
- Add CLI `midi` command for exporting progressions to Standard MIDI Files
|
||||
- Expand documentation: solfege, Helmholtz, cents, slash chords, drop voicings, chord extensions, borrowed chord analysis, ADSR envelopes, MIDI export, new CLI commands
|
||||
|
||||
## 0.10.0
|
||||
|
||||
- Add `Scale.fitness()` to score how well a set of notes fits a scale (0.0–1.0)
|
||||
- Add `Key.suggest_next(chord)` for chord progression suggestions based on functional harmony
|
||||
- Add `Tone.helmholtz` and `Tone.scientific` properties for alternate pitch notation
|
||||
- Add `Chord.slash(bass)` and `Chord.slash_name` for slash chord notation (C/G, Am/E)
|
||||
- Add `save_midi()` for exporting tones, chords, and progressions as Standard MIDI Files
|
||||
- Add chord tone highlighting in `Fretboard.scale_diagram()` — chord tones uppercase, passing tones lowercase
|
||||
- Extend `Chord.analyze()` to recognize borrowed chords (bVI, bVII, bIII, etc.)
|
||||
|
||||
## 0.9.0
|
||||
|
||||
- Add ADSR envelope system with 8 presets: `Envelope.PIANO`, `ORGAN`, `PLUCK`, `PAD`, `STRINGS`, `BELL`, `STACCATO`, `NONE`
|
||||
- Add `Chord.from_symbol()` parser — handles any standard chord symbol (e.g. "F#m7b5", "Bbmaj9", "Gsus4") without lookup tables
|
||||
- Add `Key.pivot_chords(target)` for finding modulation pivot chords between two keys
|
||||
- Add `Scale.parallel_modes()` to show all modes sharing the same notes (C major → D dorian, E phrygian, etc.)
|
||||
- Add `Tone.cents_difference(other)` for measuring fine pitch differences in cents
|
||||
- Add `--envelope` flag to CLI play command
|
||||
- CLI play command now uses `Chord.from_symbol()` for broader chord parsing
|
||||
- Replace hardcoded `c_index = 3` with named `C_INDEX` constant throughout
|
||||
|
||||
## 0.8.3
|
||||
|
||||
- Add `Chord.symbol` property for standard shorthand notation (Cmaj7, Dm, G7, m7b5, etc.)
|
||||
- Add `Key.common_progressions()` to realize all named progressions in a key
|
||||
- Add CLI commands: `modes`, `circle`, `progressions`
|
||||
|
||||
## 0.8.2
|
||||
|
||||
- Use flat spellings in CHARTS `acceptable_tone_names` (e.g. Bbm now shows Bb/Db/F instead of A#/C#/F)
|
||||
|
||||
## 0.8.1
|
||||
|
||||
- Use musically correct flat spellings in flat keys (F major gives Bb, not A#)
|
||||
|
||||
## 0.8.0
|
||||
|
||||
- Add `Fretboard.scale_diagram()` for visual scale layouts on any instrument
|
||||
- Add `play_progression()` for sequential chord playback with gaps
|
||||
- Add cookbook documentation page with practical recipes
|
||||
- Curated guitar fingering overrides for common open chords
|
||||
- Fingering memoization with bounded cache, barre detection, 4-fret span constraint
|
||||
- API ergonomics: `Fretboard.chord()`, convenience constructors, slow test markers
|
||||
|
||||
## 0.7.0
|
||||
|
||||
- Add `Fretboard.chord()` method for named chord lookups
|
||||
- Improve fingering algorithm with better voicing selection
|
||||
- Rewrite all documentation in REPL style with verified output
|
||||
|
||||
## 0.6.1
|
||||
|
||||
- Fix sawtooth and triangle wave generation
|
||||
- Add WAV export via `save()`
|
||||
- Add CLI tests and play module tests
|
||||
- Skip play module tests when PortAudio is not available
|
||||
|
||||
## 0.6.0
|
||||
|
||||
- Support flat note names (Db, Bb, Eb, etc.) throughout the system
|
||||
- Add `Fingering` class for labeled chord fingerings
|
||||
- Add `pytheory play` CLI command for playing notes and chords
|
||||
- Add 12 example scripts showcasing pytheory features
|
||||
- Expand documentation with undocumented features and CLI guide
|
||||
|
||||
## 0.4.1
|
||||
|
||||
- Add `--temperament` flag to CLI tone command
|
||||
- Add Symbolic Pitch section to tones docs
|
||||
|
||||
## 0.4.0
|
||||
|
||||
- Add key signatures, scale diagrams, chord building, and progression analysis
|
||||
- Add CLI tool (`pytheory tone`, `pytheory chord`, `pytheory key`, etc.)
|
||||
- Add Jupyter notebook tutorial
|
||||
- Improve test coverage from 93% to 97% (476 tests)
|
||||
- Add type hints, docstrings, and property caching throughout
|
||||
|
||||
## 0.3.2
|
||||
|
||||
- Add type hints and docstrings throughout the library
|
||||
|
||||
## 0.3.1
|
||||
|
||||
- Add capo support, chord merging (`+`), tritone substitution
|
||||
- Add secondary dominants, Nashville number system
|
||||
- Add more common progressions (blues, jazz, flamenco, modal)
|
||||
|
||||
## 0.3.0
|
||||
|
||||
- Add interval naming (`Tone.interval_to()`)
|
||||
- Add MIDI conversion (`Tone.midi`, `Tone.from_midi()`)
|
||||
- Add `Tone.from_frequency()`, `Tone.transpose()`
|
||||
- Add `Chord.root`, `Chord.quality` properties
|
||||
- Add `Chord.from_name()`, `Chord.from_intervals()`, `Chord.from_midi_message()`
|
||||
- Add `Interval` constants (MINOR_THIRD, PERFECT_FIFTH, etc.)
|
||||
- Add `PROGRESSIONS` dict with common named progressions
|
||||
- Add `Tone.enharmonic` property
|
||||
- Add inversions, harmonize, and Roman numeral progressions
|
||||
- Add `Key` class with detection, signatures, relative/parallel keys
|
||||
- Add `Scale.detect()` and `Chord.from_tones()` convenience constructors
|
||||
- Add 25 instrument presets (mandolin family, violin family, banjo, harp, world instruments, keyboard)
|
||||
- Add `Tone.circle_of_fifths()` and `Tone.circle_of_fourths()`
|
||||
- Add chord identification (17 types), voice leading, tension scoring
|
||||
- Add beat frequencies, Plomp-Levelt dissonance model, harmony scoring
|
||||
|
||||
## 0.2.0
|
||||
|
||||
- Add `Fretboard` class for guitar fretboards
|
||||
- Add `play()` function with sine, sawtooth, and triangle wave synthesis
|
||||
- Add chord harmony and dissonance calculations
|
||||
- Modernize project structure (pyproject.toml, sounddevice)
|
||||
|
||||
## 0.1.0
|
||||
|
||||
- Initial release
|
||||
- Western 12-tone system with tones, scales, and basic chord support
|
||||
- Temperament support (equal, Pythagorean, meantone)
|
||||
- Indian (Hindustani), Arabic, Japanese, Blues, and Gamelan systems
|
||||
@@ -0,0 +1,38 @@
|
||||
# Claude Code Instructions
|
||||
|
||||
## Release Process
|
||||
|
||||
When releasing to PyPI, always do all three:
|
||||
|
||||
1. **Tag the commit**: `git tag v0.X.Y`
|
||||
2. **Push the tag**: `git push origin --tags`
|
||||
3. **Create a GitHub release**: `gh release create v0.X.Y --title "v0.X.Y: Short description" --notes "Release notes" --latest`
|
||||
|
||||
Don't forget to update `CHANGELOG.md` *before* the release commit.
|
||||
|
||||
## Version Bumping
|
||||
|
||||
- `pyproject.toml` and `pytheory/__init__.py` must match
|
||||
- Run `uv lock` after changing the version
|
||||
- Patch releases (0.X.Y) for bug fixes and small additions
|
||||
- Minor releases (0.X.0) for new features
|
||||
|
||||
## Testing
|
||||
|
||||
```
|
||||
uv run python -m pytest test_pytheory.py -x -q --tb=short -m "not slow"
|
||||
```
|
||||
|
||||
## Publishing
|
||||
|
||||
```
|
||||
uv build && uv publish --token <token> dist/pytheory-0.X.Y*
|
||||
```
|
||||
|
||||
## Music Preferences
|
||||
|
||||
- Detune: keep at 8-15, don't go above 25
|
||||
- Humanize: 0.2 is the sweet spot for melodic parts
|
||||
- Drum humanize: 0.15 default is good
|
||||
- No swing unless specifically asked
|
||||
- Sine and triangle are underrated — use them more
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Kenneth Reitz
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
@@ -1,164 +1,161 @@
|
||||
# PyTheory: Music Theory for Humans
|
||||
|
||||
This library makes exploring music theory approachable and fun, treating Python as a musical instrument.
|
||||
|
||||
## Installation
|
||||
Explore music theory, compose multi-part arrangements, and export to MIDI — all in Python.
|
||||
|
||||
```
|
||||
$ pip install pytheory
|
||||
```
|
||||
|
||||
## Tones
|
||||
## Sketch Ideas Fast
|
||||
|
||||
```pycon
|
||||
>>> from pytheory import Tone
|
||||
```python
|
||||
from pytheory import Score, Pattern, Key, Duration, Chord
|
||||
from pytheory.play import play_score
|
||||
|
||||
>>> c4 = Tone.from_string("C4", system="western")
|
||||
>>> c4.frequency
|
||||
261.63
|
||||
score = Score("4/4", bpm=140)
|
||||
score.drums("bossa nova", repeats=4)
|
||||
|
||||
>>> c4 + 7 # perfect fifth
|
||||
<Tone G4>
|
||||
chords = score.part("chords", synth="fm", envelope="pad", reverb=0.4)
|
||||
lead = score.part("lead", synth="saw", envelope="pluck", delay=0.3, lowpass=3000)
|
||||
bass = score.part("bass", synth="sine", lowpass=500)
|
||||
|
||||
>>> c4.interval_to(c4 + 7)
|
||||
'perfect 5th'
|
||||
for sym in ["Am", "Dm", "E7", "Am"]:
|
||||
chords.add(Chord.from_symbol(sym), Duration.WHOLE)
|
||||
chords.add(Chord.from_symbol(sym), Duration.WHOLE)
|
||||
|
||||
>>> c4.midi
|
||||
60
|
||||
lead.arpeggio("Am", bars=2, pattern="updown", octaves=2)
|
||||
lead.arpeggio("Dm", bars=2, pattern="updown", octaves=2)
|
||||
lead.set(lowpass=5000, reverb=0.4)
|
||||
lead.arpeggio("E7", bars=2, pattern="up", octaves=2)
|
||||
lead.arpeggio("Am", bars=2, pattern="updown", octaves=2)
|
||||
|
||||
>>> Tone.from_frequency(440)
|
||||
<Tone A4>
|
||||
for n in ["A2", "E2", "A2", "C3"] * 4:
|
||||
bass.add(n, Duration.QUARTER)
|
||||
|
||||
>>> Tone.from_midi(69)
|
||||
<Tone A4>
|
||||
play_score(score) # hear it now
|
||||
score.save_midi("sketch.mid") # open in your DAW
|
||||
```
|
||||
|
||||
## Scales and Modes
|
||||
## Hear It Instantly
|
||||
|
||||
```pycon
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
>>> c_major = TonedScale(tonic="C4")["major"]
|
||||
>>> c_major.note_names
|
||||
['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
|
||||
>>> TonedScale(tonic="C4")["dorian"].note_names
|
||||
['C', 'D', 'D#', 'F', 'G', 'A', 'A#', 'C']
|
||||
```
|
||||
$ pytheory demo
|
||||
```
|
||||
|
||||
## Diatonic Harmony
|
||||
## Music Theory
|
||||
|
||||
```pycon
|
||||
>>> c_major.triad(0).identify()
|
||||
'C major'
|
||||
>>> from pytheory import Key, Chord, Tone
|
||||
|
||||
>>> c_major.seventh(4).identify()
|
||||
'G dominant 7th'
|
||||
|
||||
>>> [c.identify() for c in c_major.harmonize()]
|
||||
>>> Key("C", "major").chords
|
||||
['C major', 'D minor', 'E minor', 'F major', 'G major', 'A minor', 'B diminished']
|
||||
|
||||
>>> [c.identify() for c in c_major.progression("I", "V", "vi", "IV")]
|
||||
['C major', 'G major', 'A minor', 'F major']
|
||||
>>> [c.symbol for c in Key("G", "major").progression("I", "V", "vi", "IV")]
|
||||
['G', 'D', 'Em', 'C']
|
||||
|
||||
>>> Chord.from_symbol("F#m7b5").identify()
|
||||
'F# half-diminished 7th'
|
||||
|
||||
>>> Tone.from_string("C4").interval_to(Tone.from_string("G4"))
|
||||
'perfect 5th'
|
||||
|
||||
>>> Key("C", "major").pivot_chords(Key("G", "major"))
|
||||
['A minor', 'B minor', 'C major', 'D major', 'E minor', 'G major']
|
||||
|
||||
>>> Chord.from_tones("C", "E", "G").forte_number
|
||||
'3-11'
|
||||
|
||||
>>> from pytheory.scales import Scale
|
||||
>>> Scale.recommend("C", "Eb", "F", "Gb", "G", "Bb", top=3)
|
||||
[('C', 'blues', 1.0), ...]
|
||||
```
|
||||
|
||||
## Keys and Progressions
|
||||
## Composition
|
||||
|
||||
```pycon
|
||||
>>> from pytheory import Key
|
||||
```python
|
||||
score = Score("4/4", bpm=124)
|
||||
score.drums("house", repeats=16, fill="house", fill_every=8)
|
||||
|
||||
>>> key = Key("G", "major")
|
||||
>>> key.chords
|
||||
['G major', 'A minor', 'B minor', 'C major', 'D major', 'E minor', 'F# diminished']
|
||||
pad = score.part("pad", synth="supersaw", envelope="pad",
|
||||
reverb=0.5, chorus=0.3, sidechain=0.85)
|
||||
lead = score.part("lead", synth="saw", envelope="pluck",
|
||||
legato=True, glide=0.03, humanize=0.3)
|
||||
bass = score.part("bass", synth="sine", lowpass=300, sidechain=0.7)
|
||||
|
||||
>>> [c.identify() for c in key.progression("I", "V", "vi", "IV")]
|
||||
['G major', 'D major', 'E minor', 'C major']
|
||||
# Song structure
|
||||
score.section("verse")
|
||||
# ... add notes ...
|
||||
score.section("chorus")
|
||||
lead.set(lowpass=5000, reverb=0.3)
|
||||
# ... add notes ...
|
||||
score.end_section()
|
||||
|
||||
>>> Key.detect("C", "E", "G", "A", "D")
|
||||
<Key C major>
|
||||
score.repeat("verse")
|
||||
score.repeat("chorus", times=2)
|
||||
```
|
||||
|
||||
## Chord Analysis
|
||||
## 10 Synth Waveforms
|
||||
|
||||
```pycon
|
||||
>>> from pytheory import Chord, Tone
|
||||
sine, saw, triangle, square, pulse, FM, noise, supersaw, PWM slow, PWM fast — with detune, stereo pan, and spread.
|
||||
|
||||
>>> C4 = Tone.from_string("C4", system="western")
|
||||
>>> G4 = Tone.from_string("G4", system="western")
|
||||
## 58 Drum Patterns
|
||||
|
||||
>>> g7 = Chord([G4, G4+4, G4+7, G4+10])
|
||||
>>> g7.identify()
|
||||
'G dominant 7th'
|
||||
rock, jazz, bebop, bossa nova, salsa, samba, afrobeat, funk, reggae, house, trap, metal, drum and bass — and 45 more. Plus 21 fill presets. Stereo panned like a real kit.
|
||||
|
||||
>>> g7.analyze("C")
|
||||
'V7'
|
||||
## 6 Effects with Automation
|
||||
|
||||
>>> g7.tension
|
||||
{'score': 0.6, 'tritones': 1, 'minor_seconds': 0, 'has_dominant_function': True}
|
||||
```python
|
||||
lead = score.part("lead", synth="saw",
|
||||
distortion=0.7, lowpass=1000, lowpass_q=5.0,
|
||||
delay=0.3, reverb=0.4, reverb_type="plate",
|
||||
chorus=0.3)
|
||||
|
||||
>>> g7.transpose(-7).identify()
|
||||
'C dominant 7th'
|
||||
# Automate mid-song
|
||||
lead.set(lowpass=4000, distortion=0.9)
|
||||
|
||||
# LFO modulation
|
||||
lead.lfo("lowpass", rate=0.5, min=400, max=3000, bars=8)
|
||||
```
|
||||
|
||||
## Six Musical Systems
|
||||
Signal chain: distortion → chorus → lowpass → delay → reverb. Sidechain compression. Master bus compressor/limiter. Stereo output.
|
||||
|
||||
```pycon
|
||||
>>> from pytheory import TonedScale
|
||||
## Convolution Reverb
|
||||
|
||||
>>> TonedScale(tonic="Sa4", system="indian")["bhairav"].note_names
|
||||
['Sa', 'komal Re', 'Ga', 'Ma', 'Pa', 'komal Dha', 'Ni', 'Sa']
|
||||
7 synthetic impulse responses: Taj Mahal (12s), cathedral, plate, spring, cave, parking garage, canyon.
|
||||
|
||||
>>> TonedScale(tonic="Do4", system="arabic")["hijaz"].note_names
|
||||
['Do', 'Reb', 'Mi', 'Fa', 'Sol', 'Solb', 'Sib', 'Do']
|
||||
|
||||
>>> TonedScale(tonic="C4", system="japanese")["hirajoshi"].note_names
|
||||
['C', 'D', 'D#', 'G', 'G#', 'C']
|
||||
|
||||
>>> TonedScale(tonic="C4", system="blues")["blues"].note_names
|
||||
['C', 'D#', 'F', 'F#', 'G', 'A#', 'C']
|
||||
```python
|
||||
pad = score.part("pad", synth="supersaw",
|
||||
reverb=0.85, reverb_type="taj_mahal")
|
||||
```
|
||||
|
||||
## 6 Musical Systems
|
||||
|
||||
Western, Indian (Hindustani), Arabic (Maqam), Japanese, Blues/Pentatonic, Javanese Gamelan — 40+ scales.
|
||||
|
||||
## 25 Instrument Presets
|
||||
|
||||
```pycon
|
||||
>>> from pytheory import Fretboard, CHARTS
|
||||
Guitar (8 tunings), bass, ukulele, mandolin family, violin family, banjo, harp, oud, sitar, erhu, and more — with chord fingering generation.
|
||||
|
||||
>>> Fretboard.guitar() # standard tuning
|
||||
>>> Fretboard.guitar("drop d") # 8 alternate tunings
|
||||
>>> Fretboard.mandolin() # + mandola, octave mandolin, mandocello
|
||||
>>> Fretboard.violin() # + viola, cello, double bass
|
||||
>>> Fretboard.ukulele() # + banjo, harp, charango, erhu...
|
||||
>>> Fretboard.keyboard() # 88-key piano
|
||||
>>> Fretboard.keyboard(25, "C3") # 25-key MIDI controller
|
||||
## Command Line
|
||||
|
||||
>>> CHARTS['western']['Am'].fingering(fretboard=Fretboard.guitar())
|
||||
Fingering(e=0, B=1, G=2, D=2, A=0, E=0)
|
||||
|
||||
>>> Fretboard.guitar().fingering(0, 1, 0, 2, 3, 0).identify()
|
||||
'C major'
|
||||
```
|
||||
$ pytheory repl # interactive scratchpad
|
||||
$ pytheory demo # hear a generated track
|
||||
$ pytheory key G major # explore a key
|
||||
$ pytheory identify Cmaj7 # analyze a chord symbol
|
||||
$ pytheory progression C major I V vi IV # build a progression
|
||||
$ pytheory midi C major I V vi IV -o out.mid
|
||||
$ pytheory play Am7 --synth saw --envelope pluck
|
||||
$ pytheory modes C # show all modes
|
||||
$ pytheory circle C # circle of fifths
|
||||
```
|
||||
|
||||
## Audio Playback
|
||||
## Why Python?
|
||||
|
||||
```pycon
|
||||
>>> from pytheory import play, Synth, Tone
|
||||
A DAW is great for tweaking sounds. But when you're *thinking about music* — code is faster than clicking. Sketch ideas, hear them instantly, export MIDI, finish in your DAW.
|
||||
|
||||
>>> tone = Tone.from_string("A4", system="western")
|
||||
>>> play(tone, t=1_000) # sine wave, 1 second
|
||||
>>> play(tone, synth=Synth.SAW, t=1_000) # sawtooth wave
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- **6 musical systems**: Western, Indian (Hindustani), Arabic (Maqam), Japanese, Blues/Pentatonic, Javanese Gamelan
|
||||
- **40+ scales**: major, minor, harmonic minor, 7 modes, 10 thaats, 10 maqamat, pentatonic, blues, hirajoshi, pelog, slendro, and more
|
||||
- **Chord analysis**: identification (17 types), Roman numeral analysis, tension scoring, voice leading, Plomp-Levelt dissonance, beat frequencies
|
||||
- **Diatonic harmony**: triads, seventh chords, harmonize entire scales, build progressions from Roman numerals
|
||||
- **25 instrument presets**: guitar (8 tunings), 12-string, bass, mandolin family, violin family, banjo, harp, oud, sitar, shamisen, erhu, charango, pipa, balalaika, lute, pedal steel, keyboard
|
||||
- **Pitch tools**: frequency ↔ tone conversion, MIDI ↔ tone, interval naming, circle of fifths, overtone series, transposition
|
||||
- **3 temperaments**: equal, Pythagorean, quarter-comma meantone
|
||||
- **Audio synthesis**: sine, sawtooth, and triangle wave playback
|
||||
Tools like [Claude Code](https://claude.ai/code) can use PyTheory to prototype musical ideas from natural language — "write a bossa nova in A minor with a saw lead and reverb" becomes real, playable music.
|
||||
|
||||
## Documentation
|
||||
|
||||
Full documentation with music theory guides: **[pytheory.kennethreitz.org](https://pytheory.kennethreitz.org)**
|
||||
**[pytheory.kennethreitz.org](https://pytheory.kennethreitz.org)**
|
||||
|
||||
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
<audio controls style="width: 100%; margin: 0.5em 0 1.5em 0;">
|
||||
<source src="{{ pathto('_static/audio/' + file, 1) }}" type="audio/wav">
|
||||
Your browser does not support the audio element.
|
||||
</audio>
|
||||
@@ -0,0 +1,2 @@
|
||||
```{include} ../CHANGELOG.md
|
||||
```
|
||||
+11
-1
@@ -10,13 +10,16 @@ sys.modules["sounddevice"] = MagicMock()
|
||||
project = "PyTheory"
|
||||
copyright = "2026, Kenneth Reitz"
|
||||
author = "Kenneth Reitz"
|
||||
release = "0.4.1"
|
||||
import pytheory
|
||||
release = pytheory.__version__
|
||||
version = pytheory.__version__
|
||||
|
||||
extensions = [
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinx.ext.napoleon",
|
||||
"sphinx.ext.viewcode",
|
||||
"sphinx.ext.intersphinx",
|
||||
"myst_parser",
|
||||
]
|
||||
|
||||
autodoc_member_order = "bysource"
|
||||
@@ -38,7 +41,14 @@ html_theme_options = {
|
||||
"github_user": "kennethreitz",
|
||||
"github_repo": "pytheory",
|
||||
"github_banner": True,
|
||||
"github_button": True,
|
||||
"github_type": "star",
|
||||
"github_count": True,
|
||||
"description": "Music Theory for Humans",
|
||||
"extra_nav_links": {
|
||||
f"v{pytheory.__version__}": "https://pypi.org/project/pytheory/",
|
||||
},
|
||||
"show_powered_by": False,
|
||||
}
|
||||
html_static_path = ["_static"]
|
||||
html_extra_path = ["CNAME"]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+361
-129
@@ -45,18 +45,20 @@ For seventh chords, there's also **third inversion** (7th in bass):
|
||||
|
||||
- G7 in third inversion: F G B D (notated G7/F)
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Chord, Tone
|
||||
>>> from pytheory import Chord, Tone
|
||||
|
||||
# All three are "C major" — identify() finds the root
|
||||
root = Chord([Tone.from_string(n, system="western") for n in ["C4", "E4", "G4"]])
|
||||
first = Chord([Tone.from_string(n, system="western") for n in ["E3", "G3", "C4"]])
|
||||
second = Chord([Tone.from_string(n, system="western") for n in ["G3", "C4", "E4"]])
|
||||
>>> root = Chord([Tone.from_string(n, system="western") for n in ["C4", "E4", "G4"]])
|
||||
>>> first = Chord([Tone.from_string(n, system="western") for n in ["E3", "G3", "C4"]])
|
||||
>>> second = Chord([Tone.from_string(n, system="western") for n in ["G3", "C4", "E4"]])
|
||||
|
||||
root.identify() # 'C major'
|
||||
first.identify() # 'C major'
|
||||
second.identify() # 'C major'
|
||||
>>> root.identify()
|
||||
'C major'
|
||||
>>> first.identify()
|
||||
'C major'
|
||||
>>> second.identify()
|
||||
'C major'
|
||||
|
||||
Extended Chords
|
||||
---------------
|
||||
@@ -72,33 +74,42 @@ A full 13th chord contains all 7 notes of the scale! In practice,
|
||||
tones are usually omitted — the 5th is typically dropped first, then
|
||||
the 11th (which clashes with the 3rd in dominant chords).
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
scale = TonedScale(tonic="C4")["major"]
|
||||
>>> scale = TonedScale(tonic="C4")["major"]
|
||||
|
||||
# Build a Cmaj9 from the scale: C E G B D
|
||||
cmaj9 = scale.chord(0, 2, 4, 6, 8)
|
||||
|
||||
# Build a full C13 (in theory): C E G B D F A
|
||||
c13 = scale.chord(0, 2, 4, 6, 8, 10, 12)
|
||||
>>> cmaj9 = scale.chord(0, 2, 4, 6, 8)
|
||||
>>> c13 = scale.chord(0, 2, 4, 6, 8, 10, 12)
|
||||
|
||||
Using the Chord Chart
|
||||
---------------------
|
||||
|
||||
PyTheory includes 144 pre-built chords (12 roots x 12 qualities):
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import CHARTS
|
||||
>>> from pytheory import Fretboard
|
||||
|
||||
chart = CHARTS["western"]
|
||||
>>> fb = Fretboard.guitar()
|
||||
>>> fb.chord("C")
|
||||
Fingering(e=0, B=1, G=0, D=2, A=3, E=x)
|
||||
>>> fb.chord("Am")
|
||||
Fingering(e=0, B=1, G=2, D=2, A=0, E=x)
|
||||
>>> fb.chord("G7")
|
||||
Fingering(e=1, B=0, G=0, D=0, A=2, E=3)
|
||||
|
||||
c_major = chart["C"] # C major (root position)
|
||||
a_minor = chart["Am"] # A minor
|
||||
g_seven = chart["G7"] # G dominant 7th
|
||||
d_dim = chart["Ddim"] # D diminished
|
||||
You can also build chords directly with ``Chord.from_name()``:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Chord
|
||||
|
||||
>>> Chord.from_name("G7").identify()
|
||||
'G dominant 7th'
|
||||
>>> Chord.from_name("Ddim").identify()
|
||||
'D diminished'
|
||||
|
||||
Available qualities:
|
||||
|
||||
@@ -119,52 +130,48 @@ Quality Intervals Example tones (from C)
|
||||
``"maj9"`` 4, 7, 11, 14 C E G B D (major 9th)
|
||||
============ ================ ================================
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import CHARTS
|
||||
>>> chart = CHARTS["western"]
|
||||
|
||||
>>> chart["C"].acceptable_tone_names
|
||||
('C', 'E', 'G')
|
||||
|
||||
>>> chart["Cm7"].acceptable_tone_names
|
||||
('C', 'D#', 'G', 'A#') # Eb and Bb shown as sharps
|
||||
('C', 'Eb', 'G', 'Bb')
|
||||
|
||||
Building Chords
|
||||
---------------
|
||||
|
||||
Several convenience constructors make chord creation concise:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Chord
|
||||
>>> from pytheory import Chord
|
||||
|
||||
# From note names (simplest)
|
||||
Chord.from_tones("C", "E", "G") # <Chord C major>
|
||||
Chord.from_tones("A", "C", "E") # <Chord A minor>
|
||||
>>> Chord.from_tones("C", "E", "G").identify()
|
||||
'C major'
|
||||
>>> Chord.from_tones("A", "C", "E").identify()
|
||||
'A minor'
|
||||
|
||||
# From a chord name (uses the built-in chart)
|
||||
Chord.from_name("Am7") # <Chord A minor 7th>
|
||||
Chord.from_name("G7") # <Chord G dominant 7th>
|
||||
>>> Chord.from_name("Am7").identify()
|
||||
'A minor 7th'
|
||||
>>> Chord.from_name("G7").identify()
|
||||
'G dominant 7th'
|
||||
|
||||
# From root + semitone intervals
|
||||
Chord.from_intervals("C", 4, 7) # <Chord C major>
|
||||
Chord.from_intervals("D", 3, 7) # <Chord D minor>
|
||||
Chord.from_intervals("G", 4, 7, 10) # <Chord G dominant 7th>
|
||||
>>> Chord.from_intervals("C", 4, 7).identify()
|
||||
'C major'
|
||||
>>> Chord.from_intervals("G", 4, 7, 10).identify()
|
||||
'G dominant 7th'
|
||||
|
||||
# From MIDI note numbers
|
||||
Chord.from_midi_message(60, 64, 67) # <Chord C major>
|
||||
>>> Chord.from_midi_message(60, 64, 67).identify()
|
||||
'C major'
|
||||
|
||||
# Full manual construction
|
||||
from pytheory import Tone
|
||||
c_major = Chord(tones=[
|
||||
Tone.from_string("C4", system="western"),
|
||||
Tone.from_string("E4", system="western"),
|
||||
Tone.from_string("G4", system="western"),
|
||||
])
|
||||
|
||||
for tone in c_major:
|
||||
print(tone)
|
||||
|
||||
len(c_major) # 3
|
||||
"C" in c_major # True
|
||||
>>> len(Chord.from_name("C"))
|
||||
3
|
||||
>>> "C" in Chord.from_name("C")
|
||||
True
|
||||
|
||||
Intervals
|
||||
---------
|
||||
@@ -172,13 +179,13 @@ Intervals
|
||||
The ``intervals`` property returns semitone distances between adjacent
|
||||
tones — these are musically meaningful and octave-invariant:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c_major.intervals
|
||||
[4, 3] # major 3rd (4) + minor 3rd (3) = major triad
|
||||
>>> Chord.from_tones("C", "E", "G").intervals
|
||||
[4, 3]
|
||||
|
||||
>>> Chord(tones=[C4, Eb4, G4]).intervals
|
||||
[3, 4] # minor 3rd + major 3rd = minor triad
|
||||
>>> Chord.from_tones("C", "Eb", "G").intervals
|
||||
[3, 4]
|
||||
|
||||
Consonance and Dissonance
|
||||
-------------------------
|
||||
@@ -205,13 +212,16 @@ Minor 3rd 6:5 Every 6th wave aligns
|
||||
Tritone 45:32 Waves rarely align
|
||||
=========== ===== ====================
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
fifth = Chord([C4, G4])
|
||||
tritone = Chord([C4, F_sharp_4])
|
||||
>>> from pytheory import Chord, Tone
|
||||
>>> C4 = Tone.from_string("C4", system="western")
|
||||
>>> G4 = Tone.from_string("G4", system="western")
|
||||
|
||||
fifth.harmony > tritone.harmony # True
|
||||
# The perfect fifth's 3:2 ratio scores higher
|
||||
>>> fifth = Chord([C4, G4])
|
||||
>>> tritone = Chord([C4, C4 + 6])
|
||||
>>> fifth.harmony > tritone.harmony
|
||||
True
|
||||
|
||||
Dissonance Score
|
||||
~~~~~~~~~~~~~~~~
|
||||
@@ -227,14 +237,13 @@ The roughness depends on the frequency difference relative to the
|
||||
that register). Maximum roughness occurs when the difference equals
|
||||
the critical bandwidth.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
# Octave: frequencies far apart → low roughness
|
||||
octave = Chord([C4, C5])
|
||||
# Major 3rd: closer frequencies → higher roughness
|
||||
third = Chord([C4, E4])
|
||||
|
||||
octave.dissonance < third.dissonance # True
|
||||
>>> E4 = Tone.from_string("E4", system="western")
|
||||
>>> octave = Chord([C4, C4 + 12])
|
||||
>>> third = Chord([C4, E4])
|
||||
>>> octave.dissonance < third.dissonance
|
||||
True
|
||||
|
||||
Beat Frequencies
|
||||
~~~~~~~~~~~~~~~~
|
||||
@@ -247,16 +256,49 @@ you hear a pulsing at the **beat frequency**: ``|f1 - f2|`` Hz.
|
||||
- **15–30 Hz**: Perceived as buzzing/roughness
|
||||
- **> 30 Hz**: No longer beating — becomes part of the timbre
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
chord = Chord(tones=[A4, E5, A5])
|
||||
>>> A4 = Tone.from_string("A4", system="western")
|
||||
>>> chord = Chord([A4, A4 + 7, A4 + 12])
|
||||
|
||||
# All pairwise beat frequencies, sorted ascending
|
||||
chord.beat_frequencies
|
||||
# [(A4, E5, 189.6), (E5, A5, 220.0), (A4, A5, 440.0)]
|
||||
>>> chord.beat_frequencies
|
||||
[...]
|
||||
|
||||
# The slowest (most perceptible) beat
|
||||
chord.beat_pulse # 189.6 Hz
|
||||
>>> round(chord.beat_pulse, 1)
|
||||
219.3
|
||||
|
||||
Transposition
|
||||
-------------
|
||||
|
||||
Shift an entire chord up or down by any number of semitones:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Chord.from_name("C").transpose(7).identify()
|
||||
'G major'
|
||||
|
||||
>>> Chord.from_name("Am7").transpose(-2).identify()
|
||||
'G minor 7th'
|
||||
|
||||
Chord Manipulation
|
||||
------------------
|
||||
|
||||
Add or remove individual tones from a chord:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Chord, Tone
|
||||
|
||||
>>> c_major = Chord.from_tones("C", "E", "G")
|
||||
|
||||
>>> b4 = Tone.from_string("B4", system="western")
|
||||
>>> cmaj7 = c_major.add_tone(b4)
|
||||
>>> cmaj7.identify()
|
||||
'C major 7th'
|
||||
|
||||
>>> c_again = cmaj7.remove_tone("B")
|
||||
>>> c_again.identify()
|
||||
'C major'
|
||||
|
||||
Chord Identification
|
||||
--------------------
|
||||
@@ -265,25 +307,38 @@ Give PyTheory any set of tones and it will tell you what chord it is.
|
||||
It tries every tone as a potential root and matches the interval pattern
|
||||
against 17 known chord types (triads, 7ths, 9ths, sus, power chords).
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Chord, Tone
|
||||
>>> from pytheory import Chord
|
||||
|
||||
# Build a chord and identify it
|
||||
chord = Chord([
|
||||
Tone.from_string("A4", system="western"),
|
||||
Tone.from_string("C5", system="western"),
|
||||
Tone.from_string("E5", system="western"),
|
||||
])
|
||||
chord.identify() # 'A minor'
|
||||
>>> Chord.from_tones("A", "C", "E").identify()
|
||||
'A minor'
|
||||
>>> Chord.from_tones("G", "B", "D", "F").identify()
|
||||
'G dominant 7th'
|
||||
|
||||
# Works with any voicing or inversion
|
||||
chord2 = Chord([
|
||||
Tone.from_string("E4", system="western"),
|
||||
Tone.from_string("G4", system="western"),
|
||||
Tone.from_string("C5", system="western"),
|
||||
])
|
||||
chord2.identify() # 'C major' (first inversion detected)
|
||||
>>> Chord.from_tones("E", "G", "C").identify()
|
||||
'C major'
|
||||
|
||||
>>> Chord.from_tones("Bb", "D", "F").identify()
|
||||
'Bb major'
|
||||
|
||||
Enharmonic spellings are fully supported — Cb, Fb, E#, B#, double
|
||||
sharps/flats, and unicode symbols (see :doc:`tones` for details):
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Chord.from_tones("Cb", "Eb", "Gb").identify()
|
||||
'B minor'
|
||||
|
||||
You can also access the root and quality separately:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> chord = Chord.from_name("Am7")
|
||||
>>> chord.root
|
||||
<Tone A4>
|
||||
>>> chord.quality
|
||||
'minor 7th'
|
||||
|
||||
Harmonic Analysis
|
||||
-----------------
|
||||
@@ -293,22 +348,22 @@ key. This is how musicians describe chord progressions independent of
|
||||
key — "I-IV-V" means the same thing in C major (C-F-G) as in G major
|
||||
(G-C-D).
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Chord, Tone
|
||||
>>> from pytheory import Chord, Tone
|
||||
|
||||
C4 = Tone.from_string("C4", system="western")
|
||||
D4 = Tone.from_string("D4", system="western")
|
||||
E4 = Tone.from_string("E4", system="western")
|
||||
F4 = Tone.from_string("F4", system="western")
|
||||
G4 = Tone.from_string("G4", system="western")
|
||||
A4 = Tone.from_string("A4", system="western")
|
||||
B4 = Tone.from_string("B4", system="western")
|
||||
>>> C4 = Tone.from_string("C4", system="western")
|
||||
>>> E4 = Tone.from_string("E4", system="western")
|
||||
>>> G4 = Tone.from_string("G4", system="western")
|
||||
|
||||
Chord([C4, E4, G4]).analyze("C") # 'I' (tonic)
|
||||
Chord([D4, F4, A4]).analyze("C") # 'ii' (supertonic minor)
|
||||
Chord([G4, B4, G4+5]).analyze("C") # 'V' (dominant)
|
||||
Chord([G4, B4, G4+5, G4+10]).analyze("C") # 'V7' (dominant 7th)
|
||||
>>> Chord([C4, E4, G4]).analyze("C")
|
||||
'I'
|
||||
>>> Chord.from_tones("D", "F", "A").analyze("C")
|
||||
'ii'
|
||||
>>> Chord([G4, G4+4, G4+7]).analyze("C")
|
||||
'V'
|
||||
>>> Chord([G4, G4+4, G4+7, G4+10]).analyze("C")
|
||||
'V7'
|
||||
|
||||
Tension and Resolution
|
||||
----------------------
|
||||
@@ -324,18 +379,21 @@ quantifies this based on:
|
||||
- **Dominant function**: the specific combination of a major 3rd and
|
||||
minor 7th above the root — the hallmark of the V7 chord.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
# A C major triad is fully resolved — no tension
|
||||
c_major = Chord([C4, E4, G4])
|
||||
c_major.tension['score'] # 0.0
|
||||
c_major.tension['tritones'] # 0
|
||||
>>> c_major = Chord([C4, E4, G4])
|
||||
>>> c_major.tension['score']
|
||||
0.0
|
||||
>>> c_major.tension['tritones']
|
||||
0
|
||||
|
||||
# G7 is loaded with tension — it wants to resolve to C
|
||||
g7 = Chord([G4, B4, G4+5, G4+10])
|
||||
g7.tension['score'] # 0.6
|
||||
g7.tension['tritones'] # 1
|
||||
g7.tension['has_dominant_function'] # True
|
||||
>>> g7 = Chord([G4, G4+4, G4+7, G4+10])
|
||||
>>> g7.tension['score']
|
||||
0.6
|
||||
>>> g7.tension['tritones']
|
||||
1
|
||||
>>> g7.tension['has_dominant_function']
|
||||
True
|
||||
|
||||
Voice Leading
|
||||
-------------
|
||||
@@ -345,14 +403,36 @@ jumping all voices to new positions, good voice leading moves each note
|
||||
the minimum distance to reach the next chord. Bach's chorales are the
|
||||
gold standard — every voice moves by step whenever possible.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
c_maj = Chord([C4, E4, G4])
|
||||
f_maj = Chord([F4, A4, C4+12])
|
||||
>>> c_maj = Chord.from_tones("C", "E", "G")
|
||||
>>> f_maj = Chord.from_tones("F", "A", "C")
|
||||
|
||||
for src, dst, motion in c_maj.voice_leading(f_maj):
|
||||
print(f"{src} -> {dst} ({motion:+d} semitones)")
|
||||
# Each voice moves the minimum distance to reach the target chord
|
||||
>>> for src, dst, motion in c_maj.voice_leading(f_maj):
|
||||
... print(f"{src} -> {dst} ({motion:+d} semitones)")
|
||||
G4 -> A4 (+2 semitones)
|
||||
E4 -> F4 (+1 semitones)
|
||||
C4 -> C4 (+0 semitones)
|
||||
|
||||
Tritone Substitution
|
||||
--------------------
|
||||
|
||||
In jazz harmony, any `dominant chord <https://en.wikipedia.org/wiki/Dominant_seventh_chord>`_
|
||||
can be replaced by the dominant chord a
|
||||
`tritone <https://en.wikipedia.org/wiki/Tritone_substitution>`_ (6
|
||||
semitones) away. This works because the two chords share the same
|
||||
tritone interval — the 3rd and 7th simply swap roles.
|
||||
|
||||
Common tritone subs: G7 <-> Db7, C7 <-> F#7, D7 <-> Ab7.
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Chord
|
||||
|
||||
>>> g7 = Chord.from_name("G7")
|
||||
>>> sub = g7.tritone_sub()
|
||||
>>> sub.identify()
|
||||
'C# dominant 7th'
|
||||
|
||||
The Overtone Series
|
||||
-------------------
|
||||
@@ -367,12 +447,164 @@ overtones of C already contain G. The two tones share acoustic energy,
|
||||
reinforcing each other. A dissonant interval like C and C# shares
|
||||
almost no overtones — the waves clash.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Tone
|
||||
>>> from pytheory import Tone
|
||||
|
||||
a4 = Tone.from_string("A4", system="western")
|
||||
a4.overtones(8)
|
||||
# [440.0, 880.0, 1320.0, 1760.0, 2200.0, 2640.0, 3080.0, 3520.0]
|
||||
# A4 A5 E6 A6 C#7 E7 ~G7 A7
|
||||
# fund. oct. 5th+oct 2oct 3rd 5th ~7th 3oct
|
||||
>>> a4 = Tone.from_string("A4", system="western")
|
||||
>>> [round(f, 1) for f in a4.overtones(8)]
|
||||
[440.0, 880.0, 1320.0, 1760.0, 2200.0, 2640.0, 3080.0, 3520.0]
|
||||
|
||||
Chord Symbols
|
||||
-------------
|
||||
|
||||
The ``symbol`` property returns compact lead-sheet notation, while
|
||||
``from_symbol()`` parses any standard chord symbol — no lookup table needed:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Chord.from_tones("C", "E", "G").symbol
|
||||
'C'
|
||||
>>> Chord.from_name("Am7").symbol
|
||||
'Am7'
|
||||
>>> Chord.from_symbol("F#m7b5").identify()
|
||||
'F# half-diminished 7th'
|
||||
>>> Chord.from_symbol("Bbmaj9").symbol
|
||||
'Bbmaj9'
|
||||
|
||||
Slash Chords
|
||||
------------
|
||||
|
||||
`Slash chords <https://en.wikipedia.org/wiki/Slash_chord>`_ place a specific
|
||||
note in the bass below the chord. They're written as Chord/Bass in lead sheets:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c = Chord.from_symbol("C")
|
||||
>>> c_over_g = c.slash("G")
|
||||
>>> c_over_g.slash_name
|
||||
'C/G'
|
||||
>>> c.slash("E").slash_name
|
||||
'C/E'
|
||||
|
||||
Drop Voicings
|
||||
-------------
|
||||
|
||||
`Drop voicings <https://en.wikipedia.org/wiki/Voicing_(music)#Drop_voicings>`_
|
||||
are standard arranging techniques for spreading chord tones across registers:
|
||||
|
||||
- **Close voicing** — all tones packed within one octave
|
||||
- **Open voicing** — alternating tones raised an octave for wider spacing
|
||||
- **Drop 2** — second-highest voice dropped an octave (standard jazz guitar)
|
||||
- **Drop 3** — third-highest voice dropped an octave
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> cmaj7 = Chord.from_symbol("Cmaj7")
|
||||
>>> cmaj7.close_voicing()
|
||||
<Chord C major 7th>
|
||||
>>> cmaj7.drop2()
|
||||
<Chord C major 7th>
|
||||
|
||||
Chord Extensions
|
||||
----------------
|
||||
|
||||
The ``extensions()`` method suggests available extensions (9th, 11th, 13th)
|
||||
that don't clash with existing chord tones:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Chord, TonedScale
|
||||
>>> cm = Chord.from_symbol("C")
|
||||
>>> cm.extensions()
|
||||
[...]
|
||||
|
||||
>>> # Filter extensions against a scale for diatonic correctness:
|
||||
>>> scale = TonedScale(tonic="C4")["major"]
|
||||
>>> cm.extensions(scale=scale)
|
||||
[...]
|
||||
|
||||
Borrowed Chord Analysis
|
||||
-----------------------
|
||||
|
||||
``analyze()`` now recognizes chromatic chords from modal interchange,
|
||||
labeling them with flat-degree prefixes:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Chord.from_symbol("Ab").analyze("C", "major")
|
||||
'bVI'
|
||||
>>> Chord.from_symbol("Bb").analyze("C", "major")
|
||||
'bVII'
|
||||
|
||||
Figured Bass
|
||||
------------
|
||||
|
||||
`Figured bass <https://en.wikipedia.org/wiki/Figured_bass>`_ is the
|
||||
classical notation for chord inversions — numbers below the bass note
|
||||
describing the intervals above it. It's how Bach, Handel, and every
|
||||
Baroque composer communicated harmony.
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Chord, Tone
|
||||
|
||||
>>> root = Chord([Tone.from_string("C4"), Tone.from_string("E4"), Tone.from_string("G4")])
|
||||
>>> root.figured_bass
|
||||
''
|
||||
|
||||
>>> first_inv = Chord([Tone.from_string("E3"), Tone.from_string("G3"), Tone.from_string("C4")])
|
||||
>>> first_inv.figured_bass
|
||||
'6'
|
||||
|
||||
>>> second_inv = Chord([Tone.from_string("G3"), Tone.from_string("C4"), Tone.from_string("E4")])
|
||||
>>> second_inv.figured_bass
|
||||
'6/4'
|
||||
|
||||
For seventh chords: root position → ``"7"``, first inversion → ``"6/5"``,
|
||||
second inversion → ``"4/3"``, third inversion → ``"2"``.
|
||||
|
||||
Combine with Roman numeral analysis using ``analyze_figured()``:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> first_inv.analyze_figured("C")
|
||||
'I6'
|
||||
|
||||
Pitch Class Sets
|
||||
----------------
|
||||
|
||||
`Pitch class set theory <https://en.wikipedia.org/wiki/Set_theory_(music)>`_
|
||||
is the framework for analyzing atonal and post-tonal music. It reduces
|
||||
any collection of notes to abstract pitch classes (0–11, where C=0),
|
||||
finds the most compact form, and catalogs it with a Forte number.
|
||||
|
||||
If you're studying Schoenberg, Webern, Bartók, or any 20th-century
|
||||
music that doesn't follow traditional harmony, this is the tool.
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Chord.from_tones("C", "E", "G").pitch_classes
|
||||
{0, 4, 7}
|
||||
|
||||
>>> Chord.from_tones("C", "E", "G").prime_form
|
||||
(0, 3, 7)
|
||||
|
||||
>>> Chord.from_tones("A", "C", "E").prime_form
|
||||
(0, 3, 7)
|
||||
|
||||
Major and minor triads share the same prime form — they're inversions
|
||||
of each other in pitch class space.
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Chord.from_tones("C", "E", "G").forte_number
|
||||
'3-11'
|
||||
|
||||
>>> Chord.from_tones("C", "E", "G", "B").forte_number
|
||||
'4-20'
|
||||
|
||||
>>> Chord.from_tones("C", "E", "G#").forte_number
|
||||
'3-12'
|
||||
|
||||
Chords are the vertical dimension of music -- melody tells you where you're going, but harmony tells you how it feels to be there. Between construction, identification, voice leading, tension analysis, and pitch class sets, you've got tools to look at any chord from every angle. Pick a song you love, grab its chords, and start asking questions.
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
Command-Line Interface
|
||||
======================
|
||||
|
||||
PyTheory includes a CLI for music theory lookups, composition, and
|
||||
playback — all from the terminal.
|
||||
|
||||
Interactive REPL
|
||||
----------------
|
||||
|
||||
For extended exploration, the REPL is a music theory scratchpad with
|
||||
tab completion. See the :doc:`repl` guide for details::
|
||||
|
||||
$ pytheory repl
|
||||
|
||||
Demo
|
||||
----
|
||||
|
||||
The fastest way to hear what PyTheory can do. Generates and plays a
|
||||
random multi-part track — different every time::
|
||||
|
||||
$ pytheory demo
|
||||
♫ Jazz Club
|
||||
Bb major | 105 bpm
|
||||
Bb → Gm → Cm → F
|
||||
jazz drums | saw lead | fm pad
|
||||
|
||||
Tone Lookup
|
||||
-----------
|
||||
|
||||
Look up any note's frequency, MIDI number, enharmonic spelling, and
|
||||
overtones::
|
||||
|
||||
$ pytheory tone A4
|
||||
Note: A4
|
||||
Frequency: 440.00 Hz (equal temperament)
|
||||
MIDI: 69
|
||||
Overtones: 440.0, 880.0, 1320.0, 1760.0, 2200.0, 2640.0
|
||||
|
||||
Compare temperaments with ``--temperament``::
|
||||
|
||||
$ pytheory tone C5 --temperament pythagorean
|
||||
Note: C5
|
||||
Frequency: 521.48 Hz (pythagorean temperament)
|
||||
Equal temp: 523.25 Hz (diff: -5.9 cents)
|
||||
|
||||
Scale Display
|
||||
-------------
|
||||
|
||||
Show any scale in any system::
|
||||
|
||||
$ pytheory scale C major
|
||||
C major: C D E F G A B C
|
||||
Intervals: C4 -2- D4 -2- E4 -1- F4 -2- G4 -2- A4 -2- B4 -1- C5
|
||||
|
||||
$ pytheory scale C dorian
|
||||
$ pytheory scale Sa bhairav --system indian
|
||||
|
||||
Chord Identification
|
||||
--------------------
|
||||
|
||||
Identify a chord from its notes::
|
||||
|
||||
$ pytheory chord C E G
|
||||
Chord: C major
|
||||
Tones: C4 E4 G4
|
||||
Intervals: [4, 3]
|
||||
Harmony: 0.5833
|
||||
Dissonance: 0.0712
|
||||
Tension: 0.00 (tritones=0)
|
||||
|
||||
$ pytheory chord G B D F
|
||||
Chord: G dominant 7th
|
||||
|
||||
Key Explorer
|
||||
------------
|
||||
|
||||
Get a complete breakdown of any key — signature, diatonic triads,
|
||||
seventh chords, relative and parallel keys::
|
||||
|
||||
$ pytheory key G major
|
||||
Key: G major
|
||||
Signature: 1 sharps, 0 flats (F#)
|
||||
Scale: G A B C D E F#
|
||||
Triads:
|
||||
I G major
|
||||
ii A minor
|
||||
iii B minor
|
||||
IV C major
|
||||
V D major
|
||||
vi E minor
|
||||
vii° F# diminished
|
||||
7th chords:
|
||||
G major 7th
|
||||
A minor 7th
|
||||
...
|
||||
Relative: <Key E minor>
|
||||
Parallel: <Key G minor>
|
||||
|
||||
Guitar Fingerings
|
||||
-----------------
|
||||
|
||||
Get tablature for any of the 144 built-in chords::
|
||||
|
||||
$ pytheory fingering Am
|
||||
Am
|
||||
E|--0--
|
||||
B|--1--
|
||||
G|--2--
|
||||
D|--2--
|
||||
A|--0--
|
||||
E|--0--
|
||||
|
||||
Use ``--capo`` to see fingerings with a capo::
|
||||
|
||||
$ pytheory fingering G --capo 2
|
||||
|
||||
Chord Progressions
|
||||
------------------
|
||||
|
||||
Build progressions from Roman numerals::
|
||||
|
||||
$ pytheory progression G major I V vi IV
|
||||
Key: G major
|
||||
Progression: I → V → vi → IV
|
||||
|
||||
I G major
|
||||
V D major
|
||||
vi E minor
|
||||
IV C major
|
||||
|
||||
Key Detection
|
||||
-------------
|
||||
|
||||
Detect the most likely key from a set of notes::
|
||||
|
||||
$ pytheory detect C E G A D
|
||||
Detected key: C major
|
||||
Scale: C D E F G A B C
|
||||
|
||||
Audio Playback
|
||||
--------------
|
||||
|
||||
Play individual notes or chords (requires PortAudio)::
|
||||
|
||||
$ pytheory play A4 # Single note
|
||||
$ pytheory play C E G # Notes as chord
|
||||
$ pytheory play Am7 # Chord by name
|
||||
$ pytheory play C E G --synth saw # Sawtooth wave
|
||||
$ pytheory play A4 --duration 2000 # 2 seconds
|
||||
$ pytheory play C E G --temperament meantone
|
||||
$ pytheory play Am7 --envelope pad # With ADSR envelope
|
||||
$ pytheory play C4 --envelope bell # Bell-like ring
|
||||
|
||||
Chord Identification (from symbol)
|
||||
-----------------------------------
|
||||
|
||||
Parse any chord symbol and get a full analysis::
|
||||
|
||||
$ pytheory identify Cmaj7
|
||||
Chord: C major 7th
|
||||
Symbol: Cmaj7
|
||||
Tones: C4 E4 G4 B4
|
||||
Intervals: [4, 3, 4]
|
||||
Harmony: 0.5833
|
||||
Dissonance: 1.2345
|
||||
Tension: score=0.00 tritones=0 minor_2nds=0 dominant=False
|
||||
|
||||
$ pytheory identify F#m7b5
|
||||
|
||||
MIDI Export
|
||||
-----------
|
||||
|
||||
Export a chord progression to a Standard MIDI File::
|
||||
|
||||
$ pytheory midi C major I V vi IV -o pop.mid
|
||||
Key: C major
|
||||
Progression: I V vi IV
|
||||
BPM: 120
|
||||
Duration: 500 ms
|
||||
Output: pop.mid
|
||||
|
||||
$ pytheory midi G major ii V I -o jazz.mid --bpm 140 --duration 800
|
||||
|
||||
Modes
|
||||
-----
|
||||
|
||||
Show all 7 modes starting from a note::
|
||||
|
||||
$ pytheory modes C
|
||||
Modes of C:
|
||||
|
||||
ionian C D E F G A B C
|
||||
dorian C D Eb F G A Bb C
|
||||
phrygian C Db Eb F G Ab Bb C
|
||||
lydian C D E F# G A B C
|
||||
mixolydian C D E F G A Bb C
|
||||
aeolian C D Eb F G Ab Bb C
|
||||
locrian C Db Eb F Gb Ab Bb C
|
||||
|
||||
Circle of Fifths
|
||||
----------------
|
||||
|
||||
Display the circle of fifths and fourths from any note::
|
||||
|
||||
$ pytheory circle C
|
||||
Circle of fifths from C:
|
||||
→ C → G → D → A → E → B → F# → C# → G# → D# → A# → F
|
||||
|
||||
Circle of fourths from C:
|
||||
→ C → F → A# → D# → G# → C# → F# → B → E → A → D → G
|
||||
|
||||
Common Progressions
|
||||
-------------------
|
||||
|
||||
Show all named progressions realized in a key::
|
||||
|
||||
$ pytheory progressions C major
|
||||
Common progressions in C major:
|
||||
|
||||
I-IV-V-I C → F → G → C
|
||||
I-V-vi-IV C → G → Am → F
|
||||
12-bar blues C → C → C → C → F → F → C → C → G → F → C → G
|
||||
ii-V-I Dm → G7 → C
|
||||
...
|
||||
|
||||
The CLI is there for quick lookups when you don't want to open a Python session -- just ask your question and get back to playing.
|
||||
@@ -0,0 +1,547 @@
|
||||
Cookbook
|
||||
=======
|
||||
|
||||
Real-world recipes for common musical tasks. Each recipe is self-contained
|
||||
and ready to paste into a Python session.
|
||||
|
||||
Analyze a Song
|
||||
--------------
|
||||
|
||||
Take the chord progression from "Let It Be" (C G Am F) and analyze it
|
||||
in the key of C major:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Chord, Key
|
||||
|
||||
>>> C = Chord.from_name("C")
|
||||
>>> G = Chord.from_name("G")
|
||||
>>> Am = Chord.from_name("Am")
|
||||
>>> F = Chord.from_name("F")
|
||||
|
||||
>>> [c.identify() for c in [C, G, Am, F]]
|
||||
['C major', 'G major', 'A minor', 'F major']
|
||||
|
||||
>>> [c.analyze("C") for c in [C, G, Am, F]]
|
||||
['I', 'V', 'vi', 'IV']
|
||||
|
||||
>>> key = Key("C", "major")
|
||||
>>> [c.identify() for c in key.progression("I", "V", "vi", "IV")]
|
||||
['C major', 'G major', 'A minor', 'F major']
|
||||
|
||||
Write a 12-Bar Blues
|
||||
--------------------
|
||||
|
||||
The `12-bar blues <https://en.wikipedia.org/wiki/Twelve-bar_blues>`_ is
|
||||
built from the I, IV, and V chords. Here it is in the key of A:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Key, Chord
|
||||
|
||||
>>> key = Key("A", "major")
|
||||
>>> [c.identify() for c in key.progression("I", "IV", "V")]
|
||||
['A major', 'D major', 'E major']
|
||||
|
||||
>>> bars = ["I","I","I","I", "IV","IV","I","I", "V","IV","I","V"]
|
||||
>>> [c.identify() for c in key.progression(*bars)]
|
||||
['A major', 'A major', 'A major', 'A major', 'D major', 'D major', 'A major', 'A major', 'E major', 'D major', 'A major', 'E major']
|
||||
|
||||
>>> Chord.from_name("A7").identify()
|
||||
'A dominant 7th'
|
||||
>>> Chord.from_name("D7").identify()
|
||||
'D dominant 7th'
|
||||
>>> Chord.from_name("E7").identify()
|
||||
'E dominant 7th'
|
||||
|
||||
Find Chords in a Key
|
||||
--------------------
|
||||
|
||||
The :class:`~pytheory.scales.Key` class builds diatonic chords for any
|
||||
key and lets you pull progressions by Roman numeral or Nashville number:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Key
|
||||
|
||||
>>> key = Key("G", "major")
|
||||
>>> key.chords
|
||||
['G major', 'A minor', 'B minor', 'C major', 'D major', 'E minor', 'F# diminished']
|
||||
|
||||
>>> [c.identify() for c in key.progression("I", "V", "vi", "IV")]
|
||||
['G major', 'D major', 'E minor', 'C major']
|
||||
|
||||
>>> [c.identify() for c in key.nashville(1, 5, 6, 4)]
|
||||
['G major', 'D major', 'E minor', 'C major']
|
||||
|
||||
Compare Scales
|
||||
--------------
|
||||
|
||||
Play the same tonic through different scales to hear how each mode
|
||||
reshapes the palette. The western modes share the same notes but start
|
||||
on different degrees; the blues scale adds the "blue note" (flat 5th):
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
>>> c = TonedScale(tonic="C4")
|
||||
>>> c["major"].note_names
|
||||
['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
>>> c["minor"].note_names
|
||||
['C', 'D', 'Eb', 'F', 'G', 'Ab', 'Bb', 'C']
|
||||
>>> c["dorian"].note_names
|
||||
['C', 'D', 'Eb', 'F', 'G', 'A', 'Bb', 'C']
|
||||
>>> c["mixolydian"].note_names
|
||||
['C', 'D', 'E', 'F', 'G', 'A', 'Bb', 'C']
|
||||
|
||||
>>> c_blues = TonedScale(tonic="C4", system="blues")
|
||||
>>> c_blues["blues"].note_names
|
||||
['C', 'Eb', 'F', 'Gb', 'G', 'Bb', 'C']
|
||||
|
||||
Guitar Chord Chart
|
||||
------------------
|
||||
|
||||
Generate fingerings for guitar and ukulele with
|
||||
:class:`~pytheory.tones.Fretboard`:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Fretboard
|
||||
|
||||
>>> fb = Fretboard.guitar()
|
||||
>>> fb.chord("C")
|
||||
Fingering(e=0, B=1, G=0, D=2, A=3, E=x)
|
||||
>>> fb.chord("G")
|
||||
Fingering(e=3, B=0, G=0, D=0, A=2, E=3)
|
||||
>>> fb.chord("Am")
|
||||
Fingering(e=0, B=1, G=2, D=2, A=0, E=x)
|
||||
>>> fb.chord("D")
|
||||
Fingering(e=2, B=3, G=2, D=0, A=x, E=x)
|
||||
|
||||
>>> uke = Fretboard.ukulele()
|
||||
>>> uke.chord("C")
|
||||
Fingering(A=3, E=0, C=0, G=0)
|
||||
>>> uke.chord("G")
|
||||
Fingering(A=2, E=3, C=2, G=0)
|
||||
|
||||
Explore an Interval
|
||||
-------------------
|
||||
|
||||
Start from A4 (440 Hz) and walk through intervals, checking names and
|
||||
frequency ratios:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Tone
|
||||
|
||||
>>> a4 = Tone.from_string("A4", system="western")
|
||||
>>> a4.frequency
|
||||
440.0
|
||||
|
||||
>>> minor_3rd = a4 + 3
|
||||
>>> a4.interval_to(minor_3rd)
|
||||
'minor 3rd'
|
||||
|
||||
>>> p5 = a4 + 7
|
||||
>>> a4.interval_to(p5)
|
||||
'perfect 5th'
|
||||
>>> round(p5.frequency / a4.frequency, 4)
|
||||
1.4983
|
||||
|
||||
>>> octave = a4 + 12
|
||||
>>> a4.interval_to(octave)
|
||||
'octave'
|
||||
>>> round(octave.frequency / a4.frequency, 4)
|
||||
2.0
|
||||
|
||||
Walk the Circle of Fifths
|
||||
-------------------------
|
||||
|
||||
The `circle of fifths <https://en.wikipedia.org/wiki/Circle_of_fifths>`_
|
||||
is the backbone of Western harmony — each step adds one sharp or flat:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Tone
|
||||
|
||||
>>> c = Tone.from_string("C4", system="western")
|
||||
>>> [t.name for t in c.circle_of_fifths()]
|
||||
['C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#', 'G#', 'D#', 'A#', 'F']
|
||||
|
||||
>>> g = Tone.from_string("G4", system="western")
|
||||
>>> [t.name for t in g.circle_of_fifths()]
|
||||
['G', 'D', 'A', 'E', 'B', 'F#', 'C#', 'G#', 'D#', 'A#', 'F', 'C']
|
||||
|
||||
Voice Leading Between Chords
|
||||
-----------------------------
|
||||
|
||||
Find the smoothest path from one chord to the next — each voice moves
|
||||
the minimum distance:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Chord
|
||||
|
||||
>>> c_maj = Chord.from_tones("C", "E", "G")
|
||||
>>> f_maj = Chord.from_tones("F", "A", "C")
|
||||
|
||||
>>> for src, dst, motion in c_maj.voice_leading(f_maj):
|
||||
... print(f"{src} -> {dst} ({motion:+d} semitones)")
|
||||
G4 -> A4 (+2 semitones)
|
||||
E4 -> F4 (+1 semitones)
|
||||
C4 -> C4 (+0 semitones)
|
||||
|
||||
Measure Harmonic Tension
|
||||
------------------------
|
||||
|
||||
Quantify how much a chord "wants to resolve." Dominant 7ths have
|
||||
the most tension — the tritone between the 3rd and 7th pulls toward
|
||||
resolution:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Chord
|
||||
|
||||
>>> for name in ["C", "Am", "G7", "Cmaj7"]:
|
||||
... ch = Chord.from_name(name)
|
||||
... t = ch.tension
|
||||
... print(f"{name:6s} tension={t['score']:.2f} tritones={t['tritones']} dominant={t['has_dominant_function']}")
|
||||
C tension=0.00 tritones=0 dominant=False
|
||||
Am tension=0.00 tritones=0 dominant=False
|
||||
G7 tension=0.60 tritones=1 dominant=True
|
||||
Cmaj7 tension=0.15 tritones=0 dominant=False
|
||||
|
||||
Tritone Substitution (Jazz)
|
||||
---------------------------
|
||||
|
||||
Replace any dominant chord with the one a
|
||||
`tritone <https://en.wikipedia.org/wiki/Tritone_substitution>`_ away —
|
||||
they share the same tritone interval:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Chord
|
||||
|
||||
>>> g7 = Chord.from_name("G7")
|
||||
>>> g7.tritone_sub().identify()
|
||||
'C# dominant 7th'
|
||||
|
||||
>>> # ii-V-I with tritone sub:
|
||||
>>> # Dm7 -> G7 -> Cmaj7 (standard)
|
||||
>>> # Dm7 -> Db7 -> Cmaj7 (chromatic bass line!)
|
||||
|
||||
Key Signatures and Detection
|
||||
-----------------------------
|
||||
|
||||
View the accidentals in any key, or detect the key from a set of notes:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Key
|
||||
|
||||
>>> Key("C", "major").signature
|
||||
{'sharps': 0, 'flats': 0, 'accidentals': []}
|
||||
>>> Key("G", "major").signature
|
||||
{'sharps': 1, 'flats': 0, 'accidentals': ['F#']}
|
||||
>>> Key("D", "major").signature
|
||||
{'sharps': 2, 'flats': 0, 'accidentals': ['F#', 'C#']}
|
||||
|
||||
>>> Key.detect("C", "E", "G", "A", "D")
|
||||
<Key C major>
|
||||
|
||||
Relative and Parallel Keys
|
||||
--------------------------
|
||||
|
||||
Every major key has a **relative minor** (same notes, different root)
|
||||
and a **parallel minor** (same root, different notes):
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Key
|
||||
|
||||
>>> c = Key("C", "major")
|
||||
>>> c.relative
|
||||
'A minor'
|
||||
>>> c.parallel
|
||||
'C minor'
|
||||
|
||||
Borrowed Chords and Secondary Dominants
|
||||
---------------------------------------
|
||||
|
||||
Add color by borrowing from the parallel key or building secondary
|
||||
dominants that approach other scale degrees:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Key
|
||||
|
||||
>>> c = Key("C", "major")
|
||||
|
||||
>>> c.borrowed_chords[:4]
|
||||
['C minor', 'D diminished', 'Eb major', 'F minor']
|
||||
|
||||
>>> c.secondary_dominant(5).identify()
|
||||
'D dominant 7th'
|
||||
>>> c.secondary_dominant(2).identify()
|
||||
'A dominant 7th'
|
||||
>>> c.secondary_dominant(6).identify()
|
||||
'E dominant 7th'
|
||||
|
||||
The Overtone Series
|
||||
-------------------
|
||||
|
||||
Every musical tone contains a stack of harmonics — the physics behind
|
||||
why intervals sound consonant:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Tone
|
||||
|
||||
>>> a4 = Tone.from_string("A4", system="western")
|
||||
>>> [round(f, 1) for f in a4.overtones(6)]
|
||||
[440.0, 880.0, 1320.0, 1760.0, 2200.0, 2640.0]
|
||||
|
||||
>>> # Harmonic 2 = octave (2:1)
|
||||
>>> # Harmonic 3 = perfect 5th + octave (3:1)
|
||||
>>> # Harmonic 5 = major 3rd + two octaves (5:1)
|
||||
|
||||
Enharmonic Spellings
|
||||
--------------------
|
||||
|
||||
Find the alternate name for any sharp or flat:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Tone
|
||||
|
||||
>>> for name in ["C#4", "D#4", "F#4", "G#4"]:
|
||||
... t = Tone.from_string(name, system="western")
|
||||
... print(f"{t.name} = {t.enharmonic}")
|
||||
C# = Db
|
||||
D# = Eb
|
||||
F# = Gb
|
||||
G# = Ab
|
||||
|
||||
World Scales
|
||||
------------
|
||||
|
||||
Explore scales from Indian, Arabic, and Japanese traditions:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
>>> indian = TonedScale(tonic="Sa", system="indian")
|
||||
>>> indian["bhairav"].note_names
|
||||
['Sa', 'komal Re', 'Ga', 'Ma', 'Pa', 'komal Dha', 'Ni', 'Sa']
|
||||
|
||||
>>> arabic = TonedScale(tonic="Do", system="arabic")
|
||||
>>> arabic["hijaz"].note_names
|
||||
['Do', 'Reb', 'Mi', 'Fa', 'Sol', 'Solb', 'Sib', 'Do']
|
||||
|
||||
>>> japanese = TonedScale(tonic="C4", system="japanese")
|
||||
>>> japanese["hirajoshi"].note_names
|
||||
['C', 'D', 'Eb', 'G', 'Ab', 'C']
|
||||
|
||||
Visualize a Scale on Guitar
|
||||
----------------------------
|
||||
|
||||
See where the notes fall across the fretboard — E minor pentatonic,
|
||||
the most-played scale in rock:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Fretboard, Scale
|
||||
|
||||
>>> fb = Fretboard.guitar()
|
||||
>>> pent = Scale(tonic="E4", system="blues")["minor pentatonic"]
|
||||
>>> print(fb.scale_diagram(pent, frets=12))
|
||||
0 1 2 3 4 5 6 7 8 9 10 11 12
|
||||
E| E | - | - | G | - | A | - | B | - | - | D | - | E |
|
||||
B| B | - | - | D | - | E | - | - | G | - | A | - | B |
|
||||
G| G | - | A | - | B | - | - | D | - | E | - | - | G |
|
||||
D| D | - | E | - | - | G | - | A | - | B | - | - | D |
|
||||
A| A | - | B | - | - | D | - | E | - | - | G | - | A |
|
||||
E| E | - | - | G | - | A | - | B | - | - | D | - | E |
|
||||
|
||||
Composition Recipes
|
||||
-------------------
|
||||
|
||||
These recipes go beyond theory into actual music-making.
|
||||
|
||||
Acid House Track
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
303-style acid with sidechain pump:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score, Pattern, Duration, Chord
|
||||
from pytheory.play import play_score
|
||||
|
||||
score = Score("4/4", bpm=132)
|
||||
score.drums("house", repeats=8, fill="house", fill_every=8)
|
||||
|
||||
pad = score.part(
|
||||
"pad",
|
||||
synth="supersaw",
|
||||
envelope="pad",
|
||||
reverb=0.4,
|
||||
chorus=0.3,
|
||||
sidechain=0.85,
|
||||
)
|
||||
acid = score.part(
|
||||
"acid",
|
||||
synth="saw",
|
||||
envelope="pad",
|
||||
legato=True,
|
||||
glide=0.03,
|
||||
distortion=0.8,
|
||||
distortion_drive=8.0,
|
||||
lowpass=1000,
|
||||
lowpass_q=5.0,
|
||||
)
|
||||
acid.lfo("lowpass", rate=0.5, min=600, max=2500, bars=8)
|
||||
|
||||
for sym in ["Cm", "Fm", "Abm", "Gm"]:
|
||||
pad.add(Chord.from_symbol(sym), Duration.WHOLE)
|
||||
pad.add(Chord.from_symbol(sym), Duration.WHOLE)
|
||||
acid.arpeggio(sym, bars=2, pattern="up", octaves=2)
|
||||
|
||||
play_score(score)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/acid_house.wav" type="audio/wav"></audio>
|
||||
|
||||
Dub Reggae with Delay Madness
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Sparse notes into infinite echo:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=72)
|
||||
score.drums("dub", repeats=8)
|
||||
|
||||
melodica = score.part(
|
||||
"melodica",
|
||||
synth="triangle",
|
||||
envelope="pluck",
|
||||
delay=0.5,
|
||||
delay_time=0.66,
|
||||
delay_feedback=0.55,
|
||||
reverb=0.4,
|
||||
reverb_type="cathedral",
|
||||
)
|
||||
bass = score.part("bass", synth="sine", lowpass=400, lowpass_q=1.5)
|
||||
|
||||
# Play almost nothing — let the delay do the work
|
||||
melodica.add("A4", 2).rest(6)
|
||||
melodica.add("E5", 1.5).rest(6.5)
|
||||
melodica.add("D5", 1).add("C5", 1).add("A4", 2).rest(4)
|
||||
|
||||
for n in ["A1"] * 16:
|
||||
bass.add(n, Duration.HALF)
|
||||
|
||||
play_score(score)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/dub_reggae.wav" type="audio/wav"></audio>
|
||||
|
||||
Jazz Ballad with Humanize
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The difference between a robot and a musician:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=72, swing=0.5)
|
||||
score.drums("jazz", repeats=8)
|
||||
|
||||
rhodes = score.part(
|
||||
"rhodes",
|
||||
synth="fm",
|
||||
envelope="piano",
|
||||
reverb=0.4,
|
||||
reverb_type="plate",
|
||||
humanize=0.3,
|
||||
)
|
||||
lead = score.part(
|
||||
"lead",
|
||||
synth="triangle",
|
||||
envelope="strings",
|
||||
delay=0.25,
|
||||
reverb=0.3,
|
||||
humanize=0.35,
|
||||
)
|
||||
|
||||
key = Key("Bb", "major")
|
||||
for chord in key.progression("I", "vi", "ii", "V") * 2:
|
||||
rhodes.add(chord, Duration.WHOLE)
|
||||
|
||||
for n, d in [("D5", 1.5), ("F5", 0.5), ("Bb5", 2), (None, 4),
|
||||
("A5", 1), ("G5", 1), ("F5", 2), (None, 4)]:
|
||||
lead.rest(d) if n is None else lead.add(n, d)
|
||||
|
||||
play_score(score)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/jazz_ballad.wav" type="audio/wav"></audio>
|
||||
|
||||
Song with Sections
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Define once, arrange freely:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=120)
|
||||
score.drums("rock", repeats=16, fill="rock", fill_every=4)
|
||||
|
||||
chords = score.part("chords", synth="saw", envelope="pad")
|
||||
lead = score.part("lead", synth="triangle", envelope="pluck")
|
||||
|
||||
score.section("verse")
|
||||
for sym in ["Am", "F", "C", "G"]:
|
||||
chords.add(Chord.from_symbol(sym), Duration.WHOLE)
|
||||
lead.add("A4", 1).add("C5", 1).add("E5", 1).rest(1)
|
||||
lead.add("F5", 1).add("E5", 1).add("C5", 2)
|
||||
|
||||
score.section("chorus")
|
||||
lead.set(reverb=0.4, lowpass=5000)
|
||||
for sym in ["F", "G", "Am", "C"]:
|
||||
chords.add(Chord.from_symbol(sym), Duration.WHOLE)
|
||||
lead.add("C6", 2).add("A5", 1).add("G5", 1)
|
||||
lead.add("F5", 2).add("E5", 2)
|
||||
score.end_section()
|
||||
|
||||
score.repeat("verse")
|
||||
score.repeat("chorus", times=2)
|
||||
|
||||
play_score(score)
|
||||
score.save_midi("my_song.mid")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/song_sections.wav" type="audio/wav"></audio>
|
||||
|
||||
Export Everything to MIDI
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The whole point — sketch fast, finish in your DAW:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Any Score can be saved as MIDI
|
||||
score.save_midi("track.mid")
|
||||
|
||||
# Simple progressions too
|
||||
from pytheory import save_midi
|
||||
chords = Key("C", "major").progression("I", "V", "vi", "IV")
|
||||
save_midi(chords, "pop.mid", t=500, bpm=120)
|
||||
|
||||
These are all starting points. Change the key, swap the chords, layer in your own ideas -- the best way to learn is to take something that works and make it yours.
|
||||
@@ -0,0 +1,614 @@
|
||||
Drums
|
||||
=====
|
||||
|
||||
Drums are the foundation of almost everything. Change the drum pattern
|
||||
and you change the genre. The same four chords over a bossa nova
|
||||
pattern sound like you're in a cafe in Rio. Put those same chords over
|
||||
a rock beat and you're in a garage in Seattle. Over a trap beat, you're
|
||||
in Atlanta. Over a dancehall pattern, you're in Kingston. The drums ARE
|
||||
the genre -- they tell the listener's body how to move before a single
|
||||
melodic note is played.
|
||||
|
||||
PyTheory includes a complete drum system -- 51 synthesized percussion
|
||||
sounds, 95+ pattern presets across dozens of genres, and 30 fill presets.
|
||||
Every sound is generated from waveforms; no samples needed.
|
||||
|
||||
Drum Sounds
|
||||
-----------
|
||||
|
||||
Drum hits are **humanized by default** — each hit gets a tiny random
|
||||
timing offset and velocity wobble, just like a real drummer who's never
|
||||
perfectly on the grid. Control the amount with ``drum_humanize`` on the
|
||||
Score:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=120, drum_humanize=0.4) # natural feel
|
||||
score = Score("4/4", bpm=120, drum_humanize=0.0) # perfectly quantized
|
||||
score = Score("4/4", bpm=120, drum_humanize=0.1) # studio tight
|
||||
|
||||
The default is 0.15 — just enough to feel alive without sounding loose.
|
||||
|
||||
Drums Are Parts
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Drums are a real Part — the same as any melodic voice. You can set
|
||||
effects on them the same way:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score.drums("rock", repeats=4)
|
||||
score.parts["drums"].reverb_mix = 0.2
|
||||
score.parts["drums"].reverb_type = "plate"
|
||||
|
||||
Or use the shorthand:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score.set_drum_effects(reverb=0.2, reverb_type="plate", lowpass=8000)
|
||||
|
||||
Split Drums
|
||||
~~~~~~~~~~~
|
||||
|
||||
For maximum control, split the kit into separate Parts — kick, snare,
|
||||
hats, toms, cymbals, and percussion — each with independent effects:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score.drums("rock", repeats=4, split=True)
|
||||
|
||||
# Now each group is its own Part
|
||||
score.parts["snare"].reverb_mix = 0.3
|
||||
score.parts["snare"].reverb_type = "plate"
|
||||
score.parts["hats"].lowpass = 7000
|
||||
score.parts["kick"] # dry, no effects
|
||||
|
||||
# set_drum_effects still works — applies to all drum Parts
|
||||
score.set_drum_effects(reverb=0.1)
|
||||
|
||||
This is how real studios work — the snare gets its own reverb send,
|
||||
the hats get their own EQ, the kick stays dry and punchy. Now you
|
||||
can do the same thing in Python.
|
||||
|
||||
Sidechain compression triggers on kick hits only — hi-hats and snares
|
||||
don't duck the pad.
|
||||
|
||||
Every drum sound is stereo-panned like a real kit — kick and snare
|
||||
center, hi-hat right, crash left, toms spread across the field,
|
||||
percussion instruments placed naturally. Put on headphones and you'll
|
||||
hear the kit in front of you.
|
||||
|
||||
The ``DrumSound`` enum maps to General MIDI percussion note numbers:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import DrumSound
|
||||
|
||||
>>> DrumSound.KICK.value
|
||||
36
|
||||
>>> DrumSound.SNARE.value
|
||||
38
|
||||
>>> DrumSound.CLOSED_HAT.value
|
||||
42
|
||||
|
||||
All 51 sounds, organized by type:
|
||||
|
||||
**Kicks:** KICK (36)
|
||||
|
||||
**Snares:** SNARE (38), RIMSHOT (37), CLAP (39)
|
||||
|
||||
**Hi-hats:** CLOSED_HAT (42), OPEN_HAT (46), PEDAL_HAT (44)
|
||||
|
||||
**Toms:** LOW_TOM (45), MID_TOM (47), HIGH_TOM (50)
|
||||
|
||||
**Cymbals:** CRASH (49), RIDE (51), RIDE_BELL (53)
|
||||
|
||||
**Percussion:** COWBELL (56), CLAVE (75), SHAKER (70), TAMBOURINE (54),
|
||||
CONGA_HIGH (63), CONGA_LOW (64), BONGO_HIGH (60), BONGO_LOW (61),
|
||||
TIMBALE_HIGH (65), TIMBALE_LOW (66), AGOGO_HIGH (67), AGOGO_LOW (68),
|
||||
GUIRO (73)
|
||||
|
||||
**Tabla:** TABLA_NA (86), TABLA_TIN (87), TABLA_GE (88), TABLA_DHA (89),
|
||||
TABLA_TIT (90), TABLA_KE (91), TABLA_GE_BEND (108 -- bayan with upward
|
||||
pitch bend from palm pressing into the head)
|
||||
|
||||
**Dhol:** DHOL_DAGGA (92), DHOL_TILLI (93), DHOL_BOTH (94)
|
||||
|
||||
**Dholak:** DHOLAK_GE (95), DHOLAK_NA (96), DHOLAK_TIT (97)
|
||||
|
||||
**Mridangam:** MRIDANGAM_THAM (98), MRIDANGAM_NAM (99), MRIDANGAM_DIN (100),
|
||||
MRIDANGAM_THA (101)
|
||||
|
||||
**Djembe:** DJEMBE_BASS (102), DJEMBE_TONE (103), DJEMBE_SLAP (104)
|
||||
|
||||
**Cajón:** CAJON_BASS (108), CAJON_SLAP (109), CAJON_TAP (110)
|
||||
|
||||
**Metal Kit:** METAL_KICK (105), METAL_SNARE (106), METAL_HAT (107)
|
||||
|
||||
**Marching Snare:** MARCH_SNARE (115), MARCH_RIMSHOT (116), MARCH_CLICK (118)
|
||||
|
||||
**Quads (Tenors):** QUAD_1 (119), QUAD_2 (120), QUAD_3 (121), QUAD_4 (122),
|
||||
QUAD_SPOCK (123)
|
||||
|
||||
**Marching Bass:** BASS_1 (124), BASS_2 (125), BASS_3 (126), BASS_4 (127),
|
||||
BASS_5 (80)
|
||||
|
||||
Drum Synthesis
|
||||
--------------
|
||||
|
||||
Every drum sound here is synthesized from scratch using the same
|
||||
techniques that real drum machines use. This isn't a shortcut -- it's
|
||||
the real thing. The 808 kick that defined hip hop is literally a sine
|
||||
wave with a pitch envelope sweeping from 150 Hz down to 50 Hz. The 909
|
||||
snare that powered techno is a sine wave body mixed with white noise
|
||||
rattle. The hi-hat is just filtered noise with a short decay. When
|
||||
Roland built the TR-808 and TR-909, they weren't sampling real drums;
|
||||
they were synthesizing them from basic waveforms. PyTheory does the
|
||||
same thing.
|
||||
|
||||
Each sound has a dedicated synthesizer:
|
||||
|
||||
- **KICK** -- sine wave with pitch envelope sweep (150 to 50 Hz) + sub click
|
||||
- **SNARE** -- pitched body (180 Hz) + white noise rattle
|
||||
- **CLOSED_HAT** -- high-frequency noise, 50ms decay
|
||||
- **OPEN_HAT** -- high-frequency noise, 250ms decay
|
||||
- **CLAP** -- layered noise bursts with spacers
|
||||
- **RIMSHOT** -- bright 800 Hz click + noise
|
||||
- **TOMS** -- pitched sine with sweep (low=100, mid=150, high=200 Hz)
|
||||
- **CRASH** -- long noise decay (1.5s)
|
||||
- **RIDE** -- metallic ring (3500+5100 Hz) + noise
|
||||
- **RIDE_BELL** -- brighter ring, more sustain
|
||||
- **COWBELL** -- two detuned tones (545+815 Hz)
|
||||
- **CLAVE** -- short 2500 Hz click
|
||||
- **CONGAS/BONGOS** -- pitched membrane with slap transient
|
||||
- **TIMBALES** -- bright metallic ring with overtones
|
||||
- **AGOGO** -- pitched bell with harmonics
|
||||
- **SHAKER/MARACAS** -- short noise burst
|
||||
- **TAMBOURINE** -- noise + 7000 Hz jingle ring
|
||||
- **GUIRO** -- scraped noise bursts
|
||||
|
||||
Pattern Presets
|
||||
---------------
|
||||
|
||||
80+ patterns spanning genres from rock to Afro-Cuban to electronic to
|
||||
world percussion. Load them with ``Pattern.preset()``:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Pattern
|
||||
|
||||
>>> Pattern.list_presets()
|
||||
['12/8 blues', '6/8 afro-cuban', 'afrobeat', 'baiao', 'bebop', ...]
|
||||
|
||||
>>> rock = Pattern.preset("rock")
|
||||
>>> rock
|
||||
<Pattern 'rock' 4/4 4.0 beats 12 hits>
|
||||
|
||||
**Rock/Pop:** rock, half time, double time, disco, motown, train beat
|
||||
-- The backbone of Western popular music. Kick on 1 and 3, snare on 2
|
||||
and 4. Simple, effective, universal.
|
||||
|
||||
**Jazz:** jazz, bebop, shuffle, swing, linear, paradiddle -- The ride
|
||||
cymbal drives everything. The kick and snare comp and converse rather
|
||||
than keeping strict time. These patterns swing.
|
||||
|
||||
**Latin:** salsa, bossa nova, samba, cumbia, merengue, baiao, maracatu,
|
||||
bolero, tango -- Rich, layered patterns built on clave rhythms, with
|
||||
congas, timbales, and shakers creating interlocking polyrhythmic webs.
|
||||
Some of the most sophisticated drumming traditions on the planet.
|
||||
|
||||
**Afro-Cuban:** son clave 3-2, son clave 2-3, rumba clave 3-2,
|
||||
rumba clave 2-3, cascara, guaguanco, mozambique, nanigo, bembe,
|
||||
6/8 afro-cuban, tresillo, habanera -- The clave is the key that
|
||||
unlocks all Latin and Afro-Cuban music. It's a five-note rhythmic
|
||||
cell that everything else revolves around. If you learn one concept
|
||||
from world music, learn the clave.
|
||||
|
||||
**African:** afrobeat, highlife -- Born in West Africa. Fela Kuti's
|
||||
afrobeat layers multiple percussion voices into hypnotic,
|
||||
polyrhythmic grooves that can go on for twenty minutes.
|
||||
|
||||
**Caribbean:** reggae, dancehall, ska, dub -- The offbeat is king.
|
||||
Reggae flips rock drumming inside out by emphasizing the "and" of each
|
||||
beat instead of the beat itself. Ska doubles the tempo, dancehall
|
||||
adds syncopation.
|
||||
|
||||
**Electronic:** house, techno, trap, drum and bass, breakbeat, jungle
|
||||
-- Machine music. The four-on-the-floor kick of house and techno, the
|
||||
rattling hi-hats of trap, the breakneck tempo of drum and bass. These
|
||||
patterns were born in drum machines and they still live there.
|
||||
|
||||
**Metal/Punk:** metal, blast beat, punk, double kick, metal blast,
|
||||
metal groove, metal gallop -- Speed and aggression. The blast beat is
|
||||
both feet and both hands going as fast as humanly possible. Punk strips
|
||||
everything to its essentials. The metal kit adds 3 dedicated sounds
|
||||
(double kick, china cymbal, stack) and 4 patterns for extreme metal
|
||||
subgenres.
|
||||
|
||||
**World Percussion:** tabla, dhol, dholak, mridangam, djembe, cajón --
|
||||
Deep traditions from across the globe, each with authentic sound sets and
|
||||
idiomatic patterns. See the World Percussion section below for details.
|
||||
|
||||
**Other:** funk, hip hop, bo diddley, second line, new orleans, waltz,
|
||||
12/8 blues, country, gospel, flamenco -- Everything else. The syncopated
|
||||
groove of funk, the sampled feel of hip hop, the street-parade swing
|
||||
of New Orleans second line.
|
||||
|
||||
Playing Patterns
|
||||
----------------
|
||||
|
||||
``play_pattern()`` synthesizes every drum sound in real-time:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Pattern
|
||||
from pytheory.play import play_pattern
|
||||
|
||||
play_pattern(Pattern.preset("rock"), repeats=4, bpm=120)
|
||||
play_pattern(Pattern.preset("bossa nova"), repeats=4, bpm=140)
|
||||
play_pattern(Pattern.preset("salsa"), repeats=4, bpm=180)
|
||||
play_pattern(Pattern.preset("afrobeat"), repeats=8, bpm=110)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/rock_beat.wav" type="audio/wav"></audio>
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/bossa_nova_pattern.wav" type="audio/wav"></audio>
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/salsa_pattern.wav" type="audio/wav"></audio>
|
||||
<audio controls style="width:100%;margin:0.3em 0 1.5em"><source src="../_static/audio/afrobeat_pattern.wav" type="audio/wav"></audio>
|
||||
|
||||
Fills
|
||||
-----
|
||||
|
||||
A fill is the drummer's way of saying "something's about to change."
|
||||
It's that moment at the end of a verse where the drummer breaks the
|
||||
pattern and rolls around the toms before crashing into the chorus. Fills
|
||||
signal transitions -- they tell the listener's ear that the section is
|
||||
ending and a new one is about to begin. Without fills, a drum pattern
|
||||
just loops. With them, it breathes and has structure.
|
||||
|
||||
``Pattern.fill()`` loads a 1-bar drum fill -- a short break that
|
||||
transitions between sections. 30 fill presets are available:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Pattern.list_fills()
|
||||
['afrobeat', 'blast', 'bossa nova', 'breakdown', 'buildup',
|
||||
'cajon breakdown', 'cajon flam', 'cajon rumble',
|
||||
'cumbia', 'disco', 'djembe break', 'djembe call', 'djembe roll',
|
||||
'funk', 'highlife', 'hip hop', 'house',
|
||||
'jazz', 'jazz brush', 'metal', 'metal blast', 'metal cascade',
|
||||
'metal triplet', 'reggae', 'rock', 'rock crash',
|
||||
'salsa', 'samba', 'second line', 'trap']
|
||||
|
||||
>>> fill = Pattern.fill("rock")
|
||||
>>> fill
|
||||
<Pattern 'rock fill' 4/4 4.0 beats ...>
|
||||
|
||||
Score Integration
|
||||
-----------------
|
||||
|
||||
The ``score.drums()`` shorthand attaches a drum pattern to a score:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score
|
||||
|
||||
score = Score("4/4", bpm=140)
|
||||
score.drums("bossa nova", repeats=4)
|
||||
|
||||
Auto-Fills
|
||||
~~~~~~~~~~
|
||||
|
||||
The ``fill`` and ``fill_every`` parameters automatically insert drum
|
||||
fills at regular intervals:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=120)
|
||||
score.drums("rock", repeats=8, fill="rock", fill_every=4)
|
||||
|
||||
This plays the rock pattern for 8 bars, replacing every 4th bar with
|
||||
a rock fill. Useful for adding natural phrasing to longer sections.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Jazz with brush fills every 8 bars
|
||||
score.drums("bebop", repeats=16, fill="jazz brush", fill_every=8)
|
||||
|
||||
# Salsa with fills every 4 bars
|
||||
score.drums("salsa", repeats=8, fill="salsa", fill_every=4)
|
||||
|
||||
Layering Patterns
|
||||
-----------------
|
||||
|
||||
Combine drum patterns with melodic parts for full arrangements. The
|
||||
drum pattern and all named parts are mixed together by ``play_score()``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score, Key, Duration, Chord
|
||||
from pytheory.play import play_score
|
||||
|
||||
score = Score("4/4", bpm=180)
|
||||
score.drums("salsa", repeats=4, fill="salsa", fill_every=4)
|
||||
|
||||
pads = score.part("pads", synth="sine", envelope="pad", volume=0.3)
|
||||
lead = score.part("lead", synth="saw", envelope="pluck", volume=0.4)
|
||||
bass = score.part("bass", synth="sine", envelope="pluck", volume=0.45)
|
||||
|
||||
for chord in Key("D", "minor").progression("ii", "V", "i", "i") * 2:
|
||||
pads.add(chord, Duration.WHOLE)
|
||||
|
||||
lead.add("A5", 0.67).add("G5", 0.33).add("F5", 0.67).add("E5", 0.33)
|
||||
|
||||
for n in ["D2", "A2", "D2", "F2"] * 2:
|
||||
bass.add(n, Duration.QUARTER)
|
||||
|
||||
play_score(score)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/salsa_layered.wav" type="audio/wav"></audio>
|
||||
|
||||
World Percussion
|
||||
----------------
|
||||
|
||||
PyTheory includes dedicated sound sets and pattern presets for
|
||||
traditional percussion instruments from around the world. Each
|
||||
instrument has its own synthesized sounds that capture the timbral
|
||||
character of the real instrument, plus idiomatic rhythmic patterns
|
||||
drawn from their musical traditions.
|
||||
|
||||
Tabla
|
||||
~~~~~
|
||||
|
||||
The tabla is a pair of hand drums from the Indian subcontinent -- the
|
||||
smaller, higher-pitched *dayan* and the larger, bass *bayan*. It is
|
||||
the rhythmic backbone of Hindustani classical music, and one of the
|
||||
most expressive percussion instruments ever created. A single tabla
|
||||
player can produce an astonishing range of tones by varying finger
|
||||
placement, pressure, and striking technique.
|
||||
|
||||
**7 sounds** -- covering the primary tabla strokes (na, tin, tun, ge,
|
||||
dha, ke, tit) plus a bayan pitch bend sound (TABLA_GE_BEND) that
|
||||
models the technique of pressing the palm into the bayan head to bend
|
||||
the pitch upward.
|
||||
|
||||
**7 patterns:** teental (16 beats, the most common taal), jhaptaal
|
||||
(10 beats), rupak (7 beats), dadra (6 beats), keherwa (8 beats, folk
|
||||
and light classical), tabla solo, and tiri kita (fast ornamental
|
||||
pattern).
|
||||
|
||||
**5 fills:** tihai (3x crescendo landing on sam), chakkardar (32nd
|
||||
triplet cascade into slam), tiri kita (rapid 16th-note dayan burst),
|
||||
bayan (deep bass bends showcase), tabla call (dayan/bayan call-and-response).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score.drums("teental", repeats=4, fill="tihai")
|
||||
score.drums("keherwa", repeats=4, fill="chakkardar")
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=80)
|
||||
score.drums("teental", repeats=4)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/tabla_teental.wav" type="audio/wav"></audio>
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/tabla_keherwa.wav" type="audio/wav"></audio>
|
||||
<audio controls style="width:100%;margin:0.3em 0 1.5em"><source src="../_static/audio/tabla_chakradar.wav" type="audio/wav"></audio>
|
||||
|
||||
Dhol
|
||||
~~~~
|
||||
|
||||
The dhol is a double-headed barrel drum from Punjab, played with
|
||||
sticks. It is the driving force behind bhangra music -- loud,
|
||||
energetic, and physically impossible to sit still to.
|
||||
|
||||
**3 sounds** -- bass stroke, treble stroke, and rimshot.
|
||||
|
||||
**2 patterns:** bhangra (the classic bhangra groove) and dhol chaal
|
||||
(a processional rhythm).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=160)
|
||||
score.drums("bhangra", repeats=4)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/dhol.wav" type="audio/wav"></audio>
|
||||
|
||||
Dholak
|
||||
~~~~~~
|
||||
|
||||
The dholak is a smaller, lighter two-headed drum used across South
|
||||
Asia in folk music, qawwali, and Bollywood. Played with bare hands,
|
||||
it produces a warm, melodic tone.
|
||||
|
||||
**3 sounds** -- bass, treble, and slap.
|
||||
|
||||
**2 patterns:** qawwali (the rhythmic foundation of Sufi devotional
|
||||
music) and dholak folk (a general folk groove).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=120)
|
||||
score.drums("qawwali", repeats=4)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/dholak.wav" type="audio/wav"></audio>
|
||||
|
||||
Mridangam
|
||||
~~~~~~~~~
|
||||
|
||||
The mridangam is a double-headed drum from South India, the
|
||||
rhythmic anchor of Carnatic classical music. Its tuning system is
|
||||
extraordinarily precise, and its rhythmic vocabulary is among the
|
||||
most mathematically complex in the world.
|
||||
|
||||
**4 sounds** -- tha, thom, nam, and din.
|
||||
|
||||
**2 patterns:** adi talam (the most common Carnatic talam, 8 beats)
|
||||
and mridangam korvai (a rhythmic cadence pattern).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=90)
|
||||
score.drums("adi talam", repeats=4)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/mridangam.wav" type="audio/wav"></audio>
|
||||
|
||||
Djembe
|
||||
~~~~~~
|
||||
|
||||
The djembe is a rope-tuned goblet drum from West Africa, capable of
|
||||
producing a wide range of tones from deep bass to sharp slaps. It is
|
||||
central to the drum ensemble traditions of Mali, Guinea, and Senegal.
|
||||
|
||||
**3 sounds** -- bass (open center strike), tone (edge strike), and
|
||||
slap (sharp edge strike).
|
||||
|
||||
**8 patterns:** djembe (basic accompanying rhythm), kuku (Guinean harvest
|
||||
dance), soli (powerful Mandinka rhythm), dununba (heavy bass-driven),
|
||||
tiriba (joyful Susu rhythm), yankadi (gentle greeting/welcome), djansa
|
||||
(fast Malinke dance), mendiani (women's celebratory dance).
|
||||
|
||||
**3 fills:** djembe call (bass-tone-slap conversation building to climax),
|
||||
djembe roll (rapid slaps accelerating into bass), djembe break (syncopated
|
||||
West African-style break).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=120)
|
||||
score.drums("djembe", repeats=8, fill="djembe call", fill_every=4)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/djembe.wav" type="audio/wav"></audio>
|
||||
|
||||
Metal Kit
|
||||
~~~~~~~~~
|
||||
|
||||
A dedicated percussion kit for extreme metal subgenres, with
|
||||
specialized sounds and patterns that go beyond the standard drum kit.
|
||||
|
||||
**3 sounds** -- double kick (triggered, tight attack), china cymbal,
|
||||
and stack (a short, trashy cymbal choke).
|
||||
|
||||
**4 patterns:** double kick (relentless double bass drum pattern),
|
||||
metal blast (blast beat with china cymbal accents), metal groove (a
|
||||
half-time groove with double kick fills), and metal gallop (the
|
||||
classic triplet-feel gallop rhythm).
|
||||
|
||||
**4 fills:** metal (double kick 16ths with descending toms), metal triplet
|
||||
(double kick triplets with snare accents), metal blast (alternating
|
||||
snare/kick 32nds into half-time crash), metal cascade (descending snare
|
||||
roll → kick roll → alternating → crash ending).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=200)
|
||||
score.drums("metal blast", repeats=8, fill="metal cascade", fill_every=4)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/metal_blast.wav" type="audio/wav"></audio>
|
||||
|
||||
Cajón
|
||||
~~~~~
|
||||
|
||||
The cajón is a box-shaped percussion instrument from Peru, now
|
||||
ubiquitous in acoustic and unplugged settings worldwide. Players sit
|
||||
on the box and strike the front face with their hands.
|
||||
|
||||
**3 sounds** -- bass (deep center thump), slap (sharp, snare-like edge
|
||||
hit with wire buzz), and tap (light finger tap).
|
||||
|
||||
**3 patterns:** cajon (basic groove), cajon rumba (flamenco-style rumba),
|
||||
and cajon folk (folk/acoustic pattern).
|
||||
|
||||
**3 fills:** cajon flam (slaps accelerating into bass hits), cajon rumble
|
||||
(fast taps building to slap accents), cajon breakdown (syncopated
|
||||
bass-slap groove).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=100)
|
||||
score.drums("cajon", repeats=8, fill="cajon flam", fill_every=4)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/cajon.wav" type="audio/wav"></audio>
|
||||
|
||||
Marching Percussion
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A full drumline — snare, quads (tenors), and pitched bass drums.
|
||||
Every sound is synthesized: kevlar snare heads, aluminum shell ting
|
||||
on the quads, felt-beater thwack on the basses.
|
||||
|
||||
**Snare** -- 3 sounds: MARCH_SNARE (tight kevlar tap), MARCH_RIMSHOT
|
||||
(woody-metallic crack), MARCH_CLICK (stick click for count-offs).
|
||||
|
||||
**Quads** -- 5 sounds: QUAD_1 through QUAD_4 (high to low pitched
|
||||
tenors) plus QUAD_SPOCK (rim click on the shell).
|
||||
|
||||
**Bass drums** -- 5 pitched drums: BASS_1 (highest/smallest) through
|
||||
BASS_5 (lowest/biggest), each with a prominent felt-beater thwack.
|
||||
|
||||
**6 patterns:** march (basic 4/4), cadence (8-beat street beat),
|
||||
march paradiddle, march roll (buzz crescendo), quad sweep (run across
|
||||
all 4 drums), quad groove, bass split (cascading across the line),
|
||||
bass unison (all 5 hit together), drumline (snare + quads + bass).
|
||||
|
||||
**Rudiment methods:** ``Part.flam()``, ``Part.diddle()``, and
|
||||
``Part.cheese()`` for marching rudiments on any drum sound.
|
||||
|
||||
**Ensemble rendering:** ``ensemble=N`` on any Part duplicates the
|
||||
voice with per-player timing tendencies and micro pitch drift.
|
||||
``ensemble=8`` for a snare line, ``ensemble=20`` for a massive section.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Full drumline with ensemble
|
||||
snares = score.part("snares", synth="sine", volume=0.9,
|
||||
reverb=0.2, ensemble=8)
|
||||
quads = score.part("quads", synth="sine", volume=0.5,
|
||||
reverb=0.2, ensemble=4)
|
||||
basses = score.part("basses", synth="sine", volume=0.55,
|
||||
reverb=0.2, ensemble=5)
|
||||
|
||||
snares.flam(DrumSound.MARCH_SNARE, Duration.QUARTER, velocity=120)
|
||||
snares.diddle(DrumSound.MARCH_SNARE, Duration.EIGHTH, velocity=60)
|
||||
|
||||
# Or use patterns
|
||||
score.drums("drumline", repeats=4)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/march_snare.wav" type="audio/wav"></audio>
|
||||
|
||||
**Sympathetic resonance:** The marching snare builds up snare wire
|
||||
buzz as hits accumulate, and the buzz decays during rests — just like
|
||||
a real drum.
|
||||
|
||||
MIDI Export
|
||||
-----------
|
||||
|
||||
Convert any pattern to a Score, then export to MIDI (drums are written
|
||||
to channel 10):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
pattern = Pattern.preset("bossa nova")
|
||||
score = pattern.to_score(repeats=8, bpm=140)
|
||||
score.save_midi("bossa.mid")
|
||||
|
||||
Pattern.preset("afrobeat").to_score(repeats=8, bpm=110).save_midi("afrobeat.mid")
|
||||
|
||||
Drums are the foundation. The same chords over a bossa nova feel like a different song than over a rock beat -- change the pattern and you change the genre. Try swapping presets under the same progression and hear how much the drums are really doing.
|
||||
@@ -0,0 +1,912 @@
|
||||
Effects
|
||||
=======
|
||||
|
||||
Effects are how recorded music gets its character. A guitar without
|
||||
reverb sounds like it's being played in a closet. A vocal without
|
||||
compression sounds thin and amateur. A synth without filtering sounds
|
||||
like a test signal. Effects are the difference between "notes" and
|
||||
"music" -- they put the sound in a space, give it texture, and make it
|
||||
feel alive.
|
||||
|
||||
Every record you've ever loved was shaped by effects. The cavernous
|
||||
reverb on a Phil Collins drum hit. The tape delay on a reggae vocal.
|
||||
The distortion on a Hendrix guitar. The chorus on an 80s synth pad.
|
||||
These aren't decorations added after the fact; they're fundamental to
|
||||
the sound itself.
|
||||
|
||||
Each part in a Score can have its own effects chain. Effects are set at
|
||||
part creation and applied per-part before mixing, so every voice gets
|
||||
independent processing.
|
||||
|
||||
Signal Chain
|
||||
------------
|
||||
|
||||
The order of effects matters -- a lot. Distortion before a lowpass
|
||||
filter means you're generating all those rich, crunchy harmonics and
|
||||
then sculpting them with the filter. That's warm, controllable,
|
||||
musical. Filter before distortion means you're distorting the already-
|
||||
filtered signal -- a different, often harsher character. The fixed
|
||||
order in PyTheory matches classic analog synth architecture, the same
|
||||
signal path used by the Moog, the TB-303, and most hardware synths.
|
||||
It's a well-tested order that sounds good by default.
|
||||
|
||||
Effects are applied in this fixed order::
|
||||
|
||||
Signal --> Saturation --> Tremolo --> Distortion --> Cabinet --> Chorus
|
||||
--> Phaser --> Highpass --> Lowpass --> Delay --> Reverb --> Mix
|
||||
|
||||
Additionally, these per-note effects are applied before the part effects chain:
|
||||
|
||||
- **Sub-oscillator**: octave-below sine mixed in at the oscillator stage
|
||||
- **Noise layer**: filtered noise mixed per-note for breath/transients
|
||||
- **Filter envelope**: per-note lowpass sweep (attack/decay/sustain)
|
||||
- **Velocity → brightness**: harder velocity = brighter filter cutoff
|
||||
|
||||
Part-level effects:
|
||||
|
||||
- **Saturation** first: subtle even-harmonic warmth (tape/tube color).
|
||||
- **Tremolo** second: amplitude LFO modulation.
|
||||
- **Distortion** third: drives the signal before filtering.
|
||||
- **Cabinet** fourth: speaker cab simulation (rolloff + presence bump).
|
||||
- **Chorus** fifth: thickens the signal.
|
||||
- **Phaser** sixth: swept allpass notches.
|
||||
- **Highpass** seventh: removes low-frequency mud.
|
||||
- **Lowpass** eighth: shapes the tone (like a tone knob on an amp).
|
||||
- **Delay** ninth: echoes the shaped signal (tap delay / tape echo).
|
||||
- **Reverb** last: places everything in a space (room / hall).
|
||||
|
||||
Distortion
|
||||
----------
|
||||
|
||||
You know what distortion sounds like -- it's the sound of rock and roll.
|
||||
An electric guitar through a cranked amplifier. But at lower levels,
|
||||
distortion is subtler: it adds warmth, presence, and harmonic richness.
|
||||
This is why producers run clean signals through tape machines and tube
|
||||
preamps. A little saturation makes everything sound more "real."
|
||||
|
||||
Soft-clip waveshaping using ``tanh`` -- models the warm saturation of an
|
||||
overdriven tube amplifier. At low drive levels it adds harmonic warmth;
|
||||
at high levels it becomes an aggressive fuzz.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``distortion``: Wet/dry mix, 0.0--1.0.
|
||||
- ``distortion_drive``: Gain before clipping (default 3.0).
|
||||
|
||||
- 0.5--2 = subtle warmth (tube preamp)
|
||||
- 3--8 = overdrive (cranked amp)
|
||||
- 10+ = fuzz
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Warm tube saturation on a bass
|
||||
bass = score.part(
|
||||
"bass",
|
||||
synth="sine",
|
||||
envelope="pluck",
|
||||
distortion=0.3,
|
||||
distortion_drive=2.0,
|
||||
)
|
||||
|
||||
# Heavy fuzz on a lead
|
||||
lead = score.part(
|
||||
"lead",
|
||||
synth="saw",
|
||||
envelope="staccato",
|
||||
distortion=0.8,
|
||||
distortion_drive=10.0,
|
||||
)
|
||||
|
||||
Cabinet Simulation
|
||||
------------------
|
||||
|
||||
A real guitar amp doesn't just distort the signal -- the speaker
|
||||
cabinet shapes the tone dramatically. A 12-inch speaker in a closed
|
||||
cabinet rolls off the harsh high frequencies above 5 kHz and adds a
|
||||
presence bump around 2--3 kHz that gives the sound its "in the room"
|
||||
quality. Without a cabinet, distortion sounds thin and fizzy. With
|
||||
one, it sounds like a real amp.
|
||||
|
||||
PyTheory's cabinet simulation applies a speaker rolloff curve (lowpass
|
||||
at ~5 kHz) combined with a presence resonance bump, placed in the
|
||||
signal chain immediately after distortion -- exactly where it sits in
|
||||
a real amp.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``cabinet``: Wet/dry mix, 0.0--1.0 (default 0, off).
|
||||
|
||||
- 0.3--0.5 = subtle speaker coloring
|
||||
- 0.6--0.8 = classic amp-in-a-room
|
||||
- 1.0 = full cabinet, no dry signal
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Classic rock amp tone: distortion into cabinet
|
||||
guitar = score.part(
|
||||
"guitar",
|
||||
synth="saw",
|
||||
envelope="pluck",
|
||||
distortion=0.6,
|
||||
distortion_drive=5.0,
|
||||
cabinet=0.8,
|
||||
)
|
||||
|
||||
# Clean amp with just cabinet warmth (no distortion)
|
||||
clean = score.part(
|
||||
"clean",
|
||||
synth="triangle",
|
||||
envelope="pluck",
|
||||
cabinet=0.5,
|
||||
)
|
||||
|
||||
Analog Drift
|
||||
------------
|
||||
|
||||
Real analog synthesizers are never perfectly in tune. The voltage-
|
||||
controlled oscillators drift slightly over time as components warm up
|
||||
and temperature fluctuates. This imperfection is actually a big part
|
||||
of why vintage analog synths sound so appealing -- the subtle pitch
|
||||
wandering gives each note a unique, living quality that static digital
|
||||
oscillators lack.
|
||||
|
||||
The ``analog_drift`` parameter adds slow, random pitch variation to
|
||||
each oscillator, modeling this vintage behavior.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``analog_drift``: Drift amount, 0.0--1.0 (default 0, off).
|
||||
|
||||
- 0.05--0.1 = subtle warmth (studio-grade analog)
|
||||
- 0.15--0.25 = noticeable drift (vintage gear warming up)
|
||||
- 0.3+ = unstable, wobbly (broken tape machine)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Warm vintage pad
|
||||
pad = score.part(
|
||||
"pad",
|
||||
synth="supersaw",
|
||||
envelope="pad",
|
||||
analog_drift=0.1,
|
||||
chorus=0.3,
|
||||
)
|
||||
|
||||
# Lo-fi detuned lead
|
||||
lead = score.part(
|
||||
"lead",
|
||||
synth="saw",
|
||||
envelope="pluck",
|
||||
analog_drift=0.25,
|
||||
)
|
||||
|
||||
Chorus
|
||||
------
|
||||
|
||||
That shimmery, wide, slightly-out-of-focus sound that defined the
|
||||
1980s? That's chorus. Think of the intro to "Come As You Are" by
|
||||
Nirvana, or literally any synth pad from 1983 to 1989. It makes one
|
||||
instrument sound like two or three playing together, slightly out of
|
||||
tune with each other -- which is exactly how a real string section or
|
||||
choir sounds rich and full.
|
||||
|
||||
A slightly detuned, LFO-modulated delayed copy mixed back in. Thickens
|
||||
the sound like two musicians playing the same part -- the signature
|
||||
effect of the Roland Juno synthesizers.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``chorus``: Wet/dry mix, 0.0--1.0.
|
||||
- ``chorus_rate``: LFO speed in Hz. 0.5--1 = slow shimmer, 2--4 = vibrato.
|
||||
- ``chorus_depth``: Modulation depth in seconds (default 0.003).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Juno-style pad chorus
|
||||
pad = score.part(
|
||||
"pad",
|
||||
synth="supersaw",
|
||||
envelope="pad",
|
||||
chorus=0.5,
|
||||
chorus_rate=1.5,
|
||||
chorus_depth=0.003,
|
||||
)
|
||||
|
||||
# Subtle thickening on a clean lead
|
||||
lead = score.part(
|
||||
"lead",
|
||||
synth="triangle",
|
||||
envelope="pluck",
|
||||
chorus=0.2,
|
||||
chorus_rate=0.8,
|
||||
)
|
||||
|
||||
Lowpass Filter
|
||||
--------------
|
||||
|
||||
You know that sound when a DJ turns the knob and everything goes
|
||||
underwater? That's a lowpass filter closing down. It removes
|
||||
high-frequency content, leaving only the warm, round, bassy
|
||||
frequencies below the cutoff point. The lowpass filter is arguably the
|
||||
most important effect in all of electronic music -- it's the entire
|
||||
sound of acid house, the "wah" in auto-wah, and the reason analog
|
||||
synths sound warm instead of harsh.
|
||||
|
||||
A 12 dB/octave biquad lowpass filter with resonance -- the sound of
|
||||
analog synthesizers. Removes frequencies above the cutoff; the resonance
|
||||
(Q) parameter adds a peak at the cutoff frequency for that classic
|
||||
"acid squelch."
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``lowpass``: Cutoff frequency in Hz (0 = off). Reference points:
|
||||
|
||||
- 200--400 Hz = deep sub bass
|
||||
- 800--1500 Hz = warm / muffled
|
||||
- 2000--4000 Hz = present lead
|
||||
- 5000+ Hz = subtle rolloff
|
||||
|
||||
- ``lowpass_q``: Resonance / Q factor (default 0.707 = Butterworth flat).
|
||||
|
||||
- 1.0 = slight peak
|
||||
- 2.0 = pronounced
|
||||
- 5.0+ = aggressive acid squelch
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Round bass with gentle filtering
|
||||
bass = score.part(
|
||||
"bass",
|
||||
synth="sine",
|
||||
envelope="pluck",
|
||||
lowpass=400,
|
||||
lowpass_q=1.5,
|
||||
)
|
||||
|
||||
# Acid squelch on a saw lead
|
||||
acid = score.part(
|
||||
"acid",
|
||||
synth="saw",
|
||||
envelope="staccato",
|
||||
lowpass=1500,
|
||||
lowpass_q=5.0,
|
||||
legato=True,
|
||||
glide=0.03,
|
||||
)
|
||||
|
||||
Delay
|
||||
-----
|
||||
|
||||
Delay is echo. Literally. The Edge from U2 built his entire guitar
|
||||
sound around dotted-eighth-note delays. Dub reggae producers like Lee
|
||||
"Scratch" Perry and King Tubby turned delay into an art form, feeding
|
||||
echoes back into themselves until they spiraled into infinity. At short
|
||||
times with low feedback, delay adds rhythmic interest. At long times
|
||||
with high feedback, it creates cascading, psychedelic soundscapes.
|
||||
|
||||
Tempo-synced echoes with feedback. Each repeat feeds back into the
|
||||
delay line, creating rhythmic echo trails. High feedback values produce
|
||||
the cascading, self-oscillating echoes of dub reggae.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``delay``: Wet/dry mix, 0.0--1.0.
|
||||
- ``delay_time``: Time between echoes in seconds. Musically useful
|
||||
values at 120 bpm: 0.25 (8th note), 0.375 (dotted 8th),
|
||||
0.5 (quarter note).
|
||||
- ``delay_feedback``: How much each echo feeds back (0.0--1.0).
|
||||
|
||||
- 0.3 = a few repeats
|
||||
- 0.5 = many repeats
|
||||
- 0.7+ = runaway (dub style)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Dotted-eighth slapback on a lead
|
||||
lead = score.part(
|
||||
"lead",
|
||||
synth="triangle",
|
||||
envelope="strings",
|
||||
delay=0.3,
|
||||
delay_time=0.375,
|
||||
delay_feedback=0.4,
|
||||
)
|
||||
|
||||
# Dub-style runaway echoes
|
||||
melodica = score.part(
|
||||
"melodica",
|
||||
synth="triangle",
|
||||
envelope="pluck",
|
||||
delay=0.5,
|
||||
delay_time=0.66,
|
||||
delay_feedback=0.55,
|
||||
)
|
||||
|
||||
Reverb
|
||||
------
|
||||
|
||||
Everyone knows what reverb sounds like, even if they don't know the
|
||||
word -- it's the sound of singing in the shower, or clapping in a
|
||||
cathedral. It's the natural echo of a space. Without reverb, sounds
|
||||
feel uncomfortably close and dry, like someone whispering directly into
|
||||
your ear. With it, sounds feel like they exist in a real place. Reverb
|
||||
is the most universally used effect in all of recorded music.
|
||||
|
||||
PyTheory offers two reverb engines: a fast **algorithmic** reverb for
|
||||
general use, and **convolution** reverb for photorealistic acoustic
|
||||
spaces.
|
||||
|
||||
Algorithmic Reverb
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A Schroeder reverb using 4 parallel comb filters and 2 series allpass
|
||||
filters. Fast, lightweight, and good for general-purpose room
|
||||
simulation.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``reverb``: Wet/dry mix, 0.0--1.0.
|
||||
|
||||
- 0.2--0.4 = subtle space
|
||||
- 0.5--0.8 = ambient / dub
|
||||
|
||||
- ``reverb_decay``: Tail length in seconds.
|
||||
|
||||
- 0.5 = small room
|
||||
- 1.5 = hall
|
||||
- 3.0+ = cathedral / dub
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Jazz club ambience
|
||||
rhodes = score.part(
|
||||
"rhodes",
|
||||
synth="fm",
|
||||
envelope="piano",
|
||||
reverb=0.4,
|
||||
reverb_decay=1.8,
|
||||
)
|
||||
|
||||
Convolution Reverb
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Convolution reverb works by convolving your audio with an *impulse
|
||||
response* -- a recording (or simulation) of a real acoustic space.
|
||||
Where algorithmic reverb approximates the math of reflections,
|
||||
convolution reverb *is* the space. You hear every surface, every
|
||||
angle, every material.
|
||||
|
||||
PyTheory generates synthetic impulse responses that model the acoustic
|
||||
properties of real spaces: early reflection patterns, exponential
|
||||
decay envelopes, frequency-dependent absorption (high frequencies die
|
||||
faster in stone), diffusion density, and subtle pitch modulation from
|
||||
irregular surfaces. The result is dramatically more realistic than
|
||||
algorithmic reverb, especially for long tails and large spaces.
|
||||
|
||||
Set ``reverb_type`` to any preset name instead of ``"algorithmic"``:
|
||||
|
||||
- ``"taj_mahal"`` -- Massive marble dome. 12-second tail, bright early
|
||||
reflections, enormously dense and diffuse. The most dramatic verb
|
||||
you've ever heard.
|
||||
- ``"cathedral"`` -- Gothic stone cathedral. 6 seconds, strong early
|
||||
reflections off parallel walls, dark reverberant tail.
|
||||
- ``"plate"`` -- EMT 140 plate reverb. 4 seconds, dense, bright, smooth.
|
||||
The studio classic that defined pop records from the 60s onward.
|
||||
- ``"spring"`` -- Spring reverb tank. 3 seconds, metallic, boingy, lo-fi.
|
||||
The sound of surf rock and guitar amps.
|
||||
- ``"cave"`` -- Natural cave. 8 seconds, very dark, irregular reflections.
|
||||
High frequencies are aggressively absorbed by rock.
|
||||
- ``"parking_garage"`` -- Concrete box. 3 seconds, bright, flutter echoes
|
||||
from parallel hard walls.
|
||||
- ``"canyon"`` -- Open canyon. 5 seconds, sparse discrete echoes (the
|
||||
walls are far apart) dissolving into a diffuse tail.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``reverb``: Wet/dry mix, 0.0--1.0.
|
||||
- ``reverb_type``: Preset name (default ``"algorithmic"``).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# FM flute through the Taj Mahal
|
||||
flute = score.part(
|
||||
"flute",
|
||||
synth="fm",
|
||||
envelope="bell",
|
||||
reverb=0.85,
|
||||
reverb_type="taj_mahal",
|
||||
delay=0.65,
|
||||
delay_time=0.375,
|
||||
delay_feedback=0.55,
|
||||
)
|
||||
|
||||
# Cathedral wash for ambient pads
|
||||
pad = score.part(
|
||||
"pad",
|
||||
synth="supersaw",
|
||||
envelope="pad",
|
||||
reverb=0.7,
|
||||
reverb_type="cathedral",
|
||||
)
|
||||
|
||||
# Classic plate on a vocal-style lead
|
||||
lead = score.part(
|
||||
"lead",
|
||||
synth="triangle",
|
||||
envelope="strings",
|
||||
reverb=0.5,
|
||||
reverb_type="plate",
|
||||
)
|
||||
|
||||
# Algorithmic reverb still works as before
|
||||
rhodes = score.part(
|
||||
"rhodes",
|
||||
synth="fm",
|
||||
envelope="piano",
|
||||
reverb=0.4,
|
||||
reverb_decay=1.8,
|
||||
)
|
||||
|
||||
You can switch reverb types mid-song with automation:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead = score.part("lead", synth="fm", envelope="bell",
|
||||
reverb=0.5, reverb_type="plate")
|
||||
lead.add("C5", Duration.WHOLE)
|
||||
|
||||
# Switch to cathedral for the big section
|
||||
lead.set(reverb_type="cathedral", reverb=0.8)
|
||||
lead.add("E5", Duration.WHOLE)
|
||||
|
||||
Combining Effects
|
||||
-----------------
|
||||
|
||||
Effects stack naturally. Here are some real-world combinations:
|
||||
|
||||
Dub
|
||||
~~~
|
||||
|
||||
Distortion warmth into filtered delay into deep reverb:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
melodica = score.part(
|
||||
"melodica",
|
||||
synth="triangle",
|
||||
envelope="pluck",
|
||||
distortion=0.2,
|
||||
distortion_drive=2.0,
|
||||
lowpass=2000,
|
||||
lowpass_q=1.2,
|
||||
delay=0.5,
|
||||
delay_time=0.66,
|
||||
delay_feedback=0.55,
|
||||
reverb=0.4,
|
||||
reverb_decay=2.5,
|
||||
)
|
||||
|
||||
Acid
|
||||
~~~~
|
||||
|
||||
Resonant lowpass with distortion and delay:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
acid = score.part(
|
||||
"acid",
|
||||
synth="saw",
|
||||
envelope="staccato",
|
||||
lowpass=1500,
|
||||
lowpass_q=3.0,
|
||||
distortion=0.4,
|
||||
distortion_drive=4.0,
|
||||
delay=0.3,
|
||||
delay_time=0.242,
|
||||
delay_feedback=0.4,
|
||||
)
|
||||
|
||||
Ambient
|
||||
~~~~~~~
|
||||
|
||||
Wide chorus, long reverb, gentle delay:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
ambient = score.part(
|
||||
"ambient",
|
||||
synth="supersaw",
|
||||
envelope="pad",
|
||||
chorus=0.4,
|
||||
chorus_rate=0.5,
|
||||
delay=0.3,
|
||||
delay_time=0.5,
|
||||
delay_feedback=0.5,
|
||||
reverb=0.7,
|
||||
reverb_decay=4.0,
|
||||
)
|
||||
|
||||
808 Bass
|
||||
~~~~~~~~
|
||||
|
||||
Subtle saturation and deep filtering for hip-hop sub bass:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
bass = score.part(
|
||||
"bass",
|
||||
synth="sine",
|
||||
envelope="pluck",
|
||||
lowpass=200,
|
||||
lowpass_q=1.8,
|
||||
distortion=0.4,
|
||||
distortion_drive=2.0,
|
||||
)
|
||||
|
||||
Sidechain Compression
|
||||
---------------------
|
||||
|
||||
If you've ever heard a house track where the pad *breathes* — gets
|
||||
quiet every time the kick hits and swells back up between beats —
|
||||
that's sidechain compression. It's the pumping effect that defines
|
||||
modern electronic music. The kick drum triggers a compressor on
|
||||
another part, ducking its volume in rhythm with the beat.
|
||||
|
||||
In PyTheory, the drum hits are the trigger. Any part with
|
||||
``sidechain > 0`` gets ducked whenever the kick (or any drum) hits:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Classic EDM pump — pad ducks hard on every kick
|
||||
pad = score.part(
|
||||
"pad",
|
||||
synth="supersaw",
|
||||
envelope="pad",
|
||||
sidechain=0.85,
|
||||
sidechain_release=0.15,
|
||||
)
|
||||
|
||||
# Bass breathes with the kick too, but less aggressively
|
||||
bass = score.part(
|
||||
"bass",
|
||||
synth="sine",
|
||||
lowpass=250,
|
||||
sidechain=0.7,
|
||||
sidechain_release=0.1,
|
||||
)
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``sidechain``: How much to duck, 0.0–1.0 (default 0, off).
|
||||
0.5 = subtle pump, 0.7 = noticeable, 0.85 = classic EDM, 1.0 = full silence on hits.
|
||||
- ``sidechain_release``: How fast the volume comes back, in seconds
|
||||
(default 0.1). Shorter = tighter, longer = more dramatic pump.
|
||||
|
||||
The lead stays above the pump — don't sidechain everything or the
|
||||
whole mix will gasp for air:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Lead cuts through — no sidechain
|
||||
lead = score.part(
|
||||
"lead",
|
||||
synth="saw",
|
||||
envelope="pluck",
|
||||
delay=0.2,
|
||||
)
|
||||
|
||||
Saturation
|
||||
----------
|
||||
|
||||
Saturation is the warm, subtle harmonic enhancement of analog tape
|
||||
machines and tube preamps. Unlike distortion (which uses ``tanh`` and
|
||||
adds harsh odd harmonics), saturation uses a polynomial waveshaper
|
||||
that adds even harmonics -- 2nd and 4th -- which the ear perceives as
|
||||
warmth and fullness. It's why records mixed through a Neve console
|
||||
sound "bigger" than the same mix done in the box.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``saturation``: Amount, 0.0--1.0 (default 0, off).
|
||||
|
||||
- 0.05--0.15 = subtle analog warmth (tape machine)
|
||||
- 0.2--0.4 = noticeable color (tube preamp)
|
||||
- 0.5+ = heavy coloring
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Warm up a bass
|
||||
bass = score.part("bass", synth="saw", saturation=0.2)
|
||||
|
||||
# Glue a string ensemble
|
||||
strings = score.part("strings", instrument="string_ensemble",
|
||||
saturation=0.1)
|
||||
|
||||
Tremolo
|
||||
-------
|
||||
|
||||
Amplitude modulation by a sine LFO. The classic vibrating-amp sound.
|
||||
Essential for vibraphone (the rotating discs in the resonator tubes),
|
||||
Rhodes electric piano, and surf guitar. Not to be confused with
|
||||
vibrato (pitch modulation).
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``tremolo_depth``: Modulation depth, 0.0--1.0 (default 0, off).
|
||||
- ``tremolo_rate``: LFO speed in Hz (default 5.0).
|
||||
|
||||
- 3--5 Hz = classic tremolo
|
||||
- 5--7 Hz = vibraphone motor speed
|
||||
- 8+ Hz = ring-mod territory
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Classic Fender amp tremolo
|
||||
guitar = score.part("guitar", synth="saw", envelope="pluck",
|
||||
tremolo_depth=0.3, tremolo_rate=4.0)
|
||||
|
||||
# Vibraphone with motor
|
||||
vib = score.part("vib", instrument="vibraphone") # built in
|
||||
|
||||
Phaser
|
||||
------
|
||||
|
||||
A chain of allpass filters whose center frequencies are swept by an
|
||||
LFO, creating moving notches in the spectrum. The classic "jet
|
||||
engine" or "underwater" effect. Think Small Stone, MXR Phase 90, or
|
||||
the intro to "Eruption." Different from chorus -- chorus adds a
|
||||
detuned copy, phaser cancels specific frequencies.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``phaser``: Wet/dry mix, 0.0--1.0 (default 0, off).
|
||||
- ``phaser_rate``: LFO sweep speed in Hz (default 0.5).
|
||||
|
||||
- 0.1--0.3 = slow, lush sweep
|
||||
- 0.5--1.0 = classic phaser
|
||||
- 2.0+ = fast, Leslie-like
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Slow sweep on a pad
|
||||
pad = score.part("pad", synth="supersaw", envelope="pad",
|
||||
phaser=0.4, phaser_rate=0.2)
|
||||
|
||||
# Leslie sim on organ (built in)
|
||||
organ = score.part("organ", instrument="organ")
|
||||
|
||||
Highpass Filter
|
||||
---------------
|
||||
|
||||
The opposite of lowpass -- removes low-frequency content below the
|
||||
cutoff. Useful for cleaning up mud from pads, keeping multiple bass
|
||||
parts from masking each other, or thinning out a sound to sit better
|
||||
in a mix.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``highpass``: Cutoff frequency in Hz (0 = off).
|
||||
|
||||
- 80--150 Hz = clean up sub rumble
|
||||
- 200--400 Hz = thin out a pad
|
||||
- 500+ Hz = telephone / radio effect
|
||||
|
||||
- ``highpass_q``: Resonance / Q factor (default 0.707).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Clean up sub rumble from a pad
|
||||
pad = score.part("pad", synth="supersaw", highpass=120)
|
||||
|
||||
# Thin out rhythm guitar to leave room for bass
|
||||
rhythm = score.part("rhythm", synth="saw", highpass=250)
|
||||
|
||||
Filter Envelope
|
||||
---------------
|
||||
|
||||
A per-note lowpass filter whose cutoff sweeps over time. This is the
|
||||
core of subtractive synthesis -- the reason a Moog bass goes "bwow"
|
||||
instead of "boop." The filter opens on the attack and closes during
|
||||
decay, giving each note a distinctive timbral shape.
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``filter_amount``: Sweep range in Hz (0 = off). How far the filter
|
||||
opens above the base cutoff.
|
||||
- ``filter_attack``: Time to reach peak cutoff, in seconds (default 0.01).
|
||||
- ``filter_decay``: Time to fall to sustain level (default 0.3).
|
||||
- ``filter_sustain``: Sustain level as fraction of amount, 0.0--1.0
|
||||
(default 0.0 = filter closes completely after decay).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Classic synth bass "bwow"
|
||||
bass = score.part("bass", instrument="synth_bass") # built in
|
||||
|
||||
# Acid squelch
|
||||
acid = score.part("acid", instrument="acid_bass") # built in
|
||||
|
||||
# Custom filter sweep on a lead
|
||||
lead = score.part("lead", synth="saw",
|
||||
filter_amount=4000, filter_attack=0.01,
|
||||
filter_decay=0.4, filter_sustain=0.1)
|
||||
|
||||
Velocity to Brightness
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Real instruments get brighter when played harder. ``vel_to_filter``
|
||||
maps note velocity to filter cutoff boost, so louder notes have more
|
||||
high-frequency content.
|
||||
|
||||
- ``vel_to_filter``: Cutoff boost in Hz at max velocity (default 0, off).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Piano: soft = mellow, loud = bright
|
||||
piano = score.part("piano", instrument="piano") # built in
|
||||
|
||||
# Manual: custom velocity mapping on a lead
|
||||
lead = score.part("lead", synth="saw", vel_to_filter=3000)
|
||||
|
||||
Sub-Oscillator
|
||||
--------------
|
||||
|
||||
An octave-below sine wave mixed in with the main oscillator. Adds
|
||||
low-end weight without muddiness -- the sub fills in the fundamental
|
||||
while the main oscillator provides harmonic character above.
|
||||
|
||||
- ``sub_osc``: Mix level, 0.0--1.0 (default 0, off).
|
||||
|
||||
- 0.1--0.2 = subtle weight (tuba, bass guitar)
|
||||
- 0.3--0.5 = heavy sub (808, synth bass)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Fat 808 kick-bass
|
||||
bass = score.part("bass", instrument="808_bass") # built in
|
||||
|
||||
# Add weight to any part
|
||||
lead = score.part("lead", synth="saw", sub_osc=0.3)
|
||||
|
||||
Noise Layer
|
||||
-----------
|
||||
|
||||
White noise mixed into each note, following the same amplitude
|
||||
envelope. Adds breath for woodwinds, hammer/felt noise for piano,
|
||||
bow rosin for strings, and attack transients for percussion.
|
||||
|
||||
- ``noise_mix``: Mix level, 0.0--1.0 (default 0, off).
|
||||
|
||||
- 0.02--0.04 = subtle texture (strings, piano)
|
||||
- 0.05--0.08 = noticeable breath (woodwinds)
|
||||
- 0.1+ = heavy air/texture
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Breathy flute
|
||||
flute = score.part("flute", instrument="flute") # noise_mix=0.08
|
||||
|
||||
# Add air to any synth
|
||||
pad = score.part("pad", synth="supersaw", noise_mix=0.05)
|
||||
|
||||
Configurable FM
|
||||
---------------
|
||||
|
||||
The FM synth now accepts ``fm_ratio`` and ``fm_index`` parameters,
|
||||
letting you dial in specific FM timbres instead of using the defaults.
|
||||
|
||||
- ``fm_ratio``: Modulator frequency as multiple of carrier (default 2.0).
|
||||
Integer ratios = harmonic timbres; non-integer = metallic/inharmonic.
|
||||
- ``fm_index``: Modulation depth (default 3.0). Higher = more harmonics.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Warm electric piano (low ratio, low index)
|
||||
ep = score.part("ep", synth="fm", fm_ratio=1.0, fm_index=1.5)
|
||||
|
||||
# Bright metallic bell (high ratio, high index)
|
||||
bell = score.part("bell", synth="fm", fm_ratio=3.5, fm_index=5.0)
|
||||
|
||||
# Glockenspiel
|
||||
glock = score.part("glock", instrument="glockenspiel") # built in
|
||||
|
||||
Automation
|
||||
----------
|
||||
|
||||
Static effects are fine for a loop, but music breathes. The filter
|
||||
*opens* during the chorus. The reverb *swells* before the drop. The
|
||||
distortion *kicks in* when the guitar solo starts. Automation is what
|
||||
makes a track feel alive instead of robotic -- it's the difference
|
||||
between a static loop and a piece of music that has dynamics, tension,
|
||||
and release. If you've ever felt a song "build" toward something,
|
||||
you're hearing automation at work.
|
||||
|
||||
``Part.set()`` changes effect parameters mid-song at the current beat
|
||||
position. The renderer splits the audio at automation points and
|
||||
processes each section independently:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead = score.part("lead", synth="saw", lowpass=400, lowpass_q=3.0)
|
||||
|
||||
# Verse: filtered and clean
|
||||
lead.arpeggio("Cm", bars=4, pattern="up", octaves=2)
|
||||
|
||||
# Chorus: filter opens, chorus kicks in
|
||||
lead.set(lowpass=2000, chorus=0.3)
|
||||
lead.arpeggio("Fm", bars=4, pattern="updown", octaves=2)
|
||||
|
||||
# Drop: full send
|
||||
lead.set(lowpass=4000, distortion=0.7, reverb=0.3)
|
||||
lead.arpeggio("Gm", bars=4, pattern="updown", octaves=2)
|
||||
|
||||
Any parameter can be automated: ``lowpass``, ``lowpass_q``, ``highpass``,
|
||||
``reverb``, ``reverb_decay``, ``reverb_type``, ``delay``, ``delay_time``,
|
||||
``delay_feedback``, ``distortion``, ``distortion_drive``, ``chorus``,
|
||||
``phaser``, ``phaser_rate``, ``saturation``, ``tremolo_depth``,
|
||||
``tremolo_rate``, ``cabinet``, ``cabinet_brightness``, ``analog_drift``,
|
||||
``volume``.
|
||||
|
||||
LFO Automation
|
||||
--------------
|
||||
|
||||
An LFO -- Low Frequency Oscillator -- is just automation that repeats.
|
||||
Instead of manually setting parameter changes, you let a wave shape do
|
||||
it for you, cycling back and forth continuously. You already know what
|
||||
LFOs sound like, even if you don't know the term. The wobble bass in
|
||||
dubstep? That's an LFO on the filter cutoff. Tremolo on a guitar amp?
|
||||
LFO on volume. Auto-wah? LFO on filter cutoff with resonance cranked
|
||||
up. Vibrato? LFO on pitch. It's one simple concept that produces a
|
||||
huge range of effects.
|
||||
|
||||
``Part.lfo()`` automates a parameter with a low-frequency oscillator,
|
||||
generating smooth sweeps over time. This is how filter sweeps, tremolo,
|
||||
and auto-wah effects work.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead = score.part("lead", synth="saw", lowpass=400)
|
||||
|
||||
# Slow filter sweep: 400 -> 3000 Hz over 8 bars
|
||||
lead.lfo("lowpass", rate=0.125, min=400, max=3000, bars=8)
|
||||
lead.arpeggio("Cm", bars=8, pattern="up", octaves=2)
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``param``: Parameter name to modulate (``"lowpass"``, ``"reverb"``,
|
||||
``"distortion"``, ``"volume"``, ``"chorus"``, ``"delay"``).
|
||||
- ``rate``: LFO speed in cycles per bar (default 0.5 = one sweep
|
||||
every 2 bars). 0.25 = very slow, 1 = once per bar, 4 = four times
|
||||
per bar.
|
||||
- ``min`` / ``max``: Parameter value range.
|
||||
- ``bars``: Number of bars to run the LFO over (default 4).
|
||||
- ``shape``: Waveform shape.
|
||||
|
||||
- ``"sine"`` -- smooth, natural sweep
|
||||
- ``"triangle"`` -- linear up/down
|
||||
- ``"saw"`` -- ramp up, snap back
|
||||
- ``"square"`` -- abrupt on/off
|
||||
|
||||
- ``resolution``: How often to insert automation points, in beats
|
||||
(default 0.25 = every 16th note). Lower values = smoother curves.
|
||||
|
||||
Stacking Multiple LFOs
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Call ``.lfo()`` multiple times to modulate different parameters
|
||||
simultaneously:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead = score.part("lead", synth="saw", lowpass=800, reverb=0.1)
|
||||
|
||||
# Filter opens over 8 bars
|
||||
lead.lfo("lowpass", rate=0.125, min=400, max=4000, bars=8)
|
||||
# Reverb swells in and out every 2 bars
|
||||
lead.lfo("reverb", rate=0.5, min=0.1, max=0.6, bars=8, shape="triangle")
|
||||
# Volume tremolo
|
||||
lead.lfo("volume", rate=2, min=0.3, max=0.6, bars=8, shape="sine")
|
||||
|
||||
lead.arpeggio("Cm", bars=8, pattern="updown", octaves=2)
|
||||
|
||||
Effects are what turn notes into music -- the space, the movement, the character. A dry signal is just information; reverb, delay, and filtering are what make it feel like something. Experiment freely, trust your ears.
|
||||
+149
-117
@@ -31,29 +31,42 @@ Guitars
|
||||
This tuning uses intervals of a perfect 4th (5 semitones) between most
|
||||
strings, except between G and B which is a major 3rd (4 semitones).
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Fretboard
|
||||
>>> from pytheory import Fretboard
|
||||
|
||||
guitar = Fretboard.guitar() # Standard EADGBE
|
||||
twelve = Fretboard.twelve_string() # 12-string (6 doubled courses)
|
||||
bass = Fretboard.bass() # Standard 4-string EADG
|
||||
bass5 = Fretboard.bass(five_string=True) # 5-string with low B
|
||||
>>> guitar = Fretboard.guitar() # Standard EADGBE
|
||||
>>> twelve = Fretboard.twelve_string() # 12-string (6 doubled courses)
|
||||
>>> bass = Fretboard.bass() # Standard 4-string EADG
|
||||
>>> bass5 = Fretboard.bass(five_string=True) # 5-string with low B
|
||||
|
||||
**Alternate tunings** — 8 built-in presets:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
Fretboard.guitar("drop d") # DADGBE — heavy riffs, metal
|
||||
Fretboard.guitar("open g") # DGDGBD — slide guitar, Keith Richards
|
||||
Fretboard.guitar("open d") # DADF#AD — slide, folk
|
||||
Fretboard.guitar("open e") # EBEG#BE — slide blues
|
||||
Fretboard.guitar("open a") # EAC#EAE
|
||||
Fretboard.guitar("dadgad") # DADGAD — Celtic, fingerstyle
|
||||
Fretboard.guitar("half step down") # Eb standard — Hendrix, SRV
|
||||
>>> Fretboard.guitar("drop d") # DADGBE — heavy riffs, metal
|
||||
>>> Fretboard.guitar("open g") # DGDGBD — slide guitar, Keith Richards
|
||||
>>> Fretboard.guitar("open d") # DADF#AD — slide, folk
|
||||
>>> Fretboard.guitar("open e") # EBEG#BE — slide blues
|
||||
>>> Fretboard.guitar("open a") # EAC#EAE
|
||||
>>> Fretboard.guitar("dadgad") # DADGAD — Celtic, fingerstyle
|
||||
>>> Fretboard.guitar("half step down") # Eb standard — Hendrix, SRV
|
||||
|
||||
# Custom tuning with any notes
|
||||
Fretboard.guitar(("C4", "G3", "C3", "G2", "C2", "G1"))
|
||||
>>> # Custom tuning with any notes
|
||||
>>> Fretboard.guitar(("C4", "G3", "C3", "G2", "C2", "G1"))
|
||||
|
||||
**Capo** — a `capo <https://en.wikipedia.org/wiki/Capo>`_ raises all
|
||||
strings by a number of frets, letting you play open chord shapes in
|
||||
higher keys:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> # Capo on fret 2 — open G shape now sounds as A major
|
||||
>>> fb = Fretboard.guitar(capo=2)
|
||||
|
||||
>>> # Or apply a capo to an existing fretboard
|
||||
>>> fb = Fretboard.guitar()
|
||||
>>> fb_capo3 = fb.capo(3)
|
||||
|
||||
The Mandolin Family
|
||||
-------------------
|
||||
@@ -63,12 +76,12 @@ mirrors the `violin family <https://en.wikipedia.org/wiki/Violin_family>`_
|
||||
— all tuned in perfect fifths, with each member a fifth or octave
|
||||
lower than the last:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
Fretboard.mandolin() # E5 A4 D4 G3 — soprano (= violin)
|
||||
Fretboard.mandola() # A4 D4 G3 C3 — alto (= viola)
|
||||
Fretboard.octave_mandolin() # E4 A3 D3 G2 — tenor (octave below mandolin)
|
||||
Fretboard.mandocello() # A3 D3 G2 C2 — bass (= cello)
|
||||
>>> Fretboard.mandolin() # E5 A4 D4 G3 — soprano (= violin)
|
||||
>>> Fretboard.mandola() # A4 D4 G3 C3 — alto (= viola)
|
||||
>>> Fretboard.octave_mandolin() # E4 A3 D3 G2 — tenor (octave below mandolin)
|
||||
>>> Fretboard.mandocello() # A3 D3 G2 C2 — bass (= cello)
|
||||
|
||||
The mandolin's doubled courses (pairs of strings) create a natural
|
||||
chorus effect. The `octave mandolin <https://en.wikipedia.org/wiki/Octave_mandolin>`_
|
||||
@@ -80,12 +93,12 @@ The Bowed String Family
|
||||
The orchestral `string family <https://en.wikipedia.org/wiki/String_section>`_
|
||||
is tuned in perfect fifths (except the double bass, which uses fourths):
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
Fretboard.violin() # E5 A4 D4 G3 — soprano
|
||||
Fretboard.viola() # A4 D4 G3 C3 — alto (5th below violin)
|
||||
Fretboard.cello() # A3 D3 G2 C2 — tenor/bass (octave below viola)
|
||||
Fretboard.double_bass() # G2 D2 A1 E1 — bass (tuned in 4ths!)
|
||||
>>> Fretboard.violin() # E5 A4 D4 G3 — soprano
|
||||
>>> Fretboard.viola() # A4 D4 G3 C3 — alto (5th below violin)
|
||||
>>> Fretboard.cello() # A3 D3 G2 C2 — tenor/bass (octave below viola)
|
||||
>>> Fretboard.double_bass() # G2 D2 A1 E1 — bass (tuned in 4ths!)
|
||||
|
||||
Bowed strings have no frets — the player can produce any pitch along
|
||||
the fingerboard, enabling continuous
|
||||
@@ -95,19 +108,19 @@ inflections not possible on fretted instruments.
|
||||
The `erhu <https://en.wikipedia.org/wiki/Erhu>`_ — a 2-stringed Chinese
|
||||
bowed instrument with a hauntingly vocal quality:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
Fretboard.erhu() # A4 D4 — tuned a 5th apart, no fingerboard
|
||||
>>> Fretboard.erhu() # A4 D4 — tuned a 5th apart, no fingerboard
|
||||
|
||||
Plucked Strings
|
||||
---------------
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
Fretboard.ukulele() # A4 E4 C4 G4 — re-entrant tuning
|
||||
Fretboard.banjo() # Open G (bluegrass, 5th string is high drone)
|
||||
Fretboard.banjo("open d") # Open D (clawhammer, old-time)
|
||||
Fretboard.harp() # 47 strings, C1 to G7 (concert pedal harp)
|
||||
>>> Fretboard.ukulele() # A4 E4 C4 G4 — re-entrant tuning
|
||||
>>> Fretboard.banjo() # Open G (bluegrass, 5th string is high drone)
|
||||
>>> Fretboard.banjo("open d") # Open D (clawhammer, old-time)
|
||||
>>> Fretboard.harp() # 47 strings, C1 to G7 (concert pedal harp)
|
||||
|
||||
The `banjo <https://en.wikipedia.org/wiki/Banjo>`_'s short 5th string
|
||||
is a high drone — a defining feature of the instrument's sound.
|
||||
@@ -119,28 +132,28 @@ by up to two semitones across all octaves simultaneously.
|
||||
World Instruments
|
||||
-----------------
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
# Middle Eastern
|
||||
Fretboard.oud() # C4 G3 D3 A2 G2 C2 — fretless, ancestor of the lute
|
||||
Fretboard.sitar() # 7 main strings — Indian classical
|
||||
>>> # Middle Eastern
|
||||
>>> Fretboard.oud() # C4 G3 D3 A2 G2 C2 — fretless, ancestor of the lute
|
||||
>>> Fretboard.sitar() # 7 main strings — Indian classical
|
||||
|
||||
# East Asian
|
||||
Fretboard.shamisen() # C4 G3 C3 — 3-string Japanese, honchoshi tuning
|
||||
Fretboard.pipa() # D4 A3 E3 A2 — 4-string Chinese lute
|
||||
Fretboard.erhu() # A4 D4 — 2-string Chinese bowed
|
||||
>>> # East Asian
|
||||
>>> Fretboard.shamisen() # C4 G3 C3 — 3-string Japanese, honchoshi tuning
|
||||
>>> Fretboard.pipa() # D4 A3 E3 A2 — 4-string Chinese lute
|
||||
>>> Fretboard.erhu() # A4 D4 — 2-string Chinese bowed
|
||||
|
||||
# European
|
||||
Fretboard.bouzouki() # D4 A3 D3 G2 — Irish (Celtic music)
|
||||
Fretboard.bouzouki("greek") # D4 A3 F3 C3 — Greek
|
||||
Fretboard.lute() # G4 D4 A3 F3 C3 G2 — Renaissance (6 courses)
|
||||
Fretboard.balalaika() # A4 E4 E4 — Russian (2 unison strings)
|
||||
>>> # European
|
||||
>>> Fretboard.bouzouki() # D4 A3 D3 G2 — Irish (Celtic music)
|
||||
>>> Fretboard.bouzouki("greek") # D4 A3 F3 C3 — Greek
|
||||
>>> Fretboard.lute() # G4 D4 A3 F3 C3 G2 — Renaissance (6 courses)
|
||||
>>> Fretboard.balalaika() # A4 E4 E4 — Russian (2 unison strings)
|
||||
|
||||
# Latin American
|
||||
Fretboard.charango() # E5 A4 E5 C5 G4 — Andean (re-entrant tuning)
|
||||
>>> # Latin American
|
||||
>>> Fretboard.charango() # E5 A4 E5 C5 G4 — Andean (re-entrant tuning)
|
||||
|
||||
# Steel guitar
|
||||
Fretboard.pedal_steel() # 10 strings, E9 Nashville — country music
|
||||
>>> # Steel guitar
|
||||
>>> Fretboard.pedal_steel() # 10 strings, E9 Nashville — country music
|
||||
|
||||
The `oud <https://en.wikipedia.org/wiki/Oud>`_ is fretless, allowing
|
||||
the quarter-tone inflections essential to
|
||||
@@ -151,12 +164,12 @@ sympathetic strings that resonate in harmony with the played notes.
|
||||
Keyboards
|
||||
---------
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
Fretboard.keyboard() # 88-key piano (A0 to C8)
|
||||
Fretboard.keyboard(61, "C2") # 61-key synth controller
|
||||
Fretboard.keyboard(49, "C2") # 49-key controller
|
||||
Fretboard.keyboard(25, "C3") # 25-key mini MIDI controller
|
||||
>>> Fretboard.keyboard() # 88-key piano (A0 to C8)
|
||||
>>> Fretboard.keyboard(61, "C2") # 61-key synth controller
|
||||
>>> Fretboard.keyboard(49, "C2") # 49-key controller
|
||||
>>> Fretboard.keyboard(25, "C3") # 25-key mini MIDI controller
|
||||
|
||||
While keyboards don't have strings or frets, they map naturally to a
|
||||
sequence of tones. A full 88-key piano spans over 7 octaves — the
|
||||
@@ -172,46 +185,38 @@ on any instrument. It scores each possibility by:
|
||||
2. Preferring **ascending** fret patterns — easier hand position
|
||||
3. Minimizing the number of **fingers needed**
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Fretboard, CHARTS
|
||||
>>> from pytheory import Fretboard
|
||||
|
||||
fb = Fretboard.guitar()
|
||||
c = CHARTS["western"]["C"]
|
||||
>>> fb = Fretboard.guitar()
|
||||
>>> f = fb.chord("C")
|
||||
>>> f
|
||||
Fingering(e=0, B=1, G=0, D=2, A=3, E=x)
|
||||
|
||||
# Fingerings return a Fingering object with labeled strings
|
||||
f = c.fingering(fretboard=fb)
|
||||
print(f)
|
||||
# Fingering(e=0, B=1, G=0, D=2, A=3, E=0)
|
||||
>>> f['A']
|
||||
3
|
||||
>>> f[1]
|
||||
1
|
||||
|
||||
# Access by string name or index
|
||||
f['A'] # 3
|
||||
f[1] # 1 (B string)
|
||||
>>> f.identify()
|
||||
'C major'
|
||||
|
||||
# Identify the chord directly from a fingering
|
||||
f.identify() # 'C major'
|
||||
|
||||
# Convert to a Chord for further analysis
|
||||
chord = f.to_chord()
|
||||
chord.harmony # consonance score
|
||||
chord.intervals # [4, 3] — major triad
|
||||
|
||||
# All equally-scored fingerings
|
||||
all_c = c.fingering(fretboard=fb, multiple=True)
|
||||
|
||||
# Muted strings appear as None
|
||||
f = CHARTS["western"]["F"]
|
||||
print(f.fingering(fretboard=fb))
|
||||
>>> chord = f.to_chord()
|
||||
>>> chord.identify()
|
||||
'C major'
|
||||
|
||||
You can also go from fret positions to chord identification:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
# "What chord am I playing?"
|
||||
fb = Fretboard.guitar()
|
||||
f = fb.fingering(0, 0, 0, 2, 2, 0)
|
||||
print(f) # Fingering(e=0, B=0, G=0, D=2, A=2, E=0)
|
||||
print(f.identify()) # E minor
|
||||
>>> # "What chord am I playing?"
|
||||
>>> fb = Fretboard.guitar()
|
||||
>>> f = fb.fingering(0, 0, 0, 2, 2, 0)
|
||||
>>> f
|
||||
Fingering(e=0, B=0, G=0, D=2, A=2, E=0)
|
||||
>>> f.identify()
|
||||
'E minor'
|
||||
|
||||
Reading Fingerings
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
@@ -225,65 +230,92 @@ low E as ``E``::
|
||||
G|--0-- (open — G)
|
||||
D|--2-- (fret 2 — E)
|
||||
A|--3-- (fret 3 — C)
|
||||
E|--0-- (open — E)
|
||||
E|--x-- (muted)
|
||||
|
||||
A value of ``None`` means the string is muted (not played).
|
||||
A value of ``x`` (``None``) means the string is muted (not played).
|
||||
|
||||
ASCII Tablature
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
For a more visual representation, use ``tab()``:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> print(CHARTS["western"]["C"].tab(fretboard=fb))
|
||||
C
|
||||
E|--0--
|
||||
>>> print(fb.tab("C"))
|
||||
C major
|
||||
e|--0--
|
||||
B|--1--
|
||||
G|--0--
|
||||
D|--2--
|
||||
A|--3--
|
||||
E|--0--
|
||||
E|--x--
|
||||
|
||||
Generating Full Charts
|
||||
----------------------
|
||||
|
||||
Generate fingerings for every chord at once:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Fretboard, charts_for_fretboard
|
||||
>>> fb = Fretboard.guitar()
|
||||
>>> chart = fb.chart()
|
||||
|
||||
fb = Fretboard.guitar()
|
||||
chart = charts_for_fretboard(fretboard=fb)
|
||||
>>> chart["C"]
|
||||
Fingering(e=0, B=1, G=0, D=2, A=3, E=x)
|
||||
|
||||
for name, fingering in chart.items():
|
||||
print(f"{name:6s} {fingering}")
|
||||
>>> # Works with any instrument
|
||||
>>> uke_chart = Fretboard.ukulele().chart()
|
||||
>>> mando_chart = Fretboard.mandolin().chart()
|
||||
|
||||
# Works with any instrument
|
||||
uke_chart = charts_for_fretboard(fretboard=Fretboard.ukulele())
|
||||
mando_chart = charts_for_fretboard(fretboard=Fretboard.mandolin())
|
||||
Scale Diagrams with Chord Highlighting
|
||||
---------------------------------------
|
||||
|
||||
The ``scale_diagram()`` method renders an ASCII fretboard showing where
|
||||
scale notes fall on each string. Pass an optional ``chord`` argument to
|
||||
highlight chord tones in UPPERCASE while scale-only tones appear in
|
||||
lowercase — a quick way to visualize target notes for soloing:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Fretboard, TonedScale, Chord
|
||||
|
||||
>>> fb = Fretboard.guitar()
|
||||
>>> pentatonic = TonedScale(tonic="A4")["minor pentatonic"]
|
||||
>>> print(fb.scale_diagram(pentatonic, frets=5))
|
||||
|
||||
>>> # Highlight Am chord tones within the scale:
|
||||
>>> am = Chord.from_symbol("Am")
|
||||
>>> print(fb.scale_diagram(pentatonic, frets=5, chord=am))
|
||||
|
||||
Non-String Instruments
|
||||
----------------------
|
||||
|
||||
Looking for drums and percussion? PyTheory also supports drum pattern
|
||||
programming through the sequencing engine. See the :doc:`drums` guide
|
||||
for drum kits, patterns, and fills.
|
||||
|
||||
Custom Instruments
|
||||
------------------
|
||||
|
||||
Any instrument can be modeled with custom string tunings:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Tone, Fretboard
|
||||
>>> from pytheory import Tone, Fretboard
|
||||
|
||||
# Baritone ukulele (DGBE — top 4 guitar strings)
|
||||
bari_uke = Fretboard(tones=[
|
||||
Tone.from_string("E4"),
|
||||
Tone.from_string("B3"),
|
||||
Tone.from_string("G3"),
|
||||
Tone.from_string("D3"),
|
||||
])
|
||||
>>> # Baritone ukulele (DGBE — top 4 guitar strings)
|
||||
>>> bari_uke = Fretboard(tones=[
|
||||
... Tone.from_string("E4"),
|
||||
... Tone.from_string("B3"),
|
||||
... Tone.from_string("G3"),
|
||||
... Tone.from_string("D3"),
|
||||
... ])
|
||||
|
||||
# Tres cubano (Cuban guitar, 3 doubled courses)
|
||||
tres = Fretboard(tones=[
|
||||
Tone.from_string("E4"),
|
||||
Tone.from_string("B3"),
|
||||
Tone.from_string("G3"),
|
||||
])
|
||||
>>> # Tres cubano (Cuban guitar, 3 doubled courses)
|
||||
>>> tres = Fretboard(tones=[
|
||||
... Tone.from_string("E4"),
|
||||
... Tone.from_string("B3"),
|
||||
... Tone.from_string("G3"),
|
||||
... ])
|
||||
|
||||
If it has strings, you can model it. Define the tuning, and PyTheory handles the rest -- fingerings, charts, scale diagrams, all of it. Got a weird instrument or a custom tuning? That's what the ``Fretboard`` constructor is for.
|
||||
|
||||
+194
-49
@@ -1,8 +1,21 @@
|
||||
Audio Playback
|
||||
==============
|
||||
Playback and Export
|
||||
===================
|
||||
|
||||
PyTheory can synthesize and play tones and chords through your speakers
|
||||
using basic `waveform <https://en.wikipedia.org/wiki/Waveform>`_ synthesis.
|
||||
This is the output layer. You've built your theory, composed your
|
||||
arrangement, shaped your sounds -- now you need to hear it. PyTheory
|
||||
gives you three ways to get your music out: speakers, WAV files, and
|
||||
MIDI files.
|
||||
|
||||
Use **speakers** for immediate feedback while you're sketching and
|
||||
experimenting. Use **WAV export** when you want to share actual audio
|
||||
-- post it, send it, drop it into a video. Use **MIDI export** when you
|
||||
want to bring your sketch into a real DAW and finish it with
|
||||
professional instruments, mixing, and mastering. Each output serves a
|
||||
different stage of the creative process.
|
||||
|
||||
PyTheory can play audio through your speakers, save to WAV, or export
|
||||
to MIDI. Everything is synthesized from waveforms -- no samples or
|
||||
external audio files needed.
|
||||
|
||||
.. note::
|
||||
|
||||
@@ -10,70 +23,202 @@ using basic `waveform <https://en.wikipedia.org/wiki/Waveform>`_ synthesis.
|
||||
installed on your system. On macOS: ``brew install portaudio``.
|
||||
On Ubuntu: ``apt install libportaudio2``.
|
||||
|
||||
Playing a Tone
|
||||
--------------
|
||||
play() -- Single Tones and Chords
|
||||
---------------------------------
|
||||
|
||||
The simplest way to hear something:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Tone, play
|
||||
from pytheory import Tone, Chord, play
|
||||
|
||||
a4 = Tone.from_string("A4", system="western")
|
||||
play(a4, t=1_000) # Play A440 for 1 second
|
||||
play(Tone.from_string("A4"), t=1_000) # A440 for 1 second
|
||||
play(Chord.from_symbol("Am7"), t=2_000) # chord for 2 seconds
|
||||
|
||||
Playing a Chord
|
||||
---------------
|
||||
Optional parameters for synth, envelope, and temperament:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Chord, play
|
||||
from pytheory import Synth, Envelope
|
||||
|
||||
# From a chord name
|
||||
play(Chord.from_name("Am7"), t=2_000)
|
||||
play(Tone.from_string("C4"), synth=Synth.SAW, envelope=Envelope.PLUCK, t=1_000)
|
||||
play(Tone.from_string("C4"), temperament="pythagorean", t=1_000)
|
||||
|
||||
# From note names
|
||||
play(Chord.from_tones("C", "E", "G"), t=2_000)
|
||||
play_score() -- Full Arrangements
|
||||
---------------------------------
|
||||
|
||||
Waveform Types
|
||||
--------------
|
||||
|
||||
The waveform shape determines the `timbre <https://en.wikipedia.org/wiki/Timbre>`_ (tonal color) of the sound.
|
||||
Different waveforms contain different combinations of **harmonics** —
|
||||
integer multiples of the fundamental frequency.
|
||||
|
||||
- `Sine wave <https://en.wikipedia.org/wiki/Sine_wave>`_ — the purest tone. Contains only the fundamental
|
||||
frequency with no harmonics. Sounds smooth, clear, and "electronic."
|
||||
This is the building block of all other waveforms (`Fourier's theorem <https://en.wikipedia.org/wiki/Fourier_series>`_).
|
||||
|
||||
- `Sawtooth wave <https://en.wikipedia.org/wiki/Sawtooth_wave>`_ — contains all harmonics (both odd and even),
|
||||
each at amplitude 1/n. Sounds bright, buzzy, and aggressive.
|
||||
Named for its shape. Used extensively in `additive synthesis <https://en.wikipedia.org/wiki/Additive_synthesis>`_ and analog synthesizers.
|
||||
|
||||
- `Triangle wave <https://en.wikipedia.org/wiki/Triangle_wave>`_ — contains only odd harmonics, each at amplitude
|
||||
1/n². Sounds softer and more mellow than sawtooth — somewhere between
|
||||
sine and sawtooth. Often described as "woody" or "hollow."
|
||||
Plays a ``Score`` with all its parts and drums mixed together.
|
||||
Output is **stereo** — each part is panned according to its ``pan``
|
||||
setting, drums are stereo-panned like a real kit, and reverb tails
|
||||
have natural stereo width. A **master bus compressor/limiter** (4:1
|
||||
ratio, brick-wall at 0.95) is applied to prevent clipping and make
|
||||
the mix louder and punchier:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import play, Synth, Tone
|
||||
from pytheory import Score, Duration, Chord
|
||||
from pytheory.play import play_score
|
||||
|
||||
tone = Tone.from_string("C4", system="western")
|
||||
score = Score("4/4", bpm=140)
|
||||
score.drums("bossa nova", repeats=4)
|
||||
chords = score.part("chords", synth="sine", envelope="pad")
|
||||
for sym in ["Am", "Dm", "E7", "Am"]:
|
||||
chords.add(Chord.from_symbol(sym), Duration.WHOLE)
|
||||
play_score(score)
|
||||
|
||||
play(tone, synth=Synth.SINE) # Pure, clean
|
||||
play(tone, synth=Synth.SAW) # Bright, buzzy
|
||||
play(tone, synth=Synth.TRIANGLE) # Mellow, hollow
|
||||
.. raw:: html
|
||||
|
||||
Temperaments
|
||||
------------
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/playback_basic.wav" type="audio/wav"></audio>
|
||||
|
||||
Hear the difference between tuning systems:
|
||||
The render pipeline respects the Score's ``temperament`` and
|
||||
``reference_pitch`` settings, so Baroque or microtonal scores play back
|
||||
at the correct tuning:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
play(tone, temperament="equal") # Modern standard (since ~1917)
|
||||
play(tone, temperament="pythagorean") # Pure fifths, wolf intervals
|
||||
play(tone, temperament="meantone") # Pure thirds, Renaissance sound
|
||||
score = Score("4/4", bpm=80, temperament="meantone", reference_pitch=415.0)
|
||||
|
||||
Try playing a C major chord in each temperament — you'll hear subtle
|
||||
differences in the "color" of the major third. Equal temperament is
|
||||
a compromise; the other systems sacrifice some keys to make the good
|
||||
keys sound better.
|
||||
Press **Ctrl+C** at any time during playback to stop — PyTheory catches
|
||||
``KeyboardInterrupt`` and stops audio cleanly.
|
||||
|
||||
See :doc:`sequencing` for how to build scores and parts.
|
||||
|
||||
render_score() -- Headless Rendering
|
||||
------------------------------------
|
||||
|
||||
Returns a raw audio buffer (numpy float32 array) without playing it.
|
||||
Useful for saving to WAV or further processing:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory.play import render_score
|
||||
>>> buf = render_score(score) # numpy float32 array
|
||||
>>> len(buf)
|
||||
604800
|
||||
|
||||
save() -- WAV Export
|
||||
--------------------
|
||||
|
||||
Render tones or chords to a WAV file. Works without speakers or
|
||||
PortAudio:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import save, Chord, Tone, Synth
|
||||
|
||||
save(Tone.from_string("A4"), "a440.wav", t=1_000)
|
||||
save(Chord.from_name("Am7"), "am7.wav", t=2_000)
|
||||
save(
|
||||
Chord.from_name("C"),
|
||||
"c_triangle.wav",
|
||||
synth=Synth.TRIANGLE,
|
||||
temperament="meantone",
|
||||
t=3_000,
|
||||
)
|
||||
|
||||
save_midi() -- MIDI Export
|
||||
--------------------------
|
||||
|
||||
MIDI export is probably the most useful feature here for working
|
||||
musicians. The idea is simple: sketch your ideas in Python -- where
|
||||
iteration is fast, where you can use loops and randomness and music
|
||||
theory functions -- and then export to MIDI. Open that MIDI file in
|
||||
Logic, Ableton, Reaper, FL Studio, or whatever you use, and now you've
|
||||
got your chord progressions, melodies, and bass lines on real tracks.
|
||||
Swap in your favorite soft synths, add real mixing, finish the track
|
||||
properly. Python is the sketchpad; the DAW is the canvas.
|
||||
|
||||
Export tones, chords, progressions, or full scores as Standard MIDI
|
||||
Files. MIDI files can be opened in any DAW, edited, transposed, and
|
||||
assigned to any instrument.
|
||||
|
||||
Simple export (single tone, chord, or progression):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import save_midi, Key, Tone, Chord
|
||||
|
||||
save_midi(Tone.from_string("C4"), "middle_c.mid", t=1000)
|
||||
save_midi(Chord.from_symbol("Am7"), "am7.mid")
|
||||
|
||||
chords = Key("C", "major").progression("I", "V", "vi", "IV")
|
||||
save_midi(chords, "pop.mid", t=500, bpm=120)
|
||||
|
||||
Score-based export (with time signature, tempo, and parts):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score, Duration, Key
|
||||
|
||||
score = Score("4/4", bpm=140)
|
||||
for chord in Key("G", "major").progression("I", "IV", "V", "I"):
|
||||
score.add(chord, Duration.WHOLE)
|
||||
score.save_midi("progression.mid")
|
||||
|
||||
play_pattern() -- Drum Patterns
|
||||
-------------------------------
|
||||
|
||||
Play a drum pattern through the speakers:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Pattern
|
||||
from pytheory.play import play_pattern
|
||||
|
||||
play_pattern(Pattern.preset("rock"), repeats=4, bpm=120)
|
||||
play_pattern(Pattern.preset("bossa nova"), repeats=4, bpm=140)
|
||||
|
||||
See :doc:`drums` for the full list of 80+ presets and 21 fills.
|
||||
|
||||
play_progression() -- Quick Chord Playback
|
||||
------------------------------------------
|
||||
|
||||
Play a chord progression in sequence with a single call:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Key, play_progression
|
||||
|
||||
chords = Key("C", "major").progression("I", "V", "vi", "IV")
|
||||
play_progression(chords, t=800)
|
||||
|
||||
Optional synth, envelope, and gap parameters:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Synth, Envelope
|
||||
|
||||
play_progression(chords, t=1000, synth=Synth.TRIANGLE, gap=200)
|
||||
play_progression(chords, t=2000, envelope=Envelope.PAD)
|
||||
|
||||
That's the workflow: hear it, tweak it, hear it again. When it sounds right, export to WAV or MIDI and take it somewhere bigger.
|
||||
|
||||
MIDI Import
|
||||
-----------
|
||||
|
||||
Load any Standard MIDI File into a Score — then play it through
|
||||
PyTheory's synth engine with effects, or analyze the theory:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score
|
||||
from pytheory.play import play_score
|
||||
|
||||
score = Score.from_midi("song.mid")
|
||||
|
||||
# See what's inside
|
||||
for name, part in score.parts.items():
|
||||
print(f"{name}: {len(part.notes)} notes")
|
||||
|
||||
# Change the synth and add effects
|
||||
score.parts["ch1"].synth = "saw"
|
||||
score.parts["ch1"].reverb_mix = 0.3
|
||||
|
||||
play_score(score)
|
||||
|
||||
Each MIDI channel becomes a named Part (``ch1``, ``ch2``, etc.).
|
||||
Channel 10 (drums) becomes drum hits. Tempo, time signature,
|
||||
note durations, and velocities are all preserved.
|
||||
|
||||
Download any MIDI file from the internet, load it, play it through
|
||||
the synth engine with reverb and delay. That's the whole idea.
|
||||
|
||||
+216
-46
@@ -1,6 +1,18 @@
|
||||
Quickstart
|
||||
==========
|
||||
|
||||
PyTheory works at two levels — pick the one that fits what you need:
|
||||
|
||||
1. **Music theory** — explore scales, chords, keys, intervals, and
|
||||
harmony. No audio required. Works anywhere Python runs.
|
||||
|
||||
2. **Composition** — build multi-part arrangements with drums, synths,
|
||||
effects, and export to MIDI. Needs PortAudio for live playback.
|
||||
|
||||
Both are first-class. You can use PyTheory purely as a theory
|
||||
reference and never touch the audio side, or you can jump straight
|
||||
into composing. This guide covers both paths.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
@@ -8,62 +20,220 @@ Installation
|
||||
|
||||
$ pip install pytheory
|
||||
|
||||
Basic Usage
|
||||
-----------
|
||||
For audio playback through your speakers, you'll also need
|
||||
`PortAudio <http://www.portaudio.com/>`_:
|
||||
|
||||
Create tones, build scales, and explore music theory:
|
||||
- macOS: ``brew install portaudio``
|
||||
- Ubuntu: ``apt install libportaudio2``
|
||||
- Windows: included with the ``sounddevice`` package
|
||||
|
||||
PortAudio is only needed for live playback. MIDI export, WAV export,
|
||||
and all theory functions work without it.
|
||||
|
||||
Hear Something Immediately
|
||||
--------------------------
|
||||
|
||||
::
|
||||
|
||||
$ pytheory demo
|
||||
|
||||
This generates and plays a random track — different every time. It's
|
||||
the fastest way to hear what PyTheory can do.
|
||||
|
||||
Explore Music Theory
|
||||
--------------------
|
||||
|
||||
The theory layer is where most people start. No audio setup needed —
|
||||
this works everywhere Python runs. Every concept in Western music
|
||||
theory (and five other systems) has a clean Python API.
|
||||
|
||||
Tones and intervals:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Tone
|
||||
|
||||
>>> c4 = Tone.from_string("C4", system="western")
|
||||
>>> c4.frequency
|
||||
261.6255653005986
|
||||
>>> c4.midi
|
||||
60
|
||||
|
||||
>>> c4 + 7
|
||||
<Tone G4>
|
||||
>>> c4.interval_to(c4 + 7)
|
||||
'perfect 5th'
|
||||
|
||||
>>> Tone.from_frequency(440)
|
||||
<Tone A4>
|
||||
>>> Tone.from_midi(69)
|
||||
<Tone A4>
|
||||
|
||||
Keys, scales, and chords:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Key, Chord
|
||||
|
||||
>>> key = Key("C", "major")
|
||||
>>> key.chords
|
||||
['C major', 'D minor', 'E minor', 'F major', 'G major', 'A minor', 'B diminished']
|
||||
|
||||
>>> [c.symbol for c in key.progression("I", "V", "vi", "IV")]
|
||||
['C', 'G', 'Am', 'F']
|
||||
|
||||
>>> key.signature
|
||||
{'sharps': 0, 'flats': 0, 'accidentals': []}
|
||||
|
||||
>>> Key("F", "major").signature
|
||||
{'sharps': 0, 'flats': 1, 'accidentals': ['Bb']}
|
||||
|
||||
>>> Chord.from_symbol("Am7").identify()
|
||||
'A minor 7th'
|
||||
|
||||
>>> Chord.from_tones("G", "B", "D", "F").analyze("C")
|
||||
'V7'
|
||||
|
||||
Harmonic analysis and modulation:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Key("C", "major").pivot_chords(Key("G", "major"))
|
||||
['A minor', 'B minor', 'C major', 'D major', 'E minor', 'G major']
|
||||
|
||||
>>> Key("C", "major").relative
|
||||
<Key A minor>
|
||||
|
||||
>>> key.suggest_next(key.triad(4)) # what follows V?
|
||||
[<Chord C major>, <Chord A minor>, <Chord F major>]
|
||||
|
||||
Scales across 6 musical systems:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
>>> TonedScale(tonic="Sa4", system="indian")["bhairav"].note_names
|
||||
['Sa', 'komal Re', 'Ga', 'Ma', 'Pa', 'komal Dha', 'Ni', 'Sa']
|
||||
|
||||
>>> TonedScale(tonic="Do4", system="arabic")["hijaz"].note_names
|
||||
['Do', 'Reb', 'Mi', 'Fa', 'Sol', 'Solb', 'Sib', 'Do']
|
||||
|
||||
>>> TonedScale(tonic="C4", system="japanese")["hirajoshi"].note_names
|
||||
['C', 'D', 'D#', 'G', 'G#', 'C']
|
||||
|
||||
Guitar fingerings:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Fretboard
|
||||
|
||||
>>> fb = Fretboard.guitar()
|
||||
>>> fb.chord("Am")
|
||||
Fingering(e=0, B=1, G=2, D=2, A=0, E=x)
|
||||
|
||||
All of the above works without PortAudio, without sounddevice,
|
||||
without any audio setup at all. It's pure Python music theory.
|
||||
|
||||
Compose a Track
|
||||
---------------
|
||||
|
||||
This is where it gets fun. A ``Score`` is your arrangement — drums,
|
||||
chords, melody, bass, each with their own synth and effects:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Tone, TonedScale, Fretboard, CHARTS
|
||||
from pytheory import Score, Key, Duration
|
||||
from pytheory.play import play_score
|
||||
|
||||
# Create a tone — A4 is the tuning standard (440 Hz)
|
||||
a4 = Tone.from_string("A4", system="western")
|
||||
print(a4.frequency) # 440.0
|
||||
score = Score("4/4", bpm=120)
|
||||
score.drums("rock", repeats=8, fill="rock", fill_every=4)
|
||||
|
||||
# Tone arithmetic — add semitones to move up the chromatic scale
|
||||
c4 = Tone.from_string("C4", system="western")
|
||||
e4 = c4 + 4 # Major third up (4 semitones)
|
||||
g4 = c4 + 7 # Perfect fifth up (7 semitones)
|
||||
print(e4, g4) # E4 G4
|
||||
piano = score.part("piano", instrument="piano", reverb=0.3)
|
||||
lead = score.part("lead", synth="saw", envelope="pluck",
|
||||
delay=0.2, reverb=0.2, lowpass=4000)
|
||||
bass = score.part("bass", synth="triangle", lowpass=900)
|
||||
|
||||
# Measure intervals between tones
|
||||
print(g4 - c4) # 7 (semitones — a perfect fifth)
|
||||
for chord in Key("G", "major").progression("I", "V", "vi", "IV") * 2:
|
||||
piano.add(chord, Duration.WHOLE)
|
||||
|
||||
# Build a C major scale
|
||||
c_major = TonedScale(tonic="C4")["major"]
|
||||
print(c_major.note_names)
|
||||
# ['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
lead.add("D5", 1).add("B4", 0.5).add("D5", 0.5)
|
||||
lead.add("G5", 1).add("E5", 1)
|
||||
lead.add("D5", 0.5).add("B4", 0.5).add("A4", 1)
|
||||
lead.add("G4", 2).rest(2)
|
||||
|
||||
# Build diatonic triads from the scale
|
||||
I = c_major.triad(0) # C E G (C major)
|
||||
IV = c_major.triad(3) # F A C (F major)
|
||||
V = c_major.triad(4) # G B D (G major)
|
||||
for n in ["G2", "G2", "D2", "D2", "E2", "E2", "C2", "C2"] * 2:
|
||||
bass.add(n, Duration.HALF)
|
||||
|
||||
# Guitar chord fingerings — labeled with string names
|
||||
fb = Fretboard.guitar()
|
||||
fingering = CHARTS["western"]["Am"].fingering(fretboard=fb)
|
||||
print(fingering) # Fingering(e=0, B=1, G=2, D=2, A=0, E=0)
|
||||
play_score(score)
|
||||
|
||||
# Identify a chord from fret positions
|
||||
f = fb.fingering(0, 1, 0, 2, 3, 0)
|
||||
print(f.identify()) # C major
|
||||
.. raw:: html
|
||||
|
||||
What's Included
|
||||
---------------
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/quickstart.wav" type="audio/wav"></audio>
|
||||
|
||||
- **6 musical systems**: Western, Indian (Hindustani), Arabic (Maqam),
|
||||
Japanese, Blues/Pentatonic, Javanese Gamelan
|
||||
- **40+ scales**: major, minor, harmonic minor, 7 modes, 10 thaats,
|
||||
10 maqamat, 6 Japanese pentatonic scales, blues, pentatonic,
|
||||
slendro, pelog, and more
|
||||
- **Pitch calculation** in equal, Pythagorean, and meantone temperaments
|
||||
- **Chord identification**: name any chord from its notes, intervals, or
|
||||
MIDI numbers (17 chord types recognized)
|
||||
- **Chord charts** with 144 pre-built chords (12 roots x 12 qualities)
|
||||
- **Chord analysis**: consonance scoring, Plomp-Levelt dissonance,
|
||||
beat frequency calculation, harmonic tension, voice leading
|
||||
- **Key detection** and **Roman numeral analysis** (I-IV-V-I progressions)
|
||||
- **Fingering generation** for 25 instruments with labeled string names,
|
||||
including guitar (8 tunings), bass, ukulele, mandolin, and more
|
||||
- **Audio playback** with sine, sawtooth, and triangle wave synthesis
|
||||
Export to Your DAW
|
||||
------------------
|
||||
|
||||
The whole point: sketch in Python, finish in Logic / Ableton / Reaper.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score.save_midi("my_sketch.mid")
|
||||
|
||||
Open that file in any DAW and you'll see all the notes laid out on
|
||||
the timeline, ready to assign to real instruments and mix.
|
||||
|
||||
You can also save rendered audio:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import save
|
||||
save(Chord.from_symbol("Am7"), "am7.wav", t=2_000)
|
||||
|
||||
What's in the Box
|
||||
-----------------
|
||||
|
||||
**Theory** — tones, scales (40+ across 6 musical systems), chords
|
||||
(17 types, Roman numeral analysis, figured bass, tension scoring,
|
||||
voice leading, pitch class sets with Forte numbers), keys (detection,
|
||||
signatures, modulation paths, borrowed chords), scale recommendation.
|
||||
|
||||
**Sequencing** — Score, Part, Duration, TimeSignature. Arpeggiator
|
||||
with 5 patterns. Legato with pitch glide. Per-note velocity. Swing.
|
||||
Tempo changes. Fade in/out. Song sections with repeat. Humanize.
|
||||
|
||||
**Synthesis** — 10 waveforms: sine, saw, triangle, square, pulse, FM,
|
||||
noise, supersaw, PWM slow, PWM fast. 8 ADSR envelopes. Detune.
|
||||
Stereo pan and spread.
|
||||
|
||||
**Effects** — distortion, chorus, lowpass filter (with resonance),
|
||||
delay, reverb (algorithmic + 7 stereo convolution presets including
|
||||
Taj Mahal with 12-second tail). All per-part with automation and
|
||||
LFO modulation. Sidechain compression. Master bus compressor/limiter.
|
||||
|
||||
**Drums** — 58 pattern presets (rock, jazz, salsa, bossa nova,
|
||||
afrobeat, house, trap, and 50+ more). 21 fill presets. 27 synthesized
|
||||
drum voices with stereo panning.
|
||||
|
||||
**Instruments** — 25 presets (guitar with 8 tunings, bass, ukulele,
|
||||
mandolin family, violin family, banjo, harp, oud, sitar, erhu, and
|
||||
more) with chord fingering generation and scale diagrams.
|
||||
|
||||
**Output** — stereo playback, WAV export, MIDI import/export.
|
||||
|
||||
**Interface** — REPL with tab completion (``pytheory repl``), CLI with
|
||||
15 commands. ``pytheory demo``, ``pytheory key``, ``pytheory chord``,
|
||||
``pytheory identify``, ``pytheory midi``, ``pytheory play``, and more.
|
||||
|
||||
Where to Go Next
|
||||
-----------------
|
||||
|
||||
- :doc:`theory` — music theory fundamentals
|
||||
- :doc:`tones` — working with individual notes
|
||||
- :doc:`scales` — scales, modes, and keys
|
||||
- :doc:`chords` — chord construction, analysis, and progressions
|
||||
- :doc:`sequencing` — composing multi-part arrangements
|
||||
- :doc:`synths` — the 10 waveforms and 8 envelopes
|
||||
- :doc:`effects` — reverb, delay, distortion, chorus, lowpass, automation
|
||||
- :doc:`drums` — 58 patterns, 21 fills, drum synthesis
|
||||
- :doc:`playback` — play, save, export
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
Interactive REPL
|
||||
================
|
||||
|
||||
PyTheory includes an interactive scratchpad for exploring music theory,
|
||||
hearing ideas instantly, and building arrangements — all without writing
|
||||
a Python script.
|
||||
|
||||
::
|
||||
|
||||
$ pytheory repl
|
||||
|
||||
The REPL is two things at once: a **theory calculator** (what chords
|
||||
are in this key? what's the interval between these notes?) and a
|
||||
**composition sketchpad** (add drums, layer parts, tweak effects, hear
|
||||
it, export MIDI). Use whichever side you need.
|
||||
|
||||
Getting Started
|
||||
---------------
|
||||
|
||||
The welcome screen tells you everything you need::
|
||||
|
||||
♫ PyTheory REPL
|
||||
════════════════════════════════════════
|
||||
|
||||
try: key Am — set a key
|
||||
chords — see its chords
|
||||
prog I V vi IV — hear a progression
|
||||
drums bossa nova
|
||||
play_score — hear it all
|
||||
|
||||
help for all commands, quit to exit
|
||||
|
||||
Type those five things in order and you'll have music playing in
|
||||
30 seconds.
|
||||
|
||||
The Prompt
|
||||
----------
|
||||
|
||||
The prompt shows your current state — key, tempo, drums, active part,
|
||||
and effects. It starts compact and grows as you add context::
|
||||
|
||||
pytheory[key=C | bpm=120]>
|
||||
|
||||
pytheory[key=Am | bpm=140]>
|
||||
|
||||
pytheory[key=Am | bpm=140 | drums=bossa nova]>
|
||||
|
||||
pytheory[key=Am | bpm=140 | drums=bossa nova | →lead(saw)]>
|
||||
|
||||
When it gets long, it stacks into two lines::
|
||||
|
||||
key=Am | bpm=140 | drums=bossa nova | →lead(saw) rev=0.3 lp=2000
|
||||
♫>
|
||||
|
||||
You always know where you are.
|
||||
|
||||
Theory Commands
|
||||
---------------
|
||||
|
||||
These work without any audio setup. Pure theory exploration.
|
||||
|
||||
Set a key and explore it::
|
||||
|
||||
pytheory> key Am
|
||||
A minor: A B C D E F G A
|
||||
|
||||
pytheory> chords
|
||||
i A minor
|
||||
ii° B diminished
|
||||
III C major
|
||||
iv D minor
|
||||
v E minor
|
||||
VI F major
|
||||
VII G major
|
||||
|
||||
pytheory> modes
|
||||
ionian A B C# D E F# G# A
|
||||
dorian A B C D E F# G A
|
||||
phrygian A Bb C D E F G A
|
||||
...
|
||||
|
||||
pytheory> scales
|
||||
major A B C# D E F# G# A
|
||||
minor A B C D E F G A
|
||||
harmonic minor A B C D E F G# A
|
||||
...
|
||||
|
||||
Build progressions::
|
||||
|
||||
pytheory> prog I V vi IV
|
||||
Am → Em → F → Dm
|
||||
|
||||
pytheory> progression i iv V i
|
||||
Am → Dm → E → Am
|
||||
|
||||
Explore intervals and chords::
|
||||
|
||||
pytheory> interval C4 G4
|
||||
C4 → G4: perfect 5th
|
||||
7 semitones
|
||||
|
||||
pytheory> identify C E G
|
||||
C major
|
||||
symbol: C
|
||||
|
||||
pytheory> identify F#m7b5
|
||||
F# half-diminished 7th
|
||||
symbol: F#m7b5
|
||||
tones: F#4 A4 C5 E5
|
||||
intervals: [3, 3, 4]
|
||||
|
||||
Circle of fifths::
|
||||
|
||||
pytheory> circle
|
||||
fifths: A → E → B → F# → C# → G# → D# → A# → F → C → G → D
|
||||
fourths: A → D → G → C → F → A# → D# → G# → C# → F# → B → E
|
||||
|
||||
Other musical systems::
|
||||
|
||||
pytheory> system indian
|
||||
system: indian
|
||||
scales: chromatic, bilawal, khamaj, kafi, ...
|
||||
|
||||
pytheory> system arabic
|
||||
system: arabic
|
||||
scales: chromatic, ajam, nahawand, kurd, hijaz, ...
|
||||
|
||||
Guitar::
|
||||
|
||||
pytheory> fingering Am
|
||||
Am
|
||||
E|--0--
|
||||
B|--1--
|
||||
G|--2--
|
||||
D|--2--
|
||||
A|--0--
|
||||
E|--x--
|
||||
|
||||
pytheory> diagram minor 5
|
||||
0 1 2 3 4 5
|
||||
E| E | F | - | G | - | A |
|
||||
...
|
||||
|
||||
Composition Commands
|
||||
--------------------
|
||||
|
||||
When you're ready to make sound, add drums and parts.
|
||||
|
||||
Drums::
|
||||
|
||||
pytheory> drums bossa nova
|
||||
score.drums("bossa nova", repeats=4)
|
||||
|
||||
pytheory> drums
|
||||
(lists all 58 presets)
|
||||
|
||||
Parts — each with its own synth and envelope::
|
||||
|
||||
pytheory> part lead saw pluck
|
||||
score.part("lead", synth="saw", envelope="pluck")
|
||||
|
||||
pytheory> part chords fm pad
|
||||
score.part("chords", synth="fm", envelope="pad")
|
||||
|
||||
pytheory> part bass sine pluck
|
||||
score.part("bass", synth="sine", envelope="pluck")
|
||||
|
||||
pytheory> part
|
||||
lead: synth=saw envelope=pluck vol=0.5 ←
|
||||
chords: synth=fm envelope=pad vol=0.5
|
||||
bass: synth=sine envelope=pluck vol=0.5
|
||||
|
||||
The arrow (``←``) shows which part is active. Switch with
|
||||
``part <name>``.
|
||||
|
||||
Add notes, chords, arpeggios::
|
||||
|
||||
pytheory> add C5 1
|
||||
.add("C5", 1.0)
|
||||
|
||||
pytheory> add Am 4
|
||||
.add(Chord.from_symbol("Am"), 4.0)
|
||||
|
||||
pytheory> add E5 0.67 110
|
||||
.add("E5", 0.67, velocity=110)
|
||||
|
||||
pytheory> rest 2
|
||||
.rest(2.0)
|
||||
|
||||
pytheory> arp Am updown 2 2
|
||||
.arpeggio("Am", pattern="updown", bars=2.0, octaves=2)
|
||||
|
||||
pytheory> prog i iv V i
|
||||
Am → Dm → E → Am
|
||||
|
||||
Effects
|
||||
-------
|
||||
|
||||
Set effects on the active part — mirrors the Python API::
|
||||
|
||||
pytheory> reverb 0.4
|
||||
pytheory> delay 0.3 0.375
|
||||
pytheory> lowpass 2000 3
|
||||
pytheory> dist 0.5
|
||||
pytheory> chorus 0.3
|
||||
pytheory> sidechain 0.8
|
||||
pytheory> humanize 0.3
|
||||
pytheory> legato on
|
||||
pytheory> glide 0.04
|
||||
pytheory> volume 0.4
|
||||
|
||||
Automation — change effects mid-song::
|
||||
|
||||
pytheory> set lowpass 3000
|
||||
.set(lowpass=3000)
|
||||
|
||||
LFO modulation::
|
||||
|
||||
pytheory> lfo lowpass 0.5 400 3000 8 sine
|
||||
.lfo("lowpass", rate=0.5, min=400, max=3000, bars=8, shape="sine")
|
||||
|
||||
Playback and Export
|
||||
-------------------
|
||||
|
||||
Hear your work::
|
||||
|
||||
pytheory> play_score
|
||||
♫ play_score()
|
||||
|
||||
pytheory> play_pattern
|
||||
♫ play_pattern("bossa nova")
|
||||
|
||||
Export::
|
||||
|
||||
pytheory> save_midi sketch.mid
|
||||
save_midi("sketch.mid")
|
||||
|
||||
pytheory> render sketch.wav
|
||||
saved: sketch.wav
|
||||
|
||||
Session management::
|
||||
|
||||
pytheory> show
|
||||
<Score 4/4 140bpm 3 parts 8.0 measures>
|
||||
lead: saw+pluck 32 notes reverb=0.3 delay=0.25 ←
|
||||
chords: fm+pad 8 notes
|
||||
drums: bossa nova (76 hits)
|
||||
|
||||
pytheory> status
|
||||
key=A minor bpm=140 swing=0.0
|
||||
drums=bossa nova parts=[lead, chords, bass] active=lead
|
||||
|
||||
pytheory> clear
|
||||
cleared (C major, 120 bpm)
|
||||
|
||||
Complete Example
|
||||
----------------
|
||||
|
||||
A full session from start to playable track::
|
||||
|
||||
pytheory[key=C | bpm=120]> key Am
|
||||
pytheory[key=Am | bpm=120]> bpm 140
|
||||
pytheory[key=Am | bpm=140]> drums bossa nova
|
||||
pytheory[key=Am | bpm=140 | drums=bossa nova]> part chords fm pad
|
||||
pytheory[...| →chords(fm)]> prog i iv V i
|
||||
pytheory[...| →chords(fm)]> part lead saw pluck
|
||||
pytheory[...| →lead(saw)]> reverb 0.3
|
||||
pytheory[...| →lead(saw) rev=0.3]> delay 0.25
|
||||
pytheory[...| →lead(saw) rev=0.3 del=0.25]> arp Am updown 4 2
|
||||
pytheory[...]> play_score
|
||||
♫ play_score()
|
||||
pytheory[...]> save_midi my_bossa.mid
|
||||
save_midi("my_bossa.mid")
|
||||
|
||||
Every command you typed maps 1:1 to the Python API. When you're
|
||||
ready to move from the REPL to a script, the translation is direct.
|
||||
+324
-112
@@ -30,18 +30,15 @@ Building Scales
|
||||
|
||||
Use :class:`~pytheory.scales.TonedScale` to generate scales in any key:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
|
||||
c = TonedScale(tonic="C4")
|
||||
|
||||
major = c["major"]
|
||||
minor = c["minor"]
|
||||
harmonic_minor = c["harmonic minor"]
|
||||
|
||||
print(major.note_names)
|
||||
# ['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
>>> from pytheory import TonedScale
|
||||
>>> c = TonedScale(tonic="C4")
|
||||
>>> major = c["major"]
|
||||
>>> minor = c["minor"]
|
||||
>>> harmonic_minor = c["harmonic minor"]
|
||||
>>> major.note_names
|
||||
['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
|
||||
Major and Minor
|
||||
---------------
|
||||
@@ -55,13 +52,12 @@ notes but starts from the 6th degree:
|
||||
- G major → E minor (both have one sharp: F#)
|
||||
- F major → D minor (both have one flat: Bb)
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
c_major = TonedScale(tonic="C4")["major"]
|
||||
a_minor = TonedScale(tonic="A4")["minor"]
|
||||
|
||||
# Same notes, different starting point
|
||||
set(c_major.note_names) == set(a_minor.note_names) # True
|
||||
>>> c_major = TonedScale(tonic="C4")["major"]
|
||||
>>> a_minor = TonedScale(tonic="A4")["minor"]
|
||||
>>> set(c_major.note_names) == set(a_minor.note_names)
|
||||
True
|
||||
|
||||
The `harmonic minor <https://en.wikipedia.org/wiki/Harmonic_minor_scale>`_ raises the 7th degree of the natural minor,
|
||||
creating an augmented 2nd interval (3 semitones) between the 6th and
|
||||
@@ -79,44 +75,65 @@ The seven `modes <https://en.wikipedia.org/wiki/Mode_(music)>`_ of the major sca
|
||||
pattern, each starting from a different degree. Each mode has a distinct
|
||||
emotional character:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
c = TonedScale(tonic="C4")
|
||||
>>> c = TonedScale(tonic="C4")
|
||||
|
||||
**Ionian** (I) — the major scale itself. Bright, happy, resolved::
|
||||
**Ionian** (I) — the major scale itself. Bright, happy, resolved:
|
||||
|
||||
c["ionian"] # C D E F G A B C
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c["ionian"].note_names
|
||||
['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
|
||||
`Dorian <https://en.wikipedia.org/wiki/Dorian_mode>`_ (ii) — minor with a raised 6th. Jazzy, soulful (So What,
|
||||
Scarborough Fair)::
|
||||
Scarborough Fair):
|
||||
|
||||
c["dorian"] # C D Eb F G A Bb C
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c["dorian"].note_names
|
||||
['C', 'D', 'Eb', 'F', 'G', 'A', 'Bb', 'C']
|
||||
|
||||
`Phrygian <https://en.wikipedia.org/wiki/Phrygian_mode>`_ (iii) — minor with a flat 2nd. Spanish, flamenco, dark
|
||||
(White Rabbit)::
|
||||
(White Rabbit):
|
||||
|
||||
c["phrygian"] # C Db Eb F G Ab Bb C
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c["phrygian"].note_names
|
||||
['C', 'Db', 'Eb', 'F', 'G', 'Ab', 'Bb', 'C']
|
||||
|
||||
`Lydian <https://en.wikipedia.org/wiki/Lydian_mode>`_ (IV) — major with a raised 4th. Dreamy, floating, ethereal
|
||||
(The Simpsons theme, Flying by ET)::
|
||||
(The Simpsons theme, Flying by ET):
|
||||
|
||||
c["lydian"] # C D E F# G A B C
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c["lydian"].note_names
|
||||
['C', 'D', 'E', 'F#', 'G', 'A', 'B', 'C']
|
||||
|
||||
`Mixolydian <https://en.wikipedia.org/wiki/Mixolydian_mode>`_ (V) — major with a flat 7th. Bluesy, rock, dominant
|
||||
(Norwegian Wood, Sweet Home Alabama)::
|
||||
(Norwegian Wood, Sweet Home Alabama):
|
||||
|
||||
c["mixolydian"] # C D E F G A Bb C
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c["mixolydian"].note_names
|
||||
['C', 'D', 'E', 'F', 'G', 'A', 'Bb', 'C']
|
||||
|
||||
`Aeolian <https://en.wikipedia.org/wiki/Aeolian_mode>`_ (vi) — the natural minor scale. Sad, dark, introspective
|
||||
(Stairway to Heaven, Losing My Religion)::
|
||||
(Stairway to Heaven, Losing My Religion):
|
||||
|
||||
c["aeolian"] # C D Eb F G Ab Bb C
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c["aeolian"].note_names
|
||||
['C', 'D', 'Eb', 'F', 'G', 'Ab', 'Bb', 'C']
|
||||
|
||||
`Locrian <https://en.wikipedia.org/wiki/Locrian_mode>`_ (vii) — minor with flat 2nd and flat 5th. Unstable,
|
||||
rarely used as a home key (used in metal and jazz over diminished
|
||||
chords)::
|
||||
chords):
|
||||
|
||||
c["locrian"] # C Db Eb F Gb Ab Bb C
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c["locrian"].note_names
|
||||
['C', 'Db', 'Eb', 'F', 'Gb', 'Ab', 'Bb', 'C']
|
||||
|
||||
Scale Degrees
|
||||
-------------
|
||||
@@ -137,32 +154,45 @@ Leading Tone VII One semitone below tonic — pulls upward
|
||||
|
||||
Access degrees by index, Roman numeral, or name:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
major = TonedScale(tonic="C4")["major"]
|
||||
|
||||
major[0] # C4 (by index)
|
||||
major["I"] # C4 (by Roman numeral)
|
||||
major["tonic"] # C4 (by degree name)
|
||||
|
||||
major["V"] # G4 (dominant)
|
||||
major["dominant"] # G4
|
||||
|
||||
major[0:3] # (C4, D4, E4) — slicing works too
|
||||
>>> major = TonedScale(tonic="C4")["major"]
|
||||
>>> major[0]
|
||||
C4
|
||||
>>> major["I"]
|
||||
C4
|
||||
>>> major["tonic"]
|
||||
C4
|
||||
>>> major["V"]
|
||||
G4
|
||||
>>> major["dominant"]
|
||||
G4
|
||||
>>> major[0:3]
|
||||
(<Tone C4>, <Tone D4>, <Tone E4>)
|
||||
|
||||
Iteration
|
||||
---------
|
||||
|
||||
Scales are iterable and support ``len()`` and ``in``:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
for tone in major:
|
||||
print(f"{tone.name}: {tone.frequency:.1f} Hz")
|
||||
|
||||
len(major) # 8 (7 notes + octave)
|
||||
"C" in major # True
|
||||
"C#" in major # False
|
||||
>>> for tone in major:
|
||||
... print(f"{tone.name}: {tone.frequency:.1f} Hz")
|
||||
C: 261.6 Hz
|
||||
D: 293.7 Hz
|
||||
E: 329.6 Hz
|
||||
F: 349.2 Hz
|
||||
G: 392.0 Hz
|
||||
A: 440.0 Hz
|
||||
B: 493.9 Hz
|
||||
C: 523.3 Hz
|
||||
>>> len(major)
|
||||
8
|
||||
>>> "C" in major
|
||||
True
|
||||
>>> "C#" in major
|
||||
False
|
||||
|
||||
Building Chords from Scales
|
||||
----------------------------
|
||||
@@ -185,21 +215,25 @@ Notice the pattern: **major** triads on I, IV, V; **minor** triads on
|
||||
ii, iii, vi; **diminished** on vii°. This pattern holds for every major
|
||||
key.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
major = TonedScale(tonic="C4")["major"]
|
||||
|
||||
# Build diatonic triads
|
||||
I = major.triad(0) # C E G (C major)
|
||||
ii = major.triad(1) # D F A (D minor)
|
||||
iii = major.triad(2) # E G B (E minor)
|
||||
IV = major.triad(3) # F A C (F major)
|
||||
V = major.triad(4) # G B D (G major)
|
||||
vi = major.triad(5) # A C E (A minor)
|
||||
|
||||
# Build seventh chords
|
||||
Imaj7 = major.chord(0, 2, 4, 6) # C E G B = Cmaj7
|
||||
V7 = major.chord(4, 6, 8, 10) # G B D F = G7 (dominant 7th)
|
||||
>>> major = TonedScale(tonic="C4")["major"]
|
||||
>>> major.triad(0)
|
||||
C major
|
||||
>>> major.triad(1)
|
||||
D minor
|
||||
>>> major.triad(2)
|
||||
E minor
|
||||
>>> major.triad(3)
|
||||
F major
|
||||
>>> major.triad(4)
|
||||
G major
|
||||
>>> major.triad(5)
|
||||
A minor
|
||||
>>> major.chord(0, 2, 4, 6)
|
||||
C major 7th
|
||||
>>> major.chord(4, 6, 8, 10)
|
||||
G dominant 7th
|
||||
|
||||
Common Progressions
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
@@ -218,31 +252,25 @@ Some of the most-used chord progressions in Western music:
|
||||
The :class:`~pytheory.scales.Key` class makes working with progressions
|
||||
easy:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Key
|
||||
|
||||
key = Key("G", "major")
|
||||
|
||||
# Build a progression from Roman numerals
|
||||
chords = key.progression("I", "V", "vi", "IV")
|
||||
for c in chords:
|
||||
print(c.identify())
|
||||
# G major, D major, E minor, C major
|
||||
|
||||
# Nashville number system (same thing, with integers)
|
||||
key.nashville(1, 5, 6, 4)
|
||||
|
||||
# All diatonic triads in the key
|
||||
key.chords
|
||||
# ['G major', 'A minor', 'B minor', 'C major', ...]
|
||||
|
||||
# All diatonic seventh chords
|
||||
key.seventh_chords
|
||||
# ['G major 7th', 'A minor 7th', ...]
|
||||
|
||||
# Detect the key from a set of notes
|
||||
Key.detect("C", "E", "G", "A", "D") # <Key C major>
|
||||
>>> from pytheory import Key
|
||||
>>> key = Key("G", "major")
|
||||
>>> chords = key.progression("I", "V", "vi", "IV")
|
||||
>>> for c in chords:
|
||||
... print(c.identify())
|
||||
G major
|
||||
D major
|
||||
E minor
|
||||
C major
|
||||
>>> key.nashville(1, 5, 6, 4)
|
||||
[<Chord G major>, <Chord D major>, <Chord E minor>, <Chord C major>]
|
||||
>>> key.chords
|
||||
['G major', 'A minor', 'B minor', 'C major', 'D major', 'E minor', 'F# diminished']
|
||||
>>> key.seventh_chords
|
||||
['G major 7th', 'A minor 7th', 'B minor 7th', 'C major 7th', 'D dominant 7th', 'E minor 7th', 'F# half-diminished 7th']
|
||||
>>> Key.detect("C", "E", "G", "A", "D")
|
||||
C major
|
||||
|
||||
The 12-Bar Blues
|
||||
~~~~~~~~~~~~~~~~
|
||||
@@ -262,35 +290,219 @@ structure. In the key of A::
|
||||
| D | D | A | A |
|
||||
| E | D | A | E |
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
>>> from pytheory import TonedScale
|
||||
>>> a = TonedScale(tonic="A4")["major"]
|
||||
>>> I = a.triad(0)
|
||||
>>> IV = a.triad(3)
|
||||
>>> V = a.triad(4)
|
||||
>>> blues_12 = [I, I, I, I, IV, IV, I, I, V, IV, I, V]
|
||||
|
||||
a = TonedScale(tonic="A4")["major"]
|
||||
I = a.triad(0) # A major
|
||||
IV = a.triad(3) # D major
|
||||
V = a.triad(4) # E major
|
||||
Key Signatures
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
# The 12-bar blues progression
|
||||
blues_12 = [I, I, I, I, IV, IV, I, I, V, IV, I, V]
|
||||
The ``signature`` property tells you how many sharps or flats a key has:
|
||||
|
||||
Parallel Major and Minor
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
.. code-block:: pycon
|
||||
|
||||
Two scales are **relative** if they share the same notes (C major and
|
||||
A minor). Two scales are `parallel <https://en.wikipedia.org/wiki/Parallel_key>`_ if they share the same tonic but
|
||||
have different notes (C major and C minor).
|
||||
>>> Key("G", "major").signature
|
||||
{'sharps': 1, 'flats': 0, 'accidentals': ['F#']}
|
||||
>>> Key("F", "major").signature
|
||||
{'sharps': 0, 'flats': 1, 'accidentals': ['Bb']}
|
||||
>>> Key("C", "major").signature
|
||||
{'sharps': 0, 'flats': 0, 'accidentals': []}
|
||||
|
||||
Mixing parallel major and minor is a powerful compositional tool —
|
||||
borrowing chords from the parallel minor in a major key creates
|
||||
dramatic color shifts. The bVI and bVII chords (Ab and Bb in C major)
|
||||
are borrowed from C minor and appear constantly in rock and film music.
|
||||
Relative and Parallel Keys
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. code-block:: python
|
||||
Two keys are **relative** if they share the same notes (C major and
|
||||
A minor). Two keys are `parallel <https://en.wikipedia.org/wiki/Parallel_key>`_ if they share the same tonic but
|
||||
have different notes (C major and C minor):
|
||||
|
||||
c_major = TonedScale(tonic="C4")["major"]
|
||||
c_minor = TonedScale(tonic="C4")["minor"]
|
||||
.. code-block:: pycon
|
||||
|
||||
# Compare: same tonic, different notes
|
||||
c_major.note_names # ['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
c_minor.note_names # ['C', 'D', 'D#', 'F', 'G', 'G#', 'A#', 'C']
|
||||
>>> Key("C", "major").relative
|
||||
A minor
|
||||
>>> Key("A", "minor").relative
|
||||
C major
|
||||
>>> Key("C", "major").parallel
|
||||
C minor
|
||||
|
||||
Borrowed Chords
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
`Modal interchange <https://en.wikipedia.org/wiki/Borrowed_chord>`_ —
|
||||
borrowing chords from the parallel key — is one of the most powerful
|
||||
tools in songwriting. The bVI and bVII chords (Ab and Bb in C major)
|
||||
are borrowed from C minor and appear constantly in rock and film music:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Key("C", "major").borrowed_chords
|
||||
['C minor', 'D diminished', 'Eb major', 'F minor', 'G minor', 'Ab major', 'Bb major']
|
||||
|
||||
Secondary Dominants
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A `secondary dominant <https://en.wikipedia.org/wiki/Secondary_dominant>`_
|
||||
is the V chord *of* a non-tonic chord. It creates a momentary pull
|
||||
toward that chord, adding harmonic color:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> key = Key("C", "major")
|
||||
>>> key.secondary_dominant(5)
|
||||
D dominant 7th
|
||||
>>> key.secondary_dominant(2)
|
||||
A dominant 7th
|
||||
|
||||
Random Progressions
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Need inspiration? Generate weighted random progressions. The weights
|
||||
favor common chord functions (I and vi most likely, vii least):
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> key = Key("C", "major")
|
||||
>>> chords = key.random_progression(4)
|
||||
>>> [c.identify() for c in chords]
|
||||
['C major', 'F major', 'A minor', 'G major']
|
||||
|
||||
All Keys
|
||||
~~~~~~~~
|
||||
|
||||
Enumerate all 24 major and minor keys:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Key.all_keys()
|
||||
[<Key C major>, <Key C minor>, <Key C# major>, <Key C# minor>, ...]
|
||||
|
||||
Scale Transposition
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Transpose an entire scale by a number of semitones:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c_major = TonedScale(tonic="C4")["major"]
|
||||
>>> d_major = c_major.transpose(2)
|
||||
>>> d_major.note_names
|
||||
['D', 'E', 'F#', 'G', 'A', 'B', 'C#', 'D']
|
||||
|
||||
Degree Names
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Get the traditional function name for any scale degree:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> major = TonedScale(tonic="C4")["major"]
|
||||
>>> major.degree_name(0)
|
||||
'tonic'
|
||||
>>> major.degree_name(4)
|
||||
'dominant'
|
||||
>>> major.degree_name(6)
|
||||
'leading tone'
|
||||
>>> major.degree_name(6, minor=True)
|
||||
'subtonic'
|
||||
|
||||
Scale Fitness
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Score how well a set of notes fits a scale (0.0–1.0). Useful for melody
|
||||
analysis or detecting which scale a phrase belongs to:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> major = TonedScale(tonic="C4")["major"]
|
||||
>>> major.fitness("C", "D", "E", "G")
|
||||
1.0
|
||||
>>> major.fitness("C", "D", "F#", "G")
|
||||
0.75
|
||||
|
||||
Scale Recommendation
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Given a melody or set of notes, find the best-matching scales ranked
|
||||
by fitness. Useful for figuring out what key you're in or finding
|
||||
alternative scales to improvise over:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory.scales import Scale
|
||||
|
||||
>>> Scale.recommend("C", "D", "E", "G", "A", top=3)
|
||||
[('C', 'major', 1.0), ('A', 'aeolian', 1.0), ...]
|
||||
|
||||
>>> Scale.recommend("C", "Eb", "F", "Gb", "G", "Bb", top=3)
|
||||
[('C', 'blues', 1.0), ...]
|
||||
|
||||
Chromatic scales are deprioritized since they match everything.
|
||||
|
||||
Parallel Modes
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
See all 7 modes that share the same notes as a scale:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> major = TonedScale(tonic="C4")["major"]
|
||||
>>> for name, notes in major.parallel_modes().items():
|
||||
... print(f"{name}: {' '.join(notes)}")
|
||||
C ionian: C D E F G A B C
|
||||
D dorian: D E F G A B C D
|
||||
E phrygian: E F G A B C D E
|
||||
...
|
||||
|
||||
Common Progressions
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Get all named progressions realized in a key with chord symbols:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> key = Key("C", "major")
|
||||
>>> progs = key.common_progressions()
|
||||
>>> for name, chords in list(progs.items())[:3]:
|
||||
... symbols = [c.symbol for c in chords]
|
||||
... print(f"{name}: {' → '.join(symbols)}")
|
||||
I-IV-V-I: C → F → G → C
|
||||
I-V-vi-IV: C → G → Am → F
|
||||
I-vi-IV-V: C → Am → F → G
|
||||
|
||||
Chord Suggestions
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
Given a chord in a key, ``suggest_next()`` returns likely next chords
|
||||
based on functional harmony voice-leading rules:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> key = Key("C", "major")
|
||||
>>> g_major = key.triad(4) # V chord
|
||||
>>> [c.symbol for c in key.suggest_next(g_major)]
|
||||
['C', 'Am', 'F']
|
||||
|
||||
Modulation
|
||||
~~~~~~~~~~
|
||||
|
||||
``modulation_path()`` suggests a chord-by-chord route from one key to
|
||||
another, using pivot chords when available:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> path = Key("C", "major").modulation_path(Key("G", "major"))
|
||||
>>> [c.symbol for c in path]
|
||||
['C', 'Em', 'D', 'G']
|
||||
|
||||
``pivot_chords()`` shows which chords are shared between two keys:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Key("C", "major").pivot_chords(Key("G", "major"))
|
||||
['A minor', 'B minor', 'C major', 'D major', 'E minor', 'G major']
|
||||
|
||||
Scales are the map; the key is the territory. Once you know the landscape, you can wander freely -- and you'll always know how to get home.
|
||||
|
||||
@@ -0,0 +1,926 @@
|
||||
Sequencing
|
||||
==========
|
||||
|
||||
The sequencing system lets you compose multi-part arrangements with
|
||||
durations, time signatures, and instrument voices. This is where
|
||||
PyTheory goes from theory tool to composition tool.
|
||||
|
||||
At the center of everything is the ``Score``. Think of it as your
|
||||
arrangement, your song, your sketch pad. It holds the tempo, the time
|
||||
signature, the drum pattern, and every instrument part you create. If
|
||||
you've ever used a DAW, the Score is your session file. If you haven't,
|
||||
it's the sheet of paper where the whole piece lives. Everything you
|
||||
compose -- melodies, chord progressions, bass lines, arpeggios -- gets
|
||||
added to a Score before you can hear it, export it, or do anything
|
||||
useful with it.
|
||||
|
||||
Duration
|
||||
--------
|
||||
|
||||
In music, all rhythm boils down to one convention: the quarter note
|
||||
equals one beat. Everything else is relative to that. A whole note is
|
||||
four beats. An eighth note is half a beat. This is how musicians have
|
||||
communicated timing for centuries, and it's how PyTheory works too.
|
||||
Once you internalize "quarter note = 1 beat," durations become
|
||||
intuitive arithmetic.
|
||||
|
||||
A ``Duration`` represents a note length in beats (quarter note = 1 beat):
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Duration
|
||||
|
||||
>>> Duration.WHOLE.value
|
||||
4.0
|
||||
>>> Duration.HALF.value
|
||||
2.0
|
||||
>>> Duration.QUARTER.value
|
||||
1.0
|
||||
>>> Duration.EIGHTH.value
|
||||
0.5
|
||||
>>> Duration.SIXTEENTH.value
|
||||
0.25
|
||||
>>> Duration.DOTTED_HALF.value
|
||||
3.0
|
||||
>>> Duration.DOTTED_QUARTER.value
|
||||
1.5
|
||||
>>> Duration.TRIPLET_QUARTER.value
|
||||
0.6666666666666666
|
||||
|
||||
Duration supports arithmetic — multiply, divide, and add to create
|
||||
compound durations:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Duration.WHOLE * 2
|
||||
8.0
|
||||
>>> Duration.HALF + Duration.QUARTER
|
||||
3.0
|
||||
>>> Duration.WHOLE / 2
|
||||
2.0
|
||||
|
||||
Time Signatures
|
||||
---------------
|
||||
|
||||
If you're not a musician, time signatures can seem mysterious. They're
|
||||
not. The top number tells you how many beats are in a bar. The bottom
|
||||
number tells you which note value gets one beat. That's it.
|
||||
|
||||
In practice, you only need to know a handful:
|
||||
|
||||
- **4/4** -- four beats per bar. This is the default. Almost all pop,
|
||||
rock, hip hop, electronic, and R&B music is in 4/4. If you're not
|
||||
sure, use this.
|
||||
- **3/4** -- three beats per bar. The waltz feel. Think "Blue Danube"
|
||||
or Radiohead's "Everything in Its Right Place."
|
||||
- **6/8** -- six eighth notes per bar, grouped in two sets of three.
|
||||
Each group feels like one big swaying beat. Folk music, slow jams,
|
||||
ballads.
|
||||
- **12/8** -- twelve eighth notes per bar, grouped in four sets of
|
||||
three. The slow blues shuffle, the gospel feel, "At Last" by Etta
|
||||
James. Each "big beat" has a triplet swing baked into it.
|
||||
|
||||
A ``TimeSignature`` holds the meter of a piece -- how many beats per
|
||||
measure and which note value gets one beat:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory.rhythm import TimeSignature
|
||||
|
||||
>>> ts = TimeSignature.from_string("4/4")
|
||||
>>> ts.beats_per_measure
|
||||
4.0
|
||||
|
||||
>>> TimeSignature.from_string("3/4").beats_per_measure
|
||||
3.0
|
||||
|
||||
>>> TimeSignature.from_string("6/8").beats_per_measure
|
||||
3.0
|
||||
|
||||
>>> TimeSignature.from_string("12/8").beats_per_measure
|
||||
6.0
|
||||
|
||||
The ``beats_per_measure`` is always in quarter-note units. In 6/8,
|
||||
there are 6 eighth notes per bar = 3 quarter-note beats. In 12/8,
|
||||
12 eighth notes = 6 quarter-note beats, grouped in four dotted-quarter
|
||||
pulses.
|
||||
|
||||
Score Basics
|
||||
------------
|
||||
|
||||
A ``Score`` is a sequence of notes and rests with a time signature and
|
||||
tempo. Use ``.add()`` and ``.rest()`` for fluent chaining:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score, Duration, Tone
|
||||
|
||||
score = Score("4/4", bpm=120)
|
||||
score.add(Tone.from_string("C4", system="western"), Duration.QUARTER)
|
||||
score.add(Tone.from_string("E4", system="western"), Duration.QUARTER)
|
||||
score.add(Tone.from_string("G4", system="western"), Duration.HALF)
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> score.total_beats
|
||||
4.0
|
||||
>>> score.measures
|
||||
1.0
|
||||
>>> score.duration_ms
|
||||
2000.0
|
||||
|
||||
Rests
|
||||
~~~~~
|
||||
|
||||
Add silence with ``.rest()``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=120)
|
||||
score.add(Tone.from_string("C4", system="western"), Duration.HALF)
|
||||
score.rest(Duration.HALF)
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> score.measures
|
||||
1.0
|
||||
|
||||
Chords
|
||||
~~~~~~
|
||||
|
||||
Chords work just like tones — pass any ``Chord`` object:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score, Duration, Key
|
||||
|
||||
key = Key("C", "major")
|
||||
chords = key.progression("I", "V", "vi", "IV")
|
||||
|
||||
score = Score("4/4", bpm=120)
|
||||
for chord in chords:
|
||||
score.add(chord, Duration.WHOLE)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/chords_basic.wav" type="audio/wav"></audio>
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> score.measures
|
||||
4.0
|
||||
>>> score.duration_ms
|
||||
8000.0
|
||||
|
||||
Compound Time
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
12/8 is a compound meter — 12 eighth notes per bar grouped in four
|
||||
groups of three. Each group feels like one "big beat":
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score, Duration, Key
|
||||
|
||||
key = Key("A", "minor")
|
||||
chords = key.random_progression(4)
|
||||
|
||||
score = Score("12/8", bpm=120)
|
||||
for c in chords:
|
||||
score.add(c, Duration.DOTTED_HALF)
|
||||
score.add(c, Duration.DOTTED_HALF)
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> score.measures
|
||||
4.0
|
||||
|
||||
Parts
|
||||
-----
|
||||
|
||||
Parts are like tracks in a DAW. Each one has its own instrument sound
|
||||
(synth waveform + envelope), its own volume level, and its own effects
|
||||
chain. When you call ``play_score()``, all the parts get mixed together
|
||||
into a single audio stream -- just like hitting play in Logic or
|
||||
Ableton. You might have a pad part holding down chords, a lead part
|
||||
playing a melody, and a bass part holding down the low end. Each one
|
||||
is independent: different synth, different envelope, different effects.
|
||||
|
||||
The ``Part`` class lets you layer multiple instrument voices -- each with
|
||||
its own synth waveform, ADSR envelope, and volume level. Create parts
|
||||
with ``Score.part()``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score, Key, Duration, Chord
|
||||
from pytheory.play import play_score
|
||||
|
||||
score = Score("4/4", bpm=140)
|
||||
|
||||
chords = score.part("chords", synth="sine", envelope="pad", volume=0.35)
|
||||
lead = score.part("lead", synth="saw", envelope="pluck", volume=0.5)
|
||||
bass = score.part("bass", synth="triangle", envelope="pluck", volume=0.45)
|
||||
|
||||
Adding Notes to Parts
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Parts accept note strings directly — no need to wrap in
|
||||
``Tone.from_string()``. ``.add()`` and ``.rest()`` return self for
|
||||
fluent chaining:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead.add("E5", Duration.QUARTER).add("D5", Duration.EIGHTH).rest(Duration.EIGHTH)
|
||||
|
||||
Raw float beats work too — useful for swing and tuplets:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead.add("C5", 0.67).add("B4", 0.33).add("A4", 1.0)
|
||||
|
||||
Chords and Tone objects work the same way:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
for chord in Key("A", "minor").progression("i", "iv", "V", "i"):
|
||||
chords.add(chord, Duration.WHOLE)
|
||||
|
||||
for note in ["A2", "C3", "E3", "A2", "D2", "F2", "A2", "D2"]:
|
||||
bass.add(note, Duration.QUARTER)
|
||||
|
||||
Polyphonic Hold
|
||||
---------------
|
||||
|
||||
``Part.hold()`` adds a note without advancing the beat position —
|
||||
the next note starts at the *same* time. This enables polyphonic
|
||||
overlap on a single part: piano sustain, sitar drone under melody,
|
||||
guitar strum texture.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
piano = score.part("piano", instrument="piano", reverb=0.3)
|
||||
|
||||
# Hold a C major chord for 8 beats
|
||||
piano.hold("C3", Duration.WHOLE * 2, velocity=60)
|
||||
piano.hold("E3", Duration.WHOLE * 2, velocity=55)
|
||||
piano.hold("G3", Duration.WHOLE * 2, velocity=55)
|
||||
|
||||
# Melody plays simultaneously on top
|
||||
for n in ["E4", "G4", "C5", "G4", "E4", "D4", "C4", "E4"]:
|
||||
piano.add(n, Duration.QUARTER, velocity=80)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/piano_hold.wav" type="audio/wav"></audio>
|
||||
|
||||
Arpeggiator
|
||||
------------
|
||||
|
||||
An arpeggiator takes a chord and plays its notes one at a time, in a
|
||||
pattern, automatically. You hold down a chord and it ripples through
|
||||
the notes -- up, down, up-and-down, random. It's one of the most
|
||||
iconic sounds in electronic music. The bubbly bass lines of acid house,
|
||||
the cascading runs of 80s synth pop (think "Jump" or "Take On Me"),
|
||||
the hypnotic patterns of trance -- all arpeggiators. It turns a simple
|
||||
three-note chord into a rhythmic, melodic engine.
|
||||
|
||||
``Part.arpeggio()`` takes a chord and sequences through its notes
|
||||
automatically -- like a hardware arpeggiator on a synth:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead = score.part(
|
||||
"lead",
|
||||
synth="saw",
|
||||
legato=True,
|
||||
glide=0.03,
|
||||
distortion=0.8,
|
||||
lowpass=1000,
|
||||
lowpass_q=5.0,
|
||||
)
|
||||
lead.arpeggio(
|
||||
Chord.from_symbol("Cm"),
|
||||
bars=2,
|
||||
pattern="up",
|
||||
division=Duration.SIXTEENTH,
|
||||
octaves=2,
|
||||
)
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``chord``: A Chord object or string like ``"Am"``.
|
||||
- ``bars``: Number of bars to fill (default 1).
|
||||
- ``pattern``: ``"up"``, ``"down"``, ``"updown"``, ``"downup"``, ``"random"``.
|
||||
- ``division``: Step length (default ``Duration.SIXTEENTH``).
|
||||
- ``octaves``: Octave span (default 1). With 2, the pattern repeats one octave up.
|
||||
|
||||
Chain arpeggios through a progression:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
for sym in ["Cm", "Fm", "Abm", "Gm"]:
|
||||
lead.arpeggio(sym, bars=2, pattern="updown", octaves=2)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/arpeggio.wav" type="audio/wav"></audio>
|
||||
|
||||
Combined with legato, glide, distortion, and a resonant lowpass, this
|
||||
produces the classic acid/trance arpeggiator sound.
|
||||
|
||||
Legato and Glide
|
||||
----------------
|
||||
|
||||
Normally, every note you play has its own life cycle -- the sound
|
||||
attacks, sustains, and releases before the next note begins. You hear
|
||||
each note as a separate event. Legato changes that. The Italian word
|
||||
means "tied together," and that's exactly what it does: the envelope
|
||||
flows continuously from one note to the next with no retriggering. The
|
||||
pitch changes, but the sound never dies and restarts.
|
||||
|
||||
Glide (also called portamento) takes this further. Instead of the pitch
|
||||
jumping instantly from one note to the next, it *slides* -- a smooth,
|
||||
continuous pitch sweep. This is THE sound of the Roland TB-303, the
|
||||
little silver box that accidentally invented acid house. A saw wave
|
||||
with legato, glide, a resonant lowpass filter, and some distortion --
|
||||
that's the entire genre right there.
|
||||
|
||||
By default, each note gets its own attack/release envelope. ``legato=True``
|
||||
renders the entire part as one continuous waveform -- the pitch changes
|
||||
at note boundaries but the envelope flows unbroken. Add ``glide`` for
|
||||
portamento (pitch slides between notes):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
acid = score.part(
|
||||
"acid",
|
||||
synth="saw",
|
||||
legato=True,
|
||||
glide=0.04,
|
||||
lowpass=3000,
|
||||
lowpass_q=6.0,
|
||||
distortion=0.3,
|
||||
)
|
||||
acid.add("C2", 0.25).add("C3", 0.25).add("G2", 0.25).add("C2", 0.25)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/legato_glide.wav" type="audio/wav"></audio>
|
||||
|
||||
- ``legato``: If True, no envelope retrigger between notes (default False).
|
||||
- ``glide``: Portamento time in seconds (default 0, instant).
|
||||
0.03--0.05 = quick 303 slide, 0.1--0.2 = slow glide.
|
||||
|
||||
Complete Example
|
||||
----------------
|
||||
|
||||
A full multi-part arrangement — rock beat with piano chords, saw
|
||||
lead, and filtered bass:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Score, Key, Duration, Chord
|
||||
from pytheory.play import play_score
|
||||
|
||||
score = Score("4/4", bpm=120)
|
||||
score.drums("rock", repeats=8, fill="rock", fill_every=4)
|
||||
|
||||
# Piano chords with reverb
|
||||
piano = score.part("piano", instrument="piano", volume=0.4, reverb=0.3)
|
||||
|
||||
# Saw lead with delay
|
||||
lead = score.part(
|
||||
"lead", synth="saw", envelope="pluck", volume=0.4,
|
||||
delay=0.2, delay_time=0.33, reverb=0.2, lowpass=3000,
|
||||
)
|
||||
|
||||
# Filtered bass
|
||||
bass = score.part("bass", synth="triangle", envelope="pluck",
|
||||
volume=0.45, lowpass=1200)
|
||||
|
||||
for chord in Key("G", "major").progression("I", "V", "vi", "IV") * 2:
|
||||
piano.add(chord, Duration.WHOLE)
|
||||
|
||||
lead.add("D5", 1).add("B4", 0.5).add("D5", 0.5)
|
||||
lead.add("G5", 1).add("E5", 1)
|
||||
lead.add("D5", 0.5).add("B4", 0.5).add("A4", 1)
|
||||
lead.add("G4", 2).rest(2)
|
||||
lead.add("D5", 1).add("B4", 0.5).add("D5", 0.5)
|
||||
lead.add("G5", 1).add("A5", 1)
|
||||
lead.add("G5", 0.5).add("E5", 0.5).add("D5", 1)
|
||||
lead.add("B4", 2).rest(2)
|
||||
|
||||
for n in ["G2", "G2", "D2", "D2", "E2", "E2", "C2", "C2"] * 2:
|
||||
bass.add(n, Duration.HALF)
|
||||
|
||||
play_score(score)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/complete_rock.wav" type="audio/wav"></audio>
|
||||
|
||||
Velocity
|
||||
--------
|
||||
|
||||
Real music has dynamics — accents are louder, ghost notes are barely
|
||||
there, phrases crescendo and decrescendo. Every note can have its own
|
||||
velocity (1–127, where 100 is the default):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead.add("C5", Duration.QUARTER, velocity=120) # loud accent
|
||||
lead.add("D5", Duration.QUARTER, velocity=40) # ghost note
|
||||
lead.add("E5", Duration.QUARTER) # default (100)
|
||||
|
||||
The arpeggiator also accepts velocity:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead.arpeggio("Am", bars=2, pattern="up", velocity=80)
|
||||
|
||||
Articulations
|
||||
-------------
|
||||
|
||||
Articulations change *how* a note is played — its attack, duration, and
|
||||
weight. A staccato note is short and bouncy. A marcato note hits hard.
|
||||
A legato note melts into the next one. This is the difference between
|
||||
a melody that sounds like a MIDI file and one that sounds like a
|
||||
musician played it.
|
||||
|
||||
Pass ``articulation=`` to ``Part.add()``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
piano.add("C4", Duration.QUARTER, articulation="staccato") # short, bouncy
|
||||
piano.add("D4", Duration.QUARTER, articulation="legato") # smooth, overlaps
|
||||
piano.add("E4", Duration.QUARTER, articulation="marcato") # heavy accent
|
||||
piano.add("F4", Duration.QUARTER, articulation="tenuto") # held, soft attack
|
||||
piano.add("G4", Duration.QUARTER, articulation="accent") # louder
|
||||
piano.add("C5", Duration.HALF, articulation="fermata") # held longer
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/articulations.wav" type="audio/wav"></audio>
|
||||
|
||||
What each articulation does:
|
||||
|
||||
- **staccato** — plays ~40% of the note duration with a quick fade-out. Short and detached.
|
||||
- **legato** — extends ~15% into the next note. Smooth and connected.
|
||||
- **marcato** — 25% velocity boost + sharper attack. Heavy and accented.
|
||||
- **tenuto** — full duration with a softer attack ramp. Held and deliberate.
|
||||
- **accent** — 20% velocity boost, no duration change.
|
||||
- **fermata** — stretches the note 50% longer.
|
||||
|
||||
Articulations work on ``Part.hold()`` and ``Part.hit()`` too.
|
||||
|
||||
Dynamic Curves
|
||||
--------------
|
||||
|
||||
Real music breathes — phrases get louder, get quieter, swell and
|
||||
recede. Dynamic curves let you shape the velocity across a sequence
|
||||
of notes instead of setting each one manually.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Crescendo: quiet to loud
|
||||
piano.crescendo(["C4","D4","E4","F4","G4","A4","B4","C5"],
|
||||
Duration.QUARTER, start_vel=30, end_vel=110)
|
||||
|
||||
# Decrescendo: loud to quiet
|
||||
piano.decrescendo(["C5","B4","A4","G4","F4","E4","D4","C4"],
|
||||
Duration.QUARTER, start_vel=110, end_vel=30)
|
||||
|
||||
# Swell: up then back down (orchestral < > shape)
|
||||
strings.swell(["C4","D4","E4","F4","G4","F4","E4","D4"],
|
||||
Duration.QUARTER, low_vel=35, peak_vel=110)
|
||||
|
||||
# Custom curve: explicit velocity per note
|
||||
piano.dynamics(["C4","E4","G4","C5"], Duration.QUARTER,
|
||||
velocities=[50, 80, 110, 90])
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/dynamics.wav" type="audio/wav"></audio>
|
||||
|
||||
Four methods:
|
||||
|
||||
- **crescendo()** — linear velocity ramp from ``start_vel`` to ``end_vel``.
|
||||
- **decrescendo()** — same thing, but typically loud to quiet.
|
||||
- **swell()** — ramps up to the midpoint, then back down. The classic
|
||||
orchestral crescendo-decrescendo.
|
||||
- **dynamics()** — the general form. Pass a ``(start, end)`` tuple for
|
||||
a linear ramp, or a list of velocities for a custom curve.
|
||||
|
||||
All four accept ``articulation=`` to combine dynamics with articulations:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Staccato crescendo — bouncy notes getting louder
|
||||
piano.crescendo(["C4","E4","G4","C5","E5","G5","C6","E6"],
|
||||
Duration.EIGHTH, start_vel=40, end_vel=110,
|
||||
articulation="staccato")
|
||||
|
||||
Part.hit() — Manual Drum Placement
|
||||
-----------------------------------
|
||||
|
||||
The pattern system is great for grooves, but sometimes you want to
|
||||
place individual drum hits with full control — articulations, effects,
|
||||
and all. ``Part.hit()`` puts a drum sound into a Part's note stream:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import DrumSound
|
||||
|
||||
kit = score.part("kit", synth="sine", volume=0.7)
|
||||
|
||||
kit.hit(DrumSound.KICK, Duration.QUARTER, articulation="accent")
|
||||
kit.hit(DrumSound.CLOSED_HAT, Duration.EIGHTH, velocity=60)
|
||||
kit.hit(DrumSound.SNARE, Duration.EIGHTH, articulation="marcato")
|
||||
|
||||
Because hits go through the normal Part renderer, they get humanize,
|
||||
effects, and articulations for free. Use this for custom beats that
|
||||
don't fit a preset pattern, or for one-shot accent hits layered on
|
||||
top of a pattern.
|
||||
|
||||
Rudiments — Flam, Diddle, Cheese
|
||||
---------------------------------
|
||||
|
||||
Marching percussion rudiments as methods on any Part:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import DrumSound
|
||||
|
||||
p = score.part("snares", synth="sine", volume=0.9)
|
||||
|
||||
# Flam: grace note + main hit (gap controls tightness)
|
||||
p.flam(DrumSound.MARCH_SNARE, Duration.QUARTER, velocity=120)
|
||||
|
||||
# Diddle: two equal strokes in one note duration
|
||||
p.diddle(DrumSound.MARCH_SNARE, Duration.EIGHTH, velocity=60)
|
||||
|
||||
# Cheese: flam + diddle combined
|
||||
p.cheese(DrumSound.MARCH_SNARE, Duration.QUARTER, velocity=120)
|
||||
|
||||
Ensemble
|
||||
--------
|
||||
|
||||
Any Part can be rendered as an ensemble — multiple players with
|
||||
per-player timing tendencies and micro pitch drift:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# 8-player snare line
|
||||
snares = score.part("snares", synth="sine", volume=0.9, ensemble=8)
|
||||
|
||||
# 20-player string section
|
||||
strings = score.part("strings", instrument="string_ensemble", ensemble=20)
|
||||
|
||||
# Single player (default)
|
||||
solo = score.part("solo", instrument="violin")
|
||||
|
||||
Each ensemble voice gets a consistent timing personality (some rush,
|
||||
some drag) plus small per-note wobble, and slightly different tuning.
|
||||
The result sounds like a real section — together but alive.
|
||||
|
||||
Solo snare, then an 8-player section plays the same pattern:
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/ensemble.wav" type="audio/wav"></audio>
|
||||
|
||||
Swing and Groove
|
||||
----------------
|
||||
|
||||
Perfectly quantized music sounds robotic. Swing delays every other
|
||||
subdivision by a percentage, giving the rhythm a human, shuffled feel.
|
||||
Jazz swings hard. Bossa nova swings gently. Hip hop has its own pocket.
|
||||
|
||||
Set swing on the Score (applies to everything) or per-Part:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Triplet swing — lazy jazz feel
|
||||
score = Score("4/4", bpm=100, swing=0.55)
|
||||
|
||||
# Per-part override — the lead swings harder than the bass
|
||||
lead = score.part("lead", synth="saw", swing=0.6)
|
||||
bass = score.part("bass", synth="sine", swing=0.4)
|
||||
|
||||
Swing values:
|
||||
|
||||
- **0.0** = perfectly straight (default)
|
||||
- **0.3** = subtle shuffle (pop, R&B)
|
||||
- **0.5** = triplet feel (jazz, blues)
|
||||
- **0.67** = hard swing (bebop)
|
||||
|
||||
Tempo Changes
|
||||
-------------
|
||||
|
||||
Real music doesn't stay at one tempo. Songs speed up for energy,
|
||||
slow down for endings, and sometimes shift abruptly. Use
|
||||
``score.set_tempo()`` to change BPM at the current position:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=90)
|
||||
|
||||
# Verse: slow and moody
|
||||
lead.add("D5", Duration.WHOLE)
|
||||
lead.add("F5", Duration.WHOLE)
|
||||
|
||||
# Chorus: speeds up
|
||||
score.set_tempo(110)
|
||||
lead.add("A5", Duration.WHOLE)
|
||||
lead.add("D6", Duration.WHOLE)
|
||||
|
||||
# Outro: slows way down
|
||||
score.set_tempo(70)
|
||||
lead.add("D5", Duration.WHOLE)
|
||||
|
||||
The tempo map engine handles the math — beat positions are converted
|
||||
to sample positions accounting for every tempo change.
|
||||
|
||||
Fades
|
||||
-----
|
||||
|
||||
``Part.fade_in()`` and ``Part.fade_out()`` ramp the volume over a
|
||||
number of bars. They work by generating automation points, so they
|
||||
integrate naturally with the rest of the automation system:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
pad = score.part(
|
||||
"pad",
|
||||
synth="supersaw",
|
||||
envelope="pad",
|
||||
volume=0.3,
|
||||
reverb=0.5,
|
||||
)
|
||||
|
||||
# Fade in over first 4 bars
|
||||
pad.fade_in(bars=4)
|
||||
for chord in chords:
|
||||
pad.add(chord, Duration.WHOLE)
|
||||
|
||||
# Fade out over last 2 bars
|
||||
pad.fade_out(bars=2)
|
||||
pad.rest(Duration.WHOLE)
|
||||
pad.rest(Duration.WHOLE)
|
||||
|
||||
Parameter Ramps
|
||||
---------------
|
||||
|
||||
Fades only control volume. ``Part.ramp()`` smoothly sweeps *any*
|
||||
parameter from its current value to a target — filters, reverb,
|
||||
distortion, chorus, delay, anything ``.set()`` accepts. This is how
|
||||
you build filter sweeps, gradual effect sends, and EDM buildups.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead = score.part("lead", synth="saw", lowpass=200, lowpass_q=3.0)
|
||||
|
||||
# Open the filter over 8 bars
|
||||
lead.ramp(over=Duration.WHOLE * 8, lowpass=8000)
|
||||
|
||||
# Ramp multiple params at once
|
||||
pad.ramp(over=Duration.WHOLE * 4, reverb=0.5, chorus=0.3)
|
||||
|
||||
# Close the filter with distortion fading in
|
||||
lead.ramp(over=Duration.WHOLE * 4, lowpass=400, distortion=0.5)
|
||||
|
||||
Four interpolation curves:
|
||||
|
||||
- **linear** — constant rate of change (default).
|
||||
- **ease_in** — starts slow, accelerates. Good for buildups.
|
||||
- **ease_out** — starts fast, decelerates. Good for releases.
|
||||
- **ease_in_out** — slow at both ends. Smooth and natural.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# EDM buildup: slow start, accelerating filter sweep
|
||||
lead.ramp(over=Duration.WHOLE * 8, curve="ease_in", lowpass=8000)
|
||||
|
||||
# Smooth reverb wash fading in and settling
|
||||
pad.ramp(over=Duration.WHOLE * 4, curve="ease_in_out", reverb=0.6)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="../_static/audio/filter_ramp.wav" type="audio/wav"></audio>
|
||||
|
||||
``ramp()`` generates automation points every quarter-beat by default.
|
||||
Set ``resolution=0.125`` for smoother curves (every 32nd note), or
|
||||
``resolution=1.0`` for lighter automation (every beat).
|
||||
|
||||
Combine with ``lfo()`` for cyclic modulation and ``ramp()`` for
|
||||
one-shot sweeps — together they cover the full range of parameter
|
||||
automation.
|
||||
|
||||
Humanize
|
||||
--------
|
||||
|
||||
Perfectly quantized music sounds like a machine made it — because it
|
||||
did. Real musicians are never exactly on the beat. Their timing drifts
|
||||
by a few milliseconds, their velocity varies from note to note. These
|
||||
imperfections are what make music feel *alive*.
|
||||
|
||||
The ``humanize`` parameter adds random micro-variations in both timing
|
||||
and velocity at render time. The score data stays clean and
|
||||
deterministic — the randomness is only applied during playback.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Subtle — like a very tight session player
|
||||
lead = score.part("lead", synth="saw", humanize=0.1)
|
||||
|
||||
# Natural — like a good live take
|
||||
rhodes = score.part("rhodes", synth="fm", humanize=0.3)
|
||||
|
||||
# Loose — like a late-night jam after a few drinks
|
||||
bass = score.part("bass", synth="sine", humanize=0.5)
|
||||
|
||||
Humanize values:
|
||||
|
||||
- **0.0** = perfectly quantized (default)
|
||||
- **0.1** = subtle, studio-tight
|
||||
- **0.2–0.3** = natural, like a real player
|
||||
- **0.4–0.5** = loose, relaxed, human
|
||||
- **0.6+** = sloppy (sometimes that's what you want)
|
||||
|
||||
Combine with swing for the most realistic feel:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=95, swing=0.45)
|
||||
lead = score.part(
|
||||
"lead",
|
||||
synth="saw",
|
||||
envelope="pluck",
|
||||
humanize=0.3,
|
||||
delay=0.2,
|
||||
reverb=0.25,
|
||||
)
|
||||
|
||||
Song Structure
|
||||
--------------
|
||||
|
||||
Real songs aren't one long stream of notes — they have verses,
|
||||
choruses, bridges, drops. The section system lets you name blocks
|
||||
of your arrangement, then repeat them without rewriting everything.
|
||||
|
||||
This is how actual songwriting works: you write a verse, you write
|
||||
a chorus, then you arrange them — verse, verse, chorus, verse,
|
||||
chorus, chorus, outro. The sections are the building blocks;
|
||||
the arrangement is the order you play them in.
|
||||
|
||||
Define sections with ``score.section()`` and repeat them with
|
||||
``score.repeat()``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=124)
|
||||
score.drums("house", repeats=16)
|
||||
|
||||
pad = score.part("pad", synth="supersaw", envelope="pad")
|
||||
lead = score.part("lead", synth="saw", envelope="pluck")
|
||||
bass = score.part("bass", synth="sine", lowpass=300)
|
||||
|
||||
# ── Define the verse ──
|
||||
score.section("verse")
|
||||
for sym in ["Cm", "Ab", "Eb", "Bb"]:
|
||||
pad.add(Chord.from_symbol(sym), Duration.WHOLE)
|
||||
lead.add("C5", 1).add("Eb5", 1).rest(2)
|
||||
for n in ["C1", "C1", "Ab0", "Ab0", "Eb1", "Eb1", "Bb0", "Bb0"]:
|
||||
bass.add(n, Duration.HALF)
|
||||
|
||||
# ── Define the chorus ──
|
||||
score.section("chorus")
|
||||
lead.set(lowpass=5000, reverb=0.3)
|
||||
for sym in ["Cm", "Fm", "Ab", "Gm"]:
|
||||
pad.add(Chord.from_symbol(sym), Duration.WHOLE)
|
||||
lead.add("C6", 1).add("Bb5", 1).add("G5", 1).rest(1)
|
||||
for n in ["C1", "C1", "F1", "F1", "Ab0", "Ab0", "G1", "G1"]:
|
||||
bass.add(n, Duration.HALF)
|
||||
score.end_section()
|
||||
|
||||
# ── Arrange: verse, chorus, verse, chorus, chorus ──
|
||||
score.repeat("verse")
|
||||
score.repeat("chorus")
|
||||
score.repeat("verse")
|
||||
score.repeat("chorus", times=2)
|
||||
|
||||
Use any names you want — ``"intro"``, ``"verse"``, ``"chorus"``,
|
||||
``"bridge"``, ``"drop"``, ``"breakdown"``, ``"outro"``, or anything
|
||||
that makes sense for your song. The names are just labels.
|
||||
|
||||
Guitar Strumming
|
||||
----------------
|
||||
|
||||
Any part with a fretboard can strum chords using real fingering
|
||||
positions. The ``strum()`` method looks up the chord on the fretboard,
|
||||
gets the correct voicing, and plays all strings as a chord.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import Fretboard
|
||||
|
||||
guitar = score.part("guitar", instrument="acoustic_guitar",
|
||||
fretboard=Fretboard.guitar())
|
||||
|
||||
guitar.strum("Am", Duration.HALF, direction="down")
|
||||
guitar.strum("G", Duration.HALF, direction="up")
|
||||
guitar.strum("F", Duration.WHOLE)
|
||||
|
||||
Works with any fretboard instrument — guitar, ukulele, banjo, mandolin.
|
||||
Works with any guitar preset — clean, crunch, distorted, orange, metal.
|
||||
|
||||
Pitch Bends
|
||||
-----------
|
||||
|
||||
Bend a note's pitch up or down over its duration. Essential for guitar
|
||||
bends, sitar meends, trombone slides, and vocal-style expression.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Guitar bend: D up to E (2 semitones)
|
||||
guitar.add("D4", Duration.HALF, bend=2, bend_type="smooth")
|
||||
|
||||
# Release bend: E back down to D
|
||||
guitar.add("E4", Duration.HALF, bend=-2)
|
||||
|
||||
# Blues curl: hold then bend at the end
|
||||
guitar.add("C4", Duration.HALF, bend=1, bend_type="late")
|
||||
|
||||
Three bend types:
|
||||
|
||||
- ``"smooth"`` — logarithmic (default). Perceptually even pitch change.
|
||||
- ``"linear"`` — linear frequency interpolation. Mechanical/synth feel.
|
||||
- ``"late"`` — holds the starting pitch for 60%, bends in the last 40%.
|
||||
The classic blues "curl."
|
||||
|
||||
Rolls
|
||||
-----
|
||||
|
||||
Rapid repeated notes with a velocity ramp — perfect for timpani
|
||||
rolls, snare rolls, tremolo on any instrument. The velocity ramps
|
||||
from ``velocity_start`` to ``velocity_end`` for crescendo or
|
||||
decrescendo effects.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Timpani crescendo roll
|
||||
timp = score.part("timp", instrument="timpani")
|
||||
timp.roll("C3", Duration.WHOLE, velocity_start=20, velocity_end=110)
|
||||
timp.add("C3", Duration.HALF, velocity=127) # big accent
|
||||
|
||||
# Snare roll with 32nd notes
|
||||
snare = score.part("snare", synth="noise", envelope="pluck")
|
||||
snare.roll("C4", Duration.HALF, speed=0.125,
|
||||
velocity_start=40, velocity_end=100)
|
||||
|
||||
# Decrescendo (loud to quiet)
|
||||
timp.roll("G2", Duration.WHOLE, velocity_start=100, velocity_end=30)
|
||||
|
||||
Parameters:
|
||||
|
||||
- ``velocity_start``: Starting velocity (default 40).
|
||||
- ``velocity_end``: Ending velocity (default 100).
|
||||
- ``speed``: Note subdivision (default ``Duration.SIXTEENTH``).
|
||||
Use ``0.125`` for 32nd notes, ``Duration.EIGHTH`` for 8th notes.
|
||||
|
||||
Tuning Systems
|
||||
--------------
|
||||
|
||||
A Score can use any tuning system and temperament:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Baroque harpsichord — meantone tuning, A=415
|
||||
score = Score("4/4", bpm=80, temperament="meantone",
|
||||
reference_pitch=415.0)
|
||||
|
||||
# Indian classical — 22-shruti system
|
||||
score = Score("4/4", bpm=75, system="shruti")
|
||||
|
||||
# Just intonation — pure intervals
|
||||
score = Score("4/4", bpm=90, temperament="just")
|
||||
|
||||
The Score constructor accepts these tuning parameters:
|
||||
|
||||
- ``system``: Musical system name (default ``"western"``). Any system
|
||||
from :doc:`systems` works — ``"indian"``, ``"shruti"``, ``"maqam"``,
|
||||
``"carnatic"``, etc. Note strings in ``Part.add()`` are parsed against
|
||||
this system.
|
||||
- ``temperament``: Tuning temperament — ``"equal"`` (default),
|
||||
``"pythagorean"``, ``"meantone"``, ``"just"``.
|
||||
- ``reference_pitch``: Concert pitch in Hz (default 440.0). Use 415.0
|
||||
for Baroque tuning, 432.0 for "Verdi tuning", etc.
|
||||
|
||||
Custom equal temperaments via the ``TET()`` factory:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import TET
|
||||
|
||||
edo19 = TET(19) # 19-tone equal temperament
|
||||
score = Score("4/4", bpm=100, system=edo19)
|
||||
@@ -0,0 +1,968 @@
|
||||
Synthesizers
|
||||
============
|
||||
|
||||
PyTheory includes 41 built-in waveforms and 10 ADSR envelope presets.
|
||||
Every sound is generated from scratch -- no samples or external audio
|
||||
files needed.
|
||||
|
||||
Here's the beautiful thing about synthesis: all of it comes from math.
|
||||
Sine waves, addition, and shaping. That's the entire foundation. Every
|
||||
legendary synth in history -- the Moog Minimoog, the Sequential Prophet-5,
|
||||
the Yamaha DX7, the Roland Juno-106, the Roland TB-303 -- uses some
|
||||
combination of these building blocks. When you choose a waveform in
|
||||
PyTheory, you're reaching for the same raw materials that defined
|
||||
decades of music. The difference between a Moog bass and a DX7 bell
|
||||
isn't magic; it's which waveforms you start with and how you shape them.
|
||||
|
||||
Classic Waveforms
|
||||
-----------------
|
||||
|
||||
These four are the fundamentals. Every analog synthesizer ever built
|
||||
starts here. If you learn nothing else about synthesis, learn these --
|
||||
they're the primary colors you mix everything else from.
|
||||
|
||||
Sine
|
||||
~~~~
|
||||
|
||||
The purest tone possible. Contains only the fundamental frequency with
|
||||
no harmonics. Sounds smooth, clean, and "electronic." This is the
|
||||
building block of all other waveforms (Fourier's theorem).
|
||||
|
||||
**Use for:** sub bass, clean pads, test tones, blending under other voices.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import play, Synth, Tone
|
||||
|
||||
tone = Tone.from_string("C4", system="western")
|
||||
play(tone, synth=Synth.SINE)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_sine.wav" type="audio/wav"></audio>
|
||||
|
||||
Sawtooth
|
||||
~~~~~~~~
|
||||
|
||||
Contains all harmonics (both odd and even), each at amplitude 1/n.
|
||||
The richest of the classic waveforms — bright, buzzy, and aggressive.
|
||||
Named for its ramp shape.
|
||||
|
||||
**Use for:** leads, brass, pads, anything that needs presence and bite.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
play(tone, synth=Synth.SAW)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_saw.wav" type="audio/wav"></audio>
|
||||
|
||||
Triangle
|
||||
~~~~~~~~
|
||||
|
||||
Contains only odd harmonics, each at amplitude 1/n-squared. Softer and
|
||||
more mellow than sawtooth — somewhere between sine and saw. Often
|
||||
described as "woody" or "hollow."
|
||||
|
||||
**Use for:** flute-like leads, mellow bass, gentle pads.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
play(tone, synth=Synth.TRIANGLE)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_triangle.wav" type="audio/wav"></audio>
|
||||
|
||||
Square
|
||||
~~~~~~
|
||||
|
||||
Contains only odd harmonics, each at amplitude 1/n. Sounds hollow and
|
||||
punchy — the classic chiptune / 8-bit sound. A special case of the
|
||||
pulse wave with a 50% duty cycle.
|
||||
|
||||
**Use for:** chiptune, 8-bit game music, hollow leads, sub-octave bass.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
play(tone, synth=Synth.SQUARE)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_square.wav" type="audio/wav"></audio>
|
||||
|
||||
Extended Waveforms
|
||||
------------------
|
||||
|
||||
These go beyond the basics into territory that defined specific
|
||||
instruments and eras. The pulse wave is the sound of the NES. FM
|
||||
synthesis is the sound of the 1980s. If the classic waveforms are
|
||||
primary colors, these are the specific pigments that painters actually
|
||||
reach for.
|
||||
|
||||
Pulse
|
||||
~~~~~
|
||||
|
||||
A pulse wave with a variable duty cycle. Narrower pulses sound thinner
|
||||
and more nasal. At 50% it equals a square wave; at 10--20% it produces
|
||||
the classic NES-style buzzy tone.
|
||||
|
||||
**Use for:** NES/chiptune sounds, nasal leads, retro textures.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead = score.part("lead", synth="pulse", envelope="pluck")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_pulse.wav" type="audio/wav"></audio>
|
||||
|
||||
FM Synthesis
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Frequency modulation -- one oscillator (the modulator) modulates the
|
||||
frequency of another (the carrier), producing complex inharmonic
|
||||
spectra. This is how the Yamaha DX7 works -- the best-selling
|
||||
synthesizer of all time. Released in 1983, it was suddenly everywhere:
|
||||
the electric piano in every Whitney Houston ballad, the bass in every
|
||||
Depeche Mode track, the bells in a thousand TV jingles. If you heard
|
||||
pop music in the 80s, you heard FM synthesis.
|
||||
|
||||
**Use for:** bells, metallic leads, glassy pads, DX7-style sounds.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
bells = score.part(
|
||||
"bells",
|
||||
synth="fm",
|
||||
envelope="bell",
|
||||
fm_ratio=3.0,
|
||||
fm_index=5.0,
|
||||
volume=0.3,
|
||||
reverb=0.4,
|
||||
)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_fm.wav" type="audio/wav"></audio>
|
||||
|
||||
Noise
|
||||
-----
|
||||
|
||||
White Noise
|
||||
~~~~~~~~~~~
|
||||
|
||||
Equal energy at all frequencies — pure randomness with no pitch.
|
||||
Useful as a texture layer, a percussion source, or a wind/ocean effect.
|
||||
|
||||
**Use for:** snare layers, hi-hats, wind effects, risers, ambient texture.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
texture = score.part(
|
||||
"texture",
|
||||
synth="noise",
|
||||
envelope="pad",
|
||||
volume=0.1,
|
||||
lowpass=2000,
|
||||
)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_noise.wav" type="audio/wav"></audio>
|
||||
|
||||
Ensemble Waveforms
|
||||
------------------
|
||||
|
||||
These all create "bigger" sounds by layering or modulating multiple
|
||||
oscillators. Where a single sawtooth wave sounds like one instrument,
|
||||
these sound like a section -- a string ensemble, a choir, a wall of
|
||||
synths. They're the pad and atmosphere machines, the sounds that fill
|
||||
out a mix and make it feel wide and immersive.
|
||||
|
||||
Supersaw
|
||||
~~~~~~~~
|
||||
|
||||
Seven detuned sawtooth oscillators stacked together. The slight pitch
|
||||
differences create a shimmering, massive wall of sound. This is the
|
||||
Roland JP-8000's gift to the world -- the waveform that launched an
|
||||
entire genre. Every trance anthem from the late 90s and early 2000s,
|
||||
every euphoric EDM drop, every J-pop power chord owes something to the
|
||||
supersaw.
|
||||
|
||||
**Use for:** trance pads, EDM leads, massive chords, anthem hooks.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
pad = score.part(
|
||||
"pad",
|
||||
synth="supersaw",
|
||||
envelope="pad",
|
||||
volume=0.4,
|
||||
chorus=0.3,
|
||||
reverb=0.5,
|
||||
)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_supersaw.wav" type="audio/wav"></audio>
|
||||
|
||||
PWM Slow
|
||||
~~~~~~~~
|
||||
|
||||
Pulse width modulation with a slow LFO. The duty cycle sweeps back and
|
||||
forth, creating a lush, animated pad sound. This is the Roland Juno-106
|
||||
in a nutshell -- arguably the most recorded synth pad sound in history.
|
||||
That warm, slowly evolving, slightly chorused wash you hear in everything
|
||||
from Boards of Canada to Drake? PWM with a slow LFO.
|
||||
|
||||
**Use for:** lush analog pads, slow evolving textures, Juno-style warmth.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
pad = score.part(
|
||||
"pad",
|
||||
synth="pwm_slow",
|
||||
envelope="pad",
|
||||
volume=0.35,
|
||||
reverb=0.4,
|
||||
)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_pwm_slow.wav" type="audio/wav"></audio>
|
||||
|
||||
PWM Fast
|
||||
~~~~~~~~
|
||||
|
||||
Pulse width modulation with a fast LFO. The rapid duty cycle sweep
|
||||
produces a natural chorus/vibrato effect built into the waveform itself.
|
||||
|
||||
**Use for:** animated leads, vibrato textures, movement without effects.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
lead = score.part("lead", synth="pwm_fast", envelope="pluck", volume=0.5)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_pwm_fast.wav" type="audio/wav"></audio>
|
||||
|
||||
ADSR Envelopes
|
||||
--------------
|
||||
|
||||
Here's a question: a piano and an organ can play the exact same note at
|
||||
the exact same frequency. Why do they sound completely different? The
|
||||
answer is the envelope -- the *shape* of the sound over time. A piano
|
||||
hits hard and immediately starts fading. An organ snaps on at full
|
||||
volume and stays there until you lift the key. A violin swells in
|
||||
gradually. The frequency is the same; the envelope is what makes each
|
||||
instrument feel like itself.
|
||||
|
||||
ADSR stands for Attack, Decay, Sustain, Release -- four stages that
|
||||
describe how any sound's volume changes from the moment you press a key
|
||||
to the moment it falls silent. Understanding ADSR is the single most
|
||||
important thing you can learn about synthesis, because it's the
|
||||
difference between a sound that feels like an instrument and a sound
|
||||
that feels like a test tone.
|
||||
|
||||
Raw waveforms click at the start and end of each note. An ADSR envelope
|
||||
shapes the amplitude over time for natural-sounding notes:
|
||||
|
||||
- **Attack** -- how quickly the sound reaches full volume.
|
||||
- **Decay** -- how quickly it drops to the sustain level.
|
||||
- **Sustain** -- the held volume while the note is on.
|
||||
- **Release** -- how quickly it fades to silence after the note ends.
|
||||
|
||||
PyTheory includes 10 presets:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import play, Envelope, Tone
|
||||
|
||||
tone = Tone.from_string("C4", system="western")
|
||||
|
||||
play(tone, envelope=Envelope.PIANO) # Quick attack, natural decay
|
||||
play(tone, envelope=Envelope.PLUCK) # Sharp attack, fast decay
|
||||
play(tone, envelope=Envelope.PAD) # Slow fade in, lush sustain
|
||||
play(tone, envelope=Envelope.ORGAN) # Instant on/off, no shaping
|
||||
play(tone, envelope=Envelope.BELL) # Instant attack, long ring
|
||||
play(tone, envelope=Envelope.STRINGS) # Gradual bow attack
|
||||
play(tone, envelope=Envelope.BOWED) # Bow bite into sustain
|
||||
play(tone, envelope=Envelope.MALLET) # Strike with ringing sustain
|
||||
play(tone, envelope=Envelope.STACCATO) # Short and punchy
|
||||
play(tone, envelope=Envelope.NONE) # Raw waveform, no shaping
|
||||
|
||||
Envelope Descriptions
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
=============== ================================================
|
||||
Name Character
|
||||
=============== ================================================
|
||||
``"piano"`` Quick attack, natural decay -- acoustic piano feel
|
||||
``"pluck"`` Sharp attack, fast decay -- guitar pick, harp
|
||||
``"pad"`` Slow fade in, lush sustain -- strings, synth pads
|
||||
``"organ"`` Instant on/off -- Hammond organ, no shaping
|
||||
``"bell"`` Instant attack, no sustain -- short metallic ring
|
||||
``"strings"`` Gradual bow attack -- orchestral strings, slow
|
||||
``"bowed"`` Bow bite into sustain -- solo strings, brass
|
||||
``"mallet"`` Strike with ringing sustain -- vibraphone, celesta
|
||||
``"staccato"`` Short and punchy -- funk stabs, percussive hits
|
||||
``"none"`` Raw waveform, no amplitude shaping at all
|
||||
=============== ================================================
|
||||
|
||||
Detune
|
||||
------
|
||||
|
||||
Any synth can be fattened with the ``detune`` parameter — it renders
|
||||
three oscillators per note: the center pitch plus one shifted up and
|
||||
one shifted down by the specified number of cents. The slight frequency
|
||||
differences create beating and width, like an analog synth with
|
||||
oscillator drift.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Juno-style analog drift — subtle, warm
|
||||
pad = score.part("pad", synth="saw", detune=15)
|
||||
|
||||
# Trance supersaw territory — wide, shimmery
|
||||
lead = score.part("lead", synth="saw", detune=25)
|
||||
|
||||
# Subtle thickening on a bass
|
||||
bass = score.part("bass", synth="pulse", detune=8)
|
||||
|
||||
# Works on any synth — even FM
|
||||
bells = score.part("bells", synth="fm", detune=12)
|
||||
|
||||
Detune values:
|
||||
|
||||
- **5–10** = subtle thickening (barely noticeable, just warmer)
|
||||
- **12–18** = classic analog drift (Juno, Prophet)
|
||||
- **20–30** = wide and shimmery (trance, EDM)
|
||||
- **40+** = extreme, almost chorus-like
|
||||
|
||||
This is different from the ``chorus`` effect — detune creates
|
||||
additional oscillators at render time (three per note), while chorus
|
||||
processes the audio after rendering with a modulated delay line.
|
||||
Detune is "wider at the source," chorus is "wider after the fact."
|
||||
Stack both for maximum fatness.
|
||||
|
||||
Stereo Placement
|
||||
----------------
|
||||
|
||||
Every part can be placed in the stereo field with ``pan`` and ``spread``.
|
||||
|
||||
**Pan** positions a part left or right. Constant-power panning keeps
|
||||
the perceived loudness even as you move across the field:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
rhythm = score.part("rhythm", synth="saw", pan=-0.7) # left
|
||||
lead = score.part("lead", synth="saw", pan=0.6) # right
|
||||
bass = score.part("bass", synth="sine", pan=0.0) # center
|
||||
hats = score.part("hats", synth="noise", pan=0.3) # slightly right
|
||||
|
||||
Pan values: -1.0 (hard left), 0.0 (center), 1.0 (hard right).
|
||||
|
||||
**Spread** works with ``detune`` — the up-detuned oscillator goes to
|
||||
the right channel and the down-detuned goes to the left, creating
|
||||
stereo width at the source:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Wide pad: detuned + spread across the stereo field
|
||||
pad = score.part(
|
||||
"pad",
|
||||
synth="saw",
|
||||
detune=20,
|
||||
spread=1.0, # full L/R separation of detuned voices
|
||||
reverb=0.4,
|
||||
)
|
||||
|
||||
Spread values: 0.0 (detuned voices stay mono), 1.0 (full L/R split).
|
||||
Stack with pan to offset the center of the spread.
|
||||
|
||||
Reverb is also stereo — the left and right channels get different
|
||||
early reflection patterns, so the reverb tail occupies real space
|
||||
in the stereo field rather than sitting dead center.
|
||||
|
||||
Physical Modeling
|
||||
-----------------
|
||||
|
||||
Three synths go beyond traditional waveform synthesis into physical
|
||||
modeling territory — they simulate how real instruments produce sound.
|
||||
|
||||
Karplus-Strong Pluck
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A burst of noise fed into a short delay line. The delay length sets
|
||||
the pitch, the feedback filter models the string decaying. This is
|
||||
how every physical modeling synth since 1983 does plucked strings.
|
||||
It sounds genuinely like a real guitar, harp, or koto.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
guitar = score.part("guitar", synth="pluck_synth")
|
||||
harp = score.part("harp", instrument="harp") # uses pluck_synth
|
||||
|
||||
Hammond Organ
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Additive synthesis with drawbar harmonics — sine waves at the
|
||||
fundamental plus 2nd, 3rd, 4th, 5th, 6th, and 8th harmonics mixed
|
||||
at musical levels. Warm, round, unmistakably organ.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
organ = score.part("organ", synth="organ_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_organ.wav" type="audio/wav"></audio>
|
||||
|
||||
String Ensemble
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Filtered sawtooth with body resonance formants at ~500 Hz and ~1500 Hz,
|
||||
modeling the way a violin or cello body shapes the sound. Warmer and
|
||||
more "wooden" than a raw saw wave.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
violin = score.part("violin", synth="strings_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_strings.wav" type="audio/wav"></audio>
|
||||
|
||||
Dedicated Instrument Synths
|
||||
--------------------------
|
||||
|
||||
Beyond the classic and physical modeling waveforms, PyTheory includes
|
||||
31 dedicated instrument synths. Each one uses tailored synthesis
|
||||
techniques -- additive harmonics, formant shaping, body resonance
|
||||
modeling, and specialized envelopes -- to capture the character of a
|
||||
specific acoustic instrument. These are the waveforms that bring the
|
||||
total count to 41.
|
||||
|
||||
Piano Synth
|
||||
~~~~~~~~~~~
|
||||
|
||||
Hammer-strike envelope with body resonance and subtle inharmonicity.
|
||||
Models the way a felt hammer excites steel strings inside a wooden
|
||||
soundboard.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
piano = score.part("piano", synth="piano_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_piano.wav" type="audio/wav"></audio>
|
||||
|
||||
Rhodes Electric Piano
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The Fender Rhodes — a rubber-tipped hammer strikes a steel tine
|
||||
next to a tonebar, picked up by an electromagnetic pickup. Warm,
|
||||
bell-like, with a bright metallic attack that mellows into a
|
||||
singing sustain. The sound of jazz clubs, soul, and neo-soul.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
rhodes = score.part("rhodes", synth="rhodes_synth")
|
||||
# Or use the instrument preset (adds tremolo + chorus)
|
||||
rhodes = score.part("rhodes", instrument="electric_piano")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_rhodes.wav" type="audio/wav"></audio>
|
||||
|
||||
Bass Guitar Synth
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
Plucked string model with finger-damped harmonics and low-end warmth.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
bass = score.part("bass", synth="bass_guitar_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_bass_guitar.wav" type="audio/wav"></audio>
|
||||
|
||||
Flute Synth
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Breathy noise excitation through a resonant tube model, with
|
||||
overblowing behavior at higher velocities.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
flute = score.part("flute", synth="flute_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_flute.wav" type="audio/wav"></audio>
|
||||
|
||||
Trumpet Synth
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Brass lip-buzz model with spectral brightness that increases with
|
||||
velocity, plus a characteristic brassy edge from shaped harmonics.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
trumpet = score.part("trumpet", synth="trumpet_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_trumpet.wav" type="audio/wav"></audio>
|
||||
|
||||
Clarinet Synth
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Cylindrical bore model producing mostly odd harmonics, giving the
|
||||
characteristic hollow, woody tone.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
clarinet = score.part("clarinet", synth="clarinet_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_clarinet.wav" type="audio/wav"></audio>
|
||||
|
||||
Oboe Synth
|
||||
~~~~~~~~~~~
|
||||
|
||||
Double-reed model with nasal formant shaping and a buzzy, penetrating
|
||||
timbre.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
oboe = score.part("oboe", synth="oboe_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_oboe.wav" type="audio/wav"></audio>
|
||||
|
||||
Marimba Synth
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Tuned bar model with a soft mallet attack and a warm, resonant decay
|
||||
that emphasizes the fundamental.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
marimba = score.part("marimba", synth="marimba_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_marimba.wav" type="audio/wav"></audio>
|
||||
|
||||
Harpsichord Synth
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
Plucked-string model with a bright, immediate attack and rapid decay
|
||||
-- the characteristic "plink" of a quill plucking a string.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
harpsi = score.part("harpsi", synth="harpsichord_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_harpsichord.wav" type="audio/wav"></audio>
|
||||
|
||||
Cello Synth
|
||||
~~~~~~~~~~~
|
||||
|
||||
Bowed string model with body formants at cello resonance frequencies,
|
||||
producing a rich, warm, sustained tone.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
cello = score.part("cello", synth="cello_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_cello.wav" type="audio/wav"></audio>
|
||||
|
||||
Harp Synth
|
||||
~~~~~~~~~~
|
||||
|
||||
Plucked string with longer sustain and gentle high-frequency rolloff,
|
||||
modeling nylon strings on a resonant frame.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
harp = score.part("harp", synth="harp_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_harp.wav" type="audio/wav"></audio>
|
||||
|
||||
Upright Bass Synth
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Pizzicato double bass with woody body resonance and a thumpy low end.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
bass = score.part("bass", synth="upright_bass_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_upright_bass.wav" type="audio/wav"></audio>
|
||||
|
||||
Acoustic Guitar Synth
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Steel-string model with pick transient, body resonance, and natural
|
||||
string decay.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
guitar = score.part("guitar", synth="acoustic_guitar_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_acoustic_guitar.wav" type="audio/wav"></audio>
|
||||
|
||||
Electric Guitar Synth
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Magnetic pickup model with brighter harmonics and less body resonance
|
||||
than the acoustic, ready for effects processing.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
eguitar = score.part("eguitar", synth="electric_guitar_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_electric_guitar.wav" type="audio/wav"></audio>
|
||||
|
||||
Sitar Synth
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Sympathetic string resonance with the characteristic buzzy "jawari"
|
||||
bridge, producing a shimmering, metallic sustain.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
sitar = score.part("sitar", synth="sitar_synth")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_sitar.wav" type="audio/wav"></audio>
|
||||
|
||||
Timpani Synth
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Large kettle drum with definite pitch. Inharmonic membrane modes
|
||||
(1.0, 1.5, 1.99, 2.44), felt mallet attack, copper kettle resonance.
|
||||
Use ``Part.roll()`` for crescendo timpani rolls.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
timp = score.part("timp", synth="timpani_synth")
|
||||
timp.roll("C3", Duration.WHOLE, velocity_start=20, velocity_end=110)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_timpani.wav" type="audio/wav"></audio>
|
||||
|
||||
Saxophone Synth
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Single reed through a conical brass bore. All harmonics with strong
|
||||
mids, reed buzz, and brass body warmth. Four presets: ``saxophone``,
|
||||
``alto_sax``, ``tenor_sax``, ``bari_sax``.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
sax = score.part("sax", instrument="tenor_sax")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_saxophone.wav" type="audio/wav"></audio>
|
||||
|
||||
Pedal Steel Synth
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
The Nashville crying sound — singing harmonics with slow vibrato
|
||||
and long sustain. Pairs naturally with spring reverb.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
steel = score.part("steel", instrument="pedal_steel")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_pedal_steel.wav" type="audio/wav"></audio>
|
||||
|
||||
Theremin Synth
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Pure sine with natural hand wobble — the eerie sci-fi sound.
|
||||
Best used with legato and glide for continuous pitch.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
theremin = score.part("theremin", instrument="theremin")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_theremin.wav" type="audio/wav"></audio>
|
||||
|
||||
Kalimba Synth
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Metal tines on a wooden body. Bright, bell-like attack with
|
||||
inharmonic overtones (modes at 1x, 2.92x, 5.4x).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
kalimba = score.part("kalimba", instrument="kalimba")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_kalimba.wav" type="audio/wav"></audio>
|
||||
|
||||
Steel Drum Synth
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Hammered metal pan with bright, ringing, tropical character.
|
||||
Inharmonic partials at 2.0x, 3.01x, 4.1x, 5.3x.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
pan = score.part("pan", instrument="steel_drum")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_steel_drum.wav" type="audio/wav"></audio>
|
||||
|
||||
Accordion Synth
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Musette-tuned doubled reeds — two slightly detuned reed sets
|
||||
create natural beating. Bellows pressure swell modulates amplitude.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
acc = score.part("acc", instrument="accordion")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_accordion.wav" type="audio/wav"></audio>
|
||||
|
||||
Didgeridoo Synth
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Deep cylindrical drone with shifting formant overtones. The
|
||||
overtone singing effect sweeps a resonant peak between 500-1500Hz.
|
||||
Best with cave reverb.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
didg = score.part("didg", instrument="didgeridoo")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_didgeridoo.wav" type="audio/wav"></audio>
|
||||
|
||||
Bagpipe Synth
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Bright chanter reed with constant bag pressure. All harmonics
|
||||
peaked around 3-7 (the piercing brightness). No dynamics — always ff.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
pipes = score.part("pipes", instrument="bagpipe")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_bagpipe.wav" type="audio/wav"></audio>
|
||||
|
||||
Banjo Synth
|
||||
~~~~~~~~~~~
|
||||
|
||||
Steel strings on a drum-head membrane body. The membrane gives
|
||||
nasal, ringy resonance with faster decay than guitar.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
banjo = score.part("banjo", instrument="banjo")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_banjo.wav" type="audio/wav"></audio>
|
||||
|
||||
Mandolin Synth
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Paired steel strings in 4 courses — natural chorus from the
|
||||
doubled unison strings. Bright, ringing, fast attack.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
mando = score.part("mando", instrument="mandolin")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_mandolin.wav" type="audio/wav"></audio>
|
||||
|
||||
Ukulele Synth
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Nylon strings on a small body. Mid-heavy resonance (no deep bass),
|
||||
softer attack than guitar, shorter sustain.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
uke = score.part("uke", instrument="ukulele")
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_ukulele.wav" type="audio/wav"></audio>
|
||||
|
||||
Granular Synth
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Grain cloud synthesis — chops a source waveform into tiny overlapping
|
||||
grains (10-200ms), each windowed and optionally pitch/time scattered.
|
||||
Creates textures impossible with other synthesis: frozen tones,
|
||||
shimmering clouds, evolving pads, glitchy stutters.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Atmospheric granular pad
|
||||
pad = score.part("pad", instrument="granular_pad")
|
||||
|
||||
# Granular with filter envelope sweep + resonance
|
||||
texture = score.part("texture", synth="granular_synth", envelope="pad",
|
||||
filter_amount=4000, filter_attack=0.5,
|
||||
filter_decay=1.5, filter_sustain=0.3,
|
||||
lowpass=600, lowpass_q=3.0,
|
||||
reverb=0.5, reverb_type="taj_mahal")
|
||||
|
||||
Parameters (passed as synth kwargs):
|
||||
|
||||
- ``grain_size``: Duration per grain in seconds (default 0.04).
|
||||
- ``density``: Grains per second (default 50). Higher = denser cloud.
|
||||
- ``scatter``: Random position jitter 0-1 (default 0.5).
|
||||
- ``pitch_var``: Per-grain pitch randomization in cents (default 12).
|
||||
- ``source``: Base waveform — ``"saw"``, ``"sine"``, ``"triangle"``,
|
||||
``"square"``, ``"noise"``.
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.3em 0 0.5em"><source src="../_static/audio/synth_granular.wav" type="audio/wav"></audio>
|
||||
|
||||
Analog Oscillator Drift
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
All waveform synths support the ``analog_drift`` parameter, which adds
|
||||
subtle, slow random pitch variation to each oscillator -- modeling the
|
||||
voltage instability of vintage analog circuits. This is what makes a
|
||||
real Minimoog sound slightly different on every note, and why analog
|
||||
synths feel "alive" compared to their digital counterparts.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Subtle vintage drift
|
||||
pad = score.part("pad", synth="saw", analog_drift=0.1)
|
||||
|
||||
# More pronounced, wobbly analog character
|
||||
lead = score.part("lead", synth="square", analog_drift=0.3)
|
||||
|
||||
Drift values:
|
||||
|
||||
- **0.05--0.1** = subtle warmth (studio-grade analog)
|
||||
- **0.15--0.25** = noticeable drift (vintage gear warming up)
|
||||
- **0.3+** = unstable, wobbly (broken tape machine)
|
||||
|
||||
Instrument Presets
|
||||
------------------
|
||||
|
||||
Instead of choosing synth + envelope + effects manually, use an
|
||||
instrument preset — 60+ predefined combinations that approximate real
|
||||
instruments:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
piano = score.part("piano", instrument="piano")
|
||||
violin = score.part("violin", instrument="violin")
|
||||
guitar = score.part("guitar", instrument="acoustic_guitar")
|
||||
organ = score.part("organ", instrument="organ")
|
||||
bass = score.part("bass", instrument="upright_bass")
|
||||
|
||||
Available instruments:
|
||||
|
||||
**Keys**: piano, electric_piano, organ, harpsichord, celesta, music_box,
|
||||
accordion
|
||||
|
||||
**Strings**: violin, viola, cello, contrabass, string_ensemble
|
||||
|
||||
**Woodwinds**: flute, clarinet, oboe, bassoon, saxophone, alto_sax,
|
||||
tenor_sax, bari_sax
|
||||
|
||||
**Brass**: trumpet, trombone, french_horn, tuba, brass_ensemble
|
||||
|
||||
**Plucked**: acoustic_guitar, electric_guitar, clean_guitar, crunch_guitar,
|
||||
distorted_guitar, orange_crunch, metal_guitar, bass_guitar, upright_bass,
|
||||
harp, sitar, koto, banjo, mandolin, mandola, ukulele
|
||||
|
||||
**World/Exotic**: pedal_steel, theremin, kalimba, steel_drum, didgeridoo,
|
||||
bagpipe
|
||||
|
||||
**Synth**: synth_lead, synth_pad, synth_bass, acid_bass, 808_bass,
|
||||
granular_pad, granular_texture, vocal, choir
|
||||
|
||||
**Percussion**: vibraphone, marimba, xylophone, glockenspiel, tubular_bells,
|
||||
timpani
|
||||
|
||||
Explicit kwargs override preset defaults:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# Piano with extra reverb
|
||||
piano = score.part("piano", instrument="piano", reverb=0.5)
|
||||
|
||||
# Violin panned left
|
||||
violin = score.part("v", instrument="violin", pan=-0.4)
|
||||
|
||||
Choosing Synth and Envelope Combos
|
||||
----------------------------------
|
||||
|
||||
The right combination of synth and envelope defines the character of a
|
||||
voice. This is where you stop thinking about waveforms and start
|
||||
thinking about *instruments*. Here are some starting points:
|
||||
|
||||
- **Funk stabs:** ``saw`` + ``staccato`` -- bright, punchy, rhythmic.
|
||||
- **Jazz keys:** ``fm`` + ``bell`` -- glassy DX7 electric piano.
|
||||
- **Ambient pads:** ``supersaw`` + ``pad`` -- massive, slow-building wash.
|
||||
- **Acid bass:** ``saw`` + ``pluck`` with lowpass and glide -- 303-style.
|
||||
- **Chiptune lead:** ``square`` + ``none`` -- raw 8-bit.
|
||||
- **Film strings:** ``triangle`` + ``strings`` -- soft, bowed, organic.
|
||||
- **Sub bass:** ``sine`` + ``pluck`` with lowpass -- deep and round.
|
||||
- **Retro synth:** ``pwm_slow`` + ``pad`` -- Juno-style analog warmth.
|
||||
- **Percussive hit:** ``noise`` + ``staccato`` with lowpass -- snare layer.
|
||||
- **E-piano ballad:** ``fm`` + ``piano`` with reverb -- intimate jazz club.
|
||||
|
||||
Some practical combos worth memorizing:
|
||||
|
||||
- ``saw`` + ``staccato`` + legato = **acid 303 line.** Add a resonant
|
||||
lowpass and some glide and you're in a warehouse in 1988.
|
||||
- ``fm`` + ``bell`` = **jazz vibraphone.** The glassy, harmonic-rich
|
||||
attack with a long ring-out. Add reverb for a late-night club feel.
|
||||
- ``supersaw`` + ``pad`` = **ambient wash.** The slow attack lets the
|
||||
detuned oscillators build into a shimmering wall. Add chorus and
|
||||
long reverb and you're scoring a nature documentary.
|
||||
- ``saw`` + ``pluck`` = **funk stab.** Short, sharp, bright. The
|
||||
sound of Nile Rodgers' right hand.
|
||||
+247
-73
@@ -1,25 +1,33 @@
|
||||
Musical Systems
|
||||
===============
|
||||
|
||||
PyTheory supports four musical systems, each with its own tone names
|
||||
and scale patterns.
|
||||
PyTheory supports **16 musical systems** — 6 core systems mapped onto
|
||||
12-tone equal temperament, plus 10 microtonal systems with their own
|
||||
native tunings. The core systems let you compare scales across cultures;
|
||||
the microtonal systems go beyond 12-TET into genuinely different pitch
|
||||
universes.
|
||||
|
||||
Western
|
||||
-------
|
||||
|
||||
The standard 12-tone equal temperament system with major/minor scales
|
||||
and all seven modes.
|
||||
The standard 12-tone equal temperament system — the common language of
|
||||
European classical music, American popular music, and virtually all
|
||||
commercially recorded music since the early 20th century. Its
|
||||
major/minor tonality system, seven diatonic modes, and rich harmonic
|
||||
vocabulary form the foundation that most listeners around the world
|
||||
grew up hearing. If you've ever hummed along to a pop song, played
|
||||
piano, or picked up a guitar, you've been working within this system.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
c = TonedScale(tonic="C4")
|
||||
c["major"].note_names
|
||||
# ['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
>>> c = TonedScale(tonic="C4")
|
||||
>>> c["major"].note_names
|
||||
['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
|
||||
c["dorian"].note_names
|
||||
# ['C', 'D', 'D#', 'F', 'G', 'A', 'A#', 'C']
|
||||
>>> c["dorian"].note_names
|
||||
['C', 'D', 'Eb', 'F', 'G', 'A', 'Bb', 'C']
|
||||
|
||||
**Scales:** major, minor, harmonic minor, ionian, dorian, phrygian,
|
||||
lydian, mixolydian, aeolian, locrian, chromatic
|
||||
@@ -27,24 +35,34 @@ lydian, mixolydian, aeolian, locrian, chromatic
|
||||
Indian Classical (Hindustani)
|
||||
-----------------------------
|
||||
|
||||
One of the oldest and most sophisticated musical traditions on earth,
|
||||
`Hindustani classical music <https://en.wikipedia.org/wiki/Hindustani_classical_music>`_
|
||||
dates back over two thousand years to the *Natya Shastra*. Where Western
|
||||
music emphasizes harmony (chords), Indian music emphasizes *raga* —
|
||||
melodic frameworks that evoke specific moods, times of day, and seasons.
|
||||
The sound is meditative, ornamental, and deeply expressive. You'll hear
|
||||
it in classical sitar and tabla performances, Bollywood film scores,
|
||||
and the improvisatory traditions that influenced musicians from
|
||||
George Harrison to John Coltrane.
|
||||
|
||||
The Hindustani system uses **swaras** (Sa, Re, Ga, Ma, Pa, Dha, Ni) and
|
||||
organizes scales into `thaats <https://en.wikipedia.org/wiki/Thaat>`_ — the 10 parent scales from which `ragas <https://en.wikipedia.org/wiki/Raga>`_
|
||||
are derived.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
sa = TonedScale(tonic="Sa4", system="indian")
|
||||
>>> sa = TonedScale(tonic="Sa4", system="indian")
|
||||
|
||||
sa["bilawal"].note_names # = major scale
|
||||
# ['Sa', 'Re', 'Ga', 'Ma', 'Pa', 'Dha', 'Ni', 'Sa']
|
||||
>>> sa["bilawal"].note_names # = major scale
|
||||
['Sa', 'Re', 'Ga', 'Ma', 'Pa', 'Dha', 'Ni', 'Sa']
|
||||
|
||||
sa["bhairav"].note_names # unique to Indian music
|
||||
# ['Sa', 'komal Re', 'Ga', 'Ma', 'Pa', 'komal Dha', 'Ni', 'Sa']
|
||||
>>> sa["bhairav"].note_names # unique to Indian music
|
||||
['Sa', 'komal Re', 'Ga', 'Ma', 'Pa', 'komal Dha', 'Ni', 'Sa']
|
||||
|
||||
sa["todi"].note_names
|
||||
# ['Sa', 'komal Re', 'komal Ga', 'tivra Ma', 'Pa', 'komal Dha', 'Ni', 'Sa']
|
||||
>>> sa["todi"].note_names
|
||||
['Sa', 'komal Re', 'komal Ga', 'tivra Ma', 'Pa', 'komal Dha', 'Ni', 'Sa']
|
||||
|
||||
**Thaats:** bilawal, khamaj, kafi, asavari, bhairavi, kalyan, bhairav,
|
||||
poorvi, marwa, todi
|
||||
@@ -58,6 +76,16 @@ poorvi, marwa, todi
|
||||
Arabic Maqam
|
||||
------------
|
||||
|
||||
The `maqam <https://en.wikipedia.org/wiki/Arabic_maqam>`_ tradition spans
|
||||
the entire Arab world, Turkey, Iran, and Central Asia — a vast musical
|
||||
heritage stretching from medieval Andalusia to modern Cairo. Maqam music
|
||||
is melodically rich, often featuring microtonal inflections, elaborate
|
||||
ornamentation, and a sense of yearning that's unmistakable once you've
|
||||
heard it. Think of the oud-driven classical traditions of Umm Kulthum
|
||||
and Fairuz, the call to prayer, Sufi devotional music, and the
|
||||
underpinning of much Middle Eastern and North African popular music
|
||||
today.
|
||||
|
||||
The Arabic system uses **solfège-based names** (Do, Re, Mi, Fa, Sol, La, Si)
|
||||
and organizes scales into **maqamat** (plural of `maqam <https://en.wikipedia.org/wiki/Maqam>`_).
|
||||
|
||||
@@ -67,20 +95,20 @@ and organizes scales into **maqamat** (plural of `maqam <https://en.wikipedia.or
|
||||
12-tone equal temperament. These scales are the closest 12-TET
|
||||
approximations.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
do = TonedScale(tonic="Do4", system="arabic")
|
||||
>>> do = TonedScale(tonic="Do4", system="arabic")
|
||||
|
||||
do["ajam"].note_names # = major scale
|
||||
# ['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Si', 'Do']
|
||||
>>> do["ajam"].note_names # = major scale
|
||||
['Do', 'Re', 'Mi', 'Fa', 'Sol', 'La', 'Si', 'Do']
|
||||
|
||||
do["hijaz"].note_names # characteristic augmented 2nd
|
||||
# ['Do', 'Reb', 'Mi', 'Fa', 'Sol', 'Solb', 'Sib', 'Do']
|
||||
>>> do["hijaz"].note_names # characteristic augmented 2nd
|
||||
['Do', 'Reb', 'Mi', 'Fa', 'Sol', 'Solb', 'Sib', 'Do']
|
||||
|
||||
do["nikriz"].note_names
|
||||
# ['Do', 'Re', 'Mib', 'Fa#', 'Sol', 'La', 'Sib', 'Do']
|
||||
>>> do["nikriz"].note_names
|
||||
['Do', 'Re', 'Mib', 'Fa#', 'Sol', 'La', 'Sib', 'Do']
|
||||
|
||||
**Maqamat:** ajam, nahawand, kurd, hijaz, nikriz, bayati, rast, saba,
|
||||
sikah, jiharkah
|
||||
@@ -88,26 +116,37 @@ sikah, jiharkah
|
||||
Japanese
|
||||
--------
|
||||
|
||||
Japan's traditional scales have a hauntingly beautiful quality that is
|
||||
immediately recognizable — dark, sparse, and full of tension. The
|
||||
pentatonic scales (especially *hirajoshi* and *in*) use semitone steps
|
||||
that give them an unmistakably Japanese character, distinct from the
|
||||
wider-spaced pentatonics found in Chinese and Western folk music.
|
||||
You'll hear these scales in `koto <https://en.wikipedia.org/wiki/Koto_(instrument)>`_
|
||||
and `shamisen <https://en.wikipedia.org/wiki/Shamisen>`_ music, the
|
||||
`gagaku <https://en.wikipedia.org/wiki/Gagaku>`_ court orchestra,
|
||||
Kabuki and Noh theater, taiko drumming, anime and video game
|
||||
soundtracks, and the compositions of Toru Takemitsu.
|
||||
|
||||
The Japanese system uses Western note names with traditional pentatonic
|
||||
and heptatonic scales from Japanese music.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
c = TonedScale(tonic="C4", system="japanese")
|
||||
>>> c = TonedScale(tonic="C4", system="japanese")
|
||||
|
||||
c["hirajoshi"].note_names # most iconic Japanese scale
|
||||
# ['C', 'D', 'D#', 'G', 'G#', 'C']
|
||||
>>> c["hirajoshi"].note_names # most iconic Japanese scale
|
||||
['C', 'D', 'Eb', 'G', 'Ab', 'C']
|
||||
|
||||
c["in"].note_names # Miyako-bushi, used in koto music
|
||||
# ['C', 'C#', 'F', 'G', 'G#', 'C']
|
||||
>>> c["in"].note_names # Miyako-bushi, used in koto music
|
||||
['C', 'Db', 'F', 'G', 'Ab', 'C']
|
||||
|
||||
c["yo"].note_names # folk music scale
|
||||
# ['C', 'D', 'F', 'G', 'A#', 'C']
|
||||
>>> c["yo"].note_names # folk music scale
|
||||
['C', 'D', 'F', 'G', 'A#', 'C']
|
||||
|
||||
c["ritsu"].note_names # gagaku court music (= Dorian)
|
||||
# ['C', 'D', 'D#', 'F', 'G', 'A', 'A#', 'C']
|
||||
>>> c["ritsu"].note_names # gagaku court music (= Dorian)
|
||||
['C', 'D', 'Eb', 'F', 'G', 'A', 'Bb', 'C']
|
||||
|
||||
**Pentatonic scales:** hirajoshi, in, yo, iwato, kumoi, insen
|
||||
|
||||
@@ -116,6 +155,13 @@ and heptatonic scales from Japanese music.
|
||||
Blues and Pentatonic
|
||||
--------------------
|
||||
|
||||
The blues is America's deepest musical root — born from the African
|
||||
American experience in the Mississippi Delta, it gave rise to jazz,
|
||||
rock and roll, R&B, soul, funk, and hip-hop. The *blue note* (a
|
||||
flattened 5th that bends between major and minor) is the sound of
|
||||
emotional truth in music, from Robert Johnson to B.B. King to
|
||||
Jimi Hendrix.
|
||||
|
||||
The blues system provides the scales foundational to blues, rock, jazz,
|
||||
and folk music worldwide. `Pentatonic scales <https://en.wikipedia.org/wiki/Pentatonic_scale>`_ (5 notes) are the oldest
|
||||
known musical scales, found independently in cultures across every
|
||||
@@ -125,23 +171,23 @@ The `blues scale <https://en.wikipedia.org/wiki/Blues_scale>`_ adds the "`blue n
|
||||
minor pentatonic — this chromatic passing tone is the defining sound
|
||||
of the blues.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
c = TonedScale(tonic="C4", system="blues")
|
||||
>>> c = TonedScale(tonic="C4", system="blues")
|
||||
|
||||
c["major pentatonic"].note_names # the "happy" pentatonic
|
||||
# ['C', 'D', 'E', 'G', 'A', 'C']
|
||||
>>> c["major pentatonic"].note_names # the "happy" pentatonic
|
||||
['C', 'D', 'E', 'G', 'A', 'C']
|
||||
|
||||
c["minor pentatonic"].note_names # the "sad" pentatonic
|
||||
# ['C', 'D#', 'F', 'G', 'A#', 'C']
|
||||
>>> c["minor pentatonic"].note_names # the "sad" pentatonic
|
||||
['C', 'D#', 'F', 'G', 'A#', 'C']
|
||||
|
||||
c["blues"].note_names # minor pentatonic + blue note
|
||||
# ['C', 'D#', 'F', 'F#', 'G', 'A#', 'C']
|
||||
>>> c["blues"].note_names # minor pentatonic + blue note
|
||||
['C', 'Eb', 'F', 'Gb', 'G', 'Bb', 'C']
|
||||
|
||||
c["major blues"].note_names # major pentatonic + blue note
|
||||
# ['C', 'D', 'D#', 'E', 'G', 'A', 'C']
|
||||
>>> c["major blues"].note_names # major pentatonic + blue note
|
||||
['C', 'D', 'Eb', 'E', 'G', 'A', 'C']
|
||||
|
||||
**Pentatonic:** major pentatonic, minor pentatonic
|
||||
|
||||
@@ -154,7 +200,17 @@ minor (Dorian — the jazz minor sound)
|
||||
Javanese Gamelan
|
||||
----------------
|
||||
|
||||
The `gamelan <https://en.wikipedia.org/wiki/Gamelan>`_ system approximates the scales of the Javanese and Balinese
|
||||
`Gamelan <https://en.wikipedia.org/wiki/Gamelan>`_ is the shimmering,
|
||||
interlocking percussion orchestra of Java and Bali — one of the most
|
||||
otherworldly sounds in all of music. Ensembles of bronze metallophones,
|
||||
gongs, drums, and bamboo flutes create waves of resonance that
|
||||
influenced Claude Debussy, Steve Reich, and countless ambient and
|
||||
electronic artists. Each gamelan is tuned uniquely, so no two
|
||||
ensembles sound exactly alike. The music is communal, ceremonial, and
|
||||
deeply tied to Javanese and Balinese culture — it accompanies
|
||||
shadow puppet theater (*wayang*), dance, and religious ritual.
|
||||
|
||||
The gamelan system approximates the scales of the Javanese and Balinese
|
||||
gamelan orchestra in 12-tone equal temperament. True gamelan tuning is
|
||||
unique to each ensemble and does not conform to Western intonation —
|
||||
these are the closest 12-TET approximations.
|
||||
@@ -163,20 +219,20 @@ these are the closest 12-TET approximations.
|
||||
an ethereal, floating quality. `Pelog <https://en.wikipedia.org/wiki/Pelog>`_ is a 7-tone scale with unequal
|
||||
intervals, typically performed using 5-note subsets called *pathet*.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
ji = TonedScale(tonic="ji4", system="gamelan")
|
||||
>>> ji = TonedScale(tonic="ji4", system="gamelan")
|
||||
|
||||
ji["slendro"].note_names # the 5-tone equidistant scale
|
||||
# ['ji', 'ro', 'pat', 'mo', 'pi', 'ji']
|
||||
>>> ji["slendro"].note_names # the 5-tone equidistant scale
|
||||
['ji', 'ro', 'pat', 'mo', 'pi', 'ji']
|
||||
|
||||
ji["pelog"].note_names # full 7-tone pelog
|
||||
# ['ji', 'ro-', 'lu', 'pat', 'mo', 'nem-', 'barang', 'ji']
|
||||
>>> ji["pelog"].note_names # full 7-tone pelog
|
||||
['ji', 'ro-', 'lu', 'pat', 'mo', 'nem-', 'barang', 'ji']
|
||||
|
||||
ji["pelog nem"].note_names # pathet nem subset
|
||||
# ['ji', 'ro-', 'lu', 'pat', 'mo', 'ji']
|
||||
>>> ji["pelog nem"].note_names # pathet nem subset
|
||||
['ji', 'ro-', 'lu', 'pat', 'mo', 'ji']
|
||||
|
||||
**Pentatonic:** slendro, pelog nem, pelog barang, pelog lima
|
||||
|
||||
@@ -195,20 +251,138 @@ Cross-System Comparison
|
||||
Since all systems use 12-tone equal temperament, equivalent scales
|
||||
produce the same pitches:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import TonedScale, Tone
|
||||
|
||||
>>> # These are all the same scale with different names
|
||||
>>> western = TonedScale(tonic="C4")["major"]
|
||||
>>> indian = TonedScale(tonic="Sa4", system="indian")["bilawal"]
|
||||
>>> arabic = TonedScale(tonic="Do4", system="arabic")["ajam"]
|
||||
|
||||
>>> # Same pitches
|
||||
>>> c4 = Tone.from_string("C4", system="western")
|
||||
>>> sa4 = Tone.from_string("Sa4", system="indian")
|
||||
>>> do4 = Tone.from_string("Do4", system="arabic")
|
||||
|
||||
>>> c4.frequency
|
||||
261.6255653005986
|
||||
>>> sa4.frequency
|
||||
261.6255653005986
|
||||
>>> do4.frequency
|
||||
261.6255653005986
|
||||
|
||||
Microtonal Systems
|
||||
------------------
|
||||
|
||||
Beyond the six 12-TET core systems, PyTheory includes 10 microtonal
|
||||
systems that use their own native tunings — more notes per octave,
|
||||
just intonation ratios, or entirely alien pitch structures.
|
||||
|
||||
Shruti (22 tones per octave)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The Indian 22-shruti system divides the octave into 22 unequal steps
|
||||
using just intonation ratios. These microtonal inflections are what
|
||||
give classical Indian music its characteristic expressiveness — pitches
|
||||
that fall "between the cracks" of the piano.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import TonedScale, Tone
|
||||
score = Score("4/4", bpm=75, system="shruti")
|
||||
|
||||
# These are all the same scale with different names
|
||||
western = TonedScale(tonic="C4")["major"]
|
||||
indian = TonedScale(tonic="Sa4", system="indian")["bilawal"]
|
||||
arabic = TonedScale(tonic="Do4", system="arabic")["ajam"]
|
||||
Maqam (24 tones per octave)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
# Same pitches
|
||||
c4 = Tone.from_string("C4", system="western")
|
||||
sa4 = Tone.from_string("Sa4", system="indian")
|
||||
do4 = Tone.from_string("Do4", system="arabic")
|
||||
The Arabic 24-tone system adds Zalzalian quarter-tone intervals
|
||||
(derived from just intonation ratios of 11 and 13) to the standard
|
||||
12 tones. These "neutral" intervals — halfway between major and minor —
|
||||
are the soul of maqam music.
|
||||
|
||||
c4.frequency # 261.63
|
||||
sa4.frequency # 261.63
|
||||
do4.frequency # 261.63
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=90, system="maqam")
|
||||
|
||||
Slendro (5-TET)
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
The Javanese slendro scale — 5 equal divisions of the octave. Each
|
||||
step is 240 cents, wider than any Western interval. Ethereal and
|
||||
floating.
|
||||
|
||||
Pelog (9-TET)
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Approximation of the Javanese pelog tuning as 9 equal divisions of
|
||||
the octave.
|
||||
|
||||
Thai (7-TET)
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Thai classical music divides the octave into 7 equal steps of ~171
|
||||
cents each — every interval is the same size.
|
||||
|
||||
Makam (53-TET)
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Turkish makam music uses 53 equal divisions of the octave — fine
|
||||
enough to approximate virtually any just interval. The system that
|
||||
underlies Ottoman classical music.
|
||||
|
||||
Carnatic (72-TET)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
South Indian Carnatic music theory describes 72 melakarta ragas.
|
||||
The 72-TET system provides enough resolution to represent all the
|
||||
microtonal inflections of Carnatic practice.
|
||||
|
||||
19-TET and 31-TET
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Extended equal temperaments that offer better approximations of
|
||||
just intonation intervals than 12-TET. 19-TET has excellent major
|
||||
thirds; 31-TET closely matches quarter-comma meantone.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=100, system="19-tet")
|
||||
|
||||
Bohlen-Pierce (13 equal divisions of the tritave)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A genuinely alien tuning system — 13 equal divisions of the
|
||||
**tritave** (3:1 ratio) instead of the octave (2:1). No octaves, no
|
||||
fifths, built on 3:5:7 harmonics. Used by experimental composers.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
score = Score("4/4", bpm=100, system="bohlen-pierce")
|
||||
|
||||
The TET() Factory
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
Create any equal temperament on the fly with the ``TET()`` factory:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import TET
|
||||
|
||||
edo19 = TET(19) # 19-tone equal temperament
|
||||
edo31 = TET(31) # 31-tone equal temperament
|
||||
score = Score("4/4", bpm=100, system=edo19)
|
||||
|
||||
Tone names in custom TET systems are integers (0, 1, 2, ..., n-1).
|
||||
|
||||
System.tone() Method
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Any system can create a Tone directly:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import SYSTEMS
|
||||
|
||||
western = SYSTEMS["western"]
|
||||
c4 = western.tone("C", octave=4)
|
||||
|
||||
Music is universal, but every culture hears it differently. These systems are different maps of the same territory -- explore one you've never played in before and see what you find.
|
||||
|
||||
+69
-54
@@ -2,7 +2,11 @@ Music Theory Fundamentals
|
||||
=========================
|
||||
|
||||
This page covers the essential concepts of music theory — the framework
|
||||
behind everything PyTheory does.
|
||||
behind everything PyTheory does. Don't worry if you're new to this:
|
||||
music theory isn't a set of rules you have to memorize, it's a
|
||||
vocabulary for describing what you already hear. Every concept below
|
||||
connects to something you've felt while listening to music — this page
|
||||
just gives it a name.
|
||||
|
||||
Sound and Pitch
|
||||
---------------
|
||||
@@ -50,14 +54,13 @@ cycle almost closes. The tiny gap where it doesn't close perfectly is
|
||||
the `Pythagorean comma <https://en.wikipedia.org/wiki/Pythagorean_comma>`_
|
||||
— the reason we need `temperament <https://en.wikipedia.org/wiki/Musical_temperament>`_.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Tone
|
||||
>>> from pytheory import Tone
|
||||
|
||||
# Walk the circle of fifths — all 12 notes
|
||||
c = Tone.from_string("C4", system="western")
|
||||
[t.name for t in c.circle_of_fifths()]
|
||||
# ['C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#', 'G#', 'D#', 'A#', 'F']
|
||||
>>> c = Tone.from_string("C4", system="western")
|
||||
>>> [t.name for t in c.circle_of_fifths()]
|
||||
['C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#', 'G#', 'D#', 'A#', 'F']
|
||||
|
||||
Other cultures divide the octave differently: Indonesian
|
||||
`gamelan <https://en.wikipedia.org/wiki/Gamelan>`_ uses 5 or 7 unequal
|
||||
@@ -183,17 +186,18 @@ is exactly this pattern. Every "Louie Louie" and every
|
||||
`Bach chorale <https://en.wikipedia.org/wiki/Bach_chorale>`_ follows
|
||||
this basic tonal gravity.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import TonedScale
|
||||
>>> from pytheory import TonedScale
|
||||
|
||||
scale = TonedScale(tonic="C4")["major"]
|
||||
>>> scale = TonedScale(tonic="C4")["major"]
|
||||
|
||||
# The I-IV-V-I progression
|
||||
I = scale.triad(0) # C major — home
|
||||
IV = scale.triad(3) # F major — departure
|
||||
V = scale.triad(4) # G major — tension
|
||||
# I again # C major — resolution
|
||||
>>> scale.triad(0).identify()
|
||||
'C major'
|
||||
>>> scale.triad(3).identify()
|
||||
'F major'
|
||||
>>> scale.triad(4).identify()
|
||||
'G major'
|
||||
|
||||
The Dominant Seventh
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -210,20 +214,24 @@ This combination creates the strongest possible pull toward
|
||||
`resolution <https://en.wikipedia.org/wiki/Resolution_(music)>`_.
|
||||
When you hear V7→I, you feel arrival.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Chord, Tone
|
||||
>>> from pytheory import Chord, Tone
|
||||
|
||||
C4 = Tone.from_string("C4", system="western")
|
||||
G4 = Tone.from_string("G4", system="western")
|
||||
>>> C4 = Tone.from_string("C4", system="western")
|
||||
>>> G4 = Tone.from_string("G4", system="western")
|
||||
|
||||
g7 = Chord([G4, G4+4, G4+7, G4+10]) # G B D F
|
||||
g7.identify() # 'G dominant 7th'
|
||||
g7.tension['has_dominant_function'] # True
|
||||
g7.tension['tritones'] # 1
|
||||
>>> g7 = Chord([G4, G4+4, G4+7, G4+10])
|
||||
>>> g7.identify()
|
||||
'G dominant 7th'
|
||||
>>> g7.tension['has_dominant_function']
|
||||
True
|
||||
>>> g7.tension['tritones']
|
||||
1
|
||||
|
||||
c_major = Chord([C4, C4+4, C4+7]) # C E G
|
||||
c_major.tension['score'] # 0.0 — fully resolved
|
||||
>>> c_major = Chord([C4, C4+4, C4+7])
|
||||
>>> c_major.tension['score']
|
||||
0.0
|
||||
|
||||
Rhythm and Meter
|
||||
----------------
|
||||
@@ -277,43 +285,48 @@ foundation of blues and jazz. Indonesian gamelan embraces
|
||||
`beating <https://en.wikipedia.org/wiki/Beat_(acoustics)>`_ between
|
||||
paired instruments as a core aesthetic.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Chord, Tone
|
||||
>>> from pytheory import Chord, Tone
|
||||
|
||||
C4 = Tone.from_string("C4", system="western")
|
||||
E4 = Tone.from_string("E4", system="western")
|
||||
G4 = Tone.from_string("G4", system="western")
|
||||
>>> C4 = Tone.from_string("C4", system="western")
|
||||
>>> E4 = Tone.from_string("E4", system="western")
|
||||
>>> G4 = Tone.from_string("G4", system="western")
|
||||
|
||||
# The overtone series — the fifth is "built into" every tone
|
||||
C4.overtones(6)
|
||||
# [261.63, 523.25, 784.88, 1046.50, 1308.13, 1569.75]
|
||||
# 3rd harmonic (784.88) ≈ G5 (783.99) — a perfect fifth
|
||||
>>> [round(f, 2) for f in C4.overtones(6)]
|
||||
[261.63, 523.25, 784.88, 1046.5, 1308.13, 1569.75]
|
||||
|
||||
# Consonance: simple frequency ratios score high
|
||||
fifth = Chord([C4, G4]) # 3:2 ratio
|
||||
tritone = Chord([C4, C4 + 6]) # 45:32 ratio
|
||||
fifth.harmony > tritone.harmony # True
|
||||
>>> fifth = Chord([C4, G4])
|
||||
>>> tritone = Chord([C4, C4 + 6])
|
||||
>>> fifth.harmony > tritone.harmony
|
||||
True
|
||||
|
||||
# Dissonance: Plomp-Levelt roughness model
|
||||
# An octave has low roughness (frequencies far apart)
|
||||
# A major 3rd has more roughness (closer frequencies)
|
||||
octave = Chord([C4, C4 + 12])
|
||||
third = Chord([C4, E4])
|
||||
octave.dissonance < third.dissonance # True
|
||||
>>> octave = Chord([C4, C4 + 12])
|
||||
>>> third = Chord([C4, E4])
|
||||
>>> octave.dissonance < third.dissonance
|
||||
True
|
||||
|
||||
# Tension: tritones and dominant function
|
||||
c_major = Chord([C4, E4, G4])
|
||||
c_major.tension['score'] # 0.0 — fully resolved
|
||||
>>> c_major = Chord([C4, E4, G4])
|
||||
>>> c_major.tension['score']
|
||||
0.0
|
||||
|
||||
g7 = Chord([G4, G4+4, G4+7, G4+10]) # G dominant 7th
|
||||
g7.tension['score'] # 0.6 — wants to resolve
|
||||
g7.tension['tritones'] # 1 (B-F)
|
||||
g7.tension['has_dominant_function'] # True
|
||||
>>> g7 = Chord([G4, G4+4, G4+7, G4+10])
|
||||
>>> g7.tension['score']
|
||||
0.6
|
||||
>>> g7.tension['tritones']
|
||||
1
|
||||
>>> g7.tension['has_dominant_function']
|
||||
True
|
||||
|
||||
# Beat frequencies — the pulsing between close pitches
|
||||
g7.beat_frequencies
|
||||
# [(tone_a, tone_b, hz), ...] sorted by frequency
|
||||
From Theory to Composition
|
||||
--------------------------
|
||||
|
||||
Everything on this page — tones, intervals, chords, scales, keys — is
|
||||
the foundation. But PyTheory goes further: you can use these building
|
||||
blocks to compose and play actual music. See the :doc:`sequencing`
|
||||
guide to learn how to arrange multi-part scores with melodies, chord
|
||||
pads, bass lines, drum patterns, and audio effects — all driven by the
|
||||
theory concepts you've just learned.
|
||||
|
||||
Further Reading
|
||||
---------------
|
||||
@@ -328,3 +341,5 @@ Further Reading
|
||||
- `Gamelan <https://en.wikipedia.org/wiki/Gamelan>`_ — Indonesian ensemble music
|
||||
- `Blues <https://en.wikipedia.org/wiki/Blues>`_ — the foundation of American popular music
|
||||
- `Twelve-bar blues <https://en.wikipedia.org/wiki/Twelve-bar_blues>`_ — the most common blues form
|
||||
|
||||
Theory is just a vocabulary for what you already hear. You don't need it to make music -- but once you have the words, you can talk about what you're doing, understand why it works, and find new places to go.
|
||||
|
||||
+191
-46
@@ -40,34 +40,46 @@ Key reference points:
|
||||
Creating Tones
|
||||
--------------
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
from pytheory import Tone
|
||||
>>> from pytheory import Tone
|
||||
|
||||
# From a string (most common)
|
||||
c4 = Tone.from_string("C4")
|
||||
cs4 = Tone.from_string("C#4")
|
||||
>>> c4 = Tone.from_string("C4")
|
||||
>>> cs4 = Tone.from_string("C#4")
|
||||
>>> db4 = Tone.from_string("Db4")
|
||||
|
||||
# Direct construction
|
||||
d = Tone(name="D", octave=3)
|
||||
>>> d = Tone(name="D", octave=3)
|
||||
|
||||
# With a specific system
|
||||
a4 = Tone.from_string("A4", system="western")
|
||||
>>> a4 = Tone.from_string("A4", system="western")
|
||||
|
||||
>>> Tone.from_frequency(440)
|
||||
<Tone A4>
|
||||
>>> Tone.from_frequency(261.63)
|
||||
<Tone C4>
|
||||
|
||||
>>> Tone.from_midi(60)
|
||||
<Tone C4>
|
||||
>>> Tone.from_midi(69)
|
||||
<Tone A4>
|
||||
|
||||
Properties
|
||||
----------
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c4 = Tone.from_string("C4")
|
||||
>>> c4 = Tone.from_string("C4", system="western")
|
||||
>>> c4.name
|
||||
'C'
|
||||
>>> c4.octave
|
||||
4
|
||||
>>> c4.full_name
|
||||
'C4'
|
||||
>>> str(c4)
|
||||
'C4'
|
||||
>>> c4.letter
|
||||
'C'
|
||||
>>> c4.midi
|
||||
60
|
||||
>>> c4.exists
|
||||
True
|
||||
|
||||
Pitch and Frequency
|
||||
-------------------
|
||||
@@ -77,17 +89,17 @@ cycles per second). The relationship between pitch and frequency is
|
||||
**logarithmic**: each octave doubles the frequency, and each semitone
|
||||
multiplies by the 12th root of 2 (~1.05946).
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> a4 = Tone.from_string("A4", system="western")
|
||||
>>> a4.frequency
|
||||
440.0
|
||||
|
||||
>>> Tone.from_string("A3", system="western").frequency
|
||||
220.0 # One octave down = half the frequency
|
||||
220.0
|
||||
|
||||
>>> Tone.from_string("C4", system="western").frequency
|
||||
261.63 # Middle C
|
||||
261.6255653005986
|
||||
|
||||
Temperament
|
||||
~~~~~~~~~~~
|
||||
@@ -112,18 +124,18 @@ same note name:
|
||||
in closely related keys but "wolf intervals" make distant keys
|
||||
unusable.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> a4.pitch(temperament="equal")
|
||||
440.0
|
||||
>>> a4.pitch(temperament="pythagorean")
|
||||
440.0 # A4 is always 440 (it's the reference)
|
||||
440.0
|
||||
|
||||
>>> c5 = Tone.from_string("C5", system="western")
|
||||
>>> c5.pitch(temperament="equal")
|
||||
523.25
|
||||
523.2511306011972
|
||||
>>> c5.pitch(temperament="pythagorean")
|
||||
521.48 # Slightly different!
|
||||
521.4814814814815
|
||||
|
||||
Symbolic Pitch
|
||||
~~~~~~~~~~~~~~
|
||||
@@ -134,33 +146,29 @@ floating-point approximations. This is useful for mathematical analysis,
|
||||
proving tuning relationships, or comparing temperaments with exact
|
||||
arithmetic.
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> a4 = Tone.from_string("A4", system="western")
|
||||
|
||||
# Equal temperament: irrational ratios (roots of 2)
|
||||
>>> a4.pitch(symbolic=True)
|
||||
440
|
||||
>>> Tone.from_string("C5", system="western").pitch(symbolic=True)
|
||||
440*2**(1/4)
|
||||
|
||||
# Pythagorean: pure rational ratios (powers of 3/2)
|
||||
>>> Tone.from_string("G4", system="western").pitch(
|
||||
... temperament="pythagorean", symbolic=True)
|
||||
660
|
||||
391.111111111111
|
||||
|
||||
# Compare the major third across temperaments
|
||||
>>> e4 = Tone.from_string("E4", system="western")
|
||||
>>> e4.pitch(temperament="equal", symbolic=True)
|
||||
440*2**(1/3)
|
||||
220.0*2**(7/12)
|
||||
>>> e4.pitch(temperament="pythagorean", symbolic=True)
|
||||
12160/27
|
||||
330.000000000000
|
||||
>>> e4.pitch(temperament="meantone", symbolic=True)
|
||||
550
|
||||
220.0*5**(1/4)
|
||||
|
||||
# Symbolic expressions can be evaluated to any precision
|
||||
>>> e4.pitch(symbolic=True).evalf(50)
|
||||
329.62755691286991583007431157433859631791591649985
|
||||
329.62755691286992973584176104655507518647334182098
|
||||
|
||||
The symbolic output reveals *why* temperaments differ: equal temperament
|
||||
uses irrational numbers (roots of 2), Pythagorean uses powers of 3/2
|
||||
@@ -194,34 +202,84 @@ Common intervals::
|
||||
|
||||
Tones support ``+`` and ``-`` operators for semitone math:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c4 = Tone.from_string("C4", system="western")
|
||||
>>> c4 + 4 # Major third up
|
||||
>>> c4 + 4
|
||||
<Tone E4>
|
||||
>>> c4 + 7 # Perfect fifth up
|
||||
>>> c4 + 7
|
||||
<Tone G4>
|
||||
>>> c4 + 12 # Octave up
|
||||
>>> c4 + 12
|
||||
<Tone C5>
|
||||
|
||||
Subtracting two tones gives the semitone distance:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> g4 = Tone.from_string("G4", system="western")
|
||||
>>> g4 - c4 # Perfect fifth = 7 semitones
|
||||
>>> g4 - c4
|
||||
7
|
||||
|
||||
>>> c5 = Tone.from_string("C5", system="western")
|
||||
>>> c5 - c4 # Octave = 12 semitones
|
||||
>>> c5 - c4
|
||||
12
|
||||
|
||||
Naming Intervals
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
The ``interval_to`` method gives the musical name of the interval
|
||||
between two tones, including compound intervals that span more than
|
||||
one octave:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c4.interval_to(g4)
|
||||
'perfect 5th'
|
||||
>>> c4.interval_to(c4 + 4)
|
||||
'major 3rd'
|
||||
>>> c4.interval_to(c5)
|
||||
'octave'
|
||||
|
||||
>>> c4.interval_to(c4 + 19)
|
||||
'perfect 5th + 1 octave'
|
||||
|
||||
Transposition
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
The ``transpose`` method returns a new tone shifted by a number of
|
||||
semitones — equivalent to the ``+`` operator but reads more clearly
|
||||
in some contexts:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c4.transpose(7)
|
||||
<Tone G4>
|
||||
>>> c4.transpose(-2)
|
||||
<Tone A#3>
|
||||
|
||||
MIDI
|
||||
~~~~
|
||||
|
||||
Every tone maps to a `MIDI note number <https://en.wikipedia.org/wiki/MIDI>`_
|
||||
(0–127), the standard for communicating with synthesizers, DAWs, and
|
||||
digital instruments:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c4.midi
|
||||
60
|
||||
>>> Tone.from_string("A4", system="western").midi
|
||||
69
|
||||
|
||||
>>> Tone.from_midi(60).midi
|
||||
60
|
||||
|
||||
Comparison and Sorting
|
||||
----------------------
|
||||
|
||||
Tones can be compared and sorted by pitch frequency:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c4 < g4
|
||||
True
|
||||
@@ -230,9 +288,9 @@ Tones can be compared and sorted by pitch frequency:
|
||||
|
||||
Equality checks note name and octave:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c4 == "C" # Compare with string (name only)
|
||||
>>> c4 == "C"
|
||||
True
|
||||
>>> c4 == Tone(name="C", octave=4)
|
||||
True
|
||||
@@ -244,7 +302,7 @@ Every tone you hear is actually a composite of many frequencies. When
|
||||
a string vibrates, it doesn't just vibrate as a whole — it also vibrates
|
||||
in halves, thirds, quarters, and so on, producing the `harmonic series <https://en.wikipedia.org/wiki/Harmonic_series_(music)>`_:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> a4 = Tone.from_string("A4", system="western")
|
||||
>>> a4.overtones(8)
|
||||
@@ -288,7 +346,7 @@ F#=Gb and C#=Db.
|
||||
PyTheory uses sharps by default (following the tone list ordering), but
|
||||
every tone knows its enharmonic spelling:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Tone.from_string("C#4", system="western").enharmonic
|
||||
'Db'
|
||||
@@ -296,10 +354,48 @@ every tone knows its enharmonic spelling:
|
||||
>>> Tone.from_string("A#4", system="western").enharmonic
|
||||
'Bb'
|
||||
|
||||
# Natural notes have no enharmonic
|
||||
>>> Tone.from_string("C4", system="western").enharmonic is None
|
||||
True
|
||||
|
||||
Extended Enharmonics
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
PyTheory supports the full range of enharmonic spellings used in real
|
||||
music theory:
|
||||
|
||||
- **Cb** and **Fb** — musically valid flats (Cb = B, Fb = E)
|
||||
- **E#** and **B#** — musically valid sharps (E# = F, B# = C)
|
||||
- **Double sharps** (``##`` or ``x``) — e.g. F## = G
|
||||
- **Double flats** (``bb``) — e.g. Dbb = C
|
||||
- **Unicode symbols** — ``♯`` (sharp), ``♭`` (flat), ``𝄪`` (double sharp),
|
||||
``𝄫`` (double flat) are all recognized and normalized to ASCII
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Tone.from_string("Cb4") # resolves to B3 (octave boundary fix)
|
||||
<Tone B3>
|
||||
>>> Tone.from_string("B#4") # resolves to C5 (octave boundary fix)
|
||||
<Tone C5>
|
||||
>>> Tone.from_string("E#4") # resolves to F4
|
||||
<Tone F4>
|
||||
>>> Tone.from_string("Fb4") # resolves to E4
|
||||
<Tone E4>
|
||||
|
||||
The octave boundary is correctly handled: B# crosses up to the next
|
||||
octave (B#4 = C5), and Cb crosses down (Cb4 = B3), matching standard
|
||||
scientific pitch notation where the octave number increments at C.
|
||||
|
||||
Tone Validation
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
Tones are validated on construction — if a tone name is not recognized
|
||||
in its system, a ``ValueError`` is raised:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Tone.from_string("X4") # not a valid tone name
|
||||
ValueError: ...
|
||||
|
||||
The Circle of Fifths
|
||||
--------------------
|
||||
|
||||
@@ -308,17 +404,66 @@ theory. Starting from any note and ascending by perfect fifths (7
|
||||
semitones), you pass through all 12 chromatic tones before returning
|
||||
to the starting note:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c4 = Tone.from_string("C4", system="western")
|
||||
|
||||
# Clockwise — ascending fifths (adds sharps)
|
||||
>>> [t.name for t in c4.circle_of_fifths()]
|
||||
['C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#', 'G#', 'D#', 'A#', 'F']
|
||||
|
||||
# Counter-clockwise — ascending fourths (adds flats)
|
||||
>>> [t.name for t in c4.circle_of_fourths()]
|
||||
['C', 'F', 'A#', 'D#', 'G#', 'C#', 'F#', 'B', 'E', 'A', 'D', 'G']
|
||||
|
||||
Each step clockwise adds one sharp to the key signature; each step
|
||||
counter-clockwise (ascending by fourths = 5 semitones) adds one flat.
|
||||
|
||||
Solfege
|
||||
-------
|
||||
|
||||
The fixed-Do `solfege <https://en.wikipedia.org/wiki/Solf%C3%A8ge>`_ system
|
||||
maps each note to a singable syllable. PyTheory uses fixed Do (C is always Do):
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Tone.from_string("C4").solfege
|
||||
'Do'
|
||||
>>> Tone.from_string("D4").solfege
|
||||
'Re'
|
||||
>>> Tone.from_string("F#4").solfege
|
||||
'Fi'
|
||||
>>> Tone.from_string("Bb4").solfege
|
||||
'Te'
|
||||
|
||||
Helmholtz Notation
|
||||
------------------
|
||||
|
||||
The older `Helmholtz notation <https://en.wikipedia.org/wiki/Helmholtz_pitch_notation>`_
|
||||
uses case and tick marks instead of numbers:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> Tone.from_string("C3").helmholtz # Great octave
|
||||
'C'
|
||||
>>> Tone.from_string("C4").helmholtz # Middle C
|
||||
'c'
|
||||
>>> Tone.from_string("C5").helmholtz # One-line octave
|
||||
"c'"
|
||||
>>> Tone.from_string("C2").helmholtz # Contra octave
|
||||
'CC'
|
||||
|
||||
Cents
|
||||
-----
|
||||
|
||||
A **cent** is 1/100th of a semitone — the standard unit for measuring
|
||||
fine pitch differences. Use ``cents_difference`` to compare tones or
|
||||
temperaments:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> c4 = Tone.from_string("C4", system="western")
|
||||
>>> c4.cents_difference(c4 + 1) # One semitone = 100 cents
|
||||
100.0
|
||||
>>> c4.cents_difference(c4 + 7) # Perfect fifth
|
||||
700.0
|
||||
|
||||
Tones are the atoms of music -- everything else is built from them. Get comfortable here, and chords, scales, and harmony all start to make intuitive sense.
|
||||
|
||||
+116
-14
@@ -1,26 +1,112 @@
|
||||
PyTheory: Music Theory for Humans
|
||||
=================================
|
||||
|
||||
**PyTheory** is a Python library that makes exploring music theory approachable.
|
||||
Work with tones, scales, chords, and fretboards using a clean, Pythonic API.
|
||||
**PyTheory** is a Python library for exploring music theory, composing
|
||||
multi-part arrangements, and exporting them to MIDI for your DAW.
|
||||
|
||||
Use it to learn theory by doing — build chords from intervals and hear
|
||||
the result. Use it to sketch song ideas faster than clicking through a
|
||||
DAW. Use it with Claude Code to prototype
|
||||
music from natural language. Or just use it to answer "what chords are
|
||||
in G major?" without opening a browser.
|
||||
|
||||
::
|
||||
|
||||
$ pip install pytheory
|
||||
|
||||
Theory
|
||||
------
|
||||
|
||||
The theory layer works everywhere Python runs — no audio setup needed.
|
||||
Tones, scales, chords, keys, intervals, harmony, 16 musical systems,
|
||||
60+ instruments:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from pytheory import Key, Chord, Tone
|
||||
|
||||
>>> Key("C", "major").chords
|
||||
['C major', 'D minor', 'E minor', 'F major', 'G major', 'A minor', 'B diminished']
|
||||
|
||||
>>> [c.symbol for c in Key("G", "major").progression("I", "V", "vi", "IV")]
|
||||
['G', 'D', 'Em', 'C']
|
||||
|
||||
>>> Chord.from_symbol("F#m7b5").identify()
|
||||
'F# half-diminished 7th'
|
||||
|
||||
>>> Tone.from_string("C4").interval_to(Tone.from_string("G4"))
|
||||
'perfect 5th'
|
||||
|
||||
Composition
|
||||
-----------
|
||||
|
||||
When you're ready to make noise, the composition layer adds drums,
|
||||
synths, effects, and multi-part arrangements. Sketch an idea, hear
|
||||
it through your speakers, export MIDI, finish in your DAW:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pytheory import TonedScale, Fretboard, CHARTS
|
||||
from pytheory import Score, Key, Duration
|
||||
from pytheory.play import play_score
|
||||
|
||||
# Build a C major scale
|
||||
c_major = TonedScale(tonic="C4")["major"]
|
||||
print(c_major.note_names)
|
||||
# ['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']
|
||||
score = Score("4/4", bpm=120)
|
||||
score.drums("rock", repeats=8, fill="rock", fill_every=4)
|
||||
|
||||
# Build a triad from the scale
|
||||
chord = c_major.triad(0) # C major triad
|
||||
for tone in chord:
|
||||
print(f"{tone}: {tone.frequency:.1f} Hz")
|
||||
piano = score.part("piano", instrument="piano", reverb=0.3)
|
||||
lead = score.part("lead", synth="saw", envelope="pluck",
|
||||
delay=0.2, reverb=0.2, lowpass=4000)
|
||||
bass = score.part("bass", synth="triangle", lowpass=900)
|
||||
|
||||
# Get guitar fingerings
|
||||
fb = Fretboard.guitar()
|
||||
print(CHARTS["western"]["C"].fingering(fretboard=fb))
|
||||
for chord in Key("G", "major").progression("I", "V", "vi", "IV") * 2:
|
||||
piano.add(chord, Duration.WHOLE)
|
||||
|
||||
lead.add("D5", 1).add("B4", 0.5).add("D5", 0.5)
|
||||
lead.add("G5", 1).add("E5", 1)
|
||||
lead.add("D5", 0.5).add("B4", 0.5).add("A4", 1)
|
||||
lead.add("G4", 2).rest(2)
|
||||
|
||||
for n in ["G2", "G2", "D2", "D2", "E2", "E2", "C2", "C2"] * 2:
|
||||
bass.add(n, Duration.HALF)
|
||||
|
||||
play_score(score)
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<audio controls style="width:100%;margin:0.5em 0 1.5em"><source src="_static/audio/quickstart.wav" type="audio/wav"></audio>
|
||||
|
||||
Or hear a randomly generated track from the command line — different
|
||||
every time::
|
||||
|
||||
$ pytheory demo
|
||||
|
||||
What's Inside
|
||||
-------------
|
||||
|
||||
- **Theory** — tones, scales (40+ across 16 systems), chords (17 types),
|
||||
keys, Roman numeral analysis, figured bass, pitch class sets (Forte
|
||||
numbers), scale recommendation, modulation, voice leading, enharmonic
|
||||
support (Cb, Fb, E#, B#, double sharps/flats, unicode symbols)
|
||||
- **Sequencing** — Score, Parts, arpeggiator, legato/glide, velocity,
|
||||
swing, humanize, tempo changes, song sections with repeat, strumming,
|
||||
pitch bends (3 types), rolls, tuning systems (TET factory, 4
|
||||
temperaments, reference_pitch)
|
||||
- **Synthesis** — 41 waveforms (including Karplus-Strong pluck, Hammond organ,
|
||||
bowed string, granular, vocal/formant, and 31 dedicated instrument synths),
|
||||
10 envelopes, 60+ instrument presets, configurable FM, sub-oscillator,
|
||||
noise layer, filter envelope, velocity-to-brightness, analog oscillator
|
||||
drift, detune, stereo pan/spread, 80+ drum patterns (stereo panned,
|
||||
including world percussion and cajón), 21 fills, 11 microtonal systems
|
||||
- **Effects** — reverb (algorithmic + 7 convolution IRs, stereo), delay,
|
||||
lowpass/highpass (with resonance), distortion, guitar cabinet simulation,
|
||||
saturation, chorus, phaser, tremolo, analog drift, sidechain compression,
|
||||
automation, LFOs. Master bus compressor/limiter
|
||||
- **Instruments** — 60+ presets with fingering generation, guitar strumming,
|
||||
pitch bends, note choking
|
||||
- **Output** — stereo playback, WAV export, MIDI import/export
|
||||
- **Interface** — REPL with tab completion, CLI (15 commands), ``pytheory demo``,
|
||||
KeyboardInterrupt handling for clean stop
|
||||
- **AI-friendly** — Claude Code can compose
|
||||
and play music through PyTheory from natural language
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
@@ -33,7 +119,14 @@ Work with tones, scales, chords, and fretboards using a clean, Pythonic API.
|
||||
guide/chords
|
||||
guide/fretboard
|
||||
guide/systems
|
||||
guide/sequencing
|
||||
guide/synths
|
||||
guide/effects
|
||||
guide/drums
|
||||
guide/playback
|
||||
guide/repl
|
||||
guide/cli
|
||||
guide/cookbook
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
@@ -45,3 +138,12 @@ Work with tones, scales, chords, and fretboards using a clean, Pythonic API.
|
||||
api/charts
|
||||
api/play
|
||||
api/systems
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Project
|
||||
|
||||
changelog.md
|
||||
|
||||
Music is math that makes you feel something. PyTheory gives you the
|
||||
math. What you feel is up to you.
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
"""Identify chords from notes or guitar fingerings."""
|
||||
|
||||
from pytheory import Chord, Fretboard
|
||||
|
||||
print("=== Chord Identification from Notes ===")
|
||||
print()
|
||||
|
||||
test_chords = [
|
||||
("C", "E", "G"),
|
||||
("A", "C", "E"),
|
||||
("G", "B", "D", "F"),
|
||||
("D", "F#", "A"),
|
||||
("Bb", "D", "F"),
|
||||
("E", "G#", "B"),
|
||||
("C", "Eb", "Gb"),
|
||||
("C", "G"),
|
||||
("C", "F", "G"),
|
||||
("C", "D", "G"),
|
||||
]
|
||||
|
||||
for notes in test_chords:
|
||||
chord = Chord.from_tones(*notes)
|
||||
name = chord.identify() or "Unknown"
|
||||
print(f" {', '.join(notes):20s} → {name}")
|
||||
|
||||
print()
|
||||
print("=== Chord Identification from Guitar Fingerings ===")
|
||||
print()
|
||||
|
||||
fb = Fretboard.guitar()
|
||||
|
||||
# Common guitar chord shapes
|
||||
shapes = [
|
||||
("Open C", (0, 1, 0, 2, 3, 0)),
|
||||
("Open G", (3, 0, 0, 0, 2, 3)),
|
||||
("Open D", (2, 3, 2, 0, 0, 0)),
|
||||
("Open Am", (0, 1, 2, 2, 0, 0)),
|
||||
("Open Em", (0, 0, 0, 2, 2, 0)),
|
||||
("Barre F", (1, 1, 2, 3, 3, 1)),
|
||||
("Power E5", (0, 0, 0, 0, 2, 0)),
|
||||
]
|
||||
|
||||
for label, positions in shapes:
|
||||
f = fb.fingering(*positions)
|
||||
name = f.identify() or "Unknown"
|
||||
print(f" {label:12s} {f} → {name}")
|
||||
@@ -0,0 +1,52 @@
|
||||
"""Analyze harmonic tension and resolution across chords."""
|
||||
|
||||
from pytheory import Chord
|
||||
|
||||
print("Chord Tension Analysis")
|
||||
print("=" * 70)
|
||||
print()
|
||||
print(f"{'Chord':>20s} {'Tension':>8s} {'Harmony':>8s} {'Dissonance':>11s} {'Notes'}")
|
||||
print(f"{'─' * 20} {'─' * 8} {'─' * 8} {'─' * 11} {'─' * 15}")
|
||||
|
||||
chords = [
|
||||
# Stable chords
|
||||
"C", "Am",
|
||||
# Moderate tension
|
||||
"Dm7", "Cmaj7",
|
||||
# High tension
|
||||
"G7", "Bdim",
|
||||
# Extended
|
||||
"Am7", "Cmaj9",
|
||||
]
|
||||
|
||||
for name in chords:
|
||||
chord = Chord.from_name(name)
|
||||
t = chord.tension
|
||||
tones = " ".join(tone.name for tone in chord.tones)
|
||||
print(
|
||||
f"{name:>20s} {t['score']:>8.2f} {chord.harmony:>8.4f}"
|
||||
f" {chord.dissonance:>11.4f} {tones}"
|
||||
)
|
||||
|
||||
# Show the V7 → I resolution
|
||||
print()
|
||||
print("─" * 70)
|
||||
print()
|
||||
print("The V7 → I resolution (the strongest pull in tonal music):")
|
||||
print()
|
||||
|
||||
g7 = Chord.from_name("G7")
|
||||
c = Chord.from_name("C")
|
||||
|
||||
print(f" G7 (dominant): tension={g7.tension['score']:.2f} "
|
||||
f"tritones={g7.tension['tritones']} "
|
||||
f"dominant_function={g7.tension['has_dominant_function']}")
|
||||
print(f" C (tonic): tension={c.tension['score']:.2f} "
|
||||
f"tritones={c.tension['tritones']} "
|
||||
f"dominant_function={c.tension['has_dominant_function']}")
|
||||
|
||||
print()
|
||||
print("Voice leading (G7 → C):")
|
||||
for src, dst, motion in g7.voice_leading(c):
|
||||
direction = "↑" if motion > 0 else "↓" if motion < 0 else "="
|
||||
print(f" {src.name:3s} → {dst.name:3s} ({direction} {abs(motion)} semitones)")
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user