Skip to content

Instantly share code, notes, and snippets.

@smoge
Created April 29, 2023 05:27
Show Gist options
  • Save smoge/5101f21c37d0d21120f11d880c006484 to your computer and use it in GitHub Desktop.
Save smoge/5101f21c37d0d21120f11d880c006484 to your computer and use it in GitHub Desktop.
solo_improvisation (pseudo code fun)
def solo_improvisation():
# Create arrays to store musical material and acoustic space
material = [] # store longer units of material here
current_phrase = [] # store current phrase being improvised
acoustic_space = [] # store all acoustic resonances
# Use additive procedures for building patterns
# Add four phrases to the material array
for i in range(4):
current_phrase.append(random.randint(0, 9)) # add random notes to the current phrase
material.append(current_phrase.copy()) # push a copy of the current phrase to the material array
# Use repetition/mutation procedures to manipulate material
# Go through each phrase in the material array
for i in range(len(material)):
phrase = material[i]
# Repeat the following procedures three times
for j in range(3):
index = random.randint(0, len(phrase) - 1) # select a random note index in the phrase
action = random.randint(0, 2) # select a random action to perform on the note
if action == 0:
# Add a new note at the selected index
phrase.insert(index, random.randint(0, 9))
elif action == 1:
# Remove the note at the selected index
phrase.pop(index)
else:
# Change the note at the selected index by adding a random value between -1 and 1
phrase[index] += random.randint(-1, 1)
material[i] = phrase # Update the material array with the mutated phrase
# Use circular breathing and overtone selection to extend durations
# Go through each phrase in the material array
for i in range(len(material)):
phrase = material[i]
# Go through each note in the phrase
for j in range(len(phrase)):
note = phrase[j]
if note == 0:
# Use circular breathing if the note is a rest (0)
reserve_air = 10 # Set reserve air in cheeks to 10 units
while reserve_air > 0:
play_note_with_reserve(note, reserve_air) # Play the note using the reserve air
reserve_air -= 1 # Decrease the reserve air by 1 unit
else:
# Use overtone selection if the note is not a rest
overtones = [note, note * 2, note * 3, note * 4, note * 5] # Calculate the overtones of the note
selected_overtone = random.choice(overtones) # Select a random overtone
play_note_with_reserve(selected_overtone, 5) # Play the selected overtone with a reserve air of 5 units
# Fill the acoustic space to create a polyphonic illusion
# Go through each phrase in the material array
for i in range(len(material)):
phrase = material[i]
acoustic_space.append(phrase) # Push the phrase to the acoustic space
# Repeat the following procedures three times
for j in range(3):
index = random.randint(0, len(acoustic_space) - 1) # Select a random riff index from the acoustic space
riff = acoustic_space[index] # Get the selected riff
if riff != phrase:
# Mix the selected riff with the current phrase and push to the acoustic space if they are not the same
acoustic_space.append(mix_riffs(phrase, riff))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment