chords 0.4.2 → 0.4.3

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.
@@ -34,12 +34,12 @@ module Chords
34
34
  # Expanded note wil be on a higher string than existing notes.
35
35
  # It will also be the highest note.
36
36
  def expand(note, opts={})
37
- max_fret_distance = opts[:max_fret_distance] || DEFAULT_MAX_FRET_DISTANCE
37
+ max_fret_dist = opts[:max_fret_distance] || DEFAULT_MAX_FRET_DISTANCE
38
38
 
39
39
  fingerings = []
40
40
 
41
41
  ((highest_used_string+1)..(@positions.size-1)).each do |str_i|
42
- new_note_positions(note, str_i, max_fret_distance).each do |pos|
42
+ new_note_positions(note, str_i, max_fret_dist).each do |pos|
43
43
  if (@fretboard.open_notes[str_i] + pos) > highest_note
44
44
  new_positions = @positions.dup
45
45
  new_positions[str_i] = pos
@@ -54,7 +54,7 @@ module Chords
54
54
  # returns variations of this fingering with one duplicate note added
55
55
  def add_duplicate(opts={})
56
56
  return [] if unused_strings < 1
57
- max_fret_distance = opts[:max_fret_distance] || DEFAULT_MAX_FRET_DISTANCE
57
+ max_fret_dist = opts[:max_fret_distance] || DEFAULT_MAX_FRET_DISTANCE
58
58
 
59
59
  fingerings = []
60
60
 
@@ -62,7 +62,7 @@ module Chords
62
62
  next unless pos.nil?
63
63
 
64
64
  each_note do |note|
65
- new_note_positions(note, i, max_fret_distance).each do |pos|
65
+ new_note_positions(note, i, max_fret_dist).each do |pos|
66
66
  new_positions = @positions.dup
67
67
  new_positions[i] = pos
68
68
  fingerings << Fingering.new(@fretboard, new_positions)
@@ -110,16 +110,23 @@ module Chords
110
110
  end
111
111
  end
112
112
 
113
+ def max_fret_distance
114
+ max_fret_dist = 0
115
+ tmp = @positions.select{|pos| !pos.nil? and pos > 0}
116
+ max_fret_dist = tmp.max - tmp.min unless tmp.empty?
117
+ max_fret_dist
118
+ end
119
+
113
120
  private
114
121
 
115
- def new_note_positions(note, string_index, max_fret_distance)
122
+ def new_note_positions(note, string_index, max_fret_dist)
116
123
  positions = []
117
124
  open_note = @fretboard.open_notes[string_index]
118
125
  pos = note.new(open_note.octave).value - open_note.value
119
126
  pos += 12 if pos < 0
120
127
 
121
128
  while pos <= @fretboard.frets
122
- positions << pos if distance(pos) <= max_fret_distance
129
+ positions << pos if distance(pos) <= max_fret_dist
123
130
  pos += 12
124
131
  end
125
132
  positions
@@ -109,11 +109,14 @@ module Chords
109
109
 
110
110
  fretboard = Fretboard.new_by_string(tuning_part, 50, formatter_class)
111
111
 
112
- max_fret_distance, positions = parse_positions(fingering_part,
113
- fretboard.open_notes.size)
112
+ positions = parse_positions(fingering_part, fretboard.open_notes.size)
113
+
114
+ fingering = Fingering.new(fretboard, positions)
115
+ max_fret_dist = fingering.max_fret_distance
116
+ max_fret_dist = 2 if max_fret_dist < 2
114
117
 
115
- fretboard.formatter.print('', [Fingering.new(fretboard, positions)],
116
- opts.merge(:max_fret_distance => max_fret_distance))
118
+ fretboard.formatter.print('', [fingering],
119
+ opts.merge(:max_fret_distance => max_fret_dist))
117
120
  end
118
121
 
119
122
  # parse positions from a string, for example '022100'
@@ -132,12 +135,8 @@ module Chords
132
135
  end
133
136
  over_tens -= 1
134
137
  end
135
- max_fret_distance = 2
136
- tmp = positions.select{|pos| !pos.nil? and pos > 0}
137
- max_fret_distance = tmp.max - tmp.min unless tmp.empty?
138
- max_fret_distance = 2 if max_fret_distance < 2
139
138
 
140
- [max_fret_distance, positions]
139
+ positions
141
140
  end
142
141
 
143
142
  end
@@ -1,4 +1,5 @@
1
1
  require 'chords/png_formatter'
2
+ require 'base64'
2
3
 
3
4
  module Chords
4
5
 
@@ -18,7 +19,7 @@ module Chords
18
19
 
19
20
  # TODO: accept a separator element in opts
20
21
  def print(title, fingerings, opts={})
21
- html = "<h2>#{title}</h2>\n"
22
+ html = title.empty? ? '' : "<h2>#{title}</h2>\n"
22
23
 
23
24
  fingerings.each do |fingering|
24
25
  html += get_element(fingering, opts)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chords
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 2
10
- version: 0.4.2
9
+ - 3
10
+ version: 0.4.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Antti Hakala
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-11 00:00:00 +03:00
18
+ date: 2010-08-13 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21