tonal-tools 8.3.2 → 8.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edaeefa4c9e85628de77bdc793e7bf185c66b7f77449201180972798bc8c03e4
4
- data.tar.gz: c084919a42c7d53a030b208dfcadb3b6b3435a2da23393736ca7aa8a697a0866
3
+ metadata.gz: bdb178eb44ac2841a878052e7ec184d97dbe4b992596c4fc849ba7cbd8c08538
4
+ data.tar.gz: 59043afa410a203fb83c361e8f580a60e2c81903d4b95153ed5f8a8e3285a68e
5
5
  SHA512:
6
- metadata.gz: 391772bbd5096b18ced768e099f093b5d477a022cd6540a858129abddd5479d00a36e717c81a72af5c5251f71ff5de8ebe7bd6265e168993c58e00f44038562c
7
- data.tar.gz: 1d90f075280b353130e0df41f21b8993b614fa82c22dd9513ba135641895b86efc570face1f389427837ee5bfb6ffcbfa0619bcfe819b731b59a6f66e1e3f67b
6
+ metadata.gz: cbc32bccbf514a8abce43f1627b1795d8517091a452be252325317958075c1c9a13a407f389b12c93426c6786feedfb00c1bb777368e0c625440de605d734cfe
7
+ data.tar.gz: 86d55133cdd853c597d07fdd1017d674aa8cc1898dbe560a31c556877ae2c1567b262bcfd43b68eab9e67f0fe44267d0f02f9c770f5032ca66d4e53a922abab4
@@ -1,4 +1,4 @@
1
1
  module Tonal
2
2
  TOOLS_PRODUCER = "mTonal"
3
- TOOLS_VERSION = "8.3.2"
3
+ TOOLS_VERSION = "8.3.4"
4
4
  end
data/lib/tonal/cents.rb CHANGED
@@ -3,6 +3,7 @@ class Tonal::Cents
3
3
  include Comparable
4
4
 
5
5
  def_delegators :@log, :logarithm, :logarithmand, :base
6
+ def_delegators :@ratio, :numerator, :denominator, :to_reduced_ratio, :to_ratio
6
7
 
7
8
  HUNDREDTHS_ROUNDOFF = -2
8
9
  FLOAT_PRECISION = 100
@@ -40,6 +41,8 @@ class Tonal::Cents
40
41
  end
41
42
  end
42
43
 
44
+ alias :reduced_ratio :to_reduced_ratio
45
+
43
46
  # @return [Tonal::Cents] the default cents tolerance
44
47
  # @example
45
48
  # Tonal::Cents.default_tolerance => 5
@@ -149,8 +152,8 @@ class Tonal::Cents
149
152
  end
150
153
 
151
154
  def derive_ratio(log: nil, ratio: nil)
152
- return Tonal::ReducedRatio.new(log.logarithmand) if log
153
- Tonal::ReducedRatio.new(ratio.numerator, ratio.denominator)
155
+ return Tonal::Ratio.new(log.logarithmand) if log
156
+ Tonal::Ratio.new(ratio.numerator, ratio.denominator)
154
157
  end
155
158
 
156
159
  def derive_cents(cents: nil, log: nil)
@@ -145,10 +145,13 @@ class Numeric
145
145
  # @return [Float] the cents difference between self and its step in the given modulo
146
146
  # @example
147
147
  # (3/2r).efficiency(12) => -1.96
148
- # @param modulo
149
- # @param reduced
148
+ # @example
149
+ # (3/2r).efficiency(12, is_step_efficiency: true) => 1.96
150
+ # @param modulo against which the difference of self is compared
151
+ # @param reduced if true, self is reduced to the octave before calculating efficiency
152
+ # @param is_step_efficiency if true, calculates the efficiency of the step instead of the ratio (self). If the step efficiency is X cents, then the ratio efficiency is -X cents.
150
153
  #
