gitara 1.0.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/CHANGELOG.markdown +6 -0
- data/README.markdown +1 -1
- data/examples/aimee-man-wise-up.ly +1 -1
- data/gitara.gemspec +3 -4
- data/lib/gitara/app.rb +3 -3
- data/lib/gitara/node/base.rb +1 -4
- data/lib/gitara/template/tab.erb +1 -1
- data/lib/gitara/utilities.rb +7 -4
- data/lib/gitara/version.rb +1 -1
- data/lib/gitara.rb +2 -2
- data/spec/factories.rb +7 -7
- data/spec/lib/gitara/app_spec.rb +4 -4
- data/spec/lib/gitara/dsl_spec.rb +112 -112
- data/spec/lib/gitara/node/alternative_spec.rb +4 -4
- data/spec/lib/gitara/node/bar/chorded_version_spec.rb +6 -6
- data/spec/lib/gitara/node/bar/stanza_version_spec.rb +5 -5
- data/spec/lib/gitara/node/bar/voiced_version_spec.rb +5 -5
- data/spec/lib/gitara/node/bar_spec.rb +20 -20
- data/spec/lib/gitara/node/base/node_version_spec.rb +19 -19
- data/spec/lib/gitara/node/base/voiced_version_spec.rb +9 -9
- data/spec/lib/gitara/node/base_spec.rb +113 -106
- data/spec/lib/gitara/node/chord_set/chorded_version_spec.rb +2 -2
- data/spec/lib/gitara/node/line_spec.rb +2 -2
- data/spec/lib/gitara/node/repeat_spec.rb +3 -3
- data/spec/lib/gitara/node/stanza_spec.rb +14 -14
- data/spec/lib/gitara/node/tab_spec.rb +25 -25
- data/spec/lib/gitara/time_signature_spec.rb +6 -6
- data/spec/lib/gitara/voice_spec.rb +33 -33
- data/spec/lib/gitara_spec.rb +4 -4
- data/spec/spec_helper.rb +6 -4
- data/spec/support/app_tester.rb +5 -5
- metadata +68 -118
@@ -3,63 +3,63 @@ require 'spec_helper'
|
|
3
3
|
describe Gitara::Node::Tab do
|
4
4
|
describe "#voices" do
|
5
5
|
it "should create a max_number_of_voices voices" do
|
6
|
-
tab =
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
tab = FactoryBot.build(:tab, :children => [
|
7
|
+
FactoryBot.build(:bar, :children => [
|
8
|
+
FactoryBot.build(:note_set),
|
9
|
+
FactoryBot.build(:note_set)
|
10
10
|
])
|
11
11
|
])
|
12
12
|
voices = tab.voices
|
13
|
-
voices.
|
14
|
-
voices[0].id.
|
15
|
-
voices[1].id.
|
16
|
-
voices.map(&:parent).uniq.
|
13
|
+
expect(voices.size).to eq(2)
|
14
|
+
expect(voices[0].id).to eq(1)
|
15
|
+
expect(voices[1].id).to eq(2)
|
16
|
+
expect(voices.map(&:parent).uniq).to eq([tab])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "#max_number_of_voices" do
|
21
21
|
it "should be the max number of note_sets in a bar" do
|
22
|
-
tab =
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
tab = FactoryBot.build(:tab, :children => [
|
23
|
+
FactoryBot.build(:bar, :children => [
|
24
|
+
FactoryBot.build(:note_set),
|
25
|
+
FactoryBot.build(:note_set)
|
26
26
|
])
|
27
27
|
])
|
28
28
|
|
29
|
-
tab.max_number_of_voices.
|
29
|
+
expect(tab.max_number_of_voices).to eq(2)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#playable_child" do
|
34
34
|
it "should be the last child of the tab" do
|
35
|
-
tab =
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
tab = FactoryBot.build(:tab, :children => [
|
36
|
+
FactoryBot.build(:bar, :name => 'Intro', :children => [
|
37
|
+
FactoryBot.build(:note_set),
|
38
|
+
FactoryBot.build(:note_set)
|
39
39
|
]),
|
40
|
-
|
40
|
+
FactoryBot.build(:bar, :name => 'Intro')
|
41
41
|
])
|
42
42
|
|
43
|
-
tab.playable_child.id.
|
43
|
+
expect(tab.playable_child.id).to eq(2)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "#midi_instrument" do
|
48
48
|
it "should have acoustic guitar (nylon) as default" do
|
49
|
-
tab =
|
50
|
-
tab.midi_instrument.
|
49
|
+
tab = FactoryBot.build(:tab)
|
50
|
+
expect(tab.midi_instrument).to eq('acoustic guitar (nylon)')
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "#time_signature" do
|
55
55
|
it "should be based on time if it exists" do
|
56
|
-
tab =
|
57
|
-
tab.time_signature.value.
|
56
|
+
tab = FactoryBot.build(:tab, :time => '3/4')
|
57
|
+
expect(tab.time_signature.value).to eq('3/4')
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should be 4/4 if time is not set" do
|
61
|
-
tab =
|
62
|
-
tab.time_signature.value.
|
61
|
+
tab = FactoryBot.build(:tab, :time => nil)
|
62
|
+
expect(tab.time_signature.value).to eq('4/4')
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -3,33 +3,33 @@ require 'spec_helper'
|
|
3
3
|
describe Gitara::TimeSignature do
|
4
4
|
describe "#rest_bar_value" do
|
5
5
|
it "should be r1 if the time signature generates whole note bars" do
|
6
|
-
|
6
|
+
expect(FactoryBot.build(:time_signature, :value => '4/4').rest_bar_value).to eq("r1")
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should be based on beat unit and beats per bar if the time signature does not generate whole note bars" do
|
10
|
-
|
10
|
+
expect(FactoryBot.build(:time_signature, :value => '3/4').rest_bar_value).to eq("r4 r4 r4")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#generates_whole_note_bars?" do
|
15
15
|
it "should be true if the beat unit is the same as the beats per bar" do
|
16
|
-
|
16
|
+
expect(FactoryBot.build(:time_signature, :value => '4/4').generates_whole_note_bars?).to be_truthy
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should be false if the beat unit is not the same as the beats per bar" do
|
20
|
-
|
20
|
+
expect(FactoryBot.build(:time_signature, :value => '3/4').generates_whole_note_bars?).to be_falsy
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "beat_unit" do
|
25
25
|
it "is the second part of the value" do
|
26
|
-
|
26
|
+
expect(FactoryBot.build(:time_signature, :value => '3/4').beat_unit).to eq(4)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "beats_per_bar" do
|
31
31
|
it "is the first part of the value" do
|
32
|
-
|
32
|
+
expect(FactoryBot.build(:time_signature, :value => '3/4').beats_per_bar).to eq(3)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -3,83 +3,83 @@ require 'spec_helper'
|
|
3
3
|
describe Gitara::Voice do
|
4
4
|
describe "#call_name" do
|
5
5
|
it "should be the variable name of the node when called inside lilypond" do
|
6
|
-
voice =
|
7
|
-
voice.call_name.
|
6
|
+
voice = FactoryBot.build(:voice, :id => 1)
|
7
|
+
expect(voice.call_name).to eq('\vOne')
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#definition_name" do
|
12
12
|
it "should be the name of the voice in a lilypond variable definition statement" do
|
13
|
-
voice =
|
14
|
-
voice.definition_name.
|
13
|
+
voice = FactoryBot.build(:voice, :id => 1)
|
14
|
+
expect(voice.definition_name).to eq("vOne")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#id_as_word" do
|
19
19
|
it "should convert the id to word" do
|
20
|
-
node =
|
21
|
-
node.id_as_word.
|
20
|
+
node = FactoryBot.build(:voice, :id => 1)
|
21
|
+
expect(node.id_as_word).to eq("One")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "#stem_type" do
|
26
26
|
it "should be the lilypond stem type for the voice" do
|
27
|
-
voice =
|
28
|
-
voice.stem_type.
|
27
|
+
voice = FactoryBot.build(:voice, :id => 1)
|
28
|
+
expect(voice.stem_type).to eq('\voiceOne')
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#transposition" do
|
33
33
|
it "should be based on the tab's transposition and the voice's octave" do
|
34
|
-
tab =
|
34
|
+
tab = FactoryBot.build(:tab,
|
35
35
|
:transposition => 'd',
|
36
36
|
:children => [
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
FactoryBot.build(:bar, :children => [
|
38
|
+
FactoryBot.build(:note_set),
|
39
|
+
FactoryBot.build(:note_set)
|
40
40
|
])
|
41
41
|
]
|
42
42
|
)
|
43
|
-
tab.max_number_of_voices.
|
43
|
+
expect(tab.max_number_of_voices).to eq(2)
|
44
44
|
|
45
|
-
voice =
|
46
|
-
voice.transposition.
|
45
|
+
voice = FactoryBot.build(:voice, :parent => tab, :id => 1)
|
46
|
+
expect(voice.transposition).to eq("d''")
|
47
47
|
|
48
|
-
voice =
|
49
|
-
voice.transposition.
|
48
|
+
voice = FactoryBot.build(:voice, :parent => tab, :id => 2)
|
49
|
+
expect(voice.transposition).to eq("d'")
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should be blank if the tab has no transposition" do
|
53
|
-
tab =
|
53
|
+
tab = FactoryBot.build(:tab,
|
54
54
|
:children => [
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
FactoryBot.build(:bar, :children => [
|
56
|
+
FactoryBot.build(:note_set),
|
57
|
+
FactoryBot.build(:note_set)
|
58
58
|
])
|
59
59
|
]
|
60
60
|
)
|
61
|
-
tab.max_number_of_voices.
|
61
|
+
expect(tab.max_number_of_voices).to eq(2)
|
62
62
|
|
63
|
-
voice =
|
64
|
-
voice.transposition.
|
63
|
+
voice = FactoryBot.build(:voice, :parent => tab, :id => 1)
|
64
|
+
expect(voice.transposition).to be_nil
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
describe "#octave" do
|
69
69
|
it "should be based on the voice's position in the tab" do
|
70
|
-
tab =
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
tab = FactoryBot.build(:tab, :children => [
|
71
|
+
FactoryBot.build(:bar, :children => [
|
72
|
+
FactoryBot.build(:note_set),
|
73
|
+
FactoryBot.build(:note_set)
|
74
74
|
])
|
75
75
|
])
|
76
|
-
tab.max_number_of_voices.
|
76
|
+
expect(tab.max_number_of_voices).to eq(2)
|
77
77
|
|
78
|
-
voice =
|
79
|
-
voice.octave.
|
78
|
+
voice = FactoryBot.build(:voice, :parent => tab, :id => 1)
|
79
|
+
expect(voice.octave).to eq(2)
|
80
80
|
|
81
|
-
voice =
|
82
|
-
voice.octave.
|
81
|
+
voice = FactoryBot.build(:voice, :parent => tab, :id => 2)
|
82
|
+
expect(voice.octave).to eq(1)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
data/spec/lib/gitara_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe Gitara do
|
4
4
|
describe ".tab" do
|
5
5
|
it "should create a tab instance if it does not exist" do
|
6
|
-
Gitara.tab.
|
6
|
+
expect(Gitara.tab).to be_nil
|
7
7
|
Gitara.define
|
8
|
-
Gitara.tab.
|
8
|
+
expect(Gitara.tab).to be_a(Node::Tab)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -18,8 +18,8 @@ describe Gitara do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
bars = tab.definitions(Node::Bar)
|
21
|
-
bars.size.
|
22
|
-
bars[0].name.
|
21
|
+
expect(bars.size).to eq(1)
|
22
|
+
expect(bars[0].name).to eq('Intro')
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
require '
|
1
|
+
require 'factory_bot'
|
2
2
|
require 'gitara'
|
3
|
-
require '
|
3
|
+
require 'byebug'
|
4
4
|
|
5
5
|
RSpec.configure do |config|
|
6
6
|
include Gitara
|
7
7
|
require 'factories'
|
8
8
|
require 'support/app_tester'
|
9
9
|
|
10
|
+
config.example_status_persistence_file_path = 'spec/support/examples.txt'
|
11
|
+
|
10
12
|
config.before :each do
|
11
|
-
test_tmp_dir.delete! if test_tmp_dir.
|
13
|
+
test_tmp_dir.delete! if test_tmp_dir.exist? && ! run_lilypond?
|
12
14
|
Gitara.instance_variable_set :@tab, nil
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_tmp_dir
|
16
|
-
|
18
|
+
Pathname.new('tmp/test')
|
17
19
|
end
|
18
20
|
|
19
21
|
def run_lilypond?
|
data/spec/support/app_tester.rb
CHANGED
@@ -4,18 +4,18 @@ class AppTester < Valuable
|
|
4
4
|
has_value :run_lilypond, :klass => :boolean, :default => false
|
5
5
|
|
6
6
|
def run
|
7
|
-
app =
|
7
|
+
app = FactoryBot.build(:app)
|
8
8
|
app.invoke :export, ["examples/#{name}.rb"],
|
9
9
|
"target-directory" => test_tmp_dir.path,
|
10
10
|
"run-lilypond" => self.run_lilypond?
|
11
|
-
(
|
11
|
+
(Pathname.new("tmp") / "#{name}.ly").write actual if self.expected != self.actual
|
12
12
|
end
|
13
13
|
|
14
14
|
def expected
|
15
|
-
@expected ||= Utilities.read!(
|
16
|
-
rescue
|
15
|
+
@expected ||= Utilities.read!(Pathname.new("examples/#{name}.ly")).gsub(/\n\s+\n/, "\n")
|
16
|
+
rescue Utilities::PathnameDoesNotExist => e
|
17
17
|
puts "#{e.message}. Copying actual result..."
|
18
|
-
|
18
|
+
Pathname.new("examples/#{name}.ly").write actual
|
19
19
|
retry
|
20
20
|
end
|
21
21
|
|