Skip to content

Commit

Permalink
Place lines in separate voices.
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed Dec 7, 2011
1 parent 6409f7e commit a405db9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/roborabb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,36 @@ def to_lilypond
format_bar(bar)
end

score.map {|x| x[:upper] }.join(' ') +
score.map {|x| x[:lower] }.join(' ')
lilypond do
voice(:up) { score.map {|x| x[:upper] }.join(' ') } +
voice(:down) { score.map {|x| x[:lower] }.join(' ') }
end
end

protected

attr_accessor :generator, :opts

def lilypond
<<-LP
\\version "2.14.2"
\\new DrumStaff <<
#{yield}
>>
LP
end

def voice(direction)
result = <<-LP
\\new DrumVoice {
\\override Rest #'direction = ##{direction}
\\stemUp \\drummode {
#{yield}
}
}
LP
end

def format_bar(bar)
{
upper: format_notes(bar, expand(hashslice(bar.notes, :hihat))),
Expand Down
23 changes: 23 additions & 0 deletions spec/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,28 @@ def construct(attributes)
formatter = described_class.new(generator, bars: 1)
formatter.to_lilypond.should include("r8 hh8")
end

it 'includes lilypond preamble' do
generator = [stub(unit: 8, notes: {})].each
formatter = described_class.new(generator, bars: 1)
output = formatter.to_lilypond
output.should include("\\version")
output.should include("\\new DrumStaff")
end

it 'places hihats and kick/snare in different voices' do
generator = [stub(unit: 8, notes: {
hihat: [true, true],
kick: [true, false],
snare: [false, true]
})].each
formatter = described_class.new(generator, bars: 1)
output = formatter.to_lilypond
voices = output.split("\\new DrumVoice")[1..-1]
voices[0].should include("hh8 hh8")
voices[0].should include("\\override Rest #'direction = #up")
voices[1].should include("bd8 sn8")
voices[1].should include("\\override Rest #'direction = #down")
end
end
end

0 comments on commit a405db9

Please sign in to comment.