spiffyscore

Check-in [6a17d4d36a]
Login
Overview
Comment:Moved all logic into neat, orderly functions. Now prints only the csound score portion.
Timelines: family | ancestors | descendants | both | ply
Files: files | file ages | folders
SHA1: 6a17d4d36a36c58e86777d4457fe28e400b54baa
User & Date: spiffytech@gmail.com on 2010-11-12 20:12:48
Other Links: branch diff | manifest | tags
Context
2010-11-12
20:23
Now prints score file header (function table), so I can just >> to foo.sco check-in: 00f4ddc9f3 user: spiffytech@gmail.com tags: ply
20:12
Moved all logic into neat, orderly functions. Now prints only the csound score portion. check-in: 6a17d4d36a user: spiffytech@gmail.com tags: ply
20:00
Program now generates a single voice with a I IV V pattern and spits out (among other things) the csound-ified score check-in: 338933c1a8 user: spiffytech@gmail.com tags: ply
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Modified cfg.py from [73244ab69d] to [4cae783255].

     7      7   random.seed(time.time())
     8      8   
     9      9   grammars = {
    10     10       "u": ["I V I IV u", "e"],
    11     11       "e": [""],
    12     12   }
    13     13   
    14         -# Generate the scale for the key we're in
    15         -comp_key = "C"
    16         -notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
    17         -scale = [comp_key]
    18         -pos = notes.index(comp_key)
    19         -progression = [2,2,1,2,2,2,1]
    20         -for p in progression:
    21         -    pos = (pos + p) % 12
    22         -    scale.append(notes[pos])
           14  +
           15  +def main():
           16  +    score = "u u u"
           17  +    key = "C"
           18  +    score = generate_score(score)
           19  +    score = keyify_score(score, key)
           20  +    score = generate_csound_score(score)
           21  +    for line in score:
           22  +        print line
           23  +
           24  +
           25  +def make_scale(key):
           26  +    notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
           27  +    scale = [key]
           28  +    pos = notes.index(key)
           29  +    progression = [2,2,1,2,2,2,1]
           30  +    for p in progression:
           31  +        pos = (pos + p) % 12
           32  +        scale.append(notes[pos])
           33  +    return scale
           34  +
           35  +
           36  +def generate_score(score):
           37  +    while 1:
           38  +        found_substitution = False
           39  +        for key,value in grammars.iteritems():
           40  +            if score.find(key) != -1:
           41  +                found_substitution = True
           42  +                while score.find(key) != -1:
           43  +                    score = score.replace(key, random.choice(grammars[key]), 1)
           44  +        if found_substitution is False:
           45  +            break
           46  +    return score
    23     47   
    24         -scale_conversion = {
    25         -    "I": 1,
    26         -    "II": 2,
    27         -    "III": 3,
    28         -    "IV": 4,
    29         -    "V": 5,
    30         -    "VI": 6,
    31         -    "VII": 7,
    32         -    "VIII": 8,
    33         -}
           48  +def keyify_score(score, key):
           49  +    scale = make_scale(key)
           50  +    scale_conversion = {
           51  +        "I": 1,
           52  +        "II": 2,
           53  +        "III": 3,
           54  +        "IV": 4,
           55  +        "V": 5,
           56  +        "VI": 6,
           57  +        "VII": 7,
           58  +        "VIII": 8,
           59  +    }
           60  +    keyed_score = []
           61  +    for token in score.split():
           62  +        keyed_score.append(scale[scale_conversion[token]-1])
           63  +    return keyed_score
           64  +
    34     65   
    35         -csound_note_values = {
    36         -    "C": "00",
    37         -    "C#": "01",
    38         -    "D": "02",
    39         -    "D#": "03",
    40         -    "E": "04",
    41         -    "F": "05",
    42         -    "F#": "06",
    43         -    "G": "07",
    44         -    "F#": "08",
    45         -    "A": "09",
    46         -    "A#": "10",
    47         -    "B": "11",
    48         -}
           66  +def generate_csound_score(score):
           67  +    csound_note_values = {
           68  +        "C": "00",
           69  +        "C#": "01",
           70  +        "D": "02",
           71  +        "D#": "03",
           72  +        "E": "04",
           73  +        "F": "05",
           74  +        "F#": "06",
           75  +        "G": "07",
           76  +        "F#": "08",
           77  +        "A": "09",
           78  +        "A#": "10",
           79  +        "B": "11",
           80  +    }
           81  +    t = 0 
           82  +    csound_score = []
           83  +    for token in score:
           84  +        note = csound_note_values[token]
           85  +        csound_score.append("i2 %f 2 7000 %d.%s %d.%s 0 6" % (t, random.choice([8,9]), note, random.choice([8,9]), note))
           86  +        t += .25
           87  +    return csound_score
    49     88   
    50     89   
    51         -score = "u u u"
    52         -print score
    53         -while 1:
    54         -    found_substitution = False
    55         -    for key,value in grammars.iteritems():
    56         -        if score.find(key) != -1:
    57         -            found_substitution = True
    58         -            while score.find(key) != -1:
    59         -                score = score.replace(key, random.choice(grammars[key]), 1)
    60         -                print score
    61         -        #        time.sleep(.25)
    62         -    if found_substitution is False:
    63         -        break
    64         -
    65         -csound_score = []
    66         -for token in score.split():
    67         -    csound_score.append(scale[scale_conversion[token]-1])
    68         -
    69         -print csound_score
    70         -
    71         -t = 0 
    72         -for token in csound_score:
    73         -    note = csound_note_values[token]
    74         -    print "i2 %f 2 7000 %d.%s %d.%s 0 6" % (t, random.choice([8,9]), note, random.choice([8,9]), note)
    75         -    t += .25
           90  +if __name__ == "__main__": main() 

