Skip to content

Commit

Permalink
Simplification: removed Gen and Tr, retaining Env.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Voorhis committed Nov 1, 2008
1 parent 2c99ecf commit 8c3ca3d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/music.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
11 changes: 11 additions & 0 deletions lib/music/env.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 0 additions & 23 deletions lib/music/gens.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/music/interpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
24 changes: 0 additions & 24 deletions spec/gens_spec.rb → spec/env_spec.rb
Original file line number Diff line number Diff line change
@@ -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)),
Expand Down

0 comments on commit 8c3ca3d

Please sign in to comment.