Spaces:
Runtime error
Runtime error
Commit ·
e007e5d
1
Parent(s): 52b2497
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,84 +1,48 @@
|
|
| 1 |
-
import
|
| 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 |
-
winsound.Beep(int(frequency), duration)
|
| 50 |
-
|
| 51 |
-
def play_note(note, duration):
|
| 52 |
-
frequency = NOTES[note]
|
| 53 |
-
play_sound(frequency, duration)
|
| 54 |
-
|
| 55 |
-
def play_chord(chord, duration):
|
| 56 |
-
for note in CHORDS[chord]:
|
| 57 |
-
play_note(note, NOTE_DURATION)
|
| 58 |
-
# Add a brief pause between each note in the chord
|
| 59 |
-
time.sleep(NOTE_DURATION / 2000)
|
| 60 |
-
# Add a longer pause after the chord is played
|
| 61 |
-
time.sleep((duration - len(CHORDS[chord]) * NOTE_DURATION) / 1000)
|
| 62 |
-
|
| 63 |
-
def generate_verse(creepy_section=False):
|
| 64 |
-
chord_sequence = []
|
| 65 |
-
for i in range(4):
|
| 66 |
-
chord_sequence.append(random.choice(list(CHORDS.keys())))
|
| 67 |
-
for chord in chord_sequence:
|
| 68 |
-
if creepy_section and random.random() < CREEPY_CHORD_PROBABILITY:
|
| 69 |
-
creepy_chords = ["Dm", "F"]
|
| 70 |
-
chord = random.choice(creepy_chords)
|
| 71 |
-
play_chord(chord, CHORD_DURATION)
|
| 72 |
-
# Add a brief pause between each chord in the sequence
|
| 73 |
-
time.sleep(CHORD_DURATION / 2000)
|
| 74 |
-
if creepy_section:
|
| 75 |
-
for i in range(random.randint(0, MAX_SKIP_NOTES)):
|
| 76 |
-
time.sleep(NOTE_DURATION / 1000)
|
| 77 |
-
if random.random() < DISSONANCE_PROBABILITY:
|
| 78 |
-
notes = list(NOTES.keys())
|
| 79 |
-
play_note(random.choice(notes), NOTE_DURATION)
|
| 80 |
-
|
| 81 |
-
def generate_song():
|
| 82 |
-
start_time = time.time()
|
| 83 |
-
while time.time() - start_time < SONG_DURATION:
|
| 84 |
-
if time.time() - start_time < VERSE_DURATION:
|
|
|
|
| 1 |
+
from pyo import *
|
| 2 |
+
|
| 3 |
+
# Initialize the server
|
| 4 |
+
s = Server().boot()
|
| 5 |
+
|
| 6 |
+
# Define the pitch progression and create a MIDI pitch object
|
| 7 |
+
pitches = [0, 1, -2, 1]
|
| 8 |
+
midi_pitches = [midiTrans(p, "C4") for p in pitches]
|
| 9 |
+
|
| 10 |
+
# Create a sine wave oscillator and envelope
|
| 11 |
+
osc = SineLoop(freq=midi_pitches, feedback=0.08, mul=0.5)
|
| 12 |
+
env = Adsr(attack=0.01, decay=0.3, sustain=0.1, release=1.5, dur=2, mul=0.5)
|
| 13 |
+
|
| 14 |
+
# Play the pitch progression twice
|
| 15 |
+
osc.ctrl()
|
| 16 |
+
env.ctrl()
|
| 17 |
+
for i in range(2):
|
| 18 |
+
for pitch in midi_pitches:
|
| 19 |
+
env.play()
|
| 20 |
+
osc.freq = pitch
|
| 21 |
+
s.gui(locals())
|
| 22 |
+
|
| 23 |
+
# Gradually turn creepy
|
| 24 |
+
creepy_notes = [3, 6, 9, 10, 13, 16] # Random creepy MIDI notes
|
| 25 |
+
time = s.getStartTime() + 2 # Start at 2 seconds
|
| 26 |
+
index = 0
|
| 27 |
+
|
| 28 |
+
# Play creepy notes every 2 beats
|
| 29 |
+
def play_creepy_notes():
|
| 30 |
+
global time, index
|
| 31 |
+
pitch = creepy_notes[index % len(creepy_notes)]
|
| 32 |
+
osc.freq = midiTrans(pitch, "C4")
|
| 33 |
+
env.play()
|
| 34 |
+
time += 0.5
|
| 35 |
+
index += 1
|
| 36 |
+
|
| 37 |
+
pat = Pattern(play_creepy_notes, 0.5).play()
|
| 38 |
+
|
| 39 |
+
# Randomize pitch progression
|
| 40 |
+
def randomize_pitch():
|
| 41 |
+
random.shuffle(midi_pitches)
|
| 42 |
+
osc.freq = midi_pitches
|
| 43 |
+
s.gui(locals())
|
| 44 |
+
|
| 45 |
+
pat = Pattern(randomize_pitch, 1).play()
|
| 46 |
+
|
| 47 |
+
# Stop the server after 20 seconds
|
| 48 |
+
s.stop(20)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|