wtf_chord 0.4.0 → 0.5.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
  SHA1:
3
- metadata.gz: ff26ad0548f061f6982cfa47df59f0ffff78b136
4
- data.tar.gz: 073b2e5c14ac65a19c6aa806f97467c618f10145
3
+ metadata.gz: b01a7a811a348cefa9b4e05c67d4ae4cb4af5f20
4
+ data.tar.gz: 814e86e9e218ab85ec3605bdf72c99bb632c22d3
5
5
  SHA512:
6
- metadata.gz: 40326155782d5c90b1e99f6b1e0d117d06d6c6b10139636fe7d27bcc5a9207c72073a205298e870405fd5af1aee6865ffb8271d80c3e47b940d86a65d54ca74b
7
- data.tar.gz: 33d25bb0f14caaa21278dfdce45ef553656c29a77eb29bab409c80910e3f7f5c2aeeb97e5b99f580c2f2949d4ca2c1359594ce80d0798bdc7fadde366ceac4ca
6
+ metadata.gz: ff5fe7b9623c92b26d74c01cccfda962196affa8a6e171975d39b91828cce3080e31ed3bc29d2fd208030c3ed47847b8a692367ef40ffe1f1bfda72f12ddb516
7
+ data.tar.gz: f9fbcb0adc02b779dc665cafef34466c4cf569e79eb0a8636e0c5e689e3c59f271b51f62fd75d05bb64ae21a6c9d0d1118ba273cb039d0127a25136a1bc70a6e
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ ## 0.5.0 / 2016-08-17
2
+
3
+ * 2 major features
4
+ * Support chords with bass string mods (like Am/G)
5
+ * Add extra_complexity modifier
6
+
7
+ * 1 bug fixes:
8
+ * Fix fingering equality
9
+
10
+ * Add CHANGELOG.md
@@ -3,26 +3,39 @@ require 'wtf_chord/fingerings_generator'
3
3
 
4
4
  module WTFChord
5
5
  class Chord
