-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathArrangeSections.py
More file actions
executable file
·235 lines (173 loc) · 15.5 KB
/
ArrangeSections.py
File metadata and controls
executable file
·235 lines (173 loc) · 15.5 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
from __future__ import print_function
import random
import collections
import CreateMidiEventsForBass
class ArrangeSections :
def __init__ ( self, id, movement, outdir , oneMidiPerLayer) :
self.id = id
self.movement = movement
self.outdir = outdir
self.oneMidiPerLayer = oneMidiPerLayer
def arrange ( self ) :
# arranging sections
if ( 1 ) :
print()
print ( "ArrangeSections.py" )
sectionsObj = self.movement['SectionsObj'].mood
print ( "Movement: ", self.id, "Mood: ", self.movement['mood'], "Complexity: ", self.movement['complexity'], "Num Uniq Layers:", sectionsObj.numUniqCPs )
print()
print ( "Arrangement for Movement" )
for secId in sectionsObj.sections :
tse = sectionsObj.sections[secId]['tse']
print ( "\tSection: ", secId, "Uniq Mel Id: ", sectionsObj.sections[secId]['melId'], "Starting MNum: ", sectionsObj.sections[secId]['startMNum'], "Ending MNum: ", sectionsObj.sections[secId]['endMNum'], "TSE: ", tse )
uniqCPId = sectionsObj.sections[secId]['melId']
numChordsInPhrase = sectionsObj.uniqCPSettings[uniqCPId]['numChords']
phNum = 0
for chId in sectionsObj.sections[secId]['chords'] :
if ( chId % numChordsInPhrase == 0 ) :
print()
print ( "\t\tPhrase: ", phNum + 1, sectionsObj.sections[secId]['phrases'][phNum] )
phNum += 1
print ( "\t\t\tChord: ", chId, sectionsObj.sections[secId]['chords'][chId] )
print()
self.midiEventsForSectionLayers = collections.OrderedDict()
sectionsObj = self.movement['SectionsObj'].mood
for secId in sectionsObj.sections :
self.midiEventsForSectionLayers[secId] = collections.OrderedDict()
uniqCPId = sectionsObj.sections[secId]['melId']
numChordsInSection = sectionsObj.uniqCPSettings[uniqCPId]['numChords']
repCount = sectionsObj.sections[secId]['repCount']
fillsFlag = sectionsObj.sections[secId]['percussionFills']
for chId in sectionsObj.sections[secId]['chords'] :
for layer in sectionsObj.sections[secId]['chords'][chId]['layers'] :
if ( layer.endswith('Strings') or layer == 'leftPianoBass' or layer.startswith('rightPiano') or layer.startswith('drums') ) : # these are phrase level layers. deal with them below
continue
#if ( not ( layer == 'piano1' or layer == 'bass1' or layer == 'bass2' or layer == 'mel5' or layer == 'rhythmChords' ) ) :
# continue
if ( 0 ) :
print ( "Layer: ", layer )
if ( layer not in self.midiEventsForSectionLayers[secId] and layer != 'mel5' ) :
self.midiEventsForSectionLayers[secId][layer] = []
if ( layer == 'mel5' and layer+'Low' not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layer] = []
self.midiEventsForSectionLayers[secId][layer+'Low'] = []
self.midiEventsForSectionLayers[secId][layer+'Med'] = []
self.midiEventsForSectionLayers[secId][layer+'High'] = []
actualChordId = chId % numChordsInSection
if ( layer == 'bass1' or layer == 'bass2' or layer == 'bass3' ) :
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEvents ( layer, uniqCPId, secId, chId, sectionsObj.sections[secId]['chords'][chId], self.movement['layers'][uniqCPId][layer][0][actualChordId] )
if ( 0 and layer == 'bass3' ) :
print ( self.midiEventsForSectionLayers[secId][layer], self.movement['layers'][uniqCPId][layer], uniqCPId, secId, chId, sectionsObj.sections[secId]['chords'][chId], )
if ( layer == 'mel5' ) :
low, med, high, all = CreateMidiEventsForBass.CreateMidiEventsForMelody ( layer, uniqCPId, secId, chId, sectionsObj.sections[secId]['chords'][chId], self.movement['layers'][uniqCPId][layer][0][actualChordId] )
self.midiEventsForSectionLayers[secId][layer] += all
self.midiEventsForSectionLayers[secId][layer+'Low'] += low
self.midiEventsForSectionLayers[secId][layer+'Med'] += med
self.midiEventsForSectionLayers[secId][layer+'High'] += high
#self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEvents ( layer, uniqCPId, secId, chId, sectionsObj.sections[secId]['chords'][chId], self.movement['layers'][uniqCPId][layer][0][actualChordId] )
if ( layer == 'piano1' or layer == 'peruvianRhythmChords') :
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEventsForPiano ( layer, uniqCPId, secId, chId, repCount, numChordsInSection, sectionsObj.sections[secId]['chords'][chId], self.movement['layers'][uniqCPId][layer][actualChordId] )
if ( layer == 'rhythmChords' ) :
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEventsForRhythmChords ( layer, uniqCPId, secId, chId, repCount, numChordsInSection, sectionsObj.sections[secId]['chords'][chId], self.movement['layers'][uniqCPId][layer][actualChordId] )
if ( layer == 'brassRhythms' ) :
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEventsForRhythmChords ( layer, uniqCPId, secId, chId, repCount, numChordsInSection, sectionsObj.sections[secId]['chords'][chId], self.movement['layers'][uniqCPId][layer][0][actualChordId] )
for phId in sectionsObj.sections[secId]['phrases'] :
density = sectionsObj.sections[secId]['phrases'][phId]['density']
processFillForPhrase = False
#notation layer
layerName = "notationLP"
if ( layerName not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layerName] = []
layer = 'leftPianoBass'
self.midiEventsForSectionLayers[secId][layerName] += CreateMidiEventsForBass.CreateMidiEventsForStrings ( layer, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer] )
layerName = "notationRP"
if ( layerName not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layerName] = []
layer = 'rightPiano'
lyr = "_rp3" # pick one of the right piano layers randomly
layer1 = layer + lyr
# print ( "SecId: ", secId, "phId: ", phId, "layer: ", layer1 )
self.midiEventsForSectionLayers[secId][layerName] += CreateMidiEventsForBass.CreateMidiEventsForStrings ( layer1, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer1])
for layer in sectionsObj.sections[secId]['phrases'][phId]['layers'] :
#if ( layer.startswith('drums') ) :
# continue
if ( not ( layer.endswith('Strings') or layer == 'leftPianoBass' or layer.startswith('rightPiano') or layer.startswith('drums') ) ) : # these are not phrase level layers. deal with them above
continue
if ( 0 ) :
print ( layer, "SecId: ", secId, "phId: ", phId )
if ( layer.startswith( 'loStrings' ) ) :
for lyr in [ "_doubleBass", "_cello" ] :
layer1 = layer + lyr
if ( layer1 not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layer1] = []
self.midiEventsForSectionLayers[secId][layer1] += CreateMidiEventsForBass.CreateMidiEventsForStrings ( layer1, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer1] )
elif ( layer.startswith( 'midStrings' ) ) :
for lyr in [ "_viola", "_violin2" ] :
layer1 = layer + lyr
if ( layer1 not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layer1] = []
self.midiEventsForSectionLayers[secId][layer1] += CreateMidiEventsForBass.CreateMidiEventsForStrings ( layer1, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer1] )
elif ( layer.startswith( 'hiStrings' ) ) :
for lyr in [ "_violin1" ] :
layer1 = layer + lyr
if ( layer1 not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layer1] = []
self.midiEventsForSectionLayers[secId][layer1] += CreateMidiEventsForBass.CreateMidiEventsForStrings ( layer1, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer1] )
elif ( layer.startswith( 'arpStrings' ) ) :
lyr = random.choice ( [ "_arp0", "_arp1", "_arp2" ] ) # pick one of the arp layers randomly
layer1 = layer + lyr
if ( layer not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layer] = []
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEventsForStrings ( layer1, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer1])
elif ( layer.startswith ( 'drums' ) ) :
if ( layer not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layer] = []
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEventsForPercussions ( layer, density, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['percussionFills'], sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer] )
if ( not processFillForPhrase and fillsFlag ) :
layer = 'fillsForDrums'
if ( layer not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layer] = []
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEventsForPercussionFills ( layer, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['percussionFills'], sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer] )
processFillForPhrase = True
elif ( layer.startswith( 'rightPiano' ) ) :
lyr = random.choice ( [ "_rp0", "_rp1", "_rp2" ] ) # pick one of the right piano layers randomly
layer1 = layer + lyr
#print ( "SecId: ", secId, "phId: ", phId, "layer: ", layer1 )
if ( layer not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layer] = []
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEventsForStrings ( layer1, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer1])
else :
if ( layer not in self.midiEventsForSectionLayers[secId] ) :
self.midiEventsForSectionLayers[secId][layer] = []
self.midiEventsForSectionLayers[secId][layer] += CreateMidiEventsForBass.CreateMidiEventsForStrings ( layer, uniqCPId, secId, phId, repCount, numChordsInSection, sectionsObj.sections[secId]['phrases'][phId], self.movement['layers'][uniqCPId][layer] )
self.midiEventsForLayers = collections.OrderedDict()
for secId in self.midiEventsForSectionLayers :
for layer in self.midiEventsForSectionLayers[secId] :
#print("Layer: ",layer,"len: ",len(self.midiEventsForLayers))
if (self.midiEventsForLayers.get(layer,"0") == "0" ) :
#print(layer)
self.midiEventsForLayers[layer] = []
for secId in self.midiEventsForSectionLayers :
for layer in self.midiEventsForSectionLayers[secId] :
self.midiEventsForLayers[layer].extend(self.midiEventsForSectionLayers[secId][layer])
#if ( layer == 'bass1' or layer == 'bass2' or layer == 'mel5' or layer == 'piano1' or layer == 'rhythmChords' ) :
# CreateMidiEventsForBass.CreateMidiFileForBass ( self.id, secId, layer, self.midiEventsForSectionLayers[secId][layer] )
if ( 0 and layer.startswith('mel5High') ) :
print ( "Section: ", secId, "Layer: ", layer )
for ev in self.midiEventsForSectionLayers[secId][layer] :
print ( ev )
print()
if self.oneMidiPerLayer:
for layer in self.midiEventsForLayers :
CreateMidiEventsForBass.CreateMidiFileForBass ( self.id, 1, layer, self.midiEventsForLayers[layer], self.outdir )
else:
for secId in self.midiEventsForSectionLayers :
for layer in self.midiEventsForSectionLayers[secId] :
CreateMidiEventsForBass.CreateMidiFileForBass ( self.id, secId, layer, self.midiEventsForSectionLayers[secId][layer], self.outdir )
#if ( layer == 'bass1' or layer == 'bass2' or layer == 'mel5' or layer == 'piano1' or layer == 'rhythmChords' ) :
# CreateMidiEventsForBass.CreateMidiFileForBass ( self.id, secId, layer, self.midiEventsForSectionLayers[secId][layer] )
if ( 0 and layer.startswith('mel5High') ) :
print ( "Section: ", secId, "Layer: ", layer )
for ev in self.midiEventsForSectionLayers[secId][layer] :
print ( ev )
print()