ruby-mext 0.2.1 → 0.3.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: 9a8ef82a4d0e377ee67f260e3adc5f0aec0cf082abdf9f185f84cd596088f9af
4
- data.tar.gz: e477a325f72a4ac3034c888c78a6f36b2c4b08539ac5d4424977467f2bfea726
3
+ metadata.gz: e17fe59684741fe17bcb1115faf090621239cdc7afb3823a3601ae7b8e643449
4
+ data.tar.gz: 670b6028c1a79e8feaac202c9ddb3da4f07f5d72e93a3a5d862e3a9f9ce58e7a
5
5
  SHA512:
6
- metadata.gz: a394a770eb6b7d0babb8ddeeaed4e9a88e52644b9cf5cbd008d124ba68b700cbc9c388023ccd5b4af2461870bcc96616e28c25549a3aeee646ff399dba63e196
7
- data.tar.gz: 3f829693124772fc1e77080223914da0a9a525fa7f1ed191340d99c4a905d9a1d2855baae28b8dec3c2559b345f09f63dd8c669c0c353077ab415f68cdeefb15
6
+ metadata.gz: a09e8d92256aadcd2bbfe12fa3ec7caffb4c33c2213f7e1e5843a810cef484c580b39db9c064f0da2a83c562c63e0b51d06e1a391343903777f5bc23192baa6e
7
+ data.tar.gz: 7e5414a0aa5f5790286825e2acf7c800e3a43b8d315b29df1a35bb8f7d97c8587909dba9d62f256d8431ad63935aa9313c14d488f9ac66bb6581521481245c9e
data/.gitignore CHANGED
@@ -7,4 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- .byebug_history
10
+ /.byebug_history
11
+ /.rake_tasks~
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/nicb/ruby-mext.svg?branch=master)](https://travis-ci.org/nicb/ruby-mext)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/53686892aa9ee6a30ebb/maintainability)](https://codeclimate.com/github/nicb/ruby-mext/maintainability)
5
+ [![Gem Version](https://badge.fury.io/rb/ruby-mext.svg)](https://badge.fury.io/rb/ruby-mext)
5
6
 
6
7
  These are extensions of usual idiomatic `ruby` objects (i.e. `Numeric`,
7
8
  `Array`, etc.) that make `ruby` a comfortable language for musicians.
@@ -1,4 +1,4 @@
1
- class Numeric
1
+ module Mext
2
2
 
3
3
  #
4
4
  # +NegativeNumeric+ is raised on certain operations that do not allow
@@ -6,4 +6,10 @@ class Numeric
6
6
  #
7
7
  class NegativeNumeric < StandardError; end
8
8
 
9
+ #
10
+ # +PureAbstractMethodCalled+ is raised when an abstract
11
+ # base class is called
12
+ #
13
+ class PureAbstractMethodCalled < StandardError; end
14
+
9
15
  end
@@ -2,9 +2,9 @@ require 'cmath'
2
2
 
3
3
  module Math
4
4
 
5
- class Expon
5
+ class Expon < Function
6
6
 
7
- attr_reader :y_start, :y_end, :x_start, :x_end, :tau
7
+ attr_reader :y_start, :y_end, :tau
8
8
  attr_reader :a, :b, :c
9
9
 
10
10
  #
@@ -47,28 +47,6 @@ module Math
47
47
  (CMath::exp(self.a*x + self.b) + self.c).abs # we want a real number result, no complex please
48
48
  end
49
49
 
50
- #:doc:
51
- #
52
- # +xy(step)+
53
- #
54
- # Returns a full deployment of the function evaluated with a step of
55
- # +step+. It is returned in two arrays - one for the +x+ values and the
56
- # other for the +y+ values.
57
- #
58
- # This method is mainly for testing purposes with the dataxy method of +gruff+
59
- #
60
- #:nodoc:
61
- def xy(s)
62
- resx = []
63
- resy = []
64
- self.x_start.step(x_end, s) do
65
- |x|
66
- resx << x
67
- resy << self.y(x)
68
- end
69
- [resx, resy]
70
- end
71
-
72
50
  private
73
51
 
74
52
  def setup
@@ -0,0 +1,56 @@
1
+ module Math
2
+
3
+ class Function
4
+
5
+ attr_reader :x_start, :x_end
6
+ #
7
+ # +Math::Function.new+:
8
+ #
9
+ # abstract base class function
10
+ #
11
+ #:nodoc:
12
+ def initialize
13
+ setup
14
+ end
15
+
16
+ #:doc:
17
+ #
18
+ # +y(x)+:
19
+ #
20
+ # Returns a real value given x
21
+ #
22
+ #:nodoc:
23
+ def y(x)
24
+ end
25
+
26
+ #:doc:
27
+ #
28
+ # +xy(step)+
29
+ #
30
+ # Returns a full deployment of the function evaluated with a step of
31
+ # +step+. It is returned in two arrays - one for the +x+ values and the
32
+ # other for the +y+ values.
33
+ #
34
+ # This method is mainly for testing purposes with the dataxy method of +gruff+
35
+ #
36
+ #:nodoc:
37
+ def xy(s)
38
+ resx = []
39
+ resy = []
40
+ self.x_start.step(x_end, s) do
41
+ |x|
42
+ resx << x
43
+ resy << self.y(x)
44
+ end
45
+ [resx, resy]
46
+ end
47
+
48
+ private
49
+
50
+ def setup
51
+ raise Mext::PureAbstractMethodCalled
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,51 @@
1
+ module Math
2
+
3
+ class Line < Function
4
+
5
+ attr_reader :y_start, :y_end
6
+ attr_reader :a, :b
7
+
8
+ #
9
+ # +Math::Line.new(ystart, yend, xstart, xend)+:
10
+ #
11
+ # linear interpolation `y = a*x + b` where:
12
+ #
13
+ # `a = (yend-ystart)/(xend-xstart)`
14
+ # `b = ystart - (a*xstart)`
15
+ #
16
+ # Arguments are:
17
+ #
18
+ # +ystart+, +yend+: start/end y values required
19
+ # +xstart+, +xend+: start/end x values
20
+ #
21
+ #:nodoc:
22
+ def initialize(ys, ye, xs, xe)
23
+ @y_start = ys.to_f
24
+ @y_end = ye.to_f
25
+ @x_start = xs.to_f
26
+ @x_end = xe.to_f
27
+ setup
28
+ end
29
+
30
+ #:doc:
31
+ #
32
+ # +y(x)+:
33
+ #
34
+ # Returns a real value given x
35
+ #
36
+ #:nodoc:
37
+ def y(x)
38
+ (self.a*x) + self.b
39
+ end
40
+
41
+ private
42
+
43
+ def setup
44
+ @a = (self.y_end - self.y_start)/(self.x_end - self.x_start)
45
+ @b = (self.y_start - (self.x_start * self.a))
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
data/lib/mext/math.rb CHANGED
@@ -5,5 +5,7 @@ module Mext
5
5
  end
6
6
 
7
7
  %w(
8
+ function
9
+ line
8
10
  expon
9
11
  ).each { |f| require File.join(Mext::MATH_PATH, f) }
@@ -6,7 +6,7 @@ class Numeric
6
6
  # interprets its receiver as a linear value and returns it in dB
7
7
  #
8
8
  def ampdb
9
- raise NegativeNumeric if self < 0.0
9
+ raise Mext::NegativeNumeric if self < 0.0
10
10
  20*Math::log10(self)
11
11
  end
12
12
 
@@ -8,7 +8,7 @@ class Numeric
8
8
  #:nodoc:
9
9
 
10
10
  def cpspch
11
- raise NegativeNumeric if self <= 0.0
11
+ raise Mext::NegativeNumeric if self <= 0.0
12
12
 
13
13
  midi_note = self.ftom
14
14
 
@@ -7,7 +7,7 @@ class Numeric
7
7
  #
8
8
 
9
9
  def ftom
10
- raise NegativeNumeric if self < 0.0
10
+ raise Mext::NegativeNumeric if self < 0.0
11
11
  MIDI_PITCH_FORK + (12.0*Math::log2(self/self.class.pitch_fork))
12
12
  end
13
13
 
data/lib/mext/numeric.rb CHANGED
@@ -5,7 +5,6 @@ module Mext
5
5
  end
6
6
 
7
7
  %w(
8
- exceptions
9
8
  pitch_fork
10
9
  mtof
11
10
  ftom
data/lib/mext.rb CHANGED
@@ -5,6 +5,7 @@ module Mext
5
5
  end
6
6
 
7
7
  %w(
8
+ exceptions
8
9
  numeric
9
10
  array
10
11
  math
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mext
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.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.2.1
4
+ version: 0.3.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-22 00:00:00.000000000 Z
11
+ date: 2019-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,13 +116,15 @@ files:
116
116
  - lib/mext.rb
117
117
  - lib/mext/array.rb
118
118
  - lib/mext/array/choose.rb
119
+ - lib/mext/exceptions.rb
119
120
  - lib/mext/math.rb
120
121
  - lib/mext/math/expon.rb
122
+ - lib/mext/math/function.rb
123
+ - lib/mext/math/line.rb
121
124
  - lib/mext/numeric.rb
122
125
  - lib/mext/numeric/ampdb.rb
123
126
  - lib/mext/numeric/cpspch.rb
124
127
  - lib/mext/numeric/dbamp.rb
125
- - lib/mext/numeric/exceptions.rb
126
128
  - lib/mext/numeric/ftom.rb
127
129
  - lib/mext/numeric/mtof.rb
128
130
  - lib/mext/numeric/mtopch.rb