Skip to content

Commit

Permalink
Remove Music::Score::Base#seq and #par. Music.seq and Music.par repla…
Browse files Browse the repository at this point in the history
…ce Music.line and Music.chord.
  • Loading branch information
Jeremy Voorhis committed Nov 1, 2008
1 parent 631e491 commit 0410d93
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/music.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ def none; rest(0) end
=end

# Compose a list of arrangements sequentially.
def line(*ms)
def seq(*ms)
ms.inject { |a, b| a & b }
end

# Compose a list of arrangements in parallel.
def chord(*ms)
def par(*ms)
ms.inject { |a, b| a | b }
end
end
6 changes: 2 additions & 4 deletions lib/music/score.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ def self.none; rest(0) end
def none; self.class.none end

# Sequential composition.
def seq(other)
def &(other)
Seq.new(self, other)
end
alias & seq

# Parallel (concurrent) composition.
def par(other)
def |(other)
Par.new(self, other)
end
alias | par

# Parallel composition. The duration of the longer sequence is truncated
# to match the duration of the shorter one.
Expand Down
18 changes: 8 additions & 10 deletions spec/score_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
shared_examples_for "all arrangements" do
it "can be composed sequentially" do
seq = Seq.new(@object, rest(0))
( @object & rest(0) ).should == seq
@object.seq( rest(0) ).should == seq
(@object & rest(0)).should == seq
end

it "can be composed in parallel" do
par = Par.new(@object, rest(0))
( @object | rest(0) ).should == par
@object.par( rest(0) ).should == par
(@object | rest(0)).should == par
end

it "preserves its structure when mapped with the identity function" do
Expand Down Expand Up @@ -83,8 +81,8 @@
end

it "can be compared" do
@left.seq(@right).should == @object
@right.seq(@left).should_not == @object
(@left & @right).should == @object
(@right & @left).should_not == @object
end

it "can be transposed" do
Expand Down Expand Up @@ -117,8 +115,8 @@
end

it "can be compared" do
@top.par(@bottom).should == @object
@bottom.par(@top).should_not == @object
(@top | @bottom).should == @object
(@bottom | @top).should_not == @object
end

it "can be transposed" do
Expand Down Expand Up @@ -264,11 +262,11 @@
end

it "should compose lists of arrangements sequentially" do
line(note(60), note(64), note(67)).should == note(60) & note(64) & note(67)
seq(note(60), note(64), note(67)).should == note(60) & note(64) & note(67)
end

it "should compose lists of arrangements in parallel" do
chord(note(60), note(64), note(67)).should == note(60) | note(64) | note(67)
par(note(60), note(64), note(67)).should == note(60) | note(64) | note(67)
end
end

0 comments on commit 0410d93

Please sign in to comment.