fretboard_drawer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +84 -0
- data/Rakefile +2 -0
- data/fretboard_drawer.gemspec +18 -0
- data/lib/fretboard_drawer.rb +62 -0
- data/lib/fretboard_drawer/fretboard.rb +58 -0
- data/lib/fretboard_drawer/fretboard_string.rb +43 -0
- data/lib/fretboard_drawer/version.rb +3 -0
- data/spec/fretboard_drawer/fretboard_drawer_spec.rb +48 -0
- data/spec/fretboard_drawer/fretboard_spec.rb +57 -0
- data/spec/fretboard_drawer/fretboard_string_spec.rb +37 -0
- data/spec/spec_helper.rb +7 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Michal Wrobel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# FretboardDrawer
|
2
|
+
|
3
|
+
Draw fretboard structure
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fretboard_drawer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fretboard_drawer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```
|
22
|
+
FretboardDrawer.number_of_frets = 6
|
23
|
+
```
|
24
|
+
|
25
|
+
```
|
26
|
+
FretboardDrawer.draw
|
27
|
+
```
|
28
|
+
|
29
|
+
<pre>
|
30
|
+
3 5
|
31
|
+
e|-----|-----|-----|-----|-----|-----|
|
32
|
+
b|-----|-----|-----|-----|-----|-----|
|
33
|
+
g|-----|-----|-----|-----|-----|-----|
|
34
|
+
d|-----|-----|-----|-----|-----|-----|
|
35
|
+
a|-----|-----|-----|-----|-----|-----|
|
36
|
+
e|-----|-----|-----|-----|-----|-----|
|
37
|
+
</pre>
|
38
|
+
|
39
|
+
```
|
40
|
+
sounds = { 1 => { 3 => "g" }, 6 => { 5 => "a" } }
|
41
|
+
```
|
42
|
+
|
43
|
+
```
|
44
|
+
FretboardDrawer.draw(sounds)
|
45
|
+
```
|
46
|
+
|
47
|
+
<pre>
|
48
|
+
3 5
|
49
|
+
e|-----|-----|--g--|-----|-----|-----|
|
50
|
+
b|-----|-----|-----|-----|-----|-----|
|
51
|
+
g|-----|-----|-----|-----|-----|-----|
|
52
|
+
d|-----|-----|-----|-----|-----|-----|
|
53
|
+
a|-----|-----|-----|-----|-----|-----|
|
54
|
+
e|-----|-----|-----|-----|--a--|-----|
|
55
|
+
</pre>
|
56
|
+
|
57
|
+
## Config
|
58
|
+
|
59
|
+
```
|
60
|
+
FretboardDrawer::Config.number_of_strings # 6
|
61
|
+
```
|
62
|
+
|
63
|
+
```
|
64
|
+
FretboardDrawer::Config.number_of_frets # 20
|
65
|
+
```
|
66
|
+
|
67
|
+
```
|
68
|
+
FretboardDrawer::Config.use_stdout # true
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
By default FretboardDrawer.draw use puts to draw to stdout, to disable it:
|
73
|
+
|
74
|
+
```
|
75
|
+
FretboardDrawer::Config.use_stdout = false
|
76
|
+
```
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
1. Fork it
|
81
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
82
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
83
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
84
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/fretboard_drawer/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Michal Wrobel"]
|
6
|
+
gem.email = ["sparrovv@gmail.com"]
|
7
|
+
gem.description = %q{Command line fretboard drawer}
|
8
|
+
gem.summary = %q{Command line fretbarod drawer}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "fretboard_drawer"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = FretboardDrawer::VERSION
|
17
|
+
gem.add_development_dependency('rspec')
|
18
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative "fretboard_drawer/version"
|
2
|
+
require_relative "fretboard_drawer/fretboard"
|
3
|
+
require_relative "fretboard_drawer/fretboard_string"
|
4
|
+
|
5
|
+
module FretboardDrawer
|
6
|
+
STRINGS = ["e", "b", "g", "d", "a", "e"]
|
7
|
+
|
8
|
+
def self.draw(sounds={})
|
9
|
+
result = fretboard.result(sounds)
|
10
|
+
if Config.use_stdout
|
11
|
+
puts result
|
12
|
+
else
|
13
|
+
result
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# reload @@fretboard if config was changed
|
18
|
+
def self.reload
|
19
|
+
@fretboard = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
# this should be private
|
23
|
+
def self.fretboard
|
24
|
+
@fretboard ||=
|
25
|
+
FretboardDrawer::Fretboard.new(
|
26
|
+
Config.number_of_strings,
|
27
|
+
Config.number_of_frets
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
module Config
|
32
|
+
extend self
|
33
|
+
|
34
|
+
def number_of_strings
|
35
|
+
@number_of_strings || 6
|
36
|
+
end
|
37
|
+
|
38
|
+
def number_of_strings=(strings)
|
39
|
+
@number_of_strings = strings
|
40
|
+
end
|
41
|
+
|
42
|
+
def number_of_frets
|
43
|
+
@number_of_frets || 20
|
44
|
+
end
|
45
|
+
|
46
|
+
def number_of_frets=(frets)
|
47
|
+
@number_of_frets = frets
|
48
|
+
end
|
49
|
+
|
50
|
+
# if not set then true
|
51
|
+
def use_stdout
|
52
|
+
return true if @use_stdout.nil?
|
53
|
+
|
54
|
+
@use_stdout
|
55
|
+
end
|
56
|
+
|
57
|
+
# true / false
|
58
|
+
def use_stdout=(flag)
|
59
|
+
@use_stdout = flag
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module FretboardDrawer
|
2
|
+
class Fretboard
|
3
|
+
attr_reader :strings, :frets
|
4
|
+
|
5
|
+
def initialize(strings, frets)
|
6
|
+
@strings = strings
|
7
|
+
@frets = frets
|
8
|
+
end
|
9
|
+
|
10
|
+
def result(sounds = {})
|
11
|
+
result = ""
|
12
|
+
result << frets_description << "\n"
|
13
|
+
result << build_strings(sounds)
|
14
|
+
|
15
|
+
result
|
16
|
+
end
|
17
|
+
|
18
|
+
def strings_structure(strings_sounds)
|
19
|
+
result = []
|
20
|
+
(1..@strings).each do |string_number|
|
21
|
+
sounds = strings_sounds[string_number] || {}
|
22
|
+
result << generate_string_structure(string_number, sounds)
|
23
|
+
end
|
24
|
+
result
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_strings(sounds)
|
30
|
+
structure = strings_structure(sounds)
|
31
|
+
structure.inject("") do |r, string|
|
32
|
+
r << string.join() << "\n"
|
33
|
+
r
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def frets_description
|
38
|
+
frets_desc_numbers = [3, 5, 7, 9, 12, 14]
|
39
|
+
result = [" "]
|
40
|
+
|
41
|
+
@frets.times do |f|
|
42
|
+
if frets_desc_numbers.include?(f + 1)
|
43
|
+
result << " #{f+1} "
|
44
|
+
else
|
45
|
+
result << " " * 6
|
46
|
+
end
|
47
|
+
end
|
48
|
+
result.join()
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_string_structure(string_number, sounds_on_string)
|
52
|
+
sound = STRINGS[string_number - 1]
|
53
|
+
string = FretboardString.new(sound, @frets, sounds_on_string)
|
54
|
+
string.structure
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module FretboardDrawer
|
2
|
+
class FretboardString
|
3
|
+
def initialize(sound, frets, sounds_on_frets={})
|
4
|
+
@sound = sound
|
5
|
+
@frets = frets
|
6
|
+
@sounds_on_frets = sounds_on_frets
|
7
|
+
end
|
8
|
+
|
9
|
+
def structure
|
10
|
+
head = "#{@sound}"
|
11
|
+
result = [head, "|"]
|
12
|
+
|
13
|
+
(1..@frets).each do |f|
|
14
|
+
if draw_on_fret?(f)
|
15
|
+
symbol = fret_symbol(f)
|
16
|
+
result << fret_symbol_part(symbol)
|
17
|
+
else
|
18
|
+
result << "-" * 5
|
19
|
+
end
|
20
|
+
result << "|"
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def fret_symbol_part(symbol)
|
29
|
+
if symbol.size == 1
|
30
|
+
"--#{symbol}--"
|
31
|
+
else
|
32
|
+
"-#{symbol}--"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
def fret_symbol(fret)
|
36
|
+
@sounds_on_frets[fret]
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw_on_fret?(fret)
|
40
|
+
@sounds_on_frets.keys.include?(fret)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FretboardDrawer do
|
4
|
+
|
5
|
+
let(:sounds) { {} }
|
6
|
+
let(:result) { "-----" }
|
7
|
+
|
8
|
+
describe ".draw" do
|
9
|
+
before do
|
10
|
+
FretboardDrawer::Fretboard.any_instance.
|
11
|
+
should_receive(:result).and_return(result)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "draws to sdtout" do
|
15
|
+
$stdout.should_receive(:puts).with(result).and_return(true)
|
16
|
+
|
17
|
+
FretboardDrawer.draw
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ".reload" do
|
22
|
+
it "reloads Fretboard instance and use proper config values" do
|
23
|
+
FretboardDrawer.reload
|
24
|
+
|
25
|
+
FretboardDrawer::Config.number_of_strings = 4
|
26
|
+
FretboardDrawer.fretboard.strings.should == 4
|
27
|
+
|
28
|
+
FretboardDrawer::Config.number_of_strings = 5
|
29
|
+
FretboardDrawer.fretboard.strings.should == 4
|
30
|
+
|
31
|
+
FretboardDrawer.reload
|
32
|
+
|
33
|
+
FretboardDrawer.fretboard.strings.should == 5
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Config" do
|
38
|
+
it "sets number of strings" do
|
39
|
+
FretboardDrawer::Config.number_of_strings = 4
|
40
|
+
FretboardDrawer::Config.number_of_strings.should == 4
|
41
|
+
end
|
42
|
+
|
43
|
+
it "sets number of frets" do
|
44
|
+
FretboardDrawer::Config.number_of_frets = 13
|
45
|
+
FretboardDrawer::Config.number_of_frets.should == 13
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FretboardDrawer::Fretboard do
|
4
|
+
|
5
|
+
let(:strings_number) { 6 }
|
6
|
+
let(:frets_number) { 20 }
|
7
|
+
|
8
|
+
subject { FretboardDrawer::Fretboard.new(strings_number, frets_number) }
|
9
|
+
|
10
|
+
describe "#result" do
|
11
|
+
context "when no sounds to draw" do
|
12
|
+
let(:frets_number) { 10 }
|
13
|
+
|
14
|
+
it "returns string" do
|
15
|
+
expected = " 3 5 7 9 \n"
|
16
|
+
expected << "e|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
17
|
+
expected << "b|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
18
|
+
expected << "g|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
19
|
+
expected << "d|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
20
|
+
expected << "a|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
21
|
+
expected << "e|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
22
|
+
|
23
|
+
subject.result.should == expected
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when there are sounds to draw" do
|
28
|
+
let(:frets_number) { 10 }
|
29
|
+
let(:sounds) do
|
30
|
+
{ 1 => { 2 => "f#", 9 => "c#"}, 6 => { 1 => "f" } }
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns string" do
|
34
|
+
expected = " 3 5 7 9 \n"
|
35
|
+
expected << "e|-----|-f#--|-----|-----|-----|-----|-----|-----|-c#--|-----|\n"
|
36
|
+
expected << "b|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
37
|
+
expected << "g|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
38
|
+
expected << "d|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
39
|
+
expected << "a|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
40
|
+
expected << "e|--f--|-----|-----|-----|-----|-----|-----|-----|-----|-----|\n"
|
41
|
+
|
42
|
+
subject.result(sounds).should == expected
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#strings_structure" do
|
48
|
+
context "when no sounds" do
|
49
|
+
let(:sounds) { {} }
|
50
|
+
it "generates strings structure" do
|
51
|
+
structure = subject.strings_structure(sounds)
|
52
|
+
structure.size.should == strings_number
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FretboardDrawer::FretboardString do
|
4
|
+
|
5
|
+
let(:sounds) { {} }
|
6
|
+
subject { FretboardDrawer::FretboardString.new("e", 2, sounds) }
|
7
|
+
|
8
|
+
describe "#structure" do
|
9
|
+
context "when no sounds" do
|
10
|
+
|
11
|
+
it "generate structure of string" do
|
12
|
+
subject.structure.should == ["e", "|", "-"*5, '|', "-"*5, '|']
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when there is one sound" do
|
18
|
+
let(:sounds) { { 1 => "o" } }
|
19
|
+
|
20
|
+
it "generate structure of string" do
|
21
|
+
subject.structure.should == ["e", "|", "--o--", '|', "-"*5, '|']
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when there is 2 sound" do
|
27
|
+
let(:sounds) { { 1 => "o", 2 => "d#" } }
|
28
|
+
|
29
|
+
it "generate structure of string" do
|
30
|
+
subject.structure.should == ["e", "|", "--o--", '|', "-d#--", '|']
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fretboard_drawer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michal Wrobel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-12 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70248779197700 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70248779197700
|
25
|
+
description: Command line fretboard drawer
|
26
|
+
email:
|
27
|
+
- sparrovv@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- fretboard_drawer.gemspec
|
38
|
+
- lib/fretboard_drawer.rb
|
39
|
+
- lib/fretboard_drawer/fretboard.rb
|
40
|
+
- lib/fretboard_drawer/fretboard_string.rb
|
41
|
+
- lib/fretboard_drawer/version.rb
|
42
|
+
- spec/fretboard_drawer/fretboard_drawer_spec.rb
|
43
|
+
- spec/fretboard_drawer/fretboard_spec.rb
|
44
|
+
- spec/fretboard_drawer/fretboard_string_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.10
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Command line fretbarod drawer
|
70
|
+
test_files:
|
71
|
+
- spec/fretboard_drawer/fretboard_drawer_spec.rb
|
72
|
+
- spec/fretboard_drawer/fretboard_spec.rb
|
73
|
+
- spec/fretboard_drawer/fretboard_string_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
has_rdoc:
|