gitara 0.5.0 → 0.6.0

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.
Files changed (47) hide show
  1. data/.gitignore +2 -0
  2. data/.yardopts +5 -0
  3. data/CHANGELOG.markdown +5 -0
  4. data/README.markdown +135 -99
  5. data/examples/tab-with-repeats.ly +117 -0
  6. data/examples/tab-with-repeats.rb +19 -0
  7. data/gitara.gemspec +3 -0
  8. data/lib/gitara.rb +5 -3
  9. data/lib/gitara/dsl.rb +13 -0
  10. data/lib/gitara/node/alternative.rb +14 -0
  11. data/lib/gitara/node/bar.rb +3 -1
  12. data/lib/gitara/node/base.rb +22 -24
  13. data/lib/gitara/node/base/chorded_version.rb +1 -4
  14. data/lib/gitara/node/base/node_version.rb +35 -0
  15. data/lib/gitara/node/base/stanza_version.rb +1 -4
  16. data/lib/gitara/node/base/voiced_version.rb +5 -6
  17. data/lib/gitara/node/repeat.rb +10 -0
  18. data/lib/gitara/node/tab.rb +3 -5
  19. data/lib/gitara/utilities.rb +8 -0
  20. data/lib/gitara/version.rb +1 -1
  21. data/lib/gitara/voice.rb +2 -0
  22. data/spec/factories.rb +6 -0
  23. data/spec/lib/gitara/app_spec.rb +12 -28
  24. data/spec/lib/gitara/dsl_spec.rb +218 -173
  25. data/spec/lib/gitara/node/alternative_spec.rb +15 -0
  26. data/spec/lib/gitara/node/bar/chorded_version_spec.rb +2 -2
  27. data/spec/lib/gitara/node/bar/stanza_version_spec.rb +2 -2
  28. data/spec/lib/gitara/node/bar/voiced_version_spec.rb +2 -2
  29. data/spec/lib/gitara/node/bar_spec.rb +7 -7
  30. data/spec/lib/gitara/node/base/chorded_version_spec.rb +1 -1
  31. data/spec/lib/gitara/node/base/node_version_spec.rb +66 -0
  32. data/spec/lib/gitara/node/base/voiced_version_spec.rb +5 -5
  33. data/spec/lib/gitara/node/base_spec.rb +36 -42
  34. data/spec/lib/gitara/node/chord_set/chorded_version_spec.rb +2 -2
  35. data/spec/lib/gitara/node/chord_set_spec.rb +1 -1
  36. data/spec/lib/gitara/node/note_set_spec.rb +1 -1
  37. data/spec/lib/gitara/node/repeat_spec.rb +15 -0
  38. data/spec/lib/gitara/node/stanza_spec.rb +2 -2
  39. data/spec/lib/gitara/node/tab_spec.rb +6 -6
  40. data/spec/lib/gitara/voice_spec.rb +9 -9
  41. data/spec/lib/gitara_spec.rb +3 -1
  42. data/spec/spec_helper.rb +1 -0
  43. data/spec/support/app_tester.rb +22 -0
  44. metadata +70 -29
  45. data/lib/gitara/is_node_version.rb +0 -23
  46. data/lib/gitara/pow/base.rb +0 -11
  47. data/spec/lib/gitara/is_node_version_spec.rb +0 -58
@@ -1,259 +1,304 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Gitara do
4
- describe Dsl do
5
- describe "bar(name, &block)" do
6
- it "should add a bar with the name" do
7
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
8
- dsl.node.own_children.should be_empty
3
+ describe Gitara::Dsl do
4
+ describe "#bar" do
5
+ it "should add a bar with the name" do
6
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
7
+ dsl.node.children.should be_empty
9
8
 
10
- dsl.bar 'Intro'
9
+ dsl.bar 'Intro'
11
10
 
12
- dsl.node.own_children.should have(1).bar
11
+ dsl.node.children.should have(1).bar
13
12
 
