amongusrickroll68 commited on
Commit
e007e5d
·
1 Parent(s): 52b2497

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -84
app.py CHANGED
@@ -1,84 +1,48 @@
1
- import winsound
2
- import time
3
- import random
4
-
5
- # Define the musical notes and their corresponding frequencies
6
- NOTES = {
7
- "C": 261.63,
8
- "D": 293.66,
9
- "E": 329.63,
10
- "F": 349.23,
11
- "G": 392.00,
12
- "A": 440.00,
13
- "B": 493.88
14
- }
15
-
16
- # Define the chords and their corresponding note sequences
17
- CHORDS = {
18
- "C": ["C", "E", "G"],
19
- "Dm": ["D", "F", "A"],
20
- "Em": ["E", "G", "B"],
21
- "F": ["F", "A", "C"],
22
- "G": ["G", "B", "D"],
23
- "Am": ["A", "C", "E"]
24
- }
25
-
26
- # Define the length of each note in milliseconds
27
- NOTE_DURATION = 500
28
-
29
- # Define the length of each chord in milliseconds
30
- CHORD_DURATION = 1500
31
-
32
- # Define the length of each verse in seconds
33
- VERSE_DURATION = 5.0
34
-
35
- # Define the length of the entire song in seconds
36
- SONG_DURATION = 60.0
37
-
38
- # Define the maximum number of notes to randomly skip during the creepy section
39
- MAX_SKIP_NOTES = 2
40
-
41
- # Define the probability of playing a dissonant note during the creepy section
42
- DISSONANCE_PROBABILITY = 0.4
43
-
44
- # Define the probability of playing a creepy chord during the creepy section
45
- CREEPY_CHORD_PROBABILITY = 0.3
46
-
47
- def play_sound(frequency, duration):
48
- duration = int(duration)
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)