music-transcription 0.5.5 → 0.5.6

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: 4282478fab3c5ee51b228e44a971e1ac1e16e805
4
- data.tar.gz: 07d760fd03b454c6086fba4ee8ef21fe4aec2fd2
3
+ metadata.gz: a54e9f73ce558bd8c64f6a7e8931e4d0572dcdaf
4
+ data.tar.gz: bde6d1183b854e50dcbaa677154f8f9349e5d36f
5
5
  SHA512:
6
- metadata.gz: 5d87e2df814b0aa13654b988a1238d430ada083dcd260cf88ab2dbe4c7c828e9900ec2ed303cd8b15e07f93b23ecef9fe33bfb2b43eba0a2be1835d16f9ef778
7
- data.tar.gz: b6715c68ecc2519ee2856bdf8bff13ec55e188abd047ed6a8936e6b2e7543e3b9a97bb8cfba79b62261ec8f6345b2def01c331b9cdecd7982701f69a72a34b92
6
+ metadata.gz: 99e008bc37f2f2c92b202217636e67f6ab93c14eaeee8a2c824323df9da36e92f859fb8d1c0a7fabc3bc93338c11fb5065a2c25b4c28bff6f1c61843708744cf
7
+ data.tar.gz: 4cb6c971e49c05a797aed7ee913ffd2c6337d3b3baea2de317132cdea97f389df1c792fbcec6bf99a8863e72dbf071739d575034d5480226d386d4bd3a413d34
@@ -73,6 +73,20 @@ class Part
73
73
  @notes += other.notes.map {|x| x.clone}
74
74
  return self
75
75
  end
76
+
77
+ def stretch ratio
78
+ self.clone.stretch! ratio
79
+ end
80
+
81
+ def stretch! ratio
82
+ @notes.each_index do |i|
83
+ n1 = @notes[i]
84
+ @notes[i] = Note.new(n1.duration * ratio, n1.pitches, links: n1.links, accent: n1.accent)
85
+ end
86
+
87
+ @dynamic_profile.stretch! ratio
88
+ return self
89
+ end
76
90
  end
77
91
 
78
92
  end
@@ -51,6 +51,15 @@ class Profile
51
51
  return self
52
52
  end
53
53
 
54
+ def stretch ratio
55
+ self.clone.stretch! ratio
56
+ end
57
+
58
+ def stretch! ratio
59
+ @value_changes = Hash[ @value_changes.map {|k,v| [k*ratio,v] }]
60
+ return self
61
+ end
62
+
54
63
  def append profile, offset
55
64
  self.clone.append! profile
56
65
  end
@@ -2,6 +2,6 @@
2
2
  module Music
3
3
  module Transcription
4
4
  # music-transcription version
5
- VERSION = "0.5.5"
5
+ VERSION = "0.5.6"
6
6
  end
7
7
  end
data/spec/part_spec.rb CHANGED
@@ -19,7 +19,40 @@ describe Part do
19
19
  end
20
20
  end
21
21
 
22
- context '#append!' do
22
+ describe '#stretch' do
23
+ before :all do
24
+ p = Part.new(
25
+ notes: [ Note::Quarter.new, Note::Whole.new, Note::Eighth.new ],
26
+ dynamic_profile: Profile.new(
27
+ Dynamics::PP,
28
+ "1/2".to_r => Change::Immediate.new(Dynamics::MP),
29
+ "3/4".to_r => Change::Immediate.new(Dynamics::FF)
30
+ )
31
+ )
32
+ @p1 = p.stretch(1)
33
+ @p2 = p.stretch("5/3".to_r)
34
+ @p3 = p.stretch("3/5".to_r)
35
+ end
36
+
37
+ it 'should multiply durations by ratio' do
38
+ @p1.notes.map {|n| n.duration }.should eq(["1/4".to_r, "1/1".to_r, "1/8".to_r])
39
+ @p2.notes.map {|n| n.duration }.should eq(["5/12".to_r, "5/3".to_r, "5/24".to_r])
40
+ @p3.notes.map {|n| n.duration }.should eq(["3/20".to_r, "3/5".to_r, "3/40".to_r])
41
+ end
42
+
43
+ it 'should multiply dynamic profile changes by ratio' do
44
+ @p1.dynamic_profile.value_changes.should have_key("1/2".to_r)
45
+ @p1.dynamic_profile.value_changes.should have_key("3/4".to_r)
46
+
47
+ @p2.dynamic_profile.value_changes.should have_key("5/6".to_r)
48
+ @p2.dynamic_profile.value_changes.should have_key("15/12".to_r)
49
+
50
+ @p3.dynamic_profile.value_changes.should have_key("3/10".to_r)
51
+ @p3.dynamic_profile.value_changes.should have_key("9/20".to_r)
52
+ end
53
+ end
54
+
55
+ describe '#append!' do
23
56
  it 'should add other notes to current array' do
24
57
  p1 = Part.new(notes: [Note::Eighth.new([C4])])
25
58
  p2 = Part.new(notes: [Note::Eighth.new([E4])])
data/spec/profile_spec.rb CHANGED
@@ -99,6 +99,21 @@ describe Profile do
99
99
  p.value_changes[7.5].value.should eq(0.2)
100
100
  end
101
101
  end
102
+
103
+ describe '#stretch!' do
104
+ it 'should multiply change offsets by ratio' do
105
+ p = Profile.new(0.0, 5.0 => Change::Immediate.new(0.1), 7.5 => Change::Immediate.new(0.2))
106
+ p.stretch!(1)
107
+ p.value_changes[5.0].value.should eq(0.1)
108
+ p.value_changes[7.5].value.should eq(0.2)
109
+ p.stretch!("3/2".to_r)
110
+ p.value_changes[7.5].value.should eq(0.1)
111
+ p.value_changes[11.25].value.should eq(0.2)
112
+ p.stretch!("2/3".to_r)
113
+ p.value_changes[5.0].value.should eq(0.1)
114
+ p.value_changes[7.5].value.should eq(0.2)
115
+ end
116
+ end
102
117
 
103
118
  describe '#append!' do
104
119
  before :each do
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.5.5
4
+ version: 0.5.6
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-08-31 00:00:00.000000000 Z
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler