music-transcription 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +34 -0
  3. data/lib/music-transcription/change.rb +2 -2
  4. data/lib/music-transcription/meter.rb +3 -4
  5. data/lib/music-transcription/note.rb +1 -2
  6. data/lib/music-transcription/parsing/articulation_parsing.rb +266 -0
  7. data/lib/music-transcription/parsing/articulation_parsing.treetop +61 -0
  8. data/lib/music-transcription/parsing/convenience_methods.rb +83 -0
  9. data/lib/music-transcription/parsing/duration_nodes.rb +23 -0
  10. data/lib/music-transcription/parsing/duration_parsing.rb +207 -0
  11. data/lib/music-transcription/parsing/duration_parsing.treetop +27 -0
  12. data/lib/music-transcription/parsing/link_nodes.rb +37 -0
  13. data/lib/music-transcription/parsing/link_parsing.rb +272 -0
  14. data/lib/music-transcription/parsing/link_parsing.treetop +35 -0
  15. data/lib/music-transcription/parsing/nonnegative_integer_parsing.rb +57 -0
  16. data/lib/music-transcription/parsing/nonnegative_integer_parsing.treetop +13 -0
  17. data/lib/music-transcription/parsing/note_nodes.rb +64 -0
  18. data/lib/music-transcription/parsing/note_parsing.rb +354 -0
  19. data/lib/music-transcription/parsing/note_parsing.treetop +47 -0
  20. data/lib/music-transcription/parsing/pitch_node.rb +20 -0
  21. data/lib/music-transcription/parsing/pitch_parsing.rb +355 -0
  22. data/lib/music-transcription/parsing/pitch_parsing.treetop +45 -0
  23. data/lib/music-transcription/parsing/positive_integer_parsing.rb +95 -0
  24. data/lib/music-transcription/parsing/positive_integer_parsing.treetop +19 -0
  25. data/lib/music-transcription/part.rb +1 -1
  26. data/lib/music-transcription/program.rb +1 -4
  27. data/lib/music-transcription/score.rb +1 -1
  28. data/lib/music-transcription/validatable.rb +16 -1
  29. data/lib/music-transcription/version.rb +1 -1
  30. data/lib/music-transcription.rb +14 -0
  31. data/music-transcription.gemspec +2 -0
  32. data/spec/parsing/articulation_parsing_spec.rb +23 -0
  33. data/spec/parsing/convenience_methods_spec.rb +89 -0
  34. data/spec/parsing/duration_nodes_spec.rb +83 -0
  35. data/spec/parsing/duration_parsing_spec.rb +70 -0
  36. data/spec/parsing/link_nodes_spec.rb +30 -0
  37. data/spec/parsing/link_parsing_spec.rb +23 -0
  38. data/spec/parsing/nonnegative_integer_spec.rb +11 -0
  39. data/spec/parsing/note_nodes_spec.rb +84 -0
  40. data/spec/parsing/note_parsing_spec.rb +43 -0
  41. data/spec/parsing/pitch_node_spec.rb +32 -0
  42. data/spec/parsing/pitch_parsing_spec.rb +23 -0
  43. data/spec/parsing/positive_integer_spec.rb +17 -0
  44. data/spec/spec_helper.rb +12 -0
  45. metadata +59 -2
