-------- Original-Nachricht --------
Datum: Thu, 20 Dec 2007 00:01:05 +0900
Von: Lunatic D. [email protected]
An: [email protected]
Betreff: Music notation ABC
musician to work around is center of interests.
Here is a linl about ABC notation: http://www.walshaw.plus.com/abc/
Thanks for informations and afflicted to make you undergo my aglais.
Posted via http://www.ruby-forum.com/.
Hello,
welcome to Ruby :).
I couldn’t find any ready-made library for abc in Ruby.
But as the link you gave shows that the notation is done in ASCII
text, you can search that text for tune bits (=Strings) or
for Regular Expressions. These are patterns which allow you
to search for occurrences of many strings at the same time, e.g.,
you can search for all Strings having
“at least three, but at most
five occurrences of any of “a”,“b”,“c”, followed but a letter, which
is anything but “C” or “D”, then something arbitrary and a “c” at the
end.”
The corresponding Regexp is
reg=/[a-c]{3,5}[^CD].+c$/ . So, for
tune1=“CDEabcacdAAc”
tune2=“CDabcacdCCc”
ref1=reg.match(tune1)
ref2=reg.match(tune2)
p ref1[0] => “abcacdAAc”
p ref2[0] => “abcacdCCc”
There is more comprehensive information about what Regexps
can do for you here:
http://www.rubyist.net/~slagell/ruby/regexp.html
Ruby Regexp Class - Regular Expressions in Ruby .
I know too little about music to say what similarity between
tunes might mean to a musician (… please tell me) , but I guess
it can somewhat be boiled down to the number of replacements
on tune1 to get to tune2 (possibly one needs to exclude some
tunes that are too awkward using a Regexp search first).
This is what Levenstein distance
(Levenshtein distance - Wikipedia)
and the diff/lcs algorithms do.
A Ruby implementation of Levenstein distance is here:
http://rubyforge.org/projects/text
Diff/LCS is implemented here:
http://raa.ruby-lang.org/project/diff-lcs/
Best regards,
Axel