arbol 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/bin/arbol +25 -0
  3. data/lib/arbol.rb +45 -0
  4. data/lib/base.rb +397 -0
  5. data/lib/builder.rb +102 -0
  6. data/lib/documentation.rb +19 -0
  7. data/lib/dsl.rb +168 -0
  8. data/lib/functions/add.rb +70 -0
  9. data/lib/functions/add_constrain.rb +70 -0
  10. data/lib/functions/add_modulo.rb +70 -0
  11. data/lib/functions/analog_pin.rb +316 -0
  12. data/lib/functions/choose.rb +74 -0
  13. data/lib/functions/const.rb +63 -0
  14. data/lib/functions/create_lookup.rb +63 -0
  15. data/lib/functions/create_ref.rb +48 -0
  16. data/lib/functions/crossfade.rb +73 -0
  17. data/lib/functions/divide.rb +70 -0
  18. data/lib/functions/feedback.rb +65 -0
  19. data/lib/functions/feedback_offset.rb +69 -0
  20. data/lib/functions/gamma.rb +61 -0
  21. data/lib/functions/greater_than.rb +70 -0
  22. data/lib/functions/greater_than_equals.rb +70 -0
  23. data/lib/functions/lamp_phase.rb +39 -0
  24. data/lib/functions/less_than.rb +70 -0
  25. data/lib/functions/less_than_equals.rb +70 -0
  26. data/lib/functions/lfo_square.rb +68 -0
  27. data/lib/functions/lfo_triangle.rb +72 -0
  28. data/lib/functions/lookup.rb +86 -0
  29. data/lib/functions/max.rb +70 -0
  30. data/lib/functions/min.rb +70 -0
  31. data/lib/functions/minus.rb +70 -0
  32. data/lib/functions/modulo.rb +70 -0
  33. data/lib/functions/noise.rb +49 -0
  34. data/lib/functions/noise_pixel.rb +49 -0
  35. data/lib/functions/phasor.rb +96 -0
  36. data/lib/functions/ref.rb +34 -0
  37. data/lib/functions/scale.rb +71 -0
  38. data/lib/functions/table.rb +16 -0
  39. data/lib/functions/times.rb +70 -0
  40. data/lib/functions/triangle.rb +69 -0
  41. data/lib/templates/arduino_library.ino.erb +75 -0
  42. metadata +84 -0
