Skip to content

Commit

Permalink
Renamed seq() and par() to s() and p(). Renamed seqn() and parn() to …
Browse files Browse the repository at this point in the history
…sn() and pn().
  • Loading branch information
Jeremy Voorhis committed Nov 2, 2008
1 parent 58f62e1 commit cddae2f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 80 deletions.
125 changes: 63 additions & 62 deletions examples/chopin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,92 +8,93 @@

def score
# mm 1
rh = seq(parn([g2, c3, ef3, g3]),
parn([af2, c3, ef3, af3]),
par(parn([g2, b2]), parn([ef3, g3], DEN) & parn([d3, f3], SN)),
parn([ef2, g2, c3, ef3]))
lh = seq(parn([c1, c2]), parn([f0, f1]), parn([g0, g1]), parn([c1, g1, c2]))
rh = s(pn([g2, c3, ef3, g3]),
pn([af2, c3, ef3, af3]),
p(pn([g2, b2]),
pn([ef3, g3], DEN) & pn([d3, f3], SN)),
pn([ef2, g2, c3, ef3]))
lh = s(pn([c1, c2]), pn([f0, f1]), pn([g0, g1]), pn([c1, g1, c2]))

# mm 2
rh &= seq(parn([ef2, af2, c3, ef3]),
parn([f2, af2, df3, f3]),
(parn([df2, ef2, g2]) | parn([c3, ef3], DEN) & parn([bf2, df3], SN)),
parn([c2, ef2, g2, c3]))
lh &= seq(parn([af1, af2]), parn([df1, df2]), parn([ef1, ef2]), parn([af1, af2]))
rh &= s(pn([ef2, af2, c3, ef3]),
pn([f2, af2, df3, f3]),
p(pn([df2, ef2, g2]), pn([c3, ef3], DEN) & pn([bf2, df3], SN)),
pn([c2, ef2, g2, c3]))
lh &= s(pn([af1, af2]), pn([df1, df2]), pn([ef1, ef2]), pn([af1, af2]))

# mm 3
rh &= seq(parn([d2, f2, b2, d3]),
parn([e2, g2, bf2, c3, e3]),
(parn([af2, c3]) | n(g3, DEN) & n(f3, SN)),
parn([g2, c3, ef3]))
lh &= seq(parn([g1, g2]), parn([c0, c1]), parn([f0, f1]), parn([c1, c2]))
rh &= s(pn([d2, f2, b2, d3]),
pn([e2, g2, bf2, c3, e3]),
(pn([af2, c3]) | n(g3, DEN) & n(f3, SN)),
pn([g2, c3, ef3]))
lh &= s(pn([g1, g2]), pn([c0, c1]), pn([f0, f1]), pn([c1, c2]))

# mm 4
rh &= seq(parn([fs2, c3, d3]),
parn([g2, b2, d3, g3]),
(parn([c3, d3, fs3]) | n(b3, DEN) & n(a3, SN)),
parn([bf2, d3, g3]))
lh &= seq(parn([d1, a1, d2]), parn([g0, g1]), parn([d0, d1]), parn([g0, g1]))
rh &= s(pn([fs2, c3, d3]),
pn([g2, b2, d3, g3]),
(pn([c3, d3, fs3]) | n(b3, DEN) & n(a3, SN)),
pn([bf2, d3, g3]))
lh &= s(pn([d1, a1, d2]), pn([g0, g1]), pn([d0, d1]), pn([g0, g1]))

# mm 5
rh &= seq(parn([ef3, g3, ef4]),
parn([ef3, af3, ef4]),
(parn([d3, d4]) | n(af3, DEN) & n(fs3, SN)),
parn([d3, af3, d4]))
lh &= seq(parn([c1, c2]), parn([c2, c3]), parn([b1, b2]), parn([bf1, bf2]))
rh &= s(pn([ef3, g3, ef4]),
pn([ef3, af3, ef4]),
(pn([d3, d4]) | n(af3, DEN) & n(fs3, SN)),
pn([d3, af3, d4]))
lh &= s(pn([c1, c2]), pn([c2, c3]), pn([b1, b2]), pn([bf1, bf2]))