@@ -0,0 +1,23 @@
1
+ module Music
2
+ module Transcription
3
+ module Parsing
4
+ class NumDenNode < Treetop::Runtime::SyntaxNode
5
+ def to_r
6
+ text_value.to_r
7
+ end
8
+ end
9
+
10
+ class NumOnlyNode < Treetop::Runtime::SyntaxNode
11
+ def to_r
12
+ Rational(numerator.text_value.to_i,1)
13
+ end
14
+ end
15
+
16
+ class DenOnlyNode < Treetop::Runtime::SyntaxNode
17
+ def to_r
18
+ Rational(1,denominator.text_value.to_i)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,207 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Music
5
+ module Transcription
6
+ module Parsing
7
+
8
+ module Duration
9
+ include Treetop::Runtime
10
+
11
+ def root
12
+ @root ||= :duration
13
+ end
14
+
15
+ include PositiveInteger
16
+
17
+ def _nt_duration
18
+ start_index = index
19
+ if node_cache[:duration].has_key?(index)
20
+ cached = node_cache[:duration][index]
21
+ if cached
22
+ node_cache[:duration][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
23
+ @index = cached.interval.end
24
+ end
25
+ return cached
26
+ end
27
+
28
+ i0 = index
29
+ r1 = _nt_num_and_den
30
+ if r1
31
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
32
+ r0 = r1
33
+ else
34
+ r2 = _nt_num_only
35
+ if r2
36
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
37
+ r0 = r2
38
+ else
39
+ r3 = _nt_den_only
40
+ if r3
41
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
42
+ r0 = r3
43
+ else
44
+ @index = i0
45
+ r0 = nil
46
+ end
47
+ end
48
+ end
49
+
50
+ node_cache[:duration][start_index] = r0
51
+
52
+ r0
53
+ end
54
+
55
+ module NumAndDen0
56
+ def positive_integer1
57
+ elements[0]
58
+ end
59
+
60
+ def positive_integer2
61
+ elements[2]
62
+ end
63
+ end
64
+
65
+ def _nt_num_and_den
66
+ start_index = index
67
+ if node_cache[:num_and_den].has_key?(index)
68
+ cached = node_cache[:num_and_den][index]
69
+ if cached
70
+ node_cache[:num_and_den][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_positive_integer
78
+ s0 << r1
79
+ if r1
80
+ if (match_len = has_terminal?("/", false, index))
81
+ r2 = true
82
+ @index += match_len
83
+ else
84
+ terminal_parse_failure("/")
85
+ r2 = nil
86
+ end
87
+ s0 << r2
88
+ if r2
89
+ r3 = _nt_positive_integer
90
+ s0 << r3
91
+ end
92
+ end
93
+ if s0.last
94
+ r0 = instantiate_node(NumDenNode,input, i0...index, s0)
95
+ r0.extend(NumAndDen0)
96
+ else
97
+ @index = i0
98
+ r0 = nil
99
+ end
100
+
101
+ node_cache[:num_and_den][start_index] = r0
102
+
103
+ r0
104
+ end
105
+
106
+ module NumOnly0
107
+ def numerator
108
+ elements[0]
109
+ end
110
+
111
+ end
112
+
113
+ def _nt_num_only
114
+ start_index = index
115
+ if node_cache[:num_only].has_key?(index)
116
+ cached = node_cache[:num_only][index]
117
+ if cached
118
+ node_cache[:num_only][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
119
+ @index = cached.interval.end
120
+ end
121
+ return cached
122
+ end
123
+
124
+ i0, s0 = index, []
125
+ r1 = _nt_positive_integer
126
+ s0 << r1
127
+ if r1
128
+ if (match_len = has_terminal?("/", false, index))
129
+ r3 = true
130
+ @index += match_len
131
+ else
132
+ terminal_parse_failure("/")
133
+ r3 = nil
134
+ end
135
+ if r3
136
+ r2 = r3
137
+ else
138
+ r2 = instantiate_node(SyntaxNode,input, index...index)
139
+ end
140
+ s0 << r2
141
+ end
142
+ if s0.last
143
+ r0 = instantiate_node(NumOnlyNode,input, i0...index, s0)
144
+ r0.extend(NumOnly0)
145
+ else
146
+ @index = i0
147
+ r0 = nil
148
+ end
149
+
150
+ node_cache[:num_only][start_index] = r0
151
+
152
+ r0
153
+ end
154
+
155
+ module DenOnly0
156
+ def denominator
157
+ elements[1]
158
+ end
159
+ end
160
+
161
+ def _nt_den_only
162
+ start_index = index
163
+ if node_cache[:den_only].has_key?(index)
164
+ cached = node_cache[:den_only][index]
165
+ if cached
166
+ node_cache[:den_only][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
167
+ @index = cached.interval.end
168
+ end
169
+ return cached
170
+ end
171
+
172
+ i0, s0 = index, []
173
+ if (match_len = has_terminal?("/", false, index))
174
+ r1 = true
175
+ @index += match_len
176
+ else
177
+ terminal_parse_failure("/")
178
+ r1 = nil
179
+ end
180
+ s0 << r1
181
+ if r1
182
+ r2 = _nt_positive_integer
183
+ s0 << r2
184
+ end
185
+ if s0.last
186
+ r0 = instantiate_node(DenOnlyNode,input, i0...index, s0)
187
+ r0.extend(DenOnly0)
188
+ else
189
+ @index = i0
190
+ r0 = nil
191
+ end
192
+
193
+ node_cache[:den_only][start_index] = r0
194
+
195
+ r0
196
+ end
197
+
198
+ end
199
+
200
+ class DurationParser < Treetop::Runtime::CompiledParser
201
+ include Duration
202
+ end
203
+
204
+
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,27 @@
1
+ module Music
2
+ module Transcription
3
+ module Parsing
4
+
5
+ grammar Duration
6
+ include PositiveInteger
7
+
8
+ rule duration
9
+ num_and_den / num_only / den_only
10
+ end
11
+
12
+ rule num_and_den
13
+ positive_integer "/" positive_integer <NumDenNode>
14
+ end
15
+
16
+ rule num_only
17
+ numerator:positive_integer "/"? <NumOnlyNode>
18
+ end
19
+
20
+ rule den_only
21
+ "/" denominator:positive_integer <DenOnlyNode>
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ module Music
2
+ module Transcription
3
+ module Parsing
4
+ class LinkNode < Treetop::Runtime::SyntaxNode; end
5
+
6
+ class SlurNode < LinkNode
7
+ def to_link
8
+ Music::Transcription::Link::Slur.new(target.to_pitch)
9
+ end
10
+ end
11
+
12
+ class LegatoNode < LinkNode
13
+ def to_link
14
+ Music::Transcription::Link::Legato.new(target.to_pitch)
15
+ end
16
+ end
17
+
18
+ class GlissandoNode < LinkNode
19
+ def to_link
20
+ Music::Transcription::Link::Glissando.new(target.to_pitch)
21
+ end
22
+ end
23
+
24
+ class PortamentoNode < LinkNode
25
+ def to_link
26
+ Music::Transcription::Link::Portamento.new(target.to_pitch)
27
+ end
28
+ end
29
+
30
+ class TieNode < LinkNode
31
+ def to_link
32
+ Music::Transcription::Link::Tie.new
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,272 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Music
5
+ module Transcription
6
+ module Parsing
7
+
8
+ module Link
9
+ include Treetop::Runtime
10
+
11
+ def root
12
+ @root ||= :link
13
+ end
14
+
15
+ include Pitch
16
+
17
+ def _nt_link
18
+ start_index = index
19
+ if node_cache[:link].has_key?(index)
20
+ cached = node_cache[:link][index]
21
+ if cached
22
+ node_cache[:link][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
23
+ @index = cached.interval.end
24
+ end
25
+ return cached
26
+ end
27
+
28
+ i0 = index
29
+ r1 = _nt_slur_link
30
+ if r1
31
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
32
+ r0 = r1
33
+ else
34
+ r2 = _nt_tie
35
+ if r2
36
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
37
+ r0 = r2
38
+ else
39
+ r3 = _nt_legato_link
40
+ if r3
41
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
42
+ r0 = r3
43
+ else
44
+ r4 = _nt_glissando
45
+ if r4
46
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
47
+ r0 = r4
48
+ else
49
+ r5 = _nt_portamento
50
+ if r5
51
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
52
+ r0 = r5
53
+ else
54
+ @index = i0
55
+ r0 = nil
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ node_cache[:link][start_index] = r0
63
+
64
+ r0
65
+ end
66
+
67
+ module SlurLink0
68
+ def target
69
+ elements[1]
70
+ end
71
+ end
72
+
73
+ def _nt_slur_link
74
+ start_index = index
75
+ if node_cache[:slur_link].has_key?(index)
76
+ cached = node_cache[:slur_link][index]
77
+ if cached
78
+ node_cache[:slur_link][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
79
+ @index = cached.interval.end
80
+ end
81
+ return cached
82
+ end
83
+
84
+ i0, s0 = index, []
85
+ if (match_len = has_terminal?("=", false, index))
86
+ r1 = true
87
+ @index += match_len
88
+ else
89
+ terminal_parse_failure("=")
90
+ r1 = nil
91
+ end
92
+ s0 << r1
93
+ if r1
94
+ r2 = _nt_pitch
95
+ s0 << r2
96
+ end
97
+ if s0.last
98
+ r0 = instantiate_node(SlurNode,input, i0...index, s0)
99
+ r0.extend(SlurLink0)
100
+ else
101
+ @index = i0
102
+ r0 = nil
103
+ end
104
+
105
+ node_cache[:slur_link][start_index] = r0
106
+
107
+ r0
108
+ end
109
+
110
+ def _nt_tie
111
+ start_index = index
112
+ if node_cache[:tie].has_key?(index)
113
+ cached = node_cache[:tie][index]
114
+ if cached
115
+ node_cache[:tie][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
116
+ @index = cached.interval.end
117
+ end
118
+ return cached
119
+ end
120
+
121
+ if (match_len = has_terminal?("=", false, index))
122
+ r0 = instantiate_node(TieNode,input, index...(index + match_len))
123
+ @index += match_len
124
+ else
125
+ terminal_parse_failure("=")
126
+ r0 = nil
127
+ end
128
+
129
+ node_cache[:tie][start_index] = r0
130
+
131
+ r0
132
+ end
133
+
134
+ module LegatoLink0
135
+ def target
136
+ elements[1]
137
+ end
138
+ end
139
+
140
+ def _nt_legato_link
141
+ start_index = index
142
+ if node_cache[:legato_link].has_key?(index)
143
+ cached = node_cache[:legato_link][index]
144
+ if cached
145
+ node_cache[:legato_link][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
146
+ @index = cached.interval.end
147
+ end
148
+ return cached
149
+ end
150
+
151
+ i0, s0 = index, []
152
+ if (match_len = has_terminal?("-", false, index))
153
+ r1 = true
154
+ @index += match_len
155
+ else
156
+ terminal_parse_failure("-")
157
+ r1 = nil
158
+ end
159
+ s0 << r1
160
+ if r1
161
+ r2 = _nt_pitch
162
+ s0 << r2
163
+ end
164
+ if s0.last
165
+ r0 = instantiate_node(LegatoNode,input, i0...index, s0)
166
+ r0.extend(LegatoLink0)
167
+ else
168
+ @index = i0
169
+ r0 = nil
170
+ end
171
+
172
+ node_cache[:legato_link][start_index] = r0
173
+
174
+ r0
175
+ end
176
+
177
+ module Glissando0
178
+ def target
179
+ elements[1]
180
+ end
181
+ end
182
+
183
+ def _nt_glissando
184
+ start_index = index
185
+ if node_cache[:glissando].has_key?(index)
186
+ cached = node_cache[:glissando][index]
187
+ if cached
188
+ node_cache[:glissando][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
189
+ @index = cached.interval.end
190
+ end
191
+ return cached
192
+ end
193
+
194
+ i0, s0 = index, []
195
+ if (match_len = has_terminal?("~", false, index))
196
+ r1 = true
197
+ @index += match_len
198
+ else
199
+ terminal_parse_failure("~")
200
+ r1 = nil
201
+ end
202
+ s0 << r1
203
+ if r1
204
+ r2 = _nt_pitch
205
+ s0 << r2
206
+ end
207
+ if s0.last
208
+ r0 = instantiate_node(GlissandoNode,input, i0...index, s0)
209
+ r0.extend(Glissando0)
210
+ else
211
+ @index = i0
212
+ r0 = nil
213
+ end
214
+
215
+ node_cache[:glissando][start_index] = r0
216
+
217
+ r0
218
+ end
219
+
220
+ module Portamento0
221
+ def target
222
+ elements[1]
223
+ end
224
+ end
225
+
226
+ def _nt_portamento
227
+ start_index = index
228
+ if node_cache[:portamento].has_key?(index)
229
+ cached = node_cache[:portamento][index]
230
+ if cached
231
+ node_cache[:portamento][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
232
+ @index = cached.interval.end
233
+ end
234
+ return cached
235
+ end
236
+
237
+ i0, s0 = index, []
238
+ if (match_len = has_terminal?("/", false, index))
239
+ r1 = true
240
+ @index += match_len
241
+ else
242
+ terminal_parse_failure("/")
243
+ r1 = nil
244
+ end
245
+ s0 << r1
246
+ if r1
247
+ r2 = _nt_pitch
248
+ s0 << r2
249
+ end
250
+ if s0.last
251
+ r0 = instantiate_node(PortamentoNode,input, i0...index, s0)
252
+ r0.extend(Portamento0)
253
+ else
254
+ @index = i0
255
+ r0 = nil
256
+ end
257
+
258
+ node_cache[:portamento][start_index] = r0
259
+
260
+ r0
261
+ end
262
+
263
+ end
264
+
265
+ class LinkParser < Treetop::Runtime::CompiledParser
266
+ include Link
267
+ end
268
+
269
+
270
+ end
271
+ end
272
+ end