diff --git a/docs/Array.html b/docs/Array.html index 141e625..3a2fc92 100644 --- a/docs/Array.html +++ b/docs/Array.html @@ -143,7 +143,7 @@

  • - #lcm ⇒ Integer + #denominize ⇒ Array @@ -158,7 +158,7 @@

    -

    Least common multiple of integer elements of self.

    +

    An array of ratios with equalized denominators.

  • @@ -167,7 +167,7 @@

  • - #mean ⇒ Float + #lcm ⇒ Integer @@ -182,7 +182,7 @@

    -

    The mean of the elements of self.

    +

    Least common multiple of integer elements of self.

  • @@ -191,7 +191,7 @@

  • - #modulo_translate(lower = 0, upper) ⇒ Array + #mean ⇒ Float @@ -206,7 +206,7 @@

    -

    Translated modularly.

    +

    The mean of the elements of self.

  • @@ -215,7 +215,7 @@

  • - #normalize ⇒ Array + #modulo_translate(lower = 0, upper) ⇒ Array @@ -230,7 +230,7 @@

    -

    An array of normalized ratios.

    +

    Translated modularly.

  • @@ -265,7 +265,7 @@

  • - #ratio_from_prime_divisions ⇒ Tonal::ReducedRatio + #ratio_from_prime_divisions(reduced: false) ⇒ Tonal::ReducedRatio @@ -508,6 +508,75 @@

    + + +
    +

    + + #denominizeArray + + + + + +

    +
    + +

    Returns an array of ratios with equalized denominators.

    + + +
    +
    +
    + +
    +

    Examples:

    + + +
    [4/3r, 3/2r].denominize => [(8/6), (9/6)]
    + +
    + +

    Returns:

    +
      + +
    • + + + (Array) + + + + — +
      +

      an array of ratios with equalized denominators

      +
      + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +331
    +332
    +333
    +334
    +
    +
    # File 'lib/tonal/extensions.rb', line 331
    +
    +def denominize
    +  l = denominators.lcm
    +  map{|r| Tonal::Ratio.new(l / r.denominator * r.numerator, l)}
    +end
    +
    @@ -727,15 +796,15 @@

     
     
    -386
     387
     388
     389
     390
    -391
    +391 +392 -
    # File 'lib/tonal/extensions.rb', line 386
    +      
    # File 'lib/tonal/extensions.rb', line 387
     
     def modulo_translate(lower=0, upper)
       range = (upper - lower) == 0 ? 1 : upper - lower
    @@ -746,75 +815,6 @@ 

    -

    - -
    -

    - - #normalizeArray - - - - - -

    -
    - -

    Returns an array of normalized ratios.

    - - -
    -
    -
    - -
    -

    Examples:

    - - -
    [4/3r, 3/2r].normalize => [(8/6), (9/6)]
    - -
    - -

    Returns:

    -
      - -
    • - - - (Array) - - - - — -
      -

      an array of normalized ratios

      -
      - -
    • - -
    - -
    - - - - -
    -
    -
    -
    -331
    -332
    -333
    -334
    -
    -
    # File 'lib/tonal/extensions.rb', line 331
    -
    -def normalize
    -  l = denominators.lcm
    -  map{|r| Tonal::Ratio.new(l / r.denominator * r.numerator, l)}
    -end
    -
    @@ -887,7 +887,7 @@

    - #ratio_from_prime_divisionsTonal::ReducedRatio + #ratio_from_prime_divisions(reduced: false) ⇒ Tonal::ReducedRatio @@ -936,12 +936,12 @@

     
     
    -353
    +354 -
    # File 'lib/tonal/extensions.rb', line 353
    +      
    # File 'lib/tonal/extensions.rb', line 354
     
    -def ratio_from_prime_divisions = Tonal::Ratio.new(Prime.int_from_prime_division(self.first), Prime.int_from_prime_division(self.last))
    +def ratio_from_prime_divisions(reduced: false) = reduced ? Tonal::ReducedRatio.new(Prime.int_from_prime_division(self.first), Prime.int_from_prime_division(self.last)) : Tonal::Ratio.new(Prime.int_from_prime_division(self.first), Prime.int_from_prime_division(self.last))
    @@ -1028,17 +1028,17 @@

     
     
    -370
     371
     372
     373
     374
     375
     376
    -377
    +377 +378 -
    # File 'lib/tonal/extensions.rb', line 370
    +      
    # File 'lib/tonal/extensions.rb', line 371
     
     def rescale(new_min=0, new_max)
       old_min = min
    @@ -1447,10 +1447,10 @@ 

     
     
    -360
    +361

    -
    # File 'lib/tonal/extensions.rb', line 360
    +      
    # File 'lib/tonal/extensions.rb', line 361
     
     def translate(value) = self.map{|e| e + value}
    @@ -1463,7 +1463,7 @@

    diff --git a/docs/Integer.html b/docs/Integer.html index 53047af..d738776 100644 --- a/docs/Integer.html +++ b/docs/Integer.html @@ -808,7 +808,7 @@

    diff --git a/docs/Math.html b/docs/Math.html index a714c27..3177834 100644 --- a/docs/Math.html +++ b/docs/Math.html @@ -214,10 +214,10 @@

     
     
    -411
    +412 -
    # File 'lib/tonal/extensions.rb', line 411
    +      
    # File 'lib/tonal/extensions.rb', line 412
     
     def self.factorial(limit) = (2..limit).reduce(1, :*)
    @@ -230,7 +230,7 @@

    diff --git a/docs/Numeric.html b/docs/Numeric.html index 6d2ab4f..6550fd7 100644 --- a/docs/Numeric.html +++ b/docs/Numeric.html @@ -2468,7 +2468,7 @@

    diff --git a/docs/Prime.html b/docs/Prime.html index fe2e8d5..e23ccf8 100644 --- a/docs/Prime.html +++ b/docs/Prime.html @@ -253,7 +253,7 @@

    diff --git a/docs/Rational.html b/docs/Rational.html index 0bd9860..8680f51 100644 --- a/docs/Rational.html +++ b/docs/Rational.html @@ -482,7 +482,7 @@

    diff --git a/docs/Tonal.html b/docs/Tonal.html index d88e9c8..1cf38c6 100644 --- a/docs/Tonal.html +++ b/docs/Tonal.html @@ -78,7 +78,9 @@
    Defined in:
    -
    lib/tonal/tools.rb
    +
    lib/tonal/tools.rb,
    + lib/tonal/attributions.rb
    +
    @@ -94,6 +96,27 @@

    Defined Under Namespace

    + +

    + Constant Summary + collapse +

    + +
    + +
    TOOLS_PRODUCER = + +
    +
    "mTonal"
    + +
    TOOLS_VERSION = + +
    +
    "2.0.1"
    + +
    + + @@ -105,7 +128,7 @@

    Defined Under Namespace

    diff --git a/docs/Tonal/Cents.html b/docs/Tonal/Cents.html index 9256abd..034d8cc 100644 --- a/docs/Tonal/Cents.html +++ b/docs/Tonal/Cents.html @@ -143,11 +143,6 @@

    2
    -
    DEFAULT_ROUNDING_PRECISION = - -
    -
    2
    - @@ -546,6 +541,7 @@

     
     
    +23
     24
     25
     26
    @@ -563,11 +559,10 @@ 

    38 39 40 -41 -42

    +41

    -
    # File 'lib/tonal/cents.rb', line 24
    +      
    # File 'lib/tonal/cents.rb', line 23
     
     def initialize(cents: nil, log: nil, ratio: nil, precision: PRECISION)
       raise ArgumentError, "One of cents:, log: or ratio: must be provided" unless [cents, log, ratio].compact.count == 1
    @@ -627,6 +622,7 @@ 

     
     
    +129
     130
     131
     132
    @@ -638,11 +634,10 @@ 

    138 139 140 -141 -142

    +141

    -
    # File 'lib/tonal/cents.rb', line 130
    +      
    # File 'lib/tonal/cents.rb', line 129
     
     def method_missing(op, *args, &blk)
       rhs = args.collect do |arg|
    @@ -695,12 +690,12 @@ 

     
     
    +13
     14
    -15
    -16
    +15

    -
    # File 'lib/tonal/cents.rb', line 14
    +      
    # File 'lib/tonal/cents.rb', line 13
     
     def log
       @log
    @@ -738,12 +733,12 @@ 

     
     
    +13
     14
    -15
    -16
    +15

    -
    # File 'lib/tonal/cents.rb', line 14
    +      
    # File 'lib/tonal/cents.rb', line 13
     
     def ratio
       @ratio
    @@ -812,12 +807,12 @@ 

     
     
    +47
     48
    -49
    -50
    +49

    -
    # File 'lib/tonal/cents.rb', line 48
    +      
    # File 'lib/tonal/cents.rb', line 47
     
     def self.default_tolerance
       self.new(cents: TOLERANCE)
    @@ -859,15 +854,15 @@ 

     
     
    +101
     102
    -103
    -104
    +103

    -
    # File 'lib/tonal/cents.rb', line 102
    +      
    # File 'lib/tonal/cents.rb', line 101
     
     def <=>(rhs)
    -  rhs.kind_of?(self.class) ? value.round(2) <=> rhs.value.round(2) : value.round(2) <=> rhs.round(2)
    +  rhs.kind_of?(self.class) ? value.round(PRECISION) <=> rhs.value.round(PRECISION) : value.round(PRECISION) <=> rhs.round(PRECISION)
     end
    @@ -928,12 +923,12 @@

     
     
    +92
     93
    -94
    -95
    +94

    -
    # File 'lib/tonal/cents.rb', line 93
    +      
    # File 'lib/tonal/cents.rb', line 92
     
     def inspect
       "#{value.round(@precision)}"
    @@ -997,12 +992,12 @@ 

     
     
    +65
     66
    -67
    -68
    +67

    -
    # File 'lib/tonal/cents.rb', line 66
    +      
    # File 'lib/tonal/cents.rb', line 65
     
     def nearest_hundredth
       self.class.new(cents: value.round(Tonal::Cents::HUNDREDTHS_ROUNDOFF).to_f)
    @@ -1066,12 +1061,12 @@ 

     
     
    +74
     75
    -76
    -77
    +76

    -
    # File 'lib/tonal/cents.rb', line 75
    +      
    # File 'lib/tonal/cents.rb', line 74
     
     def nearest_hundredth_difference
       self.class.new(cents: (value - nearest_hundredth))
    @@ -1134,12 +1129,12 @@ 

     
     
    +83
     84
    -85
    -86
    +85

    -
    # File 'lib/tonal/cents.rb', line 84
    +      
    # File 'lib/tonal/cents.rb', line 83
     
     def plus_minus(limit = 5)
       [self - limit, self + limit]
    @@ -1205,12 +1200,12 @@ 

     
     
    +55
     56
    -57
    -58
    +57

    -
    # File 'lib/tonal/cents.rb', line 56
    +      
    # File 'lib/tonal/cents.rb', line 55
     
     def value(precision: @precision)
       @value.round(precision)
    @@ -1225,7 +1220,7 @@ 

    diff --git a/docs/Tonal/Comma.html b/docs/Tonal/Comma.html index 3e64694..059d54a 100644 --- a/docs/Tonal/Comma.html +++ b/docs/Tonal/Comma.html @@ -504,7 +504,7 @@

    diff --git a/docs/Tonal/Hertz.html b/docs/Tonal/Hertz.html index fc0856a..b99da78 100644 --- a/docs/Tonal/Hertz.html +++ b/docs/Tonal/Hertz.html @@ -822,7 +822,7 @@

    diff --git a/docs/Tonal/Interval.html b/docs/Tonal/Interval.html index 039e896..fd1f17f 100644 --- a/docs/Tonal/Interval.html +++ b/docs/Tonal/Interval.html @@ -139,6 +139,8 @@

    Instance Attribute Summary collaps + (also: #ratio) + @@ -261,15 +263,13 @@

  • - #initialize(upper_ratio, lower_ratio) ⇒ Interval + #denominize ⇒ Object - constructor - @@ -277,9 +277,7 @@

    -
    -

    A new instance of Interval.

    -
    +

  • @@ -287,13 +285,15 @@

  • - #inspect ⇒ Object + #initialize(upper_ratio, lower_ratio) ⇒ Interval + constructor + @@ -301,7 +301,9 @@

    -
    +
    +

    A new instance of Interval.

    +

  • @@ -309,7 +311,7 @@

  • - #normalize ⇒ Object + #inspect ⇒ Object @@ -417,6 +419,10 @@

    + Also known as: + ratio + +

    @@ -567,12 +573,12 @@

     
     
    -35
     36
    -37
    +37 +38

  • -
    # File 'lib/tonal/interval.rb', line 35
    +      
    # File 'lib/tonal/interval.rb', line 36
     
     def <=>(rhs)
       interval.to_r <=> rhs.interval.to_r
    @@ -583,9 +589,9 @@ 

    -

    +

    - #inspectObject + #denominizeObject @@ -597,15 +603,19 @@

     
     
    -31
    -32
    -33
    +26 +27 +28 +29 +30

    -
    # File 'lib/tonal/interval.rb', line 31
    +      
    # File 'lib/tonal/interval.rb', line 26
     
    -def inspect
    -  "#{self.to_r} (#{upper.to_r} / #{lower.to_r})"
    +def denominize
    +  ratios = to_a
    +  lcm = ratios.denominators.lcm
    +  ratios.map{|r| Tonal::Ratio.new(lcm / r.denominator * r.numerator, lcm)}
     end
    @@ -613,9 +623,9 @@

    -

    +

    - #normalizeObject + #inspectObject @@ -627,19 +637,15 @@

     
     
    -25
    -26
    -27
    -28
    -29
    +32 +33 +34

    -
    # File 'lib/tonal/interval.rb', line 25
    +      
    # File 'lib/tonal/interval.rb', line 32
     
    -def normalize
    -  ratios = to_a
    -  lcm = ratios.denominators.lcm
    -  ratios.map{|r| Tonal::Ratio.new(lcm / r.denominator * r.numerator, lcm)}
    +def inspect
    +  "#{self.to_r} (#{upper.to_r} / #{lower.to_r})"
     end
    @@ -661,12 +667,12 @@

     
     
    -21
     22
    -23
    +23 +24

    -
    # File 'lib/tonal/interval.rb', line 21
    +      
    # File 'lib/tonal/interval.rb', line 22
     
     def to_a
       [lower_ratio, upper_ratio]
    @@ -681,7 +687,7 @@ 

    diff --git a/docs/Tonal/Log.html b/docs/Tonal/Log.html index d874366..adced86 100644 --- a/docs/Tonal/Log.html +++ b/docs/Tonal/Log.html @@ -1016,7 +1016,7 @@

    diff --git a/docs/Tonal/Log2.html b/docs/Tonal/Log2.html index b581141..b8ff3b6 100644 --- a/docs/Tonal/Log2.html +++ b/docs/Tonal/Log2.html @@ -216,7 +216,7 @@

    diff --git a/docs/Tonal/Ratio.html b/docs/Tonal/Ratio.html index 5df8d70..c4410c2 100644 --- a/docs/Tonal/Ratio.html +++ b/docs/Tonal/Ratio.html @@ -104,7 +104,7 @@
    Defined in:
    -
    lib/tonal/approximations.rb,
    +
    lib/tonal/approximation.rb,
    lib/tonal/ratio.rb
    @@ -121,7 +121,7 @@

    Defined Under Namespace

    - Classes: Approximations + Classes: Approximation

    @@ -321,7 +321,7 @@

  • - .random_ratio(number_of_factors = 2, within: 100) ⇒ Tonal::Ratio + .random_ratio(number_of_factors = 2, within: 100, reduced: false) ⇒ Tonal::Ratio @@ -345,7 +345,7 @@

  • - .superparticular(n) ⇒ Tonal::Ratio + .superparticular(n, factor: 1, superpart: :upper) ⇒ Tonal::Ratio @@ -360,7 +360,7 @@

    -

    Ratio who’s numerator and denominator are 1 apart.

    +

    Ratio who’s numerator and denominator are seperated by a difference of 1.

  • @@ -369,7 +369,7 @@

  • - .superpartient(n, part) ⇒ Tonal::Ratio + .superpartient(n, summand:, factor: 1, superpart: :upper) ⇒ Tonal::Ratio @@ -384,7 +384,7 @@

    -

    Ratio who’s numerator and denominator are a partient apart.

    +

    Ratio who’s numerator and denominator are separated by a summand difference.

  • @@ -558,7 +558,7 @@

  • - #approx ⇒ Tonal::Ratio::Approximations + #approximate ⇒ Tonal::Ratio::Approximation @@ -1072,28 +1072,6 @@

    The mirror of self along the axis (default 1/1).

    -

  • - - -
  • - - - #mirror2(ratio) ⇒ Tonal::Ratio - - - - - - - - - - - - - -
    -
  • @@ -1826,7 +1804,7 @@

    @equave = equave @reduced_antecedent, @reduced_consequent = _equave_reduce(equave) @label = label - @approximations = Approximations.new(ratio: self) + @approximation = Approximation.new(ratio: self) end

  • @@ -2160,12 +2138,12 @@

     
     
    -80
    -81
    -82
    +89 +90 +91

    -
    # File 'lib/tonal/ratio.rb', line 80
    +      
    # File 'lib/tonal/ratio.rb', line 89
     
     def self.ed(modulo, step, equave: 2/1r)
       self.new(2**(step.to_f/modulo), equave: equave)
    @@ -2178,7 +2156,7 @@ 

    - .random_ratio(number_of_factors = 2, within: 100) ⇒ Tonal::Ratio + .random_ratio(number_of_factors = 2, within: 100, reduced: false) ⇒ Tonal::Ratio @@ -2257,21 +2235,21 @@

     
     
    -61
    -62
    -63
    -64
    -65
    -66
    -67
    -68
    -69
    -70
    +70 +71 +72 +73 +74 +75 +76 +77 +78 +79

    -
    # File 'lib/tonal/ratio.rb', line 61
    +      
    # File 'lib/tonal/ratio.rb', line 70
     
    -def self.random_ratio(number_of_factors = 2, within: 100)
    +def self.random_ratio(number_of_factors = 2, within: 100, reduced: false)
       primes = Prime.each(within).to_a
       nums = []
       dens = []
    @@ -2279,7 +2257,7 @@ 

    nums << [primes[rand(10)], rand(3)] dens << [primes[rand(10)], rand(3)] end - [nums, dens].ratio_from_prime_divisions + [nums, dens].ratio_from_prime_divisions(reduced:) end

    @@ -2289,7 +2267,7 @@

    - .superparticular(n) ⇒ Tonal::Ratio + .superparticular(n, factor: 1, superpart: :upper) ⇒ Tonal::Ratio @@ -2298,7 +2276,7 @@

    -

    Returns ratio who’s numerator and denominator are 1 apart.

    +

    Returns ratio who’s numerator and denominator are seperated by a difference of 1.

    @@ -2309,7 +2287,7 @@

    Examples:

    -
    Tonal::Ratio.superparticular(100) = (100/99)
    +
    Tonal::Ratio.superparticular(100) = (101/100)

    Parameters:

    @@ -2320,13 +2298,49 @@

    n - + (Integer) + + + + — +
    +

    number from which the superior part is calculated

    +
    + +

  • + +
  • + + factor + (Rational) + + + (defaults to: 1) + —
    -

    numerator of ratio

    +

    multiplied into the resulting ratio, default 1/1

    +
    + +
  • + +
  • + + superpart + + + (Symbol) + + + (defaults to: :upper) + + + — +
    +

    assigning the superior part to the antecedent or consequent

  • @@ -2345,7 +2359,7 @@

    -

    ratio who’s numerator and denominator are 1 apart

    +

    ratio who’s numerator and denominator are seperated by a difference of 1

    @@ -2358,15 +2372,15 @@

     
     
    -41
    -42
    -43
    +43 +44 +45 -
    # File 'lib/tonal/ratio.rb', line 41
    +      
    # File 'lib/tonal/ratio.rb', line 43
     
    -def self.superparticular(n)
    -  superpartient(n, 1)
    +def self.superparticular(n, factor: 1/1r, superpart: :upper)
    +  superpartient(n, summand: 1, factor:, superpart:)
     end
    @@ -2376,7 +2390,7 @@

    - .superpartient(n, part) ⇒ Tonal::Ratio + .superpartient(n, summand:, factor: 1, superpart: :upper) ⇒ Tonal::Ratio @@ -2385,7 +2399,7 @@

    -

    Returns ratio who’s numerator and denominator are a partient apart.

    +

    Returns ratio who’s numerator and denominator are separated by a summand difference.

    @@ -2396,7 +2410,7 @@

    Examples:

    -
    Tonal::Ratio.superpartient(100, 5) => (100/95)
    +
    Tonal::Ratio.superpartient(23, summand: 3) => (26/23)

    Parameters:

    @@ -2407,29 +2421,65 @@

    n - + (Integer)
    -

    numerator of ratio

    +

    number from which the superior part is calculated

  • - part + summand - + (Integer)
    -

    partient separating the numerator and denominator

    +

    term added to the superior part

    +
    + +
  • + +
  • + + factor + + + (Rational) + + + (defaults to: 1) + + + — +
    +

    multiplied into the resulting ratio, default 1/1

    +
    + +
  • + +
  • + + superpart + + + (Symbol) + + + (defaults to: :upper) + + + — +
    +

    assigning the superior part to the antecedent or consequent

  • @@ -2448,7 +2498,7 @@

    -

    ratio who’s numerator and denominator are a partient apart

    +

    ratio who’s numerator and denominator are separated by a summand difference

    @@ -2461,15 +2511,25 @@

     
     
    -51
    -52
    -53
    +55 +56 +57 +58 +59 +60 +61 +62

    -
    # File 'lib/tonal/ratio.rb', line 51
    +      
    # File 'lib/tonal/ratio.rb', line 55
     
    -def self.superpartient(n, part)
    -  self.new(n, n-part)
    +def self.superpartient(n, summand:, factor: 1/1r, superpart: :upper)
    +  case superpart.to_sym.downcase
    +  when :lower, :consequent, :denominator
    +    self.new(n*factor.numerator, (n+summand)*factor.denominator)
    +  else
    +    self.new((n+summand)*factor.numerator, n*factor.denominator)
    +  end
     end
    @@ -2565,12 +2625,12 @@

     
     
    -91
    -92
    -93
    +100 +101 +102

    -
    # File 'lib/tonal/ratio.rb', line 91
    +      
    # File 'lib/tonal/ratio.rb', line 100
     
     def self.within_cents?(cents1, cents2, within)
       (cents1 - cents2).abs <= within
    @@ -2771,9 +2831,9 @@ 

    -

    +

    - #approxTonal::Ratio::Approximations + #approximateTonal::Ratio::Approximation @@ -2795,7 +2855,7 @@

  • - (Tonal::Ratio::Approximations) + (Tonal::Ratio::Approximation) @@ -2814,15 +2874,15 @@

     
     
    -103
    -104
    -105
    +112 +113 +114

  • -
    # File 'lib/tonal/ratio.rb', line 103
    +      
    # File 'lib/tonal/ratio.rb', line 112
     
    -def approx
    -  @approximations
    +def approximate
    +  @approximation
     end
    @@ -3288,7 +3348,7 @@

    # File 'lib/tonal/ratio.rb', line 436
     
     def efficiency(modulo)
    -  (Tonal::Cents::CENT_SCALE * step(modulo).step / modulo.to_f) - to_cents
    +  ((Tonal::Cents::CENT_SCALE * step(modulo).step / modulo.to_f) - to_cents).round(Tonal::Cents::PRECISION)
     end
    @@ -3373,12 +3433,12 @@

     
     
    -212
    -213
    -214
    +221 +222 +223

    -
    # File 'lib/tonal/ratio.rb', line 212
    +      
    # File 'lib/tonal/ratio.rb', line 221
     
     def equave_reduce(equave=2/1r)
       self.class.new(*_equave_reduce(equave))
    @@ -3466,13 +3526,13 @@ 

     
     
    -223
    -224
    -225
    -226
    +232 +233 +234 +235

    -
    # File 'lib/tonal/ratio.rb', line 223
    +      
    # File 'lib/tonal/ratio.rb', line 232
     
     def equave_reduce!(equave=2/1r)
       @antecedent, @consequent = _equave_reduce(equave)
    @@ -3542,12 +3602,12 @@ 

     
     
    -203
    -204
    -205
    +212 +213 +214

    -
    # File 'lib/tonal/ratio.rb', line 203
    +      
    # File 'lib/tonal/ratio.rb', line 212
     
     def fraction_reduce
       self.class.new(to_r)
    @@ -3684,12 +3744,12 @@ 

     
     
    -243
    -244
    -245
    +252 +253 +254

    -
    # File 'lib/tonal/ratio.rb', line 243
    +      
    # File 'lib/tonal/ratio.rb', line 252
     
     def invert
       self.class.new(consequent, antecedent)
    @@ -3751,14 +3811,14 @@ 

     
     
    -252
    -253
    -254
    -255
    -256
    +261 +262 +263 +264 +265

    -
    # File 'lib/tonal/ratio.rb', line 252
    +      
    # File 'lib/tonal/ratio.rb', line 261
     
     def invert!
       tmp = antecedent
    @@ -3828,7 +3888,7 @@ 

    # Return label, if defined; or, # Return the "antecedent/consequent", if antecedent is less than 7 digits long; or # Return the floating point representation rounded to 2 digits of precision - (@label || ((Math.log10(antecedent).to_i + 1) <= 6 ? "#{antecedent}/#{consequent}" : to_f.round(2))).to_s + (@label || ((Math.log10(antecedent).to_i + 1) <= 6 ? "#{antecedent}/#{consequent}" : to_f.round(Tonal::Cents::PRECISION))).to_s end

    @@ -4278,81 +4338,6 @@

     
     
    -263
    -264
    -265
    - - -
    # File 'lib/tonal/ratio.rb', line 263
    -
    -def mirror(axis=1/1r)
    -  (self.class.new(axis) ** 2) / self
    -end
    - - - - - -
    -

    - - #mirror2(ratio) ⇒ Tonal::Ratio - - - - - -

    -
    - - -
    -
    -
    - -
    -

    Examples:

    - - -
    Tonal::Ratio.new(4/3r).mirror2(4/2r) => (3/8)
    - -
    -

    Parameters:

    -
      - -
    • - - ratio - - - - - - -
    • - -
    - -

    Returns:

    - - -
    - - @@ -4504,12 +4489,12 @@

     
     
    -185
    -186
    -187
    +194 +195 +196

    @@ -242,7 +242,7 @@

    diff --git a/docs/_config.yml b/docs/_config.yml deleted file mode 100644 index a25eb13..0000000 --- a/docs/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: minima diff --git a/docs/_index.html b/docs/_index.html index f211bfe..f34ddfd 100644 --- a/docs/_index.html +++ b/docs/_index.html @@ -81,7 +81,7 @@

    Namespace Listing A-Z

    • - Approximations + Approximation (Tonal::Ratio) @@ -248,6 +248,13 @@

      Namespace Listing A-Z

    • S
      • +
      • + Set + + (Tonal::Ratio::Approximation) + +
      • +
      • Step @@ -293,7 +300,7 @@

        Namespace Listing A-Z

        diff --git a/docs/class_list.html b/docs/class_list.html index d514395..30ff551 100644 --- a/docs/class_list.html +++ b/docs/class_list.html @@ -43,7 +43,7 @@

        Class List

        diff --git a/docs/file.README.html b/docs/file.README.html index e1ce386..8de7c05 100644 --- a/docs/file.README.html +++ b/docs/file.README.html @@ -79,7 +79,7 @@

        License

        diff --git a/docs/index.html b/docs/index.html index 18e24d0..521b5a1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -79,7 +79,7 @@

        License

        diff --git a/docs/method_list.html b/docs/method_list.html index 1bf318f..a8ecf37 100644 --- a/docs/method_list.html +++ b/docs/method_list.html @@ -94,8 +94,8 @@

        Method List

      • - #<=> - Tonal::Hertz + #<=> + Tonal::Cents
      • @@ -118,24 +118,24 @@

        Method List

      • - #<=> - Tonal::Log + #<=> + Tonal::Step
      • - #<=> - Tonal::Cents + #<=> + Tonal::Log
      • - #<=> - Tonal::Step + #<=> + Tonal::Hertz
      • @@ -158,7 +158,7 @@

        Method List

      • - #approx + #approximate Tonal::Ratio
      • @@ -166,23 +166,23 @@

        Method List

      • - base - Tonal::Log + base + Tonal::Log2
      • - base - Tonal::Log2 + #base + Tonal::Log
      • - #base + base Tonal::Log
      • @@ -190,53 +190,61 @@

        Method List

      • - #benedetti_height - Tonal::Ratio + #benedetti_height + Numeric
      • - #benedetti_height - Numeric + #benedetti_height + Tonal::Ratio
      • - #by_continued_fraction - Tonal::Ratio::Approximations + #by_continued_fraction + Tonal::Ratio::Approximation
      • - #by_neighborhood - Tonal::Ratio::Approximations + #by_neighborhood + Tonal::Ratio::Approximation
      • - #by_quotient_walk - Tonal::Ratio::Approximations + #by_quotient_walk + Tonal::Ratio::Approximation
      • - #by_tree_path - Tonal::Ratio::Approximations + #by_superparticular + Tonal::Ratio::Approximation
      • +
        + #by_tree_path + Tonal::Ratio::Approximation +
        +
      • + + +
      • #cent_diff Tonal::Ratio @@ -244,7 +252,7 @@

        Method List

      • -
      • +
      • #cents Numeric @@ -252,7 +260,7 @@

        Method List

      • -
      • +
      • #combination Tonal::Ratio @@ -260,7 +268,7 @@

        Method List

      • -
      • +
      • commas Tonal::Comma @@ -268,7 +276,7 @@

        Method List

      • -
      • +
      • #consequent Tonal::Ratio @@ -276,7 +284,7 @@

        Method List

      • -
      • +
      • #convert Tonal::Step @@ -284,7 +292,7 @@

        Method List

      • -
      • +
      • #coprime? Integer @@ -292,7 +300,7 @@

        Method List

      • -
      • +
      • #coprimes Integer @@ -300,7 +308,7 @@

        Method List

      • -
      • +
      • default_tolerance Tonal::Cents @@ -308,7 +316,7 @@

        Method List

      • -
      • +
      • #denominators Array @@ -316,17 +324,25 @@

        Method List

      • +
      • +
        + #denominize + Array +
        +
      • + +
      • - #difference - Tonal::Ratio + #denominize + Tonal::Interval
      • - #div_times + #difference Tonal::Ratio
      • @@ -334,23 +350,23 @@

        Method List

      • - #div_times - Numeric + #div_times + Tonal::Ratio
      • - ed - Tonal::Ratio + #div_times + Numeric
      • - #efficiency + ed Tonal::Ratio
      • @@ -366,7 +382,7 @@

        Method List

      • - #equave + #efficiency Tonal::Ratio
      • @@ -374,7 +390,7 @@

        Method List

      • - #equave_reduce + #equave Tonal::Ratio
      • @@ -382,7 +398,7 @@

        Method List

      • - #equave_reduce! + #equave_reduce Tonal::Ratio
      • @@ -390,8 +406,8 @@

        Method List

      • - #factorial - Integer + #equave_reduce! + Tonal::Ratio
      • @@ -405,6 +421,14 @@

        Method List

      • +
        + #factorial + Integer +
        +
      • + + +
      • #fraction_reduce Tonal::Ratio @@ -412,7 +436,7 @@

        Method List

      • -
      • +
      • #hz Numeric @@ -420,7 +444,7 @@

        Method List

      • -
      • +
      • identity Tonal::ReducedRatio @@ -428,6 +452,14 @@

        Method List

      • +
      • +
        + #initialize + Tonal::Ratio::Approximation::Set +
        +
      • + +
      • #initialize @@ -438,8 +470,8 @@

        Method List

      • - #initialize - Tonal::Cents + #initialize + Tonal::Log
      • @@ -454,32 +486,32 @@

        Method List

      • - #initialize - Tonal::ReducedRatio + #initialize + Tonal::Cents
      • - #initialize - Tonal::Ratio::Approximations + #initialize + Tonal::Ratio::Approximation
      • - #initialize - Tonal::Log + #initialize + Tonal::Ratio
      • - #initialize - Tonal::Ratio + #initialize + Tonal::ReducedRatio
      • @@ -494,16 +526,16 @@

        Method List

      • - #inspect - Tonal::Log + #inspect + Tonal::Cents
      • - #inspect - Tonal::Cents + #inspect + Tonal::Step
      • @@ -518,29 +550,37 @@

        Method List

      • - #inspect - Tonal::Ratio + #inspect + Tonal::Interval
      • - #inspect - Tonal::Interval + #inspect + Tonal::Ratio::Approximation::Set
      • - #inspect - Tonal::Step + #inspect + Tonal::Log
      • +
        + #inspect + Tonal::Ratio +
        +
      • + + +
      • #interval Tonal::Interval @@ -548,7 +588,7 @@

        Method List

      • -
      • +
      • #interval_with Numeric @@ -556,7 +596,7 @@

        Method List

      • -
      • +
      • #interval_with Tonal::ReducedRatio @@ -564,7 +604,7 @@

        Method List

      • -
      • +
      • #invert Tonal::Ratio @@ -572,7 +612,7 @@

        Method List

      • -
      • +
      • #invert! Tonal::Ratio @@ -580,7 +620,7 @@

        Method List

      • -
      • +
      • keys Tonal::Comma @@ -588,7 +628,7 @@

        Method List

      • -
      • +
      • #label Tonal::Ratio @@ -596,6 +636,14 @@

        Method List

      • +
      • +
        + #lcm + Tonal::Ratio +
        +
      • + +
      • #lcm @@ -606,8 +654,8 @@

        Method List

      • - #lcm - Tonal::Ratio + #log + Numeric
      • @@ -630,7 +678,7 @@

        Method List

      • - #log + #log2 Numeric
      • @@ -638,8 +686,8 @@

        Method List

      • - #log2 - Numeric + #log_weil_height + Tonal::Ratio
      • @@ -654,15 +702,15 @@

        Method List

      • - #log_weil_height - Tonal::Ratio + #logarithm + Tonal::Log
      • - #logarithm + #logarithmand Tonal::Log
      • @@ -670,24 +718,24 @@

        Method List

      • - #logarithmand - Tonal::Log + #lower_ratio + Tonal::Interval
      • - #lower_ratio - Tonal::Interval + #max_prime + Tonal::Ratio
      • - #max_prime - Tonal::Ratio + #max_prime + Integer
      • @@ -710,24 +758,24 @@

        Method List

      • - #max_prime - Integer + #mean + Array
      • - #mean - Array + #mediant_sum + Tonal::Ratio
      • - #mediant_sum - Tonal::Ratio + #method_missing + Tonal::Hertz
      • @@ -742,16 +790,16 @@

        Method List

      • - #method_missing - Tonal::Hertz + #min_prime + Tonal::Ratio
      • - #min_prime - Tonal::Ratio + #min_prime + Integer
      • @@ -772,22 +820,6 @@

        Method List

        -
      • -
        - #min_prime - Integer -
        -
      • - - -
      • -
        - #mirror - Tonal::Ratio -
        -
      • - -
      • #mirror @@ -798,7 +830,7 @@

        Method List

      • - #mirror2 + #mirror Tonal::Ratio
      • @@ -814,16 +846,16 @@

        Method List

      • - #modulo_translate - Array + #modulo_translate + Numeric
      • - #modulo_translate - Numeric + #modulo_translate + Array
      • @@ -862,32 +894,16 @@

        Method List

      • - #neighborhood - Tonal::Ratio::Approximations + #neighborhood + Tonal::Ratio::Approximation
      • - neighbors - Tonal::Ratio::Approximations -
        -
      • - - -
      • -
        - #normalize - Array -
        -
      • - - -
      • -
        - #normalize - Tonal::Interval + neighbors + Tonal::Ratio::Approximation
      • @@ -958,40 +974,40 @@

        Method List

      • - #plus_minus - Tonal::Ratio + #plus_minus + Numeric
      • - #plus_minus - Numeric + #plus_minus + Tonal::Cents
      • - #plus_minus - Tonal::Cents + #plus_minus + Tonal::Ratio
      • - #prime_divisions - Tonal::Ratio + #prime_divisions + Rational
      • - #prime_divisions - Rational + #prime_divisions + Tonal::Ratio
      • @@ -1006,16 +1022,16 @@

        Method List

      • - #prime_vector - Numeric + #prime_vector + Tonal::Ratio
      • - #prime_vector - Tonal::Ratio + #prime_vector + Numeric
      • @@ -1030,16 +1046,16 @@

        Method List

      • - #ratio - Tonal::Cents + #ratio + Tonal::Step
      • - #ratio - Tonal::Ratio::Approximations + #ratio + Tonal::Cents
      • @@ -1054,13 +1070,21 @@

        Method List

      • - #ratio - Tonal::Step + #ratio + Tonal::Ratio::Approximation::Set
      • +
        + #ratio + Tonal::Ratio::Approximation +
        +
      • + + +
      • #ratio_from_prime_divisions Array @@ -1068,6 +1092,14 @@

        Method List

      • +
      • +
        + #ratios + Tonal::Ratio::Approximation::Set +
        +
      • + +
      • #reduced_antecedent @@ -1126,8 +1158,8 @@

        Method List

      • - #step - Tonal::Log + #step + Tonal::Ratio
      • @@ -1150,8 +1182,8 @@

        Method List

      • - #step - Tonal::Ratio + #step + Tonal::Log
      • @@ -1222,40 +1254,40 @@

        Method List

      • - #to_cents - Tonal::Step + #to_cents + Numeric
      • - #to_cents - Tonal::Log + #to_cents + Tonal::Ratio
      • - #to_cents - Tonal::Ratio + #to_cents + Array
      • - #to_cents - Array + #to_cents + Tonal::Step
      • - #to_cents - Numeric + #to_cents + Tonal::Log
      • @@ -1294,8 +1326,8 @@

        Method List

      • - #to_r - Tonal::Ratio + #to_r + Tonal::Step
      • @@ -1310,8 +1342,8 @@

        Method List

      • - #to_r - Tonal::Step + #to_r + Tonal::Ratio
      • @@ -1350,16 +1382,16 @@

        Method List

      • - #to_vector - Rational + #to_vector + Array
      • - #to_vector - Array + #to_vector + Rational
      • diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html index 5ae45a1..22c14fb 100644 --- a/docs/top-level-namespace.html +++ b/docs/top-level-namespace.html @@ -102,7 +102,7 @@

        Defined Under Namespace

        diff --git a/lib/tonal/approximation.rb b/lib/tonal/approximation.rb new file mode 100644 index 0000000..a8527b0 --- /dev/null +++ b/lib/tonal/approximation.rb @@ -0,0 +1,189 @@ +class Tonal::Ratio + class Approximation + DEFAULT_MAX_PRIME = Float::INFINITY + DEFAULT_MAX_GRID_SCALE = 100 + DEFAULT_MAX_GRID_BOUNDARY = 5 + DEFAULT_DEPTH = Float::INFINITY + DEFAULT_COMPLEXITY_AMOUNT = 50.0 + CONVERGENT_LIMIT = 10 + + extend Forwardable + def_delegators :@ratio, :antecedent, :consequent, :to_cents, :to_basic_ratio, :to_f + + attr_reader :ratio + + def initialize(ratio:) + raise ArgumentError, "Tonal::Ratio required" unless ratio.kind_of?(Tonal::Ratio) + @ratio = ratio + end + + # @return [Tonal::Ratio::Approximation::Set] of ratios within cent tolerance of self found using continued fraction approximation + # @example + # 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)] + # @param cents_tolerance the cents tolerance used to scope the collection + # @param depth the maximum number of ratios in the collection + # @param max_prime the maximum prime number to allow in the collection + # @param conv_limit the number of convergents to limit the ContinuedFraction method + # + 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) + 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) + 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 + end + + # @return [Tonal::Ratio::Approximation::Set] of ratios within cent tolerance of self found using a quotient walk on the fraction tree + # @example + # Tonal::Ratio.ed(12,1).approximate.by_quotient_walk(max_prime: 89) + # => (4771397596969315/4503599627370496): [(18/17), (196/185), (89/84), (71/67), (53/50), (35/33), (17/16)] + # @param cents_tolerance the cents tolerance used to scope the collection + # @param depth the maximum number of ratios in the collection + # @param max_prime the maximum prime number to allow in the collection + # @param conv_limit the number of convergents to limit the ContinuedFraction method + # + def by_quotient_walk(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) + + Set.new(ratio: ratio).tap do |set| + FractionTree.quotient_walk(to_f, limit: conv_limit).each do |node| + ratio2 = ratio.class.new(node.weight) + 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 + end + + # @return [Tonal::Ratio::Approximation::Set] of fraction tree ratios within cent tolerance of self + # @example + # Tonal::Ratio.ed(12,1).approximate.by_tree_path(max_prime: 17) + # => (4771397596969315/4503599627370496): [(18/17), (35/33), (17/16)] + # @param cents_tolerance the cents tolerance used to scope the collection + # @param depth the maximum number of ratios in the collection + # @param max_prime the maximum prime number to allow in the collection + # + def by_tree_path(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME) + self_in_cents = to_cents + within = cents_tolerance.kind_of?(Tonal::Cents) ? cents_tolerance : Tonal::Cents.new(cents: cents_tolerance) + Set.new(ratio: ratio).tap do |set| + FractionTree.path_to(to_f).each do |node| + ratio2 = ratio.class.new(node.weight) + 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 + end + + # @return [Tonal::Ratio::Approximation::Set] of superparticular approximations within cent tolerance of self + # @example + # Tonal::Ratio.new(3/2r).approximate.by_superparticular + # => (3/2): [(1098/730), (1095/728), (1092/726), (1089/724), (1086/722), (1083/720), (1080/718), (1077/716), (1074/714), (1071/712), (1068/710), (1065/708), (1062/706), (1059/704), (1056/702), (1053/700), (1050/698), (1047/696), (1044/694), (1041/692)] + # @param cents_tolerance the cents tolerance used to scope the collection + # @param depth the maximum number of ratios in the collection + # @param max_prime the maximum prime number to allow in the collection + # @param superpart if the superior part is the numerator or denominator + # + def by_superparticular(cents_tolerance: Tonal::Cents::TOLERANCE, depth: 20, max_prime: DEFAULT_MAX_PRIME, superpart: :upper) + self_in_cents = to_cents + within = cents_tolerance.kind_of?(Tonal::Cents) ? cents_tolerance : Tonal::Cents.new(cents: cents_tolerance) + Set.new(ratio: ratio).tap do |set| + n = 1 + while true do + ratio2 = ratio.class.superparticular(n, factor: ratio.to_r, superpart:) + set.ratios << ratio2 if ratio.class.within_cents?(self_in_cents, ratio2.to_cents, within) && ratio2.within_prime?(max_prime) && ratio2 != ratio + break if set.length >= depth + n += 1 + end + end + end + + # @return [Array] of ratios within cent tolerance of self found on the ratio grid + # @example + # Tonal::Ratio.new(3,2).approximate.by_neighborhood(max_prime: 23, cents_tolerance: 5, max_boundary: 10, max_scale: 60) + # => (3/2): [(175/117), (176/117)] + # @param cents_tolerance the cents tolerance used to scope the collection + # @param depth the maximum number of ratios in the collection + # @param max_prime the maximum prime number to allow in the collection + # @param max_boundary the maximum distance grid ratios will be from the scaled ratio + # @param max_scale the maximum self will be scaled + # + def by_neighborhood(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, max_boundary: DEFAULT_MAX_GRID_BOUNDARY, max_scale: DEFAULT_MAX_GRID_SCALE) + self_in_cents = to_cents + within = cents_tolerance.kind_of?(Tonal::Cents) ? cents_tolerance : Tonal::Cents.new(cents: cents_tolerance) + Set.new(ratio: ratio).tap do |set| + scale = 1 + boundary = 1 + + while set.length <= depth && scale <= max_scale do + while boundary <= max_boundary + vacinity = ratio.respond_to?(:to_basic_ratio) ? to_basic_ratio.scale(scale) : ratio.scale(scale) + self.class.neighbors(away: boundary, vacinity: vacinity).each do |neighbor| + set.ratios << neighbor if ratio.class.within_cents?(self_in_cents, neighbor.to_cents, within) && neighbor.within_prime?(max_prime) && neighbor != ratio + end + boundary += 1 + end + boundary = 1 + scale += 1 + end + end + end + + # @return [Array] of bounding ratios in the ratio grid vacinity of antecedent/consequent scaled by scale + # @example + # Tonal::ReducedRatio.new(3,2).neighborhood(scale: 256, boundary: 2) + # => [(768/514), (766/512), (768/513), (767/512), (768/512), (769/512), (768/511), (770/512), (768/510)] + # @param scale [Integer] used to scale antecedent/consequent on coordinate system + # @param boundary [Integer] limit within which to calculate neighboring ratios + # + def neighborhood(scale: 2**0, boundary: 1) + scale = scale.round + vacinity = ratio.respond_to?(:to_basic_ratio) ? to_basic_ratio.scale(scale) : ratio.scale(scale) + SortedSet.new([].tap do |ratio_list| + 1.upto(boundary) do |away| + ratio_list << self.class.neighbors(away: away, vacinity: vacinity) + end + end.flatten).to_a + end + + # @return [Array] an array of Tonal::Ratio neighbors in the scaled ratio's grid neighborhood + # @example + # Tonal::Ratio::Approximation.neighbors(vacinity: (3/2r).ratio(reduced:false).scale(256), away: 1) + # => [(768/513), (767/512), (768/512), (769/512), (768/511)] + # @param away [Integer] the neighbors distance away from self's antecedent and consequent + # + def self.neighbors(vacinity:, away: 1) + [vacinity, + vacinity.class.new(vacinity.antecedent+away, vacinity.consequent), + vacinity.class.new(vacinity.antecedent-away, vacinity.consequent), + vacinity.class.new(vacinity.antecedent, vacinity.consequent+away), + vacinity.class.new(vacinity.antecedent, vacinity.consequent-away), + vacinity.class.new(vacinity.antecedent+away, vacinity.consequent+away), + vacinity.class.new(vacinity.antecedent+away, vacinity.consequent-away), + vacinity.class.new(vacinity.antecedent-away, vacinity.consequent+away), + vacinity.class.new(vacinity.antecedent-away, vacinity.consequent-away)] + end + + class Set + extend Forwardable + def_delegators :@ratios, :count, :length, :min, :max, :entries, :all?, :any?, :reject, :map + + attr_reader :ratios, :ratio + + def initialize(ratio:) + @ratio = ratio + @ratios = SortedSet.new + end + alias :approximations :entries + + def inspect + "#{ratio}: #{entries}" + end + end + end +end \ No newline at end of file diff --git a/lib/tonal/approximations.rb b/lib/tonal/approximations.rb deleted file mode 100644 index 0558942..0000000 --- a/lib/tonal/approximations.rb +++ /dev/null @@ -1,148 +0,0 @@ -class Tonal::Ratio - class Approximations - DEFAULT_MAX_PRIME = Float::INFINITY - DEFAULT_MAX_GRID_SCALE = 100 - DEFAULT_MAX_GRID_BOUNDARY = 5 - DEFAULT_DEPTH = Float::INFINITY - DEFAULT_COMPLEXITY_AMOUNT = 50.0 - CONVERGENT_LIMIT = 10 - - extend Forwardable - def_delegators :@ratio, :antecedent, :consequent, :to_cents, :to_basic_ratio, :to_f - - attr_reader :ratio - - def initialize(ratio:) - raise ArgumentError, "Tonal::Ratio required" unless ratio.kind_of?(Tonal::Ratio) - @ratio = ratio - end - - # @return [Array] of ratios within cent tolerance of self found using continued fraction approximation - # @example - # 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)] - # @param cents_tolerance - # @param depth - # @param max_prime - # @param conv_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| - 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 - end - end.sort - end - - # @return [Array] of ratios within cent tolerance of self found using a quotient walk on the fraction tree - # @example - # Tonal::Ratio.ed(12,1).by_quotient_walk(max_prime: 89) - # => [(18/17), (196/185), (89/84), (71/67), (53/50), (35/33), (17/16)] - # @param cents_tolerance - # @param depth - # @param max_prime - # - def by_quotient_walk(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| - FractionTree.quotient_walk(to_f, limit: conv_limit).each do |node| - ratio2 = ratio.class.new(node.weight) - results << ratio2 if ratio.class.within_cents?(self_in_cents, ratio2.to_cents, within) && ratio2.within_prime?(max_prime) - break if results.length >= depth - end - end.sort - end - - # @return [Array] of fraction tree ratios within cent tolerance of self - # @example - # Tonal::Ratio.ed(12,1).by_tree_path(max_prime: 17) - # => [(18/17), (35/33), (17/16)] - # @param cents_tolerance - # @param depth - # @param max_prime - # - def by_tree_path(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME) - self_in_cents = to_cents - within = cents_tolerance.kind_of?(Tonal::Cents) ? cents_tolerance : Tonal::Cents.new(cents: cents_tolerance) - [].tap do |results| - FractionTree.path_to(to_f).each do |node| - ratio2 = ratio.class.new(node.weight) - results << ratio2 if ratio.class.within_cents?(self_in_cents, ratio2.to_cents, within) && ratio2.within_prime?(max_prime) - break if results.length >= depth - end - end.sort - end - - # @return [Array] of ratios within cent tolerance of self found on the ratio grid - # @example - # Tonal::Ratio.new(3,2).by_neighborhood(max_prime: 23, cents_tolerance: 5, max_boundary: 10, max_scale: 60) - # => [(175/117), (176/117)] - # @param cents_tolerance the maximum cents self is allowed from grid ratios - # @param depth the maximum depth the array will get - # @param max_prime the maximum prime the grid ratios will contain - # @param max_boundary the maximum distance grid ratios will be from the scaled ratio - # @param max_scale the maximum self will be scaled - # - def by_neighborhood(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, max_boundary: DEFAULT_MAX_GRID_BOUNDARY, max_scale: DEFAULT_MAX_GRID_SCALE) - self_in_cents = to_cents - within = cents_tolerance.kind_of?(Tonal::Cents) ? cents_tolerance : Tonal::Cents.new(cents: cents_tolerance) - [].tap do |results| - scale = 1 - boundary = 1 - - while results.length <= depth && scale <= max_scale do - while boundary <= max_boundary - vacinity = ratio.respond_to?(:to_basic_ratio) ? to_basic_ratio.scale(scale) : ratio.scale(scale) - self.class.neighbors(away: boundary, vacinity: vacinity).each do |neighbor| - results << neighbor if ratio.class.within_cents?(self_in_cents, neighbor.to_cents, within) && neighbor.within_prime?(max_prime) - end - boundary += 1 - end - boundary = 1 - scale += 1 - end - end.uniq(&:to_r).reject{|r| r == ratio}.sort - end - - # @return [Array] of bounding ratios in the ratio grid vacinity of antecedent/consequent scaled by scale - # @example - # Tonal::ReducedRatio.new(3,2).neighborhood(scale: 256, boundary: 2) - # => [(768/514), (766/512), (768/513), (767/512), (768/512), (769/512), (768/511), (770/512), (768/510)] - # @param scale [Integer] used to scale antecedent/consequent on coordinate system - # @param boundary [Integer] limit within which to calculate neighboring ratios - # - def neighborhood(scale: 2**0, boundary: 1) - scale = scale.round - vacinity = ratio.respond_to?(:to_basic_ratio) ? to_basic_ratio.scale(scale) : ratio.scale(scale) - SortedSet.new([].tap do |ratio_list| - 1.upto(boundary) do |away| - ratio_list << self.class.neighbors(away: away, vacinity: vacinity) - end - end.flatten).to_a - end - - # @return [Array] an array of Tonal::Ratio neighbors in the scaled ratio's grid neighborhood - # @example - # Tonal::Ratio::Approximations.neighbors(vacinity: (3/2r).ratio(reduced:false).scale(256), away: 1) - # => [(768/513), (767/512), (768/512), (769/512), (768/511)] - # @param away [Integer] the neighbors distance away from self's antecedent and consequent - # - def self.neighbors(vacinity:, away: 1) - [vacinity, - vacinity.class.new(vacinity.antecedent+away, vacinity.consequent), - vacinity.class.new(vacinity.antecedent-away, vacinity.consequent), - vacinity.class.new(vacinity.antecedent, vacinity.consequent+away), - vacinity.class.new(vacinity.antecedent, vacinity.consequent-away), - vacinity.class.new(vacinity.antecedent+away, vacinity.consequent+away), - vacinity.class.new(vacinity.antecedent+away, vacinity.consequent-away), - vacinity.class.new(vacinity.antecedent-away, vacinity.consequent+away), - vacinity.class.new(vacinity.antecedent-away, vacinity.consequent-away)] - end - end -end \ No newline at end of file diff --git a/lib/tonal/attributions.rb b/lib/tonal/attributions.rb new file mode 100644 index 0000000..64c4c32 --- /dev/null +++ b/lib/tonal/attributions.rb @@ -0,0 +1,4 @@ +module Tonal + TOOLS_PRODUCER = "mTonal" + TOOLS_VERSION = "2.0.1" +end diff --git a/lib/tonal/cents.rb b/lib/tonal/cents.rb index 2563674..d3a779c 100644 --- a/lib/tonal/cents.rb +++ b/lib/tonal/cents.rb @@ -9,7 +9,6 @@ class Tonal::Cents CENT_SCALE = 1200.0 TOLERANCE = 5 PRECISION = 2 - DEFAULT_ROUNDING_PRECISION = 2 attr_reader :log, :ratio @@ -100,7 +99,7 @@ def inspect # https://embeddeduse.com/2019/08/26/qt-compare-two-floats/ # def <=>(rhs) - rhs.kind_of?(self.class) ? value.round(2) <=> rhs.value.round(2) : value.round(2) <=> rhs.round(2) + rhs.kind_of?(self.class) ? value.round(PRECISION) <=> rhs.value.round(PRECISION) : value.round(PRECISION) <=> rhs.round(PRECISION) end private diff --git a/lib/tonal/extensions.rb b/lib/tonal/extensions.rb index a875e39..30279f0 100644 --- a/lib/tonal/extensions.rb +++ b/lib/tonal/extensions.rb @@ -324,11 +324,11 @@ def numerators = self.map(&:numerator) def denominators = self.map(&:denominator) alias :consequents :denominators - # @return [Array] an array of normalized ratios + # @return [Array] an array of ratios with equalized denominators # @example - # [4/3r, 3/2r].normalize => [(8/6), (9/6)] + # [4/3r, 3/2r].denominize => [(8/6), (9/6)] # - def normalize + def denominize l = denominators.lcm map{|r| Tonal::Ratio.new(l / r.denominator * r.numerator, l)} end @@ -349,8 +349,9 @@ def mean = self.sum / self.count.to_f # @return [Tonal::ReducedRatio] ratio reconstructed from the result of a prime factor decomposition # @example # [[[3, 1]], [[2, 1]]].ratio_from_prime_divisions => (3/2) + # @reduced [Boolean] if a reduced or unreduced ratio is returned # - def ratio_from_prime_divisions = Tonal::Ratio.new(Prime.int_from_prime_division(self.first), Prime.int_from_prime_division(self.last)) + def ratio_from_prime_divisions(reduced: false) = reduced ? Tonal::ReducedRatio.new(Prime.int_from_prime_division(self.first), Prime.int_from_prime_division(self.last)) : Tonal::Ratio.new(Prime.int_from_prime_division(self.first), Prime.int_from_prime_division(self.last)) # @return [Array] translated by value # @example diff --git a/lib/tonal/interval.rb b/lib/tonal/interval.rb index 30e5132..12b183d 100644 --- a/lib/tonal/interval.rb +++ b/lib/tonal/interval.rb @@ -2,7 +2,7 @@ class Tonal::Interval extend Forwardable include Comparable - def_delegators :@interval, :to_r, :antecedent, :consequent + def_delegators :@interval, :to_r, :antecedent, :consequent, :to_cents attr_reader :lower_ratio, :upper_ratio, :interval @@ -13,6 +13,7 @@ def initialize(upper_ratio, lower_ratio) @upper_ratio = upper_ratio.ratio @interval = @upper_ratio / @lower_ratio end + alias :ratio :interval alias :lower :lower_ratio alias :upper :upper_ratio alias :numerator :antecedent @@ -22,7 +23,7 @@ def to_a [lower_ratio, upper_ratio] end - def normalize + def denominize ratios = to_a lcm = ratios.denominators.lcm ratios.map{|r| Tonal::Ratio.new(lcm / r.denominator * r.numerator, lcm)} diff --git a/lib/tonal/ratio.rb b/lib/tonal/ratio.rb index 201409e..af99713 100644 --- a/lib/tonal/ratio.rb +++ b/lib/tonal/ratio.rb @@ -2,7 +2,7 @@ class Tonal::Ratio extend Forwardable include Comparable - def_delegators :@approximations, :neighborhood + def_delegators :@approximation, :neighborhood attr_reader :antecedent, :consequent, :equave, :reduced_antecedent, :reduced_consequent @@ -27,29 +27,38 @@ def initialize(antecedent, consequent=nil, label: nil, equave: 2/1r) @equave = equave @reduced_antecedent, @reduced_consequent = _equave_reduce(equave) @label = label - @approximations = Approximations.new(ratio: self) + @approximation = Approximation.new(ratio: self) end alias :numerator :antecedent alias :denominator :consequent - # @return [Tonal::Ratio] ratio who's numerator and denominator are 1 apart + # @return [Tonal::Ratio] ratio who's numerator and denominator are seperated by a difference of 1 # @example - # Tonal::Ratio.superparticular(100) = (100/99) - # @param n numerator of ratio + # Tonal::Ratio.superparticular(100) = (101/100) + # @param n [Integer] number from which the superior part is calculated + # @param factor [Rational] multiplied into the resulting ratio, default 1/1 + # @param superpart [Symbol] assigning the superior part to the antecedent or consequent # - def self.superparticular(n) - superpartient(n, 1) + def self.superparticular(n, factor: 1/1r, superpart: :upper) + superpartient(n, summand: 1, factor:, superpart:) end - # @return [Tonal::Ratio] ratio who's numerator and denominator are a partient apart + # @return [Tonal::Ratio] ratio who's numerator and denominator are separated by a summand difference # @example - # Tonal::Ratio.superpartient(100, 5) => (100/95) - # @param n numerator of ratio - # @param part partient separating the numerator and denominator + # Tonal::Ratio.superpartient(23, summand: 3) => (26/23) + # @param n [Integer] number from which the superior part is calculated + # @param summand [Integer] term added to the superior part + # @param factor [Rational] multiplied into the resulting ratio, default 1/1 + # @param superpart [Symbol] assigning the superior part to the antecedent or consequent # - def self.superpartient(n, part) - self.new(n, n-part) + def self.superpartient(n, summand:, factor: 1/1r, superpart: :upper) + case superpart.to_sym.downcase + when :lower, :consequent, :denominator + self.new(n*factor.numerator, (n+summand)*factor.denominator) + else + self.new((n+summand)*factor.numerator, n*factor.denominator) + end end # @return [Tonal::Ratio] a randomly generated ratio @@ -58,7 +67,7 @@ def self.superpartient(n, part) # @param number_of_factors # @param within # - def self.random_ratio(number_of_factors = 2, within: 100) + def self.random_ratio(number_of_factors = 2, within: 100, reduced: false) primes = Prime.each(within).to_a nums = [] dens = [] @@ -66,7 +75,7 @@ def self.random_ratio(number_of_factors = 2, within: 100) nums << [primes[rand(10)], rand(3)] dens << [primes[rand(10)], rand(3)] end - [nums, dens].ratio_from_prime_divisions + [nums, dens].ratio_from_prime_divisions(reduced:) end # @return [Tonal::Ratio] the ratio of step in the modulo @@ -98,10 +107,10 @@ def ratio self end - # @return [Tonal::Ratio::Approximations] self's approximation instance + # @return [Tonal::Ratio::Approximation] self's approximation instance # - def approx - @approximations + def approximate + @approximation end # ================================== @@ -264,15 +273,6 @@ def mirror(axis=1/1r) (self.class.new(axis) ** 2) / self end - # @return [Tonal::Ratio] - # @example - # Tonal::Ratio.new(4/3r).mirror2(4/2r) => (3/8) - # @param ratio - # - def mirror2(ratio) - self.class.new(invert.to_r / ratio) - end - # @return Tonal::ReducedRatio the Ernst Levy negative of self # @example # Tonal::ReducedRatio.new(7/4r).negative => (12/7) @@ -434,7 +434,7 @@ def wilson_height(prime_rejects: [2]) # @param modulo # def efficiency(modulo) - (Tonal::Cents::CENT_SCALE * step(modulo).step / modulo.to_f) - to_cents + ((Tonal::Cents::CENT_SCALE * step(modulo).step / modulo.to_f) - to_cents).round(Tonal::Cents::PRECISION) end # @return [Array] the results of ratio dividing and multiplying self @@ -473,7 +473,7 @@ def label # Return label, if defined; or, # Return the "antecedent/consequent", if antecedent is less than 7 digits long; or # Return the floating point representation rounded to 2 digits of precision - (@label || ((Math.log10(antecedent).to_i + 1) <= 6 ? "#{antecedent}/#{consequent}" : to_f.round(2))).to_s + (@label || ((Math.log10(antecedent).to_i + 1) <= 6 ? "#{antecedent}/#{consequent}" : to_f.round(Tonal::Cents::PRECISION))).to_s end # @return [String] the string representation of Tonal::Ratio diff --git a/lib/tonal/tools.rb b/lib/tonal/tools.rb index f799db4..d44e375 100644 --- a/lib/tonal/tools.rb +++ b/lib/tonal/tools.rb @@ -11,7 +11,7 @@ module Tonal require "tonal/hertz" require "tonal/log" require "tonal/log2" - require "tonal/approximations" + require "tonal/approximation" require "tonal/ratio" require "tonal/reduced_ratio" require "tonal/interval" diff --git a/spec/tonal_tools/approximations_spec.rb b/spec/tonal_tools/approximation_spec.rb similarity index 59% rename from spec/tonal_tools/approximations_spec.rb rename to spec/tonal_tools/approximation_spec.rb index 6f0f584..0cc4bf5 100644 --- a/spec/tonal_tools/approximations_spec.rb +++ b/spec/tonal_tools/approximation_spec.rb @@ -1,8 +1,6 @@ require "spec_helper" -RSpec.describe Tonal::Ratio::Approximations do - let(:ratio) { Tonal::Ratio.new(3/2r) } - +RSpec.describe Tonal::Ratio::Approximation do describe "class methods" do describe ".new" do it "requires a ratio" do @@ -15,13 +13,17 @@ end describe ".neighbors" do - it "returns the neighbors distance away from self's antecedent and consequent" do + let(:ratio) { Tonal::Ratio.new(3/2r) } + + it "returns the neighbors distance away from ratio's antecedent and consequent" do expect(described_class.neighbors(vacinity: ratio, away: 2)).to eq [Tonal::Ratio.new(3,2), Tonal::Ratio.new(5,2), Tonal::Ratio.new(1,2), Tonal::Ratio.new(3,4), Tonal::Ratio.new(3,0), Tonal::Ratio.new(5,4), Tonal::Ratio.new(5,0), Tonal::Ratio.new(1,4), Tonal::Ratio.new(1,0)] end end end describe "instance methods" do + let(:ratio) { Tonal::Ratio.new(3/2r) } + subject { described_class.new(ratio: ratio) } describe "#neighborhood" do @@ -35,15 +37,15 @@ context "with defaults" do it "returns ratios up to the default depth" do - expect(ratio.approx.by_continued_fraction.length).to be <= Tonal::Ratio::Approximations::CONVERGENT_LIMIT + expect(ratio.approximate.by_continued_fraction.length).to be <= Tonal::Ratio::Approximation::CONVERGENT_LIMIT end it "returns ratios that are within 5 cents of self" do - expect(ratio.approx.by_continued_fraction.all?{|r| r.cent_diff(ratio) <= Tonal::Cents::TOLERANCE}).to be true + expect(ratio.approximate.by_continued_fraction.all?{|r| r.cent_diff(ratio) <= Tonal::Cents::TOLERANCE}).to be true end it "returns ratios with maximum primes limited only by the depth of the search" do - expect(ratio.approx.by_continued_fraction.all?{|r| r.max_prime <= 2549 }).to be true + expect(ratio.approximate.by_continued_fraction.all?{|r| r.max_prime <= 2549 }).to be true end end end @@ -53,7 +55,7 @@ let(:max_prime) { 89 } it "returns ratios with max prime" do - expect(ratio.approx.by_quotient_walk(max_prime: max_prime)).to eq [(18/17r), (196/185r), (89/84r), (71/67r), (53/50r), (35/33r), (17/16r)] + expect(ratio.approximate.by_quotient_walk(max_prime: max_prime).entries).to eq [(18/17r), (196/185r), (89/84r), (71/67r), (53/50r), (35/33r), (17/16r)] end end @@ -62,7 +64,22 @@ let(:depth) { 10 } it "returns 10 ratios" do - expect(ratio.approx.by_tree_path(depth: depth).count).to eq 10 + expect(ratio.approximate.by_tree_path(depth: depth).count).to eq depth + end + end + + describe "#by_superparticular" do + let(:ratio) { Tonal::Ratio.new(3/2r)} + let(:depth) { 5 } + + it "returns approximations by descending superparticulars factored by ratio" do + expect(ratio.approximate.by_superparticular(depth: depth).entries).to eq [(351/350r), (350/349r), (349/348r), (348/347r), (347/346r)].map{|r| r * 3/2r} + end + + context "when the superpart is the denomimator" do + it "returns approximations by ascending superparticulars factored by ratio" do + expect(ratio.approximate.by_superparticular(superpart: :lower, depth: depth).entries).to eq [(346/347r), (347/348r), (348/349r), (349/350r), (350/351r)].map{|r| r * 3/2r} + end end end @@ -74,11 +91,11 @@ let(:max_prime) { 23 } let(:max_boundary) { 10 } let(:max_scale) { 60 } - let(:ratios) { ratio.approx.by_neighborhood(max_prime: max_prime, max_boundary: max_boundary, max_scale: max_scale) } + let(:ratios) { ratio.approximate.by_neighborhood(max_prime: max_prime, max_boundary: max_boundary, max_scale: max_scale) } let(:ratio_in_cents) { ratio.to_cents } it "returns a set of ratios within 5¢ of ratio and with max prime of 23" do - expect(ratios).to eq [(175/117r), (176/117r)] + expect(ratios.entries).to eq [(175/117r), (176/117r)] expect(ratios.all?{|r| Tonal::Ratio.within_cents?(r.to_cents, ratio_in_cents, cents_tolerance)}).to be true expect(ratios.all?{|r| r.within_prime?(max_prime) }).to be true end @@ -86,3 +103,7 @@ end end end + +RSpec.describe Tonal::Ratio::Approximation::Set do + +end \ No newline at end of file diff --git a/spec/tonal_tools/extensions_spec.rb b/spec/tonal_tools/extensions_spec.rb index 7215743..c843e00 100644 --- a/spec/tonal_tools/extensions_spec.rb +++ b/spec/tonal_tools/extensions_spec.rb @@ -262,9 +262,9 @@ end end - describe "#normalize" do - it "returns an array of normalized ratios" do - expect([4/3r, 3/2r].normalize).to eq [Tonal::Ratio.new(8,6), Tonal::Ratio.new(9,6)] + describe "#denominize" do + it "returns an array of ratios with equalized denominators" do + expect([4/3r, 3/2r].denominize).to eq [Tonal::Ratio.new(8,6), Tonal::Ratio.new(9,6)] end end diff --git a/spec/tonal_tools/interval_spec.rb b/spec/tonal_tools/interval_spec.rb index d6f4faa..adb35b1 100644 --- a/spec/tonal_tools/interval_spec.rb +++ b/spec/tonal_tools/interval_spec.rb @@ -55,12 +55,22 @@ end end - describe "#normalize" do + describe "#denominize" do let(:lower_ratio) { 3/2r } let(:upper_ratio) { 7/4r } - it "returns the interval endpoints normalized to their lcm" do - expect(described_class.new(lower_ratio, upper_ratio).normalize).to eq [7/4r, 6/4r] + it "returns the interval endpoints with their denominators equalized" do + expect(described_class.new(lower_ratio, upper_ratio).denominize).to eq [7/4r, 6/4r] + end + end + + describe "#ratio" do + let(:lower_ratio) { 3/2r } + let(:upper_ratio) { 7/4r } + + it "returns the interval as a Tonal::ReducedRatio" do + expect(described_class.new(lower_ratio, upper_ratio).ratio).to be_a_kind_of(Tonal::ReducedRatio) + expect(described_class.new(lower_ratio, upper_ratio).ratio).to eq 12/7r end end diff --git a/spec/tonal_tools/ratio_spec.rb b/spec/tonal_tools/ratio_spec.rb index 5988677..1b73c8d 100644 --- a/spec/tonal_tools/ratio_spec.rb +++ b/spec/tonal_tools/ratio_spec.rb @@ -59,7 +59,7 @@ let(:n) { rand(100)+1 } it "returns a ratio who's numerator and denominator are one apart" do - expect(described_class.superparticular(n)).to eq described_class.new(n, n-1) + expect(described_class.superparticular(n)).to eq described_class.new(n+1, n) end end @@ -68,12 +68,16 @@ let(:partient) { rand(10) } it "returns a ratio who's numerator and denominator are a partient apart" do - expect(described_class.superpartient(n, partient)).to eq described_class.new(n, n-partient) + expect(described_class.superpartient(n, summand: partient)).to eq described_class.new(n+partient, n) end end describe ".random_ratio" do it { expect(described_class.random_ratio).to be_a_kind_of(Tonal::Ratio) } + + context "when reduced is true" do + it { expect(described_class.random_ratio(reduced: true)).to be_a_kind_of(Tonal::ReducedRatio) } + end end describe ".ed" do @@ -354,7 +358,7 @@ describe "#efficiency" do it "returns the difference between self and its step for a given modulo" do - expect(subject.efficiency(12)).to eq -1.9600000000000364 + expect(subject.efficiency(12)).to eq -1.96 end end diff --git a/tonal-tools.gemspec b/tonal-tools.gemspec index e703f3a..79a16be 100644 --- a/tonal-tools.gemspec +++ b/tonal-tools.gemspec @@ -1,8 +1,9 @@ require "date" +require_relative "lib/tonal/attributions" Gem::Specification.new do |spec| spec.name = "tonal-tools" - spec.version = "1.3.1" + spec.version = Tonal::TOOLS_VERSION spec.summary = "Tonal tools" spec.description = "Basic tools, utilities and conveniences for microtonal music making and analysis" spec.authors = ["Jose Hales-Garcia"]
    -
    -
    -
     272
     273
     274
    @@ -4360,8 +4345,8 @@

    # File 'lib/tonal/ratio.rb', line 272
     
    -def mirror2(ratio)
    -  self.class.new(invert.to_r / ratio)
    +def mirror(axis=1/1r)
    +  (self.class.new(axis) ** 2) / self
     end
    -
    # 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 @@ 

    diff --git a/docs/Tonal/Ratio/Approximations.html b/docs/Tonal/Ratio/Approximation.html similarity index 65% rename from docs/Tonal/Ratio/Approximations.html rename to docs/Tonal/Ratio/Approximation.html index 2f1e62b..c82252f 100644 --- a/docs/Tonal/Ratio/Approximations.html +++ b/docs/Tonal/Ratio/Approximation.html @@ -4,7 +4,7 @@ - Class: Tonal::Ratio::Approximations + Class: Tonal::Ratio::Approximation — Documentation by YARD 0.9.34 @@ -15,7 +15,7 @@ <link rel="stylesheet" href="../../css/common.css" type="text/css" /> <script type="text/javascript"> - pathId = "Tonal::Ratio::Approximations"; + pathId = "Tonal::Ratio::Approximation"; relpath = '../../'; </script> @@ -39,7 +39,7 @@ <a href="../../_index.html">Index (A)</a> » <span class='title'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span> » <span class='title'><span class='object_link'><a href="../Ratio.html" title="Tonal::Ratio (class)">Ratio</a></span></span> » - <span class="title">Approximations</span> + <span class="title">Approximation</span> </div> @@ -59,7 +59,7 @@ <div class="clear"></div> </div> - <div id="content"><h1>Class: Tonal::Ratio::Approximations + <div id="content"><h1>Class: Tonal::Ratio::Approximation @@ -74,7 +74,7 @@ <ul class="fullTree"> <li>Object</li> - <li class="next">Tonal::Ratio::Approximations</li> + <li class="next">Tonal::Ratio::Approximation</li> </ul> <a href="#" class="inheritanceTree">show all</a> @@ -99,11 +99,21 @@ <dl> <dt>Defined in:</dt> - <dd>lib/tonal/approximations.rb</dd> + <dd>lib/tonal/approximation.rb</dd> </dl> </div> +<h2>Defined Under Namespace</h2> +<p class="children"> + + + + + <strong class="classes">Classes:</strong> <span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Set</a></span> + + +</p> <h2> @@ -230,7 +240,7 @@ <h2> <li class="public "> <span class="summary_signature"> - <a href="#by_continued_fraction-instance_method" title="#by_continued_fraction (instance method)">#<strong>by_continued_fraction</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ Array </a> + <a href="#by_continued_fraction-instance_method" title="#by_continued_fraction (instance method)">#<strong>by_continued_fraction</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ Tonal::Ratio::Approximation::Set </a> @@ -278,7 +288,7 @@ <h2> <li class="public "> <span class="summary_signature"> - <a href="#by_quotient_walk-instance_method" title="#by_quotient_walk (instance method)">#<strong>by_quotient_walk</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ Array </a> + <a href="#by_quotient_walk-instance_method" title="#by_quotient_walk (instance method)">#<strong>by_quotient_walk</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ Tonal::Ratio::Approximation::Set </a> @@ -302,7 +312,31 @@ <h2> <li class="public "> <span class="summary_signature"> - <a href="#by_tree_path-instance_method" title="#by_tree_path (instance method)">#<strong>by_tree_path</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME) ⇒ Array </a> + <a href="#by_superparticular-instance_method" title="#by_superparticular (instance method)">#<strong>by_superparticular</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: 20, max_prime: DEFAULT_MAX_PRIME, superpart: :upper) ⇒ Tonal::Ratio::Approximation::Set </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Of superparticular approximations within cent tolerance of self.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#by_tree_path-instance_method" title="#by_tree_path (instance method)">#<strong>by_tree_path</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME) ⇒ Tonal::Ratio::Approximation::Set </a> @@ -326,7 +360,7 @@ <h2> <li class="public "> <span class="summary_signature"> - <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(ratio:) ⇒ Approximations </a> + <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(ratio:) ⇒ Approximation </a> @@ -343,7 +377,7 @@ <h2> <span class="summary_desc"><div class='inline'> -<p>A new instance of Approximations.</p> +<p>A new instance of Approximation.</p> </div></span> </li> @@ -383,7 +417,7 @@ <h2>Constructor Details</h2> <div class="method_details first"> <h3 class="signature first" id="initialize-instance_method"> - #<strong>initialize</strong>(ratio:) ⇒ <tt><span class='object_link'><a href="" title="Tonal::Ratio::Approximations (class)">Approximations</a></span></tt> + #<strong>initialize</strong>(ratio:) ⇒ <tt><span class='object_link'><a href="" title="Tonal::Ratio::Approximation (class)">Approximation</a></span></tt> @@ -392,7 +426,7 @@ <h3 class="signature first" id="initialize-instance_method"> </h3><div class="docstring"> <div class="discussion"> -<p>Returns a new instance of Approximations.</p> +<p>Returns a new instance of Approximation.</p> </div> @@ -425,7 +459,7 @@ <h3 class="signature first" id="initialize-instance_method"> 18</pre> </td> <td> - <pre class="code"><span class="info file"># File 'lib/tonal/approximations.rb', line 15</span> + <pre class="code"><span class="info file"># File 'lib/tonal/approximation.rb', line 15</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>ratio:</span><span class='rparen'>)</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Tonal::Ratio required</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Ratio.html" title="Tonal::Ratio (class)">Ratio</a></span></span><span class='rparen'>)</span> @@ -474,7 +508,7 @@ <h3 class="signature first" id="ratio-instance_method"> 15</pre> </td> <td> - <pre class="code"><span class="info file"># File 'lib/tonal/approximations.rb', line 13</span> + <pre class="code"><span class="info file"># File 'lib/tonal/approximation.rb', line 13</span> <span class='kw'>def</span> <span class='id identifier rubyid_ratio'>ratio</span> <span class='ivar'>@ratio</span> @@ -514,7 +548,7 @@ <h3 class="signature first" id="neighbors-class_method"> <p class="tag_title">Examples:</p> - <pre class="example code"><code>Tonal::Ratio::Approximations.neighbors(vacinity: (3/2r).ratio(reduced:false).scale(256), away: 1) + <pre class="example code"><code>Tonal::Ratio::Approximation.neighbors(vacinity: (3/2r).ratio(reduced:false).scale(256), away: 1) => [(768/513), (767/512), (768/512), (769/512), (768/511)]</code></pre> </div> @@ -566,20 +600,20 @@ <h3 class="signature first" id="neighbors-class_method"> <pre class="lines"> -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146</pre> +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170</pre> </td> <td> - <pre class="code"><span class="info file"># File 'lib/tonal/approximations.rb', line 136</span> + <pre class="code"><span class="info file"># File 'lib/tonal/approximation.rb', line 160</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_neighbors'>neighbors</span><span class='lparen'>(</span><span class='label'>vacinity:</span><span class='comma'>,</span> <span class='label'>away:</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='lbracket'>[</span><span class='id identifier rubyid_vacinity'>vacinity</span><span class='comma'>,</span> @@ -606,7 +640,7 @@ <h2>Instance Method Details</h2> <div class="method_details first"> <h3 class="signature first" id="by_continued_fraction-instance_method"> - #<strong>by_continued_fraction</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ <tt><span class='object_link'><a href="../../Array.html" title="Array (class)">Array</a></span></tt> + #<strong>by_continued_fraction</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ <tt><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Tonal::Ratio::Approximation::Set</a></span></tt> @@ -626,8 +660,8 @@ <h3 class="signature first" id="by_continued_fraction-instance_method"> <p class="tag_title">Examples:</p> - <pre class="example code"><code>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)]</code></pre> + <pre class="example code"><code>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)]</code></pre> </div> <p class="tag_title">Parameters:</p> @@ -644,6 +678,11 @@ <h3 class="signature first" id="by_continued_fraction-instance_method"> <em class="default">(defaults to: <tt>Tonal::Cents::TOLERANCE</tt>)</em> + — + <div class='inline'> +<p>the cents tolerance used to scope the collection</p> +</div> + </li> <li> @@ -657,6 +696,11 @@ <h3 class="signature first" id="by_continued_fraction-instance_method"> <em class="default">(defaults to: <tt>DEFAULT_DEPTH</tt>)</em> + — + <div class='inline'> +<p>the maximum number of ratios in the collection</p> +</div> + </li> <li> @@ -670,6 +714,11 @@ <h3 class="signature first" id="by_continued_fraction-instance_method"> <em class="default">(defaults to: <tt>DEFAULT_MAX_PRIME</tt>)</em> + — + <div class='inline'> +<p>the maximum prime number to allow in the collection</p> +</div> + </li> <li> @@ -683,6 +732,11 @@ <h3 class="signature first" id="by_continued_fraction-instance_method"> <em class="default">(defaults to: <tt>CONVERGENT_LIMIT</tt>)</em> + — + <div class='inline'> +<p>the number of convergents to limit the ContinuedFraction method</p> +</div> + </li> </ul> @@ -693,7 +747,7 @@ <h3 class="signature first" id="by_continued_fraction-instance_method"> <li> - <span class='type'>(<tt><span class='object_link'><a href="../../Array.html" title="Array (class)">Array</a></span></tt>)</span> + <span class='type'>(<tt><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Tonal::Ratio::Approximation::Set</a></span></tt>)</span> @@ -725,18 +779,18 @@ <h3 class="signature first" id="by_continued_fraction-instance_method"> 39</pre> </td> <td> - <pre class="code"><span class="info file"># File 'lib/tonal/approximations.rb', line 29</span> + <pre class="code"><span class="info file"># File 'lib/tonal/approximation.rb', line 29</span> -<span class='kw'>def</span> <span class='id identifier rubyid_by_continued_fraction'>by_continued_fraction</span><span class='lparen'>(</span><span class='label'>cents_tolerance:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html#TOLERANCE-constant" title="Tonal::Cents::TOLERANCE (constant)">TOLERANCE</a></span></span><span class='comma'>,</span> <span class='label'>depth:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_DEPTH-constant" title="Tonal::Ratio::Approximations::DEFAULT_DEPTH (constant)">DEFAULT_DEPTH</a></span></span><span class='comma'>,</span> <span class='label'>max_prime:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_PRIME-constant" title="Tonal::Ratio::Approximations::DEFAULT_MAX_PRIME (constant)">DEFAULT_MAX_PRIME</a></span></span><span class='comma'>,</span> <span class='label'>conv_limit:</span> <span class='const'><span class='object_link'><a href="#CONVERGENT_LIMIT-constant" title="Tonal::Ratio::Approximations::CONVERGENT_LIMIT (constant)">CONVERGENT_LIMIT</a></span></span><span class='rparen'>)</span> +<span class='kw'>def</span> <span class='id identifier rubyid_by_continued_fraction'>by_continued_fraction</span><span class='lparen'>(</span><span class='label'>cents_tolerance:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html#TOLERANCE-constant" title="Tonal::Cents::TOLERANCE (constant)">TOLERANCE</a></span></span><span class='comma'>,</span> <span class='label'>depth:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_DEPTH-constant" title="Tonal::Ratio::Approximation::DEFAULT_DEPTH (constant)">DEFAULT_DEPTH</a></span></span><span class='comma'>,</span> <span class='label'>max_prime:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_PRIME-constant" title="Tonal::Ratio::Approximation::DEFAULT_MAX_PRIME (constant)">DEFAULT_MAX_PRIME</a></span></span><span class='comma'>,</span> <span class='label'>conv_limit:</span> <span class='const'><span class='object_link'><a href="#CONVERGENT_LIMIT-constant" title="Tonal::Ratio::Approximation::CONVERGENT_LIMIT (constant)">CONVERGENT_LIMIT</a></span></span><span class='rparen'>)</span> <span class='id identifier rubyid_self_in_cents'>self_in_cents</span> <span class='op'>=</span> <span class='id identifier rubyid_to_cents'>to_cents</span> <span class='id identifier rubyid_within'>within</span> <span class='op'>=</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span> <span class='op'>:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="../Cents.html#initialize-instance_method" title="Tonal::Cents#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>cents:</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='rparen'>)</span> - <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_results'>results</span><span class='op'>|</span> + <span class='const'><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Set</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Approximation/Set.html#initialize-instance_method" title="Tonal::Ratio::Approximation::Set#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>ratio:</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_set'>set</span><span class='op'>|</span> <span class='const'>ContinuedFraction</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_antecedent'>antecedent</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span><span class='op'>/</span><span class='id identifier rubyid_consequent'>consequent</span><span class='comma'>,</span> <span class='id identifier rubyid_conv_limit'>conv_limit</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_convergents'>convergents</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_convergent'>convergent</span><span class='op'>|</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='op'>=</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_convergent'>convergent</span><span class='period'>.</span><span class='id identifier rubyid_numerator'>numerator</span><span class='comma'>,</span><span class='id identifier rubyid_convergent'>convergent</span><span class='period'>.</span><span class='id identifier rubyid_denominator'>denominator</span><span class='rparen'>)</span> - <span class='id identifier rubyid_results'>results</span> <span class='op'><<</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='kw'>if</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_within_cents?'>within_cents?</span><span class='lparen'>(</span><span class='id identifier rubyid_self_in_cents'>self_in_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_to_cents'>to_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_within'>within</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_within_prime?'>within_prime?</span><span class='lparen'>(</span><span class='id identifier rubyid_max_prime'>max_prime</span><span class='rparen'>)</span> - <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_results'>results</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>>=</span> <span class='id identifier rubyid_depth'>depth</span> + <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_ratios'>ratios</span> <span class='op'><<</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='kw'>if</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_within_cents?'>within_cents?</span><span class='lparen'>(</span><span class='id identifier rubyid_self_in_cents'>self_in_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_to_cents'>to_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_within'>within</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_within_prime?'>within_prime?</span><span class='lparen'>(</span><span class='id identifier rubyid_max_prime'>max_prime</span><span class='rparen'>)</span> + <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>>=</span> <span class='id identifier rubyid_depth'>depth</span> <span class='kw'>end</span> - <span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_sort'>sort</span> + <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> @@ -766,8 +820,8 @@ <h3 class="signature " id="by_neighborhood-instance_method"> <p class="tag_title">Examples:</p> - <pre class="example code"><code>Tonal::Ratio.new(3,2).by_neighborhood(max_prime: 23, cents_tolerance: 5, max_boundary: 10, max_scale: 60) -=> [(175/117), (176/117)]</code></pre> + <pre class="example code"><code>Tonal::Ratio.new(3,2).approximate.by_neighborhood(max_prime: 23, cents_tolerance: 5, max_boundary: 10, max_scale: 60) +=> (3/2): [(175/117), (176/117)]</code></pre> </div> <p class="tag_title">Parameters:</p> @@ -786,7 +840,7 @@ <h3 class="signature " id="by_neighborhood-instance_method"> — <div class='inline'> -<p>the maximum cents self is allowed from grid ratios</p> +<p>the cents tolerance used to scope the collection</p> </div> </li> @@ -804,7 +858,7 @@ <h3 class="signature " id="by_neighborhood-instance_method"> — <div class='inline'> -<p>the maximum depth the array will get</p> +<p>the maximum number of ratios in the collection</p> </div> </li> @@ -822,7 +876,7 @@ <h3 class="signature " id="by_neighborhood-instance_method"> — <div class='inline'> -<p>the maximum prime the grid ratios will contain</p> +<p>the maximum prime number to allow in the collection</p> </div> </li> @@ -890,49 +944,49 @@ <h3 class="signature " id="by_neighborhood-instance_method"> <pre class="lines"> -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111</pre> +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135</pre> </td> <td> - <pre class="code"><span class="info file"># File 'lib/tonal/approximations.rb', line 92</span> + <pre class="code"><span class="info file"># File 'lib/tonal/approximation.rb', line 116</span> -<span class='kw'>def</span> <span class='id identifier rubyid_by_neighborhood'>by_neighborhood</span><span class='lparen'>(</span><span class='label'>cents_tolerance:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html#TOLERANCE-constant" title="Tonal::Cents::TOLERANCE (constant)">TOLERANCE</a></span></span><span class='comma'>,</span> <span class='label'>depth:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_DEPTH-constant" title="Tonal::Ratio::Approximations::DEFAULT_DEPTH (constant)">DEFAULT_DEPTH</a></span></span><span class='comma'>,</span> <span class='label'>max_prime:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_PRIME-constant" title="Tonal::Ratio::Approximations::DEFAULT_MAX_PRIME (constant)">DEFAULT_MAX_PRIME</a></span></span><span class='comma'>,</span> <span class='label'>max_boundary:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_GRID_BOUNDARY-constant" title="Tonal::Ratio::Approximations::DEFAULT_MAX_GRID_BOUNDARY (constant)">DEFAULT_MAX_GRID_BOUNDARY</a></span></span><span class='comma'>,</span> <span class='label'>max_scale:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_GRID_SCALE-constant" title="Tonal::Ratio::Approximations::DEFAULT_MAX_GRID_SCALE (constant)">DEFAULT_MAX_GRID_SCALE</a></span></span><span class='rparen'>)</span> +<span class='kw'>def</span> <span class='id identifier rubyid_by_neighborhood'>by_neighborhood</span><span class='lparen'>(</span><span class='label'>cents_tolerance:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html#TOLERANCE-constant" title="Tonal::Cents::TOLERANCE (constant)">TOLERANCE</a></span></span><span class='comma'>,</span> <span class='label'>depth:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_DEPTH-constant" title="Tonal::Ratio::Approximation::DEFAULT_DEPTH (constant)">DEFAULT_DEPTH</a></span></span><span class='comma'>,</span> <span class='label'>max_prime:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_PRIME-constant" title="Tonal::Ratio::Approximation::DEFAULT_MAX_PRIME (constant)">DEFAULT_MAX_PRIME</a></span></span><span class='comma'>,</span> <span class='label'>max_boundary:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_GRID_BOUNDARY-constant" title="Tonal::Ratio::Approximation::DEFAULT_MAX_GRID_BOUNDARY (constant)">DEFAULT_MAX_GRID_BOUNDARY</a></span></span><span class='comma'>,</span> <span class='label'>max_scale:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_GRID_SCALE-constant" title="Tonal::Ratio::Approximation::DEFAULT_MAX_GRID_SCALE (constant)">DEFAULT_MAX_GRID_SCALE</a></span></span><span class='rparen'>)</span> <span class='id identifier rubyid_self_in_cents'>self_in_cents</span> <span class='op'>=</span> <span class='id identifier rubyid_to_cents'>to_cents</span> <span class='id identifier rubyid_within'>within</span> <span class='op'>=</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span> <span class='op'>:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="../Cents.html#initialize-instance_method" title="Tonal::Cents#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>cents:</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='rparen'>)</span> - <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_results'>results</span><span class='op'>|</span> + <span class='const'><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Set</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Approximation/Set.html#initialize-instance_method" title="Tonal::Ratio::Approximation::Set#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>ratio:</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_set'>set</span><span class='op'>|</span> <span class='id identifier rubyid_scale'>scale</span> <span class='op'>=</span> <span class='int'>1</span> <span class='id identifier rubyid_boundary'>boundary</span> <span class='op'>=</span> <span class='int'>1</span> - <span class='kw'>while</span> <span class='id identifier rubyid_results'>results</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'><=</span> <span class='id identifier rubyid_depth'>depth</span> <span class='op'>&&</span> <span class='id identifier rubyid_scale'>scale</span> <span class='op'><=</span> <span class='id identifier rubyid_max_scale'>max_scale</span> <span class='kw'>do</span> + <span class='kw'>while</span> <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'><=</span> <span class='id identifier rubyid_depth'>depth</span> <span class='op'>&&</span> <span class='id identifier rubyid_scale'>scale</span> <span class='op'><=</span> <span class='id identifier rubyid_max_scale'>max_scale</span> <span class='kw'>do</span> <span class='kw'>while</span> <span class='id identifier rubyid_boundary'>boundary</span> <span class='op'><=</span> <span class='id identifier rubyid_max_boundary'>max_boundary</span> <span class='id identifier rubyid_vacinity'>vacinity</span> <span class='op'>=</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:to_basic_ratio</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_to_basic_ratio'>to_basic_ratio</span><span class='period'>.</span><span class='id identifier rubyid_scale'>scale</span><span class='lparen'>(</span><span class='id identifier rubyid_scale'>scale</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_scale'>scale</span><span class='lparen'>(</span><span class='id identifier rubyid_scale'>scale</span><span class='rparen'>)</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_neighbors'>neighbors</span><span class='lparen'>(</span><span class='label'>away:</span> <span class='id identifier rubyid_boundary'>boundary</span><span class='comma'>,</span> <span class='label'>vacinity:</span> <span class='id identifier rubyid_vacinity'>vacinity</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_neighbor'>neighbor</span><span class='op'>|</span> - <span class='id identifier rubyid_results'>results</span> <span class='op'><<</span> <span class='id identifier rubyid_neighbor'>neighbor</span> <span class='kw'>if</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_within_cents?'>within_cents?</span><span class='lparen'>(</span><span class='id identifier rubyid_self_in_cents'>self_in_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_neighbor'>neighbor</span><span class='period'>.</span><span class='id identifier rubyid_to_cents'>to_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_within'>within</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_neighbor'>neighbor</span><span class='period'>.</span><span class='id identifier rubyid_within_prime?'>within_prime?</span><span class='lparen'>(</span><span class='id identifier rubyid_max_prime'>max_prime</span><span class='rparen'>)</span> + <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_ratios'>ratios</span> <span class='op'><<</span> <span class='id identifier rubyid_neighbor'>neighbor</span> <span class='kw'>if</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_within_cents?'>within_cents?</span><span class='lparen'>(</span><span class='id identifier rubyid_self_in_cents'>self_in_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_neighbor'>neighbor</span><span class='period'>.</span><span class='id identifier rubyid_to_cents'>to_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_within'>within</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_neighbor'>neighbor</span><span class='period'>.</span><span class='id identifier rubyid_within_prime?'>within_prime?</span><span class='lparen'>(</span><span class='id identifier rubyid_max_prime'>max_prime</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_neighbor'>neighbor</span> <span class='op'>!=</span> <span class='id identifier rubyid_ratio'>ratio</span> <span class='kw'>end</span> <span class='id identifier rubyid_boundary'>boundary</span> <span class='op'>+=</span> <span class='int'>1</span> <span class='kw'>end</span> <span class='id identifier rubyid_boundary'>boundary</span> <span class='op'>=</span> <span class='int'>1</span> <span class='id identifier rubyid_scale'>scale</span> <span class='op'>+=</span> <span class='int'>1</span> <span class='kw'>end</span> - <span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:to_r</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_reject'>reject</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_r'>r</span><span class='op'>|</span> <span class='id identifier rubyid_r'>r</span> <span class='op'>==</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_sort'>sort</span> + <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> @@ -942,7 +996,7 @@ <h3 class="signature " id="by_neighborhood-instance_method"> <div class="method_details "> <h3 class="signature " id="by_quotient_walk-instance_method"> - #<strong>by_quotient_walk</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ <tt><span class='object_link'><a href="../../Array.html" title="Array (class)">Array</a></span></tt> + #<strong>by_quotient_walk</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME, conv_limit: CONVERGENT_LIMIT) ⇒ <tt><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Tonal::Ratio::Approximation::Set</a></span></tt> @@ -962,8 +1016,8 @@ <h3 class="signature " id="by_quotient_walk-instance_method"> <p class="tag_title">Examples:</p> - <pre class="example code"><code>Tonal::Ratio.ed(12,1).by_quotient_walk(max_prime: 89) -=> [(18/17), (196/185), (89/84), (71/67), (53/50), (35/33), (17/16)]</code></pre> + <pre class="example code"><code>Tonal::Ratio.ed(12,1).approximate.by_quotient_walk(max_prime: 89) +=> (4771397596969315/4503599627370496): [(18/17), (196/185), (89/84), (71/67), (53/50), (35/33), (17/16)]</code></pre> </div> <p class="tag_title">Parameters:</p> @@ -980,6 +1034,11 @@ <h3 class="signature " id="by_quotient_walk-instance_method"> <em class="default">(defaults to: <tt>Tonal::Cents::TOLERANCE</tt>)</em> + — + <div class='inline'> +<p>the cents tolerance used to scope the collection</p> +</div> + </li> <li> @@ -993,6 +1052,11 @@ <h3 class="signature " id="by_quotient_walk-instance_method"> <em class="default">(defaults to: <tt>DEFAULT_DEPTH</tt>)</em> + — + <div class='inline'> +<p>the maximum number of ratios in the collection</p> +</div> + </li> <li> @@ -1006,6 +1070,29 @@ <h3 class="signature " id="by_quotient_walk-instance_method"> <em class="default">(defaults to: <tt>DEFAULT_MAX_PRIME</tt>)</em> + — + <div class='inline'> +<p>the maximum prime number to allow in the collection</p> +</div> + + </li> + + <li> + + <span class='name'>conv_limit</span> + + + <span class='type'></span> + + + <em class="default">(defaults to: <tt>CONVERGENT_LIMIT</tt>)</em> + + + — + <div class='inline'> +<p>the number of convergents to limit the ContinuedFraction method</p> +</div> + </li> </ul> @@ -1016,7 +1103,7 @@ <h3 class="signature " id="by_quotient_walk-instance_method"> <li> - <span class='type'>(<tt><span class='object_link'><a href="../../Array.html" title="Array (class)">Array</a></span></tt>)</span> + <span class='type'>(<tt><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Tonal::Ratio::Approximation::Set</a></span></tt>)</span> @@ -1035,7 +1122,6 @@ <h3 class="signature " id="by_quotient_walk-instance_method"> <pre class="lines"> -49 50 51 52 @@ -1046,22 +1132,187 @@ <h3 class="signature " id="by_quotient_walk-instance_method"> 57 58 59 -60</pre> +60 +61</pre> </td> <td> - <pre class="code"><span class="info file"># File 'lib/tonal/approximations.rb', line 49</span> + <pre class="code"><span class="info file"># File 'lib/tonal/approximation.rb', line 50</span> -<span class='kw'>def</span> <span class='id identifier rubyid_by_quotient_walk'>by_quotient_walk</span><span class='lparen'>(</span><span class='label'>cents_tolerance:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html#TOLERANCE-constant" title="Tonal::Cents::TOLERANCE (constant)">TOLERANCE</a></span></span><span class='comma'>,</span> <span class='label'>depth:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_DEPTH-constant" title="Tonal::Ratio::Approximations::DEFAULT_DEPTH (constant)">DEFAULT_DEPTH</a></span></span><span class='comma'>,</span> <span class='label'>max_prime:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_PRIME-constant" title="Tonal::Ratio::Approximations::DEFAULT_MAX_PRIME (constant)">DEFAULT_MAX_PRIME</a></span></span><span class='comma'>,</span> <span class='label'>conv_limit:</span> <span class='const'><span class='object_link'><a href="#CONVERGENT_LIMIT-constant" title="Tonal::Ratio::Approximations::CONVERGENT_LIMIT (constant)">CONVERGENT_LIMIT</a></span></span><span class='rparen'>)</span> +<span class='kw'>def</span> <span class='id identifier rubyid_by_quotient_walk'>by_quotient_walk</span><span class='lparen'>(</span><span class='label'>cents_tolerance:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html#TOLERANCE-constant" title="Tonal::Cents::TOLERANCE (constant)">TOLERANCE</a></span></span><span class='comma'>,</span> <span class='label'>depth:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_DEPTH-constant" title="Tonal::Ratio::Approximation::DEFAULT_DEPTH (constant)">DEFAULT_DEPTH</a></span></span><span class='comma'>,</span> <span class='label'>max_prime:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_PRIME-constant" title="Tonal::Ratio::Approximation::DEFAULT_MAX_PRIME (constant)">DEFAULT_MAX_PRIME</a></span></span><span class='comma'>,</span> <span class='label'>conv_limit:</span> <span class='const'><span class='object_link'><a href="#CONVERGENT_LIMIT-constant" title="Tonal::Ratio::Approximation::CONVERGENT_LIMIT (constant)">CONVERGENT_LIMIT</a></span></span><span class='rparen'>)</span> <span class='id identifier rubyid_self_in_cents'>self_in_cents</span> <span class='op'>=</span> <span class='id identifier rubyid_to_cents'>to_cents</span> <span class='id identifier rubyid_within'>within</span> <span class='op'>=</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span> <span class='op'>:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="../Cents.html#initialize-instance_method" title="Tonal::Cents#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>cents:</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='rparen'>)</span> - <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_results'>results</span><span class='op'>|</span> + <span class='const'><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Set</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Approximation/Set.html#initialize-instance_method" title="Tonal::Ratio::Approximation::Set#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>ratio:</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_set'>set</span><span class='op'>|</span> <span class='const'>FractionTree</span><span class='period'>.</span><span class='id identifier rubyid_quotient_walk'>quotient_walk</span><span class='lparen'>(</span><span class='id identifier rubyid_to_f'>to_f</span><span class='comma'>,</span> <span class='label'>limit:</span> <span class='id identifier rubyid_conv_limit'>conv_limit</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_node'>node</span><span class='op'>|</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='op'>=</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_node'>node</span><span class='period'>.</span><span class='id identifier rubyid_weight'>weight</span><span class='rparen'>)</span> - <span class='id identifier rubyid_results'>results</span> <span class='op'><<</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='kw'>if</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_within_cents?'>within_cents?</span><span class='lparen'>(</span><span class='id identifier rubyid_self_in_cents'>self_in_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_to_cents'>to_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_within'>within</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_within_prime?'>within_prime?</span><span class='lparen'>(</span><span class='id identifier rubyid_max_prime'>max_prime</span><span class='rparen'>)</span> - <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_results'>results</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>>=</span> <span class='id identifier rubyid_depth'>depth</span> + <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_ratios'>ratios</span> <span class='op'><<</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='kw'>if</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_within_cents?'>within_cents?</span><span class='lparen'>(</span><span class='id identifier rubyid_self_in_cents'>self_in_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_to_cents'>to_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_within'>within</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_within_prime?'>within_prime?</span><span class='lparen'>(</span><span class='id identifier rubyid_max_prime'>max_prime</span><span class='rparen'>)</span> + <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>>=</span> <span class='id identifier rubyid_depth'>depth</span> <span class='kw'>end</span> - <span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_sort'>sort</span> + <span class='kw'>end</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="by_superparticular-instance_method"> + + #<strong>by_superparticular</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: 20, max_prime: DEFAULT_MAX_PRIME, superpart: :upper) ⇒ <tt><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Tonal::Ratio::Approximation::Set</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns of superparticular approximations within cent tolerance of self.</p> + + + </div> +</div> +<div class="tags"> + + <div class="examples"> + <p class="tag_title">Examples:</p> + + + <pre class="example code"><code>Tonal::Ratio.new(3/2r).approximate.by_superparticular +=> (3/2): [(1098/730), (1095/728), (1092/726), (1089/724), (1086/722), (1083/720), (1080/718), (1077/716), (1074/714), (1071/712), (1068/710), (1065/708), (1062/706), (1059/704), (1056/702), (1053/700), (1050/698), (1047/696), (1044/694), (1041/692)]</code></pre> + + </div> +<p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>cents_tolerance</span> + + + <span class='type'></span> + + + <em class="default">(defaults to: <tt>Tonal::Cents::TOLERANCE</tt>)</em> + + + — + <div class='inline'> +<p>the cents tolerance used to scope the collection</p> +</div> + + </li> + + <li> + + <span class='name'>depth</span> + + + <span class='type'></span> + + + <em class="default">(defaults to: <tt>20</tt>)</em> + + + — + <div class='inline'> +<p>the maximum number of ratios in the collection</p> +</div> + + </li> + + <li> + + <span class='name'>max_prime</span> + + + <span class='type'></span> + + + <em class="default">(defaults to: <tt>DEFAULT_MAX_PRIME</tt>)</em> + + + — + <div class='inline'> +<p>the maximum prime number to allow in the collection</p> +</div> + + </li> + + <li> + + <span class='name'>superpart</span> + + + <span class='type'></span> + + + <em class="default">(defaults to: <tt>:upper</tt>)</em> + + + — + <div class='inline'> +<p>if the superior part is the numerator or denominator</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Tonal::Ratio::Approximation::Set</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>of superparticular approximations within cent tolerance of self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/tonal/approximation.rb', line 92</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_by_superparticular'>by_superparticular</span><span class='lparen'>(</span><span class='label'>cents_tolerance:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html#TOLERANCE-constant" title="Tonal::Cents::TOLERANCE (constant)">TOLERANCE</a></span></span><span class='comma'>,</span> <span class='label'>depth:</span> <span class='int'>20</span><span class='comma'>,</span> <span class='label'>max_prime:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_PRIME-constant" title="Tonal::Ratio::Approximation::DEFAULT_MAX_PRIME (constant)">DEFAULT_MAX_PRIME</a></span></span><span class='comma'>,</span> <span class='label'>superpart:</span> <span class='symbol'>:upper</span><span class='rparen'>)</span> + <span class='id identifier rubyid_self_in_cents'>self_in_cents</span> <span class='op'>=</span> <span class='id identifier rubyid_to_cents'>to_cents</span> + <span class='id identifier rubyid_within'>within</span> <span class='op'>=</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span> <span class='op'>:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="../Cents.html#initialize-instance_method" title="Tonal::Cents#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>cents:</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='rparen'>)</span> + <span class='const'><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Set</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Approximation/Set.html#initialize-instance_method" title="Tonal::Ratio::Approximation::Set#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>ratio:</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_set'>set</span><span class='op'>|</span> + <span class='id identifier rubyid_n'>n</span> <span class='op'>=</span> <span class='int'>1</span> + <span class='kw'>while</span> <span class='kw'>true</span> <span class='kw'>do</span> + <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='op'>=</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_superparticular'>superparticular</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='comma'>,</span> <span class='label'>factor:</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_to_r'>to_r</span><span class='comma'>,</span> <span class='label'>superpart:</span><span class='rparen'>)</span> + <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_ratios'>ratios</span> <span class='op'><<</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='kw'>if</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_within_cents?'>within_cents?</span><span class='lparen'>(</span><span class='id identifier rubyid_self_in_cents'>self_in_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_to_cents'>to_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_within'>within</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_within_prime?'>within_prime?</span><span class='lparen'>(</span><span class='id identifier rubyid_max_prime'>max_prime</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='op'>!=</span> <span class='id identifier rubyid_ratio'>ratio</span> + <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>>=</span> <span class='id identifier rubyid_depth'>depth</span> + <span class='id identifier rubyid_n'>n</span> <span class='op'>+=</span> <span class='int'>1</span> + <span class='kw'>end</span> + <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> @@ -1071,7 +1322,7 @@ <h3 class="signature " id="by_quotient_walk-instance_method"> <div class="method_details "> <h3 class="signature " id="by_tree_path-instance_method"> - #<strong>by_tree_path</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME) ⇒ <tt><span class='object_link'><a href="../../Array.html" title="Array (class)">Array</a></span></tt> + #<strong>by_tree_path</strong>(cents_tolerance: Tonal::Cents::TOLERANCE, depth: DEFAULT_DEPTH, max_prime: DEFAULT_MAX_PRIME) ⇒ <tt><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Tonal::Ratio::Approximation::Set</a></span></tt> @@ -1091,8 +1342,8 @@ <h3 class="signature " id="by_tree_path-instance_method"> <p class="tag_title">Examples:</p> - <pre class="example code"><code>Tonal::Ratio.ed(12,1).by_tree_path(max_prime: 17) -=> [(18/17), (35/33), (17/16)]</code></pre> + <pre class="example code"><code>Tonal::Ratio.ed(12,1).approximate.by_tree_path(max_prime: 17) +=> (4771397596969315/4503599627370496): [(18/17), (35/33), (17/16)]</code></pre> </div> <p class="tag_title">Parameters:</p> @@ -1109,6 +1360,11 @@ <h3 class="signature " id="by_tree_path-instance_method"> <em class="default">(defaults to: <tt>Tonal::Cents::TOLERANCE</tt>)</em> + — + <div class='inline'> +<p>the cents tolerance used to scope the collection</p> +</div> + </li> <li> @@ -1122,6 +1378,11 @@ <h3 class="signature " id="by_tree_path-instance_method"> <em class="default">(defaults to: <tt>DEFAULT_DEPTH</tt>)</em> + — + <div class='inline'> +<p>the maximum number of ratios in the collection</p> +</div> + </li> <li> @@ -1135,6 +1396,11 @@ <h3 class="signature " id="by_tree_path-instance_method"> <em class="default">(defaults to: <tt>DEFAULT_MAX_PRIME</tt>)</em> + — + <div class='inline'> +<p>the maximum prime number to allow in the collection</p> +</div> + </li> </ul> @@ -1145,7 +1411,7 @@ <h3 class="signature " id="by_tree_path-instance_method"> <li> - <span class='type'>(<tt><span class='object_link'><a href="../../Array.html" title="Array (class)">Array</a></span></tt>)</span> + <span class='type'>(<tt><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Tonal::Ratio::Approximation::Set</a></span></tt>)</span> @@ -1164,7 +1430,6 @@ <h3 class="signature " id="by_tree_path-instance_method"> <pre class="lines"> -70 71 72 73 @@ -1174,21 +1439,22 @@ <h3 class="signature " id="by_tree_path-instance_method"> 77 78 79 -80</pre> +80 +81</pre> </td> <td> - <pre class="code"><span class="info file"># File 'lib/tonal/approximations.rb', line 70</span> + <pre class="code"><span class="info file"># File 'lib/tonal/approximation.rb', line 71</span> -<span class='kw'>def</span> <span class='id identifier rubyid_by_tree_path'>by_tree_path</span><span class='lparen'>(</span><span class='label'>cents_tolerance:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html#TOLERANCE-constant" title="Tonal::Cents::TOLERANCE (constant)">TOLERANCE</a></span></span><span class='comma'>,</span> <span class='label'>depth:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_DEPTH-constant" title="Tonal::Ratio::Approximations::DEFAULT_DEPTH (constant)">DEFAULT_DEPTH</a></span></span><span class='comma'>,</span> <span class='label'>max_prime:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_PRIME-constant" title="Tonal::Ratio::Approximations::DEFAULT_MAX_PRIME (constant)">DEFAULT_MAX_PRIME</a></span></span><span class='rparen'>)</span> +<span class='kw'>def</span> <span class='id identifier rubyid_by_tree_path'>by_tree_path</span><span class='lparen'>(</span><span class='label'>cents_tolerance:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html#TOLERANCE-constant" title="Tonal::Cents::TOLERANCE (constant)">TOLERANCE</a></span></span><span class='comma'>,</span> <span class='label'>depth:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_DEPTH-constant" title="Tonal::Ratio::Approximation::DEFAULT_DEPTH (constant)">DEFAULT_DEPTH</a></span></span><span class='comma'>,</span> <span class='label'>max_prime:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_MAX_PRIME-constant" title="Tonal::Ratio::Approximation::DEFAULT_MAX_PRIME (constant)">DEFAULT_MAX_PRIME</a></span></span><span class='rparen'>)</span> <span class='id identifier rubyid_self_in_cents'>self_in_cents</span> <span class='op'>=</span> <span class='id identifier rubyid_to_cents'>to_cents</span> <span class='id identifier rubyid_within'>within</span> <span class='op'>=</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span> <span class='op'>:</span> <span class='const'><span class='object_link'><a href="../../Tonal.html" title="Tonal (module)">Tonal</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Cents.html" title="Tonal::Cents (class)">Cents</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="../Cents.html#initialize-instance_method" title="Tonal::Cents#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>cents:</span> <span class='id identifier rubyid_cents_tolerance'>cents_tolerance</span><span class='rparen'>)</span> - <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_results'>results</span><span class='op'>|</span> + <span class='const'><span class='object_link'><a href="Approximation/Set.html" title="Tonal::Ratio::Approximation::Set (class)">Set</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Approximation/Set.html#initialize-instance_method" title="Tonal::Ratio::Approximation::Set#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>ratio:</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_set'>set</span><span class='op'>|</span> <span class='const'>FractionTree</span><span class='period'>.</span><span class='id identifier rubyid_path_to'>path_to</span><span class='lparen'>(</span><span class='id identifier rubyid_to_f'>to_f</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_node'>node</span><span class='op'>|</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='op'>=</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_node'>node</span><span class='period'>.</span><span class='id identifier rubyid_weight'>weight</span><span class='rparen'>)</span> - <span class='id identifier rubyid_results'>results</span> <span class='op'><<</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='kw'>if</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_within_cents?'>within_cents?</span><span class='lparen'>(</span><span class='id identifier rubyid_self_in_cents'>self_in_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_to_cents'>to_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_within'>within</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_within_prime?'>within_prime?</span><span class='lparen'>(</span><span class='id identifier rubyid_max_prime'>max_prime</span><span class='rparen'>)</span> - <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_results'>results</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>>=</span> <span class='id identifier rubyid_depth'>depth</span> + <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_ratios'>ratios</span> <span class='op'><<</span> <span class='id identifier rubyid_ratio2'>ratio2</span> <span class='kw'>if</span> <span class='id identifier rubyid_ratio'>ratio</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_within_cents?'>within_cents?</span><span class='lparen'>(</span><span class='id identifier rubyid_self_in_cents'>self_in_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_to_cents'>to_cents</span><span class='comma'>,</span> <span class='id identifier rubyid_within'>within</span><span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_ratio2'>ratio2</span><span class='period'>.</span><span class='id identifier rubyid_within_prime?'>within_prime?</span><span class='lparen'>(</span><span class='id identifier rubyid_max_prime'>max_prime</span><span class='rparen'>)</span> + <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_set'>set</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>>=</span> <span class='id identifier rubyid_depth'>depth</span> <span class='kw'>end</span> - <span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_sort'>sort</span> + <span class='kw'>end</span> <span class='kw'>end</span></pre> </td> </tr> @@ -1288,18 +1554,18 @@ <h3 class="signature " id="neighborhood-instance_method"> <pre class="lines"> -120 -121 -122 -123 -124 -125 -126 -127 -128</pre> +144 +145 +146 +147 +148 +149 +150 +151 +152</pre> </td> <td> - <pre class="code"><span class="info file"># File 'lib/tonal/approximations.rb', line 120</span> + <pre class="code"><span class="info file"># File 'lib/tonal/approximation.rb', line 144</span> <span class='kw'>def</span> <span class='id identifier rubyid_neighborhood'>neighborhood</span><span class='lparen'>(</span><span class='label'>scale:</span> <span class='int'>2</span><span class='op'>**</span><span class='int'>0</span><span class='comma'>,</span> <span class='label'>boundary:</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='id identifier rubyid_scale'>scale</span> <span class='op'>=</span> <span class='id identifier rubyid_scale'>scale</span><span class='period'>.</span><span class='id identifier rubyid_round'>round</span> @@ -1320,7 +1586,7 @@ <h3 class="signature " id="neighborhood-instance_method"> </div> <div id="footer"> - Generated on Tue Jan 23 15:49:04 2024 by + Generated on Tue Feb 13 15:15:39 2024 by <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.9.34 (ruby-3.2.2). </div> diff --git a/docs/Tonal/Ratio/Approximation/Set.html b/docs/Tonal/Ratio/Approximation/Set.html new file mode 100644 index 0000000..458d101 --- /dev/null +++ b/docs/Tonal/Ratio/Approximation/Set.html @@ -0,0 +1,423 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: Tonal::Ratio::Approximation::Set + + — Documentation by YARD 0.9.34 + + + + + + + + + + + + + + + + + + + +
    + + +

    Class: Tonal::Ratio::Approximation::Set + + + +

    +
    + +
    +
    Inherits:
    +
    + Object + +
      +
    • Object
    • + + + +
    + show all + +
    +
    + + + + +
    +
    Extended by:
    +
    Forwardable
    +
    + + + + + + + + +
    +
    Defined in:
    +
    lib/tonal/approximation.rb
    +
    + +
    + + + + + +

    Instance Attribute Summary collapse

    +
      + +
    • + + + #ratio ⇒ Object + + + + + + + + + readonly + + + + + + + + + +
      +

      Returns the value of attribute ratio.

      +
      + +
    • + + +
    • + + + #ratios ⇒ Object + + + + + + + + + readonly + + + + + + + + + +
      +

      Returns the value of attribute ratios.

      +
      + +
    • + + +
    + + + + + +

    + Instance Method Summary + collapse +

    + + + + + +
    +

    Constructor Details

    + +
    +

    + + #initialize(ratio:) ⇒ Set + + + + + +

    +
    + +

    Returns a new instance of Set.

    + + +
    +
    +
    + + +
    + + + + +
    +
    +
    +
    +178
    +179
    +180
    +181
    +
    +
    # File 'lib/tonal/approximation.rb', line 178
    +
    +def initialize(ratio:)
    +  @ratio = ratio
    +  @ratios = SortedSet.new
    +end
    +
    +
    + +
    + +
    +

    Instance Attribute Details

    + + + +
    +

    + + #ratioObject (readonly) + + + + + +

    +
    + +

    Returns the value of attribute ratio.

    + + +
    +
    +
    + + +
    + + + + +
    +
    +
    +
    +176
    +177
    +178
    +
    +
    # File 'lib/tonal/approximation.rb', line 176
    +
    +def ratio
    +  @ratio
    +end
    +
    +
    + + + +
    +

    + + #ratiosObject (readonly) + + + + + +

    +
    + +

    Returns the value of attribute ratios.

    + + +
    +
    +
    + + +
    + + + + +
    +
    +
    +
    +176
    +177
    +178
    +
    +
    # File 'lib/tonal/approximation.rb', line 176
    +
    +def ratios
    +  @ratios
    +end
    +
    +
    + +
    + + +
    +

    Instance Method Details

    + + +
    +

    + + #inspectObject + + + + + +

    + + + + +
    +
    +
    +
    +184
    +185
    +186
    +
    +
    # File 'lib/tonal/approximation.rb', line 184
    +
    +def inspect
    +  "#{ratio}: #{entries}"
    +end
    +
    +
    + +
    + +
    + + + +
    + + \ No newline at end of file diff --git a/docs/Tonal/ReducedRatio.html b/docs/Tonal/ReducedRatio.html index 5719a57..c784864 100644 --- a/docs/Tonal/ReducedRatio.html +++ b/docs/Tonal/ReducedRatio.html @@ -253,7 +253,7 @@

    Methods inherited from Ratio

    -

    #*, #**, #+, #-, #/, #<=>, #approx, #benedetti_height, #cent_diff, #combination, #difference, #div_times, ed, #efficiency, #equave_reduce, #equave_reduce!, #fraction_reduce, #inspect, #invert, #invert!, #label, #lcm, #log_weil_height, #max_prime, #mediant_sum, #min_prime, #mirror, #mirror2, #negative, #period_degrees, #period_radians, #planar_degrees, #planar_radians, #plus_minus, #prime_divisions, #prime_vector, random_ratio, #ratio, #scale, #shear, #step, superparticular, superpartient, #tenney_height, #to_a, #to_cents, #to_f, #to_log, #to_log2, #to_r, #to_reduced_ratio, #to_v, #translate, #weil_height, #wilson_height, within_cents?, #within_prime?

    +

    #*, #**, #+, #-, #/, #<=>, #approximate, #benedetti_height, #cent_diff, #combination, #difference, #div_times, ed, #efficiency, #equave_reduce, #equave_reduce!, #fraction_reduce, #inspect, #invert, #invert!, #label, #lcm, #log_weil_height, #max_prime, #mediant_sum, #min_prime, #mirror, #negative, #period_degrees, #period_radians, #planar_degrees, #planar_radians, #plus_minus, #prime_divisions, #prime_vector, random_ratio, #ratio, #scale, #shear, #step, superparticular, superpartient, #tenney_height, #to_a, #to_cents, #to_f, #to_log, #to_log2, #to_r, #to_reduced_ratio, #to_v, #translate, #weil_height, #wilson_height, within_cents?, #within_prime?

    @@ -553,7 +553,7 @@

    diff --git a/docs/Tonal/Step.html b/docs/Tonal/Step.html index 8ec87c7..882bf4f 100644 --- a/docs/Tonal/Step.html +++ b/docs/Tonal/Step.html @@ -944,7 +944,7 @@

    diff --git a/docs/Vector.html b/docs/Vector.html index fb61512..2146f96 100644 --- a/docs/Vector.html +++ b/docs/Vector.html @@ -226,10 +226,10 @@

     
     
    -401
    +402

    -
    # File 'lib/tonal/extensions.rb', line 401
    +      
    # File 'lib/tonal/extensions.rb', line 402
     
     def to_ratio(reduced: true, equave: 2/1r) = reduced ? Tonal::ReducedRatio.new(*self, equave: equave) : Tonal::Ratio.new(*self, equave: equave)