Modified test.sco from [24ff5724a8] to [acb8a904c1].

     1      1   f1  0   256 10  1 0 3   ; sine wave function table
     2      2   
     3         -i2 0.000000 2 7000 9.00 8.00 0 6
     4         -i2 0.250000 2 7000 9.07 9.07 0 6
     5         -i2 0.500000 2 7000 8.00 9.00 0 6
     6         -i2 0.750000 2 7000 9.05 8.05 0 6
     7         -i2 1.000000 2 7000 9.00 8.00 0 6
            3  +i2 0.000000 2 7000 8.00 9.00 0 6
            4  +i2 0.250000 2 7000 8.07 8.07 0 6
            5  +i2 0.500000 2 7000 9.00 8.00 0 6
            6  +i2 0.750000 2 7000 8.05 9.05 0 6
            7  +i2 1.000000 2 7000 8.00 9.00 0 6
     8      8   i2 1.250000 2 7000 9.07 9.07 0 6
     9      9   i2 1.500000 2 7000 9.00 9.00 0 6
    10         -i2 1.750000 2 7000 9.05 8.05 0 6
           10  +i2 1.750000 2 7000 8.05 9.05 0 6
           11  +i2 2.000000 2 7000 9.00 8.00 0 6
           12  +i2 2.250000 2 7000 8.07 9.07 0 6
           13  +i2 2.500000 2 7000 8.00 8.00 0 6
           14  +i2 2.750000 2 7000 9.05 9.05 0 6
           15  +i2 3.000000 2 7000 8.00 8.00 0 6
           16  +i2 3.250000 2 7000 8.07 9.07 0 6
           17  +i2 3.500000 2 7000 9.00 9.00 0 6
           18  +i2 3.750000 2 7000 8.05 9.05 0 6
           19  +i2 4.000000 2 7000 8.00 9.00 0 6
           20  +i2 4.250000 2 7000 9.07 9.07 0 6
           21  +i2 4.500000 2 7000 9.00 9.00 0 6
           22  +i2 4.750000 2 7000 8.05 8.05 0 6
           23  +i2 5.000000 2 7000 9.00 8.00 0 6
           24  +i2 5.250000 2 7000 8.07 8.07 0 6
           25  +i2 5.500000 2 7000 8.00 9.00 0 6
           26  +i2 5.750000 2 7000 9.05 9.05 0 6
           27  +i2 6.000000 2 7000 9.00 9.00 0 6
           28  +i2 6.250000 2 7000 9.07 9.07 0 6
           29  +i2 6.500000 2 7000 9.00 8.00 0 6
           30  +i2 6.750000 2 7000 8.05 8.05 0 6
           31  +i2 7.000000 2 7000 9.00 9.00 0 6
           32  +i2 7.250000 2 7000 8.07 9.07 0 6
           33  +i2 7.500000 2 7000 8.00 8.00 0 6
           34  +i2 7.750000 2 7000 9.05 8.05 0 6
           35  +i2 8.000000 2 7000 9.00 8.00 0 6
           36  +i2 8.250000 2 7000 8.07 8.07 0 6
           37  +i2 8.500000 2 7000 9.00 9.00 0 6
           38  +i2 8.750000 2 7000 8.05 9.05 0 6