Abcmatch


Introduction

Abcmatch is a utility for searching the contents of a abc file for specific music themes or motifs. It automatically adjusts for different key signatures and it is not restricted to just the first few bars of the tune. It has many uses. For example, you may start to transcribe a new tune and would like to know whether the tune was already transcribed with a different name. Alternatively, you know a tune but not its name. In another situation, there is a tune you like and you want to find other similar tunes with the same nuances. Or you are creating a medley starting with a specific tune and you are looking for other tunes which share something in common. You might use abcmatch as a research tool in musicology to identify groups of tunes sharing similar motifs. You can do all of this manually without the program, but then it is very time consuming and you require a good memory for melodies.

Abcmatch is bar orientated and probably not as easy to use as some other matching schemes. It is necessary to know the time signature of the music and where to place the bar lines. Also the key signature should be reflective of the piece of music you are presenting. The template that you provide to the program is in the form of an abc file called match.abc containing a few complete bars of the music. This possibly limits the use of the program to someone fairly knowledgeable of music theory and capable of expressing a tune in proper music notation. Furthermore, the program is probably not intelligent enough to match a tune in 4/4 with another tune expressed in 4/8 time. Nevertheless, if you are starting with part of a tune already expressed in abc music notation, then it is fairly easy to prepare a suitable template file match.abc, using runabc as explained later. To use abcmatch, you create an abc formated file called match.abc with sample bars from your tunes. Abcmatch is not a straight string matcher, so extraneous information such as guitar chords, grace notes, staccato indications are ignored. The program searches the entire tune for the bars of interest not just the beginning. The program automaticly transposes the input to a common key signature allowing it to match tunes notated in a different key. There are various modes of operation which allow the program to make an approximate match to the given music measures.

How does it work

Abcmatch changes the representation of the tune into something resembling a midi file. This representation is only stored in memory, so you never see it. The notes are stored in two arrays: one array store the pitch in midi units and the other stores the duration where one quarter note has a value of 24 ticks. Bar lines of all types are indicated by a value of 1000. Rests have a pitch value of zero. This representation was chosen to allow transpositions and transformations to other representations.

Abcmatch compares the tune bar by bar. The bar either matches or does not, but the matching criterion can be loose. If several bars are given, you have a choice of matching all the bars in the same sequence. Or any of the bars in any sequence. In the any mode, it is not necessary for all the bars to match and they may dispersed in the tune in any order. In the all mode (which is the default), all the bars must match in the same sequence.

If contour matching is selected, then the program matches the pitch intervals between the notes. The advantage of the contour match, is that transpositions are handled very well. If contour matching is not chosen, the notes must be positioned in the correct octaves after transposition. This may not be the case if the program transposes to the key signature in the wrong direction. The disadvantage is that contour matching does not work in the any mode.

For most applications it is recommended that you set the resolution to exact (a value of 0). This requires that the note lengths in bars match exactly as notated. If you change the resolution to something lower, like 1/8 notes, then the matching becomes looser. In this mode, the program looks at the bar at 1/8 note intervals and compares the note that is playing with the note that should be playing. Anything else can happen in between. Furthermore certain rhythm differences are ignored. For example, the bar |A4 BC| would match with |A2 AA BC|, (assuming L: 1/8). This function could be used for just matching the first beat and offbeat of a tune. In the runabc.tcl, the resolution value can also be set with the menu button adjoining the resolution entry box.

Operation

Though abcmatch can be run stand alone, it is preferable to to run it with the graphical user interface runabc.tcl. The output from the program is rather cryptic and not easy to decipher. You access, the abcmatch functions by choosing the find/find bars menu item. In running the matcher, it is important that you have the correct L:, M: and K: values for the template. If the key signature is wrong, then some of the notes may not be sharpened or flattened. In runabc, you may make an auditory check by clicking the play button.

The easiest way to set the template parameters, is to grab a bar or two from an abc file using my selection editor in runabc. You highlight the bars making sure to end the bar with a bar line and press Alt-t key on your keyboard. Alternatively, you can click the button marked transfer. Runabc will automatically set the other entry values for key signature, time signature and note length. Then you click the match button. The first bar should not start with a bar line, but the last bar should end with a bar line. Though the entry box exposing the contents of the music body is not very large, you can put many staff lines or even the entire tune. Using the arrow keys in the keyboard, you can scroll through the entire contents of the entry box.

The path entry box specifies the file containing all the abc tunes that you wish to match. Alternatively, the entry box can point to a directory which contains many abc files to be searched. If the directory, contains subdirectories the program will search each of the subdirectories recursively. If you use the browse button to indicate the path, you must specify a particular file; however, you can then edit the entry box so it points to a directory instead of a file. Clicking the match button will initiate the process.

On slow computers you may need to allow a few minutes to scan all the abc files. On a 600 Mhz machine, the process is done in several seconds. You may abort the matching procedure by clicking the stop button which was initially labeled match. Click only once and allow for a short pause if a big file is being processed.

