music-transcription 0.16.0 → 0.17.0
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/model/pitch.rb +11 -3
- data/lib/music-transcription/version.rb +1 -1
- data/spec/model/pitch_spec.rb +19 -0
- 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: 8585079e44d770cd9b479c84c0ecc3e9271cc024
|
4
|
+
data.tar.gz: a8eb0336f24ddc38d6a4db9ef455cb257dbf0bdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2553a91e355ae72e6a8323e6bea35ee13e52d3bcd83b107d29e898bee273b4fcea220c1a3215df26e5ea563e310ce5b180f27d7fe18cde73e3adbc0d2b73b45
|
7
|
+
data.tar.gz: 23e06712c82eb5dd92c4be0f77562ff2c3ed89ad6a2e2b6ce889194e7aa287c1a33b778c727a7c4d5c217defe2e6fcdc1e0da35e070a39d1337bb030d655af93
|
@@ -40,7 +40,7 @@ class Pitch
|
|
40
40
|
@semitone = semitone
|
41
41
|
@cent = cent
|
42
42
|
@total_cents = (@octave*SEMITONES_PER_OCTAVE + @semitone)*CENTS_PER_SEMITONE + @cent
|
43
|
-
|
43
|
+
balance!
|
44
44
|
end
|
45
45
|
|
46
46
|
# Return the pitch's frequency, which is determined by multiplying the base
|
@@ -96,7 +96,15 @@ class Pitch
|
|
96
96
|
def transpose semitones
|
97
97
|
Pitch.new(cent: (@total_cents + semitones * CENTS_PER_SEMITONE).round)
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
|
+
def total_semitones
|
101
|
+
Rational(@total_cents, CENTS_PER_SEMITONE)
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.from_semitones semitones
|
105
|
+
Pitch.new(cent: (semitones * CENTS_PER_SEMITONE).round)
|
106
|
+
end
|
107
|
+
|
100
108
|
def clone
|
101
109
|
Pitch.new(cent: @total_cents)
|
102
110
|
end
|
@@ -139,7 +147,7 @@ class Pitch
|
|
139
147
|
private
|
140
148
|
|
141
149
|
# Balance out the octave and semitone count.
|
142
|
-
def
|
150
|
+
def balance!
|
143
151
|
centsTotal = @total_cents
|
144
152
|
|
145
153
|
@octave = centsTotal / CENTS_PER_OCTAVE
|
data/spec/model/pitch_spec.rb
CHANGED
@@ -70,6 +70,25 @@ describe Pitch do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
describe '.total_semitones' do
|
74
|
+
it 'should convert to whole/fractional total semitones value' do
|
75
|
+
C4.total_semitones.should eq(48)
|
76
|
+
C5.total_semitones.should eq(60)
|
77
|
+
C4.transpose(0.1).total_semitones.should eq(48.1)
|
78
|
+
C5.transpose(0.19).total_semitones.should eq(60.19)
|
79
|
+
C5.transpose(-0.19).total_semitones.should eq(59.81)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '.from_semitones' do
|
84
|
+
it 'should convert (rounded) fractional part to cent value' do
|
85
|
+
Pitch.from_semitones(4).total_cents.should eq(400)
|
86
|
+
Pitch.from_semitones(4.11).total_cents.should eq(411)
|
87
|
+
Pitch.from_semitones(57.123).total_cents.should eq(5712)
|
88
|
+
Pitch.from_semitones(57.125).total_cents.should eq(5713)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
73
92
|
describe '.from_ratio' do
|
74
93
|
it 'should return a Pitch with given ratio' do
|
75
94
|
@cases.each do |case_data|
|