gitara 0.1.1 → 0.2.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.
@@ -1,10 +1,16 @@
1
- 0.1.0 - 2012-02-17
1
+ 0.2.0 - 2012-02-19
2
2
  ------------------
3
3
 
4
- * Added notes, bars, lines and scores to API.
4
+ * [#13] Add stanzas.
5
5
 
6
6
  0.1.1 - 2012-02-18
7
7
  ------------------
8
8
 
9
9
  * [#12] Expressions should be id'd based on class.
10
10
 
11
+ 0.1.0 - 2012-02-17
12
+ ------------------
13
+
14
+ * Added notes, bars, lines and scores to API.
15
+
16
+
@@ -24,14 +24,18 @@ Gitara is a Ruby DSL. A typical Gitara file will have the following structure:
24
24
 
25
25
  Gitara.define do
26
26
  score do
27
- line do
28
- bar do
29
- notes "c d e f g a b c"
27
+ stanza "Verse 1" do
28
+ line do
29
+ bar do
30
+ notes "c d e f g a b c"
31
+ end
30
32
  end
31
33
  end
32
34
  end
33
35
  end
34
36
 
37
+ You can find examples in the examples directory.
38
+
35
39
 
36
40
  Bars
37
41
  ----
@@ -169,6 +173,12 @@ Lines are manually breaked with [\\break](http://lilypond.org/doc/v2.12/Document
169
173
  Like bars, lines can be named, reused, etc.
170
174
 
171
175
 
176
+ Stanzas
177
+ -------
178
+
179
+ The names of a stanza will be displayed at the top of the stanza's first bar.
180
+
181
+
172
182
  Notes with single quotes and backslashes
173
183
  ----------------------------------------
174
184
 
@@ -200,12 +210,11 @@ I'm no Lilypond expert (heh). When writing a tab, I use [TuxGuitar](http://tuxgu
200
210
  To do
201
211
  -----
202
212
 
203
- For version 1, I want to convert this lilypond file I wrote to Gitara format:
213
+ For version 1, I want to convert this lilypond file to Gitara format:
204
214
 
205
215
  * [https://github.com/gsmendoza/tabs/tree/master/aimee-mann-wise-up](https://github.com/gsmendoza/tabs/tree/master/aimee-mann-wise-up)
206
216
 
207
217
  The remaining features are:
208
218
 
209
219
  1. Properties like the title and authors
210
- 2. Stanza labels
211
- 3. Chord labels
220
+ 2. Chord labels
@@ -1,6 +1,10 @@
1
1
  \version "2.12.3"
2
2
  \include "english.ly"
3
3
 
4
+ \paper {
5
+ indent = #0
6
+ }
7
+
4
8
  %-----------------------------------------------------------------------
5
9
  % Bars
6
10
 
@@ -77,45 +81,89 @@ vTwoLineIntroLineOne = { \vTwoBarIntro \vTwoBarIntro \vTwoBarIntro \vTwoBarIntro
77
81
  vOneLineVerseOneLineTwo = { \vOneBarYouGot \vOneBarWhatYouThought \vOneBarWhenYouFirst \vOneBarItThough \break }
78
82
  vTwoLineVerseOneLineTwo = { \vTwoBarYouGot \vTwoBarWhatYouThought \vTwoBarWhenYouFirst \vTwoBarItThough \break }
79
83
 
80
- vOneLineTabOneScoreTwentyFourLineTwo = { \vOneBarItsNot \vOneBarWhatYouThought \vOneBarWhenYouFirst \vOneBarBeganIt \break }
81
- vTwoLineTabOneScoreTwentyFourLineTwo = { \vTwoBarItsNot \vTwoBarWhatYouThought \vTwoBarWhenYouFirst \vTwoBarBeganIt \break }
84
+ vOneLineVerseOneLineOne = { \vOneBarItsNot \vOneBarWhatYouThought \vOneBarWhenYouFirst \vOneBarBeganIt \break }
85
+ vTwoLineVerseOneLineOne = { \vTwoBarItsNot \vTwoBarWhatYouThought \vTwoBarWhenYouFirst \vTwoBarBeganIt \break }
86
+
87
+ vOneLineChorusOneLineTwo = { \vOneBarItsNotGoingToStopCcge \vOneBarTilYouWiseUp \vOneBarIntro \vOneBarIntro \break }
88
+ vTwoLineChorusOneLineTwo = { \vTwoBarItsNotGoingToStopCcge \vTwoBarTilYouWiseUp \vTwoBarIntro \vTwoBarIntro \break }
89
+
90
+ vOneLineVerseTwoLineOne = { \vOneBarYoureSure \vOneBarTheresACure \vOneBarWhenYouFirst \vOneBarBeganIt \break }
91
+ vTwoLineVerseTwoLineOne = { \vTwoBarYoureSure \vTwoBarTheresACure \vTwoBarWhenYouFirst \vTwoBarBeganIt \break }
92
+
93
+ vOneLineChorusTwoLineTwo = { \vOneBarItsNotGoingToStopCcge \vOneBarTilYouWiseUpTwo \vOneBarIntro \vOneBarIntro \break }
94
+ vTwoLineChorusTwoLineTwo = { \vTwoBarItsNotGoingToStopCcge \vTwoBarTilYouWiseUpTwo \vTwoBarIntro \vTwoBarIntro \break }
95
+
96
+ vOneLineBridgeLineOne = { \vOneBarPrepareAList \vOneBarBeforeYouSign \break }
97
+ vTwoLineBridgeLineOne = { \vTwoBarPrepareAList \vTwoBarBeforeYouSign \break }
98
+
99
+ vOneLineChorusThreeLineTwo = { \vOneBarItsNotGoingToStopCcge \vOneBarTilYouWiseUpThree \vOneBarItsNotGoingToStopCcgeTwo \vOneBarTilYouWiseUpThree \break }
100
+ vTwoLineChorusThreeLineTwo = { \vTwoBarItsNotGoingToStopCcge \vTwoBarTilYouWiseUpThree \vTwoBarItsNotGoingToStopCcgeTwo \vTwoBarTilYouWiseUpThree \break }
101
+
102
+ vOneLineChorusThreeLineThree = { \vOneBarItsNotGoingToStopCcgeTwo \vOneBarTilYouWiseUpThree \vOneBarItsNotGoingToStopCcgeTwo \vOneBarSoJustGiveUp \break }
103
+ vTwoLineChorusThreeLineThree = { \vTwoBarItsNotGoingToStopCcgeTwo \vTwoBarTilYouWiseUpThree \vTwoBarItsNotGoingToStopCcgeTwo \vTwoBarSoJustGiveUp \break }
104
+
105
+ vOneLineOutroLineTwo = { \vOneBarOutro \vOneBarOutro \vOneBarOutro \vOneBarOutro \break }
106
+ vTwoLineOutroLineTwo = { \vTwoBarOutro \vTwoBarOutro \vTwoBarOutro \vTwoBarOutro \break }
107
+
82
108
 
83
- vOneLineTabOneScoreTwentyFourLineFive = { \vOneBarItsNotGoingToStopCcge \vOneBarTilYouWiseUp \vOneBarIntro \vOneBarIntro \break }
84
- vTwoLineTabOneScoreTwentyFourLineFive = { \vTwoBarItsNotGoingToStopCcge \vTwoBarTilYouWiseUp \vTwoBarIntro \vTwoBarIntro \break }
109
+ %-----------------------------------------------------------------------
110
+ % Stanzas
111
+
112
+ vOneStanzaIntro = { \vOneLineIntroLineOne }
113
+ vTwoStanzaIntro = { \vTwoLineIntroLineOne }
114
+
115
+ vOneStanzaVerseOne = { \vOneLineVerseOneLineOne \vOneLineVerseOneLineTwo }
116
+ vTwoStanzaVerseOne = { \vTwoLineVerseOneLineOne \vTwoLineVerseOneLineTwo }
85
117
 
86
- vOneLineTabOneScoreTwentyFourLineSix = { \vOneBarYoureSure \vOneBarTheresACure \vOneBarWhenYouFirst \vOneBarBeganIt \break }
87
- vTwoLineTabOneScoreTwentyFourLineSix = { \vTwoBarYoureSure \vTwoBarTheresACure \vTwoBarWhenYouFirst \vTwoBarBeganIt \break }
118
+ vOneStanzaChorusOne = { \vOneLineChorusOneLineOne \vOneLineChorusOneLineTwo }
119
+ vTwoStanzaChorusOne = { \vTwoLineChorusOneLineOne \vTwoLineChorusOneLineTwo }
88
120
 
89
- vOneLineTabOneScoreTwentyFourLineNine = { \vOneBarItsNotGoingToStopCcge \vOneBarTilYouWiseUpTwo \vOneBarIntro \vOneBarIntro \break }
90
- vTwoLineTabOneScoreTwentyFourLineNine = { \vTwoBarItsNotGoingToStopCcge \vTwoBarTilYouWiseUpTwo \vTwoBarIntro \vTwoBarIntro \break }
121
+ vOneStanzaVerseTwo = { \vOneLineVerseTwoLineOne \vOneLineVerseOneLineTwo }
122
+ vTwoStanzaVerseTwo = { \vTwoLineVerseTwoLineOne \vTwoLineVerseOneLineTwo }
91
123
 
92
- vOneLineTabOneScoreTwentyFourLineTen = { \vOneBarPrepareAList \vOneBarBeforeYouSign \break }
93
- vTwoLineTabOneScoreTwentyFourLineTen = { \vTwoBarPrepareAList \vTwoBarBeforeYouSign \break }
124
+ vOneStanzaChorusTwo = { \vOneLineChorusOneLineOne \vOneLineChorusTwoLineTwo }
125
+ vTwoStanzaChorusTwo = { \vTwoLineChorusOneLineOne \vTwoLineChorusTwoLineTwo }
94
126
 
95
- vOneLineTabOneScoreTwentyFourLineTwelve = { \vOneBarItsNotGoingToStopCcge \vOneBarTilYouWiseUpThree \vOneBarItsNotGoingToStopCcgeTwo \vOneBarTilYouWiseUpThree \break }
96
- vTwoLineTabOneScoreTwentyFourLineTwelve = { \vTwoBarItsNotGoingToStopCcge \vTwoBarTilYouWiseUpThree \vTwoBarItsNotGoingToStopCcgeTwo \vTwoBarTilYouWiseUpThree \break }
127
+ vOneStanzaBridge = { \vOneLineBridgeLineOne }
128
+ vTwoStanzaBridge = { \vTwoLineBridgeLineOne }
97
129
 
98
- vOneLineTabOneScoreTwentyFourLineThirteen = { \vOneBarItsNotGoingToStopCcgeTwo \vOneBarTilYouWiseUpThree \vOneBarItsNotGoingToStopCcgeTwo \vOneBarSoJustGiveUp \break }
99
- vTwoLineTabOneScoreTwentyFourLineThirteen = { \vTwoBarItsNotGoingToStopCcgeTwo \vTwoBarTilYouWiseUpThree \vTwoBarItsNotGoingToStopCcgeTwo \vTwoBarSoJustGiveUp \break }
130
+ vOneStanzaChorusThree = { \vOneLineChorusOneLineOne \vOneLineChorusThreeLineTwo \vOneLineChorusThreeLineThree }
131
+ vTwoStanzaChorusThree = { \vTwoLineChorusOneLineOne \vTwoLineChorusThreeLineTwo \vTwoLineChorusThreeLineThree }
100
132
 
101
- vOneLineTabOneScoreTwentyFourLineFifteen = { \vOneBarOutro \vOneBarOutro \vOneBarOutro \vOneBarOutro \break }
102
- vTwoLineTabOneScoreTwentyFourLineFifteen = { \vTwoBarOutro \vTwoBarOutro \vTwoBarOutro \vTwoBarOutro \break }
133
+ vOneStanzaOutro = { \vOneLineIntroLineOne \vOneLineOutroLineTwo }
134
+ vTwoStanzaOutro = { \vTwoLineIntroLineOne \vTwoLineOutroLineTwo }
103
135
 
104
136
 
105
137
  %-----------------------------------------------------------------------
106
138
  % Scores
107
139
 
108
- vOneScoreTabOneScoreTwentyFour = { \vOneLineIntroLineOne \vOneLineTabOneScoreTwentyFourLineTwo \vOneLineVerseOneLineTwo \vOneLineChorusOneLineOne \vOneLineTabOneScoreTwentyFourLineFive \vOneLineTabOneScoreTwentyFourLineSix \vOneLineVerseOneLineTwo \vOneLineChorusOneLineOne \vOneLineTabOneScoreTwentyFourLineNine \vOneLineTabOneScoreTwentyFourLineTen \vOneLineChorusOneLineOne \vOneLineTabOneScoreTwentyFourLineTwelve \vOneLineTabOneScoreTwentyFourLineThirteen \vOneLineIntroLineOne \vOneLineTabOneScoreTwentyFourLineFifteen }
109
- vTwoScoreTabOneScoreTwentyFour = { \vTwoLineIntroLineOne \vTwoLineTabOneScoreTwentyFourLineTwo \vTwoLineVerseOneLineTwo \vTwoLineChorusOneLineOne \vTwoLineTabOneScoreTwentyFourLineFive \vTwoLineTabOneScoreTwentyFourLineSix \vTwoLineVerseOneLineTwo \vTwoLineChorusOneLineOne \vTwoLineTabOneScoreTwentyFourLineNine \vTwoLineTabOneScoreTwentyFourLineTen \vTwoLineChorusOneLineOne \vTwoLineTabOneScoreTwentyFourLineTwelve \vTwoLineTabOneScoreTwentyFourLineThirteen \vTwoLineIntroLineOne \vTwoLineTabOneScoreTwentyFourLineFifteen }
140
+ vOneScoreTabOneScoreOne = { \vOneStanzaIntro \vOneStanzaVerseOne \vOneStanzaChorusOne \vOneStanzaVerseTwo \vOneStanzaChorusTwo \vOneStanzaBridge \vOneStanzaChorusThree \vOneStanzaOutro }
141
+ vTwoScoreTabOneScoreOne = { \vTwoStanzaIntro \vTwoStanzaVerseOne \vTwoStanzaChorusOne \vTwoStanzaVerseTwo \vTwoStanzaChorusTwo \vTwoStanzaBridge \vTwoStanzaChorusThree \vTwoStanzaOutro }
110
142
 
111
143
 
112
144
  %-----------------------------------------------------------------------
113
145
  % Voices
114
146
 
115
- vOne = { \vOneScoreTabOneScoreTwentyFour }
147
+ vOne = { \vOneScoreTabOneScoreOne }
148
+
149
+ vTwo = { \vTwoScoreTabOneScoreOne }
150
+
116
151
 
117
- vTwo = { \vTwoScoreTabOneScoreTwentyFour }
152
+ %-----------------------------------------------------------------------
153
+ % Stanza Headings
154
+
155
+ stanzaHeadings = {
156
+ r1^"Intro" r r r
157
+ r1^"Verse 1" r r r r r r r
158
+ r1^"Chorus 1" r r r r r r r
159
+ r1^"Verse 2" r r r r r r r
160
+ r1^"Chorus 2" r r r r r r r
161
+ r1^"Bridge" r
162
+ r1^"Chorus 3" r r r r r r r r r r r
163
+ r1^"Outro" r r r r r r r
164
+ }
118
165
 
166
+ %-----------------------------------------------------------------------
119
167
 
120
168
  \score {
121
169
  \new StaffGroup <<
@@ -123,6 +171,10 @@ vTwo = { \vTwoScoreTabOneScoreTwentyFour }
123
171
  \tempo 4 = 75
124
172
  \clef "treble_8"
125
173
 
174
+ \new Voice \with { \remove Rest_engraver } {
175
+ \stanzaHeadings
176
+ }
177
+
126
178
  \new Voice {
127
179
  \voiceOne
128
180
  \vOne
@@ -116,55 +116,63 @@ Gitara.define do
116
116
  #-----------------------------------------------------------------------
117
117
 
118
118
  score do
119
- # stanza Intro do
120
- line :IntroLineOne
121
-
122
- # stanza "Verse 1" do
123
- line do
124
- bar :ItsNot, :WhatYouThought, :WhenYouFirst, :BeganIt
119
+ stanza "Intro" do
120
+ line :IntroLineOne
125
121
  end
126
122
 
127
- line :VerseOneLineTwo
123
+ stanza "Verse 1" do
124
+ line do
125
+ bar :ItsNot, :WhatYouThought, :WhenYouFirst, :BeganIt
126
+ end
128
127
 
129
- # stanza "Chorus 1" do
130
- line :ChorusOneLineOne
131
- line do
132
- bar :ItsNotGoingToStopCcge, :TilYouWiseUp, :Intro, :Intro
128
+ line :VerseOneLineTwo
133
129
  end
134
130
 
135
- # stanza "Verse 2" do
136
- line do
137
- bar :YoureSure, :TheresACure, :WhenYouFirst, :BeganIt
131
+ stanza "Chorus 1" do
132
+ line :ChorusOneLineOne
133
+ line do
134
+ bar :ItsNotGoingToStopCcge, :TilYouWiseUp, :Intro, :Intro
135
+ end
138
136
  end
139
137
 
140
- line :VerseOneLineTwo
138
+ stanza "Verse 2" do
139
+ line do
140
+ bar :YoureSure, :TheresACure, :WhenYouFirst, :BeganIt
141
+ end
141
142
 
142
- # stanza "Chorus 2" do
143
- line :ChorusOneLineOne
144
- line do
145
- bar :ItsNotGoingToStopCcge, :TilYouWiseUpTwo, :Intro, :Intro
143
+ line :VerseOneLineTwo
146
144
  end
147
145
 
148
- # stanza "Bridge" do
149
- line do
150
- bar :PrepareAList, :BeforeYouSign
146
+ stanza "Chorus 2" do
147
+ line :ChorusOneLineOne
148
+ line do
149
+ bar :ItsNotGoingToStopCcge, :TilYouWiseUpTwo, :Intro, :Intro
150
+ end
151
151
  end
152
152
 
153
- # stanza "Chorus 3" do
154
- line :ChorusOneLineOne
155
-
156
- line do
157
- bar :ItsNotGoingToStopCcge, :TilYouWiseUpThree, :ItsNotGoingToStopCcgeTwo, :TilYouWiseUpThree
153
+ stanza "Bridge" do
154
+ line do
155
+ bar :PrepareAList, :BeforeYouSign
156
+ end
158
157
  end
159
158
 
160
- line do
161
- bar :ItsNotGoingToStopCcgeTwo, :TilYouWiseUpThree, :ItsNotGoingToStopCcgeTwo, :SoJustGiveUp
159
+ stanza "Chorus 3" do
160
+ line :ChorusOneLineOne
161
+
162
+ line do
163
+ bar :ItsNotGoingToStopCcge, :TilYouWiseUpThree, :ItsNotGoingToStopCcgeTwo, :TilYouWiseUpThree
164
+ end
165
+
166
+ line do
167
+ bar :ItsNotGoingToStopCcgeTwo, :TilYouWiseUpThree, :ItsNotGoingToStopCcgeTwo, :SoJustGiveUp
168
+ end
162
169
  end
163
170
 
164
- # stanza "Outro" do
165
- line :IntroLineOne
166
- line do
167
- bar :Outro, :Outro, :Outro, :Outro
171
+ stanza "Outro" do
172
+ line :IntroLineOne
173
+ line do
174
+ bar :Outro, :Outro, :Outro, :Outro
175
+ end
168
176
  end
169
177
  end
170
178
  end
@@ -1,6 +1,10 @@
1
1
  \version "2.12.3"
2
2
  \include "english.ly"
3
3
 
4
+ \paper {
5
+ indent = #0
6
+ }
7
+
4
8
  %-----------------------------------------------------------------------
5
9
  % Bars
6
10
 
@@ -29,15 +33,22 @@ vTwoBarYouGot = { <f\4>4 <f\4>4 <c\5>4 <e\4>4 }
29
33
  vOneLineVerseOneLineTwo = { \vOneBarYouGot \vOneBarWhatYouThought \vOneBarWhenYouFirst \vOneBarItThough \break }
30
34
  vTwoLineVerseOneLineTwo = { \vTwoBarYouGot \vTwoBarWhatYouThought \vTwoBarWhenYouFirst \vTwoBarItThough \break }
31
35
 
32
- vOneLineTabOneScoreOneLineOne = { \vOneBarItsNot \vOneBarWhatYouThought \vOneBarWhenYouFirst \vOneBarBeganIt \break }
33
- vTwoLineTabOneScoreOneLineOne = { \vTwoBarItsNot \vTwoBarWhatYouThought \vTwoBarWhenYouFirst \vTwoBarBeganIt \break }
36
+ vOneLineVerseOneLineOne = { \vOneBarItsNot \vOneBarWhatYouThought \vOneBarWhenYouFirst \vOneBarBeganIt \break }
37
+ vTwoLineVerseOneLineOne = { \vTwoBarItsNot \vTwoBarWhatYouThought \vTwoBarWhenYouFirst \vTwoBarBeganIt \break }
38
+
39
+
40
+ %-----------------------------------------------------------------------
41
+ % Stanzas
42
+
43
+ vOneStanzaVerseOne = { \vOneLineVerseOneLineOne \vOneLineVerseOneLineTwo }
44
+ vTwoStanzaVerseOne = { \vTwoLineVerseOneLineOne \vTwoLineVerseOneLineTwo }
34
45
 
35
46
 
36
47
  %-----------------------------------------------------------------------
37
48
  % Scores
38
49
 
39
- vOneScoreTabOneScoreOne = { \vOneLineTabOneScoreOneLineOne \vOneLineVerseOneLineTwo }
40
- vTwoScoreTabOneScoreOne = { \vTwoLineTabOneScoreOneLineOne \vTwoLineVerseOneLineTwo }
50
+ vOneScoreTabOneScoreOne = { \vOneStanzaVerseOne }
51
+ vTwoScoreTabOneScoreOne = { \vTwoStanzaVerseOne }
41
52
 
42
53
 
43
54
  %-----------------------------------------------------------------------
@@ -48,12 +59,25 @@ vOne = { \vOneScoreTabOneScoreOne }
48
59
  vTwo = { \vTwoScoreTabOneScoreOne }
49
60
 
50
61
 
62
+ %-----------------------------------------------------------------------
63
+ % Stanza Headings
64
+
65
+ stanzaHeadings = {
66
+ r1^"Verse 1" r r r r r r r
67
+ }
68
+
69
+ %-----------------------------------------------------------------------
70
+
51
71
  \score {
52
72
  \new StaffGroup <<
53
73
  \new Staff <<
54
74
  \tempo 4 = 75
55
75
  \clef "treble_8"
56
76
 
77
+ \new Voice \with { \remove Rest_engraver } {
78
+ \stanzaHeadings
79
+ }
80
+
57
81
  \new Voice {
58
82
  \voiceOne
59
83
  \vOne
@@ -34,10 +34,12 @@ Gitara.define do
34
34
  end
35
35
 
36
36
  score do
37
- line do
38
- bar :ItsNot, :WhatYouThought, :WhenYouFirst, :BeganIt
39
- end
37
+ stanza "Verse 1" do
38
+ line do
39
+ bar :ItsNot, :WhatYouThought, :WhenYouFirst, :BeganIt
40
+ end
40
41
 
41
- line :VerseOneLineTwo
42
+ line :VerseOneLineTwo
43
+ end
42
44
  end
43
45
  end
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
21
21
  s.add_runtime_dependency "active_support"
22
22
  s.add_runtime_dependency "erubis"
23
23
  s.add_runtime_dependency "linguistics"
24
- s.add_runtime_dependency "parslet"
25
24
  s.add_runtime_dependency "pow"
26
25
  s.add_runtime_dependency "thor"
27
26
  s.add_runtime_dependency "valuable"
@@ -1,7 +1,6 @@
1
1
  require "active_support/inflector"
2
2
  require "erubis"
3
3
  require "linguistics"
4
- require "parslet"
5
4
  require "pow"
6
5
  require "thor"
7
6
  require "valuable"
@@ -15,6 +14,7 @@ require "gitara/node/bar/voiced_node"
15
14
  require "gitara/node/line"
16
15
  require "gitara/node/note_set"
17
16
  require "gitara/node/score"
17
+ require "gitara/node/stanza"
18
18
  require "gitara/node/tab"
19
19
  require "gitara/pow/base"
20
20
  require "gitara/utilities"
@@ -31,5 +31,9 @@ module Gitara
31
31
  def score(*names, &block)
32
32
  add_names :names => names, :node_class => Node::Score, &block
33
33
  end
34
+
35
+ def stanza(*names, &block)
36
+ add_names :names => names, :node_class => Node::Stanza, &block
37
+ end
34
38
  end
35
39
  end
@@ -26,10 +26,26 @@ module Gitara
26
26
  end
27
27
  end
28
28
 
29
+ def definition(target = self)
30
+ if self.definition_of?(target)
31
+ self
32
+ else
33
+ result = parent.own_children.detect{|node| node.definition_of?(target) }
34
+ result ? result : parent.definition(target)
35
+ end
36
+ end
37
+
29
38
  def definition?
30
39
  ! own_children.empty?
31
40
  end
32
41
 
42
+ def definition_name
43
+ name.to_s.
44
+ gsub(/\W/, '_').
45
+ gsub(/\d+/){|s| Utilities.id_as_word(s)}.
46
+ camelize
47
+ end
48
+
33
49
  def definition_of?(target)
34
50
  self.definition? && self.name == target.name && self.class == target.class
35
51
  end
@@ -38,10 +54,18 @@ module Gitara
38
54
  self.is_a?(klass) && self.definition? ? [self] : self.own_children.map{|child| child.definitions(klass) }.flatten
39
55
  end
40
56
 
57
+ def descendants(klass)
58
+ self.is_a?(klass) ? [self.definition] : self.children.map{|child| child.descendants(klass) }.flatten
59
+ end
60
+
41
61
  def id_as_word
42
62
  Utilities.id_as_word(id)
43
63
  end
44
64
 
65
+ def inspect
66
+ Utilities.inspect_attributes self, :name
67
+ end
68
+
45
69
  def name
46
70
  attributes[:name] || "#{parent && parent.name}#{self.class.to_s.split('::').last}#{self.id_as_word}"
47
71
  end
@@ -67,17 +91,6 @@ module Gitara
67
91
  raise ArgumentError
68
92
  end
69
93
  end
70
-
71
- private
72
-
73
- def definition(target = self)
74
- if self.definition_of?(target)
75
- self
76
- else
77
- result = parent.own_children.detect{|node| node.definition_of?(target) }
78
- result ? result : parent.definition(target)
79
- end
80
- end
81
94
  end
82
95
  end
83
96
  end
@@ -14,7 +14,7 @@ module Gitara
14
14
  end
15
15
 
16
16
  def definition_name
17
- "#{voice.definition_name}#{node.class.to_s.split('::').last}#{node.name}"
17
+ "#{voice.definition_name}#{node.class.to_s.split('::').last}#{node.definition_name}"
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,11 @@
1
+ module Gitara
2
+ module Node
3
+ class Stanza < Base
4
+ def heading_in_lilypond
5
+ results = Array.new(descendants(Node::Bar).size, 'r')
6
+ results[0] = %Q|r1^"#{name}"|
7
+ results.join(' ')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ <% self.voiced_as(self.root.voices).each do |voiced_stanza| %>
2
+ <%= voiced_stanza.definition_name %> = { <%= voiced_stanza.children.map(&:call_name).join(' ') %> }
3
+ <% end %>
@@ -1,6 +1,10 @@
1
1
  \version "2.12.3"
2
2
  \include "english.ly"
3
3
 
4
+ \paper {
5
+ indent = #0
6
+ }
7
+
4
8
  %-----------------------------------------------------------------------
5
9
  % Bars
6
10
 
@@ -15,6 +19,13 @@
15
19
  <%= Gitara.render('line', line) %>
16
20
  <% end %>
17
21
 
22
+ %-----------------------------------------------------------------------
23
+ % Stanzas
24
+
25
+ <% definitions(Gitara::Node::Stanza).each do |stanza| %>
26
+ <%= Gitara.render('stanza', stanza) %>
27
+ <% end %>
28
+
18
29
  %-----------------------------------------------------------------------
19
30
  % Scores
20
31
 
@@ -29,12 +40,27 @@
29
40
  <%= Gitara.render('voice', voice) %>
30
41
  <% end %>
31
42
 
43
+ %-----------------------------------------------------------------------
44
+ % Stanza Headings
45
+
46
+ stanzaHeadings = {
47
+ <% definitions(Gitara::Node::Stanza).each do |stanza| %>
48
+ <%= stanza.heading_in_lilypond %>
49
+ <% end %>
50
+ }
51
+
52
+ %-----------------------------------------------------------------------
53
+
32
54
  \score {
33
55
  \new StaffGroup <<
34
56
  \new Staff <<
35
57
  \tempo 4 = 75
36
58
  \clef "treble_8"
37
59
 
60
+ \new Voice \with { \remove Rest_engraver } {
61
+ \stanzaHeadings
62
+ }
63
+
38
64
  <% voices.each do |voice| %>
39
65
  \new Voice {
40
66
  <%= voice.stem_type %>
@@ -3,6 +3,10 @@ module Gitara
3
3
  def self.id_as_word(id)
4
4
  id.en.numwords.gsub('-', '_').camelize
5
5
  end
6
+
7
+ def self.inspect_attributes(object, *attributes)
8
+ "#{object.class}(" + attributes.collect{|a| "#{a}=#{object.send(a).inspect}"}.join(', ') + ")"
9
+ end
6
10
  end
7
11
  end
8
12
 
@@ -1,3 +1,3 @@
1
1
  module Gitara
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -6,7 +6,11 @@ describe App do
6
6
  app = Gitara::App.new
7
7
  app.invoke :export, ['examples/tab.rb'], "target-directory" => test_tmp_dir.path, "run-lilypond" => false
8
8
 
9
- (test_tmp_dir / 'tab.ly').read.should == Pow('examples/tab.ly').read
9
+ example = Pow('examples/tab.ly').read
10
+ actual = (test_tmp_dir / 'tab.ly').read
11
+
12
+ (Pow('tmp') / 'new-tab.ly').write actual if example != actual
13
+ actual.should == example
10
14
  end
11
15
  end
12
16
  end
@@ -169,5 +169,38 @@ describe Gitara do
169
169
  score.own_children[0].should == note_set
170
170
  end
171
171
  end
172
+
173
+ describe "stanza(name, &block)" do
174
+ it "should add a stanza with the name" do
175
+ dsl = Dsl.new(:node => Node::Tab.new)
176
+ dsl.node.own_children.should be_empty
177
+
178
+ dsl.stanza 'Intro'
179
+
180
+ dsl.node.own_children.should have(1).stanza
181
+
182
+ stanza = dsl.node.own_children[0]
183
+ stanza.name.should == 'Intro'
184
+ stanza.own_children.should be_empty
185
+ end
186
+
187
+ it "should add the children declared in the block to the stanza" do
188
+ dsl = Dsl.new(:node => Node::Tab.new)
189
+ dsl.node.own_children.should be_empty
190
+
191
+ line = Node::Line.new
192
+
193
+ dsl.stanza 'Intro' do
194
+ add line
195
+ end
196
+
197
+ dsl.node.own_children.should have(1).stanza
198
+ dsl.node.own_children[0].name.should == 'Intro'
199
+
200
+ stanza = dsl.node.own_children[0]
201
+ stanza.own_children.should have(1).line
202
+ stanza.own_children[0].should == line
203
+ end
204
+ end
172
205
  end
173
206
  end
@@ -214,4 +214,49 @@ describe Node::Base do
214
214
  node.id_as_word.should == "TwentyFour"
215
215
  end
216
216
  end
217
+
218
+ describe "definition_name" do
219
+ it "should turn the name to a lilypond acceptable name" do
220
+ node = Node::Base.new(:name => "Verse 1 line-2")
221
+ node.definition_name.should == "VerseOneLineTwo"
222
+ end
223
+ end
224
+
225
+ describe "descendants(klass)" do
226
+ it "should be itself if it is an instance of the klass" do
227
+ tab = Node::Tab.new(:children => [Node::Bar.new])
228
+ tab.descendants(Node::Tab).should == [tab]
229
+ end
230
+
231
+ it "should include descendants which are instances of klass" do
232
+ tab = Node::Tab.new(:children => [
233
+ Node::Bar.new(:name => :Intro, :children => [
234
+ Node::NoteSet.new
235
+ ])
236
+ ])
237
+
238
+ tab.descendants(Node::Bar).should have(1).bar
239
+ end
240
+
241
+ it "should follow the definitions of node references for descendants" do
242
+ tab = Node::Tab.new(:children => [
243
+ Node::Bar.new(:name => :Intro, :children => [
244
+ Node::NoteSet.new
245
+ ]),
246
+
247
+ Node::Line.new(:name => 'Line 1', :children => [
248
+ Node::Bar.new(:name => :Intro)
249
+ ]),
250
+
251
+ Node::Stanza.new(:children => [
252
+ Node::Line.new(:name => 'Line 1')
253
+ ])
254
+ ])
255
+
256
+ bar = tab.own_children[0]
257
+
258
+ stanza = tab.own_children[2]
259
+ stanza.descendants(Node::Bar).should == [bar]
260
+ end
261
+ end
217
262
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Stanza' do
4
+ describe "heading_in_lilypond" do
5
+ it "should allow the stanza's name to be added as a heading to the lilypond template" do
6
+ stanza = Node::Stanza.new(:name => "Verse 1", :children => [
7
+ Node::Line.new(:children => [
8
+ Node::Bar.new(:children => [Node::NoteSet.new]),
9
+ Node::Bar.new(:children => [Node::NoteSet.new]),
10
+ ])
11
+ ])
12
+
13
+ stanza.heading_in_lilypond.should == 'r1^"Verse 1" r'
14
+ end
15
+ end
16
+ end
@@ -1,6 +1,4 @@
1
1
  require 'gitara'
2
- require 'parslet/convenience'
3
- require 'parslet/rig/rspec'
4
2
  require 'pry'
5
3
 
6
4
  RSpec.configure do |config|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitara
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - George Mendoza
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-18 00:00:00 Z
18
+ date: 2012-02-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: active_support
@@ -60,7 +60,7 @@ dependencies:
60
60
  type: :runtime
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
- name: parslet
63
+ name: pow
64
64
  prerelease: false
65
65
  requirement: &id004 !ruby/object:Gem::Requirement
66
66
  none: false
@@ -74,7 +74,7 @@ dependencies:
74
74
  type: :runtime
75
75
  version_requirements: *id004
76
76
  - !ruby/object:Gem::Dependency
77
- name: pow
77
+ name: thor
78
78
  prerelease: false
79
79
  requirement: &id005 !ruby/object:Gem::Requirement
80
80
  none: false
@@ -88,7 +88,7 @@ dependencies:
88
88
  type: :runtime
89
89
  version_requirements: *id005
90
90
  - !ruby/object:Gem::Dependency
91
- name: thor
91
+ name: valuable
92
92
  prerelease: false
93
93
  requirement: &id006 !ruby/object:Gem::Requirement
94
94
  none: false
@@ -102,7 +102,7 @@ dependencies:
102
102
  type: :runtime
103
103
  version_requirements: *id006
104
104
  - !ruby/object:Gem::Dependency
105
- name: valuable
105
+ name: guard
106
106
  prerelease: false
107
107
  requirement: &id007 !ruby/object:Gem::Requirement
108
108
  none: false
@@ -113,10 +113,10 @@ dependencies:
113
113
  segments:
114
114
  - 0
115
115
  version: "0"
116
- type: :runtime
116
+ type: :development
117
117
  version_requirements: *id007
118
118
  - !ruby/object:Gem::Dependency
119
- name: guard
119
+ name: guard-rspec
120
120
  prerelease: false
121
121
  requirement: &id008 !ruby/object:Gem::Requirement
122
122
  none: false
@@ -130,7 +130,7 @@ dependencies:
130
130
  type: :development
131
131
  version_requirements: *id008
132
132
  - !ruby/object:Gem::Dependency
133
- name: guard-rspec
133
+ name: pry
134
134
  prerelease: false
135
135
  requirement: &id009 !ruby/object:Gem::Requirement
136
136
  none: false
@@ -144,7 +144,7 @@ dependencies:
144
144
  type: :development
145
145
  version_requirements: *id009
146
146
  - !ruby/object:Gem::Dependency
147
- name: pry
147
+ name: rb-inotify
148
148
  prerelease: false
149
149
  requirement: &id010 !ruby/object:Gem::Requirement
150
150
  none: false
@@ -158,7 +158,7 @@ dependencies:
158
158
  type: :development
159
159
  version_requirements: *id010
160
160
  - !ruby/object:Gem::Dependency
161
- name: rb-inotify
161
+ name: rspec
162
162
  prerelease: false
163
163
  requirement: &id011 !ruby/object:Gem::Requirement
164
164
  none: false
@@ -171,20 +171,6 @@ dependencies:
171
171
  version: "0"
172
172
  type: :development
173
173
  version_requirements: *id011
174
- - !ruby/object:Gem::Dependency
175
- name: rspec
176
- prerelease: false
177
- requirement: &id012 !ruby/object:Gem::Requirement
178
- none: false
179
- requirements:
180
- - - ">="
181
- - !ruby/object:Gem::Version
182
- hash: 3
183
- segments:
184
- - 0
185
- version: "0"
186
- type: :development
187
- version_requirements: *id012
188
174
  description: A Ruby DSL for generating Lilypond guitar tablatures.
189
175
  email:
190
176
  - gsmendoza@gmail.com
@@ -221,11 +207,13 @@ files:
221
207
  - lib/gitara/node/line.rb
222
208
  - lib/gitara/node/note_set.rb
223
209
  - lib/gitara/node/score.rb
210
+ - lib/gitara/node/stanza.rb
224
211
  - lib/gitara/node/tab.rb
225
212
  - lib/gitara/pow/base.rb
226
213
  - lib/gitara/template/bar.erb
227
214
  - lib/gitara/template/line.erb
228
215
  - lib/gitara/template/score.erb
216
+ - lib/gitara/template/stanza.erb
229
217
  - lib/gitara/template/tab.erb
230
218
  - lib/gitara/template/voice.erb
231
219
  - lib/gitara/utilities.rb
@@ -238,6 +226,7 @@ files:
238
226
  - spec/lib/gitara/node/base/voiced_node_spec.rb
239
227
  - spec/lib/gitara/node/base_spec.rb
240
228
  - spec/lib/gitara/node/note_set_spec.rb
229
+ - spec/lib/gitara/node/stanza_spec.rb
241
230
  - spec/lib/gitara/node/tab_spec.rb
242
231
  - spec/lib/gitara/voice_spec.rb
243
232
  - spec/lib/gitara_spec.rb