14
- bar = dsl.node.own_children[0]
15
- bar.name.should == 'Intro'
16
- bar.own_children.should be_empty
17
- end
13
+ bar = dsl.node.children[0]
14
+ bar.name.should == 'Intro'
15
+ bar.children.should be_empty
16
+ end
18
17
 
19
- it "should add the children declared in the block to the bar" do
20
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
21
- dsl.node.own_children.should be_empty
18
+ it "should add the definition_children declared in the block to the bar" do
19
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
20
+ dsl.node.children.should be_empty
22
21
 
23
- note_set = FactoryGirl.build(:note_set)
22
+ note_set = FactoryGirl.build(:note_set)
24
23
 
25
- dsl.bar 'Intro' do
26
- add note_set
27
- end
24
+ dsl.bar 'Intro' do
25
+ add note_set
26
+ end
28
27
 
29
- dsl.node.own_children.should have(1).bar
30
- dsl.node.own_children[0].name.should == 'Intro'
28
+ dsl.node.children.should have(1).bar
29
+ dsl.node.children[0].name.should == 'Intro'
31
30
 
32
- bar = dsl.node.own_children[0]
33
- bar.own_children.should have(1).note_set
34
- bar.own_children[0].should == note_set
35
- end
31
+ bar = dsl.node.children[0]
32
+ bar.children.should have(1).note_set
33
+ bar.children[0].should == note_set
36
34
  end
35
+ end
37
36
 
38
- describe "add(child, &block)" do
39
- it "should add the child to the dsl's node" do
40
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
41
- dsl.node.own_children.should be_empty
37
+ describe "#add" do
38
+ it "should add the child to the dsl's node" do
39
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
40
+ dsl.node.children.should be_empty
42
41
 
43
- bar = FactoryGirl.build(:bar, :name => 'Intro')
42
+ bar = FactoryGirl.build(:bar, :name => 'Intro')
44
43
 
45
- dsl.add bar
44
+ dsl.add bar
46
45
 
47
- dsl.node.own_children.should have(1).bar
48
- dsl.node.own_children[0].should == bar
49
- end
46
+ dsl.node.children.should have(1).bar
47
+ dsl.node.children[0].should == bar
48
+ end
50
49
 
51
- it "should add the children in the block to the child" do
52
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
53
- dsl.node.own_children.should be_empty
50
+ it "should add the definition_children in the block to the child" do
51
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
52
+ dsl.node.children.should be_empty
54
53
 
55
- bar = FactoryGirl.build(:bar, :children => [])
56
- note_set = FactoryGirl.build(:note_set)
54
+ bar = FactoryGirl.build(:bar, :children => [])
55
+ note_set = FactoryGirl.build(:note_set)
57
56
 
58
- dsl.add bar do
59
- add note_set
60
- end
57
+ dsl.add bar do
58
+ add note_set
59
+ end
61
60
 
62
- dsl.node.own_children.should have(1).bar
63
- dsl.node.own_children[0].should == bar
61
+ dsl.node.children.should have(1).bar
62
+ dsl.node.children[0].should == bar
64
63
 
65
- bar.own_children.should have(1).note_set
66
- bar.own_children[0].should == note_set
67
- end
64
+ bar.children.should have(1).note_set
65
+ bar.children[0].should == note_set
68
66
  end
67
+ end
69
68
 
70
- describe "notes(value)" do
71
- it "should add a note set with the value" do
72
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:bar, :children => []))
73
- dsl.node.own_children.should be_empty
69
+ describe "#notes" do
70
+ it "should add a note set with the value" do
71
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:bar, :children => []))
72
+ dsl.node.children.should be_empty
74
73
 
75
- dsl.notes 'test'
74
+ dsl.notes 'test'
76
75
 
77
- dsl.node.own_children.should have(1).note_set
78
- dsl.node.own_children[0].value.should == 'test'
79
- end
76
+ dsl.node.children.should have(1).note_set
77
+ dsl.node.children[0].value.should == 'test'
80
78
  end
79
+ end
81
80
 
