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.
- checksums.yaml +4 -4
- data/Rakefile +34 -0
- data/lib/music-transcription/change.rb +2 -2
- data/lib/music-transcription/meter.rb +3 -4
- data/lib/music-transcription/note.rb +1 -2
- data/lib/music-transcription/parsing/articulation_parsing.rb +266 -0
- data/lib/music-transcription/parsing/articulation_parsing.treetop +61 -0
- data/lib/music-transcription/parsing/convenience_methods.rb +83 -0
- data/lib/music-transcription/parsing/duration_nodes.rb +23 -0
- data/lib/music-transcription/parsing/duration_parsing.rb +207 -0
- data/lib/music-transcription/parsing/duration_parsing.treetop +27 -0
- data/lib/music-transcription/parsing/link_nodes.rb +37 -0
- data/lib/music-transcription/parsing/link_parsing.rb +272 -0
- data/lib/music-transcription/parsing/link_parsing.treetop +35 -0
- data/lib/music-transcription/parsing/nonnegative_integer_parsing.rb +57 -0
- data/lib/music-transcription/parsing/nonnegative_integer_parsing.treetop +13 -0
- data/lib/music-transcription/parsing/note_nodes.rb +64 -0
- data/lib/music-transcription/parsing/note_parsing.rb +354 -0
- data/lib/music-transcription/parsing/note_parsing.treetop +47 -0
- data/lib/music-transcription/parsing/pitch_node.rb +20 -0
- data/lib/music-transcription/parsing/pitch_parsing.rb +355 -0
- data/lib/music-transcription/parsing/pitch_parsing.treetop +45 -0
- data/lib/music-transcription/parsing/positive_integer_parsing.rb +95 -0
- data/lib/music-transcription/parsing/positive_integer_parsing.treetop +19 -0
- data/lib/music-transcription/part.rb +1 -1
- data/lib/music-transcription/program.rb +1 -4
- data/lib/music-transcription/score.rb +1 -1
- data/lib/music-transcription/validatable.rb +16 -1
- data/lib/music-transcription/version.rb +1 -1
- data/lib/music-transcription.rb +14 -0
- data/music-transcription.gemspec +2 -0
- data/spec/parsing/articulation_parsing_spec.rb +23 -0
- data/spec/parsing/convenience_methods_spec.rb +89 -0
- data/spec/parsing/duration_nodes_spec.rb +83 -0
- data/spec/parsing/duration_parsing_spec.rb +70 -0
- data/spec/parsing/link_nodes_spec.rb +30 -0
- data/spec/parsing/link_parsing_spec.rb +23 -0
- data/spec/parsing/nonnegative_integer_spec.rb +11 -0
- data/spec/parsing/note_nodes_spec.rb +84 -0
- data/spec/parsing/note_parsing_spec.rb +43 -0
- data/spec/parsing/pitch_node_spec.rb +32 -0
- data/spec/parsing/pitch_parsing_spec.rb +23 -0
- data/spec/parsing/positive_integer_spec.rb +17 -0
- data/spec/spec_helper.rb +12 -0
- metadata +59 -2
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Parsing::LinkNode do
|
4
|
+
parser = Parsing::LinkParser.new
|
5
|
+
|
6
|
+
{
|
7
|
+
'=C4' => Link::Slur.new(C4),
|
8
|
+
'/Db2' => Link::Portamento.new(Db2),
|
9
|
+
'~C#2' => Link::Glissando.new(Db2),
|
10
|
+
'-Db2' => Link::Legato.new(Db2),
|
11
|
+
}.each do |str,tgt|
|
12
|
+
res = parser.parse(str)
|
13
|
+
context str do
|
14
|
+
it 'should parse as LinkNode' do
|
15
|
+
res.should be_a Parsing::LinkNode
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#to_pitch' do
|
19
|
+
l = res.to_link
|
20
|
+
it 'should produce a Link object' do
|
21
|
+
l.should be_a Link
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should produce pitch matching input str' do
|
25
|
+
l.should eq tgt
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Parsing::LinkParser do
|
4
|
+
before :all do
|
5
|
+
@parser = Parsing::LinkParser.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should parse a "=C2"' do
|
9
|
+
@parser.parse("=C2").should_not be nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should parse a "-C2"' do
|
13
|
+
@parser.parse("-C2").should_not be nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should parse a "~C2"' do
|
17
|
+
@parser.parse("~C2").should_not be nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should parse a "/C2"' do
|
21
|
+
@parser.parse("/C2").should_not be nil
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Parsing::NonnegativeIntegerParser do
|
4
|
+
parser = Parsing::NonnegativeIntegerParser.new
|
5
|
+
|
6
|
+
["1","50","05","502530","0"].each do |str|
|
7
|
+
it "should parse '#{str}'" do
|
8
|
+
parser.parse(str).should_not be nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
NOTE_PARSER = Parsing::NoteParser.new
|
4
|
+
|
5
|
+
describe Parsing::RestNoteNode do
|
6
|
+
{
|
7
|
+
'/2' => Note.new(Rational(1,2)),
|
8
|
+
'4/2' => Note.new(Rational(4,2)),
|
9
|
+
'28' => Note.new(Rational(28,1)),
|
10
|
+
'56/33' => Note.new(Rational(56,33)),
|
11
|
+
}.each do |str,tgt|
|
12
|
+
res = NOTE_PARSER.parse(str)
|
13
|
+
context str do
|
14
|
+
it 'should parse as RestNoteNode' do
|
15
|
+
res.should be_a Parsing::RestNoteNode
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#to_note' do
|
19
|
+
n = res.to_note
|
20
|
+
it 'should produce a Note' do
|
21
|
+
n.should be_a Note
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should produce value matching input str' do
|
25
|
+
n.should eq tgt
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Parsing::MonophonicNoteNode do
|
33
|
+
{
|
34
|
+
'/2=C2=C2' => Note.new(Rational(1,2),[C2],articulation:SLUR, links:{C2=>Link::Slur.new(C2)}),
|
35
|
+
'4/2.D#6' => Note.new(Rational(4,2),[Eb6],articulation:STACCATO),
|
36
|
+
'28%Eb7!' => Note.new(Rational(28,1),[Eb7],articulation:PORTATO, accented: true),
|
37
|
+
"56/33'B1" => Note.new(Rational(56,33),[B1],articulation:STACCATISSIMO),
|
38
|
+
}.each do |str,tgt|
|
39
|
+
res = NOTE_PARSER.parse(str)
|
40
|
+
context str do
|
41
|
+
it 'should parse as MonophonicNoteNode' do
|
42
|
+
res.should be_a Parsing::MonophonicNoteNode
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#to_note' do
|
46
|
+
n = res.to_note
|
47
|
+
it 'should produce a Note' do
|
48
|
+
n.should be_a Note
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should produce value matching input str' do
|
52
|
+
n.should eq tgt
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe Parsing::PolyphonicNoteNode do
|
60
|
+
{
|
61
|
+
'/2C2,D2,E2-F2' => Note.new(Rational(1,2),[C2,D2,E2],links:{E2=>Link::Legato.new(F2)}),
|
62
|
+
'4/2.D#6,G4' => Note.new(Rational(4,2),[Eb6,G4], articulation:STACCATO),
|
63
|
+
'28_Eb7,D7,G7' => Note.new(Rational(28,1),[Eb7,D7,G7],articulation:TENUTO),
|
64
|
+
'56/33B1,B2,B3,B4,B5!' => Note.new(Rational(56,33),[B1,B2,B3,B4,B5], accented: true),
|
65
|
+
}.each do |str,tgt|
|
66
|
+
res = NOTE_PARSER.parse(str)
|
67
|
+
context str do
|
68
|
+
it 'should parse as PolyphonicNoteNode' do
|
69
|
+
res.should be_a Parsing::PolyphonicNoteNode
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#to_note' do
|
73
|
+
n = res.to_note
|
74
|
+
it 'should produce a Note' do
|
75
|
+
n.should be_a Note
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should produce value matching input str' do
|
79
|
+
n.should eq tgt
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Parsing::NoteParser do
|
4
|
+
before :all do
|
5
|
+
@parser = Parsing::NoteParser.new
|
6
|
+
end
|
7
|
+
|
8
|
+
valid_cases = {
|
9
|
+
'duration only' => ['1/4','/2','1','55/33'],
|
10
|
+
'single pitch' => ['/4C2','5/3Db3','/33E#8'],
|
11
|
+
'multiple pitches' => ['/4C2,C3,c5','5/3Db3,Bb2,E5','/33E#8,F1,B9'],
|
12
|
+
'with articulation' => ['/4.C2',"5/3'Db3,Bb2,E5",'/33=F3','5-B2','/2_D3,F4'],
|
13
|
+
'with accent' => ['/4C2!','3/2Db3,Bb4!'],
|
14
|
+
'with links' => ['/2C2=','/2C2=D2','/4D4-E4,G4~A5'],
|
15
|
+
'with single pitch + articulation + link + accent' => [
|
16
|
+
'3/4.D2=!','5/8=F2=!','/8Db4-Db5!','/3_G4~B4!'],
|
17
|
+
'with multiple pitches + articulation + links + accent' => [
|
18
|
+
'5/4.D2=,G4-A4,C3~D3!','5/8-F2=D4,B4/A4!'],
|
19
|
+
}
|
20
|
+
invalid_cases = {
|
21
|
+
'single pitch' => ['/4C22','5/3Hb-3','/33E-2'],
|
22
|
+
'multiple pitches' => ['/4C20,C3,c5','5/3Db3,Bb-1,E5','/33H8,F1,B9'],
|
23
|
+
'with articulation' => ['/4[C2',"5/3>Db3"],
|
24
|
+
'with accent' => ['/4C2['],
|
25
|
+
'with links' => ['/2C2)'],
|
26
|
+
}
|
27
|
+
|
28
|
+
valid_cases.each do |descr, strs|
|
29
|
+
context(descr + ' (valid)') do
|
30
|
+
it 'should parse' do
|
31
|
+
strs.each {|s| @parser.should parse(s) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
invalid_cases.each do |descr, strs|
|
37
|
+
context(descr + ' (invalid)') do
|
38
|
+
it 'should not parse' do
|
39
|
+
strs.each {|s| @parser.should_not parse(s) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Parsing::PitchNode do
|
4
|
+
parser = Parsing::PitchParser.new
|
5
|
+
|
6
|
+
{
|
7
|
+
'C4' => C4,
|
8
|
+
'Db2' => Db2,
|
9
|
+
'C#2' => Db2,
|
10
|
+
'Db2' => Db2,
|
11
|
+
'F7' => F7,
|
12
|
+
'B1' => B1,
|
13
|
+
}.each do |str,tgt|
|
14
|
+
res = parser.parse(str)
|
15
|
+
context str do
|
16
|
+
it 'should parse as PitchNode' do
|
17
|
+
res.should be_a Parsing::PitchNode
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#to_pitch' do
|
21
|
+
p = res.to_pitch
|
22
|
+
it 'should produce a Pitch object' do
|
23
|
+
p.should be_a Pitch
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should produce pitch matching input str' do
|
27
|
+
p.should eq tgt
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Parsing::PitchParser do
|
4
|
+
before :all do
|
5
|
+
@parser = Parsing::PitchParser.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should parse "C4"' do
|
9
|
+
@parser.parse("C4").should_not be nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should parse "C#9"' do
|
13
|
+
@parser.parse("C#9").should_not be nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should parse "Ab0"' do
|
17
|
+
@parser.parse("Ab0").should_not be nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should parse "G#2"' do
|
21
|
+
@parser.parse("G#2").should_not be nil
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Parsing::PositiveIntegerParser do
|
4
|
+
parser = Parsing::PositiveIntegerParser.new
|
5
|
+
|
6
|
+
["1","50","05","502530"].each do |str|
|
7
|
+
it "should parse '#{str}'" do
|
8
|
+
parser.parse(str).should_not be nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
["0"].each do |str|
|
13
|
+
it "should not parse '#{str}'" do
|
14
|
+
parser.parse(str).should be nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -29,3 +29,15 @@ RSpec::Matchers.define :be_invalid do
|
|
29
29
|
obj.invalid?
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
RSpec::Matchers.define :parse do |str|
|
34
|
+
match do |parser|
|
35
|
+
!parser.parse(str).nil?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
RSpec::Matchers.define :parse_as do |str,nodeclass|
|
40
|
+
match do |parser|
|
41
|
+
parser.parse(str).is_a?(nodeclass)
|
42
|
+
end
|
43
|
+
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.
|
4
|
+
version: 0.10.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-
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: treetop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: "The goal of music-transcription is the abstract representation of standard
|
126
140
|
\nmusical features such as pitch, note, loudness, tempo, etc. Establishing\na common
|
127
141
|
representation enables composition and performance.\n"
|
@@ -159,6 +173,25 @@ files:
|
|
159
173
|
- lib/music-transcription/meter.rb
|
160
174
|
- lib/music-transcription/meters.rb
|
161
175
|
- lib/music-transcription/note.rb
|
176
|
+
- lib/music-transcription/parsing/articulation_parsing.rb
|
177
|
+
- lib/music-transcription/parsing/articulation_parsing.treetop
|
178
|
+
- lib/music-transcription/parsing/convenience_methods.rb
|
179
|
+
- lib/music-transcription/parsing/duration_nodes.rb
|
180
|
+
- lib/music-transcription/parsing/duration_parsing.rb
|
181
|
+
- lib/music-transcription/parsing/duration_parsing.treetop
|
182
|
+
- lib/music-transcription/parsing/link_nodes.rb
|
183
|
+
- lib/music-transcription/parsing/link_parsing.rb
|
184
|
+
- lib/music-transcription/parsing/link_parsing.treetop
|
185
|
+
- lib/music-transcription/parsing/nonnegative_integer_parsing.rb
|
186
|
+
- lib/music-transcription/parsing/nonnegative_integer_parsing.treetop
|
187
|
+
- lib/music-transcription/parsing/note_nodes.rb
|
188
|
+
- lib/music-transcription/parsing/note_parsing.rb
|
189
|
+
- lib/music-transcription/parsing/note_parsing.treetop
|
190
|
+
- lib/music-transcription/parsing/pitch_node.rb
|
191
|
+
- lib/music-transcription/parsing/pitch_parsing.rb
|
192
|
+
- lib/music-transcription/parsing/pitch_parsing.treetop
|
193
|
+
- lib/music-transcription/parsing/positive_integer_parsing.rb
|
194
|
+
- lib/music-transcription/parsing/positive_integer_parsing.treetop
|
162
195
|
- lib/music-transcription/part.rb
|
163
196
|
- lib/music-transcription/pitch.rb
|
164
197
|
- lib/music-transcription/pitches.rb
|
@@ -173,6 +206,18 @@ files:
|
|
173
206
|
- spec/meter_spec.rb
|
174
207
|
- spec/music-transcription_spec.rb
|
175
208
|
- spec/note_spec.rb
|
209
|
+
- spec/parsing/articulation_parsing_spec.rb
|
210
|
+
- spec/parsing/convenience_methods_spec.rb
|
211
|
+
- spec/parsing/duration_nodes_spec.rb
|
212
|
+
- spec/parsing/duration_parsing_spec.rb
|
213
|
+
- spec/parsing/link_nodes_spec.rb
|
214
|
+
- spec/parsing/link_parsing_spec.rb
|
215
|
+
- spec/parsing/nonnegative_integer_spec.rb
|
216
|
+
- spec/parsing/note_nodes_spec.rb
|
217
|
+
- spec/parsing/note_parsing_spec.rb
|
218
|
+
- spec/parsing/pitch_node_spec.rb
|
219
|
+
- spec/parsing/pitch_parsing_spec.rb
|
220
|
+
- spec/parsing/positive_integer_spec.rb
|
176
221
|
- spec/part_spec.rb
|
177
222
|
- spec/pitch_spec.rb
|
178
223
|
- spec/program_spec.rb
|
@@ -210,6 +255,18 @@ test_files:
|
|
210
255
|
- spec/meter_spec.rb
|
211
256
|
- spec/music-transcription_spec.rb
|
212
257
|
- spec/note_spec.rb
|
258
|
+
- spec/parsing/articulation_parsing_spec.rb
|
259
|
+
- spec/parsing/convenience_methods_spec.rb
|
260
|
+
- spec/parsing/duration_nodes_spec.rb
|
261
|
+
- spec/parsing/duration_parsing_spec.rb
|
262
|
+
- spec/parsing/link_nodes_spec.rb
|
263
|
+
- spec/parsing/link_parsing_spec.rb
|
264
|
+
- spec/parsing/nonnegative_integer_spec.rb
|
265
|
+
- spec/parsing/note_nodes_spec.rb
|
266
|
+
- spec/parsing/note_parsing_spec.rb
|
267
|
+
- spec/parsing/pitch_node_spec.rb
|
268
|
+
- spec/parsing/pitch_parsing_spec.rb
|
269
|
+
- spec/parsing/positive_integer_spec.rb
|
213
270
|
- spec/part_spec.rb
|
214
271
|
- spec/pitch_spec.rb
|
215
272
|
- spec/program_spec.rb
|