ruby-mext 0.8.0 → 0.9.0

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: 8d72010c6b0800faf5a6ebedf92f50ec963935b718ed34e2695b5fae0f7b63b9
4
- data.tar.gz: c8a1ffbc2cbea66d52d9883be1bd93d0ec3c79e0cd8add0044d18a385099eb8f
3
+ metadata.gz: 294779db24d6436cc838a41d8673fe440180e95a4dddf2e8cfa0ad6d70998552
4
+ data.tar.gz: c456b20be223a8b47589f9b9495465add2d50a3afa0063ec0634c27884ea2ce7
5
5
  SHA512:
6
- metadata.gz: 041bc47c56ec3fe1fb53c693f50b6971e3fdc7587254c1b96a6e0bca947a6cb2cffa44c91ed4150a6c27283211319a14b34239d8602f05d99c3732a41d77ffa8
7
- data.tar.gz: 8526adedc36ffb1c7ebfa09756c410c5843046c180f359f27e9a46e876be29e3da0276e77032ae71fe1512cc7df5de423d7389bcc2261d8308c88fd603e7c091
6
+ metadata.gz: 563369c90b8d73a3f10b070e67051b870ff672ac8dd28ce79a5acac3d94c5aec041e590b42ce2361fe4e6483808c27e6bdaef368cb213f0328d551b5a88754a8
7
+ data.tar.gz: fd9e7b2c50a2ebb6b7da7f640a6f2aff96887a50194895cfbedbff0c31606640bacf62ef1e4265800af81836fc814a7965deba9c813f140126d2f5f019285524
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  /.byebug_history
11
11
  /.rake_tasks~
12
+ TODO
@@ -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
@@ -0,0 +1,9 @@
1
+ module Mext
2
+
3
+ MUSIC_PATH = File.join(Mext::PATH, 'music')
4
+
5
+ end
6
+
7
+ %w(
8
+ pitch_class
9
+ ).each { |f| require File.join(Mext::MUSIC_PATH, f) }
data/lib/mext.rb CHANGED
@@ -9,4 +9,5 @@ end
9
9
  numeric
10
10
  array
11
11
  math
12
+ music
12
13
  ).each { |f| require File.join(Mext::PATH, f) }
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mext
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
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.8.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-04-28 00:00:00.000000000 Z
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