Module: Webern::LilypondBuilder
- Defined in:
- lib/webern/lilypond_builder.rb
Constant Summary
- NOTES =
%w{c
- PREAMBLE_BLOCK =
<<-STR \\version \"#{self.current_lilypond_version}\" \\include \"english.ly\" #(set-global-staff-size 13) STR
- STAFF_BLOCK =
<<-STR rows = { \\override Score.TimeSignature #'stencil = ##f \\clef bass \\time 12/4 STR
- SCORE_BLOCK =
<<-STR \\score { << \\new Staff \\rows >> } STR
Class Attribute Summary (collapse)
Class Method Summary (collapse)
Class Attribute Details
+ (Object) zero_note
13 14 15 |
# File 'lib/webern/lilypond_builder.rb', line 13 def self.zero_note @zero_note ||= "c" end |
Class Method Details
+ (Object) convert_row(row)
17 18 19 |
# File 'lib/webern/lilypond_builder.rb', line 17 def self.convert_row(row) row.map{|note| NOTES[(note + NOTES.index(self.zero_note)) % 12] }.join(" ") end |
+ (Object) current_lilypond_version
9 10 11 |
# File 'lib/webern/lilypond_builder.rb', line 9 def self.current_lilypond_version `lilypond --version`.match(/\d+\.\d+\.\d+/)[0] end |
+ (Object) generate_file(matrix)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/webern/lilypond_builder.rb', line 21 def self.generate_file(matrix) file = [PREAMBLE_BLOCK, "\n"] file << STAFF_BLOCK [:primes, :retrogrades, :inversions, :retrograde_inversions].each do |method| abbrev = method.to_s.scan(/^\w|_\w/).join("").gsub(/_/, "").upcase matrix.send(method).each do |row| first = row[0] row = self.convert_row(row) row = row.sub(" ", "^\\markup{#{abbrev}#{first}} ") file << " #{row}" end end file << "\}" << "\n" << SCORE_BLOCK File.open("matrix.ly", "w") do |f| f << file.join("\n") end # TODO: This unless seems a bit messy system("lilypond matrix.ly") unless $0 =~ /spec|rcov/ end |