Class: Gly::DocumentLyConvertor

Inherits:
Object
  • Object
show all
Defined in:
lib/gly/document_ly_convertor.rb

Overview

Converts gly to modern-notation LilyPond

expects the ‘lygre’ gem (which is only an optional dependency of gly)

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ DocumentLyConvertor

Returns a new instance of DocumentLyConvertor.



9
10
11
# File 'lib/gly/document_ly_convertor.rb', line 9

def initialize(document)
  @doc = document
end

Instance Method Details

#convertObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gly/document_ly_convertor.rb', line 13

def convert
  gabcor = GabcConvertor.new
  parser = GabcParser.new
  lilyor = LilypondConvertor.new cadenza: true, version: false

  ly_output = StringIO.new

  ly_output.puts '\version "2.18.0"'
  ly_output.puts
  ly_output.puts header @doc.header
  ly_output.puts
  ly_output.puts default_style
  ly_output.puts

  @doc.scores.each do |score|
    gabc = gabcor.convert(score).string
    parsed_score = parser.parse gabc
    begin
      ly_output.puts lilyor.convert parsed_score.create_score
    rescue NoMethodError
      ly_output.puts "\\markup{error processing score \\italic{#{score.lyrics.readable}}}"
    end

    ly_output.puts
  end

  out_fname = File.basename(@doc.path) + '.ly'
  File.open(out_fname, 'w') do |fw|
    fw.puts ly_output.string
  end
end