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 +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/wtf_chord/chord.rb +20 -7
- data/lib/wtf_chord/complexity_counter.rb +1 -1
- data/lib/wtf_chord/fingering.rb +20 -1
- data/lib/wtf_chord/fingerings_generator.rb +31 -1
- data/lib/wtf_chord/guitar_string.rb +7 -0
- data/lib/wtf_chord/pitch.rb +4 -0
- data/lib/wtf_chord/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b01a7a811a348cefa9b4e05c67d4ae4cb4af5f20
|
4
|
+
data.tar.gz: 814e86e9e218ab85ec3605bdf72c99bb632c22d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff5fe7b9623c92b26d74c01cccfda962196affa8a6e171975d39b91828cce3080e31ed3bc29d2fd208030c3ed47847b8a692367ef40ffe1f1bfda72f12ddb516
|
7
|
+
data.tar.gz: f9fbcb0adc02b779dc665cafef34466c4cf569e79eb0a8636e0c5e689e3c59f271b51f62fd75d05bb64ae21a6c9d0d1118ba273cb039d0127a25136a1bc70a6e
|
data/CHANGELOG.md
ADDED
data/lib/wtf_chord/chord.rb
CHANGED
@@ -3,26 +3,39 @@ require 'wtf_chord/fingerings_generator'
|
|
3
3
|
|
4
4
|
module WTFChord
|
5
5
|
class Chord
|
6
|
-
|
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
|
-
|
16
|
-
|
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
|
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.
|
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
|
data/lib/wtf_chord/fingering.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/wtf_chord/pitch.rb
CHANGED
data/lib/wtf_chord/version.rb
CHANGED
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
|
+
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-
|
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
|