lydown 0.12.4 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +41 -1
  3. data/bin/lydown +2 -0
  4. data/lib/lydown.rb +6 -2
  5. data/lib/lydown/cache.rb +5 -1
  6. data/lib/lydown/cli.rb +1 -1
  7. data/lib/lydown/cli/commands.rb +7 -11
  8. data/lib/lydown/cli/compiler.rb +5 -0
  9. data/lib/lydown/cli/proofing.rb +2 -2
  10. data/lib/lydown/cli/repl.rb +1 -1
  11. data/lib/lydown/cli/support.rb +0 -33
  12. data/lib/lydown/defaults.yml +50 -8
  13. data/lib/lydown/inverso.rb +84 -0
  14. data/lib/lydown/lilypond.rb +76 -10
  15. data/lib/lydown/ly_lib/lib.ly +140 -127
  16. data/lib/lydown/parsing/lydown.treetop +25 -12
  17. data/lib/lydown/parsing/nodes.rb +55 -19
  18. data/lib/lydown/rendering.rb +72 -1
  19. data/lib/lydown/rendering/base.rb +21 -0
  20. data/lib/lydown/rendering/command.rb +53 -0
  21. data/lib/lydown/rendering/layout.rb +83 -0
  22. data/lib/lydown/rendering/lyrics.rb +1 -1
  23. data/lib/lydown/rendering/markup.rb +23 -0
  24. data/lib/lydown/rendering/movement.rb +7 -4
  25. data/lib/lydown/rendering/music.rb +35 -29
  26. data/lib/lydown/rendering/notes.rb +75 -41
  27. data/lib/lydown/rendering/repeats.rb +27 -0
  28. data/lib/lydown/rendering/settings.rb +36 -9
  29. data/lib/lydown/rendering/skipping.rb +10 -2
  30. data/lib/lydown/rendering/staff.rb +38 -31
  31. data/lib/lydown/rendering/voices.rb +1 -1
  32. data/lib/lydown/templates.rb +8 -8
  33. data/lib/lydown/templates/layout.rb +40 -0
  34. data/lib/lydown/templates/lilypond_doc.rb +95 -0
  35. data/lib/lydown/templates/movement.rb +188 -0
  36. data/lib/lydown/templates/multi_voice.rb +25 -0
  37. data/lib/lydown/templates/part.rb +146 -0
  38. data/lib/lydown/templates/variables.rb +43 -0
  39. data/lib/lydown/translation/ripple.rb +1 -1
  40. data/lib/lydown/translation/ripple/nodes.rb +51 -2
  41. data/lib/lydown/translation/ripple/ripple.treetop +87 -10
  42. data/lib/lydown/version.rb +1 -1
  43. data/lib/lydown/work.rb +19 -2
  44. data/lib/lydown/work_context.rb +10 -2
  45. metadata +12 -8
  46. data/lib/lydown/cli/installer.rb +0 -175
  47. data/lib/lydown/templates/lilypond_doc.erb +0 -34
  48. data/lib/lydown/templates/movement.erb +0 -118
  49. data/lib/lydown/templates/multi_voice.erb +0 -16
  50. data/lib/lydown/templates/part.erb +0 -118
  51. data/lib/lydown/templates/variables.erb +0 -43
@@ -1,3 +1,3 @@
1
1
  module Lydown
2
- VERSION = "0.12.4"
2
+ VERSION = "0.14.0"
3
3
  end
data/lib/lydown/work.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'lydown/templates'
1
+ require 'lydown/inverso'
2
2
  require 'lydown/cli/output'
3
3
  require 'parallel'
4
4
 
@@ -26,6 +26,23 @@ module Lydown
26
26
 
27
27
  def to_lilypond(opts = {})
28
28
  @context[:render_opts] = opts.stringify_keys
29
+
30
+ if edition = @context['render_opts/edition']
31
+ edition_settings = @context["global/settings/editions/#{edition}"]
32
+ if edition_settings
33
+ @context["global/settings/editions/#{edition}"] = nil
34
+ @context["global/settings"].deep_merge!(edition_settings)
35
+ end
36
+
37
+ (@context["movements"] || {}).each do |n, m|
38
+ edition_settings = m["settings/editions/#{edition}"]
39
+ if edition_settings
40
+ m["settings/editions/#{edition}"] = nil
41
+ m["settings"].deep_merge!(edition_settings)
42
+ end
43
+ end
44
+ end
45
+
29
46
  @context[:variables] = {}
