-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
263 lines (212 loc) · 6.77 KB
/
main.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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# import time
# import pandas as pd
from utils import FamilyParser
from braid import *
import copy
START_YEAR = 1990 # tamir
END_YEAR = 2021
TEMPO = 200
family_chord = E3, DOM
mourning_chord = E3, MIN
data_path = "elazar_family.csv"
# START_YEAR = 1982 # keren
# END_YEAR = 2006
# TEMPO = 180
# family_chord = D3, MAJ
# mourning_chord = E3, MIN
# data_path = "sch_family.csv"
member_passed = False
vel = 1
def counter(func):
def wrapped(*args, **kwargs):
if wrapped.year == END_YEAR:
if data_path == "sch_family.csv":
stop()
clear()
return
wrapped.year += 1
print(wrapped.year)
return func(*args, wrapped.year, **kwargs)
wrapped.year = START_YEAR - 1
return wrapped
@counter
def update_all_patterns(curr_year):
global family
global_pattern = create_global_pattern(curr_year)
for memb in family:
memb_num = memb.get_ref_num()
personal_pat = global_to_personal(copy.deepcopy(global_pattern), memb_num)
memb.get_thread().pattern = personal_pat
@counter
def update_all_patterns_3rd(curr_year):
global family
global_pattern = create_global_pattern(curr_year)
for memb in family:
if memb.get_birth().year > curr_year:
continue
personal_pat = copy.deepcopy(global_pattern)
if memb.passed(curr_year):
update_deceased_pattern(memb, personal_pat)
else:
memb_num = memb.get_ref_num()
memb_thread = memb.get_thread()
def weak(n):
def f(memb_thread):
if member_passed:
memb_thread.velocity = 0.3
return n
else:
memb_thread.velocity = 0.5
return n
return f
def reg(n):
def f(memb_thread):
memb_thread.velocity = 1
return n
return f
for i in range(4):
if not personal_pat[i]:
personal_pat[i] = [0]
else:
personal_pat[i] = [reg(i) if i == memb_num else weak(memb_num) for i in personal_pat[i]]
memb_thread.pattern = personal_pat
def update_deceased_pattern(member, pattern):
memb_thread = member.get_thread()
def reg(n):
def f(memb_thread):
global TEMPO, vel
if TEMPO > 100:
TEMPO = TEMPO / 4
tempo(TEMPO)
if vel > 0.5:
vel = vel - 0.1
# memb_thread.velocity = vel
if vel <= 0.6:
stop()
clear()
return n
return f
for i in range(4):
pattern[i] = [0]
pattern[3].append(reg(-1))
memb_thread.pattern = pattern
@counter
def update_all_patterns_4rd(curr_year):
global family
global_pattern = create_global_pattern(curr_year)
for memb in family:
if memb.get_birth().year > curr_year:
continue
memb_num = memb.get_ref_num()
memb_thread = memb.get_thread()
personal_pat = copy.deepcopy(global_pattern)
def weak(n):
def f(memb_thread):
memb_thread.velocity = 0.8
return n
return f
def reg(n):
def f(memb_thread):
memb_thread.velocity = 1
return n
return f
for i in range(4):
if not personal_pat[i]:
personal_pat[i] = 0
elif memb_num in personal_pat[i]:
personal_pat[i] = reg(memb_num)
else:
personal_pat[i] = weak(memb_num)
memb_thread.pattern = personal_pat
def global_to_personal(pattern, mem_num):
for i in range(4):
if not pattern[i]:
pattern[i] = 0
else:
pattern[i] = [i if i == mem_num else 0 for i in pattern[i]]
return pattern
def update_personal_pattern(mem, curr_year):
q1, q2, q3, q4 = [0] * 4
mem_thread = mem.get_thread()
mem_birth_year = mem.get_birth().year
mem_birth_month = mem.get_birth().month
mem_num = mem.get_ref_num()
if curr_year < mem_birth_year:
pass
else:
if mem_birth_month in [1, 2, 3]:
q1 = mem_num
elif mem_birth_month in [4, 5, 6]:
q2 = mem_num
elif mem_birth_month in [7, 8, 9]:
q3 = mem_num
else:
q4 = mem_num
mem_thread.pattern = [q1, q2, q3, q4]
return
def create_global_pattern(curr_year):
global family
q1, q2, q3, q4 = [], [], [], []
for mem in family:
mem_birth_year = mem.get_birth().year
mem_birth_month = mem.get_birth().month
mem_num = mem.get_ref_num()
if curr_year < mem_birth_year:
pass
else:
if mem_birth_month in [1, 2, 3]:
q1.append(mem_num)
elif mem_birth_month in [4, 5, 6]:
q2.append(mem_num)
elif mem_birth_month in [7, 8, 9]:
q3.append(mem_num)
else:
q4.append(mem_num)
if mem.passed(curr_year):
global member_passed
member_passed = True
# if mem.passed(curr_year):
# death_month = mem.get_death().month
# mem_num = (-1) * mem_num
# if death_month in [1, 2, 3]:
# q1.append(mem_num)
# elif death_month in [4, 5, 6]:
# q2.append(mem_num)
# elif death_month in [7, 8, 9]:
# q3.append(mem_num)
# else:
# q4.append(mem_num)
return [q1, q2, q3, q4]
parser = FamilyParser(data_path)
family = parser.get_month_sorted_family()
tempo(TEMPO)
global_beat = Thread(10)
global_beat.chord = family_chord
global_beat.pattern = Z, Z, Z, Z
for idx, member in enumerate(family):
new_thread = Thread(idx + 1)
new_thread.chord = family_chord
new_thread.start(global_beat)
member.set_braid_thread(new_thread)
global_beat.trigger(update_all_patterns_3rd, 1, True)
global_beat.start()
play()
def run_sonification(data_path):
parser = FamilyParser(data_path)
family = parser.get_month_sorted_family()
tempo(TEMPO)
global_beat = Thread(10)
global_beat.chord = family_chord
global_beat.pattern = Z, Z, Z, Z
for idx, member in enumerate(family):
new_thread = Thread(idx + 1)
new_thread.chord = family_chord
new_thread.start(global_beat)
member.set_braid_thread(new_thread)
global_beat.trigger(update_all_patterns_3rd, 1, True)
global_beat.start()
play()
# if __name__ == "__main__":
# # family_data = sys.argv[1]
# family_data = "sch_family.csv"
# run_sonification(family_data)