This is a well known Shetland reel. The story (in MacPherson’s Rant, Stuart McHardy, 2004) is that it was composed by one James Gaudie.
James lived in the early nineteenth century, working in a quarry. Apparently, a rock fell on his head (other versions of this true story say it was a hammer) and he suffered some neurological damage that manifested in episodes of extreme verbal, though not physical, aggression.
Usually, after one of his outbursts the constable would lock him up for a few hours until he had calmed down, whereupon he would be released with no charges against him. However, on one occasion he was sentenced to a week in gaol, and in his rage dislodged a window bar and escaped. That night he headed to the pub and played this tune, which he had just composed ‘in honour’ of his escape.
He was again arrested and brought before an apparently non-music-loving magistrate. The magistrate decreed that James should be sent to a lunatic asylum in Edinburgh, from whence he never emerged.