# Music notation ABC

**URL:** <https://www.ruby-forum.com/t/music-notation-abc/123656>\
**Category:** Ruby\
**Created:** [December 19, 2007, 4:01pm UTC](https://www.ruby-forum.com/t/music-notation-abc/123656 "2007-12-19T16:01:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunatic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/73ab20/32.png) [@lunatic](https://www.ruby-forum.com/u/lunatic)\
**Post date:** [December 19, 2007, 4:01pm UTC](https://www.ruby-forum.com/t/music-notation-abc/123656/1 "2007-12-19T16:01:09Z")

</div>

Hi,

Do you know something about library for parse ABC music notation?

I want something or write something to load files containig mutliple ABC  
tunes, organise then cherche for similar tunes in the files, create  
listes of tunes from the files, sets of tunes and books of sets whith  
index.

I leanr Ruby (beginner) and I think it’s a good thing o do for a  
musician to work around is center of interests.

Here is a linl about ABC notation: [http://www.walshaw.plus.com/abc/](http://www.walshaw.plus.com/abc/)

Thanks for informations and afflicted to make you undergo my aglais.

---

<div class="post-metadata">

**Author:** ![lunatic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/73ab20/32.png) [@lunatic](https://www.ruby-forum.com/u/lunatic)\
**Post date:** [December 19, 2007, 5:30pm UTC](https://www.ruby-forum.com/t/music-notation-abc/123656/2 "2007-12-19T17:30:13Z")

</div>

-------- Original-Nachricht --------

> Datum: Thu, 20 Dec 2007 00:01:05 +0900  
> Von: Lunatic D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> 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/](http://www.walshaw.plus.com/abc/)
> 
> ## Thanks for informations and afflicted to make you undergo my aglais.
> 
> Posted via [http://www.ruby-forum.com/](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](http://www.rubyist.net/~slagell/ruby/regexp.html)  
[Ruby Regexp Class - Regular Expressions in Ruby](http://www.regular-expressions.info/ruby.html) .

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](http://en.wikipedia.org/wiki/Levenshtein_distance))  
and the diff/lcs algorithms do.

A Ruby implementation of Levenstein distance is here:

[http://rubyforge.org/projects/text](http://rubyforge.org/projects/text)

Diff/LCS is implemented here:

[http://raa.ruby-lang.org/project/diff-lcs/](http://raa.ruby-lang.org/project/diff-lcs/)

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![lunatic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/73ab20/32.png) [@lunatic](https://www.ruby-forum.com/u/lunatic)\
**Post date:** [December 19, 2007, 5:49pm UTC](https://www.ruby-forum.com/t/music-notation-abc/123656/3 "2007-12-19T17:49:35Z")

</div>

Lunatic D. wrote:

> Here is a linl about ABC notation: [http://www.walshaw.plus.com/abc/](http://www.walshaw.plus.com/abc/)
> 
> Thanks for informations and afflicted to make you undergo my aglais.

No, there isn’t any ABC notation package available AFAIK. But it would  
be extremely easy to do one, since the format itself isn’t very advanced  
or complicated.

If you want to do a ABC parser, you should make a header loader and a  
tune loader. And for each loaded section in the header, do syntax check  
of the input specific to that section. But before you begin, make sure  
you are a master of regular expressions (as Axel already said), it’s the  
foundation of parsing text.

FWIW, I’m writing a MusicXML library for Ruby. The package should be  
available sometime very early next year as a gem.

Best regards,

Jari W.

---

<div class="post-metadata">

**Author:** ![lunatic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/73ab20/32.png) [@lunatic](https://www.ruby-forum.com/u/lunatic)\
**Post date:** [December 19, 2007, 7:28pm UTC](https://www.ruby-forum.com/t/music-notation-abc/123656/4 "2007-12-19T19:28:58Z")

</div>

Jari W. wrote:

> FWIW, I’m writing a MusicXML library for Ruby. The package should be  
> available sometime very early next year as a gem.

ok, thanks to Axel and jari!

First you confirm that there is probably nothing about ABC in ruby and I  
think it is a good thing to do this:)

Second a musicXML parser will be very interersting too:

ABC is generaly used by trad musician peoples and I hop that the stat of  
the norm is certanly larger than the usage need. a musicXML parser will  
permit to write some tools between the ABC world and tools like “finale”  
ABC2musicXML and musiXML2ABC with the ability to choice the  
granuralirity of details you want to get. Then there are tools to  
complÃ¨te graphicaly like “finale” or print directly from tune or tune  
list if more simple… and there is “lilypond”…

Ok I retrn to ruby and regular expressions 😉

regards,