@@ -0,0 +1,86 @@
1
+ class Lookup < Base
2
+ Arbol.add_mapped_class(
3
+ 'lookup',
4
+ Lookup,
5
+ %{void lookup(long index[3], long table[][3], long table_size, long out[3]) {
6
+ out[0] = table[long_mult(index[0], table_size)][0];
7
+ out[1] = table[long_mult(index[1], table_size)][1];
8
+ out[2] = table[long_mult(index[2], table_size)][2];
9
+ }}
10
+ )
11
+
12
+ attr_accessor :op1
13
+ attr_accessor :op2
14
+
15
+ def param_keys
16
+ [:index, :table]
17
+ end
18
+
19
+ def arduino_code
20
+ unless @frame_optimized
21
+ [
22
+ "lookup(#{@index.name}, #{@table}, #{tables[@table].length}, long #{@name});"
23
+ ]
24
+ else
25
+ []
26
+ end
27
+ end
28
+
29
+ def cycle_level_arduino_code
30
+ if @frame_optimized
31
+ [
32
+ "lookup(#{@index.name}, #{@table}, #{tables[@table].length}, long #{@name});"
33
+ ]
34
+ else
35
+ []
36
+ end
37
+ end
38
+
39
+ def top_level_scope_code
40
+ [
41
+ "long #{@name}[3];"
42
+ ]
43
+ end
44
+ end
45
+
46
+ module Arbol
47
+ class Documentation
48
+
49
+ def lookup
50
+ %{--
51
+ ### lookup(table\\_reference, index)
52
+
53
+ * **table\\_reference** - reference to a predefined table.
54
+ * **index** - index used to look up the value in the table.
55
+
56
+ Allows you to lookup values in a user defined table. Note that the table must be declared before it is referenced.
57
+
58
+ ```
59
+ my_table = [0, 0.5, 0.6, 0.0, 0.9];
60
+
61
+ my_lookup = lookup(
62
+ my_table,
63
+ phasor(1000)
64
+ );
65
+ ```
66
+ }
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ def resolve_table_reference(table_ref)
73
+ if $tables.has_key?(table_ref)
74
+ table_ref
75
+ else
76
+ raise "table #{table_ref} invalid"
77
+ end
78
+ end
79
+
80
+ def lookup(table, index)
81
+ {
82
+ type: 'lookup',
83
+ table: resolve_table_reference(table),
84
+ index: resolve(index)
85
+ }
86
+ end
@@ -0,0 +1,70 @@
1
+ class Maximum < Base
2
+ Arbol.add_mapped_class(
3
+ 'max',
4
+ Maximum,
5
+ %{void maximum(long op1[3], long op2[3], long out[3]) {
6
+ out[0] = max(op1[0], op2[0]);
7
+ out[1] = max(op1[1], op2[1]);
8
+ out[2] = max(op1[2], op2[2]);
9
+ }}
10
+ )
11
+
12
+ attr_accessor :op1
13
+ attr_accessor :op2
14
+
15
+ def param_keys
16
+ [:op1, :op2]
17
+ end
18
+
19
+ def arduino_code
20
+ unless @frame_optimized
21
+ [
22
+ "maximum(#{@op1.name}, #{@op2.name}, #{@name});"
23
+ ]
24
+ else
25
+ []
26
+ end
27
+ end
28
+
29
+ def cycle_level_arduino_code
30
+ if @frame_optimized
31
+ [
32
+ "maximum(#{@op1.name}, #{@op2.name}, #{@name});"
33
+ ]
34
+ else
35
+ []
36
+ end
37
+ end
38
+
39
+ def top_level_scope_code
40
+ [
41
+ "long #{@name}[3];"
42
+ ]
43
+ end
44
+ end
45
+
46
+ module Arbol
47
+ class Documentation
48
+
49
+ def max
50
+ %{--
51
+ ### max(left, right)
52
+
53
+ * **operator1**
54
+ * **operator2**
55
+
56
+ Maximum (greater) of the two operators.
57
+
58
+ }
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+ def max(op1, op2)
65
+ h = ArbolHash.new
66
+ h[:type] = 'max'
67
+ h[:op1] = resolve(op1)
68
+ h[:op2] = resolve(op2)
69
+ h
70
+ end
@@ -0,0 +1,70 @@
1
+ class Minimum < Base
2
+ Arbol.add_mapped_class(
3
+ 'min',
4
+ Minimum,
5
+ %{void minimum(long op1[3], long op2[3], long out[3]) {
6
+ out[0] = min(op1[0], op2[0]);
7
+ out[1] = min(op1[1], op2[1]);
8
+ out[2] = min(op1[2], op2[2]);
9
+ }}
10
+ )
11
+
12
+ attr_accessor :op1
13
+ attr_accessor :op2
14
+
15
+ def param_keys
16
+ [:op1, :op2]
17
+ end
18
+
19
+ def arduino_code
20
+ unless @frame_optimized
21
+ [
22
+ "minimum(#{@op1.name}, #{@op2.name}, #{@name});"
23
+ ]
24
+ else
25
+ []
26
+ end
27
+ end
28
+
29
+ def cycle_level_arduino_code
30
+ if @frame_optimized
31
+ [
32
+ "minimum(#{@op1.name}, #{@op2.name}, #{@name});"
33
+ ]
34
+ else
35
+ []
36
+ end
37
+ end
38
+
39
+ def top_level_scope_code
40
+ [
41
+ "long #{@name}[3];"
42
+ ]
43
+ end
44
+ end
45
+
46
+ module Arbol
47
+ class Documentation
48
+
49
+ def min
50
+ %{--
51
+ ### min(left, right)
52
+
53
+ * **operator1**
54
+ * **operator2**
55
+
56
+ Minimum (least) of the two operators.
57
+
58
+ }
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+ def min(op1, op2)
65
+ h = ArbolHash.new
66
+ h[:type] = 'min'
67
+ h[:op1] = resolve(op1)
68
+ h[:op2] = resolve(op2)
69
+ h
70
+ end
@@ -0,0 +1,70 @@
1
+ class Minus < Base
2
+ Arbol.add_mapped_class(
3
+ 'minus',
4
+ Minus,
5
+ %{void minus(long op1[3], long op2[3], long out[3]) {
6
+ out[0] = op1[0] - op2[0];
7
+ out[1] = op1[1] - op2[1];
8
+ out[2] = op1[2] - op2[2];
9
+ }}
10
+ )
11
+
12
+ attr_accessor :op1
13
+ attr_accessor :op2
14
+
15
+ def param_keys
16
+ [:op1, :op2]
17
+ end
18
+
19
+ def arduino_code
20
+ unless @frame_optimized
21
+ [
22
+ "minus(#{@op1.name}, #{@op2.name}, #{@name});"
23
+ ]
24
+ else
25
+ []
26
+ end
27
+ end
28
+
29
+ def cycle_level_arduino_code
30
+ if @frame_optimized
31
+ [
32
+ "minus(#{@op1.name}, #{@op2.name}, #{@name});"
33
+ ]
34
+ else
35
+ []
36
+ end
37
+ end
38
+
39
+ def top_level_scope_code
40
+ [
41
+ "long #{@name}[3];"
42
+ ]
43
+ end
44
+ end
45
+
46
+ module Arbol
47
+ class Documentation
48
+
49
+ def minus
50
+ %{--
51
+ ### minus(operator1, operator2)
52
+
53
+ * **operator1**
54
+ * **operator2**
55
+
56
+ Difference of the two operators. Can also be used with the form `operator1 - operator2`.
57
+
58
+ }
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+ def minus(op1, op2)
65
+ h = ArbolHash.new
66
+ h[:type] = 'minus'
67
+ h[:op1] = resolve(op1)
68
+ h[:op2] = resolve(op2)
69
+ h
70
+ end
@@ -0,0 +1,70 @@
1
+ class Modulo < Base
2
+ Arbol.add_mapped_class(
3
+ 'modulo',
4
+ Modulo,
5
+ %{void modulo(long op1[3], long op2[3], long out[3]) {
6
+ out[0] = op1[0] % op2[0];
7
+ out[1] = op1[1] % op2[1];
8
+ out[2] = op1[2] % op2[2];
9
+ }}
10
+ )
11
+
12
+ attr_accessor :op1
13
+ attr_accessor :op2
14
+
15
+ def param_keys
16
+ [:op1, :op2]
17
+ end
18
+
19
+ def arduino_code
20
+ unless @frame_optimized
21
+ [
22
+ "modulo(#{@op1.name}, #{@op2.name}, #{@name});"
23
+ ]
24
+ else
25
+ []
26
+ end
27
+ end
28
+
29
+ def cycle_level_arduino_code
30
+ if @frame_optimized
31
+ [
32
+ "modulo(#{@op1.name}, #{@op2.name}, #{@name});"
33
+ ]
34
+ else
35
+ []
36
+ end
37
+ end
38
+
39
+ def top_level_scope_code
40
+ [
41
+ "long #{@name}[3];"
42
+ ]
43
+ end
44
+ end
45
+
46
+ module Arbol
47
+ class Documentation
48
+
49
+ def mod
50
+ %{--
51
+ ### mod(operator1, operator2)
52
+
53
+ * **operator1**
54
+ * **operator2**
55
+
56
+ Modulo of the two operators. Can also be used with the form `operator1 % operator2`.
57
+
58
+ }
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+ def mod(op1, op2)
65
+ h = ArbolHash.new
66
+ h[:type] = 'modulo'
67
+ h[:op1] = resolve(op1)
68
+ h[:op2] = resolve(op2)
69
+ h
70
+ end
@@ -0,0 +1,49 @@
1
+ class Noise < Base
2
+ Arbol.add_mapped_class(
3
+ 'noise',
4
+ Noise,
5
+ %{void noise(long out[3]) {
6
+ out[0] = random(INTEGER_SCALE);
7
+ out[1] = random(INTEGER_SCALE);
8
+ out[2] = random(INTEGER_SCALE);
9
+ }}
10
+ )
11
+
12
+ def initialize(params)
13
+ super(params)
14
+ @frame_optimized = false
15
+ end
16
+
17
+ def arduino_code
18
+ [
19
+ "noise(#{@name});"
20
+ ]
21
+ end
22
+
23
+ def top_level_scope_code
24
+ [
25
+ "long #{@name}[3];"
26
+ ]
27
+ end
28
+ end
29
+
30
+ module Arbol
31
+ class Documentation
32
+
33
+ def noise
34
+ %{--
35
+ ### noise
36
+
37
+ Outputs a random value for RGB of each pixel.
38
+
39
+ }
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+ def noise
46
+ h = ArbolHash.new
47
+ h[:type] = 'noise'
48
+ h
49
+ end
@@ -0,0 +1,49 @@
1
+ class NoisePixel < Base
2
+ Arbol.add_mapped_class(
3
+ 'noise_pixel',
4
+ NoisePixel,
5
+ %{void noise_pixel(long out[3]) {
6
+ out[0] = random(INTEGER_SCALE);
7
+ out[1] = out[0];
8
+ out[2] = out[1];
9
+ }}
10
+ )
11
+
12
+ def initialize(params)
13
+ super(params)
14
+ @frame_optimized = false
15
+ end
16
+
17
+ def arduino_code
18
+ [
19
+ "noise_pixel(#{@name});"
20
+ ]
21
+ end
22
+
23
+ def top_level_scope_code
24
+ [
25
+ "long #{@name}[3];"
26
+ ]
27
+ end
28
+ end
29
+
30
+ module Arbol
31
+ class Documentation
32
+
33
+ def noise_pixel
34
+ %{--
35
+ ### noise\\_pixel
36
+
37
+ Outputs a random value for each pixel.
38
+
39
+ }
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+ def noise_pixel
46
+ h = ArbolHash.new
47
+ h[:type] = 'noise_pixel'
48
+ h
49
+ end