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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df3cae40779381ec3e2bfbe1a6829883529a41a5
4
- data.tar.gz: 85c4b61b76208b878bfd5db7d8ebf36c34fac625
3
+ metadata.gz: 4282478fab3c5ee51b228e44a971e1ac1e16e805
4
+ data.tar.gz: 07d760fd03b454c6086fba4ee8ef21fe4aec2fd2
5
5
  SHA512:
6
- metadata.gz: 41d2495c49a7d2cf9dccc7ee4d668bd8e7e349b29a045fbe732bc960f8ca4ea821c4fdf784daa1b0fd175196a661fe9b3480d17138285ef134c0414441e4490e
7
- data.tar.gz: 94147ffd63eb13fd3585ae7626f2e5db696cef35e0c72b7a16121608cfe0d4a59a1feea4cdb4a277ff53c7b486b49bf6e734b4e8d8f0605909c488857111a4ca
6
+ metadata.gz: 5d87e2df814b0aa13654b988a1238d430ada083dcd260cf88ab2dbe4c7c828e9900ec2ed303cd8b15e07f93b23ecef9fe33bfb2b43eba0a2be1835d16f9ef778
7
+ data.tar.gz: b6715c68ecc2519ee2856bdf8bff13ec55e188abd047ed6a8936e6b2e7543e3b9a97bb8cfba79b62261ec8f6345b2def01c331b9cdecd7982701f69a72a34b92
@@ -149,7 +149,7 @@ class Note
149
149
  end
150
150
  end
151
151
 
152
- class Half < Note
152
+ class DottedHalf < Note
153
153
  def initialize pitches = [], links: {}, accent: nil
154
154
  super(Rational(3,4),pitches, links: links, accent: accent)
155
155
  end
@@ -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
- d = self.duration
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
- last = @start_value
29
- last_change_pair = @value_changes.max_by {|k,v| k}
30
- unless last_change_pair.nil?
31
- last = last_change_pair[1].value
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 merge_changes changes
56
- self.clone.merge_changes! changes
54
+ def append profile, offset
55
+ self.clone.append! profile
57
56
  end
58
57
 
59
- def merge_changes! changes
60
- @value_changes.merge! 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
 
@@ -2,6 +2,6 @@
2
2
  module Music
3
3
  module Transcription
4
4
  # music-transcription version
5
- VERSION = "0.5.3"
5
+ VERSION = "0.5.5"
6
6
  end
7
7
  end
data/spec/profile_spec.rb CHANGED
@@ -100,13 +100,49 @@ describe Profile do
100
100
  end
101
101
  end
102
102
 
103
- describe '#merge_changes!' do
104
- it 'should merge given value changes with existing' do
105
- p = Profile.new(0.0, 5.0 => Change::Immediate.new(0.1), 7.5 => Change::Immediate.new(0.2))
106
- p.value_changes[7.5].value.should eq(0.2)
107
- p.value_changes[10.0].should be nil
108
- p.merge_changes!(10.0 => Change::Immediate.new(0.3))
109
- p.value_changes[10.0].value.should eq(0.3)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: music-transcription
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Tunnell