fretboard 1.0.1 → 1.2.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
  SHA256:
3
- metadata.gz: f0a46ecd63bcdc0c371eb2dd055dd49866342e21f44143a1c251e295dc481a25
4
- data.tar.gz: da4cf2a0618c6933e2bbd1cf6c9fe5bae055473675afeed7e3970962025a2ba9
3
+ metadata.gz: b7435bd0a766a28745a79a3741e0b08f3793ca8566ed0ab6cca5c864cba776fd
4
+ data.tar.gz: 1e6935842f0d1f730c7d9a7fdfd3e5cc18bb525e725b761cd66b3a4b97207dab
5
5
  SHA512:
6
- metadata.gz: d24330355134a4adf64dc87baff7f992fa2b3e22c409232830079a692686ca590670527f4963d201e8dafe7ae764043e28aa79d422f7c98244c8415f0a8fc17a
7
- data.tar.gz: bcb1765254dea7013edab1c462c198c4b140fc73f52bc33b54f4f44bebb99199eec8a3910c9d153bff6be76452087a67ad1d790c9eae89951a947909adb96929
6
+ metadata.gz: e66075625a1147938126d904ad1f37a5f4b7d44fd18608c87e9c3199a055ada3c401f6d305c5d266ac1b18a4dfdc5dbc68b5d11c1d2d94a37f7538b82b422991
7
+ data.tar.gz: 8359c7422823e670980a0bde6add31442a7e739f4e725a33053e9db870088feace52360c7fa9f2388db2afcafbb328ff6d623151764885bc5e77f91be406441d
data/README.md CHANGED
@@ -55,4 +55,10 @@ fretboard.draw
55
55
 
56
56
  ### Available tunings:
57
57
 
58
- - standart
58
+ - Standart (`standart`)
59
+ - Drop C (`drop_c`)
60
+ - Drop D (`drop_d`)
61
+ - Double Drop D (`double_drop_d`)
62
+ - Open C (`open_c`)
63
+ - Open D (`open_d`)
64
+ - Open G (`open_g`)
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  # spec.executables = ['fretboard']
21
21
 
22
- # spec.add_dependency 'colorize', '~> 0.8.1'
22
+ spec.add_dependency 'colorize', '~> 0.8.1'
23
23
  spec.add_dependency 'terminal-table', '~> 1.8.0'
24
24
  spec.add_development_dependency 'rubocop', '= 0.88'
25
25
  end
@@ -1,7 +1,8 @@
1
- require 'fretboard/constants'
1
+ require 'fretboard/builder'
2
+ # require 'fretboard/constants'
2
3
  require 'fretboard/note'
3
4
  require 'fretboard/notes'
4
- require 'fretboard/builder'
5
+ require 'fretboard/tunings'
5
6
 
6
7
  module Fretboard
7
8
  # extend Constants
@@ -1,33 +1,82 @@
1
- require 'terminal-table'
1
+ require 'fretboard/console'
2
2
 
3
3
  module Fretboard
4
4
  class Builder
5
5
  # fretboard = Fretboard::Builder.new(:standart)
6
6
  # fretboard = Fretboard::Builder.standart
7
+ # fretboard = Fretboard::Builder.drop_c
8
+ # fretboard = Fretboard::Builder.drop_d
9
+ # fretboard = Fretboard::Builder.double_drop_d
10
+ # fretboard = Fretboard::Builder.open_c
11
+ # fretboard = Fretboard::Builder.open_d
12
+ # fretboard = Fretboard::Builder.open_g
13
+
7
14
  # fretboard.build
8
15
  # fretboard.data
9
16
  # fretboard.draw
10
17
 
18
+ DEFAULT_NUMBER_OF_FRETS = 12
19
+
20
+ # METHODS_NAMES = %i[
21
+ # standart
22
+ # drop_c
23
+ # drop_d
24
+ # double_drop_d
25
+ # open_c
26
+ # open_d
27
+ # open_g
28
+ # ].freeze
29
+
11
30
  attr_reader :data
12
31
 
13
- def self.standart(number_of_frets = 12)
32
+ # METHODS_NAMES.each do |method_name|
33
+ # define_method(method_name) do |number_of_frets = DEFAULT_NUMBER_OF_FRETS|
34
+ # new(method_name, number_of_frets)
35
+ # end
36
+ # end
37
+
38
+ def self.standart(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
14
39
  new(:standart, number_of_frets)
15
40
  end
16
41
 
17
- def initialize(tuning, number_of_frets = 12)
42
+ def self.drop_c(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
43
+ new(:drop_c, number_of_frets)
44
+ end
45
+
46
+ def self.drop_d(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
47
+ new(:drop_d, number_of_frets)
48
+ end
49
+
50
+ def self.double_drop_d(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
51
+ new(:double_drop_d, number_of_frets)
52
+ end
53
+
54
+ def self.open_c(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
55
+ new(:open_c, number_of_frets)
56
+ end
57
+
58
+ def self.open_d(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
59
+ new(:open_d, number_of_frets)
60
+ end
61
+
62
+ def self.open_g(number_of_frets = DEFAULT_NUMBER_OF_FRETS)
63
+ new(:open_g, number_of_frets)
64
+ end
65
+
66
+ def initialize(tuning, number_of_frets = DEFAULT_NUMBER_OF_FRETS)
18
67
  @tuning = tuning.upcase.to_sym
19
68
  @number_of_frets = number_of_frets
20
69
 
21
70
  @data = {}
22
71
  end
23
72
 
24
- def build
25
- unless Fretboard::Constants::GUITAR_TUNINGS.key?(@tuning)
26
- puts 'Unable to detect guitar tuning'
73
+ def build(sharp_or_flat: :both)
74
+ unless Fretboard::Tunings.exists?(@tuning)
75
+ Fretboard::Console.danger('Unable to detect guitar tuning')
27
76
  return
28
77
  end
29
78
 
30
- tuning = Fretboard::Constants::GUITAR_TUNINGS[@tuning]
79
+ tuning = Fretboard::Tunings.get(@tuning)
31
80
  strings = tuning[:STRINGS]
32
81
  number_of_strings = strings.size
33
82
 
@@ -47,8 +96,7 @@ module Fretboard
47
96
  (1..@number_of_frets).each do |fret|
48
97
  next_note = Fretboard::Note.next_for(
49
98
  current_note,
50
- sharp_or_flat: :both,
51
- formated: true
99
+ sharp_or_flat: sharp_or_flat
52
100
  )
53
101
 
54
102
  puts "Fret: #{fret} (#{next_note})"
@@ -63,7 +111,12 @@ module Fretboard
63
111
  puts 'done'
64
112
  end
65
113
 
66
- def draw
114
+ def draw(sharp_or_flat: :both)
115
+ unless @data.any?
116
+ Fretboard::Console.danger('Create the data')
117
+ return
118
+ end
119
+
67
120
  headings = []
68
121
  rows = []
69
122
 
@@ -74,7 +127,20 @@ module Fretboard
74
127
  row << string_number
75
128
 
76
129
  headings << 0
77
- row << string_notes[0]
130
+
131
+ open_note = string_notes[0]
132
+
133
+ if open_note.is_a?(Array)
134
+ open_note = if sharp_or_flat == :both
135
+ open_note.join('/')
136
+ elsif sharp_or_flat == :sharp
137
+ open_note.first
138
+ else
139
+ open_note.last
140
+ end
141
+ end
142
+
143
+ row << open_note
78
144
 
79
145
  string_notes.except(0).each_pair do |fret, note|
80
146
  headings << fret
@@ -84,13 +150,7 @@ module Fretboard
84
150
  rows << row
85
151
  end
86
152
 
87
- table = Terminal::Table.new(
88
- headings: headings.uniq,
89
- rows: rows,
90
- style: { border_x: '~', border_i: '~' }
91
- )
92
-
93
- puts table
153
+ Fretboard::Console.print_table(headings.uniq, rows)
94
154
 
95
155
  nil
96
156
  end
@@ -0,0 +1,41 @@
1
+ require 'colorize'
2
+ require 'terminal-table'
3
+
4
+ module Fretboard
5
+ class Console
6
+ # def self.log(text)
7
+ # new(text, nil).print
8
+ # end
9
+
10
+ # def self.success(text)
11
+ # new(text, :green).print
12
+ # end
13
+
14
+ # def self.warning(text)
15
+ # new(text, :yellow).print
16
+ # end
17
+
18
+ def self.danger(text)
19
+ new(text, :red).print
20
+ end
21
+
22
+ def self.print_table(headings, rows)
23
+ table = Terminal::Table.new(
24
+ headings: headings,
25
+ rows: rows,
26
+ style: { border_x: '~', border_i: '~' }
27
+ )
28
+
29
+ new(table.to_s, nil).print
30
+ end
31
+
32
+ def initialize(text, color = nil)
33
+ @text = text
34
+ @color = color
35
+ end
36
+
37
+ def print
38
+ puts @text.colorize(@color)
39
+ end
40
+ end
41
+ end
@@ -1,44 +1,5 @@
1
1
  module Fretboard
2
2
  module Constants
3
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
4
  end
44
5
  end
@@ -3,13 +3,24 @@ require 'fretboard/notes'
3
3
  module Fretboard
4
4
  class Note
5
5
  # Fretboard::Note.next_for('C')
6
+ # Fretboard::Note.next_for(['F#', 'Gb'])
7
+ # Fretboard::Note.next_for('F#/Gb')
6
8
 
7
- def self.next_for(note, sharp_or_flat: :sharp, formated: false)
9
+ def self.next_for(note, sharp_or_flat: :both)
8
10
  all_notes = Fretboard::Notes.all(
9
- sharp_or_flat,
10
- formated: formated
11
+ sharp_or_flat
11
12
  )
12
13
 
14
+ if note.is_a?(Array)
15
+ note = if sharp_or_flat == :both
16
+ note.join('/')
17
+ elsif sharp_or_flat == :sharp
18
+ note.first
19
+ else
20
+ note.last
21
+ end
22
+ end
23
+
13
24
  current_index = all_notes.find_index(note)
14
25
  next_index = current_index + 1
15
26
 
@@ -19,24 +30,8 @@ module Fretboard
19
30
  next_note
20
31
  end
21
32
 
22
- def self.formated(note)
23
- new(note).formated
24
- end
25
-
26
33
  def initialize(note)
27
34
  @note = note
28
35
  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
36
  end
42
37
  end
@@ -7,34 +7,34 @@ module Fretboard
7
7
  BASIS_NOTES = {
8
8
  1 => 'C',
9
9
  2 => [
10
- 'C sharp',
11
- 'D flat'
10
+ 'C#',
11
+ 'Db'
12
12
  ],
13
13
  3 => 'D',
14
14
  4 => [
15
- 'D sharp',
16
- 'E flat'
15
+ 'D#',
16
+ 'Eb'
17
17
  ],
18
18
  5 => 'E',
19
19
  6 => 'F',
20
20
  7 => [
21
- 'F sharp',
22
- 'G flat'
21
+ 'F#',
22
+ 'Gb'
23
23
  ],
24
24
  8 => 'G',
25
25
  9 => [
26
- 'G sharp',
27
- 'A flat'
26
+ 'G#',
27
+ 'Ab'
28
28
  ],
29
29
  10 => 'A',
30
30
  11 => [
31
- 'A sharp',
32
- 'B flat'
31
+ 'A#',
32
+ 'Bb'
33
33
  ],
34
34
  12 => 'B'
35
35
  }.freeze
36
36
 
37
- def self.all(sharp_or_flat = :sharp, formated: false)
37
+ def self.all(sharp_or_flat = :sharp)
38
38
  BASIS_NOTES.map do |_key, value|
39
39
  result = value
40
40
 
@@ -48,11 +48,7 @@ module Fretboard
48
48
  end
49
49
  end
50
50
 
51
- if formated
52
- Fretboard::Note.formated(result)
53
- else
54
- result
55
- end
51
+ result
56
52
  end
57
53
  end
58
54
 
@@ -0,0 +1,245 @@
1
+ module Fretboard
2
+ class Tunings
3
+ # Fretboard::Tunings.get(:standart)
4
+ # Fretboard::Tunings.exists?(:standart)
5
+
6
+ # SPN => Scientific pitch notation
7
+
8
+ TUNINGS = {
9
+ STANDART: {
10
+ STRINGS: {
11
+ 1 => {
12
+ NOTE: 'E',
13
+ # FREQUENCY: '329.63 Hz',
14
+ SPN: 'E4'
15
+ },
16
+ 2 => {
17
+ NOTE: 'B',
18
+ # FREQUENCY: '246.94 Hz',
19
+ SPN: 'B3'
20
+ },
21
+ 3 => {
22
+ NOTE: 'G',
23
+ # FREQUENCY: '196.00 Hz',
24
+ SPN: 'G3'
25
+ },
26
+ 4 => {
27
+ NOTE: 'D',
28
+ # FREQUENCY: '146.83 Hz',
29
+ SPN: 'D3'
30
+ },
31
+ 5 => {
32
+ NOTE: 'A',
33
+ # FREQUENCY: '110.00 Hz',
34
+ SPN: 'A2'
35
+ },
36
+ 6 => {
37
+ NOTE: 'E',
38
+ # FREQUENCY: '82.41 Hz',
39
+ SPN: 'E2'
40
+ }
41
+ }
42
+ },
43
+
44
+ DROP_C: {
45
+ STRINGS: {
46
+ 1 => {
47
+ NOTE: 'D',
48
+ SPN: 'D4'
49
+ },
50
+ 2 => {
51
+ NOTE: 'A',
52
+ SPN: 'A3'
53
+ },
54
+ 3 => {
55
+ NOTE: 'F',
56
+ SPN: 'F3'
57
+ },
58
+ 4 => {
59
+ NOTE: 'C',
60
+ SPN: 'C3'
61
+ },
62
+ 5 => {
63
+ NOTE: 'G',
64
+ SPN: 'G2'
65
+ },
66
+ 6 => {
67
+ NOTE: 'C',
68
+ SPN: 'C2'
69
+ }
70
+ }
71
+ },
72
+
73
+ DROP_D: {
74
+ STRINGS: {
75
+ 1 => {
76
+ NOTE: 'E',
77
+ SPN: 'E4'
78
+ },
79
+ 2 => {
80
+ NOTE: 'B',
81
+ SPN: 'B3'
82
+ },
83
+ 3 => {
84
+ NOTE: 'G',
85
+ SPN: 'G3'
86
+ },
87
+ 4 => {
88
+ NOTE: 'D',
89
+ SPN: 'D3'
90
+ },
91
+ 5 => {
92
+ NOTE: 'A',
93
+ SPN: 'A2'
94
+ },
95
+ 6 => {
96
+ NOTE: 'D',
97
+ SPN: 'D2'
98
+ }
99
+ }
100
+ },
101
+
102
+ DOUBLE_DROP_D: {
103
+ STRINGS: {
104
+ 1 => {
105
+ NOTE: 'D',
106
+ SPN: 'D4'
107
+ },
108
+ 2 => {
109
+ NOTE: 'B',
110
+ SPN: 'B3'
111
+ },
112
+ 3 => {
113
+ NOTE: 'G',
114
+ SPN: 'G3'
115
+ },
116
+ 4 => {
117
+ NOTE: 'D',
118
+ SPN: 'D3'
119
+ },
120
+ 5 => {
121
+ NOTE: 'A',
122
+ SPN: 'A2'
123
+ },
124
+ 6 => {
125
+ NOTE: 'D',
126
+ SPN: 'D2'
127
+ }
128
+ }
129
+ },
130
+
131
+ OPEN_C: {
132
+ STRINGS: {
133
+ 1 => {
134
+ NOTE: 'E',
135
+ SPN: 'E4'
136
+ },
137
+ 2 => {
138
+ NOTE: 'C',
139
+ SPN: 'C4'
140
+ },
141
+ 3 => {
142
+ NOTE: 'G',
143
+ SPN: 'G3'
144
+ },
145
+ 4 => {
146
+ NOTE: 'C',
147
+ SPN: 'C3'
148
+ },
149
+ 5 => {
150
+ NOTE: 'G',
151
+ SPN: 'G2'
152
+ },
153
+ 6 => {
154
+ NOTE: 'C',
155
+ SPN: 'C2'
156
+ }
157
+ }
158
+ },
159
+
160
+ OPEN_D: {
161
+ STRINGS: {
162
+ 1 => {
163
+ NOTE: 'D',
164
+ SPN: 'D4'
165
+ },
166
+ 2 => {
167
+ NOTE: 'A',
168
+ SPN: 'A3'
169
+ },
170
+ 3 => {
171
+ NOTE: [
172
+ 'F#',
173
+ 'Gb'
174
+ ],
175
+ SPN: [
176
+ 'F#3',
177
+ 'Gb3'
178
+ ]
179
+ },
180
+ 4 => {
181
+ NOTE: 'D',
182
+ SPN: 'D3'
183
+ },
184
+ 5 => {
185
+ NOTE: 'A',
186
+ SPN: 'A2'
187
+ },
188
+ 6 => {
189
+ NOTE: 'D',
190
+ SPN: 'D2'
191
+ }
192
+ }
193
+ },
194
+
195
+ OPEN_G: {
196
+ STRINGS: {
197
+ 1 => {
198
+ NOTE: 'D',
199
+ SPN: 'D4'
200
+ },
201
+ 2 => {
202
+ NOTE: 'B',
203
+ SPN: 'B3'
204
+ },
205
+ 3 => {
206
+ NOTE: 'G',
207
+ SPN: 'G3'
208
+ },
209
+ 4 => {
210
+ NOTE: 'D',
211
+ SPN: 'D3'
212
+ },
213
+ 5 => {
214
+ NOTE: 'G',
215
+ SPN: 'G2'
216
+ },
217
+ 6 => {
218
+ NOTE: 'D',
219
+ SPN: 'D2'
220
+ }
221
+ }
222
+ }
223
+ }.freeze
224
+
225
+ def self.get(tuning_name)
226
+ new(tuning_name).get
227
+ end
228
+
229
+ def self.exists?(tuning_name)
230
+ new(tuning_name).exists?
231
+ end
232
+
233
+ def initialize(tuning_name)
234
+ @tuning_name = tuning_name.upcase.to_sym
235
+ end
236
+
237
+ def get
238
+ TUNINGS[@tuning_name]
239
+ end
240
+
241
+ def exists?
242
+ TUNINGS.key?(@tuning_name)
243
+ end
244
+ end
245
+ end
@@ -1,7 +1,7 @@
1
1
  module Fretboard
2
2
  MAJOR = 1
3
- MINOR = 0
4
- PATCH = 1
3
+ MINOR = 2
4
+ PATCH = 0
5
5
 
6
6
  VERSION = [
7
7
  MAJOR,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fretboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: terminal-table
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,9 +64,11 @@ files:
50
64
  - fretboard.gemspec
51
65
  - lib/fretboard.rb
52
66
  - lib/fretboard/builder.rb
67
+ - lib/fretboard/console.rb
53
68
  - lib/fretboard/constants.rb
54
69
  - lib/fretboard/note.rb
55
70
  - lib/fretboard/notes.rb
71
+ - lib/fretboard/tunings.rb
56
72
  - lib/fretboard/version.rb
57
73
  homepage: https://github.com/afuno/fretboard
58
74
  licenses: