-
Notifications
You must be signed in to change notification settings - Fork 1
/
NodeExtraction.py
51 lines (49 loc) · 2.54 KB
/
NodeExtraction.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
def node_extraction(notes):
# 4분의 4박자
beat1 = 2
beat2 = 4
# 코드
chord = ['f', 'f', 'f', 'f', 'c7', 'f', 'c', 'c', 'f', 'f', 'f', 'f', 'bm', 'f', 'c7', 'f', 'f', 'f', 'bm', 'f', 'c', 'c7', 'f', 'f']
# 음계
scale = ['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'a#', 'b']
chord_scale = ['c', 'cm', 'c7', 'd', 'dm', 'd7', 'e', 'em', 'e7', 'f', 'fm', 'f7', 'g', 'gm', 'g7', 'a', 'am', 'a7', 'b', 'bm', 'b7']
# 마디별 출력될 노드
node = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
value = 0
for i in notes:
# 마디안의 음 길이 계산
if (i[1] > 0):
value = value + (beat2 / i[1])
else:
value = value + (beat2 / abs(i[1])) + (beat2 / (abs(i[1]) * 2))
k = 0
for j in scale:
# 스케일과 비교해서 같을 경우 해당 노드의 자리를 1증가
if (i[0][:-1] == j):
node[k] = node[k] + 1
k = k + 1
if (value == beat1):
print(node)
node = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
value = 0
print("========================================")
chord_node = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in chord:
k = 0
for j in chord_scale:
if (i == j):
chord_node[k] = chord_node[k] + 1
print(chord_node)
chord_node = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
break
k = k + 1
song = [['c5', 8], ['r', 8], ['c5', 8], ['r', 8], ['c5', -8], ['a#4', 16], ['a4', 8], ['a#4', 8], ['c5', -8],
['c5', 16], ['c5', 8], ['d5', 8], ['c5', 4], ['r', 4], ['a#4', -8], ['a#4', 16], ['a#4', 8], ['a#4', 8],
['a4', -8], ['a4', 16], ['a4', 4], ['g4', -8], ['g4', 16], ['g4', 8], ['a4', 8], ['g4', 4], ['r', 4],
['c5', 8], ['r', 8], ['c5', 8], ['r', 8], ['c5', -8], ['a#4', 16], ['a4', 8], ['a#4', 8], ['c5', -8],
['c5', 16], ['c5', 8], ['d5', 8], ['c5', 4], ['r', 4], ['d5', -8], ['d5', 16], ['d5', 8], ['d5', 8],
['c5', -8], ['c5', 16], ['c5', 4], ['c5', -8], ['a#4', 16], ['a4', 8], ['g4', 8], ['f4', 4], ['r', 4],
['c4', -8], ['c4', 16], ['f4', 8], ['a4', 8], ['c5', -8], ['c5', 16], ['c5', 4], ['d5', -8], ['d5', 16],
['c5', 8], ['a#4', 8], ['a4', 4], ['r', 4], ['c4', -8], ['c4', 16], ['e4', 8], ['g4', 8], ['a#4', -8],
['a#4', 16], ['a#4', 4], ['a4', -8], ['a4', 16], ['g4', 8], ['g4', 8], ['f4', 4], ['r', 4]]
node_extraction(notes=song)