The results are displayed in abc format in a scrolling text window. The bars that satisfy the matching criterion will be displayed in red. The file name in blue, above the each result is also a link. Clicking the blue file name, will load it into the table of contents of that file, and select that tune so you can display or play it.

Grouping

Runabc has provision to use abcmatch for finding groups of tunes having common bars (or motifs). You access this function with the menu item find/grouper. In order to use this function you require abcmatch version 1.22 or higher.

Given a specific abc file composed of many tunes, the function compares each tune in the file with each other and determines the number of bars common to each other. When the number of common bars is greater than a specific threshold, the program reports the name of the tune and the number of common bars in a text window. If the number of common bars is large, it is likely that the two tunes are identical. If there are a few common bars, the tunes likely have similar nuances. The amount of output in the text window, depends on the threshold you select for the number of common bars. A threshold around 3 seems to work well with me.

The function executes a script procedure which processes each tune in the abc file individually. For each tune, it creates a template file match.abc (which is overwritten many times) and then executes a separate program abcmatch. Abcmatch then compares then template with every tune in the file and reports the results back to runabc. The number of common bars reported, is the number of bars in the tune that were found in matching template (match.abc). This number is not symmetric (i.e. the same when you interchange the template with the test tune.). Often a single bar in the tune occurs more than once in the template. Only the first match counts.


The output of the grouper is recorded in a text frame in the grouper window. Whenever the function finds tunes with common bars it lists the template tune first followed by all the tunes in the file which had more than a specific number of bars common with the template. The total number of bars in the template is listed after the title of the template tune. The number of bars found in the tune which also occur in the template (adjusting for transposition) is indicated in parenthesis.

If you click the blue word marked details associated with any template tune, the program will display the contents of each of the tunes matched with the template and highlight the matched bars. This will appear in the matcher window, the same one used in find/find bars; however, beware that the template parameters and other controls in the matcher window were not updated when you clicked on the details key. I decided to do it this way since so the path to the directory that 'find bars' uses does not get overwritten. If you wanted to perform the same task without clicking on details, you would have to open the template tune with 'my selection editor', grab the entire tune body using alt-t, change the path name in the matcher window to the specific file that grouper used, set the matching criterion to 'any' with resolution 0 and finally click match.

The matching criterion in grouper requires that the rhythm (note durations) and the pitch (adjusted for transposition) match exactly. This seems to work out well for the files I tried; however, the grouping function probably needs more tuning. Some simple bars consisting of only one whole note leads to many matches which are not significant. If you see a long series of tunes with consecutive reference numbers, this may be the problem.

As an interesting example, I ran the program on Francis O'Neils collection of dances (available on either Frank Nordberg's site (www.musicaviva.com) or John Chamber's site (http://ecf-guest.mit.edu/~jc/music/). Here is an interesting bunch of dances it found.

for 3 Hartigan's fancy (18 bars)
135 Boiled goat's milk (5 bars)
231 Finerty's frolic (6 bars)
252 The cook in the kitchen (7 bars)
292 The dairy maid (7 bars)
314 Sally Magee (6 bars)
If you listen to these tunes you can pick out common cadences and motifs in these tunes.

Applications and Examples

I find that a single bar is often sufficient to locate a few tunes in a large abc database. Often the same tune is present under different names. Here are a few examples. See if you can recognize the tune from the single bar provided.
1 sample 1
2 sample 2
3 sample 3
The answers are here.

The files loch.abc and monoghan.abc demonstrate abcmatch's ability to find abc notated tunes with similar motifs. See the notes at the beginning of these files. A larger collection is found in traveller.abc.

Interesting References

  • A.L. Uitdenbogerd and J. Zobel, Manipulation of music for melody matching, ACM Multimedia 98, http://goanna.cs.rmit.edu/~alu/research
  • J.C.C. Chen and A.L.P. Chen, Query by rhythm an approach for song retrieval in music databases, Proc IEEE Intl. Workshop on Research Issues in Data Engineering.
  • Kjell Lemstrom and P. Laine, Musical information retrieval using musical parameters, International Computer Music Conference, Ann Arbour, 1998.
  • P-Y Rolland and J-G Ganascia, Pattern detection and discovery: the case of music data mining, Lecture Notes in Artificial Intelligence (LNAI), Vol. 2447, Pages 190-198.
  • Y. Kim, W Chai, R. Garcia and B Vercoe, Analysis of a contour-based representation for melody, Procc 2000. International Symposium on Music Information Retrieval, Plymouth, MA, Oct 2000.
  • J. Chambers, JC's ABC tune finder, http://trillian.mit.edu/~jc/music/abc/findtune.html.
  • Numerous papers in the 2nd Annual International Symposium on Music Information Retrieval (ISMIR 2001). http://ismir2001.indiana.edu/