class Jekyll::Lilypond::FileProcessor
Public Class Methods
new(working_dir, hash, source)
click to toggle source
# File lib/jekyll-lilypond/file_processor.rb, line 6 def initialize(working_dir, hash, source) @hash = hash @source = source @working_dir = working_dir end
Public Instance Methods
compile()
click to toggle source
# File lib/jekyll-lilypond/file_processor.rb, line 27 def compile unless File.exist?("#{filepath}.svg") puts "Jekyll-lilypond: making #{@hash}.svg" Kernel.system("lilypond", "-lERROR", "-dbackend=svg", "--output=#{filepath}", "#{filepath}.ly") end end
filepath()
click to toggle source
# File lib/jekyll-lilypond/file_processor.rb, line 12 def filepath "#{@working_dir}/#{@hash}" end
make_mp3()
click to toggle source
# File lib/jekyll-lilypond/file_processor.rb, line 53 def make_mp3 unless File.exist?("#{filepath}.mp3") if File.exist?("#{filepath}.midi") puts "Jekyll-lilypond: making #{@hash}.mp3" Kernel.system("timidity #{filepath}.midi -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k #{filepath}.mp3", [:out, :err] => "/dev/null") else raise RuntimeError.new( "Cannot generate mp3: expected MIDI file #{filepath}.midi does not exist.") end end end
trim_svg()
click to toggle source
# File lib/jekyll-lilypond/file_processor.rb, line 37 def trim_svg unless File.exist?("#{filepath}-trimmed.svg") if File.exist?("#{filepath}.svg") puts "Jekyll-lilypond: making #{@hash}-trimmed.svg" Kernel.system("inkscape", "#{filepath}.svg", "--export-area-drawing", "--export-type=svg", "--export-filename=#{filepath}-trimmed.svg") else raise RuntimeError.new( "Cannot trim SVG: expected SVG file #{filepath}.svg does not exist") end end end
write()
click to toggle source
# File lib/jekyll-lilypond/file_processor.rb, line 16 def write unless File.directory?(@working_dir) FileUtils.mkdir_p(@working_dir) end unless File.exist?("#{filepath}.ly") File.open("#{filepath}.ly", "w") do |f| f.write(@source) end end end