arbol 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/arbol +25 -0
- data/lib/arbol.rb +45 -0
- data/lib/base.rb +397 -0
- data/lib/builder.rb +102 -0
- data/lib/documentation.rb +19 -0
- data/lib/dsl.rb +168 -0
- data/lib/functions/add.rb +70 -0
- data/lib/functions/add_constrain.rb +70 -0
- data/lib/functions/add_modulo.rb +70 -0
- data/lib/functions/analog_pin.rb +316 -0
- data/lib/functions/choose.rb +74 -0
- data/lib/functions/const.rb +63 -0
- data/lib/functions/create_lookup.rb +63 -0
- data/lib/functions/create_ref.rb +48 -0
- data/lib/functions/crossfade.rb +73 -0
- data/lib/functions/divide.rb +70 -0
- data/lib/functions/feedback.rb +65 -0
- data/lib/functions/feedback_offset.rb +69 -0
- data/lib/functions/gamma.rb +61 -0
- data/lib/functions/greater_than.rb +70 -0
- data/lib/functions/greater_than_equals.rb +70 -0
- data/lib/functions/lamp_phase.rb +39 -0
- data/lib/functions/less_than.rb +70 -0
- data/lib/functions/less_than_equals.rb +70 -0
- data/lib/functions/lfo_square.rb +68 -0
- data/lib/functions/lfo_triangle.rb +72 -0
- data/lib/functions/lookup.rb +86 -0
- data/lib/functions/max.rb +70 -0
- data/lib/functions/min.rb +70 -0
- data/lib/functions/minus.rb +70 -0
- data/lib/functions/modulo.rb +70 -0
- data/lib/functions/noise.rb +49 -0
- data/lib/functions/noise_pixel.rb +49 -0
- data/lib/functions/phasor.rb +96 -0
- data/lib/functions/ref.rb +34 -0
- data/lib/functions/scale.rb +71 -0
- data/lib/functions/table.rb +16 -0
- data/lib/functions/times.rb +70 -0
- data/lib/functions/triangle.rb +69 -0
- data/lib/templates/arduino_library.ino.erb +75 -0
- metadata +84 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
class GreaterThan < Base
|
2
|
+
Arbol.add_mapped_class(
|
3
|
+
'greater_than',
|
4
|
+
GreaterThan,
|
5
|
+
%{void greater_than(long left[3], long right[3], long out[3]) {
|
6
|
+
if(left[0] > right[0]) { out[0] = INTEGER_SCALE; } else { out[0] = 0; }
|
7
|
+
if(left[1] > right[1]) { out[1] = INTEGER_SCALE; } else { out[1] = 0; }
|
8
|
+
if(left[2] > right[2]) { out[2] = INTEGER_SCALE; } else { out[2] = 0; }
|
9
|
+
}}
|
10
|
+
)
|
11
|
+
attr_accessor :left
|
12
|
+
attr_accessor :right
|
13
|
+
|
14
|
+
def param_keys
|
15
|
+
[:left, :right]
|
16
|
+
end
|
17
|
+
|
18
|
+
def arduino_code
|
19
|
+
unless @frame_optimized
|
20
|
+
[
|
21
|
+
"greater_than(#{@left.name}, #{@right.name}, #{@name});"
|
22
|
+
]
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def cycle_level_arduino_code
|
29
|
+
if @frame_optimized
|
30
|
+
[
|
31
|
+
"greater_than(#{@left.name}, #{@right.name}, #{@name});"
|
32
|
+
]
|
33
|
+
else
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def top_level_scope_code
|
39
|
+
[
|
40
|
+
"long #{@name}[3];"
|
41
|
+
]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Arbol
|
46
|
+
class Documentation
|
47
|
+
|
48
|
+
def greater_than
|
49
|
+
%{--
|
50
|
+
### greater\_than(left, right)
|
51
|
+
|
52
|
+
* **left** - left operand
|
53
|
+
* **right** - right operand
|
54
|
+
|
55
|
+
left > right as a logical operation returning 0 or 1.0.
|
56
|
+
Can be used in the form `left > right`.
|
57
|
+
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def greater_than(left, right)
|
65
|
+
h = ArbolHash.new
|
66
|
+
h[:type] = 'greater_than'
|
67
|
+
h[:left] = resolve(left)
|
68
|
+
h[:right] = resolve(right)
|
69
|
+
h
|
70
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class GreaterThanEquals < Base
|
2
|
+
Arbol.add_mapped_class(
|
3
|
+
'greater_than_equals',
|
4
|
+
GreaterThanEquals,
|
5
|
+
%{void greater_than_equals(long left[3], long right[3], long out[3]) {
|
6
|
+
if(left[0] >= right[0]) { out[0] = INTEGER_SCALE; } else { out[0] = 0; }
|
7
|
+
if(left[1] >= right[1]) { out[1] = INTEGER_SCALE; } else { out[1] = 0; }
|
8
|
+
if(left[2] >= right[2]) { out[2] = INTEGER_SCALE; } else { out[2] = 0; }
|
9
|
+
}}
|
10
|
+
)
|
11
|
+
attr_accessor :left
|
12
|
+
attr_accessor :right
|
13
|
+
|
14
|
+
def param_keys
|
15
|
+
[:left, :right]
|
16
|
+
end
|
17
|
+
|
18
|
+
def arduino_code
|
19
|
+
unless @frame_optimized
|
20
|
+
[
|
21
|
+
"greater_than_equals(#{@left.name}, #{@right.name}, #{@name});"
|
22
|
+
]
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def cycle_level_arduino_code
|
29
|
+
if @frame_optimized
|
30
|
+
[
|
31
|
+
"greater_than_equals(#{@left.name}, #{@right.name}, #{@name});"
|
32
|
+
]
|
33
|
+
else
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def top_level_scope_code
|
39
|
+
[
|
40
|
+
"long #{@name}[3];"
|
41
|
+
]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Arbol
|
46
|
+
class Documentation
|
47
|
+
|
48
|
+
def greater_than_equals
|
49
|
+
%{--
|
50
|
+
### greater\\_than\\_equals(left, right)
|
51
|
+
|
52
|
+
* **left** - left operand
|
53
|
+
* **right** - right operand
|
54
|
+
|
55
|
+
left >= right as a logical operation returning 0 or 1.0.
|
56
|
+
Can be used in the form `left >= right`.
|
57
|
+
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def greater_than_equals(left, right)
|
65
|
+
h = ArbolHash.new
|
66
|
+
h[:type] = 'greater_than_equals'
|
67
|
+
h[:left] = resolve(left)
|
68
|
+
h[:right] = resolve(right)
|
69
|
+
h
|
70
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class LampPhase < Base
|
2
|
+
Arbol.add_mapped_class('lamp_phase', LampPhase, nil)
|
3
|
+
|
4
|
+
def initialize(params)
|
5
|
+
super(params)
|
6
|
+
@frame_optimized = false
|
7
|
+
end
|
8
|
+
|
9
|
+
def arduino_code
|
10
|
+
[
|
11
|
+
"long #{@name}[3] = {this_phase, this_phase, this_phase};"
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
def top_level_scope_code
|
16
|
+
[]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Arbol
|
21
|
+
class Documentation
|
22
|
+
|
23
|
+
def lamp_phase
|
24
|
+
%{--
|
25
|
+
### lamp\_phase
|
26
|
+
|
27
|
+
Returns current lamp number expressed as a phase 0-~1.0.
|
28
|
+
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def lamp_phase
|
36
|
+
h = ArbolHash.new
|
37
|
+
h[:type] = 'lamp_phase'
|
38
|
+
h
|
39
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class LessThan < Base
|
2
|
+
Arbol.add_mapped_class(
|
3
|
+
'less_than',
|
4
|
+
LessThan,
|
5
|
+
%{void less_than(long left[3], long right[3], long out[3]) {
|
6
|
+
if(left[0] < right[0]) { out[0] = INTEGER_SCALE; } else { out[0] = 0; }
|
7
|
+
if(left[1] < right[1]) { out[1] = INTEGER_SCALE; } else { out[1] = 0; }
|
8
|
+
if(left[2] < right[2]) { out[2] = INTEGER_SCALE; } else { out[2] = 0; }
|
9
|
+
}}
|
10
|
+
)
|
11
|
+
attr_accessor :left
|
12
|
+
attr_accessor :right
|
13
|
+
|
14
|
+
def param_keys
|
15
|
+
[:left, :right]
|
16
|
+
end
|
17
|
+
|
18
|
+
def arduino_code
|
19
|
+
unless @frame_optimized
|
20
|
+
[
|
21
|
+
"less_than(#{@left.name}, #{@right.name}, #{@name});"
|
22
|
+
]
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def cycle_level_arduino_code
|
29
|
+
if @frame_optimized
|
30
|
+
[
|
31
|
+
"less_than(#{@left.name}, #{@right.name}, #{@name});"
|
32
|
+
]
|
33
|
+
else
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def top_level_scope_code
|
39
|
+
[
|
40
|
+
"long #{@name}[3];"
|
41
|
+
]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Arbol
|
46
|
+
class Documentation
|
47
|
+
|
48
|
+
def less_than
|
49
|
+
%{--
|
50
|
+
### less\\_than(left, right)
|
51
|
+
|
52
|
+
* **left** - left operand
|
53
|
+
* **right** - right operand
|
54
|
+
|
55
|
+
left < right as a logical operation returning 0 or 1.0.
|
56
|
+
Can be used in the form `left < right`.
|
57
|
+
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def less_than(left, right)
|
65
|
+
h = ArbolHash.new
|
66
|
+
h[:type] = 'less_than'
|
67
|
+
h[:left] = resolve(left)
|
68
|
+
h[:right] = resolve(right)
|
69
|
+
h
|
70
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class LessThanEquals < Base
|
2
|
+
Arbol.add_mapped_class(
|
3
|
+
'less_than_equals',
|
4
|
+
LessThanEquals,
|
5
|
+
%{void less_than_equals(long left[3], long right[3], long out[3]) {
|
6
|
+
if(left[0] <= right[0]) { out[0] = INTEGER_SCALE; } else { out[0] = 0; }
|
7
|
+
if(left[1] <= right[1]) { out[1] = INTEGER_SCALE; } else { out[1] = 0; }
|
8
|
+
if(left[2] <= right[2]) { out[2] = INTEGER_SCALE; } else { out[2] = 0; }
|
9
|
+
}}
|
10
|
+
)
|
11
|
+
attr_accessor :left
|
12
|
+
attr_accessor :right
|
13
|
+
|
14
|
+
def param_keys
|
15
|
+
[:left, :right]
|
16
|
+
end
|
17
|
+
|
18
|
+
def arduino_code
|
19
|
+
unless @frame_optimized
|
20
|
+
[
|
21
|
+
"less_than_equals(#{@left.name}, #{@right.name}, #{@name});"
|
22
|
+
]
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def cycle_level_arduino_code
|
29
|
+
if @frame_optimized
|
30
|
+
[
|
31
|
+
"less_than_equals(#{@left.name}, #{@right.name}, #{@name});"
|
32
|
+
]
|
33
|
+
else
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def top_level_scope_code
|
39
|
+
[
|
40
|
+
"long #{@name}[3];"
|
41
|
+
]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Arbol
|
46
|
+
class Documentation
|
47
|
+
|
48
|
+
def less_than_equals
|
49
|
+
%{--
|
50
|
+
### less\\_than\\_equals(left, right)
|
51
|
+
|
52
|
+
* **left** - left operand
|
53
|
+
* **right** - right operand
|
54
|
+
|
55
|
+
left <= right as a logical operation returning 0 or 1.0.
|
56
|
+
Can be used in the form `left <= right`.
|
57
|
+
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def less_than_equals(left, right)
|
65
|
+
h = ArbolHash.new
|
66
|
+
h[:type] = 'less_than_equals'
|
67
|
+
h[:left] = resolve(left)
|
68
|
+
h[:right] = resolve(right)
|
69
|
+
h
|
70
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
class LFOSquare < Base
|
2
|
+
Arbol.add_mapped_class(
|
3
|
+
'lfo_square',
|
4
|
+
LFOSquare,
|
5
|
+
%{long half_int_scale_vec[3] = {long(INTEGER_SCALE / 2), long(INTEGER_SCALE / 2), long(INTEGER_SCALE / 2)};
|
6
|
+
void lfo_square(long mils, long cycle_ms[3], long out[3]) {
|
7
|
+
long phase[3];
|
8
|
+
phasor(mils, cycle_ms, phase);
|
9
|
+
greater_than(phase, half_int_scale_vec, out);
|
10
|
+
}}
|
11
|
+
)
|
12
|
+
attr_accessor :cycle_ms
|
13
|
+
|
14
|
+
def param_keys
|
15
|
+
[:cycle_ms]
|
16
|
+
end
|
17
|
+
|
18
|
+
def arduino_code
|
19
|
+
unless @frame_optimized
|
20
|
+
[
|
21
|
+
"lfo_square(mils, #{@cycle_ms.name}, #{@name});"
|
22
|
+
]
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def cycle_level_arduino_code
|
29
|
+
if @frame_optimized
|
30
|
+
[
|
31
|
+
"lfo_square(mils, #{@cycle_ms.name}, #{@name});"
|
32
|
+
]
|
33
|
+
else
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def top_level_scope_code
|
39
|
+
[
|
40
|
+
"long #{@name}[3];"
|
41
|
+
]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Arbol
|
46
|
+
class Documentation
|
47
|
+
|
48
|
+
def lfo_square
|
49
|
+
%{--
|
50
|
+
### lfo\\_square(cycle\\_ms)
|
51
|
+
|
52
|
+
* **cycle\\_ms** - cycle length expressed as milliseconds
|
53
|
+
|
54
|
+
Outputs a square wave. Note that the cycle length value is interpreted literally
|
55
|
+
as milliseconds, so you should use integer constants as input.
|
56
|
+
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def lfo_square(cycle_ms)
|
64
|
+
h = ArbolHash.new
|
65
|
+
h[:type] = 'lfo_square'
|
66
|
+
h[:cycle_ms] = resolve(cycle_ms)
|
67
|
+
h
|
68
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class LFOTriangle < Base
|
2
|
+
Arbol.add_mapped_class(
|
3
|
+
'lfo_triangle',
|
4
|
+
LFOTriangle,
|
5
|
+
%{long twice_int_scale_vec[3] = {long(INTEGER_SCALE * 2), long(INTEGER_SCALE * 2), long(INTEGER_SCALE * 2)};
|
6
|
+
void lfo_triangle(long mils, long cycle_ms[3], long out[3]) {
|
7
|
+
long phase[3];
|
8
|
+
phasor(mils, cycle_ms, phase);
|
9
|
+
long times_result[3];
|
10
|
+
times(phase, twice_int_scale_vec, times_result);
|
11
|
+
if(times_result[0] > INTEGER_SCALE) { out[0] = (twice_int_scale_vec[0] - times_result[0]); } else { out[0] = times_result[0]; }
|
12
|
+
if(times_result[1] > INTEGER_SCALE) { out[1] = (twice_int_scale_vec[1] - times_result[1]); } else { out[1] = times_result[1]; }
|
13
|
+
if(times_result[2] > INTEGER_SCALE) { out[2] = (twice_int_scale_vec[2] - times_result[2]); } else { out[2] = times_result[2]; }
|
14
|
+
}}
|
15
|
+
)
|
16
|
+
attr_accessor :cycle_ms
|
17
|
+
|
18
|
+
def param_keys
|
19
|
+
[:cycle_ms]
|
20
|
+
end
|
21
|
+
|
22
|
+
def arduino_code
|
23
|
+
unless @frame_optimized
|
24
|
+
[
|
25
|
+
"lfo_triangle(mils, #{@cycle_ms.name}, #{@name});"
|
26
|
+
]
|
27
|
+
else
|
28
|
+
[]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def cycle_level_arduino_code
|
33
|
+
if @frame_optimized
|
34
|
+
[
|
35
|
+
"lfo_triangle(mils, #{@cycle_ms.name}, #{@name});"
|
36
|
+
]
|
37
|
+
else
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def top_level_scope_code
|
43
|
+
[
|
44
|
+
"long #{@name}[3];"
|
45
|
+
]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module Arbol
|
50
|
+
class Documentation
|
51
|
+
|
52
|
+
def lfo_triangle
|
53
|
+
%{--
|
54
|
+
### lfo\\_triangle(cycle\\_ms)
|
55
|
+
|
56
|
+
* **cycle\\_ms** - cycle length expressed as milliseconds
|
57
|
+
|
58
|
+
Outputs a triangle wave. Note that the cycle length value is interpreted literally
|
59
|
+
as milliseconds, so you should use integer constants as input.
|
60
|
+
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def lfo_triangle(cycle_ms)
|
68
|
+
h = ArbolHash.new
|
69
|
+
h[:type] = 'lfo_triangle'
|
70
|
+
h[:cycle_ms] = resolve(cycle_ms)
|
71
|
+
h
|
72
|
+
end
|