diff --git a/lib/music.rb b/lib/music.rb index a4aa286..ffb3e41 100644 --- a/lib/music.rb +++ b/lib/music.rb @@ -21,7 +21,7 @@ require 'music/key' require 'music/interpreter' require 'music/score' -require 'music/gens' +require 'music/env' require 'music/timeline' require 'music/smf_writer' diff --git a/lib/music/env.rb b/lib/music/env.rb new file mode 100644 index 0000000..0e6ea22 --- /dev/null +++ b/lib/music/env.rb @@ -0,0 +1,11 @@ +module Music + class Env + def initialize(&fn) + @fn = fn + end + + def apply(name, val, context) + @fn.call(val, context.phase) + end + end +end diff --git a/lib/music/gens.rb b/lib/music/gens.rb deleted file mode 100644 index 4249b6d..0000000 --- a/lib/music/gens.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Music - class Gen - def initialize(&fn) - @fn = fn - end - - def apply(name, val, context) - @fn.call(context) - end - end - - class Tr < Gen - def apply(name, val, context) - @fn.call(val) - end - end - - class Env < Gen - def apply(name, val, context) - @fn.call(val, context.phase) - end - end -end diff --git a/lib/music/interpreter.rb b/lib/music/interpreter.rb index 8c3b71d..00c0e48 100644 --- a/lib/music/interpreter.rb +++ b/lib/music/interpreter.rb @@ -48,7 +48,7 @@ def accept(a0) push(names.inject({}) { |a1, name| a1.merge name => case new = self.attributes[name] # If a0 yields a Gen, apply it - when Gen: new.apply(name, a0[name], self) + when Env: new.apply(name, a0[name], self) # otherwise, inherit the attribute value from a0 if # we haven't defined it else self.attributes[name] || a0[name] diff --git a/spec/gens_spec.rb b/spec/env_spec.rb similarity index 64% rename from spec/gens_spec.rb rename to spec/env_spec.rb index d678d67..63edeea 100644 --- a/spec/gens_spec.rb +++ b/spec/env_spec.rb @@ -1,29 +1,5 @@ require File.join( File.dirname(__FILE__), 'spec_helper') -describe Gen do - before(:all) do - @score = s( n(c4, 1), - :amp => gen { |c| 0.5 }) - end - - it "should generate values from the given context" do - timeline = @score.to_timeline - timeline[0].amp.should == 0.5 - end -end - -describe Tr do - before(:all) do - @score = s( n(c4, 1, :amp => 0.5), - :amp => tr { |amp| amp * 0.5 } ) - end - - it "should transform attribute values" do - timeline = @score.to_timeline - timeline[0].amp.should == 0.25 - end -end - describe Env do it "should transform attribute values based on their phase" do score = s( seq(n([c4, e4, g4], 1, :amp => 0.5)),