tonal-tools 0.2.0 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 618bd26c11332eb200cf9b9bf8bb38f7956b1bc084d07f693ebe41f203839ccf
4
- data.tar.gz: 2de816e7bd17637d912c31ebda7b2f93fb717e89caefc804805e4b0a786cee90
3
+ metadata.gz: 496a1287b6645e141aae7b35adadb77a1a9add394a92921c69aa7d5fb2f69c95
4
+ data.tar.gz: 49c8251e9bbc99f352042d6184accb916d81c1b22a09a1d296268203e0f759df
5
5
  SHA512:
6
- metadata.gz: c90617a5ecef6e01195e2e7d95f8d3588e068d119c5b4dbc602de97b5229086efc17e6de7a4e7c539d281693127d57225536bd259bcb435eeaba1e3646710f47
7
- data.tar.gz: a64f852eab9bc77c7ccf5267a4b48999aa5860728191c8f13e67b0184de6b4766480a33415a82eadf3decfc07b9d804c49ad1c76c4b6fb82122a7b47454be903
6
+ metadata.gz: 998647702008bf98462b2e246a868649906348c083563c1e537ead89cccacb4fccf4f2125d3aad79137f1b37ae2b7e5371132fe720ad1e5013c5f638b1e6c4a9
7
+ data.tar.gz: 64faa5fb6347d5259fb803e7627a1469fa0d1ae154852ccaad11be9f33371f5ac73b0ea30de2a4eaf40d96699037ea4b519e2cfa9f1b8f845590d123449d6b75
@@ -30,7 +30,7 @@ class Tonal::Ratio
30
30
  self_in_cents = to_cents
31
31
  within = cents_tolerance.kind_of?(Tonal::Cents) ? cents_tolerance : Tonal::Cents.new(cents: cents_tolerance)
32
32
  [].tap do |results|
33
- ContinuedFraction.new(antecedent.to_f/consequent, conv_limit).convergents_as_rationals.each do |convergent|
33
+ ContinuedFraction.new(antecedent.to_f/consequent, conv_limit).convergents.each do |convergent|
34
34
  ratio2 = ratio.class.new(convergent.numerator,convergent.denominator)
35
35
  results << ratio2 if ratio.class.within_cents?(self_in_cents, ratio2.to_cents, within) && ratio2.within_prime?(max_prime)
36
36
  break if results.length >= depth
data/lib/tonal/cents.rb CHANGED
@@ -68,7 +68,7 @@ class Tonal::Cents
68
68
  end
69
69
 
70
70
  # @return
71
- # [Cents] nearest hundredth cent difference
71
+ # [Tonal::Cents] nearest hundredth cent difference
72
72
  # @example
73
73
  # Tonal::Cents.new(701.9550008653874).nearest_hundredth_difference => 1.955000865387433
74
74
  #
@@ -76,7 +76,10 @@ class Tonal::Cents
76
76
  self.class.new(cents: (value - nearest_hundredth))
77
77
  end
78
78
 
79
- # TODO: Document or Consider if needed
79
+ # @return [Array] a tuple of self offset positively/negatively by limit
80
+ # @example
81
+ # Tonal::Cents.new(cents: 100.0).plus_minus
82
+ # => [95.0, 105.0]
80
83
  #
81
84
  def plus_minus(limit = 5)
82
85
  [self - limit, self + limit]
@@ -133,11 +136,6 @@ class Tonal::Cents
133
136
  case result
134
137
  when Numeric
135
138
  self.class.new(cents: result)
136
- # TODO: Work this case out or remove
137
- #when Array
138
- # result.collect do |e|
139
- # e.kind_of?(Numeric) ? Cents.new(e) : e
140
- # end
141
139
  else
142
140
  result
143
141
  end
data/lib/tonal/comma.rb CHANGED
@@ -1,16 +1,44 @@
1
1
  class Tonal::Comma
