Created
April 18, 2012 23:05
-
-
Save Ceasar/2417260 to your computer and use it in GitHub Desktop.
Tool to generate music automatically using Markov Chains. Simply pass a Melopy mp file to the script and it will generate a song. Requires Nonsense and Melopy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from itertools import izip | |
from melopy import Melopy | |
from nonsense import StationarySource | |
if __name__ == "__main__": | |
try: | |
sample = sys.argv[1] # must not have comments | |
except IndexError: | |
sample = sys.stdin.read() | |
degree = 2 | |
output = "mysong" | |
else: | |
try: | |
degree = sys.argv[2] | |
except IndexError: | |
degree = 2 | |
try: | |
output = sys.argv[3] | |
except IndexError: | |
output = "mysong" | |
ss = StationarySource(["".join(sample.split())], int(degree)) | |
m = Melopy(output) | |
print "Generating song..." | |
song = "".join([c for c, _ in izip(ss.generate_sequence(), xrange(500))]) | |
print "Parsng song..." | |
m.parse(song) | |
m.render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment