LilyPond-Ruby 0.1.5 → 0.1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lilypond/builder.rb +2 -2
- data/lib/lilypond/config.rb +23 -0
- data/lib/lilypond-ruby.rb +48 -31
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d54f5369710cc4da48b7114204e186b85edeff67dd1cd8eda50066ff4495b2a
|
4
|
+
data.tar.gz: b3ff051ea699b01fb52c803c7d61159566d0484bb80b29d23f94ac2465f1a8f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ffb4a7ab0157de96b1a22b5d44cc20288d3a4c874fee6c20784e5187a7437b2a9533e5f6c23ba423ba0ae0abff61054a8193d4fc70c02e635ed09e8c1174dd5
|
7
|
+
data.tar.gz: 1068a3ec0dea29a3a3e874d8f7e7b89c5d963d44224bddea5d4fc51d4cfce63984c3459f4d18db284a738bdf4f6cf271ba5ab495d70a4a45b022e944f00a3cdc
|
data/lib/lilypond/builder.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative "../lilypond-ruby.rb"
|
2
2
|
|
3
|
-
# The LilyPond
|
4
|
-
|
3
|
+
# The LilyPond module provides an interface for generating LilyPond notation.
|
4
|
+
module LilyPond
|
5
5
|
# The Builder class is responsible for building LilyPond notation.
|
6
6
|
class Builder
|
7
7
|
# Creates a new LilyPond Builder object.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "../lilypond-ruby.rb"
|
2
|
+
|
3
|
+
module LilyPond
|
4
|
+
class << self
|
5
|
+
attr_accessor :configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configuration
|
9
|
+
@configuration ||= Configuration.new
|
10
|
+
yield(@configuration) if block_given?
|
11
|
+
@configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_accessor :default_output, :destination_directory, :lilypond_path
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@default_output = :pdf
|
19
|
+
@destination_directory = "."
|
20
|
+
@lilypond_path = File.expand_path("../../../lilypond-2.24.1/bin/lilypond", __FILE__)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/lilypond-ruby.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require "open3"
|
2
2
|
require "lilypond/builder"
|
3
|
+
require "lilypond/config"
|
3
4
|
require "guile"
|
4
5
|
|
5
|
-
|
6
|
-
LILYPOND_PATH = File.expand_path("../../lilypond-2.24.1/bin/lilypond", __FILE__)
|
6
|
+
module LilyPond
|
7
7
|
class << self
|
8
|
-
|
9
8
|
def version
|
10
|
-
output, error, status = Open3.capture3(
|
9
|
+
output, error, status = Open3.capture3(path, "--version")
|
11
10
|
if status.success?
|
12
11
|
puts output
|
13
12
|
else
|
@@ -16,7 +15,7 @@ class LilyPond
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def version_number
|
19
|
-
output, error, status = Open3.capture3(
|
18
|
+
output, error, status = Open3.capture3(path, "--version")
|
20
19
|
if status.success?
|
21
20
|
return output.match(/GNU LilyPond (\d+\.\d+\.\d+)/)[1]
|
22
21
|
else
|
@@ -24,40 +23,58 @@ class LilyPond
|
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
|
-
|
26
|
+
# Approved output types: `[:pdf, :svg, :png]` If none is provided, it defaults to
|
27
|
+
# LilyPond.configuration.default_output, which initializes as `:pdf`
|
28
|
+
def generate_with_lilypond(file_name, lilypond_code, output_type = nil)
|
28
29
|
tempfile = Tempfile.new(file_name)
|
29
30
|
tempfile.write(lilypond_code)
|
30
31
|
tempfile.close
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
data
|
48
|
-
|
32
|
+
output_type ||= default_output
|
33
|
+
Dir.chdir(destination) do
|
34
|
+
Open3.popen3(path, "--#{output_type}", tempfile.path) do |stdin, stdout, stderr, wait_thr|
|
35
|
+
# Write the Lilypond code to stdin
|
36
|
+
stdin.write(lilypond_code)
|
37
|
+
stdin.close
|
38
|
+
|
39
|
+
# Wait for the process to complete
|
40
|
+
Process.detach(wait_thr.pid)
|
41
|
+
|
42
|
+
# Read and process the output and error streams
|
43
|
+
loop do
|
44
|
+
# Wait for output to become available for reading
|
45
|
+
ready = IO.select([stdout, stderr])
|
46
|
+
next unless ready
|
47
|
+
|
48
|
+
# Read available data from the streams
|
49
|
+
ready[0].each do |stream|
|
50
|
+
data = stream.read_nonblock(1024)
|
51
|
+
puts data # or process the data as necessary
|
52
|
+
end
|
53
|
+
rescue IO::WaitReadable, IO::WaitWritable
|
54
|
+
# Continue waiting if the streams are not yet ready
|
55
|
+
IO.select([stdout, stderr])
|
56
|
+
retry
|
57
|
+
rescue EOFError
|
58
|
+
# Stop waiting if the streams have been closed
|
59
|
+
break
|
49
60
|
end
|
50
|
-
rescue IO::WaitReadable, IO::WaitWritable
|
51
|
-
# Continue waiting if the streams are not yet ready
|
52
|
-
IO.select([stdout, stderr])
|
53
|
-
retry
|
54
|
-
rescue EOFError
|
55
|
-
# Stop waiting if the streams have been closed
|
56
|
-
break
|
57
61
|
end
|
58
62
|
end
|
59
63
|
File.delete(tempfile.path)
|
60
64
|
end
|
61
65
|
|
66
|
+
private
|
67
|
+
def default_output
|
68
|
+
LilyPond.configuration.default_output
|
69
|
+
end
|
70
|
+
|
71
|
+
def destination
|
72
|
+
LilyPond.configuration.destination_directory
|
73
|
+
end
|
74
|
+
|
75
|
+
def path
|
76
|
+
LilyPond.configuration.lilypond_path.to_s
|
77
|
+
end
|
78
|
+
|
62
79
|
end # end self
|
63
80
|
end # end LilyPond
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: LilyPond-Ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.5
|
4
|
+
version: 0.1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Whittaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -30,9 +30,10 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.15.5
|
33
|
-
description:
|
34
|
-
|
35
|
-
also provides a builder tool for generating LilyPond files dynamically
|
33
|
+
description: |
|
34
|
+
This gem provides a library to access and control Lilypond within Ruby.
|
35
|
+
It also provides a builder tool for generating LilyPond files dynamically
|
36
|
+
with Ruby.
|
36
37
|
email: whittakerlee81@gmail.com
|
37
38
|
executables: []
|
38
39
|
extensions: []
|
@@ -41,6 +42,7 @@ files:
|
|
41
42
|
- lib/guile.rb
|
42
43
|
- lib/lilypond-ruby.rb
|
43
44
|
- lib/lilypond/builder.rb
|
45
|
+
- lib/lilypond/config.rb
|
44
46
|
- lilypond-2.24.1/bin/abc2ly
|
45
47
|
- lilypond-2.24.1/bin/convert-ly
|
46
48
|
- lilypond-2.24.1/bin/etf2ly
|