brevity 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +3 -0
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.rdoc +4 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +27 -0
- data/Rakefile +67 -0
- data/bin/debrief +56 -0
- data/brevity.gemspec +28 -0
- data/examples/alley_cat.br +50 -0
- data/examples/hip.br +15 -0
- data/examples/missed_connection.br +6 -0
- data/examples/song1.br +11 -0
- data/examples/song2.br +10 -0
- data/examples/twinkle.br +18 -0
- data/lib/brevity/commands/constants.rb +18 -0
- data/lib/brevity/commands/expr.rb +17 -0
- data/lib/brevity/commands/meter.rb +20 -0
- data/lib/brevity/commands/part.rb +47 -0
- data/lib/brevity/commands/tempo.rb +13 -0
- data/lib/brevity/itemization.rb +73 -0
- data/lib/brevity/parsing/expression/dynamic.rb +280 -0
- data/lib/brevity/parsing/expression/dynamic.treetop +41 -0
- data/lib/brevity/parsing/expression/dynamic_nodes.rb +55 -0
- data/lib/brevity/parsing/expression/expression.rb +429 -0
- data/lib/brevity/parsing/expression/expression.treetop +39 -0
- data/lib/brevity/parsing/expression/expression_nodes.rb +26 -0
- data/lib/brevity/parsing/expression/gradual.rb +44 -0
- data/lib/brevity/parsing/expression/gradual.treetop +9 -0
- data/lib/brevity/parsing/expression/gradual_node.rb +11 -0
- data/lib/brevity/parsing/expression/label.rb +75 -0
- data/lib/brevity/parsing/expression/label.treetop +9 -0
- data/lib/brevity/parsing/expression/label_node.rb +15 -0
- data/lib/brevity/parsing/expression/sequence.rb +130 -0
- data/lib/brevity/parsing/expression/sequence.treetop +12 -0
- data/lib/brevity/parsing/expression/sequence_node.rb +14 -0
- data/lib/brevity/parsing/file/command.rb +216 -0
- data/lib/brevity/parsing/file/command.treetop +17 -0
- data/lib/brevity/parsing/file/command_node.rb +11 -0
- data/lib/brevity/parsing/file/comment.rb +178 -0
- data/lib/brevity/parsing/file/comment.treetop +21 -0
- data/lib/brevity/parsing/file/comment_node.rb +3 -0
- data/lib/brevity/parsing/file/file.rb +152 -0
- data/lib/brevity/parsing/file/file.treetop +16 -0
- data/lib/brevity/parsing/file/file_node.rb +7 -0
- data/lib/brevity/parsing/file/path.rb +235 -0
- data/lib/brevity/parsing/file/path.treetop +12 -0
- data/lib/brevity/parsing/modifiers/duplicate_modifier.rb +65 -0
- data/lib/brevity/parsing/modifiers/duplicate_modifier.treetop +11 -0
- data/lib/brevity/parsing/modifiers/duplicate_modifier_node.rb +8 -0
- data/lib/brevity/parsing/modifiers/modifier.rb +64 -0
- data/lib/brevity/parsing/modifiers/modifier.treetop +13 -0
- data/lib/brevity/parsing/modifiers/stretch_modifier.rb +69 -0
- data/lib/brevity/parsing/modifiers/stretch_modifier.treetop +11 -0
- data/lib/brevity/parsing/modifiers/stretch_modifier_node.rb +21 -0
- data/lib/brevity/parsing/modifiers/transpose_modifier.rb +69 -0
- data/lib/brevity/parsing/modifiers/transpose_modifier.treetop +11 -0
- data/lib/brevity/parsing/modifiers/transpose_modifier_node.rb +13 -0
- data/lib/brevity/parsing/note/accent.rb +44 -0
- data/lib/brevity/parsing/note/accent.treetop +9 -0
- data/lib/brevity/parsing/note/duration.rb +203 -0
- data/lib/brevity/parsing/note/duration.treetop +23 -0
- data/lib/brevity/parsing/note/duration_nodes.rb +19 -0
- data/lib/brevity/parsing/note/link.rb +69 -0
- data/lib/brevity/parsing/note/link.treetop +11 -0
- data/lib/brevity/parsing/note/link_node.rb +19 -0
- data/lib/brevity/parsing/note/note.rb +300 -0
- data/lib/brevity/parsing/note/note.treetop +30 -0
- data/lib/brevity/parsing/note/note_nodes.rb +77 -0
- data/lib/brevity/parsing/note/pitch.rb +81 -0
- data/lib/brevity/parsing/note/pitch.treetop +9 -0
- data/lib/brevity/parsing/note/pitch_node.rb +50 -0
- data/lib/brevity/parsing/numbers/nonnegative_integer.rb +53 -0
- data/lib/brevity/parsing/numbers/nonnegative_integer.treetop +9 -0
- data/lib/brevity/parsing/numbers/positive_integer.rb +91 -0
- data/lib/brevity/parsing/numbers/positive_integer.treetop +15 -0
- data/lib/brevity/read_file.rb +18 -0
- data/lib/brevity/score_maker.rb +64 -0
- data/lib/brevity/version.rb +4 -0
- data/lib/brevity.rb +53 -0
- data/manuals/brevity.pdf +0 -0
- data/manuals/brevity.tex +273 -0
- data/spec/brevity_spec.rb +8 -0
- data/spec/commands/expr_spec.rb +15 -0
- data/spec/commands/meter_spec.rb +21 -0
- data/spec/commands/part_spec.rb +16 -0
- data/spec/commands/tempo_spec.rb +20 -0
- data/spec/itemization_spec.rb +46 -0
- data/spec/parsing/expression/dynamic_nodes_spec.rb +32 -0
- data/spec/parsing/expression/dynamic_spec.rb +23 -0
- data/spec/parsing/expression/expression_nodes_spec.rb +87 -0
- data/spec/parsing/expression/expression_spec.rb +85 -0
- data/spec/parsing/expression/gradual_spec.rb +10 -0
- data/spec/parsing/expression/label_node_spec.rb +13 -0
- data/spec/parsing/expression/label_spec.rb +35 -0
- data/spec/parsing/file/command_node_spec.rb +29 -0
- data/spec/parsing/file/command_spec.rb +18 -0
- data/spec/parsing/file/comment_spec.rb +14 -0
- data/spec/parsing/file/file_node_spec.rb +19 -0
- data/spec/parsing/file/file_spec.rb +30 -0
- data/spec/parsing/modifiers/modifier_nodes_spec.rb +25 -0
- data/spec/parsing/modifiers/modifier_parsers_spec.rb +20 -0
- data/spec/parsing/note/accent_spec.rb +27 -0
- data/spec/parsing/note/duration_nodes_spec.rb +79 -0
- data/spec/parsing/note/duration_spec.rb +69 -0
- data/spec/parsing/note/link_node_spec.rb +30 -0
- data/spec/parsing/note/link_spec.rb +23 -0
- data/spec/parsing/note/note_nodes_spec.rb +82 -0
- data/spec/parsing/note/note_spec.rb +188 -0
- data/spec/parsing/note/pitch_node_spec.rb +48 -0
- data/spec/parsing/note/pitch_spec.rb +23 -0
- data/spec/parsing/numbers/nonnegative_integer_spec.rb +11 -0
- data/spec/parsing/numbers/positive_integer_spec.rb +17 -0
- data/spec/spec_helper.rb +112 -0
- metadata +293 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module Brevity
|
|
5
|
+
|
|
6
|
+
module Note
|
|
7
|
+
include Treetop::Runtime
|
|
8
|
+
|
|
9
|
+
def root
|
|
10
|
+
@root ||= :note
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
include Pitch
|
|
14
|
+
|
|
15
|
+
include Accent
|
|
16
|
+
|
|
17
|
+
include Link
|
|
18
|
+
|
|
19
|
+
include Duration
|
|
20
|
+
|
|
21
|
+
def _nt_note
|
|
22
|
+
start_index = index
|
|
23
|
+
if node_cache[:note].has_key?(index)
|
|
24
|
+
cached = node_cache[:note][index]
|
|
25
|
+
if cached
|
|
26
|
+
node_cache[:note][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
|
27
|
+
@index = cached.interval.end
|
|
28
|
+
end
|
|
29
|
+
return cached
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
i0 = index
|
|
33
|
+
r1 = _nt_polyphonic_note
|
|
34
|
+
if r1
|
|
35
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
|
36
|
+
r0 = r1
|
|
37
|
+
else
|
|
38
|
+
r2 = _nt_monophonic_note
|
|
39
|
+
if r2
|
|
40
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
|
41
|
+
r0 = r2
|
|
42
|
+
else
|
|
43
|
+
r3 = _nt_rest_note
|
|
44
|
+
if r3
|
|
45
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
|
46
|
+
r0 = r3
|
|
47
|
+
else
|
|
48
|
+
@index = i0
|
|
49
|
+
r0 = nil
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
node_cache[:note][start_index] = r0
|
|
55
|
+
|
|
56
|
+
r0
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
module RestNote0
|
|
60
|
+
def duration
|
|
61
|
+
elements[0]
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def _nt_rest_note
|
|
66
|
+
start_index = index
|
|
67
|
+
if node_cache[:rest_note].has_key?(index)
|
|
68
|
+
cached = node_cache[:rest_note][index]
|
|
69
|
+
if cached
|
|
70
|
+
node_cache[:rest_note][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
|
71
|
+
@index = cached.interval.end
|
|
72
|
+
end
|
|
73
|
+
return cached
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
i0, s0 = index, []
|
|
77
|
+
r1 = _nt_duration
|
|
78
|
+
s0 << r1
|
|
79
|
+
if s0.last
|
|
80
|
+
r0 = instantiate_node(RestNoteNode,input, i0...index, s0)
|
|
81
|
+
r0.extend(RestNote0)
|
|
82
|
+
else
|
|
83
|
+
@index = i0
|
|
84
|
+
r0 = nil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
node_cache[:rest_note][start_index] = r0
|
|
88
|
+
|
|
89
|
+
r0
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
module MonophonicNote0
|
|
93
|
+
def duration
|
|
94
|
+
elements[0]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def pl
|
|
98
|
+
elements[1]
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def acc
|
|
102
|
+
elements[2]
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def _nt_monophonic_note
|
|
107
|
+
start_index = index
|
|
108
|
+
if node_cache[:monophonic_note].has_key?(index)
|
|
109
|
+
cached = node_cache[:monophonic_note][index]
|
|
110
|
+
if cached
|
|
111
|
+
node_cache[:monophonic_note][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
|
112
|
+
@index = cached.interval.end
|
|
113
|
+
end
|
|
114
|
+
return cached
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
i0, s0 = index, []
|
|
118
|
+
r1 = _nt_duration
|
|
119
|
+
s0 << r1
|
|
120
|
+
if r1
|
|
121
|
+
r2 = _nt_pitch_link
|
|
122
|
+
s0 << r2
|
|
123
|
+
if r2
|
|
124
|
+
r4 = _nt_accent
|
|
125
|
+
if r4
|
|
126
|
+
r3 = r4
|
|
127
|
+
else
|
|
128
|
+
r3 = instantiate_node(SyntaxNode,input, index...index)
|
|
129
|
+
end
|
|
130
|
+
s0 << r3
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
if s0.last
|
|
134
|
+
r0 = instantiate_node(MonophonicNoteNode,input, i0...index, s0)
|
|
135
|
+
r0.extend(MonophonicNote0)
|
|
136
|
+
else
|
|
137
|
+
@index = i0
|
|
138
|
+
r0 = nil
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
node_cache[:monophonic_note][start_index] = r0
|
|
142
|
+
|
|
143
|
+
r0
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
module PolyphonicNote0
|
|
147
|
+
def pl
|
|
148
|
+
elements[1]
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
module PolyphonicNote1
|
|
153
|
+
def duration
|
|
154
|
+
elements[0]
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def pl
|
|
158
|
+
elements[1]
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def more_pitches
|
|
162
|
+
elements[2]
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def acc
|
|
166
|
+
elements[3]
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def _nt_polyphonic_note
|
|
171
|
+
start_index = index
|
|
172
|
+
if node_cache[:polyphonic_note].has_key?(index)
|
|
173
|
+
cached = node_cache[:polyphonic_note][index]
|
|
174
|
+
if cached
|
|
175
|
+
node_cache[:polyphonic_note][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
|
176
|
+
@index = cached.interval.end
|
|
177
|
+
end
|
|
178
|
+
return cached
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
i0, s0 = index, []
|
|
182
|
+
r1 = _nt_duration
|
|
183
|
+
s0 << r1
|
|
184
|
+
if r1
|
|
185
|
+
r2 = _nt_pitch_link
|
|
186
|
+
s0 << r2
|
|
187
|
+
if r2
|
|
188
|
+
s3, i3 = [], index
|
|
189
|
+
loop do
|
|
190
|
+
i4, s4 = index, []
|
|
191
|
+
if (match_len = has_terminal?(",", false, index))
|
|
192
|
+
r5 = true
|
|
193
|
+
@index += match_len
|
|
194
|
+
else
|
|
195
|
+
terminal_parse_failure(",")
|
|
196
|
+
r5 = nil
|
|
197
|
+
end
|
|
198
|
+
s4 << r5
|
|
199
|
+
if r5
|
|
200
|
+
r6 = _nt_pitch_link
|
|
201
|
+
s4 << r6
|
|
202
|
+
end
|
|
203
|
+
if s4.last
|
|
204
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
|
205
|
+
r4.extend(PolyphonicNote0)
|
|
206
|
+
else
|
|
207
|
+
@index = i4
|
|
208
|
+
r4 = nil
|
|
209
|
+
end
|
|
210
|
+
if r4
|
|
211
|
+
s3 << r4
|
|
212
|
+
else
|
|
213
|
+
break
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
if s3.empty?
|
|
217
|
+
@index = i3
|
|
218
|
+
r3 = nil
|
|
219
|
+
else
|
|
220
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
|
221
|
+
end
|
|
222
|
+
s0 << r3
|
|
223
|
+
if r3
|
|
224
|
+
r8 = _nt_accent
|
|
225
|
+
if r8
|
|
226
|
+
r7 = r8
|
|
227
|
+
else
|
|
228
|
+
r7 = instantiate_node(SyntaxNode,input, index...index)
|
|
229
|
+
end
|
|
230
|
+
s0 << r7
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
if s0.last
|
|
235
|
+
r0 = instantiate_node(PolyphonicNoteNode,input, i0...index, s0)
|
|
236
|
+
r0.extend(PolyphonicNote1)
|
|
237
|
+
else
|
|
238
|
+
@index = i0
|
|
239
|
+
r0 = nil
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
node_cache[:polyphonic_note][start_index] = r0
|
|
243
|
+
|
|
244
|
+
r0
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
module PitchLink0
|
|
248
|
+
def pitch
|
|
249
|
+
elements[0]
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def the_link
|
|
253
|
+
elements[1]
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def _nt_pitch_link
|
|
258
|
+
start_index = index
|
|
259
|
+
if node_cache[:pitch_link].has_key?(index)
|
|
260
|
+
cached = node_cache[:pitch_link][index]
|
|
261
|
+
if cached
|
|
262
|
+
node_cache[:pitch_link][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
|
263
|
+
@index = cached.interval.end
|
|
264
|
+
end
|
|
265
|
+
return cached
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
i0, s0 = index, []
|
|
269
|
+
r1 = _nt_pitch
|
|
270
|
+
s0 << r1
|
|
271
|
+
if r1
|
|
272
|
+
r3 = _nt_link
|
|
273
|
+
if r3
|
|
274
|
+
r2 = r3
|
|
275
|
+
else
|
|
276
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
|
277
|
+
end
|
|
278
|
+
s0 << r2
|
|
279
|
+
end
|
|
280
|
+
if s0.last
|
|
281
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
|
282
|
+
r0.extend(PitchLink0)
|
|
283
|
+
else
|
|
284
|
+
@index = i0
|
|
285
|
+
r0 = nil
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
node_cache[:pitch_link][start_index] = r0
|
|
289
|
+
|
|
290
|
+
r0
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
class NoteParser < Treetop::Runtime::CompiledParser
|
|
296
|
+
include Note
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Brevity
|
|
2
|
+
|
|
3
|
+
grammar Note
|
|
4
|
+
include Pitch
|
|
5
|
+
include Accent
|
|
6
|
+
include Link
|
|
7
|
+
include Duration
|
|
8
|
+
|
|
9
|
+
rule note
|
|
10
|
+
polyphonic_note / monophonic_note / rest_note
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
rule rest_note
|
|
14
|
+
duration:duration <RestNoteNode>
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
rule monophonic_note
|
|
18
|
+
duration pl:pitch_link acc:(accent)? <MonophonicNoteNode>
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
rule polyphonic_note
|
|
22
|
+
duration pl:pitch_link more_pitches:("," pl:pitch_link)+ acc:(accent)? <PolyphonicNoteNode>
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
rule pitch_link
|
|
26
|
+
pitch the_link:link?
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
class String
|
|
2
|
+
def to_accent
|
|
3
|
+
case self
|
|
4
|
+
when "."
|
|
5
|
+
accent = Music::Transcription::Accent::Staccato.new
|
|
6
|
+
when "'"
|
|
7
|
+
accent = Music::Transcription::Accent::Staccatissimo.new
|
|
8
|
+
when ">"
|
|
9
|
+
accent = Music::Transcription::Accent::Marcato.new
|
|
10
|
+
when "^"
|
|
11
|
+
accent = Music::Transcription::Accent::Martellato.new
|
|
12
|
+
when "_"
|
|
13
|
+
accent = Music::Transcription::Accent::Tenuto.new
|
|
14
|
+
else
|
|
15
|
+
raise RuntimeError, "no accent found for #{self}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module Brevity
|
|
21
|
+
class NoteNode < Treetop::Runtime::SyntaxNode
|
|
22
|
+
def itemize(env)
|
|
23
|
+
Itemization.new(notes: [self.to_note])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def primitives env
|
|
27
|
+
[ self.to_note ]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class RestNoteNode < NoteNode
|
|
32
|
+
def to_note
|
|
33
|
+
Music::Transcription::Note.new(duration.to_r)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class MonophonicNoteNode < NoteNode
|
|
38
|
+
def to_note
|
|
39
|
+
pitches = [ pl.pitch.to_pitch ]
|
|
40
|
+
links = {}
|
|
41
|
+
unless pl.the_link.empty?
|
|
42
|
+
links[pitches[0]] = pl.the_link.to_link
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
if acc.empty?
|
|
46
|
+
Music::Transcription::Note.new(duration.to_r,pitches,links:links)
|
|
47
|
+
else
|
|
48
|
+
accent = acc.text_value.to_accent
|
|
49
|
+
Music::Transcription::Note.new(duration.to_r,pitches,links:links,accent:accent)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class PolyphonicNoteNode < NoteNode
|
|
55
|
+
def to_note
|
|
56
|
+
pitches = [ pl.pitch.to_pitch ]
|
|
57
|
+
links = {}
|
|
58
|
+
unless pl.the_link.empty?
|
|
59
|
+
links[pitches[0]] = pl.the_link.to_link
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
more_pitches.elements.each do |mp|
|
|
63
|
+
pitches.push mp.pl.pitch.to_pitch
|
|
64
|
+
unless mp.pl.the_link.empty?
|
|
65
|
+
links[pitches[-1]] = mp.pl.the_link.to_link
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
if acc.empty?
|
|
70
|
+
Music::Transcription::Note.new(duration.to_r,pitches,links:links)
|
|
71
|
+
else
|
|
72
|
+
accent = acc.text_value.to_accent
|
|
73
|
+
Music::Transcription::Note.new(duration.to_r,pitches,links:links,accent:accent)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module Brevity
|
|
5
|
+
|
|
6
|
+
module Pitch
|
|
7
|
+
include Treetop::Runtime
|
|
8
|
+
|
|
9
|
+
def root
|
|
10
|
+
@root ||= :pitch
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module Pitch0
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def _nt_pitch
|
|
17
|
+
start_index = index
|
|
18
|
+
if node_cache[:pitch].has_key?(index)
|
|
19
|
+
cached = node_cache[:pitch][index]
|
|
20
|
+
if cached
|
|
21
|
+
node_cache[:pitch][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
|
22
|
+
@index = cached.interval.end
|
|
23
|
+
end
|
|
24
|
+
return cached
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
i0, s0 = index, []
|
|
28
|
+
if has_terminal?(@regexps[gr = '\A[A-Ga-g]'] ||= Regexp.new(gr), :regexp, index)
|
|
29
|
+
r1 = true
|
|
30
|
+
@index += 1
|
|
31
|
+
else
|
|
32
|
+
terminal_parse_failure('[A-Ga-g]')
|
|
33
|
+
r1 = nil
|
|
34
|
+
end
|
|
35
|
+
s0 << r1
|
|
36
|
+
if r1
|
|
37
|
+
if has_terminal?(@regexps[gr = '\A[#b]'] ||= Regexp.new(gr), :regexp, index)
|
|
38
|
+
r3 = true
|
|
39
|
+
@index += 1
|
|
40
|
+
else
|
|
41
|
+
terminal_parse_failure('[#b]')
|
|
42
|
+
r3 = nil
|
|
43
|
+
end
|
|
44
|
+
if r3
|
|
45
|
+
r2 = r3
|
|
46
|
+
else
|
|
47
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
|
48
|
+
end
|
|
49
|
+
s0 << r2
|
|
50
|
+
if r2
|
|
51
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
|
52
|
+
r4 = true
|
|
53
|
+
@index += 1
|
|
54
|
+
else
|
|
55
|
+
terminal_parse_failure('[0-9]')
|
|
56
|
+
r4 = nil
|
|
57
|
+
end
|
|
58
|
+
s0 << r4
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
if s0.last
|
|
62
|
+
r0 = instantiate_node(PitchNode,input, i0...index, s0)
|
|
63
|
+
r0.extend(Pitch0)
|
|
64
|
+
else
|
|
65
|
+
@index = i0
|
|
66
|
+
r0 = nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
node_cache[:pitch][start_index] = r0
|
|
70
|
+
|
|
71
|
+
r0
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class PitchParser < Treetop::Runtime::CompiledParser
|
|
77
|
+
include Pitch
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
class String
|
|
2
|
+
# Create a Pitch object from a string (e.g. "C2"). String can contain a letter (A-G),
|
|
3
|
+
# to indicate the semitone, followed by an optional sharp/flat (#/b) and then the
|
|
4
|
+
# octave number (non-negative integer).
|
|
5
|
+
def to_pitch
|
|
6
|
+
string = self
|
|
7
|
+
if string =~ /[AaBbCcDdEeFfGg][#b][\d]+/
|
|
8
|
+
semitone = letter_to_semitone string[0]
|
|
9
|
+
semitone = case string[1]
|
|
10
|
+
when "#" then semitone + 1
|
|
11
|
+
when "b" then semitone - 1
|
|
12
|
+
else raise ArgumentError, "unexpected symbol found"
|
|
13
|
+
end
|
|
14
|
+
octave = string[2..-1].to_i
|
|
15
|
+
return Music::Transcription::Pitch.new(:octave => octave, :semitone => semitone)
|
|
16
|
+
elsif string =~ /[AaBbCcDdEeFfGg][\d]+/
|
|
17
|
+
semitone = letter_to_semitone string[0]
|
|
18
|
+
octave = string[1..-1].to_i
|
|
19
|
+
return Music::Transcription::Pitch.new(:octave => octave, :semitone => semitone)
|
|
20
|
+
else
|
|
21
|
+
raise ArgumentError, "string #{string} cannot be converted to a pitch"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def letter_to_semitone letter
|
|
28
|
+
semitone = case letter
|
|
29
|
+
when /[Cc]/ then 0
|
|
30
|
+
when /[Dd]/ then 2
|
|
31
|
+
when /[Ee]/ then 4
|
|
32
|
+
when /[Ff]/ then 5
|
|
33
|
+
when /[Gg]/ then 7
|
|
34
|
+
when /[Aa]/ then 9
|
|
35
|
+
when /[Bb]/ then 11
|
|
36
|
+
else raise ArgumentError, "invalid letter \"#{letter}\" given"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
return semitone
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
module Brevity
|
|
44
|
+
class PitchNode < Treetop::Runtime::SyntaxNode
|
|
45
|
+
def to_pitch
|
|
46
|
+
# use the added String#to_pitch method
|
|
47
|
+
text_value.to_pitch
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module Brevity
|
|
5
|
+
|
|
6
|
+
module NonnegativeInteger
|
|
7
|
+
include Treetop::Runtime
|
|
8
|
+
|
|
9
|
+
def root
|
|
10
|
+
@root ||= :nonnegative_integer
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def _nt_nonnegative_integer
|
|
14
|
+
start_index = index
|
|
15
|
+
if node_cache[:nonnegative_integer].has_key?(index)
|
|
16
|
+
cached = node_cache[:nonnegative_integer][index]
|
|
17
|
+
if cached
|
|
18
|
+
node_cache[:nonnegative_integer][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
|
19
|
+
@index = cached.interval.end
|
|
20
|
+
end
|
|
21
|
+
return cached
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
s0, i0 = [], index
|
|
25
|
+
loop do
|
|
26
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
|
27
|
+
r1 = true
|
|
28
|
+
@index += 1
|
|
29
|
+
else
|
|
30
|
+
terminal_parse_failure('[0-9]')
|
|
31
|
+
r1 = nil
|
|
32
|
+
end
|
|
33
|
+
if r1
|
|
34
|
+
s0 << r1
|
|
35
|
+
else
|
|
36
|
+
break
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
|
40
|
+
|
|
41
|
+
node_cache[:nonnegative_integer][start_index] = r0
|
|
42
|
+
|
|
43
|
+
r0
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class NonnegativeIntegerParser < Treetop::Runtime::CompiledParser
|
|
49
|
+
include NonnegativeInteger
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module Brevity
|
|
5
|
+
|
|
6
|
+
module PositiveInteger
|
|
7
|
+
include Treetop::Runtime
|
|
8
|
+
|
|
9
|
+
def root
|
|
10
|
+
@root ||= :positive_integer
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
include NonnegativeInteger
|
|
14
|
+
|
|
15
|
+
module PositiveInteger0
|
|
16
|
+
def nonnegative_integer
|
|
17
|
+
elements[2]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module PositiveInteger1
|
|
22
|
+
def to_i
|
|
23
|
+
text_value.to_i
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def _nt_positive_integer
|
|
28
|
+
start_index = index
|
|
29
|
+
if node_cache[:positive_integer].has_key?(index)
|
|
30
|
+
cached = node_cache[:positive_integer][index]
|
|
31
|
+
if cached
|
|
32
|
+
node_cache[:positive_integer][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
|
33
|
+
@index = cached.interval.end
|
|
34
|
+
end
|
|
35
|
+
return cached
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
i0, s0 = index, []
|
|
39
|
+
s1, i1 = [], index
|
|
40
|
+
loop do
|
|
41
|
+
if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
|
|
42
|
+
r2 = true
|
|
43
|
+
@index += 1
|
|
44
|
+
else
|
|
45
|
+
terminal_parse_failure('[0]')
|
|
46
|
+
r2 = nil
|
|
47
|
+
end
|
|
48
|
+
if r2
|
|
49
|
+
s1 << r2
|
|
50
|
+
else
|
|
51
|
+
break
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
|
55
|
+
s0 << r1
|
|
56
|
+
if r1
|
|
57
|
+
if has_terminal?(@regexps[gr = '\A[1-9]'] ||= Regexp.new(gr), :regexp, index)
|
|
58
|
+
r3 = true
|
|
59
|
+
@index += 1
|
|
60
|
+
else
|
|
61
|
+
terminal_parse_failure('[1-9]')
|
|
62
|
+
r3 = nil
|
|
63
|
+
end
|
|
64
|
+
s0 << r3
|
|
65
|
+
if r3
|
|
66
|
+
r4 = _nt_nonnegative_integer
|
|
67
|
+
s0 << r4
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
if s0.last
|
|
71
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
|
72
|
+
r0.extend(PositiveInteger0)
|
|
73
|
+
r0.extend(PositiveInteger1)
|
|
74
|
+
else
|
|
75
|
+
@index = i0
|
|
76
|
+
r0 = nil
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
node_cache[:positive_integer][start_index] = r0
|
|
80
|
+
|
|
81
|
+
r0
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
class PositiveIntegerParser < Treetop::Runtime::CompiledParser
|
|
87
|
+
include PositiveInteger
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
end
|