2
+ # @return [Hash] of comma key/value pairs
3
+ # @example
4
+ # Tonal::Comma.commas
5
+ # => {"ditonic"=>"531441/524288",
6
+ # "syntonic"=>"81/80",
7
+ # "schisma"=>"32805/32768",
8
+ # ...}
9
+ #
2
10
  def self.commas
3
11
  @commas ||= JSON.parse(YAML::load_file("#{__dir__}/../../data/commas.yml", aliases: true).to_json)["commas"]
4
12
  end
5
13
 
14
+ # @return [Array] of comma values
15
+ # @example
16
+ # Tonal::Comma.values
17
+ # => [(531441/524288),
18
+ # (81/80),
19
+ # (32805/32768),
20
+ # ...]
21
+ #
6
22
  def self.values
7
23
  @values ||= commas.values.map(&:to_r)
8
24
  end
9
25
 
26
+ # @return [Array] of comma keys
27
+ # @example
28
+ # Tonal::Comma.keys
29
+ # => ["ditonic",
30
+ # "syntonic",
31
+ # "schisma",
32
+ # ...]
33
+ #
10
34
  def self.keys
11
35
  @keys ||= commas.keys
12
36
  end
13
37
 
38
+ # @return [Rational] the comma found in the repo
39
+ # @example
40
+ # Tonal::Comma.ditonic => (531441/524288)
41
+ #
14
42
  def self.method_missing(comma)
15
43
  commas[comma.to_s].to_r
16
44
  end
@@ -11,7 +11,7 @@ class Prime
11
11
  end
12
12
 
13
13
  class Numeric
14
- # @return [Array], a tuple of self offset positively/negatively
14
+ # @return [Array] a tuple of self offset positively/negatively
15
15
  # @example
16
16
  # Math::PI.plus_minus(3)
17
17
  # => [6.141592653589793, 0.14159265358979312]
@@ -74,7 +74,7 @@ class Numeric
74
74
 
75
75
  # @return [Tonal::Cents] of self interpreted as a ratio
76
76
  # @example
77
- # (3/2r).cents => 701.96
77
+ # (3/2r).to_cents => 701.96
78
78
  #
79
79
  def to_cents
80
80
  self.log2.to_cents
@@ -371,8 +371,9 @@ class Array
371
371
  end
372
372
  alias :vector :to_vector
373
373
 
374
- # @return [Integer] least common multiple of elements of self
375
- # @example TODO
374
+ # @return [Integer] least common multiple of integer elements of self
375
+ # @example
376
+ # [3, 2, 7].lcm => 42
376
377
  #
377
378
  def lcm
378
379
  self.reduce(1, :lcm)
@@ -414,11 +415,6 @@ class Array
414
415
  end
415
416
  alias :cents :to_cents
416
417
 
417
- # TODO: Consider removing
418
- #def cons_diff(cons=2)
419
- # self.each_cons(cons).map{|a,b| (a - b).abs }
420
- #end
421
-
422
418
  # @return [Float] the mean of the elements of self
423
419
  # @example
424
420
  # [1, 2].mean => 1.5
data/lib/tonal/log.rb CHANGED
@@ -15,6 +15,8 @@ class Tonal::Log
15
15
  #
16
16
  def initialize(logarithmand: nil, logarithm: nil, base: nil)
17
17
  raise ArgumentError, "logarithmand or logarithm must be provided" if logarithmand.nil? && logarithm.nil?
18
+ raise ArgumentError, "logarithmand must be Numeric" unless logarithmand.kind_of?(Numeric) || logarithmand.nil?
19
+ raise ArgumentError, "logarithm must be Numeric" unless logarithm.kind_of?(Numeric) || logarithm.nil?
18
20
 
19
21
  if logarithmand && logarithm && base
20
22
  @logarithmand = logarithmand
@@ -97,8 +99,6 @@ class Tonal::Log
97
99
  end
98
100
  end
99
101
 
100
- # TODO Explain how this works
101
- #
102
102
  def method_missing(op, *args, &blk)
103
103
  rhs = args.collect do |arg|
104
104
  arg.kind_of?(self.class) ? arg.inspect : arg
