diff --git a/.gitignore b/.gitignore index ea4cdc7..da31a1e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ .rspec_status .byebug_history TAGS +/.gtm/ diff --git a/lib/scruby/ugen/base.rb b/lib/scruby/ugen/base.rb index 9807cfe..3a8b12e 100644 --- a/lib/scruby/ugen/base.rb +++ b/lib/scruby/ugen/base.rb @@ -37,6 +37,21 @@ def input_values inputs.values.flatten end + # TODO: no specs + def rate_index + E_RATES.index(rate) + end + + # TODO: no specs + def output_specs #:nodoc: + [ E_RATES.index(rate) ] + end + + # TODO: no specs + def channels_count + 1 + end + protected def rate=(rate) diff --git a/lib/scruby/ugen/graph.rb b/lib/scruby/ugen/graph.rb index d0a71a0..2e91ad8 100644 --- a/lib/scruby/ugen/graph.rb +++ b/lib/scruby/ugen/graph.rb @@ -23,18 +23,23 @@ def encode [ encode_constants, encode_controls, encode_control_names, - encode_nodes + encode_nodes, + encode_variants ].join end private def encode_controls - [ 0 ].pack("N") + encode_int32(0) end def encode_control_names - [ 0 ].pack("N") + encode_int32(0) + end + + def encode_variants + encode_int16(0) end def encode_constants @@ -42,7 +47,7 @@ def encode_constants end def encode_nodes - [ nodes.size ].pack("N") + nodes.map(&:encode).join + encode_int32(nodes.size) + nodes.map(&:encode).join end end end diff --git a/lib/scruby/ugen/graph/node.rb b/lib/scruby/ugen/graph/node.rb index e8cc3af..1c84400 100644 --- a/lib/scruby/ugen/graph/node.rb +++ b/lib/scruby/ugen/graph/node.rb @@ -24,12 +24,12 @@ def initialize(value, graph) def encode [ encode_string(value.name), - encode_int8(rate_index), + encode_int8(value.rate_index), encode_int32(inputs.count), - encode_int32(channels_count), + encode_int32(value.channels_count), encode_int16(special_index), collect_input_specs.flatten.pack("N*"), - output_specs.map { |i| encode_int8(i) }.join + value.output_specs.map { |i| encode_int8(i) }.join ].join end @@ -56,18 +56,6 @@ def special_index 0 end - def channels_count - 1 - end - - def rate_index - E_RATES.index(rate) - end - - def output_specs #:nodoc: - [ E_RATES.index(rate) ] - end - def collect_input_specs #:nodoc: inputs.map(&:input_specs) end diff --git a/lib/scruby/ugen/out.rb b/lib/scruby/ugen/out.rb index 866f0bb..3ff6541 100644 --- a/lib/scruby/ugen/out.rb +++ b/lib/scruby/ugen/out.rb @@ -4,8 +4,15 @@ class Out < Ugen::Base rates :control, :audio inputs bus: nil, channels_array: nil - # @channels = [] - # def output_specs; []; end + # TODO: no specs + def output_specs + [] + end + + # TODO: no specs + def channels_count + 0 + end class << self def ar(bus, *inputs) diff --git a/spec/ugen/graph_spec.rb b/spec/ugen/graph_spec.rb index da2c736..02e4918 100644 --- a/spec/ugen/graph_spec.rb +++ b/spec/ugen/graph_spec.rb @@ -7,29 +7,21 @@ let(:ugen) { Ugen::Out.ar(1, sin_osc) } let(:expected) do - %w( - 00 00 00 03 43 - dc 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 - 00 00 00 00 00 00 02 06 53 69 6e 4f 73 63 02 00 - 00 00 02 00 00 00 01 00 00 ff ff ff ff 00 00 00 - 00 ff ff ff ff 00 00 00 01 02 03 4f 75 74 02 00 - 00 00 02 00 00 00 00 00 00 ff ff ff ff 00 00 00 - 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 - ) + [ 0, 0, 0, 3, 67, -36, 0, 0, 0, 0, 0, 0, 63, -128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 83, 105, 110, 79, 115, 99, + 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, + -1, -1, -1, -1, 0, 0, 0, 1, 2, 3, 79, 117, 116, 2, 0, 0, 0, + 2, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 2, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 ].pack("C*") end subject(:graph) { described_class.new(ugen) } - let(:encoded) do - graph.encode.unpack("C*") - .map { |num| num.to_s(16).rjust(2, "0") } - end - it { expect(graph.constants.map(&:value)).to eq [ 440, 0, 1 ] } it { expect(graph.nodes.map(&:value)).to eq [ sin_osc, ugen ] } it "should encode graph" do - expect(encoded).to eq(expected) + expect(graph.encode).to eq(expected) end end end