Skip to content

Commit

Permalink
Changed attribute layout of Controller. Converting bpm to qn/usec for…
Browse files Browse the repository at this point in the history
… SetTempo.
  • Loading branch information
Jeremy Voorhis committed Nov 18, 2008
1 parent ba072f8 commit 61bcf33
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/music.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def env(&fn) Env.new(&fn) end
=end =end


def ctl(name, value, attrs = {}) def ctl(name, attrs = {})
Controller.new(name, value, attrs) Controller.new(name, attrs)
end end
end end
7 changes: 3 additions & 4 deletions lib/music/score.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ class Controller < ScoreObject
include Instant include Instant
attr_reader :attributes attr_reader :attributes


def initialize(name, data, attrs = {}) def initialize(name, as = {})
@attributes = attrs.merge(:name => name, :data => Array(data)) @attributes = as.merge(:name => name)
end end


def ==(other) def ==(other)
Expand All @@ -339,8 +339,7 @@ def ==(other)


def update(key, val) def update(key, val)
a = attributes.merge(key => val) a = attributes.merge(key => val)
n, v = attributes.values_at(:name, :value) self.class.new(name, a)
self.class.new(n, v, a)
end end


def eval(interpreter, context) def eval(interpreter, context)
Expand Down
4 changes: 2 additions & 2 deletions lib/music/smf_writer.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def write_controller(track, ctl, time)


track << case ctl.name.to_s track << case ctl.name.to_s
when 'tempo' when 'tempo'
SetTempo.new(offset, ctl.data[0]) SetTempo.new(offset, bpm_to_qn_per_usec(ctl.tempo))
when /^cc(0?[1-9]|1[0-6])$/ when /^cc(0?[1-9]|1[0-6])$/
ControlChange.new(offset, channel, $1, ctl.data[0]) ControlChange.new(offset, channel, $1, ctl.value)
end end
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion spec/attribute_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@


describe Controller do describe Controller do
before(:all) do before(:all) do
@object = Controller.new(60, 1) @object = Controller.new(:cc1, :value => 64)
end end
it_should_behave_like "all attributes implementations" it_should_behave_like "all attributes implementations"
end end
6 changes: 3 additions & 3 deletions spec/score_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@


describe Controller do describe Controller do
before(:all) do before(:all) do
@object = Controller.new(:tempo, 120) @object = Controller.new(:tempo, :tempo => 120)
end end


it_should_behave_like "all scores" it_should_behave_like "all scores"

it "should carry associated data" do it "should carry associated data" do
@object.data.should == [120] @object.tempo.should == 120
end end
end end


Expand Down
2 changes: 1 addition & 1 deletion spec/temporal_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
describe Controller do describe Controller do
before(:all) do before(:all) do
@dur = 0 @dur = 0
@object = ctl(:tempo, 120) @object = ctl(:tempo, :tempo => 120)
end end
it_should_behave_like "all temporal objects" it_should_behave_like "all temporal objects"
end end

0 comments on commit 61bcf33

Please sign in to comment.