music-transcription 0.17.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/examples/hip.rb +4 -4
  3. data/examples/missed_connection.rb +3 -3
  4. data/examples/song1.rb +6 -6
  5. data/examples/song2.rb +3 -3
  6. data/lib/music-transcription.rb +8 -2
  7. data/lib/music-transcription/model/change.rb +9 -3
  8. data/lib/music-transcription/model/measure_score.rb +62 -0
  9. data/lib/music-transcription/model/meter.rb +5 -1
  10. data/lib/music-transcription/model/note.rb +4 -1
  11. data/lib/music-transcription/model/note_score.rb +60 -0
  12. data/lib/music-transcription/model/part.rb +4 -1
  13. data/lib/music-transcription/model/program.rb +5 -2
  14. data/lib/music-transcription/model/tempo.rb +13 -23
  15. data/lib/music-transcription/packing/measure_score_packing.rb +34 -0
  16. data/lib/music-transcription/packing/{score_packing.rb → note_score_packing.rb} +12 -21
  17. data/lib/music-transcription/packing/part_packing.rb +1 -1
  18. data/lib/music-transcription/packing/program_packing.rb +1 -1
  19. data/lib/music-transcription/parsing/convenience_methods.rb +37 -58
  20. data/lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb +172 -59
  21. data/lib/music-transcription/parsing/numbers/nonnegative_float_parsing.treetop +13 -1
  22. data/lib/music-transcription/parsing/numbers/positive_float_parsing.rb +505 -0
  23. data/lib/music-transcription/parsing/numbers/positive_float_parsing.treetop +35 -0
  24. data/lib/music-transcription/parsing/numbers/positive_integer_parsing.rb +2 -0
  25. data/lib/music-transcription/parsing/numbers/positive_integer_parsing.treetop +2 -0
  26. data/lib/music-transcription/parsing/numbers/positive_rational_parsing.rb +86 -0
  27. data/lib/music-transcription/parsing/numbers/positive_rational_parsing.treetop +21 -0
  28. data/lib/music-transcription/parsing/parseable.rb +32 -0
  29. data/lib/music-transcription/parsing/tempo_parsing.rb +396 -0
  30. data/lib/music-transcription/parsing/tempo_parsing.treetop +49 -0
  31. data/lib/music-transcription/validatable.rb +5 -18
  32. data/lib/music-transcription/version.rb +1 -1
  33. data/spec/model/measure_score_spec.rb +85 -0
  34. data/spec/model/note_score_spec.rb +68 -0
  35. data/spec/model/tempo_spec.rb +15 -15
  36. data/spec/packing/{score_packing_spec.rb → measure_score_packing_spec.rb} +13 -7
  37. data/spec/packing/note_score_packing_spec.rb +100 -0
  38. data/spec/packing/part_packing_spec.rb +1 -1
  39. data/spec/parsing/convenience_methods_spec.rb +80 -81
  40. data/spec/parsing/numbers/nonnegative_float_spec.rb +19 -2
  41. data/spec/parsing/numbers/positive_float_spec.rb +28 -0
  42. data/spec/parsing/numbers/positive_integer_spec.rb +13 -2
  43. data/spec/parsing/numbers/positive_rational_spec.rb +28 -0
  44. data/spec/parsing/tempo_parsing_spec.rb +21 -0
  45. metadata +27 -8
  46. data/lib/music-transcription/model/score.rb +0 -68
  47. data/spec/model/score_spec.rb +0 -69
