ruby-mext 0.9.1 → 0.10.0
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/mext/music/pitch_class.rb +20 -3
- data/lib/mext/numeric/constants.rb +8 -2
- data/lib/mext/numeric/cround.rb +18 -0
- data/lib/mext/numeric/mtopch.rb +2 -18
- data/lib/mext/numeric/pchtom.rb +1 -10
- data/lib/mext/numeric/pchtooctsemi.rb +24 -0
- data/lib/mext/numeric/pchtosemi.rb +18 -0
- data/lib/mext/numeric/semitopch.rb +23 -0
- data/lib/mext/numeric.rb +4 -0
- data/lib/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 765a069de73dccde01080cc08b7dc773781bc26f5dd5f3181a4d01e1bbdd04f2
|
4
|
+
data.tar.gz: bd1a550f9cce944c99c0fdd863696d99784eca0536278d19ec7768df45a775b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3de1073d0fb33c9dd5a1fd29eae1ea17ede3915a644478ed452780de20e75c2fe3ea15464fab9515e0c0c9331e83e879a77c55f382d156443c96022143a2016
|
7
|
+
data.tar.gz: c601e4e6f42b862f06238878a2a55bed482311851fc05e8b30c74f3904ed24ae202d9c61c963d73e3bef6929661494533de7ad8409c4a95186a52c1caefc2e45
|
@@ -66,9 +66,9 @@ module Mext
|
|
66
66
|
#
|
67
67
|
#:nodoc:
|
68
68
|
def +(other)
|
69
|
-
octave = (self.to_semitones + other.to_semitones) / 12.0
|
69
|
+
octave = ((self.to_semitones + other.to_semitones) / 12.0).cround
|
70
70
|
octave = octave >= 0.0 ? octave.floor : octave.ceil
|
71
|
-
semis = (self.to_semitones + other.to_semitones) % 12.0
|
71
|
+
semis = (self.to_semitones + other.to_semitones).cround % 12.0
|
72
72
|
phase = octave >= 0.0 ? 1 : -1
|
73
73
|
PitchClass.new(octave, phase*semis)
|
74
74
|
end
|
@@ -93,7 +93,7 @@ module Mext
|
|
93
93
|
# returns the +PitchClass+ to a number of semitones
|
94
94
|
#
|
95
95
|
def to_semitones
|
96
|
-
|
96
|
+
self.to_f.pchtosemi
|
97
97
|
end
|
98
98
|
|
99
99
|
#:doc:
|
@@ -119,6 +119,19 @@ module Mext
|
|
119
119
|
self + PitchClass.new(0.0, semi)
|
120
120
|
end
|
121
121
|
|
122
|
+
#:doc:
|
123
|
+
#
|
124
|
+
# +interval_proportion(prop, other)+:
|
125
|
+
#
|
126
|
+
# returns the interval proportion (in semitones) given
|
127
|
+
#
|
128
|
+
# - +prop+: a proportional factor (should be in the range 0-1)
|
129
|
+
# - +other+: the other pitch
|
130
|
+
#
|
131
|
+
def interval_proportion(prop, other)
|
132
|
+
self.interval(other) * prop
|
133
|
+
end
|
134
|
+
|
122
135
|
class << self
|
123
136
|
|
124
137
|
#:doc:
|
@@ -135,6 +148,10 @@ module Mext
|
|
135
148
|
end
|
136
149
|
|
137
150
|
private
|
151
|
+
|
152
|
+
def setup_with_one_semitone_argument(semival)
|
153
|
+
setup_with_one_argument(semival.semitopch)
|
154
|
+
end
|
138
155
|
|
139
156
|
def setup_with_one_argument(fval)
|
140
157
|
(o, s) = separate_oct_semi(fval)
|
@@ -19,11 +19,17 @@ class Numeric
|
|
19
19
|
#
|
20
20
|
CHROMATIC_NOTES_PER_OCTAVE = CNPO = 12.0
|
21
21
|
|
22
|
+
#
|
23
|
+
# +ZERO_PITCH+ (short: +ZP+): where does the +0.00+ pitch-class reside
|
24
|
+
# in terms of semitones (+96)
|
25
|
+
#
|
26
|
+
ZERO_PITCH = ZP = PITCH_MIDDLE_C * CNPO
|
27
|
+
|
22
28
|
#
|
23
29
|
# +ZERO_MIDI_PITCH+ (short: +ZMP+): where does the +0.00+ pitch-class reside
|
24
|
-
# in terms of midi notes
|
30
|
+
# in terms of midi notes (-36)
|
25
31
|
#
|
26
|
-
ZERO_MIDI_PITCH = ZMP = MIDI_MIDDLE_C -
|
32
|
+
ZERO_MIDI_PITCH = ZMP = MIDI_MIDDLE_C - ZERO_PITCH
|
27
33
|
|
28
34
|
#
|
29
35
|
# +PITCH_CLASS_CENTS+ (short: +PCC+): the number of parts in every semitone
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Numeric
|
2
|
+
|
3
|
+
#
|
4
|
+
# +cround(eps = 1e-8)+: conditional rounding algorithm
|
5
|
+
#
|
6
|
+
# +cround+ will return a rounded number if the starting value is nearer to
|
7
|
+
# its nearest integer by less than +eps+. Otherwise it will not round
|
8
|
+
# the receiver
|
9
|
+
#
|
10
|
+
#:nodoc:
|
11
|
+
DEFAULT_CROUND_EPS = 1e-8
|
12
|
+
|
13
|
+
def cround(eps = DEFAULT_CROUND_EPS)
|
14
|
+
rv = self.round
|
15
|
+
((self - rv).abs < eps) ? rv : self
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/mext/numeric/mtopch.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
class Numeric
|
2
2
|
|
3
|
+
#:doc:
|
3
4
|
#
|
4
5
|
# +mtopch+: MIDI note to pitch class converter
|
5
6
|
#
|
@@ -9,24 +10,7 @@ class Numeric
|
|
9
10
|
|
10
11
|
def mtopch
|
11
12
|
|
12
|
-
|
13
|
-
oct = semi.to_i
|
14
|
-
semi = (semi - oct) * CNPO
|
15
|
-
semi %= CNPO
|
16
|
-
semi = (self > ZMP) ? semi : -((CNPO - semi) % CNPO)
|
17
|
-
|
18
|
-
oct + (semi / PCC)
|
19
|
-
|
20
|
-
# intv = self - MIDI_MIDDLE_C
|
21
|
-
# intv /= CHROMATIC_NOTES_PER_OCTAVE
|
22
|
-
|
23
|
-
# intv_octave = intv.floor
|
24
|
-
# intv_semi = (intv_octave >= 0.0) ? (intv - intv_octave) : (1 - (intv_octave - intv))
|
25
|
-
#
|
26
|
-
# intv_semi *= CHROMATIC_NOTES_PER_OCTAVE;
|
27
|
-
# intv_semi %= CHROMATIC_NOTES_PER_OCTAVE;
|
28
|
-
|
29
|
-
# PITCH_MIDDLE_C + intv_octave + (intv_semi/100.0);
|
13
|
+
(self - ZMP).semitopch
|
30
14
|
|
31
15
|
end
|
32
16
|
|
data/lib/mext/numeric/pchtom.rb
CHANGED
@@ -8,16 +8,7 @@ class Numeric
|
|
8
8
|
#:nodoc:
|
9
9
|
|
10
10
|
def pchtom
|
11
|
-
|
12
|
-
p_note = (self - p_octave) * 100
|
13
|
-
ref = self < 0.0 ? -CHROMATIC_NOTES_PER_OCTAVE : CHROMATIC_NOTES_PER_OCTAVE
|
14
|
-
|
15
|
-
p_octave += (p_note / CHROMATIC_NOTES_PER_OCTAVE).to_i # cater for octave wrapping
|
16
|
-
p_note = (p_note % ref); # reduce note in a 0-11 space (keeping track of sign)
|
17
|
-
|
18
|
-
m_octave = ((p_octave - PITCH_MIDDLE_C)*CHROMATIC_NOTES_PER_OCTAVE) + MIDI_MIDDLE_C; # find the appropriate midi octave
|
19
|
-
|
20
|
-
m_octave + p_note
|
11
|
+
self.pchtosemi + ZMP
|
21
12
|
end
|
22
13
|
|
23
14
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Numeric
|
2
|
+
|
3
|
+
#:doc:
|
4
|
+
#
|
5
|
+
# +pchtooctsemi+: pitch class to [octave, semitones] converter
|
6
|
+
#
|
7
|
+
# interprets its receiver as a pitch class and returns an array
|
8
|
+
# in the format [+octave+, +semitones+]
|
9
|
+
#
|
10
|
+
#:nodoc:
|
11
|
+
|
12
|
+
def pchtooctsemi
|
13
|
+
p_octave = self.to_i
|
14
|
+
p_note = (self - p_octave) * 100
|
15
|
+
ref = self < 0.0 ? -CHROMATIC_NOTES_PER_OCTAVE : CHROMATIC_NOTES_PER_OCTAVE
|
16
|
+
|
17
|
+
p_octave += (p_note / CHROMATIC_NOTES_PER_OCTAVE).to_i # cater for octave wrapping
|
18
|
+
p_note = (p_note % ref); # reduce note in a 0-11 space (keeping track of sign)
|
19
|
+
|
20
|
+
[p_octave, p_note]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Numeric
|
2
|
+
|
3
|
+
#:doc:
|
4
|
+
#
|
5
|
+
# +pchtosemi+: pitch class to semitones converter
|
6
|
+
#
|
7
|
+
# interprets its receiver as a pitch class and returns the
|
8
|
+
# corresponding quantity in semitones
|
9
|
+
#
|
10
|
+
#:nodoc:
|
11
|
+
|
12
|
+
def pchtosemi
|
13
|
+
(p_octave, p_note) = self.pchtooctsemi
|
14
|
+
|
15
|
+
(p_octave * CNPO) + p_note
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Numeric
|
2
|
+
|
3
|
+
#:doc:
|
4
|
+
#
|
5
|
+
# +semitopch+: semitone to pitch class converter
|
6
|
+
#
|
7
|
+
# interprets its receiver as a semitone quantity (starting from 0 at
|
8
|
+
# pitch class 0.00) and returns its corresponing pitch class
|
9
|
+
#
|
10
|
+
#:nodoc:
|
11
|
+
|
12
|
+
def semitopch
|
13
|
+
|
14
|
+
oct = (self / CNPO).to_i
|
15
|
+
semi = self - (oct * CNPO)
|
16
|
+
semi %= CNPO
|
17
|
+
semi = (self >= 0.0) ? semi : -((CNPO - semi) % CNPO)
|
18
|
+
|
19
|
+
oct + (semi / PCC)
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/mext/numeric.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicola Bernardini
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/mext/numeric/ampdb.rb
|
130
130
|
- lib/mext/numeric/constants.rb
|
131
131
|
- lib/mext/numeric/cpspch.rb
|
132
|
+
- lib/mext/numeric/cround.rb
|
132
133
|
- lib/mext/numeric/dbamp.rb
|
133
134
|
- lib/mext/numeric/ftom.rb
|
134
135
|
- lib/mext/numeric/gold.rb
|
@@ -137,8 +138,11 @@ files:
|
|
137
138
|
- lib/mext/numeric/mtopch.rb
|
138
139
|
- lib/mext/numeric/pchcps.rb
|
139
140
|
- lib/mext/numeric/pchtom.rb
|
141
|
+
- lib/mext/numeric/pchtooctsemi.rb
|
142
|
+
- lib/mext/numeric/pchtosemi.rb
|
140
143
|
- lib/mext/numeric/pitch_fork.rb
|
141
144
|
- lib/mext/numeric/rrand.rb
|
145
|
+
- lib/mext/numeric/semitopch.rb
|
142
146
|
- lib/ruby-mext.rb
|
143
147
|
- lib/ruby.rb
|
144
148
|
- lib/ruby/extensions.rb
|