Class: Tonal::ReducedRatio

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

Constant Summary collapse

IDENTITY_RATIO =
1

Constants inherited from Ratio

Tonal::Ratio::PRECISION

Instance Attribute Summary

Attributes inherited from Ratio

#antecedent, #consequent, #equave, #label, #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, #interval_with, #invert, #lcm, #log_weil_height, #max_prime, #max_prime_within?, #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?

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

#invert!Tonal::ReducedRatio

Returns with antecedent and precedent switched.

Examples:

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

Returns:



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

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