-
Notifications
You must be signed in to change notification settings - Fork 1
/
chords.py
81 lines (69 loc) · 2.25 KB
/
chords.py
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
import tools
import performer
import conductor
import random
import watchman
import section
import bass
current_chords = ". . . . . . . . . . . . . . . ."
rhythm = [".",".",".",".",".",".",".",".",".",".",".",".",".",".",".","."]
c_lock = False
prev_degree = 0
degree = 0
def make_phrase(template, scale):
bar = []
sequence = template.split()
for note in sequence:
if note != "." and note.startswith("r") == False:
note = str(scale[int(note[:1])] + note[-2:])
bar.append(note)
return " ".join(bar)
def gen_rhythm(template):
newtem = template
for i in xrange(len(template)):
if (random.random() < float(watchman.activities["chords"])):
if template[i] == "." and newtem.count("x") <= section.xlim:
newtem[i] = "x"
else:
newtem[i] = "."
return newtem
def gen_notes(template):
global degree, prev_degree
# Note lengths and pitch
newtem = template
edited = False
newdeg = 0
icount = 0
# print "A", newtem
for i in xrange(int(performer.tsig * performer.timing)):
if template[i] != ".":
newdeg, newtem = tools.place_notes(i, template, True, degree, prev_degree)
prev_degree = degree
degree = newdeg
edited = True
icount = i
else:
newtem[i] = "."
# print "B", newtem
if edited == False:
newtem[0] = "r1"
else:
if abs(int(icount) - int(performer.tsig * performer.timing)) > (tools.lengths[newtem[icount][-2:]] * performer.timing):
newdeg, newtem[icount+1] = tools.place_notes(icount, newtem, False, degree, prev_degree)
if newtem[0] == '.':
newdeg, newtem = tools.place_notes(0, newtem, False, degree, prev_degree)
return newtem
def gen():
global current_chords, c_lock
if c_lock == False:
current_chords = " ".join(gen_notes(gen_rhythm(rhythm)))
c_lock = True
def play():
global current_chords
key = conductor.relativekey
mode = conductor.relativemode
octave = str(2)
scale = tools.make_chordscale(key, mode, octave)
bar = make_phrase(current_chords, scale)
while len(performer.chordlines) <= performer.buff:
performer.add_chords(bar)