brevity 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/.document +3 -0
  3. data/.gitignore +7 -0
  4. data/.rspec +1 -0
  5. data/.ruby-version +1 -0
  6. data/.yardopts +1 -0
  7. data/ChangeLog.rdoc +4 -0
  8. data/Gemfile +3 -0
  9. data/LICENSE.txt +20 -0
  10. data/README.rdoc +27 -0
  11. data/Rakefile +67 -0
  12. data/bin/debrief +56 -0
  13. data/brevity.gemspec +28 -0
  14. data/examples/alley_cat.br +50 -0
  15. data/examples/hip.br +15 -0
  16. data/examples/missed_connection.br +6 -0
  17. data/examples/song1.br +11 -0
  18. data/examples/song2.br +10 -0
  19. data/examples/twinkle.br +18 -0
  20. data/lib/brevity/commands/constants.rb +18 -0
  21. data/lib/brevity/commands/expr.rb +17 -0
  22. data/lib/brevity/commands/meter.rb +20 -0
  23. data/lib/brevity/commands/part.rb +47 -0
  24. data/lib/brevity/commands/tempo.rb +13 -0
  25. data/lib/brevity/itemization.rb +73 -0
  26. data/lib/brevity/parsing/expression/dynamic.rb +280 -0
  27. data/lib/brevity/parsing/expression/dynamic.treetop +41 -0
  28. data/lib/brevity/parsing/expression/dynamic_nodes.rb +55 -0
  29. data/lib/brevity/parsing/expression/expression.rb +429 -0
  30. data/lib/brevity/parsing/expression/expression.treetop +39 -0
  31. data/lib/brevity/parsing/expression/expression_nodes.rb +26 -0
  32. data/lib/brevity/parsing/expression/gradual.rb +44 -0
  33. data/lib/brevity/parsing/expression/gradual.treetop +9 -0
  34. data/lib/brevity/parsing/expression/gradual_node.rb +11 -0
  35. data/lib/brevity/parsing/expression/label.rb +75 -0
  36. data/lib/brevity/parsing/expression/label.treetop +9 -0
  37. data/lib/brevity/parsing/expression/label_node.rb +15 -0
  38. data/lib/brevity/parsing/expression/sequence.rb +130 -0
  39. data/lib/brevity/parsing/expression/sequence.treetop +12 -0
  40. data/lib/brevity/parsing/expression/sequence_node.rb +14 -0
  41. data/lib/brevity/parsing/file/command.rb +216 -0
  42. data/lib/brevity/parsing/file/command.treetop +17 -0
  43. data/lib/brevity/parsing/file/command_node.rb +11 -0
  44. data/lib/brevity/parsing/file/comment.rb +178 -0
  45. data/lib/brevity/parsing/file/comment.treetop +21 -0
  46. data/lib/brevity/parsing/file/comment_node.rb +3 -0
  47. data/lib/brevity/parsing/file/file.rb +152 -0
  48. data/lib/brevity/parsing/file/file.treetop +16 -0
  49. data/lib/brevity/parsing/file/file_node.rb +7 -0
  50. data/lib/brevity/parsing/file/path.rb +235 -0
  51. data/lib/brevity/parsing/file/path.treetop +12 -0
  52. data/lib/brevity/parsing/modifiers/duplicate_modifier.rb +65 -0
  53. data/lib/brevity/parsing/modifiers/duplicate_modifier.treetop +11 -0
  54. data/lib/brevity/parsing/modifiers/duplicate_modifier_node.rb +8 -0
  55. data/lib/brevity/parsing/modifiers/modifier.rb +64 -0
  56. data/lib/brevity/parsing/modifiers/modifier.treetop +13 -0
  57. data/lib/brevity/parsing/modifiers/stretch_modifier.rb +69 -0
  58. data/lib/brevity/parsing/modifiers/stretch_modifier.treetop +11 -0
  59. data/lib/brevity/parsing/modifiers/stretch_modifier_node.rb +21 -0
  60. data/lib/brevity/parsing/modifiers/transpose_modifier.rb +69 -0
  61. data/lib/brevity/parsing/modifiers/transpose_modifier.treetop +11 -0
  62. data/lib/brevity/parsing/modifiers/transpose_modifier_node.rb +13 -0
  63. data/lib/brevity/parsing/note/accent.rb +44 -0
  64. data/lib/brevity/parsing/note/accent.treetop +9 -0
  65. data/lib/brevity/parsing/note/duration.rb +203 -0
  66. data/lib/brevity/parsing/note/duration.treetop +23 -0
  67. data/lib/brevity/parsing/note/duration_nodes.rb +19 -0
  68. data/lib/brevity/parsing/note/link.rb +69 -0
  69. data/lib/brevity/parsing/note/link.treetop +11 -0
  70. data/lib/brevity/parsing/note/link_node.rb +19 -0
  71. data/lib/brevity/parsing/note/note.rb +300 -0
  72. data/lib/brevity/parsing/note/note.treetop +30 -0
  73. data/lib/brevity/parsing/note/note_nodes.rb +77 -0
  74. data/lib/brevity/parsing/note/pitch.rb +81 -0
  75. data/lib/brevity/parsing/note/pitch.treetop +9 -0
  76. data/lib/brevity/parsing/note/pitch_node.rb +50 -0
  77. data/lib/brevity/parsing/numbers/nonnegative_integer.rb +53 -0
  78. data/lib/brevity/parsing/numbers/nonnegative_integer.treetop +9 -0
  79. data/lib/brevity/parsing/numbers/positive_integer.rb +91 -0
  80. data/lib/brevity/parsing/numbers/positive_integer.treetop +15 -0
  81. data/lib/brevity/read_file.rb +18 -0
  82. data/lib/brevity/score_maker.rb +64 -0
  83. data/lib/brevity/version.rb +4 -0
  84. data/lib/brevity.rb +53 -0
  85. data/manuals/brevity.pdf +0 -0
  86. data/manuals/brevity.tex +273 -0
  87. data/spec/brevity_spec.rb +8 -0
  88. data/spec/commands/expr_spec.rb +15 -0
  89. data/spec/commands/meter_spec.rb +21 -0
  90. data/spec/commands/part_spec.rb +16 -0
  91. data/spec/commands/tempo_spec.rb +20 -0
  92. data/spec/itemization_spec.rb +46 -0
  93. data/spec/parsing/expression/dynamic_nodes_spec.rb +32 -0
  94. data/spec/parsing/expression/dynamic_spec.rb +23 -0
  95. data/spec/parsing/expression/expression_nodes_spec.rb +87 -0
  96. data/spec/parsing/expression/expression_spec.rb +85 -0
  97. data/spec/parsing/expression/gradual_spec.rb +10 -0
  98. data/spec/parsing/expression/label_node_spec.rb +13 -0
  99. data/spec/parsing/expression/label_spec.rb +35 -0
  100. data/spec/parsing/file/command_node_spec.rb +29 -0
  101. data/spec/parsing/file/command_spec.rb +18 -0
  102. data/spec/parsing/file/comment_spec.rb +14 -0
  103. data/spec/parsing/file/file_node_spec.rb +19 -0
  104. data/spec/parsing/file/file_spec.rb +30 -0
  105. data/spec/parsing/modifiers/modifier_nodes_spec.rb +25 -0
  106. data/spec/parsing/modifiers/modifier_parsers_spec.rb +20 -0
  107. data/spec/parsing/note/accent_spec.rb +27 -0
  108. data/spec/parsing/note/duration_nodes_spec.rb +79 -0
  109. data/spec/parsing/note/duration_spec.rb +69 -0
  110. data/spec/parsing/note/link_node_spec.rb +30 -0
  111. data/spec/parsing/note/link_spec.rb +23 -0
  112. data/spec/parsing/note/note_nodes_spec.rb +82 -0
  113. data/spec/parsing/note/note_spec.rb +188 -0
  114. data/spec/parsing/note/pitch_node_spec.rb +48 -0
  115. data/spec/parsing/note/pitch_spec.rb +23 -0
  116. data/spec/parsing/numbers/nonnegative_integer_spec.rb +11 -0
  117. data/spec/parsing/numbers/positive_integer_spec.rb +17 -0
  118. data/spec/spec_helper.rb +112 -0
  119. metadata +293 -0
@@ -0,0 +1,69 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Brevity
5
+
6
+ module TransposeModifier
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :transpose_modifier
11
+ end
12
+
13
+ include NonnegativeInteger
14
+
15
+ module TransposeModifier0
16
+ def op
17
+ elements[0]
18
+ end
19
+
20
+ def nsem
21
+ elements[1]
22
+ end
23
+ end
24
+
25
+ def _nt_transpose_modifier
26
+ start_index = index
27
+ if node_cache[:transpose_modifier].has_key?(index)
28
+ cached = node_cache[:transpose_modifier][index]
29
+ if cached
30
+ node_cache[:transpose_modifier][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
31
+ @index = cached.interval.end
32
+ end
33
+ return cached
34
+ end
35
+
36
+ i0, s0 = index, []
37
+ if has_terminal?(@regexps[gr = '\A[+-]'] ||= Regexp.new(gr), :regexp, index)
38
+ r1 = true
39
+ @index += 1
40
+ else
41
+ terminal_parse_failure('[+-]')
42
+ r1 = nil
43
+ end
44
+ s0 << r1
45
+ if r1
46
+ r2 = _nt_nonnegative_integer
47
+ s0 << r2
48
+ end
49
+ if s0.last
50
+ r0 = instantiate_node(TransposeModifierNode,input, i0...index, s0)
51
+ r0.extend(TransposeModifier0)
52
+ else
53
+ @index = i0
54
+ r0 = nil
55
+ end
56
+
57
+ node_cache[:transpose_modifier][start_index] = r0
58
+
59
+ r0
60
+ end
61
+
62
+ end
63
+
64
+ class TransposeModifierParser < Treetop::Runtime::CompiledParser
65
+ include TransposeModifier
66
+ end
67
+
68
+
69
+ end
@@ -0,0 +1,11 @@
1
+ module Brevity
2
+
3
+ grammar TransposeModifier
4
+ include NonnegativeInteger
5
+
6
+ rule transpose_modifier
7
+ op:[+-] nsem:nonnegative_integer <TransposeModifierNode>
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,13 @@
1
+ module Brevity
2
+ class TransposeModifierNode < Treetop::Runtime::SyntaxNode
3
+ def process primitives
4
+ n = nsem.text_value.to_i
5
+ if op.text_value == "-"
6
+ n = -n
7
+ end
8
+ primitives.map do |p|
9
+ p.respond_to?(:transpose) ? p.transpose(n) : p
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Brevity
5
+
6
+ module Accent
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :accent
11
+ end
12
+
13
+ def _nt_accent
14
+ start_index = index
15
+ if node_cache[:accent].has_key?(index)
16
+ cached = node_cache[:accent][index]
17
+ if cached
18
+ node_cache[:accent][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
+ if has_terminal?(@regexps[gr = '\A[.\'>^_]'] ||= Regexp.new(gr), :regexp, index)
25
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
26
+ @index += 1
27
+ else
28
+ terminal_parse_failure('[.\'>^_]')
29
+ r0 = nil
30
+ end
31
+
32
+ node_cache[:accent][start_index] = r0
33
+
34
+ r0
35
+ end
36
+
37
+ end
38
+
39
+ class AccentParser < Treetop::Runtime::CompiledParser
40
+ include Accent
41
+ end
42
+
43
+
44
+ end
@@ -0,0 +1,9 @@
1
+ module Brevity
2
+
3
+ grammar Accent
4
+ rule accent
5
+ [.'>^_]
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,203 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Brevity
5
+
6
+ module Duration
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :duration
11
+ end
12
+
13
+ include PositiveInteger
14
+
15
+ def _nt_duration
16
+ start_index = index
17
+ if node_cache[:duration].has_key?(index)
18
+ cached = node_cache[:duration][index]
19
+ if cached
20
+ node_cache[:duration][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
21
+ @index = cached.interval.end
22
+ end
23
+ return cached
24
+ end
25
+
26
+ i0 = index
27
+ r1 = _nt_num_and_den
28
+ if r1
29
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
30
+ r0 = r1
31
+ else
32
+ r2 = _nt_num_only
33
+ if r2
34
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
35
+ r0 = r2
36
+ else
37
+ r3 = _nt_den_only
38
+ if r3
39
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
40
+ r0 = r3
41
+ else
42
+ @index = i0
43
+ r0 = nil
44
+ end
45
+ end
46
+ end
47
+
48
+ node_cache[:duration][start_index] = r0
49
+
50
+ r0
51
+ end
52
+
53
+ module NumAndDen0
54
+ def positive_integer1
55
+ elements[0]
56
+ end
57
+
58
+ def positive_integer2
59
+ elements[2]
60
+ end
61
+ end
62
+
63
+ def _nt_num_and_den
64
+ start_index = index
65
+ if node_cache[:num_and_den].has_key?(index)
66
+ cached = node_cache[:num_and_den][index]
67
+ if cached
68
+ node_cache[:num_and_den][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
69
+ @index = cached.interval.end
70
+ end
71
+ return cached
72
+ end
73
+
74
+ i0, s0 = index, []
75
+ r1 = _nt_positive_integer
76
+ s0 << r1
77
+ if r1
78
+ if (match_len = has_terminal?("/", false, index))
79
+ r2 = true
80
+ @index += match_len
81
+ else
82
+ terminal_parse_failure("/")
83
+ r2 = nil
84
+ end
85
+ s0 << r2
86
+ if r2
87
+ r3 = _nt_positive_integer
88
+ s0 << r3
89
+ end
90
+ end
91
+ if s0.last
92
+ r0 = instantiate_node(NumDenNode,input, i0...index, s0)
93
+ r0.extend(NumAndDen0)
94
+ else
95
+ @index = i0
96
+ r0 = nil
97
+ end
98
+
99
+ node_cache[:num_and_den][start_index] = r0
100
+
101
+ r0
102
+ end
103
+
104
+ module NumOnly0
105
+ def numerator
106
+ elements[0]
107
+ end
108
+
109
+ end
110
+
111
+ def _nt_num_only
112
+ start_index = index
113
+ if node_cache[:num_only].has_key?(index)
114
+ cached = node_cache[:num_only][index]
115
+ if cached
116
+ node_cache[:num_only][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
117
+ @index = cached.interval.end
118
+ end
119
+ return cached
120
+ end
121
+
122
+ i0, s0 = index, []
123
+ r1 = _nt_positive_integer
124
+ s0 << r1
125
+ if r1
126
+ if (match_len = has_terminal?("/", false, index))
127
+ r3 = true
128
+ @index += match_len
129
+ else
130
+ terminal_parse_failure("/")
131
+ r3 = nil
132
+ end
133
+ if r3
134
+ r2 = r3
135
+ else
136
+ r2 = instantiate_node(SyntaxNode,input, index...index)
137
+ end
138
+ s0 << r2
139
+ end
140
+ if s0.last
141
+ r0 = instantiate_node(NumOnlyNode,input, i0...index, s0)
142
+ r0.extend(NumOnly0)
143
+ else
144
+ @index = i0
145
+ r0 = nil
146
+ end
147
+
148
+ node_cache[:num_only][start_index] = r0
149
+
150
+ r0
151
+ end
152
+
153
+ module DenOnly0
154
+ def denominator
155
+ elements[1]
156
+ end
157
+ end
158
+
159
+ def _nt_den_only
160
+ start_index = index
161
+ if node_cache[:den_only].has_key?(index)
162
+ cached = node_cache[:den_only][index]
163
+ if cached
164
+ node_cache[:den_only][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
165
+ @index = cached.interval.end
166
+ end
167
+ return cached
168
+ end
169
+
170
+ i0, s0 = index, []
171
+ if (match_len = has_terminal?("/", false, index))
172
+ r1 = true
173
+ @index += match_len
174
+ else
175
+ terminal_parse_failure("/")
176
+ r1 = nil
177
+ end
178
+ s0 << r1
179
+ if r1
180
+ r2 = _nt_positive_integer
181
+ s0 << r2
182
+ end
183
+ if s0.last
184
+ r0 = instantiate_node(DenOnlyNode,input, i0...index, s0)
185
+ r0.extend(DenOnly0)
186
+ else
187
+ @index = i0
188
+ r0 = nil
189
+ end
190
+
191
+ node_cache[:den_only][start_index] = r0
192
+
193
+ r0
194
+ end
195
+
196
+ end
197
+
198
+ class DurationParser < Treetop::Runtime::CompiledParser
199
+ include Duration
200
+ end
201
+
202
+
203
+ end
@@ -0,0 +1,23 @@
1
+ module Brevity
2
+
3
+ grammar Duration
4
+ include PositiveInteger
5
+
6
+ rule duration
7
+ num_and_den / num_only / den_only
8
+ end
9
+
10
+ rule num_and_den
11
+ positive_integer "/" positive_integer <NumDenNode>
12
+ end
13
+
14
+ rule num_only
15
+ numerator:positive_integer "/"? <NumOnlyNode>
16
+ end
17
+
18
+ rule den_only
19
+ "/" denominator:positive_integer <DenOnlyNode>
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,19 @@
1
+ module Brevity
2
+ class NumDenNode < Treetop::Runtime::SyntaxNode
3
+ def to_r
4
+ text_value.to_r
5
+ end
6
+ end
7
+
8
+ class NumOnlyNode < Treetop::Runtime::SyntaxNode
9
+ def to_r
10
+ Rational(numerator.text_value.to_i,1)
11
+ end
12
+ end
13
+
14
+ class DenOnlyNode < Treetop::Runtime::SyntaxNode
15
+ def to_r
16
+ Rational(1,denominator.text_value.to_i)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,69 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Brevity
5
+
6
+ module Link
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :link
11
+ end
12
+
13
+ include Pitch
14
+
15
+ module Link0
16
+ def link_sym
17
+ elements[0]
18
+ end
19
+
20
+ def target
21
+ elements[1]
22
+ end
23
+ end
24
+
25
+ def _nt_link
26
+ start_index = index
27
+ if node_cache[:link].has_key?(index)
28
+ cached = node_cache[:link][index]
29
+ if cached
30
+ node_cache[:link][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
31
+ @index = cached.interval.end
32
+ end
33
+ return cached
34
+ end
35
+
36
+ i0, s0 = index, []
37
+ if has_terminal?(@regexps[gr = '\A[=\\-~/]'] ||= Regexp.new(gr), :regexp, index)
38
+ r1 = true
39
+ @index += 1
40
+ else
41
+ terminal_parse_failure('[=\\-~/]')
42
+ r1 = nil
43
+ end
44
+ s0 << r1
45
+ if r1
46
+ r2 = _nt_pitch
47
+ s0 << r2
48
+ end
49
+ if s0.last
50
+ r0 = instantiate_node(LinkNode,input, i0...index, s0)
51
+ r0.extend(Link0)
52
+ else
53
+ @index = i0
54
+ r0 = nil
55
+ end
56
+
57
+ node_cache[:link][start_index] = r0
58
+
59
+ r0
60
+ end
61
+
62
+ end
63
+
64
+ class LinkParser < Treetop::Runtime::CompiledParser
65
+ include Link
66
+ end
67
+
68
+
69
+ end
@@ -0,0 +1,11 @@
1
+ module Brevity
2
+
3
+ grammar Link
4
+ include Pitch
5
+
6
+ rule link
7
+ link_sym:[=\-~/] target:pitch <LinkNode>
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,19 @@
1
+ module Brevity
2
+ class LinkNode < Treetop::Runtime::SyntaxNode
3
+ def to_link
4
+ tgt = target.to_pitch
5
+
6
+ case link_sym.text_value
7
+ when '='
8
+ link = Music::Transcription::Link::Slur.new(tgt)
9
+ when '-'
10
+ link = Music::Transcription::Link::Legato.new(tgt)
11
+ when '~'
12
+ link = Music::Transcription::Link::Glissando.new(tgt)
13
+ when '/'
14
+ link = Music::Transcription::Link::Portamento.new(tgt)
15
+ end
16
+ return link
17
+ end
18
+ end
19
+ end