scruby 0.2.7

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 (69) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +53 -0
  5. data/README.rdoc +65 -0
  6. data/Rakefile +10 -0
  7. data/TODO.markdown +3 -0
  8. data/examples/example.rb +73 -0
  9. data/lib/scruby/buffer.rb +153 -0
  10. data/lib/scruby/bus.rb +67 -0
  11. data/lib/scruby/control_name.rb +29 -0
  12. data/lib/scruby/core_ext/array.rb +44 -0
  13. data/lib/scruby/core_ext/delegator_array.rb +44 -0
  14. data/lib/scruby/core_ext/fixnum.rb +8 -0
  15. data/lib/scruby/core_ext/numeric.rb +25 -0
  16. data/lib/scruby/core_ext/object.rb +23 -0
  17. data/lib/scruby/core_ext/proc.rb +11 -0
  18. data/lib/scruby/core_ext/string.rb +5 -0
  19. data/lib/scruby/core_ext/symbol.rb +5 -0
  20. data/lib/scruby/core_ext/typed_array.rb +54 -0
  21. data/lib/scruby/env.rb +93 -0
  22. data/lib/scruby/group.rb +24 -0
  23. data/lib/scruby/node.rb +102 -0
  24. data/lib/scruby/server.rb +182 -0
  25. data/lib/scruby/synth.rb +50 -0
  26. data/lib/scruby/synthdef.rb +109 -0
  27. data/lib/scruby/ticker.rb +92 -0
  28. data/lib/scruby/ugens/buffer_read_write.rb +98 -0
  29. data/lib/scruby/ugens/demand.rb +9 -0
  30. data/lib/scruby/ugens/disk_in_out.rb +33 -0
  31. data/lib/scruby/ugens/env_gen.rb +38 -0
  32. data/lib/scruby/ugens/in_out.rb +46 -0
  33. data/lib/scruby/ugens/multi_out.rb +53 -0
  34. data/lib/scruby/ugens/operation_indices.yaml +92 -0
  35. data/lib/scruby/ugens/operation_ugens.rb +63 -0
  36. data/lib/scruby/ugens/panner.rb +137 -0
  37. data/lib/scruby/ugens/ugen.rb +173 -0
  38. data/lib/scruby/ugens/ugen_defs.yaml +3123 -0
  39. data/lib/scruby/ugens/ugen_operations.rb +57 -0
  40. data/lib/scruby/ugens/ugens.rb +95 -0
  41. data/lib/scruby/version.rb +3 -0
  42. data/lib/scruby.rb +65 -0
  43. data/scruby.gemspec +27 -0
  44. data/spec/buffer_read_write_spec.rb +333 -0
  45. data/spec/buffer_spec.rb +199 -0
  46. data/spec/bus_spec.rb +184 -0
  47. data/spec/core_ext/core_ext_spec.rb +120 -0
  48. data/spec/core_ext/delegator_array_spec.rb +144 -0
  49. data/spec/core_ext/typed_array_spec.rb +95 -0
  50. data/spec/demand_spec.rb +81 -0
  51. data/spec/disk_in_out_spec.rb +138 -0
  52. data/spec/env_gen_spec.rb +23 -0
  53. data/spec/env_spec.rb +73 -0
  54. data/spec/group_spec.rb +71 -0
  55. data/spec/helper.rb +20 -0
  56. data/spec/in_out_spec.rb +127 -0
  57. data/spec/integration_spec.rb +88 -0
  58. data/spec/multiout_ugen_spec.rb +86 -0
  59. data/spec/node_spec.rb +112 -0
  60. data/spec/operation_ugens_spec.rb +196 -0
  61. data/spec/panner_spec.rb +271 -0
  62. data/spec/server.rb +12 -0
  63. data/spec/server_spec.rb +198 -0
  64. data/spec/synth_spec.rb +103 -0
  65. data/spec/synthdef_spec.rb +267 -0
  66. data/spec/ugen_operations_spec.rb +100 -0
  67. data/spec/ugen_spec.rb +356 -0
  68. data/spec/ugens_spec.rb +65 -0
  69. metadata +207 -0