6
- attr_reader :pitch, :steps, :notes, :name
6
+ BASS_MATCH = /(?<=[\\\/])[A-H][b#]?(?=$)/
7
+
8
+ attr_reader :pitch, :steps, :notes, :name, :bass
7
9
 
8
10
  def initialize(note, name)
9
11
  @pitch = note.is_a?(Pitch) ? note : WTFChord.note(note)
10
12
  @name = "#{@pitch.key}#{name}".freeze
11
13
  @steps = Array(WTFChord.rules[name])
12
14
  @notes = @steps.map { |dist| (@pitch + dist).note }.tap(&:uniq!)
13
- end
14
15
 
15
- def inspect
16
- "#{name} (#{@notes.map(&:key) * ' - '})"
16
+ BASS_MATCH.match(@name) do |m|
17
+ @bass = WTFChord.note(m[0]).note
18
+ end
17
19
  end
18
20
 
19
21
  def fingerings(limit = nil)
20
- limit ||= 5
21
- FingeringsGenerator.new(self).call[0, limit]
22
+ FingeringsGenerator.new(self).call[0, limit || 5]
22
23
  end
23
24
 
24
25
  def third_tone
25
- @third_tone ||= @notes[@steps.index(7) || -1]
26
+ @third_tone ||= @notes[@steps.size > 3 ? 2 : -1]
27
+ end
28
+
29
+ def bass?
30
+ !!@bass
31
+ end
32
+
33
+ def original_bass
34
+ @notes[0]
35
+ end
36
+
37
+ def inspect
38
+ "#{name} (#{@notes.map(&:key) * ' - '})"
26
39
  end
27
40
  end
28
41
  end
@@ -28,7 +28,7 @@ module WTFChord
28
28
  end
29
29
  end
30
30
 
31
- base_rate
31
+ base_rate + @fingering.extra_complexity
32
32
  end
33
33
 
34
34
  private
@@ -4,15 +4,18 @@ require 'wtf_chord/formatter'
4
4
 
5
5
  module WTFChord
6
6
  class Fingering < Fretboard
7
+ attr_accessor :extra_complexity
8
+
7
9
  def initialize(guitar, fingers = nil)
8
10
  @capo = guitar.capo
9
11
  @strings = guitar.strings.map(&:dup)
12
+ @extra_complexity = 0.0
10
13
  set_fingers(fingers) if fingers.is_a?(Array)
11
14
  yield(self) if block_given?
12
15
  end
13
16
 
14
17
  def code
15
- @code ||= strings.map(&:code).pack("c*")
18
+ strings.map(&:code).pack("c*")
16
19
  end
17
20
 
18
21
  def == other
@@ -23,6 +26,14 @@ module WTFChord
23
26
  end
24
27
  end
25
28
 
29
+ def eql?(other)
30
+ super || self == other
31
+ end
32
+
33
+ def hash
34
+ strings.map(&:code).hash
35
+ end
36
+
26
37
  def complexity
27
38
  complexity_counter.rate
28
39
  end
@@ -43,6 +54,14 @@ module WTFChord
43
54
  @strings.reject(&:dead?)
44
55
  end
45
56
 
57
+ def find_used_string_for(note)
58
+ used = used_strings
59
+ if idx = used.index(note)
60
+ string = used[idx]
61
+ yield(strings.index(string), string)
62
+ end
63
+ end
64
+
46
65
  def min_fret
47
66
  holded_strings.min.fret
48
67
  end
@@ -16,10 +16,11 @@ module WTFChord
16
16
  (0...MAX_FRET).each do |from|
17
17
  to = from + MAX_DIST
18
18
  generate(from...to) do |variant|
19
- fingerings << variant if filter_variant(variant)
19
+ fingerings << set_bass(variant) if filter_variant(variant)
20
20
  end
21
21
  end
22
22
 
23
+ fingerings.uniq!
23
24
  fingerings.sort_by!(&:complexity)
24
25
  end
25
26
 
@@ -66,6 +67,35 @@ module WTFChord
66
67
  end
67
68
  end
68
69
 
70
+ def set_bass(variant)
71
+ if bass?
72
+ variant.find_used_string_for(original_bass) do |idx, bass_string|
73
+ try_set_bass_on(variant, idx) or begin
74
+ 4.times do |i|
75
+ next if i == idx
76
+ if try_set_bass_on(variant, i)
77
+ bass_string.dead
78
+ break
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ variant
86
+ end
87
+
88
+ def try_set_bass_on(variant, idx)
89
+ bass_string = variant.strings[idx].dup
90
+ distance = bass_string.distance_to(bass)
91
+
92
+ if distance >= 0 && distance < 5 && (distance - variant.min_fret) > -3
93
+ variant.extra_complexity += 0.5 if distance < variant.min_fret
94
+ variant.strings[idx].hold_on(distance)
95
+ true
96
+ end
97
+ end
98
+
69
99
  def all_notes?(used_notes)
70
100
  notes.all? { |n| used_notes.include?(n) }
71
101
  end
@@ -48,6 +48,13 @@ module WTFChord
48
48
  dead? ? -1 : to_i
49
49
  end
50
50
 
51
+ def distance_to(pitch)
52
+ pos = 0
53
+ opened = dup.open
54
+ pos += 1 while (opened + pos) != pitch
55
+ pos
56
+ end
57
+
51
58
  def <=> other
52
59
  return if dead?
53
60
  case other
@@ -46,6 +46,10 @@ module WTFChord
46
46
  move -amount
47
47
  end
48
48
 
49
+ def -@
50
+ -to_i
51
+ end
52
+
49
53
  def to_i
50
54
  (@octave * 12) + @note.position
51
55
  end
@@ -1,3 +1,3 @@
1
1
  module WTFChord
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wtf_chord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-20 00:00:00.000000000 Z
11
+ date: 2016-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone
@@ -83,6 +83,7 @@ files:
83
83
  - ".gitignore"
84
84
  - ".rspec"
85
85
  - ".travis.yml"
86
+ - CHANGELOG.md
86
87
  - Gemfile
87
88
  - README.md
88
89
  - Rakefile