coltrane 3.2.0 → 3.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: 389f01b2c9f2a783e912534f02c9b0a1506f3c9bb4274f3c08c7e94eb18559d6
4
- data.tar.gz: d2550c127ae11b1798559d41195b3905c6481019195e1a634e54386e14e66215
3
+ metadata.gz: 2d2c4c2f31729c93b6b3e8a37715d3686210da80970f4f42ea5205e8e39f029c
4
+ data.tar.gz: 376e9ca70b7b63896ea315383695a26b624a6bf90e5397776e8700104de078a9
5
5
  SHA512:
6
- metadata.gz: 8a5ee68e12b83f27ea1f0da1e74efad208548a6d1376bcc75e828f64c777b24964ac1ce40ee7a9df1e9c9555e3228565335e233938f68231cd656eb64e14057f
7
- data.tar.gz: 4b84d5abe27a48bf6dff5942860d16be8ae77b18cccff75f507eee1f5de078a8caac1b31fb7333b83181b08b4a7af44241c9ba7a3f8e63288c397e520edd8add
6
+ metadata.gz: 52459e563498115c43f5e69c7da097102c598ef941beb5917df7c3867bf850616ed54978fb6119d6443e6e129255a916e7b4f2583e51dc8a6013134d0e69fbae
7
+ data.tar.gz: 458eba1dfdfdb95a535b6dd2520ce32bec09aa3ef98aa1f6482855ca878071ebebd818cfd4a75fd3ff30060101196bbc9f438db2dfc5a3ba7d3120533e9bf0c2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coltrane (3.2.0)
4
+ coltrane (3.3.0)
5
5
  color (~> 1.8)
6
6
  dry-monads (~> 0.4)
7
7
  paint (~> 2.0)
@@ -39,19 +39,19 @@ module Coltrane
39
39
  end
40
40
 
41
41
  def rank
42
- +completeness * 10_000 +
43
- +fullness * 1000 +
44
- -spreadness * 100 +
45
- +easyness * 1
42
+ +completeness * 10_000 +
43
+ +fullness * 1_000 +
44
+ -spreadness * 10 +
45
+ -discontinuity * 1 +
46
+ +easyness * 1
46
47
  end
47
48
 
48
49
  def analysis
49
- {
50
- completeness: completeness,
51
- fullness: fullness,
52
- easyness: easyness,
53
- spreadness: spreadness
54
- }
50
+ %i[completeness discontinuity fullness spreadness easyness]
51
+ .reduce({}) do |output, criteria|
52
+ output.merge(criteria => send(criteria).round(2))
53
+ end
54
+ .merge(rank: rank.round(4))
55
55
  end
56
56
 
57
57
  def spreadness
@@ -70,6 +70,10 @@ module Coltrane
70
70
  (guitar.strings.size.to_f - frets.count(nil)) / guitar.strings.size
71
71
  end
72
72
 
73
+ def discontinuity
74
+ voicing.discontinuity
75
+ end
76
+
73
77
  def barre?
74
78
  !@barre.nil?
75
79
  end
@@ -153,12 +157,14 @@ module Coltrane
153
157
  [(0 unless barre?)].compact
154
158
  end
155
159
 
156
- def to_s
157
- guitar_notes.map { |n| n.fret.nil? ? 'x' : n.fret }.join('-')
160
+ def to_s(debug = false)
161
+ guitar_notes.map {
162
+ |n| n.fret.nil? ? 'x' : n.fret
163
+ }.join('-') + (debug ? ' ' + analysis.to_s : '')
158
164
  end
159
165
 
160
166
  def voicing
161
- Coltrane::Voicing.new(pitches: guitar_notes.map(&:pitch).compact)
167
+ Theory::Voicing.new(pitches: guitar_notes.map(&:pitch).compact)
162
168
  end
163
169
 
164
170
  private
@@ -3,12 +3,17 @@
3
3
  module Coltrane
4
4
  module Theory
5
5
  class Frequency
6
+ include Comparable
6
7
  attr_reader :frequency
7
8
 
8
9
  def initialize(frequency)
9
10
  @frequency = frequency.to_f
10
11
  end
11
12
 
13
+ def <=>(other)
14
+ to_f <=> other.to_f
15
+ end
16
+
12
17
  class << self
13
18
  alias [] new
14
19
  end
@@ -4,6 +4,7 @@ module Coltrane
4
4
  module Theory
5
5
  # It describes a pitch, like E4 or Bb5. It's like a note, but it has an octave
6
6
  class Pitch
7
+ include Comparable
7
8
  attr_reader :integer
8
9
 
9
10
  def initialize(notation_arg = nil,
@@ -29,6 +30,10 @@ module Coltrane
29
30
  new *args
30
31
  end
31
32
 
33
+ def <=>(other)
34
+ integer <=> other.integer
35
+ end
36
+
32
37
  def scientific_notation
33
38
  "#{pitch_class}#{octave}"
34
39
  end
@@ -5,16 +5,19 @@ module Coltrane
5
5
  # This class describes an actual implementation of a Chord, being aware
6
6
  # of exact octaves of each pitch and even repeating pitches across octaves.
7
7
  class Voicing
8
+
8
9
  attr_reader :pitches
9
10
 
10
11
  def initialize(*pitch_strings, pitches: nil)
11
- @pitches = if pitch_strings.any?
12
- pitch_strings.map { |s| Pitch[s] }
13
- elsif pitches
14
- pitches
15
- else
16
- raise WrongArgumentsError
17
- end
12
+ @pitches = begin
13
+ if pitch_strings.any?
14
+ pitch_strings.map { |s| Pitch[s] }
15
+ elsif pitches
16
+ pitches
17
+ else
18
+ raise WrongArgumentsError
19
+ end
20
+ end.sort
18
21
  end
19
22
 
20
23
  def self.[](*args)
@@ -34,8 +37,22 @@ module Coltrane
34
37
  end
35
38
 
36
39
  def frequencies
37
- pitches.map(&:frequency)
40
+ @frequencies ||= pitches.map(&:frequency)
41
+ end
42
+
43
+ def discontinuity
44
+ frequencies.each_with_index.reduce(0) do |max_dist, (freq, index)|
45
+ next 0 if index.zero?
46
+ [max_dist, freq.to_f - frequencies[index - 1].to_f].max
47
+ end
38
48
  end
49
+
50
+ private
51
+
52
+ def ideal_frequency_distance
53
+ (Pitch['D3'].frequency - Pitch['A2'].frequency).to_f
54
+ end
55
+
39
56
  end
40
57
  end
41
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coltrane
4
- VERSION = '3.2.0'
4
+ VERSION = '3.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coltrane
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Maciel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-reader