# mm 6
rh &= seq(parn([c3, g3, c4]),
parn([c3, d3, fs3, d4]),
(parn([d3, g3, b3], DEN) & parn([c3, a3], SN)),
parn([b2, d3, g3]))
lh &= seq(parn([a1, a2]), parn([af1, af2]), parn([g1, g2]), parn([f1, f2]))
rh &= s(pn([c3, g3, c4]),
pn([c3, d3, fs3, d4]),
(pn([d3, g3, b3], DEN) & pn([c3, a3], SN)),
pn([b2, d3, g3]))
lh &= s(pn([a1, a2]), pn([af1, af2]), pn([g1, g2]), pn([f1, f2]))

# mm 7
rh &= seq(parn([c3, g3, c4]),
parn([af2, c3, af3]),
(parn([g2, d3]) | n(g3, DEN) & n(f3, SN)),
parn([g2, c3, ef3]))
lh &= seq(parn([ef1, ef2]), parn([f1, f2]), parn([b0, b1]), parn([c1, c2]))
rh &= s(pn([c3, g3, c4]),
pn([af2, c3, af3]),
(pn([g2, d3]) | n(g3, DEN) & n(f3, SN)),
pn([g2, c3, ef3]))
lh &= s(pn([ef1, ef2]), pn([f1, f2]), pn([b0, b1]), pn([c1, c2]))

# mm 8
rh &= seq(parn([ef2, af2, c3, ef3]),
parn([f2, af2, df3, f3]),
(parn([f2, g2, b2]) | n(ef3, DEN) & n(d3, SN)),
parn([ef2, g2, c3]))
lh &= seq(parn([af0, af1]), parn([df0, df1]), parn([g0, g1]), parn([c0, c1]))
rh &= s(pn([ef2, af2, c3, ef3]),
pn([f2, af2, df3, f3]),
(pn([f2, g2, b2]) | n(ef3, DEN) & n(d3, SN)),
pn([ef2, g2, c3]))
lh &= s(pn([af0, af1]), pn([df0, df1]), pn([g0, g1]), pn([c0, c1]))

# mm 9
rh &= seq(parn([ef3, g3, ef4]),
parn([ef3, af3, ef3]),
(parn([d3, d4]) | n(af3, DEN) & n(fs3, SN)),
parn([d3, g3, d4]))
lh &= seq(parn([c1, c2]), parn([c2, c3]), parn([b1, b2]), parn([bf1, bf2]))
rh &= s(pn([ef3, g3, ef4]),
pn([ef3, af3, ef3]),
(pn([d3, d4]) | n(af3, DEN) & n(fs3, SN)),
pn([d3, g3, d4]))
lh &= s(pn([c1, c2]), pn([c2, c3]), pn([b1, b2]), pn([bf1, bf2]))

# mm 10
rh &= seq(parn([c3, g3, c4]),
parn([c3, d3, fs3, d4]),
(parn([d3, g3, b3], DEN) & parn([c3, a3], SN)),
parn([b2, d3, g3]))
lh &= seq(parn([a1, a2]), parn([af1, af2]), parn([g1, g2]), parn([f1, f2]))
rh &= s(pn([c3, g3, c4]),
pn([c3, d3, fs3, d4]),
(pn([d3, g3, b3], DEN) & pn([c3, a3], SN)),
pn([b2, d3, g3]))
lh &= s(pn([a1, a2]), pn([af1, af2]), pn([g1, g2]), pn([f1, f2]))

# mm 11
rh &= seq(parn([c3, g3, c4]),
parn([af2, c3, af3]),
(parn([g2, d3]) | n(g3, DEN) & n(f3, SN)),
parn([g2, c3, ef3]))
lh &= seq(parn([ef1, ef2]), parn([f1, f2]), parn([b0, b1]), parn([c1, c2]))
rh &= s(pn([c3, g3, c4]),
pn([af2, c3, af3]),
(pn([g2, d3]) | n(g3, DEN) & n(f3, SN)),
pn([g2, c3, ef3]))
lh &= s(pn([ef1, ef2]), pn([f1, f2]), pn([b0, b1]), pn([c1, c2]))

