lygre 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,144 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ def gabc2score(str)
6
+ return GabcParser.new.parse(str).create_score
7
+ end
8
+
9
+ describe LilypondConvertor do
10
+
11
+ before :each do
12
+ @c = LilypondConvertor.new(version: false)
13
+ end
14
+
15
+ describe '#convert_min' do
16
+
17
+ describe 'basics' do
18
+
19
+ it 'converts empty gabc to empty lilypond score' do
20
+ @c.convert_min(gabc2score("%%\n\n")).should eq '\score { }'
21
+ end
22
+
23
+ it 'converts one-note score' do
24
+ @c.convert_min(gabc2score("%%\n(c4) (j)")).should \
25
+ eq '\score { \absolute { c\'\' } \addlyrics { } }'
26
+ end
27
+
28
+ it 'converts two-note score' do
29
+ @c.convert_min(gabc2score("%%\n(c4) (j) (h)")).should \
30
+ eq '\score { \absolute { c\'\' a\' } \addlyrics { } }'
31
+ end
32
+
33
+ it 'converts two-note score with lyrics' do
34
+ @c.convert_min(gabc2score("%%\n(c4) ti(j)bi(h)")).should \
35
+ eq '\score { \absolute { c\'\' a\' } \addlyrics { ti -- bi } }'
36
+ end
37
+
38
+ it 'converts two-note score with lyrics - separate words' do
39
+ @c.convert_min(gabc2score("%%\n(c4) non(j) tu(h)")).should \
40
+ eq '\score { \absolute { c\'\' a\' } \addlyrics { non tu } }'
41
+ end
42
+
43
+ it 'converts two-note melisma' do
44
+ @c.convert_min(gabc2score("%%\n(c4) (jh)")).should \
45
+ eq '\score { \absolute { c\'\'( a\') } \addlyrics { } }'
46
+ end
47
+
48
+ end
49
+
50
+ describe 'clefs and their positions' do
51
+
52
+ it 'handles c4' do
53
+ @c.convert_min(gabc2score("%%\n(c4) (h) (d)")).should \
54
+ eq "\\score { \\absolute { a' d' } \\addlyrics { } }"
55
+ end
56
+
57
+ it 'handles c3' do
58
+ @c.convert_min(gabc2score("%%\n(c3) (h) (d)")).should \
59
+ eq "\\score { \\absolute { c'' f' } \\addlyrics { } }"
60
+ end
61
+
62
+ it 'handles c2' do
63
+ @c.convert_min(gabc2score("%%\n(c2) (h) (d)")).should \
64
+ eq "\\score { \\absolute { e'' a' } \\addlyrics { } }"
65
+ end
66
+
67
+ it 'handles c1' do
68
+ @c.convert_min(gabc2score("%%\n(c1) (h) (d)")).should \
69
+ eq "\\score { \\absolute { g'' c'' } \\addlyrics { } }"
70
+ end
71
+
72
+ it 'handles f3' do
73
+ @c.convert_min(gabc2score("%%\n(f3) (h) (d)")).should \
74
+ eq "\\score { \\absolute { f' b } \\addlyrics { } }"
75
+ end
76
+
77
+ it 'handles f2' do
78
+ @c.convert_min(gabc2score("%%\n(f2) (h) (d)")).should \
79
+ eq "\\score { \\absolute { a' d' } \\addlyrics { } }"
80
+ end
81
+ end
82
+
83
+ describe 'barlines' do
84
+
85
+ it 'translates : to \bar "|"' do
86
+ @c.convert_min(gabc2score("%%\n(c4) (j) (:)")).should \
87
+ eq "\\score { \\absolute { c'' \\bar \"|\" } \\addlyrics { } }"
88
+ end
89
+
90
+ it 'translates ; to \bar "|"' do
91
+ @c.convert_min(gabc2score("%%\n(c4) (j) (;)")).should \
92
+ eq "\\score { \\absolute { c'' \\bar \"|\" } \\addlyrics { } }"
93
+ end
94
+
95
+ it 'translates :: to \bar "||"' do
96
+ @c.convert_min(gabc2score("%%\n(c4) (j) (::)")).should \
97
+ eq "\\score { \\absolute { c'' \\bar \"||\" } \\addlyrics { } }"
98
+ end
99
+
100
+ it 'translates , to \bar "|"' do
101
+ @c.convert_min(gabc2score("%%\n(c4) (j) (,)")).should \
102
+ eq "\\score { \\absolute { c'' \\bar \"'\" } \\addlyrics { } }"
103
+ end
104
+ end
105
+
106
+ describe 'handles special cases of lyrics: ' do
107
+
108
+ it 'quotes syllable beginning with asterisk' do
109
+ @c.convert_min(gabc2score("%%\n(c4) *la(j)")).should \
110
+ eq "\\score { \\absolute { c'' } \\addlyrics { \"*la\" } }"
111
+ end
112
+
113
+ it 'handles lyrics under a divisio' do
114
+ @c.convert_min(gabc2score("%%\n(c4) Ps.(::)")).should \
115
+ eq "\\score { \\absolute { \\bar \"||\" } \\addlyrics { \\set stanza = \\markup{Ps.} } }"
116
+ end
117
+
118
+ it 'handles italic in plain lyrics' do
119
+ @c.convert_min(gabc2score("%%\n(c4) <i>heu</i>(j)")).should \
120
+ eq "\\score { \\absolute { c'' } \\addlyrics { \\markup{\\italic{heu}} } }"
121
+ end
122
+
123
+ it 'handles italic in lyrics under a divisio' do
124
+ @c.convert_min(gabc2score("%%\n(c4) <i>Ps.</i>(::)")).should \
125
+ eq "\\score { \\absolute { \\bar \"||\" } \\addlyrics { \\set stanza = \\markup{\\italic{Ps.}} } }"
126
+ end
127
+ end
128
+
129
+ describe 'optional features' do
130
+
131
+ it 'cadenza' do
132
+ LilypondConvertor.new(version: false, cadenza: true) \
133
+ .convert_min(gabc2score("%%\n(c4) (j)\n")).should \
134
+ eq '\score { \absolute { \cadenzaOn c\'\' } \addlyrics { } }'
135
+ end
136
+
137
+ it 'lily version' do
138
+ LilypondConvertor.new(version: true) \
139
+ .convert_min(gabc2score("%%\n(c4) (j)\n")).should \
140
+ eq '\version "2.16.0" \score { \absolute { c\'\' } \addlyrics { } }'
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,20 @@
1
+ # custom matchers
2
+
3
+ # Treetop parser's #parse returns SyntaxNode on success,
4
+ # nil on fail.
5
+ #
6
+ # usage:
7
+ # @parser.parse(text).should compile
8
+ RSpec::Matchers.define :compile do
9
+ match do |actual|
10
+ GabcParser.new.parse(actual).kind_of? Treetop::Runtime::SyntaxNode
11
+ end
12
+ end
13
+
14
+ RSpec::Matchers.define :contain_a do |expected_kind|
15
+ match do |actual_collection|
16
+ found = false
17
+ actual_collection.each {|e| found = true if e.is_a? expected_kind }
18
+ found
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
18
+
19
+ require 'polyglot'
20
+ require 'treetop'
21
+
22
+ require_relative 'matchers'
23
+
24
+
25
+ $: << '../lib'
26
+ require 'grely'
27
+
28
+ Treetop.load File.expand_path('../lib/lygre/gabcgrammar', File.dirname(__FILE__))
29
+
30
+ def load_example(fname)
31
+ File.read(
32
+ File.expand_path(
33
+ File.join('examples', fname),
34
+ File.dirname(__FILE__)
35
+ )
36
+ )
37
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lygre
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jakub Pavlík
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: treetop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: polyglot
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rb-music-theory
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ description: |
70
+ two of the free music typesetting applications most popular
71
+ among church musicians are LilyPond and Gregorio.
72
+
73
+ lygre gem currently provides tool *grely* converting Gregorio's
74
+ input format (gabc) to simple LilyPond input.
75
+
76
+ In future another tool for the other direction of conversion may be added.
77
+
78
+ As rb-music-theory is not at RubyGems, either install it before
79
+ attempting to 'gem install lygre', or get lygre's source from github
80
+ and install the dependencies by 'bundle install'.
81
+ email: jkb.pavlik@gmail.com
82
+ executables:
83
+ - grely.rb
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - bin/grely.rb
88
+ - lib/grely.rb
89
+ - lib/lygre/lilypondconvertor.rb
90
+ - lib/lygre/gabcsemantics.rb
91
+ - lib/lygre/gabcpitchreader.rb
92
+ - lib/lygre/gabcscore.rb
93
+ - spec/gabcpitchreader_spec.rb
94
+ - spec/spec_helper.rb
95
+ - spec/gabcparser_spec.rb
96
+ - spec/gabcgrammar_spec.rb
97
+ - spec/gabcscore_spec.rb
98
+ - spec/lilypondconvertor_spec.rb
99
+ - spec/matchers.rb
100
+ homepage: http://github.com/igneus/lygre
101
+ licenses:
102
+ - LGPL-3.0
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.1.11
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: converts music formats gabc -> lilypond
125
+ test_files: []