This is actually a rather difficult task, due to the many ways that music may be represented. An attempt is made to generalize the music somewhat, by removing things like chords and ornaments. Also, bar lines are ignored, since musicians often don't agree on how many to use.
One small heuristic used is: Everything before the first bar line is ignored, since that is usually a "pickup" that is often written differently by nearly every musician. This does have an unfotrunate side-effect, however: It's common to omit initial bar lines, even for full measures. So if the music starts right on the downbeat, it's a good idea to use the initial bar line. This helps readers, of course, so it's a good idea in general. And it will prevent code like this from treating the first bar as a long pickup.
For the more theoretically inclined, what this match does is convert the musical sample into the second code described in the contour match. These are really the same sort of match, but this one lets you just copy a line of music into the tune finder's input widget.
This should all be considered experimental. It doesn't really work all that well, due to the huge variety in the ways that a piece of music can be encoded as ABC (or as staff notation, for that matter). If you have comments or suggestions, send me a message.