Skip to content
Snippets Groups Projects
Commit 7378781c authored by jda92's avatar jda92
Browse files

just adding computoser file

parent 3eb9bfe9
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
from midiutil import MIDIFile
import random
random.seed()
scale = [48, 50, 52, 53, 55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83]
#scale = [48, 50, 51, 53, 55, 56, 58, 60, 62, 63, 65, 67, 68, 70, 72, 74, 75, 77, 79, 80, 82]
track = 0
channel = 0
trackTime = 0
time = 0
duration = 1
tempo = 60
volume = 100
MyMIDI = MIDIFile(1)
MyMIDI.addTempo(track, time, tempo)
def addMotif(pitch, time, trackTime):
for i in range(0, len(pitch)):
MyMIDI.addNote(track, channel, pitch[i], trackTime + time[i], duration, volume)
return trackTime + time[len(time)-1]
def createMotif():
length = random.randint(5, 10)
motifPitch = []
motifTime = []
previous = 60
upPercent = 50
consecutive = 1
time = 0
previousJump = 0
previousTimeInterval = 0
for i in range(0, length):
intervalType = random.randint(0, 100)
upDown = random.randint(0,100)
y = scale.index(previous)
if upDown > upPercent:
upDown = -1
upPercent += 2 * consecutive
consecutive += 1
else:
upDown = 1
upPercent += -2 * consecutive
consecutive += 1
y = scale.index(previous)
try:
if intervalType <= 25:
pitch = previous
elif intervalType <= 27:
upDown = -1 * previousJump
pitch = scale[y + 7*upDown]
elif intervalType <= 75:
pitch = scale[y + 1*upDown]
else:
skipInterval = random.randint(0, 100)
if intervalType <= 25:
pitch = scale[y + 4*upDown]
elif intervalType <= 27:
pitch = scale[y + 3*upDown]
elif intervalType <= 75:
pitch = scale[y + 2*upDown]
else:
pitch = scale[y + 5*upDown]
except IndexError:
upDown *= -1
if intervalType <= 25:
pitch = previous
elif intervalType <= 27:
pitch = scale[y + 7*upDown]
elif intervalType <= 75:
pitch = scale[y + 1*upDown]
else:
skipInterval = random.randint(0, 100)
if intervalType <= 25:
pitch = scale[y + 4*upDown]
elif intervalType <= 27:
pitch = scale[y + 3*upDown]
elif intervalType <= 75:
pitch = scale[y + 2*upDown]
else:
pitch = scale[y + 5*upDown]
timeInterval = random.randint(0, 100)
if timeInterval <= 10:
if previousTimeInterval == 1:
time = time + 1/4
previousTimeInterval = 1/4
else:
time = time + 1/16
previousTimeInterval = 1/16
elif timeInterval <= 41:
if previousTimeInterval == 1:
time = time + 1/4
previousTimeInterval = 1/4
else:
time = time + 1/8
previousTimeInterval = 1/8
elif timeInterval <= 81:
time = time + 1/4
previousTimeInterval = 1/4
elif timeInterval <= 88:
time = time + 1/4 + 1/8
previousTimeInterval = 1/8 + 1/4
elif timeInterval <= 97:
if previousTimeInterval == 1/16:
time = time + 1/4
previousTimeInterval = 1/4
else:
time = time + 1/2
previousTimeInterval = 1/2
elif timeInterval <= 100:
if previousTimeInterval == 1/16:
time = time + 1/2
previousTimeInterval = 1/2
else:
time = time + 1
previousTimeInterval = 1
motifPitch.append(pitch)
motifTime.append(time)
previous = pitch
previousJump = upDown
return motifPitch, motifTime
x, y = createMotif()
a, b = createMotif()
c, d = createMotif()
trackTime = addMotif(x, y, trackTime)
trackTime = addMotif(x, y, trackTime)
trackTime = addMotif(a, b, trackTime)
trackTime = addMotif(a, b, trackTime)
trackTime = addMotif(c, d, trackTime)
with open("random.mid", "wb") as output_file:
MyMIDI.writeFile(output_file)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment