-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.rb
170 lines (141 loc) · 4.39 KB
/
generate.rb
1
2
3
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# coding: utf-8
# Generates notation (in gly format) for the Epiphany proclamation,
# by default for the next 50 years.
require 'calendarium-romanum'
require 'gly'
# Movable feasts whose dates are part of the Epiphany proclamation,
# as feast symbols defined by calendarium-romanum
FEASTS = %i(ash_wednesday easter_sunday ascension pentecost corpus_christi first_advent_sunday)
class DateToText
# Parts of generated "text dates", syllabified, in format expected by the Gly parser.
NUMERALS = [
nil,
'prv -- ní -- ho',
'dru -- hé -- ho',
'tře -- tí -- ho',
'čtvr -- té -- ho',
'pá -- té -- ho',
'šes -- té -- ho',
'sed -- mé -- ho',
'os -- mé -- ho',
'de -- vá -- té -- ho',
'de -- sá -- té -- ho',
'je -- de -- nác -- té -- ho',
'dva -- nác -- té -- ho',
'tři -- nác -- té -- ho',
'čtr -- nác -- té -- ho',
'pat -- nác -- té -- ho',
'šest -- nác -- té -- ho',
'se -- dm -- nác -- té -- ho',
'o -- sm -- nác -- té -- ho',
'de -- va -- te -- nác -- té -- ho',
'dva -- cá -- té -- ho',
'dva -- cá -- té -- ho prv -- ní -- ho',
'dva -- cá -- té -- ho dru -- hé -- ho',
'dva -- cá -- té -- ho tře -- tí -- ho',
'dva -- cá -- té -- ho čtvr -- té -- ho',
'dva -- cá -- té -- ho pá -- té -- ho',
'dva -- cá -- té -- ho šes -- té -- ho',
'dva -- cá -- té -- ho sed -- mé -- ho',
'dva -- cá -- té -- ho os -- mé -- ho',
'dva -- cá -- té -- ho de -- vá -- té -- ho',
'tři -- cá -- té -- ho',
'tři -- cá -- té -- ho prv -- ní -- ho',
]
MONTHS = [
nil,
'led -- na',
'ú -- no -- ra',
'břez -- na',
'dub -- na',
'květ -- na',
'červ -- na',
'čer -- ven -- ce',
'srp -- na',
'zá -- ří',
'říj -- na',
'lis -- to -- pa -- du',
'pro -- sin -- ce',
]
# Takes `Date`, returns its string representation as it will be chanted.
def self.call(date)
NUMERALS[date.day] +
' ' +
MONTHS[date.month]
end
end
# Each public method (names correspond to feast symbols) returns a snippet of gly notation
# with the date of the movable feast in question.
class GlySnippetForFeast
# Expects (civil, not liturgical) year for whose Epiphany the proclamation is being generated.
def initialize(year)
@year = year
@parser = Gly::Parser.new
end
def ash_wednesday
make_snippet __method__, initial_pes: false
end
def easter_sunday
make_snippet __method__
end
def ascension
make_snippet __method__
end
def pentecost
make_snippet __method__
end
def corpus_christi
make_snippet __method__
end
def first_advent_sunday
make_snippet __method__, initial_pes: false, final_ornament: false
end
protected
def make_snippet(feast, initial_pes: true, final_ornament: true)
liturgical_year = feast == :first_advent_sunday ? @year : @year - 1
date = CalendariumRomanum::Temporale::Dates.public_send(feast, liturgical_year)
lyrics = DateToText.(date)
lyrics_parsed = @parser.parse_str(lyrics).scores.first.lyrics
syllable_count =
lyrics_parsed
.each_syllable
.reject {|s| s =~ /\A\s*\Z/ }
.to_a
.size
beginning = [initial_pes ? 'fh' : 'h']
reciting = ['h']
preparatory_syllables = ['g', 'h']
accent = ['i']
ending = ['h.']
music =
beginning +
if final_ornament
last_word_length = lyrics_parsed.each_word.to_a.last.each_syllable.to_a.count
(reciting * (syllable_count - last_word_length - beginning.size - preparatory_syllables.size)) +
preparatory_syllables +
accent +
(reciting * (last_word_length - accent.size - ending.size))
else
reciting * (syllable_count - beginning.size - ending.size)
end +
ending
music.join(' ') + "\n" + lyrics
end
end
year_from = (ARGV[0] || Time.now.year).to_i
year_to = (ARGV[1] || (year_from + 50)).to_i
template = File.read 'template.gly'
out = STDOUT
out.puts "\\header\ntitle: Ohlášení pohyblivých svátků"
(year_from..year_to).each_with_index do |year, i|
out.puts "\\markup\\pagebreak" if i > 0
out.puts "\\markup\\section*{#{year}}"
out.puts
buffer = template.dup
glyfier = GlySnippetForFeast.new year
FEASTS.each do |feast|
placeholder = "{{#{feast}}}"
buffer.sub! placeholder, glyfier.send(feast)
end
out.puts buffer
end