30
47
 
31
48
  if opts[:stream_path]
@@ -40,7 +57,7 @@ module Lydown
40
57
  filtered.extend(TemplateBinding)
41
58
 
42
59
  # Remove empty lines from the rendered code
43
- Lydown::Templates.render(:lilypond_doc, filtered)
60
+ Inverso::Template.render(:lilypond_doc, context: filtered)
44
61
  end
45
62
  end
46
63
 
@@ -245,6 +245,7 @@ module Lydown
245
245
  def query_setting(movement, part, path)
246
246
  path = "#{settings_path(movement, part)}/#{path}"
247
247
  value = @context[path]
248
+
248
249
  unless value.nil?
249
250
  @temp_setting_value = value
250
251
  true
@@ -253,6 +254,10 @@ module Lydown
253
254
  end
254
255
  end
255
256
 
257
+ def rendered_edition
258
+ @rendered_edition = @context['render_opts/edition']
259
+ end
260
+
256
261
  def query_defaults(path)
257
262
  value = DEFAULTS[path]
258
263
  unless value.nil?
@@ -274,17 +279,20 @@ module Lydown
274
279
  # setting value once it's found. That way we can use the
275
280
  # || operator to stop searching once we've found it.
276
281
  @temp_setting_value = nil
282
+
277
283
  if opts[:part]
278
284
  parts_section_path = "parts/#{opts[:part]}/#{path}"
279
285
 
280
286
  query_setting(opts[:movement], opts[:part], path) ||
281
287
  query_setting(nil, opts[:part], path) ||
282
- query_setting(opts[:movement], nil, path) ||
283
- query_setting(nil, nil, path) ||
284
288
 
285
289
  # search in parts section
286
290
  query_setting(opts[:movement], nil, parts_section_path) ||
291
+ query_setting(opts[:movement], nil, path) ||
292
+
287
293
  query_setting(nil, nil, parts_section_path) ||
294
+
295
+ query_setting(nil, nil, path) ||
288
296
 
289
297
  query_defaults("parts/#{opts[:part]}/#{path}") ||
290
298
  query_defaults(path)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lydown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.4
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-28 00:00:00.000000000 Z
11
+ date: 2016-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop
@@ -138,7 +138,6 @@ files:
138
138
  - lib/lydown/cli/commands.rb
139
139
  - lib/lydown/cli/compiler.rb
140
140
  - lib/lydown/cli/diff.rb
141
- - lib/lydown/cli/installer.rb
142
141
  - lib/lydown/cli/output.rb
143
142
  - lib/lydown/cli/proofing.rb
144
143
  - lib/lydown/cli/repl.rb
@@ -148,6 +147,7 @@ files:
148
147
  - lib/lydown/core_ext.rb
149
148
  - lib/lydown/defaults.yml
150
149
  - lib/lydown/errors.rb
150
+ - lib/lydown/inverso.rb
151
151
  - lib/lydown/lilypond.rb
152
152
  - lib/lydown/ly_lib/lib.ly
153
153
  - lib/lydown/parsing.rb
@@ -158,22 +158,26 @@ files:
158
158
  - lib/lydown/rendering/command.rb
159
159
  - lib/lydown/rendering/comments.rb
160
160
  - lib/lydown/rendering/figures.rb
161
+ - lib/lydown/rendering/layout.rb
161
162
  - lib/lydown/rendering/literal.rb
162
163
  - lib/lydown/rendering/lyrics.rb
164
+ - lib/lydown/rendering/markup.rb
163
165
  - lib/lydown/rendering/movement.rb
164
166
  - lib/lydown/rendering/music.rb
165
167
  - lib/lydown/rendering/notes.rb
168
+ - lib/lydown/rendering/repeats.rb
166
169
  - lib/lydown/rendering/settings.rb
167
170
  - lib/lydown/rendering/skipping.rb