@@ -0,0 +1,98 @@
1
+ module Scruby
2
+ module Ugens
3
+ class PlayBuf < Ugen
4
+ include MultiOut
5
+
6
+ class << self
7
+ def kr channels, bufnum = 0, rate = 1.0, trigger = 1.0, start = 0.0, loop = 0.0, doneAction = 0
8
+ new :control, channels, bufnum, rate, trigger, start, loop, doneAction
9
+ end
10
+
11
+ def ar channels, bufnum = 0, rate = 1.0, trigger = 1.0, start = 0.0, loop = 0.0, doneAction = 0;
12
+ new :audio, channels, bufnum, rate, trigger, start, loop, doneAction
13
+ end
14
+ named_args_for :kr, :ar
15
+ end
16
+ end
17
+
18
+ class TGrains < Ugen
19
+ include MultiOut
20
+
21
+ def initialize rate, channels, *inputs
22
+ raise ArgumentError.new("#{ self.class } instance needs at least two channels.") unless channels > 1
23
+ super
24
+ end
25
+
26
+ class << self
27
+ def ar channels, trigger = 0, bufnum = 0, rate = 1, center_pos = 0, dur = 0.1, pan = 0, amp = 0.1, interp = 4
28
+ new :audio, channels, trigger, bufnum, rate, center_pos, dur, pan, amp, interp
29
+ end
30
+ named_args_for :ar
31
+ end
32
+ end
33
+
34
+ class BufRd < Ugen
35
+ include MultiOut
36
+
37
+ class << self
38
+ def kr channels, bufnum = 0, phase = 0.0, loop = 1.0, interpolation = 2
39
+ new :control, channels, bufnum, phase, loop, interpolation
40
+ end
41
+
42
+ def ar channels, bufnum = 0, phase = 0.0, loop = 1.0, interpolation = 2
43
+ new :audio, channels, bufnum, phase, loop, interpolation
44
+ end
45
+ named_args_for :kr, :ar
46
+ end
47
+ end
48
+
49
+ class BufWr < Ugen
50
+ class << self
51
+ def kr input, bufnum = 0, phase = 0.0, loop = 1.0
52
+ new :control, bufnum, phase, loop, *input.to_array
53
+ end
54
+
55
+ def ar input, bufnum = 0, phase = 0.0, loop = 1.0
56
+ new :audio, bufnum, phase, loop, *input.to_array
57
+ end
58
+ named_args_for :kr, :ar
59
+ end
60
+ end
61
+
62
+ class RecordBuf < Ugen
63
+ class << self
64
+ def kr input, bufnum = 0, offset = 0.0, rec_level = 1.0, pre_level = 0.0, run = 1.0, loop = 1.0, trigger = 1.0, doneAction=0
65
+ new :control, bufnum, offset, rec_level, pre_level, run, loop, trigger, doneAction, *input.to_array
66
+ end
67
+
68
+ def ar input, bufnum = 0, offset = 0.0, rec_level = 1.0, pre_level = 0.0, run = 1.0, loop = 1.0, trigger = 1.0, doneAction=0
69
+ new :audio, bufnum, offset, rec_level, pre_level, run, loop, trigger, doneAction, *input.to_array
70
+ end
71
+ named_args_for :kr, :ar
72
+ end
73
+ end
74
+
75
+ class ScopeOut < Ugen
76
+ class << self
77
+ def kr input, bufnum = 0
78
+ new :control, bufnum, *input.to_array
79
+ end
80
+
81
+ def ar input, bufnum = 0
82
+ new :audio, bufnum, *input.to_array
83
+ end
84
+ named_args_for :kr, :ar
85
+ end
86
+ end
87
+
88
+ class Tap < Ugen
89
+ class << self
90
+ def ar bufnum = 0, num_channels = 1, delay_time = 0.2
91
+ PlayBuf.ar num_channels, bufnum, 1, 0, SampleRate.ir.neg * 3, 1
92
+ end
93
+ named_args_for :ar
94
+ end
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,9 @@
1
+ module Scruby
2
+ module Ugens
3
+ class Demand < Ugen
4
+ include MultiOut
5
+
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ module Scruby
2
+ module Ugens
3
+ class DiskOut < Ugen
4
+ def output_specs; []; end
5
+ def channels; []; end
6
+
7
+ class << self
8
+ def ar bufnum, *inputs
9
+ inputs.peel!
10
+ new :audio, bufnum, *inputs
11
+ 0.0
12
+ end
13
+ end
14
+ end
15
+
16
+ class DiskIn < Ugen
17
+ include MultiOut
18
+ def self.ar channels, bufnum, loop = 0
19
+ new :audio, channels, bufnum, loop
20
+ end
21
+ end
22
+
23
+ class VDiskIn < Ugen
24
+ include MultiOut
25
+ class << self
26
+ def ar channels, bufnum, rate = 1, loop = 0, send_id = 0
27
+ new :audio, channels, bufnum, rate, loop, send_id
28
+ end
29
+ named_args_for :ar
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ module Scruby
2
+ module Ugens
3
+ # Done Actions:
4
+ #
5
+ # * 0 do nothing when the UGen is finished
6
+ # * 1 pause the enclosing synth, but do not free it
7
+ # * 2 free the enclosing synth
8
+ # * 3 free both this synth and the preceding node
9
+ # * 4 free both this synth and the following node
10
+ # * 5 free this synth; if the preceding node is a group then do g_freeAll on it, else free it
11
+ # * 6 free this synth; if the following node is a group then do g_freeAll on it, else free it
12
+ # * 7 free this synth and all preceding nodes in this group
13
+ # * 8 free this synth and all following nodes in this group
14
+ # * 9 free this synth and pause the preceding node
15
+ # * 10 free this synth and pause the following node
16
+ # * 11 free this synth and if the preceding node is a group then do g_deepFree on it, else free it
17
+ # * 12 free this synth and if the following node is a group then do g_deepFree on it, else free it
18
+ # * 13 free this synth and all other nodes in this group (before and after)
19
+ # * 14 free the enclosing group and all nodes within it (including this synth)
20
+ class EnvGen < Ugen
21
+ class << self
22
+ # New EnvGen with :audio rate, inputs should be valid Ugen inputs or Ugens, arguments can be passed as an options hash or in the given order
23
+ def ar envelope, gate = 1, levelScale = 1, levelBias = 0, timeScale = 1, doneAction = 0
24
+ new :audio, gate, levelScale, levelBias, timeScale, doneAction, *envelope.to_array
25
+ end
26
+ # New EnvGen with :control rate, inputs should be valid Ugen inputs or Ugens, arguments can be passed as an options hash or in the given order
27
+ def kr envelope, gate = 1, levelScale = 1, levelBias = 0, timeScale = 1, doneAction = 0
28
+ new :control, gate, levelScale, levelBias, timeScale, doneAction, *envelope.to_array
29
+ end
30
+
31
+ named_arguments_for :ar, :kr
32
+ private
33
+ def new *args; super; end
34
+ end
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,46 @@
1
+ module Scruby
2
+ module Ugens
3
+ class In < Ugen
4
+ include MultiOut
5
+
6
+ class << self
7
+ # New In with :audio rate, inputs should be valid Ugen inputs or Ugens, arguments can be passed as an options hash or in the given order
8
+ def ar bus, channels = 1
9
+ new :audio, channels, bus
10
+ end
11
+ # New In with :control rate, inputs should be valid Ugen inputs or Ugens, arguments can be passed as an options hash or in the given order
12
+ def kr bus, channels = 1
13
+ new :control, channels, bus
14
+ end
15
+ end
16
+ end
17
+
18
+ class Out < Ugen
19
+ # ar and kr should be use for instantiation
20
+ def initialize *args
21
+ super
22
+ @channels = []
23
+ end
24
+
25
+ #:nodoc:
26
+ def output_specs; []; end
27
+
28
+ class << self
29
+ # New Out with :audio rate, inputs should be valid Ugen inputs or Ugens, arguments can be passed as an options hash or in the given order
30
+ def ar bus, *inputs
31
+ inputs.peel!
32
+ new :audio, bus, *inputs; 0.0 #Out has no output
33
+ end
34
+
35
+ # New Out with :control rate, inputs should be valid Ugen inputs or Ugens, arguments can be passed as an options hash or in the given order
36
+ def kr bus, *inputs
37
+ inputs.peel!
38
+ new :control, bus, *inputs; 0.0 #Out has no output
39
+ end
40
+ end
41
+ end
42
+
43
+ class ReplaceOut < Out
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ module Scruby
2
+ module Ugens
3
+ module MultiOut #:nodoc:
4
+ def self.included base
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ def initialize rate, channels, *inputs
9
+ super rate, *inputs
10
+ @channels = Array === channels ? channels : (0...channels).map{ |i| OutputProxy.new rate, self, i }
11
+ @channels = @channels.to_da
12
+ end
13
+
14
+ def output_specs
15
+ channels.output_specs.flatten
16
+ end
17
+
18
+ module ClassMethods
19
+ private
20
+ def new rate, channels, *inputs
21
+ instantiated = super
22
+ Array === instantiated ? instantiated : instantiated.channels
23
+ end
24
+ end
25
+ end
26
+
27
+ class OutputProxy < Ugen #:nodoc:
28
+ attr_reader :source, :control_name, :output_index
29
+ class << self; public :new; end
30
+
31
+ def initialize rate, source, output_index, name = nil
32
+ super rate
33
+ @source, @control_name, @output_index = source, name, output_index
34
+ end
35
+
36
+ def index; @source.index; end
37
+
38
+ def add_to_synthdef; end
39
+ end
40
+
41
+ class Control < Ugen #:nodoc:
42
+ include MultiOut
43
+
44
+ def initialize rate, *names
45
+ super rate, names.collect_with_index{ |n, i| OutputProxy.new rate, self, i, n }
46
+ end
47
+
48
+ def self.and_proxies_from names
49
+ new names.first.rate, *names
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,92 @@
1
+
2
+ binary:
3
+ !ruby/symbol +: 0
4
+ !ruby/symbol -: 1
5
+ !ruby/symbol *: 2
6
+ !ruby/symbol div: 3
7
+ !ruby/symbol /: 4
8
+ !ruby/symbol mod: 5
9
+ !ruby/symbol <=: 10
10
+ !ruby/symbol >=: 11
11
+ !ruby/symbol minimum: 12
12
+ !ruby/symbol maximum: 13 #can't be called max because there is an array method calle maximum
13
+ !ruby/symbol lcm: 17
14
+ !ruby/symbol gcd: 18
15
+ !ruby/symbol round: 19
16
+ !ruby/symbol roundUp: 20
17
+ !ruby/symbol trunc: 21
18
+ !ruby/symbol atan2: 22
19
+ !ruby/symbol hypot: 23
20
+ !ruby/symbol hypotApx: 24
21
+ !ruby/symbol pow: 25
22
+ !ruby/symbol leftShift: 26
23
+ !ruby/symbol rightShift: 27
24
+ !ruby/symbol unsignedRightShift: 28
25
+ !ruby/symbol ring1: 30
26
+ !ruby/symbol ring2: 31
27
+ !ruby/symbol ring3: 32
28
+ !ruby/symbol ring4: 33
29
+ !ruby/symbol difsqr: 34
30
+ !ruby/symbol sumsqr: 35
31
+ !ruby/symbol sqrsum: 36
32
+ !ruby/symbol sqrdif: 37
33
+ !ruby/symbol absdif: 38
34
+ !ruby/symbol thresh: 39
35
+ !ruby/symbol amclip: 40
36
+ !ruby/symbol scaleneg: 41
37
+ !ruby/symbol clip2: 42
38
+ !ruby/symbol excess: 43
39
+ !ruby/symbol fold2: 44
40
+ !ruby/symbol wrap2: 45
41
+ !ruby/symbol rrand: 47
42
+ !ruby/symbol exprand: 48
43
+
44
+ unary:
45
+ !ruby/symbol neg: 0
46
+ !ruby/symbol bitNot: 4
47
+ !ruby/symbol abs: 5
48
+ !ruby/symbol asFloat: 6
49
+ !ruby/symbol ceil: 8
50
+ !ruby/symbol floor: 9
51
+ !ruby/symbol frac: 10
52
+ !ruby/symbol sign: 11
53
+ !ruby/symbol squared: 12
54
+ !ruby/symbol cubed: 13
55
+ !ruby/symbol sqrt: 14
56
+ !ruby/symbol exp: 15
57
+ !ruby/symbol reciprocal: 16
58
+ !ruby/symbol midicps: 17
59
+ !ruby/symbol cpsmidi: 18
60
+ !ruby/symbol midiratio: 19
61
+ !ruby/symbol ratiomidi: 20
62
+ !ruby/symbol dbamp: 21
63
+ !ruby/symbol ampdb: 22
64
+ !ruby/symbol octcps: 23
65
+ !ruby/symbol cpsoct: 24
66
+ !ruby/symbol log: 25
67
+ !ruby/symbol log2: 26
68
+ !ruby/symbol log10: 27
69
+ !ruby/symbol sin: 28
70
+ !ruby/symbol cos: 29
71
+ !ruby/symbol tam: 30
72
+ !ruby/symbol asin: 31
73
+ !ruby/symbol acos: 32
74
+ !ruby/symbol atan: 33
75
+ !ruby/symbol sinh: 34
76
+ !ruby/symbol cosh: 35
77
+ !ruby/symbol tanh: 36
78
+ !ruby/symbol rand: 37
79
+ !ruby/symbol rand2: 38
80
+ !ruby/symbol linrand: 39
81
+ !ruby/symbol bilinrand: 40
82
+ !ruby/symbol sum3rand: 41
83
+ !ruby/symbol distort: 42
84
+ !ruby/symbol softclip: 43
85
+ !ruby/symbol coin: 44
86
+ !ruby/symbol rectWindow: 48
87
+ !ruby/symbol hanWindow: 49
88
+ !ruby/symbol welWindow: 50
89
+ !ruby/symbol triWindow: 51
90
+ !ruby/symbol ramp: 52
91
+ !ruby/symbol scurve: 53
92
+
@@ -0,0 +1,63 @@
1
+ module Scruby
2
+ module Ugens
3
+
4
+ class BasicOpUgen < Ugen #:nodoc:
5
+ attr_accessor :operator
6
+
7
+ class << self
8
+ def new operator, *inputs
9
+ obj = super get_rate(inputs), inputs
10
+ set_operator_for obj, operator
11
+ obj
12
+ end
13
+
14
+ private
15
+ #:nodoc:
16
+ def set_operator_for input, operator
17
+ input.kind_of?(Array) ? input.each{ |element| set_operator_for element, operator } : input.operator = operator
18
+ end
19
+
20
+ #:nodoc:
21
+ def get_rate *inputs
22
+ max_index = inputs.flatten.collect{ |ugen| Ugen::RATES.index ugen.rate }.max
23
+ Ugen::RATES[max_index]
24
+ end
25
+ end
26
+ end
27
+
28
+ class UnaryOpUGen < BasicOpUgen
29
+ def self.new operator, input
30
+ super
31
+ end
32
+
33
+ def special_index
34
+ UgenOperations::UNARY[operator.to_sym]
35
+ end
36
+ end
37
+
38
+ class BinaryOpUGen < BasicOpUgen
39
+ def self.new operator, left, right
40
+ super
41
+ end
42
+
43
+ def special_index
44
+ UgenOperations::BINARY[operator.to_sym]
45
+ end
46
+ end
47
+
48
+ class MulAdd < Ugen
49
+ def self.new input, mul, add
50
+ no_mul = mul == 1.0
51
+ minus = mul == -1.0
52
+ return add if mul == 0
53
+ return input if no_mul and add == 0
54
+ return input.neg if minus and add == 0
55
+ return input * mul if add == 0
56
+ return add - input if minus
57
+ return input + add if no_mul
58
+ super input.rate, input, mul, add
59
+ end
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,137 @@
1
+ module Scruby
2
+ module Ugens
3
+ class Pan2 < Ugen
4
+ include MultiOut
5
+
6
+ class << self
7
+ def ar input, pos = 0.0, level = 1.0
8
+ new :audio, 2, input, pos, level
9
+ end
10
+
11
+ def kr input, pos = 0.0, level = 1.0
12
+ new :control, 2, input, pos, level
13
+ end
14
+ named_args_for :ar, :kr
15
+ end
16
+ end
17
+
18
+ class LinPan2 < Pan2; end
19
+
20
+ class Pan4 < Ugen
21
+ include MultiOut
22
+
23
+ class << self
24
+ def ar input, xpos = 0.0, ypos = 0.0, level = 1.0
25
+ new :audio, 4, input, xpos, ypos, level
26
+ end
27
+
28
+ def kr input, xpos = 0.0, ypos = 0.0, level = 1.0
29
+ new :control, 4, input, xpos, ypos, level
30
+ end
31
+ named_args_for :ar, :kr
32
+ end
33
+ end
34
+
35
+ class Balance2 < Ugen
36
+ include MultiOut
37
+
38
+ class << self
39
+ def ar left, right, pos = 0.0, level = 1.0
40
+ new :audio, 2, left, right, pos, level
41
+ end
42
+
43
+ def kr left, right, pos = 0.0, level = 1.0
44
+ new :control, 2, left, right, pos, level
45
+ end
46
+ named_args_for :ar, :kr
47
+ end
48
+ end
49
+
50
+ class Rotate2 < Ugen
51
+ include MultiOut
52
+
53
+ class << self
54
+ def ar x, y, pos = 0.0
55
+ new :audio, 2, x, y, pos
56
+ end
57
+
58
+ def kr x, y, pos = 0.0
59
+ new :control, 2, x, y, pos
60
+ end
61
+ end
62
+ end
63
+
64
+ class PanB < Ugen
65
+ include MultiOut
66
+
67
+ class << self
68
+ def ar input, azimuth = 0, elevation = 0, gain = 1
69
+ new :audio, 4, input, azimuth, elevation, gain
70
+ end
71
+
72
+ def kr input, azimuth = 0, elevation = 0, gain = 1
73
+ new :control, 4, input, azimuth, elevation, gain
74
+ end
75
+ named_args_for :ar, :kr
76
+ end
77
+ end
78
+
79
+ class PanB2 < Ugen
80
+ include MultiOut
81
+
82
+ class << self
83
+ def ar input, azimuth = 0, gain = 1
84
+ new :audio, 3, input, azimuth, gain
85
+ end
86
+
87
+ def kr input, azimuth = 0, gain = 1
88
+ new :control, 3, input, azimuth, gain
89
+ end
90
+ named_args_for :ar, :kr
91
+ end
92
+ end
93
+
94
+ class BiPanB2 < Ugen
95
+ include MultiOut
96
+
97
+ class << self
98
+ def ar a, b, azimuth, gain = 1
99
+ new :audio, 3, a, b, azimuth, gain
100
+ end
101
+
102
+ def kr a, b, azimuth, gain = 1
103
+ new :control, 3, a, b, azimuth, gain
104
+ end
105
+ end
106
+ end
107
+
108
+ class DecodeB2 < Ugen
109
+ include MultiOut
110
+
111
+ class << self
112
+ def ar num_channels, w, x, y, orientation = 0.5
113
+ new :audio, num_channels, w, x, y, orientation
114
+ end
115
+
116
+ def kr num_channels, w, x, y, orientation = 0.5
117
+ new :control, num_channels, w, x, y, orientation
118
+ end
119
+ end
120
+ end
121
+
122
+ class PanAz < Ugen
123
+ include MultiOut
124
+
125
+ class << self
126
+ def ar num_channels, input, pos = 0.0, level = 1.0, width = 2.0, orientation = 0.5
127
+ new :audio, num_channels, input, pos, level, width, orientation
128
+ end
129
+
130
+ def kr num_channels, input, pos = 0.0, level = 1.0, width = 2.0, orientation = 0.5
131
+ new :control, num_channels, input, pos, level, width, orientation
132
+ end
133
+ named_args_for :ar, :kr
134
+ end
135
+ end
136
+ end
137
+ end