ruby-mext 0.15.2 → 0.15.3

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: a96e593b1907f7f809ebf6749fcb08f4eb5df98776af5228f150e3fe61a7d72d
4
- data.tar.gz: 1be4db352142785ed91a8bc296730083abb8f1832d99b8462d6bcf0fd81d7078
3
+ metadata.gz: 8e05f91f8b3453a105147a9d4fc3ccf56cbb5c8b2ede5f4ab1e0cba89a659054
4
+ data.tar.gz: 1d28728e1a17b43e67099b01dc49e18cfa33cf53550b0056cc3a05017da173f4
5
5
  SHA512:
6
- metadata.gz: 389edc3a3a5a67485dbeb2e8b731cb178899d464f9527aa7fc0c6e09c0c949e04dcceef980082e1ea61887ecceb7dd83a80906ca83c62cbf76dfbd23312840a3
7
- data.tar.gz: dc027c5e60ca811cae9757fcb987e28d2952a25a9a5d256796c05a8664505d6187aba99bd0213125d0ce930190d449a1ec6bed4c853ff4f41c1e89136bc6369b
6
+ metadata.gz: df981d8cf1a992a21509e148f9fec04176ff1c6ffeb7040d36b775f8a513f8c64d8467085923f1b9aa1148c3eb078f5ae625d54bf01116cdceae3510837b9958
7
+ data.tar.gz: 88b73c56c537a049d89054b73ab2bc7af7ab126fa136d258ca183056ec34e8810d46f8d23bbdbc3bbe094be05bbbec7965cbf56120cd277f5e6fcd43eea750ac
@@ -97,11 +97,15 @@ module Mext
97
97
  #
98
98
  #
99
99
  #:nodoc:
100
- [:>, :>=, :<, :<=, :<=>, :==, :!=, :=== ].each do
100
+ [:>, :>=, :<, :<=, :<=>, :!=, :=== ].each do
101
101
  |op|
102
102
  define_method(op) { |other| self.inner_representation.send(op, other.inner_representation) }
103
103
  end
104
104
 
105
+ def ==(other)
106
+ self.inner_representation.cround == other.inner_representation.cround
107
+ end
108
+
105
109
  #:doc:
106
110
  #
107
111
  # +\+(other)+ (operator plus)
@@ -217,12 +221,14 @@ module Mext
217
221
  # as C4
218
222
  #
219
223
  #
220
- SEMI_NAMES = %w(C Cs D Ds E F Fs G Gs A As B Bs)
224
+ SEMI_NAMES = %w(C Cs D Ds E F Fs G Gs A As B)
221
225
  OCT_DIFF = 4
222
226
 
223
227
  def anglo_note_name
224
228
  oct = self.octave - OCT_DIFF
225
- name = SEMI_NAMES[self.semi.round]
229
+ s = self.semi.round
230
+ oct = self.inner_representation < 0.0 && s != 0.0 ? oct-1 : oct
231
+ name = SEMI_NAMES[s]
226
232
  "%s%d" % [ name, oct ]
227
233
  end
228
234
 
@@ -251,6 +257,24 @@ module Mext
251
257
  new(f.cpspch)
252
258
  end
253
259
 
260
+ #:doc:
261
+ #
262
+ # +find_by_anglo_name(anglo_name = 'C4')+
263
+ #
264
+ # creates a +PitchClass+ object passing a note name in anglosaxon
265
+ # notation (where +C4+ corresponds to +8.00+)
266
+ #
267
+ def find_by_anglo_name(anglo_name = 'C4')
268
+ anglo_name = anglo_name.upcase
269
+ raise ArgumentError, "malformed name #{anglo_name}" unless anglo_name.match?(/\A[A-G]S?\-?\d+\Z/)
270
+ note = anglo_name.sub(/\A([A-G]S?).*\Z/i, '\1')
271
+ upcased_names = SEMI_NAMES.map { |n| n.upcase }
272
+ semi = upcased_names.index(note)
273
+ oct = anglo_name.sub(/\A[A-G]S?(\-?\d+)\Z/, '\1').to_i + OCT_DIFF
274
+ # semi = oct <= 0 ? -semi : semi
275
+ new(oct, semi)
276
+ end
277
+
254
278
  end
255
279
 
256
280
  private
@@ -0,0 +1,17 @@
1
+ class Numeric
2
+
3
+ #
4
+ # +mround(digits = 0)+: round to the nearest +digit+ digits
5
+ #
6
+ # +mround+ will return a rounded number to the nearest digit indicated
7
+ # in its argument
8
+ #
9
+ #:nodoc:
10
+
11
+ def mround(digit = 0)
12
+ mul = (10**(digit)).to_f
13
+ res = (self * mul).round
14
+ res / mul
15
+ end
16
+
17
+ end
data/lib/mext/numeric.rb CHANGED
@@ -3,6 +3,7 @@ module Mext
3
3
 
4
4
  PATH = File.join(Mext::PATH, 'numeric')
5
5
  VECTORIZABLE_METHODS = %w(
6
+ mround
6
7
  cround
7
8
  mtof
8
9
  ftom
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mext
2
- VERSION = '0.15.2'
2
+ VERSION = '0.15.3'
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.15.2
4
+ version: 0.15.3
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-06-26 00:00:00.000000000 Z
11
+ date: 2019-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -139,6 +139,7 @@ files:
139
139
  - lib/mext/numeric/ftom.rb
140
140
  - lib/mext/numeric/gold.rb
141
141
  - lib/mext/numeric/mmtot.rb
142
+ - lib/mext/numeric/mround.rb
142
143
  - lib/mext/numeric/mtof.rb
143
144
  - lib/mext/numeric/mtopch.rb
144
145
  - lib/mext/numeric/pchcps.rb