Class: Webern::Formatters::LilypondFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/webern/formatters/lilypond_formatter.rb

Constant Summary

Constants inherited from BaseFormatter

BaseFormatter::DEFAULT_OPTS, BaseFormatter::PITCH_CLASSES

Instance Method Summary collapse

Methods inherited from BaseFormatter

#initialize, #pitch_value

Constructor Details

This class inherits a constructor from Webern::Formatters::BaseFormatter

Instance Method Details

#lilypond_pitch(n) ⇒ Object



22
23
24
# 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_fileObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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