# mm 12
rh &= seq(parn([ef2, af2, c3, ef3]),
parn([f2, af2, df3, f3]),
(parn([f2, g2, b2]) | n(ef3, DEN) & n(d3, SN)),
parn([ef2, g2, c3]))
lh &= seq(parn([af0, af1]), parn([df0, df1]), parn([g0, g1]), parn([c0, c1]))
rh &= s(pn([ef2, af2, c3, ef3]),
pn([f2, af2, df3, f3]),
(pn([f2, g2, b2]) | n(ef3, DEN) & n(d3, SN)),
pn([ef2, g2, c3]))
lh &= s(pn([af0, af1]), pn([df0, df1]), pn([g0, g1]), pn([c0, c1]))

# mm 13
rh &= parn([c3, ef3, g3, c4], 4)
lh &= parn([c2, g2], 4)
rh &= pn([c3, ef3, g3, c4], 4)
lh &= pn([c2, g2], 4)

final = rh | lh
# Not all applications agree on where to begin numbering pitches. Uncomment the
Expand Down
16 changes: 8 additions & 8 deletions lib/music.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,21 @@ def none; rest(0) end
=end

# Compose a list of arrangements sequentially.
def seq(*args)
args[0].is_a?(Array) ? seq(*args[0]) : args.inject(&:&)
def s(*args)
args[0].is_a?(Array) ? s(*args[0]) : args.inject(&:&)
end

def seqn(pit, dur = 1, attrs = {})
seq(n(pit, dur, attrs))
def sn(pit, dur = 1, attrs = {})
s(n(pit, dur, attrs))
end

# Compose a list of arrangements in parallel.
def par(*args)
args[0].is_a?(Array) ? par(*args[0]) : args.inject(&:|)
def p(*args)
args[0].is_a?(Array) ? p(*args[0]) : args.inject(&:|)
end

def parn(pit, dur = 1, attrs = {})
par(n(pit, dur, attrs))
def pn(pit, dur = 1, attrs = {})
p(n(pit, dur, attrs))
end
=begin
Expand Down
6 changes: 3 additions & 3 deletions spec/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ def cresc(factor, score)

it "can be used to implement various transforms" do
score = cresc(2,
seqn([c4, e4, g4], 1, :velocity => 64))
sn([c4, e4, g4], 1, :velocity => 64))
timeline = score.to_timeline
timeline.map(&:velocity).should == [64, 96, 127]
end

it "can be nested" do
score = cresc(1.5,
seqn([c4, e4, g4], 1, :velocity => 40) &
sn([c4, e4, g4], 1, :velocity => 40) &
cresc(1.5,
seqn([c4, e4, g4], 1, :velocity => 40)))
sn([c4, e4, g4], 1, :velocity => 40)))
timeline = score.to_timeline
timeline.map(&:velocity).should == [40, 47, 53, 60, 83, 110]
end
Expand Down
15 changes: 8 additions & 7 deletions spec/score_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,30 +287,31 @@
end

describe "helper functions" do
it "should arrange notes" do
it "should construct notes" do
note(60).should == Note.new(60, 1)
note(60, 2).should == Note.new(60, 2)
end

it "should arrange rests" do
it "should construct rests" do
rest().should == Rest.new(1)
rest(2).should == Rest.new(2)
end

it "should arrange groups" do
it "should construct groups" do
group(note(67) & note(60), {}).should == Group.new(note(67) & note(60), {})
end

it "should create the empty score" do
it "should construct the empty score" do
none().should == rest(0)
end

it "should compose lists of scores sequentially" do
seq(note(60), note(64), note(67)).should == note(60) & note(64) & note(67)
s(note(60), note(64), note(67)).should == note(60) & note(64) & note(67)
sn([60, 64, 67]).should == note(60) & note(64) & note(67)
end

it "should compose lists of scores in parallel" do
par(note(60), note(64), note(67)).should == note(60) | note(64) | note(67)
p(note(60), note(64), note(67)).should == note(60) | note(64) | note(67)
pn([60, 64, 67]).should == p(note(60), note(64), note(67))
end
end

0 comments on commit cddae2f

Please sign in to comment.