Skip to content

Commit

Permalink
[#14] I should be able to specify the tab's transposition.
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmendoza committed Feb 20, 2012
1 parent 2957b4e commit 9cc5df1
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 9 deletions.
10 changes: 8 additions & 2 deletions examples/aimee-man-wise-up/aimee-man-wise-up.ly
Expand Up @@ -151,9 +151,15 @@ vTwoScoreTabOneScoreOne = { \vTwoStanzaIntro \vTwoStanzaVerseOne \vTwoStanzaChor
%-----------------------------------------------------------------------
% Voices

vOne = { \vOneScoreTabOneScoreOne }
vOne = {
\transposition d''
\vOneScoreTabOneScoreOne
}

vTwo = { \vTwoScoreTabOneScoreOne }
vTwo = {
\transposition d'
\vTwoScoreTabOneScoreOne
}


%-----------------------------------------------------------------------
Expand Down
Binary file modified examples/aimee-man-wise-up/aimee-man-wise-up.midi
Binary file not shown.
Binary file modified examples/aimee-man-wise-up/aimee-man-wise-up.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions examples/aimee-man-wise-up/aimee-man-wise-up.rb
Expand Up @@ -5,6 +5,7 @@
instrument "Guitar (capo on second fret)"
midi_instrument "acoustic guitar (nylon)"
tempo "4 = 75"
transposition "d"

bar :BeforeYouSign do
notes "r8 <d'/2>16( <c'/2>8.) <a/3>16 <c'/2>8. <d'/2>16 <e'/1>8. <g/3>8"
Expand Down
10 changes: 8 additions & 2 deletions examples/tab.ly
Expand Up @@ -61,9 +61,15 @@ vTwoScoreTabOneScoreOne = { \vTwoStanzaVerseOne }
%-----------------------------------------------------------------------
% Voices

vOne = { \vOneScoreTabOneScoreOne }
vOne = {
\transposition d''
\vOneScoreTabOneScoreOne
}

vTwo = { \vTwoScoreTabOneScoreOne }
vTwo = {
\transposition d'
\vTwoScoreTabOneScoreOne
}


%-----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/tab.rb
Expand Up @@ -4,7 +4,7 @@
arranger "Arranged by George Mendoza"
instrument "Guitar (capo on second fret)"
midi_instrument "acoustic guitar (nylon)"
#key "d"
transposition "d"
tempo "4 = 75"

bar :BeganIt do
Expand Down
2 changes: 1 addition & 1 deletion lib/gitara/dsl.rb
Expand Up @@ -9,10 +9,10 @@ class Dsl < Valuable
can_add_property :arranger
can_add_property :composer
can_add_property :instrument
#can_add_property :key
can_add_property :midi_instrument
can_add_property :tempo
can_add_property :title
can_add_property :transposition

def add(child, &block)
self.node.add child
Expand Down
2 changes: 1 addition & 1 deletion lib/gitara/node/tab.rb
Expand Up @@ -4,10 +4,10 @@ class Tab < Base
has_value :arranger
has_value :composer
has_value :instrument
#has_value :key
has_value :midi_instrument, :default => "acoustic guitar (nylon)"
has_value :tempo
has_value :title
has_value :transposition

def self.parse(text)
Transform.new.apply(Parser.new.parse(text))
Expand Down
7 changes: 6 additions & 1 deletion lib/gitara/template/voice.erb
@@ -1 +1,6 @@
<%= definition_name %> = { <%= parent.playable_child.voiced_as(self).call_name %> }
<%= definition_name %> = {
<% if self.transposition %>
\transposition <%= self.transposition %>
<% end %>
<%= parent.playable_child.voiced_as(self).call_name %>
}
8 changes: 8 additions & 0 deletions lib/gitara/voice.rb
Expand Up @@ -15,8 +15,16 @@ def id_as_word
Utilities.id_as_word(id)
end

def octave
(self.parent.max_number_of_voices - self.id) + 1
end

def stem_type
"\\voice#{id_as_word}"
end

def transposition
"#{self.parent.transposition}#{"'" * self.octave}" if self.parent.transposition
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/gitara/dsl_spec.rb
Expand Up @@ -203,7 +203,7 @@
end
end

[:title, :composer, :arranger, :instrument, :midi_instrument, :tempo].each do |property|
[:title, :composer, :arranger, :instrument, :midi_instrument, :tempo, :transposition].each do |property|
describe "#{property}(value)" do
it "should set the #{property} of the tab to value" do
tab =Node::Tab.new
Expand Down
54 changes: 54 additions & 0 deletions spec/lib/gitara/voice_spec.rb
Expand Up @@ -28,4 +28,58 @@
voice.stem_type.should == '\voiceOne'
end
end

describe "transposition" do
it "should be based on the tab's transposition and the voice's octave" do
tab = Node::Tab.new(
:transposition => 'd',
:children => [
Node::Bar.new(:children => [
Node::NoteSet.new,
Node::NoteSet.new
])
]
)
tab.max_number_of_voices.should == 2

voice = Voice.new(:parent => tab, :id => 1)
voice.transposition.should == "d''"

voice = Voice.new(:parent => tab, :id => 2)
voice.transposition.should == "d'"
end

it "should be blank if the tab has no transposition" do
tab = Node::Tab.new(
:children => [
Node::Bar.new(:children => [
Node::NoteSet.new,
Node::NoteSet.new
])
]
)
tab.max_number_of_voices.should == 2

voice = Voice.new(:parent => tab, :id => 1)
voice.transposition.should be_nil
end
end

describe "octave" do
it "should be based on the voice's position in the tab" do
tab = Node::Tab.new(:children => [
Node::Bar.new(:children => [
Node::NoteSet.new,
Node::NoteSet.new
])
])
tab.max_number_of_voices.should == 2

voice = Voice.new(:parent => tab, :id => 1)
voice.octave.should == 2

voice = Voice.new(:parent => tab, :id => 2)
voice.octave.should == 1
end
end
end

0 comments on commit 9cc5df1

Please sign in to comment.