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)