Using brackets instead of parentheses for \parenthesize

Sometimes a note is to be played only in special circumstances (e.g., only on the first repeat). One can use \parenthesize to put parentheses around the notehead. However, a different notation uses square brackets. This snippet shows how to tweak the settings for \parenthesize to use square brackets instead of parentheses. A function \bracketify is defined, which works similar to parenthesize.