tonal-tools 0.1.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/data/commas.yml +11 -0
- data/lib/tonal/approximations.rb +1 -1
- data/lib/tonal/comma.rb +45 -0
- data/lib/tonal/ratio.rb +2 -2
- data/lib/tonal/tools.rb +3 -0
- metadata +38 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc35954dbfa03dfe0acca0efda8508d06cffc3259fd7f9d959ff260e099c2de5
|
4
|
+
data.tar.gz: 1de6de9804f88b954ec67720e5b29a3de83a6c6d49577de5a679745b5f4491ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f9cd04eab65b20ddf0263910c661337c6a02d47ebabc5277eeaf7358e686f38283d1158ef985ee238625330b338acca9090021d22c10128d92955b3d5f59891
|
7
|
+
data.tar.gz: '0858ee0672ee37381878371622d7b46471341e56e7c85bceae5c447a3112199330d59931f5ba070fb5a82d6fd9e1e42d8f66838edb229707c9afbdadb13222cd'
|
data/data/commas.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
commas:
|
2
|
+
# Interval between two enharmonically equivalent notes, as B# and C, in the Pythogorean tuning. ~23 cents
|
3
|
+
ditonic: 531441/524288
|
4
|
+
# The interval between a just major third (5:4) and a Pythogorean third (81:64). ~22 cents
|
5
|
+
syntonic: 81/80
|
6
|
+
# Difference between the syntonic and ditonic commas. ~2 cents
|
7
|
+
schisma: 32805/32768
|
8
|
+
diaschisma: 2048/2025
|
9
|
+
dieses1: 648/625
|
10
|
+
dieses2: 128/125
|
11
|
+
septimal: 64/63
|
data/lib/tonal/approximations.rb
CHANGED
@@ -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).
|
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/comma.rb
ADDED
@@ -0,0 +1,45 @@
|
|
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
|
+
#
|
10
|
+
def self.commas
|
11
|
+
@commas ||= JSON.parse(YAML::load_file("#{__dir__}/../../data/commas.yml", aliases: true).to_json)["commas"]
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Array] of comma values
|
15
|
+
# @example
|
16
|
+
# Tonal::Comma.values
|
17
|
+
# => [(531441/524288),
|
18
|
+
# (81/80),
|
19
|
+
# (32805/32768),
|
20
|
+
# ...]
|
21
|
+
#
|
22
|
+
def self.values
|
23
|
+
@values ||= commas.values.map(&:to_r)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Array] of comma keys
|
27
|
+
# @example
|
28
|
+
# Tonal::Comma.keys
|
29
|
+
# => ["ditonic",
|
30
|
+
# "syntonic",
|
31
|
+
# "schisma",
|
32
|
+
# ...]
|
33
|
+
#
|
34
|
+
def self.keys
|
35
|
+
@keys ||= commas.keys
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Rational] the comma found in the repo
|
39
|
+
# @example
|
40
|
+
# Tonal::Comma.ditonic => (531441/524288)
|
41
|
+
#
|
42
|
+
def self.method_missing(comma)
|
43
|
+
commas[comma.to_s].to_r
|
44
|
+
end
|
45
|
+
end
|
data/lib/tonal/ratio.rb
CHANGED
@@ -469,12 +469,12 @@ class Tonal::Ratio
|
|
469
469
|
# Return label, if defined; or,
|
470
470
|
# Return the "antecedent/consequent", if antecedent is less than 7 digits long; or
|
471
471
|
# Return the floating point representation rounded to 2 digits of precision
|
472
|
-
@label || ((Math.log10(antecedent).to_i + 1) <= 6 ? "#{antecedent}/#{consequent}" : to_f.round(2))
|
472
|
+
(@label || ((Math.log10(antecedent).to_i + 1) <= 6 ? "#{antecedent}/#{consequent}" : to_f.round(2))).to_s
|
473
473
|
end
|
474
474
|
|
475
475
|
# @return [String] the string representation of Tonal::Ratio
|
476
476
|
# @example
|
477
|
-
# Tonal::Ratio.new(3, 2).inspect => "
|
477
|
+
# Tonal::Ratio.new(3, 2).inspect => "(3/2)"
|
478
478
|
#
|
479
479
|
def inspect
|
480
480
|
"(#{antecedent}/#{consequent})"
|
data/lib/tonal/tools.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
module Tonal
|
2
|
+
require "yaml"
|
3
|
+
require "json"
|
2
4
|
require "prime"
|
3
5
|
require "matrix"
|
4
6
|
require "sorted_set"
|
5
7
|
require "continued_fractions"
|
6
8
|
require "fraction_tree"
|
9
|
+
require "tonal/comma"
|
7
10
|
require "tonal/cents"
|
8
11
|
require "tonal/hertz"
|
9
12
|
require "tonal/log"
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tonal-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yaml
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.6'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: prime
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,28 +86,28 @@ dependencies:
|
|
58
86
|
requirements:
|
59
87
|
- - "~>"
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
89
|
+
version: '2.0'
|
62
90
|
type: :runtime
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
96
|
+
version: '2.0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: fraction-tree
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - "~>"
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
103
|
+
version: '1.0'
|
76
104
|
type: :runtime
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
110
|
+
version: '1.0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: rspec
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,8 +157,10 @@ executables: []
|
|
129
157
|
extensions: []
|
130
158
|
extra_rdoc_files: []
|
131
159
|
files:
|
160
|
+
- data/commas.yml
|
132
161
|
- lib/tonal/approximations.rb
|
133
162
|
- lib/tonal/cents.rb
|
163
|
+
- lib/tonal/comma.rb
|
134
164
|
- lib/tonal/extensions.rb
|
135
165
|
- lib/tonal/hertz.rb
|
136
166
|
- lib/tonal/interval.rb
|
@@ -153,12 +183,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
183
|
requirements:
|
154
184
|
- - ">="
|
155
185
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
186
|
+
version: 3.1.2
|
157
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
188
|
requirements:
|
159
189
|
- - ">="
|
160
190
|
- !ruby/object:Gem::Version
|
161
|
-
version: '
|
191
|
+
version: '3.1'
|
162
192
|
requirements: []
|
163
193
|
rubygems_version: 3.4.22
|
164
194
|
signing_key:
|