music-transcription 0.5.3 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/music-transcription/note.rb +1 -1
- data/lib/music-transcription/part.rb +1 -4
- data/lib/music-transcription/profile.rb +24 -9
- data/lib/music-transcription/version.rb +1 -1
- data/spec/profile_spec.rb +43 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4282478fab3c5ee51b228e44a971e1ac1e16e805
|
4
|
+
data.tar.gz: 07d760fd03b454c6086fba4ee8ef21fe4aec2fd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d87e2df814b0aa13654b988a1238d430ada083dcd260cf88ab2dbe4c7c828e9900ec2ed303cd8b15e07f93b23ecef9fe33bfb2b43eba0a2be1835d16f9ef778
|
7
|
+
data.tar.gz: b6715c68ecc2519ee2856bdf8bff13ec55e188abd047ed6a8936e6b2e7543e3b9a97bb8cfba79b62261ec8f6345b2def01c331b9cdecd7982701f69a72a34b92
|
@@ -69,10 +69,7 @@ class Part
|
|
69
69
|
# Part object. The offsets of value changes in the dynamic profile,
|
70
70
|
# for the other part, will be considered relative from end of current part.
|
71
71
|
def append! other
|
72
|
-
|
73
|
-
@dynamic_profile.merge_changes!(d => Change::Immediate.new(other.dynamic_profile.start_value))
|
74
|
-
@dynamic_profile.merge_changes!(other.dynamic_profile.shift(d).value_changes)
|
75
|
-
|
72
|
+
@dynamic_profile.append!(other.dynamic_profile,self.duration)
|
76
73
|
@notes += other.notes.map {|x| x.clone}
|
77
74
|
return self
|
78
75
|
end
|
@@ -25,12 +25,11 @@ class Profile
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def last_value
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
if @value_changes.empty?
|
29
|
+
return @start_value
|
30
|
+
else
|
31
|
+
return @value_changes[@value_changes.keys.max].value
|
32
32
|
end
|
33
|
-
return last
|
34
33
|
end
|
35
34
|
|
36
35
|
def changes_before? offset
|
@@ -52,12 +51,28 @@ class Profile
|
|
52
51
|
return self
|
53
52
|
end
|
54
53
|
|
55
|
-
def
|
56
|
-
self.clone.
|
54
|
+
def append profile, offset
|
55
|
+
self.clone.append! profile
|
57
56
|
end
|
58
57
|
|
59
|
-
def
|
60
|
-
@value_changes.
|
58
|
+
def append! profile, start_offset
|
59
|
+
if @value_changes.any? && start_offset < @value_changes.keys.max
|
60
|
+
raise ArgumentError, "appending profile overlaps"
|
61
|
+
end
|
62
|
+
|
63
|
+
lv = self.last_value
|
64
|
+
unless lv == profile.start_value
|
65
|
+
@value_changes[start_offset] = Change::Immediate.new(profile.start_value)
|
66
|
+
lv = profile.start_value
|
67
|
+
end
|
68
|
+
|
69
|
+
shifted = profile.shift(start_offset)
|
70
|
+
shifted.value_changes.sort.each do |offset,value_change|
|
71
|
+
unless value_change.value == lv
|
72
|
+
@value_changes[offset] = value_change
|
73
|
+
lv = value_change.value
|
74
|
+
end
|
75
|
+
end
|
61
76
|
return self
|
62
77
|
end
|
63
78
|
|
data/spec/profile_spec.rb
CHANGED
@@ -100,13 +100,49 @@ describe Profile do
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
describe '#
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
103
|
+
describe '#append!' do
|
104
|
+
before :each do
|
105
|
+
@p1 = Profile.new(0.0, 5.0 => Change::Immediate.new(0.1), 7.5 => Change::Immediate.new(0.2))
|
106
|
+
@p2 = Profile.new(0.2, 1.0 => Change::Immediate.new(0.0), 2.0 => Change::Gradual.new(100.0))
|
107
|
+
@p3 = Profile.new(0.1, 1.0 => Change::Immediate.new(0.0))
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'offset less than last value change offset' do
|
111
|
+
it' should raise ArgumentError' do
|
112
|
+
expect { @p1.append!(@p2,7.0) }.to raise_error(ArgumentError)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'offset equal to last value change offset' do
|
117
|
+
it' should not raise ArgumentError' do
|
118
|
+
expect { @p1.append!(@p2,7.5) }.not_to raise_error
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'offset greater than last value change offset' do
|
123
|
+
it' should not raise ArgumentError' do
|
124
|
+
expect { @p1.append!(@p2, 7.6) }.not_to raise_error
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should add on shifted value changes from second profile' do
|
128
|
+
@p1.append!(@p2,10.0)
|
129
|
+
@p1.value_changes[11.0].value.should eq 0.0
|
130
|
+
@p1.value_changes[12.0].value.should eq 100.0
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'second profile start value equal to first profile last value' do
|
135
|
+
it 'should not add value change at offset' do
|
136
|
+
@p1.append!(@p2, 10.0)
|
137
|
+
@p1.value_changes[10.0].should be nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'second profile start value not equal to first profile last value' do
|
142
|
+
it 'should add value change at offset' do
|
143
|
+
@p1.append!(@p3, 10.0)
|
144
|
+
@p1.value_changes[10.0].should_not be nil
|
145
|
+
end
|
110
146
|
end
|
111
147
|
end
|
112
148
|
end
|