151
- def efficiency(modulo, reduced: false) = ratio(reduced:).efficiency(modulo)
154
+ def efficiency(modulo, reduced: false, is_step_efficiency: false) = ratio(reduced:).efficiency(modulo, is_step_efficiency:)
152
155
 
153
156
  # @return [Tonal::Interval] beween self (upper) and ratio (lower)
154
157
  # @example
data/lib/tonal/hertz.rb CHANGED
@@ -15,9 +15,9 @@ class Tonal::Hertz
15
15
 
16
16
  # @return [Tonal::Hertz] 440 Hz
17
17
  # @example
18
- # Tonal::Hertz.a440 => 440.0 Hz
18
+ # Tonal::Hertz.reference => 440.0 Hz
19
19
  #
20
- def self.a440
20
+ def self.reference
21
21
  self.new(440.0)
22
22
  end
23
23
 
@@ -29,7 +29,6 @@ class Tonal::Hertz
29
29
  Rational(value)
30
30
  end
31
31
 
32
-
33
32
  # @return [Rational] self as a float
34
33
  # @example
35
34
  # Tonal::Hertz.new(440).to_f => 440.0
@@ -38,6 +37,15 @@ class Tonal::Hertz
38
37
  value.to_f
39
38
  end
40
39
 
40
+ # @return [Tonal::Cents] the cents difference between self and a reference frequency
41
+ # @example
42
+ # Tonal::Hertz.new(880).to_cents => 1200.0
43
+ # @param reference [Tonal::Hertz, Numeric] the reference frequency to compare to
44
+ #
45
+ def to_cents(reference: self.class.reference)
46
+ Tonal::Cents.new(ratio: to_r / reference.to_r)
47
+ end
48
+
41
49
  # @return [String] the string representation of Tonal::Hertz
42
50
  # @example
43
51
  # Tonal::Hertz(1000.0).inspect => "1000.0 Hz"
data/lib/tonal/ratio.rb CHANGED
@@ -5,6 +5,7 @@ class Tonal::Ratio
5
5
  def_delegators :@approximation, :neighborhood
6
6
 
7
7
  PRECISION = 2
8
+ DEFAULT_EQUAVE = 2/1r
8
9
 
9
10
  attr_reader :antecedent, :consequent, :equave, :reduced_antecedent, :reduced_consequent
10
11
 
@@ -16,7 +17,7 @@ class Tonal::Ratio
16
17
  # @param antecedent [Numeric, Tonal::Ratio]
17
18
  # @param consequent [Numeric, Tonal::Ratio]
18
19
  #
19
- def initialize(antecedent, consequent=nil, label: nil, equave: 2/1r)
20
+ def initialize(antecedent, consequent=nil, label: nil, equave: DEFAULT_EQUAVE)
20
21
  raise ArgumentError, "Antecedent must be Numeric" unless antecedent.kind_of?(Numeric)
21
22
  raise ArgumentError, "Consequent must be Numeric or nil" unless (consequent.kind_of?(Numeric) || consequent.nil?)
22
23
 
@@ -79,8 +80,8 @@ class Tonal::Ratio
79
80
  # @param step the step number in the equal division of the equave
80
81
  # @param equave the interval of equivalence, default 2/1
81
82
  #
82
- def self.ed(step, modulo, equave: 2/1r)
83
- self.new(2**(step.to_f/modulo), equave: equave)
83
+ def self.ed(step, modulo, equave: DEFAULT_EQUAVE)
84
+ self.new(2**(step.to_f/modulo), equave:)
84
85
  end
85
86
 
86
87
  # @return [Boolean] if pair of ratios are within the given cents limit
@@ -213,7 +214,7 @@ class Tonal::Ratio
213
214
  # Tonal::Ratio.new(48,14).equave_reduce(3) => 8/7
214
215
  # @param equave Numeric
215
216
  #
216
- def equave_reduce(equave=2/1r)
217
+ def equave_reduce(equave=DEFAULT_EQUAVE)
217
218
  self.class.new(*_equave_reduce(equave))
218
219
  end
219
220
  alias :reduce :equave_reduce
@@ -224,7 +225,7 @@ class Tonal::Ratio
224
225
  # Tonal::Ratio.new(48,14).equave_reduce!(3) => 8/7
225
226
  # @param equave Numeric
226
227
  #
227
- def equave_reduce!(equave=2/1r)
228
+ def equave_reduce!(equave=DEFAULT_EQUAVE)
228
229
  @antecedent, @consequent = _equave_reduce(equave)
229
230
  self
230
231
  end
@@ -430,10 +431,10 @@ class Tonal::Ratio
430
431
  # Tonal::ReducedRatio.new(3,2).efficiency(12) => -1.96
431
432
  # @param modulo against which the difference of self is compared
432
433
  #
433
- def efficiency(modulo)
434
- # We want the efficiency from the ratio (self).
434
+ def efficiency(modulo, is_step_efficiency: false)
435
+ # For single ratios, we normally want the efficiency from the ratio (self).
435
436
  # If the step efficiency is X cents, then the ratio efficiency is -X cents.
436
- step(modulo).efficiency * -1.0
437
+ step(modulo).efficiency * (is_step_efficiency ? 1.0 : -1.0)
437
438
  end
438
439
 
439
440
  # @return [Array] the results of ratio dividing and multiplying self
@@ -459,12 +460,13 @@ class Tonal::Ratio
459
460
 
460
461
  # @return [Tonal::Cents] cent difference between self and other ratio
461
462
  # @example
462
- # Tonal::ReducedRatio.new(3,2).cent_diff(4/3r) => 203.92
463
+ # Tonal::ReducedRatio.new(3,2).cents_difference_with(4/3r) => 203.92
463
464
  # @param other_ratio [Tonal::ReducedRatio, Numeric] from which self's cents is measured
464
465
  #
465
- def cent_diff(other_ratio)
466
- cents - other_ratio.ratio.cents
466
+ def cents_difference_with(other_ratio)
467
+ to_cents - other_ratio.ratio.to_cents
467
468
  end
469
+ alias :cent_diff :cents_difference_with
468
470
 
469
471
  # @return [Integer] the least common multiple with self's denominator and the given number's denominator
470
472
  # @example
@@ -649,7 +651,7 @@ class Tonal::Ratio
649
651
  end
650
652
 
651
653
  private
652
- def _initialize(antecedent, consequent=nil, label: nil, equave: 2/1r)
654
+ def _initialize(antecedent, consequent=nil, label: nil, equave: DEFAULT_EQUAVE)
653
655
  if consequent
654
656
  @antecedent = antecedent.abs
655
657
  @consequent = consequent.abs
@@ -668,7 +670,7 @@ class Tonal::Ratio
668
670
  raise ArgumentError, "Arguments must be greater than zero" if args.any?{|i| i < 0 }
669
671
  end
670
672
 
671
- def _equave_reduce(equave=2/1r)
673
+ def _equave_reduce(equave=DEFAULT_EQUAVE)
672
674
  case to_r
673
675
  when Float::INFINITY
674
676
  ante, cons = antecedent, 0
data/lib/tonal/step.rb CHANGED
@@ -85,6 +85,7 @@ class Tonal::Scale
85
85
  # We want the efficiency from the step (self).
86
86
  ratio_to_cents - step_to_cents
87
87
  end
88
+ alias :cents_difference :efficiency
88
89
 
89
90
  def +(rhs)
90
91
  self.class.new(step: (rhs % modulo), modulo: modulo)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tonal-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.3.2
4
+ version: 8.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Hales-Garcia
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-02-15 00:00:00.000000000 Z
10
+ date: 2026-03-22 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: yaml
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  - !ruby/object:Gem::Version
193
193
  version: '3.1'
194
194
  requirements: []
195
- rubygems_version: 4.0.4
195
+ rubygems_version: 4.0.7
196
196
  specification_version: 4
197
197
  summary: Tonal tools
198
198
  test_files: []