forked from frallebini/musicomb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.py
102 lines (92 loc) · 2.6 KB
/
generate.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
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import argparse
from datetime import datetime
from pathlib import Path
import yaml
from commu_dset import DSET
from commu_wrapper import make_midis
from musicomb import MusiComb
import random
def main(args: argparse.Namespace, timestamp: str) -> None:
if args.generate_samples:
role_to_midis = make_midis(
args.bpm,
args.key,
args.time_signature,
args.num_measures,
args.genre,
args.rhythm,
args.chord_progression,
timestamp)
else:
role_to_midis = DSET.sample_midis(
args.bpm,
args.key,
args.time_signature,
args.num_measures,
args.genre,
args.rhythm,
args.chord_progression)
MusiComb(role_to_midis, timestamp, args.bpm, args.time_signature, args.num_measures, args.genre, args.music_length).solve()
if __name__ == '__main__':
with open('cfg/metadata.yaml') as f:
meta = yaml.safe_load(f)
parser = argparse.ArgumentParser()
parser.add_argument(
'--bpm',
dest='bpm',
type=int,
required=True,
choices=meta['bpm'])
parser.add_argument(
'--key',
dest='key',
type=str,
required=True,
choices=meta['key'])
parser.add_argument(
'--time_signature',
dest='time_signature',
type=str,
required=True,
choices=meta['time_signature'])
parser.add_argument(
'--num_measures',
dest='num_measures',
type=int,
required=True,
choices=meta['num_measures'])
parser.add_argument(
'--genre',
dest='genre',
type=str,
required=True,
choices=meta['genre'])
parser.add_argument(
'--rhythm',
dest='rhythm',
type=str,
required=True,
choices=meta['rhythm'])
parser.add_argument(
'--chord_progression',
dest='chord_progression',
type=str,
required=True,
choices=meta['chord_progression'])
parser.add_argument(
'--music_length',
dest='music_length',
type=int,
required=True,
choices=meta['music_length'])
parser.add_argument(
'--generate_samples',
dest='generate_samples',
default=False,
action='store_true')
args = parser.parse_args()
now = datetime.now().strftime('%Y-%m-%d_%H.%M.%S')
Path(f'out/{now}').mkdir(parents=True)
with open(f'out/{now}/metadata.yaml', 'w') as f:
yaml.dump(vars(args), f)
main(args, now)