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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c2fc709b232296837b37e177d25e0137463190d
4
- data.tar.gz: 81a65dbc071f0d8348639ac3d62a1d24f1228cf5
3
+ metadata.gz: 8585079e44d770cd9b479c84c0ecc3e9271cc024
4
+ data.tar.gz: a8eb0336f24ddc38d6a4db9ef455cb257dbf0bdd
5
5
  SHA512:
6
- metadata.gz: cbce6472afdf023f80b0f96a8b504a07d7d45ad52eb669cb8364c63a088846c6c0abf05b6159bd92d77af5ce7452a8ab2054a8e590ab891ac189aa40e70a48b0
7
- data.tar.gz: 926ddd4d1255da7023bf38dcbe60c51cf89b03e8cf1abf3383485d2cab6df61df0e79219d304b41af9a2ee3953d5586ab410ab39bb4dfabcbb7c5215c4d9e3fd
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
- normalize!
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 normalize!
150
+ def balance!
143
151
  centsTotal = @total_cents
144
152
 
145
153
  @octave = centsTotal / CENTS_PER_OCTAVE
@@ -2,6 +2,6 @@
2
2
  module Music
3
3
  module Transcription
4
4
  # music-transcription version
5
- VERSION = "0.16.0"
5
+ VERSION = "0.17.0"
6
6
  end
7
7
  end
@@ -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|
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.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Tunnell