PyCodeDJ Manual

Write Python code. Hear it change in real time.

1. What PyCodeDJ Does

PyCodeDJ turns Python source code into live music. It parses files, reads @loop blocks, maps code structure to musical parameters, and sends OSC messages to SuperCollider.

from pycodedj import dj, loop

@loop(interval=2.0)
def bass():
    dj.volume = 0.4
    for i in range(8):
        if i % 2 == 0:
            pass

@loop(synth="kick_floor", beat=0.25)
def kick():
    dj.volume = 0.8
    dj.pattern = "x . x ."

The function name is the loop name. Use it with pycodedj eval demo.py::bass, mute, and stop.

2. Install and Start

pip install 'pycodedj[watch]'

Open sc/synths.scd in SuperCollider, run it, and confirm:

PyCodeDJ synths loaded. Ready. OSC port: 57120
pycodedj eval examples/demo.py::bass

3. Basic Loop Syntax

from pycodedj import dj, loop

@loop(interval=1.0)
def loop_name():
    dj.volume = 0.3
    dj.eq = "flat"
    pass
SettingMeaningDefault
dj.volumeAmplitude, 0.0 to 1.00.3
dj.eqEQ preset"flat"
dj.low/mid/highPer-band EQ override, 0.0 to 2.0preset value
dj.patternRhythm and pitch patternnone
@loop(interval=0.25)
def hats():
    dj.volume = 0.08
    dj.eq = "edm"
    dj.low = 0.5
    dj.high = 1.25
PresetCharacter
"flat"No adjustment
"classic" / "classical"Restrained lows/highs, forward mids
"jazz"Warm lows, forward mids, soft highs
"rock" / "pop"Slight low and high boost
"edm" / "hiphop"Stronger low end
"acoustic"Restrained lows, slight mid-high lift

4. Code Structure Mapping

When dj.pattern is absent, the shape of the function body controls sound.

Code featureMusic parameterEffect
Max block depthFilter cutoffDeeper code sounds brighter
if / for / while countLFO rateMore control flow moves faster
Nested def countVoice countMore functions add voices
Comment ratioReverb mixMore comments add space

5. Rhythm and Pitch with dj.pattern

@loop(synth="bass_acid", root="A1", scale="minor", beat=0.25)
def bass():
    dj.volume = 0.35
    dj.pattern = "0 . [0 3] ~ 5 . 3 ."
TokenMeaning
xTrigger at root note
.Rest
0, 1, ...Scale degree
[0 3]Chord
~Tie

dj.pattern = p1 is intentionally not supported. Keep pattern strings visible in the loop body.

6. Multiple Loops

@loop(synth="kick_floor", beat=0.25)
def kick():
    dj.volume = 0.8
    dj.pattern = "x . x ."

@loop(interval=4.0)
def pad():
    dj.volume = 0.08
    # wide space
    pass
pycodedj watch examples/demo.py

7. Sound Reference

Use synth= to choose a SuperCollider synth. The function name remains the loop name; synth= only chooses the sound.

@loop(synth="bass_acid", root="A1", scale="minor", beat=0.25)
def acid():
    dj.volume = 0.25
    dj.pattern = "0 . 3 . 5 ."

Audition all sounds one at a time:

pycodedj eval examples/sound_showcase.py::kick_floor
pycodedj eval examples/sound_showcase.py::bass_acid
pycodedj eval examples/sound_showcase.py::lead_acid

Kicks

SynthCharacterGood for
kick_hardTight, punchy, short attackStrong downbeats and minimal patterns
kick_floorFull four-on-the-floor club kickMain kick in dance/techno loops
kick_pulseLighter pulse kickSecondary pulse, softer rhythmic support
kick_softRounder kick with less clickWarm grooves and quieter sections
kick_909Long electronic kick tailHouse and techno foundations
kick_clickShort kick with a clear transientFast patterns that need definition

Bass

SynthCharacterGood for
bass_rumbleDeep, loose low-end pressureRumble layers under a kick
bass_reeseWide, moving Reese-style bassDark basslines and sustained movement
bass_subClean sine-like sub weightFundamental low notes and floor pressure
bass_acidResonant 303-like acid tonePatterned basslines and squelchy sequences
bass_pluckShort plucked bassSyncopated low-end hooks
bass_fmMetallic FM low tonePercussive basslines
bass_monoSimple mono synth bassStable bass phrases
bass_wobbleFilter-modulated bassDubstep-style movement and breakdowns

Percussion

SynthCharacterGood for
hat_engineShort closed/open hat texture16th-note grids and forward motion
hat_rideLonger open hat / ride colorOffbeats and sustained top-end energy
clap_snapSharp, dry clapSnappy accents
clap_snareBroader snare-like clapBackbeats on beats 2 and 4
tom_drumPitch-swept tomFills, transitions, low percussion
snare_rollRepeated snare textureRolls and build-ups
crash_noiseLong noisy crashSection changes and impacts
rim_shotDry rim transientSparse syncopation
cowbellMetallic two-tone hitClassic machine percussion
perc_blipSmall pitched blipMinimal percussion and call-response details
shaker_loopContinuous shaker textureTop-end groove and motion
tick_metalTiny metallic tickGlitch grids and high-frequency accents
wood_blockWoody resonant knockDry percussion patterns

Chords and Stabs

SynthCharacterGood for
chord_raveBright rave stabShort chord hits and hooks
stab_neonGlossy synthetic stabMelodic accents
chord_dubSoft dub-techno chordSpacious chord pulses
stab_sawDetuned saw stabAggressive harmonic accents
chord_organOrgan-like sustained chordWarm harmonic beds
bell_raveMetallic FM bellBright melodic stabs
pad_minorDark minor padSuspense and darker harmonic beds
chord_deepLow filtered chordDeep house / dub-techno pulses
chord_glassClear glassy chordClean bright harmonic accents
pad_warmSmooth analog-style padSoft background harmony
pad_stringBowed string-like synth padLong sustained emotional layers
pad_choirVocal-formant padChoral beds without a lead vocal

Leads and Notes

SynthCharacterGood for
lead_acidAcid-style leadMelodic sequences
lead_hooverHoover-like leadBig sustained gestures
pluck_softGentle plucked toneSparse melodies
arp_synthArpeggiated synth toneFast melodic motion
lead_squareHollow square-wave leadRetro melodic hooks
lead_fmBell-like FM leadBright digital melodies
lead_chipShort chiptune leadFast arcade-like phrases
lead_sawDetuned saw leadLarger melodic lines
lead_whistleThin sine-like whistleHigh counter-melodies
noteNeutral note synthGeneral dj.pattern pitch tests and chords

Atmosphere and FX

SynthCharacterGood for
pad_shimmerWide, slow shimmerBackground pads
air_warehouseIndustrial room toneSpace, air, and noise bed
vox_ahhVocal-like formant padBreath and choir-like layers
fx_dropLow impact hitDrops and transitions
fx_riserRising noise sweepBuild-ups
fx_glitchSmall glitch clicksDetailed percussive texture
drone_spaceLow evolving droneLong ambient beds
fx_downDescending noise sweepDrops and section endings
fx_zapShort falling laser-like hitSmall FX punctuation
fx_noiseFiltered noise burstImpacts and transitions
fx_laserPitch-bending laser FXSci-fi accents
fx_vinylCrackle and hiss bedTexture and lo-fi background

8. CLI Reference

pycodedj eval FILE::LOOP
pycodedj watch examples/demo.py
pycodedj panic
pycodedj stop bass
pycodedj mute bass
pycodedj unmute bass

9. Troubleshooting

No sound: boot SuperCollider, run sc/synths.scd, confirm the OSC port, then run pycodedj eval examples/demo.py::bass.

Loop not found: the name after :: must match the Python function name.

10. Under the Hood

PyCodeDJ parses Python with ast. loop, dj, and pattern are runtime helpers so files can still be imported normally.