Index: cfg.py ================================================================== --- cfg.py +++ cfg.py @@ -5,25 +5,25 @@ import sys import time random.seed(time.time()) def main(): - key = "C" + key = "A" note_grammars = { - "u": ["I V I IV u", "I IV", "I VII IV" , "e"], + "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e"], "e": [""], } chord_grammars = { - "u": ["I IV V IV I", "e"], + "u": ["I IV V IV I u u", "I VII IV u u", "I V IV u u", "e"], "e": [""] } compose_piece(key, note_grammars) compose_piece(key, chord_grammars, chords=True) def compose_piece(key, grammars, chords=False): score = "" - while len(score.split()) < 15: + while len(score.split()) < 200: score = "u u u" score = generate_score(score, grammars) score = transliterate_score(score, key, chords) score = generate_csound_score(score) print "f1 0 256 10 1 0 3 ; sine wave function table" ADDED parse.py Index: parse.py ================================================================== --- parse.py +++ parse.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +from ply import lex + +tokens = ( + "NOTE", + "REST", + "SHARP", + "FLAT", + "OCTAVE", + "NATURAL", + "LENGTH", +) + +t_NOTE = r"[A-Ga-g]" +t_REST = r"z" +t_SHARP = r"\^" +t_FLAT = r"_" +t_NATURAL = r"=" +t_OCTAVE = r"'+|,+" + +def t_LENGTH(t): + r"/?\d+" + multiplier = float(t.value.strip("/")) + if t.value.startswith("/"): + multiplier = 1/multiplier + t.value = multiplier + return t + +def t_error(t): + raise TypeError("Unknown text '%s'" % (t.value,)) + +t_ignore = " |" + +lex.lex() + +lex.input("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD") +for tok in iter(lex.token, None): + print repr(tok.type), repr(tok.value) Index: test.sco ================================================================== --- test.sco +++ test.sco @@ -1,62 +0,0 @@ -f1 0 256 10 1 0 3 ; sine wave function table -i2 0.000000 1 7000 9.00 9.00 0 6 -i2 0.250000 1 7000 8.07 8.07 0 6 -i2 0.500000 1 7000 8.00 8.00 0 6 -i2 0.750000 1 7000 8.05 8.05 0 6 -i2 1.000000 1 7000 9.00 9.00 0 6 -i2 1.250000 1 7000 9.07 9.07 0 6 -i2 1.500000 1 7000 8.00 8.00 0 6 -i2 1.750000 1 7000 8.05 8.05 0 6 -i2 2.000000 1 7000 8.00 8.00 0 6 -i2 2.250000 1 7000 9.11 9.11 0 6 -i2 2.500000 1 7000 8.05 8.05 0 6 -i2 2.750000 1 7000 9.00 9.00 0 6 -i2 3.000000 1 7000 9.07 9.07 0 6 -i2 3.250000 1 7000 9.00 9.00 0 6 -i2 3.500000 1 7000 8.05 8.05 0 6 -f1 0 256 10 1 0 3 ; sine wave function table -i2 0.000000 1 7000 8.02 8.02 0 6 -i2 0.000000 1 7000 7.07 7.07 0 6 -i2 0.000000 1 7000 8.11 8.11 0 6 -i2 1.000000 1 7000 7.07 7.07 0 6 -i2 1.000000 1 7000 8.00 8.00 0 6 -i2 1.000000 1 7000 7.02 7.02 0 6 -i2 2.000000 1 7000 8.09 8.09 0 6 -i2 2.000000 1 7000 8.00 8.00 0 6 -i2 2.000000 1 7000 8.04 8.04 0 6 -i2 3.000000 1 7000 8.07 8.07 0 6 -i2 3.000000 1 7000 8.00 8.00 0 6 -i2 3.000000 1 7000 8.02 8.02 0 6 -i2 4.000000 1 7000 7.02 7.02 0 6 -i2 4.000000 1 7000 7.07 7.07 0 6 -i2 4.000000 1 7000 7.11 7.11 0 6 -i2 5.000000 1 7000 7.02 7.02 0 6 -i2 5.000000 1 7000 7.07 7.07 0 6 -i2 5.000000 1 7000 8.11 8.11 0 6 -i2 6.000000 1 7000 8.07 8.07 0 6 -i2 6.000000 1 7000 7.00 7.00 0 6 -i2 6.000000 1 7000 7.02 7.02 0 6 -i2 7.000000 1 7000 8.09 8.09 0 6 -i2 7.000000 1 7000 7.00 7.00 0 6 -i2 7.000000 1 7000 7.04 7.04 0 6 -i2 8.000000 1 7000 7.07 7.07 0 6 -i2 8.000000 1 7000 7.00 7.00 0 6 -i2 8.000000 1 7000 7.02 7.02 0 6 -i2 9.000000 1 7000 8.02 8.02 0 6 -i2 9.000000 1 7000 8.07 8.07 0 6 -i2 9.000000 1 7000 7.11 7.11 0 6 -i2 10.000000 1 7000 7.02 7.02 0 6 -i2 10.000000 1 7000 8.07 8.07 0 6 -i2 10.000000 1 7000 8.11 8.11 0 6 -i2 11.000000 1 7000 7.07 7.07 0 6 -i2 11.000000 1 7000 8.00 8.00 0 6 -i2 11.000000 1 7000 7.02 7.02 0 6 -i2 12.000000 1 7000 8.09 8.09 0 6 -i2 12.000000 1 7000 7.00 7.00 0 6 -i2 12.000000 1 7000 8.04 8.04 0 6 -i2 13.000000 1 7000 7.07 7.07 0 6 -i2 13.000000 1 7000 7.00 7.00 0 6 -i2 13.000000 1 7000 8.02 8.02 0 6 -i2 14.000000 1 7000 7.02 7.02 0 6 -i2 14.000000 1 7000 7.07 7.07 0 6 -i2 14.000000 1 7000 7.11 7.11 0 6