forked from Jobsecond/random-midi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·30 lines (22 loc) · 815 Bytes
/
main.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import json
import time
from subprocess import check_output
from masterpiece import Masterpiece
from argument_parser import parse_args
if __name__ == '__main__':
args = parse_args()
result_dir = 'output'
os.makedirs(result_dir, exist_ok=True)
filename_str = os.path.join(result_dir, f'{time.time():.01f}')
with open('rules.json') as f:
rules = json.load(f)
rhythm = [[0.5] * (4 * args.num_bars - 1) + [4.5]]
my_masterpiece = Masterpiece(rules, rhythm, args)
lilypond_str = my_masterpiece.create_midi_file(f'{filename_str}.mid')
with open(f'{filename_str}.txt', 'w') as f:
f.write(lilypond_str)
cmd_str = 'lilypond --output={0} {0}.txt'.format(filename_str)
check_output(cmd_str.split(' '))