jamming 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -24,6 +24,29 @@ This will write Em7#9, <em>The Jimi Hendrix Chord</em>, to <tt>/tmp/old_good_jim
24
24
 
25
25
  ![Em7#9 - The Jimi Hendrix Chord](https://github.com/andmej/jamming/raw/master/examples/Em7%239.png)
26
26
 
27
+ ### Auto labels
28
+
29
+ Jamming has an internal database with some chords that lets her auto-identify some chords. So, for example:
30
+
31
+ File.open("/tmp/a_major.png", 'w') do |f|
32
+ chord = Jamming::Chord.new("x-0-2-2-2-0")
33
+ f.write chord.to_png
34
+ end
35
+
36
+ will generate an image like this:
37
+
38
+ ![A Major](http://jamming.heroku.com/chords/x02220)
39
+
40
+ (Notice the _A_ label even if you never explicitly declared it.)
41
+
42
+ If you'd like to override this behavior, pass `:label => nil` to the `to_png` method.
43
+
44
+ If you find a chord that is not auto-labeled but you'd like it to be, please add it [to this file](https://github.com/andmej/jamming/blob/master/lib/jamming/dictionary.rb) and send a pull request.
45
+
46
+ ### Front-end
47
+
48
+ Jamming is better served with a front-end that takes care of generating the images for you. Check out [this tiny Sinatra app](https://github.com/andmej/jamming_frontend) that does just that.
49
+
27
50
  Thanks
28
51
  ---
29
52
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/jamming.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jamming}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrés Mejía"]
12
- s.date = %q{2010-12-20}
12
+ s.date = %q{2010-12-21}
13
13
  s.description = %q{A Ruby library to generate images of guitar chords}
14
14
  s.email = %q{andmej@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "jamming.gemspec",
29
29
  "lib/jamming.rb",
30
30
  "lib/jamming/chord.rb",
31
+ "lib/jamming/dictionary.rb",
31
32
  "lib/jamming/png_formatter.rb",
32
33
  "test/helper.rb",
33
34
  "test/test_jamming.rb"
data/lib/jamming/chord.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'jamming/png_formatter'
2
+ require 'jamming/dictionary'
2
3
 
3
4
  module Jamming
4
5
  class Chord
@@ -9,7 +10,11 @@ module Jamming
9
10
  end
10
11
 
11
12
  def to_png(options = {})
12
- Jamming::PNGFormatter.new(frets).print(options)
13
+ Jamming::PNGFormatter.new(frets).print({ :label => name }.merge(options))
14
+ end
15
+
16
+ def name
17
+ Jamming::Dictionary.name_for(frets)
13
18
  end
14
19
 
15
20
  protected
@@ -0,0 +1,34 @@
1
+ module Jamming
2
+ class Dictionary
3
+ DICTIONARY = {
4
+ "A" => %w(x02220),
5
+ "Am" => %w(x02210),
6
+ "B" => %w(x24442),
7
+ "Bm" => %w(x24432),
8
+ "C" => %w(x32010),
9
+ "Cm" => %w(x35543),
10
+ "D" => %w(xx0232),
11
+ "Dm" => %w(xx0231),
12
+ "E" => %w(022100),
13
+ "Em" => %w(022000),
14
+ "F" => %w(133211),
15
+ "Fm" => %w(133111),
16
+ "G" => %w(320022 320002),
17
+ "Gm" => %w(355333)
18
+ }
19
+
20
+ def self.name_for(frets)
21
+ frets = normalize_frets(frets)
22
+ DICTIONARY.each do |key, different_fingerings|
23
+ return key if different_fingerings.include?(frets)
24
+ end
25
+ nil
26
+ end
27
+
28
+ private
29
+ def self.normalize_frets(frets)
30
+ join_with = frets.any? { |f| f && f >= 10 } ? "-" : ""
31
+ frets.map { |f| f.nil? ? "x" : f.to_s }.join(join_with)
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Andr\xC3\xA9s Mej\xC3\xADa"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-20 00:00:00 +01:00
17
+ date: 2010-12-21 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -107,6 +107,7 @@ files:
107
107
  - jamming.gemspec
108
108
  - lib/jamming.rb
109
109
  - lib/jamming/chord.rb
110
+ - lib/jamming/dictionary.rb
110
111
  - lib/jamming/png_formatter.rb
111
112
  - test/helper.rb
112
113
  - test/test_jamming.rb
@@ -124,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
125
  requirements:
125
126
  - - ">="
126
127
  - !ruby/object:Gem::Version
127
- hash: 168576609755258433
128
+ hash: 2896660226921079104
128
129
  segments:
129
130
  - 0
130
131
  version: "0"