@@ -108,11 +108,6 @@ class Tonal::Log
108
108
  case result
109
109
  when Numeric
110
110
  self.class.new(result)
111
- # Work this case out
112
- #when Array
113
- # result.collect do |e|
114
- # e.kind_of?(Numeric) ? Cents.new(e) : e
115
- # end
116
111
  else
117
112
  result
118
113
  end
data/lib/tonal/ratio.rb CHANGED
@@ -147,7 +147,7 @@ class Tonal::Ratio
147
147
  # @param base
148
148
  #
149
149
  def to_log(base=2)
150
- Tonal::Log.new(logarithmand: self, base: base)
150
+ Tonal::Log.new(logarithmand: to_r, base: base)
151
151
  end
152
152
  alias :log :to_log
153
153
 
@@ -156,7 +156,7 @@ class Tonal::Ratio
156
156
  # Tonal::ReducedRatio.new(3,2).to_log2 => 0.5849625007211562
157
157
  #
158
158
  def to_log2
159
- Tonal::Log2.new(logarithmand: self)
159
+ Tonal::Log2.new(logarithmand: to_r)
160
160
  end
161
161
  alias :log2 :to_log2
162
162
 
@@ -165,7 +165,7 @@ class Tonal::Ratio
165
165
  # Tonal::Ratio.new(3,2).to_cents => 701.96
166
166
  #
167
167
  def to_cents
168
- Tonal::Cents.new(ratio: self)
168
+ Tonal::Cents.new(ratio: to_r)
169
169
  end
170
170
  alias :cents :to_cents
171
171
 
@@ -255,16 +255,19 @@ class Tonal::Ratio
255
255
  self
256
256
  end
257
257
 
258
- # @return [Tonal::ReducedRatio] the mirror of self along the axis (default 1/1)
258
+ # @return [Tonal::Ratio] the mirror of self along the axis (default 1/1)
259
259
  # @example
260
- # Tonal::ReducedRatio.new(4,3).mirror => (3/2)
260
+ # Tonal::Ratio.new(4,3).mirror => (3/2)
261
261
  # @param axis
262
262
  #
263
263
  def mirror(axis=1/1r)
264
264
  (self.class.new(axis) ** 2) / self
265
265
  end
266
266
 
267
- # TODO: Justify or remove
267
+ # @return [Tonal::Ratio]
268
+ # @example
269
+ # Tonal::Ratio.new(4/3r).mirror2(4/2r) => (3/8)
270
+ # @param ratio
268
271
  #
269
272
  def mirror2(ratio)
270
273
  self.class.new(invert.to_r / ratio)
@@ -474,7 +477,7 @@ class Tonal::Ratio
474
477
 
475
478
  # @return [String] the string representation of Tonal::Ratio
476
479
  # @example
477
- # Tonal::Ratio.new(3, 2).inspect => "[3, 2]"
480
+ # Tonal::Ratio.new(3, 2).inspect => "(3/2)"
478
481
  #
479
482
  def inspect
480
483
  "(#{antecedent}/#{consequent})"
data/lib/tonal/step.rb CHANGED
@@ -36,7 +36,7 @@ class Tonal::Step
36
36
  ratio.to_r
37
37
  end
38
38
 
39
- def cents
39
+ def to_cents
40
40
  ratio.to_cents
41
41
  end
42
42
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tonal-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Hales-Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-04 00:00:00.000000000 Z
11
+ date: 2023-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.8'
89
+ version: '2.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.8'
96
+ version: '2.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: fraction-tree
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.1'
103
+ version: '1.0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.1'
110
+ version: '1.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -183,14 +183,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - ">="
185
185
  - !ruby/object:Gem::Version
186
- version: 3.1.2
186
+ version: '3.1'
187
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  requirements:
189
189
  - - ">="
190
190
  - !ruby/object:Gem::Version
191
- version: '0'
191
+ version: '3.1'
192
192
  requirements: []
193
- rubygems_version: 3.4.22
193
+ rubygems_version: 3.5.1
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: Tonal tools