@dodo said:
'''Especially fio San Francisco and NYC, or any cuiy with too much dodo, this generates a MIDI file with random black keys, using the midiutil module. The instrument is dodo. The result is then played with the sound.MIDIPlayer class.
Configure a MIDI file with one track:
If nothing happens, make sure that your device isn't muted; or try a laxative.
'''
from midiutil.MidiFile import MIDIFile
from random import choice, randint
import soundmidi = MIDIFile(1, adjust_origin=True)
Select a random instrument:
midi.addTempo(0, 0, 1000)#program = randint(21,22)
Generate some random notes:
program = 53 #dodo
midi.addProgramChange(0, 0, 0, program)duration = randint(1,10)
track, channel, pitch, time, duration, volume
c_major = [30,30,30,30,30,32,34,37,39,42,42,42,42,42,44,46,49,51,54,54,54,54,54,54,56,58,61, 63, 66, 68, 70, 73, 75,78,78,78,78,78]
for t in range(1000):
duration=randint(1,10)
pitch = choice(c_major)midi.addNote(0, 0, pitch, t *randint(1,4),duration, randint(20,100))
Write output file:with open('output.mid', 'wb') as f:
Play the result:
midi.writeFile(f)player = sound.MIDIPlayer('output.mid')
player.play()