168
171
  - lib/lydown/rendering/source_ref.rb
169
172
  - lib/lydown/rendering/staff.rb
170
173
  - lib/lydown/rendering/voices.rb
171
174
  - lib/lydown/templates.rb
172
- - lib/lydown/templates/lilypond_doc.erb
173
- - lib/lydown/templates/movement.erb
174
- - lib/lydown/templates/multi_voice.erb
175
- - lib/lydown/templates/part.erb
176
- - lib/lydown/templates/variables.erb
175
+ - lib/lydown/templates/layout.rb
176
+ - lib/lydown/templates/lilypond_doc.rb
177
+ - lib/lydown/templates/movement.rb
178
+ - lib/lydown/templates/multi_voice.rb
179
+ - lib/lydown/templates/part.rb
180
+ - lib/lydown/templates/variables.rb
177
181
  - lib/lydown/translation.rb
178
182
  - lib/lydown/translation/ripple.rb
179
183
  - lib/lydown/translation/ripple/nodes.rb
@@ -1,175 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
- require 'ruby-progressbar'
4
- require 'tempfile'
5
- require 'fileutils'
6
-
7
- module Lydown::CLI::Installer
8
- class << self
9
- def install(package, version = nil)
10
- case package
11
- when 'lilypond'
12
- Lilypond.install(version)
13
- else
14
- STDERR.puts "Unknown package name specified"
15
- exit!(1)
16
- end
17
- end
18
- end
19
-
20
- module Lilypond
21
- class << self
22
- LILYPOND_DEFAULT_VERSION = "2.19.29"
23
-
24
- def detect_version(specified_version)
25
- case specified_version
26
- when nil, 'stable'
27
- list = get_version_list
28
- end
29
- end
30
-
31
- def install(version = nil)
32
- platform = detect_lilypond_platform
33
- version ||= LILYPOND_DEFAULT_VERSION
34
- # version = detect_version(version)
35
- url = lilypond_install_url(platform, version)
36
- fn = Tempfile.new('lydown-lilypond-installer').path
37
-
38
- download_lilypond(url, fn)
39
- install_lilypond_files(fn, platform, version)
40
- rescue => e
41
- STDERR.puts "Failed to install lilypond #{version}"
42
- puts e.message
43
- puts e.backtrace.join("\n")
44
- exit(1)
45
- end
46
-
47
- BASE_URL = "http://download.linuxaudio.org/lilypond/binaries"
48
-
49
- def lilypond_install_url(platform, version)
50
- ext = platform =~ /darwin/ ? ".tar.bz2" : ".sh"
51
- filename = "lilypond-#{version}-1.#{platform}"
52
-
53
- "#{BASE_URL}/#{platform}/#{filename}#{ext}"
54
- end
55
-
56
- def detect_lilypond_platform
57
- case RUBY_PLATFORM
58
- when /x86_64-darwin/
59
- "darwin-x86"
60
- when /ppc-darwin/
61
- "darwin-ppc"
62
- when "i686-linux"
63
- "linux-x86"
64
- when "x86_64-linux"
65
- "linux-64"
66
- when "ppc-linux"
67
- "linux-ppc"
68
- end
69
- end
70
-
71
- def download_lilypond(url, fn)
72
- STDERR.puts "Downloading #{url}"
73
-
74
- url_base = url.split('/')[2]
75
- url_path = '/'+url.split('/')[3..-1].join('/')
76
- download_count = 0
77
-
78
- Net::HTTP.start(url_base) do |http|
79
- request_url = URI.escape(url_path)
80
- response = http.request_head(request_url)
81
- total_size = response['content-length'].to_i
82
- pbar = ProgressBar.create(title: 'Downloading', total: total_size)
83
- File.open(fn, 'w') do |f|
84
- http.get(request_url) do |data|
85
- f << data
86
- download_count += data.length
87
- pbar.progress = download_count if download_count <= total_size
88
- end
89
- end
90
- pbar.finish
91
- end
92
- end
93
-
94
- def install_lilypond_files(fn, platform, version)
95
- case platform
96
- when /darwin/
97
- install_lilypond_files_osx(fn, version)
98
- when /linux/
99
- install_lilypond_files_linux(fn, version)
100
- end
101
- end
102
-
103
- def install_lilypond_files_osx(fn, version)
104
- target = "/tmp/lydown/installer/lilypond"
105
- FileUtils.mkdir_p(target)
106
-
107
- STDERR.puts "Extracting..."
108
- exec "tar -xjf #{fn} -C #{target}"
109
-
110
- copy_lilypond_files("#{target}/LilyPond.app/Contents/Resources", version)
111
- end
112
-
113
- def install_lilypond_files_linux(fn, version)
114
- target = "/tmp/lydown/installer/lilypond"
115
- FileUtils.mkdir_p(target)
116
-
117
- # create temp directory in which to untar file
118
- tmp_dir = "/tmp/lydown/#{Time.now.to_f}"
119
- FileUtils.mkdir_p(tmp_dir)
120
-
121
- FileUtils.cd(tmp_dir) do
122
- exec "sh #{fn} --tarball"
123
- end
124
-
125
- STDERR.puts "Extracting..."
126
- exec "tar -xjf #{tmp_dir}/#{fn} -C #{target}"
127
-
128
- copy_lilypond_files_linux("#{target}/usr", version)
129
- end
130
-
131
- def copy_lilypond_files(base_path, version)
132
- target_dir = File.expand_path("~/.lydown/packages/lilypond/#{version}")
133
-
134
- FileUtils.rm_rf(target_dir) if File.exists?(target_dir)
135
-
136
- # create directory for lilypond files
137
- FileUtils.mkdir_p(target_dir)
138
-
139
- # copy files
140
- STDERR.puts "Copying..."
141
- %w{bin etc lib lib64 share var}.each do |entry|
142
- dir = File.join(base_path, entry)
143
- FileUtils.cp_r(dir, target_dir, remove_destination: true) if File.directory?(dir)
144
- end
145
-
146
- install_lilypond_executable(base_path, version)
147
- end
148
-
149
- BIN_SCRIPT_PATH = "#{File.expand_path('~')}/bin/lilypond"
150
-
151
- def install_lilypond_executable(base_path, version)
152
- target_dir = File.expand_path("~/.lydown/packages/lilypond/#{version}")
153
-
154
- script = "#!/bin/sh\n#{target_dir}/bin/lilypond \"$@\"\n"
155
-
156
- # create executable
157
- FileUtils.rm(BIN_SCRIPT_PATH) if File.file?(BIN_SCRIPT_PATH)
158
- File.open(BIN_SCRIPT_PATH, 'w+') {|f| f << script}
159
- FileUtils.chmod('+x', BIN_SCRIPT_PATH)
160
- # symlink_path = File.expand_path('~/bin/lilypond')
161
- # FileUtils.ln_sf("#{target_dir}/bin/lilypond", symlink_path)
162
-
163
- test_lilypond
164
- end
165
-
166
- def test_lilypond
167
- STDERR.puts `lilypond -v`
168
- end
169
-
170
- def exec(cmd)
171
- raise unless system(cmd)
172
- end
173
- end
174
- end
175
- end
@@ -1,34 +0,0 @@
1
- \version "2.18.2"
2
-
3
- <% unless self['render_opts/no_lib'] %>
4
- \include "<%= File.join(LY_LIB_DIR, 'lib.ly') %>"
5
- <% end %>
6
-
7
- <% includes = Lydown::Rendering.include_files(self, {}) %>
8
- <% includes.each do |i| %>
9
- <%= i %>
10
- <% end %>
11
-
12
- <% if self.render_mode == :proof %>
13
- <%= Lydown::Rendering::PROOFING_LY_SETTINGS %>
14
- <% end %>
15
-
16
- <% if self['layout'] %>
17
- \layout {
18
- }
19
- <% end %>
20
-
21
- <%= Lydown::Templates.render(:variables, self) %>
22
-
23
- \book {
24
- \header {
25
- }
26
-
27
- \bookpart {
28
- <% self['movements'].each do |n, m| %>
29
- <%= Lydown::Templates.render(:movement, self, name: n, movement: m)
30
- %>
31
- <% end %>
32
-
33
- }
34
- }
@@ -1,118 +0,0 @@
1
- <%
2
- render_mode = self.render_mode
3
- staff_groups = Lydown::Rendering::Staff.staff_groups(
4
- self, {movement: name}, movement['parts'].keys)
5
- parts_in_order = staff_groups.flatten
6
- staff_hierarchy = Lydown::Rendering::Staff.staff_hierarchy(staff_groups)
7
-
8
- parts = parts_in_order.inject({}) do |m, p|
9
- m[p] = movement['parts'][p]
10
- m
11
- end
12
-
13
- score_mode = (render_mode == :score) ||
14
- (render_mode == :proof) || (parts.size > 1)
15
-
16
- tacet = Lydown::Rendering::Movement.tacet?(self, name)
17
- movement_title = Lydown::Rendering::Movement.movement_title(self, name)
18
- movement_source = self.get_setting(:movement_source , movement: name)
19
-
20
- format = self['options/format'] || self['render_opts/format'] || :pdf
21
- midi_mode = (format == :midi) || (format == :mp3)
22
-
23
- empty_staves = self.get_setting(:empty_staves, movement: name)
24
-
25
- page_breaks = Lydown::Rendering::Movement.page_breaks(self, movement: name)
26
-
27
- includes = Lydown::Rendering.include_files(self, movement: name)
28
-
29
- hide_bar_numbers = Lydown::Rendering::Movement.hide_bar_numbers?(
30
- self, movement: name
31
- )
32
- %>
33
-
34
- <% if page_breaks[:blank_page_before] %>
35
- } \bookpart {
36
- \markup \column {
37
- \null \null \null \null \null \null
38
- \null \null \null \null \null \null
39
- \null \null \null \null \null \null
40
- \null \null \null \null \null \null
41
- \fill-line { "(this page has been left blank to facilitate page turning)" }
42
- }
43
- } \bookpart {
44
- \pageBreak
45
- <% elsif page_breaks[:before] %>
46
- } \bookpart {
47
- <% end %>
48
-
49
- <% includes.each do |i| %>
50
- <%= i %>
51
- <% end %>
52
-
53
- <% unless tacet %>
54
- \score {
55
- <% if movement_title && render_mode != :proof %>
56
- \header {
57
- piece = \markup {
58
- \bold \large { <%= movement_title %> }
59
- <% if movement_source %>
60
- \hspace #1 \italic { <%= movement_source %> }
61
- <% end %>
62
- }
63
- }
64
- <% end %>
65
-
66
- <% if score_mode %>
67
- <% if empty_staves == 'hide' %>
68
- \layout {
69
- \context {
70
- \RemoveEmptyStaffContext
71
- \override VerticalAxisGroup #'remove-first = ##t
72
- }
73
- }
74
- <% end %>
75
-
76
- \new StaffGroup <<
77
- \set StaffGroup.systemStartDelimiterHierarchy = <%= staff_hierarchy %>
78
- <% end %>
79
-
80
- <% if n = movement['bar_number'] %>
81
- \set Score.currentBarNumber = #<%= n %>
82
- \set Score.barNumberVisibility = #all-bar-numbers-visible
83
- \bar ""
84
- <% end %>
85
-
86
- <% parts.each do |n, p| %>
87
- <%= Lydown::Templates.render(:part, self,
88
- name: n, part: p, movement: movement, movement_name: name) %>
89
- <% end %>
90
-
91
- <% if score_mode %>
92
- >>
93
- <% end %>
94
- <% if midi_mode %>
95
- \midi {
96
- <% if tempo = self.get_setting(:midi_tempo, movement: name) %>
97
- \tempo <%= tempo %>
98
- <% end %>
99
- }
100
- <% end %>
101
-
102
- <% if hide_bar_numbers %>
103
- \layout {
104
- \context {
105
- \Score
106
- \omit BarNumber
107
- }
108
- }
109
- <% end %>
110
- }
111
- <% else # tacet %>
112
- \markup {
113
- \line { \bold \large { <%= movement_title %> } }
114
- \line { \pad-markup #3 " " }
115
-
116
- }
117
- <% end %>
118
- <% if page_breaks[:after] %>\pageBreak <% end %>