Created
December 12, 2016 20:46
-
-
Save igneus/7098ce45ee4cbae0c5324ff91df7e3c1 to your computer and use it in GitHub Desktop.
"How melismatic chants do my gabc files contain?"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# takes a list of gabc file paths as commandline arguments, | |
# for each of them prints syllable count, note count and notes per syllable | |
require 'grely' | |
class GabcScore | |
def syllables_count | |
i = 0 | |
each_syllable {|s| i += 1 } | |
i | |
end | |
def notes_count | |
i = 0 | |
each_syllable do |s| | |
s.notes.each do |music_something| | |
i += 1 if music_something.is_a? GabcNote | |
end | |
end | |
i | |
end | |
def each_syllable | |
music.words.each do |word| | |
word.each_syllable do |syllable| | |
next unless contains_any_notes? syllable | |
yield syllable | |
end | |
end | |
end | |
def contains_any_notes?(syllable) | |
note = syllable.notes.find {|n| n.is_a? GabcNote } | |
not note.nil? | |
end | |
end | |
def csv(*args) | |
args.collect(&:to_s).join(';') | |
end | |
parser = GabcParser.new | |
puts csv 'file name', 'syllables', 'notes', 'notes per syllable' | |
ARGV.each do |fname| | |
result = parser.parse(File.read(fname)) | |
raise "Failed to parse #{fname}." unless result | |
score = result.create_score | |
puts csv fname, score.syllables_count, score.notes_count, '%.2f' % (score.notes_count.to_f / score.syllables_count) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment