Class: Tonal::ReducedRatio

Inherits:
Ratio
  • Object
show all
Defined in:
lib/tonal/reduced_ratio.rb

Constant Summary collapse

IDENTITY_RATIO =
1

Instance Attribute Summary

Attributes inherited from Ratio

#antecedent, #consequent, #equave, #reduced_antecedent, #reduced_consequent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ratio

#*, #**, #+, #-, #/, #<=>, #approximate, #benedetti_height, #cent_diff, #combination, #difference, #div_times, ed, #efficiency, #equave_reduce, #equave_reduce!, #fraction_reduce, #inspect, #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?

Constructor Details

#initialize(antecedent, consequent = 1, label: nil, equave: 2) ⇒ Tonal::ReducedRatio

Examples:

Tonal::ReducedRatio.new(12,2) => (3/2)

Parameters:



11
12
13
14
# File 'lib/tonal/reduced_ratio.rb', line 11

def initialize(antecedent, consequent=1, label: nil, equave: 2/1r)
  super(antecedent, consequent, label: label, equave: equave)
  @antecedent, @consequent = @reduced_antecedent, @reduced_consequent
end

Class Method Details

.identityObject



16
17
18
# File 'lib/tonal/reduced_ratio.rb', line 16

def self.identity
  self.new(IDENTITY_RATIO)
end

Instance Method Details

#interval_with(ratio) ⇒ Tonal::Interval

Returns between ratio (upper) and self (lower).

Examples:

Tonal::ReducedRatio.new(133).interval_with(3/2r)
=> 192/133 (3/2 / 133/128)

Parameters:

  • ratio

Returns:



34
35
36
37
# File 'lib/tonal/reduced_ratio.rb', line 34

def interval_with(ratio)
  r = ratio.is_a?(self.class) ? ratio : self.class.new(ratio)
  Tonal::Interval.new(r, self)
end

#invert!Tonal::ReducedRatio

Returns with antecedent and precedent switched.

Examples:

Tonal::ReducedRatio.new(3,2).invert! => (4/3)

Returns:



43
44
45
46
47
# File 'lib/tonal/reduced_ratio.rb', line 43

def invert!
  super
  @antecedent, @consequent = @reduced_antecedent, @reduced_consequent
  self
end

#to_basic_ratioTonal::Ratio

Returns self as an instance of unreduced ratio.

Examples:

Tonal::ReducedRatio.new(3,2).to_basic_ratio => (3/2)

Returns:



24
25
26
# File 'lib/tonal/reduced_ratio.rb', line 24

def to_basic_ratio
  Tonal::Ratio.new(antecedent, consequent)
end