Replacing some accidentals with a user-defined stencil

Here is a way to replace all accidentals of any sort with an arbitrary stencil (in this case, a markup). Alterations are defined as 1 for a double-flat, -3/4 for a sesquiflat, etc.