@@ -1,100 +1,99 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- dur_stuff = ['should parse as single duration',
4
- {
3
+ class_cases = { Duration => {
5
4
  '/2' => "1/2".to_r,
6
5
  '5/29' => "5/29".to_r,
7
6
  '200/' => "200/1".to_r,
8
7
  '66' => "66/1".to_r
9
- }]
10
-
11
- durs_stuff = ['should parse as whitespace-separated durations',
12
- {
13
- '/2 5/29 200/ 66' => ["1/2".to_r,"5/29".to_r,"200/1".to_r,"66/1".to_r],
14
- "/2\t5/29\n200/ \t\n 66" => ["1/2".to_r,"5/29".to_r,"200/1".to_r,"66/1".to_r],
15
- }]
16
-
17
- pitch_stuff = ['should parse as single pitch',
18
- {
19
- 'C2' => C2,
20
- 'Db4' => Db4,
21
- 'A#9' => Bb9
22
- }]
23
-
24
- pitches_stuff = ['should parse as whitespace-separated pitches',
25
- {
26
- 'C2 C2 D2 C2' => [C2,C2,D2,C2],
27
- "Bb2\tF5 \n Gb7" => [Bb2,F5,Gb7],
28
- }]
29
-
30
- note_stuff = ['should parse as a single note',
31
- {
32
- '/2' => Note::half,
33
- '99/10C2' => Note.new('99/10'.to_r, [C2]),
34
- '5/2.Db4,Eb5' => Note.new('5/2'.to_r, [Db4,Eb5], articulation:STACCATO)
35
- }]
36
-
37
- notes_stuff = ['should parse as whitespace-separated notes',
38
- {
39
- '/2 /2 /4' => [Note::half,Note::half,Note::quarter],
40
- "/4C4 \t /4D4" => [Note::quarter([C4]),Note::quarter([D4])],
41
- "/2Db2\t/2C2 \n /2C2" => [Note::half([Db2]), Note::half([C2]), Note::half([C2])]
42
- }]
8
+ },
9
+ Note => {
10
+ '/2' => Note::half,
11
+ '99/10C2' => Note.new('99/10'.to_r, [C2]),
12
+ '5/2.Db4,Eb5' => Note.new('5/2'.to_r, [Db4,Eb5], articulation:STACCATO)
13
+ },
14
+ Pitch => {
15
+ 'C2' => C2,
16
+ 'Db4' => Db4,
17
+ 'A#9' => Bb9
18
+ },
19
+ Meter => {
20
+ '2/2' => Meter.new(2,"1/2".to_r),
21
+ "4/4" => Meter.new(4,"1/4".to_r),
22
+ "6/8" => Meter.new(6,"1/8".to_r),
23
+ "12/3" => Meter.new(12,"1/3".to_r),
24
+ "133/55" => Meter.new(133,"1/55".to_r),
25
+ },
26
+ Segment => {
27
+ }
28
+ }
43
29
 
44
- meter_stuff = ['should parse as meter',
45
- {
46
- '2/2' => Meter.new(2,"1/2".to_r),
47
- "4/4" => Meter.new(4,"1/4".to_r),
48
- "6/8" => Meter.new(6,"1/8".to_r),
49
- "12/3" => Meter.new(12,"1/3".to_r),
50
- "133/55" => Meter.new(133,"1/55".to_r),
51
- }]
30
+ class_cases.each do |klass,cases|
31
+ describe("#{klass}.parse") do
32
+ it "should produce a single #{klass}" do
33
+ cases.each do |str,tgt|
34
+ klass.parse(str).should eq(tgt)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe("#{klass}.split_parse") do
40
+ context 'joined with whitespace, using default pattern' do
41
+ it "should produce multiple of #{klass}" do
42
+ str = cases.keys.join(" ")
43
+ klass.split_parse(str).should eq(cases.values)
44
+ end
45
+ end
46
+
47
+ context 'joined by custom separator, using matching pattern' do
48
+ it "should raise produce multiple of #{klass}" do
49
+ str = cases.keys.join(";")
50
+ klass.split_parse(str,";").should eq(cases.values)
51
+ end
52
+ end
53
+ end
54
+ end
52
55
 
53
56
  {
54
- :duration => dur_stuff,
55
- :dur => dur_stuff,
56
- :durations => durs_stuff,
57
- :durs => durs_stuff,
58
- :pitch => pitch_stuff,
59
- :pitches => pitches_stuff,
60
- :note => note_stuff,
61
- :notes => notes_stuff,
62
- :meter => meter_stuff
63
- }.each do |mod_fun,descr_cases|
64
- describe("Parsing::" + mod_fun.to_s) do
65
- descr, cases = descr_cases
66
- it descr do
67
- cases.each do |s,tgt|
68
- Parsing.send(mod_fun,s).should eq tgt
57
+ Duration => [:to_d, :to_dur, :to_duration],
58
+ Pitch => [:to_p, :to_pitch],
59
+ Note => [:to_n, :to_note],
60
+ Meter => [:to_meter],
61
+ }.each do |klass,str_parse_methods|
62
+ describe 'String' do
63
+ str_parse_methods.each do |method|
64
+ describe "\##{method}" do
65
+ it "should return a #{klass}" do
66
+ class_cases[klass].each do |str,tgt|
67
+ str.send(method).should eq(tgt)
68
+ end
69
+ end
69
70
  end
70
71
  end
71
72
  end
72
73
  end
73
74
 
