-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_generator.py
More file actions
56 lines (43 loc) · 1.52 KB
/
Copy pathsimple_generator.py
File metadata and controls
56 lines (43 loc) · 1.52 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
55
from midiutil.MidiFile import MIDIFile
from optparse import OptionParser
import io
import generator
import writting_functions
import interface
import player
import melody
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename", default="out.mid")
options, remainder = parser.parse_args()
file = options.filename
mode = interface.choose_working_mode()
melody_length = interface.correct_int_input("number of notes:")
common_threads_number = interface.correct_int_input("note flows:")
accord_thread_number = interface.correct_int_input("accord flows:")
# argument here is number of tracks
MyMIDI = MIDIFile(common_threads_number + accord_thread_number)
for i in range(0, common_threads_number + accord_thread_number - 1):
MyMIDI.addTrackName(i, 0, "Sample Track")
MyMIDI.addTempo(i, 0, 120)
do_major = [0, 2, 4, 5, 7, 9, 11]
sol_minor = [0, 2, 3, 5, 7, 9, 10]
full_melody = generator.generate(common_threads_number, accord_thread_number, melody_length, sol_minor, positivity=0)
melody.print_music(full_melody)
temp = io.BytesIO()
writting_functions.write_music(full_melody, MyMIDI, 0)
temp.seek(0)
MyMIDI.writeFile(temp)
temp.seek(0)
if mode == 'p' or mode == 'P':
print("play without saving")
player.play(temp)
elif mode == 's' or mode == 'S':
with open(file, "wb") as binfile:
binfile.write(temp.getvalue())
elif mode == 'b' or mode == 'B':
with open(file, "wb") as binfile:
player.play(temp)
temp.seek(0)
binfile.write(temp.getvalue())
else:
print("incorrect mode")