-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateExamplefiles.py
More file actions
56 lines (53 loc) · 1.83 KB
/
CreateExamplefiles.py
File metadata and controls
56 lines (53 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import sys
import os.path
import numpy as np
import matplotlib.pyplot as plt
import random
if __name__ == '__main__':
try:
os.mkdir('ExamplesYOLO')
except OSError:
print("Folder ExampleYOLO already exists.\n Proceed to creating examples.")
os.chdir(os.getcwd()+'/ExamplesYOLO')
song = []
done = False
for i in range(1, 501):
p = open('Example' + str(i) + '.txt', 'w')
itteration = 1
while itteration <= 200:
if random.random() <= 0.025 and itteration > 60:
done = True
patternlength = random.randint(10,60)
patternposition = random.randint (0, itteration-61)
for k in range(0, patternlength):
song.append(song[patternposition + k])
p.write(str(itteration+k) + ',' + str(song[patternposition + k]) + ',1\n')
else:
note = random.randint(0, 128)
p.write(str(itteration) + ',' + str(note) + ',1\n')
song.append(note)
itteration += 1
if done:
done = False
itteration = itteration + patternlength
p.close()
for i in range(1, 501):
p = open('Example' + str(i) + '.txt', 'r')
time = []
note = []
while True:
nextline = p.readline()
if nextline == '':
break
else:
informations = nextline.split(',')
time.append(int(informations[0]))
note.append(int(informations[1]))
plt.yticks(np.arange(0,128,10))
plt.xticks(np.arange(0,300,40))
plt.scatter(time, note)
plt.xlabel('Note in Track')
plt.ylabel('Notepitch')
plt.savefig('Example'+str(i)+'.png', dpi=200)
plt.clf()
p.close()