# install external libraries from IPython.display import clear_output !pip install -q git+https://github.com/davidkant/mai#egg=mai; !apt-get -qq update !apt-get -qq install -y libfluidsynth1 clear_output() # imports import mai import random # parameters pulse = 240 # duration in seconds 60 / pulse # start with an empty list my_durs = [] # loop until we have enough notes while len(my_durs) < 16: # choose duration new_dur = 60 / pulse # append to the melody my_durs += [new_dur] # let's see it mai.make_music_plot(pitches=60, durs=my_durs) # let's hear it mai.make_music(pitches=60, durs=my_durs, is_drum=True) # parameters pulse = 240 rhythm = 1 # duration in seconds duration = 60.0 / pulse # random variation in duration duration * random.uniform(1 - rhythm, 1 + rhythm) # start with an empty list my_durs = [] # loop until we have enough notes while len(my_durs) < 12: # choose duration new_dur = (60.0 / pulse) * random.uniform(1 - rhythm, 1 + rhythm) # append to the melody my_durs += [new_dur] # let's see it mai.make_music_plot(pitches=60, durs=my_durs) # let's hear it mai.make_music(pitches=60, durs=my_durs, is_drum=True) # parameters pitch_center = 60 pitch_range = 6 # choose pitch random.randint(pitch_center - pitch_range, pitch_center + pitch_range) # start with empty lists for both pitch and duration my_pitches = [] my_durs = [] # loop until we have enough notes while len(my_durs) < 24: # choose pitch new_pitch = random.randint(pitch_center - pitch_range, pitch_center + pitch_range) # choose duration new_dur = (60.0 / pulse) * random.uniform(1 - rhythm, 1 + rhythm) # append to the melody my_pitches += [new_pitch] my_durs += [new_dur] # let's see it mai.make_music_plot(pitches=my_pitches, durs=my_durs) # let's hear it mai.make_music(pitches=my_pitches, durs=my_durs, is_drum=False) # parameter detune = 1.0 # given a pitch pitch = 60 # microtronal pitch adjustment random.uniform(pitch - detune, pitch + detune) # start with empty lists for both pitch and duration my_pitches = [] my_durs = [] # loop until we have enough notes while len(my_durs) < 24: # choose pitch new_pitch = random.randint(pitch_center - pitch_range, pitch_center + pitch_range) # microtonal pitch adjustment new_pitch = random.uniform(new_pitch - detune, new_pitch + detune) # choose duration new_dur = (60.0 / pulse) * random.uniform(1 - rhythm, 1 + rhythm) # append to the melody my_pitches += [new_pitch] my_durs += [new_dur] # let's see it mai.make_music_plot(pitches=my_pitches, durs=my_durs) # let's hear it mai.make_music(pitches=my_pitches, durs=my_durs, is_drum=False) # parameter repeat = 0.7 # let's say this is our music thus far my_music = [60, 62, 64, 64, 64, 66, 64, 60] # do we look back or choose a brand new pitch? if random.random() <= repeat: # take the fifth previous note pitch = my_music[-8] print(pitch) # start with empty lists for both pitch and duration my_pitches = [] my_durs = [] # loop until we have enough notes while len(my_durs) < 16: # do we look back? if random.random() <= repeat and len(my_pitches) >= 8: # use the fifth previous note new_pitch = my_pitches[-8] new_dur = my_durs[-8] # if we don't look back else: # choose pitch new_pitch = random.randint(pitch_center - pitch_range, pitch_center + pitch_range) # microtonal pitch adjustment new_pitch = random.uniform(new_pitch - detune, new_pitch + detune) # choose duration new_dur = (60.0 / pulse) * random.uniform(1 - rhythm, 1 + rhythm) # append to the melody my_pitches += [new_pitch] my_durs += [new_dur] # let's see it mai.make_music_plot(pitches=my_pitches, durs=my_durs) # let's hear it mai.make_music(my_pitches, durs=my_durs, pgm=1) # parameters pitch_center = 60 # center pitch pitch_range = 6 # variation in pitch pulse = 240 # in bpm beats per minute rhythm = 1 # percent of variation around the pulse detune = 0.5 # amount of microtonal inflection repeat = 0.85 # probability of repeat or interestingness # run AMB my_pitches, my_durs = mai.amb(pitch_center=60, pitch_range=12, pulse=240, rhythm=0.3, detune=0.3, repeat=0.7, memory=5, length=40) # let's see it mai.make_music_plot(pitches=my_pitches, durs=my_durs) # let's hear it mai.make_music(my_pitches, durs=my_durs, pgm=1, is_drum=False) # choose parameters pitch_center = random.randint(24, 99) # pitch in MIDI pitch value pitch_range = random.randint(1, 36) # variation in MIDI pitch value pulse = random.randint(40, 480) # in bpm beats per minute rhythm = random.uniform(0, 1) # percent of variation around the pulse detune = random.uniform(0, 1) # amount of microtonal inflection repeat = random.uniform(0, 1) # probability of repeat memory = random.randint(0, 10) # how far back to look pgm = random.randint(0, 127) # instrument sound # print random parameters print("RANDOM PARAMETERS!") print("- pitch center:", pitch_center) print("- pitch range:", pitch_range) print("- pulse:", pulse) print("- rhythm:", rhythm) print("- detune:", detune) print("- repeat:", repeat) print("- memory:", memory) # run AMB my_pitches, my_durs = mai.amb(pitch_center=pitch_center, pitch_range=pitch_range, pulse=pulse, rhythm=rhythm, detune=detune, repeat=repeat, memory=memory) # let's see it mai.make_music_plot(pitches=my_pitches, durs=my_durs) # let's hear it mai.make_music(my_pitches, durs=my_durs, pgm=pgm+1, is_drum=False) #@title Anna's Music Box # choose parameters length = 9 #@param {type:"slider", min:1, max:99, step:1.0} pitch_center = 45 #@param {type:"slider", min:32, max:84, step:1.0} pitch_range = 3 #@param {type:"slider", min:0, max:36, step:1.0} pulse = 184 #@param {type:"slider", min:40, max:480, step:1.0} rhythm = 0.73 #@param {type:"slider", min:0, max:1, step:0.01} detune = 1 #@param {type:"slider", min:0, max:1, step:0.01} repeat = 0.82 #@param {type:"slider", min:0, max:1, step:0.01} memory = 5 #@param {type:"slider", min:1, max:10, step:1.0} pgm = 22 #@param {type:"slider", min:1, max:128, step:1.0} is_drums = True #@param {type:"boolean"} autoplay = False #@param {type:"boolean"} # run AMB my_pitches, my_durs = mai.amb(pitch_center=pitch_center, pitch_range=pitch_range, pulse=pulse, rhythm=rhythm, detune=detune, repeat=repeat, memory=memory, length=length) # let's see it mai.make_music_plot(pitches=my_pitches, durs=my_durs) # let's hear it mai.make_music(my_pitches, durs=my_durs, pgm=pgm, is_drum=is_drums, format='autoplay' if autoplay else 'inbrowser') #@title Anna's Music Box # choose parameters length = 18 #@param {type:"slider", min:1, max:99, step:1.0} pitch_center = 52 #@param {type:"slider", min:32, max:84, step:1.0} pitch_range = 36 #@param {type:"slider", min:0, max:36, step:1.0} pulse = 201 #@param {type:"slider", min:40, max:480, step:1.0} rhythm = 0.57 #@param {type:"slider", min:0, max:1, step:0.01} detune = 0.24 #@param {type:"slider", min:0, max:1, step:0.01} repeat = 1 #@param {type:"slider", min:0, max:1, step:0.01} memory = 5 #@param {type:"slider", min:1, max:10, step:1.0} pgm = 13 #@param {type:"slider", min:1, max:128, step:1.0} num_critters = 4 #@param {type:"slider", min:1, max:16, step:1.0} is_drums = False #@param {type:"boolean"} autoplay = False #@param {type:"boolean"} # run AMB my_music = [mai.amb(pitch_center=pitch_center, pitch_range=pitch_range, pulse=pulse, rhythm=rhythm, detune=detune, repeat=repeat, memory=memory, length=length) for i in range(num_critters)] # combine multiple voices pitches = [x[0] for x in my_music] durs = [x[1] for x in my_music] # let's hear it mai.make_music_heterophonic(pitches, durs=durs, pgm=pgm, is_drum=is_drums, format='autoplay' if autoplay else 'inbrowser')