musicality 0.1.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.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +47 -0
  8. data/Rakefile +65 -0
  9. data/bin/midify +78 -0
  10. data/examples/hip.rb +32 -0
  11. data/examples/missed_connection.rb +26 -0
  12. data/examples/song1.rb +33 -0
  13. data/examples/song2.rb +32 -0
  14. data/lib/musicality/errors.rb +9 -0
  15. data/lib/musicality/notation/conversion/change_conversion.rb +19 -0
  16. data/lib/musicality/notation/conversion/measure_note_map.rb +40 -0
  17. data/lib/musicality/notation/conversion/measured_score_conversion.rb +70 -0
  18. data/lib/musicality/notation/conversion/measured_score_converter.rb +95 -0
  19. data/lib/musicality/notation/conversion/note_time_converter.rb +68 -0
  20. data/lib/musicality/notation/conversion/tempo_conversion.rb +25 -0
  21. data/lib/musicality/notation/conversion/unmeasured_score_conversion.rb +47 -0
  22. data/lib/musicality/notation/conversion/unmeasured_score_converter.rb +64 -0
  23. data/lib/musicality/notation/model/articulations.rb +13 -0
  24. data/lib/musicality/notation/model/change.rb +62 -0
  25. data/lib/musicality/notation/model/dynamics.rb +12 -0
  26. data/lib/musicality/notation/model/link.rb +73 -0
  27. data/lib/musicality/notation/model/meter.rb +54 -0
  28. data/lib/musicality/notation/model/meters.rb +9 -0
  29. data/lib/musicality/notation/model/note.rb +120 -0
  30. data/lib/musicality/notation/model/part.rb +54 -0
  31. data/lib/musicality/notation/model/pitch.rb +163 -0
  32. data/lib/musicality/notation/model/pitches.rb +21 -0
  33. data/lib/musicality/notation/model/program.rb +53 -0
  34. data/lib/musicality/notation/model/score.rb +132 -0
  35. data/lib/musicality/notation/packing/change_packing.rb +46 -0
  36. data/lib/musicality/notation/packing/part_packing.rb +31 -0
  37. data/lib/musicality/notation/packing/program_packing.rb +16 -0
  38. data/lib/musicality/notation/packing/score_packing.rb +108 -0
  39. data/lib/musicality/notation/parsing/articulation_parsing.rb +264 -0
  40. data/lib/musicality/notation/parsing/articulation_parsing.treetop +59 -0
  41. data/lib/musicality/notation/parsing/convenience_methods.rb +74 -0
  42. data/lib/musicality/notation/parsing/duration_nodes.rb +21 -0
  43. data/lib/musicality/notation/parsing/duration_parsing.rb +205 -0
  44. data/lib/musicality/notation/parsing/duration_parsing.treetop +25 -0
  45. data/lib/musicality/notation/parsing/link_nodes.rb +35 -0
  46. data/lib/musicality/notation/parsing/link_parsing.rb +270 -0
  47. data/lib/musicality/notation/parsing/link_parsing.treetop +33 -0
  48. data/lib/musicality/notation/parsing/meter_parsing.rb +190 -0
  49. data/lib/musicality/notation/parsing/meter_parsing.treetop +29 -0
  50. data/lib/musicality/notation/parsing/note_node.rb +40 -0
  51. data/lib/musicality/notation/parsing/note_parsing.rb +229 -0
  52. data/lib/musicality/notation/parsing/note_parsing.treetop +28 -0
  53. data/lib/musicality/notation/parsing/numbers/nonnegative_float_parsing.rb +289 -0
  54. data/lib/musicality/notation/parsing/numbers/nonnegative_float_parsing.treetop +29 -0
  55. data/lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.rb +64 -0
  56. data/lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.treetop +17 -0
  57. data/lib/musicality/notation/parsing/numbers/nonnegative_rational_parsing.rb +86 -0
  58. data/lib/musicality/notation/parsing/numbers/nonnegative_rational_parsing.treetop +20 -0
  59. data/lib/musicality/notation/parsing/numbers/positive_float_parsing.rb +503 -0
  60. data/lib/musicality/notation/parsing/numbers/positive_float_parsing.treetop +33 -0
  61. data/lib/musicality/notation/parsing/numbers/positive_integer_parsing.rb +95 -0
  62. data/lib/musicality/notation/parsing/numbers/positive_integer_parsing.treetop +19 -0
  63. data/lib/musicality/notation/parsing/numbers/positive_rational_parsing.rb +84 -0
  64. data/lib/musicality/notation/parsing/numbers/positive_rational_parsing.treetop +19 -0
  65. data/lib/musicality/notation/parsing/parseable.rb +30 -0
  66. data/lib/musicality/notation/parsing/pitch_node.rb +23 -0
  67. data/lib/musicality/notation/parsing/pitch_parsing.rb +448 -0
  68. data/lib/musicality/notation/parsing/pitch_parsing.treetop +52 -0
  69. data/lib/musicality/notation/parsing/segment_parsing.rb +141 -0
  70. data/lib/musicality/notation/parsing/segment_parsing.treetop +23 -0
  71. data/lib/musicality/notation/util/interpolation.rb +16 -0
  72. data/lib/musicality/notation/util/piecewise_function.rb +122 -0
  73. data/lib/musicality/notation/util/value_computer.rb +170 -0
  74. data/lib/musicality/performance/conversion/glissando_converter.rb +34 -0
  75. data/lib/musicality/performance/conversion/note_sequence_extractor.rb +98 -0
  76. data/lib/musicality/performance/conversion/portamento_converter.rb +24 -0
  77. data/lib/musicality/performance/conversion/score_collator.rb +126 -0
  78. data/lib/musicality/performance/midi/midi_events.rb +34 -0
  79. data/lib/musicality/performance/midi/midi_util.rb +31 -0
  80. data/lib/musicality/performance/midi/part_sequencer.rb +123 -0
  81. data/lib/musicality/performance/midi/score_sequencer.rb +45 -0
  82. data/lib/musicality/performance/model/note_attacks.rb +19 -0
  83. data/lib/musicality/performance/model/note_sequence.rb +111 -0
  84. data/lib/musicality/performance/util/note_linker.rb +28 -0
  85. data/lib/musicality/performance/util/optimization.rb +31 -0
  86. data/lib/musicality/validatable.rb +38 -0
  87. data/lib/musicality/version.rb +3 -0
  88. data/lib/musicality.rb +81 -0
  89. data/musicality.gemspec +30 -0
  90. data/spec/musicality_spec.rb +7 -0
  91. data/spec/notation/conversion/change_conversion_spec.rb +40 -0
  92. data/spec/notation/conversion/measure_note_map_spec.rb +73 -0
  93. data/spec/notation/conversion/measured_score_conversion_spec.rb +141 -0
  94. data/spec/notation/conversion/measured_score_converter_spec.rb +329 -0
  95. data/spec/notation/conversion/note_time_converter_spec.rb +81 -0
  96. data/spec/notation/conversion/tempo_conversion_spec.rb +40 -0
  97. data/spec/notation/conversion/unmeasured_score_conversion_spec.rb +71 -0
  98. data/spec/notation/conversion/unmeasured_score_converter_spec.rb +116 -0
  99. data/spec/notation/model/change_spec.rb +90 -0
  100. data/spec/notation/model/link_spec.rb +83 -0
  101. data/spec/notation/model/meter_spec.rb +97 -0
  102. data/spec/notation/model/note_spec.rb +183 -0
  103. data/spec/notation/model/part_spec.rb +69 -0
  104. data/spec/notation/model/pitch_spec.rb +180 -0
  105. data/spec/notation/model/program_spec.rb +50 -0
  106. data/spec/notation/model/score_spec.rb +211 -0
  107. data/spec/notation/packing/change_packing_spec.rb +153 -0
  108. data/spec/notation/packing/part_packing_spec.rb +66 -0
  109. data/spec/notation/packing/program_packing_spec.rb +33 -0
  110. data/spec/notation/packing/score_packing_spec.rb +301 -0
  111. data/spec/notation/parsing/articulation_parsing_spec.rb +23 -0
  112. data/spec/notation/parsing/convenience_methods_spec.rb +99 -0
  113. data/spec/notation/parsing/duration_nodes_spec.rb +83 -0
  114. data/spec/notation/parsing/duration_parsing_spec.rb +70 -0
  115. data/spec/notation/parsing/link_nodes_spec.rb +30 -0
  116. data/spec/notation/parsing/link_parsing_spec.rb +13 -0
  117. data/spec/notation/parsing/meter_parsing_spec.rb +23 -0
  118. data/spec/notation/parsing/note_node_spec.rb +87 -0
  119. data/spec/notation/parsing/note_parsing_spec.rb +46 -0
  120. data/spec/notation/parsing/numbers/nonnegative_float_spec.rb +28 -0
  121. data/spec/notation/parsing/numbers/nonnegative_integer_spec.rb +11 -0
  122. data/spec/notation/parsing/numbers/nonnegative_rational_spec.rb +11 -0
  123. data/spec/notation/parsing/numbers/positive_float_spec.rb +28 -0
  124. data/spec/notation/parsing/numbers/positive_integer_spec.rb +28 -0
  125. data/spec/notation/parsing/numbers/positive_rational_spec.rb +28 -0
  126. data/spec/notation/parsing/pitch_node_spec.rb +38 -0
  127. data/spec/notation/parsing/pitch_parsing_spec.rb +14 -0
  128. data/spec/notation/parsing/segment_parsing_spec.rb +27 -0
  129. data/spec/notation/util/value_computer_spec.rb +146 -0
  130. data/spec/performance/conversion/glissando_converter_spec.rb +93 -0
  131. data/spec/performance/conversion/note_sequence_extractor_spec.rb +230 -0
  132. data/spec/performance/conversion/portamento_converter_spec.rb +91 -0
  133. data/spec/performance/conversion/score_collator_spec.rb +183 -0
  134. data/spec/performance/midi/midi_util_spec.rb +110 -0
  135. data/spec/performance/midi/part_sequencer_spec.rb +40 -0
  136. data/spec/performance/midi/score_sequencer_spec.rb +50 -0
  137. data/spec/performance/model/note_sequence_spec.rb +147 -0
  138. data/spec/performance/util/note_linker_spec.rb +68 -0
  139. data/spec/performance/util/optimization_spec.rb +73 -0
  140. data/spec/spec_helper.rb +43 -0
  141. metadata +323 -0
@@ -0,0 +1,190 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Musicality
5
+ module Parsing
6
+
7
+ module Meter
8
+ include Treetop::Runtime
9
+
10
+ def root
11
+ @root ||= :meter
12
+ end
13
+
14
+ include PositiveInteger
15
+
16
+ def _nt_meter
17
+ start_index = index
18
+ if node_cache[:meter].has_key?(index)
19
+ cached = node_cache[:meter][index]
20
+ if cached
21
+ node_cache[:meter][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 = index
28
+ r1 = _nt_meter1
29
+ if r1
30
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
31
+ r0 = r1
32
+ else
33
+ r2 = _nt_meter2
34
+ if r2
35
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
36
+ r0 = r2
37
+ else
38
+ @index = i0
39
+ r0 = nil
40
+ end
41
+ end
42
+
43
+ node_cache[:meter][start_index] = r0
44
+
45
+ r0
46
+ end
47
+
48
+ module Meter10
49
+ def bpm
50
+ elements[0]
51
+ end
52
+
53
+ def bd
54
+ elements[2]
55
+ end
56
+ end
57
+
58
+ module Meter11
59
+ def to_meter
60
+ Musicality::Meter.new(bpm.to_i, Rational(1,bd.to_i))
61
+ end
62
+ end
63
+
64
+ def _nt_meter1
65
+ start_index = index
66
+ if node_cache[:meter1].has_key?(index)
67
+ cached = node_cache[:meter1][index]
68
+ if cached
69
+ node_cache[:meter1][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
70
+ @index = cached.interval.end
71
+ end
72
+ return cached
73
+ end
74
+
75
+ i0, s0 = index, []
76
+ r1 = _nt_positive_integer
77
+ s0 << r1
78
+ if r1
79
+ if (match_len = has_terminal?("/", false, index))
80
+ r2 = true
81
+ @index += match_len
82
+ else
83
+ terminal_parse_failure("/")
84
+ r2 = nil
85
+ end
86
+ s0 << r2
87
+ if r2
88
+ r3 = _nt_positive_integer
89
+ s0 << r3
90
+ end
91
+ end
92
+ if s0.last
93
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
94
+ r0.extend(Meter10)
95
+ r0.extend(Meter11)
96
+ else
97
+ @index = i0
98
+ r0 = nil
99
+ end
100
+
101
+ node_cache[:meter1][start_index] = r0
102
+
103
+ r0
104
+ end
105
+
106
+ module Meter20
107
+ def bpm
108
+ elements[0]
109
+ end
110
+
111
+ def num
112
+ elements[2]
113
+ end
114
+
115
+ def den
116
+ elements[4]
117
+ end
118
+ end
119
+
120
+ module Meter21
121
+ def to_meter
122
+ Musicality::Meter.new(bpm.to_i, Rational(num.to_i,den.to_i))
123
+ end
124
+ end
125
+
126
+ def _nt_meter2
127
+ start_index = index
128
+ if node_cache[:meter2].has_key?(index)
129
+ cached = node_cache[:meter2][index]
130
+ if cached
131
+ node_cache[:meter2][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
132
+ @index = cached.interval.end
133
+ end
134
+ return cached
135
+ end
136
+
137
+ i0, s0 = index, []
138
+ r1 = _nt_positive_integer
139
+ s0 << r1
140
+ if r1
141
+ if (match_len = has_terminal?("*", false, index))
142
+ r2 = true
143
+ @index += match_len
144
+ else
145
+ terminal_parse_failure("*")
146
+ r2 = nil
147
+ end
148
+ s0 << r2
149
+ if r2
150
+ r3 = _nt_positive_integer
151
+ s0 << r3
152
+ if r3
153
+ if (match_len = has_terminal?("/", false, index))
154
+ r4 = true
155
+ @index += match_len
156
+ else
157
+ terminal_parse_failure("/")
158
+ r4 = nil
159
+ end
160
+ s0 << r4
161
+ if r4
162
+ r5 = _nt_positive_integer
163
+ s0 << r5
164
+ end
165
+ end
166
+ end
167
+ end
168
+ if s0.last
169
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
170
+ r0.extend(Meter20)
171
+ r0.extend(Meter21)
172
+ else
173
+ @index = i0
174
+ r0 = nil
175
+ end
176
+
177
+ node_cache[:meter2][start_index] = r0
178
+
179
+ r0
180
+ end
181
+
182
+ end
183
+
184
+ class MeterParser < Treetop::Runtime::CompiledParser
185
+ include Meter
186
+ end
187
+
188
+
189
+ end
190
+ end
@@ -0,0 +1,29 @@
1
+ module Musicality
2
+ module Parsing
3
+
4
+ grammar Meter
5
+ include PositiveInteger
6
+
7
+ rule meter
8
+ meter1 / meter2
9
+ end
10
+
11
+ rule meter1
12
+ bpm:positive_integer "/" bd:positive_integer {
13
+ def to_meter
14
+ Musicality::Meter.new(bpm.to_i, Rational(1,bd.to_i))
15
+ end
16
+ }
17
+ end
18
+
19
+ rule meter2
20
+ bpm:positive_integer "*" num:positive_integer "/" den:positive_integer {
21
+ def to_meter
22
+ Musicality::Meter.new(bpm.to_i, Rational(num.to_i,den.to_i))
23
+ end
24
+ }
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ module Musicality
2
+ module Parsing
3
+ class NoteNode < Treetop::Runtime::SyntaxNode
4
+ def primitives env
5
+ [ self.to_note ]
6
+ end
7
+
8
+ def to_note
9
+ pitches = []
10
+ links = {}
11
+
12
+ unless pitch_links.empty?
13
+ first = pitch_links.first
14
+ more = pitch_links.more
15
+
16
+ pitches.push first.pitch.to_pitch
17
+ unless first.the_link.empty?
18
+ links[pitches[-1]] = first.the_link.to_link
19
+ end
20
+
21
+ more.elements.each do |x|
22
+ pitches.push x.pl.pitch.to_pitch
23
+ unless x.pl.the_link.empty?
24
+ links[pitches[-1]] = x.pl.the_link.to_link
25
+ end
26
+ end
27
+ end
28
+
29
+ artic = Musicality::Articulations::NORMAL
30
+ unless art.empty?
31
+ artic = art.to_articulation
32
+ end
33
+
34
+ accent_flag = acc.empty? ? false : true
35
+ Musicality::Note.new(duration.to_r,
36
+ pitches, links: links, articulation: artic, accented: accent_flag)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,229 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Musicality
5
+ module Parsing
6
+
7
+ module Note
8
+ include Treetop::Runtime
9
+
10
+ def root
11
+ @root ||= :note
12
+ end
13
+
14
+ include Pitch
15
+
16
+ include Articulation
17
+
18
+ include Link
19
+
20
+ include Duration
21
+
22
+ module Note0
23
+ def pl
24
+ elements[1]
25
+ end
26
+ end
27
+
28
+ module Note1
29
+ def first
30
+ elements[0]
31
+ end
32
+
33
+ def more
34
+ elements[1]
35
+ end
36
+ end
37
+
38
+ module Note2
39
+ def duration
40
+ elements[0]
41
+ end
42
+
43
+ def art
44
+ elements[1]
45
+ end
46
+
47
+ def pitch_links
48
+ elements[2]
49
+ end
50
+
51
+ def acc
52
+ elements[3]
53
+ end
54
+ end
55
+
56
+ def _nt_note
57
+ start_index = index
58
+ if node_cache[:note].has_key?(index)
59
+ cached = node_cache[:note][index]
60
+ if cached
61
+ node_cache[:note][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
62
+ @index = cached.interval.end
63
+ end
64
+ return cached
65
+ end
66
+
67
+ i0, s0 = index, []
68
+ r1 = _nt_duration
69
+ s0 << r1
70
+ if r1
71
+ r3 = _nt_articulation
72
+ if r3
73
+ r2 = r3
74
+ else
75
+ r2 = instantiate_node(SyntaxNode,input, index...index)
76
+ end
77
+ s0 << r2
78
+ if r2
79
+ i5, s5 = index, []
80
+ r6 = _nt_pitch_link
81
+ s5 << r6
82
+ if r6
83
+ s7, i7 = [], index
84
+ loop do
85
+ i8, s8 = index, []
86
+ if (match_len = has_terminal?(",", false, index))
87
+ r9 = true
88
+ @index += match_len
89
+ else
90
+ terminal_parse_failure(",")
91
+ r9 = nil
92
+ end
93
+ s8 << r9
94
+ if r9
95
+ r10 = _nt_pitch_link
96
+ s8 << r10
97
+ end
98
+ if s8.last
99
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
100
+ r8.extend(Note0)
101
+ else
102
+ @index = i8
103
+ r8 = nil
104
+ end
105
+ if r8
106
+ s7 << r8
107
+ else
108
+ break
109
+ end
110
+ end
111
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
112
+ s5 << r7
113
+ end
114
+ if s5.last
115
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
116
+ r5.extend(Note1)
117
+ else
118
+ @index = i5
119
+ r5 = nil
120
+ end
121
+ if r5
122
+ r4 = r5
123
+ else
124
+ r4 = instantiate_node(SyntaxNode,input, index...index)
125
+ end
126
+ s0 << r4
127
+ if r4
128
+ r12 = _nt_accent
129
+ if r12
130
+ r11 = r12
131
+ else
132
+ r11 = instantiate_node(SyntaxNode,input, index...index)
133
+ end
134
+ s0 << r11
135
+ end
136
+ end
137
+ end
138
+ if s0.last
139
+ r0 = instantiate_node(NoteNode,input, i0...index, s0)
140
+ r0.extend(Note2)
141
+ else
142
+ @index = i0
143
+ r0 = nil
144
+ end
145
+
146
+ node_cache[:note][start_index] = r0
147
+
148
+ r0
149
+ end
150
+
151
+ module PitchLink0
152
+ def pitch
153
+ elements[0]
154
+ end
155
+
156
+ def the_link
157
+ elements[1]
158
+ end
159
+ end
160
+
161
+ def _nt_pitch_link
162
+ start_index = index
163
+ if node_cache[:pitch_link].has_key?(index)
164
+ cached = node_cache[:pitch_link][index]
165
+ if cached
166
+ node_cache[:pitch_link][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
+ r1 = _nt_pitch
174
+ s0 << r1
175
+ if r1
176
+ r3 = _nt_link
177
+ if r3
178
+ r2 = r3
179
+ else
180
+ r2 = instantiate_node(SyntaxNode,input, index...index)
181
+ end
182
+ s0 << r2
183
+ end
184
+ if s0.last
185
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
186
+ r0.extend(PitchLink0)
187
+ else
188
+ @index = i0
189
+ r0 = nil
190
+ end
191
+
192
+ node_cache[:pitch_link][start_index] = r0
193
+
194
+ r0
195
+ end
196
+
197
+ def _nt_accent
198
+ start_index = index
199
+ if node_cache[:accent].has_key?(index)
200
+ cached = node_cache[:accent][index]
201
+ if cached
202
+ node_cache[:accent][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
203
+ @index = cached.interval.end
204
+ end
205
+ return cached
206
+ end
207
+
208
+ if (match_len = has_terminal?("!", false, index))
209
+ r0 = instantiate_node(SyntaxNode,input, index...(index + match_len))
210
+ @index += match_len
211
+ else
212
+ terminal_parse_failure("!")
213
+ r0 = nil
214
+ end
215
+
216
+ node_cache[:accent][start_index] = r0
217
+
218
+ r0
219
+ end
220
+
221
+ end
222
+
223
+ class NoteParser < Treetop::Runtime::CompiledParser
224
+ include Note
225
+ end
226
+
227
+
228
+ end
229
+ end
@@ -0,0 +1,28 @@
1
+ module Musicality
2
+ module Parsing
3
+
4
+ grammar Note
5
+ include Pitch
6
+ include Articulation
7
+ include Link
8
+ include Duration
9
+
10
+ rule note
11
+ duration
12
+ art:articulation?
13
+ pitch_links:(first:pitch_link more:("," pl:pitch_link)*)?
14
+ acc:accent?
15
+ <NoteNode>
16
+ end
17
+
18
+ rule pitch_link
19
+ pitch the_link:link?
20
+ end
21
+
22
+ rule accent
23
+ "!"
24
+ end
25
+ end
26
+
27
+ end
28
+ end