74
75
  {
75
- :to_d => dur_stuff,
76
- :to_dur => dur_stuff,
77
- :to_duration => dur_stuff,
78
- :to_ds => durs_stuff,
79
- :to_durs => durs_stuff,
80
- :to_durations => durs_stuff,
81
- :to_p => pitch_stuff,
82
- :to_pitch => pitch_stuff,
83
- :to_ps=> pitches_stuff,
84
- :to_pitches => pitches_stuff,
85
- :to_n => note_stuff,
86
- :to_note => note_stuff,
87
- :to_ns => notes_stuff,
88
- :to_notes => notes_stuff,
89
- :to_meter => meter_stuff,
90
- }.each do |inst_meth,descr_cases|
91
- describe("String#" + inst_meth.to_s) do
92
- descr, cases = descr_cases
93
- it descr do
94
- cases.each do |s,tgt|
95
- s.send(inst_meth).should eq tgt
76
+ Duration => [:to_ds, :to_durs, :to_durations],
77
+ Pitch => [:to_ps, :to_pitches],
78
+ Note => [:to_ns, :to_notes],
79
+ }.each do |klass,str_parse_methods|
80
+ describe 'String' do
81
+ str_parse_methods.each do |method|
82
+ describe "\##{method}" do
83
+ context 'joined with whitespace' do
84
+ it "should return multiple of #{klass}" do
85
+ str = class_cases[klass].keys.join(" ")
86
+ str.send(method).should eq(class_cases[klass].values)
87
+ end
88
+ end
89
+
90
+ context 'joined by custom separator, using matching pattern' do
91
+ it "should raise produce multiple of #{klass}" do
92
+ str = class_cases[klass].keys.join(";")
93
+ str.send(method,";").should eq(class_cases[klass].values)
94
+ end
95
+ end
96
96
  end
97
97
  end
98
98
  end
99
99
  end
100
-
@@ -3,9 +3,26 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
3
  describe Parsing::NonnegativeFloatParser do
4
4
  parser = Parsing::NonnegativeFloatParser .new
5
5
 
6
- ["1.0","0.50","05.003e-10","1.555e+2","3.443214"].each do |str|
6
+ ["0.0","0e1","2e2","1.0","0.50","05.003e-10","1.555e+2","3.443214","0.001","0000.0030000"].each do |str|
7
+ res = parser.parse(str)
8
+ f = str.to_f
9
+
7
10
  it "should parse '#{str}'" do
8
- parser.parse(str).should_not be nil
11
+ res.should_not be nil
9
12
  end
13
+
14
+ it 'should return node that is convertible to float using #to_f method' do
15
+ res.to_f.should eq(f)
16
+ end
17
+
18
+ it 'should return node that is convertible to float using #to_num method' do
19
+ res.to_num.should eq(f)
20
+ end
21
+ end
22
+
23
+ ["-1.0","-0e1"].each do |str|
24
+ it "should not parse '#{str}'" do
25
+ parser.should_not parse(str)
26
+ end
10
27
  end
11
28
  end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Parsing::PositiveFloatParser do
4
+ parser = Parsing::PositiveFloatParser.new
5
+
6
+ ["2e2","1.0","0.50","05.003e-10","1.555e+2","3.443214","0.001","0000.0030000"].each do |str|
7
+ res = parser.parse(str)
8
+ f = str.to_f
9
+
10
+ it "should parse '#{str}'" do
11
+ res.should_not be nil
12
+ end
13
+
14
+ it 'should return node that is convertible to float using #to_f method' do
15
+ res.to_f.should eq(f)
16
+ end
17
+
18
+ it 'should return node that is convertible to float using #to_num method' do
19
+ res.to_num.should eq(f)
20
+ end
21
+ end
22
+
23
+ ["-2.0","-1.55e-2","0.0","0e1"].each do |str|
24
+ it "should not parse '#{str}'" do
25
+ parser.should_not parse(str)
26
+ end
27
+ end
28
+ end
@@ -4,14 +4,25 @@ describe Parsing::PositiveIntegerParser do
4
4
  parser = Parsing::PositiveIntegerParser.new
5
5
 
6
6
  ["1","50","05","502530"].each do |str|
7
+ res = parser.parse(str)
8
+ i = str.to_i
9
+
7
10
  it "should parse '#{str}'" do
8
- parser.parse(str).should_not be nil
11
+ res.should_not be nil
12
+ end
13
+
14
+ it 'should return node that is convertible to integer using #to_i method' do
15
+ res.to_i.should eq(i)
16
+ end
17
+
18
+ it 'should return node that is convertible to integer using #to_num method' do
19
+ res.to_num.should eq(i)
9
20
  end
