chord_diagrams 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c83de466241bba4b2f58a900ebe70cca5c6f8961edb74ddd020caed64e28d154
4
+ data.tar.gz: a33cd628d31d85f6676df5cd6d4dc05994f5801c418386fa6268ab6a3b1efdaa
5
+ SHA512:
6
+ metadata.gz: 628d39f5e1efaa35e5804fc065b2bc5688fa76d6d8adf52f0a7e5a292eaeb43bd3252e0d718b9a978552d67df4099997f0ecb5c8ea3895ed6ccd29abca68c7f9
7
+ data.tar.gz: 26fd9de06972e59cca82612d6fe288647aa45e4aa65daf5f7b9a9f4148f0a70e9249e724b3c899cef70d7e68e43f166b781e2b5fb9c3a1ba6965ed90d3067919
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .idea
14
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chord_diagrams.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Brian Kelly
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.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # ChordDiagrams
2
+
3
+ Generate SVGs of Guitar Chord Diagrams
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'chord_diagrams'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chord_diagrams
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'chord_diagrams'
25
+ puts ChordDiagrams.chord_svg('Am')
26
+ ```
27
+
28
+ <svg width="100" height="100" viewBox="0 0 200 200"><text x="100" y="40" text-anchor="middle" style="font-size:36; font-weight:bold">Am</text><line x1="50" y1="80" x2="150" y2="80" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="50" y1="100" x2="150" y2="100" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="50" y1="120" x2="150" y2="120" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="50" y1="140" x2="150" y2="140" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="50" y1="160" x2="150" y2="160" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="50" y1="80" x2="50" y2="160" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="70" y1="80" x2="70" y2="160" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="90" y1="80" x2="90" y2="160" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="110" y1="80" x2="110" y2="160" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="130" y1="80" x2="130" y2="160" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="150" y1="80" x2="150" y2="160" style="stroke:black; stroke-width:2; stroke-linecap:square"/><line x1="49" y1="77" x2="151" y2="77" style="stroke:black; stroke-width:8"/><circle cx="50" cy="61" r="6" style="stroke:black; fill:white; stroke-width:2"/><circle cx="70" cy="61" r="6" style="stroke:black; fill:white; stroke-width:2"/><circle cx="90" cy="110" r="8" style="fill:black"/><circle cx="110" cy="110" r="8" style="fill:black"/><circle cx="130" cy="90" r="8" style="fill:black"/><circle cx="150" cy="61" r="6" style="stroke:black; fill:white; stroke-width:2"/></svg>
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/spilth/chord_diagrams.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "chord_diagrams"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'chord_diagrams/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'chord_diagrams'
7
+ spec.version = ChordDiagrams::VERSION
8
+ spec.authors = ['Brian Kelly']
9
+ spec.email = ['bkelly@carbonfive.com']
10
+
11
+ spec.summary = 'Generate Chord Diagrams for Guitar'
12
+ spec.description = 'Generate Chord Diagrams for Guitar'
13
+ spec.homepage = 'https://github.com/spilth/chord_diagrams'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://github.com/spilth/chord_diagrams'
23
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = 'exe'
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ['lib']
37
+
38
+ spec.add_dependency 'victor', '0.2.4'
39
+ spec.add_development_dependency 'bundler', '~> 2.0'
40
+ spec.add_development_dependency 'rake', '~> 10.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ end
@@ -0,0 +1,235 @@
1
+ require 'chord_diagrams/version'
2
+ require 'victor'
3
+
4
+ module ChordDiagrams
5
+ LINE_STYLE = {
6
+ stroke: :black,
7
+ stroke_width: 2,
8
+ stroke_linecap: :square
9
+ }.freeze
10
+
11
+ class << self
12
+ def chord_svg(name, fingerings = nil)
13
+ svg = Victor::SVG.new template: :html, width: 100, height: 100, viewBox: '0 0 200 200'
14
+
15
+ ChordDiagrams.draw_name(name, svg)
16
+ ChordDiagrams.draw_frets(svg)
17
+ ChordDiagrams.draw_strings(svg)
18
+
19
+ fingerings = CHORD_FINGERINGS[name.to_sym] if fingerings.nil?
20
+
21
+ if !fingerings.nil?
22
+ ChordDiagrams.draw_chord_diagram(fingerings, svg)
23
+ else
24
+ ChordDiagrams.draw_missing_chord_diagram(svg)
25
+ end
26
+
27
+ svg.render
28
+ end
29
+
30
+ def draw_missing_chord_diagram(svg)
31
+ puts "Could't find fingerings for the chord '#{name}'"
32
+
33
+ svg.text '?', x: 102, y: 155, text_anchor: :middle, style: {
34
+ font_size: 96,
35
+ font_weight: :bold,
36
+ fill: :gray
37
+ }
38
+ end
39
+
40
+ def draw_chord_diagram(fingerings, svg)
41
+ fingerings = fingerings.split('')
42
+
43
+ lowest_fret = fingerings.min
44
+
45
+ if lowest_fret.to_i > 2
46
+ svg.text lowest_fret, x: 35, y: 96, text_anchor: :end, style: { font_size: 20 }
47
+
48
+ fingerings = fingerings.map do |fingering|
49
+ if fingering != 'x'
50
+ fingering.to_i - lowest_fret.to_i + 1
51
+ else
52
+ fingering
53
+ end
54
+ end
55
+ else
56
+ draw_nut(svg)
57
+ end
58
+
59
+ fingerings.each_with_index do |fingering, index|
60
+ offset = 50 + (20 * index)
61
+
62
+ if fingering == 'x'
63
+ draw_muted_string(offset, svg)
64
+ elsif fingering == '0'
65
+ draw_open_string(offset, svg)
66
+ else
67
+ draw_fingered_string(fingering, offset, svg)
68
+ end
69
+ end
70
+ end
71
+
72
+ def draw_name(name, svg)
73
+ svg.text name, x: 100, y: 40, text_anchor: :middle, style: {
74
+ font_size: 36,
75
+ font_weight: :bold
76
+ }
77
+ end
78
+
79
+ def draw_nut(svg)
80
+ svg.line x1: 49, y1: 77, x2: 151, y2: 77, style: {
81
+ stroke: :black,
82
+ stroke_width: 8
83
+ }
84
+ end
85
+
86
+ def draw_fingered_string(fingering, offset, svg)
87
+ svg.circle cx: offset, cy: 70 + (fingering.to_i * 20), r: 8, style: {
88
+ fill: :black
89
+ }
90
+ end
91
+
92
+ def draw_open_string(offset, svg)
93
+ svg.circle cx: offset, cy: 61, r: 6, style: {
94
+ stroke: :black, fill: :white, stroke_width: 2
95
+ }
96
+ end
97
+
98
+ def draw_muted_string(offset, svg)
99
+ svg.line x1: offset - 4, y1: 61 - 4, x2: offset + 4, y2: 61 + 4, style: LINE_STYLE
100
+ svg.line x1: offset - 4, y1: 61 + 4, x2: offset + 4, y2: 61 - 4, style: LINE_STYLE
101
+ end
102
+
103
+ def draw_strings(svg)
104
+ [50, 70, 90, 110, 130, 150].each do |x|
105
+ svg.line x1: x, y1: 80, x2: x, y2: 160, style: LINE_STYLE
106
+ end
107
+ end
108
+
109
+ def draw_frets(svg)
110
+ [80, 100, 120, 140, 160].each do |y|
111
+ svg.line x1: 50, y1: y, x2: 150, y2: y, style: LINE_STYLE
112
+ end
113
+ end
114
+ end
115
+
116
+ CHORD_FINGERINGS = {
117
+ # Major Chords
118
+ 'A': '002220',
119
+ 'B': 'x24442',
120
+ 'Bb': 'x13331',
121
+ 'C': 'x32010',
122
+ 'C#': 'x46664',
123
+ 'D': 'x00232',
124
+ 'D#': 'x68886',
125
+ 'E': '022100',
126
+ 'Eb': 'x68886',
127
+ 'F': '133211',
128
+ 'F#': '244322',
129
+ 'G': '320003',
130
+ 'G#': '466544',
131
+
132
+ # Root/Five Chords
133
+ 'C5': 'x355xx',
134
+ 'D5': 'x577xx',
135
+ 'D#5': 'x688xx',
136
+
137
+ # Six Chords
138
+ 'D6': 'xx0202',
139
+ 'E6': '022120',
140
+ 'G6': '320000',
141
+
142
+ # Seventh Chords
143
+ 'A7': '002020',
144
+ 'B7': 'x21202',
145
+ 'C7': 'x32310',
146
+ 'C#7': 'x46464',
147
+ 'D7': 'x00212',
148
+ 'E7': '020100',
149
+ 'F7': '131211',
150
+ 'F#7': '242322',
151
+ 'G7': '320001',
152
+ 'G#7': '464544',
153
+
154
+ # Major Seventh Chords
155
+ 'AM7': 'x02120',
156
+ 'CM7': 'x32000',
157
+ 'DM7': 'xx0222',
158
+ 'EM7': 'xx2444',
159
+ 'FM7': '132211',
160
+
161
+ # Major Suspended 2nd Chords
162
+ 'Dsus2': 'xx0230',
163
+ 'Asus2': 'x02200',
164
+
165
+ # Major Suspended 4th Chords
166
+ 'Asus4': 'x02230',
167
+ 'Dsus4': 'xx0233',
168
+ 'Esus4': '022200',
169
+
170
+ # Seventh Suspended 4th Chords
171
+ 'A7sus4': '002030',
172
+ 'G7sus4': '353533',
173
+
174
+ # Minor Chords
175
+ 'Am': '002210',
176
+ 'Bm': 'x24432',
177
+ 'Cm': 'x35543',
178
+ 'C#m': 'x46654',
179
+ 'Dm': 'x00231',
180
+ 'Em': '022000',
181
+ 'Fm': '133111',
182
+ 'F#m': '244222',
183
+ 'Gm': '355333',
184
+ 'G#m': '466444',
185
+
186
+ # Minor Seventh Chords
187
+ 'Am7': '002010',
188
+ 'A#m7': 'x13121',
189
+ 'Bm7': 'x24232',
190
+ 'Cm7': 'x35343',
191
+ 'C#m7': 'x46454',
192
+ 'Dm7': 'x00211',
193
+ 'Em7': '020030',
194
+ 'Fm7': '131111',
195
+ 'F#m7': '242222',
196
+ 'Gm7': '353333',
197
+
198
+ # Minor Eleventh Chords
199
+ 'Bm11': 'x20220',
200
+ 'F#m11': '202200',
201
+
202
+ # Major 9th Chords
203
+ 'Cadd9': 'x32033',
204
+
205
+ # Major Chords with Bass Notes
206
+ 'A/C#': '002220',
207
+ 'A/E': '04222x',
208
+ 'A/F#': '202220',
209
+ 'Bb/A': 'x00331',
210
+ 'C/B': 'x22010',
211
+ 'C/E': '032010',
212
+ 'D/A': 'x04232',
213
+ 'D/F#': '200232',
214
+ 'F/A': 'x03211',
215
+ 'G/B': 'x20003',
216
+
217
+ # Seventh Chords with Bass Notes
218
+ 'C7/G': '3323xx',
219
+ 'D7/F#': '200212',
220
+
221
+ # Minor Chords with Bass Notes
222
+ 'Am/D': 'xx0210',
223
+ 'Am/G': '302210',
224
+ 'A#m/D#': 'xx1321',
225
+ 'Dm/F': '10323x',
226
+ 'Gm/Bb': 'x10333',
227
+
228
+ # Diminished Chords
229
+ 'G#dim': '4564xx',
230
+
231
+ # Diminished Seventh Chords
232
+ 'D#dim7': 'xx1212',
233
+ 'G#dim7': '456464'
234
+ }.freeze
235
+ end
@@ -0,0 +1,3 @@
1
+ module ChordDiagrams
2
+ VERSION = '0.0.3'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chord_diagrams
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Brian Kelly
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: victor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Generate Chord Diagrams for Guitar
70
+ email:
71
+ - bkelly@carbonfive.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - chord_diagrams.gemspec
86
+ - lib/chord_diagrams.rb
87
+ - lib/chord_diagrams/version.rb
88
+ homepage: https://github.com/spilth/chord_diagrams
89
+ licenses:
90
+ - MIT
91
+ metadata:
92
+ allowed_push_host: https://rubygems.org
93
+ homepage_uri: https://github.com/spilth/chord_diagrams
94
+ source_code_uri: https://github.com/spilth/chord_diagrams
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Generate Chord Diagrams for Guitar
114
+ test_files: []