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
|
#!/usr/bin/env python
import os
import random
import sys
import time
random.seed(time.time())
import parse
def main():
key = "A"
composition = {
"a": { # Movement block 'a' for reuse throughout the piece
"melody": { # Instrument 'melody'
"csound_parameters": {
"instrument": 1,
},
"grammars": { # Notes for this instrument to use in this piece
"u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e"],
# "u": ["I I I I u u", "e"],
"e": [""],
},
"score": "u u u u u",
},
"rhythm": {
"csound_parameters": {
"instrument": 1,
},
"grammars": {
# "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "vii" "IV" u u', '"I" "v" "IV" u u', "e"],
"u": ['"i" "I" "ii" "II" "v" "V" u', "e"],
"e": [""]
},
"score": "u u u",
},
},
"b": {
"melody": { # Instrument 'melody'
|
>
>
>
>
<
|
|
|
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
|
#!/usr/bin/env python
from __future__ import division
import os
import random
import sys
import time
random.seed(time.time())
import parse
def main():
key = "A"
bps = 80/60
print bps
tempo = 1/bps
composition = {
"a": { # Movement block 'a' for reuse throughout the piece
"melody": { # Instrument 'melody'
"csound_parameters": {
"instrument": 1,
},
"grammars": { # Notes for this instrument to use in this piece
"u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u" , "e"],
"e": [""],
},
"score": "u u u u u",
},
"rhythm": {
"csound_parameters": {
"instrument": 1,
},
"grammars": {
"u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "vii" "IV" u u', '"I" "v" "IV" u u', "e"],
# "u": ['"i" "I" "ii" "II" "v" "V" u', "e"],
"e": [""]
},
"score": "u u u",
},
},
"b": {
"melody": { # Instrument 'melody'
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
generated_score = generate_score(instr["score"], instr["grammars"]) # Fill in the scores by generating them based on the grammars
score = parse.parse(generated_score) # Return Node/Chord objects
# Generate timestamps for the notes
t = instr_start_time
for note in range(len(score)):
score[note].time = t
t += score[note].duration
max_t = t if t > max_t else max_t
# print "end note,", max_t
composition[comp_name][instr_name]["score"] = score
# print "end instr,", max_t
# Must be done after all note times keyed in, else you can't coordinate melodies with the rhythm chords
for comp_name in progression.split():
for instr_name, instr in composition[comp_name].iteritems():
composition[comp_name][instr_name]["score"] = transliterate_score(composition[comp_name][instr_name]["score"], key)
# print "\nMovement %s instrument %s" % (comp_name, instr_name)
# print composition[comp_name][instr_name]["score"]
|
>
>
>
>
<
<
|
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
generated_score = generate_score(instr["score"], instr["grammars"]) # Fill in the scores by generating them based on the grammars
score = parse.parse(generated_score) # Return Node/Chord objects
# Generate timestamps for the notes
t = instr_start_time
for note in range(len(score)):
score[note].time = t
# print "Original duration:", score[note].duration
score[note].duration *= tempo
# print "New duration:", score[note].duration
t += score[note].duration
# print "t:", t
max_t = t if t > max_t else max_t
composition[comp_name][instr_name]["score"] = score
# Must be done after all note times keyed in, else you can't coordinate melodies with the rhythm chords
for comp_name in progression.split():
for instr_name, instr in composition[comp_name].iteritems():
composition[comp_name][instr_name]["score"] = transliterate_score(composition[comp_name][instr_name]["score"], key)
# print "\nMovement %s instrument %s" % (comp_name, instr_name)
# print composition[comp_name][instr_name]["score"]
|