tonal-tools 1.0.2 → 1.0.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 +4 -4
- data/lib/tonal/cents.rb +5 -7
- data/lib/tonal/extensions.rb +5 -9
- data/lib/tonal/log.rb +2 -7
- data/lib/tonal/ratio.rb +9 -6
- data/lib/tonal/step.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6ae36a205038f24fa661fa8a7ede3bb360e2c5241b980cfb356f394d06f92c0
|
4
|
+
data.tar.gz: d86932650896d5e8e765ff3de65b78b1bdeca2db70e9c2b7a0a57ca6ae763bb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2eff196352f633616155a0730abd04ff134b6157dbf9a34234d3fb59f12d659431509d6f8f462f326a80fc25e5ad97496f6b866c45961592ebe9826d20066c0
|
7
|
+
data.tar.gz: 1ccd7aecfb974180d56909535c43cce03cb4cb872b3991264b594c38eb23a496ad83139123586b4999ff5274193ef82f78f9a234f088855c5853108bbfb9fbea
|
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
|
-
#
|
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/extensions.rb
CHANGED
@@ -11,7 +11,7 @@ class Prime
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Numeric
|
14
|
-
# @return [Array]
|
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).
|
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
|
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:
|
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:
|
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:
|
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::
|
258
|
+
# @return [Tonal::Ratio] the mirror of self along the axis (default 1/1)
|
259
259
|
# @example
|
260
|
-
# Tonal::
|
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
|
-
#
|
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)
|
data/lib/tonal/step.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.4
|
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-
|
11
|
+
date: 2023-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '2.
|
89
|
+
version: '2.1'
|
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: '2.
|
96
|
+
version: '2.1'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: fraction-tree
|
99
99
|
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
|
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
191
|
version: '3.1'
|
192
192
|
requirements: []
|
193
|
-
rubygems_version: 3.
|
193
|
+
rubygems_version: 3.5.1
|
194
194
|
signing_key:
|
195
195
|
specification_version: 4
|
196
196
|
summary: Tonal tools
|