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: |
6a17d4d36a36c58e86777d4457fe28e4 |
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
Modified cfg.py from [73244ab69d] to [4cae783255].
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/usr/bin/env python import os import random import sys import time random.seed(time.time()) grammars = { "u": ["I V I IV u", "e"], "e": [""], } | | > > | > > > > > > > > | | | | | | | > > > > > > > > > > > > > > > > | | | | | | | | | | > > > > > > | | | | | | | | | | | | | | | < < < < < < < < < < < < < < < | | < < < < < < | | | > > > > | 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 | #!/usr/bin/env python import os import random import sys import time random.seed(time.time()) grammars = { "u": ["I V I IV u", "e"], "e": [""], } def main(): score = "u u u" key = "C" score = generate_score(score) score = keyify_score(score, key) score = generate_csound_score(score) for line in score: print line def make_scale(key): notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"] scale = [key] pos = notes.index(key) progression = [2,2,1,2,2,2,1] for p in progression: pos = (pos + p) % 12 scale.append(notes[pos]) return scale def generate_score(score): while 1: found_substitution = False for key,value in grammars.iteritems(): if score.find(key) != -1: found_substitution = True while score.find(key) != -1: score = score.replace(key, random.choice(grammars[key]), 1) if found_substitution is False: break return score def keyify_score(score, key): scale = make_scale(key) scale_conversion = { "I": 1, "II": 2, "III": 3, "IV": 4, "V": 5, "VI": 6, "VII": 7, "VIII": 8, } keyed_score = [] for token in score.split(): keyed_score.append(scale[scale_conversion[token]-1]) return keyed_score def generate_csound_score(score): csound_note_values = { "C": "00", "C#": "01", "D": "02", "D#": "03", "E": "04", "F": "05", "F#": "06", "G": "07", "F#": "08", "A": "09", "A#": "10", "B": "11", } t = 0 csound_score = [] for token in score: note = csound_note_values[token] csound_score.append("i2 %f 2 7000 %d.%s %d.%s 0 6" % (t, random.choice([8,9]), note, random.choice([8,9]), note)) t += .25 return csound_score if __name__ == "__main__": main() |
Modified test.sco from [24ff5724a8] to [acb8a904c1].
1 2 | f1 0 256 10 1 0 3 ; sine wave function table | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | f1 0 256 10 1 0 3 ; sine wave function table i2 0.000000 2 7000 8.00 9.00 0 6 i2 0.250000 2 7000 8.07 8.07 0 6 i2 0.500000 2 7000 9.00 8.00 0 6 i2 0.750000 2 7000 8.05 9.05 0 6 i2 1.000000 2 7000 8.00 9.00 0 6 i2 1.250000 2 7000 9.07 9.07 0 6 i2 1.500000 2 7000 9.00 9.00 0 6 i2 1.750000 2 7000 8.05 9.05 0 6 i2 2.000000 2 7000 9.00 8.00 0 6 i2 2.250000 2 7000 8.07 9.07 0 6 i2 2.500000 2 7000 8.00 8.00 0 6 i2 2.750000 2 7000 9.05 9.05 0 6 i2 3.000000 2 7000 8.00 8.00 0 6 i2 3.250000 2 7000 8.07 9.07 0 6 i2 3.500000 2 7000 9.00 9.00 0 6 i2 3.750000 2 7000 8.05 9.05 0 6 i2 4.000000 2 7000 8.00 9.00 0 6 i2 4.250000 2 7000 9.07 9.07 0 6 i2 4.500000 2 7000 9.00 9.00 0 6 i2 4.750000 2 7000 8.05 8.05 0 6 i2 5.000000 2 7000 9.00 8.00 0 6 i2 5.250000 2 7000 8.07 8.07 0 6 i2 5.500000 2 7000 8.00 9.00 0 6 i2 5.750000 2 7000 9.05 9.05 0 6 i2 6.000000 2 7000 9.00 9.00 0 6 i2 6.250000 2 7000 9.07 9.07 0 6 i2 6.500000 2 7000 9.00 8.00 0 6 i2 6.750000 2 7000 8.05 8.05 0 6 i2 7.000000 2 7000 9.00 9.00 0 6 i2 7.250000 2 7000 8.07 9.07 0 6 i2 7.500000 2 7000 8.00 8.00 0 6 i2 7.750000 2 7000 9.05 8.05 0 6 i2 8.000000 2 7000 9.00 8.00 0 6 i2 8.250000 2 7000 8.07 8.07 0 6 i2 8.500000 2 7000 9.00 9.00 0 6 i2 8.750000 2 7000 8.05 9.05 0 6 |