Skip to content

Commit

Permalink
Include beat structure every bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed Dec 7, 2011
1 parent c529aad commit 4d8e4e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/roborabb.rb
Expand Up @@ -28,12 +28,17 @@ def to_lilypond
def format_bars(bars, voice)
last_bar = Bar.new({})
bars.map do |bar|
preamble = if last_bar.time_signature != bar[:bar].time_signature
%(\\time "#{bar[:bar].time_signature}"\n)
preamble = ""
if last_bar.time_signature != bar[:bar].time_signature
preamble += %(\\time "#{bar[:bar].time_signature}"\n)
end

if last_bar.beat_structure != bar[:bar].beat_structure
preamble += %(\\set Staff.beatStructure = #'(%s)\n) % bar[:bar].beat_structure.join(' ')
end
last_bar = bar[:bar]

preamble.to_s + bar[voice]
preamble + bar[voice]
end.join(' | ')
end

Expand Down
18 changes: 17 additions & 1 deletion spec/unit_spec.rb
Expand Up @@ -104,7 +104,10 @@ def construct(attributes)
describe '#to_lilypond' do
def bar(attributes)
double("Bar", {
time_signature: "4/4"
unit: 8,
notes: {hihat: [true]},
time_signature: "4/4",
beat_structure: [4, 4]
}.merge(attributes))
end

Expand Down Expand Up @@ -197,5 +200,18 @@ def bar(attributes)
bars[1].should_not include(%(\\time "1/8"))
bars[2].should include(%(\\time "1/4"))
end

it 'includes beat structure changes per bar' do
generator = [
bar(beat_structure: [3, 2]),
bar(beat_structure: [3, 2]),
bar(beat_structure: [2, 3]),
].each
formatter = described_class.new(generator, bars: 3)
bars = formatter.to_lilypond.split('|')
bars[0].should include(%(\\set Staff.beatStructure = #'(3 2)))
bars[1].should_not include(%(\\set Staff.beatStructure))
bars[2].should include(%(\\set Staff.beatStructure = #'(2 3)))
end
end
end

0 comments on commit 4d8e4e5

Please sign in to comment.