Spaces:
Runtime error
Runtime error
File size: 1,197 Bytes
e007e5d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | from pyo import *
# Initialize the server
s = Server().boot()
# Define the pitch progression and create a MIDI pitch object
pitches = [0, 1, -2, 1]
midi_pitches = [midiTrans(p, "C4") for p in pitches]
# Create a sine wave oscillator and envelope
osc = SineLoop(freq=midi_pitches, feedback=0.08, mul=0.5)
env = Adsr(attack=0.01, decay=0.3, sustain=0.1, release=1.5, dur=2, mul=0.5)
# Play the pitch progression twice
osc.ctrl()
env.ctrl()
for i in range(2):
for pitch in midi_pitches:
env.play()
osc.freq = pitch
s.gui(locals())
# Gradually turn creepy
creepy_notes = [3, 6, 9, 10, 13, 16] # Random creepy MIDI notes
time = s.getStartTime() + 2 # Start at 2 seconds
index = 0
# Play creepy notes every 2 beats
def play_creepy_notes():
global time, index
pitch = creepy_notes[index % len(creepy_notes)]
osc.freq = midiTrans(pitch, "C4")
env.play()
time += 0.5
index += 1
pat = Pattern(play_creepy_notes, 0.5).play()
# Randomize pitch progression
def randomize_pitch():
random.shuffle(midi_pitches)
osc.freq = midi_pitches
s.gui(locals())
pat = Pattern(randomize_pitch, 1).play()
# Stop the server after 20 seconds
s.stop(20)
|