82
- describe "line(name, &block)" do
83
- it "should add a line with the name" do
84
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
85
- dsl.node.own_children.should be_empty
81
+ describe "#line" do
82
+ it "should add a line with the name" do
83
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
84
+ dsl.node.children.should be_empty
86
85
 
87
- dsl.line 'Intro'
86
+ dsl.line 'Intro'
88
87
 
89
- dsl.node.own_children.should have(1).line
88
+ dsl.node.children.should have(1).line
90
89
 
91
- line = dsl.node.own_children[0]
92
- line.name.should == 'Intro'
93
- line.own_children.should be_empty
94
- end
90
+ line = dsl.node.children[0]
91
+ line.name.should == 'Intro'
92
+ line.children.should be_empty
93
+ end
95
94
 
96
- it "should add the children declared in the block to the line" do
97
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
98
- dsl.node.own_children.should be_empty
95
+ it "should add the definition_children declared in the block to the line" do
96
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
97
+ dsl.node.children.should be_empty
99
98
 
100
- bar = FactoryGirl.build(:bar)
99
+ bar = FactoryGirl.build(:bar)
101
100
 
102
- dsl.line 'Intro' do
103
- add bar
104
- end
101
+ dsl.line 'Intro' do
102
+ add bar
103
+ end
105
104
 
106
- dsl.node.own_children.should have(1).line
107
- dsl.node.own_children[0].name.should == 'Intro'
105
+ dsl.node.children.should have(1).line
106
+ dsl.node.children[0].name.should == 'Intro'
108
107
 
109
- line = dsl.node.own_children[0]
110
- line.own_children.should have(1).bar
111
- line.own_children[0].should == bar
112
- end
108
+ line = dsl.node.children[0]
109
+ line.children.should have(1).bar
110
+ line.children[0].should == bar
113
111
  end
112
+ end
114
113
 
115
- describe "add_names(o)" do
116
- it "should add a node with o[:name] of o[:node_class] to the node" do
117
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
118
- dsl.node.own_children.should be_empty
114
+ describe "#add_names" do
115
+ it "should add a node with o[:name] of o[:node_class] to the node" do
116
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
117
+ dsl.node.children.should be_empty
119
118
 
120
- dsl.add_names :names => [:Intro, :Intro], :node_class => Node::Bar
119
+ dsl.add_names :names => [:Intro, :Intro], :node_class => Node::Bar
121
120
 
122
- dsl.node.own_children.should have(2).bars
123
- dsl.node.own_children.each do |child|
124
- child.should be_a(Node::Bar)
125
- child.name.should == :Intro
126
- end
121
+ dsl.node.children.should have(2).bars
122
+ dsl.node.children.each do |child|
123
+ child.should be_a(Node::Bar)
124
+ child.name.should == :Intro
127
125
  end
126
+ end
128
127
 
129
- it "should add a node with nil name if the o[:names] is blank" do
130
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
131
- dsl.node.own_children.should be_empty
128
+ it "should add a node with nil name if the o[:names] is blank" do
129
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
130
+ dsl.node.children.should be_empty
132
131
 
133
- dsl.add_names :names => [], :node_class => Node::Bar
132
+ dsl.add_names :names => [], :node_class => Node::Bar
134
133
 
135
- dsl.node.own_children.should have(1).bar
136
- dsl.node.own_children[0].attributes[:name].should be_nil
137
- dsl.node.own_children[0].should be_a(Node::Bar)
138
- end
134
+ dsl.node.children.should have(1).bar
135
+ dsl.node.children[0].attributes[:name].should be_nil
136
+ dsl.node.children[0].should be_a(Node::Bar)
139
137
  end
138
+ end
140
139
 
141
- describe "score(name, &block)" do
142
- it "should add a score with the name" do
143
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
144
- dsl.node.own_children.should be_empty
140
+ describe "#score" do
141
+ it "should add a score with the name" do
142
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
143
+ dsl.node.children.should be_empty
145
144
 
