An article in The Baltimore Sun by Chris Kaltenbach recounts how documents from 1917 on the musical arrangement of "The Star-Spangled Banner" came to be donated to Fort McHenry.
The tune to which Francis Scott Key's poem (originally titled "Defence of Fort McHenry") is that of "To Anacreon in Heaven." Anacreon, the Greek lyric poet, was the patron of The Anacreontic Club of eighteenth-century London, which celebrated food and drink. The melody is attributed to the British musicologist and composer John Stafford Smith.
But it is probably not the text of "To Anacreon in Heaven"* that buzzed in Key's head as he wrote his verses, but a different set of words, "Adams and Liberty," a patriotic text by Robert Treat Paine also set to Smith's tune:
YE sons of Columbia, who bravely have fought,
For those rights, which unstained from your Sires had descended,
May you long taste the blessings your valour has brought,
And your sons reap the soil which their fathers defended.
'Mid the reign of mild Peace,
May your nation increase,
With the glory of Rome, and the wisdom of Greece;
And ne'er shall the sons of Columbia be slaves,
While the earth bears a plant, or the sea rolls its waves.
Paine's text, you see, is every bit as dense as Key's, and neither offers the ordinary singer much assistance in essaying the melody.
*To Anacreon in heaven where he sat in full glee,
A few sons of harmony sent a petition,
That he their inspirer and patron would be,
When this answer arrived from the jolly old Grecian:
Voice, fiddle and flute, no longer be mute,
I'll lend you my name and inspire you to boot!
And besides I'll instruct you like me to entwine
The myrtle of Venus and Bacchus's vine.