diff --git a/examples/aimee-man-wise-up/aimee-man-wise-up.ly b/examples/aimee-man-wise-up/aimee-man-wise-up.ly index 865effd..ea575ee 100644 --- a/examples/aimee-man-wise-up/aimee-man-wise-up.ly +++ b/examples/aimee-man-wise-up/aimee-man-wise-up.ly @@ -151,9 +151,15 @@ vTwoScoreTabOneScoreOne = { \vTwoStanzaIntro \vTwoStanzaVerseOne \vTwoStanzaChor %----------------------------------------------------------------------- % Voices -vOne = { \vOneScoreTabOneScoreOne } +vOne = { + \transposition d'' + \vOneScoreTabOneScoreOne +} -vTwo = { \vTwoScoreTabOneScoreOne } +vTwo = { + \transposition d' + \vTwoScoreTabOneScoreOne +} %----------------------------------------------------------------------- diff --git a/examples/aimee-man-wise-up/aimee-man-wise-up.midi b/examples/aimee-man-wise-up/aimee-man-wise-up.midi index 27bb1a4..56c5665 100644 Binary files a/examples/aimee-man-wise-up/aimee-man-wise-up.midi and b/examples/aimee-man-wise-up/aimee-man-wise-up.midi differ diff --git a/examples/aimee-man-wise-up/aimee-man-wise-up.pdf b/examples/aimee-man-wise-up/aimee-man-wise-up.pdf index 8d02611..afe8b38 100644 Binary files a/examples/aimee-man-wise-up/aimee-man-wise-up.pdf and b/examples/aimee-man-wise-up/aimee-man-wise-up.pdf differ diff --git a/examples/aimee-man-wise-up/aimee-man-wise-up.rb b/examples/aimee-man-wise-up/aimee-man-wise-up.rb index ca4febe..d5666c8 100644 --- a/examples/aimee-man-wise-up/aimee-man-wise-up.rb +++ b/examples/aimee-man-wise-up/aimee-man-wise-up.rb @@ -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 16( 8.) 16 8. 16 8. 8" diff --git a/examples/tab.ly b/examples/tab.ly index 804543c..e8ea5b2 100644 --- a/examples/tab.ly +++ b/examples/tab.ly @@ -61,9 +61,15 @@ vTwoScoreTabOneScoreOne = { \vTwoStanzaVerseOne } %----------------------------------------------------------------------- % Voices -vOne = { \vOneScoreTabOneScoreOne } +vOne = { + \transposition d'' + \vOneScoreTabOneScoreOne +} -vTwo = { \vTwoScoreTabOneScoreOne } +vTwo = { + \transposition d' + \vTwoScoreTabOneScoreOne +} %----------------------------------------------------------------------- diff --git a/examples/tab.rb b/examples/tab.rb index 444000f..c5a6dc6 100644 --- a/examples/tab.rb +++ b/examples/tab.rb @@ -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 diff --git a/lib/gitara/dsl.rb b/lib/gitara/dsl.rb index 5abd2d6..2f1a32b 100644 --- a/lib/gitara/dsl.rb +++ b/lib/gitara/dsl.rb @@ -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 diff --git a/lib/gitara/node/tab.rb b/lib/gitara/node/tab.rb index 564b56f..184b18f 100644 --- a/lib/gitara/node/tab.rb +++ b/lib/gitara/node/tab.rb @@ -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)) diff --git a/lib/gitara/template/voice.erb b/lib/gitara/template/voice.erb index cf4e051..478570c 100644 --- a/lib/gitara/template/voice.erb +++ b/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 %> +} diff --git a/lib/gitara/voice.rb b/lib/gitara/voice.rb index 7df4f78..313b758 100644 --- a/lib/gitara/voice.rb +++ b/lib/gitara/voice.rb @@ -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 diff --git a/spec/lib/gitara/dsl_spec.rb b/spec/lib/gitara/dsl_spec.rb index e1c4fcb..e885ef2 100644 --- a/spec/lib/gitara/dsl_spec.rb +++ b/spec/lib/gitara/dsl_spec.rb @@ -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 diff --git a/spec/lib/gitara/voice_spec.rb b/spec/lib/gitara/voice_spec.rb index cfdc58e..8b0394c 100644 --- a/spec/lib/gitara/voice_spec.rb +++ b/spec/lib/gitara/voice_spec.rb @@ -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