music-transcription 0.11.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/examples/{make_hip.rb → hip.rb} +8 -2
  4. data/examples/hip_packed.yml +22 -0
  5. data/examples/{make_missed_connection.rb → missed_connection.rb} +8 -2
  6. data/examples/missed_connection.yml +2 -2
  7. data/examples/missed_connection_packed.yml +14 -0
  8. data/examples/{make_song1.rb → song1.rb} +7 -1
  9. data/examples/song1_packed.yml +19 -0
  10. data/examples/{make_song2.rb → song2.rb} +6 -1
  11. data/examples/song2_packed.yml +21 -0
  12. data/lib/music-transcription.rb +11 -3
  13. data/lib/music-transcription/model/link.rb +24 -6
  14. data/lib/music-transcription/model/meter.rb +10 -0
  15. data/lib/music-transcription/model/meters.rb +1 -1
  16. data/lib/music-transcription/model/note.rb +32 -0
  17. data/lib/music-transcription/model/pitch.rb +19 -0
  18. data/lib/music-transcription/packing/change_packing.rb +27 -0
  19. data/lib/music-transcription/packing/part_packing.rb +33 -0
  20. data/lib/music-transcription/packing/program_packing.rb +18 -0
  21. data/lib/music-transcription/packing/score_packing.rb +59 -0
  22. data/lib/music-transcription/parsing/convenience_methods.rb +10 -0
  23. data/lib/music-transcription/parsing/meter_parsing.rb +117 -9
  24. data/lib/music-transcription/parsing/meter_parsing.treetop +12 -0
  25. data/lib/music-transcription/parsing/note_node.rb +42 -0
  26. data/lib/music-transcription/parsing/note_parsing.rb +57 -180
  27. data/lib/music-transcription/parsing/note_parsing.treetop +2 -19
  28. data/lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb +178 -0
  29. data/lib/music-transcription/parsing/numbers/nonnegative_float_parsing.treetop +19 -0
  30. data/lib/music-transcription/parsing/{nonnegative_integer_parsing.rb → numbers/nonnegative_integer_parsing.rb} +9 -0
  31. data/lib/music-transcription/parsing/{nonnegative_integer_parsing.treetop → numbers/nonnegative_integer_parsing.treetop} +7 -1
  32. data/lib/music-transcription/parsing/numbers/nonnegative_rational_parsing.rb +88 -0
  33. data/lib/music-transcription/parsing/numbers/nonnegative_rational_parsing.treetop +22 -0
  34. data/lib/music-transcription/parsing/{positive_integer_parsing.rb → numbers/positive_integer_parsing.rb} +0 -0
  35. data/lib/music-transcription/parsing/{positive_integer_parsing.treetop → numbers/positive_integer_parsing.treetop} +0 -0
  36. data/lib/music-transcription/parsing/segment_parsing.rb +143 -0
  37. data/lib/music-transcription/parsing/segment_parsing.treetop +25 -0
  38. data/lib/music-transcription/version.rb +1 -1
  39. data/spec/model/link_spec.rb +44 -60
  40. data/spec/model/meter_spec.rb +18 -0
  41. data/spec/model/note_spec.rb +39 -0
  42. data/spec/model/pitch_spec.rb +32 -0
  43. data/spec/packing/change_packing_spec.rb +91 -0
  44. data/spec/packing/part_packing_spec.rb +66 -0
  45. data/spec/packing/program_packing_spec.rb +33 -0
  46. data/spec/packing/score_packing_spec.rb +122 -0
  47. data/spec/parsing/meter_parsing_spec.rb +2 -2
  48. data/spec/parsing/note_node_spec.rb +87 -0
  49. data/spec/parsing/note_parsing_spec.rb +3 -0
  50. data/spec/parsing/numbers/nonnegative_float_spec.rb +11 -0
  51. data/spec/parsing/{nonnegative_integer_spec.rb → numbers/nonnegative_integer_spec.rb} +1 -1
  52. data/spec/parsing/numbers/nonnegative_rational_spec.rb +11 -0
  53. data/spec/parsing/{positive_integer_spec.rb → numbers/positive_integer_spec.rb} +1 -1
  54. data/spec/parsing/segment_parsing_spec.rb +27 -0
  55. metadata +45 -17
  56. data/lib/music-transcription/parsing/note_nodes.rb +0 -64
  57. data/spec/parsing/note_nodes_spec.rb +0 -84
@@ -9,28 +9,11 @@ grammar Note
9
9
  include Duration
10
10
 
11
11
  rule note
12
- polyphonic_note / monophonic_note / rest_note
13
- end
14
-
15
- rule rest_note
16
- duration:duration <RestNoteNode>
17
- end
18
-
19
- rule monophonic_note
20
- duration
21
- art:articulation?
22
- pl:pitch_link
23
- acc:accent?
24
- <MonophonicNoteNode>
25
- end
26
-
27
- rule polyphonic_note
28
12
  duration
29
13
  art:articulation?
30
- pl:pitch_link
31
- more_pitches:("," pl:pitch_link)+
14
+ pitch_links:(first:pitch_link more:("," pl:pitch_link)*)?
32
15
  acc:accent?
33
- <PolyphonicNoteNode>
16
+ <NoteNode>
34
17
  end
35
18
 
36
19
  rule pitch_link
@@ -0,0 +1,178 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Music
5
+ module Transcription
6
+ module Parsing
7
+
8
+ module NonnegativeFloat
9
+ include Treetop::Runtime
10
+
11
+ def root
12
+ @root ||= :nonnegative_float
13
+ end
14
+
15
+ module NonnegativeFloat0
16
+ end
17
+
18
+ module NonnegativeFloat1
19
+ end
20
+
21
+ module NonnegativeFloat2
22
+ def to_f
23
+ text_value.to_f
24
+ end
25
+
26
+ alias :to_num :to_f
27
+ end
28
+
29
+ def _nt_nonnegative_float
30
+ start_index = index
31
+ if node_cache[:nonnegative_float].has_key?(index)
32
+ cached = node_cache[:nonnegative_float][index]
33
+ if cached
34
+ node_cache[:nonnegative_float][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
35
+ @index = cached.interval.end
36
+ end
37
+ return cached
38
+ end
39
+
40
+ i0, s0 = index, []
41
+ s1, i1 = [], index
42
+ loop do
43
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
44
+ r2 = true
45
+ @index += 1
46
+ else
47
+ terminal_parse_failure('[0-9]')
48
+ r2 = nil
49
+ end
50
+ if r2
51
+ s1 << r2
52
+ else
53
+ break
54
+ end
55
+ end
56
+ if s1.empty?
57
+ @index = i1
58
+ r1 = nil
59
+ else
60
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
61
+ end
62
+ s0 << r1
63
+ if r1
64
+ if has_terminal?(@regexps[gr = '\A[.]'] ||= Regexp.new(gr), :regexp, index)
65
+ r3 = true
66
+ @index += 1
67
+ else
68
+ terminal_parse_failure('[.]')
69
+ r3 = nil
70
+ end
71
+ s0 << r3
72
+ if r3
73
+ s4, i4 = [], index
74
+ loop do
75
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
76
+ r5 = true
77
+ @index += 1
78
+ else
79
+ terminal_parse_failure('[0-9]')
80
+ r5 = nil
81
+ end
82
+ if r5
83
+ s4 << r5
84
+ else
85
+ break
86
+ end
87
+ end
88
+ if s4.empty?
89
+ @index = i4
90
+ r4 = nil
91
+ else
92
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
93
+ end
94
+ s0 << r4
95
+ if r4
96
+ i7, s7 = index, []
97
+ if (match_len = has_terminal?("e", false, index))
98
+ r8 = true
99
+ @index += match_len
100
+ else
101
+ terminal_parse_failure("e")
102
+ r8 = nil
103
+ end
104
+ s7 << r8
105
+ if r8
106
+ if has_terminal?(@regexps[gr = '\A[+-]'] ||= Regexp.new(gr), :regexp, index)
107
+ r9 = true
108
+ @index += 1
109
+ else
110
+ terminal_parse_failure('[+-]')
111
+ r9 = nil
112
+ end
113
+ s7 << r9
114
+ if r9
115
+ s10, i10 = [], index
116
+ loop do
117
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
118
+ r11 = true
119
+ @index += 1
120
+ else
121
+ terminal_parse_failure('[0-9]')
122
+ r11 = nil
123
+ end
124
+ if r11
125
+ s10 << r11
126
+ else
127
+ break
128
+ end
129
+ end
130
+ if s10.empty?
131
+ @index = i10
132
+ r10 = nil
133
+ else
134
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
135
+ end
136
+ s7 << r10
137
+ end
138
+ end
139
+ if s7.last
140
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
141
+ r7.extend(NonnegativeFloat0)
142
+ else
143
+ @index = i7
144
+ r7 = nil
145
+ end
146
+ if r7
147
+ r6 = r7
148
+ else
149
+ r6 = instantiate_node(SyntaxNode,input, index...index)
150
+ end
151
+ s0 << r6
152
+ end
153
+ end
154
+ end
155
+ if s0.last
156
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
157
+ r0.extend(NonnegativeFloat1)
158
+ r0.extend(NonnegativeFloat2)
159
+ else
160
+ @index = i0
161
+ r0 = nil
162
+ end
163
+
164
+ node_cache[:nonnegative_float][start_index] = r0
165
+
166
+ r0
167
+ end
168
+
169
+ end
170
+
171
+ class NonnegativeFloatParser < Treetop::Runtime::CompiledParser
172
+ include NonnegativeFloat
173
+ end
174
+
175
+
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,19 @@
1
+ module Music
2
+ module Transcription
3
+ module Parsing
4
+
5
+ grammar NonnegativeFloat
6
+ rule nonnegative_float
7
+ [0-9]+ [.] [0-9]+ ("e" [+-] [0-9]+)? {
8
+ def to_f
9
+ text_value.to_f
10
+ end
11
+
12
+ alias :to_num :to_f
13
+ }
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -12,6 +12,14 @@ module NonnegativeInteger
12
12
  @root ||= :nonnegative_integer
13
13
  end
14
14
 
15
+ module NonnegativeInteger0
16
+ def to_i
17
+ text_value.to_i
18
+ end
19
+
20
+ alias :to_num :to_i
21
+ end
22
+
15
23
  def _nt_nonnegative_integer
16
24
  start_index = index
17
25
  if node_cache[:nonnegative_integer].has_key?(index)
@@ -39,6 +47,7 @@ module NonnegativeInteger
39
47
  end
40
48
  end
41
49
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
50
+ r0.extend(NonnegativeInteger0)
42
51
 
43
52
  node_cache[:nonnegative_integer][start_index] = r0
44
53
 
@@ -4,7 +4,13 @@ module Parsing
4
4
 
5
5
  grammar NonnegativeInteger
6
6
  rule nonnegative_integer
7
- [0-9]*
7
+ [0-9]* {
8
+ def to_i
9
+ text_value.to_i
10
+ end
11
+
12
+ alias :to_num :to_i
13
+ }
8
14
  end
9
15
  end
10
16
 
@@ -0,0 +1,88 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Music
5
+ module Transcription
6
+ module Parsing
7
+
8
+ module NonnegativeRational
9
+ include Treetop::Runtime
10
+
11
+ def root
12
+ @root ||= :nonnegative_rational
13
+ end
14
+
15
+ include NonnegativeInteger
16
+
17
+ include PositiveInteger
18
+
19
+ module NonnegativeRational0
20
+ def nonnegative_integer
21
+ elements[0]
22
+ end
23
+
24
+ def positive_integer
25
+ elements[2]
26
+ end
27
+ end
28
+
29
+ module NonnegativeRational1
30
+ def to_r
31
+ text_value.to_r
32
+ end
33
+
34
+ alias :to_num :to_r
35
+ end
36
+
37
+ def _nt_nonnegative_rational
38
+ start_index = index
39
+ if node_cache[:nonnegative_rational].has_key?(index)
40
+ cached = node_cache[:nonnegative_rational][index]
41
+ if cached
42
+ node_cache[:nonnegative_rational][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
43
+ @index = cached.interval.end
44
+ end
45
+ return cached
46
+ end
47
+
48
+ i0, s0 = index, []
49
+ r1 = _nt_nonnegative_integer
50
+ s0 << r1
51
+ if r1
52
+ if (match_len = has_terminal?("/", false, index))
53
+ r2 = true
54
+ @index += match_len
55
+ else
56
+ terminal_parse_failure("/")
57
+ r2 = nil
58
+ end
59
+ s0 << r2
60
+ if r2
61
+ r3 = _nt_positive_integer
62
+ s0 << r3
63
+ end
64
+ end
65
+ if s0.last
66
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
67
+ r0.extend(NonnegativeRational0)
68
+ r0.extend(NonnegativeRational1)
69
+ else
70
+ @index = i0
71
+ r0 = nil
72
+ end
73
+
74
+ node_cache[:nonnegative_rational][start_index] = r0
75
+
76
+ r0
77
+ end
78
+
79
+ end
80
+
81
+ class NonnegativeRationalParser < Treetop::Runtime::CompiledParser
82
+ include NonnegativeRational
83
+ end
84
+
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,22 @@
1
+ module Music
2
+ module Transcription
3
+ module Parsing
4
+
5
+ grammar NonnegativeRational
6
+ include NonnegativeInteger
7
+ include PositiveInteger
8
+
9
+ rule nonnegative_rational
10
+ nonnegative_integer "/" positive_integer {
11
+ def to_r
12
+ text_value.to_r
13
+ end
14
+
15
+ alias :to_num :to_r
16
+ }
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,143 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Music
5
+ module Transcription
6
+ module Parsing
7
+
8
+ module Segment
9
+ include Treetop::Runtime
10
+
11
+ def root
12
+ @root ||= :range
13
+ end
14
+
15
+ include NonnegativeInteger
16
+
17
+ include NonnegativeFloat
18
+
19
+ include NonnegativeRational
20
+
21
+ module Range0
22
+ def first
23
+ elements[0]
24
+ end
25
+
26
+ def last
27
+ elements[2]
28
+ end
29
+ end
30
+
31
+ module Range1
32
+ def to_range
33
+ first.to_num...last.to_num
34
+ end
35
+ end
36
+
37
+ def _nt_range
38
+ start_index = index
39
+ if node_cache[:range].has_key?(index)
40
+ cached = node_cache[:range][index]
41
+ if cached
42
+ node_cache[:range][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
43
+ @index = cached.interval.end
44
+ end
45
+ return cached
46
+ end
47
+
48
+ i0, s0 = index, []
49
+ r1 = _nt_nonnegative_number
50
+ s0 << r1
51
+ if r1
52
+ s2, i2 = [], index
53
+ loop do
54
+ if has_terminal?(@regexps[gr = '\A[.]'] ||= Regexp.new(gr), :regexp, index)
55
+ r3 = true
56
+ @index += 1
57
+ else
58
+ terminal_parse_failure('[.]')
59
+ r3 = nil
60
+ end
61
+ if r3
62
+ s2 << r3
63
+ else
64
+ break
65
+ end
66
+ if s2.size == 3
67
+ break
68
+ end
69
+ end
70
+ if s2.size < 2
71
+ @index = i2
72
+ r2 = nil
73
+ else
74
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
75
+ end
76
+ s0 << r2
77
+ if r2
78
+ r4 = _nt_nonnegative_number
79
+ s0 << r4
80
+ end
81
+ end
82
+ if s0.last
83
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
84
+ r0.extend(Range0)
85
+ r0.extend(Range1)
86
+ else
87
+ @index = i0
88
+ r0 = nil
89
+ end
90
+
91
+ node_cache[:range][start_index] = r0
92
+
93
+ r0
94
+ end
95
+
96
+ def _nt_nonnegative_number
97
+ start_index = index
98
+ if node_cache[:nonnegative_number].has_key?(index)
99
+ cached = node_cache[:nonnegative_number][index]
100
+ if cached
101
+ node_cache[:nonnegative_number][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
102
+ @index = cached.interval.end
103
+ end
104
+ return cached
105
+ end
106
+
107
+ i0 = index
108
+ r1 = _nt_nonnegative_float
109
+ if r1
110
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
111
+ r0 = r1
112
+ else
113
+ r2 = _nt_nonnegative_rational
114
+ if r2
115
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
116
+ r0 = r2
117
+ else
118
+ r3 = _nt_nonnegative_integer
119
+ if r3
120
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
121
+ r0 = r3
122
+ else
123
+ @index = i0
124
+ r0 = nil
125
+ end
126
+ end
127
+ end
128
+
129
+ node_cache[:nonnegative_number][start_index] = r0
130
+
131
+ r0
132
+ end
133
+
134
+ end
135
+
136
+ class SegmentParser < Treetop::Runtime::CompiledParser
137
+ include Segment
138
+ end
139
+
140
+
141
+ end
142
+ end
143
+ end