A compelling historical anecdote: Beethoven composed Piano Sonata No. 14 ("Moonlight Sonata") while sitting beside the casket of his friend and patron, Prince Karl von Lichnowsky, waiting for the funeral to take place.
Most scholars date the "Moonlight" to 1801, dedicated to Countess Giulietta Guicciardi. The Lichnowsky funeral story may conflate with another work or a later visit. Regardless, the sonata's funereal first movement (Adagio sostenuto) evokes the atmosphere of vigil and mourning.