stringed 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -2
- data/lib/stringed/instrument.rb +9 -13
- data/lib/stringed/instrument_string.rb +13 -5
- data/lib/stringed/version.rb +1 -1
- data/spec/stringed/instrument_spec.rb +6 -6
- data/spec/stringed/instrument_string_spec.rb +21 -19
- data/stringed.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Stringed
|
2
2
|
|
3
|
-
|
3
|
+
A library for Stringed instruments. Recognizes chords and notes for any stringed instrument.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,8 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
guitar = Stringed::Instrument.new(%w( E2 A2 D3 G3 B3 E4 ))
|
22
|
+
guitar.
|
22
23
|
|
23
24
|
## Contributing
|
24
25
|
|
data/lib/stringed/instrument.rb
CHANGED
@@ -2,35 +2,31 @@ module Stringed
|
|
2
2
|
|
3
3
|
class Instrument
|
4
4
|
|
5
|
-
attr_accessor :strings, :
|
5
|
+
attr_accessor :strings, :fret_count
|
6
6
|
|
7
|
-
def initialize(strings,
|
8
|
-
@strings = strings.map{ |string| InstrumentString.new(string.to_s)}
|
9
|
-
@
|
7
|
+
def initialize(strings,options={})
|
8
|
+
@strings = strings.map{ |string| InstrumentString.new(string.to_s, options)}
|
9
|
+
@fret_count = options.fetch(:fret_count,14)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def find(note)
|
13
13
|
matches = []
|
14
14
|
strings.each do |string|
|
15
|
-
matches << string.
|
15
|
+
matches << string.find(note)
|
16
16
|
end
|
17
17
|
matches
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def find_chord(chord)
|
21
21
|
matches = []
|
22
22
|
strings.each do |string|
|
23
|
-
|
24
|
-
chord.notes.each do |note|
|
25
|
-
string_matches << string.matches(note.name,{ limit: @neck_length })
|
26
|
-
end
|
27
|
-
matches << string_matches.flatten.compact.sort
|
23
|
+
matches << string.find_chord(chord)
|
28
24
|
end
|
29
25
|
matches
|
30
26
|
end
|
31
27
|
|
32
28
|
def in_range?(fret_no)
|
33
|
-
fret_no >= 0 and fret_no <=
|
29
|
+
fret_no >= 0 and fret_no <= fret_count
|
34
30
|
end
|
35
31
|
|
36
32
|
end
|
@@ -3,10 +3,11 @@ module Stringed
|
|
3
3
|
class InstrumentString
|
4
4
|
include Music
|
5
5
|
|
6
|
-
attr_reader :root_note
|
6
|
+
attr_reader :root_note, :fret_count
|
7
7
|
|
8
|
-
def initialize(root_note)
|
8
|
+
def initialize(root_note, options={})
|
9
9
|
@root_note = Music::Note.new(root_note.to_s)
|
10
|
+
@fret_count = options.fetch(:fret_count,14)
|
10
11
|
end
|
11
12
|
|
12
13
|
def fret_note(fret_no)
|
@@ -31,14 +32,21 @@ module Stringed
|
|
31
32
|
@root_note.to_s
|
32
33
|
end
|
33
34
|
|
34
|
-
def
|
35
|
-
limit = options.has_key?(:limit) ? options[:limit] : 20
|
35
|
+
def find(note_name)
|
36
36
|
matches = []
|
37
|
-
(0..
|
37
|
+
(0..(fret_count)).each do |fret|
|
38
38
|
matches.push fret if fret_note(fret).name == note_name
|
39
39
|
end
|
40
40
|
matches
|
41
41
|
end
|
42
42
|
|
43
|
+
def find_chord(chord)
|
44
|
+
matches = []
|
45
|
+
chord.notes.each do |note|
|
46
|
+
matches << find(note.name)
|
47
|
+
end
|
48
|
+
matches.flatten.compact.sort
|
49
|
+
end
|
50
|
+
|
43
51
|
end
|
44
52
|
end
|
data/lib/stringed/version.rb
CHANGED
@@ -2,23 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Stringed::Instrument do
|
4
4
|
|
5
|
-
let(:guitar) { Stringed::Instrument.new(%w( E2 A2 D3 G3 B3 E4 ), 20) }
|
5
|
+
let(:guitar) { Stringed::Instrument.new(%w( E2 A2 D3 G3 B3 E4 ), fret_count: 20) }
|
6
6
|
|
7
7
|
it "should have strings" do
|
8
8
|
guitar.strings.count.should == 6
|
9
9
|
end
|
10
10
|
|
11
|
-
it "should have a
|
12
|
-
guitar.
|
11
|
+
it "should have a fret count" do
|
12
|
+
guitar.fret_count.should == 20
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should know where all the matches for a given note are" do
|
16
|
-
guitar.
|
17
|
-
guitar.
|
16
|
+
guitar.find('F').should eq [[1,13], [8,20], [3,15], [10], [6,18], [1,13]]
|
17
|
+
guitar.find('D').should eq [[10], [5, 17], [0, 12], [7, 19], [3, 15], [10]]
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should know where all the matches for a given chord are" do
|
21
|
-
guitar.
|
21
|
+
guitar.find_chord(Chord.new(['C4', 'E4', 'G4'])).should eq [[0, 3, 8, 12, 15, 20],
|
22
22
|
[3, 7, 10, 15, 19],
|
23
23
|
[2, 5, 10, 14, 17],
|
24
24
|
[0, 5, 9, 12, 17],
|
@@ -2,40 +2,42 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe InstrumentString do
|
4
4
|
|
5
|
-
let(:e2){ InstrumentString.new('E2') }
|
5
|
+
let(:e2){ InstrumentString.new('E2', :fret_count => 20) }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
e2.root_note.should eq Note.new('E2')
|
10
|
-
}
|
11
|
-
it { InstrumentString.new(Note.new('A2')).root_note.to_s.should eq 'A2' }
|
7
|
+
it "should have a root note" do
|
8
|
+
e2.root_note.should eq Note.new('E2')
|
12
9
|
end
|
13
10
|
|
14
|
-
it "should
|
11
|
+
it "should have a fret_count" do
|
12
|
+
e2.fret_count.should eq 20
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should know the note at any fret" do
|
15
16
|
e2.fret_note(4).should eq Note.new('G#2')
|
16
|
-
e2.fret_note(5).should eq Note.new('A2' )
|
17
17
|
end
|
18
18
|
|
19
|
-
it "should know
|
20
|
-
e2.fret_no('G2').should eq 3
|
19
|
+
it "should know the fret no of a given note" do
|
21
20
|
e2.fret_no('D#3').should eq 11
|
22
21
|
end
|
23
22
|
|
24
|
-
it "should know
|
25
|
-
InstrumentString.octave_up(
|
23
|
+
it "should know an octave up from a given fret" do
|
24
|
+
InstrumentString.octave_up(2).should == 14
|
26
25
|
end
|
27
26
|
|
28
|
-
it "should know
|
29
|
-
InstrumentString.octave_down(
|
27
|
+
it "should know an octave down from a given fret" do
|
28
|
+
InstrumentString.octave_down(14).should == 2
|
30
29
|
end
|
31
30
|
|
32
|
-
it
|
31
|
+
it "should know to_s" do
|
32
|
+
e2.to_s.should eq "E2"
|
33
|
+
end
|
33
34
|
|
34
|
-
it "should
|
35
|
-
e2.
|
36
|
-
e2.matches("F", :limit => 30).should eq [1,13,25]
|
35
|
+
it "should be able to find a note" do
|
36
|
+
e2.find("F").should eq [1,13]
|
37
37
|
end
|
38
38
|
|
39
|
-
it "should
|
39
|
+
it "should be able to find a chord" do
|
40
|
+
e2.find_chord(Chord.new(["D3","F#3","A3"])).should eq [2,5,10,14,17]
|
41
|
+
end
|
40
42
|
|
41
43
|
end
|
data/stringed.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.authors = ["andrewthomascampbell@gmail.com"]
|
10
10
|
gem.email = ["andrewthomascampbell.com"]
|
11
11
|
gem.description = %q{A library for Stringed instruments.}
|
12
|
-
gem.summary = %q{Recognizes chords and notes for any stringed instrument
|
12
|
+
gem.summary = %q{Recognizes chords and notes for any stringed instrument.}
|
13
13
|
gem.homepage = "https://github.com/andycamp/stringed"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stringed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -88,7 +88,7 @@ rubyforge_project:
|
|
88
88
|
rubygems_version: 1.8.24
|
89
89
|
signing_key:
|
90
90
|
specification_version: 3
|
91
|
-
summary: Recognizes chords and notes for any stringed instrument
|
91
|
+
summary: Recognizes chords and notes for any stringed instrument.
|
92
92
|
test_files:
|
93
93
|
- spec/spec_helper.rb
|
94
94
|
- spec/stringed/instrument_spec.rb
|