Class: Gly::GabcConvertor

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

Overview

converts parsed gly to gabc

Instance Method Summary collapse

Instance Method Details

#clef?(chunk) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/gly/gabc_convertor.rb', line 39

def clef?(chunk)
  chunk =~ /\A[cf][1-4]\Z/
end

#convert(score, out = StringIO.new) ⇒ Object



4
5
6
7
8
9
10
11
12
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
# File 'lib/gly/gabc_convertor.rb', line 4

def convert(score, out=StringIO.new)
  score.headers.each_pair do |key,value|
    out.print '% ' unless Headers.gregorio_supported?(key)
    out.puts "#{key}: #{value};"
  end

  out.puts '%%'

  lyric_enum = score.lyrics.each_syllable.to_enum
  score.music.each_with_index do |mus_chunk,i|
    begin
      next_syl = lyric_enum.peek
    rescue StopIteration
      next_syl = ''
    end

    if clef?(mus_chunk) ||
       (nonlyrical_chunk?(mus_chunk) && ! nonlyrical_lyrics?(next_syl))
      # music chunk normally not having lyrics
      out.print ' ' if i != 0
    else
      # regular music chunk
      begin
        out.print strip_directives lyric_enum.next
      rescue StopIteration
        out.print ' ' if i != 0
      end
    end
    out.print "(#{mus_chunk})"
    # out.puts if differentia?(mus_chunk) # newline after each differentia
  end

  return out
end

#differentia?(chunk) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/gly/gabc_convertor.rb', line 43

def differentia?(chunk)
  chunk =~ /\A*[,;:]+\Z/ # differentia
end

#nonlyrical_chunk?(chunk) ⇒ Boolean

is the given music chunk capable of bearing lyrics?

Returns:

  • (Boolean)


48
49
50
# File 'lib/gly/gabc_convertor.rb', line 48

def nonlyrical_chunk?(chunk)
  differentia? chunk
end

#nonlyrical_lyrics?(syl) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/gly/gabc_convertor.rb', line 52

def nonlyrical_lyrics?(syl)
  syl =~ /\A\s*!/ || syl =~ /\A\s*\*\Z/
end

#strip_directives(syl) ⇒ Object



56
57
58
# File 'lib/gly/gabc_convertor.rb', line 56

def strip_directives(syl)
  syl.sub(/(\s*)!/, '\1') # exclamation mark at the beginning - place even under nonlyrical music chunk
end