10
21
  end
11
22
 
12
23
  ["0"].each do |str|
13
24
  it "should not parse '#{str}'" do
14
- parser.parse(str).should be nil
25
+ parser.should_not parse(str)
15
26
  end
16
27
  end
17
28
  end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Parsing::PositiveRationalParser do
4
+ parser = Parsing::PositiveRationalParser.new
5
+
6
+ ["1/2","50/50","050/003","502530/1","01/1"].each do |str|
7
+ res = parser.parse(str)
8
+ r = str.to_r
9
+
10
+ it "should parse '#{str}'" do
11
+ res.should_not be nil
12
+ end
13
+
14
+ it 'should return node that is convertible to rational using #to_r method' do
15
+ res.to_r.should eq(r)
16
+ end
17
+
18
+ it 'should return node that is convertible to rational using #to_num method' do
19
+ res.to_num.should eq(r)
20
+ end
21
+ end
22
+
23
+ ["0/0","0/10","0000/1"].each do |str|
24
+ it "should not parse '#{str}'" do
25
+ parser.should_not parse(str)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Parsing::TempoParser do
4
+ parser = Parsing::TempoParser.new
5
+
6
+ [120,200,2.5,Rational(1,2),1.55e2].each do |val|
7
+ [:bpm,:qnpm,:npm,:nps].each do |type|
8
+ tempo = Tempo.const_get(type.upcase).new(val)
9
+ str = tempo.to_s
10
+ res = parser.parse(str)
11
+
12
+ it "should parse #{str}" do
13
+ res.should_not be nil
14
+ end
15
+
16
+ it 'should produce node that converts to back to original tempo via #to_tempo' do
17
+ res.to_tempo.should eq(tempo)
18
+ end
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: music-transcription
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Tunnell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-29 00:00:00.000000000 Z
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -174,19 +174,21 @@ files:
174
174
  - lib/music-transcription/model/change.rb
175
175
  - lib/music-transcription/model/dynamics.rb
176
176
  - lib/music-transcription/model/link.rb
177
+ - lib/music-transcription/model/measure_score.rb
177
178
  - lib/music-transcription/model/meter.rb
178
179
  - lib/music-transcription/model/meters.rb
179
180
  - lib/music-transcription/model/note.rb
181
+ - lib/music-transcription/model/note_score.rb
180
182
  - lib/music-transcription/model/part.rb
181
183
  - lib/music-transcription/model/pitch.rb
182
184
  - lib/music-transcription/model/pitches.rb
183
185
  - lib/music-transcription/model/program.rb
184
- - lib/music-transcription/model/score.rb
185
186
  - lib/music-transcription/model/tempo.rb
186
187
  - lib/music-transcription/packing/change_packing.rb
188
+ - lib/music-transcription/packing/measure_score_packing.rb
189
+ - lib/music-transcription/packing/note_score_packing.rb
187
190
  - lib/music-transcription/packing/part_packing.rb
188
191
  - lib/music-transcription/packing/program_packing.rb
189
- - lib/music-transcription/packing/score_packing.rb
190
192
  - lib/music-transcription/parsing/articulation_parsing.rb
191
193
  - lib/music-transcription/parsing/articulation_parsing.treetop
192
194
  - lib/music-transcription/parsing/convenience_methods.rb
@@ -207,30 +209,39 @@ files:
207
209
  - lib/music-transcription/parsing/numbers/nonnegative_integer_parsing.treetop
208
210
  - lib/music-transcription/parsing/numbers/nonnegative_rational_parsing.rb
209
211
  - lib/music-transcription/parsing/numbers/nonnegative_rational_parsing.treetop
212
+ - lib/music-transcription/parsing/numbers/positive_float_parsing.rb
213
+ - lib/music-transcription/parsing/numbers/positive_float_parsing.treetop
210
214
  - lib/music-transcription/parsing/numbers/positive_integer_parsing.rb
211
215
  - lib/music-transcription/parsing/numbers/positive_integer_parsing.treetop
216
+ - lib/music-transcription/parsing/numbers/positive_rational_parsing.rb
217
+ - lib/music-transcription/parsing/numbers/positive_rational_parsing.treetop
218
+ - lib/music-transcription/parsing/parseable.rb
212
219
  - lib/music-transcription/parsing/pitch_node.rb
213
220
  - lib/music-transcription/parsing/pitch_parsing.rb
214
221
  - lib/music-transcription/parsing/pitch_parsing.treetop
215
222
  - lib/music-transcription/parsing/segment_parsing.rb
