-185
-186
-187
+194
+195
+196
- # File 'lib/tonal/ratio.rb', line 185
+ # File 'lib/tonal/ratio.rb', line 194
def period_degrees(round: 2)
(360.0 * Math.log(to_f, equave)).round(round)
@@ -4588,12 +4573,12 @@
-194
-195
-196
+203
+204
+205
|
- # File 'lib/tonal/ratio.rb', line 194
+ # File 'lib/tonal/ratio.rb', line 203
def period_radians(round: 2)
(2 * Math::PI * Math.log(to_f, equave)).round(round)
@@ -5059,12 +5044,12 @@
-97
-98
-99
+106
+107
+108
|
- # File 'lib/tonal/ratio.rb', line 97
+ # File 'lib/tonal/ratio.rb', line 106
def ratio
self
@@ -5320,12 +5305,12 @@
-176
-177
-178
+185
+186
+187
|
- # File 'lib/tonal/ratio.rb', line 176
+ # File 'lib/tonal/ratio.rb', line 185
def step(modulo=12)
to_log2.step(modulo)
@@ -5458,12 +5443,12 @@
-115
-116
-117
+124
+125
+126
|
- # File 'lib/tonal/ratio.rb', line 115
+ # File 'lib/tonal/ratio.rb', line 124
def to_a
[antecedent, consequent]
@@ -5529,12 +5514,12 @@
-167
-168
-169
+176
+177
+178
|
- # File 'lib/tonal/ratio.rb', line 167
+ # File 'lib/tonal/ratio.rb', line 176
def to_cents
Tonal::Cents.new(ratio: to_r)
@@ -5596,12 +5581,12 @@
-140
-141
-142
+149
+150
+151
|
- # File 'lib/tonal/ratio.rb', line 140
+ # File 'lib/tonal/ratio.rb', line 149
def to_f
antecedent.to_f / consequent.to_f
@@ -5684,12 +5669,12 @@
-149
-150
-151
+158
+159
+160
|
- # File 'lib/tonal/ratio.rb', line 149
+ # File 'lib/tonal/ratio.rb', line 158
def to_log(base=2)
Tonal::Log.new(logarithmand: to_r, base: base)
@@ -5755,12 +5740,12 @@
-158
-159
-160
+167
+168
+169
|
- # File 'lib/tonal/ratio.rb', line 158
+ # File 'lib/tonal/ratio.rb', line 167
def to_log2
Tonal::Log2.new(logarithmand: to_r)
@@ -5822,13 +5807,13 @@
-131
-132
-133
-134
+140
+141
+142
+143
|
- # File 'lib/tonal/ratio.rb', line 131
+ # File 'lib/tonal/ratio.rb', line 140
def to_r
return Float::INFINITY if consequent.zero? || !antecedent.finite?
@@ -5895,12 +5880,12 @@
-234
-235
-236
+243
+244
+245
|
- # File 'lib/tonal/ratio.rb', line 234
+ # File 'lib/tonal/ratio.rb', line 243
def to_reduced_ratio
Tonal::ReducedRatio.new(reduced_antecedent, reduced_consequent, equave: equave)
@@ -5962,12 +5947,12 @@
-123
-124
-125
+132
+133
+134
|
- # File 'lib/tonal/ratio.rb', line 123
+ # File 'lib/tonal/ratio.rb', line 132
def to_v
Vector[antecedent, consequent]
@@ -6271,7 +6256,7 @@ |
- # File 'lib/tonal/approximations.rb', line 15
+ # File 'lib/tonal/approximation.rb', line 15
def initialize(ratio:)
raise ArgumentError, "Tonal::Ratio required" unless ratio.kind_of?(Tonal::Ratio)
@@ -474,7 +508,7 @@
15
|
- # File 'lib/tonal/approximations.rb', line 13
+ # File 'lib/tonal/approximation.rb', line 13
def ratio
@ratio
@@ -514,7 +548,7 @@
Examples:
- Tonal::Ratio::Approximations.neighbors(vacinity: (3/2r).ratio(reduced:false).scale(256), away: 1)
+ Tonal::Ratio::Approximation.neighbors(vacinity: (3/2r).ratio(reduced:false).scale(256), away: 1)
=> [(768/513), (767/512), (768/512), (769/512), (768/511)]
@@ -566,20 +600,20 @@
-136
-137
-138
-139
-140
-141
-142
-143
-144
-145
-146
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
|
- # File 'lib/tonal/approximations.rb', line 136
+ # File 'lib/tonal/approximation.rb', line 160
def self.neighbors(vacinity:, away: 1)
[vacinity,
@@ -606,7 +640,7 @@ Instance Method Details
- #by_continued_fraction(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ Array
+ #by_continued_fraction(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ Tonal::Ratio::Approximation::Set
@@ -626,8 +660,8 @@
Examples:
- Tonal::Ratio.ed(12,1).by_continued_fraction
-=> [(18/17), (196/185), (1657/1564), (7893/7450), (18904/17843), (3118/2943), (1461/1379), (89/84), (17/16)]
+ Tonal::Ratio.ed(12,1).approximate.by_continued_fraction
+=> (4771397596969315/4503599627370496): [(18/17), (196/185), (1657/1564), (7893/7450), (18904/17843), (3118/2943), (1461/1379), (89/84), (17/16)]
Parameters:
@@ -644,6 +678,11 @@
(defaults to: Tonal::Cents::TOLERANCE)
+ —
+
+ the cents tolerance used to scope the collection
+
+
@@ -657,6 +696,11 @@
(defaults to: DEFAULT_DEPTH)
+ —
+
+ the maximum number of ratios in the collection
+
+
@@ -670,6 +714,11 @@
(defaults to: DEFAULT_MAX_PRIME)
+ —
+
+ the maximum prime number to allow in the collection
+
+
@@ -683,6 +732,11 @@
(defaults to: CONVERGENT_LIMIT)
+ —
+
+ the number of convergents to limit the ContinuedFraction method
+
+
@@ -693,7 +747,7 @@
- (Array)
+ (Tonal::Ratio::Approximation::Set)
@@ -725,18 +779,18 @@
39
|
- # File 'lib/tonal/approximations.rb', line 29
+ # File 'lib/tonal/approximation.rb', line 29
-def by_continued_fraction(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT)
+def by_continued_fraction(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT)
self_in_cents = to_cents
within = cents_tolerance.kind_of?(Tonal::Cents) ? cents_tolerance : Tonal::Cents.new(cents: cents_tolerance)
- [].tap do |results|
+ Set.new(ratio: ratio).tap do |set|
ContinuedFraction.new(antecedent.to_f/consequent, conv_limit).convergents.each do |convergent|
ratio2 = ratio.class.new(convergent.numerator,convergent.denominator)
- results << ratio2 if ratio.class.within_cents?(self_in_cents, ratio2.to_cents, within) && ratio2.within_prime?(max_prime)
- break if results.length >= depth
+ set.ratios << ratio2 if ratio.class.within_cents?(self_in_cents, ratio2.to_cents, within) && ratio2.within_prime?(max_prime)
+ break if set.length >= depth
end
- end.sort
+ end
end
|
@@ -766,8 +820,8 @@