-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.py
62 lines (52 loc) · 2.69 KB
/
examples.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
from src.automata import Automata, Pause, Note, VariationFunction
c2_4 = Note("c2", 1 / 4)
c2_8 = Note("c2", 1 / 8)
e2_4 = Note("e2", 1 / 4)
e2_8 = Note("e2", 1 / 8)
a1_4 = Note("a1", 1 / 4)
a1_8 = Note("a1", 1 / 8)
f1_4 = Note("f1", 1/4)
f1_8 = Note("f1", 1/8)
p_4 = Pause(1 / 4)
p_8 = Pause(1 / 8)
def AND():
"""
Takes a musical boolean in c_2 followed by a musical boolean in e_2 and computes the AND of these two bools. The ouput is in a_2.
The musical boolean is defined by 0 = 1/8 and 1 = 1/4.
"""
AND_mva = Automata("AND")
AND_mva.add_variation_function(VariationFunction([c2_8, e2_8], [p_8, a1_8]))
AND_mva.add_variation_function(VariationFunction([c2_4, e2_8], [p_8, a1_8]))
AND_mva.add_variation_function(VariationFunction([c2_8, e2_4], [p_8, a1_8]))
AND_mva.add_variation_function(VariationFunction([c2_8, e2_8], [p_8, a1_8]))
AND_mva.add_variation_function(VariationFunction([c2_4, e2_4], [p_8, a1_4]))
AND_mva.add_theme([c2_4, e2_4])
return AND_mva
def BINARY_ADDITION():
"""
Takes a binary string in c_2 followed by a reversed binary string in e_2 and computes the addition of these two numbers. The ouput is in a_2.
The musical boolean is defined by 0 = 1/8 and 1 = 1/4.
"""
ADD_mva = Automata("Binary Adder")
# 1-bit addition
ADD_mva.add_variation_function(VariationFunction([c2_4, e2_4], [f1_4, a1_8]))
ADD_mva.add_variation_function(VariationFunction([c2_8, e2_4], [a1_4]))
ADD_mva.add_variation_function(VariationFunction([c2_4, e2_8], [a1_4]))
ADD_mva.add_variation_function(VariationFunction([c2_8, e2_8], [a1_8]))
# concat carries
ADD_mva.add_variation_function(VariationFunction([p_8, f1_4], [p_4, a1_4]))
ADD_mva.add_variation_function(VariationFunction([p_8, a1_4, f1_4], [p_4, a1_4, a1_8]))
ADD_mva.add_variation_function(VariationFunction([p_8, a1_8, f1_4], [p_4, a1_4]))
ADD_mva.add_variation_function(VariationFunction([a1_4, f1_4], [f1_4, a1_8]))
ADD_mva.add_variation_function(VariationFunction([a1_8, f1_4], [a1_4]))
# swapping
ADD_mva.add_variation_function(VariationFunction([a1_4, e2_4], [e2_4, a1_4]))
ADD_mva.add_variation_function(VariationFunction([a1_4, e2_8], [e2_8, a1_4]))
ADD_mva.add_variation_function(VariationFunction([a1_8, e2_4], [e2_4, a1_8]))
ADD_mva.add_variation_function(VariationFunction([a1_8, e2_8], [e2_8, a1_8]))
ADD_mva.add_variation_function(VariationFunction([f1_4, e2_4], [e2_4, f1_4]))
ADD_mva.add_variation_function(VariationFunction([f1_4, e2_8], [e2_8, f1_4]))
# self reproducing
for el in [c2_4, c2_8, e2_4, e2_8, a1_4, a1_8, f1_4, p_8]:
ADD_mva.add_variation_function(VariationFunction([el], [el]))
return ADD_mva