216
223
  - lib/music-transcription/parsing/segment_parsing.treetop
224
+ - lib/music-transcription/parsing/tempo_parsing.rb
225
+ - lib/music-transcription/parsing/tempo_parsing.treetop
217
226
  - lib/music-transcription/validatable.rb
218
227
  - lib/music-transcription/version.rb
219
228
  - music-transcription.gemspec
220
229
  - spec/model/change_spec.rb
221
230
  - spec/model/link_spec.rb
231
+ - spec/model/measure_score_spec.rb
222
232
  - spec/model/meter_spec.rb
233
+ - spec/model/note_score_spec.rb
223
234
  - spec/model/note_spec.rb
224
235
  - spec/model/part_spec.rb
225
236
  - spec/model/pitch_spec.rb
226
237
  - spec/model/program_spec.rb
227
- - spec/model/score_spec.rb
228
238
  - spec/model/tempo_spec.rb
229
239
  - spec/music-transcription_spec.rb
230
240
  - spec/packing/change_packing_spec.rb
241
+ - spec/packing/measure_score_packing_spec.rb
242
+ - spec/packing/note_score_packing_spec.rb
231
243
  - spec/packing/part_packing_spec.rb
232
244
  - spec/packing/program_packing_spec.rb
233
- - spec/packing/score_packing_spec.rb
234
245
  - spec/parsing/articulation_parsing_spec.rb
235
246
  - spec/parsing/convenience_methods_spec.rb
236
247
  - spec/parsing/duration_nodes_spec.rb
@@ -243,10 +254,13 @@ files:
243
254
  - spec/parsing/numbers/nonnegative_float_spec.rb
244
255
  - spec/parsing/numbers/nonnegative_integer_spec.rb
245
256
  - spec/parsing/numbers/nonnegative_rational_spec.rb
257
+ - spec/parsing/numbers/positive_float_spec.rb
246
258
  - spec/parsing/numbers/positive_integer_spec.rb
259
+ - spec/parsing/numbers/positive_rational_spec.rb
247
260
  - spec/parsing/pitch_node_spec.rb
248
261
  - spec/parsing/pitch_parsing_spec.rb
249
262
  - spec/parsing/segment_parsing_spec.rb
263
+ - spec/parsing/tempo_parsing_spec.rb
250
264
  - spec/spec_helper.rb
251
265
  homepage: https://github.com/jamestunnell/music-transcription
252
266
  licenses:
@@ -276,18 +290,20 @@ summary: Classes for representing music notational features like pitch, note, lo
276
290
  test_files:
277
291
  - spec/model/change_spec.rb
278
292
  - spec/model/link_spec.rb
293
+ - spec/model/measure_score_spec.rb
279
294
  - spec/model/meter_spec.rb
295
+ - spec/model/note_score_spec.rb
280
296
  - spec/model/note_spec.rb
281
297
  - spec/model/part_spec.rb
282
298
  - spec/model/pitch_spec.rb
283
299
  - spec/model/program_spec.rb
284
- - spec/model/score_spec.rb
285
300
  - spec/model/tempo_spec.rb
286
301
  - spec/music-transcription_spec.rb
287
302
  - spec/packing/change_packing_spec.rb
303
+ - spec/packing/measure_score_packing_spec.rb
304
+ - spec/packing/note_score_packing_spec.rb
288
305
  - spec/packing/part_packing_spec.rb
289
306
  - spec/packing/program_packing_spec.rb
290
- - spec/packing/score_packing_spec.rb
291
307
  - spec/parsing/articulation_parsing_spec.rb
292
308
  - spec/parsing/convenience_methods_spec.rb
293
309
  - spec/parsing/duration_nodes_spec.rb
@@ -300,9 +316,12 @@ test_files:
300
316
  - spec/parsing/numbers/nonnegative_float_spec.rb
301
317
  - spec/parsing/numbers/nonnegative_integer_spec.rb
302
318
  - spec/parsing/numbers/nonnegative_rational_spec.rb
319
+ - spec/parsing/numbers/positive_float_spec.rb
303
320
  - spec/parsing/numbers/positive_integer_spec.rb
321
+ - spec/parsing/numbers/positive_rational_spec.rb
304
322
  - spec/parsing/pitch_node_spec.rb
305
323
  - spec/parsing/pitch_parsing_spec.rb
306
324
  - spec/parsing/segment_parsing_spec.rb
325
+ - spec/parsing/tempo_parsing_spec.rb
307
326
  - spec/spec_helper.rb
308
327
  has_rdoc: