Skip to content

Instantly share code, notes, and snippets.

@jhw
Last active May 28, 2023 00:57
Show Gist options
  • Save jhw/3af61a50e42ef0110e041238a7f802e3 to your computer and use it in GitHub Desktop.
Save jhw/3af61a50e42ef0110e041238a7f802e3 to your computer and use it in GitHub Desktop.
Some sample Sunvox patterns
bin
include
lib
share
data
*.sunvox
*.pyc

run

python hello_drumsynth_1.py
python hello_drumsynth_2.py
python hello_drumsynth_3.py

sunvox

virtualenv

  • virtualenv -p /usr/bin/python3.6 .
  • source bin/activate
  • pip install -r requirements.txt
  • {...}
  • deactivate
from rv.api import Project
from rv.modules.drumsynth import DrumSynth
from rv.pattern import Pattern
from rv.note import Note
if __name__=="__main__":
proj=Project()
drum=DrumSynth(x=256)
proj.attach_module(drum)
proj.connect(proj.modules[1],
proj.modules[0])
pat=Pattern(lines=64,
tracks=1)
def notefn(track, i, j):
if 0==i%4:
return Note(note=1,
module=2)
else:
return Note()
pat.set_via_fn(notefn)
proj.patterns.append(pat)
with open("hello_drumsynth_1.sunvox", 'wb') as f:
proj.write_to(f)
from rv.api import Project
from rv.modules.drumsynth import DrumSynth
from rv.pattern import Pattern
from rv.note import Note
import random
def handle_empty(fn):
def wrapped(*args, **kwargs):
resp=fn(*args, **kwargs)
return Note() if not resp else resp
return wrapped
def generate(notefn,
filename,
lines=64,
tracks=1,
x=256,
seed=13):
random.seed(seed)
proj=Project()
drum=DrumSynth(x=x)
proj.attach_module(drum)
proj.connect(proj.modules[1],
proj.modules[0])
pat=Pattern(lines=lines,
tracks=tracks)
pat.set_via_fn(notefn)
proj.patterns.append(pat)
with open(filename, 'wb') as f:
proj.write_to(f)
if __name__=="__main__":
@handle_empty
def notefn(track, i, j):
if j==0 and 0==i%4: # bass
return Note(note=49, module=2)
elif j==1 and 4==i%8: # snare
return Note(note=80, module=2)
elif j==2 and 2==i%4: # hat
return Note(note=65, module=2)
elif j==3 and 1==i%2 and random.random() < 0.3: # tom
return Note(note=random.choice([109, 110, 111, 112]), module=2)
elif j==4 and i==54: # hiss
return Note(note=77, module=2)
generate(notefn,
filename="hello_drumsynth_2.sunvox",
seed=14,
tracks=5)
from rv.api import Project
from rv.pattern import Pattern
from rv.note import Note
import random
def handle_empty(fn):
def wrapped(*args, **kwargs):
resp=fn(*args, **kwargs)
return Note() if not resp else resp
return wrapped
def generate(notefn,
filename,
lines=64,
tracks=1,
seed=13):
random.seed(seed)
from rv.modules.drumsynth import DrumSynth
from rv.modules.distortion import Distortion
from rv.modules.reverb import Reverb
proj=Project()
for i, Mod in enumerate([Reverb,
Distortion,
DrumSynth]):
x=512-128*(i+1)
proj.attach_module(Mod(x=x))
proj.connect(proj.modules[i+1],
proj.modules[i])
pat=Pattern(lines=lines,
tracks=tracks)
pat.set_via_fn(notefn)
proj.patterns.append(pat)
with open(filename, 'wb') as f:
proj.write_to(f)
if __name__=="__main__":
@handle_empty
def notefn(track, i, j):
if j==0 and 0==i%4: # bass
return Note(note=49,
module=4)
elif j==1 and 4==i%8: # snare
return Note(note=80,
module=4)
elif j==2 and 2==i%4: # hat
return Note(note=65,
module=4)
elif j==3 and 1==i%2 and random.random() < 0.3: # tom
return Note(note=random.choice([109, 110, 111, 112]),
vel=64, # NB
module=4)
elif j==4 and i==54: # hiss
return Note(note=77,
module=4)
elif j==5 and 0==i%4: # distortion
return Note(module=3,
ctl=3*(2**8),
val=int(random.random()*(2**14)))
elif j==6 and 0==i%8: # reverb
return Note(module=2,
ctl=2*(2**8),
val=int(random.random()*(2**11)))
generate(notefn,
filename="hello_drumsynth_3.sunvox",
seed=14,
tracks=7)
attrs==19.1.0 # https://stackoverflow.com/questions/58189683/typeerror-attrib-got-an-unexpected-keyword-argument-convert
git+https://github.com//metrasynth/radiant-voices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment