tonal-tools 8.3.2 → 8.3.3

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: e4abf5cbb165cd0add4c91cc6d4394219076e7ab5bc02ac52288f6d3f6c278e1
4
+ data.tar.gz: 405af2ddb5dcbf483c3dca44a1ba6307d283f0d85b28d20b65c916178963b7d6
5
5
  SHA512:
6
- metadata.gz: 391772bbd5096b18ced768e099f093b5d477a022cd6540a858129abddd5479d00a36e717c81a72af5c5251f71ff5de8ebe7bd6265e168993c58e00f44038562c
7
- data.tar.gz: 1d90f075280b353130e0df41f21b8993b614fa82c22dd9513ba135641895b86efc570face1f389427837ee5bfb6ffcbfa0619bcfe819b731b59a6f66e1e3f67b
6
+ metadata.gz: c516d5914d93c9f563cf0b9b71d2d15c89f408c159010899ea9552d82d176d193c62cd7463ed44c6e287c67efc9091979e5ca7aa4ed3b37d0453e9bebd02690c
7
+ data.tar.gz: 72ea362063ea441c121200cc0ec6b9aa6e789047f9090218a3b7d1dbe156c8f0614e88b67911ecbfbc635d7919671f32f41c0f87ea1f66938eb26bd55090e006
@@ -1,4 +1,4 @@
1
1
  module Tonal
2
2
  TOOLS_PRODUCER = "mTonal"
3
- TOOLS_VERSION = "8.3.2"
3
+ TOOLS_VERSION = "8.3.3"
4
4
  end
@@ -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/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.3
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-02-26 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: []