fretboard 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e693a29f4bdd5acf2f84f4fe9cf1a550636ab1a642ae0919a8c8e7fa35eb790e
4
+ data.tar.gz: 7c60bf49fda12e0d7c1daae56bffbb2c2b663c9ef0edd7c0a0ef7a500433135c
5
+ SHA512:
6
+ metadata.gz: b11b6cb3ff18495b1866e15637c9ea1bd3c8c04f5043f647f56a77cb8527f69ec117a6c69afc09999c18e20586c090e0f4c22d6785b677e35be26802503b20f0
7
+ data.tar.gz: c42ebced988ef825dda2a06177f3e8be257d1244828238ef0fee8fd41dde33e2b2ca1aa014e793650a3807cf2df8a27e200fd092342322b5dfb02be6b6e723b5
@@ -0,0 +1,21 @@
1
+ # MIT LICENSE
2
+
3
+ Copyright (c) 2020 Anton Sokolov <anton@sokolov.digital>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # Fretboard for Guitar
2
+
3
+ Tools for working with the guitar fretboard.
4
+
5
+ ![Demo](https://raw.githubusercontent.com/afuno/fretboard/dev/images/demo1.png)
6
+
7
+ [Documentation](https://www.rubydoc.info/gems/fretboard)
8
+
9
+ ## Installation
10
+
11
+ ```ruby
12
+ gem 'fretboard'
13
+ ```
14
+
15
+ ## Using
16
+
17
+ ### Creates a fretboard with the specified tuning
18
+
19
+ ```ruby
20
+ fretboard = Fretboard::Builder.new(:standart)
21
+ # or
22
+ fretboard = Fretboard::Builder.standart
23
+ ```
24
+
25
+ Creating the fretboard data:
26
+
27
+ ```ruby
28
+ fretboard.build
29
+ ```
30
+
31
+ Get the created data:
32
+
33
+ ```ruby
34
+ fretboard.data
35
+ ```
36
+
37
+ Drawing the fretboard in the console:
38
+
39
+ ```ruby
40
+ fretboard.draw
41
+ ```
42
+
43
+ ### Available tunings:
44
+
45
+ - standart
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'fretboard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fretboard'
8
+ spec.version = Fretboard::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ['Anton Sokolov']
11
+ spec.email = ['anton@sokolov.digital']
12
+ spec.homepage = 'https://github.com/afuno/fretboard'
13
+ spec.licenses = ['MIT']
14
+ spec.summary = 'Tools for working with the guitar fretboard'
15
+ spec.description = 'Tools for working with the guitar fretboard'
16
+
17
+ spec.files = `git ls-files -z *.md *.gemspec bin lib images`.split("\x0")
18
+ spec.require_paths = ['lib']
19
+
20
+ # spec.executables = ['fretboard']
21
+
22
+ # spec.add_dependency 'colorize', '~> 0.8.1'
23
+ spec.add_dependency 'terminal-table', '~> 1.8.0'
24
+ spec.add_development_dependency 'rubocop', '= 0.88'
25
+ end
Binary file
@@ -0,0 +1,8 @@
1
+ require 'fretboard/constants'
2
+ require 'fretboard/note'
3
+ require 'fretboard/notes'
4
+ require 'fretboard/builder'
5
+
6
+ module Fretboard
7
+ # extend Constants
8
+ end
@@ -0,0 +1,98 @@
1
+ require 'terminal-table'
2
+
3
+ module Fretboard
4
+ class Builder
5
+ # fretboard = Fretboard::Builder.new(:standart)
6
+ # fretboard = Fretboard::Builder.standart
7
+ # fretboard.build
8
+ # fretboard.data
9
+ # fretboard.draw
10
+
11
+ attr_reader :data
12
+
13
+ def self.standart(number_of_frets = 12)
14
+ new(:standart, number_of_frets)
15
+ end
16
+
17
+ def initialize(tuning, number_of_frets = 12)
18
+ @tuning = tuning.upcase.to_sym
19
+ @number_of_frets = number_of_frets
20
+
21
+ @data = {}
22
+ end
23
+
24
+ def build
25
+ unless Fretboard::Constants::GUITAR_TUNINGS.key?(@tuning)
26
+ puts 'Unable to detect guitar tuning'
27
+ return
28
+ end
29
+
30
+ tuning = Fretboard::Constants::GUITAR_TUNINGS[@tuning]
31
+ strings = tuning[:STRINGS]
32
+ number_of_strings = strings.size
33
+
34
+ (1..number_of_strings).each do |string_number|
35
+ puts
36
+ puts "String: #{string_number}"
37
+ puts
38
+
39
+ current_note = strings[string_number][:NOTE]
40
+
41
+ @data[string_number] = {}
42
+
43
+ puts "Fret: 0 (#{current_note})"
44
+
45
+ @data[string_number][0] = current_note
46
+
47
+ (1..@number_of_frets).each do |fret|
48
+ next_note = Fretboard::Note.next_for(
49
+ current_note,
50
+ sharp_or_flat: :both,
51
+ formated: true
52
+ )
53
+
54
+ puts "Fret: #{fret} (#{next_note})"
55
+
56
+ @data[string_number][fret] = next_note
57
+
58
+ current_note = next_note
59
+ end
60
+ end
61
+
62
+ puts
63
+ puts 'done'
64
+ end
65
+
66
+ def draw
67
+ headings = []
68
+ rows = []
69
+
70
+ @data.each_pair do |string_number, string_notes|
71
+ row = []
72
+
73
+ headings << '№'
74
+ row << string_number
75
+
76
+ headings << 0
77
+ row << string_notes[0]
78
+
79
+ string_notes.except(0).each_pair do |fret, note|
80
+ headings << fret
81
+ row << note
82
+ end
83
+
84
+ rows << row
85
+ end
86
+
87
+ table = Terminal::Table.new(
88
+ headings: headings.uniq,
89
+ rows: rows,
90
+ style: { border_x: '~', border_i: '~' }
91
+ )
92
+
93
+ puts table
94
+
95
+ nil
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,44 @@
1
+ module Fretboard
2
+ module Constants
3
+ # Fretboard::Constants.constants
4
+
5
+ # SPN => Scientific pitch notation
6
+
7
+ GUITAR_TUNINGS = {
8
+ STANDART: {
9
+ STRINGS: {
10
+ 1 => {
11
+ NOTE: 'E',
12
+ FREQUENCY: '329.63 Hz',
13
+ SPN: 'E4'
14
+ },
15
+ 2 => {
16
+ NOTE: 'B',
17
+ FREQUENCY: '246.94 Hz',
18
+ SPN: 'B3'
19
+ },
20
+ 3 => {
21
+ NOTE: 'G',
22
+ FREQUENCY: '196.00 Hz',
23
+ SPN: 'G3'
24
+ },
25
+ 4 => {
26
+ NOTE: 'D',
27
+ FREQUENCY: '146.83 Hz',
28
+ SPN: 'D3'
29
+ },
30
+ 5 => {
31
+ NOTE: 'A',
32
+ FREQUENCY: '110.00 Hz',
33
+ SPN: 'A2'
34
+ },
35
+ 6 => {
36
+ NOTE: 'E',
37
+ FREQUENCY: '82.41 Hz',
38
+ SPN: 'E2'
39
+ }
40
+ }
41
+ }
42
+ }.freeze
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ require 'fretboard/notes'
2
+
3
+ module Fretboard
4
+ class Note
5
+ # Fretboard::Note.next_for('C')
6
+
7
+ def self.next_for(note, sharp_or_flat: :sharp, formated: false)
8
+ all_notes = Fretboard::Notes.all(
9
+ sharp_or_flat,
10
+ formated: formated
11
+ )
12
+
13
+ current_index = all_notes.find_index(note)
14
+ next_index = current_index + 1
15
+
16
+ next_note = all_notes[next_index]
17
+ next_note = all_notes.first if next_note.blank?
18
+
19
+ next_note
20
+ end
21
+
22
+ def self.formated(note)
23
+ new(note).formated
24
+ end
25
+
26
+ def initialize(note)
27
+ @note = note
28
+ end
29
+
30
+ def formated
31
+ result = @note
32
+
33
+ result = result.gsub('sharp', '#') if result.include?('sharp')
34
+
35
+ if result.include?('flat')
36
+ result = result.gsub('flat', 'b') # ♭
37
+ end
38
+
39
+ result.gsub(' ', '')
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,63 @@
1
+ module Fretboard
2
+ class Notes
3
+ # Fretboard::Notes.all(:both)
4
+ # Fretboard::Notes.all(:sharp)
5
+ # Fretboard::Notes.all(:flat)
6
+
7
+ BASIS_NOTES = {
8
+ 1 => 'C',
9
+ 2 => [
10
+ 'C sharp',
11
+ 'D flat'
12
+ ],
13
+ 3 => 'D',
14
+ 4 => [
15
+ 'D sharp',
16
+ 'E flat'
17
+ ],
18
+ 5 => 'E',
19
+ 6 => 'F',
20
+ 7 => [
21
+ 'F sharp',
22
+ 'G flat'
23
+ ],
24
+ 8 => 'G',
25
+ 9 => [
26
+ 'G sharp',
27
+ 'A flat'
28
+ ],
29
+ 10 => 'A',
30
+ 11 => [
31
+ 'A sharp',
32
+ 'B flat'
33
+ ],
34
+ 12 => 'B'
35
+ }.freeze
36
+
37
+ def self.all(sharp_or_flat = :sharp, formated: false)
38
+ BASIS_NOTES.map do |_key, value|
39
+ result = value
40
+
41
+ if value.is_a?(Array)
42
+ result = if sharp_or_flat == :both
43
+ value.join('/')
44
+ elsif sharp_or_flat == :sharp
45
+ value.first
46
+ else
47
+ value.last
48
+ end
49
+ end
50
+
51
+ if formated
52
+ Fretboard::Note.formated(result)
53
+ else
54
+ result
55
+ end
56
+ end
57
+ end
58
+
59
+ def self.first
60
+ all.first
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,11 @@
1
+ module Fretboard
2
+ MAJOR = 1
3
+ MINOR = 0
4
+ PATCH = 0
5
+
6
+ VERSION = [
7
+ MAJOR,
8
+ MINOR,
9
+ PATCH
10
+ ].join('.')
11
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fretboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anton Sokolov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: terminal-table
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: '0.88'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: '0.88'
41
+ description: Tools for working with the guitar fretboard
42
+ email:
43
+ - anton@sokolov.digital
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE.md
49
+ - README.md
50
+ - fretboard.gemspec
51
+ - images/demo1.png
52
+ - lib/fretboard.rb
53
+ - lib/fretboard/builder.rb
54
+ - lib/fretboard/constants.rb
55
+ - lib/fretboard/note.rb
56
+ - lib/fretboard/notes.rb
57
+ - lib/fretboard/version.rb
58
+ homepage: https://github.com/afuno/fretboard
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.1.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Tools for working with the guitar fretboard
81
+ test_files: []