chordy 0.7.2 → 0.7.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.
@@ -1,4 +1,4 @@
1
- = chordy {<img src="https://travis-ci.org/darth10/chordy.png" />}[https://travis-ci.org/darth10/chordy]
1
+ = chordy {<img src="https://secure.travis-ci.org/darth10/chordy.png?branch=master" />}[https://travis-ci.org/darth10/chordy]
2
2
 
3
3
  chordy is a DSL written in Ruby for printing guitar chord diagrams.
4
4
  A chordy script produces output that looks like a song with various chords, sections and arbitrary text.
@@ -14,7 +14,9 @@ Formatting options are also provided.
14
14
  == Usage
15
15
 
16
16
  After installing the chordy gem, you can start chordy in an interactive mode through <code>irb</code>.
17
- You can declare chords to play using the <code>play</code> function.
17
+ You can declare chords to play using the <code>play</code> function.
18
+
19
+ === Basic chords
18
20
 
19
21
  The <code>play</code> function takes one required arugment, which can be a chord family like C or F#.
20
22
  There are a handful of notations to specify a chord family.
@@ -187,8 +189,10 @@ You can specify low-to-high string order for playing a chord by adding a <code>:
187
189
 
188
190
  1.9.3-p327 :005 >
189
191
 
190
- You can also play variations in notes, such as a muted chord or a harmonic.
191
- To play a variation, you can either use the <code>play</code> function suffixed with the variation name to play.
192
+ === Variations
193
+
194
+ You can also play variations in chords, such as a muted chord or a harmonic.
195
+ To play a variation, use the <em>play_var</em> function, where <em>var</em> is the variation name to play.
192
196
  Alternatively, you could use the name of the variation itself as a function, which takes a block of chords to be played.
193
197
  For example, the <code>play_mute</code> function plays a muted chord, and the <code>slide_down</code> function plays multiple chords with a slide down.
194
198
  This {wiki page}[http://darth10.github.com/chordy/chords.html] contains a complete listing of all supported varations.
@@ -248,6 +252,8 @@ For example, it's not possible to print both variations in a chord with both <co
248
252
 
249
253
  1.9.3-p327 :008 >
250
254
 
255
+ === Tuning
256
+
251
257
  Chordy also supports different tunings.
252
258
  The <code>tune</code> function can be used to change the tuning, and has to be supplied with a tuning parameter.
253
259
  A tuning is represented as <em>tuning_x_y</em>, where <em>x</em> is the number of strings in the tuning and <em>y</em> is the name of the tuning.
@@ -295,6 +301,8 @@ This {wiki page}[http://darth10.github.com/chordy/tuning.html] contains a comple
295
301
 
296
302
  1.9.3-p327 :005 >
297
303
 
304
+ === Scripting
305
+
298
306
  You could also script the chords to play by using <code>require 'chordy_script'</code>.
299
307
  Just be sure to call <code>print_chords</code>.
300
308
  Here's a sample chordy script.
@@ -322,6 +330,8 @@ Here's what the output of the script looks like.
322
330
  A [--3---2---3---2--|--1-----]
323
331
  E [--3---0-------0--|--------]
324
332
 
333
+ === Text and Sections
334
+
325
335
  Text can be added by using <code>text</code>.
326
336
  To provide structure to your output, use <code>section</code> to separate chords.
327
337
  Here's the previous script with some text and sections.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.3
@@ -1,5 +1,4 @@
1
- # encoding: utf-8
2
-
1
+ require 'stringio'
3
2
  includes = ['chords', 'util']
4
3
 
5
4
  include_dirs = includes.map { |dir| "chordy/#{dir}/" }
@@ -76,16 +75,12 @@ module Chordy
76
75
  strings = [6, 7, 8]
77
76
 
78
77
  if new_tuning.is_a? Array
79
- if strings.include? new_tuning.length
80
- if direction == :high_to_low
81
- new_tuning = new_tuning.reverse
82
- end
83
-
84
- set_chords_to_tuning new_tuning
85
- to_do_print = true
86
- else
87
- puts "Invalid tuning; only " + strings.join(",") + " strings are allowed"
78
+ if direction == :high_to_low
79
+ new_tuning = new_tuning.reverse
88
80
  end
81
+
82
+ set_chords_to_tuning new_tuning
83
+ to_do_print = true
89
84
  else
90
85
  if is_tuning? new_tuning.to_s
91
86
  new_tuning = eval("#{new_tuning}")
@@ -164,7 +159,7 @@ module Chordy
164
159
  do_print
165
160
  end
166
161
 
167
- def separator
162
+ def separator
168
163
  section
169
164
  end
170
165
 
@@ -210,14 +205,14 @@ module Chordy
210
205
  line << curr_chord.print_string_at(i, Chordy.chord_space, Chordy.low_to_high)
211
206
  end
212
207
  end
213
-
208
+
214
209
  chords_in_section = chords_in_section + 1
215
210
  to_skip_end_strings = false
216
211
  elsif (chords[chord_index].is_a? Util::Text) or (chords[chord_index].is_a? Util::Section)
217
212
  lines_to_print.push chords[chord_index].to_s
218
213
  to_skip_end_strings = true
219
214
  chords_in_section = 0
220
-
215
+
221
216
  if chords[chord_index + 1].is_a? Chord
222
217
  to_print_start_chords = true
223
218
  end
@@ -229,7 +224,7 @@ module Chordy
229
224
  else
230
225
  is_next_chord_section_or_text = false
231
226
  end
232
-
227
+
233
228
  if ((chords_in_section % Chordy.line_length) == 0) or (chord_index == chords.length) or is_next_chord_section_or_text
234
229
  if to_skip_end_strings
235
230
  to_skip_end_strings = false
@@ -244,11 +239,11 @@ module Chordy
244
239
  lines_to_print.push ""
245
240
  is_new_line = true
246
241
  elsif (chords_in_section % Chordy.line_length) == (Chordy.line_length / 2) and is_even_line_length
247
- last_chord_lines.each_with_index do |line, i|
242
+ last_chord_lines.each_with_index do |line, i|
248
243
  line << Chord.print_half_length_string_at(i, Chordy.tuning, Chordy.half_length_delimiter, Chordy.chord_space)
249
244
  end
250
245
  end
251
-
246
+
252
247
  if is_next_chord_section_or_text
253
248
  is_new_line = false
254
249
  end
@@ -263,6 +258,14 @@ module Chordy
263
258
  nil
264
259
  end
265
260
 
261
+ def print_chords_to_string
262
+ sio = StringIO.new
263
+ old_stdout, $stdout = $stdout, sio
264
+ print_chords
265
+ $stdout = old_stdout
266
+ sio.string
267
+ end
268
+
266
269
  Chord::CHORD_FLAGS.each_with_index do |name,i|
267
270
  eval <<-ENDOFEVAL
268
271
  def #{name}
@@ -271,7 +274,7 @@ module Chordy
271
274
  Chordy.auto = false
272
275
  begin
273
276
  chord = yield if block_given?
274
-
277
+
275
278
  num_new_chords = Chordy.chords.length - saved_chord_index
276
279
  Chordy.chords.last(num_new_chords).each { |c| c.send :#{name} }
277
280
  rescue Exception => e
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Chordy
4
2
 
5
3
  class Chord
@@ -13,7 +11,7 @@ module Chordy
13
11
  def self.get_num_high_strings length
14
12
  (length / 3.0).ceil
15
13
  end
16
-
14
+
17
15
  def self.start_of_strings tuning, start_delimiter, low_to_high
18
16
  num_strings = tuning.length
19
17
  num_high_strings = get_num_high_strings num_strings
@@ -30,7 +28,7 @@ module Chordy
30
28
  strings_to_print = strings_range.map { |s| s.rjust(2) + start_delimiter.rjust(2) }
31
29
  strings_to_print + [ " " * 4 ]
32
30
  end
33
-
31
+
34
32
  def self.end_of_strings tuning, end_delimiter
35
33
  num_strings = tuning.length
36
34
  ([ end_delimiter ] * num_strings) + [ "" ]
@@ -71,7 +69,7 @@ module Chordy
71
69
  :sus7 => :suspended_7,
72
70
  }
73
71
  end
74
-
72
+
75
73
  def initialize chord, strings
76
74
  @strings = [-1] * strings
77
75
  pad_low = false
@@ -93,7 +91,7 @@ module Chordy
93
91
  pad_or_trim strings, pad_low
94
92
  @flags = 0
95
93
  end
96
-
94
+
97
95
  def pad_or_trim length, pad_low
98
96
  if @strings.length > length
99
97
  @strings = @strings.last length
@@ -102,7 +100,7 @@ module Chordy
102
100
  if pad_low
103
101
  first = @strings.first
104
102
  min = @strings.min
105
-
103
+
106
104
  # play as bar chord
107
105
  bar_chord_string = ((first == min) and (min > 0) and (first > 0)) ? first : -1
108
106
  @strings = ([bar_chord_string] * diff) + @strings
@@ -117,6 +115,10 @@ module Chordy
117
115
  def play chord_type
118
116
  method_for_chord_type = "play_" + chord_type.to_s
119
117
  chord = eval(method_for_chord_type)
118
+ if chord.length > @strings.length
119
+ chord = chord.last @strings.length
120
+ end
121
+
120
122
  chord
121
123
  end
122
124
 
@@ -159,11 +161,11 @@ module Chordy
159
161
  end
160
162
 
161
163
  to_print = to_print.rjust(3, chord_space)
162
-
164
+
163
165
  if @flags != 0
164
166
  to_print = print_string_with_flag_at index_to_print, to_print, chord_space
165
167
  end
166
-
168
+
167
169
  to_print.ljust(4, chord_space)
168
170
  end
169
171
 
@@ -193,7 +195,7 @@ module Chordy
193
195
  end
194
196
 
195
197
  # for printing flags on diff line
196
- def print_flag
198
+ def print_flag
197
199
  to_print = ""
198
200
 
199
201
  if has_flag MUTE
@@ -203,7 +205,7 @@ module Chordy
203
205
  end
204
206
 
205
207
  to_print.rjust(3).ljust(4)
206
- end
208
+ end
207
209
  end
208
210
 
209
211
  Chord::CHORD_FLAGS.each_with_index do |name,i|
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -20,7 +18,7 @@ module Chordy
20
18
  def play_dominant_7_5
21
19
  [0, 1, 2, 1, 3, 4]
22
20
  end
23
-
21
+
24
22
  def play_major_6
25
23
  [1, 1, 3, 3, 3, 3]
26
24
  end
@@ -40,7 +38,7 @@ module Chordy
40
38
  def play_minor_7
41
39
  [1, 1, 3, 1, 2, 1]
42
40
  end
43
-
41
+
44
42
  def play_half_diminished_7
45
43
  [1, 1, 2, 1, 2, 4]
46
44
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -20,7 +18,7 @@ module Chordy
20
18
  def play_dominant_7_5
21
19
  [-1, 2, 3, 4, 2, 3]
22
20
  end
23
-
21
+
24
22
  def play_major_6
25
23
  [1, 1, 3, 1, 2, 1]
26
24
  end
@@ -40,7 +38,7 @@ module Chordy
40
38
  def play_minor_7
41
39
  [0, 2, 2, 4, 2, 4]
42
40
  end
43
-
41
+
44
42
  def play_half_diminished_7
45
43
  [0, 2, 2, 4, 2, 3]
46
44
  end
@@ -56,7 +54,7 @@ module Chordy
56
54
  def play_augmented_7
57
55
  [-1, 2, 3, 4, 2, 5]
58
56
  end
59
-
57
+
60
58
  def play_augmented_major_7
61
59
  [1, 4, 3, 2, 1, 1]
62
60
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -20,7 +18,7 @@ module Chordy
20
18
  def play_dominant_7_5
21
19
  [-1, 0, 1, 2, 2, 3]
22
20
  end
23
-
21
+
24
22
  def play_major_6
25
23
  [-1, 1, 1, 3, 1, 3]
26
24
  end
@@ -40,7 +38,7 @@ module Chordy
40
38
  def play_minor_7
41
39
  [-1, 1, 1, 3, 2, 2]
42
40
  end
43
-
41
+
44
42
  def play_half_diminished_7
45
43
  [2, -1, 1, 2, 2, 2]
46
44
  end
@@ -56,7 +54,7 @@ module Chordy
56
54
  def play_augmented_7
57
55
  [-1, -1, 1, 4, 2, 3]
58
56
  end
59
-
57
+
60
58
  def play_augmented_major_7
61
59
  [-1, 2, 1, 0, 3, 3]
62
60
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require File.join(File.dirname(__FILE__), '..', 'chord')
4
2
 
5
3
  module Chordy
@@ -20,7 +18,7 @@ module Chordy
20
18
  def play_dominant_7_5
21
19
  [-1, -1, 0, 1, 1, 2]
22
20
  end
23
-
21
+
24
22
  def play_major_6
25
23
  [4, 3, 1, 1, 1, 1]
26
24
  end
@@ -40,7 +38,7 @@ module Chordy
40
38
  def play_minor_7
41
39
  [0, 0, 2, 2, 1, 3]
42
40
  end
43
-
41
+
44
42
  def play_half_diminished_7
45
43
  [2, 2, 0, 1, 0, 2]
46
44
  end
@@ -56,7 +54,7 @@ module Chordy
56
54
  def play_augmented_7
57
55
  [-1, 3, 2, 1, 1, 2]
58
56
  end
59
-
57
+
60
58
  def play_augmented_major_7
61
59
  [0, 3, 2, 1, 1, 3]
62
60
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Util
4
2
 
5
3
  class Section
@@ -9,7 +7,7 @@ module Util
9
7
  @title = title
10
8
  @separator_length = separator_length
11
9
  end
12
-
10
+
13
11
  def to_s
14
12
  title_str = @title.to_s
15
13
  title_str.rjust(title_str.length + 2, "-").ljust(@separator_length, "-")
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Util
4
2
 
5
3
  class Text < String
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Util
4
2
 
5
3
  module Tuning
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'chordy'
4
2
 
5
3
  no_auto
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'rubygems'
4
2
  require 'bundler'
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'helper'
4
2
 
5
3
  class TestChordy < Test::Unit::TestCase
@@ -42,9 +40,29 @@ class TestChordy < Test::Unit::TestCase
42
40
  end
43
41
  end
44
42
 
45
- should "have 6,7 or 8 strings" do
46
- # TODO implement
47
- true
43
+ should "support any tuning length" do
44
+ no_auto
45
+ tuning_range = 1..20
46
+
47
+ tuning_range.each do |t|
48
+ assert_nothing_raised do
49
+ tuning = ["a"] * t
50
+ tune tuning
51
+ play :C
52
+ end
53
+ end
54
+ end
55
+
56
+ should "print to string" do
57
+ string = 1
58
+ no_of_strings = 6
59
+
60
+ no_auto
61
+ play [string] * no_of_strings
62
+ a = print_chords_to_string
63
+ a_parts = a.split("\n").first(no_of_strings)
64
+
65
+ a_parts.each { |c| assert(c.include? string.to_s) }
48
66
  end
49
67
 
50
68
  should "know strings at different positions" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chordy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-09 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
@@ -172,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  segments:
174
174
  - 0
175
- hash: -115352785
175
+ hash: 509814771
176
176
  required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  none: false
178
178
  requirements:
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  requirements: []
183
183
  rubyforge_project: chordy
184
- rubygems_version: 1.8.24
184
+ rubygems_version: 1.8.25
185
185
  signing_key:
186
186
  specification_version: 3
187
187
  summary: DSL for guitar chords