-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate_song.py
34 lines (26 loc) · 918 Bytes
/
generate_song.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
import decoder
from pathlib import Path
from typing import Optional
import argparse
from markovify import Chain
def main(model: Path, output: Optional[Path] = None):
with open(model, "r") as file:
chain = Chain.from_json(file.read())
text = chain.walk()
midi = decoder.decode(text)
output = output or model.with_suffix(".mid")
midi.save(output)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate a Markov chain from a directory of MIDI files.")
parser.add_argument(
"model",
help="The path to a '.json' model file, generated by generate_model.py.",
type=Path
)
parser.add_argument(
"--output", "-o",
help="The path to the output file. Defaults to the same path as the input file, with a `.mid` file extension.",
default=None,
type=Path
)
main(**vars(parser.parse_args()))