class Webern::Formatters::LilypondFormatter

Public Instance Methods

lilypond_pitch(n) click to toggle source
# File lib/webern/formatters/lilypond_formatter.rb, line 22
def lilypond_pitch(n)
  %w{ c'' cs'' d'' ef'' e'' f' fs' g' af' a' bf' b' }[n]
end
write_to_file() click to toggle source
# File lib/webern/formatters/lilypond_formatter.rb, line 4
def write_to_file
  File.open("#{@filepath}.ly", 'w') do |f|
    f << LILYPOND_HEADER
    f << "rows = {\n"
    f << "\\time 12/4\n"
    f << "\\override Staff.Stem #'transparent = ##t\n"
    {p: :prime, i: :inversion, r: :retrograde, ri: :retrograde_inversion}.each do |key, transformation|
      (0..11).each do |transposition|
        f << "\\mark \"#{key}#{transposition}\" "
        f << @prime_row.send(transformation).zero.transpose(transposition).map{|n| lilypond_pitch(n) }.join(' ') + "\n"
      end
      f << "\\bar \"||\"\n"
    end
    f << "}\n"
    f << LILYPOND_SCORE_BLOCK
  end
end