Menu

Two pass algorithm to fix repeats

I have added a new feature to Toadflax and also Tabctoabc, the clone
of abc2abc built around the Toadflax version of the abc2abc code. The
new feature is the ability to complete repeats. It is selected by a -R flag
in Tabctoabc and uses a fairly simple algorithm. If it finds a start repeat
with no matching end repeat, it tries to add the end repeat. Likewise, if
it finds an end repeat with a missing start repeat, it tries to add a
start repeat. This deals with the most common problems seen in abc
and in notated music. Inevitably there will be cases where the program
encounters a repeat problem that it cannot fix or where the fix will not
be what a musician familiar with the genre might have expected; the
aim is to be helpful in most cases rather than providing a definitive
correction.

From a coding point of view, this is a departure from the currently
supported set of Tabctoabc features in that it requires two passes
through an abc tune, making it much more of a challenge to program.
The first pass creates a list of all the bar symbols in the tune.
This is processed to correct any repeat errors and then in the second
pass, the original bar symbols are replaced by the corrected ones.

Each abc tune has two passes rather than the whole abc file having
two passes. The way this works is that when the parser finds the start
of a tune, it starts storing each line away. When it reaches the end of
the tune, these stored lines are processed again to create the second
pass.

For the two passes to result in just the one corrected output, the
output from the first pass is suppressed. This is done by creating
a dummy backend which does nothing. It would have been possible
to simply suppress the final output, but this solution seems fairly
elegant and results in the program having to do less work.

Posted by James Allwright 2021-07-10

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.