Class: Gly::GabcConvertor

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

Overview

takes ParsedScore, translates it to gabc

Instance Method Summary collapse

Instance Method Details

#clef?(chunk) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/gly/gabc_convertor.rb', line 41

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

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



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
38
39
# File 'lib/gly/gabc_convertor.rb', line 6

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)


45
46
47
# File 'lib/gly/gabc_convertor.rb', line 45

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

#nonlyrical_chunk?(chunk) ⇒ Boolean

is the given music chunk capable of bearing lyrics?

Returns:

  • (Boolean)


50
51
52
# File 'lib/gly/gabc_convertor.rb', line 50

def nonlyrical_chunk?(chunk)
  differentia? chunk
end

#nonlyrical_lyrics?(syl) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/gly/gabc_convertor.rb', line 54

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

#strip_directives(syl) ⇒ Object



58
59
60
# File 'lib/gly/gabc_convertor.rb', line 58

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