Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[#21] I should be able to specify the key signature.

  • Loading branch information...
commit da65482bc65c0fb319aeec605ba6ed899b26cb2f 1 parent 7aac26d
George Mendoza authored
132 examples/tab-with-key-signature.ly
... ... @@ -0,0 +1,132 @@
  1 +\version "2.12.3"
  2 +\include "english.ly"
  3 +
  4 +\paper {
  5 + indent = #0
  6 +}
  7 +
  8 +\header {
  9 + title = ""
  10 + composer = ""
  11 + arranger = ""
  12 + instrument = ""
  13 +}
  14 +
  15 +%-----------------------------------------------------------------------
  16 +% Chord Sets
  17 +%-----------------------------------------------------------------------
  18 +% Bars
  19 +
  20 +vOneBarTabOneBarOne = { <d'\2 fs'\1 >4. <fs'\1 d'\2 >4 <fs'\1 d'\2 >8 \skip 4 }
  21 +vTwoBarTabOneBarOne = { <d,\6>4 <d\4>2 <d\4>8 <a,\5>8 }
  22 +cBarTabOneBarOne = { }
  23 +sBarTabOneBarOne = { r1 }
  24 +%-----------------------------------------------------------------------
  25 +% Lines
  26 +%-----------------------------------------------------------------------
  27 +% Stanzas
  28 +%-----------------------------------------------------------------------
  29 +% Scores
  30 +%-----------------------------------------------------------------------
  31 +% Voices
  32 +
  33 +vOne = {
  34 + \transposition d''
  35 + \vOneBarTabOneBarOne
  36 +}
  37 +
  38 +vTwo = {
  39 + \transposition d'
  40 + \vTwoBarTabOneBarOne
  41 +}
  42 +%-----------------------------------------------------------------------
  43 +% Stanza Headings
  44 +
  45 +stanzaHeadings = { \sBarTabOneBarOne }
  46 +
  47 +%-----------------------------------------------------------------------
  48 +% Chord Headings
  49 +
  50 +chordHeadings = { \cBarTabOneBarOne }
  51 +
  52 +%-----------------------------------------------------------------------
  53 +
  54 +\score {
  55 + \new StaffGroup <<
  56 + \new Staff <<
  57 + \tempo 4 = 100
  58 +
  59 + \clef "treble_8"
  60 +
  61 + \new Voice \with { \remove Rest_engraver } {
  62 + \stanzaHeadings
  63 + }
  64 +
  65 + \new Voice {
  66 + \key d \major
  67 + \voiceOne
  68 + \vOne
  69 + }
  70 + \new Voice {
  71 + \key d \major
  72 + \voiceTwo
  73 + \vTwo
  74 + }
  75 + >>
  76 +
  77 + \new TabStaff <<
  78 + \set TabStaff.stringTunings = #'(4 -1 -5 -10 -15 -22)
  79 + \new TabVoice {
  80 + \slurUp
  81 + \vOne
  82 + }
  83 + \new TabVoice {
  84 + \slurUp
  85 + \vTwo
  86 + }
  87 + \new TabVoice {
  88 + \chordHeadings
  89 + }
  90 + >>
  91 + >>
  92 +
  93 + \layout {
  94 + \context { \Staff
  95 + \override TimeSignature #'style = #'numbered
  96 + \override StringNumber #'transparent = ##t
  97 + }
  98 + \context { \TabStaff
  99 + \override TimeSignature #'style = #'numbered
  100 + }
  101 + \context { \Voice
  102 + \remove Slur_engraver
  103 + }
  104 + \context { \TabVoice
  105 + \remove Dots_engraver
  106 + \remove Stem_engraver
  107 + \remove Rest_engraver
  108 + }
  109 + }
  110 +}
  111 +
  112 +% showLastLength = R1*4
  113 +\score {
  114 + \new Staff \with {midiInstrument = #"acoustic guitar (nylon)"} <<
  115 + \tempo 4 = 100
  116 +
  117 + \clef "treble_8"
  118 +
  119 + \new Voice {
  120 + \unfoldRepeats {
  121 + \vOne
  122 + }
  123 + }
  124 + \new Voice {
  125 + \unfoldRepeats {
  126 + \vTwo
  127 + }
  128 + }
  129 + >>
  130 +
  131 + \midi {}
  132 +}
11 examples/tab-with-key-signature.rb
... ... @@ -0,0 +1,11 @@
  1 +Gitara.define do
  2 + key 'd \major'
  3 + string_tunings "#'(4 -1 -5 -10 -15 -22)" # Drop D
  4 + tempo "4 = 100"
  5 + transposition "d"
  6 +
  7 + bar do
  8 + notes "<d'/2 fs'/1 >4. <fs'/1 d'/2 >4 <fs'/1 d'/2 >8 /skip 4"
  9 + notes "<d,/6>4 <d/4>2 <d/4>8 <a,/5>8"
  10 + end
  11 +end
1  lib/gitara/dsl.rb
@@ -9,6 +9,7 @@ class Dsl < Valuable
9 9 can_add_property :arranger
10 10 can_add_property :composer
11 11 can_add_property :instrument
  12 + can_add_property :key
12 13 can_add_property :midi_instrument
13 14 can_add_property :string_tunings
14 15 can_add_property :tempo
1  lib/gitara/node/tab.rb
@@ -4,6 +4,7 @@ class Tab < Base
4 4 has_value :arranger
5 5 has_value :composer
6 6 has_value :instrument
  7 + has_value :key
7 8 has_value :midi_instrument, :default => "acoustic guitar (nylon)"
8 9 has_value :string_tunings
9 10 has_value :tempo
1  lib/gitara/template/tab.erb
@@ -78,6 +78,7 @@ chordHeadings = { <%= playable_child.chorded.call_name %> }
78 78
79 79 <% voices.each do |voice| %>
80 80 \new Voice {
  81 + <%= self.key && "\\key #{self.key}" %>
81 82 <%= voice.stem_type %>
82 83 <%= voice.call_name %>
83 84 }
4 lib/gitara/template/voice.erb
... ... @@ -1,6 +1,4 @@
1 1 <%= definition_name %> = {
2   - <% if self.transposition %>
3   - \transposition <%= self.transposition %>
4   - <% end %>
  2 + <%= self.transposition && "\\transposition #{self.transposition}" %>
5 3 <%= parent.playable_child.voiced_as(self).call_name %>
6 4 }
12 spec/lib/gitara/app_spec.rb
@@ -12,6 +12,10 @@ def run
12 12
13 13 def expected
14 14 @expected ||= Pow("examples/#{name}.ly").read!.gsub(/\n\s+\n/, "\n")
  15 + rescue PowError => e
  16 + puts "#{e.message}. Copying actual result..."
  17 + Pow("examples/#{name}.ly").write actual
  18 + retry
15 19 end
16 20
17 21 def actual
@@ -32,10 +36,16 @@ def actual
32 36 app_test.actual.should == app_test.expected
33 37 end
34 38
35   - it "can convert a table with alternate tuning to lilypond" do
  39 + it "can convert a tab with alternate tuning to lilypond" do
36 40 app_test = AppTest.new(:name => 'tab-with-alternate-tuning')
37 41 app_test.run
38 42 app_test.actual.should == app_test.expected
39 43 end
  44 +
  45 + it "can convert a tab with a specified key signature to lilypond" do
  46 + app_test = AppTest.new(:name => 'tab-with-key-signature')
  47 + app_test.run
  48 + app_test.actual.should == app_test.expected
  49 + end
40 50 end
41 51 end
2  spec/lib/gitara/dsl_spec.rb
@@ -203,7 +203,7 @@
203 203 end
204 204 end
205 205
206   - [:title, :composer, :arranger, :instrument, :midi_instrument, :string_tunings, :tempo, :transposition].each do |property|
  206 + [:title, :composer, :arranger, :instrument, :key, :midi_instrument, :string_tunings, :tempo, :transposition].each do |property|
207 207 describe "#{property}(value)" do
208 208 it "should set the #{property} of the tab to value" do
209 209 tab = FactoryGirl.build(:tab)

0 comments on commit da65482

Please sign in to comment.
Something went wrong with that request. Please try again.