ruby-mext 0.8.0 → 0.9.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/.gitignore +1 -0
- data/lib/mext/music/pitch_class.rb +130 -0
- data/lib/mext/music.rb +9 -0
- data/lib/mext.rb +1 -0
- data/lib/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294779db24d6436cc838a41d8673fe440180e95a4dddf2e8cfa0ad6d70998552
|
4
|
+
data.tar.gz: c456b20be223a8b47589f9b9495465add2d50a3afa0063ec0634c27884ea2ce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 563369c90b8d73a3f10b070e67051b870ff672ac8dd28ce79a5acac3d94c5aec041e590b42ce2361fe4e6483808c27e6bdaef368cb213f0328d551b5a88754a8
|
7
|
+
data.tar.gz: fd9e7b2c50a2ebb6b7da7f640a6f2aff96887a50194895cfbedbff0c31606640bacf62ef1e4265800af81836fc814a7965deba9c813f140126d2f5f019285524
|
data/.gitignore
CHANGED
@@ -0,0 +1,130 @@
|
|
1
|
+
module Mext
|
2
|
+
module Music
|
3
|
+
|
4
|
+
class PitchClass
|
5
|
+
|
6
|
+
attr_reader :octave, :semi
|
7
|
+
|
8
|
+
#
|
9
|
+
# +Mext::Music::PitchClass.new(float_value):
|
10
|
+
#
|
11
|
+
# pitch class object, where argument is:
|
12
|
+
#
|
13
|
+
# +float_value+: a pitch class in float notation (i.e. 8.00 for middle C, etc.)
|
14
|
+
#
|
15
|
+
#:nodoc:
|
16
|
+
def initialize(fv)
|
17
|
+
setup(fv)
|
18
|
+
end
|
19
|
+
|
20
|
+
#:doc:
|
21
|
+
#
|
22
|
+
# +to_f+
|
23
|
+
#
|
24
|
+
# returns the +pitch class+ in float notation
|
25
|
+
#
|
26
|
+
#:nodoc:
|
27
|
+
def to_f
|
28
|
+
#
|
29
|
+
# we suppose here that the pitch_class data is well-formed inside the
|
30
|
+
# object
|
31
|
+
#
|
32
|
+
self.octave + (self.semi / 100.0)
|
33
|
+
end
|
34
|
+
|
35
|
+
#:doc:
|
36
|
+
#
|
37
|
+
# +to_freq+
|
38
|
+
#
|
39
|
+
# returns the +pitch class+ in frequency (Hz)
|
40
|
+
#
|
41
|
+
#:nodoc:
|
42
|
+
def to_freq
|
43
|
+
self.to_f.pchcps
|
44
|
+
end
|
45
|
+
|
46
|
+
#:doc:
|
47
|
+
#
|
48
|
+
# all logical operators
|
49
|
+
#
|
50
|
+
#
|
51
|
+
#:nodoc:
|
52
|
+
[:>, :>=, :<, :<=, :<=>, :==, :!=, :=== ].each do
|
53
|
+
|op|
|
54
|
+
define_method(op) { |other| self.to_freq.send(op, other.to_freq) }
|
55
|
+
end
|
56
|
+
|
57
|
+
#:doc:
|
58
|
+
#
|
59
|
+
# +\+(other)+ (operator plus)
|
60
|
+
#
|
61
|
+
# sums two pitch classes
|
62
|
+
#
|
63
|
+
#
|
64
|
+
#:nodoc:
|
65
|
+
def +(other)
|
66
|
+
PitchClass.new((self.to_freq + other.to_freq).cpspch)
|
67
|
+
end
|
68
|
+
|
69
|
+
#:doc:
|
70
|
+
#
|
71
|
+
# +-(other)+ (operator minus)
|
72
|
+
#
|
73
|
+
# subtracts two pitch classes
|
74
|
+
#
|
75
|
+
#
|
76
|
+
#:nodoc:
|
77
|
+
def -(other)
|
78
|
+
PitchClass.new((self.to_freq - other.to_freq).cpspch)
|
79
|
+
end
|
80
|
+
|
81
|
+
#:doc:
|
82
|
+
#
|
83
|
+
# +to_semitones+
|
84
|
+
#
|
85
|
+
# returns the +PitchClass+ to a number of semitones
|
86
|
+
#
|
87
|
+
def to_semitones
|
88
|
+
(self.octave * 12.0) + self.semi
|
89
|
+
end
|
90
|
+
|
91
|
+
#:doc:
|
92
|
+
#
|
93
|
+
# +interval(other)+
|
94
|
+
#
|
95
|
+
# computes the interval among two pitch classes (in
|
96
|
+
# number of semitones and fractions thereof)
|
97
|
+
#
|
98
|
+
#:nodoc:
|
99
|
+
def interval(other)
|
100
|
+
other.to_semitones - self.to_semitones
|
101
|
+
end
|
102
|
+
|
103
|
+
class << self
|
104
|
+
|
105
|
+
#:doc:
|
106
|
+
#
|
107
|
+
# +from_freq+
|
108
|
+
#
|
109
|
+
# returns a +pitch class+ object from a frequency (Hz)
|
110
|
+
#
|
111
|
+
#:nodoc:
|
112
|
+
def from_freq(f)
|
113
|
+
new(f.cpspch)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def setup(fval)
|
121
|
+
@octave = fval.floor
|
122
|
+
s = (fval-@octave) * 100.0
|
123
|
+
@octave += (s/12.0).floor
|
124
|
+
@semi = s % 12.0
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
data/lib/mext/music.rb
ADDED
data/lib/mext.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.9.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-
|
11
|
+
date: 2019-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,6 +123,8 @@ files:
|
|
123
123
|
- lib/mext/math/function.rb
|
124
124
|
- lib/mext/math/line.rb
|
125
125
|
- lib/mext/math/stepwise.rb
|
126
|
+
- lib/mext/music.rb
|
127
|
+
- lib/mext/music/pitch_class.rb
|
126
128
|
- lib/mext/numeric.rb
|
127
129
|
- lib/mext/numeric/ampdb.rb
|
128
130
|
- lib/mext/numeric/cpspch.rb
|