146
- dsl.score
145
+ dsl.score
147
146
 
148
- dsl.node.own_children.should have(1).score
147
+ dsl.node.children.should have(1).score
149
148
 
150
- score = dsl.node.own_children[0]
151
- score.should be_a(Node::Score)
152
- score.own_children.should be_empty
153
- end
149
+ score = dsl.node.children[0]
150
+ score.should be_a(Node::Score)
151
+ score.children.should be_empty
152
+ end
154
153
 
155
- it "should add the children declared in the block to the score" do
156
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
157
- dsl.node.own_children.should be_empty
154
+ it "should add the definition_children declared in the block to the score" do
155
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
156
+ dsl.node.children.should be_empty
158
157
 
159
- note_set = FactoryGirl.build(:note_set)
158
+ note_set = FactoryGirl.build(:note_set)
160
159
 
161
- dsl.score do
162
- add note_set
163
- end
160
+ dsl.score do
161
+ add note_set
162
+ end
164
163
 
165
- dsl.node.own_children.should have(1).score
164
+ dsl.node.children.should have(1).score
166
165
 
167
- score = dsl.node.own_children[0]
168
- score.own_children.should have(1).note_set
169
- score.own_children[0].should == note_set
170
- end
166
+ score = dsl.node.children[0]
167
+ score.children.should have(1).note_set
168
+ score.children[0].should == note_set
171
169
  end
170
+ end
171
+
172
+ describe "#stanza" do
173
+ it "should add a stanza with the name" do
174
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
175
+ dsl.node.children.should be_empty
172
176
 
173
- describe "stanza(name, &block)" do
174
- it "should add a stanza with the name" do
175
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
176
- dsl.node.own_children.should be_empty
177
+ dsl.stanza 'Intro'
177
178
 
178
- dsl.stanza 'Intro'
179
+ dsl.node.children.should have(1).stanza
179
180
 
180
- dsl.node.own_children.should have(1).stanza
181
+ stanza = dsl.node.children[0]
182
+ stanza.name.should == 'Intro'
183
+ stanza.children.should be_empty
184
+ end
185
+
186
+ it "should add the definition_children declared in the block to the stanza" do
187
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
188
+ dsl.node.children.should be_empty
181
189
 
182
- stanza = dsl.node.own_children[0]
183
- stanza.name.should == 'Intro'
184
- stanza.own_children.should be_empty
190
+ line = FactoryGirl.build(:line)
191
+
192
+ dsl.stanza 'Intro' do
193
+ add line
185
194
  end
186
195
 
187
- it "should add the children declared in the block to the stanza" do
188
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
189
- dsl.node.own_children.should be_empty
196
+ dsl.node.children.should have(1).stanza
197
+ dsl.node.children[0].name.should == 'Intro'
190
198
 
191
- line = FactoryGirl.build(:line)
199
+ stanza = dsl.node.children[0]
200
+ stanza.children.should have(1).line
201
+ stanza.children[0].should == line
202
+ end
203
+ end
192
204
 
193
- dsl.stanza 'Intro' do
194
- add line
195
- end
205
+ [:title, :composer, :arranger, :instrument, :key, :midi_instrument, :string_tunings, :tempo, :transposition].each do |property|
206
+ describe "##{property}" do
207
+ it "should set the #{property} of the tab to value" do
208
+ tab = FactoryGirl.build(:tab)
196
209
 
197
- dsl.node.own_children.should have(1).stanza
198
- dsl.node.own_children[0].name.should == 'Intro'
210
+ dsl = FactoryGirl.build(:dsl, :node => tab)
211
+ dsl.send property, "test"
199
212
 
200
- stanza = dsl.node.own_children[0]
201
- stanza.own_children.should have(1).line
202
- stanza.own_children[0].should == line
213
+ tab.send(property).should == "test"
203
214
  end
204
215
  end
216
+ end
205
217
 
206
- [:title, :composer, :arranger, :instrument, :key, :midi_instrument, :string_tunings, :tempo, :transposition].each do |property|
207
- describe "#{property}(value)" do
208
- it "should set the #{property} of the tab to value" do
209
- tab = FactoryGirl.build(:tab)
218
+ describe "#chords" do
219
+ it "should add a chord set with the name" do
220
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
221
+ dsl.node.children.should be_empty
210
222
 
211
- dsl = FactoryGirl.build(:dsl, :node => tab)
212
- dsl.send property, "test"
223
+ dsl.chords :Am, 'r4-"Am" r r r'
213
224
 
214
- tab.send(property).should == "test"
215
- end
216
- end
225
+ dsl.node.children.should have(1).chord_set
226
+
227
+ chord_set = dsl.node.children[0]
228
+ chord_set.name.should == :Am
229
+ chord_set.value.should == 'r4-"Am" r r r'
217
230
  end
231
+ end
218
232
 
219
- describe "chords(name, value)" do
220
- it "should add a chord set with the name" do
221
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
222
- dsl.node.own_children.should be_empty
233
+ describe "#chords" do
234
+ it "should add a bar with the name" do
235
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
236
+ dsl.node.children.should be_empty
223
237
 
224
- dsl.chords :Am, 'r4-"Am" r r r'
238
+ dsl.chords :Am
225
239
 
226
- dsl.node.own_children.should have(1).chord_set
240
+ dsl.node.children.should have(1).chord_set
227
241
 
228
- chord_set = dsl.node.own_children[0]
229
- chord_set.name.should == :Am
230
- chord_set.value.should == 'r4-"Am" r r r'
231
- end
242
+ chord_set = dsl.node.children[0]
243
+ chord_set.name.should == :Am
244
+ end
245
+ end
246
+
247
+ describe "#partial" do
248
+ it "should set the specified duration of the bar node to duration" do
249
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:bar))
250
+ dsl.node.specified_duration.should be_nil
251
+
252
+ dsl.partial 8
253
+
254
+ dsl.node.specified_duration.should == 8
232
255
  end
256
+ end
233
257
 
234
- describe "chords(name)" do
235
- it "should add a bar with the name" do
236
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
237
- dsl.node.own_children.should be_empty
258
+ describe "#repeat" do
259
+ it "should add a repeat with the value" do
260
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
238
261
 
239
- dsl.chords :Am
262
+ dsl.repeat 2
240
263
 
241
- dsl.node.own_children.should have(1).chord_set
264
+ dsl.node.children.should have(1).repeat
242
265
 
243
- chord_set = dsl.node.own_children[0]
244
- chord_set.name.should == :Am
245
- end
266
+ repeat = dsl.node.children[0]
267
+ repeat.value.should == 2
268
+ repeat.children.should be_empty
246
269
  end
247
270
 
248
- describe "partial(duration)" do
249
- it "should set the specified duration of the bar node to duration" do
250
- dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:bar))
251
- dsl.node.specified_duration.should be_nil
271
+ it "should add the children declared in the block to the repeat" do
272
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
252
273
 
253
- dsl.partial 8
274
+ bar = FactoryGirl.build(:bar)
254
275
 
255
- dsl.node.specified_duration.should == 8
276
+ dsl.repeat 2 do
277
+ add bar
256
278
  end
279
+
280
+ dsl.node.children.should have(1).repeat
281
+
282
+ repeat = dsl.node.children[0]
283
+ repeat.children.should have(1).child
284
+ repeat.children[0].should == bar
285
+ end
286
+ end
287
+
288
+ describe "#alternative" do
289
+ it "should add the children declared in the block to the alternative" do
290
+ dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
291
+ bar = FactoryGirl.build(:bar)
292
+
293
+ dsl.alternative do
294
+ add bar
295
+ end
296
+
297
+ dsl.node.children.should have(1).alternative
298
+
299
+ alternative = dsl.node.children[0]
300
+ alternative.children.should have(1).child
301
+ alternative.children[0].should == bar
257
302
  end
258
303
  end
259
304
  end